1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
3 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
25 Emacs separates the task of updating the display from code
26 modifying global state, e.g. buffer text. This way functions
27 operating on buffers don't also have to be concerned with updating
30 Updating the display is triggered by the Lisp interpreter when it
31 decides it's time to do it. This is done either automatically for
32 you as part of the interpreter's command loop or as the result of
33 calling Lisp functions like `sit-for'. The C function `redisplay'
34 in xdisp.c is the only entry into the inner redisplay code. (Or,
35 let's say almost---see the description of direct update
38 The following diagram shows how redisplay code is invoked. As you
39 can see, Lisp calls redisplay and vice versa. Under window systems
40 like X, some portions of the redisplay code are also called
41 asynchronously during mouse movement or expose events. It is very
42 important that these code parts do NOT use the C library (malloc,
43 free) because many C libraries under Unix are not reentrant. They
44 may also NOT call functions of the Lisp interpreter which could
45 change the interpreter's state. If you don't follow these rules,
46 you will encounter bugs which are very hard to explain.
48 (Direct functions, see below)
49 direct_output_for_insert,
50 direct_forward_char (dispnew.c)
51 +---------------------------------+
54 +--------------+ redisplay +----------------+
55 | Lisp machine |---------------->| Redisplay code |<--+
56 +--------------+ (xdisp.c) +----------------+ |
58 +----------------------------------+ |
59 Don't use this path when called |
62 expose_window (asynchronous) |
64 X expose events -----+
66 What does redisplay do? Obviously, it has to figure out somehow what
67 has been changed since the last time the display has been updated,
68 and to make these changes visible. Preferably it would do that in
69 a moderately intelligent way, i.e. fast.
71 Changes in buffer text can be deduced from window and buffer
72 structures, and from some global variables like `beg_unchanged' and
73 `end_unchanged'. The contents of the display are additionally
74 recorded in a `glyph matrix', a two-dimensional matrix of glyph
75 structures. Each row in such a matrix corresponds to a line on the
76 display, and each glyph in a row corresponds to a column displaying
77 a character, an image, or what else. This matrix is called the
78 `current glyph matrix' or `current matrix' in redisplay
81 For buffer parts that have been changed since the last update, a
82 second glyph matrix is constructed, the so called `desired glyph
83 matrix' or short `desired matrix'. Current and desired matrix are
84 then compared to find a cheap way to update the display, e.g. by
85 reusing part of the display by scrolling lines.
90 You will find a lot of redisplay optimizations when you start
91 looking at the innards of redisplay. The overall goal of all these
92 optimizations is to make redisplay fast because it is done
95 Two optimizations are not found in xdisp.c. These are the direct
96 operations mentioned above. As the name suggests they follow a
97 different principle than the rest of redisplay. Instead of
98 building a desired matrix and then comparing it with the current
99 display, they perform their actions directly on the display and on
102 One direct operation updates the display after one character has
103 been entered. The other one moves the cursor by one position
104 forward or backward. You find these functions under the names
105 `direct_output_for_insert' and `direct_output_forward_char' in
111 Desired matrices are always built per Emacs window. The function
112 `display_line' is the central function to look at if you are
113 interested. It constructs one row in a desired matrix given an
114 iterator structure containing both a buffer position and a
115 description of the environment in which the text is to be
116 displayed. But this is too early, read on.
118 Characters and pixmaps displayed for a range of buffer text depend
119 on various settings of buffers and windows, on overlays and text
120 properties, on display tables, on selective display. The good news
121 is that all this hairy stuff is hidden behind a small set of
122 interface functions taking an iterator structure (struct it)
125 Iteration over things to be displayed is then simple. It is
126 started by initializing an iterator with a call to init_iterator.
127 Calls to get_next_display_element fill the iterator structure with
128 relevant information about the next thing to display. Calls to
129 set_iterator_to_next move the iterator to the next thing.
131 Besides this, an iterator also contains information about the
132 display environment in which glyphs for display elements are to be
133 produced. It has fields for the width and height of the display,
134 the information whether long lines are truncated or continued, a
135 current X and Y position, and lots of other stuff you can better
138 Glyphs in a desired matrix are normally constructed in a loop
139 calling get_next_display_element and then produce_glyphs. The call
140 to produce_glyphs will fill the iterator structure with pixel
141 information about the element being displayed and at the same time
142 produce glyphs for it. If the display element fits on the line
143 being displayed, set_iterator_to_next is called next, otherwise the
144 glyphs produced are discarded.
149 That just couldn't be all, could it? What about terminal types not
150 supporting operations on sub-windows of the screen? To update the
151 display on such a terminal, window-based glyph matrices are not
152 well suited. To be able to reuse part of the display (scrolling
153 lines up and down), we must instead have a view of the whole
154 screen. This is what `frame matrices' are for. They are a trick.
156 Frames on terminals like above have a glyph pool. Windows on such
157 a frame sub-allocate their glyph memory from their frame's glyph
158 pool. The frame itself is given its own glyph matrices. By
159 coincidence---or maybe something else---rows in window glyph
160 matrices are slices of corresponding rows in frame matrices. Thus
161 writing to window matrices implicitly updates a frame matrix which
162 provides us with the view of the whole screen that we originally
163 wanted to have without having to move many bytes around. To be
164 honest, there is a little bit more done, but not much more. If you
165 plan to extend that code, take a look at dispnew.c. The function
166 build_frame_matrix is a good starting point. */
174 #include "keyboard.h"
177 #include "termchar.h"
178 #include "dispextern.h"
180 #include "character.h"
183 #include "commands.h"
187 #include "termhooks.h"
188 #include "intervals.h"
191 #include "region-cache.h"
194 #include "blockinput.h"
196 #ifdef HAVE_X_WINDOWS
211 #ifndef FRAME_X_OUTPUT
212 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
215 #define INFINITY 10000000
217 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
218 || defined(HAVE_NS) || defined (USE_GTK)
219 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
220 extern int pending_menu_activation
;
223 extern int interrupt_input
;
224 extern int command_loop_level
;
226 extern Lisp_Object do_mouse_tracking
;
228 extern int minibuffer_auto_raise
;
229 extern Lisp_Object Vminibuffer_list
;
231 extern Lisp_Object Qface
;
232 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
234 extern Lisp_Object Voverriding_local_map
;
235 extern Lisp_Object Voverriding_local_map_menu_flag
;
236 extern Lisp_Object Qmenu_item
;
237 extern Lisp_Object Qwhen
;
238 extern Lisp_Object Qhelp_echo
;
239 extern Lisp_Object Qbefore_string
, Qafter_string
;
241 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
242 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
243 Lisp_Object Qwindow_text_change_functions
, Vwindow_text_change_functions
;
244 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
245 Lisp_Object Qinhibit_point_motion_hooks
;
246 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
247 Lisp_Object Qfontified
;
248 Lisp_Object Qgrow_only
;
249 Lisp_Object Qinhibit_eval_during_redisplay
;
250 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
251 Lisp_Object Qright_to_left
, Qleft_to_right
;
254 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
257 Lisp_Object Qarrow
, Qhand
, Qtext
;
259 Lisp_Object Qrisky_local_variable
;
261 /* Holds the list (error). */
262 Lisp_Object list_of_error
;
264 /* Functions called to fontify regions of text. */
266 Lisp_Object Vfontification_functions
;
267 Lisp_Object Qfontification_functions
;
269 /* Non-nil means automatically select any window when the mouse
270 cursor moves into it. */
271 Lisp_Object Vmouse_autoselect_window
;
273 Lisp_Object Vwrap_prefix
, Qwrap_prefix
;
274 Lisp_Object Vline_prefix
, Qline_prefix
;
276 /* Non-zero means draw tool bar buttons raised when the mouse moves
279 int auto_raise_tool_bar_buttons_p
;
281 /* Non-zero means to reposition window if cursor line is only partially visible. */
283 int make_cursor_line_fully_visible_p
;
285 /* Margin below tool bar in pixels. 0 or nil means no margin.
286 If value is `internal-border-width' or `border-width',
287 the corresponding frame parameter is used. */
289 Lisp_Object Vtool_bar_border
;
291 /* Margin around tool bar buttons in pixels. */
293 Lisp_Object Vtool_bar_button_margin
;
295 /* Thickness of shadow to draw around tool bar buttons. */
297 EMACS_INT tool_bar_button_relief
;
299 /* Non-nil means automatically resize tool-bars so that all tool-bar
300 items are visible, and no blank lines remain.
302 If value is `grow-only', only make tool-bar bigger. */
304 Lisp_Object Vauto_resize_tool_bars
;
306 /* Non-zero means draw block and hollow cursor as wide as the glyph
307 under it. For example, if a block cursor is over a tab, it will be
308 drawn as wide as that tab on the display. */
310 int x_stretch_cursor_p
;
312 /* Non-nil means don't actually do any redisplay. */
314 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
316 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
318 int inhibit_eval_during_redisplay
;
320 /* Names of text properties relevant for redisplay. */
322 Lisp_Object Qdisplay
;
323 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
325 /* Symbols used in text property values. */
327 Lisp_Object Vdisplay_pixels_per_inch
;
328 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
329 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
332 Lisp_Object Qmargin
, Qpointer
;
333 Lisp_Object Qline_height
;
334 extern Lisp_Object Qheight
;
335 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
336 extern Lisp_Object Qscroll_bar
;
337 extern Lisp_Object Qcursor
;
339 /* Non-nil means highlight trailing whitespace. */
341 Lisp_Object Vshow_trailing_whitespace
;
343 /* Non-nil means escape non-break space and hyphens. */
345 Lisp_Object Vnobreak_char_display
;
347 #ifdef HAVE_WINDOW_SYSTEM
348 extern Lisp_Object Voverflow_newline_into_fringe
;
350 /* Test if overflow newline into fringe. Called with iterator IT
351 at or past right window margin, and with IT->current_x set. */
353 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
354 (!NILP (Voverflow_newline_into_fringe) \
355 && FRAME_WINDOW_P (it->f) \
356 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
357 && it->current_x == it->last_visible_x \
358 && it->line_wrap != WORD_WRAP)
360 #else /* !HAVE_WINDOW_SYSTEM */
361 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
362 #endif /* HAVE_WINDOW_SYSTEM */
364 /* Test if the display element loaded in IT is a space or tab
365 character. This is used to determine word wrapping. */
367 #define IT_DISPLAYING_WHITESPACE(it) \
368 (it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t'))
370 /* Non-nil means show the text cursor in void text areas
371 i.e. in blank areas after eol and eob. This used to be
372 the default in 21.3. */
374 Lisp_Object Vvoid_text_area_pointer
;
376 /* Name of the face used to highlight trailing whitespace. */
378 Lisp_Object Qtrailing_whitespace
;
380 /* Name and number of the face used to highlight escape glyphs. */
382 Lisp_Object Qescape_glyph
;
384 /* Name and number of the face used to highlight non-breaking spaces. */
386 Lisp_Object Qnobreak_space
;
388 /* The symbol `image' which is the car of the lists used to represent
393 /* The image map types. */
394 Lisp_Object QCmap
, QCpointer
;
395 Lisp_Object Qrect
, Qcircle
, Qpoly
;
397 /* Non-zero means print newline to stdout before next mini-buffer
400 int noninteractive_need_newline
;
402 /* Non-zero means print newline to message log before next message. */
404 static int message_log_need_newline
;
406 /* Three markers that message_dolog uses.
407 It could allocate them itself, but that causes trouble
408 in handling memory-full errors. */
409 static Lisp_Object message_dolog_marker1
;
410 static Lisp_Object message_dolog_marker2
;
411 static Lisp_Object message_dolog_marker3
;
413 /* The buffer position of the first character appearing entirely or
414 partially on the line of the selected window which contains the
415 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
416 redisplay optimization in redisplay_internal. */
418 static struct text_pos this_line_start_pos
;
420 /* Number of characters past the end of the line above, including the
421 terminating newline. */
423 static struct text_pos this_line_end_pos
;
425 /* The vertical positions and the height of this line. */
427 static int this_line_vpos
;
428 static int this_line_y
;
429 static int this_line_pixel_height
;
431 /* X position at which this display line starts. Usually zero;
432 negative if first character is partially visible. */
434 static int this_line_start_x
;
436 /* Buffer that this_line_.* variables are referring to. */
438 static struct buffer
*this_line_buffer
;
440 /* Nonzero means truncate lines in all windows less wide than the
443 Lisp_Object Vtruncate_partial_width_windows
;
445 /* A flag to control how to display unibyte 8-bit character. */
447 int unibyte_display_via_language_environment
;
449 /* Nonzero means we have more than one non-mini-buffer-only frame.
450 Not guaranteed to be accurate except while parsing
451 frame-title-format. */
455 Lisp_Object Vglobal_mode_string
;
458 /* List of variables (symbols) which hold markers for overlay arrows.
459 The symbols on this list are examined during redisplay to determine
460 where to display overlay arrows. */
462 Lisp_Object Voverlay_arrow_variable_list
;
464 /* Marker for where to display an arrow on top of the buffer text. */
466 Lisp_Object Voverlay_arrow_position
;
468 /* String to display for the arrow. Only used on terminal frames. */
470 Lisp_Object Voverlay_arrow_string
;
472 /* Values of those variables at last redisplay are stored as
473 properties on `overlay-arrow-position' symbol. However, if
474 Voverlay_arrow_position is a marker, last-arrow-position is its
475 numerical position. */
477 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
479 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
480 properties on a symbol in overlay-arrow-variable-list. */
482 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
484 /* Like mode-line-format, but for the title bar on a visible frame. */
486 Lisp_Object Vframe_title_format
;
488 /* Like mode-line-format, but for the title bar on an iconified frame. */
490 Lisp_Object Vicon_title_format
;
492 /* List of functions to call when a window's size changes. These
493 functions get one arg, a frame on which one or more windows' sizes
496 static Lisp_Object Vwindow_size_change_functions
;
498 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
500 /* Nonzero if an overlay arrow has been displayed in this window. */
502 static int overlay_arrow_seen
;
504 /* Nonzero means highlight the region even in nonselected windows. */
506 int highlight_nonselected_windows
;
508 /* If cursor motion alone moves point off frame, try scrolling this
509 many lines up or down if that will bring it back. */
511 static EMACS_INT scroll_step
;
513 /* Nonzero means scroll just far enough to bring point back on the
514 screen, when appropriate. */
516 static EMACS_INT scroll_conservatively
;
518 /* Recenter the window whenever point gets within this many lines of
519 the top or bottom of the window. This value is translated into a
520 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
521 that there is really a fixed pixel height scroll margin. */
523 EMACS_INT scroll_margin
;
525 /* Number of windows showing the buffer of the selected window (or
526 another buffer with the same base buffer). keyboard.c refers to
531 /* Vector containing glyphs for an ellipsis `...'. */
533 static Lisp_Object default_invis_vector
[3];
535 /* Zero means display the mode-line/header-line/menu-bar in the default face
536 (this slightly odd definition is for compatibility with previous versions
537 of emacs), non-zero means display them using their respective faces.
539 This variable is deprecated. */
541 int mode_line_inverse_video
;
543 /* Prompt to display in front of the mini-buffer contents. */
545 Lisp_Object minibuf_prompt
;
547 /* Width of current mini-buffer prompt. Only set after display_line
548 of the line that contains the prompt. */
550 int minibuf_prompt_width
;
552 /* This is the window where the echo area message was displayed. It
553 is always a mini-buffer window, but it may not be the same window
554 currently active as a mini-buffer. */
556 Lisp_Object echo_area_window
;
558 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
559 pushes the current message and the value of
560 message_enable_multibyte on the stack, the function restore_message
561 pops the stack and displays MESSAGE again. */
563 Lisp_Object Vmessage_stack
;
565 /* Nonzero means multibyte characters were enabled when the echo area
566 message was specified. */
568 int message_enable_multibyte
;
570 /* Nonzero if we should redraw the mode lines on the next redisplay. */
572 int update_mode_lines
;
574 /* Nonzero if window sizes or contents have changed since last
575 redisplay that finished. */
577 int windows_or_buffers_changed
;
579 /* Nonzero means a frame's cursor type has been changed. */
581 int cursor_type_changed
;
583 /* Nonzero after display_mode_line if %l was used and it displayed a
586 int line_number_displayed
;
588 /* Maximum buffer size for which to display line numbers. */
590 Lisp_Object Vline_number_display_limit
;
592 /* Line width to consider when repositioning for line number display. */
594 static EMACS_INT line_number_display_limit_width
;
596 /* Number of lines to keep in the message log buffer. t means
597 infinite. nil means don't log at all. */
599 Lisp_Object Vmessage_log_max
;
601 /* The name of the *Messages* buffer, a string. */
603 static Lisp_Object Vmessages_buffer_name
;
605 /* Current, index 0, and last displayed echo area message. Either
606 buffers from echo_buffers, or nil to indicate no message. */
608 Lisp_Object echo_area_buffer
[2];
610 /* The buffers referenced from echo_area_buffer. */
612 static Lisp_Object echo_buffer
[2];
614 /* A vector saved used in with_area_buffer to reduce consing. */
616 static Lisp_Object Vwith_echo_area_save_vector
;
618 /* Non-zero means display_echo_area should display the last echo area
619 message again. Set by redisplay_preserve_echo_area. */
621 static int display_last_displayed_message_p
;
623 /* Nonzero if echo area is being used by print; zero if being used by
626 int message_buf_print
;
628 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
630 Lisp_Object Qinhibit_menubar_update
;
631 int inhibit_menubar_update
;
633 /* When evaluating expressions from menu bar items (enable conditions,
634 for instance), this is the frame they are being processed for. */
636 Lisp_Object Vmenu_updating_frame
;
638 /* Maximum height for resizing mini-windows. Either a float
639 specifying a fraction of the available height, or an integer
640 specifying a number of lines. */
642 Lisp_Object Vmax_mini_window_height
;
644 /* Non-zero means messages should be displayed with truncated
645 lines instead of being continued. */
647 int message_truncate_lines
;
648 Lisp_Object Qmessage_truncate_lines
;
650 /* Set to 1 in clear_message to make redisplay_internal aware
651 of an emptied echo area. */
653 static int message_cleared_p
;
655 /* How to blink the default frame cursor off. */
656 Lisp_Object Vblink_cursor_alist
;
658 /* A scratch glyph row with contents used for generating truncation
659 glyphs. Also used in direct_output_for_insert. */
661 #define MAX_SCRATCH_GLYPHS 100
662 struct glyph_row scratch_glyph_row
;
663 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
665 /* Ascent and height of the last line processed by move_it_to. */
667 static int last_max_ascent
, last_height
;
669 /* Non-zero if there's a help-echo in the echo area. */
671 int help_echo_showing_p
;
673 /* If >= 0, computed, exact values of mode-line and header-line height
674 to use in the macros CURRENT_MODE_LINE_HEIGHT and
675 CURRENT_HEADER_LINE_HEIGHT. */
677 int current_mode_line_height
, current_header_line_height
;
679 /* The maximum distance to look ahead for text properties. Values
680 that are too small let us call compute_char_face and similar
681 functions too often which is expensive. Values that are too large
682 let us call compute_char_face and alike too often because we
683 might not be interested in text properties that far away. */
685 #define TEXT_PROP_DISTANCE_LIMIT 100
689 /* Variables to turn off display optimizations from Lisp. */
691 int inhibit_try_window_id
, inhibit_try_window_reusing
;
692 int inhibit_try_cursor_movement
;
694 /* Non-zero means print traces of redisplay if compiled with
697 int trace_redisplay_p
;
699 #endif /* GLYPH_DEBUG */
701 #ifdef DEBUG_TRACE_MOVE
702 /* Non-zero means trace with TRACE_MOVE to stderr. */
705 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
707 #define TRACE_MOVE(x) (void) 0
710 /* Non-zero means automatically scroll windows horizontally to make
713 int automatic_hscrolling_p
;
714 Lisp_Object Qauto_hscroll_mode
;
716 /* How close to the margin can point get before the window is scrolled
718 EMACS_INT hscroll_margin
;
720 /* How much to scroll horizontally when point is inside the above margin. */
721 Lisp_Object Vhscroll_step
;
723 /* The variable `resize-mini-windows'. If nil, don't resize
724 mini-windows. If t, always resize them to fit the text they
725 display. If `grow-only', let mini-windows grow only until they
728 Lisp_Object Vresize_mini_windows
;
730 /* Buffer being redisplayed -- for redisplay_window_error. */
732 struct buffer
*displayed_buffer
;
734 /* Space between overline and text. */
736 EMACS_INT overline_margin
;
738 /* Require underline to be at least this many screen pixels below baseline
739 This to avoid underline "merging" with the base of letters at small
740 font sizes, particularly when x_use_underline_position_properties is on. */
742 EMACS_INT underline_minimum_offset
;
744 /* Value returned from text property handlers (see below). */
749 HANDLED_RECOMPUTE_PROPS
,
750 HANDLED_OVERLAY_STRING_CONSUMED
,
754 /* A description of text properties that redisplay is interested
759 /* The name of the property. */
762 /* A unique index for the property. */
765 /* A handler function called to set up iterator IT from the property
766 at IT's current position. Value is used to steer handle_stop. */
767 enum prop_handled (*handler
) P_ ((struct it
*it
));
770 static enum prop_handled handle_face_prop
P_ ((struct it
*));
771 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
772 static enum prop_handled handle_display_prop
P_ ((struct it
*));
773 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
774 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
775 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
777 /* Properties handled by iterators. */
779 static struct props it_props
[] =
781 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
782 /* Handle `face' before `display' because some sub-properties of
783 `display' need to know the face. */
784 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
785 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
786 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
787 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
791 /* Value is the position described by X. If X is a marker, value is
792 the marker_position of X. Otherwise, value is X. */
794 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
796 /* Enumeration returned by some move_it_.* functions internally. */
800 /* Not used. Undefined value. */
803 /* Move ended at the requested buffer position or ZV. */
804 MOVE_POS_MATCH_OR_ZV
,
806 /* Move ended at the requested X pixel position. */
809 /* Move within a line ended at the end of a line that must be
813 /* Move within a line ended at the end of a line that would
814 be displayed truncated. */
817 /* Move within a line ended at a line end. */
821 /* This counter is used to clear the face cache every once in a while
822 in redisplay_internal. It is incremented for each redisplay.
823 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
826 #define CLEAR_FACE_CACHE_COUNT 500
827 static int clear_face_cache_count
;
829 /* Similarly for the image cache. */
831 #ifdef HAVE_WINDOW_SYSTEM
832 #define CLEAR_IMAGE_CACHE_COUNT 101
833 static int clear_image_cache_count
;
836 /* Non-zero while redisplay_internal is in progress. */
840 /* Non-zero means don't free realized faces. Bound while freeing
841 realized faces is dangerous because glyph matrices might still
844 int inhibit_free_realized_faces
;
845 Lisp_Object Qinhibit_free_realized_faces
;
847 /* If a string, XTread_socket generates an event to display that string.
848 (The display is done in read_char.) */
850 Lisp_Object help_echo_string
;
851 Lisp_Object help_echo_window
;
852 Lisp_Object help_echo_object
;
855 /* Temporary variable for XTread_socket. */
857 Lisp_Object previous_help_echo_string
;
859 /* Null glyph slice */
861 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
863 /* Platform-independent portion of hourglass implementation. */
865 /* Non-zero means we're allowed to display a hourglass pointer. */
866 int display_hourglass_p
;
868 /* Non-zero means an hourglass cursor is currently shown. */
869 int hourglass_shown_p
;
871 /* If non-null, an asynchronous timer that, when it expires, displays
872 an hourglass cursor on all frames. */
873 struct atimer
*hourglass_atimer
;
875 /* Number of seconds to wait before displaying an hourglass cursor. */
876 Lisp_Object Vhourglass_delay
;
878 /* Default number of seconds to wait before displaying an hourglass
880 #define DEFAULT_HOURGLASS_DELAY 1
883 /* Function prototypes. */
885 static void setup_for_ellipsis
P_ ((struct it
*, int));
886 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
887 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
888 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
889 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
890 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
891 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
893 static Lisp_Object get_it_property
P_ ((struct it
*it
, Lisp_Object prop
));
895 static void handle_line_prefix
P_ ((struct it
*));
897 static void pint2str
P_ ((char *, int, int));
898 static void pint2hrstr
P_ ((char *, int, int));
899 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
901 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
902 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
903 static void store_mode_line_noprop_char
P_ ((char));
904 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
905 static void x_consider_frame_title
P_ ((Lisp_Object
));
906 static void handle_stop
P_ ((struct it
*));
907 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
908 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
909 static void ensure_echo_area_buffers
P_ ((void));
910 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
911 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
912 static int with_echo_area_buffer
P_ ((struct window
*, int,
913 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
914 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
915 static void clear_garbaged_frames
P_ ((void));
916 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
917 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
918 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
919 static int display_echo_area
P_ ((struct window
*));
920 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
921 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
922 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
923 static int string_char_and_length
P_ ((const unsigned char *, int *));
924 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
926 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
927 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
928 static void insert_left_trunc_glyphs
P_ ((struct it
*));
929 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
931 static void extend_face_to_end_of_line
P_ ((struct it
*));
932 static int append_space_for_newline
P_ ((struct it
*, int));
933 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
934 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
935 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
936 static int trailing_whitespace_p
P_ ((int));
937 static int message_log_check_duplicate
P_ ((int, int, int, int));
938 static void push_it
P_ ((struct it
*));
939 static void pop_it
P_ ((struct it
*));
940 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
941 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
942 static void redisplay_internal
P_ ((int));
943 static int echo_area_display
P_ ((int));
944 static void redisplay_windows
P_ ((Lisp_Object
));
945 static void redisplay_window
P_ ((Lisp_Object
, int));
946 static Lisp_Object
redisplay_window_error ();
947 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
948 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
949 static int update_menu_bar
P_ ((struct frame
*, int, int));
950 static int try_window_reusing_current_matrix
P_ ((struct window
*));
951 static int try_window_id
P_ ((struct window
*));
952 static int display_line
P_ ((struct it
*));
953 static int display_mode_lines
P_ ((struct window
*));
954 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
955 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
956 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
957 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
958 static void display_menu_bar
P_ ((struct window
*));
959 static int display_count_lines
P_ ((int, int, int, int, int *));
960 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
961 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int));
962 static void compute_line_metrics
P_ ((struct it
*));
963 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
964 static int get_overlay_strings
P_ ((struct it
*, int));
965 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
966 static void next_overlay_string
P_ ((struct it
*));
967 static void reseat
P_ ((struct it
*, struct text_pos
, int));
968 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
969 static void back_to_previous_visible_line_start
P_ ((struct it
*));
970 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
971 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
972 static int next_element_from_ellipsis
P_ ((struct it
*));
973 static int next_element_from_display_vector
P_ ((struct it
*));
974 static int next_element_from_string
P_ ((struct it
*));
975 static int next_element_from_c_string
P_ ((struct it
*));
976 static int next_element_from_buffer
P_ ((struct it
*));
977 static int next_element_from_composition
P_ ((struct it
*));
978 static int next_element_from_image
P_ ((struct it
*));
979 static int next_element_from_stretch
P_ ((struct it
*));
980 static void load_overlay_strings
P_ ((struct it
*, int));
981 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
982 struct display_pos
*));
983 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
984 Lisp_Object
, int, int, int, int));
985 static enum move_it_result
986 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
987 enum move_operation_enum
);
988 void move_it_vertically_backward
P_ ((struct it
*, int));
989 static void init_to_row_start
P_ ((struct it
*, struct window
*,
990 struct glyph_row
*));
991 static int init_to_row_end
P_ ((struct it
*, struct window
*,
992 struct glyph_row
*));
993 static void back_to_previous_line_start
P_ ((struct it
*));
994 static int forward_to_next_line_start
P_ ((struct it
*, int *));
995 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
997 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
998 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
999 static int number_of_chars
P_ ((unsigned char *, int));
1000 static void compute_stop_pos
P_ ((struct it
*));
1001 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
1003 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
1004 static EMACS_INT next_overlay_change
P_ ((EMACS_INT
));
1005 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
1006 Lisp_Object
, Lisp_Object
,
1007 struct text_pos
*, int));
1008 static int underlying_face_id
P_ ((struct it
*));
1009 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
1012 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
1013 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
1015 #ifdef HAVE_WINDOW_SYSTEM
1017 static void update_tool_bar
P_ ((struct frame
*, int));
1018 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
1019 static int redisplay_tool_bar
P_ ((struct frame
*));
1020 static void display_tool_bar_line
P_ ((struct it
*, int));
1021 static void notice_overwritten_cursor
P_ ((struct window
*,
1022 enum glyph_row_area
,
1023 int, int, int, int));
1027 #endif /* HAVE_WINDOW_SYSTEM */
1030 /***********************************************************************
1031 Window display dimensions
1032 ***********************************************************************/
1034 /* Return the bottom boundary y-position for text lines in window W.
1035 This is the first y position at which a line cannot start.
1036 It is relative to the top of the window.
1038 This is the height of W minus the height of a mode line, if any. */
1041 window_text_bottom_y (w
)
1044 int height
= WINDOW_TOTAL_HEIGHT (w
);
1046 if (WINDOW_WANTS_MODELINE_P (w
))
1047 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1051 /* Return the pixel width of display area AREA of window W. AREA < 0
1052 means return the total width of W, not including fringes to
1053 the left and right of the window. */
1056 window_box_width (w
, area
)
1060 int cols
= XFASTINT (w
->total_cols
);
1063 if (!w
->pseudo_window_p
)
1065 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1067 if (area
== TEXT_AREA
)
1069 if (INTEGERP (w
->left_margin_cols
))
1070 cols
-= XFASTINT (w
->left_margin_cols
);
1071 if (INTEGERP (w
->right_margin_cols
))
1072 cols
-= XFASTINT (w
->right_margin_cols
);
1073 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1075 else if (area
== LEFT_MARGIN_AREA
)
1077 cols
= (INTEGERP (w
->left_margin_cols
)
1078 ? XFASTINT (w
->left_margin_cols
) : 0);
1081 else if (area
== RIGHT_MARGIN_AREA
)
1083 cols
= (INTEGERP (w
->right_margin_cols
)
1084 ? XFASTINT (w
->right_margin_cols
) : 0);
1089 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1093 /* Return the pixel height of the display area of window W, not
1094 including mode lines of W, if any. */
1097 window_box_height (w
)
1100 struct frame
*f
= XFRAME (w
->frame
);
1101 int height
= WINDOW_TOTAL_HEIGHT (w
);
1103 xassert (height
>= 0);
1105 /* Note: the code below that determines the mode-line/header-line
1106 height is essentially the same as that contained in the macro
1107 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1108 the appropriate glyph row has its `mode_line_p' flag set,
1109 and if it doesn't, uses estimate_mode_line_height instead. */
1111 if (WINDOW_WANTS_MODELINE_P (w
))
1113 struct glyph_row
*ml_row
1114 = (w
->current_matrix
&& w
->current_matrix
->rows
1115 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1117 if (ml_row
&& ml_row
->mode_line_p
)
1118 height
-= ml_row
->height
;
1120 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1123 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1125 struct glyph_row
*hl_row
1126 = (w
->current_matrix
&& w
->current_matrix
->rows
1127 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1129 if (hl_row
&& hl_row
->mode_line_p
)
1130 height
-= hl_row
->height
;
1132 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1135 /* With a very small font and a mode-line that's taller than
1136 default, we might end up with a negative height. */
1137 return max (0, height
);
1140 /* Return the window-relative coordinate of the left edge of display
1141 area AREA of window W. AREA < 0 means return the left edge of the
1142 whole window, to the right of the left fringe of W. */
1145 window_box_left_offset (w
, area
)
1151 if (w
->pseudo_window_p
)
1154 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1156 if (area
== TEXT_AREA
)
1157 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1158 + window_box_width (w
, LEFT_MARGIN_AREA
));
1159 else if (area
== RIGHT_MARGIN_AREA
)
1160 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1161 + window_box_width (w
, LEFT_MARGIN_AREA
)
1162 + window_box_width (w
, TEXT_AREA
)
1163 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1165 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1166 else if (area
== LEFT_MARGIN_AREA
1167 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1168 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1174 /* Return the window-relative coordinate of the right edge of display
1175 area AREA of window W. AREA < 0 means return the left edge of the
1176 whole window, to the left of the right fringe of W. */
1179 window_box_right_offset (w
, area
)
1183 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1186 /* Return the frame-relative coordinate of the left edge of display
1187 area AREA of window W. AREA < 0 means return the left edge of the
1188 whole window, to the right of the left fringe of W. */
1191 window_box_left (w
, area
)
1195 struct frame
*f
= XFRAME (w
->frame
);
1198 if (w
->pseudo_window_p
)
1199 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1201 x
= (WINDOW_LEFT_EDGE_X (w
)
1202 + window_box_left_offset (w
, area
));
1208 /* Return the frame-relative coordinate of the right edge of display
1209 area AREA of window W. AREA < 0 means return the left edge of the
1210 whole window, to the left of the right fringe of W. */
1213 window_box_right (w
, area
)
1217 return window_box_left (w
, area
) + window_box_width (w
, area
);
1220 /* Get the bounding box of the display area AREA of window W, without
1221 mode lines, in frame-relative coordinates. AREA < 0 means the
1222 whole window, not including the left and right fringes of
1223 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1224 coordinates of the upper-left corner of the box. Return in
1225 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1228 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1231 int *box_x
, *box_y
, *box_width
, *box_height
;
1234 *box_width
= window_box_width (w
, area
);
1236 *box_height
= window_box_height (w
);
1238 *box_x
= window_box_left (w
, area
);
1241 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1242 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1243 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1248 /* Get the bounding box of the display area AREA of window W, without
1249 mode lines. AREA < 0 means the whole window, not including the
1250 left and right fringe of the window. Return in *TOP_LEFT_X
1251 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1252 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1253 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1257 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1258 bottom_right_x
, bottom_right_y
)
1261 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1263 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1265 *bottom_right_x
+= *top_left_x
;
1266 *bottom_right_y
+= *top_left_y
;
1271 /***********************************************************************
1273 ***********************************************************************/
1275 /* Return the bottom y-position of the line the iterator IT is in.
1276 This can modify IT's settings. */
1282 int line_height
= it
->max_ascent
+ it
->max_descent
;
1283 int line_top_y
= it
->current_y
;
1285 if (line_height
== 0)
1288 line_height
= last_height
;
1289 else if (IT_CHARPOS (*it
) < ZV
)
1291 move_it_by_lines (it
, 1, 1);
1292 line_height
= (it
->max_ascent
|| it
->max_descent
1293 ? it
->max_ascent
+ it
->max_descent
1298 struct glyph_row
*row
= it
->glyph_row
;
1300 /* Use the default character height. */
1301 it
->glyph_row
= NULL
;
1302 it
->what
= IT_CHARACTER
;
1305 PRODUCE_GLYPHS (it
);
1306 line_height
= it
->ascent
+ it
->descent
;
1307 it
->glyph_row
= row
;
1311 return line_top_y
+ line_height
;
1315 /* Return 1 if position CHARPOS is visible in window W.
1316 CHARPOS < 0 means return info about WINDOW_END position.
1317 If visible, set *X and *Y to pixel coordinates of top left corner.
1318 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1319 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1322 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1324 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1327 struct text_pos top
;
1329 struct buffer
*old_buffer
= NULL
;
1331 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1334 if (XBUFFER (w
->buffer
) != current_buffer
)
1336 old_buffer
= current_buffer
;
1337 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1340 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1342 /* Compute exact mode line heights. */
1343 if (WINDOW_WANTS_MODELINE_P (w
))
1344 current_mode_line_height
1345 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1346 current_buffer
->mode_line_format
);
1348 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1349 current_header_line_height
1350 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1351 current_buffer
->header_line_format
);
1353 start_display (&it
, w
, top
);
1354 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1355 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1357 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1359 /* We have reached CHARPOS, or passed it. How the call to
1360 move_it_to can overshoot: (i) If CHARPOS is on invisible
1361 text, move_it_to stops at the end of the invisible text,
1362 after CHARPOS. (ii) If CHARPOS is in a display vector,
1363 move_it_to stops on its last glyph. */
1364 int top_x
= it
.current_x
;
1365 int top_y
= it
.current_y
;
1366 enum it_method it_method
= it
.method
;
1367 /* Calling line_bottom_y may change it.method. */
1368 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1369 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1371 if (top_y
< window_top_y
)
1372 visible_p
= bottom_y
> window_top_y
;
1373 else if (top_y
< it
.last_visible_y
)
1377 if (it_method
== GET_FROM_BUFFER
)
1379 Lisp_Object window
, prop
;
1381 XSETWINDOW (window
, w
);
1382 prop
= Fget_char_property (make_number (it
.position
.charpos
),
1383 Qinvisible
, window
);
1385 /* If charpos coincides with invisible text covered with an
1386 ellipsis, use the first glyph of the ellipsis to compute
1387 the pixel positions. */
1388 if (TEXT_PROP_MEANS_INVISIBLE (prop
) == 2)
1390 struct glyph_row
*row
= it
.glyph_row
;
1391 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1392 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
1396 && (!BUFFERP (glyph
->object
)
1397 || glyph
->charpos
< charpos
);
1399 x
+= glyph
->pixel_width
;
1403 else if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1405 /* We stopped on the last glyph of a display vector.
1406 Try and recompute. Hack alert! */
1407 if (charpos
< 2 || top
.charpos
>= charpos
)
1408 top_x
= it
.glyph_row
->x
;
1412 start_display (&it2
, w
, top
);
1413 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1414 get_next_display_element (&it2
);
1415 PRODUCE_GLYPHS (&it2
);
1416 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1417 || it2
.current_x
> it2
.last_visible_x
)
1418 top_x
= it
.glyph_row
->x
;
1421 top_x
= it2
.current_x
;
1422 top_y
= it2
.current_y
;
1428 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1429 *rtop
= max (0, window_top_y
- top_y
);
1430 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1431 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1432 - max (top_y
, window_top_y
)));
1441 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1442 move_it_by_lines (&it
, 1, 0);
1443 if (charpos
< IT_CHARPOS (it
)
1444 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1447 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1449 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1450 *rtop
= max (0, -it2
.current_y
);
1451 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1452 - it
.last_visible_y
));
1453 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1455 - max (it2
.current_y
,
1456 WINDOW_HEADER_LINE_HEIGHT (w
))));
1462 set_buffer_internal_1 (old_buffer
);
1464 current_header_line_height
= current_mode_line_height
= -1;
1466 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1467 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1470 /* Debugging code. */
1472 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1473 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1475 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1482 /* Return the next character from STR which is MAXLEN bytes long.
1483 Return in *LEN the length of the character. This is like
1484 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1485 we find one, we return a `?', but with the length of the invalid
1489 string_char_and_length (str
, len
)
1490 const unsigned char *str
;
1495 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1496 if (!CHAR_VALID_P (c
, 1))
1497 /* We may not change the length here because other places in Emacs
1498 don't use this function, i.e. they silently accept invalid
1507 /* Given a position POS containing a valid character and byte position
1508 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1510 static struct text_pos
1511 string_pos_nchars_ahead (pos
, string
, nchars
)
1512 struct text_pos pos
;
1516 xassert (STRINGP (string
) && nchars
>= 0);
1518 if (STRING_MULTIBYTE (string
))
1520 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1521 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1526 string_char_and_length (p
, &len
);
1527 p
+= len
, rest
-= len
;
1528 xassert (rest
>= 0);
1530 BYTEPOS (pos
) += len
;
1534 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1540 /* Value is the text position, i.e. character and byte position,
1541 for character position CHARPOS in STRING. */
1543 static INLINE
struct text_pos
1544 string_pos (charpos
, string
)
1548 struct text_pos pos
;
1549 xassert (STRINGP (string
));
1550 xassert (charpos
>= 0);
1551 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1556 /* Value is a text position, i.e. character and byte position, for
1557 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1558 means recognize multibyte characters. */
1560 static struct text_pos
1561 c_string_pos (charpos
, s
, multibyte_p
)
1566 struct text_pos pos
;
1568 xassert (s
!= NULL
);
1569 xassert (charpos
>= 0);
1573 int rest
= strlen (s
), len
;
1575 SET_TEXT_POS (pos
, 0, 0);
1578 string_char_and_length (s
, &len
);
1579 s
+= len
, rest
-= len
;
1580 xassert (rest
>= 0);
1582 BYTEPOS (pos
) += len
;
1586 SET_TEXT_POS (pos
, charpos
, charpos
);
1592 /* Value is the number of characters in C string S. MULTIBYTE_P
1593 non-zero means recognize multibyte characters. */
1596 number_of_chars (s
, multibyte_p
)
1604 int rest
= strlen (s
), len
;
1605 unsigned char *p
= (unsigned char *) s
;
1607 for (nchars
= 0; rest
> 0; ++nchars
)
1609 string_char_and_length (p
, &len
);
1610 rest
-= len
, p
+= len
;
1614 nchars
= strlen (s
);
1620 /* Compute byte position NEWPOS->bytepos corresponding to
1621 NEWPOS->charpos. POS is a known position in string STRING.
1622 NEWPOS->charpos must be >= POS.charpos. */
1625 compute_string_pos (newpos
, pos
, string
)
1626 struct text_pos
*newpos
, pos
;
1629 xassert (STRINGP (string
));
1630 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1632 if (STRING_MULTIBYTE (string
))
1633 *newpos
= string_pos_nchars_ahead (pos
, string
,
1634 CHARPOS (*newpos
) - CHARPOS (pos
));
1636 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1640 Return an estimation of the pixel height of mode or header lines on
1641 frame F. FACE_ID specifies what line's height to estimate. */
1644 estimate_mode_line_height (f
, face_id
)
1646 enum face_id face_id
;
1648 #ifdef HAVE_WINDOW_SYSTEM
1649 if (FRAME_WINDOW_P (f
))
1651 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1653 /* This function is called so early when Emacs starts that the face
1654 cache and mode line face are not yet initialized. */
1655 if (FRAME_FACE_CACHE (f
))
1657 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1661 height
= FONT_HEIGHT (face
->font
);
1662 if (face
->box_line_width
> 0)
1663 height
+= 2 * face
->box_line_width
;
1674 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1675 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1676 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1677 not force the value into range. */
1680 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1682 register int pix_x
, pix_y
;
1684 NativeRectangle
*bounds
;
1688 #ifdef HAVE_WINDOW_SYSTEM
1689 if (FRAME_WINDOW_P (f
))
1691 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1692 even for negative values. */
1694 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1696 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1698 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1699 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1702 STORE_NATIVE_RECT (*bounds
,
1703 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1704 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1705 FRAME_COLUMN_WIDTH (f
) - 1,
1706 FRAME_LINE_HEIGHT (f
) - 1);
1712 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1713 pix_x
= FRAME_TOTAL_COLS (f
);
1717 else if (pix_y
> FRAME_LINES (f
))
1718 pix_y
= FRAME_LINES (f
);
1728 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1729 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1730 can't tell the positions because W's display is not up to date,
1734 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1737 int *frame_x
, *frame_y
;
1739 #ifdef HAVE_WINDOW_SYSTEM
1740 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1744 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1745 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1747 if (display_completed
)
1749 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1750 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1751 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1757 hpos
+= glyph
->pixel_width
;
1761 /* If first glyph is partially visible, its first visible position is still 0. */
1773 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1774 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1785 #ifdef HAVE_WINDOW_SYSTEM
1787 /* Find the glyph under window-relative coordinates X/Y in window W.
1788 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1789 strings. Return in *HPOS and *VPOS the row and column number of
1790 the glyph found. Return in *AREA the glyph area containing X.
1791 Value is a pointer to the glyph found or null if X/Y is not on
1792 text, or we can't tell because W's current matrix is not up to
1797 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1800 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1802 struct glyph
*glyph
, *end
;
1803 struct glyph_row
*row
= NULL
;
1806 /* Find row containing Y. Give up if some row is not enabled. */
1807 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1809 row
= MATRIX_ROW (w
->current_matrix
, i
);
1810 if (!row
->enabled_p
)
1812 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1819 /* Give up if Y is not in the window. */
1820 if (i
== w
->current_matrix
->nrows
)
1823 /* Get the glyph area containing X. */
1824 if (w
->pseudo_window_p
)
1831 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1833 *area
= LEFT_MARGIN_AREA
;
1834 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1836 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1839 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1843 *area
= RIGHT_MARGIN_AREA
;
1844 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1848 /* Find glyph containing X. */
1849 glyph
= row
->glyphs
[*area
];
1850 end
= glyph
+ row
->used
[*area
];
1852 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1854 x
-= glyph
->pixel_width
;
1864 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1867 *hpos
= glyph
- row
->glyphs
[*area
];
1873 Convert frame-relative x/y to coordinates relative to window W.
1874 Takes pseudo-windows into account. */
1877 frame_to_window_pixel_xy (w
, x
, y
)
1881 if (w
->pseudo_window_p
)
1883 /* A pseudo-window is always full-width, and starts at the
1884 left edge of the frame, plus a frame border. */
1885 struct frame
*f
= XFRAME (w
->frame
);
1886 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1887 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1891 *x
-= WINDOW_LEFT_EDGE_X (w
);
1892 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1897 Return in RECTS[] at most N clipping rectangles for glyph string S.
1898 Return the number of stored rectangles. */
1901 get_glyph_string_clip_rects (s
, rects
, n
)
1902 struct glyph_string
*s
;
1903 NativeRectangle
*rects
;
1911 if (s
->row
->full_width_p
)
1913 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1914 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1915 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1917 /* Unless displaying a mode or menu bar line, which are always
1918 fully visible, clip to the visible part of the row. */
1919 if (s
->w
->pseudo_window_p
)
1920 r
.height
= s
->row
->visible_height
;
1922 r
.height
= s
->height
;
1926 /* This is a text line that may be partially visible. */
1927 r
.x
= window_box_left (s
->w
, s
->area
);
1928 r
.width
= window_box_width (s
->w
, s
->area
);
1929 r
.height
= s
->row
->visible_height
;
1933 if (r
.x
< s
->clip_head
->x
)
1935 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1936 r
.width
-= s
->clip_head
->x
- r
.x
;
1939 r
.x
= s
->clip_head
->x
;
1942 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1944 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1945 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1950 /* If S draws overlapping rows, it's sufficient to use the top and
1951 bottom of the window for clipping because this glyph string
1952 intentionally draws over other lines. */
1953 if (s
->for_overlaps
)
1955 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1956 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1958 /* Alas, the above simple strategy does not work for the
1959 environments with anti-aliased text: if the same text is
1960 drawn onto the same place multiple times, it gets thicker.
1961 If the overlap we are processing is for the erased cursor, we
1962 take the intersection with the rectagle of the cursor. */
1963 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1965 XRectangle rc
, r_save
= r
;
1967 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1968 rc
.y
= s
->w
->phys_cursor
.y
;
1969 rc
.width
= s
->w
->phys_cursor_width
;
1970 rc
.height
= s
->w
->phys_cursor_height
;
1972 x_intersect_rectangles (&r_save
, &rc
, &r
);
1977 /* Don't use S->y for clipping because it doesn't take partially
1978 visible lines into account. For example, it can be negative for
1979 partially visible lines at the top of a window. */
1980 if (!s
->row
->full_width_p
1981 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1982 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1984 r
.y
= max (0, s
->row
->y
);
1986 /* If drawing a tool-bar window, draw it over the internal border
1987 at the top of the window. */
1988 if (WINDOWP (s
->f
->tool_bar_window
)
1989 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1990 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1993 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1995 /* If drawing the cursor, don't let glyph draw outside its
1996 advertised boundaries. Cleartype does this under some circumstances. */
1997 if (s
->hl
== DRAW_CURSOR
)
1999 struct glyph
*glyph
= s
->first_glyph
;
2004 r
.width
-= s
->x
- r
.x
;
2007 r
.width
= min (r
.width
, glyph
->pixel_width
);
2009 /* If r.y is below window bottom, ensure that we still see a cursor. */
2010 height
= min (glyph
->ascent
+ glyph
->descent
,
2011 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2012 max_y
= window_text_bottom_y (s
->w
) - height
;
2013 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2014 if (s
->ybase
- glyph
->ascent
> max_y
)
2021 /* Don't draw cursor glyph taller than our actual glyph. */
2022 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2023 if (height
< r
.height
)
2025 max_y
= r
.y
+ r
.height
;
2026 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2027 r
.height
= min (max_y
- r
.y
, height
);
2034 XRectangle r_save
= r
;
2036 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2040 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2041 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2043 #ifdef CONVERT_FROM_XRECT
2044 CONVERT_FROM_XRECT (r
, *rects
);
2052 /* If we are processing overlapping and allowed to return
2053 multiple clipping rectangles, we exclude the row of the glyph
2054 string from the clipping rectangle. This is to avoid drawing
2055 the same text on the environment with anti-aliasing. */
2056 #ifdef CONVERT_FROM_XRECT
2059 XRectangle
*rs
= rects
;
2061 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2063 if (s
->for_overlaps
& OVERLAPS_PRED
)
2066 if (r
.y
+ r
.height
> row_y
)
2069 rs
[i
].height
= row_y
- r
.y
;
2075 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2078 if (r
.y
< row_y
+ s
->row
->visible_height
)
2080 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2082 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2083 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2092 #ifdef CONVERT_FROM_XRECT
2093 for (i
= 0; i
< n
; i
++)
2094 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2101 Return in *NR the clipping rectangle for glyph string S. */
2104 get_glyph_string_clip_rect (s
, nr
)
2105 struct glyph_string
*s
;
2106 NativeRectangle
*nr
;
2108 get_glyph_string_clip_rects (s
, nr
, 1);
2113 Return the position and height of the phys cursor in window W.
2114 Set w->phys_cursor_width to width of phys cursor.
2118 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2120 struct glyph_row
*row
;
2121 struct glyph
*glyph
;
2122 int *xp
, *yp
, *heightp
;
2124 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2125 int x
, y
, wd
, h
, h0
, y0
;
2127 /* Compute the width of the rectangle to draw. If on a stretch
2128 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2129 rectangle as wide as the glyph, but use a canonical character
2131 wd
= glyph
->pixel_width
- 1;
2132 #if defined(HAVE_NTGUI) || defined(HAVE_NS)
2136 x
= w
->phys_cursor
.x
;
2143 if (glyph
->type
== STRETCH_GLYPH
2144 && !x_stretch_cursor_p
)
2145 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2146 w
->phys_cursor_width
= wd
;
2148 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2150 /* If y is below window bottom, ensure that we still see a cursor. */
2151 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2153 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2154 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2156 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2159 h
= max (h
- (y0
- y
) + 1, h0
);
2164 y0
= window_text_bottom_y (w
) - h0
;
2172 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2173 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2178 * Remember which glyph the mouse is over.
2182 remember_mouse_glyph (f
, gx
, gy
, rect
)
2185 NativeRectangle
*rect
;
2189 struct glyph_row
*r
, *gr
, *end_row
;
2190 enum window_part part
;
2191 enum glyph_row_area area
;
2192 int x
, y
, width
, height
;
2194 /* Try to determine frame pixel position and size of the glyph under
2195 frame pixel coordinates X/Y on frame F. */
2197 if (!f
->glyphs_initialized_p
2198 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2201 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2202 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2206 w
= XWINDOW (window
);
2207 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2208 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2210 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2211 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2213 if (w
->pseudo_window_p
)
2216 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2222 case ON_LEFT_MARGIN
:
2223 area
= LEFT_MARGIN_AREA
;
2226 case ON_RIGHT_MARGIN
:
2227 area
= RIGHT_MARGIN_AREA
;
2230 case ON_HEADER_LINE
:
2232 gr
= (part
== ON_HEADER_LINE
2233 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2234 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2237 goto text_glyph_row_found
;
2244 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2245 if (r
->y
+ r
->height
> y
)
2251 text_glyph_row_found
:
2254 struct glyph
*g
= gr
->glyphs
[area
];
2255 struct glyph
*end
= g
+ gr
->used
[area
];
2257 height
= gr
->height
;
2258 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2259 if (gx
+ g
->pixel_width
> x
)
2264 if (g
->type
== IMAGE_GLYPH
)
2266 /* Don't remember when mouse is over image, as
2267 image may have hot-spots. */
2268 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2271 width
= g
->pixel_width
;
2275 /* Use nominal char spacing at end of line. */
2277 gx
+= (x
/ width
) * width
;
2280 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2281 gx
+= window_box_left_offset (w
, area
);
2285 /* Use nominal line height at end of window. */
2286 gx
= (x
/ width
) * width
;
2288 gy
+= (y
/ height
) * height
;
2292 case ON_LEFT_FRINGE
:
2293 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2294 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2295 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2296 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2299 case ON_RIGHT_FRINGE
:
2300 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2301 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2302 : window_box_right_offset (w
, TEXT_AREA
));
2303 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2307 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2309 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2310 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2311 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2313 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2317 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2318 if (r
->y
+ r
->height
> y
)
2325 height
= gr
->height
;
2328 /* Use nominal line height at end of window. */
2330 gy
+= (y
/ height
) * height
;
2337 /* If there is no glyph under the mouse, then we divide the screen
2338 into a grid of the smallest glyph in the frame, and use that
2341 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2342 round down even for negative values. */
2348 gx
= (gx
/ width
) * width
;
2349 gy
= (gy
/ height
) * height
;
2354 gx
+= WINDOW_LEFT_EDGE_X (w
);
2355 gy
+= WINDOW_TOP_EDGE_Y (w
);
2358 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2360 /* Visible feedback for debugging. */
2363 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2364 f
->output_data
.x
->normal_gc
,
2365 gx
, gy
, width
, height
);
2371 #endif /* HAVE_WINDOW_SYSTEM */
2374 /***********************************************************************
2375 Lisp form evaluation
2376 ***********************************************************************/
2378 /* Error handler for safe_eval and safe_call. */
2381 safe_eval_handler (arg
)
2384 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2389 /* Evaluate SEXPR and return the result, or nil if something went
2390 wrong. Prevent redisplay during the evaluation. */
2392 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2393 Return the result, or nil if something went wrong. Prevent
2394 redisplay during the evaluation. */
2397 safe_call (nargs
, args
)
2403 if (inhibit_eval_during_redisplay
)
2407 int count
= SPECPDL_INDEX ();
2408 struct gcpro gcpro1
;
2411 gcpro1
.nvars
= nargs
;
2412 specbind (Qinhibit_redisplay
, Qt
);
2413 /* Use Qt to ensure debugger does not run,
2414 so there is no possibility of wanting to redisplay. */
2415 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2418 val
= unbind_to (count
, val
);
2425 /* Call function FN with one argument ARG.
2426 Return the result, or nil if something went wrong. */
2429 safe_call1 (fn
, arg
)
2430 Lisp_Object fn
, arg
;
2432 Lisp_Object args
[2];
2435 return safe_call (2, args
);
2438 static Lisp_Object Qeval
;
2441 safe_eval (Lisp_Object sexpr
)
2443 return safe_call1 (Qeval
, sexpr
);
2446 /* Call function FN with one argument ARG.
2447 Return the result, or nil if something went wrong. */
2450 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2452 Lisp_Object args
[3];
2456 return safe_call (3, args
);
2461 /***********************************************************************
2463 ***********************************************************************/
2467 /* Define CHECK_IT to perform sanity checks on iterators.
2468 This is for debugging. It is too slow to do unconditionally. */
2474 if (it
->method
== GET_FROM_STRING
)
2476 xassert (STRINGP (it
->string
));
2477 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2481 xassert (IT_STRING_CHARPOS (*it
) < 0);
2482 if (it
->method
== GET_FROM_BUFFER
)
2484 /* Check that character and byte positions agree. */
2485 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2490 xassert (it
->current
.dpvec_index
>= 0);
2492 xassert (it
->current
.dpvec_index
< 0);
2495 #define CHECK_IT(IT) check_it ((IT))
2499 #define CHECK_IT(IT) (void) 0
2506 /* Check that the window end of window W is what we expect it
2507 to be---the last row in the current matrix displaying text. */
2510 check_window_end (w
)
2513 if (!MINI_WINDOW_P (w
)
2514 && !NILP (w
->window_end_valid
))
2516 struct glyph_row
*row
;
2517 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2518 XFASTINT (w
->window_end_vpos
)),
2520 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2521 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2525 #define CHECK_WINDOW_END(W) check_window_end ((W))
2527 #else /* not GLYPH_DEBUG */
2529 #define CHECK_WINDOW_END(W) (void) 0
2531 #endif /* not GLYPH_DEBUG */
2535 /***********************************************************************
2536 Iterator initialization
2537 ***********************************************************************/
2539 /* Initialize IT for displaying current_buffer in window W, starting
2540 at character position CHARPOS. CHARPOS < 0 means that no buffer
2541 position is specified which is useful when the iterator is assigned
2542 a position later. BYTEPOS is the byte position corresponding to
2543 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2545 If ROW is not null, calls to produce_glyphs with IT as parameter
2546 will produce glyphs in that row.
2548 BASE_FACE_ID is the id of a base face to use. It must be one of
2549 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2550 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2551 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2553 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2554 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2555 will be initialized to use the corresponding mode line glyph row of
2556 the desired matrix of W. */
2559 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2562 int charpos
, bytepos
;
2563 struct glyph_row
*row
;
2564 enum face_id base_face_id
;
2566 int highlight_region_p
;
2567 enum face_id remapped_base_face_id
= base_face_id
;
2569 /* Some precondition checks. */
2570 xassert (w
!= NULL
&& it
!= NULL
);
2571 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2574 /* If face attributes have been changed since the last redisplay,
2575 free realized faces now because they depend on face definitions
2576 that might have changed. Don't free faces while there might be
2577 desired matrices pending which reference these faces. */
2578 if (face_change_count
&& !inhibit_free_realized_faces
)
2580 face_change_count
= 0;
2581 free_all_realized_faces (Qnil
);
2584 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2585 if (! NILP (Vface_remapping_alist
))
2586 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2588 /* Use one of the mode line rows of W's desired matrix if
2592 if (base_face_id
== MODE_LINE_FACE_ID
2593 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2594 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2595 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2596 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2600 bzero (it
, sizeof *it
);
2601 it
->current
.overlay_string_index
= -1;
2602 it
->current
.dpvec_index
= -1;
2603 it
->base_face_id
= remapped_base_face_id
;
2605 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2607 /* The window in which we iterate over current_buffer: */
2608 XSETWINDOW (it
->window
, w
);
2610 it
->f
= XFRAME (w
->frame
);
2614 /* Extra space between lines (on window systems only). */
2615 if (base_face_id
== DEFAULT_FACE_ID
2616 && FRAME_WINDOW_P (it
->f
))
2618 if (NATNUMP (current_buffer
->extra_line_spacing
))
2619 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2620 else if (FLOATP (current_buffer
->extra_line_spacing
))
2621 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2622 * FRAME_LINE_HEIGHT (it
->f
));
2623 else if (it
->f
->extra_line_spacing
> 0)
2624 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2625 it
->max_extra_line_spacing
= 0;
2628 /* If realized faces have been removed, e.g. because of face
2629 attribute changes of named faces, recompute them. When running
2630 in batch mode, the face cache of the initial frame is null. If
2631 we happen to get called, make a dummy face cache. */
2632 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2633 init_frame_faces (it
->f
);
2634 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2635 recompute_basic_faces (it
->f
);
2637 /* Current value of the `slice', `space-width', and 'height' properties. */
2638 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2639 it
->space_width
= Qnil
;
2640 it
->font_height
= Qnil
;
2641 it
->override_ascent
= -1;
2643 /* Are control characters displayed as `^C'? */
2644 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2646 /* -1 means everything between a CR and the following line end
2647 is invisible. >0 means lines indented more than this value are
2649 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2650 ? XFASTINT (current_buffer
->selective_display
)
2651 : (!NILP (current_buffer
->selective_display
)
2653 it
->selective_display_ellipsis_p
2654 = !NILP (current_buffer
->selective_display_ellipses
);
2656 /* Display table to use. */
2657 it
->dp
= window_display_table (w
);
2659 /* Are multibyte characters enabled in current_buffer? */
2660 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2662 /* Do we need to reorder bidirectional text? */
2663 it
->bidi_p
= !NILP (current_buffer
->bidi_display_reordering
);
2665 /* Non-zero if we should highlight the region. */
2667 = (!NILP (Vtransient_mark_mode
)
2668 && !NILP (current_buffer
->mark_active
)
2669 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2671 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2672 start and end of a visible region in window IT->w. Set both to
2673 -1 to indicate no region. */
2674 if (highlight_region_p
2675 /* Maybe highlight only in selected window. */
2676 && (/* Either show region everywhere. */
2677 highlight_nonselected_windows
2678 /* Or show region in the selected window. */
2679 || w
== XWINDOW (selected_window
)
2680 /* Or show the region if we are in the mini-buffer and W is
2681 the window the mini-buffer refers to. */
2682 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2683 && WINDOWP (minibuf_selected_window
)
2684 && w
== XWINDOW (minibuf_selected_window
))))
2686 int charpos
= marker_position (current_buffer
->mark
);
2687 it
->region_beg_charpos
= min (PT
, charpos
);
2688 it
->region_end_charpos
= max (PT
, charpos
);
2691 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2693 /* Get the position at which the redisplay_end_trigger hook should
2694 be run, if it is to be run at all. */
2695 if (MARKERP (w
->redisplay_end_trigger
)
2696 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2697 it
->redisplay_end_trigger_charpos
2698 = marker_position (w
->redisplay_end_trigger
);
2699 else if (INTEGERP (w
->redisplay_end_trigger
))
2700 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2702 /* Correct bogus values of tab_width. */
2703 it
->tab_width
= XINT (current_buffer
->tab_width
);
2704 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2707 /* Are lines in the display truncated? */
2708 if (base_face_id
!= DEFAULT_FACE_ID
2709 || XINT (it
->w
->hscroll
)
2710 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2711 && ((!NILP (Vtruncate_partial_width_windows
)
2712 && !INTEGERP (Vtruncate_partial_width_windows
))
2713 || (INTEGERP (Vtruncate_partial_width_windows
)
2714 && (WINDOW_TOTAL_COLS (it
->w
)
2715 < XINT (Vtruncate_partial_width_windows
))))))
2716 it
->line_wrap
= TRUNCATE
;
2717 else if (NILP (current_buffer
->truncate_lines
))
2718 it
->line_wrap
= NILP (current_buffer
->word_wrap
)
2719 ? WINDOW_WRAP
: WORD_WRAP
;
2721 it
->line_wrap
= TRUNCATE
;
2723 /* Get dimensions of truncation and continuation glyphs. These are
2724 displayed as fringe bitmaps under X, so we don't need them for such
2726 if (!FRAME_WINDOW_P (it
->f
))
2728 if (it
->line_wrap
== TRUNCATE
)
2730 /* We will need the truncation glyph. */
2731 xassert (it
->glyph_row
== NULL
);
2732 produce_special_glyphs (it
, IT_TRUNCATION
);
2733 it
->truncation_pixel_width
= it
->pixel_width
;
2737 /* We will need the continuation glyph. */
2738 xassert (it
->glyph_row
== NULL
);
2739 produce_special_glyphs (it
, IT_CONTINUATION
);
2740 it
->continuation_pixel_width
= it
->pixel_width
;
2743 /* Reset these values to zero because the produce_special_glyphs
2744 above has changed them. */
2745 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2746 it
->phys_ascent
= it
->phys_descent
= 0;
2749 /* Set this after getting the dimensions of truncation and
2750 continuation glyphs, so that we don't produce glyphs when calling
2751 produce_special_glyphs, above. */
2752 it
->glyph_row
= row
;
2753 it
->area
= TEXT_AREA
;
2755 /* Get the dimensions of the display area. The display area
2756 consists of the visible window area plus a horizontally scrolled
2757 part to the left of the window. All x-values are relative to the
2758 start of this total display area. */
2759 if (base_face_id
!= DEFAULT_FACE_ID
)
2761 /* Mode lines, menu bar in terminal frames. */
2762 it
->first_visible_x
= 0;
2763 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2768 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2769 it
->last_visible_x
= (it
->first_visible_x
2770 + window_box_width (w
, TEXT_AREA
));
2772 /* If we truncate lines, leave room for the truncator glyph(s) at
2773 the right margin. Otherwise, leave room for the continuation
2774 glyph(s). Truncation and continuation glyphs are not inserted
2775 for window-based redisplay. */
2776 if (!FRAME_WINDOW_P (it
->f
))
2778 if (it
->line_wrap
== TRUNCATE
)
2779 it
->last_visible_x
-= it
->truncation_pixel_width
;
2781 it
->last_visible_x
-= it
->continuation_pixel_width
;
2784 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2785 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2788 /* Leave room for a border glyph. */
2789 if (!FRAME_WINDOW_P (it
->f
)
2790 && !WINDOW_RIGHTMOST_P (it
->w
))
2791 it
->last_visible_x
-= 1;
2793 it
->last_visible_y
= window_text_bottom_y (w
);
2795 /* For mode lines and alike, arrange for the first glyph having a
2796 left box line if the face specifies a box. */
2797 if (base_face_id
!= DEFAULT_FACE_ID
)
2801 it
->face_id
= remapped_base_face_id
;
2803 /* If we have a boxed mode line, make the first character appear
2804 with a left box line. */
2805 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2806 if (face
->box
!= FACE_NO_BOX
)
2807 it
->start_of_box_run_p
= 1;
2810 /* If we are to reorder bidirectional text, init the bidi
2814 /* Note the paragraph direction that this buffer wants to
2816 if (EQ (current_buffer
->bidi_paragraph_direction
, Qleft_to_right
))
2817 it
->paragraph_embedding
= L2R
;
2818 else if (EQ (current_buffer
->bidi_paragraph_direction
, Qright_to_left
))
2819 it
->paragraph_embedding
= R2L
;
2821 it
->paragraph_embedding
= NEUTRAL_DIR
;
2822 bidi_init_it (charpos
, bytepos
, &it
->bidi_it
);
2825 /* If a buffer position was specified, set the iterator there,
2826 getting overlays and face properties from that position. */
2827 if (charpos
>= BUF_BEG (current_buffer
))
2829 it
->end_charpos
= ZV
;
2831 IT_CHARPOS (*it
) = charpos
;
2833 /* Compute byte position if not specified. */
2834 if (bytepos
< charpos
)
2835 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2837 IT_BYTEPOS (*it
) = bytepos
;
2839 it
->start
= it
->current
;
2841 /* Compute faces etc. */
2842 reseat (it
, it
->current
.pos
, 1);
2849 /* Initialize IT for the display of window W with window start POS. */
2852 start_display (it
, w
, pos
)
2855 struct text_pos pos
;
2857 struct glyph_row
*row
;
2858 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2860 row
= w
->desired_matrix
->rows
+ first_vpos
;
2861 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2862 it
->first_vpos
= first_vpos
;
2864 /* Don't reseat to previous visible line start if current start
2865 position is in a string or image. */
2866 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2868 int start_at_line_beg_p
;
2869 int first_y
= it
->current_y
;
2871 /* If window start is not at a line start, skip forward to POS to
2872 get the correct continuation lines width. */
2873 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2874 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2875 if (!start_at_line_beg_p
)
2879 reseat_at_previous_visible_line_start (it
);
2880 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2882 new_x
= it
->current_x
+ it
->pixel_width
;
2884 /* If lines are continued, this line may end in the middle
2885 of a multi-glyph character (e.g. a control character
2886 displayed as \003, or in the middle of an overlay
2887 string). In this case move_it_to above will not have
2888 taken us to the start of the continuation line but to the
2889 end of the continued line. */
2890 if (it
->current_x
> 0
2891 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2892 && (/* And glyph doesn't fit on the line. */
2893 new_x
> it
->last_visible_x
2894 /* Or it fits exactly and we're on a window
2896 || (new_x
== it
->last_visible_x
2897 && FRAME_WINDOW_P (it
->f
))))
2899 if (it
->current
.dpvec_index
>= 0
2900 || it
->current
.overlay_string_index
>= 0)
2902 set_iterator_to_next (it
, 1);
2903 move_it_in_display_line_to (it
, -1, -1, 0);
2906 it
->continuation_lines_width
+= it
->current_x
;
2909 /* We're starting a new display line, not affected by the
2910 height of the continued line, so clear the appropriate
2911 fields in the iterator structure. */
2912 it
->max_ascent
= it
->max_descent
= 0;
2913 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2915 it
->current_y
= first_y
;
2917 it
->current_x
= it
->hpos
= 0;
2923 /* Return 1 if POS is a position in ellipses displayed for invisible
2924 text. W is the window we display, for text property lookup. */
2927 in_ellipses_for_invisible_text_p (pos
, w
)
2928 struct display_pos
*pos
;
2931 Lisp_Object prop
, window
;
2933 int charpos
= CHARPOS (pos
->pos
);
2935 /* If POS specifies a position in a display vector, this might
2936 be for an ellipsis displayed for invisible text. We won't
2937 get the iterator set up for delivering that ellipsis unless
2938 we make sure that it gets aware of the invisible text. */
2939 if (pos
->dpvec_index
>= 0
2940 && pos
->overlay_string_index
< 0
2941 && CHARPOS (pos
->string_pos
) < 0
2943 && (XSETWINDOW (window
, w
),
2944 prop
= Fget_char_property (make_number (charpos
),
2945 Qinvisible
, window
),
2946 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2948 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2950 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2957 /* Initialize IT for stepping through current_buffer in window W,
2958 starting at position POS that includes overlay string and display
2959 vector/ control character translation position information. Value
2960 is zero if there are overlay strings with newlines at POS. */
2963 init_from_display_pos (it
, w
, pos
)
2966 struct display_pos
*pos
;
2968 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2969 int i
, overlay_strings_with_newlines
= 0;
2971 /* If POS specifies a position in a display vector, this might
2972 be for an ellipsis displayed for invisible text. We won't
2973 get the iterator set up for delivering that ellipsis unless
2974 we make sure that it gets aware of the invisible text. */
2975 if (in_ellipses_for_invisible_text_p (pos
, w
))
2981 /* Keep in mind: the call to reseat in init_iterator skips invisible
2982 text, so we might end up at a position different from POS. This
2983 is only a problem when POS is a row start after a newline and an
2984 overlay starts there with an after-string, and the overlay has an
2985 invisible property. Since we don't skip invisible text in
2986 display_line and elsewhere immediately after consuming the
2987 newline before the row start, such a POS will not be in a string,
2988 but the call to init_iterator below will move us to the
2990 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2992 /* This only scans the current chunk -- it should scan all chunks.
2993 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2994 to 16 in 22.1 to make this a lesser problem. */
2995 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2997 const char *s
= SDATA (it
->overlay_strings
[i
]);
2998 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3000 while (s
< e
&& *s
!= '\n')
3005 overlay_strings_with_newlines
= 1;
3010 /* If position is within an overlay string, set up IT to the right
3012 if (pos
->overlay_string_index
>= 0)
3016 /* If the first overlay string happens to have a `display'
3017 property for an image, the iterator will be set up for that
3018 image, and we have to undo that setup first before we can
3019 correct the overlay string index. */
3020 if (it
->method
== GET_FROM_IMAGE
)
3023 /* We already have the first chunk of overlay strings in
3024 IT->overlay_strings. Load more until the one for
3025 pos->overlay_string_index is in IT->overlay_strings. */
3026 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3028 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3029 it
->current
.overlay_string_index
= 0;
3032 load_overlay_strings (it
, 0);
3033 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3037 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3038 relative_index
= (it
->current
.overlay_string_index
3039 % OVERLAY_STRING_CHUNK_SIZE
);
3040 it
->string
= it
->overlay_strings
[relative_index
];
3041 xassert (STRINGP (it
->string
));
3042 it
->current
.string_pos
= pos
->string_pos
;
3043 it
->method
= GET_FROM_STRING
;
3046 if (CHARPOS (pos
->string_pos
) >= 0)
3048 /* Recorded position is not in an overlay string, but in another
3049 string. This can only be a string from a `display' property.
3050 IT should already be filled with that string. */
3051 it
->current
.string_pos
= pos
->string_pos
;
3052 xassert (STRINGP (it
->string
));
3055 /* Restore position in display vector translations, control
3056 character translations or ellipses. */
3057 if (pos
->dpvec_index
>= 0)
3059 if (it
->dpvec
== NULL
)
3060 get_next_display_element (it
);
3061 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3062 it
->current
.dpvec_index
= pos
->dpvec_index
;
3066 return !overlay_strings_with_newlines
;
3070 /* Initialize IT for stepping through current_buffer in window W
3071 starting at ROW->start. */
3074 init_to_row_start (it
, w
, row
)
3077 struct glyph_row
*row
;
3079 init_from_display_pos (it
, w
, &row
->start
);
3080 it
->start
= row
->start
;
3081 it
->continuation_lines_width
= row
->continuation_lines_width
;
3086 /* Initialize IT for stepping through current_buffer in window W
3087 starting in the line following ROW, i.e. starting at ROW->end.
3088 Value is zero if there are overlay strings with newlines at ROW's
3092 init_to_row_end (it
, w
, row
)
3095 struct glyph_row
*row
;
3099 if (init_from_display_pos (it
, w
, &row
->end
))
3101 if (row
->continued_p
)
3102 it
->continuation_lines_width
3103 = row
->continuation_lines_width
+ row
->pixel_width
;
3114 /***********************************************************************
3116 ***********************************************************************/
3118 /* Called when IT reaches IT->stop_charpos. Handle text property and
3119 overlay changes. Set IT->stop_charpos to the next position where
3126 enum prop_handled handled
;
3127 int handle_overlay_change_p
;
3131 it
->current
.dpvec_index
= -1;
3132 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3133 it
->ignore_overlay_strings_at_pos_p
= 0;
3136 /* Use face of preceding text for ellipsis (if invisible) */
3137 if (it
->selective_display_ellipsis_p
)
3138 it
->saved_face_id
= it
->face_id
;
3142 handled
= HANDLED_NORMALLY
;
3144 /* Call text property handlers. */
3145 for (p
= it_props
; p
->handler
; ++p
)
3147 handled
= p
->handler (it
);
3149 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3151 else if (handled
== HANDLED_RETURN
)
3153 /* We still want to show before and after strings from
3154 overlays even if the actual buffer text is replaced. */
3155 if (!handle_overlay_change_p
3157 || !get_overlay_strings_1 (it
, 0, 0))
3160 setup_for_ellipsis (it
, 0);
3161 /* When handling a display spec, we might load an
3162 empty string. In that case, discard it here. We
3163 used to discard it in handle_single_display_spec,
3164 but that causes get_overlay_strings_1, above, to
3165 ignore overlay strings that we must check. */
3166 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3170 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3174 it
->ignore_overlay_strings_at_pos_p
= 1;
3175 it
->string_from_display_prop_p
= 0;
3176 handle_overlay_change_p
= 0;
3178 handled
= HANDLED_RECOMPUTE_PROPS
;
3181 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3182 handle_overlay_change_p
= 0;
3185 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3187 /* Don't check for overlay strings below when set to deliver
3188 characters from a display vector. */
3189 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3190 handle_overlay_change_p
= 0;
3192 /* Handle overlay changes.
3193 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3194 if it finds overlays. */
3195 if (handle_overlay_change_p
)
3196 handled
= handle_overlay_change (it
);
3201 setup_for_ellipsis (it
, 0);
3205 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3207 /* Determine where to stop next. */
3208 if (handled
== HANDLED_NORMALLY
)
3209 compute_stop_pos (it
);
3213 /* Compute IT->stop_charpos from text property and overlay change
3214 information for IT's current position. */
3217 compute_stop_pos (it
)
3220 register INTERVAL iv
, next_iv
;
3221 Lisp_Object object
, limit
, position
;
3222 EMACS_INT charpos
, bytepos
;
3224 /* If nowhere else, stop at the end. */
3225 it
->stop_charpos
= it
->end_charpos
;
3227 if (STRINGP (it
->string
))
3229 /* Strings are usually short, so don't limit the search for
3231 object
= it
->string
;
3233 charpos
= IT_STRING_CHARPOS (*it
);
3234 bytepos
= IT_STRING_BYTEPOS (*it
);
3240 /* If next overlay change is in front of the current stop pos
3241 (which is IT->end_charpos), stop there. Note: value of
3242 next_overlay_change is point-max if no overlay change
3244 charpos
= IT_CHARPOS (*it
);
3245 bytepos
= IT_BYTEPOS (*it
);
3246 pos
= next_overlay_change (charpos
);
3247 if (pos
< it
->stop_charpos
)
3248 it
->stop_charpos
= pos
;
3250 /* If showing the region, we have to stop at the region
3251 start or end because the face might change there. */
3252 if (it
->region_beg_charpos
> 0)
3254 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3255 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3256 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3257 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3260 /* Set up variables for computing the stop position from text
3261 property changes. */
3262 XSETBUFFER (object
, current_buffer
);
3263 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3266 /* Get the interval containing IT's position. Value is a null
3267 interval if there isn't such an interval. */
3268 position
= make_number (charpos
);
3269 iv
= validate_interval_range (object
, &position
, &position
, 0);
3270 if (!NULL_INTERVAL_P (iv
))
3272 Lisp_Object values_here
[LAST_PROP_IDX
];
3275 /* Get properties here. */
3276 for (p
= it_props
; p
->handler
; ++p
)
3277 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3279 /* Look for an interval following iv that has different
3281 for (next_iv
= next_interval (iv
);
3282 (!NULL_INTERVAL_P (next_iv
)
3284 || XFASTINT (limit
) > next_iv
->position
));
3285 next_iv
= next_interval (next_iv
))
3287 for (p
= it_props
; p
->handler
; ++p
)
3289 Lisp_Object new_value
;
3291 new_value
= textget (next_iv
->plist
, *p
->name
);
3292 if (!EQ (values_here
[p
->idx
], new_value
))
3300 if (!NULL_INTERVAL_P (next_iv
))
3302 if (INTEGERP (limit
)
3303 && next_iv
->position
>= XFASTINT (limit
))
3304 /* No text property change up to limit. */
3305 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3307 /* Text properties change in next_iv. */
3308 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3312 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3313 it
->stop_charpos
, it
->string
);
3315 xassert (STRINGP (it
->string
)
3316 || (it
->stop_charpos
>= BEGV
3317 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3321 /* Return the position of the next overlay change after POS in
3322 current_buffer. Value is point-max if no overlay change
3323 follows. This is like `next-overlay-change' but doesn't use
3327 next_overlay_change (pos
)
3332 Lisp_Object
*overlays
;
3335 /* Get all overlays at the given position. */
3336 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3338 /* If any of these overlays ends before endpos,
3339 use its ending point instead. */
3340 for (i
= 0; i
< noverlays
; ++i
)
3345 oend
= OVERLAY_END (overlays
[i
]);
3346 oendpos
= OVERLAY_POSITION (oend
);
3347 endpos
= min (endpos
, oendpos
);
3355 /***********************************************************************
3357 ***********************************************************************/
3359 /* Handle changes in the `fontified' property of the current buffer by
3360 calling hook functions from Qfontification_functions to fontify
3363 static enum prop_handled
3364 handle_fontified_prop (it
)
3367 Lisp_Object prop
, pos
;
3368 enum prop_handled handled
= HANDLED_NORMALLY
;
3370 if (!NILP (Vmemory_full
))
3373 /* Get the value of the `fontified' property at IT's current buffer
3374 position. (The `fontified' property doesn't have a special
3375 meaning in strings.) If the value is nil, call functions from
3376 Qfontification_functions. */
3377 if (!STRINGP (it
->string
)
3379 && !NILP (Vfontification_functions
)
3380 && !NILP (Vrun_hooks
)
3381 && (pos
= make_number (IT_CHARPOS (*it
)),
3382 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3383 /* Ignore the special cased nil value always present at EOB since
3384 no amount of fontifying will be able to change it. */
3385 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3387 int count
= SPECPDL_INDEX ();
3390 val
= Vfontification_functions
;
3391 specbind (Qfontification_functions
, Qnil
);
3393 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3394 safe_call1 (val
, pos
);
3397 Lisp_Object globals
, fn
;
3398 struct gcpro gcpro1
, gcpro2
;
3401 GCPRO2 (val
, globals
);
3403 for (; CONSP (val
); val
= XCDR (val
))
3409 /* A value of t indicates this hook has a local
3410 binding; it means to run the global binding too.
3411 In a global value, t should not occur. If it
3412 does, we must ignore it to avoid an endless
3414 for (globals
= Fdefault_value (Qfontification_functions
);
3416 globals
= XCDR (globals
))
3418 fn
= XCAR (globals
);
3420 safe_call1 (fn
, pos
);
3424 safe_call1 (fn
, pos
);
3430 unbind_to (count
, Qnil
);
3432 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3433 something. This avoids an endless loop if they failed to
3434 fontify the text for which reason ever. */
3435 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3436 handled
= HANDLED_RECOMPUTE_PROPS
;
3444 /***********************************************************************
3446 ***********************************************************************/
3448 /* Set up iterator IT from face properties at its current position.
3449 Called from handle_stop. */
3451 static enum prop_handled
3452 handle_face_prop (it
)
3456 EMACS_INT next_stop
;
3458 if (!STRINGP (it
->string
))
3461 = face_at_buffer_position (it
->w
,
3463 it
->region_beg_charpos
,
3464 it
->region_end_charpos
,
3467 + TEXT_PROP_DISTANCE_LIMIT
),
3468 0, it
->base_face_id
);
3470 /* Is this a start of a run of characters with box face?
3471 Caveat: this can be called for a freshly initialized
3472 iterator; face_id is -1 in this case. We know that the new
3473 face will not change until limit, i.e. if the new face has a
3474 box, all characters up to limit will have one. But, as
3475 usual, we don't know whether limit is really the end. */
3476 if (new_face_id
!= it
->face_id
)
3478 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3480 /* If new face has a box but old face has not, this is
3481 the start of a run of characters with box, i.e. it has
3482 a shadow on the left side. The value of face_id of the
3483 iterator will be -1 if this is the initial call that gets
3484 the face. In this case, we have to look in front of IT's
3485 position and see whether there is a face != new_face_id. */
3486 it
->start_of_box_run_p
3487 = (new_face
->box
!= FACE_NO_BOX
3488 && (it
->face_id
>= 0
3489 || IT_CHARPOS (*it
) == BEG
3490 || new_face_id
!= face_before_it_pos (it
)));
3491 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3496 int base_face_id
, bufpos
;
3498 Lisp_Object from_overlay
3499 = (it
->current
.overlay_string_index
>= 0
3500 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3503 /* See if we got to this string directly or indirectly from
3504 an overlay property. That includes the before-string or
3505 after-string of an overlay, strings in display properties
3506 provided by an overlay, their text properties, etc.
3508 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3509 if (! NILP (from_overlay
))
3510 for (i
= it
->sp
- 1; i
>= 0; i
--)
3512 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3514 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3515 else if (! NILP (it
->stack
[i
].from_overlay
))
3516 from_overlay
= it
->stack
[i
].from_overlay
;
3518 if (!NILP (from_overlay
))
3522 if (! NILP (from_overlay
))
3524 bufpos
= IT_CHARPOS (*it
);
3525 /* For a string from an overlay, the base face depends
3526 only on text properties and ignores overlays. */
3528 = face_for_overlay_string (it
->w
,
3530 it
->region_beg_charpos
,
3531 it
->region_end_charpos
,
3534 + TEXT_PROP_DISTANCE_LIMIT
),
3542 /* For strings from a `display' property, use the face at
3543 IT's current buffer position as the base face to merge
3544 with, so that overlay strings appear in the same face as
3545 surrounding text, unless they specify their own
3547 base_face_id
= underlying_face_id (it
);
3550 new_face_id
= face_at_string_position (it
->w
,
3552 IT_STRING_CHARPOS (*it
),
3554 it
->region_beg_charpos
,
3555 it
->region_end_charpos
,
3559 /* Is this a start of a run of characters with box? Caveat:
3560 this can be called for a freshly allocated iterator; face_id
3561 is -1 is this case. We know that the new face will not
3562 change until the next check pos, i.e. if the new face has a
3563 box, all characters up to that position will have a
3564 box. But, as usual, we don't know whether that position
3565 is really the end. */
3566 if (new_face_id
!= it
->face_id
)
3568 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3569 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3571 /* If new face has a box but old face hasn't, this is the
3572 start of a run of characters with box, i.e. it has a
3573 shadow on the left side. */
3574 it
->start_of_box_run_p
3575 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3576 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3580 it
->face_id
= new_face_id
;
3581 return HANDLED_NORMALLY
;
3585 /* Return the ID of the face ``underlying'' IT's current position,
3586 which is in a string. If the iterator is associated with a
3587 buffer, return the face at IT's current buffer position.
3588 Otherwise, use the iterator's base_face_id. */
3591 underlying_face_id (it
)
3594 int face_id
= it
->base_face_id
, i
;
3596 xassert (STRINGP (it
->string
));
3598 for (i
= it
->sp
- 1; i
>= 0; --i
)
3599 if (NILP (it
->stack
[i
].string
))
3600 face_id
= it
->stack
[i
].face_id
;
3606 /* Compute the face one character before or after the current position
3607 of IT. BEFORE_P non-zero means get the face in front of IT's
3608 position. Value is the id of the face. */
3611 face_before_or_after_it_pos (it
, before_p
)
3616 EMACS_INT next_check_charpos
;
3617 struct text_pos pos
;
3619 xassert (it
->s
== NULL
);
3621 if (STRINGP (it
->string
))
3623 int bufpos
, base_face_id
;
3625 /* No face change past the end of the string (for the case
3626 we are padding with spaces). No face change before the
3628 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3629 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3632 /* Set pos to the position before or after IT's current position. */
3634 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3636 /* For composition, we must check the character after the
3638 pos
= (it
->what
== IT_COMPOSITION
3639 ? string_pos (IT_STRING_CHARPOS (*it
)
3640 + it
->cmp_it
.nchars
, it
->string
)
3641 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3643 if (it
->current
.overlay_string_index
>= 0)
3644 bufpos
= IT_CHARPOS (*it
);
3648 base_face_id
= underlying_face_id (it
);
3650 /* Get the face for ASCII, or unibyte. */
3651 face_id
= face_at_string_position (it
->w
,
3655 it
->region_beg_charpos
,
3656 it
->region_end_charpos
,
3657 &next_check_charpos
,
3660 /* Correct the face for charsets different from ASCII. Do it
3661 for the multibyte case only. The face returned above is
3662 suitable for unibyte text if IT->string is unibyte. */
3663 if (STRING_MULTIBYTE (it
->string
))
3665 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3666 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3668 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3670 c
= string_char_and_length (p
, &len
);
3671 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3676 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3677 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3680 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3681 pos
= it
->current
.pos
;
3684 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3687 if (it
->what
== IT_COMPOSITION
)
3688 /* For composition, we must check the position after the
3690 pos
.charpos
+= it
->cmp_it
.nchars
, pos
.bytepos
+= it
->len
;
3692 INC_TEXT_POS (pos
, it
->multibyte_p
);
3695 /* Determine face for CHARSET_ASCII, or unibyte. */
3696 face_id
= face_at_buffer_position (it
->w
,
3698 it
->region_beg_charpos
,
3699 it
->region_end_charpos
,
3700 &next_check_charpos
,
3703 /* Correct the face for charsets different from ASCII. Do it
3704 for the multibyte case only. The face returned above is
3705 suitable for unibyte text if current_buffer is unibyte. */
3706 if (it
->multibyte_p
)
3708 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3709 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3710 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3719 /***********************************************************************
3721 ***********************************************************************/
3723 /* Set up iterator IT from invisible properties at its current
3724 position. Called from handle_stop. */
3726 static enum prop_handled
3727 handle_invisible_prop (it
)
3730 enum prop_handled handled
= HANDLED_NORMALLY
;
3732 if (STRINGP (it
->string
))
3734 extern Lisp_Object Qinvisible
;
3735 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3737 /* Get the value of the invisible text property at the
3738 current position. Value will be nil if there is no such
3740 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3741 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3744 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3746 handled
= HANDLED_RECOMPUTE_PROPS
;
3748 /* Get the position at which the next change of the
3749 invisible text property can be found in IT->string.
3750 Value will be nil if the property value is the same for
3751 all the rest of IT->string. */
3752 XSETINT (limit
, SCHARS (it
->string
));
3753 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3756 /* Text at current position is invisible. The next
3757 change in the property is at position end_charpos.
3758 Move IT's current position to that position. */
3759 if (INTEGERP (end_charpos
)
3760 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3762 struct text_pos old
;
3763 old
= it
->current
.string_pos
;
3764 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3765 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3769 /* The rest of the string is invisible. If this is an
3770 overlay string, proceed with the next overlay string
3771 or whatever comes and return a character from there. */
3772 if (it
->current
.overlay_string_index
>= 0)
3774 next_overlay_string (it
);
3775 /* Don't check for overlay strings when we just
3776 finished processing them. */
3777 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3781 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3782 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3790 EMACS_INT newpos
, next_stop
, start_charpos
;
3791 Lisp_Object pos
, prop
, overlay
;
3793 /* First of all, is there invisible text at this position? */
3794 start_charpos
= IT_CHARPOS (*it
);
3795 pos
= make_number (IT_CHARPOS (*it
));
3796 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3798 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3800 /* If we are on invisible text, skip over it. */
3801 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3803 /* Record whether we have to display an ellipsis for the
3805 int display_ellipsis_p
= invis_p
== 2;
3807 handled
= HANDLED_RECOMPUTE_PROPS
;
3809 /* Loop skipping over invisible text. The loop is left at
3810 ZV or with IT on the first char being visible again. */
3813 /* Try to skip some invisible text. Return value is the
3814 position reached which can be equal to IT's position
3815 if there is nothing invisible here. This skips both
3816 over invisible text properties and overlays with
3817 invisible property. */
3818 newpos
= skip_invisible (IT_CHARPOS (*it
),
3819 &next_stop
, ZV
, it
->window
);
3821 /* If we skipped nothing at all we weren't at invisible
3822 text in the first place. If everything to the end of
3823 the buffer was skipped, end the loop. */
3824 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3828 /* We skipped some characters but not necessarily
3829 all there are. Check if we ended up on visible
3830 text. Fget_char_property returns the property of
3831 the char before the given position, i.e. if we
3832 get invis_p = 0, this means that the char at
3833 newpos is visible. */
3834 pos
= make_number (newpos
);
3835 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3836 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3839 /* If we ended up on invisible text, proceed to
3840 skip starting with next_stop. */
3842 IT_CHARPOS (*it
) = next_stop
;
3844 /* If there are adjacent invisible texts, don't lose the
3845 second one's ellipsis. */
3847 display_ellipsis_p
= 1;
3851 /* The position newpos is now either ZV or on visible text. */
3852 IT_CHARPOS (*it
) = newpos
;
3853 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3855 /* If there are before-strings at the start of invisible
3856 text, and the text is invisible because of a text
3857 property, arrange to show before-strings because 20.x did
3858 it that way. (If the text is invisible because of an
3859 overlay property instead of a text property, this is
3860 already handled in the overlay code.) */
3862 && get_overlay_strings (it
, start_charpos
))
3864 handled
= HANDLED_RECOMPUTE_PROPS
;
3865 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3867 else if (display_ellipsis_p
)
3869 /* Make sure that the glyphs of the ellipsis will get
3870 correct `charpos' values. If we would not update
3871 it->position here, the glyphs would belong to the
3872 last visible character _before_ the invisible
3873 text, which confuses `set_cursor_from_row'.
3875 We use the last invisible position instead of the
3876 first because this way the cursor is always drawn on
3877 the first "." of the ellipsis, whenever PT is inside
3878 the invisible text. Otherwise the cursor would be
3879 placed _after_ the ellipsis when the point is after the
3880 first invisible character. */
3881 if (!STRINGP (it
->object
))
3883 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3884 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3887 /* Let the ellipsis display before
3888 considering any properties of the following char.
3889 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3890 handled
= HANDLED_RETURN
;
3899 /* Make iterator IT return `...' next.
3900 Replaces LEN characters from buffer. */
3903 setup_for_ellipsis (it
, len
)
3907 /* Use the display table definition for `...'. Invalid glyphs
3908 will be handled by the method returning elements from dpvec. */
3909 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3911 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3912 it
->dpvec
= v
->contents
;
3913 it
->dpend
= v
->contents
+ v
->size
;
3917 /* Default `...'. */
3918 it
->dpvec
= default_invis_vector
;
3919 it
->dpend
= default_invis_vector
+ 3;
3922 it
->dpvec_char_len
= len
;
3923 it
->current
.dpvec_index
= 0;
3924 it
->dpvec_face_id
= -1;
3926 /* Remember the current face id in case glyphs specify faces.
3927 IT's face is restored in set_iterator_to_next.
3928 saved_face_id was set to preceding char's face in handle_stop. */
3929 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3930 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3932 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3938 /***********************************************************************
3940 ***********************************************************************/
3942 /* Set up iterator IT from `display' property at its current position.
3943 Called from handle_stop.
3944 We return HANDLED_RETURN if some part of the display property
3945 overrides the display of the buffer text itself.
3946 Otherwise we return HANDLED_NORMALLY. */
3948 static enum prop_handled
3949 handle_display_prop (it
)
3952 Lisp_Object prop
, object
, overlay
;
3953 struct text_pos
*position
;
3954 /* Nonzero if some property replaces the display of the text itself. */
3955 int display_replaced_p
= 0;
3957 if (STRINGP (it
->string
))
3959 object
= it
->string
;
3960 position
= &it
->current
.string_pos
;
3964 XSETWINDOW (object
, it
->w
);
3965 position
= &it
->current
.pos
;
3968 /* Reset those iterator values set from display property values. */
3969 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3970 it
->space_width
= Qnil
;
3971 it
->font_height
= Qnil
;
3974 /* We don't support recursive `display' properties, i.e. string
3975 values that have a string `display' property, that have a string
3976 `display' property etc. */
3977 if (!it
->string_from_display_prop_p
)
3978 it
->area
= TEXT_AREA
;
3980 prop
= get_char_property_and_overlay (make_number (position
->charpos
),
3981 Qdisplay
, object
, &overlay
);
3983 return HANDLED_NORMALLY
;
3984 /* Now OVERLAY is the overlay that gave us this property, or nil
3985 if it was a text property. */
3987 if (!STRINGP (it
->string
))
3988 object
= it
->w
->buffer
;
3991 /* Simple properties. */
3992 && !EQ (XCAR (prop
), Qimage
)
3993 && !EQ (XCAR (prop
), Qspace
)
3994 && !EQ (XCAR (prop
), Qwhen
)
3995 && !EQ (XCAR (prop
), Qslice
)
3996 && !EQ (XCAR (prop
), Qspace_width
)
3997 && !EQ (XCAR (prop
), Qheight
)
3998 && !EQ (XCAR (prop
), Qraise
)
3999 /* Marginal area specifications. */
4000 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
4001 && !EQ (XCAR (prop
), Qleft_fringe
)
4002 && !EQ (XCAR (prop
), Qright_fringe
)
4003 && !NILP (XCAR (prop
)))
4005 for (; CONSP (prop
); prop
= XCDR (prop
))
4007 if (handle_single_display_spec (it
, XCAR (prop
), object
, overlay
,
4008 position
, display_replaced_p
))
4010 display_replaced_p
= 1;
4011 /* If some text in a string is replaced, `position' no
4012 longer points to the position of `object'. */
4013 if (STRINGP (object
))
4018 else if (VECTORP (prop
))
4021 for (i
= 0; i
< ASIZE (prop
); ++i
)
4022 if (handle_single_display_spec (it
, AREF (prop
, i
), object
, overlay
,
4023 position
, display_replaced_p
))
4025 display_replaced_p
= 1;
4026 /* If some text in a string is replaced, `position' no
4027 longer points to the position of `object'. */
4028 if (STRINGP (object
))
4034 if (handle_single_display_spec (it
, prop
, object
, overlay
,
4036 display_replaced_p
= 1;
4039 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4043 /* Value is the position of the end of the `display' property starting
4044 at START_POS in OBJECT. */
4046 static struct text_pos
4047 display_prop_end (it
, object
, start_pos
)
4050 struct text_pos start_pos
;
4053 struct text_pos end_pos
;
4055 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4056 Qdisplay
, object
, Qnil
);
4057 CHARPOS (end_pos
) = XFASTINT (end
);
4058 if (STRINGP (object
))
4059 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4061 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4067 /* Set up IT from a single `display' specification PROP. OBJECT
4068 is the object in which the `display' property was found. *POSITION
4069 is the position at which it was found. DISPLAY_REPLACED_P non-zero
4070 means that we previously saw a display specification which already
4071 replaced text display with something else, for example an image;
4072 we ignore such properties after the first one has been processed.
4074 OVERLAY is the overlay this `display' property came from,
4075 or nil if it was a text property.
4077 If PROP is a `space' or `image' specification, and in some other
4078 cases too, set *POSITION to the position where the `display'
4081 Value is non-zero if something was found which replaces the display
4082 of buffer or string text. */
4085 handle_single_display_spec (it
, spec
, object
, overlay
, position
,
4086 display_replaced_before_p
)
4090 Lisp_Object overlay
;
4091 struct text_pos
*position
;
4092 int display_replaced_before_p
;
4095 Lisp_Object location
, value
;
4096 struct text_pos start_pos
, save_pos
;
4099 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4100 If the result is non-nil, use VALUE instead of SPEC. */
4102 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4111 if (!NILP (form
) && !EQ (form
, Qt
))
4113 int count
= SPECPDL_INDEX ();
4114 struct gcpro gcpro1
;
4116 /* Bind `object' to the object having the `display' property, a
4117 buffer or string. Bind `position' to the position in the
4118 object where the property was found, and `buffer-position'
4119 to the current position in the buffer. */
4120 specbind (Qobject
, object
);
4121 specbind (Qposition
, make_number (CHARPOS (*position
)));
4122 specbind (Qbuffer_position
,
4123 make_number (STRINGP (object
)
4124 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
4126 form
= safe_eval (form
);
4128 unbind_to (count
, Qnil
);
4134 /* Handle `(height HEIGHT)' specifications. */
4136 && EQ (XCAR (spec
), Qheight
)
4137 && CONSP (XCDR (spec
)))
4139 if (!FRAME_WINDOW_P (it
->f
))
4142 it
->font_height
= XCAR (XCDR (spec
));
4143 if (!NILP (it
->font_height
))
4145 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4146 int new_height
= -1;
4148 if (CONSP (it
->font_height
)
4149 && (EQ (XCAR (it
->font_height
), Qplus
)
4150 || EQ (XCAR (it
->font_height
), Qminus
))
4151 && CONSP (XCDR (it
->font_height
))
4152 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4154 /* `(+ N)' or `(- N)' where N is an integer. */
4155 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4156 if (EQ (XCAR (it
->font_height
), Qplus
))
4158 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4160 else if (FUNCTIONP (it
->font_height
))
4162 /* Call function with current height as argument.
4163 Value is the new height. */
4165 height
= safe_call1 (it
->font_height
,
4166 face
->lface
[LFACE_HEIGHT_INDEX
]);
4167 if (NUMBERP (height
))
4168 new_height
= XFLOATINT (height
);
4170 else if (NUMBERP (it
->font_height
))
4172 /* Value is a multiple of the canonical char height. */
4175 face
= FACE_FROM_ID (it
->f
,
4176 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4177 new_height
= (XFLOATINT (it
->font_height
)
4178 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4182 /* Evaluate IT->font_height with `height' bound to the
4183 current specified height to get the new height. */
4184 int count
= SPECPDL_INDEX ();
4186 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4187 value
= safe_eval (it
->font_height
);
4188 unbind_to (count
, Qnil
);
4190 if (NUMBERP (value
))
4191 new_height
= XFLOATINT (value
);
4195 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4201 /* Handle `(space-width WIDTH)'. */
4203 && EQ (XCAR (spec
), Qspace_width
)
4204 && CONSP (XCDR (spec
)))
4206 if (!FRAME_WINDOW_P (it
->f
))
4209 value
= XCAR (XCDR (spec
));
4210 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4211 it
->space_width
= value
;
4216 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4218 && EQ (XCAR (spec
), Qslice
))
4222 if (!FRAME_WINDOW_P (it
->f
))
4225 if (tem
= XCDR (spec
), CONSP (tem
))
4227 it
->slice
.x
= XCAR (tem
);
4228 if (tem
= XCDR (tem
), CONSP (tem
))
4230 it
->slice
.y
= XCAR (tem
);
4231 if (tem
= XCDR (tem
), CONSP (tem
))
4233 it
->slice
.width
= XCAR (tem
);
4234 if (tem
= XCDR (tem
), CONSP (tem
))
4235 it
->slice
.height
= XCAR (tem
);
4243 /* Handle `(raise FACTOR)'. */
4245 && EQ (XCAR (spec
), Qraise
)
4246 && CONSP (XCDR (spec
)))
4248 if (!FRAME_WINDOW_P (it
->f
))
4251 #ifdef HAVE_WINDOW_SYSTEM
4252 value
= XCAR (XCDR (spec
));
4253 if (NUMBERP (value
))
4255 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4256 it
->voffset
= - (XFLOATINT (value
)
4257 * (FONT_HEIGHT (face
->font
)));
4259 #endif /* HAVE_WINDOW_SYSTEM */
4264 /* Don't handle the other kinds of display specifications
4265 inside a string that we got from a `display' property. */
4266 if (it
->string_from_display_prop_p
)
4269 /* Characters having this form of property are not displayed, so
4270 we have to find the end of the property. */
4271 start_pos
= *position
;
4272 *position
= display_prop_end (it
, object
, start_pos
);
4275 /* Stop the scan at that end position--we assume that all
4276 text properties change there. */
4277 it
->stop_charpos
= position
->charpos
;
4279 /* Handle `(left-fringe BITMAP [FACE])'
4280 and `(right-fringe BITMAP [FACE])'. */
4282 && (EQ (XCAR (spec
), Qleft_fringe
)
4283 || EQ (XCAR (spec
), Qright_fringe
))
4284 && CONSP (XCDR (spec
)))
4286 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
4289 if (!FRAME_WINDOW_P (it
->f
))
4290 /* If we return here, POSITION has been advanced
4291 across the text with this property. */
4294 #ifdef HAVE_WINDOW_SYSTEM
4295 value
= XCAR (XCDR (spec
));
4296 if (!SYMBOLP (value
)
4297 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4298 /* If we return here, POSITION has been advanced
4299 across the text with this property. */
4302 if (CONSP (XCDR (XCDR (spec
))))
4304 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4305 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4311 /* Save current settings of IT so that we can restore them
4312 when we are finished with the glyph property value. */
4314 save_pos
= it
->position
;
4315 it
->position
= *position
;
4317 it
->position
= save_pos
;
4319 it
->area
= TEXT_AREA
;
4320 it
->what
= IT_IMAGE
;
4321 it
->image_id
= -1; /* no image */
4322 it
->position
= start_pos
;
4323 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4324 it
->method
= GET_FROM_IMAGE
;
4325 it
->from_overlay
= Qnil
;
4326 it
->face_id
= face_id
;
4328 /* Say that we haven't consumed the characters with
4329 `display' property yet. The call to pop_it in
4330 set_iterator_to_next will clean this up. */
4331 *position
= start_pos
;
4333 if (EQ (XCAR (spec
), Qleft_fringe
))
4335 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4336 it
->left_user_fringe_face_id
= face_id
;
4340 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4341 it
->right_user_fringe_face_id
= face_id
;
4343 #endif /* HAVE_WINDOW_SYSTEM */
4347 /* Prepare to handle `((margin left-margin) ...)',
4348 `((margin right-margin) ...)' and `((margin nil) ...)'
4349 prefixes for display specifications. */
4350 location
= Qunbound
;
4351 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4355 value
= XCDR (spec
);
4357 value
= XCAR (value
);
4360 if (EQ (XCAR (tem
), Qmargin
)
4361 && (tem
= XCDR (tem
),
4362 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4364 || EQ (tem
, Qleft_margin
)
4365 || EQ (tem
, Qright_margin
))))
4369 if (EQ (location
, Qunbound
))
4375 /* After this point, VALUE is the property after any
4376 margin prefix has been stripped. It must be a string,
4377 an image specification, or `(space ...)'.
4379 LOCATION specifies where to display: `left-margin',
4380 `right-margin' or nil. */
4382 valid_p
= (STRINGP (value
)
4383 #ifdef HAVE_WINDOW_SYSTEM
4384 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4385 #endif /* not HAVE_WINDOW_SYSTEM */
4386 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4388 if (valid_p
&& !display_replaced_before_p
)
4390 /* Save current settings of IT so that we can restore them
4391 when we are finished with the glyph property value. */
4392 save_pos
= it
->position
;
4393 it
->position
= *position
;
4395 it
->position
= save_pos
;
4396 it
->from_overlay
= overlay
;
4398 if (NILP (location
))
4399 it
->area
= TEXT_AREA
;
4400 else if (EQ (location
, Qleft_margin
))
4401 it
->area
= LEFT_MARGIN_AREA
;
4403 it
->area
= RIGHT_MARGIN_AREA
;
4405 if (STRINGP (value
))
4408 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4409 it
->current
.overlay_string_index
= -1;
4410 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4411 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4412 it
->method
= GET_FROM_STRING
;
4413 it
->stop_charpos
= 0;
4414 it
->string_from_display_prop_p
= 1;
4415 /* Say that we haven't consumed the characters with
4416 `display' property yet. The call to pop_it in
4417 set_iterator_to_next will clean this up. */
4418 if (BUFFERP (object
))
4419 *position
= start_pos
;
4421 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4423 it
->method
= GET_FROM_STRETCH
;
4425 *position
= it
->position
= start_pos
;
4427 #ifdef HAVE_WINDOW_SYSTEM
4430 it
->what
= IT_IMAGE
;
4431 it
->image_id
= lookup_image (it
->f
, value
);
4432 it
->position
= start_pos
;
4433 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4434 it
->method
= GET_FROM_IMAGE
;
4436 /* Say that we haven't consumed the characters with
4437 `display' property yet. The call to pop_it in
4438 set_iterator_to_next will clean this up. */
4439 *position
= start_pos
;
4441 #endif /* HAVE_WINDOW_SYSTEM */
4446 /* Invalid property or property not supported. Restore
4447 POSITION to what it was before. */
4448 *position
= start_pos
;
4453 /* Check if SPEC is a display sub-property value whose text should be
4454 treated as intangible. */
4457 single_display_spec_intangible_p (prop
)
4460 /* Skip over `when FORM'. */
4461 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4475 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4476 we don't need to treat text as intangible. */
4477 if (EQ (XCAR (prop
), Qmargin
))
4485 || EQ (XCAR (prop
), Qleft_margin
)
4486 || EQ (XCAR (prop
), Qright_margin
))
4490 return (CONSP (prop
)
4491 && (EQ (XCAR (prop
), Qimage
)
4492 || EQ (XCAR (prop
), Qspace
)));
4496 /* Check if PROP is a display property value whose text should be
4497 treated as intangible. */
4500 display_prop_intangible_p (prop
)
4504 && CONSP (XCAR (prop
))
4505 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4507 /* A list of sub-properties. */
4508 while (CONSP (prop
))
4510 if (single_display_spec_intangible_p (XCAR (prop
)))
4515 else if (VECTORP (prop
))
4517 /* A vector of sub-properties. */
4519 for (i
= 0; i
< ASIZE (prop
); ++i
)
4520 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4524 return single_display_spec_intangible_p (prop
);
4530 /* Return 1 if PROP is a display sub-property value containing STRING. */
4533 single_display_spec_string_p (prop
, string
)
4534 Lisp_Object prop
, string
;
4536 if (EQ (string
, prop
))
4539 /* Skip over `when FORM'. */
4540 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4549 /* Skip over `margin LOCATION'. */
4550 if (EQ (XCAR (prop
), Qmargin
))
4561 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4565 /* Return 1 if STRING appears in the `display' property PROP. */
4568 display_prop_string_p (prop
, string
)
4569 Lisp_Object prop
, string
;
4572 && CONSP (XCAR (prop
))
4573 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4575 /* A list of sub-properties. */
4576 while (CONSP (prop
))
4578 if (single_display_spec_string_p (XCAR (prop
), string
))
4583 else if (VECTORP (prop
))
4585 /* A vector of sub-properties. */
4587 for (i
= 0; i
< ASIZE (prop
); ++i
)
4588 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4592 return single_display_spec_string_p (prop
, string
);
4597 /* Look for STRING in overlays and text properties in W's buffer,
4598 between character positions FROM and TO (excluding TO).
4599 BACK_P non-zero means look back (in this case, TO is supposed to be
4601 Value is the first character position where STRING was found, or
4602 zero if it wasn't found before hitting TO.
4604 W's buffer must be current.
4606 This function may only use code that doesn't eval because it is
4607 called asynchronously from note_mouse_highlight. */
4610 string_buffer_position_lim (w
, string
, from
, to
, back_p
)
4616 Lisp_Object limit
, prop
, pos
;
4619 pos
= make_number (from
);
4621 if (!back_p
) /* looking forward */
4623 limit
= make_number (min (to
, ZV
));
4624 while (!found
&& !EQ (pos
, limit
))
4626 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4627 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4630 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
4634 else /* looking back */
4636 limit
= make_number (max (to
, BEGV
));
4637 while (!found
&& !EQ (pos
, limit
))
4639 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4640 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4643 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4648 return found
? XINT (pos
) : 0;
4651 /* Determine which buffer position in W's buffer STRING comes from.
4652 AROUND_CHARPOS is an approximate position where it could come from.
4653 Value is the buffer position or 0 if it couldn't be determined.
4655 W's buffer must be current.
4657 This function is necessary because we don't record buffer positions
4658 in glyphs generated from strings (to keep struct glyph small).
4659 This function may only use code that doesn't eval because it is
4660 called asynchronously from note_mouse_highlight. */
4663 string_buffer_position (w
, string
, around_charpos
)
4666 EMACS_INT around_charpos
;
4668 Lisp_Object limit
, prop
, pos
;
4669 const int MAX_DISTANCE
= 1000;
4670 EMACS_INT found
= string_buffer_position_lim (w
, string
, around_charpos
,
4671 around_charpos
+ MAX_DISTANCE
,
4675 found
= string_buffer_position_lim (w
, string
, around_charpos
,
4676 around_charpos
- MAX_DISTANCE
, 1);
4682 /***********************************************************************
4683 `composition' property
4684 ***********************************************************************/
4686 /* Set up iterator IT from `composition' property at its current
4687 position. Called from handle_stop. */
4689 static enum prop_handled
4690 handle_composition_prop (it
)
4693 Lisp_Object prop
, string
;
4694 EMACS_INT pos
, pos_byte
, start
, end
;
4696 if (STRINGP (it
->string
))
4700 pos
= IT_STRING_CHARPOS (*it
);
4701 pos_byte
= IT_STRING_BYTEPOS (*it
);
4702 string
= it
->string
;
4703 s
= SDATA (string
) + pos_byte
;
4704 it
->c
= STRING_CHAR (s
);
4708 pos
= IT_CHARPOS (*it
);
4709 pos_byte
= IT_BYTEPOS (*it
);
4711 it
->c
= FETCH_CHAR (pos_byte
);
4714 /* If there's a valid composition and point is not inside of the
4715 composition (in the case that the composition is from the current
4716 buffer), draw a glyph composed from the composition components. */
4717 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4718 && COMPOSITION_VALID_P (start
, end
, prop
)
4719 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4723 if (STRINGP (it
->string
))
4724 pos_byte
= string_char_to_byte (it
->string
, start
);
4726 pos_byte
= CHAR_TO_BYTE (start
);
4728 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
4731 if (it
->cmp_it
.id
>= 0)
4734 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
4735 it
->cmp_it
.nglyphs
= -1;
4739 return HANDLED_NORMALLY
;
4744 /***********************************************************************
4746 ***********************************************************************/
4748 /* The following structure is used to record overlay strings for
4749 later sorting in load_overlay_strings. */
4751 struct overlay_entry
4753 Lisp_Object overlay
;
4760 /* Set up iterator IT from overlay strings at its current position.
4761 Called from handle_stop. */
4763 static enum prop_handled
4764 handle_overlay_change (it
)
4767 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4768 return HANDLED_RECOMPUTE_PROPS
;
4770 return HANDLED_NORMALLY
;
4774 /* Set up the next overlay string for delivery by IT, if there is an
4775 overlay string to deliver. Called by set_iterator_to_next when the
4776 end of the current overlay string is reached. If there are more
4777 overlay strings to display, IT->string and
4778 IT->current.overlay_string_index are set appropriately here.
4779 Otherwise IT->string is set to nil. */
4782 next_overlay_string (it
)
4785 ++it
->current
.overlay_string_index
;
4786 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4788 /* No more overlay strings. Restore IT's settings to what
4789 they were before overlay strings were processed, and
4790 continue to deliver from current_buffer. */
4792 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4795 || (NILP (it
->string
)
4796 && it
->method
== GET_FROM_BUFFER
4797 && it
->stop_charpos
>= BEGV
4798 && it
->stop_charpos
<= it
->end_charpos
));
4799 it
->current
.overlay_string_index
= -1;
4800 it
->n_overlay_strings
= 0;
4802 /* If we're at the end of the buffer, record that we have
4803 processed the overlay strings there already, so that
4804 next_element_from_buffer doesn't try it again. */
4805 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4806 it
->overlay_strings_at_end_processed_p
= 1;
4810 /* There are more overlay strings to process. If
4811 IT->current.overlay_string_index has advanced to a position
4812 where we must load IT->overlay_strings with more strings, do
4814 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4816 if (it
->current
.overlay_string_index
&& i
== 0)
4817 load_overlay_strings (it
, 0);
4819 /* Initialize IT to deliver display elements from the overlay
4821 it
->string
= it
->overlay_strings
[i
];
4822 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4823 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4824 it
->method
= GET_FROM_STRING
;
4825 it
->stop_charpos
= 0;
4826 if (it
->cmp_it
.stop_pos
>= 0)
4827 it
->cmp_it
.stop_pos
= 0;
4834 /* Compare two overlay_entry structures E1 and E2. Used as a
4835 comparison function for qsort in load_overlay_strings. Overlay
4836 strings for the same position are sorted so that
4838 1. All after-strings come in front of before-strings, except
4839 when they come from the same overlay.
4841 2. Within after-strings, strings are sorted so that overlay strings
4842 from overlays with higher priorities come first.
4844 2. Within before-strings, strings are sorted so that overlay
4845 strings from overlays with higher priorities come last.
4847 Value is analogous to strcmp. */
4851 compare_overlay_entries (e1
, e2
)
4854 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4855 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4858 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4860 /* Let after-strings appear in front of before-strings if
4861 they come from different overlays. */
4862 if (EQ (entry1
->overlay
, entry2
->overlay
))
4863 result
= entry1
->after_string_p
? 1 : -1;
4865 result
= entry1
->after_string_p
? -1 : 1;
4867 else if (entry1
->after_string_p
)
4868 /* After-strings sorted in order of decreasing priority. */
4869 result
= entry2
->priority
- entry1
->priority
;
4871 /* Before-strings sorted in order of increasing priority. */
4872 result
= entry1
->priority
- entry2
->priority
;
4878 /* Load the vector IT->overlay_strings with overlay strings from IT's
4879 current buffer position, or from CHARPOS if that is > 0. Set
4880 IT->n_overlays to the total number of overlay strings found.
4882 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4883 a time. On entry into load_overlay_strings,
4884 IT->current.overlay_string_index gives the number of overlay
4885 strings that have already been loaded by previous calls to this
4888 IT->add_overlay_start contains an additional overlay start
4889 position to consider for taking overlay strings from, if non-zero.
4890 This position comes into play when the overlay has an `invisible'
4891 property, and both before and after-strings. When we've skipped to
4892 the end of the overlay, because of its `invisible' property, we
4893 nevertheless want its before-string to appear.
4894 IT->add_overlay_start will contain the overlay start position
4897 Overlay strings are sorted so that after-string strings come in
4898 front of before-string strings. Within before and after-strings,
4899 strings are sorted by overlay priority. See also function
4900 compare_overlay_entries. */
4903 load_overlay_strings (it
, charpos
)
4907 extern Lisp_Object Qwindow
, Qpriority
;
4908 Lisp_Object overlay
, window
, str
, invisible
;
4909 struct Lisp_Overlay
*ov
;
4912 int n
= 0, i
, j
, invis_p
;
4913 struct overlay_entry
*entries
4914 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4917 charpos
= IT_CHARPOS (*it
);
4919 /* Append the overlay string STRING of overlay OVERLAY to vector
4920 `entries' which has size `size' and currently contains `n'
4921 elements. AFTER_P non-zero means STRING is an after-string of
4923 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4926 Lisp_Object priority; \
4930 int new_size = 2 * size; \
4931 struct overlay_entry *old = entries; \
4933 (struct overlay_entry *) alloca (new_size \
4934 * sizeof *entries); \
4935 bcopy (old, entries, size * sizeof *entries); \
4939 entries[n].string = (STRING); \
4940 entries[n].overlay = (OVERLAY); \
4941 priority = Foverlay_get ((OVERLAY), Qpriority); \
4942 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4943 entries[n].after_string_p = (AFTER_P); \
4948 /* Process overlay before the overlay center. */
4949 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4951 XSETMISC (overlay
, ov
);
4952 xassert (OVERLAYP (overlay
));
4953 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4954 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4959 /* Skip this overlay if it doesn't start or end at IT's current
4961 if (end
!= charpos
&& start
!= charpos
)
4964 /* Skip this overlay if it doesn't apply to IT->w. */
4965 window
= Foverlay_get (overlay
, Qwindow
);
4966 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4969 /* If the text ``under'' the overlay is invisible, both before-
4970 and after-strings from this overlay are visible; start and
4971 end position are indistinguishable. */
4972 invisible
= Foverlay_get (overlay
, Qinvisible
);
4973 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4975 /* If overlay has a non-empty before-string, record it. */
4976 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4977 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4979 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4981 /* If overlay has a non-empty after-string, record it. */
4982 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4983 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4985 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4988 /* Process overlays after the overlay center. */
4989 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4991 XSETMISC (overlay
, ov
);
4992 xassert (OVERLAYP (overlay
));
4993 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4994 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4996 if (start
> charpos
)
4999 /* Skip this overlay if it doesn't start or end at IT's current
5001 if (end
!= charpos
&& start
!= charpos
)
5004 /* Skip this overlay if it doesn't apply to IT->w. */
5005 window
= Foverlay_get (overlay
, Qwindow
);
5006 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5009 /* If the text ``under'' the overlay is invisible, it has a zero
5010 dimension, and both before- and after-strings apply. */
5011 invisible
= Foverlay_get (overlay
, Qinvisible
);
5012 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5014 /* If overlay has a non-empty before-string, record it. */
5015 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5016 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5018 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5020 /* If overlay has a non-empty after-string, record it. */
5021 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5022 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5024 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5027 #undef RECORD_OVERLAY_STRING
5031 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5033 /* Record the total number of strings to process. */
5034 it
->n_overlay_strings
= n
;
5036 /* IT->current.overlay_string_index is the number of overlay strings
5037 that have already been consumed by IT. Copy some of the
5038 remaining overlay strings to IT->overlay_strings. */
5040 j
= it
->current
.overlay_string_index
;
5041 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5043 it
->overlay_strings
[i
] = entries
[j
].string
;
5044 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5051 /* Get the first chunk of overlay strings at IT's current buffer
5052 position, or at CHARPOS if that is > 0. Value is non-zero if at
5053 least one overlay string was found. */
5056 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
5061 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5062 process. This fills IT->overlay_strings with strings, and sets
5063 IT->n_overlay_strings to the total number of strings to process.
5064 IT->pos.overlay_string_index has to be set temporarily to zero
5065 because load_overlay_strings needs this; it must be set to -1
5066 when no overlay strings are found because a zero value would
5067 indicate a position in the first overlay string. */
5068 it
->current
.overlay_string_index
= 0;
5069 load_overlay_strings (it
, charpos
);
5071 /* If we found overlay strings, set up IT to deliver display
5072 elements from the first one. Otherwise set up IT to deliver
5073 from current_buffer. */
5074 if (it
->n_overlay_strings
)
5076 /* Make sure we know settings in current_buffer, so that we can
5077 restore meaningful values when we're done with the overlay
5080 compute_stop_pos (it
);
5081 xassert (it
->face_id
>= 0);
5083 /* Save IT's settings. They are restored after all overlay
5084 strings have been processed. */
5085 xassert (!compute_stop_p
|| it
->sp
== 0);
5087 /* When called from handle_stop, there might be an empty display
5088 string loaded. In that case, don't bother saving it. */
5089 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
5092 /* Set up IT to deliver display elements from the first overlay
5094 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5095 it
->string
= it
->overlay_strings
[0];
5096 it
->from_overlay
= Qnil
;
5097 it
->stop_charpos
= 0;
5098 xassert (STRINGP (it
->string
));
5099 it
->end_charpos
= SCHARS (it
->string
);
5100 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5101 it
->method
= GET_FROM_STRING
;
5105 it
->current
.overlay_string_index
= -1;
5110 get_overlay_strings (it
, charpos
)
5115 it
->method
= GET_FROM_BUFFER
;
5117 (void) get_overlay_strings_1 (it
, charpos
, 1);
5121 /* Value is non-zero if we found at least one overlay string. */
5122 return STRINGP (it
->string
);
5127 /***********************************************************************
5128 Saving and restoring state
5129 ***********************************************************************/
5131 /* Save current settings of IT on IT->stack. Called, for example,
5132 before setting up IT for an overlay string, to be able to restore
5133 IT's settings to what they were after the overlay string has been
5140 struct iterator_stack_entry
*p
;
5142 xassert (it
->sp
< IT_STACK_SIZE
);
5143 p
= it
->stack
+ it
->sp
;
5145 p
->stop_charpos
= it
->stop_charpos
;
5146 p
->prev_stop
= it
->prev_stop
;
5147 p
->base_level_stop
= it
->base_level_stop
;
5148 p
->cmp_it
= it
->cmp_it
;
5149 xassert (it
->face_id
>= 0);
5150 p
->face_id
= it
->face_id
;
5151 p
->string
= it
->string
;
5152 p
->method
= it
->method
;
5153 p
->from_overlay
= it
->from_overlay
;
5156 case GET_FROM_IMAGE
:
5157 p
->u
.image
.object
= it
->object
;
5158 p
->u
.image
.image_id
= it
->image_id
;
5159 p
->u
.image
.slice
= it
->slice
;
5161 case GET_FROM_STRETCH
:
5162 p
->u
.stretch
.object
= it
->object
;
5165 p
->position
= it
->position
;
5166 p
->current
= it
->current
;
5167 p
->end_charpos
= it
->end_charpos
;
5168 p
->string_nchars
= it
->string_nchars
;
5170 p
->multibyte_p
= it
->multibyte_p
;
5171 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5172 p
->space_width
= it
->space_width
;
5173 p
->font_height
= it
->font_height
;
5174 p
->voffset
= it
->voffset
;
5175 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5176 p
->display_ellipsis_p
= 0;
5177 p
->line_wrap
= it
->line_wrap
;
5182 /* Restore IT's settings from IT->stack. Called, for example, when no
5183 more overlay strings must be processed, and we return to delivering
5184 display elements from a buffer, or when the end of a string from a
5185 `display' property is reached and we return to delivering display
5186 elements from an overlay string, or from a buffer. */
5192 struct iterator_stack_entry
*p
;
5194 xassert (it
->sp
> 0);
5196 p
= it
->stack
+ it
->sp
;
5197 it
->stop_charpos
= p
->stop_charpos
;
5198 it
->prev_stop
= p
->prev_stop
;
5199 it
->base_level_stop
= p
->base_level_stop
;
5200 it
->cmp_it
= p
->cmp_it
;
5201 it
->face_id
= p
->face_id
;
5202 it
->current
= p
->current
;
5203 it
->position
= p
->position
;
5204 it
->string
= p
->string
;
5205 it
->from_overlay
= p
->from_overlay
;
5206 if (NILP (it
->string
))
5207 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5208 it
->method
= p
->method
;
5211 case GET_FROM_IMAGE
:
5212 it
->image_id
= p
->u
.image
.image_id
;
5213 it
->object
= p
->u
.image
.object
;
5214 it
->slice
= p
->u
.image
.slice
;
5216 case GET_FROM_STRETCH
:
5217 it
->object
= p
->u
.comp
.object
;
5219 case GET_FROM_BUFFER
:
5220 it
->object
= it
->w
->buffer
;
5222 case GET_FROM_STRING
:
5223 it
->object
= it
->string
;
5225 case GET_FROM_DISPLAY_VECTOR
:
5227 it
->method
= GET_FROM_C_STRING
;
5228 else if (STRINGP (it
->string
))
5229 it
->method
= GET_FROM_STRING
;
5232 it
->method
= GET_FROM_BUFFER
;
5233 it
->object
= it
->w
->buffer
;
5236 it
->end_charpos
= p
->end_charpos
;
5237 it
->string_nchars
= p
->string_nchars
;
5239 it
->multibyte_p
= p
->multibyte_p
;
5240 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5241 it
->space_width
= p
->space_width
;
5242 it
->font_height
= p
->font_height
;
5243 it
->voffset
= p
->voffset
;
5244 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5245 it
->line_wrap
= p
->line_wrap
;
5250 /***********************************************************************
5252 ***********************************************************************/
5254 /* Set IT's current position to the previous line start. */
5257 back_to_previous_line_start (it
)
5260 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5261 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5265 /* Move IT to the next line start.
5267 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5268 we skipped over part of the text (as opposed to moving the iterator
5269 continuously over the text). Otherwise, don't change the value
5272 Newlines may come from buffer text, overlay strings, or strings
5273 displayed via the `display' property. That's the reason we can't
5274 simply use find_next_newline_no_quit.
5276 Note that this function may not skip over invisible text that is so
5277 because of text properties and immediately follows a newline. If
5278 it would, function reseat_at_next_visible_line_start, when called
5279 from set_iterator_to_next, would effectively make invisible
5280 characters following a newline part of the wrong glyph row, which
5281 leads to wrong cursor motion. */
5284 forward_to_next_line_start (it
, skipped_p
)
5288 int old_selective
, newline_found_p
, n
;
5289 const int MAX_NEWLINE_DISTANCE
= 500;
5291 /* If already on a newline, just consume it to avoid unintended
5292 skipping over invisible text below. */
5293 if (it
->what
== IT_CHARACTER
5295 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5297 set_iterator_to_next (it
, 0);
5302 /* Don't handle selective display in the following. It's (a)
5303 unnecessary because it's done by the caller, and (b) leads to an
5304 infinite recursion because next_element_from_ellipsis indirectly
5305 calls this function. */
5306 old_selective
= it
->selective
;
5309 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5310 from buffer text. */
5311 for (n
= newline_found_p
= 0;
5312 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5313 n
+= STRINGP (it
->string
) ? 0 : 1)
5315 if (!get_next_display_element (it
))
5317 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5318 set_iterator_to_next (it
, 0);
5321 /* If we didn't find a newline near enough, see if we can use a
5323 if (!newline_found_p
)
5325 int start
= IT_CHARPOS (*it
);
5326 int limit
= find_next_newline_no_quit (start
, 1);
5329 xassert (!STRINGP (it
->string
));
5331 /* If there isn't any `display' property in sight, and no
5332 overlays, we can just use the position of the newline in
5334 if (it
->stop_charpos
>= limit
5335 || ((pos
= Fnext_single_property_change (make_number (start
),
5337 Qnil
, make_number (limit
)),
5339 && next_overlay_change (start
) == ZV
))
5341 IT_CHARPOS (*it
) = limit
;
5342 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5343 *skipped_p
= newline_found_p
= 1;
5347 while (get_next_display_element (it
)
5348 && !newline_found_p
)
5350 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5351 set_iterator_to_next (it
, 0);
5356 it
->selective
= old_selective
;
5357 return newline_found_p
;
5361 /* Set IT's current position to the previous visible line start. Skip
5362 invisible text that is so either due to text properties or due to
5363 selective display. Caution: this does not change IT->current_x and
5367 back_to_previous_visible_line_start (it
)
5370 while (IT_CHARPOS (*it
) > BEGV
)
5372 back_to_previous_line_start (it
);
5374 if (IT_CHARPOS (*it
) <= BEGV
)
5377 /* If selective > 0, then lines indented more than its value are
5379 if (it
->selective
> 0
5380 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5381 (double) it
->selective
)) /* iftc */
5384 /* Check the newline before point for invisibility. */
5387 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5388 Qinvisible
, it
->window
);
5389 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5393 if (IT_CHARPOS (*it
) <= BEGV
)
5400 Lisp_Object val
, overlay
;
5402 /* If newline is part of a composition, continue from start of composition */
5403 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5404 && beg
< IT_CHARPOS (*it
))
5407 /* If newline is replaced by a display property, find start of overlay
5408 or interval and continue search from that point. */
5410 pos
= --IT_CHARPOS (it2
);
5413 it2
.string_from_display_prop_p
= 0;
5414 if (handle_display_prop (&it2
) == HANDLED_RETURN
5415 && !NILP (val
= get_char_property_and_overlay
5416 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5417 && (OVERLAYP (overlay
)
5418 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5419 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5422 /* Newline is not replaced by anything -- so we are done. */
5428 IT_CHARPOS (*it
) = beg
;
5429 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5433 it
->continuation_lines_width
= 0;
5435 xassert (IT_CHARPOS (*it
) >= BEGV
);
5436 xassert (IT_CHARPOS (*it
) == BEGV
5437 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5442 /* Reseat iterator IT at the previous visible line start. Skip
5443 invisible text that is so either due to text properties or due to
5444 selective display. At the end, update IT's overlay information,
5445 face information etc. */
5448 reseat_at_previous_visible_line_start (it
)
5451 back_to_previous_visible_line_start (it
);
5452 reseat (it
, it
->current
.pos
, 1);
5457 /* Reseat iterator IT on the next visible line start in the current
5458 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5459 preceding the line start. Skip over invisible text that is so
5460 because of selective display. Compute faces, overlays etc at the
5461 new position. Note that this function does not skip over text that
5462 is invisible because of text properties. */
5465 reseat_at_next_visible_line_start (it
, on_newline_p
)
5469 int newline_found_p
, skipped_p
= 0;
5471 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5473 /* Skip over lines that are invisible because they are indented
5474 more than the value of IT->selective. */
5475 if (it
->selective
> 0)
5476 while (IT_CHARPOS (*it
) < ZV
5477 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5478 (double) it
->selective
)) /* iftc */
5480 xassert (IT_BYTEPOS (*it
) == BEGV
5481 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5482 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5485 /* Position on the newline if that's what's requested. */
5486 if (on_newline_p
&& newline_found_p
)
5488 if (STRINGP (it
->string
))
5490 if (IT_STRING_CHARPOS (*it
) > 0)
5492 --IT_STRING_CHARPOS (*it
);
5493 --IT_STRING_BYTEPOS (*it
);
5496 else if (IT_CHARPOS (*it
) > BEGV
)
5500 reseat (it
, it
->current
.pos
, 0);
5504 reseat (it
, it
->current
.pos
, 0);
5511 /***********************************************************************
5512 Changing an iterator's position
5513 ***********************************************************************/
5515 /* Change IT's current position to POS in current_buffer. If FORCE_P
5516 is non-zero, always check for text properties at the new position.
5517 Otherwise, text properties are only looked up if POS >=
5518 IT->check_charpos of a property. */
5521 reseat (it
, pos
, force_p
)
5523 struct text_pos pos
;
5526 int original_pos
= IT_CHARPOS (*it
);
5528 reseat_1 (it
, pos
, 0);
5530 /* Determine where to check text properties. Avoid doing it
5531 where possible because text property lookup is very expensive. */
5533 || CHARPOS (pos
) > it
->stop_charpos
5534 || CHARPOS (pos
) < original_pos
)
5541 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5542 IT->stop_pos to POS, also. */
5545 reseat_1 (it
, pos
, set_stop_p
)
5547 struct text_pos pos
;
5550 /* Don't call this function when scanning a C string. */
5551 xassert (it
->s
== NULL
);
5553 /* POS must be a reasonable value. */
5554 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5556 it
->current
.pos
= it
->position
= pos
;
5557 it
->end_charpos
= ZV
;
5559 it
->current
.dpvec_index
= -1;
5560 it
->current
.overlay_string_index
= -1;
5561 IT_STRING_CHARPOS (*it
) = -1;
5562 IT_STRING_BYTEPOS (*it
) = -1;
5564 it
->string_from_display_prop_p
= 0;
5565 it
->method
= GET_FROM_BUFFER
;
5566 it
->object
= it
->w
->buffer
;
5567 it
->area
= TEXT_AREA
;
5568 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5570 it
->string_from_display_prop_p
= 0;
5571 it
->face_before_selective_p
= 0;
5573 it
->bidi_it
.first_elt
= 1;
5577 it
->stop_charpos
= CHARPOS (pos
);
5578 it
->base_level_stop
= CHARPOS (pos
);
5583 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5584 If S is non-null, it is a C string to iterate over. Otherwise,
5585 STRING gives a Lisp string to iterate over.
5587 If PRECISION > 0, don't return more then PRECISION number of
5588 characters from the string.
5590 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5591 characters have been returned. FIELD_WIDTH < 0 means an infinite
5594 MULTIBYTE = 0 means disable processing of multibyte characters,
5595 MULTIBYTE > 0 means enable it,
5596 MULTIBYTE < 0 means use IT->multibyte_p.
5598 IT must be initialized via a prior call to init_iterator before
5599 calling this function. */
5602 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5607 int precision
, field_width
, multibyte
;
5609 /* No region in strings. */
5610 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5612 /* No text property checks performed by default, but see below. */
5613 it
->stop_charpos
= -1;
5615 /* Set iterator position and end position. */
5616 bzero (&it
->current
, sizeof it
->current
);
5617 it
->current
.overlay_string_index
= -1;
5618 it
->current
.dpvec_index
= -1;
5619 xassert (charpos
>= 0);
5621 /* If STRING is specified, use its multibyteness, otherwise use the
5622 setting of MULTIBYTE, if specified. */
5624 it
->multibyte_p
= multibyte
> 0;
5628 xassert (STRINGP (string
));
5629 it
->string
= string
;
5631 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5632 it
->method
= GET_FROM_STRING
;
5633 it
->current
.string_pos
= string_pos (charpos
, string
);
5640 /* Note that we use IT->current.pos, not it->current.string_pos,
5641 for displaying C strings. */
5642 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5643 if (it
->multibyte_p
)
5645 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5646 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5650 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5651 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5654 it
->method
= GET_FROM_C_STRING
;
5657 /* PRECISION > 0 means don't return more than PRECISION characters
5659 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5660 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5662 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5663 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5664 FIELD_WIDTH < 0 means infinite field width. This is useful for
5665 padding with `-' at the end of a mode line. */
5666 if (field_width
< 0)
5667 field_width
= INFINITY
;
5668 if (field_width
> it
->end_charpos
- charpos
)
5669 it
->end_charpos
= charpos
+ field_width
;
5671 /* Use the standard display table for displaying strings. */
5672 if (DISP_TABLE_P (Vstandard_display_table
))
5673 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5675 it
->stop_charpos
= charpos
;
5681 /***********************************************************************
5683 ***********************************************************************/
5685 /* Map enum it_method value to corresponding next_element_from_* function. */
5687 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5689 next_element_from_buffer
,
5690 next_element_from_display_vector
,
5691 next_element_from_string
,
5692 next_element_from_c_string
,
5693 next_element_from_image
,
5694 next_element_from_stretch
5697 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5700 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5701 (possibly with the following characters). */
5703 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS) \
5704 ((IT)->cmp_it.id >= 0 \
5705 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5706 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5707 (IT)->end_charpos, (IT)->w, \
5708 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5712 /* Load IT's display element fields with information about the next
5713 display element from the current position of IT. Value is zero if
5714 end of buffer (or C string) is reached. */
5716 static struct frame
*last_escape_glyph_frame
= NULL
;
5717 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5718 static int last_escape_glyph_merged_face_id
= 0;
5721 get_next_display_element (it
)
5724 /* Non-zero means that we found a display element. Zero means that
5725 we hit the end of what we iterate over. Performance note: the
5726 function pointer `method' used here turns out to be faster than
5727 using a sequence of if-statements. */
5731 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5733 if (it
->what
== IT_CHARACTER
)
5735 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
5736 and only if (a) the resolved directionality of that character
5738 /* FIXME: Do we need an exception for characters from display
5740 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
5741 it
->c
= bidi_mirror_char (it
->c
);
5742 /* Map via display table or translate control characters.
5743 IT->c, IT->len etc. have been set to the next character by
5744 the function call above. If we have a display table, and it
5745 contains an entry for IT->c, translate it. Don't do this if
5746 IT->c itself comes from a display table, otherwise we could
5747 end up in an infinite recursion. (An alternative could be to
5748 count the recursion depth of this function and signal an
5749 error when a certain maximum depth is reached.) Is it worth
5751 if (success_p
&& it
->dpvec
== NULL
)
5754 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
5755 enum { char_is_other
= 0, char_is_nbsp
, char_is_soft_hyphen
}
5756 nbsp_or_shy
= char_is_other
;
5757 int decoded
= it
->c
;
5760 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5763 struct Lisp_Vector
*v
= XVECTOR (dv
);
5765 /* Return the first character from the display table
5766 entry, if not empty. If empty, don't display the
5767 current character. */
5770 it
->dpvec_char_len
= it
->len
;
5771 it
->dpvec
= v
->contents
;
5772 it
->dpend
= v
->contents
+ v
->size
;
5773 it
->current
.dpvec_index
= 0;
5774 it
->dpvec_face_id
= -1;
5775 it
->saved_face_id
= it
->face_id
;
5776 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5781 set_iterator_to_next (it
, 0);
5786 if (unibyte_display_via_language_environment
5787 && !ASCII_CHAR_P (it
->c
))
5788 decoded
= DECODE_CHAR (unibyte
, it
->c
);
5790 if (it
->c
>= 0x80 && ! NILP (Vnobreak_char_display
))
5792 if (it
->multibyte_p
)
5793 nbsp_or_shy
= (it
->c
== 0xA0 ? char_is_nbsp
5794 : it
->c
== 0xAD ? char_is_soft_hyphen
5796 else if (unibyte_display_via_language_environment
)
5797 nbsp_or_shy
= (decoded
== 0xA0 ? char_is_nbsp
5798 : decoded
== 0xAD ? char_is_soft_hyphen
5802 /* Translate control characters into `\003' or `^C' form.
5803 Control characters coming from a display table entry are
5804 currently not translated because we use IT->dpvec to hold
5805 the translation. This could easily be changed but I
5806 don't believe that it is worth doing.
5808 If it->multibyte_p is nonzero, non-printable non-ASCII
5809 characters are also translated to octal form.
5811 If it->multibyte_p is zero, eight-bit characters that
5812 don't have corresponding multibyte char code are also
5813 translated to octal form. */
5815 ? (it
->area
!= TEXT_AREA
5816 /* In mode line, treat \n, \t like other crl chars. */
5819 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
5820 || (it
->c
!= '\n' && it
->c
!= '\t'))
5823 ? ! CHAR_PRINTABLE_P (it
->c
)
5824 : (! unibyte_display_via_language_environment
5826 : (decoded
>= 0x80 && decoded
< 0xA0))))))
5828 /* IT->c is a control character which must be displayed
5829 either as '\003' or as `^C' where the '\\' and '^'
5830 can be defined in the display table. Fill
5831 IT->ctl_chars with glyphs for what we have to
5832 display. Then, set IT->dpvec to these glyphs. */
5835 int face_id
, lface_id
= 0 ;
5838 /* Handle control characters with ^. */
5840 if (it
->c
< 128 && it
->ctl_arrow_p
)
5844 g
= '^'; /* default glyph for Control */
5845 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5847 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5848 && GLYPH_CODE_CHAR_VALID_P (gc
))
5850 g
= GLYPH_CODE_CHAR (gc
);
5851 lface_id
= GLYPH_CODE_FACE (gc
);
5855 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5857 else if (it
->f
== last_escape_glyph_frame
5858 && it
->face_id
== last_escape_glyph_face_id
)
5860 face_id
= last_escape_glyph_merged_face_id
;
5864 /* Merge the escape-glyph face into the current face. */
5865 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5867 last_escape_glyph_frame
= it
->f
;
5868 last_escape_glyph_face_id
= it
->face_id
;
5869 last_escape_glyph_merged_face_id
= face_id
;
5872 XSETINT (it
->ctl_chars
[0], g
);
5873 XSETINT (it
->ctl_chars
[1], it
->c
^ 0100);
5875 goto display_control
;
5878 /* Handle non-break space in the mode where it only gets
5881 if (EQ (Vnobreak_char_display
, Qt
)
5882 && nbsp_or_shy
== char_is_nbsp
)
5884 /* Merge the no-break-space face into the current face. */
5885 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5889 XSETINT (it
->ctl_chars
[0], ' ');
5891 goto display_control
;
5894 /* Handle sequences that start with the "escape glyph". */
5896 /* the default escape glyph is \. */
5897 escape_glyph
= '\\';
5900 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5901 && GLYPH_CODE_CHAR_VALID_P (gc
))
5903 escape_glyph
= GLYPH_CODE_CHAR (gc
);
5904 lface_id
= GLYPH_CODE_FACE (gc
);
5908 /* The display table specified a face.
5909 Merge it into face_id and also into escape_glyph. */
5910 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5913 else if (it
->f
== last_escape_glyph_frame
5914 && it
->face_id
== last_escape_glyph_face_id
)
5916 face_id
= last_escape_glyph_merged_face_id
;
5920 /* Merge the escape-glyph face into the current face. */
5921 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5923 last_escape_glyph_frame
= it
->f
;
5924 last_escape_glyph_face_id
= it
->face_id
;
5925 last_escape_glyph_merged_face_id
= face_id
;
5928 /* Handle soft hyphens in the mode where they only get
5931 if (EQ (Vnobreak_char_display
, Qt
)
5932 && nbsp_or_shy
== char_is_soft_hyphen
)
5935 XSETINT (it
->ctl_chars
[0], '-');
5937 goto display_control
;
5940 /* Handle non-break space and soft hyphen
5941 with the escape glyph. */
5945 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5946 it
->c
= (nbsp_or_shy
== char_is_nbsp
? ' ' : '-');
5947 XSETINT (it
->ctl_chars
[1], it
->c
);
5949 goto display_control
;
5953 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5957 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5958 if (CHAR_BYTE8_P (it
->c
))
5960 str
[0] = CHAR_TO_BYTE8 (it
->c
);
5963 else if (it
->c
< 256)
5970 /* It's an invalid character, which shouldn't
5971 happen actually, but due to bugs it may
5972 happen. Let's print the char as is, there's
5973 not much meaningful we can do with it. */
5975 str
[1] = it
->c
>> 8;
5976 str
[2] = it
->c
>> 16;
5977 str
[3] = it
->c
>> 24;
5981 for (i
= 0; i
< len
; i
++)
5984 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5985 /* Insert three more glyphs into IT->ctl_chars for
5986 the octal display of the character. */
5987 g
= ((str
[i
] >> 6) & 7) + '0';
5988 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5989 g
= ((str
[i
] >> 3) & 7) + '0';
5990 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5991 g
= (str
[i
] & 7) + '0';
5992 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5998 /* Set up IT->dpvec and return first character from it. */
5999 it
->dpvec_char_len
= it
->len
;
6000 it
->dpvec
= it
->ctl_chars
;
6001 it
->dpend
= it
->dpvec
+ ctl_len
;
6002 it
->current
.dpvec_index
= 0;
6003 it
->dpvec_face_id
= face_id
;
6004 it
->saved_face_id
= it
->face_id
;
6005 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6012 #ifdef HAVE_WINDOW_SYSTEM
6013 /* Adjust face id for a multibyte character. There are no multibyte
6014 character in unibyte text. */
6015 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6018 && FRAME_WINDOW_P (it
->f
))
6020 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6022 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6024 /* Automatic composition with glyph-string. */
6025 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6027 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6031 int pos
= (it
->s
? -1
6032 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6033 : IT_CHARPOS (*it
));
6035 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
, pos
, it
->string
);
6040 /* Is this character the last one of a run of characters with
6041 box? If yes, set IT->end_of_box_run_p to 1. */
6045 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6047 int face_id
= underlying_face_id (it
);
6048 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6052 if (face
->box
== FACE_NO_BOX
)
6054 /* If the box comes from face properties in a
6055 display string, check faces in that string. */
6056 int string_face_id
= face_after_it_pos (it
);
6057 it
->end_of_box_run_p
6058 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6061 /* Otherwise, the box comes from the underlying face.
6062 If this is the last string character displayed, check
6063 the next buffer location. */
6064 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6065 && (it
->current
.overlay_string_index
6066 == it
->n_overlay_strings
- 1))
6070 struct text_pos pos
= it
->current
.pos
;
6071 INC_TEXT_POS (pos
, it
->multibyte_p
);
6073 next_face_id
= face_at_buffer_position
6074 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6075 it
->region_end_charpos
, &ignore
,
6076 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6078 it
->end_of_box_run_p
6079 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6086 int face_id
= face_after_it_pos (it
);
6087 it
->end_of_box_run_p
6088 = (face_id
!= it
->face_id
6089 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6093 /* Value is 0 if end of buffer or string reached. */
6098 /* Move IT to the next display element.
6100 RESEAT_P non-zero means if called on a newline in buffer text,
6101 skip to the next visible line start.
6103 Functions get_next_display_element and set_iterator_to_next are
6104 separate because I find this arrangement easier to handle than a
6105 get_next_display_element function that also increments IT's
6106 position. The way it is we can first look at an iterator's current
6107 display element, decide whether it fits on a line, and if it does,
6108 increment the iterator position. The other way around we probably
6109 would either need a flag indicating whether the iterator has to be
6110 incremented the next time, or we would have to implement a
6111 decrement position function which would not be easy to write. */
6114 set_iterator_to_next (it
, reseat_p
)
6118 /* Reset flags indicating start and end of a sequence of characters
6119 with box. Reset them at the start of this function because
6120 moving the iterator to a new position might set them. */
6121 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6125 case GET_FROM_BUFFER
:
6126 /* The current display element of IT is a character from
6127 current_buffer. Advance in the buffer, and maybe skip over
6128 invisible lines that are so because of selective display. */
6129 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6130 reseat_at_next_visible_line_start (it
, 0);
6131 else if (it
->cmp_it
.id
>= 0)
6133 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6134 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6135 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6136 it
->cmp_it
.from
= it
->cmp_it
.to
;
6140 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6141 IT_BYTEPOS (*it
), it
->stop_charpos
,
6147 xassert (it
->len
!= 0);
6151 IT_BYTEPOS (*it
) += it
->len
;
6152 IT_CHARPOS (*it
) += 1;
6156 /* If this is a new paragraph, determine its base
6157 direction (a.k.a. its base embedding level). */
6158 if (it
->bidi_it
.new_paragraph
)
6159 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
);
6160 bidi_get_next_char_visually (&it
->bidi_it
);
6161 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6162 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6164 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6168 case GET_FROM_C_STRING
:
6169 /* Current display element of IT is from a C string. */
6170 IT_BYTEPOS (*it
) += it
->len
;
6171 IT_CHARPOS (*it
) += 1;
6174 case GET_FROM_DISPLAY_VECTOR
:
6175 /* Current display element of IT is from a display table entry.
6176 Advance in the display table definition. Reset it to null if
6177 end reached, and continue with characters from buffers/
6179 ++it
->current
.dpvec_index
;
6181 /* Restore face of the iterator to what they were before the
6182 display vector entry (these entries may contain faces). */
6183 it
->face_id
= it
->saved_face_id
;
6185 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6187 int recheck_faces
= it
->ellipsis_p
;
6190 it
->method
= GET_FROM_C_STRING
;
6191 else if (STRINGP (it
->string
))
6192 it
->method
= GET_FROM_STRING
;
6195 it
->method
= GET_FROM_BUFFER
;
6196 it
->object
= it
->w
->buffer
;
6200 it
->current
.dpvec_index
= -1;
6202 /* Skip over characters which were displayed via IT->dpvec. */
6203 if (it
->dpvec_char_len
< 0)
6204 reseat_at_next_visible_line_start (it
, 1);
6205 else if (it
->dpvec_char_len
> 0)
6207 if (it
->method
== GET_FROM_STRING
6208 && it
->n_overlay_strings
> 0)
6209 it
->ignore_overlay_strings_at_pos_p
= 1;
6210 it
->len
= it
->dpvec_char_len
;
6211 set_iterator_to_next (it
, reseat_p
);
6214 /* Maybe recheck faces after display vector */
6216 it
->stop_charpos
= IT_CHARPOS (*it
);
6220 case GET_FROM_STRING
:
6221 /* Current display element is a character from a Lisp string. */
6222 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6223 if (it
->cmp_it
.id
>= 0)
6225 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6226 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6227 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6228 it
->cmp_it
.from
= it
->cmp_it
.to
;
6232 composition_compute_stop_pos (&it
->cmp_it
,
6233 IT_STRING_CHARPOS (*it
),
6234 IT_STRING_BYTEPOS (*it
),
6235 it
->stop_charpos
, it
->string
);
6240 IT_STRING_BYTEPOS (*it
) += it
->len
;
6241 IT_STRING_CHARPOS (*it
) += 1;
6244 consider_string_end
:
6246 if (it
->current
.overlay_string_index
>= 0)
6248 /* IT->string is an overlay string. Advance to the
6249 next, if there is one. */
6250 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6253 next_overlay_string (it
);
6255 setup_for_ellipsis (it
, 0);
6260 /* IT->string is not an overlay string. If we reached
6261 its end, and there is something on IT->stack, proceed
6262 with what is on the stack. This can be either another
6263 string, this time an overlay string, or a buffer. */
6264 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6268 if (it
->method
== GET_FROM_STRING
)
6269 goto consider_string_end
;
6274 case GET_FROM_IMAGE
:
6275 case GET_FROM_STRETCH
:
6276 /* The position etc with which we have to proceed are on
6277 the stack. The position may be at the end of a string,
6278 if the `display' property takes up the whole string. */
6279 xassert (it
->sp
> 0);
6281 if (it
->method
== GET_FROM_STRING
)
6282 goto consider_string_end
;
6286 /* There are no other methods defined, so this should be a bug. */
6290 xassert (it
->method
!= GET_FROM_STRING
6291 || (STRINGP (it
->string
)
6292 && IT_STRING_CHARPOS (*it
) >= 0));
6295 /* Load IT's display element fields with information about the next
6296 display element which comes from a display table entry or from the
6297 result of translating a control character to one of the forms `^C'
6300 IT->dpvec holds the glyphs to return as characters.
6301 IT->saved_face_id holds the face id before the display vector--it
6302 is restored into IT->face_id in set_iterator_to_next. */
6305 next_element_from_display_vector (it
)
6311 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6313 it
->face_id
= it
->saved_face_id
;
6315 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6316 That seemed totally bogus - so I changed it... */
6317 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6319 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6321 it
->c
= GLYPH_CODE_CHAR (gc
);
6322 it
->len
= CHAR_BYTES (it
->c
);
6324 /* The entry may contain a face id to use. Such a face id is
6325 the id of a Lisp face, not a realized face. A face id of
6326 zero means no face is specified. */
6327 if (it
->dpvec_face_id
>= 0)
6328 it
->face_id
= it
->dpvec_face_id
;
6331 int lface_id
= GLYPH_CODE_FACE (gc
);
6333 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6338 /* Display table entry is invalid. Return a space. */
6339 it
->c
= ' ', it
->len
= 1;
6341 /* Don't change position and object of the iterator here. They are
6342 still the values of the character that had this display table
6343 entry or was translated, and that's what we want. */
6344 it
->what
= IT_CHARACTER
;
6349 /* Load IT with the next display element from Lisp string IT->string.
6350 IT->current.string_pos is the current position within the string.
6351 If IT->current.overlay_string_index >= 0, the Lisp string is an
6355 next_element_from_string (it
)
6358 struct text_pos position
;
6360 xassert (STRINGP (it
->string
));
6361 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6362 position
= it
->current
.string_pos
;
6364 /* Time to check for invisible text? */
6365 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6366 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6370 /* Since a handler may have changed IT->method, we must
6372 return GET_NEXT_DISPLAY_ELEMENT (it
);
6375 if (it
->current
.overlay_string_index
>= 0)
6377 /* Get the next character from an overlay string. In overlay
6378 strings, There is no field width or padding with spaces to
6380 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6385 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6386 IT_STRING_BYTEPOS (*it
))
6387 && next_element_from_composition (it
))
6391 else if (STRING_MULTIBYTE (it
->string
))
6393 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6394 const unsigned char *s
= (SDATA (it
->string
)
6395 + IT_STRING_BYTEPOS (*it
));
6396 it
->c
= string_char_and_length (s
, &it
->len
);
6400 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6406 /* Get the next character from a Lisp string that is not an
6407 overlay string. Such strings come from the mode line, for
6408 example. We may have to pad with spaces, or truncate the
6409 string. See also next_element_from_c_string. */
6410 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6415 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6417 /* Pad with spaces. */
6418 it
->c
= ' ', it
->len
= 1;
6419 CHARPOS (position
) = BYTEPOS (position
) = -1;
6421 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6422 IT_STRING_BYTEPOS (*it
))
6423 && next_element_from_composition (it
))
6427 else if (STRING_MULTIBYTE (it
->string
))
6429 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6430 const unsigned char *s
= (SDATA (it
->string
)
6431 + IT_STRING_BYTEPOS (*it
));
6432 it
->c
= string_char_and_length (s
, &it
->len
);
6436 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6441 /* Record what we have and where it came from. */
6442 it
->what
= IT_CHARACTER
;
6443 it
->object
= it
->string
;
6444 it
->position
= position
;
6449 /* Load IT with next display element from C string IT->s.
6450 IT->string_nchars is the maximum number of characters to return
6451 from the string. IT->end_charpos may be greater than
6452 IT->string_nchars when this function is called, in which case we
6453 may have to return padding spaces. Value is zero if end of string
6454 reached, including padding spaces. */
6457 next_element_from_c_string (it
)
6463 it
->what
= IT_CHARACTER
;
6464 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6467 /* IT's position can be greater IT->string_nchars in case a field
6468 width or precision has been specified when the iterator was
6470 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6472 /* End of the game. */
6476 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6478 /* Pad with spaces. */
6479 it
->c
= ' ', it
->len
= 1;
6480 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6482 else if (it
->multibyte_p
)
6484 /* Implementation note: The calls to strlen apparently aren't a
6485 performance problem because there is no noticeable performance
6486 difference between Emacs running in unibyte or multibyte mode. */
6487 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6488 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
6491 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6497 /* Set up IT to return characters from an ellipsis, if appropriate.
6498 The definition of the ellipsis glyphs may come from a display table
6499 entry. This function fills IT with the first glyph from the
6500 ellipsis if an ellipsis is to be displayed. */
6503 next_element_from_ellipsis (it
)
6506 if (it
->selective_display_ellipsis_p
)
6507 setup_for_ellipsis (it
, it
->len
);
6510 /* The face at the current position may be different from the
6511 face we find after the invisible text. Remember what it
6512 was in IT->saved_face_id, and signal that it's there by
6513 setting face_before_selective_p. */
6514 it
->saved_face_id
= it
->face_id
;
6515 it
->method
= GET_FROM_BUFFER
;
6516 it
->object
= it
->w
->buffer
;
6517 reseat_at_next_visible_line_start (it
, 1);
6518 it
->face_before_selective_p
= 1;
6521 return GET_NEXT_DISPLAY_ELEMENT (it
);
6525 /* Deliver an image display element. The iterator IT is already
6526 filled with image information (done in handle_display_prop). Value
6531 next_element_from_image (it
)
6534 it
->what
= IT_IMAGE
;
6539 /* Fill iterator IT with next display element from a stretch glyph
6540 property. IT->object is the value of the text property. Value is
6544 next_element_from_stretch (it
)
6547 it
->what
= IT_STRETCH
;
6551 /* Scan forward from CHARPOS in the current buffer, until we find a
6552 stop position > current IT's position. Then handle the stop
6553 position before that.
6555 This is called when we are reordering bidirectional text. The
6556 caller should save and restore IT and in particular the bidi_p
6557 flag, because this function modifies them. */
6560 handle_stop_backwards (it
, charpos
)
6564 struct text_pos pos1
;
6565 EMACS_INT where_we_are
= IT_CHARPOS (*it
);
6566 EMACS_INT next_stop
;
6568 /* Scan in strict logical order. */
6572 it
->prev_stop
= charpos
;
6573 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
6574 reseat_1 (it
, pos1
, 0);
6575 compute_stop_pos (it
);
6576 /* We must advance forward, right? */
6577 if (it
->stop_charpos
<= it
->prev_stop
)
6579 charpos
= it
->stop_charpos
;
6581 while (charpos
<= where_we_are
);
6583 next_stop
= it
->stop_charpos
;
6584 it
->stop_charpos
= it
->prev_stop
;
6586 it
->stop_charpos
= next_stop
;
6589 /* Load IT with the next display element from current_buffer. Value
6590 is zero if end of buffer reached. IT->stop_charpos is the next
6591 position at which to stop and check for text properties or buffer
6595 next_element_from_buffer (it
)
6600 xassert (IT_CHARPOS (*it
) >= BEGV
);
6602 /* With bidi reordering, the character to display might not be the
6603 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
6604 we were reseat()ed to a new buffer position, which is potentially
6605 a different paragraph. */
6606 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
6608 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6609 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6610 /* If we are at the beginning of a line, we can produce the next
6611 element right away. */
6612 if (it
->bidi_it
.bytepos
== BEGV_BYTE
6613 /* FIXME: Should support all Unicode line separators. */
6614 || FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
6615 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')
6617 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
);
6618 /* If the paragraph base direction is R2L, its glyphs should
6620 if (it
->glyph_row
&& (it
->bidi_it
.level_stack
[0].level
& 1) != 0)
6621 it
->glyph_row
->reversed_p
= 1;
6622 bidi_get_next_char_visually (&it
->bidi_it
);
6626 int orig_bytepos
= IT_BYTEPOS (*it
);
6628 /* We need to prime the bidi iterator starting at the line's
6629 beginning, before we will be able to produce the next
6631 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
), -1);
6632 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
6633 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6634 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6635 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
);
6636 if (it
->glyph_row
&& (it
->bidi_it
.level_stack
[0].level
& 1) != 0)
6637 it
->glyph_row
->reversed_p
= 1;
6639 /* Now return to buffer position where we were asked to
6640 get the next display element, and produce that. */
6641 bidi_get_next_char_visually (&it
->bidi_it
);
6642 } while (it
->bidi_it
.bytepos
!= orig_bytepos
6643 && it
->bidi_it
.bytepos
< ZV_BYTE
);
6646 it
->bidi_it
.first_elt
= 0; /* paranoia: bidi.c does this */
6647 /* Adjust IT's position information to where we ended up. */
6648 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6649 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6650 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
6653 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6655 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6657 int overlay_strings_follow_p
;
6659 /* End of the game, except when overlay strings follow that
6660 haven't been returned yet. */
6661 if (it
->overlay_strings_at_end_processed_p
)
6662 overlay_strings_follow_p
= 0;
6665 it
->overlay_strings_at_end_processed_p
= 1;
6666 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6669 if (overlay_strings_follow_p
)
6670 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6674 it
->position
= it
->current
.pos
;
6678 else if (!(!it
->bidi_p
6679 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6680 || IT_CHARPOS (*it
) == it
->stop_charpos
))
6682 /* With bidi non-linear iteration, we could find ourselves
6683 far beyond the last computed stop_charpos, with several
6684 other stop positions in between that we missed. Scan
6685 them all now, in buffer's logical order, until we find
6686 and handle the last stop_charpos that precedes our
6687 current position. */
6688 struct it save_it
= *it
;
6690 handle_stop_backwards (it
, it
->stop_charpos
);
6692 it
->current
= save_it
.current
;
6693 it
->position
= save_it
.position
;
6694 return GET_NEXT_DISPLAY_ELEMENT (it
);
6698 /* If we are at base paragraph embedding level, take note of
6699 the last stop position seen at this level. */
6700 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6701 it
->base_level_stop
= it
->stop_charpos
;
6703 return GET_NEXT_DISPLAY_ELEMENT (it
);
6706 else if (it
->bidi_p
&& IT_CHARPOS (*it
) < it
->prev_stop
)
6708 struct it save_it
= *it
;
6710 if (it
->base_level_stop
<= 0)
6711 it
->base_level_stop
= 1;
6712 if (IT_CHARPOS (*it
) < it
->base_level_stop
)
6714 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6716 handle_stop_backwards (it
, it
->base_level_stop
);
6718 it
->current
= save_it
.current
;
6719 it
->position
= save_it
.position
;
6720 return GET_NEXT_DISPLAY_ELEMENT (it
);
6724 /* No face changes, overlays etc. in sight, so just return a
6725 character from current_buffer. */
6728 /* Maybe run the redisplay end trigger hook. Performance note:
6729 This doesn't seem to cost measurable time. */
6730 if (it
->redisplay_end_trigger_charpos
6732 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6733 run_redisplay_end_trigger_hook (it
);
6735 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
))
6736 && next_element_from_composition (it
))
6741 /* Get the next character, maybe multibyte. */
6742 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6743 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6744 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
6746 it
->c
= *p
, it
->len
= 1;
6748 /* Record what we have and where it came from. */
6749 it
->what
= IT_CHARACTER
;
6750 it
->object
= it
->w
->buffer
;
6751 it
->position
= it
->current
.pos
;
6753 /* Normally we return the character found above, except when we
6754 really want to return an ellipsis for selective display. */
6759 /* A value of selective > 0 means hide lines indented more
6760 than that number of columns. */
6761 if (it
->selective
> 0
6762 && IT_CHARPOS (*it
) + 1 < ZV
6763 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6764 IT_BYTEPOS (*it
) + 1,
6765 (double) it
->selective
)) /* iftc */
6767 success_p
= next_element_from_ellipsis (it
);
6768 it
->dpvec_char_len
= -1;
6771 else if (it
->c
== '\r' && it
->selective
== -1)
6773 /* A value of selective == -1 means that everything from the
6774 CR to the end of the line is invisible, with maybe an
6775 ellipsis displayed for it. */
6776 success_p
= next_element_from_ellipsis (it
);
6777 it
->dpvec_char_len
= -1;
6782 /* Value is zero if end of buffer reached. */
6783 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6788 /* Run the redisplay end trigger hook for IT. */
6791 run_redisplay_end_trigger_hook (it
)
6794 Lisp_Object args
[3];
6796 /* IT->glyph_row should be non-null, i.e. we should be actually
6797 displaying something, or otherwise we should not run the hook. */
6798 xassert (it
->glyph_row
);
6800 /* Set up hook arguments. */
6801 args
[0] = Qredisplay_end_trigger_functions
;
6802 args
[1] = it
->window
;
6803 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6804 it
->redisplay_end_trigger_charpos
= 0;
6806 /* Since we are *trying* to run these functions, don't try to run
6807 them again, even if they get an error. */
6808 it
->w
->redisplay_end_trigger
= Qnil
;
6809 Frun_hook_with_args (3, args
);
6811 /* Notice if it changed the face of the character we are on. */
6812 handle_face_prop (it
);
6816 /* Deliver a composition display element. Unlike the other
6817 next_element_from_XXX, this function is not registered in the array
6818 get_next_element[]. It is called from next_element_from_buffer and
6819 next_element_from_string when necessary. */
6822 next_element_from_composition (it
)
6825 it
->what
= IT_COMPOSITION
;
6826 it
->len
= it
->cmp_it
.nbytes
;
6827 if (STRINGP (it
->string
))
6831 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6832 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6835 it
->position
= it
->current
.string_pos
;
6836 it
->object
= it
->string
;
6837 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
6838 IT_STRING_BYTEPOS (*it
), it
->string
);
6844 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6845 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6848 it
->position
= it
->current
.pos
;
6849 it
->object
= it
->w
->buffer
;
6850 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
6851 IT_BYTEPOS (*it
), Qnil
);
6858 /***********************************************************************
6859 Moving an iterator without producing glyphs
6860 ***********************************************************************/
6862 /* Check if iterator is at a position corresponding to a valid buffer
6863 position after some move_it_ call. */
6865 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6866 ((it)->method == GET_FROM_STRING \
6867 ? IT_STRING_CHARPOS (*it) == 0 \
6871 /* Move iterator IT to a specified buffer or X position within one
6872 line on the display without producing glyphs.
6874 OP should be a bit mask including some or all of these bits:
6875 MOVE_TO_X: Stop upon reaching x-position TO_X.
6876 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
6877 Regardless of OP's value, stop upon reaching the end of the display line.
6879 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6880 This means, in particular, that TO_X includes window's horizontal
6883 The return value has several possible values that
6884 say what condition caused the scan to stop:
6886 MOVE_POS_MATCH_OR_ZV
6887 - when TO_POS or ZV was reached.
6890 -when TO_X was reached before TO_POS or ZV were reached.
6893 - when we reached the end of the display area and the line must
6897 - when we reached the end of the display area and the line is
6901 - when we stopped at a line end, i.e. a newline or a CR and selective
6904 static enum move_it_result
6905 move_it_in_display_line_to (struct it
*it
,
6906 EMACS_INT to_charpos
, int to_x
,
6907 enum move_operation_enum op
)
6909 enum move_it_result result
= MOVE_UNDEFINED
;
6910 struct glyph_row
*saved_glyph_row
;
6911 struct it wrap_it
, atpos_it
, atx_it
;
6914 /* Don't produce glyphs in produce_glyphs. */
6915 saved_glyph_row
= it
->glyph_row
;
6916 it
->glyph_row
= NULL
;
6918 /* Use wrap_it to save a copy of IT wherever a word wrap could
6919 occur. Use atpos_it to save a copy of IT at the desired buffer
6920 position, if found, so that we can scan ahead and check if the
6921 word later overshoots the window edge. Use atx_it similarly, for
6927 #define BUFFER_POS_REACHED_P() \
6928 ((op & MOVE_TO_POS) != 0 \
6929 && BUFFERP (it->object) \
6930 && IT_CHARPOS (*it) >= to_charpos \
6931 && (it->method == GET_FROM_BUFFER \
6932 || (it->method == GET_FROM_DISPLAY_VECTOR \
6933 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6935 /* If there's a line-/wrap-prefix, handle it. */
6936 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
6937 && it
->current_y
< it
->last_visible_y
)
6938 handle_line_prefix (it
);
6942 int x
, i
, ascent
= 0, descent
= 0;
6944 /* Utility macro to reset an iterator with x, ascent, and descent. */
6945 #define IT_RESET_X_ASCENT_DESCENT(IT) \
6946 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
6947 (IT)->max_descent = descent)
6949 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
6951 if ((op
& MOVE_TO_POS
) != 0
6952 && BUFFERP (it
->object
)
6953 && it
->method
== GET_FROM_BUFFER
6954 && IT_CHARPOS (*it
) > to_charpos
)
6956 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6958 result
= MOVE_POS_MATCH_OR_ZV
;
6961 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
6962 /* If wrap_it is valid, the current position might be in a
6963 word that is wrapped. So, save the iterator in
6964 atpos_it and continue to see if wrapping happens. */
6968 /* Stop when ZV reached.
6969 We used to stop here when TO_CHARPOS reached as well, but that is
6970 too soon if this glyph does not fit on this line. So we handle it
6971 explicitly below. */
6972 if (!get_next_display_element (it
))
6974 result
= MOVE_POS_MATCH_OR_ZV
;
6978 if (it
->line_wrap
== TRUNCATE
)
6980 if (BUFFER_POS_REACHED_P ())
6982 result
= MOVE_POS_MATCH_OR_ZV
;
6988 if (it
->line_wrap
== WORD_WRAP
)
6990 if (IT_DISPLAYING_WHITESPACE (it
))
6994 /* We have reached a glyph that follows one or more
6995 whitespace characters. If the position is
6996 already found, we are done. */
6997 if (atpos_it
.sp
>= 0)
7000 result
= MOVE_POS_MATCH_OR_ZV
;
7006 result
= MOVE_X_REACHED
;
7009 /* Otherwise, we can wrap here. */
7016 /* Remember the line height for the current line, in case
7017 the next element doesn't fit on the line. */
7018 ascent
= it
->max_ascent
;
7019 descent
= it
->max_descent
;
7021 /* The call to produce_glyphs will get the metrics of the
7022 display element IT is loaded with. Record the x-position
7023 before this display element, in case it doesn't fit on the
7027 PRODUCE_GLYPHS (it
);
7029 if (it
->area
!= TEXT_AREA
)
7031 set_iterator_to_next (it
, 1);
7035 /* The number of glyphs we get back in IT->nglyphs will normally
7036 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
7037 character on a terminal frame, or (iii) a line end. For the
7038 second case, IT->nglyphs - 1 padding glyphs will be present.
7039 (On X frames, there is only one glyph produced for a
7040 composite character.)
7042 The behavior implemented below means, for continuation lines,
7043 that as many spaces of a TAB as fit on the current line are
7044 displayed there. For terminal frames, as many glyphs of a
7045 multi-glyph character are displayed in the current line, too.
7046 This is what the old redisplay code did, and we keep it that
7047 way. Under X, the whole shape of a complex character must
7048 fit on the line or it will be completely displayed in the
7051 Note that both for tabs and padding glyphs, all glyphs have
7055 /* More than one glyph or glyph doesn't fit on line. All
7056 glyphs have the same width. */
7057 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
7059 int x_before_this_char
= x
;
7060 int hpos_before_this_char
= it
->hpos
;
7062 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
7064 new_x
= x
+ single_glyph_width
;
7066 /* We want to leave anything reaching TO_X to the caller. */
7067 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
7069 if (BUFFER_POS_REACHED_P ())
7071 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7072 goto buffer_pos_reached
;
7073 if (atpos_it
.sp
< 0)
7076 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7081 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7084 result
= MOVE_X_REACHED
;
7090 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
7095 if (/* Lines are continued. */
7096 it
->line_wrap
!= TRUNCATE
7097 && (/* And glyph doesn't fit on the line. */
7098 new_x
> it
->last_visible_x
7099 /* Or it fits exactly and we're on a window
7101 || (new_x
== it
->last_visible_x
7102 && FRAME_WINDOW_P (it
->f
))))
7104 if (/* IT->hpos == 0 means the very first glyph
7105 doesn't fit on the line, e.g. a wide image. */
7107 || (new_x
== it
->last_visible_x
7108 && FRAME_WINDOW_P (it
->f
)))
7111 it
->current_x
= new_x
;
7113 /* The character's last glyph just barely fits
7115 if (i
== it
->nglyphs
- 1)
7117 /* If this is the destination position,
7118 return a position *before* it in this row,
7119 now that we know it fits in this row. */
7120 if (BUFFER_POS_REACHED_P ())
7122 if (it
->line_wrap
!= WORD_WRAP
7125 it
->hpos
= hpos_before_this_char
;
7126 it
->current_x
= x_before_this_char
;
7127 result
= MOVE_POS_MATCH_OR_ZV
;
7130 if (it
->line_wrap
== WORD_WRAP
7134 atpos_it
.current_x
= x_before_this_char
;
7135 atpos_it
.hpos
= hpos_before_this_char
;
7139 set_iterator_to_next (it
, 1);
7140 /* On graphical terminals, newlines may
7141 "overflow" into the fringe if
7142 overflow-newline-into-fringe is non-nil.
7143 On text-only terminals, newlines may
7144 overflow into the last glyph on the
7146 if (!FRAME_WINDOW_P (it
->f
)
7147 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7149 if (!get_next_display_element (it
))
7151 result
= MOVE_POS_MATCH_OR_ZV
;
7154 if (BUFFER_POS_REACHED_P ())
7156 if (ITERATOR_AT_END_OF_LINE_P (it
))
7157 result
= MOVE_POS_MATCH_OR_ZV
;
7159 result
= MOVE_LINE_CONTINUED
;
7162 if (ITERATOR_AT_END_OF_LINE_P (it
))
7164 result
= MOVE_NEWLINE_OR_CR
;
7171 IT_RESET_X_ASCENT_DESCENT (it
);
7173 if (wrap_it
.sp
>= 0)
7180 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
7182 result
= MOVE_LINE_CONTINUED
;
7186 if (BUFFER_POS_REACHED_P ())
7188 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7189 goto buffer_pos_reached
;
7190 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7193 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7197 if (new_x
> it
->first_visible_x
)
7199 /* Glyph is visible. Increment number of glyphs that
7200 would be displayed. */
7205 if (result
!= MOVE_UNDEFINED
)
7208 else if (BUFFER_POS_REACHED_P ())
7211 IT_RESET_X_ASCENT_DESCENT (it
);
7212 result
= MOVE_POS_MATCH_OR_ZV
;
7215 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
7217 /* Stop when TO_X specified and reached. This check is
7218 necessary here because of lines consisting of a line end,
7219 only. The line end will not produce any glyphs and we
7220 would never get MOVE_X_REACHED. */
7221 xassert (it
->nglyphs
== 0);
7222 result
= MOVE_X_REACHED
;
7226 /* Is this a line end? If yes, we're done. */
7227 if (ITERATOR_AT_END_OF_LINE_P (it
))
7229 result
= MOVE_NEWLINE_OR_CR
;
7233 /* The current display element has been consumed. Advance
7235 set_iterator_to_next (it
, 1);
7237 /* Stop if lines are truncated and IT's current x-position is
7238 past the right edge of the window now. */
7239 if (it
->line_wrap
== TRUNCATE
7240 && it
->current_x
>= it
->last_visible_x
)
7242 if (!FRAME_WINDOW_P (it
->f
)
7243 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7245 if (!get_next_display_element (it
)
7246 || BUFFER_POS_REACHED_P ())
7248 result
= MOVE_POS_MATCH_OR_ZV
;
7251 if (ITERATOR_AT_END_OF_LINE_P (it
))
7253 result
= MOVE_NEWLINE_OR_CR
;
7257 result
= MOVE_LINE_TRUNCATED
;
7260 #undef IT_RESET_X_ASCENT_DESCENT
7263 #undef BUFFER_POS_REACHED_P
7265 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7266 restore the saved iterator. */
7267 if (atpos_it
.sp
>= 0)
7269 else if (atx_it
.sp
>= 0)
7274 /* Restore the iterator settings altered at the beginning of this
7276 it
->glyph_row
= saved_glyph_row
;
7280 /* For external use. */
7282 move_it_in_display_line (struct it
*it
,
7283 EMACS_INT to_charpos
, int to_x
,
7284 enum move_operation_enum op
)
7286 if (it
->line_wrap
== WORD_WRAP
7287 && (op
& MOVE_TO_X
))
7289 struct it save_it
= *it
;
7290 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7291 /* When word-wrap is on, TO_X may lie past the end
7292 of a wrapped line. Then it->current is the
7293 character on the next line, so backtrack to the
7294 space before the wrap point. */
7295 if (skip
== MOVE_LINE_CONTINUED
)
7297 int prev_x
= max (it
->current_x
- 1, 0);
7299 move_it_in_display_line_to
7300 (it
, -1, prev_x
, MOVE_TO_X
);
7304 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7308 /* Move IT forward until it satisfies one or more of the criteria in
7309 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7311 OP is a bit-mask that specifies where to stop, and in particular,
7312 which of those four position arguments makes a difference. See the
7313 description of enum move_operation_enum.
7315 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7316 screen line, this function will set IT to the next position >
7320 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
7322 int to_charpos
, to_x
, to_y
, to_vpos
;
7325 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7326 int line_height
, line_start_x
= 0, reached
= 0;
7330 if (op
& MOVE_TO_VPOS
)
7332 /* If no TO_CHARPOS and no TO_X specified, stop at the
7333 start of the line TO_VPOS. */
7334 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7336 if (it
->vpos
== to_vpos
)
7342 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7346 /* TO_VPOS >= 0 means stop at TO_X in the line at
7347 TO_VPOS, or at TO_POS, whichever comes first. */
7348 if (it
->vpos
== to_vpos
)
7354 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7356 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7361 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7363 /* We have reached TO_X but not in the line we want. */
7364 skip
= move_it_in_display_line_to (it
, to_charpos
,
7366 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7374 else if (op
& MOVE_TO_Y
)
7376 struct it it_backup
;
7378 if (it
->line_wrap
== WORD_WRAP
)
7381 /* TO_Y specified means stop at TO_X in the line containing
7382 TO_Y---or at TO_CHARPOS if this is reached first. The
7383 problem is that we can't really tell whether the line
7384 contains TO_Y before we have completely scanned it, and
7385 this may skip past TO_X. What we do is to first scan to
7388 If TO_X is not specified, use a TO_X of zero. The reason
7389 is to make the outcome of this function more predictable.
7390 If we didn't use TO_X == 0, we would stop at the end of
7391 the line which is probably not what a caller would expect
7393 skip
= move_it_in_display_line_to
7394 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
7395 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
7397 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7398 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7400 else if (skip
== MOVE_X_REACHED
)
7402 /* If TO_X was reached, we want to know whether TO_Y is
7403 in the line. We know this is the case if the already
7404 scanned glyphs make the line tall enough. Otherwise,
7405 we must check by scanning the rest of the line. */
7406 line_height
= it
->max_ascent
+ it
->max_descent
;
7407 if (to_y
>= it
->current_y
7408 && to_y
< it
->current_y
+ line_height
)
7414 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7415 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7417 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7418 line_height
= it
->max_ascent
+ it
->max_descent
;
7419 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7421 if (to_y
>= it
->current_y
7422 && to_y
< it
->current_y
+ line_height
)
7424 /* If TO_Y is in this line and TO_X was reached
7425 above, we scanned too far. We have to restore
7426 IT's settings to the ones before skipping. */
7433 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7439 /* Check whether TO_Y is in this line. */
7440 line_height
= it
->max_ascent
+ it
->max_descent
;
7441 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7443 if (to_y
>= it
->current_y
7444 && to_y
< it
->current_y
+ line_height
)
7446 /* When word-wrap is on, TO_X may lie past the end
7447 of a wrapped line. Then it->current is the
7448 character on the next line, so backtrack to the
7449 space before the wrap point. */
7450 if (skip
== MOVE_LINE_CONTINUED
7451 && it
->line_wrap
== WORD_WRAP
)
7453 int prev_x
= max (it
->current_x
- 1, 0);
7455 skip
= move_it_in_display_line_to
7456 (it
, -1, prev_x
, MOVE_TO_X
);
7465 else if (BUFFERP (it
->object
)
7466 && (it
->method
== GET_FROM_BUFFER
7467 || it
->method
== GET_FROM_STRETCH
)
7468 && IT_CHARPOS (*it
) >= to_charpos
)
7469 skip
= MOVE_POS_MATCH_OR_ZV
;
7471 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7475 case MOVE_POS_MATCH_OR_ZV
:
7479 case MOVE_NEWLINE_OR_CR
:
7480 set_iterator_to_next (it
, 1);
7481 it
->continuation_lines_width
= 0;
7484 case MOVE_LINE_TRUNCATED
:
7485 it
->continuation_lines_width
= 0;
7486 reseat_at_next_visible_line_start (it
, 0);
7487 if ((op
& MOVE_TO_POS
) != 0
7488 && IT_CHARPOS (*it
) > to_charpos
)
7495 case MOVE_LINE_CONTINUED
:
7496 /* For continued lines ending in a tab, some of the glyphs
7497 associated with the tab are displayed on the current
7498 line. Since it->current_x does not include these glyphs,
7499 we use it->last_visible_x instead. */
7502 it
->continuation_lines_width
+= it
->last_visible_x
;
7503 /* When moving by vpos, ensure that the iterator really
7504 advances to the next line (bug#847, bug#969). Fixme:
7505 do we need to do this in other circumstances? */
7506 if (it
->current_x
!= it
->last_visible_x
7507 && (op
& MOVE_TO_VPOS
)
7508 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
7510 line_start_x
= it
->current_x
+ it
->pixel_width
7511 - it
->last_visible_x
;
7512 set_iterator_to_next (it
, 0);
7516 it
->continuation_lines_width
+= it
->current_x
;
7523 /* Reset/increment for the next run. */
7524 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7525 it
->current_x
= line_start_x
;
7528 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7530 last_height
= it
->max_ascent
+ it
->max_descent
;
7531 last_max_ascent
= it
->max_ascent
;
7532 it
->max_ascent
= it
->max_descent
= 0;
7537 /* On text terminals, we may stop at the end of a line in the middle
7538 of a multi-character glyph. If the glyph itself is continued,
7539 i.e. it is actually displayed on the next line, don't treat this
7540 stopping point as valid; move to the next line instead (unless
7541 that brings us offscreen). */
7542 if (!FRAME_WINDOW_P (it
->f
)
7544 && IT_CHARPOS (*it
) == to_charpos
7545 && it
->what
== IT_CHARACTER
7547 && it
->line_wrap
== WINDOW_WRAP
7548 && it
->current_x
== it
->last_visible_x
- 1
7551 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
7553 it
->continuation_lines_width
+= it
->current_x
;
7554 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
7555 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7557 last_height
= it
->max_ascent
+ it
->max_descent
;
7558 last_max_ascent
= it
->max_ascent
;
7561 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7565 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7567 If DY > 0, move IT backward at least that many pixels. DY = 0
7568 means move IT backward to the preceding line start or BEGV. This
7569 function may move over more than DY pixels if IT->current_y - DY
7570 ends up in the middle of a line; in this case IT->current_y will be
7571 set to the top of the line moved to. */
7574 move_it_vertically_backward (it
, dy
)
7585 start_pos
= IT_CHARPOS (*it
);
7587 /* Estimate how many newlines we must move back. */
7588 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7590 /* Set the iterator's position that many lines back. */
7591 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7592 back_to_previous_visible_line_start (it
);
7594 /* Reseat the iterator here. When moving backward, we don't want
7595 reseat to skip forward over invisible text, set up the iterator
7596 to deliver from overlay strings at the new position etc. So,
7597 use reseat_1 here. */
7598 reseat_1 (it
, it
->current
.pos
, 1);
7600 /* We are now surely at a line start. */
7601 it
->current_x
= it
->hpos
= 0;
7602 it
->continuation_lines_width
= 0;
7604 /* Move forward and see what y-distance we moved. First move to the
7605 start of the next line so that we get its height. We need this
7606 height to be able to tell whether we reached the specified
7609 it2
.max_ascent
= it2
.max_descent
= 0;
7612 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7613 MOVE_TO_POS
| MOVE_TO_VPOS
);
7615 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7616 xassert (IT_CHARPOS (*it
) >= BEGV
);
7619 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7620 xassert (IT_CHARPOS (*it
) >= BEGV
);
7621 /* H is the actual vertical distance from the position in *IT
7622 and the starting position. */
7623 h
= it2
.current_y
- it
->current_y
;
7624 /* NLINES is the distance in number of lines. */
7625 nlines
= it2
.vpos
- it
->vpos
;
7627 /* Correct IT's y and vpos position
7628 so that they are relative to the starting point. */
7634 /* DY == 0 means move to the start of the screen line. The
7635 value of nlines is > 0 if continuation lines were involved. */
7637 move_it_by_lines (it
, nlines
, 1);
7641 /* The y-position we try to reach, relative to *IT.
7642 Note that H has been subtracted in front of the if-statement. */
7643 int target_y
= it
->current_y
+ h
- dy
;
7644 int y0
= it3
.current_y
;
7645 int y1
= line_bottom_y (&it3
);
7646 int line_height
= y1
- y0
;
7648 /* If we did not reach target_y, try to move further backward if
7649 we can. If we moved too far backward, try to move forward. */
7650 if (target_y
< it
->current_y
7651 /* This is heuristic. In a window that's 3 lines high, with
7652 a line height of 13 pixels each, recentering with point
7653 on the bottom line will try to move -39/2 = 19 pixels
7654 backward. Try to avoid moving into the first line. */
7655 && (it
->current_y
- target_y
7656 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7657 && IT_CHARPOS (*it
) > BEGV
)
7659 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7660 target_y
- it
->current_y
));
7661 dy
= it
->current_y
- target_y
;
7662 goto move_further_back
;
7664 else if (target_y
>= it
->current_y
+ line_height
7665 && IT_CHARPOS (*it
) < ZV
)
7667 /* Should move forward by at least one line, maybe more.
7669 Note: Calling move_it_by_lines can be expensive on
7670 terminal frames, where compute_motion is used (via
7671 vmotion) to do the job, when there are very long lines
7672 and truncate-lines is nil. That's the reason for
7673 treating terminal frames specially here. */
7675 if (!FRAME_WINDOW_P (it
->f
))
7676 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7681 move_it_by_lines (it
, 1, 1);
7683 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7690 /* Move IT by a specified amount of pixel lines DY. DY negative means
7691 move backwards. DY = 0 means move to start of screen line. At the
7692 end, IT will be on the start of a screen line. */
7695 move_it_vertically (it
, dy
)
7700 move_it_vertically_backward (it
, -dy
);
7703 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7704 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7705 MOVE_TO_POS
| MOVE_TO_Y
);
7706 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7708 /* If buffer ends in ZV without a newline, move to the start of
7709 the line to satisfy the post-condition. */
7710 if (IT_CHARPOS (*it
) == ZV
7712 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7713 move_it_by_lines (it
, 0, 0);
7718 /* Move iterator IT past the end of the text line it is in. */
7721 move_it_past_eol (it
)
7724 enum move_it_result rc
;
7726 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7727 if (rc
== MOVE_NEWLINE_OR_CR
)
7728 set_iterator_to_next (it
, 0);
7732 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7733 negative means move up. DVPOS == 0 means move to the start of the
7734 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7735 NEED_Y_P is zero, IT->current_y will be left unchanged.
7737 Further optimization ideas: If we would know that IT->f doesn't use
7738 a face with proportional font, we could be faster for
7739 truncate-lines nil. */
7742 move_it_by_lines (it
, dvpos
, need_y_p
)
7744 int dvpos
, need_y_p
;
7746 struct position pos
;
7748 /* The commented-out optimization uses vmotion on terminals. This
7749 gives bad results, because elements like it->what, on which
7750 callers such as pos_visible_p rely, aren't updated. */
7751 /* if (!FRAME_WINDOW_P (it->f))
7753 struct text_pos textpos;
7755 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7756 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7757 reseat (it, textpos, 1);
7758 it->vpos += pos.vpos;
7759 it->current_y += pos.vpos;
7765 /* DVPOS == 0 means move to the start of the screen line. */
7766 move_it_vertically_backward (it
, 0);
7767 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7768 /* Let next call to line_bottom_y calculate real line height */
7773 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7774 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7775 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7780 int start_charpos
, i
;
7782 /* Start at the beginning of the screen line containing IT's
7783 position. This may actually move vertically backwards,
7784 in case of overlays, so adjust dvpos accordingly. */
7786 move_it_vertically_backward (it
, 0);
7789 /* Go back -DVPOS visible lines and reseat the iterator there. */
7790 start_charpos
= IT_CHARPOS (*it
);
7791 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7792 back_to_previous_visible_line_start (it
);
7793 reseat (it
, it
->current
.pos
, 1);
7795 /* Move further back if we end up in a string or an image. */
7796 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7798 /* First try to move to start of display line. */
7800 move_it_vertically_backward (it
, 0);
7802 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7804 /* If start of line is still in string or image,
7805 move further back. */
7806 back_to_previous_visible_line_start (it
);
7807 reseat (it
, it
->current
.pos
, 1);
7811 it
->current_x
= it
->hpos
= 0;
7813 /* Above call may have moved too far if continuation lines
7814 are involved. Scan forward and see if it did. */
7816 it2
.vpos
= it2
.current_y
= 0;
7817 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7818 it
->vpos
-= it2
.vpos
;
7819 it
->current_y
-= it2
.current_y
;
7820 it
->current_x
= it
->hpos
= 0;
7822 /* If we moved too far back, move IT some lines forward. */
7823 if (it2
.vpos
> -dvpos
)
7825 int delta
= it2
.vpos
+ dvpos
;
7827 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7828 /* Move back again if we got too far ahead. */
7829 if (IT_CHARPOS (*it
) >= start_charpos
)
7835 /* Return 1 if IT points into the middle of a display vector. */
7838 in_display_vector_p (it
)
7841 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7842 && it
->current
.dpvec_index
> 0
7843 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7847 /***********************************************************************
7849 ***********************************************************************/
7852 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7856 add_to_log (format
, arg1
, arg2
)
7858 Lisp_Object arg1
, arg2
;
7860 Lisp_Object args
[3];
7861 Lisp_Object msg
, fmt
;
7864 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7867 /* Do nothing if called asynchronously. Inserting text into
7868 a buffer may call after-change-functions and alike and
7869 that would means running Lisp asynchronously. */
7870 if (handling_signal
)
7874 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7876 args
[0] = fmt
= build_string (format
);
7879 msg
= Fformat (3, args
);
7881 len
= SBYTES (msg
) + 1;
7882 SAFE_ALLOCA (buffer
, char *, len
);
7883 bcopy (SDATA (msg
), buffer
, len
);
7885 message_dolog (buffer
, len
- 1, 1, 0);
7892 /* Output a newline in the *Messages* buffer if "needs" one. */
7895 message_log_maybe_newline ()
7897 if (message_log_need_newline
)
7898 message_dolog ("", 0, 1, 0);
7902 /* Add a string M of length NBYTES to the message log, optionally
7903 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7904 nonzero, means interpret the contents of M as multibyte. This
7905 function calls low-level routines in order to bypass text property
7906 hooks, etc. which might not be safe to run.
7908 This may GC (insert may run before/after change hooks),
7909 so the buffer M must NOT point to a Lisp string. */
7912 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7914 int nbytes
, nlflag
, multibyte
;
7916 if (!NILP (Vmemory_full
))
7919 if (!NILP (Vmessage_log_max
))
7921 struct buffer
*oldbuf
;
7922 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7923 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7924 int point_at_end
= 0;
7926 Lisp_Object old_deactivate_mark
, tem
;
7927 struct gcpro gcpro1
;
7929 old_deactivate_mark
= Vdeactivate_mark
;
7930 oldbuf
= current_buffer
;
7931 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7932 current_buffer
->undo_list
= Qt
;
7934 oldpoint
= message_dolog_marker1
;
7935 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7936 oldbegv
= message_dolog_marker2
;
7937 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7938 oldzv
= message_dolog_marker3
;
7939 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7940 GCPRO1 (old_deactivate_mark
);
7948 BEGV_BYTE
= BEG_BYTE
;
7951 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7953 /* Insert the string--maybe converting multibyte to single byte
7954 or vice versa, so that all the text fits the buffer. */
7956 && NILP (current_buffer
->enable_multibyte_characters
))
7958 int i
, c
, char_bytes
;
7959 unsigned char work
[1];
7961 /* Convert a multibyte string to single-byte
7962 for the *Message* buffer. */
7963 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7965 c
= string_char_and_length (m
+ i
, &char_bytes
);
7966 work
[0] = (ASCII_CHAR_P (c
)
7968 : multibyte_char_to_unibyte (c
, Qnil
));
7969 insert_1_both (work
, 1, 1, 1, 0, 0);
7972 else if (! multibyte
7973 && ! NILP (current_buffer
->enable_multibyte_characters
))
7975 int i
, c
, char_bytes
;
7976 unsigned char *msg
= (unsigned char *) m
;
7977 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7978 /* Convert a single-byte string to multibyte
7979 for the *Message* buffer. */
7980 for (i
= 0; i
< nbytes
; i
++)
7983 MAKE_CHAR_MULTIBYTE (c
);
7984 char_bytes
= CHAR_STRING (c
, str
);
7985 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7989 insert_1 (m
, nbytes
, 1, 0, 0);
7993 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7994 insert_1 ("\n", 1, 1, 0, 0);
7996 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7998 this_bol_byte
= PT_BYTE
;
8000 /* See if this line duplicates the previous one.
8001 If so, combine duplicates. */
8004 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8006 prev_bol_byte
= PT_BYTE
;
8008 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
8009 this_bol
, this_bol_byte
);
8012 del_range_both (prev_bol
, prev_bol_byte
,
8013 this_bol
, this_bol_byte
, 0);
8019 /* If you change this format, don't forget to also
8020 change message_log_check_duplicate. */
8021 sprintf (dupstr
, " [%d times]", dup
);
8022 duplen
= strlen (dupstr
);
8023 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
8024 insert_1 (dupstr
, duplen
, 1, 0, 1);
8029 /* If we have more than the desired maximum number of lines
8030 in the *Messages* buffer now, delete the oldest ones.
8031 This is safe because we don't have undo in this buffer. */
8033 if (NATNUMP (Vmessage_log_max
))
8035 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
8036 -XFASTINT (Vmessage_log_max
) - 1, 0);
8037 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
8040 BEGV
= XMARKER (oldbegv
)->charpos
;
8041 BEGV_BYTE
= marker_byte_position (oldbegv
);
8050 ZV
= XMARKER (oldzv
)->charpos
;
8051 ZV_BYTE
= marker_byte_position (oldzv
);
8055 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8057 /* We can't do Fgoto_char (oldpoint) because it will run some
8059 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
8060 XMARKER (oldpoint
)->bytepos
);
8063 unchain_marker (XMARKER (oldpoint
));
8064 unchain_marker (XMARKER (oldbegv
));
8065 unchain_marker (XMARKER (oldzv
));
8067 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
8068 set_buffer_internal (oldbuf
);
8070 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
8071 message_log_need_newline
= !nlflag
;
8072 Vdeactivate_mark
= old_deactivate_mark
;
8077 /* We are at the end of the buffer after just having inserted a newline.
8078 (Note: We depend on the fact we won't be crossing the gap.)
8079 Check to see if the most recent message looks a lot like the previous one.
8080 Return 0 if different, 1 if the new one should just replace it, or a
8081 value N > 1 if we should also append " [N times]". */
8084 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
8085 int prev_bol
, this_bol
;
8086 int prev_bol_byte
, this_bol_byte
;
8089 int len
= Z_BYTE
- 1 - this_bol_byte
;
8091 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
8092 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
8094 for (i
= 0; i
< len
; i
++)
8096 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
8104 if (*p1
++ == ' ' && *p1
++ == '[')
8107 while (*p1
>= '0' && *p1
<= '9')
8108 n
= n
* 10 + *p1
++ - '0';
8109 if (strncmp (p1
, " times]\n", 8) == 0)
8116 /* Display an echo area message M with a specified length of NBYTES
8117 bytes. The string may include null characters. If M is 0, clear
8118 out any existing message, and let the mini-buffer text show
8121 This may GC, so the buffer M must NOT point to a Lisp string. */
8124 message2 (m
, nbytes
, multibyte
)
8129 /* First flush out any partial line written with print. */
8130 message_log_maybe_newline ();
8132 message_dolog (m
, nbytes
, 1, multibyte
);
8133 message2_nolog (m
, nbytes
, multibyte
);
8137 /* The non-logging counterpart of message2. */
8140 message2_nolog (m
, nbytes
, multibyte
)
8142 int nbytes
, multibyte
;
8144 struct frame
*sf
= SELECTED_FRAME ();
8145 message_enable_multibyte
= multibyte
;
8147 if (FRAME_INITIAL_P (sf
))
8149 if (noninteractive_need_newline
)
8150 putc ('\n', stderr
);
8151 noninteractive_need_newline
= 0;
8153 fwrite (m
, nbytes
, 1, stderr
);
8154 if (cursor_in_echo_area
== 0)
8155 fprintf (stderr
, "\n");
8158 /* A null message buffer means that the frame hasn't really been
8159 initialized yet. Error messages get reported properly by
8160 cmd_error, so this must be just an informative message; toss it. */
8161 else if (INTERACTIVE
8162 && sf
->glyphs_initialized_p
8163 && FRAME_MESSAGE_BUF (sf
))
8165 Lisp_Object mini_window
;
8168 /* Get the frame containing the mini-buffer
8169 that the selected frame is using. */
8170 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8171 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8173 FRAME_SAMPLE_VISIBILITY (f
);
8174 if (FRAME_VISIBLE_P (sf
)
8175 && ! FRAME_VISIBLE_P (f
))
8176 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
8180 set_message (m
, Qnil
, nbytes
, multibyte
);
8181 if (minibuffer_auto_raise
)
8182 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8185 clear_message (1, 1);
8187 do_pending_window_change (0);
8188 echo_area_display (1);
8189 do_pending_window_change (0);
8190 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8191 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8196 /* Display an echo area message M with a specified length of NBYTES
8197 bytes. The string may include null characters. If M is not a
8198 string, clear out any existing message, and let the mini-buffer
8201 This function cancels echoing. */
8204 message3 (m
, nbytes
, multibyte
)
8209 struct gcpro gcpro1
;
8212 clear_message (1,1);
8215 /* First flush out any partial line written with print. */
8216 message_log_maybe_newline ();
8222 SAFE_ALLOCA (buffer
, char *, nbytes
);
8223 bcopy (SDATA (m
), buffer
, nbytes
);
8224 message_dolog (buffer
, nbytes
, 1, multibyte
);
8227 message3_nolog (m
, nbytes
, multibyte
);
8233 /* The non-logging version of message3.
8234 This does not cancel echoing, because it is used for echoing.
8235 Perhaps we need to make a separate function for echoing
8236 and make this cancel echoing. */
8239 message3_nolog (m
, nbytes
, multibyte
)
8241 int nbytes
, multibyte
;
8243 struct frame
*sf
= SELECTED_FRAME ();
8244 message_enable_multibyte
= multibyte
;
8246 if (FRAME_INITIAL_P (sf
))
8248 if (noninteractive_need_newline
)
8249 putc ('\n', stderr
);
8250 noninteractive_need_newline
= 0;
8252 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8253 if (cursor_in_echo_area
== 0)
8254 fprintf (stderr
, "\n");
8257 /* A null message buffer means that the frame hasn't really been
8258 initialized yet. Error messages get reported properly by
8259 cmd_error, so this must be just an informative message; toss it. */
8260 else if (INTERACTIVE
8261 && sf
->glyphs_initialized_p
8262 && FRAME_MESSAGE_BUF (sf
))
8264 Lisp_Object mini_window
;
8268 /* Get the frame containing the mini-buffer
8269 that the selected frame is using. */
8270 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8271 frame
= XWINDOW (mini_window
)->frame
;
8274 FRAME_SAMPLE_VISIBILITY (f
);
8275 if (FRAME_VISIBLE_P (sf
)
8276 && !FRAME_VISIBLE_P (f
))
8277 Fmake_frame_visible (frame
);
8279 if (STRINGP (m
) && SCHARS (m
) > 0)
8281 set_message (NULL
, m
, nbytes
, multibyte
);
8282 if (minibuffer_auto_raise
)
8283 Fraise_frame (frame
);
8284 /* Assume we are not echoing.
8285 (If we are, echo_now will override this.) */
8286 echo_message_buffer
= Qnil
;
8289 clear_message (1, 1);
8291 do_pending_window_change (0);
8292 echo_area_display (1);
8293 do_pending_window_change (0);
8294 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8295 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8300 /* Display a null-terminated echo area message M. If M is 0, clear
8301 out any existing message, and let the mini-buffer text show through.
8303 The buffer M must continue to exist until after the echo area gets
8304 cleared or some other message gets displayed there. Do not pass
8305 text that is stored in a Lisp string. Do not pass text in a buffer
8306 that was alloca'd. */
8312 message2 (m
, (m
? strlen (m
) : 0), 0);
8316 /* The non-logging counterpart of message1. */
8322 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8325 /* Display a message M which contains a single %s
8326 which gets replaced with STRING. */
8329 message_with_string (m
, string
, log
)
8334 CHECK_STRING (string
);
8340 if (noninteractive_need_newline
)
8341 putc ('\n', stderr
);
8342 noninteractive_need_newline
= 0;
8343 fprintf (stderr
, m
, SDATA (string
));
8344 if (!cursor_in_echo_area
)
8345 fprintf (stderr
, "\n");
8349 else if (INTERACTIVE
)
8351 /* The frame whose minibuffer we're going to display the message on.
8352 It may be larger than the selected frame, so we need
8353 to use its buffer, not the selected frame's buffer. */
8354 Lisp_Object mini_window
;
8355 struct frame
*f
, *sf
= SELECTED_FRAME ();
8357 /* Get the frame containing the minibuffer
8358 that the selected frame is using. */
8359 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8360 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8362 /* A null message buffer means that the frame hasn't really been
8363 initialized yet. Error messages get reported properly by
8364 cmd_error, so this must be just an informative message; toss it. */
8365 if (FRAME_MESSAGE_BUF (f
))
8367 Lisp_Object args
[2], message
;
8368 struct gcpro gcpro1
, gcpro2
;
8370 args
[0] = build_string (m
);
8371 args
[1] = message
= string
;
8372 GCPRO2 (args
[0], message
);
8375 message
= Fformat (2, args
);
8378 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8380 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8384 /* Print should start at the beginning of the message
8385 buffer next time. */
8386 message_buf_print
= 0;
8392 /* Dump an informative message to the minibuf. If M is 0, clear out
8393 any existing message, and let the mini-buffer text show through. */
8397 message (m
, a1
, a2
, a3
)
8399 EMACS_INT a1
, a2
, a3
;
8405 if (noninteractive_need_newline
)
8406 putc ('\n', stderr
);
8407 noninteractive_need_newline
= 0;
8408 fprintf (stderr
, m
, a1
, a2
, a3
);
8409 if (cursor_in_echo_area
== 0)
8410 fprintf (stderr
, "\n");
8414 else if (INTERACTIVE
)
8416 /* The frame whose mini-buffer we're going to display the message
8417 on. It may be larger than the selected frame, so we need to
8418 use its buffer, not the selected frame's buffer. */
8419 Lisp_Object mini_window
;
8420 struct frame
*f
, *sf
= SELECTED_FRAME ();
8422 /* Get the frame containing the mini-buffer
8423 that the selected frame is using. */
8424 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8425 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8427 /* A null message buffer means that the frame hasn't really been
8428 initialized yet. Error messages get reported properly by
8429 cmd_error, so this must be just an informative message; toss
8431 if (FRAME_MESSAGE_BUF (f
))
8442 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8443 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
8445 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8446 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
8448 #endif /* NO_ARG_ARRAY */
8450 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8455 /* Print should start at the beginning of the message
8456 buffer next time. */
8457 message_buf_print
= 0;
8463 /* The non-logging version of message. */
8466 message_nolog (m
, a1
, a2
, a3
)
8468 EMACS_INT a1
, a2
, a3
;
8470 Lisp_Object old_log_max
;
8471 old_log_max
= Vmessage_log_max
;
8472 Vmessage_log_max
= Qnil
;
8473 message (m
, a1
, a2
, a3
);
8474 Vmessage_log_max
= old_log_max
;
8478 /* Display the current message in the current mini-buffer. This is
8479 only called from error handlers in process.c, and is not time
8485 if (!NILP (echo_area_buffer
[0]))
8488 string
= Fcurrent_message ();
8489 message3 (string
, SBYTES (string
),
8490 !NILP (current_buffer
->enable_multibyte_characters
));
8495 /* Make sure echo area buffers in `echo_buffers' are live.
8496 If they aren't, make new ones. */
8499 ensure_echo_area_buffers ()
8503 for (i
= 0; i
< 2; ++i
)
8504 if (!BUFFERP (echo_buffer
[i
])
8505 || NILP (XBUFFER (echo_buffer
[i
])->name
))
8508 Lisp_Object old_buffer
;
8511 old_buffer
= echo_buffer
[i
];
8512 sprintf (name
, " *Echo Area %d*", i
);
8513 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8514 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
8515 /* to force word wrap in echo area -
8516 it was decided to postpone this*/
8517 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
8519 for (j
= 0; j
< 2; ++j
)
8520 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8521 echo_area_buffer
[j
] = echo_buffer
[i
];
8526 /* Call FN with args A1..A4 with either the current or last displayed
8527 echo_area_buffer as current buffer.
8529 WHICH zero means use the current message buffer
8530 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8531 from echo_buffer[] and clear it.
8533 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8534 suitable buffer from echo_buffer[] and clear it.
8536 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8537 that the current message becomes the last displayed one, make
8538 choose a suitable buffer for echo_area_buffer[0], and clear it.
8540 Value is what FN returns. */
8543 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
8546 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
8552 int this_one
, the_other
, clear_buffer_p
, rc
;
8553 int count
= SPECPDL_INDEX ();
8555 /* If buffers aren't live, make new ones. */
8556 ensure_echo_area_buffers ();
8561 this_one
= 0, the_other
= 1;
8563 this_one
= 1, the_other
= 0;
8566 this_one
= 0, the_other
= 1;
8569 /* We need a fresh one in case the current echo buffer equals
8570 the one containing the last displayed echo area message. */
8571 if (!NILP (echo_area_buffer
[this_one
])
8572 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8573 echo_area_buffer
[this_one
] = Qnil
;
8576 /* Choose a suitable buffer from echo_buffer[] is we don't
8578 if (NILP (echo_area_buffer
[this_one
]))
8580 echo_area_buffer
[this_one
]
8581 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8582 ? echo_buffer
[the_other
]
8583 : echo_buffer
[this_one
]);
8587 buffer
= echo_area_buffer
[this_one
];
8589 /* Don't get confused by reusing the buffer used for echoing
8590 for a different purpose. */
8591 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8594 record_unwind_protect (unwind_with_echo_area_buffer
,
8595 with_echo_area_buffer_unwind_data (w
));
8597 /* Make the echo area buffer current. Note that for display
8598 purposes, it is not necessary that the displayed window's buffer
8599 == current_buffer, except for text property lookup. So, let's
8600 only set that buffer temporarily here without doing a full
8601 Fset_window_buffer. We must also change w->pointm, though,
8602 because otherwise an assertions in unshow_buffer fails, and Emacs
8604 set_buffer_internal_1 (XBUFFER (buffer
));
8608 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8611 current_buffer
->undo_list
= Qt
;
8612 current_buffer
->read_only
= Qnil
;
8613 specbind (Qinhibit_read_only
, Qt
);
8614 specbind (Qinhibit_modification_hooks
, Qt
);
8616 if (clear_buffer_p
&& Z
> BEG
)
8619 xassert (BEGV
>= BEG
);
8620 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8622 rc
= fn (a1
, a2
, a3
, a4
);
8624 xassert (BEGV
>= BEG
);
8625 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8627 unbind_to (count
, Qnil
);
8632 /* Save state that should be preserved around the call to the function
8633 FN called in with_echo_area_buffer. */
8636 with_echo_area_buffer_unwind_data (w
)
8640 Lisp_Object vector
, tmp
;
8642 /* Reduce consing by keeping one vector in
8643 Vwith_echo_area_save_vector. */
8644 vector
= Vwith_echo_area_save_vector
;
8645 Vwith_echo_area_save_vector
= Qnil
;
8648 vector
= Fmake_vector (make_number (7), Qnil
);
8650 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
8651 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
8652 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
8656 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
8657 ASET (vector
, i
, w
->buffer
); ++i
;
8658 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
8659 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
8664 for (; i
< end
; ++i
)
8665 ASET (vector
, i
, Qnil
);
8668 xassert (i
== ASIZE (vector
));
8673 /* Restore global state from VECTOR which was created by
8674 with_echo_area_buffer_unwind_data. */
8677 unwind_with_echo_area_buffer (vector
)
8680 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8681 Vdeactivate_mark
= AREF (vector
, 1);
8682 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8684 if (WINDOWP (AREF (vector
, 3)))
8687 Lisp_Object buffer
, charpos
, bytepos
;
8689 w
= XWINDOW (AREF (vector
, 3));
8690 buffer
= AREF (vector
, 4);
8691 charpos
= AREF (vector
, 5);
8692 bytepos
= AREF (vector
, 6);
8695 set_marker_both (w
->pointm
, buffer
,
8696 XFASTINT (charpos
), XFASTINT (bytepos
));
8699 Vwith_echo_area_save_vector
= vector
;
8704 /* Set up the echo area for use by print functions. MULTIBYTE_P
8705 non-zero means we will print multibyte. */
8708 setup_echo_area_for_printing (multibyte_p
)
8711 /* If we can't find an echo area any more, exit. */
8712 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8715 ensure_echo_area_buffers ();
8717 if (!message_buf_print
)
8719 /* A message has been output since the last time we printed.
8720 Choose a fresh echo area buffer. */
8721 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8722 echo_area_buffer
[0] = echo_buffer
[1];
8724 echo_area_buffer
[0] = echo_buffer
[0];
8726 /* Switch to that buffer and clear it. */
8727 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8728 current_buffer
->truncate_lines
= Qnil
;
8732 int count
= SPECPDL_INDEX ();
8733 specbind (Qinhibit_read_only
, Qt
);
8734 /* Note that undo recording is always disabled. */
8736 unbind_to (count
, Qnil
);
8738 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8740 /* Set up the buffer for the multibyteness we need. */
8742 != !NILP (current_buffer
->enable_multibyte_characters
))
8743 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8745 /* Raise the frame containing the echo area. */
8746 if (minibuffer_auto_raise
)
8748 struct frame
*sf
= SELECTED_FRAME ();
8749 Lisp_Object mini_window
;
8750 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8751 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8754 message_log_maybe_newline ();
8755 message_buf_print
= 1;
8759 if (NILP (echo_area_buffer
[0]))
8761 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8762 echo_area_buffer
[0] = echo_buffer
[1];
8764 echo_area_buffer
[0] = echo_buffer
[0];
8767 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8769 /* Someone switched buffers between print requests. */
8770 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8771 current_buffer
->truncate_lines
= Qnil
;
8777 /* Display an echo area message in window W. Value is non-zero if W's
8778 height is changed. If display_last_displayed_message_p is
8779 non-zero, display the message that was last displayed, otherwise
8780 display the current message. */
8783 display_echo_area (w
)
8786 int i
, no_message_p
, window_height_changed_p
, count
;
8788 /* Temporarily disable garbage collections while displaying the echo
8789 area. This is done because a GC can print a message itself.
8790 That message would modify the echo area buffer's contents while a
8791 redisplay of the buffer is going on, and seriously confuse
8793 count
= inhibit_garbage_collection ();
8795 /* If there is no message, we must call display_echo_area_1
8796 nevertheless because it resizes the window. But we will have to
8797 reset the echo_area_buffer in question to nil at the end because
8798 with_echo_area_buffer will sets it to an empty buffer. */
8799 i
= display_last_displayed_message_p
? 1 : 0;
8800 no_message_p
= NILP (echo_area_buffer
[i
]);
8802 window_height_changed_p
8803 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8804 display_echo_area_1
,
8805 (EMACS_INT
) w
, Qnil
, 0, 0);
8808 echo_area_buffer
[i
] = Qnil
;
8810 unbind_to (count
, Qnil
);
8811 return window_height_changed_p
;
8815 /* Helper for display_echo_area. Display the current buffer which
8816 contains the current echo area message in window W, a mini-window,
8817 a pointer to which is passed in A1. A2..A4 are currently not used.
8818 Change the height of W so that all of the message is displayed.
8819 Value is non-zero if height of W was changed. */
8822 display_echo_area_1 (a1
, a2
, a3
, a4
)
8827 struct window
*w
= (struct window
*) a1
;
8829 struct text_pos start
;
8830 int window_height_changed_p
= 0;
8832 /* Do this before displaying, so that we have a large enough glyph
8833 matrix for the display. If we can't get enough space for the
8834 whole text, display the last N lines. That works by setting w->start. */
8835 window_height_changed_p
= resize_mini_window (w
, 0);
8837 /* Use the starting position chosen by resize_mini_window. */
8838 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8841 clear_glyph_matrix (w
->desired_matrix
);
8842 XSETWINDOW (window
, w
);
8843 try_window (window
, start
, 0);
8845 return window_height_changed_p
;
8849 /* Resize the echo area window to exactly the size needed for the
8850 currently displayed message, if there is one. If a mini-buffer
8851 is active, don't shrink it. */
8854 resize_echo_area_exactly ()
8856 if (BUFFERP (echo_area_buffer
[0])
8857 && WINDOWP (echo_area_window
))
8859 struct window
*w
= XWINDOW (echo_area_window
);
8861 Lisp_Object resize_exactly
;
8863 if (minibuf_level
== 0)
8864 resize_exactly
= Qt
;
8866 resize_exactly
= Qnil
;
8868 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8869 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8872 ++windows_or_buffers_changed
;
8873 ++update_mode_lines
;
8874 redisplay_internal (0);
8880 /* Callback function for with_echo_area_buffer, when used from
8881 resize_echo_area_exactly. A1 contains a pointer to the window to
8882 resize, EXACTLY non-nil means resize the mini-window exactly to the
8883 size of the text displayed. A3 and A4 are not used. Value is what
8884 resize_mini_window returns. */
8887 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8889 Lisp_Object exactly
;
8892 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8896 /* Resize mini-window W to fit the size of its contents. EXACT_P
8897 means size the window exactly to the size needed. Otherwise, it's
8898 only enlarged until W's buffer is empty.
8900 Set W->start to the right place to begin display. If the whole
8901 contents fit, start at the beginning. Otherwise, start so as
8902 to make the end of the contents appear. This is particularly
8903 important for y-or-n-p, but seems desirable generally.
8905 Value is non-zero if the window height has been changed. */
8908 resize_mini_window (w
, exact_p
)
8912 struct frame
*f
= XFRAME (w
->frame
);
8913 int window_height_changed_p
= 0;
8915 xassert (MINI_WINDOW_P (w
));
8917 /* By default, start display at the beginning. */
8918 set_marker_both (w
->start
, w
->buffer
,
8919 BUF_BEGV (XBUFFER (w
->buffer
)),
8920 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8922 /* Don't resize windows while redisplaying a window; it would
8923 confuse redisplay functions when the size of the window they are
8924 displaying changes from under them. Such a resizing can happen,
8925 for instance, when which-func prints a long message while
8926 we are running fontification-functions. We're running these
8927 functions with safe_call which binds inhibit-redisplay to t. */
8928 if (!NILP (Vinhibit_redisplay
))
8931 /* Nil means don't try to resize. */
8932 if (NILP (Vresize_mini_windows
)
8933 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8936 if (!FRAME_MINIBUF_ONLY_P (f
))
8939 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8940 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8941 int height
, max_height
;
8942 int unit
= FRAME_LINE_HEIGHT (f
);
8943 struct text_pos start
;
8944 struct buffer
*old_current_buffer
= NULL
;
8946 if (current_buffer
!= XBUFFER (w
->buffer
))
8948 old_current_buffer
= current_buffer
;
8949 set_buffer_internal (XBUFFER (w
->buffer
));
8952 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8954 /* Compute the max. number of lines specified by the user. */
8955 if (FLOATP (Vmax_mini_window_height
))
8956 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8957 else if (INTEGERP (Vmax_mini_window_height
))
8958 max_height
= XINT (Vmax_mini_window_height
);
8960 max_height
= total_height
/ 4;
8962 /* Correct that max. height if it's bogus. */
8963 max_height
= max (1, max_height
);
8964 max_height
= min (total_height
, max_height
);
8966 /* Find out the height of the text in the window. */
8967 if (it
.line_wrap
== TRUNCATE
)
8972 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8973 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8974 height
= it
.current_y
+ last_height
;
8976 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8977 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8978 height
= (height
+ unit
- 1) / unit
;
8981 /* Compute a suitable window start. */
8982 if (height
> max_height
)
8984 height
= max_height
;
8985 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8986 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8987 start
= it
.current
.pos
;
8990 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8991 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8993 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8995 /* Let it grow only, until we display an empty message, in which
8996 case the window shrinks again. */
8997 if (height
> WINDOW_TOTAL_LINES (w
))
8999 int old_height
= WINDOW_TOTAL_LINES (w
);
9000 freeze_window_starts (f
, 1);
9001 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9002 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9004 else if (height
< WINDOW_TOTAL_LINES (w
)
9005 && (exact_p
|| BEGV
== ZV
))
9007 int old_height
= WINDOW_TOTAL_LINES (w
);
9008 freeze_window_starts (f
, 0);
9009 shrink_mini_window (w
);
9010 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9015 /* Always resize to exact size needed. */
9016 if (height
> WINDOW_TOTAL_LINES (w
))
9018 int old_height
= WINDOW_TOTAL_LINES (w
);
9019 freeze_window_starts (f
, 1);
9020 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9021 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9023 else if (height
< WINDOW_TOTAL_LINES (w
))
9025 int old_height
= WINDOW_TOTAL_LINES (w
);
9026 freeze_window_starts (f
, 0);
9027 shrink_mini_window (w
);
9031 freeze_window_starts (f
, 1);
9032 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9035 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9039 if (old_current_buffer
)
9040 set_buffer_internal (old_current_buffer
);
9043 return window_height_changed_p
;
9047 /* Value is the current message, a string, or nil if there is no
9055 if (!BUFFERP (echo_area_buffer
[0]))
9059 with_echo_area_buffer (0, 0, current_message_1
,
9060 (EMACS_INT
) &msg
, Qnil
, 0, 0);
9062 echo_area_buffer
[0] = Qnil
;
9070 current_message_1 (a1
, a2
, a3
, a4
)
9075 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
9078 *msg
= make_buffer_string (BEG
, Z
, 1);
9085 /* Push the current message on Vmessage_stack for later restauration
9086 by restore_message. Value is non-zero if the current message isn't
9087 empty. This is a relatively infrequent operation, so it's not
9088 worth optimizing. */
9094 msg
= current_message ();
9095 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
9096 return STRINGP (msg
);
9100 /* Restore message display from the top of Vmessage_stack. */
9107 xassert (CONSP (Vmessage_stack
));
9108 msg
= XCAR (Vmessage_stack
);
9110 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9112 message3_nolog (msg
, 0, 0);
9116 /* Handler for record_unwind_protect calling pop_message. */
9119 pop_message_unwind (dummy
)
9126 /* Pop the top-most entry off Vmessage_stack. */
9131 xassert (CONSP (Vmessage_stack
));
9132 Vmessage_stack
= XCDR (Vmessage_stack
);
9136 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
9137 exits. If the stack is not empty, we have a missing pop_message
9141 check_message_stack ()
9143 if (!NILP (Vmessage_stack
))
9148 /* Truncate to NCHARS what will be displayed in the echo area the next
9149 time we display it---but don't redisplay it now. */
9152 truncate_echo_area (nchars
)
9156 echo_area_buffer
[0] = Qnil
;
9157 /* A null message buffer means that the frame hasn't really been
9158 initialized yet. Error messages get reported properly by
9159 cmd_error, so this must be just an informative message; toss it. */
9160 else if (!noninteractive
9162 && !NILP (echo_area_buffer
[0]))
9164 struct frame
*sf
= SELECTED_FRAME ();
9165 if (FRAME_MESSAGE_BUF (sf
))
9166 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
9171 /* Helper function for truncate_echo_area. Truncate the current
9172 message to at most NCHARS characters. */
9175 truncate_message_1 (nchars
, a2
, a3
, a4
)
9180 if (BEG
+ nchars
< Z
)
9181 del_range (BEG
+ nchars
, Z
);
9183 echo_area_buffer
[0] = Qnil
;
9188 /* Set the current message to a substring of S or STRING.
9190 If STRING is a Lisp string, set the message to the first NBYTES
9191 bytes from STRING. NBYTES zero means use the whole string. If
9192 STRING is multibyte, the message will be displayed multibyte.
9194 If S is not null, set the message to the first LEN bytes of S. LEN
9195 zero means use the whole string. MULTIBYTE_P non-zero means S is
9196 multibyte. Display the message multibyte in that case.
9198 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
9199 to t before calling set_message_1 (which calls insert).
9203 set_message (s
, string
, nbytes
, multibyte_p
)
9206 int nbytes
, multibyte_p
;
9208 message_enable_multibyte
9209 = ((s
&& multibyte_p
)
9210 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
9212 with_echo_area_buffer (0, -1, set_message_1
,
9213 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
9214 message_buf_print
= 0;
9215 help_echo_showing_p
= 0;
9219 /* Helper function for set_message. Arguments have the same meaning
9220 as there, with A1 corresponding to S and A2 corresponding to STRING
9221 This function is called with the echo area buffer being
9225 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
9228 EMACS_INT nbytes
, multibyte_p
;
9230 const char *s
= (const char *) a1
;
9231 Lisp_Object string
= a2
;
9233 /* Change multibyteness of the echo buffer appropriately. */
9234 if (message_enable_multibyte
9235 != !NILP (current_buffer
->enable_multibyte_characters
))
9236 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9238 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
9240 /* Insert new message at BEG. */
9241 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9243 if (STRINGP (string
))
9248 nbytes
= SBYTES (string
);
9249 nchars
= string_byte_to_char (string
, nbytes
);
9251 /* This function takes care of single/multibyte conversion. We
9252 just have to ensure that the echo area buffer has the right
9253 setting of enable_multibyte_characters. */
9254 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9259 nbytes
= strlen (s
);
9261 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
9263 /* Convert from multi-byte to single-byte. */
9265 unsigned char work
[1];
9267 /* Convert a multibyte string to single-byte. */
9268 for (i
= 0; i
< nbytes
; i
+= n
)
9270 c
= string_char_and_length (s
+ i
, &n
);
9271 work
[0] = (ASCII_CHAR_P (c
)
9273 : multibyte_char_to_unibyte (c
, Qnil
));
9274 insert_1_both (work
, 1, 1, 1, 0, 0);
9277 else if (!multibyte_p
9278 && !NILP (current_buffer
->enable_multibyte_characters
))
9280 /* Convert from single-byte to multi-byte. */
9282 const unsigned char *msg
= (const unsigned char *) s
;
9283 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9285 /* Convert a single-byte string to multibyte. */
9286 for (i
= 0; i
< nbytes
; i
++)
9289 MAKE_CHAR_MULTIBYTE (c
);
9290 n
= CHAR_STRING (c
, str
);
9291 insert_1_both (str
, 1, n
, 1, 0, 0);
9295 insert_1 (s
, nbytes
, 1, 0, 0);
9302 /* Clear messages. CURRENT_P non-zero means clear the current
9303 message. LAST_DISPLAYED_P non-zero means clear the message
9307 clear_message (current_p
, last_displayed_p
)
9308 int current_p
, last_displayed_p
;
9312 echo_area_buffer
[0] = Qnil
;
9313 message_cleared_p
= 1;
9316 if (last_displayed_p
)
9317 echo_area_buffer
[1] = Qnil
;
9319 message_buf_print
= 0;
9322 /* Clear garbaged frames.
9324 This function is used where the old redisplay called
9325 redraw_garbaged_frames which in turn called redraw_frame which in
9326 turn called clear_frame. The call to clear_frame was a source of
9327 flickering. I believe a clear_frame is not necessary. It should
9328 suffice in the new redisplay to invalidate all current matrices,
9329 and ensure a complete redisplay of all windows. */
9332 clear_garbaged_frames ()
9336 Lisp_Object tail
, frame
;
9337 int changed_count
= 0;
9339 FOR_EACH_FRAME (tail
, frame
)
9341 struct frame
*f
= XFRAME (frame
);
9343 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9347 Fredraw_frame (frame
);
9348 f
->force_flush_display_p
= 1;
9350 clear_current_matrices (f
);
9359 ++windows_or_buffers_changed
;
9364 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9365 is non-zero update selected_frame. Value is non-zero if the
9366 mini-windows height has been changed. */
9369 echo_area_display (update_frame_p
)
9372 Lisp_Object mini_window
;
9375 int window_height_changed_p
= 0;
9376 struct frame
*sf
= SELECTED_FRAME ();
9378 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9379 w
= XWINDOW (mini_window
);
9380 f
= XFRAME (WINDOW_FRAME (w
));
9382 /* Don't display if frame is invisible or not yet initialized. */
9383 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9386 #ifdef HAVE_WINDOW_SYSTEM
9387 /* When Emacs starts, selected_frame may be the initial terminal
9388 frame. If we let this through, a message would be displayed on
9390 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9392 #endif /* HAVE_WINDOW_SYSTEM */
9394 /* Redraw garbaged frames. */
9396 clear_garbaged_frames ();
9398 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9400 echo_area_window
= mini_window
;
9401 window_height_changed_p
= display_echo_area (w
);
9402 w
->must_be_updated_p
= 1;
9404 /* Update the display, unless called from redisplay_internal.
9405 Also don't update the screen during redisplay itself. The
9406 update will happen at the end of redisplay, and an update
9407 here could cause confusion. */
9408 if (update_frame_p
&& !redisplaying_p
)
9412 /* If the display update has been interrupted by pending
9413 input, update mode lines in the frame. Due to the
9414 pending input, it might have been that redisplay hasn't
9415 been called, so that mode lines above the echo area are
9416 garbaged. This looks odd, so we prevent it here. */
9417 if (!display_completed
)
9418 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9420 if (window_height_changed_p
9421 /* Don't do this if Emacs is shutting down. Redisplay
9422 needs to run hooks. */
9423 && !NILP (Vrun_hooks
))
9425 /* Must update other windows. Likewise as in other
9426 cases, don't let this update be interrupted by
9428 int count
= SPECPDL_INDEX ();
9429 specbind (Qredisplay_dont_pause
, Qt
);
9430 windows_or_buffers_changed
= 1;
9431 redisplay_internal (0);
9432 unbind_to (count
, Qnil
);
9434 else if (FRAME_WINDOW_P (f
) && n
== 0)
9436 /* Window configuration is the same as before.
9437 Can do with a display update of the echo area,
9438 unless we displayed some mode lines. */
9439 update_single_window (w
, 1);
9440 FRAME_RIF (f
)->flush_display (f
);
9443 update_frame (f
, 1, 1);
9445 /* If cursor is in the echo area, make sure that the next
9446 redisplay displays the minibuffer, so that the cursor will
9447 be replaced with what the minibuffer wants. */
9448 if (cursor_in_echo_area
)
9449 ++windows_or_buffers_changed
;
9452 else if (!EQ (mini_window
, selected_window
))
9453 windows_or_buffers_changed
++;
9455 /* Last displayed message is now the current message. */
9456 echo_area_buffer
[1] = echo_area_buffer
[0];
9457 /* Inform read_char that we're not echoing. */
9458 echo_message_buffer
= Qnil
;
9460 /* Prevent redisplay optimization in redisplay_internal by resetting
9461 this_line_start_pos. This is done because the mini-buffer now
9462 displays the message instead of its buffer text. */
9463 if (EQ (mini_window
, selected_window
))
9464 CHARPOS (this_line_start_pos
) = 0;
9466 return window_height_changed_p
;
9471 /***********************************************************************
9472 Mode Lines and Frame Titles
9473 ***********************************************************************/
9475 /* A buffer for constructing non-propertized mode-line strings and
9476 frame titles in it; allocated from the heap in init_xdisp and
9477 resized as needed in store_mode_line_noprop_char. */
9479 static char *mode_line_noprop_buf
;
9481 /* The buffer's end, and a current output position in it. */
9483 static char *mode_line_noprop_buf_end
;
9484 static char *mode_line_noprop_ptr
;
9486 #define MODE_LINE_NOPROP_LEN(start) \
9487 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9490 MODE_LINE_DISPLAY
= 0,
9496 /* Alist that caches the results of :propertize.
9497 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9498 static Lisp_Object mode_line_proptrans_alist
;
9500 /* List of strings making up the mode-line. */
9501 static Lisp_Object mode_line_string_list
;
9503 /* Base face property when building propertized mode line string. */
9504 static Lisp_Object mode_line_string_face
;
9505 static Lisp_Object mode_line_string_face_prop
;
9508 /* Unwind data for mode line strings */
9510 static Lisp_Object Vmode_line_unwind_vector
;
9513 format_mode_line_unwind_data (struct buffer
*obuf
,
9517 Lisp_Object vector
, tmp
;
9519 /* Reduce consing by keeping one vector in
9520 Vwith_echo_area_save_vector. */
9521 vector
= Vmode_line_unwind_vector
;
9522 Vmode_line_unwind_vector
= Qnil
;
9525 vector
= Fmake_vector (make_number (8), Qnil
);
9527 ASET (vector
, 0, make_number (mode_line_target
));
9528 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9529 ASET (vector
, 2, mode_line_string_list
);
9530 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9531 ASET (vector
, 4, mode_line_string_face
);
9532 ASET (vector
, 5, mode_line_string_face_prop
);
9535 XSETBUFFER (tmp
, obuf
);
9538 ASET (vector
, 6, tmp
);
9539 ASET (vector
, 7, owin
);
9545 unwind_format_mode_line (vector
)
9548 mode_line_target
= XINT (AREF (vector
, 0));
9549 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9550 mode_line_string_list
= AREF (vector
, 2);
9551 if (! EQ (AREF (vector
, 3), Qt
))
9552 mode_line_proptrans_alist
= AREF (vector
, 3);
9553 mode_line_string_face
= AREF (vector
, 4);
9554 mode_line_string_face_prop
= AREF (vector
, 5);
9556 if (!NILP (AREF (vector
, 7)))
9557 /* Select window before buffer, since it may change the buffer. */
9558 Fselect_window (AREF (vector
, 7), Qt
);
9560 if (!NILP (AREF (vector
, 6)))
9562 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9563 ASET (vector
, 6, Qnil
);
9566 Vmode_line_unwind_vector
= vector
;
9571 /* Store a single character C for the frame title in mode_line_noprop_buf.
9572 Re-allocate mode_line_noprop_buf if necessary. */
9576 store_mode_line_noprop_char (char c
)
9578 store_mode_line_noprop_char (c
)
9582 /* If output position has reached the end of the allocated buffer,
9583 double the buffer's size. */
9584 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9586 int len
= MODE_LINE_NOPROP_LEN (0);
9587 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9588 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9589 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9590 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9593 *mode_line_noprop_ptr
++ = c
;
9597 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9598 mode_line_noprop_ptr. STR is the string to store. Do not copy
9599 characters that yield more columns than PRECISION; PRECISION <= 0
9600 means copy the whole string. Pad with spaces until FIELD_WIDTH
9601 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9602 pad. Called from display_mode_element when it is used to build a
9606 store_mode_line_noprop (str
, field_width
, precision
)
9607 const unsigned char *str
;
9608 int field_width
, precision
;
9613 /* Copy at most PRECISION chars from STR. */
9614 nbytes
= strlen (str
);
9615 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9617 store_mode_line_noprop_char (*str
++);
9619 /* Fill up with spaces until FIELD_WIDTH reached. */
9620 while (field_width
> 0
9623 store_mode_line_noprop_char (' ');
9630 /***********************************************************************
9632 ***********************************************************************/
9634 #ifdef HAVE_WINDOW_SYSTEM
9636 /* Set the title of FRAME, if it has changed. The title format is
9637 Vicon_title_format if FRAME is iconified, otherwise it is
9638 frame_title_format. */
9641 x_consider_frame_title (frame
)
9644 struct frame
*f
= XFRAME (frame
);
9646 if (FRAME_WINDOW_P (f
)
9647 || FRAME_MINIBUF_ONLY_P (f
)
9648 || f
->explicit_name
)
9650 /* Do we have more than one visible frame on this X display? */
9657 int count
= SPECPDL_INDEX ();
9659 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9661 Lisp_Object other_frame
= XCAR (tail
);
9662 struct frame
*tf
= XFRAME (other_frame
);
9665 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9666 && !FRAME_MINIBUF_ONLY_P (tf
)
9667 && !EQ (other_frame
, tip_frame
)
9668 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9672 /* Set global variable indicating that multiple frames exist. */
9673 multiple_frames
= CONSP (tail
);
9675 /* Switch to the buffer of selected window of the frame. Set up
9676 mode_line_target so that display_mode_element will output into
9677 mode_line_noprop_buf; then display the title. */
9678 record_unwind_protect (unwind_format_mode_line
,
9679 format_mode_line_unwind_data
9680 (current_buffer
, selected_window
, 0));
9682 Fselect_window (f
->selected_window
, Qt
);
9683 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9684 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9686 mode_line_target
= MODE_LINE_TITLE
;
9687 title_start
= MODE_LINE_NOPROP_LEN (0);
9688 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9689 NULL
, DEFAULT_FACE_ID
);
9690 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9691 len
= MODE_LINE_NOPROP_LEN (title_start
);
9692 title
= mode_line_noprop_buf
+ title_start
;
9693 unbind_to (count
, Qnil
);
9695 /* Set the title only if it's changed. This avoids consing in
9696 the common case where it hasn't. (If it turns out that we've
9697 already wasted too much time by walking through the list with
9698 display_mode_element, then we might need to optimize at a
9699 higher level than this.) */
9700 if (! STRINGP (f
->name
)
9701 || SBYTES (f
->name
) != len
9702 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9707 if (!MINI_WINDOW_P(XWINDOW(f
->selected_window
)))
9710 ns_set_name_as_filename (f
);
9712 x_implicitly_set_name (f
, make_string(title
, len
),
9718 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9723 /* do this also for frames with explicit names */
9724 ns_implicitly_set_icon_type(f
);
9725 ns_set_doc_edited(f
, Fbuffer_modified_p
9726 (XWINDOW (f
->selected_window
)->buffer
), Qnil
);
9732 #endif /* not HAVE_WINDOW_SYSTEM */
9737 /***********************************************************************
9739 ***********************************************************************/
9742 /* Prepare for redisplay by updating menu-bar item lists when
9743 appropriate. This can call eval. */
9746 prepare_menu_bars ()
9749 struct gcpro gcpro1
, gcpro2
;
9751 Lisp_Object tooltip_frame
;
9753 #ifdef HAVE_WINDOW_SYSTEM
9754 tooltip_frame
= tip_frame
;
9756 tooltip_frame
= Qnil
;
9759 /* Update all frame titles based on their buffer names, etc. We do
9760 this before the menu bars so that the buffer-menu will show the
9761 up-to-date frame titles. */
9762 #ifdef HAVE_WINDOW_SYSTEM
9763 if (windows_or_buffers_changed
|| update_mode_lines
)
9765 Lisp_Object tail
, frame
;
9767 FOR_EACH_FRAME (tail
, frame
)
9770 if (!EQ (frame
, tooltip_frame
)
9771 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9772 x_consider_frame_title (frame
);
9775 #endif /* HAVE_WINDOW_SYSTEM */
9777 /* Update the menu bar item lists, if appropriate. This has to be
9778 done before any actual redisplay or generation of display lines. */
9779 all_windows
= (update_mode_lines
9780 || buffer_shared
> 1
9781 || windows_or_buffers_changed
);
9784 Lisp_Object tail
, frame
;
9785 int count
= SPECPDL_INDEX ();
9786 /* 1 means that update_menu_bar has run its hooks
9787 so any further calls to update_menu_bar shouldn't do so again. */
9788 int menu_bar_hooks_run
= 0;
9790 record_unwind_save_match_data ();
9792 FOR_EACH_FRAME (tail
, frame
)
9796 /* Ignore tooltip frame. */
9797 if (EQ (frame
, tooltip_frame
))
9800 /* If a window on this frame changed size, report that to
9801 the user and clear the size-change flag. */
9802 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9804 Lisp_Object functions
;
9806 /* Clear flag first in case we get an error below. */
9807 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9808 functions
= Vwindow_size_change_functions
;
9809 GCPRO2 (tail
, functions
);
9811 while (CONSP (functions
))
9813 if (!EQ (XCAR (functions
), Qt
))
9814 call1 (XCAR (functions
), frame
);
9815 functions
= XCDR (functions
);
9821 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9822 #ifdef HAVE_WINDOW_SYSTEM
9823 update_tool_bar (f
, 0);
9828 unbind_to (count
, Qnil
);
9832 struct frame
*sf
= SELECTED_FRAME ();
9833 update_menu_bar (sf
, 1, 0);
9834 #ifdef HAVE_WINDOW_SYSTEM
9835 update_tool_bar (sf
, 1);
9839 /* Motif needs this. See comment in xmenu.c. Turn it off when
9840 pending_menu_activation is not defined. */
9841 #ifdef USE_X_TOOLKIT
9842 pending_menu_activation
= 0;
9847 /* Update the menu bar item list for frame F. This has to be done
9848 before we start to fill in any display lines, because it can call
9851 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9853 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9854 already ran the menu bar hooks for this redisplay, so there
9855 is no need to run them again. The return value is the
9856 updated value of this flag, to pass to the next call. */
9859 update_menu_bar (f
, save_match_data
, hooks_run
)
9861 int save_match_data
;
9865 register struct window
*w
;
9867 /* If called recursively during a menu update, do nothing. This can
9868 happen when, for instance, an activate-menubar-hook causes a
9870 if (inhibit_menubar_update
)
9873 window
= FRAME_SELECTED_WINDOW (f
);
9874 w
= XWINDOW (window
);
9876 if (FRAME_WINDOW_P (f
)
9878 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9879 || defined (HAVE_NS) || defined (USE_GTK)
9880 FRAME_EXTERNAL_MENU_BAR (f
)
9882 FRAME_MENU_BAR_LINES (f
) > 0
9884 : FRAME_MENU_BAR_LINES (f
) > 0)
9886 /* If the user has switched buffers or windows, we need to
9887 recompute to reflect the new bindings. But we'll
9888 recompute when update_mode_lines is set too; that means
9889 that people can use force-mode-line-update to request
9890 that the menu bar be recomputed. The adverse effect on
9891 the rest of the redisplay algorithm is about the same as
9892 windows_or_buffers_changed anyway. */
9893 if (windows_or_buffers_changed
9894 /* This used to test w->update_mode_line, but we believe
9895 there is no need to recompute the menu in that case. */
9896 || update_mode_lines
9897 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9898 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9899 != !NILP (w
->last_had_star
))
9900 || ((!NILP (Vtransient_mark_mode
)
9901 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9902 != !NILP (w
->region_showing
)))
9904 struct buffer
*prev
= current_buffer
;
9905 int count
= SPECPDL_INDEX ();
9907 specbind (Qinhibit_menubar_update
, Qt
);
9909 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9910 if (save_match_data
)
9911 record_unwind_save_match_data ();
9912 if (NILP (Voverriding_local_map_menu_flag
))
9914 specbind (Qoverriding_terminal_local_map
, Qnil
);
9915 specbind (Qoverriding_local_map
, Qnil
);
9920 /* Run the Lucid hook. */
9921 safe_run_hooks (Qactivate_menubar_hook
);
9923 /* If it has changed current-menubar from previous value,
9924 really recompute the menu-bar from the value. */
9925 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9926 call0 (Qrecompute_lucid_menubar
);
9928 safe_run_hooks (Qmenu_bar_update_hook
);
9933 XSETFRAME (Vmenu_updating_frame
, f
);
9934 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9936 /* Redisplay the menu bar in case we changed it. */
9937 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9938 || defined (HAVE_NS) || defined (USE_GTK)
9939 if (FRAME_WINDOW_P (f
))
9941 #if defined (HAVE_NS)
9942 /* All frames on Mac OS share the same menubar. So only
9943 the selected frame should be allowed to set it. */
9944 if (f
== SELECTED_FRAME ())
9946 set_frame_menubar (f
, 0, 0);
9949 /* On a terminal screen, the menu bar is an ordinary screen
9950 line, and this makes it get updated. */
9951 w
->update_mode_line
= Qt
;
9952 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9953 /* In the non-toolkit version, the menu bar is an ordinary screen
9954 line, and this makes it get updated. */
9955 w
->update_mode_line
= Qt
;
9956 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9958 unbind_to (count
, Qnil
);
9959 set_buffer_internal_1 (prev
);
9968 /***********************************************************************
9970 ***********************************************************************/
9972 #ifdef HAVE_WINDOW_SYSTEM
9975 Nominal cursor position -- where to draw output.
9976 HPOS and VPOS are window relative glyph matrix coordinates.
9977 X and Y are window relative pixel coordinates. */
9979 struct cursor_pos output_cursor
;
9983 Set the global variable output_cursor to CURSOR. All cursor
9984 positions are relative to updated_window. */
9987 set_output_cursor (cursor
)
9988 struct cursor_pos
*cursor
;
9990 output_cursor
.hpos
= cursor
->hpos
;
9991 output_cursor
.vpos
= cursor
->vpos
;
9992 output_cursor
.x
= cursor
->x
;
9993 output_cursor
.y
= cursor
->y
;
9998 Set a nominal cursor position.
10000 HPOS and VPOS are column/row positions in a window glyph matrix. X
10001 and Y are window text area relative pixel positions.
10003 If this is done during an update, updated_window will contain the
10004 window that is being updated and the position is the future output
10005 cursor position for that window. If updated_window is null, use
10006 selected_window and display the cursor at the given position. */
10009 x_cursor_to (vpos
, hpos
, y
, x
)
10010 int vpos
, hpos
, y
, x
;
10014 /* If updated_window is not set, work on selected_window. */
10015 if (updated_window
)
10016 w
= updated_window
;
10018 w
= XWINDOW (selected_window
);
10020 /* Set the output cursor. */
10021 output_cursor
.hpos
= hpos
;
10022 output_cursor
.vpos
= vpos
;
10023 output_cursor
.x
= x
;
10024 output_cursor
.y
= y
;
10026 /* If not called as part of an update, really display the cursor.
10027 This will also set the cursor position of W. */
10028 if (updated_window
== NULL
)
10031 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
10032 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
10033 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
10038 #endif /* HAVE_WINDOW_SYSTEM */
10041 /***********************************************************************
10043 ***********************************************************************/
10045 #ifdef HAVE_WINDOW_SYSTEM
10047 /* Where the mouse was last time we reported a mouse event. */
10049 FRAME_PTR last_mouse_frame
;
10051 /* Tool-bar item index of the item on which a mouse button was pressed
10054 int last_tool_bar_item
;
10058 update_tool_bar_unwind (frame
)
10061 selected_frame
= frame
;
10065 /* Update the tool-bar item list for frame F. This has to be done
10066 before we start to fill in any display lines. Called from
10067 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
10068 and restore it here. */
10071 update_tool_bar (f
, save_match_data
)
10073 int save_match_data
;
10075 #if defined (USE_GTK) || defined (HAVE_NS)
10076 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
10078 int do_update
= WINDOWP (f
->tool_bar_window
)
10079 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
10084 Lisp_Object window
;
10087 window
= FRAME_SELECTED_WINDOW (f
);
10088 w
= XWINDOW (window
);
10090 /* If the user has switched buffers or windows, we need to
10091 recompute to reflect the new bindings. But we'll
10092 recompute when update_mode_lines is set too; that means
10093 that people can use force-mode-line-update to request
10094 that the menu bar be recomputed. The adverse effect on
10095 the rest of the redisplay algorithm is about the same as
10096 windows_or_buffers_changed anyway. */
10097 if (windows_or_buffers_changed
10098 || !NILP (w
->update_mode_line
)
10099 || update_mode_lines
10100 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10101 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10102 != !NILP (w
->last_had_star
))
10103 || ((!NILP (Vtransient_mark_mode
)
10104 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10105 != !NILP (w
->region_showing
)))
10107 struct buffer
*prev
= current_buffer
;
10108 int count
= SPECPDL_INDEX ();
10109 Lisp_Object frame
, new_tool_bar
;
10110 int new_n_tool_bar
;
10111 struct gcpro gcpro1
;
10113 /* Set current_buffer to the buffer of the selected
10114 window of the frame, so that we get the right local
10116 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10118 /* Save match data, if we must. */
10119 if (save_match_data
)
10120 record_unwind_save_match_data ();
10122 /* Make sure that we don't accidentally use bogus keymaps. */
10123 if (NILP (Voverriding_local_map_menu_flag
))
10125 specbind (Qoverriding_terminal_local_map
, Qnil
);
10126 specbind (Qoverriding_local_map
, Qnil
);
10129 GCPRO1 (new_tool_bar
);
10131 /* We must temporarily set the selected frame to this frame
10132 before calling tool_bar_items, because the calculation of
10133 the tool-bar keymap uses the selected frame (see
10134 `tool-bar-make-keymap' in tool-bar.el). */
10135 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
10136 XSETFRAME (frame
, f
);
10137 selected_frame
= frame
;
10139 /* Build desired tool-bar items from keymaps. */
10140 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
10143 /* Redisplay the tool-bar if we changed it. */
10144 if (new_n_tool_bar
!= f
->n_tool_bar_items
10145 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
10147 /* Redisplay that happens asynchronously due to an expose event
10148 may access f->tool_bar_items. Make sure we update both
10149 variables within BLOCK_INPUT so no such event interrupts. */
10151 f
->tool_bar_items
= new_tool_bar
;
10152 f
->n_tool_bar_items
= new_n_tool_bar
;
10153 w
->update_mode_line
= Qt
;
10159 unbind_to (count
, Qnil
);
10160 set_buffer_internal_1 (prev
);
10166 /* Set F->desired_tool_bar_string to a Lisp string representing frame
10167 F's desired tool-bar contents. F->tool_bar_items must have
10168 been set up previously by calling prepare_menu_bars. */
10171 build_desired_tool_bar_string (f
)
10174 int i
, size
, size_needed
;
10175 struct gcpro gcpro1
, gcpro2
, gcpro3
;
10176 Lisp_Object image
, plist
, props
;
10178 image
= plist
= props
= Qnil
;
10179 GCPRO3 (image
, plist
, props
);
10181 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
10182 Otherwise, make a new string. */
10184 /* The size of the string we might be able to reuse. */
10185 size
= (STRINGP (f
->desired_tool_bar_string
)
10186 ? SCHARS (f
->desired_tool_bar_string
)
10189 /* We need one space in the string for each image. */
10190 size_needed
= f
->n_tool_bar_items
;
10192 /* Reuse f->desired_tool_bar_string, if possible. */
10193 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
10194 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
10195 make_number (' '));
10198 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
10199 Fremove_text_properties (make_number (0), make_number (size
),
10200 props
, f
->desired_tool_bar_string
);
10203 /* Put a `display' property on the string for the images to display,
10204 put a `menu_item' property on tool-bar items with a value that
10205 is the index of the item in F's tool-bar item vector. */
10206 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
10208 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
10210 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
10211 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
10212 int hmargin
, vmargin
, relief
, idx
, end
;
10213 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
10215 /* If image is a vector, choose the image according to the
10217 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
10218 if (VECTORP (image
))
10222 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
10223 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
10226 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
10227 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
10229 xassert (ASIZE (image
) >= idx
);
10230 image
= AREF (image
, idx
);
10235 /* Ignore invalid image specifications. */
10236 if (!valid_image_p (image
))
10239 /* Display the tool-bar button pressed, or depressed. */
10240 plist
= Fcopy_sequence (XCDR (image
));
10242 /* Compute margin and relief to draw. */
10243 relief
= (tool_bar_button_relief
>= 0
10244 ? tool_bar_button_relief
10245 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10246 hmargin
= vmargin
= relief
;
10248 if (INTEGERP (Vtool_bar_button_margin
)
10249 && XINT (Vtool_bar_button_margin
) > 0)
10251 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10252 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10254 else if (CONSP (Vtool_bar_button_margin
))
10256 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10257 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10258 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10260 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10261 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10262 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10265 if (auto_raise_tool_bar_buttons_p
)
10267 /* Add a `:relief' property to the image spec if the item is
10271 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10278 /* If image is selected, display it pressed, i.e. with a
10279 negative relief. If it's not selected, display it with a
10281 plist
= Fplist_put (plist
, QCrelief
,
10283 ? make_number (-relief
)
10284 : make_number (relief
)));
10289 /* Put a margin around the image. */
10290 if (hmargin
|| vmargin
)
10292 if (hmargin
== vmargin
)
10293 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10295 plist
= Fplist_put (plist
, QCmargin
,
10296 Fcons (make_number (hmargin
),
10297 make_number (vmargin
)));
10300 /* If button is not enabled, and we don't have special images
10301 for the disabled state, make the image appear disabled by
10302 applying an appropriate algorithm to it. */
10303 if (!enabled_p
&& idx
< 0)
10304 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10306 /* Put a `display' text property on the string for the image to
10307 display. Put a `menu-item' property on the string that gives
10308 the start of this item's properties in the tool-bar items
10310 image
= Fcons (Qimage
, plist
);
10311 props
= list4 (Qdisplay
, image
,
10312 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10314 /* Let the last image hide all remaining spaces in the tool bar
10315 string. The string can be longer than needed when we reuse a
10316 previous string. */
10317 if (i
+ 1 == f
->n_tool_bar_items
)
10318 end
= SCHARS (f
->desired_tool_bar_string
);
10321 Fadd_text_properties (make_number (i
), make_number (end
),
10322 props
, f
->desired_tool_bar_string
);
10330 /* Display one line of the tool-bar of frame IT->f.
10332 HEIGHT specifies the desired height of the tool-bar line.
10333 If the actual height of the glyph row is less than HEIGHT, the
10334 row's height is increased to HEIGHT, and the icons are centered
10335 vertically in the new height.
10337 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10338 count a final empty row in case the tool-bar width exactly matches
10343 display_tool_bar_line (it
, height
)
10347 struct glyph_row
*row
= it
->glyph_row
;
10348 int max_x
= it
->last_visible_x
;
10349 struct glyph
*last
;
10351 prepare_desired_row (row
);
10352 row
->y
= it
->current_y
;
10354 /* Note that this isn't made use of if the face hasn't a box,
10355 so there's no need to check the face here. */
10356 it
->start_of_box_run_p
= 1;
10358 while (it
->current_x
< max_x
)
10360 int x
, n_glyphs_before
, i
, nglyphs
;
10361 struct it it_before
;
10363 /* Get the next display element. */
10364 if (!get_next_display_element (it
))
10366 /* Don't count empty row if we are counting needed tool-bar lines. */
10367 if (height
< 0 && !it
->hpos
)
10372 /* Produce glyphs. */
10373 n_glyphs_before
= row
->used
[TEXT_AREA
];
10376 PRODUCE_GLYPHS (it
);
10378 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10380 x
= it_before
.current_x
;
10381 while (i
< nglyphs
)
10383 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10385 if (x
+ glyph
->pixel_width
> max_x
)
10387 /* Glyph doesn't fit on line. Backtrack. */
10388 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10390 /* If this is the only glyph on this line, it will never fit on the
10391 toolbar, so skip it. But ensure there is at least one glyph,
10392 so we don't accidentally disable the tool-bar. */
10393 if (n_glyphs_before
== 0
10394 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10400 x
+= glyph
->pixel_width
;
10404 /* Stop at line ends. */
10405 if (ITERATOR_AT_END_OF_LINE_P (it
))
10408 set_iterator_to_next (it
, 1);
10413 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10415 /* Use default face for the border below the tool bar.
10417 FIXME: When auto-resize-tool-bars is grow-only, there is
10418 no additional border below the possibly empty tool-bar lines.
10419 So to make the extra empty lines look "normal", we have to
10420 use the tool-bar face for the border too. */
10421 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10422 it
->face_id
= DEFAULT_FACE_ID
;
10424 extend_face_to_end_of_line (it
);
10425 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10426 last
->right_box_line_p
= 1;
10427 if (last
== row
->glyphs
[TEXT_AREA
])
10428 last
->left_box_line_p
= 1;
10430 /* Make line the desired height and center it vertically. */
10431 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10433 /* Don't add more than one line height. */
10434 height
%= FRAME_LINE_HEIGHT (it
->f
);
10435 it
->max_ascent
+= height
/ 2;
10436 it
->max_descent
+= (height
+ 1) / 2;
10439 compute_line_metrics (it
);
10441 /* If line is empty, make it occupy the rest of the tool-bar. */
10442 if (!row
->displays_text_p
)
10444 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10445 row
->visible_height
= row
->height
;
10446 row
->ascent
= row
->phys_ascent
= 0;
10447 row
->extra_line_spacing
= 0;
10450 row
->full_width_p
= 1;
10451 row
->continued_p
= 0;
10452 row
->truncated_on_left_p
= 0;
10453 row
->truncated_on_right_p
= 0;
10455 it
->current_x
= it
->hpos
= 0;
10456 it
->current_y
+= row
->height
;
10462 /* Max tool-bar height. */
10464 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10465 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10467 /* Value is the number of screen lines needed to make all tool-bar
10468 items of frame F visible. The number of actual rows needed is
10469 returned in *N_ROWS if non-NULL. */
10472 tool_bar_lines_needed (f
, n_rows
)
10476 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10478 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10479 the desired matrix, so use (unused) mode-line row as temporary row to
10480 avoid destroying the first tool-bar row. */
10481 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10483 /* Initialize an iterator for iteration over
10484 F->desired_tool_bar_string in the tool-bar window of frame F. */
10485 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10486 it
.first_visible_x
= 0;
10487 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10488 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10490 while (!ITERATOR_AT_END_P (&it
))
10492 clear_glyph_row (temp_row
);
10493 it
.glyph_row
= temp_row
;
10494 display_tool_bar_line (&it
, -1);
10496 clear_glyph_row (temp_row
);
10498 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10500 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10502 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10506 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10508 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10517 frame
= selected_frame
;
10519 CHECK_FRAME (frame
);
10520 f
= XFRAME (frame
);
10522 if (WINDOWP (f
->tool_bar_window
)
10523 || (w
= XWINDOW (f
->tool_bar_window
),
10524 WINDOW_TOTAL_LINES (w
) > 0))
10526 update_tool_bar (f
, 1);
10527 if (f
->n_tool_bar_items
)
10529 build_desired_tool_bar_string (f
);
10530 nlines
= tool_bar_lines_needed (f
, NULL
);
10534 return make_number (nlines
);
10538 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10539 height should be changed. */
10542 redisplay_tool_bar (f
)
10547 struct glyph_row
*row
;
10549 #if defined (USE_GTK) || defined (HAVE_NS)
10550 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10551 update_frame_tool_bar (f
);
10555 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10556 do anything. This means you must start with tool-bar-lines
10557 non-zero to get the auto-sizing effect. Or in other words, you
10558 can turn off tool-bars by specifying tool-bar-lines zero. */
10559 if (!WINDOWP (f
->tool_bar_window
)
10560 || (w
= XWINDOW (f
->tool_bar_window
),
10561 WINDOW_TOTAL_LINES (w
) == 0))
10564 /* Set up an iterator for the tool-bar window. */
10565 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10566 it
.first_visible_x
= 0;
10567 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10568 row
= it
.glyph_row
;
10570 /* Build a string that represents the contents of the tool-bar. */
10571 build_desired_tool_bar_string (f
);
10572 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10574 if (f
->n_tool_bar_rows
== 0)
10578 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10579 nlines
!= WINDOW_TOTAL_LINES (w
)))
10581 extern Lisp_Object Qtool_bar_lines
;
10583 int old_height
= WINDOW_TOTAL_LINES (w
);
10585 XSETFRAME (frame
, f
);
10586 Fmodify_frame_parameters (frame
,
10587 Fcons (Fcons (Qtool_bar_lines
,
10588 make_number (nlines
)),
10590 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10592 clear_glyph_matrix (w
->desired_matrix
);
10593 fonts_changed_p
= 1;
10599 /* Display as many lines as needed to display all tool-bar items. */
10601 if (f
->n_tool_bar_rows
> 0)
10603 int border
, rows
, height
, extra
;
10605 if (INTEGERP (Vtool_bar_border
))
10606 border
= XINT (Vtool_bar_border
);
10607 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10608 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10609 else if (EQ (Vtool_bar_border
, Qborder_width
))
10610 border
= f
->border_width
;
10616 rows
= f
->n_tool_bar_rows
;
10617 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10618 extra
= it
.last_visible_y
- border
- height
* rows
;
10620 while (it
.current_y
< it
.last_visible_y
)
10623 if (extra
> 0 && rows
-- > 0)
10625 h
= (extra
+ rows
- 1) / rows
;
10628 display_tool_bar_line (&it
, height
+ h
);
10633 while (it
.current_y
< it
.last_visible_y
)
10634 display_tool_bar_line (&it
, 0);
10637 /* It doesn't make much sense to try scrolling in the tool-bar
10638 window, so don't do it. */
10639 w
->desired_matrix
->no_scrolling_p
= 1;
10640 w
->must_be_updated_p
= 1;
10642 if (!NILP (Vauto_resize_tool_bars
))
10644 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10645 int change_height_p
= 0;
10647 /* If we couldn't display everything, change the tool-bar's
10648 height if there is room for more. */
10649 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10650 && it
.current_y
< max_tool_bar_height
)
10651 change_height_p
= 1;
10653 row
= it
.glyph_row
- 1;
10655 /* If there are blank lines at the end, except for a partially
10656 visible blank line at the end that is smaller than
10657 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10658 if (!row
->displays_text_p
10659 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10660 change_height_p
= 1;
10662 /* If row displays tool-bar items, but is partially visible,
10663 change the tool-bar's height. */
10664 if (row
->displays_text_p
10665 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10666 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10667 change_height_p
= 1;
10669 /* Resize windows as needed by changing the `tool-bar-lines'
10670 frame parameter. */
10671 if (change_height_p
)
10673 extern Lisp_Object Qtool_bar_lines
;
10675 int old_height
= WINDOW_TOTAL_LINES (w
);
10677 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10679 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10680 && !f
->minimize_tool_bar_window_p
)
10681 ? (nlines
> old_height
)
10682 : (nlines
!= old_height
));
10683 f
->minimize_tool_bar_window_p
= 0;
10685 if (change_height_p
)
10687 XSETFRAME (frame
, f
);
10688 Fmodify_frame_parameters (frame
,
10689 Fcons (Fcons (Qtool_bar_lines
,
10690 make_number (nlines
)),
10692 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10694 clear_glyph_matrix (w
->desired_matrix
);
10695 f
->n_tool_bar_rows
= nrows
;
10696 fonts_changed_p
= 1;
10703 f
->minimize_tool_bar_window_p
= 0;
10708 /* Get information about the tool-bar item which is displayed in GLYPH
10709 on frame F. Return in *PROP_IDX the index where tool-bar item
10710 properties start in F->tool_bar_items. Value is zero if
10711 GLYPH doesn't display a tool-bar item. */
10714 tool_bar_item_info (f
, glyph
, prop_idx
)
10716 struct glyph
*glyph
;
10723 /* This function can be called asynchronously, which means we must
10724 exclude any possibility that Fget_text_property signals an
10726 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10727 charpos
= max (0, charpos
);
10729 /* Get the text property `menu-item' at pos. The value of that
10730 property is the start index of this item's properties in
10731 F->tool_bar_items. */
10732 prop
= Fget_text_property (make_number (charpos
),
10733 Qmenu_item
, f
->current_tool_bar_string
);
10734 if (INTEGERP (prop
))
10736 *prop_idx
= XINT (prop
);
10746 /* Get information about the tool-bar item at position X/Y on frame F.
10747 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10748 the current matrix of the tool-bar window of F, or NULL if not
10749 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10750 item in F->tool_bar_items. Value is
10752 -1 if X/Y is not on a tool-bar item
10753 0 if X/Y is on the same item that was highlighted before.
10757 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10760 struct glyph
**glyph
;
10761 int *hpos
, *vpos
, *prop_idx
;
10763 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10764 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10767 /* Find the glyph under X/Y. */
10768 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10769 if (*glyph
== NULL
)
10772 /* Get the start of this tool-bar item's properties in
10773 f->tool_bar_items. */
10774 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10777 /* Is mouse on the highlighted item? */
10778 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10779 && *vpos
>= dpyinfo
->mouse_face_beg_row
10780 && *vpos
<= dpyinfo
->mouse_face_end_row
10781 && (*vpos
> dpyinfo
->mouse_face_beg_row
10782 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10783 && (*vpos
< dpyinfo
->mouse_face_end_row
10784 || *hpos
< dpyinfo
->mouse_face_end_col
10785 || dpyinfo
->mouse_face_past_end
))
10793 Handle mouse button event on the tool-bar of frame F, at
10794 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10795 0 for button release. MODIFIERS is event modifiers for button
10799 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10802 unsigned int modifiers
;
10804 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10805 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10806 int hpos
, vpos
, prop_idx
;
10807 struct glyph
*glyph
;
10808 Lisp_Object enabled_p
;
10810 /* If not on the highlighted tool-bar item, return. */
10811 frame_to_window_pixel_xy (w
, &x
, &y
);
10812 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10815 /* If item is disabled, do nothing. */
10816 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10817 if (NILP (enabled_p
))
10822 /* Show item in pressed state. */
10823 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10824 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10825 last_tool_bar_item
= prop_idx
;
10829 Lisp_Object key
, frame
;
10830 struct input_event event
;
10831 EVENT_INIT (event
);
10833 /* Show item in released state. */
10834 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10835 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10837 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10839 XSETFRAME (frame
, f
);
10840 event
.kind
= TOOL_BAR_EVENT
;
10841 event
.frame_or_window
= frame
;
10843 kbd_buffer_store_event (&event
);
10845 event
.kind
= TOOL_BAR_EVENT
;
10846 event
.frame_or_window
= frame
;
10848 event
.modifiers
= modifiers
;
10849 kbd_buffer_store_event (&event
);
10850 last_tool_bar_item
= -1;
10855 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10856 tool-bar window-relative coordinates X/Y. Called from
10857 note_mouse_highlight. */
10860 note_tool_bar_highlight (f
, x
, y
)
10864 Lisp_Object window
= f
->tool_bar_window
;
10865 struct window
*w
= XWINDOW (window
);
10866 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10868 struct glyph
*glyph
;
10869 struct glyph_row
*row
;
10871 Lisp_Object enabled_p
;
10873 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10874 int mouse_down_p
, rc
;
10876 /* Function note_mouse_highlight is called with negative x(y
10877 values when mouse moves outside of the frame. */
10878 if (x
<= 0 || y
<= 0)
10880 clear_mouse_face (dpyinfo
);
10884 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10887 /* Not on tool-bar item. */
10888 clear_mouse_face (dpyinfo
);
10892 /* On same tool-bar item as before. */
10893 goto set_help_echo
;
10895 clear_mouse_face (dpyinfo
);
10897 /* Mouse is down, but on different tool-bar item? */
10898 mouse_down_p
= (dpyinfo
->grabbed
10899 && f
== last_mouse_frame
10900 && FRAME_LIVE_P (f
));
10902 && last_tool_bar_item
!= prop_idx
)
10905 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10906 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10908 /* If tool-bar item is not enabled, don't highlight it. */
10909 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10910 if (!NILP (enabled_p
))
10912 /* Compute the x-position of the glyph. In front and past the
10913 image is a space. We include this in the highlighted area. */
10914 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10915 for (i
= x
= 0; i
< hpos
; ++i
)
10916 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10918 /* Record this as the current active region. */
10919 dpyinfo
->mouse_face_beg_col
= hpos
;
10920 dpyinfo
->mouse_face_beg_row
= vpos
;
10921 dpyinfo
->mouse_face_beg_x
= x
;
10922 dpyinfo
->mouse_face_beg_y
= row
->y
;
10923 dpyinfo
->mouse_face_past_end
= 0;
10925 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10926 dpyinfo
->mouse_face_end_row
= vpos
;
10927 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10928 dpyinfo
->mouse_face_end_y
= row
->y
;
10929 dpyinfo
->mouse_face_window
= window
;
10930 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10932 /* Display it as active. */
10933 show_mouse_face (dpyinfo
, draw
);
10934 dpyinfo
->mouse_face_image_state
= draw
;
10939 /* Set help_echo_string to a help string to display for this tool-bar item.
10940 XTread_socket does the rest. */
10941 help_echo_object
= help_echo_window
= Qnil
;
10942 help_echo_pos
= -1;
10943 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10944 if (NILP (help_echo_string
))
10945 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10948 #endif /* HAVE_WINDOW_SYSTEM */
10952 /************************************************************************
10953 Horizontal scrolling
10954 ************************************************************************/
10956 static int hscroll_window_tree
P_ ((Lisp_Object
));
10957 static int hscroll_windows
P_ ((Lisp_Object
));
10959 /* For all leaf windows in the window tree rooted at WINDOW, set their
10960 hscroll value so that PT is (i) visible in the window, and (ii) so
10961 that it is not within a certain margin at the window's left and
10962 right border. Value is non-zero if any window's hscroll has been
10966 hscroll_window_tree (window
)
10967 Lisp_Object window
;
10969 int hscrolled_p
= 0;
10970 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10971 int hscroll_step_abs
= 0;
10972 double hscroll_step_rel
= 0;
10974 if (hscroll_relative_p
)
10976 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10977 if (hscroll_step_rel
< 0)
10979 hscroll_relative_p
= 0;
10980 hscroll_step_abs
= 0;
10983 else if (INTEGERP (Vhscroll_step
))
10985 hscroll_step_abs
= XINT (Vhscroll_step
);
10986 if (hscroll_step_abs
< 0)
10987 hscroll_step_abs
= 0;
10990 hscroll_step_abs
= 0;
10992 while (WINDOWP (window
))
10994 struct window
*w
= XWINDOW (window
);
10996 if (WINDOWP (w
->hchild
))
10997 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10998 else if (WINDOWP (w
->vchild
))
10999 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
11000 else if (w
->cursor
.vpos
>= 0)
11003 int text_area_width
;
11004 struct glyph_row
*current_cursor_row
11005 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
11006 struct glyph_row
*desired_cursor_row
11007 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
11008 struct glyph_row
*cursor_row
11009 = (desired_cursor_row
->enabled_p
11010 ? desired_cursor_row
11011 : current_cursor_row
);
11013 text_area_width
= window_box_width (w
, TEXT_AREA
);
11015 /* Scroll when cursor is inside this scroll margin. */
11016 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
11018 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
11019 && ((XFASTINT (w
->hscroll
)
11020 && w
->cursor
.x
<= h_margin
)
11021 || (cursor_row
->enabled_p
11022 && cursor_row
->truncated_on_right_p
11023 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
11027 struct buffer
*saved_current_buffer
;
11031 /* Find point in a display of infinite width. */
11032 saved_current_buffer
= current_buffer
;
11033 current_buffer
= XBUFFER (w
->buffer
);
11035 if (w
== XWINDOW (selected_window
))
11036 pt
= BUF_PT (current_buffer
);
11039 pt
= marker_position (w
->pointm
);
11040 pt
= max (BEGV
, pt
);
11044 /* Move iterator to pt starting at cursor_row->start in
11045 a line with infinite width. */
11046 init_to_row_start (&it
, w
, cursor_row
);
11047 it
.last_visible_x
= INFINITY
;
11048 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
11049 current_buffer
= saved_current_buffer
;
11051 /* Position cursor in window. */
11052 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
11053 hscroll
= max (0, (it
.current_x
11054 - (ITERATOR_AT_END_OF_LINE_P (&it
)
11055 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
11056 : (text_area_width
/ 2))))
11057 / FRAME_COLUMN_WIDTH (it
.f
);
11058 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
11060 if (hscroll_relative_p
)
11061 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
11064 wanted_x
= text_area_width
11065 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11068 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11072 if (hscroll_relative_p
)
11073 wanted_x
= text_area_width
* hscroll_step_rel
11076 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11079 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11081 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
11083 /* Don't call Fset_window_hscroll if value hasn't
11084 changed because it will prevent redisplay
11086 if (XFASTINT (w
->hscroll
) != hscroll
)
11088 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
11089 w
->hscroll
= make_number (hscroll
);
11098 /* Value is non-zero if hscroll of any leaf window has been changed. */
11099 return hscrolled_p
;
11103 /* Set hscroll so that cursor is visible and not inside horizontal
11104 scroll margins for all windows in the tree rooted at WINDOW. See
11105 also hscroll_window_tree above. Value is non-zero if any window's
11106 hscroll has been changed. If it has, desired matrices on the frame
11107 of WINDOW are cleared. */
11110 hscroll_windows (window
)
11111 Lisp_Object window
;
11113 int hscrolled_p
= hscroll_window_tree (window
);
11115 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
11116 return hscrolled_p
;
11121 /************************************************************************
11123 ************************************************************************/
11125 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
11126 to a non-zero value. This is sometimes handy to have in a debugger
11131 /* First and last unchanged row for try_window_id. */
11133 int debug_first_unchanged_at_end_vpos
;
11134 int debug_last_unchanged_at_beg_vpos
;
11136 /* Delta vpos and y. */
11138 int debug_dvpos
, debug_dy
;
11140 /* Delta in characters and bytes for try_window_id. */
11142 int debug_delta
, debug_delta_bytes
;
11144 /* Values of window_end_pos and window_end_vpos at the end of
11147 EMACS_INT debug_end_pos
, debug_end_vpos
;
11149 /* Append a string to W->desired_matrix->method. FMT is a printf
11150 format string. A1...A9 are a supplement for a variable-length
11151 argument list. If trace_redisplay_p is non-zero also printf the
11152 resulting string to stderr. */
11155 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
11158 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
11161 char *method
= w
->desired_matrix
->method
;
11162 int len
= strlen (method
);
11163 int size
= sizeof w
->desired_matrix
->method
;
11164 int remaining
= size
- len
- 1;
11166 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
11167 if (len
&& remaining
)
11170 --remaining
, ++len
;
11173 strncpy (method
+ len
, buffer
, remaining
);
11175 if (trace_redisplay_p
)
11176 fprintf (stderr
, "%p (%s): %s\n",
11178 ((BUFFERP (w
->buffer
)
11179 && STRINGP (XBUFFER (w
->buffer
)->name
))
11180 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
11185 #endif /* GLYPH_DEBUG */
11188 /* Value is non-zero if all changes in window W, which displays
11189 current_buffer, are in the text between START and END. START is a
11190 buffer position, END is given as a distance from Z. Used in
11191 redisplay_internal for display optimization. */
11194 text_outside_line_unchanged_p (w
, start
, end
)
11198 int unchanged_p
= 1;
11200 /* If text or overlays have changed, see where. */
11201 if (XFASTINT (w
->last_modified
) < MODIFF
11202 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11204 /* Gap in the line? */
11205 if (GPT
< start
|| Z
- GPT
< end
)
11208 /* Changes start in front of the line, or end after it? */
11210 && (BEG_UNCHANGED
< start
- 1
11211 || END_UNCHANGED
< end
))
11214 /* If selective display, can't optimize if changes start at the
11215 beginning of the line. */
11217 && INTEGERP (current_buffer
->selective_display
)
11218 && XINT (current_buffer
->selective_display
) > 0
11219 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
11222 /* If there are overlays at the start or end of the line, these
11223 may have overlay strings with newlines in them. A change at
11224 START, for instance, may actually concern the display of such
11225 overlay strings as well, and they are displayed on different
11226 lines. So, quickly rule out this case. (For the future, it
11227 might be desirable to implement something more telling than
11228 just BEG/END_UNCHANGED.) */
11231 if (BEG
+ BEG_UNCHANGED
== start
11232 && overlay_touches_p (start
))
11234 if (END_UNCHANGED
== end
11235 && overlay_touches_p (Z
- end
))
11239 /* Under bidi reordering, adding or deleting a character in the
11240 beginning of a paragraph, before the first strong directional
11241 character, can change the base direction of the paragraph (unless
11242 the buffer specifies a fixed paragraph direction), which will
11243 require to redisplay the whole paragraph. It might be worthwhile
11244 to find the paragraph limits and widen the range of redisplayed
11245 lines to that, but for now just give up this optimization. */
11246 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
11247 && NILP (XBUFFER (w
->buffer
)->bidi_paragraph_direction
))
11251 return unchanged_p
;
11255 /* Do a frame update, taking possible shortcuts into account. This is
11256 the main external entry point for redisplay.
11258 If the last redisplay displayed an echo area message and that message
11259 is no longer requested, we clear the echo area or bring back the
11260 mini-buffer if that is in use. */
11265 redisplay_internal (0);
11270 overlay_arrow_string_or_property (var
)
11275 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11278 return Voverlay_arrow_string
;
11281 /* Return 1 if there are any overlay-arrows in current_buffer. */
11283 overlay_arrow_in_current_buffer_p ()
11287 for (vlist
= Voverlay_arrow_variable_list
;
11289 vlist
= XCDR (vlist
))
11291 Lisp_Object var
= XCAR (vlist
);
11294 if (!SYMBOLP (var
))
11296 val
= find_symbol_value (var
);
11298 && current_buffer
== XMARKER (val
)->buffer
)
11305 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11309 overlay_arrows_changed_p ()
11313 for (vlist
= Voverlay_arrow_variable_list
;
11315 vlist
= XCDR (vlist
))
11317 Lisp_Object var
= XCAR (vlist
);
11318 Lisp_Object val
, pstr
;
11320 if (!SYMBOLP (var
))
11322 val
= find_symbol_value (var
);
11323 if (!MARKERP (val
))
11325 if (! EQ (COERCE_MARKER (val
),
11326 Fget (var
, Qlast_arrow_position
))
11327 || ! (pstr
= overlay_arrow_string_or_property (var
),
11328 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11334 /* Mark overlay arrows to be updated on next redisplay. */
11337 update_overlay_arrows (up_to_date
)
11342 for (vlist
= Voverlay_arrow_variable_list
;
11344 vlist
= XCDR (vlist
))
11346 Lisp_Object var
= XCAR (vlist
);
11348 if (!SYMBOLP (var
))
11351 if (up_to_date
> 0)
11353 Lisp_Object val
= find_symbol_value (var
);
11354 Fput (var
, Qlast_arrow_position
,
11355 COERCE_MARKER (val
));
11356 Fput (var
, Qlast_arrow_string
,
11357 overlay_arrow_string_or_property (var
));
11359 else if (up_to_date
< 0
11360 || !NILP (Fget (var
, Qlast_arrow_position
)))
11362 Fput (var
, Qlast_arrow_position
, Qt
);
11363 Fput (var
, Qlast_arrow_string
, Qt
);
11369 /* Return overlay arrow string to display at row.
11370 Return integer (bitmap number) for arrow bitmap in left fringe.
11371 Return nil if no overlay arrow. */
11374 overlay_arrow_at_row (it
, row
)
11376 struct glyph_row
*row
;
11380 for (vlist
= Voverlay_arrow_variable_list
;
11382 vlist
= XCDR (vlist
))
11384 Lisp_Object var
= XCAR (vlist
);
11387 if (!SYMBOLP (var
))
11390 val
= find_symbol_value (var
);
11393 && current_buffer
== XMARKER (val
)->buffer
11394 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11396 if (FRAME_WINDOW_P (it
->f
)
11397 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11399 #ifdef HAVE_WINDOW_SYSTEM
11400 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11403 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11404 return make_number (fringe_bitmap
);
11407 return make_number (-1); /* Use default arrow bitmap */
11409 return overlay_arrow_string_or_property (var
);
11416 /* Return 1 if point moved out of or into a composition. Otherwise
11417 return 0. PREV_BUF and PREV_PT are the last point buffer and
11418 position. BUF and PT are the current point buffer and position. */
11421 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
11422 struct buffer
*prev_buf
, *buf
;
11425 EMACS_INT start
, end
;
11427 Lisp_Object buffer
;
11429 XSETBUFFER (buffer
, buf
);
11430 /* Check a composition at the last point if point moved within the
11432 if (prev_buf
== buf
)
11435 /* Point didn't move. */
11438 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11439 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11440 && COMPOSITION_VALID_P (start
, end
, prop
)
11441 && start
< prev_pt
&& end
> prev_pt
)
11442 /* The last point was within the composition. Return 1 iff
11443 point moved out of the composition. */
11444 return (pt
<= start
|| pt
>= end
);
11447 /* Check a composition at the current point. */
11448 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11449 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11450 && COMPOSITION_VALID_P (start
, end
, prop
)
11451 && start
< pt
&& end
> pt
);
11455 /* Reconsider the setting of B->clip_changed which is displayed
11459 reconsider_clip_changes (w
, b
)
11463 if (b
->clip_changed
11464 && !NILP (w
->window_end_valid
)
11465 && w
->current_matrix
->buffer
== b
11466 && w
->current_matrix
->zv
== BUF_ZV (b
)
11467 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11468 b
->clip_changed
= 0;
11470 /* If display wasn't paused, and W is not a tool bar window, see if
11471 point has been moved into or out of a composition. In that case,
11472 we set b->clip_changed to 1 to force updating the screen. If
11473 b->clip_changed has already been set to 1, we can skip this
11475 if (!b
->clip_changed
11476 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11480 if (w
== XWINDOW (selected_window
))
11481 pt
= BUF_PT (current_buffer
);
11483 pt
= marker_position (w
->pointm
);
11485 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11486 || pt
!= XINT (w
->last_point
))
11487 && check_point_in_composition (w
->current_matrix
->buffer
,
11488 XINT (w
->last_point
),
11489 XBUFFER (w
->buffer
), pt
))
11490 b
->clip_changed
= 1;
11495 /* Select FRAME to forward the values of frame-local variables into C
11496 variables so that the redisplay routines can access those values
11500 select_frame_for_redisplay (frame
)
11503 Lisp_Object tail
, symbol
, val
;
11504 Lisp_Object old
= selected_frame
;
11505 struct Lisp_Symbol
*sym
;
11507 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11509 selected_frame
= frame
;
11513 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11514 if (CONSP (XCAR (tail
))
11515 && (symbol
= XCAR (XCAR (tail
)),
11517 && (sym
= indirect_variable (XSYMBOL (symbol
)),
11519 (BUFFER_LOCAL_VALUEP (val
)))
11520 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
11521 /* Use find_symbol_value rather than Fsymbol_value
11522 to avoid an error if it is void. */
11523 find_symbol_value (symbol
);
11524 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11528 #define STOP_POLLING \
11529 do { if (! polling_stopped_here) stop_polling (); \
11530 polling_stopped_here = 1; } while (0)
11532 #define RESUME_POLLING \
11533 do { if (polling_stopped_here) start_polling (); \
11534 polling_stopped_here = 0; } while (0)
11537 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
11538 response to any user action; therefore, we should preserve the echo
11539 area. (Actually, our caller does that job.) Perhaps in the future
11540 avoid recentering windows if it is not necessary; currently that
11541 causes some problems. */
11544 redisplay_internal (preserve_echo_area
)
11545 int preserve_echo_area
;
11547 struct window
*w
= XWINDOW (selected_window
);
11550 int must_finish
= 0;
11551 struct text_pos tlbufpos
, tlendpos
;
11552 int number_of_visible_frames
;
11555 int polling_stopped_here
= 0;
11556 Lisp_Object old_frame
= selected_frame
;
11558 /* Non-zero means redisplay has to consider all windows on all
11559 frames. Zero means, only selected_window is considered. */
11560 int consider_all_windows_p
;
11562 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11564 /* No redisplay if running in batch mode or frame is not yet fully
11565 initialized, or redisplay is explicitly turned off by setting
11566 Vinhibit_redisplay. */
11567 if (FRAME_INITIAL_P (SELECTED_FRAME ())
11568 || !NILP (Vinhibit_redisplay
))
11571 /* Don't examine these until after testing Vinhibit_redisplay.
11572 When Emacs is shutting down, perhaps because its connection to
11573 X has dropped, we should not look at them at all. */
11574 f
= XFRAME (w
->frame
);
11575 sf
= SELECTED_FRAME ();
11577 if (!f
->glyphs_initialized_p
)
11580 /* The flag redisplay_performed_directly_p is set by
11581 direct_output_for_insert when it already did the whole screen
11582 update necessary. */
11583 if (redisplay_performed_directly_p
)
11585 redisplay_performed_directly_p
= 0;
11586 if (!hscroll_windows (selected_window
))
11590 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
11591 if (popup_activated ())
11595 /* I don't think this happens but let's be paranoid. */
11596 if (redisplaying_p
)
11599 /* Record a function that resets redisplaying_p to its old value
11600 when we leave this function. */
11601 count
= SPECPDL_INDEX ();
11602 record_unwind_protect (unwind_redisplay
,
11603 Fcons (make_number (redisplaying_p
), selected_frame
));
11605 specbind (Qinhibit_free_realized_faces
, Qnil
);
11608 Lisp_Object tail
, frame
;
11610 FOR_EACH_FRAME (tail
, frame
)
11612 struct frame
*f
= XFRAME (frame
);
11613 f
->already_hscrolled_p
= 0;
11618 if (!EQ (old_frame
, selected_frame
)
11619 && FRAME_LIVE_P (XFRAME (old_frame
)))
11620 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11621 selected_frame and selected_window to be temporarily out-of-sync so
11622 when we come back here via `goto retry', we need to resync because we
11623 may need to run Elisp code (via prepare_menu_bars). */
11624 select_frame_for_redisplay (old_frame
);
11627 reconsider_clip_changes (w
, current_buffer
);
11628 last_escape_glyph_frame
= NULL
;
11629 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11631 /* If new fonts have been loaded that make a glyph matrix adjustment
11632 necessary, do it. */
11633 if (fonts_changed_p
)
11635 adjust_glyphs (NULL
);
11636 ++windows_or_buffers_changed
;
11637 fonts_changed_p
= 0;
11640 /* If face_change_count is non-zero, init_iterator will free all
11641 realized faces, which includes the faces referenced from current
11642 matrices. So, we can't reuse current matrices in this case. */
11643 if (face_change_count
)
11644 ++windows_or_buffers_changed
;
11646 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
11647 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11649 /* Since frames on a single ASCII terminal share the same
11650 display area, displaying a different frame means redisplay
11651 the whole thing. */
11652 windows_or_buffers_changed
++;
11653 SET_FRAME_GARBAGED (sf
);
11655 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11657 FRAME_TTY (sf
)->previous_frame
= sf
;
11660 /* Set the visible flags for all frames. Do this before checking
11661 for resized or garbaged frames; they want to know if their frames
11662 are visible. See the comment in frame.h for
11663 FRAME_SAMPLE_VISIBILITY. */
11665 Lisp_Object tail
, frame
;
11667 number_of_visible_frames
= 0;
11669 FOR_EACH_FRAME (tail
, frame
)
11671 struct frame
*f
= XFRAME (frame
);
11673 FRAME_SAMPLE_VISIBILITY (f
);
11674 if (FRAME_VISIBLE_P (f
))
11675 ++number_of_visible_frames
;
11676 clear_desired_matrices (f
);
11680 /* Notice any pending interrupt request to change frame size. */
11681 do_pending_window_change (1);
11683 /* Clear frames marked as garbaged. */
11684 if (frame_garbaged
)
11685 clear_garbaged_frames ();
11687 /* Build menubar and tool-bar items. */
11688 if (NILP (Vmemory_full
))
11689 prepare_menu_bars ();
11691 if (windows_or_buffers_changed
)
11692 update_mode_lines
++;
11694 /* Detect case that we need to write or remove a star in the mode line. */
11695 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11697 w
->update_mode_line
= Qt
;
11698 if (buffer_shared
> 1)
11699 update_mode_lines
++;
11702 /* Avoid invocation of point motion hooks by `current_column' below. */
11703 count1
= SPECPDL_INDEX ();
11704 specbind (Qinhibit_point_motion_hooks
, Qt
);
11706 /* If %c is in the mode line, update it if needed. */
11707 if (!NILP (w
->column_number_displayed
)
11708 /* This alternative quickly identifies a common case
11709 where no change is needed. */
11710 && !(PT
== XFASTINT (w
->last_point
)
11711 && XFASTINT (w
->last_modified
) >= MODIFF
11712 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11713 && (XFASTINT (w
->column_number_displayed
)
11714 != (int) current_column ())) /* iftc */
11715 w
->update_mode_line
= Qt
;
11717 unbind_to (count1
, Qnil
);
11719 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11721 /* The variable buffer_shared is set in redisplay_window and
11722 indicates that we redisplay a buffer in different windows. See
11724 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11725 || cursor_type_changed
);
11727 /* If specs for an arrow have changed, do thorough redisplay
11728 to ensure we remove any arrow that should no longer exist. */
11729 if (overlay_arrows_changed_p ())
11730 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11732 /* Normally the message* functions will have already displayed and
11733 updated the echo area, but the frame may have been trashed, or
11734 the update may have been preempted, so display the echo area
11735 again here. Checking message_cleared_p captures the case that
11736 the echo area should be cleared. */
11737 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11738 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11739 || (message_cleared_p
11740 && minibuf_level
== 0
11741 /* If the mini-window is currently selected, this means the
11742 echo-area doesn't show through. */
11743 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11745 int window_height_changed_p
= echo_area_display (0);
11748 /* If we don't display the current message, don't clear the
11749 message_cleared_p flag, because, if we did, we wouldn't clear
11750 the echo area in the next redisplay which doesn't preserve
11752 if (!display_last_displayed_message_p
)
11753 message_cleared_p
= 0;
11755 if (fonts_changed_p
)
11757 else if (window_height_changed_p
)
11759 consider_all_windows_p
= 1;
11760 ++update_mode_lines
;
11761 ++windows_or_buffers_changed
;
11763 /* If window configuration was changed, frames may have been
11764 marked garbaged. Clear them or we will experience
11765 surprises wrt scrolling. */
11766 if (frame_garbaged
)
11767 clear_garbaged_frames ();
11770 else if (EQ (selected_window
, minibuf_window
)
11771 && (current_buffer
->clip_changed
11772 || XFASTINT (w
->last_modified
) < MODIFF
11773 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11774 && resize_mini_window (w
, 0))
11776 /* Resized active mini-window to fit the size of what it is
11777 showing if its contents might have changed. */
11779 /* FIXME: this causes all frames to be updated, which seems unnecessary
11780 since only the current frame needs to be considered. This function needs
11781 to be rewritten with two variables, consider_all_windows and
11782 consider_all_frames. */
11783 consider_all_windows_p
= 1;
11784 ++windows_or_buffers_changed
;
11785 ++update_mode_lines
;
11787 /* If window configuration was changed, frames may have been
11788 marked garbaged. Clear them or we will experience
11789 surprises wrt scrolling. */
11790 if (frame_garbaged
)
11791 clear_garbaged_frames ();
11795 /* If showing the region, and mark has changed, we must redisplay
11796 the whole window. The assignment to this_line_start_pos prevents
11797 the optimization directly below this if-statement. */
11798 if (((!NILP (Vtransient_mark_mode
)
11799 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11800 != !NILP (w
->region_showing
))
11801 || (!NILP (w
->region_showing
)
11802 && !EQ (w
->region_showing
,
11803 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11804 CHARPOS (this_line_start_pos
) = 0;
11806 /* Optimize the case that only the line containing the cursor in the
11807 selected window has changed. Variables starting with this_ are
11808 set in display_line and record information about the line
11809 containing the cursor. */
11810 tlbufpos
= this_line_start_pos
;
11811 tlendpos
= this_line_end_pos
;
11812 if (!consider_all_windows_p
11813 && CHARPOS (tlbufpos
) > 0
11814 && NILP (w
->update_mode_line
)
11815 && !current_buffer
->clip_changed
11816 && !current_buffer
->prevent_redisplay_optimizations_p
11817 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11818 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11819 /* Make sure recorded data applies to current buffer, etc. */
11820 && this_line_buffer
== current_buffer
11821 && current_buffer
== XBUFFER (w
->buffer
)
11822 && NILP (w
->force_start
)
11823 && NILP (w
->optional_new_start
)
11824 /* Point must be on the line that we have info recorded about. */
11825 && PT
>= CHARPOS (tlbufpos
)
11826 && PT
<= Z
- CHARPOS (tlendpos
)
11827 /* All text outside that line, including its final newline,
11828 must be unchanged. */
11829 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11830 CHARPOS (tlendpos
)))
11832 if (CHARPOS (tlbufpos
) > BEGV
11833 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11834 && (CHARPOS (tlbufpos
) == ZV
11835 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11836 /* Former continuation line has disappeared by becoming empty. */
11838 else if (XFASTINT (w
->last_modified
) < MODIFF
11839 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11840 || MINI_WINDOW_P (w
))
11842 /* We have to handle the case of continuation around a
11843 wide-column character (see the comment in indent.c around
11846 For instance, in the following case:
11848 -------- Insert --------
11849 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11850 J_I_ ==> J_I_ `^^' are cursors.
11854 As we have to redraw the line above, we cannot use this
11858 int line_height_before
= this_line_pixel_height
;
11860 /* Note that start_display will handle the case that the
11861 line starting at tlbufpos is a continuation line. */
11862 start_display (&it
, w
, tlbufpos
);
11864 /* Implementation note: It this still necessary? */
11865 if (it
.current_x
!= this_line_start_x
)
11868 TRACE ((stderr
, "trying display optimization 1\n"));
11869 w
->cursor
.vpos
= -1;
11870 overlay_arrow_seen
= 0;
11871 it
.vpos
= this_line_vpos
;
11872 it
.current_y
= this_line_y
;
11873 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11874 display_line (&it
);
11876 /* If line contains point, is not continued,
11877 and ends at same distance from eob as before, we win. */
11878 if (w
->cursor
.vpos
>= 0
11879 /* Line is not continued, otherwise this_line_start_pos
11880 would have been set to 0 in display_line. */
11881 && CHARPOS (this_line_start_pos
)
11882 /* Line ends as before. */
11883 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11884 /* Line has same height as before. Otherwise other lines
11885 would have to be shifted up or down. */
11886 && this_line_pixel_height
== line_height_before
)
11888 /* If this is not the window's last line, we must adjust
11889 the charstarts of the lines below. */
11890 if (it
.current_y
< it
.last_visible_y
)
11892 struct glyph_row
*row
11893 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11894 int delta
, delta_bytes
;
11896 /* We used to distinguish between two cases here,
11897 conditioned by Z - CHARPOS (tlendpos) == ZV, for
11898 when the line ends in a newline or the end of the
11899 buffer's accessible portion. But both cases did
11900 the same, so they were collapsed. */
11902 - CHARPOS (tlendpos
)
11903 - MATRIX_ROW_START_CHARPOS (row
));
11904 delta_bytes
= (Z_BYTE
11905 - BYTEPOS (tlendpos
)
11906 - MATRIX_ROW_START_BYTEPOS (row
));
11908 increment_matrix_positions (w
->current_matrix
,
11909 this_line_vpos
+ 1,
11910 w
->current_matrix
->nrows
,
11911 delta
, delta_bytes
);
11914 /* If this row displays text now but previously didn't,
11915 or vice versa, w->window_end_vpos may have to be
11917 if ((it
.glyph_row
- 1)->displays_text_p
)
11919 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11920 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11922 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11923 && this_line_vpos
> 0)
11924 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11925 w
->window_end_valid
= Qnil
;
11927 /* Update hint: No need to try to scroll in update_window. */
11928 w
->desired_matrix
->no_scrolling_p
= 1;
11931 *w
->desired_matrix
->method
= 0;
11932 debug_method_add (w
, "optimization 1");
11934 #ifdef HAVE_WINDOW_SYSTEM
11935 update_window_fringes (w
, 0);
11942 else if (/* Cursor position hasn't changed. */
11943 PT
== XFASTINT (w
->last_point
)
11944 /* Make sure the cursor was last displayed
11945 in this window. Otherwise we have to reposition it. */
11946 && 0 <= w
->cursor
.vpos
11947 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11951 do_pending_window_change (1);
11953 /* We used to always goto end_of_redisplay here, but this
11954 isn't enough if we have a blinking cursor. */
11955 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11956 goto end_of_redisplay
;
11960 /* If highlighting the region, or if the cursor is in the echo area,
11961 then we can't just move the cursor. */
11962 else if (! (!NILP (Vtransient_mark_mode
)
11963 && !NILP (current_buffer
->mark_active
))
11964 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11965 || highlight_nonselected_windows
)
11966 && NILP (w
->region_showing
)
11967 && NILP (Vshow_trailing_whitespace
)
11968 && !cursor_in_echo_area
)
11971 struct glyph_row
*row
;
11973 /* Skip from tlbufpos to PT and see where it is. Note that
11974 PT may be in invisible text. If so, we will end at the
11975 next visible position. */
11976 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11977 NULL
, DEFAULT_FACE_ID
);
11978 it
.current_x
= this_line_start_x
;
11979 it
.current_y
= this_line_y
;
11980 it
.vpos
= this_line_vpos
;
11982 /* The call to move_it_to stops in front of PT, but
11983 moves over before-strings. */
11984 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11986 if (it
.vpos
== this_line_vpos
11987 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11990 xassert (this_line_vpos
== it
.vpos
);
11991 xassert (this_line_y
== it
.current_y
);
11992 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11994 *w
->desired_matrix
->method
= 0;
11995 debug_method_add (w
, "optimization 3");
12004 /* Text changed drastically or point moved off of line. */
12005 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
12008 CHARPOS (this_line_start_pos
) = 0;
12009 consider_all_windows_p
|= buffer_shared
> 1;
12010 ++clear_face_cache_count
;
12011 #ifdef HAVE_WINDOW_SYSTEM
12012 ++clear_image_cache_count
;
12015 /* Build desired matrices, and update the display. If
12016 consider_all_windows_p is non-zero, do it for all windows on all
12017 frames. Otherwise do it for selected_window, only. */
12019 if (consider_all_windows_p
)
12021 Lisp_Object tail
, frame
;
12023 FOR_EACH_FRAME (tail
, frame
)
12024 XFRAME (frame
)->updated_p
= 0;
12026 /* Recompute # windows showing selected buffer. This will be
12027 incremented each time such a window is displayed. */
12030 FOR_EACH_FRAME (tail
, frame
)
12032 struct frame
*f
= XFRAME (frame
);
12034 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
12036 if (! EQ (frame
, selected_frame
))
12037 /* Select the frame, for the sake of frame-local
12039 select_frame_for_redisplay (frame
);
12041 /* Mark all the scroll bars to be removed; we'll redeem
12042 the ones we want when we redisplay their windows. */
12043 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
12044 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
12046 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12047 redisplay_windows (FRAME_ROOT_WINDOW (f
));
12049 /* The X error handler may have deleted that frame. */
12050 if (!FRAME_LIVE_P (f
))
12053 /* Any scroll bars which redisplay_windows should have
12054 nuked should now go away. */
12055 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
12056 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
12058 /* If fonts changed, display again. */
12059 /* ??? rms: I suspect it is a mistake to jump all the way
12060 back to retry here. It should just retry this frame. */
12061 if (fonts_changed_p
)
12064 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12066 /* See if we have to hscroll. */
12067 if (!f
->already_hscrolled_p
)
12069 f
->already_hscrolled_p
= 1;
12070 if (hscroll_windows (f
->root_window
))
12074 /* Prevent various kinds of signals during display
12075 update. stdio is not robust about handling
12076 signals, which can cause an apparent I/O
12078 if (interrupt_input
)
12079 unrequest_sigio ();
12082 /* Update the display. */
12083 set_window_update_flags (XWINDOW (f
->root_window
), 1);
12084 pause
|= update_frame (f
, 0, 0);
12090 if (!EQ (old_frame
, selected_frame
)
12091 && FRAME_LIVE_P (XFRAME (old_frame
)))
12092 /* We played a bit fast-and-loose above and allowed selected_frame
12093 and selected_window to be temporarily out-of-sync but let's make
12094 sure this stays contained. */
12095 select_frame_for_redisplay (old_frame
);
12096 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
12100 /* Do the mark_window_display_accurate after all windows have
12101 been redisplayed because this call resets flags in buffers
12102 which are needed for proper redisplay. */
12103 FOR_EACH_FRAME (tail
, frame
)
12105 struct frame
*f
= XFRAME (frame
);
12108 mark_window_display_accurate (f
->root_window
, 1);
12109 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
12110 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
12115 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12117 Lisp_Object mini_window
;
12118 struct frame
*mini_frame
;
12120 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12121 /* Use list_of_error, not Qerror, so that
12122 we catch only errors and don't run the debugger. */
12123 internal_condition_case_1 (redisplay_window_1
, selected_window
,
12125 redisplay_window_error
);
12127 /* Compare desired and current matrices, perform output. */
12130 /* If fonts changed, display again. */
12131 if (fonts_changed_p
)
12134 /* Prevent various kinds of signals during display update.
12135 stdio is not robust about handling signals,
12136 which can cause an apparent I/O error. */
12137 if (interrupt_input
)
12138 unrequest_sigio ();
12141 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12143 if (hscroll_windows (selected_window
))
12146 XWINDOW (selected_window
)->must_be_updated_p
= 1;
12147 pause
= update_frame (sf
, 0, 0);
12150 /* We may have called echo_area_display at the top of this
12151 function. If the echo area is on another frame, that may
12152 have put text on a frame other than the selected one, so the
12153 above call to update_frame would not have caught it. Catch
12155 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
12156 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
12158 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
12160 XWINDOW (mini_window
)->must_be_updated_p
= 1;
12161 pause
|= update_frame (mini_frame
, 0, 0);
12162 if (!pause
&& hscroll_windows (mini_window
))
12167 /* If display was paused because of pending input, make sure we do a
12168 thorough update the next time. */
12171 /* Prevent the optimization at the beginning of
12172 redisplay_internal that tries a single-line update of the
12173 line containing the cursor in the selected window. */
12174 CHARPOS (this_line_start_pos
) = 0;
12176 /* Let the overlay arrow be updated the next time. */
12177 update_overlay_arrows (0);
12179 /* If we pause after scrolling, some rows in the current
12180 matrices of some windows are not valid. */
12181 if (!WINDOW_FULL_WIDTH_P (w
)
12182 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
12183 update_mode_lines
= 1;
12187 if (!consider_all_windows_p
)
12189 /* This has already been done above if
12190 consider_all_windows_p is set. */
12191 mark_window_display_accurate_1 (w
, 1);
12193 /* Say overlay arrows are up to date. */
12194 update_overlay_arrows (1);
12196 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
12197 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
12200 update_mode_lines
= 0;
12201 windows_or_buffers_changed
= 0;
12202 cursor_type_changed
= 0;
12205 /* Start SIGIO interrupts coming again. Having them off during the
12206 code above makes it less likely one will discard output, but not
12207 impossible, since there might be stuff in the system buffer here.
12208 But it is much hairier to try to do anything about that. */
12209 if (interrupt_input
)
12213 /* If a frame has become visible which was not before, redisplay
12214 again, so that we display it. Expose events for such a frame
12215 (which it gets when becoming visible) don't call the parts of
12216 redisplay constructing glyphs, so simply exposing a frame won't
12217 display anything in this case. So, we have to display these
12218 frames here explicitly. */
12221 Lisp_Object tail
, frame
;
12224 FOR_EACH_FRAME (tail
, frame
)
12226 int this_is_visible
= 0;
12228 if (XFRAME (frame
)->visible
)
12229 this_is_visible
= 1;
12230 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
12231 if (XFRAME (frame
)->visible
)
12232 this_is_visible
= 1;
12234 if (this_is_visible
)
12238 if (new_count
!= number_of_visible_frames
)
12239 windows_or_buffers_changed
++;
12242 /* Change frame size now if a change is pending. */
12243 do_pending_window_change (1);
12245 /* If we just did a pending size change, or have additional
12246 visible frames, redisplay again. */
12247 if (windows_or_buffers_changed
&& !pause
)
12250 /* Clear the face cache eventually. */
12251 if (consider_all_windows_p
)
12253 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12255 clear_face_cache (0);
12256 clear_face_cache_count
= 0;
12258 #ifdef HAVE_WINDOW_SYSTEM
12259 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12261 clear_image_caches (Qnil
);
12262 clear_image_cache_count
= 0;
12264 #endif /* HAVE_WINDOW_SYSTEM */
12268 unbind_to (count
, Qnil
);
12273 /* Redisplay, but leave alone any recent echo area message unless
12274 another message has been requested in its place.
12276 This is useful in situations where you need to redisplay but no
12277 user action has occurred, making it inappropriate for the message
12278 area to be cleared. See tracking_off and
12279 wait_reading_process_output for examples of these situations.
12281 FROM_WHERE is an integer saying from where this function was
12282 called. This is useful for debugging. */
12285 redisplay_preserve_echo_area (from_where
)
12288 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12290 if (!NILP (echo_area_buffer
[1]))
12292 /* We have a previously displayed message, but no current
12293 message. Redisplay the previous message. */
12294 display_last_displayed_message_p
= 1;
12295 redisplay_internal (1);
12296 display_last_displayed_message_p
= 0;
12299 redisplay_internal (1);
12301 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12302 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12303 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12307 /* Function registered with record_unwind_protect in
12308 redisplay_internal. Reset redisplaying_p to the value it had
12309 before redisplay_internal was called, and clear
12310 prevent_freeing_realized_faces_p. It also selects the previously
12311 selected frame, unless it has been deleted (by an X connection
12312 failure during redisplay, for example). */
12315 unwind_redisplay (val
)
12318 Lisp_Object old_redisplaying_p
, old_frame
;
12320 old_redisplaying_p
= XCAR (val
);
12321 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12322 old_frame
= XCDR (val
);
12323 if (! EQ (old_frame
, selected_frame
)
12324 && FRAME_LIVE_P (XFRAME (old_frame
)))
12325 select_frame_for_redisplay (old_frame
);
12330 /* Mark the display of window W as accurate or inaccurate. If
12331 ACCURATE_P is non-zero mark display of W as accurate. If
12332 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12333 redisplay_internal is called. */
12336 mark_window_display_accurate_1 (w
, accurate_p
)
12340 if (BUFFERP (w
->buffer
))
12342 struct buffer
*b
= XBUFFER (w
->buffer
);
12345 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12346 w
->last_overlay_modified
12347 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12349 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12353 b
->clip_changed
= 0;
12354 b
->prevent_redisplay_optimizations_p
= 0;
12356 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12357 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12358 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12359 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12361 w
->current_matrix
->buffer
= b
;
12362 w
->current_matrix
->begv
= BUF_BEGV (b
);
12363 w
->current_matrix
->zv
= BUF_ZV (b
);
12365 w
->last_cursor
= w
->cursor
;
12366 w
->last_cursor_off_p
= w
->cursor_off_p
;
12368 if (w
== XWINDOW (selected_window
))
12369 w
->last_point
= make_number (BUF_PT (b
));
12371 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12377 w
->window_end_valid
= w
->buffer
;
12378 w
->update_mode_line
= Qnil
;
12383 /* Mark the display of windows in the window tree rooted at WINDOW as
12384 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12385 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12386 be redisplayed the next time redisplay_internal is called. */
12389 mark_window_display_accurate (window
, accurate_p
)
12390 Lisp_Object window
;
12395 for (; !NILP (window
); window
= w
->next
)
12397 w
= XWINDOW (window
);
12398 mark_window_display_accurate_1 (w
, accurate_p
);
12400 if (!NILP (w
->vchild
))
12401 mark_window_display_accurate (w
->vchild
, accurate_p
);
12402 if (!NILP (w
->hchild
))
12403 mark_window_display_accurate (w
->hchild
, accurate_p
);
12408 update_overlay_arrows (1);
12412 /* Force a thorough redisplay the next time by setting
12413 last_arrow_position and last_arrow_string to t, which is
12414 unequal to any useful value of Voverlay_arrow_... */
12415 update_overlay_arrows (-1);
12420 /* Return value in display table DP (Lisp_Char_Table *) for character
12421 C. Since a display table doesn't have any parent, we don't have to
12422 follow parent. Do not call this function directly but use the
12423 macro DISP_CHAR_VECTOR. */
12426 disp_char_vector (dp
, c
)
12427 struct Lisp_Char_Table
*dp
;
12432 if (ASCII_CHAR_P (c
))
12435 if (SUB_CHAR_TABLE_P (val
))
12436 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12442 XSETCHAR_TABLE (table
, dp
);
12443 val
= char_table_ref (table
, c
);
12452 /***********************************************************************
12454 ***********************************************************************/
12456 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12459 redisplay_windows (window
)
12460 Lisp_Object window
;
12462 while (!NILP (window
))
12464 struct window
*w
= XWINDOW (window
);
12466 if (!NILP (w
->hchild
))
12467 redisplay_windows (w
->hchild
);
12468 else if (!NILP (w
->vchild
))
12469 redisplay_windows (w
->vchild
);
12470 else if (!NILP (w
->buffer
))
12472 displayed_buffer
= XBUFFER (w
->buffer
);
12473 /* Use list_of_error, not Qerror, so that
12474 we catch only errors and don't run the debugger. */
12475 internal_condition_case_1 (redisplay_window_0
, window
,
12477 redisplay_window_error
);
12485 redisplay_window_error ()
12487 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12492 redisplay_window_0 (window
)
12493 Lisp_Object window
;
12495 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12496 redisplay_window (window
, 0);
12501 redisplay_window_1 (window
)
12502 Lisp_Object window
;
12504 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12505 redisplay_window (window
, 1);
12510 /* Increment GLYPH until it reaches END or CONDITION fails while
12511 adding (GLYPH)->pixel_width to X. */
12513 #define SKIP_GLYPHS(glyph, end, x, condition) \
12516 (x) += (glyph)->pixel_width; \
12519 while ((glyph) < (end) && (condition))
12522 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12523 DELTA and DELTA_BYTES are the numbers of characters and bytes by
12524 which positions recorded in ROW differ from current buffer
12527 Return 0 if cursor is not on this row, 1 otherwise. */
12530 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
12532 struct glyph_row
*row
;
12533 struct glyph_matrix
*matrix
;
12534 int delta
, delta_bytes
, dy
, dvpos
;
12536 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12537 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12538 struct glyph
*cursor
= NULL
;
12539 /* The last known character position in row. */
12540 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12543 EMACS_INT pt_old
= PT
- delta
;
12544 EMACS_INT pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12545 EMACS_INT pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
12546 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
12547 /* Non-zero means we've found a match for cursor position, but that
12548 glyph has the avoid_cursor_p flag set. */
12549 int match_with_avoid_cursor
= 0;
12550 /* Non-zero means we've seen at least one glyph that came from a
12552 int string_seen
= 0;
12553 /* Largest buffer position seen so far during scan of glyph row. */
12554 EMACS_INT bpos_max
= last_pos
;
12555 /* Last buffer position covered by an overlay string with an integer
12556 `cursor' property. */
12557 EMACS_INT bpos_covered
= 0;
12559 /* Skip over glyphs not having an object at the start and the end of
12560 the row. These are special glyphs like truncation marks on
12561 terminal frames. */
12562 if (row
->displays_text_p
)
12564 if (!row
->reversed_p
)
12567 && INTEGERP (glyph
->object
)
12568 && glyph
->charpos
< 0)
12570 x
+= glyph
->pixel_width
;
12574 && INTEGERP ((end
- 1)->object
)
12575 /* CHARPOS is zero for blanks inserted by
12576 extend_face_to_end_of_line. */
12577 && (end
- 1)->charpos
<= 0)
12579 glyph_before
= glyph
- 1;
12586 /* If the glyph row is reversed, we need to process it from back
12587 to front, so swap the edge pointers. */
12589 glyph
+= row
->used
[TEXT_AREA
] - 1;
12590 /* Reverse the known positions in the row. */
12591 last_pos
= pos_after
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12592 pos_before
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
12594 while (glyph
> end
+ 1
12595 && INTEGERP (glyph
->object
)
12596 && glyph
->charpos
< 0)
12599 x
-= glyph
->pixel_width
;
12601 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
12603 /* By default, put the cursor on the rightmost glyph. */
12604 for (g
= end
+ 1; g
< glyph
; g
++)
12605 x
+= g
->pixel_width
;
12608 && INTEGERP ((end
+ 1)->object
)
12609 && (end
+ 1)->charpos
<= 0)
12611 glyph_before
= glyph
+ 1;
12615 else if (row
->reversed_p
)
12617 /* In R2L rows that don't display text, put the cursor on the
12618 rightmost glyph. Case in point: an empty last line that is
12619 part of an R2L paragraph. */
12621 x
= -1; /* will be computed below, at lable compute_x */
12624 /* Step 1: Try to find the glyph whose character position
12625 corresponds to point. If that's not possible, find 2 glyphs
12626 whose character positions are the closest to point, one before
12627 point, the other after it. */
12628 if (!row
->reversed_p
)
12629 while (/* not marched to end of glyph row */
12631 /* glyph was not inserted by redisplay for internal purposes */
12632 && !INTEGERP (glyph
->object
))
12634 if (BUFFERP (glyph
->object
))
12636 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12638 if (glyph
->charpos
> bpos_max
)
12639 bpos_max
= glyph
->charpos
;
12640 if (!glyph
->avoid_cursor_p
)
12642 /* If we hit point, we've found the glyph on which to
12643 display the cursor. */
12646 match_with_avoid_cursor
= 0;
12649 /* See if we've found a better approximation to
12650 POS_BEFORE or to POS_AFTER. Note that we want the
12651 first (leftmost) glyph of all those that are the
12652 closest from below, and the last (rightmost) of all
12653 those from above. */
12654 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12656 pos_before
= glyph
->charpos
;
12657 glyph_before
= glyph
;
12659 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12661 pos_after
= glyph
->charpos
;
12662 glyph_after
= glyph
;
12665 else if (dpos
== 0)
12666 match_with_avoid_cursor
= 1;
12668 else if (STRINGP (glyph
->object
))
12670 Lisp_Object chprop
;
12671 int glyph_pos
= glyph
->charpos
;
12673 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12675 if (INTEGERP (chprop
))
12677 bpos_covered
= bpos_max
+ XINT (chprop
);
12678 /* If the `cursor' property covers buffer positions up
12679 to and including point, we should display cursor on
12681 /* Implementation note: bpos_max == pt_old when, e.g.,
12682 we are in an empty line, where bpos_max is set to
12683 MATRIX_ROW_START_CHARPOS, see above. */
12684 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12693 x
+= glyph
->pixel_width
;
12696 else if (glyph
> end
) /* row is reversed */
12697 while (!INTEGERP (glyph
->object
))
12699 if (BUFFERP (glyph
->object
))
12701 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12703 if (glyph
->charpos
> bpos_max
)
12704 bpos_max
= glyph
->charpos
;
12705 if (!glyph
->avoid_cursor_p
)
12709 match_with_avoid_cursor
= 0;
12712 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12714 pos_before
= glyph
->charpos
;
12715 glyph_before
= glyph
;
12717 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12719 pos_after
= glyph
->charpos
;
12720 glyph_after
= glyph
;
12723 else if (dpos
== 0)
12724 match_with_avoid_cursor
= 1;
12726 else if (STRINGP (glyph
->object
))
12728 Lisp_Object chprop
;
12729 int glyph_pos
= glyph
->charpos
;
12731 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12733 if (INTEGERP (chprop
))
12735 bpos_covered
= bpos_max
+ XINT (chprop
);
12736 /* If the `cursor' property covers buffer positions up
12737 to and including point, we should display cursor on
12739 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12750 x
-= glyph
->pixel_width
;
12753 /* Step 2: If we didn't find an exact match for point, we need to
12754 look for a proper place to put the cursor among glyphs between
12755 GLYPH_BEFORE and GLYPH_AFTER. */
12756 if (!(BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
12757 && bpos_covered
< pt_old
)
12759 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
12761 EMACS_INT ellipsis_pos
;
12763 /* Scan back over the ellipsis glyphs. */
12764 if (!row
->reversed_p
)
12766 ellipsis_pos
= (glyph
- 1)->charpos
;
12767 while (glyph
> row
->glyphs
[TEXT_AREA
]
12768 && (glyph
- 1)->charpos
== ellipsis_pos
)
12769 glyph
--, x
-= glyph
->pixel_width
;
12770 /* That loop always goes one position too far, including
12771 the glyph before the ellipsis. So scan forward over
12773 x
+= glyph
->pixel_width
;
12776 else /* row is reversed */
12778 ellipsis_pos
= (glyph
+ 1)->charpos
;
12779 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
12780 && (glyph
+ 1)->charpos
== ellipsis_pos
)
12781 glyph
++, x
+= glyph
->pixel_width
;
12782 x
-= glyph
->pixel_width
;
12786 else if (match_with_avoid_cursor
12787 /* zero-width characters produce no glyphs */
12788 || eabs (glyph_after
- glyph_before
) == 1)
12790 cursor
= glyph_after
;
12793 else if (string_seen
)
12795 int incr
= row
->reversed_p
? -1 : +1;
12797 /* Need to find the glyph that came out of a string which is
12798 present at point. That glyph is somewhere between
12799 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
12800 positioned between POS_BEFORE and POS_AFTER in the
12802 struct glyph
*stop
= glyph_after
;
12803 EMACS_INT pos
= pos_before
;
12806 for (glyph
= glyph_before
+ incr
;
12807 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
12810 /* Any glyphs that come from the buffer are here because
12811 of bidi reordering. Skip them, and only pay
12812 attention to glyphs that came from some string. */
12813 if (STRINGP (glyph
->object
))
12818 str
= glyph
->object
;
12819 tem
= string_buffer_position_lim (w
, str
, pos
, pos_after
, 0);
12822 /* If the string from which this glyph came is
12823 found in the buffer at point, then we've
12824 found the glyph we've been looking for. */
12827 /* The glyphs from this string could have
12828 been reordered. Find the one with the
12829 smallest string position. Or there could
12830 be a character in the string with the
12831 `cursor' property, which means display
12832 cursor on that character's glyph. */
12833 int strpos
= glyph
->charpos
;
12836 for (glyph
+= incr
;
12837 EQ (glyph
->object
, str
);
12841 int gpos
= glyph
->charpos
;
12843 cprop
= Fget_char_property (make_number (gpos
),
12851 if (glyph
->charpos
< strpos
)
12853 strpos
= glyph
->charpos
;
12860 pos
= tem
+ 1; /* don't find previous instances */
12862 /* This string is not what we want; skip all of the
12863 glyphs that came from it. */
12866 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
12867 && EQ (glyph
->object
, str
));
12873 /* If we reached the end of the line, and END was from a string,
12874 the cursor is not on this line. */
12876 && STRINGP ((glyph
- incr
)->object
)
12877 && row
->continued_p
)
12883 if (cursor
!= NULL
)
12889 /* Need to compute x that corresponds to GLYPH. */
12890 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
12892 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
12894 x
+= g
->pixel_width
;
12898 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12900 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12901 w
->cursor
.y
= row
->y
+ dy
;
12903 if (w
== XWINDOW (selected_window
))
12905 if (!row
->continued_p
12906 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12909 this_line_buffer
= XBUFFER (w
->buffer
);
12911 CHARPOS (this_line_start_pos
)
12912 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12913 BYTEPOS (this_line_start_pos
)
12914 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12916 CHARPOS (this_line_end_pos
)
12917 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12918 BYTEPOS (this_line_end_pos
)
12919 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12921 this_line_y
= w
->cursor
.y
;
12922 this_line_pixel_height
= row
->height
;
12923 this_line_vpos
= w
->cursor
.vpos
;
12924 this_line_start_x
= row
->x
;
12927 CHARPOS (this_line_start_pos
) = 0;
12934 /* Run window scroll functions, if any, for WINDOW with new window
12935 start STARTP. Sets the window start of WINDOW to that position.
12937 We assume that the window's buffer is really current. */
12939 static INLINE
struct text_pos
12940 run_window_scroll_functions (window
, startp
)
12941 Lisp_Object window
;
12942 struct text_pos startp
;
12944 struct window
*w
= XWINDOW (window
);
12945 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12947 if (current_buffer
!= XBUFFER (w
->buffer
))
12950 if (!NILP (Vwindow_scroll_functions
))
12952 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12953 make_number (CHARPOS (startp
)));
12954 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12955 /* In case the hook functions switch buffers. */
12956 if (current_buffer
!= XBUFFER (w
->buffer
))
12957 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12964 /* Make sure the line containing the cursor is fully visible.
12965 A value of 1 means there is nothing to be done.
12966 (Either the line is fully visible, or it cannot be made so,
12967 or we cannot tell.)
12969 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12970 is higher than window.
12972 A value of 0 means the caller should do scrolling
12973 as if point had gone off the screen. */
12976 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12979 int current_matrix_p
;
12981 struct glyph_matrix
*matrix
;
12982 struct glyph_row
*row
;
12985 if (!make_cursor_line_fully_visible_p
)
12988 /* It's not always possible to find the cursor, e.g, when a window
12989 is full of overlay strings. Don't do anything in that case. */
12990 if (w
->cursor
.vpos
< 0)
12993 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12994 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12996 /* If the cursor row is not partially visible, there's nothing to do. */
12997 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
13000 /* If the row the cursor is in is taller than the window's height,
13001 it's not clear what to do, so do nothing. */
13002 window_height
= window_box_height (w
);
13003 if (row
->height
>= window_height
)
13005 if (!force_p
|| MINI_WINDOW_P (w
)
13006 || w
->vscroll
|| w
->cursor
.vpos
== 0)
13013 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
13014 non-zero means only WINDOW is redisplayed in redisplay_internal.
13015 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
13016 in redisplay_window to bring a partially visible line into view in
13017 the case that only the cursor has moved.
13019 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
13020 last screen line's vertical height extends past the end of the screen.
13024 1 if scrolling succeeded
13026 0 if scrolling didn't find point.
13028 -1 if new fonts have been loaded so that we must interrupt
13029 redisplay, adjust glyph matrices, and try again. */
13035 SCROLLING_NEED_LARGER_MATRICES
13039 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
13040 scroll_step
, temp_scroll_step
, last_line_misfit
)
13041 Lisp_Object window
;
13042 int just_this_one_p
;
13043 EMACS_INT scroll_conservatively
, scroll_step
;
13044 int temp_scroll_step
;
13045 int last_line_misfit
;
13047 struct window
*w
= XWINDOW (window
);
13048 struct frame
*f
= XFRAME (w
->frame
);
13049 struct text_pos pos
, startp
;
13051 int this_scroll_margin
, scroll_max
, rc
, height
;
13052 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
13053 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
13054 Lisp_Object aggressive
;
13055 int scroll_limit
= INT_MAX
/ FRAME_LINE_HEIGHT (f
);
13058 debug_method_add (w
, "try_scrolling");
13061 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13063 /* Compute scroll margin height in pixels. We scroll when point is
13064 within this distance from the top or bottom of the window. */
13065 if (scroll_margin
> 0)
13066 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
13067 * FRAME_LINE_HEIGHT (f
);
13069 this_scroll_margin
= 0;
13071 /* Force scroll_conservatively to have a reasonable value, to avoid
13072 overflow while computing how much to scroll. Note that the user
13073 can supply scroll-conservatively equal to `most-positive-fixnum',
13074 which can be larger than INT_MAX. */
13075 if (scroll_conservatively
> scroll_limit
)
13077 scroll_conservatively
= scroll_limit
;
13078 scroll_max
= INT_MAX
;
13080 else if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
13081 /* Compute how much we should try to scroll maximally to bring
13082 point into view. */
13083 scroll_max
= (max (scroll_step
,
13084 max (scroll_conservatively
, temp_scroll_step
))
13085 * FRAME_LINE_HEIGHT (f
));
13086 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
13087 || NUMBERP (current_buffer
->scroll_up_aggressively
))
13088 /* We're trying to scroll because of aggressive scrolling but no
13089 scroll_step is set. Choose an arbitrary one. */
13090 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
13096 /* Decide whether to scroll down. */
13097 if (PT
> CHARPOS (startp
))
13099 int scroll_margin_y
;
13101 /* Compute the pixel ypos of the scroll margin, then move it to
13102 either that ypos or PT, whichever comes first. */
13103 start_display (&it
, w
, startp
);
13104 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
13105 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
13106 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
13107 (MOVE_TO_POS
| MOVE_TO_Y
));
13109 if (PT
> CHARPOS (it
.current
.pos
))
13111 int y0
= line_bottom_y (&it
);
13113 /* Compute the distance from the scroll margin to PT
13114 (including the height of the cursor line). Moving the
13115 iterator unconditionally to PT can be slow if PT is far
13116 away, so stop 10 lines past the window bottom (is there a
13117 way to do the right thing quickly?). */
13118 move_it_to (&it
, PT
, -1,
13119 it
.last_visible_y
+ 10 * FRAME_LINE_HEIGHT (f
),
13120 -1, MOVE_TO_POS
| MOVE_TO_Y
);
13121 dy
= line_bottom_y (&it
) - y0
;
13123 if (dy
> scroll_max
)
13124 return SCROLLING_FAILED
;
13132 /* Point is in or below the bottom scroll margin, so move the
13133 window start down. If scrolling conservatively, move it just
13134 enough down to make point visible. If scroll_step is set,
13135 move it down by scroll_step. */
13136 if (scroll_conservatively
)
13138 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
13139 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
13140 else if (scroll_step
|| temp_scroll_step
)
13141 amount_to_scroll
= scroll_max
;
13144 aggressive
= current_buffer
->scroll_up_aggressively
;
13145 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13146 if (NUMBERP (aggressive
))
13148 double float_amount
= XFLOATINT (aggressive
) * height
;
13149 amount_to_scroll
= float_amount
;
13150 if (amount_to_scroll
== 0 && float_amount
> 0)
13151 amount_to_scroll
= 1;
13155 if (amount_to_scroll
<= 0)
13156 return SCROLLING_FAILED
;
13158 start_display (&it
, w
, startp
);
13159 move_it_vertically (&it
, amount_to_scroll
);
13161 /* If STARTP is unchanged, move it down another screen line. */
13162 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
13163 move_it_by_lines (&it
, 1, 1);
13164 startp
= it
.current
.pos
;
13168 struct text_pos scroll_margin_pos
= startp
;
13170 /* See if point is inside the scroll margin at the top of the
13172 if (this_scroll_margin
)
13174 start_display (&it
, w
, startp
);
13175 move_it_vertically (&it
, this_scroll_margin
);
13176 scroll_margin_pos
= it
.current
.pos
;
13179 if (PT
< CHARPOS (scroll_margin_pos
))
13181 /* Point is in the scroll margin at the top of the window or
13182 above what is displayed in the window. */
13185 /* Compute the vertical distance from PT to the scroll
13186 margin position. Give up if distance is greater than
13188 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
13189 start_display (&it
, w
, pos
);
13191 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
13192 it
.last_visible_y
, -1,
13193 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13194 dy
= it
.current_y
- y0
;
13195 if (dy
> scroll_max
)
13196 return SCROLLING_FAILED
;
13198 /* Compute new window start. */
13199 start_display (&it
, w
, startp
);
13201 if (scroll_conservatively
)
13203 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
13204 else if (scroll_step
|| temp_scroll_step
)
13205 amount_to_scroll
= scroll_max
;
13208 aggressive
= current_buffer
->scroll_down_aggressively
;
13209 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13210 if (NUMBERP (aggressive
))
13212 double float_amount
= XFLOATINT (aggressive
) * height
;
13213 amount_to_scroll
= float_amount
;
13214 if (amount_to_scroll
== 0 && float_amount
> 0)
13215 amount_to_scroll
= 1;
13219 if (amount_to_scroll
<= 0)
13220 return SCROLLING_FAILED
;
13222 move_it_vertically_backward (&it
, amount_to_scroll
);
13223 startp
= it
.current
.pos
;
13227 /* Run window scroll functions. */
13228 startp
= run_window_scroll_functions (window
, startp
);
13230 /* Display the window. Give up if new fonts are loaded, or if point
13232 if (!try_window (window
, startp
, 0))
13233 rc
= SCROLLING_NEED_LARGER_MATRICES
;
13234 else if (w
->cursor
.vpos
< 0)
13236 clear_glyph_matrix (w
->desired_matrix
);
13237 rc
= SCROLLING_FAILED
;
13241 /* Maybe forget recorded base line for line number display. */
13242 if (!just_this_one_p
13243 || current_buffer
->clip_changed
13244 || BEG_UNCHANGED
< CHARPOS (startp
))
13245 w
->base_line_number
= Qnil
;
13247 /* If cursor ends up on a partially visible line,
13248 treat that as being off the bottom of the screen. */
13249 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
13251 clear_glyph_matrix (w
->desired_matrix
);
13252 ++extra_scroll_margin_lines
;
13255 rc
= SCROLLING_SUCCESS
;
13262 /* Compute a suitable window start for window W if display of W starts
13263 on a continuation line. Value is non-zero if a new window start
13266 The new window start will be computed, based on W's width, starting
13267 from the start of the continued line. It is the start of the
13268 screen line with the minimum distance from the old start W->start. */
13271 compute_window_start_on_continuation_line (w
)
13274 struct text_pos pos
, start_pos
;
13275 int window_start_changed_p
= 0;
13277 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
13279 /* If window start is on a continuation line... Window start may be
13280 < BEGV in case there's invisible text at the start of the
13281 buffer (M-x rmail, for example). */
13282 if (CHARPOS (start_pos
) > BEGV
13283 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
13286 struct glyph_row
*row
;
13288 /* Handle the case that the window start is out of range. */
13289 if (CHARPOS (start_pos
) < BEGV
)
13290 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
13291 else if (CHARPOS (start_pos
) > ZV
)
13292 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
13294 /* Find the start of the continued line. This should be fast
13295 because scan_buffer is fast (newline cache). */
13296 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
13297 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
13298 row
, DEFAULT_FACE_ID
);
13299 reseat_at_previous_visible_line_start (&it
);
13301 /* If the line start is "too far" away from the window start,
13302 say it takes too much time to compute a new window start. */
13303 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
13304 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
13306 int min_distance
, distance
;
13308 /* Move forward by display lines to find the new window
13309 start. If window width was enlarged, the new start can
13310 be expected to be > the old start. If window width was
13311 decreased, the new window start will be < the old start.
13312 So, we're looking for the display line start with the
13313 minimum distance from the old window start. */
13314 pos
= it
.current
.pos
;
13315 min_distance
= INFINITY
;
13316 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
13317 distance
< min_distance
)
13319 min_distance
= distance
;
13320 pos
= it
.current
.pos
;
13321 move_it_by_lines (&it
, 1, 0);
13324 /* Set the window start there. */
13325 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
13326 window_start_changed_p
= 1;
13330 return window_start_changed_p
;
13334 /* Try cursor movement in case text has not changed in window WINDOW,
13335 with window start STARTP. Value is
13337 CURSOR_MOVEMENT_SUCCESS if successful
13339 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
13341 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
13342 display. *SCROLL_STEP is set to 1, under certain circumstances, if
13343 we want to scroll as if scroll-step were set to 1. See the code.
13345 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
13346 which case we have to abort this redisplay, and adjust matrices
13351 CURSOR_MOVEMENT_SUCCESS
,
13352 CURSOR_MOVEMENT_CANNOT_BE_USED
,
13353 CURSOR_MOVEMENT_MUST_SCROLL
,
13354 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
13358 try_cursor_movement (window
, startp
, scroll_step
)
13359 Lisp_Object window
;
13360 struct text_pos startp
;
13363 struct window
*w
= XWINDOW (window
);
13364 struct frame
*f
= XFRAME (w
->frame
);
13365 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
13368 if (inhibit_try_cursor_movement
)
13372 /* Handle case where text has not changed, only point, and it has
13373 not moved off the frame. */
13374 if (/* Point may be in this window. */
13375 PT
>= CHARPOS (startp
)
13376 /* Selective display hasn't changed. */
13377 && !current_buffer
->clip_changed
13378 /* Function force-mode-line-update is used to force a thorough
13379 redisplay. It sets either windows_or_buffers_changed or
13380 update_mode_lines. So don't take a shortcut here for these
13382 && !update_mode_lines
13383 && !windows_or_buffers_changed
13384 && !cursor_type_changed
13385 /* Can't use this case if highlighting a region. When a
13386 region exists, cursor movement has to do more than just
13388 && !(!NILP (Vtransient_mark_mode
)
13389 && !NILP (current_buffer
->mark_active
))
13390 && NILP (w
->region_showing
)
13391 && NILP (Vshow_trailing_whitespace
)
13392 /* Right after splitting windows, last_point may be nil. */
13393 && INTEGERP (w
->last_point
)
13394 /* This code is not used for mini-buffer for the sake of the case
13395 of redisplaying to replace an echo area message; since in
13396 that case the mini-buffer contents per se are usually
13397 unchanged. This code is of no real use in the mini-buffer
13398 since the handling of this_line_start_pos, etc., in redisplay
13399 handles the same cases. */
13400 && !EQ (window
, minibuf_window
)
13401 /* When splitting windows or for new windows, it happens that
13402 redisplay is called with a nil window_end_vpos or one being
13403 larger than the window. This should really be fixed in
13404 window.c. I don't have this on my list, now, so we do
13405 approximately the same as the old redisplay code. --gerd. */
13406 && INTEGERP (w
->window_end_vpos
)
13407 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
13408 && (FRAME_WINDOW_P (f
)
13409 || !overlay_arrow_in_current_buffer_p ()))
13411 int this_scroll_margin
, top_scroll_margin
;
13412 struct glyph_row
*row
= NULL
;
13415 debug_method_add (w
, "cursor movement");
13418 /* Scroll if point within this distance from the top or bottom
13419 of the window. This is a pixel value. */
13420 if (scroll_margin
> 0)
13422 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13423 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
13426 this_scroll_margin
= 0;
13428 top_scroll_margin
= this_scroll_margin
;
13429 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13430 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
13432 /* Start with the row the cursor was displayed during the last
13433 not paused redisplay. Give up if that row is not valid. */
13434 if (w
->last_cursor
.vpos
< 0
13435 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
13436 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13439 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
13440 if (row
->mode_line_p
)
13442 if (!row
->enabled_p
)
13443 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13446 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
13449 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
13451 if (PT
> XFASTINT (w
->last_point
))
13453 /* Point has moved forward. */
13454 while (MATRIX_ROW_END_CHARPOS (row
) < PT
13455 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
13457 xassert (row
->enabled_p
);
13461 /* The end position of a row equals the start position
13462 of the next row. If PT is there, we would rather
13463 display it in the next line. */
13464 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13465 && MATRIX_ROW_END_CHARPOS (row
) == PT
13466 && !cursor_row_p (w
, row
))
13469 /* If within the scroll margin, scroll. Note that
13470 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
13471 the next line would be drawn, and that
13472 this_scroll_margin can be zero. */
13473 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
13474 || PT
> MATRIX_ROW_END_CHARPOS (row
)
13475 /* Line is completely visible last line in window
13476 and PT is to be set in the next line. */
13477 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
13478 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13479 && !row
->ends_at_zv_p
13480 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13483 else if (PT
< XFASTINT (w
->last_point
))
13485 /* Cursor has to be moved backward. Note that PT >=
13486 CHARPOS (startp) because of the outer if-statement. */
13487 while (!row
->mode_line_p
13488 && (MATRIX_ROW_START_CHARPOS (row
) > PT
13489 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13490 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
13491 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13492 row
> w
->current_matrix
->rows
13493 && (row
-1)->ends_in_newline_from_string_p
))))
13494 && (row
->y
> top_scroll_margin
13495 || CHARPOS (startp
) == BEGV
))
13497 xassert (row
->enabled_p
);
13501 /* Consider the following case: Window starts at BEGV,
13502 there is invisible, intangible text at BEGV, so that
13503 display starts at some point START > BEGV. It can
13504 happen that we are called with PT somewhere between
13505 BEGV and START. Try to handle that case. */
13506 if (row
< w
->current_matrix
->rows
13507 || row
->mode_line_p
)
13509 row
= w
->current_matrix
->rows
;
13510 if (row
->mode_line_p
)
13514 /* Due to newlines in overlay strings, we may have to
13515 skip forward over overlay strings. */
13516 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13517 && MATRIX_ROW_END_CHARPOS (row
) == PT
13518 && !cursor_row_p (w
, row
))
13521 /* If within the scroll margin, scroll. */
13522 if (row
->y
< top_scroll_margin
13523 && CHARPOS (startp
) != BEGV
)
13528 /* Cursor did not move. So don't scroll even if cursor line
13529 is partially visible, as it was so before. */
13530 rc
= CURSOR_MOVEMENT_SUCCESS
;
13533 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13534 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13536 /* if PT is not in the glyph row, give up. */
13537 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13539 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13540 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13541 && make_cursor_line_fully_visible_p
)
13543 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13544 && !row
->ends_at_zv_p
13545 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13546 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13547 else if (row
->height
> window_box_height (w
))
13549 /* If we end up in a partially visible line, let's
13550 make it fully visible, except when it's taller
13551 than the window, in which case we can't do much
13554 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13558 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13559 if (!cursor_row_fully_visible_p (w
, 0, 1))
13560 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13562 rc
= CURSOR_MOVEMENT_SUCCESS
;
13566 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13571 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
13573 rc
= CURSOR_MOVEMENT_SUCCESS
;
13578 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13579 && MATRIX_ROW_START_CHARPOS (row
) == PT
13580 && cursor_row_p (w
, row
));
13589 set_vertical_scroll_bar (w
)
13592 int start
, end
, whole
;
13594 /* Calculate the start and end positions for the current window.
13595 At some point, it would be nice to choose between scrollbars
13596 which reflect the whole buffer size, with special markers
13597 indicating narrowing, and scrollbars which reflect only the
13600 Note that mini-buffers sometimes aren't displaying any text. */
13601 if (!MINI_WINDOW_P (w
)
13602 || (w
== XWINDOW (minibuf_window
)
13603 && NILP (echo_area_buffer
[0])))
13605 struct buffer
*buf
= XBUFFER (w
->buffer
);
13606 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13607 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13608 /* I don't think this is guaranteed to be right. For the
13609 moment, we'll pretend it is. */
13610 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13614 if (whole
< (end
- start
))
13615 whole
= end
- start
;
13618 start
= end
= whole
= 0;
13620 /* Indicate what this scroll bar ought to be displaying now. */
13621 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13622 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13623 (w
, end
- start
, whole
, start
);
13627 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13628 selected_window is redisplayed.
13630 We can return without actually redisplaying the window if
13631 fonts_changed_p is nonzero. In that case, redisplay_internal will
13635 redisplay_window (window
, just_this_one_p
)
13636 Lisp_Object window
;
13637 int just_this_one_p
;
13639 struct window
*w
= XWINDOW (window
);
13640 struct frame
*f
= XFRAME (w
->frame
);
13641 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13642 struct buffer
*old
= current_buffer
;
13643 struct text_pos lpoint
, opoint
, startp
;
13644 int update_mode_line
;
13647 /* Record it now because it's overwritten. */
13648 int current_matrix_up_to_date_p
= 0;
13649 int used_current_matrix_p
= 0;
13650 /* This is less strict than current_matrix_up_to_date_p.
13651 It indictes that the buffer contents and narrowing are unchanged. */
13652 int buffer_unchanged_p
= 0;
13653 int temp_scroll_step
= 0;
13654 int count
= SPECPDL_INDEX ();
13656 int centering_position
= -1;
13657 int last_line_misfit
= 0;
13658 int beg_unchanged
, end_unchanged
;
13660 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13663 /* W must be a leaf window here. */
13664 xassert (!NILP (w
->buffer
));
13666 *w
->desired_matrix
->method
= 0;
13670 reconsider_clip_changes (w
, buffer
);
13672 /* Has the mode line to be updated? */
13673 update_mode_line
= (!NILP (w
->update_mode_line
)
13674 || update_mode_lines
13675 || buffer
->clip_changed
13676 || buffer
->prevent_redisplay_optimizations_p
);
13678 if (MINI_WINDOW_P (w
))
13680 if (w
== XWINDOW (echo_area_window
)
13681 && !NILP (echo_area_buffer
[0]))
13683 if (update_mode_line
)
13684 /* We may have to update a tty frame's menu bar or a
13685 tool-bar. Example `M-x C-h C-h C-g'. */
13686 goto finish_menu_bars
;
13688 /* We've already displayed the echo area glyphs in this window. */
13689 goto finish_scroll_bars
;
13691 else if ((w
!= XWINDOW (minibuf_window
)
13692 || minibuf_level
== 0)
13693 /* When buffer is nonempty, redisplay window normally. */
13694 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13695 /* Quail displays non-mini buffers in minibuffer window.
13696 In that case, redisplay the window normally. */
13697 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13699 /* W is a mini-buffer window, but it's not active, so clear
13701 int yb
= window_text_bottom_y (w
);
13702 struct glyph_row
*row
;
13705 for (y
= 0, row
= w
->desired_matrix
->rows
;
13707 y
+= row
->height
, ++row
)
13708 blank_row (w
, row
, y
);
13709 goto finish_scroll_bars
;
13712 clear_glyph_matrix (w
->desired_matrix
);
13715 /* Otherwise set up data on this window; select its buffer and point
13717 /* Really select the buffer, for the sake of buffer-local
13719 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13721 current_matrix_up_to_date_p
13722 = (!NILP (w
->window_end_valid
)
13723 && !current_buffer
->clip_changed
13724 && !current_buffer
->prevent_redisplay_optimizations_p
13725 && XFASTINT (w
->last_modified
) >= MODIFF
13726 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13728 /* Run the window-bottom-change-functions
13729 if it is possible that the text on the screen has changed
13730 (either due to modification of the text, or any other reason). */
13731 if (!current_matrix_up_to_date_p
13732 && !NILP (Vwindow_text_change_functions
))
13734 safe_run_hooks (Qwindow_text_change_functions
);
13738 beg_unchanged
= BEG_UNCHANGED
;
13739 end_unchanged
= END_UNCHANGED
;
13741 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13743 specbind (Qinhibit_point_motion_hooks
, Qt
);
13746 = (!NILP (w
->window_end_valid
)
13747 && !current_buffer
->clip_changed
13748 && XFASTINT (w
->last_modified
) >= MODIFF
13749 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13751 /* When windows_or_buffers_changed is non-zero, we can't rely on
13752 the window end being valid, so set it to nil there. */
13753 if (windows_or_buffers_changed
)
13755 /* If window starts on a continuation line, maybe adjust the
13756 window start in case the window's width changed. */
13757 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13758 compute_window_start_on_continuation_line (w
);
13760 w
->window_end_valid
= Qnil
;
13763 /* Some sanity checks. */
13764 CHECK_WINDOW_END (w
);
13765 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
13767 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
13770 /* If %c is in mode line, update it if needed. */
13771 if (!NILP (w
->column_number_displayed
)
13772 /* This alternative quickly identifies a common case
13773 where no change is needed. */
13774 && !(PT
== XFASTINT (w
->last_point
)
13775 && XFASTINT (w
->last_modified
) >= MODIFF
13776 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
13777 && (XFASTINT (w
->column_number_displayed
)
13778 != (int) current_column ())) /* iftc */
13779 update_mode_line
= 1;
13781 /* Count number of windows showing the selected buffer. An indirect
13782 buffer counts as its base buffer. */
13783 if (!just_this_one_p
)
13785 struct buffer
*current_base
, *window_base
;
13786 current_base
= current_buffer
;
13787 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13788 if (current_base
->base_buffer
)
13789 current_base
= current_base
->base_buffer
;
13790 if (window_base
->base_buffer
)
13791 window_base
= window_base
->base_buffer
;
13792 if (current_base
== window_base
)
13796 /* Point refers normally to the selected window. For any other
13797 window, set up appropriate value. */
13798 if (!EQ (window
, selected_window
))
13800 int new_pt
= XMARKER (w
->pointm
)->charpos
;
13801 int new_pt_byte
= marker_byte_position (w
->pointm
);
13805 new_pt_byte
= BEGV_BYTE
;
13806 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13808 else if (new_pt
> (ZV
- 1))
13811 new_pt_byte
= ZV_BYTE
;
13812 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13815 /* We don't use SET_PT so that the point-motion hooks don't run. */
13816 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
13819 /* If any of the character widths specified in the display table
13820 have changed, invalidate the width run cache. It's true that
13821 this may be a bit late to catch such changes, but the rest of
13822 redisplay goes (non-fatally) haywire when the display table is
13823 changed, so why should we worry about doing any better? */
13824 if (current_buffer
->width_run_cache
)
13826 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
13828 if (! disptab_matches_widthtab (disptab
,
13829 XVECTOR (current_buffer
->width_table
)))
13831 invalidate_region_cache (current_buffer
,
13832 current_buffer
->width_run_cache
,
13834 recompute_width_table (current_buffer
, disptab
);
13838 /* If window-start is screwed up, choose a new one. */
13839 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
13842 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13844 /* If someone specified a new starting point but did not insist,
13845 check whether it can be used. */
13846 if (!NILP (w
->optional_new_start
)
13847 && CHARPOS (startp
) >= BEGV
13848 && CHARPOS (startp
) <= ZV
)
13850 w
->optional_new_start
= Qnil
;
13851 start_display (&it
, w
, startp
);
13852 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
13853 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13854 if (IT_CHARPOS (it
) == PT
)
13855 w
->force_start
= Qt
;
13856 /* IT may overshoot PT if text at PT is invisible. */
13857 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
13858 w
->force_start
= Qt
;
13863 /* Handle case where place to start displaying has been specified,
13864 unless the specified location is outside the accessible range. */
13865 if (!NILP (w
->force_start
)
13866 || w
->frozen_window_start_p
)
13868 /* We set this later on if we have to adjust point. */
13871 w
->force_start
= Qnil
;
13873 w
->window_end_valid
= Qnil
;
13875 /* Forget any recorded base line for line number display. */
13876 if (!buffer_unchanged_p
)
13877 w
->base_line_number
= Qnil
;
13879 /* Redisplay the mode line. Select the buffer properly for that.
13880 Also, run the hook window-scroll-functions
13881 because we have scrolled. */
13882 /* Note, we do this after clearing force_start because
13883 if there's an error, it is better to forget about force_start
13884 than to get into an infinite loop calling the hook functions
13885 and having them get more errors. */
13886 if (!update_mode_line
13887 || ! NILP (Vwindow_scroll_functions
))
13889 update_mode_line
= 1;
13890 w
->update_mode_line
= Qt
;
13891 startp
= run_window_scroll_functions (window
, startp
);
13894 w
->last_modified
= make_number (0);
13895 w
->last_overlay_modified
= make_number (0);
13896 if (CHARPOS (startp
) < BEGV
)
13897 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
13898 else if (CHARPOS (startp
) > ZV
)
13899 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
13901 /* Redisplay, then check if cursor has been set during the
13902 redisplay. Give up if new fonts were loaded. */
13903 /* We used to issue a CHECK_MARGINS argument to try_window here,
13904 but this causes scrolling to fail when point begins inside
13905 the scroll margin (bug#148) -- cyd */
13906 if (!try_window (window
, startp
, 0))
13908 w
->force_start
= Qt
;
13909 clear_glyph_matrix (w
->desired_matrix
);
13910 goto need_larger_matrices
;
13913 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
13915 /* If point does not appear, try to move point so it does
13916 appear. The desired matrix has been built above, so we
13917 can use it here. */
13918 new_vpos
= window_box_height (w
) / 2;
13921 if (!cursor_row_fully_visible_p (w
, 0, 0))
13923 /* Point does appear, but on a line partly visible at end of window.
13924 Move it back to a fully-visible line. */
13925 new_vpos
= window_box_height (w
);
13928 /* If we need to move point for either of the above reasons,
13929 now actually do it. */
13932 struct glyph_row
*row
;
13934 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13935 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13938 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13939 MATRIX_ROW_START_BYTEPOS (row
));
13941 if (w
!= XWINDOW (selected_window
))
13942 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13943 else if (current_buffer
== old
)
13944 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13946 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13948 /* If we are highlighting the region, then we just changed
13949 the region, so redisplay to show it. */
13950 if (!NILP (Vtransient_mark_mode
)
13951 && !NILP (current_buffer
->mark_active
))
13953 clear_glyph_matrix (w
->desired_matrix
);
13954 if (!try_window (window
, startp
, 0))
13955 goto need_larger_matrices
;
13960 debug_method_add (w
, "forced window start");
13965 /* Handle case where text has not changed, only point, and it has
13966 not moved off the frame, and we are not retrying after hscroll.
13967 (current_matrix_up_to_date_p is nonzero when retrying.) */
13968 if (current_matrix_up_to_date_p
13969 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13970 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13974 case CURSOR_MOVEMENT_SUCCESS
:
13975 used_current_matrix_p
= 1;
13978 case CURSOR_MOVEMENT_MUST_SCROLL
:
13979 goto try_to_scroll
;
13985 /* If current starting point was originally the beginning of a line
13986 but no longer is, find a new starting point. */
13987 else if (!NILP (w
->start_at_line_beg
)
13988 && !(CHARPOS (startp
) <= BEGV
13989 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13992 debug_method_add (w
, "recenter 1");
13997 /* Try scrolling with try_window_id. Value is > 0 if update has
13998 been done, it is -1 if we know that the same window start will
13999 not work. It is 0 if unsuccessful for some other reason. */
14000 else if ((tem
= try_window_id (w
)) != 0)
14003 debug_method_add (w
, "try_window_id %d", tem
);
14006 if (fonts_changed_p
)
14007 goto need_larger_matrices
;
14011 /* Otherwise try_window_id has returned -1 which means that we
14012 don't want the alternative below this comment to execute. */
14014 else if (CHARPOS (startp
) >= BEGV
14015 && CHARPOS (startp
) <= ZV
14016 && PT
>= CHARPOS (startp
)
14017 && (CHARPOS (startp
) < ZV
14018 /* Avoid starting at end of buffer. */
14019 || CHARPOS (startp
) == BEGV
14020 || (XFASTINT (w
->last_modified
) >= MODIFF
14021 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
14024 /* If first window line is a continuation line, and window start
14025 is inside the modified region, but the first change is before
14026 current window start, we must select a new window start.
14028 However, if this is the result of a down-mouse event (e.g. by
14029 extending the mouse-drag-overlay), we don't want to select a
14030 new window start, since that would change the position under
14031 the mouse, resulting in an unwanted mouse-movement rather
14032 than a simple mouse-click. */
14033 if (NILP (w
->start_at_line_beg
)
14034 && NILP (do_mouse_tracking
)
14035 && CHARPOS (startp
) > BEGV
14036 && CHARPOS (startp
) > BEG
+ beg_unchanged
14037 && CHARPOS (startp
) <= Z
- end_unchanged
14038 /* Even if w->start_at_line_beg is nil, a new window may
14039 start at a line_beg, since that's how set_buffer_window
14040 sets it. So, we need to check the return value of
14041 compute_window_start_on_continuation_line. (See also
14043 && XMARKER (w
->start
)->buffer
== current_buffer
14044 && compute_window_start_on_continuation_line (w
))
14046 w
->force_start
= Qt
;
14047 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14052 debug_method_add (w
, "same window start");
14055 /* Try to redisplay starting at same place as before.
14056 If point has not moved off frame, accept the results. */
14057 if (!current_matrix_up_to_date_p
14058 /* Don't use try_window_reusing_current_matrix in this case
14059 because a window scroll function can have changed the
14061 || !NILP (Vwindow_scroll_functions
)
14062 || MINI_WINDOW_P (w
)
14063 || !(used_current_matrix_p
14064 = try_window_reusing_current_matrix (w
)))
14066 IF_DEBUG (debug_method_add (w
, "1"));
14067 if (try_window (window
, startp
, 1) < 0)
14068 /* -1 means we need to scroll.
14069 0 means we need new matrices, but fonts_changed_p
14070 is set in that case, so we will detect it below. */
14071 goto try_to_scroll
;
14074 if (fonts_changed_p
)
14075 goto need_larger_matrices
;
14077 if (w
->cursor
.vpos
>= 0)
14079 if (!just_this_one_p
14080 || current_buffer
->clip_changed
14081 || BEG_UNCHANGED
< CHARPOS (startp
))
14082 /* Forget any recorded base line for line number display. */
14083 w
->base_line_number
= Qnil
;
14085 if (!cursor_row_fully_visible_p (w
, 1, 0))
14087 clear_glyph_matrix (w
->desired_matrix
);
14088 last_line_misfit
= 1;
14090 /* Drop through and scroll. */
14095 clear_glyph_matrix (w
->desired_matrix
);
14100 w
->last_modified
= make_number (0);
14101 w
->last_overlay_modified
= make_number (0);
14103 /* Redisplay the mode line. Select the buffer properly for that. */
14104 if (!update_mode_line
)
14106 update_mode_line
= 1;
14107 w
->update_mode_line
= Qt
;
14110 /* Try to scroll by specified few lines. */
14111 if ((scroll_conservatively
14113 || temp_scroll_step
14114 || NUMBERP (current_buffer
->scroll_up_aggressively
)
14115 || NUMBERP (current_buffer
->scroll_down_aggressively
))
14116 && !current_buffer
->clip_changed
14117 && CHARPOS (startp
) >= BEGV
14118 && CHARPOS (startp
) <= ZV
)
14120 /* The function returns -1 if new fonts were loaded, 1 if
14121 successful, 0 if not successful. */
14122 int rc
= try_scrolling (window
, just_this_one_p
,
14123 scroll_conservatively
,
14125 temp_scroll_step
, last_line_misfit
);
14128 case SCROLLING_SUCCESS
:
14131 case SCROLLING_NEED_LARGER_MATRICES
:
14132 goto need_larger_matrices
;
14134 case SCROLLING_FAILED
:
14142 /* Finally, just choose place to start which centers point */
14145 if (centering_position
< 0)
14146 centering_position
= window_box_height (w
) / 2;
14149 debug_method_add (w
, "recenter");
14152 /* w->vscroll = 0; */
14154 /* Forget any previously recorded base line for line number display. */
14155 if (!buffer_unchanged_p
)
14156 w
->base_line_number
= Qnil
;
14158 /* Move backward half the height of the window. */
14159 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14160 it
.current_y
= it
.last_visible_y
;
14161 move_it_vertically_backward (&it
, centering_position
);
14162 xassert (IT_CHARPOS (it
) >= BEGV
);
14164 /* The function move_it_vertically_backward may move over more
14165 than the specified y-distance. If it->w is small, e.g. a
14166 mini-buffer window, we may end up in front of the window's
14167 display area. Start displaying at the start of the line
14168 containing PT in this case. */
14169 if (it
.current_y
<= 0)
14171 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14172 move_it_vertically_backward (&it
, 0);
14176 it
.current_x
= it
.hpos
= 0;
14178 /* Set startp here explicitly in case that helps avoid an infinite loop
14179 in case the window-scroll-functions functions get errors. */
14180 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
14182 /* Run scroll hooks. */
14183 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
14185 /* Redisplay the window. */
14186 if (!current_matrix_up_to_date_p
14187 || windows_or_buffers_changed
14188 || cursor_type_changed
14189 /* Don't use try_window_reusing_current_matrix in this case
14190 because it can have changed the buffer. */
14191 || !NILP (Vwindow_scroll_functions
)
14192 || !just_this_one_p
14193 || MINI_WINDOW_P (w
)
14194 || !(used_current_matrix_p
14195 = try_window_reusing_current_matrix (w
)))
14196 try_window (window
, startp
, 0);
14198 /* If new fonts have been loaded (due to fontsets), give up. We
14199 have to start a new redisplay since we need to re-adjust glyph
14201 if (fonts_changed_p
)
14202 goto need_larger_matrices
;
14204 /* If cursor did not appear assume that the middle of the window is
14205 in the first line of the window. Do it again with the next line.
14206 (Imagine a window of height 100, displaying two lines of height
14207 60. Moving back 50 from it->last_visible_y will end in the first
14209 if (w
->cursor
.vpos
< 0)
14211 if (!NILP (w
->window_end_valid
)
14212 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
14214 clear_glyph_matrix (w
->desired_matrix
);
14215 move_it_by_lines (&it
, 1, 0);
14216 try_window (window
, it
.current
.pos
, 0);
14218 else if (PT
< IT_CHARPOS (it
))
14220 clear_glyph_matrix (w
->desired_matrix
);
14221 move_it_by_lines (&it
, -1, 0);
14222 try_window (window
, it
.current
.pos
, 0);
14226 /* Not much we can do about it. */
14230 /* Consider the following case: Window starts at BEGV, there is
14231 invisible, intangible text at BEGV, so that display starts at
14232 some point START > BEGV. It can happen that we are called with
14233 PT somewhere between BEGV and START. Try to handle that case. */
14234 if (w
->cursor
.vpos
< 0)
14236 struct glyph_row
*row
= w
->current_matrix
->rows
;
14237 if (row
->mode_line_p
)
14239 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14242 if (!cursor_row_fully_visible_p (w
, 0, 0))
14244 /* If vscroll is enabled, disable it and try again. */
14248 clear_glyph_matrix (w
->desired_matrix
);
14252 /* If centering point failed to make the whole line visible,
14253 put point at the top instead. That has to make the whole line
14254 visible, if it can be done. */
14255 if (centering_position
== 0)
14258 clear_glyph_matrix (w
->desired_matrix
);
14259 centering_position
= 0;
14265 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14266 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
14267 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
14270 /* Display the mode line, if we must. */
14271 if ((update_mode_line
14272 /* If window not full width, must redo its mode line
14273 if (a) the window to its side is being redone and
14274 (b) we do a frame-based redisplay. This is a consequence
14275 of how inverted lines are drawn in frame-based redisplay. */
14276 || (!just_this_one_p
14277 && !FRAME_WINDOW_P (f
)
14278 && !WINDOW_FULL_WIDTH_P (w
))
14279 /* Line number to display. */
14280 || INTEGERP (w
->base_line_pos
)
14281 /* Column number is displayed and different from the one displayed. */
14282 || (!NILP (w
->column_number_displayed
)
14283 && (XFASTINT (w
->column_number_displayed
)
14284 != (int) current_column ()))) /* iftc */
14285 /* This means that the window has a mode line. */
14286 && (WINDOW_WANTS_MODELINE_P (w
)
14287 || WINDOW_WANTS_HEADER_LINE_P (w
)))
14289 display_mode_lines (w
);
14291 /* If mode line height has changed, arrange for a thorough
14292 immediate redisplay using the correct mode line height. */
14293 if (WINDOW_WANTS_MODELINE_P (w
)
14294 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
14296 fonts_changed_p
= 1;
14297 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
14298 = DESIRED_MODE_LINE_HEIGHT (w
);
14301 /* If header line height has changed, arrange for a thorough
14302 immediate redisplay using the correct header line height. */
14303 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14304 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
14306 fonts_changed_p
= 1;
14307 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
14308 = DESIRED_HEADER_LINE_HEIGHT (w
);
14311 if (fonts_changed_p
)
14312 goto need_larger_matrices
;
14315 if (!line_number_displayed
14316 && !BUFFERP (w
->base_line_pos
))
14318 w
->base_line_pos
= Qnil
;
14319 w
->base_line_number
= Qnil
;
14324 /* When we reach a frame's selected window, redo the frame's menu bar. */
14325 if (update_mode_line
14326 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
14328 int redisplay_menu_p
= 0;
14329 int redisplay_tool_bar_p
= 0;
14331 if (FRAME_WINDOW_P (f
))
14333 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
14334 || defined (HAVE_NS) || defined (USE_GTK)
14335 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
14337 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14341 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14343 if (redisplay_menu_p
)
14344 display_menu_bar (w
);
14346 #ifdef HAVE_WINDOW_SYSTEM
14347 if (FRAME_WINDOW_P (f
))
14349 #if defined (USE_GTK) || defined (HAVE_NS)
14350 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
14352 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
14353 && (FRAME_TOOL_BAR_LINES (f
) > 0
14354 || !NILP (Vauto_resize_tool_bars
));
14357 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
14359 extern int ignore_mouse_drag_p
;
14360 ignore_mouse_drag_p
= 1;
14366 #ifdef HAVE_WINDOW_SYSTEM
14367 if (FRAME_WINDOW_P (f
)
14368 && update_window_fringes (w
, (just_this_one_p
14369 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
14370 || w
->pseudo_window_p
)))
14374 if (draw_window_fringes (w
, 1))
14375 x_draw_vertical_border (w
);
14379 #endif /* HAVE_WINDOW_SYSTEM */
14381 /* We go to this label, with fonts_changed_p nonzero,
14382 if it is necessary to try again using larger glyph matrices.
14383 We have to redeem the scroll bar even in this case,
14384 because the loop in redisplay_internal expects that. */
14385 need_larger_matrices
:
14387 finish_scroll_bars
:
14389 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
14391 /* Set the thumb's position and size. */
14392 set_vertical_scroll_bar (w
);
14394 /* Note that we actually used the scroll bar attached to this
14395 window, so it shouldn't be deleted at the end of redisplay. */
14396 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
14397 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
14400 /* Restore current_buffer and value of point in it. */
14401 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
14402 set_buffer_internal_1 (old
);
14403 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
14404 shorter. This can be caused by log truncation in *Messages*. */
14405 if (CHARPOS (lpoint
) <= ZV
)
14406 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
14408 unbind_to (count
, Qnil
);
14412 /* Build the complete desired matrix of WINDOW with a window start
14413 buffer position POS.
14415 Value is 1 if successful. It is zero if fonts were loaded during
14416 redisplay which makes re-adjusting glyph matrices necessary, and -1
14417 if point would appear in the scroll margins.
14418 (We check that only if CHECK_MARGINS is nonzero. */
14421 try_window (window
, pos
, check_margins
)
14422 Lisp_Object window
;
14423 struct text_pos pos
;
14426 struct window
*w
= XWINDOW (window
);
14428 struct glyph_row
*last_text_row
= NULL
;
14429 struct frame
*f
= XFRAME (w
->frame
);
14431 /* Make POS the new window start. */
14432 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
14434 /* Mark cursor position as unknown. No overlay arrow seen. */
14435 w
->cursor
.vpos
= -1;
14436 overlay_arrow_seen
= 0;
14438 /* Initialize iterator and info to start at POS. */
14439 start_display (&it
, w
, pos
);
14441 /* Display all lines of W. */
14442 while (it
.current_y
< it
.last_visible_y
)
14444 if (display_line (&it
))
14445 last_text_row
= it
.glyph_row
- 1;
14446 if (fonts_changed_p
)
14450 /* Don't let the cursor end in the scroll margins. */
14452 && !MINI_WINDOW_P (w
))
14454 int this_scroll_margin
;
14456 if (scroll_margin
> 0)
14458 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14459 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14462 this_scroll_margin
= 0;
14464 if ((w
->cursor
.y
>= 0 /* not vscrolled */
14465 && w
->cursor
.y
< this_scroll_margin
14466 && CHARPOS (pos
) > BEGV
14467 && IT_CHARPOS (it
) < ZV
)
14468 /* rms: considering make_cursor_line_fully_visible_p here
14469 seems to give wrong results. We don't want to recenter
14470 when the last line is partly visible, we want to allow
14471 that case to be handled in the usual way. */
14472 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
14474 w
->cursor
.vpos
= -1;
14475 clear_glyph_matrix (w
->desired_matrix
);
14480 /* If bottom moved off end of frame, change mode line percentage. */
14481 if (XFASTINT (w
->window_end_pos
) <= 0
14482 && Z
!= IT_CHARPOS (it
))
14483 w
->update_mode_line
= Qt
;
14485 /* Set window_end_pos to the offset of the last character displayed
14486 on the window from the end of current_buffer. Set
14487 window_end_vpos to its row number. */
14490 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
14491 w
->window_end_bytepos
14492 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14494 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14496 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14497 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
14498 ->displays_text_p
);
14502 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14503 w
->window_end_pos
= make_number (Z
- ZV
);
14504 w
->window_end_vpos
= make_number (0);
14507 /* But that is not valid info until redisplay finishes. */
14508 w
->window_end_valid
= Qnil
;
14514 /************************************************************************
14515 Window redisplay reusing current matrix when buffer has not changed
14516 ************************************************************************/
14518 /* Try redisplay of window W showing an unchanged buffer with a
14519 different window start than the last time it was displayed by
14520 reusing its current matrix. Value is non-zero if successful.
14521 W->start is the new window start. */
14524 try_window_reusing_current_matrix (w
)
14527 struct frame
*f
= XFRAME (w
->frame
);
14528 struct glyph_row
*row
, *bottom_row
;
14531 struct text_pos start
, new_start
;
14532 int nrows_scrolled
, i
;
14533 struct glyph_row
*last_text_row
;
14534 struct glyph_row
*last_reused_text_row
;
14535 struct glyph_row
*start_row
;
14536 int start_vpos
, min_y
, max_y
;
14539 if (inhibit_try_window_reusing
)
14543 if (/* This function doesn't handle terminal frames. */
14544 !FRAME_WINDOW_P (f
)
14545 /* Don't try to reuse the display if windows have been split
14547 || windows_or_buffers_changed
14548 || cursor_type_changed
)
14551 /* Can't do this if region may have changed. */
14552 if ((!NILP (Vtransient_mark_mode
)
14553 && !NILP (current_buffer
->mark_active
))
14554 || !NILP (w
->region_showing
)
14555 || !NILP (Vshow_trailing_whitespace
))
14558 /* If top-line visibility has changed, give up. */
14559 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14560 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
14563 /* Give up if old or new display is scrolled vertically. We could
14564 make this function handle this, but right now it doesn't. */
14565 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14566 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
14569 /* The variable new_start now holds the new window start. The old
14570 start `start' can be determined from the current matrix. */
14571 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
14572 start
= start_row
->start
.pos
;
14573 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14575 /* Clear the desired matrix for the display below. */
14576 clear_glyph_matrix (w
->desired_matrix
);
14578 if (CHARPOS (new_start
) <= CHARPOS (start
))
14582 /* Don't use this method if the display starts with an ellipsis
14583 displayed for invisible text. It's not easy to handle that case
14584 below, and it's certainly not worth the effort since this is
14585 not a frequent case. */
14586 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
14589 IF_DEBUG (debug_method_add (w
, "twu1"));
14591 /* Display up to a row that can be reused. The variable
14592 last_text_row is set to the last row displayed that displays
14593 text. Note that it.vpos == 0 if or if not there is a
14594 header-line; it's not the same as the MATRIX_ROW_VPOS! */
14595 start_display (&it
, w
, new_start
);
14596 first_row_y
= it
.current_y
;
14597 w
->cursor
.vpos
= -1;
14598 last_text_row
= last_reused_text_row
= NULL
;
14600 while (it
.current_y
< it
.last_visible_y
14601 && !fonts_changed_p
)
14603 /* If we have reached into the characters in the START row,
14604 that means the line boundaries have changed. So we
14605 can't start copying with the row START. Maybe it will
14606 work to start copying with the following row. */
14607 while (IT_CHARPOS (it
) > CHARPOS (start
))
14609 /* Advance to the next row as the "start". */
14611 start
= start_row
->start
.pos
;
14612 /* If there are no more rows to try, or just one, give up. */
14613 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14614 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14615 || CHARPOS (start
) == ZV
)
14617 clear_glyph_matrix (w
->desired_matrix
);
14621 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14623 /* If we have reached alignment,
14624 we can copy the rest of the rows. */
14625 if (IT_CHARPOS (it
) == CHARPOS (start
))
14628 if (display_line (&it
))
14629 last_text_row
= it
.glyph_row
- 1;
14632 /* A value of current_y < last_visible_y means that we stopped
14633 at the previous window start, which in turn means that we
14634 have at least one reusable row. */
14635 if (it
.current_y
< it
.last_visible_y
)
14637 /* IT.vpos always starts from 0; it counts text lines. */
14638 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14640 /* Find PT if not already found in the lines displayed. */
14641 if (w
->cursor
.vpos
< 0)
14643 int dy
= it
.current_y
- start_row
->y
;
14645 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14646 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14648 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14649 dy
, nrows_scrolled
);
14652 clear_glyph_matrix (w
->desired_matrix
);
14657 /* Scroll the display. Do it before the current matrix is
14658 changed. The problem here is that update has not yet
14659 run, i.e. part of the current matrix is not up to date.
14660 scroll_run_hook will clear the cursor, and use the
14661 current matrix to get the height of the row the cursor is
14663 run
.current_y
= start_row
->y
;
14664 run
.desired_y
= it
.current_y
;
14665 run
.height
= it
.last_visible_y
- it
.current_y
;
14667 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14670 FRAME_RIF (f
)->update_window_begin_hook (w
);
14671 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14672 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14673 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14677 /* Shift current matrix down by nrows_scrolled lines. */
14678 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14679 rotate_matrix (w
->current_matrix
,
14681 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14684 /* Disable lines that must be updated. */
14685 for (i
= 0; i
< nrows_scrolled
; ++i
)
14686 (start_row
+ i
)->enabled_p
= 0;
14688 /* Re-compute Y positions. */
14689 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14690 max_y
= it
.last_visible_y
;
14691 for (row
= start_row
+ nrows_scrolled
;
14695 row
->y
= it
.current_y
;
14696 row
->visible_height
= row
->height
;
14698 if (row
->y
< min_y
)
14699 row
->visible_height
-= min_y
- row
->y
;
14700 if (row
->y
+ row
->height
> max_y
)
14701 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14702 row
->redraw_fringe_bitmaps_p
= 1;
14704 it
.current_y
+= row
->height
;
14706 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14707 last_reused_text_row
= row
;
14708 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14712 /* Disable lines in the current matrix which are now
14713 below the window. */
14714 for (++row
; row
< bottom_row
; ++row
)
14715 row
->enabled_p
= row
->mode_line_p
= 0;
14718 /* Update window_end_pos etc.; last_reused_text_row is the last
14719 reused row from the current matrix containing text, if any.
14720 The value of last_text_row is the last displayed line
14721 containing text. */
14722 if (last_reused_text_row
)
14724 w
->window_end_bytepos
14725 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14727 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14729 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14730 w
->current_matrix
));
14732 else if (last_text_row
)
14734 w
->window_end_bytepos
14735 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14737 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14739 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14743 /* This window must be completely empty. */
14744 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14745 w
->window_end_pos
= make_number (Z
- ZV
);
14746 w
->window_end_vpos
= make_number (0);
14748 w
->window_end_valid
= Qnil
;
14750 /* Update hint: don't try scrolling again in update_window. */
14751 w
->desired_matrix
->no_scrolling_p
= 1;
14754 debug_method_add (w
, "try_window_reusing_current_matrix 1");
14758 else if (CHARPOS (new_start
) > CHARPOS (start
))
14760 struct glyph_row
*pt_row
, *row
;
14761 struct glyph_row
*first_reusable_row
;
14762 struct glyph_row
*first_row_to_display
;
14764 int yb
= window_text_bottom_y (w
);
14766 /* Find the row starting at new_start, if there is one. Don't
14767 reuse a partially visible line at the end. */
14768 first_reusable_row
= start_row
;
14769 while (first_reusable_row
->enabled_p
14770 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
14771 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14772 < CHARPOS (new_start
)))
14773 ++first_reusable_row
;
14775 /* Give up if there is no row to reuse. */
14776 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
14777 || !first_reusable_row
->enabled_p
14778 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14779 != CHARPOS (new_start
)))
14782 /* We can reuse fully visible rows beginning with
14783 first_reusable_row to the end of the window. Set
14784 first_row_to_display to the first row that cannot be reused.
14785 Set pt_row to the row containing point, if there is any. */
14787 for (first_row_to_display
= first_reusable_row
;
14788 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
14789 ++first_row_to_display
)
14791 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
14792 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
14793 pt_row
= first_row_to_display
;
14796 /* Start displaying at the start of first_row_to_display. */
14797 xassert (first_row_to_display
->y
< yb
);
14798 init_to_row_start (&it
, w
, first_row_to_display
);
14800 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
14802 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
14804 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
14805 + WINDOW_HEADER_LINE_HEIGHT (w
));
14807 /* Display lines beginning with first_row_to_display in the
14808 desired matrix. Set last_text_row to the last row displayed
14809 that displays text. */
14810 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
14811 if (pt_row
== NULL
)
14812 w
->cursor
.vpos
= -1;
14813 last_text_row
= NULL
;
14814 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
14815 if (display_line (&it
))
14816 last_text_row
= it
.glyph_row
- 1;
14818 /* If point is in a reused row, adjust y and vpos of the cursor
14822 w
->cursor
.vpos
-= nrows_scrolled
;
14823 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
14826 /* Give up if point isn't in a row displayed or reused. (This
14827 also handles the case where w->cursor.vpos < nrows_scrolled
14828 after the calls to display_line, which can happen with scroll
14829 margins. See bug#1295.) */
14830 if (w
->cursor
.vpos
< 0)
14832 clear_glyph_matrix (w
->desired_matrix
);
14836 /* Scroll the display. */
14837 run
.current_y
= first_reusable_row
->y
;
14838 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14839 run
.height
= it
.last_visible_y
- run
.current_y
;
14840 dy
= run
.current_y
- run
.desired_y
;
14845 FRAME_RIF (f
)->update_window_begin_hook (w
);
14846 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14847 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14848 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14852 /* Adjust Y positions of reused rows. */
14853 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14854 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14855 max_y
= it
.last_visible_y
;
14856 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
14859 row
->visible_height
= row
->height
;
14860 if (row
->y
< min_y
)
14861 row
->visible_height
-= min_y
- row
->y
;
14862 if (row
->y
+ row
->height
> max_y
)
14863 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14864 row
->redraw_fringe_bitmaps_p
= 1;
14867 /* Scroll the current matrix. */
14868 xassert (nrows_scrolled
> 0);
14869 rotate_matrix (w
->current_matrix
,
14871 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14874 /* Disable rows not reused. */
14875 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
14876 row
->enabled_p
= 0;
14878 /* Point may have moved to a different line, so we cannot assume that
14879 the previous cursor position is valid; locate the correct row. */
14882 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
14883 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
14887 w
->cursor
.y
= row
->y
;
14889 if (row
< bottom_row
)
14891 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14892 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
14893 struct glyph
*orig_glyph
= glyph
;
14894 struct cursor_pos orig_cursor
= w
->cursor
;
14897 && (!BUFFERP (glyph
->object
)
14898 || glyph
->charpos
!= PT
);
14902 w
->cursor
.x
+= glyph
->pixel_width
;
14904 /* With bidi reordering, charpos changes non-linearly
14905 with hpos, so the right glyph could be to the
14907 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
14908 && (!BUFFERP (glyph
->object
) || glyph
->charpos
!= PT
))
14910 struct glyph
*start_glyph
= row
->glyphs
[TEXT_AREA
];
14912 glyph
= orig_glyph
- 1;
14913 orig_cursor
.hpos
--;
14914 orig_cursor
.x
-= glyph
->pixel_width
;
14915 for (; glyph
>= start_glyph
14916 && (!BUFFERP (glyph
->object
)
14917 || glyph
->charpos
!= PT
);
14921 w
->cursor
.x
-= glyph
->pixel_width
;
14923 if (BUFFERP (glyph
->object
) && glyph
->charpos
== PT
)
14924 w
->cursor
= orig_cursor
;
14929 /* Adjust window end. A null value of last_text_row means that
14930 the window end is in reused rows which in turn means that
14931 only its vpos can have changed. */
14934 w
->window_end_bytepos
14935 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14937 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14939 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14944 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
14947 w
->window_end_valid
= Qnil
;
14948 w
->desired_matrix
->no_scrolling_p
= 1;
14951 debug_method_add (w
, "try_window_reusing_current_matrix 2");
14961 /************************************************************************
14962 Window redisplay reusing current matrix when buffer has changed
14963 ************************************************************************/
14965 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
14966 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
14968 static struct glyph_row
*
14969 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
14970 struct glyph_row
*));
14973 /* Return the last row in MATRIX displaying text. If row START is
14974 non-null, start searching with that row. IT gives the dimensions
14975 of the display. Value is null if matrix is empty; otherwise it is
14976 a pointer to the row found. */
14978 static struct glyph_row
*
14979 find_last_row_displaying_text (matrix
, it
, start
)
14980 struct glyph_matrix
*matrix
;
14982 struct glyph_row
*start
;
14984 struct glyph_row
*row
, *row_found
;
14986 /* Set row_found to the last row in IT->w's current matrix
14987 displaying text. The loop looks funny but think of partially
14990 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14991 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14993 xassert (row
->enabled_p
);
14995 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
15004 /* Return the last row in the current matrix of W that is not affected
15005 by changes at the start of current_buffer that occurred since W's
15006 current matrix was built. Value is null if no such row exists.
15008 BEG_UNCHANGED us the number of characters unchanged at the start of
15009 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
15010 first changed character in current_buffer. Characters at positions <
15011 BEG + BEG_UNCHANGED are at the same buffer positions as they were
15012 when the current matrix was built. */
15014 static struct glyph_row
*
15015 find_last_unchanged_at_beg_row (w
)
15018 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
15019 struct glyph_row
*row
;
15020 struct glyph_row
*row_found
= NULL
;
15021 int yb
= window_text_bottom_y (w
);
15023 /* Find the last row displaying unchanged text. */
15024 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15025 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15026 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
15029 if (/* If row ends before first_changed_pos, it is unchanged,
15030 except in some case. */
15031 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
15032 /* When row ends in ZV and we write at ZV it is not
15034 && !row
->ends_at_zv_p
15035 /* When first_changed_pos is the end of a continued line,
15036 row is not unchanged because it may be no longer
15038 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
15039 && (row
->continued_p
15040 || row
->exact_window_width_line_p
)))
15043 /* Stop if last visible row. */
15044 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
15052 /* Find the first glyph row in the current matrix of W that is not
15053 affected by changes at the end of current_buffer since the
15054 time W's current matrix was built.
15056 Return in *DELTA the number of chars by which buffer positions in
15057 unchanged text at the end of current_buffer must be adjusted.
15059 Return in *DELTA_BYTES the corresponding number of bytes.
15061 Value is null if no such row exists, i.e. all rows are affected by
15064 static struct glyph_row
*
15065 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
15067 int *delta
, *delta_bytes
;
15069 struct glyph_row
*row
;
15070 struct glyph_row
*row_found
= NULL
;
15072 *delta
= *delta_bytes
= 0;
15074 /* Display must not have been paused, otherwise the current matrix
15075 is not up to date. */
15076 eassert (!NILP (w
->window_end_valid
));
15078 /* A value of window_end_pos >= END_UNCHANGED means that the window
15079 end is in the range of changed text. If so, there is no
15080 unchanged row at the end of W's current matrix. */
15081 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
15084 /* Set row to the last row in W's current matrix displaying text. */
15085 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15087 /* If matrix is entirely empty, no unchanged row exists. */
15088 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15090 /* The value of row is the last glyph row in the matrix having a
15091 meaningful buffer position in it. The end position of row
15092 corresponds to window_end_pos. This allows us to translate
15093 buffer positions in the current matrix to current buffer
15094 positions for characters not in changed text. */
15095 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15096 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15097 int last_unchanged_pos
, last_unchanged_pos_old
;
15098 struct glyph_row
*first_text_row
15099 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15101 *delta
= Z
- Z_old
;
15102 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15104 /* Set last_unchanged_pos to the buffer position of the last
15105 character in the buffer that has not been changed. Z is the
15106 index + 1 of the last character in current_buffer, i.e. by
15107 subtracting END_UNCHANGED we get the index of the last
15108 unchanged character, and we have to add BEG to get its buffer
15110 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
15111 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
15113 /* Search backward from ROW for a row displaying a line that
15114 starts at a minimum position >= last_unchanged_pos_old. */
15115 for (; row
> first_text_row
; --row
)
15117 /* This used to abort, but it can happen.
15118 It is ok to just stop the search instead here. KFS. */
15119 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15122 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
15127 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
15133 /* Make sure that glyph rows in the current matrix of window W
15134 reference the same glyph memory as corresponding rows in the
15135 frame's frame matrix. This function is called after scrolling W's
15136 current matrix on a terminal frame in try_window_id and
15137 try_window_reusing_current_matrix. */
15140 sync_frame_with_window_matrix_rows (w
)
15143 struct frame
*f
= XFRAME (w
->frame
);
15144 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
15146 /* Preconditions: W must be a leaf window and full-width. Its frame
15147 must have a frame matrix. */
15148 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
15149 xassert (WINDOW_FULL_WIDTH_P (w
));
15150 xassert (!FRAME_WINDOW_P (f
));
15152 /* If W is a full-width window, glyph pointers in W's current matrix
15153 have, by definition, to be the same as glyph pointers in the
15154 corresponding frame matrix. Note that frame matrices have no
15155 marginal areas (see build_frame_matrix). */
15156 window_row
= w
->current_matrix
->rows
;
15157 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
15158 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
15159 while (window_row
< window_row_end
)
15161 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
15162 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
15164 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
15165 frame_row
->glyphs
[TEXT_AREA
] = start
;
15166 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
15167 frame_row
->glyphs
[LAST_AREA
] = end
;
15169 /* Disable frame rows whose corresponding window rows have
15170 been disabled in try_window_id. */
15171 if (!window_row
->enabled_p
)
15172 frame_row
->enabled_p
= 0;
15174 ++window_row
, ++frame_row
;
15179 /* Find the glyph row in window W containing CHARPOS. Consider all
15180 rows between START and END (not inclusive). END null means search
15181 all rows to the end of the display area of W. Value is the row
15182 containing CHARPOS or null. */
15185 row_containing_pos (w
, charpos
, start
, end
, dy
)
15188 struct glyph_row
*start
, *end
;
15191 struct glyph_row
*row
= start
;
15194 /* If we happen to start on a header-line, skip that. */
15195 if (row
->mode_line_p
)
15198 if ((end
&& row
>= end
) || !row
->enabled_p
)
15201 last_y
= window_text_bottom_y (w
) - dy
;
15205 /* Give up if we have gone too far. */
15206 if (end
&& row
>= end
)
15208 /* This formerly returned if they were equal.
15209 I think that both quantities are of a "last plus one" type;
15210 if so, when they are equal, the row is within the screen. -- rms. */
15211 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
15214 /* If it is in this row, return this row. */
15215 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
15216 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
15217 /* The end position of a row equals the start
15218 position of the next row. If CHARPOS is there, we
15219 would rather display it in the next line, except
15220 when this line ends in ZV. */
15221 && !row
->ends_at_zv_p
15222 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15223 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
15230 /* Try to redisplay window W by reusing its existing display. W's
15231 current matrix must be up to date when this function is called,
15232 i.e. window_end_valid must not be nil.
15236 1 if display has been updated
15237 0 if otherwise unsuccessful
15238 -1 if redisplay with same window start is known not to succeed
15240 The following steps are performed:
15242 1. Find the last row in the current matrix of W that is not
15243 affected by changes at the start of current_buffer. If no such row
15246 2. Find the first row in W's current matrix that is not affected by
15247 changes at the end of current_buffer. Maybe there is no such row.
15249 3. Display lines beginning with the row + 1 found in step 1 to the
15250 row found in step 2 or, if step 2 didn't find a row, to the end of
15253 4. If cursor is not known to appear on the window, give up.
15255 5. If display stopped at the row found in step 2, scroll the
15256 display and current matrix as needed.
15258 6. Maybe display some lines at the end of W, if we must. This can
15259 happen under various circumstances, like a partially visible line
15260 becoming fully visible, or because newly displayed lines are displayed
15261 in smaller font sizes.
15263 7. Update W's window end information. */
15269 struct frame
*f
= XFRAME (w
->frame
);
15270 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
15271 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
15272 struct glyph_row
*last_unchanged_at_beg_row
;
15273 struct glyph_row
*first_unchanged_at_end_row
;
15274 struct glyph_row
*row
;
15275 struct glyph_row
*bottom_row
;
15278 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
15279 struct text_pos start_pos
;
15281 int first_unchanged_at_end_vpos
= 0;
15282 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
15283 struct text_pos start
;
15284 int first_changed_charpos
, last_changed_charpos
;
15287 if (inhibit_try_window_id
)
15291 /* This is handy for debugging. */
15293 #define GIVE_UP(X) \
15295 fprintf (stderr, "try_window_id give up %d\n", (X)); \
15299 #define GIVE_UP(X) return 0
15302 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
15304 /* Don't use this for mini-windows because these can show
15305 messages and mini-buffers, and we don't handle that here. */
15306 if (MINI_WINDOW_P (w
))
15309 /* This flag is used to prevent redisplay optimizations. */
15310 if (windows_or_buffers_changed
|| cursor_type_changed
)
15313 /* Verify that narrowing has not changed.
15314 Also verify that we were not told to prevent redisplay optimizations.
15315 It would be nice to further
15316 reduce the number of cases where this prevents try_window_id. */
15317 if (current_buffer
->clip_changed
15318 || current_buffer
->prevent_redisplay_optimizations_p
)
15321 /* Window must either use window-based redisplay or be full width. */
15322 if (!FRAME_WINDOW_P (f
)
15323 && (!FRAME_LINE_INS_DEL_OK (f
)
15324 || !WINDOW_FULL_WIDTH_P (w
)))
15327 /* Give up if point is known NOT to appear in W. */
15328 if (PT
< CHARPOS (start
))
15331 /* Another way to prevent redisplay optimizations. */
15332 if (XFASTINT (w
->last_modified
) == 0)
15335 /* Verify that window is not hscrolled. */
15336 if (XFASTINT (w
->hscroll
) != 0)
15339 /* Verify that display wasn't paused. */
15340 if (NILP (w
->window_end_valid
))
15343 /* Can't use this if highlighting a region because a cursor movement
15344 will do more than just set the cursor. */
15345 if (!NILP (Vtransient_mark_mode
)
15346 && !NILP (current_buffer
->mark_active
))
15349 /* Likewise if highlighting trailing whitespace. */
15350 if (!NILP (Vshow_trailing_whitespace
))
15353 /* Likewise if showing a region. */
15354 if (!NILP (w
->region_showing
))
15357 /* Can't use this if overlay arrow position and/or string have
15359 if (overlay_arrows_changed_p ())
15362 /* When word-wrap is on, adding a space to the first word of a
15363 wrapped line can change the wrap position, altering the line
15364 above it. It might be worthwhile to handle this more
15365 intelligently, but for now just redisplay from scratch. */
15366 if (!NILP (XBUFFER (w
->buffer
)->word_wrap
))
15369 /* Under bidi reordering, adding or deleting a character in the
15370 beginning of a paragraph, before the first strong directional
15371 character, can change the base direction of the paragraph (unless
15372 the buffer specifies a fixed paragraph direction), which will
15373 require to redisplay the whole paragraph. It might be worthwhile
15374 to find the paragraph limits and widen the range of redisplayed
15375 lines to that, but for now just give up this optimization and
15376 redisplay from scratch. */
15377 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
15378 && NILP (XBUFFER (w
->buffer
)->bidi_paragraph_direction
))
15381 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
15382 only if buffer has really changed. The reason is that the gap is
15383 initially at Z for freshly visited files. The code below would
15384 set end_unchanged to 0 in that case. */
15385 if (MODIFF
> SAVE_MODIFF
15386 /* This seems to happen sometimes after saving a buffer. */
15387 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
15389 if (GPT
- BEG
< BEG_UNCHANGED
)
15390 BEG_UNCHANGED
= GPT
- BEG
;
15391 if (Z
- GPT
< END_UNCHANGED
)
15392 END_UNCHANGED
= Z
- GPT
;
15395 /* The position of the first and last character that has been changed. */
15396 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
15397 last_changed_charpos
= Z
- END_UNCHANGED
;
15399 /* If window starts after a line end, and the last change is in
15400 front of that newline, then changes don't affect the display.
15401 This case happens with stealth-fontification. Note that although
15402 the display is unchanged, glyph positions in the matrix have to
15403 be adjusted, of course. */
15404 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15405 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15406 && ((last_changed_charpos
< CHARPOS (start
)
15407 && CHARPOS (start
) == BEGV
)
15408 || (last_changed_charpos
< CHARPOS (start
) - 1
15409 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
15411 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
15412 struct glyph_row
*r0
;
15414 /* Compute how many chars/bytes have been added to or removed
15415 from the buffer. */
15416 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15417 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15419 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15421 /* Give up if PT is not in the window. Note that it already has
15422 been checked at the start of try_window_id that PT is not in
15423 front of the window start. */
15424 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
15427 /* If window start is unchanged, we can reuse the whole matrix
15428 as is, after adjusting glyph positions. No need to compute
15429 the window end again, since its offset from Z hasn't changed. */
15430 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15431 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
15432 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
15433 /* PT must not be in a partially visible line. */
15434 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
15435 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15437 /* Adjust positions in the glyph matrix. */
15438 if (delta
|| delta_bytes
)
15440 struct glyph_row
*r1
15441 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15442 increment_matrix_positions (w
->current_matrix
,
15443 MATRIX_ROW_VPOS (r0
, current_matrix
),
15444 MATRIX_ROW_VPOS (r1
, current_matrix
),
15445 delta
, delta_bytes
);
15448 /* Set the cursor. */
15449 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15451 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15458 /* Handle the case that changes are all below what is displayed in
15459 the window, and that PT is in the window. This shortcut cannot
15460 be taken if ZV is visible in the window, and text has been added
15461 there that is visible in the window. */
15462 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
15463 /* ZV is not visible in the window, or there are no
15464 changes at ZV, actually. */
15465 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
15466 || first_changed_charpos
== last_changed_charpos
))
15468 struct glyph_row
*r0
;
15470 /* Give up if PT is not in the window. Note that it already has
15471 been checked at the start of try_window_id that PT is not in
15472 front of the window start. */
15473 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
15476 /* If window start is unchanged, we can reuse the whole matrix
15477 as is, without changing glyph positions since no text has
15478 been added/removed in front of the window end. */
15479 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15480 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
15481 /* PT must not be in a partially visible line. */
15482 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
15483 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15485 /* We have to compute the window end anew since text
15486 can have been added/removed after it. */
15488 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15489 w
->window_end_bytepos
15490 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15492 /* Set the cursor. */
15493 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15495 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15502 /* Give up if window start is in the changed area.
15504 The condition used to read
15506 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
15508 but why that was tested escapes me at the moment. */
15509 if (CHARPOS (start
) >= first_changed_charpos
15510 && CHARPOS (start
) <= last_changed_charpos
)
15513 /* Check that window start agrees with the start of the first glyph
15514 row in its current matrix. Check this after we know the window
15515 start is not in changed text, otherwise positions would not be
15517 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15518 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
15521 /* Give up if the window ends in strings. Overlay strings
15522 at the end are difficult to handle, so don't try. */
15523 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
15524 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
15527 /* Compute the position at which we have to start displaying new
15528 lines. Some of the lines at the top of the window might be
15529 reusable because they are not displaying changed text. Find the
15530 last row in W's current matrix not affected by changes at the
15531 start of current_buffer. Value is null if changes start in the
15532 first line of window. */
15533 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
15534 if (last_unchanged_at_beg_row
)
15536 /* Avoid starting to display in the moddle of a character, a TAB
15537 for instance. This is easier than to set up the iterator
15538 exactly, and it's not a frequent case, so the additional
15539 effort wouldn't really pay off. */
15540 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
15541 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
15542 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
15543 --last_unchanged_at_beg_row
;
15545 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
15548 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
15550 start_pos
= it
.current
.pos
;
15552 /* Start displaying new lines in the desired matrix at the same
15553 vpos we would use in the current matrix, i.e. below
15554 last_unchanged_at_beg_row. */
15555 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
15557 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15558 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
15560 xassert (it
.hpos
== 0 && it
.current_x
== 0);
15564 /* There are no reusable lines at the start of the window.
15565 Start displaying in the first text line. */
15566 start_display (&it
, w
, start
);
15567 it
.vpos
= it
.first_vpos
;
15568 start_pos
= it
.current
.pos
;
15571 /* Find the first row that is not affected by changes at the end of
15572 the buffer. Value will be null if there is no unchanged row, in
15573 which case we must redisplay to the end of the window. delta
15574 will be set to the value by which buffer positions beginning with
15575 first_unchanged_at_end_row have to be adjusted due to text
15577 first_unchanged_at_end_row
15578 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
15579 IF_DEBUG (debug_delta
= delta
);
15580 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
15582 /* Set stop_pos to the buffer position up to which we will have to
15583 display new lines. If first_unchanged_at_end_row != NULL, this
15584 is the buffer position of the start of the line displayed in that
15585 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
15586 that we don't stop at a buffer position. */
15588 if (first_unchanged_at_end_row
)
15590 xassert (last_unchanged_at_beg_row
== NULL
15591 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
15593 /* If this is a continuation line, move forward to the next one
15594 that isn't. Changes in lines above affect this line.
15595 Caution: this may move first_unchanged_at_end_row to a row
15596 not displaying text. */
15597 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
15598 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15599 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15600 < it
.last_visible_y
))
15601 ++first_unchanged_at_end_row
;
15603 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15604 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15605 >= it
.last_visible_y
))
15606 first_unchanged_at_end_row
= NULL
;
15609 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
15611 first_unchanged_at_end_vpos
15612 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
15613 xassert (stop_pos
>= Z
- END_UNCHANGED
);
15616 else if (last_unchanged_at_beg_row
== NULL
)
15622 /* Either there is no unchanged row at the end, or the one we have
15623 now displays text. This is a necessary condition for the window
15624 end pos calculation at the end of this function. */
15625 xassert (first_unchanged_at_end_row
== NULL
15626 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
15628 debug_last_unchanged_at_beg_vpos
15629 = (last_unchanged_at_beg_row
15630 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
15632 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
15634 #endif /* GLYPH_DEBUG != 0 */
15637 /* Display new lines. Set last_text_row to the last new line
15638 displayed which has text on it, i.e. might end up as being the
15639 line where the window_end_vpos is. */
15640 w
->cursor
.vpos
= -1;
15641 last_text_row
= NULL
;
15642 overlay_arrow_seen
= 0;
15643 while (it
.current_y
< it
.last_visible_y
15644 && !fonts_changed_p
15645 && (first_unchanged_at_end_row
== NULL
15646 || IT_CHARPOS (it
) < stop_pos
))
15648 if (display_line (&it
))
15649 last_text_row
= it
.glyph_row
- 1;
15652 if (fonts_changed_p
)
15656 /* Compute differences in buffer positions, y-positions etc. for
15657 lines reused at the bottom of the window. Compute what we can
15659 if (first_unchanged_at_end_row
15660 /* No lines reused because we displayed everything up to the
15661 bottom of the window. */
15662 && it
.current_y
< it
.last_visible_y
)
15665 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15667 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15668 run
.current_y
= first_unchanged_at_end_row
->y
;
15669 run
.desired_y
= run
.current_y
+ dy
;
15670 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15674 delta
= delta_bytes
= dvpos
= dy
15675 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15676 first_unchanged_at_end_row
= NULL
;
15678 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15681 /* Find the cursor if not already found. We have to decide whether
15682 PT will appear on this window (it sometimes doesn't, but this is
15683 not a very frequent case.) This decision has to be made before
15684 the current matrix is altered. A value of cursor.vpos < 0 means
15685 that PT is either in one of the lines beginning at
15686 first_unchanged_at_end_row or below the window. Don't care for
15687 lines that might be displayed later at the window end; as
15688 mentioned, this is not a frequent case. */
15689 if (w
->cursor
.vpos
< 0)
15691 /* Cursor in unchanged rows at the top? */
15692 if (PT
< CHARPOS (start_pos
)
15693 && last_unchanged_at_beg_row
)
15695 row
= row_containing_pos (w
, PT
,
15696 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15697 last_unchanged_at_beg_row
+ 1, 0);
15699 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15702 /* Start from first_unchanged_at_end_row looking for PT. */
15703 else if (first_unchanged_at_end_row
)
15705 row
= row_containing_pos (w
, PT
- delta
,
15706 first_unchanged_at_end_row
, NULL
, 0);
15708 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15709 delta_bytes
, dy
, dvpos
);
15712 /* Give up if cursor was not found. */
15713 if (w
->cursor
.vpos
< 0)
15715 clear_glyph_matrix (w
->desired_matrix
);
15720 /* Don't let the cursor end in the scroll margins. */
15722 int this_scroll_margin
, cursor_height
;
15724 this_scroll_margin
= max (0, scroll_margin
);
15725 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15726 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15727 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15729 if ((w
->cursor
.y
< this_scroll_margin
15730 && CHARPOS (start
) > BEGV
)
15731 /* Old redisplay didn't take scroll margin into account at the bottom,
15732 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
15733 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
15734 ? cursor_height
+ this_scroll_margin
15735 : 1)) > it
.last_visible_y
)
15737 w
->cursor
.vpos
= -1;
15738 clear_glyph_matrix (w
->desired_matrix
);
15743 /* Scroll the display. Do it before changing the current matrix so
15744 that xterm.c doesn't get confused about where the cursor glyph is
15746 if (dy
&& run
.height
)
15750 if (FRAME_WINDOW_P (f
))
15752 FRAME_RIF (f
)->update_window_begin_hook (w
);
15753 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15754 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15755 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15759 /* Terminal frame. In this case, dvpos gives the number of
15760 lines to scroll by; dvpos < 0 means scroll up. */
15761 int first_unchanged_at_end_vpos
15762 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
15763 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
15764 int end
= (WINDOW_TOP_EDGE_LINE (w
)
15765 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
15766 + window_internal_height (w
));
15768 /* Perform the operation on the screen. */
15771 /* Scroll last_unchanged_at_beg_row to the end of the
15772 window down dvpos lines. */
15773 set_terminal_window (f
, end
);
15775 /* On dumb terminals delete dvpos lines at the end
15776 before inserting dvpos empty lines. */
15777 if (!FRAME_SCROLL_REGION_OK (f
))
15778 ins_del_lines (f
, end
- dvpos
, -dvpos
);
15780 /* Insert dvpos empty lines in front of
15781 last_unchanged_at_beg_row. */
15782 ins_del_lines (f
, from
, dvpos
);
15784 else if (dvpos
< 0)
15786 /* Scroll up last_unchanged_at_beg_vpos to the end of
15787 the window to last_unchanged_at_beg_vpos - |dvpos|. */
15788 set_terminal_window (f
, end
);
15790 /* Delete dvpos lines in front of
15791 last_unchanged_at_beg_vpos. ins_del_lines will set
15792 the cursor to the given vpos and emit |dvpos| delete
15794 ins_del_lines (f
, from
+ dvpos
, dvpos
);
15796 /* On a dumb terminal insert dvpos empty lines at the
15798 if (!FRAME_SCROLL_REGION_OK (f
))
15799 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
15802 set_terminal_window (f
, 0);
15808 /* Shift reused rows of the current matrix to the right position.
15809 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
15811 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15812 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
15815 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
15816 bottom_vpos
, dvpos
);
15817 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
15820 else if (dvpos
> 0)
15822 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
15823 bottom_vpos
, dvpos
);
15824 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
15825 first_unchanged_at_end_vpos
+ dvpos
, 0);
15828 /* For frame-based redisplay, make sure that current frame and window
15829 matrix are in sync with respect to glyph memory. */
15830 if (!FRAME_WINDOW_P (f
))
15831 sync_frame_with_window_matrix_rows (w
);
15833 /* Adjust buffer positions in reused rows. */
15834 if (delta
|| delta_bytes
)
15835 increment_matrix_positions (current_matrix
,
15836 first_unchanged_at_end_vpos
+ dvpos
,
15837 bottom_vpos
, delta
, delta_bytes
);
15839 /* Adjust Y positions. */
15841 shift_glyph_matrix (w
, current_matrix
,
15842 first_unchanged_at_end_vpos
+ dvpos
,
15845 if (first_unchanged_at_end_row
)
15847 first_unchanged_at_end_row
+= dvpos
;
15848 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
15849 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
15850 first_unchanged_at_end_row
= NULL
;
15853 /* If scrolling up, there may be some lines to display at the end of
15855 last_text_row_at_end
= NULL
;
15858 /* Scrolling up can leave for example a partially visible line
15859 at the end of the window to be redisplayed. */
15860 /* Set last_row to the glyph row in the current matrix where the
15861 window end line is found. It has been moved up or down in
15862 the matrix by dvpos. */
15863 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
15864 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
15866 /* If last_row is the window end line, it should display text. */
15867 xassert (last_row
->displays_text_p
);
15869 /* If window end line was partially visible before, begin
15870 displaying at that line. Otherwise begin displaying with the
15871 line following it. */
15872 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
15874 init_to_row_start (&it
, w
, last_row
);
15875 it
.vpos
= last_vpos
;
15876 it
.current_y
= last_row
->y
;
15880 init_to_row_end (&it
, w
, last_row
);
15881 it
.vpos
= 1 + last_vpos
;
15882 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
15886 /* We may start in a continuation line. If so, we have to
15887 get the right continuation_lines_width and current_x. */
15888 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
15889 it
.hpos
= it
.current_x
= 0;
15891 /* Display the rest of the lines at the window end. */
15892 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15893 while (it
.current_y
< it
.last_visible_y
15894 && !fonts_changed_p
)
15896 /* Is it always sure that the display agrees with lines in
15897 the current matrix? I don't think so, so we mark rows
15898 displayed invalid in the current matrix by setting their
15899 enabled_p flag to zero. */
15900 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
15901 if (display_line (&it
))
15902 last_text_row_at_end
= it
.glyph_row
- 1;
15906 /* Update window_end_pos and window_end_vpos. */
15907 if (first_unchanged_at_end_row
15908 && !last_text_row_at_end
)
15910 /* Window end line if one of the preserved rows from the current
15911 matrix. Set row to the last row displaying text in current
15912 matrix starting at first_unchanged_at_end_row, after
15914 xassert (first_unchanged_at_end_row
->displays_text_p
);
15915 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
15916 first_unchanged_at_end_row
);
15917 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
15919 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15920 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15922 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
15923 xassert (w
->window_end_bytepos
>= 0);
15924 IF_DEBUG (debug_method_add (w
, "A"));
15926 else if (last_text_row_at_end
)
15929 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
15930 w
->window_end_bytepos
15931 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
15933 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
15934 xassert (w
->window_end_bytepos
>= 0);
15935 IF_DEBUG (debug_method_add (w
, "B"));
15937 else if (last_text_row
)
15939 /* We have displayed either to the end of the window or at the
15940 end of the window, i.e. the last row with text is to be found
15941 in the desired matrix. */
15943 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15944 w
->window_end_bytepos
15945 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15947 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
15948 xassert (w
->window_end_bytepos
>= 0);
15950 else if (first_unchanged_at_end_row
== NULL
15951 && last_text_row
== NULL
15952 && last_text_row_at_end
== NULL
)
15954 /* Displayed to end of window, but no line containing text was
15955 displayed. Lines were deleted at the end of the window. */
15956 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
15957 int vpos
= XFASTINT (w
->window_end_vpos
);
15958 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
15959 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
15962 row
== NULL
&& vpos
>= first_vpos
;
15963 --vpos
, --current_row
, --desired_row
)
15965 if (desired_row
->enabled_p
)
15967 if (desired_row
->displays_text_p
)
15970 else if (current_row
->displays_text_p
)
15974 xassert (row
!= NULL
);
15975 w
->window_end_vpos
= make_number (vpos
+ 1);
15976 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15977 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15978 xassert (w
->window_end_bytepos
>= 0);
15979 IF_DEBUG (debug_method_add (w
, "C"));
15984 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
15985 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
15987 /* Record that display has not been completed. */
15988 w
->window_end_valid
= Qnil
;
15989 w
->desired_matrix
->no_scrolling_p
= 1;
15997 /***********************************************************************
15998 More debugging support
15999 ***********************************************************************/
16003 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
16004 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
16005 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
16008 /* Dump the contents of glyph matrix MATRIX on stderr.
16010 GLYPHS 0 means don't show glyph contents.
16011 GLYPHS 1 means show glyphs in short form
16012 GLYPHS > 1 means show glyphs in long form. */
16015 dump_glyph_matrix (matrix
, glyphs
)
16016 struct glyph_matrix
*matrix
;
16020 for (i
= 0; i
< matrix
->nrows
; ++i
)
16021 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
16025 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
16026 the glyph row and area where the glyph comes from. */
16029 dump_glyph (row
, glyph
, area
)
16030 struct glyph_row
*row
;
16031 struct glyph
*glyph
;
16034 if (glyph
->type
== CHAR_GLYPH
)
16037 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16038 glyph
- row
->glyphs
[TEXT_AREA
],
16041 (BUFFERP (glyph
->object
)
16043 : (STRINGP (glyph
->object
)
16046 glyph
->pixel_width
,
16048 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
16052 glyph
->left_box_line_p
,
16053 glyph
->right_box_line_p
);
16055 else if (glyph
->type
== STRETCH_GLYPH
)
16058 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16059 glyph
- row
->glyphs
[TEXT_AREA
],
16062 (BUFFERP (glyph
->object
)
16064 : (STRINGP (glyph
->object
)
16067 glyph
->pixel_width
,
16071 glyph
->left_box_line_p
,
16072 glyph
->right_box_line_p
);
16074 else if (glyph
->type
== IMAGE_GLYPH
)
16077 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16078 glyph
- row
->glyphs
[TEXT_AREA
],
16081 (BUFFERP (glyph
->object
)
16083 : (STRINGP (glyph
->object
)
16086 glyph
->pixel_width
,
16090 glyph
->left_box_line_p
,
16091 glyph
->right_box_line_p
);
16093 else if (glyph
->type
== COMPOSITE_GLYPH
)
16096 " %5d %4c %6d %c %3d 0x%05x",
16097 glyph
- row
->glyphs
[TEXT_AREA
],
16100 (BUFFERP (glyph
->object
)
16102 : (STRINGP (glyph
->object
)
16105 glyph
->pixel_width
,
16107 if (glyph
->u
.cmp
.automatic
)
16110 glyph
->u
.cmp
.from
, glyph
->u
.cmp
.to
);
16111 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
16113 glyph
->left_box_line_p
,
16114 glyph
->right_box_line_p
);
16119 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
16120 GLYPHS 0 means don't show glyph contents.
16121 GLYPHS 1 means show glyphs in short form
16122 GLYPHS > 1 means show glyphs in long form. */
16125 dump_glyph_row (row
, vpos
, glyphs
)
16126 struct glyph_row
*row
;
16131 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
16132 fprintf (stderr
, "======================================================================\n");
16134 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
16135 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
16137 MATRIX_ROW_START_CHARPOS (row
),
16138 MATRIX_ROW_END_CHARPOS (row
),
16139 row
->used
[TEXT_AREA
],
16140 row
->contains_overlapping_glyphs_p
,
16142 row
->truncated_on_left_p
,
16143 row
->truncated_on_right_p
,
16145 MATRIX_ROW_CONTINUATION_LINE_P (row
),
16146 row
->displays_text_p
,
16149 row
->ends_in_middle_of_char_p
,
16150 row
->starts_in_middle_of_char_p
,
16156 row
->visible_height
,
16159 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
16160 row
->end
.overlay_string_index
,
16161 row
->continuation_lines_width
);
16162 fprintf (stderr
, "%9d %5d\n",
16163 CHARPOS (row
->start
.string_pos
),
16164 CHARPOS (row
->end
.string_pos
));
16165 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
16166 row
->end
.dpvec_index
);
16173 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16175 struct glyph
*glyph
= row
->glyphs
[area
];
16176 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
16178 /* Glyph for a line end in text. */
16179 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
16182 if (glyph
< glyph_end
)
16183 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
16185 for (; glyph
< glyph_end
; ++glyph
)
16186 dump_glyph (row
, glyph
, area
);
16189 else if (glyphs
== 1)
16193 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16195 char *s
= (char *) alloca (row
->used
[area
] + 1);
16198 for (i
= 0; i
< row
->used
[area
]; ++i
)
16200 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
16201 if (glyph
->type
== CHAR_GLYPH
16202 && glyph
->u
.ch
< 0x80
16203 && glyph
->u
.ch
>= ' ')
16204 s
[i
] = glyph
->u
.ch
;
16210 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
16216 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
16217 Sdump_glyph_matrix
, 0, 1, "p",
16218 doc
: /* Dump the current matrix of the selected window to stderr.
16219 Shows contents of glyph row structures. With non-nil
16220 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
16221 glyphs in short form, otherwise show glyphs in long form. */)
16223 Lisp_Object glyphs
;
16225 struct window
*w
= XWINDOW (selected_window
);
16226 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16228 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
16229 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
16230 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
16231 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
16232 fprintf (stderr
, "=============================================\n");
16233 dump_glyph_matrix (w
->current_matrix
,
16234 NILP (glyphs
) ? 0 : XINT (glyphs
));
16239 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
16240 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
16243 struct frame
*f
= XFRAME (selected_frame
);
16244 dump_glyph_matrix (f
->current_matrix
, 1);
16249 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
16250 doc
: /* Dump glyph row ROW to stderr.
16251 GLYPH 0 means don't dump glyphs.
16252 GLYPH 1 means dump glyphs in short form.
16253 GLYPH > 1 or omitted means dump glyphs in long form. */)
16255 Lisp_Object row
, glyphs
;
16257 struct glyph_matrix
*matrix
;
16260 CHECK_NUMBER (row
);
16261 matrix
= XWINDOW (selected_window
)->current_matrix
;
16263 if (vpos
>= 0 && vpos
< matrix
->nrows
)
16264 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
16266 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16271 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
16272 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
16273 GLYPH 0 means don't dump glyphs.
16274 GLYPH 1 means dump glyphs in short form.
16275 GLYPH > 1 or omitted means dump glyphs in long form. */)
16277 Lisp_Object row
, glyphs
;
16279 struct frame
*sf
= SELECTED_FRAME ();
16280 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
16283 CHECK_NUMBER (row
);
16285 if (vpos
>= 0 && vpos
< m
->nrows
)
16286 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
16287 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16292 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
16293 doc
: /* Toggle tracing of redisplay.
16294 With ARG, turn tracing on if and only if ARG is positive. */)
16299 trace_redisplay_p
= !trace_redisplay_p
;
16302 arg
= Fprefix_numeric_value (arg
);
16303 trace_redisplay_p
= XINT (arg
) > 0;
16310 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
16311 doc
: /* Like `format', but print result to stderr.
16312 usage: (trace-to-stderr STRING &rest OBJECTS) */)
16317 Lisp_Object s
= Fformat (nargs
, args
);
16318 fprintf (stderr
, "%s", SDATA (s
));
16322 #endif /* GLYPH_DEBUG */
16326 /***********************************************************************
16327 Building Desired Matrix Rows
16328 ***********************************************************************/
16330 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
16331 Used for non-window-redisplay windows, and for windows w/o left fringe. */
16333 static struct glyph_row
*
16334 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
16336 Lisp_Object overlay_arrow_string
;
16338 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16339 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16340 struct buffer
*old
= current_buffer
;
16341 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
16342 int arrow_len
= SCHARS (overlay_arrow_string
);
16343 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
16344 const unsigned char *p
;
16347 int n_glyphs_before
;
16349 set_buffer_temp (buffer
);
16350 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
16351 it
.glyph_row
->used
[TEXT_AREA
] = 0;
16352 SET_TEXT_POS (it
.position
, 0, 0);
16354 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
16356 while (p
< arrow_end
)
16358 Lisp_Object face
, ilisp
;
16360 /* Get the next character. */
16362 it
.c
= string_char_and_length (p
, &it
.len
);
16364 it
.c
= *p
, it
.len
= 1;
16367 /* Get its face. */
16368 ilisp
= make_number (p
- arrow_string
);
16369 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
16370 it
.face_id
= compute_char_face (f
, it
.c
, face
);
16372 /* Compute its width, get its glyphs. */
16373 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
16374 SET_TEXT_POS (it
.position
, -1, -1);
16375 PRODUCE_GLYPHS (&it
);
16377 /* If this character doesn't fit any more in the line, we have
16378 to remove some glyphs. */
16379 if (it
.current_x
> it
.last_visible_x
)
16381 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16386 set_buffer_temp (old
);
16387 return it
.glyph_row
;
16391 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
16392 glyphs are only inserted for terminal frames since we can't really
16393 win with truncation glyphs when partially visible glyphs are
16394 involved. Which glyphs to insert is determined by
16395 produce_special_glyphs. */
16398 insert_left_trunc_glyphs (it
)
16401 struct it truncate_it
;
16402 struct glyph
*from
, *end
, *to
, *toend
;
16404 xassert (!FRAME_WINDOW_P (it
->f
));
16406 /* Get the truncation glyphs. */
16408 truncate_it
.current_x
= 0;
16409 truncate_it
.face_id
= DEFAULT_FACE_ID
;
16410 truncate_it
.glyph_row
= &scratch_glyph_row
;
16411 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
16412 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
16413 truncate_it
.object
= make_number (0);
16414 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
16416 /* Overwrite glyphs from IT with truncation glyphs. */
16417 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16418 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
16419 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16420 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
16425 /* There may be padding glyphs left over. Overwrite them too. */
16426 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
16428 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16434 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
16438 /* Compute the pixel height and width of IT->glyph_row.
16440 Most of the time, ascent and height of a display line will be equal
16441 to the max_ascent and max_height values of the display iterator
16442 structure. This is not the case if
16444 1. We hit ZV without displaying anything. In this case, max_ascent
16445 and max_height will be zero.
16447 2. We have some glyphs that don't contribute to the line height.
16448 (The glyph row flag contributes_to_line_height_p is for future
16449 pixmap extensions).
16451 The first case is easily covered by using default values because in
16452 these cases, the line height does not really matter, except that it
16453 must not be zero. */
16456 compute_line_metrics (it
)
16459 struct glyph_row
*row
= it
->glyph_row
;
16462 if (FRAME_WINDOW_P (it
->f
))
16464 int i
, min_y
, max_y
;
16466 /* The line may consist of one space only, that was added to
16467 place the cursor on it. If so, the row's height hasn't been
16469 if (row
->height
== 0)
16471 if (it
->max_ascent
+ it
->max_descent
== 0)
16472 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
16473 row
->ascent
= it
->max_ascent
;
16474 row
->height
= it
->max_ascent
+ it
->max_descent
;
16475 row
->phys_ascent
= it
->max_phys_ascent
;
16476 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16477 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16480 /* Compute the width of this line. */
16481 row
->pixel_width
= row
->x
;
16482 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
16483 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
16485 xassert (row
->pixel_width
>= 0);
16486 xassert (row
->ascent
>= 0 && row
->height
> 0);
16488 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
16489 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
16491 /* If first line's physical ascent is larger than its logical
16492 ascent, use the physical ascent, and make the row taller.
16493 This makes accented characters fully visible. */
16494 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
16495 && row
->phys_ascent
> row
->ascent
)
16497 row
->height
+= row
->phys_ascent
- row
->ascent
;
16498 row
->ascent
= row
->phys_ascent
;
16501 /* Compute how much of the line is visible. */
16502 row
->visible_height
= row
->height
;
16504 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
16505 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
16507 if (row
->y
< min_y
)
16508 row
->visible_height
-= min_y
- row
->y
;
16509 if (row
->y
+ row
->height
> max_y
)
16510 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16514 row
->pixel_width
= row
->used
[TEXT_AREA
];
16515 if (row
->continued_p
)
16516 row
->pixel_width
-= it
->continuation_pixel_width
;
16517 else if (row
->truncated_on_right_p
)
16518 row
->pixel_width
-= it
->truncation_pixel_width
;
16519 row
->ascent
= row
->phys_ascent
= 0;
16520 row
->height
= row
->phys_height
= row
->visible_height
= 1;
16521 row
->extra_line_spacing
= 0;
16524 /* Compute a hash code for this row. */
16526 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16527 for (i
= 0; i
< row
->used
[area
]; ++i
)
16528 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
16529 + row
->glyphs
[area
][i
].u
.val
16530 + row
->glyphs
[area
][i
].face_id
16531 + row
->glyphs
[area
][i
].padding_p
16532 + (row
->glyphs
[area
][i
].type
<< 2));
16534 it
->max_ascent
= it
->max_descent
= 0;
16535 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
16539 /* Append one space to the glyph row of iterator IT if doing a
16540 window-based redisplay. The space has the same face as
16541 IT->face_id. Value is non-zero if a space was added.
16543 This function is called to make sure that there is always one glyph
16544 at the end of a glyph row that the cursor can be set on under
16545 window-systems. (If there weren't such a glyph we would not know
16546 how wide and tall a box cursor should be displayed).
16548 At the same time this space let's a nicely handle clearing to the
16549 end of the line if the row ends in italic text. */
16552 append_space_for_newline (it
, default_face_p
)
16554 int default_face_p
;
16556 if (FRAME_WINDOW_P (it
->f
))
16558 int n
= it
->glyph_row
->used
[TEXT_AREA
];
16560 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
16561 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
16563 /* Save some values that must not be changed.
16564 Must save IT->c and IT->len because otherwise
16565 ITERATOR_AT_END_P wouldn't work anymore after
16566 append_space_for_newline has been called. */
16567 enum display_element_type saved_what
= it
->what
;
16568 int saved_c
= it
->c
, saved_len
= it
->len
;
16569 int saved_x
= it
->current_x
;
16570 int saved_face_id
= it
->face_id
;
16571 struct text_pos saved_pos
;
16572 Lisp_Object saved_object
;
16575 saved_object
= it
->object
;
16576 saved_pos
= it
->position
;
16578 it
->what
= IT_CHARACTER
;
16579 bzero (&it
->position
, sizeof it
->position
);
16580 it
->object
= make_number (0);
16584 if (default_face_p
)
16585 it
->face_id
= DEFAULT_FACE_ID
;
16586 else if (it
->face_before_selective_p
)
16587 it
->face_id
= it
->saved_face_id
;
16588 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16589 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
16591 PRODUCE_GLYPHS (it
);
16593 it
->override_ascent
= -1;
16594 it
->constrain_row_ascent_descent_p
= 0;
16595 it
->current_x
= saved_x
;
16596 it
->object
= saved_object
;
16597 it
->position
= saved_pos
;
16598 it
->what
= saved_what
;
16599 it
->face_id
= saved_face_id
;
16600 it
->len
= saved_len
;
16610 /* Extend the face of the last glyph in the text area of IT->glyph_row
16611 to the end of the display line. Called from display_line.
16612 If the glyph row is empty, add a space glyph to it so that we
16613 know the face to draw. Set the glyph row flag fill_line_p. */
16616 extend_face_to_end_of_line (it
)
16620 struct frame
*f
= it
->f
;
16622 /* If line is already filled, do nothing. */
16623 if (it
->current_x
>= it
->last_visible_x
)
16626 /* Face extension extends the background and box of IT->face_id
16627 to the end of the line. If the background equals the background
16628 of the frame, we don't have to do anything. */
16629 if (it
->face_before_selective_p
)
16630 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
16632 face
= FACE_FROM_ID (f
, it
->face_id
);
16634 if (FRAME_WINDOW_P (f
)
16635 && it
->glyph_row
->displays_text_p
16636 && face
->box
== FACE_NO_BOX
16637 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
16641 /* Set the glyph row flag indicating that the face of the last glyph
16642 in the text area has to be drawn to the end of the text area. */
16643 it
->glyph_row
->fill_line_p
= 1;
16645 /* If current character of IT is not ASCII, make sure we have the
16646 ASCII face. This will be automatically undone the next time
16647 get_next_display_element returns a multibyte character. Note
16648 that the character will always be single byte in unibyte
16650 if (!ASCII_CHAR_P (it
->c
))
16652 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
16655 if (FRAME_WINDOW_P (f
))
16657 /* If the row is empty, add a space with the current face of IT,
16658 so that we know which face to draw. */
16659 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16661 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16662 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16663 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16668 /* Save some values that must not be changed. */
16669 int saved_x
= it
->current_x
;
16670 struct text_pos saved_pos
;
16671 Lisp_Object saved_object
;
16672 enum display_element_type saved_what
= it
->what
;
16673 int saved_face_id
= it
->face_id
;
16675 saved_object
= it
->object
;
16676 saved_pos
= it
->position
;
16678 it
->what
= IT_CHARACTER
;
16679 bzero (&it
->position
, sizeof it
->position
);
16680 it
->object
= make_number (0);
16683 it
->face_id
= face
->id
;
16685 PRODUCE_GLYPHS (it
);
16687 while (it
->current_x
<= it
->last_visible_x
)
16688 PRODUCE_GLYPHS (it
);
16690 /* Don't count these blanks really. It would let us insert a left
16691 truncation glyph below and make us set the cursor on them, maybe. */
16692 it
->current_x
= saved_x
;
16693 it
->object
= saved_object
;
16694 it
->position
= saved_pos
;
16695 it
->what
= saved_what
;
16696 it
->face_id
= saved_face_id
;
16701 /* Value is non-zero if text starting at CHARPOS in current_buffer is
16702 trailing whitespace. */
16705 trailing_whitespace_p (charpos
)
16708 int bytepos
= CHAR_TO_BYTE (charpos
);
16711 while (bytepos
< ZV_BYTE
16712 && (c
= FETCH_CHAR (bytepos
),
16713 c
== ' ' || c
== '\t'))
16716 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
16718 if (bytepos
!= PT_BYTE
)
16725 /* Highlight trailing whitespace, if any, in ROW. */
16728 highlight_trailing_whitespace (f
, row
)
16730 struct glyph_row
*row
;
16732 int used
= row
->used
[TEXT_AREA
];
16736 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
16737 struct glyph
*glyph
= start
+ used
- 1;
16739 /* Skip over glyphs inserted to display the cursor at the
16740 end of a line, for extending the face of the last glyph
16741 to the end of the line on terminals, and for truncation
16742 and continuation glyphs. */
16743 while (glyph
>= start
16744 && glyph
->type
== CHAR_GLYPH
16745 && INTEGERP (glyph
->object
))
16748 /* If last glyph is a space or stretch, and it's trailing
16749 whitespace, set the face of all trailing whitespace glyphs in
16750 IT->glyph_row to `trailing-whitespace'. */
16752 && BUFFERP (glyph
->object
)
16753 && (glyph
->type
== STRETCH_GLYPH
16754 || (glyph
->type
== CHAR_GLYPH
16755 && glyph
->u
.ch
== ' '))
16756 && trailing_whitespace_p (glyph
->charpos
))
16758 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
16762 while (glyph
>= start
16763 && BUFFERP (glyph
->object
)
16764 && (glyph
->type
== STRETCH_GLYPH
16765 || (glyph
->type
== CHAR_GLYPH
16766 && glyph
->u
.ch
== ' ')))
16767 (glyph
--)->face_id
= face_id
;
16773 /* Value is non-zero if glyph row ROW in window W should be
16774 used to hold the cursor. */
16777 cursor_row_p (w
, row
)
16779 struct glyph_row
*row
;
16781 int cursor_row_p
= 1;
16783 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
16785 /* Suppose the row ends on a string.
16786 Unless the row is continued, that means it ends on a newline
16787 in the string. If it's anything other than a display string
16788 (e.g. a before-string from an overlay), we don't want the
16789 cursor there. (This heuristic seems to give the optimal
16790 behavior for the various types of multi-line strings.) */
16791 if (CHARPOS (row
->end
.string_pos
) >= 0)
16793 if (row
->continued_p
)
16797 /* Check for `display' property. */
16798 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
16799 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
16800 struct glyph
*glyph
;
16803 for (glyph
= end
; glyph
>= beg
; --glyph
)
16804 if (STRINGP (glyph
->object
))
16807 = Fget_char_property (make_number (PT
),
16811 && display_prop_string_p (prop
, glyph
->object
));
16816 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
16818 /* If the row ends in middle of a real character,
16819 and the line is continued, we want the cursor here.
16820 That's because MATRIX_ROW_END_CHARPOS would equal
16821 PT if PT is before the character. */
16822 if (!row
->ends_in_ellipsis_p
)
16823 cursor_row_p
= row
->continued_p
;
16825 /* If the row ends in an ellipsis, then
16826 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
16827 We want that position to be displayed after the ellipsis. */
16830 /* If the row ends at ZV, display the cursor at the end of that
16831 row instead of at the start of the row below. */
16832 else if (row
->ends_at_zv_p
)
16838 return cursor_row_p
;
16843 /* Push the display property PROP so that it will be rendered at the
16844 current position in IT. Return 1 if PROP was successfully pushed,
16848 push_display_prop (struct it
*it
, Lisp_Object prop
)
16852 if (STRINGP (prop
))
16854 if (SCHARS (prop
) == 0)
16861 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
16862 it
->current
.overlay_string_index
= -1;
16863 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
16864 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
16865 it
->method
= GET_FROM_STRING
;
16866 it
->stop_charpos
= 0;
16868 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
16870 it
->method
= GET_FROM_STRETCH
;
16873 #ifdef HAVE_WINDOW_SYSTEM
16874 else if (IMAGEP (prop
))
16876 it
->what
= IT_IMAGE
;
16877 it
->image_id
= lookup_image (it
->f
, prop
);
16878 it
->method
= GET_FROM_IMAGE
;
16880 #endif /* HAVE_WINDOW_SYSTEM */
16883 pop_it (it
); /* bogus display property, give up */
16890 /* Return the character-property PROP at the current position in IT. */
16893 get_it_property (it
, prop
)
16897 Lisp_Object position
;
16899 if (STRINGP (it
->object
))
16900 position
= make_number (IT_STRING_CHARPOS (*it
));
16901 else if (BUFFERP (it
->object
))
16902 position
= make_number (IT_CHARPOS (*it
));
16906 return Fget_char_property (position
, prop
, it
->object
);
16909 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
16912 handle_line_prefix (struct it
*it
)
16914 Lisp_Object prefix
;
16915 if (it
->continuation_lines_width
> 0)
16917 prefix
= get_it_property (it
, Qwrap_prefix
);
16919 prefix
= Vwrap_prefix
;
16923 prefix
= get_it_property (it
, Qline_prefix
);
16925 prefix
= Vline_prefix
;
16927 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
16929 /* If the prefix is wider than the window, and we try to wrap
16930 it, it would acquire its own wrap prefix, and so on till the
16931 iterator stack overflows. So, don't wrap the prefix. */
16932 it
->line_wrap
= TRUNCATE
;
16933 it
->avoid_cursor_p
= 1;
16939 /* Construct the glyph row IT->glyph_row in the desired matrix of
16940 IT->w from text at the current position of IT. See dispextern.h
16941 for an overview of struct it. Value is non-zero if
16942 IT->glyph_row displays text, as opposed to a line displaying ZV
16949 struct glyph_row
*row
= it
->glyph_row
;
16950 Lisp_Object overlay_arrow_string
;
16952 int may_wrap
= 0, wrap_x
;
16953 int wrap_row_used
= -1, wrap_row_ascent
, wrap_row_height
;
16954 int wrap_row_phys_ascent
, wrap_row_phys_height
;
16955 int wrap_row_extra_line_spacing
;
16956 struct display_pos row_end
;
16958 /* We always start displaying at hpos zero even if hscrolled. */
16959 xassert (it
->hpos
== 0 && it
->current_x
== 0);
16961 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
16962 >= it
->w
->desired_matrix
->nrows
)
16964 it
->w
->nrows_scale_factor
++;
16965 fonts_changed_p
= 1;
16969 /* Is IT->w showing the region? */
16970 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
16972 /* Clear the result glyph row and enable it. */
16973 prepare_desired_row (row
);
16975 row
->y
= it
->current_y
;
16976 row
->start
= it
->start
;
16977 row
->continuation_lines_width
= it
->continuation_lines_width
;
16978 row
->displays_text_p
= 1;
16979 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
16980 it
->starts_in_middle_of_char_p
= 0;
16981 /* If the paragraph base direction is R2L, its glyphs should be
16983 if (it
->bidi_p
&& (it
->bidi_it
.level_stack
[0].level
& 1) != 0)
16984 row
->reversed_p
= 1;
16986 /* Arrange the overlays nicely for our purposes. Usually, we call
16987 display_line on only one line at a time, in which case this
16988 can't really hurt too much, or we call it on lines which appear
16989 one after another in the buffer, in which case all calls to
16990 recenter_overlay_lists but the first will be pretty cheap. */
16991 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
16993 /* Move over display elements that are not visible because we are
16994 hscrolled. This may stop at an x-position < IT->first_visible_x
16995 if the first glyph is partially visible or if we hit a line end. */
16996 if (it
->current_x
< it
->first_visible_x
)
16998 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
16999 MOVE_TO_POS
| MOVE_TO_X
);
17003 /* We only do this when not calling `move_it_in_display_line_to'
17004 above, because move_it_in_display_line_to calls
17005 handle_line_prefix itself. */
17006 handle_line_prefix (it
);
17009 /* Get the initial row height. This is either the height of the
17010 text hscrolled, if there is any, or zero. */
17011 row
->ascent
= it
->max_ascent
;
17012 row
->height
= it
->max_ascent
+ it
->max_descent
;
17013 row
->phys_ascent
= it
->max_phys_ascent
;
17014 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17015 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17017 /* Loop generating characters. The loop is left with IT on the next
17018 character to display. */
17021 int n_glyphs_before
, hpos_before
, x_before
;
17023 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
17025 /* Retrieve the next thing to display. Value is zero if end of
17027 if (!get_next_display_element (it
))
17029 /* Maybe add a space at the end of this line that is used to
17030 display the cursor there under X. Set the charpos of the
17031 first glyph of blank lines not corresponding to any text
17033 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17034 row
->exact_window_width_line_p
= 1;
17035 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
17036 || row
->used
[TEXT_AREA
] == 0)
17038 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
17039 row
->displays_text_p
= 0;
17041 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
17042 && (!MINI_WINDOW_P (it
->w
)
17043 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
17044 row
->indicate_empty_line_p
= 1;
17047 it
->continuation_lines_width
= 0;
17048 row
->ends_at_zv_p
= 1;
17049 /* A row that displays right-to-left text must always have
17050 its last face extended all the way to the end of line,
17051 even if this row ends in ZV. */
17052 if (row
->reversed_p
)
17053 extend_face_to_end_of_line (it
);
17054 row_end
= it
->current
;
17058 /* Now, get the metrics of what we want to display. This also
17059 generates glyphs in `row' (which is IT->glyph_row). */
17060 n_glyphs_before
= row
->used
[TEXT_AREA
];
17063 /* Remember the line height so far in case the next element doesn't
17064 fit on the line. */
17065 if (it
->line_wrap
!= TRUNCATE
)
17067 ascent
= it
->max_ascent
;
17068 descent
= it
->max_descent
;
17069 phys_ascent
= it
->max_phys_ascent
;
17070 phys_descent
= it
->max_phys_descent
;
17072 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
17074 if (IT_DISPLAYING_WHITESPACE (it
))
17080 wrap_row_used
= row
->used
[TEXT_AREA
];
17081 wrap_row_ascent
= row
->ascent
;
17082 wrap_row_height
= row
->height
;
17083 wrap_row_phys_ascent
= row
->phys_ascent
;
17084 wrap_row_phys_height
= row
->phys_height
;
17085 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
17091 PRODUCE_GLYPHS (it
);
17093 /* If this display element was in marginal areas, continue with
17095 if (it
->area
!= TEXT_AREA
)
17097 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17098 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17099 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17100 row
->phys_height
= max (row
->phys_height
,
17101 it
->max_phys_ascent
+ it
->max_phys_descent
);
17102 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17103 it
->max_extra_line_spacing
);
17104 set_iterator_to_next (it
, 1);
17108 /* Does the display element fit on the line? If we truncate
17109 lines, we should draw past the right edge of the window. If
17110 we don't truncate, we want to stop so that we can display the
17111 continuation glyph before the right margin. If lines are
17112 continued, there are two possible strategies for characters
17113 resulting in more than 1 glyph (e.g. tabs): Display as many
17114 glyphs as possible in this line and leave the rest for the
17115 continuation line, or display the whole element in the next
17116 line. Original redisplay did the former, so we do it also. */
17117 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
17118 hpos_before
= it
->hpos
;
17121 if (/* Not a newline. */
17123 /* Glyphs produced fit entirely in the line. */
17124 && it
->current_x
< it
->last_visible_x
)
17126 it
->hpos
+= nglyphs
;
17127 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17128 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17129 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17130 row
->phys_height
= max (row
->phys_height
,
17131 it
->max_phys_ascent
+ it
->max_phys_descent
);
17132 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17133 it
->max_extra_line_spacing
);
17134 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
17135 row
->x
= x
- it
->first_visible_x
;
17140 struct glyph
*glyph
;
17142 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
17144 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17145 new_x
= x
+ glyph
->pixel_width
;
17147 if (/* Lines are continued. */
17148 it
->line_wrap
!= TRUNCATE
17149 && (/* Glyph doesn't fit on the line. */
17150 new_x
> it
->last_visible_x
17151 /* Or it fits exactly on a window system frame. */
17152 || (new_x
== it
->last_visible_x
17153 && FRAME_WINDOW_P (it
->f
))))
17155 /* End of a continued line. */
17158 || (new_x
== it
->last_visible_x
17159 && FRAME_WINDOW_P (it
->f
)))
17161 /* Current glyph is the only one on the line or
17162 fits exactly on the line. We must continue
17163 the line because we can't draw the cursor
17164 after the glyph. */
17165 row
->continued_p
= 1;
17166 it
->current_x
= new_x
;
17167 it
->continuation_lines_width
+= new_x
;
17169 if (i
== nglyphs
- 1)
17171 /* If line-wrap is on, check if a previous
17172 wrap point was found. */
17173 if (wrap_row_used
> 0
17174 /* Even if there is a previous wrap
17175 point, continue the line here as
17176 usual, if (i) the previous character
17177 was a space or tab AND (ii) the
17178 current character is not. */
17180 || IT_DISPLAYING_WHITESPACE (it
)))
17183 set_iterator_to_next (it
, 1);
17184 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17186 if (!get_next_display_element (it
))
17188 row
->exact_window_width_line_p
= 1;
17189 it
->continuation_lines_width
= 0;
17190 row
->continued_p
= 0;
17191 row
->ends_at_zv_p
= 1;
17193 else if (ITERATOR_AT_END_OF_LINE_P (it
))
17195 row
->continued_p
= 0;
17196 row
->exact_window_width_line_p
= 1;
17201 else if (CHAR_GLYPH_PADDING_P (*glyph
)
17202 && !FRAME_WINDOW_P (it
->f
))
17204 /* A padding glyph that doesn't fit on this line.
17205 This means the whole character doesn't fit
17207 row
->used
[TEXT_AREA
] = n_glyphs_before
;
17209 /* Fill the rest of the row with continuation
17210 glyphs like in 20.x. */
17211 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
17212 < row
->glyphs
[1 + TEXT_AREA
])
17213 produce_special_glyphs (it
, IT_CONTINUATION
);
17215 row
->continued_p
= 1;
17216 it
->current_x
= x_before
;
17217 it
->continuation_lines_width
+= x_before
;
17219 /* Restore the height to what it was before the
17220 element not fitting on the line. */
17221 it
->max_ascent
= ascent
;
17222 it
->max_descent
= descent
;
17223 it
->max_phys_ascent
= phys_ascent
;
17224 it
->max_phys_descent
= phys_descent
;
17226 else if (wrap_row_used
> 0)
17230 it
->continuation_lines_width
+= wrap_x
;
17231 row
->used
[TEXT_AREA
] = wrap_row_used
;
17232 row
->ascent
= wrap_row_ascent
;
17233 row
->height
= wrap_row_height
;
17234 row
->phys_ascent
= wrap_row_phys_ascent
;
17235 row
->phys_height
= wrap_row_phys_height
;
17236 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
17237 row
->continued_p
= 1;
17238 row
->ends_at_zv_p
= 0;
17239 row
->exact_window_width_line_p
= 0;
17240 it
->continuation_lines_width
+= x
;
17242 /* Make sure that a non-default face is extended
17243 up to the right margin of the window. */
17244 extend_face_to_end_of_line (it
);
17246 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
17248 /* A TAB that extends past the right edge of the
17249 window. This produces a single glyph on
17250 window system frames. We leave the glyph in
17251 this row and let it fill the row, but don't
17252 consume the TAB. */
17253 it
->continuation_lines_width
+= it
->last_visible_x
;
17254 row
->ends_in_middle_of_char_p
= 1;
17255 row
->continued_p
= 1;
17256 glyph
->pixel_width
= it
->last_visible_x
- x
;
17257 it
->starts_in_middle_of_char_p
= 1;
17261 /* Something other than a TAB that draws past
17262 the right edge of the window. Restore
17263 positions to values before the element. */
17264 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17266 /* Display continuation glyphs. */
17267 if (!FRAME_WINDOW_P (it
->f
))
17268 produce_special_glyphs (it
, IT_CONTINUATION
);
17269 row
->continued_p
= 1;
17271 it
->current_x
= x_before
;
17272 it
->continuation_lines_width
+= x
;
17273 extend_face_to_end_of_line (it
);
17275 if (nglyphs
> 1 && i
> 0)
17277 row
->ends_in_middle_of_char_p
= 1;
17278 it
->starts_in_middle_of_char_p
= 1;
17281 /* Restore the height to what it was before the
17282 element not fitting on the line. */
17283 it
->max_ascent
= ascent
;
17284 it
->max_descent
= descent
;
17285 it
->max_phys_ascent
= phys_ascent
;
17286 it
->max_phys_descent
= phys_descent
;
17289 row_end
= it
->current
;
17292 else if (new_x
> it
->first_visible_x
)
17294 /* Increment number of glyphs actually displayed. */
17297 if (x
< it
->first_visible_x
)
17298 /* Glyph is partially visible, i.e. row starts at
17299 negative X position. */
17300 row
->x
= x
- it
->first_visible_x
;
17304 /* Glyph is completely off the left margin of the
17305 window. This should not happen because of the
17306 move_it_in_display_line at the start of this
17307 function, unless the text display area of the
17308 window is empty. */
17309 xassert (it
->first_visible_x
<= it
->last_visible_x
);
17313 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17314 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17315 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17316 row
->phys_height
= max (row
->phys_height
,
17317 it
->max_phys_ascent
+ it
->max_phys_descent
);
17318 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17319 it
->max_extra_line_spacing
);
17321 /* End of this display line if row is continued. */
17322 if (row
->continued_p
|| row
->ends_at_zv_p
)
17324 row_end
= it
->current
;
17330 /* Is this a line end? If yes, we're also done, after making
17331 sure that a non-default face is extended up to the right
17332 margin of the window. */
17333 if (ITERATOR_AT_END_OF_LINE_P (it
))
17335 int used_before
= row
->used
[TEXT_AREA
];
17337 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
17339 /* Add a space at the end of the line that is used to
17340 display the cursor there. */
17341 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17342 append_space_for_newline (it
, 0);
17344 /* Extend the face to the end of the line. */
17345 extend_face_to_end_of_line (it
);
17347 /* Make sure we have the position. */
17348 if (used_before
== 0)
17349 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
17351 /* Consume the line end. This skips over invisible lines. */
17354 /* When we are reordering bidi text, we still need the
17355 next character in logical order, to set row->end
17356 correctly below. */
17359 set_iterator_to_next (it
, 1);
17360 row_end
= it
->current
;
17364 set_iterator_to_next (it
, 1);
17365 it
->continuation_lines_width
= 0;
17367 row_end
= it
->current
;
17371 /* Proceed with next display element. Note that this skips
17372 over lines invisible because of selective display. */
17373 set_iterator_to_next (it
, 1);
17375 /* If we truncate lines, we are done when the last displayed
17376 glyphs reach past the right margin of the window. */
17377 if (it
->line_wrap
== TRUNCATE
17378 && (FRAME_WINDOW_P (it
->f
)
17379 ? (it
->current_x
>= it
->last_visible_x
)
17380 : (it
->current_x
> it
->last_visible_x
)))
17382 /* Maybe add truncation glyphs. */
17383 if (!FRAME_WINDOW_P (it
->f
))
17387 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17388 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17391 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17393 row
->used
[TEXT_AREA
] = i
;
17394 produce_special_glyphs (it
, IT_TRUNCATION
);
17397 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17399 /* Don't truncate if we can overflow newline into fringe. */
17400 if (!get_next_display_element (it
))
17402 it
->continuation_lines_width
= 0;
17403 row
->ends_at_zv_p
= 1;
17404 row
->exact_window_width_line_p
= 1;
17405 row_end
= it
->current
;
17408 if (ITERATOR_AT_END_OF_LINE_P (it
))
17410 row
->exact_window_width_line_p
= 1;
17411 goto at_end_of_line
;
17415 row
->truncated_on_right_p
= 1;
17416 it
->continuation_lines_width
= 0;
17417 reseat_at_next_visible_line_start (it
, 0);
17418 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
17419 it
->hpos
= hpos_before
;
17420 it
->current_x
= x_before
;
17421 row_end
= it
->current
;
17426 /* If line is not empty and hscrolled, maybe insert truncation glyphs
17427 at the left window margin. */
17428 if (it
->first_visible_x
17429 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
17431 if (!FRAME_WINDOW_P (it
->f
))
17432 insert_left_trunc_glyphs (it
);
17433 row
->truncated_on_left_p
= 1;
17436 /* If the start of this line is the overlay arrow-position, then
17437 mark this glyph row as the one containing the overlay arrow.
17438 This is clearly a mess with variable size fonts. It would be
17439 better to let it be displayed like cursors under X. */
17440 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
17441 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
17442 !NILP (overlay_arrow_string
)))
17444 /* Overlay arrow in window redisplay is a fringe bitmap. */
17445 if (STRINGP (overlay_arrow_string
))
17447 struct glyph_row
*arrow_row
17448 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
17449 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
17450 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
17451 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
17452 struct glyph
*p2
, *end
;
17454 /* Copy the arrow glyphs. */
17455 while (glyph
< arrow_end
)
17458 /* Throw away padding glyphs. */
17460 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17461 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
17467 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
17472 xassert (INTEGERP (overlay_arrow_string
));
17473 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
17475 overlay_arrow_seen
= 1;
17478 /* Compute pixel dimensions of this line. */
17479 compute_line_metrics (it
);
17481 /* Remember the position at which this line ends. */
17482 row
->end
= row_end
;
17484 /* Record whether this row ends inside an ellipsis. */
17485 row
->ends_in_ellipsis_p
17486 = (it
->method
== GET_FROM_DISPLAY_VECTOR
17487 && it
->ellipsis_p
);
17489 /* Save fringe bitmaps in this row. */
17490 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
17491 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
17492 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
17493 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
17495 it
->left_user_fringe_bitmap
= 0;
17496 it
->left_user_fringe_face_id
= 0;
17497 it
->right_user_fringe_bitmap
= 0;
17498 it
->right_user_fringe_face_id
= 0;
17500 /* Maybe set the cursor. */
17501 if (it
->w
->cursor
.vpos
< 0
17502 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
17503 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
17504 && cursor_row_p (it
->w
, row
))
17505 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
17507 /* Highlight trailing whitespace. */
17508 if (!NILP (Vshow_trailing_whitespace
))
17509 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
17511 /* Prepare for the next line. This line starts horizontally at (X
17512 HPOS) = (0 0). Vertical positions are incremented. As a
17513 convenience for the caller, IT->glyph_row is set to the next
17515 it
->current_x
= it
->hpos
= 0;
17516 it
->current_y
+= row
->height
;
17519 it
->start
= row_end
;
17520 return row
->displays_text_p
;
17525 /***********************************************************************
17527 ***********************************************************************/
17529 /* Redisplay the menu bar in the frame for window W.
17531 The menu bar of X frames that don't have X toolkit support is
17532 displayed in a special window W->frame->menu_bar_window.
17534 The menu bar of terminal frames is treated specially as far as
17535 glyph matrices are concerned. Menu bar lines are not part of
17536 windows, so the update is done directly on the frame matrix rows
17537 for the menu bar. */
17540 display_menu_bar (w
)
17543 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17548 /* Don't do all this for graphical frames. */
17550 if (FRAME_W32_P (f
))
17553 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
17559 if (FRAME_NS_P (f
))
17561 #endif /* HAVE_NS */
17563 #ifdef USE_X_TOOLKIT
17564 xassert (!FRAME_WINDOW_P (f
));
17565 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
17566 it
.first_visible_x
= 0;
17567 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17568 #else /* not USE_X_TOOLKIT */
17569 if (FRAME_WINDOW_P (f
))
17571 /* Menu bar lines are displayed in the desired matrix of the
17572 dummy window menu_bar_window. */
17573 struct window
*menu_w
;
17574 xassert (WINDOWP (f
->menu_bar_window
));
17575 menu_w
= XWINDOW (f
->menu_bar_window
);
17576 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
17578 it
.first_visible_x
= 0;
17579 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17583 /* This is a TTY frame, i.e. character hpos/vpos are used as
17585 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
17587 it
.first_visible_x
= 0;
17588 it
.last_visible_x
= FRAME_COLS (f
);
17590 #endif /* not USE_X_TOOLKIT */
17592 if (! mode_line_inverse_video
)
17593 /* Force the menu-bar to be displayed in the default face. */
17594 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17596 /* Clear all rows of the menu bar. */
17597 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
17599 struct glyph_row
*row
= it
.glyph_row
+ i
;
17600 clear_glyph_row (row
);
17601 row
->enabled_p
= 1;
17602 row
->full_width_p
= 1;
17605 /* Display all items of the menu bar. */
17606 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
17607 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
17609 Lisp_Object string
;
17611 /* Stop at nil string. */
17612 string
= AREF (items
, i
+ 1);
17616 /* Remember where item was displayed. */
17617 ASET (items
, i
+ 3, make_number (it
.hpos
));
17619 /* Display the item, pad with one space. */
17620 if (it
.current_x
< it
.last_visible_x
)
17621 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
17622 SCHARS (string
) + 1, 0, 0, -1);
17625 /* Fill out the line with spaces. */
17626 if (it
.current_x
< it
.last_visible_x
)
17627 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
17629 /* Compute the total height of the lines. */
17630 compute_line_metrics (&it
);
17635 /***********************************************************************
17637 ***********************************************************************/
17639 /* Redisplay mode lines in the window tree whose root is WINDOW. If
17640 FORCE is non-zero, redisplay mode lines unconditionally.
17641 Otherwise, redisplay only mode lines that are garbaged. Value is
17642 the number of windows whose mode lines were redisplayed. */
17645 redisplay_mode_lines (window
, force
)
17646 Lisp_Object window
;
17651 while (!NILP (window
))
17653 struct window
*w
= XWINDOW (window
);
17655 if (WINDOWP (w
->hchild
))
17656 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
17657 else if (WINDOWP (w
->vchild
))
17658 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
17660 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
17661 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
17663 struct text_pos lpoint
;
17664 struct buffer
*old
= current_buffer
;
17666 /* Set the window's buffer for the mode line display. */
17667 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
17668 set_buffer_internal_1 (XBUFFER (w
->buffer
));
17670 /* Point refers normally to the selected window. For any
17671 other window, set up appropriate value. */
17672 if (!EQ (window
, selected_window
))
17674 struct text_pos pt
;
17676 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
17677 if (CHARPOS (pt
) < BEGV
)
17678 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
17679 else if (CHARPOS (pt
) > (ZV
- 1))
17680 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
17682 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
17685 /* Display mode lines. */
17686 clear_glyph_matrix (w
->desired_matrix
);
17687 if (display_mode_lines (w
))
17690 w
->must_be_updated_p
= 1;
17693 /* Restore old settings. */
17694 set_buffer_internal_1 (old
);
17695 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
17705 /* Display the mode and/or header line of window W. Value is the
17706 sum number of mode lines and header lines displayed. */
17709 display_mode_lines (w
)
17712 Lisp_Object old_selected_window
, old_selected_frame
;
17715 old_selected_frame
= selected_frame
;
17716 selected_frame
= w
->frame
;
17717 old_selected_window
= selected_window
;
17718 XSETWINDOW (selected_window
, w
);
17720 /* These will be set while the mode line specs are processed. */
17721 line_number_displayed
= 0;
17722 w
->column_number_displayed
= Qnil
;
17724 if (WINDOW_WANTS_MODELINE_P (w
))
17726 struct window
*sel_w
= XWINDOW (old_selected_window
);
17728 /* Select mode line face based on the real selected window. */
17729 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
17730 current_buffer
->mode_line_format
);
17734 if (WINDOW_WANTS_HEADER_LINE_P (w
))
17736 display_mode_line (w
, HEADER_LINE_FACE_ID
,
17737 current_buffer
->header_line_format
);
17741 selected_frame
= old_selected_frame
;
17742 selected_window
= old_selected_window
;
17747 /* Display mode or header line of window W. FACE_ID specifies which
17748 line to display; it is either MODE_LINE_FACE_ID or
17749 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
17750 display. Value is the pixel height of the mode/header line
17754 display_mode_line (w
, face_id
, format
)
17756 enum face_id face_id
;
17757 Lisp_Object format
;
17761 int count
= SPECPDL_INDEX ();
17763 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17764 /* Don't extend on a previously drawn mode-line.
17765 This may happen if called from pos_visible_p. */
17766 it
.glyph_row
->enabled_p
= 0;
17767 prepare_desired_row (it
.glyph_row
);
17769 it
.glyph_row
->mode_line_p
= 1;
17771 if (! mode_line_inverse_video
)
17772 /* Force the mode-line to be displayed in the default face. */
17773 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17775 record_unwind_protect (unwind_format_mode_line
,
17776 format_mode_line_unwind_data (NULL
, Qnil
, 0));
17778 mode_line_target
= MODE_LINE_DISPLAY
;
17780 /* Temporarily make frame's keyboard the current kboard so that
17781 kboard-local variables in the mode_line_format will get the right
17783 push_kboard (FRAME_KBOARD (it
.f
));
17784 record_unwind_save_match_data ();
17785 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17788 unbind_to (count
, Qnil
);
17790 /* Fill up with spaces. */
17791 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
17793 compute_line_metrics (&it
);
17794 it
.glyph_row
->full_width_p
= 1;
17795 it
.glyph_row
->continued_p
= 0;
17796 it
.glyph_row
->truncated_on_left_p
= 0;
17797 it
.glyph_row
->truncated_on_right_p
= 0;
17799 /* Make a 3D mode-line have a shadow at its right end. */
17800 face
= FACE_FROM_ID (it
.f
, face_id
);
17801 extend_face_to_end_of_line (&it
);
17802 if (face
->box
!= FACE_NO_BOX
)
17804 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
17805 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
17806 last
->right_box_line_p
= 1;
17809 return it
.glyph_row
->height
;
17812 /* Move element ELT in LIST to the front of LIST.
17813 Return the updated list. */
17816 move_elt_to_front (elt
, list
)
17817 Lisp_Object elt
, list
;
17819 register Lisp_Object tail
, prev
;
17820 register Lisp_Object tem
;
17824 while (CONSP (tail
))
17830 /* Splice out the link TAIL. */
17832 list
= XCDR (tail
);
17834 Fsetcdr (prev
, XCDR (tail
));
17836 /* Now make it the first. */
17837 Fsetcdr (tail
, list
);
17842 tail
= XCDR (tail
);
17846 /* Not found--return unchanged LIST. */
17850 /* Contribute ELT to the mode line for window IT->w. How it
17851 translates into text depends on its data type.
17853 IT describes the display environment in which we display, as usual.
17855 DEPTH is the depth in recursion. It is used to prevent
17856 infinite recursion here.
17858 FIELD_WIDTH is the number of characters the display of ELT should
17859 occupy in the mode line, and PRECISION is the maximum number of
17860 characters to display from ELT's representation. See
17861 display_string for details.
17863 Returns the hpos of the end of the text generated by ELT.
17865 PROPS is a property list to add to any string we encounter.
17867 If RISKY is nonzero, remove (disregard) any properties in any string
17868 we encounter, and ignore :eval and :propertize.
17870 The global variable `mode_line_target' determines whether the
17871 output is passed to `store_mode_line_noprop',
17872 `store_mode_line_string', or `display_string'. */
17875 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
17878 int field_width
, precision
;
17879 Lisp_Object elt
, props
;
17882 int n
= 0, field
, prec
;
17887 elt
= build_string ("*too-deep*");
17891 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
17895 /* A string: output it and check for %-constructs within it. */
17899 if (SCHARS (elt
) > 0
17900 && (!NILP (props
) || risky
))
17902 Lisp_Object oprops
, aelt
;
17903 oprops
= Ftext_properties_at (make_number (0), elt
);
17905 /* If the starting string's properties are not what
17906 we want, translate the string. Also, if the string
17907 is risky, do that anyway. */
17909 if (NILP (Fequal (props
, oprops
)) || risky
)
17911 /* If the starting string has properties,
17912 merge the specified ones onto the existing ones. */
17913 if (! NILP (oprops
) && !risky
)
17917 oprops
= Fcopy_sequence (oprops
);
17919 while (CONSP (tem
))
17921 oprops
= Fplist_put (oprops
, XCAR (tem
),
17922 XCAR (XCDR (tem
)));
17923 tem
= XCDR (XCDR (tem
));
17928 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
17929 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
17931 /* AELT is what we want. Move it to the front
17932 without consing. */
17934 mode_line_proptrans_alist
17935 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
17941 /* If AELT has the wrong props, it is useless.
17942 so get rid of it. */
17944 mode_line_proptrans_alist
17945 = Fdelq (aelt
, mode_line_proptrans_alist
);
17947 elt
= Fcopy_sequence (elt
);
17948 Fset_text_properties (make_number (0), Flength (elt
),
17950 /* Add this item to mode_line_proptrans_alist. */
17951 mode_line_proptrans_alist
17952 = Fcons (Fcons (elt
, props
),
17953 mode_line_proptrans_alist
);
17954 /* Truncate mode_line_proptrans_alist
17955 to at most 50 elements. */
17956 tem
= Fnthcdr (make_number (50),
17957 mode_line_proptrans_alist
);
17959 XSETCDR (tem
, Qnil
);
17968 prec
= precision
- n
;
17969 switch (mode_line_target
)
17971 case MODE_LINE_NOPROP
:
17972 case MODE_LINE_TITLE
:
17973 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
17975 case MODE_LINE_STRING
:
17976 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
17978 case MODE_LINE_DISPLAY
:
17979 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
17980 0, prec
, 0, STRING_MULTIBYTE (elt
));
17987 /* Handle the non-literal case. */
17989 while ((precision
<= 0 || n
< precision
)
17990 && SREF (elt
, offset
) != 0
17991 && (mode_line_target
!= MODE_LINE_DISPLAY
17992 || it
->current_x
< it
->last_visible_x
))
17994 int last_offset
= offset
;
17996 /* Advance to end of string or next format specifier. */
17997 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
18000 if (offset
- 1 != last_offset
)
18002 int nchars
, nbytes
;
18004 /* Output to end of string or up to '%'. Field width
18005 is length of string. Don't output more than
18006 PRECISION allows us. */
18009 prec
= c_string_width (SDATA (elt
) + last_offset
,
18010 offset
- last_offset
, precision
- n
,
18013 switch (mode_line_target
)
18015 case MODE_LINE_NOPROP
:
18016 case MODE_LINE_TITLE
:
18017 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
18019 case MODE_LINE_STRING
:
18021 int bytepos
= last_offset
;
18022 int charpos
= string_byte_to_char (elt
, bytepos
);
18023 int endpos
= (precision
<= 0
18024 ? string_byte_to_char (elt
, offset
)
18025 : charpos
+ nchars
);
18027 n
+= store_mode_line_string (NULL
,
18028 Fsubstring (elt
, make_number (charpos
),
18029 make_number (endpos
)),
18033 case MODE_LINE_DISPLAY
:
18035 int bytepos
= last_offset
;
18036 int charpos
= string_byte_to_char (elt
, bytepos
);
18038 if (precision
<= 0)
18039 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
18040 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
18042 STRING_MULTIBYTE (elt
));
18047 else /* c == '%' */
18049 int percent_position
= offset
;
18051 /* Get the specified minimum width. Zero means
18054 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
18055 field
= field
* 10 + c
- '0';
18057 /* Don't pad beyond the total padding allowed. */
18058 if (field_width
- n
> 0 && field
> field_width
- n
)
18059 field
= field_width
- n
;
18061 /* Note that either PRECISION <= 0 or N < PRECISION. */
18062 prec
= precision
- n
;
18065 n
+= display_mode_element (it
, depth
, field
, prec
,
18066 Vglobal_mode_string
, props
,
18071 int bytepos
, charpos
;
18072 unsigned char *spec
;
18074 bytepos
= percent_position
;
18075 charpos
= (STRING_MULTIBYTE (elt
)
18076 ? string_byte_to_char (elt
, bytepos
)
18079 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
18081 switch (mode_line_target
)
18083 case MODE_LINE_NOPROP
:
18084 case MODE_LINE_TITLE
:
18085 n
+= store_mode_line_noprop (spec
, field
, prec
);
18087 case MODE_LINE_STRING
:
18089 int len
= strlen (spec
);
18090 Lisp_Object tem
= make_string (spec
, len
);
18091 props
= Ftext_properties_at (make_number (charpos
), elt
);
18092 /* Should only keep face property in props */
18093 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
18096 case MODE_LINE_DISPLAY
:
18098 int nglyphs_before
, nwritten
;
18100 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18101 nwritten
= display_string (spec
, Qnil
, elt
,
18106 /* Assign to the glyphs written above the
18107 string where the `%x' came from, position
18111 struct glyph
*glyph
18112 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
18116 for (i
= 0; i
< nwritten
; ++i
)
18118 glyph
[i
].object
= elt
;
18119 glyph
[i
].charpos
= charpos
;
18136 /* A symbol: process the value of the symbol recursively
18137 as if it appeared here directly. Avoid error if symbol void.
18138 Special case: if value of symbol is a string, output the string
18141 register Lisp_Object tem
;
18143 /* If the variable is not marked as risky to set
18144 then its contents are risky to use. */
18145 if (NILP (Fget (elt
, Qrisky_local_variable
)))
18148 tem
= Fboundp (elt
);
18151 tem
= Fsymbol_value (elt
);
18152 /* If value is a string, output that string literally:
18153 don't check for % within it. */
18157 if (!EQ (tem
, elt
))
18159 /* Give up right away for nil or t. */
18169 register Lisp_Object car
, tem
;
18171 /* A cons cell: five distinct cases.
18172 If first element is :eval or :propertize, do something special.
18173 If first element is a string or a cons, process all the elements
18174 and effectively concatenate them.
18175 If first element is a negative number, truncate displaying cdr to
18176 at most that many characters. If positive, pad (with spaces)
18177 to at least that many characters.
18178 If first element is a symbol, process the cadr or caddr recursively
18179 according to whether the symbol's value is non-nil or nil. */
18181 if (EQ (car
, QCeval
))
18183 /* An element of the form (:eval FORM) means evaluate FORM
18184 and use the result as mode line elements. */
18189 if (CONSP (XCDR (elt
)))
18192 spec
= safe_eval (XCAR (XCDR (elt
)));
18193 n
+= display_mode_element (it
, depth
, field_width
- n
,
18194 precision
- n
, spec
, props
,
18198 else if (EQ (car
, QCpropertize
))
18200 /* An element of the form (:propertize ELT PROPS...)
18201 means display ELT but applying properties PROPS. */
18206 if (CONSP (XCDR (elt
)))
18207 n
+= display_mode_element (it
, depth
, field_width
- n
,
18208 precision
- n
, XCAR (XCDR (elt
)),
18209 XCDR (XCDR (elt
)), risky
);
18211 else if (SYMBOLP (car
))
18213 tem
= Fboundp (car
);
18217 /* elt is now the cdr, and we know it is a cons cell.
18218 Use its car if CAR has a non-nil value. */
18221 tem
= Fsymbol_value (car
);
18228 /* Symbol's value is nil (or symbol is unbound)
18229 Get the cddr of the original list
18230 and if possible find the caddr and use that. */
18234 else if (!CONSP (elt
))
18239 else if (INTEGERP (car
))
18241 register int lim
= XINT (car
);
18245 /* Negative int means reduce maximum width. */
18246 if (precision
<= 0)
18249 precision
= min (precision
, -lim
);
18253 /* Padding specified. Don't let it be more than
18254 current maximum. */
18256 lim
= min (precision
, lim
);
18258 /* If that's more padding than already wanted, queue it.
18259 But don't reduce padding already specified even if
18260 that is beyond the current truncation point. */
18261 field_width
= max (lim
, field_width
);
18265 else if (STRINGP (car
) || CONSP (car
))
18267 Lisp_Object halftail
= elt
;
18271 && (precision
<= 0 || n
< precision
))
18273 n
+= display_mode_element (it
, depth
,
18274 /* Do padding only after the last
18275 element in the list. */
18276 (! CONSP (XCDR (elt
))
18279 precision
- n
, XCAR (elt
),
18283 if ((len
& 1) == 0)
18284 halftail
= XCDR (halftail
);
18285 /* Check for cycle. */
18286 if (EQ (halftail
, elt
))
18295 elt
= build_string ("*invalid*");
18299 /* Pad to FIELD_WIDTH. */
18300 if (field_width
> 0 && n
< field_width
)
18302 switch (mode_line_target
)
18304 case MODE_LINE_NOPROP
:
18305 case MODE_LINE_TITLE
:
18306 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
18308 case MODE_LINE_STRING
:
18309 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
18311 case MODE_LINE_DISPLAY
:
18312 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
18321 /* Store a mode-line string element in mode_line_string_list.
18323 If STRING is non-null, display that C string. Otherwise, the Lisp
18324 string LISP_STRING is displayed.
18326 FIELD_WIDTH is the minimum number of output glyphs to produce.
18327 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18328 with spaces. FIELD_WIDTH <= 0 means don't pad.
18330 PRECISION is the maximum number of characters to output from
18331 STRING. PRECISION <= 0 means don't truncate the string.
18333 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
18334 properties to the string.
18336 PROPS are the properties to add to the string.
18337 The mode_line_string_face face property is always added to the string.
18341 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
18343 Lisp_Object lisp_string
;
18352 if (string
!= NULL
)
18354 len
= strlen (string
);
18355 if (precision
> 0 && len
> precision
)
18357 lisp_string
= make_string (string
, len
);
18359 props
= mode_line_string_face_prop
;
18360 else if (!NILP (mode_line_string_face
))
18362 Lisp_Object face
= Fplist_get (props
, Qface
);
18363 props
= Fcopy_sequence (props
);
18365 face
= mode_line_string_face
;
18367 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
18368 props
= Fplist_put (props
, Qface
, face
);
18370 Fadd_text_properties (make_number (0), make_number (len
),
18371 props
, lisp_string
);
18375 len
= XFASTINT (Flength (lisp_string
));
18376 if (precision
> 0 && len
> precision
)
18379 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
18382 if (!NILP (mode_line_string_face
))
18386 props
= Ftext_properties_at (make_number (0), lisp_string
);
18387 face
= Fplist_get (props
, Qface
);
18389 face
= mode_line_string_face
;
18391 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
18392 props
= Fcons (Qface
, Fcons (face
, Qnil
));
18394 lisp_string
= Fcopy_sequence (lisp_string
);
18397 Fadd_text_properties (make_number (0), make_number (len
),
18398 props
, lisp_string
);
18403 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
18407 if (field_width
> len
)
18409 field_width
-= len
;
18410 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
18412 Fadd_text_properties (make_number (0), make_number (field_width
),
18413 props
, lisp_string
);
18414 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
18422 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
18424 doc
: /* Format a string out of a mode line format specification.
18425 First arg FORMAT specifies the mode line format (see `mode-line-format'
18426 for details) to use.
18428 Optional second arg FACE specifies the face property to put
18429 on all characters for which no face is specified.
18430 The value t means whatever face the window's mode line currently uses
18431 \(either `mode-line' or `mode-line-inactive', depending).
18432 A value of nil means the default is no face property.
18433 If FACE is an integer, the value string has no text properties.
18435 Optional third and fourth args WINDOW and BUFFER specify the window
18436 and buffer to use as the context for the formatting (defaults
18437 are the selected window and the window's buffer). */)
18438 (format
, face
, window
, buffer
)
18439 Lisp_Object format
, face
, window
, buffer
;
18444 struct buffer
*old_buffer
= NULL
;
18446 int no_props
= INTEGERP (face
);
18447 int count
= SPECPDL_INDEX ();
18449 int string_start
= 0;
18452 window
= selected_window
;
18453 CHECK_WINDOW (window
);
18454 w
= XWINDOW (window
);
18457 buffer
= w
->buffer
;
18458 CHECK_BUFFER (buffer
);
18460 /* Make formatting the modeline a non-op when noninteractive, otherwise
18461 there will be problems later caused by a partially initialized frame. */
18462 if (NILP (format
) || noninteractive
)
18463 return empty_unibyte_string
;
18471 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
18472 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
18476 face_id
= DEFAULT_FACE_ID
;
18478 if (XBUFFER (buffer
) != current_buffer
)
18479 old_buffer
= current_buffer
;
18481 /* Save things including mode_line_proptrans_alist,
18482 and set that to nil so that we don't alter the outer value. */
18483 record_unwind_protect (unwind_format_mode_line
,
18484 format_mode_line_unwind_data
18485 (old_buffer
, selected_window
, 1));
18486 mode_line_proptrans_alist
= Qnil
;
18488 Fselect_window (window
, Qt
);
18490 set_buffer_internal_1 (XBUFFER (buffer
));
18492 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18496 mode_line_target
= MODE_LINE_NOPROP
;
18497 mode_line_string_face_prop
= Qnil
;
18498 mode_line_string_list
= Qnil
;
18499 string_start
= MODE_LINE_NOPROP_LEN (0);
18503 mode_line_target
= MODE_LINE_STRING
;
18504 mode_line_string_list
= Qnil
;
18505 mode_line_string_face
= face
;
18506 mode_line_string_face_prop
18507 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
18510 push_kboard (FRAME_KBOARD (it
.f
));
18511 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18516 len
= MODE_LINE_NOPROP_LEN (string_start
);
18517 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
18521 mode_line_string_list
= Fnreverse (mode_line_string_list
);
18522 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
18523 empty_unibyte_string
);
18526 unbind_to (count
, Qnil
);
18530 /* Write a null-terminated, right justified decimal representation of
18531 the positive integer D to BUF using a minimal field width WIDTH. */
18534 pint2str (buf
, width
, d
)
18535 register char *buf
;
18536 register int width
;
18539 register char *p
= buf
;
18547 *p
++ = d
% 10 + '0';
18552 for (width
-= (int) (p
- buf
); width
> 0; --width
)
18563 /* Write a null-terminated, right justified decimal and "human
18564 readable" representation of the nonnegative integer D to BUF using
18565 a minimal field width WIDTH. D should be smaller than 999.5e24. */
18567 static const char power_letter
[] =
18581 pint2hrstr (buf
, width
, d
)
18586 /* We aim to represent the nonnegative integer D as
18587 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
18590 /* -1 means: do not use TENTHS. */
18594 /* Length of QUOTIENT.TENTHS as a string. */
18600 if (1000 <= quotient
)
18602 /* Scale to the appropriate EXPONENT. */
18605 remainder
= quotient
% 1000;
18609 while (1000 <= quotient
);
18611 /* Round to nearest and decide whether to use TENTHS or not. */
18614 tenths
= remainder
/ 100;
18615 if (50 <= remainder
% 100)
18622 if (quotient
== 10)
18630 if (500 <= remainder
)
18632 if (quotient
< 999)
18643 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
18644 if (tenths
== -1 && quotient
<= 99)
18651 p
= psuffix
= buf
+ max (width
, length
);
18653 /* Print EXPONENT. */
18655 *psuffix
++ = power_letter
[exponent
];
18658 /* Print TENTHS. */
18661 *--p
= '0' + tenths
;
18665 /* Print QUOTIENT. */
18668 int digit
= quotient
% 10;
18669 *--p
= '0' + digit
;
18671 while ((quotient
/= 10) != 0);
18673 /* Print leading spaces. */
18678 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
18679 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
18680 type of CODING_SYSTEM. Return updated pointer into BUF. */
18682 static unsigned char invalid_eol_type
[] = "(*invalid*)";
18685 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
18686 Lisp_Object coding_system
;
18687 register char *buf
;
18691 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
18692 const unsigned char *eol_str
;
18694 /* The EOL conversion we are using. */
18695 Lisp_Object eoltype
;
18697 val
= CODING_SYSTEM_SPEC (coding_system
);
18700 if (!VECTORP (val
)) /* Not yet decided. */
18705 eoltype
= eol_mnemonic_undecided
;
18706 /* Don't mention EOL conversion if it isn't decided. */
18711 Lisp_Object eolvalue
;
18713 attrs
= AREF (val
, 0);
18714 eolvalue
= AREF (val
, 2);
18717 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
18721 /* The EOL conversion that is normal on this system. */
18723 if (NILP (eolvalue
)) /* Not yet decided. */
18724 eoltype
= eol_mnemonic_undecided
;
18725 else if (VECTORP (eolvalue
)) /* Not yet decided. */
18726 eoltype
= eol_mnemonic_undecided
;
18727 else /* eolvalue is Qunix, Qdos, or Qmac. */
18728 eoltype
= (EQ (eolvalue
, Qunix
)
18729 ? eol_mnemonic_unix
18730 : (EQ (eolvalue
, Qdos
) == 1
18731 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
18737 /* Mention the EOL conversion if it is not the usual one. */
18738 if (STRINGP (eoltype
))
18740 eol_str
= SDATA (eoltype
);
18741 eol_str_len
= SBYTES (eoltype
);
18743 else if (CHARACTERP (eoltype
))
18745 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
18746 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
18751 eol_str
= invalid_eol_type
;
18752 eol_str_len
= sizeof (invalid_eol_type
) - 1;
18754 bcopy (eol_str
, buf
, eol_str_len
);
18755 buf
+= eol_str_len
;
18761 /* Return a string for the output of a mode line %-spec for window W,
18762 generated by character C. PRECISION >= 0 means don't return a
18763 string longer than that value. FIELD_WIDTH > 0 means pad the
18764 string returned with spaces to that value. Return 1 in *MULTIBYTE
18765 if the result is multibyte text.
18767 Note we operate on the current buffer for most purposes,
18768 the exception being w->base_line_pos. */
18770 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
18773 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
18776 int field_width
, precision
;
18780 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18781 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
18782 struct buffer
*b
= current_buffer
;
18790 if (!NILP (b
->read_only
))
18792 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18797 /* This differs from %* only for a modified read-only buffer. */
18798 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18800 if (!NILP (b
->read_only
))
18805 /* This differs from %* in ignoring read-only-ness. */
18806 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18818 if (command_loop_level
> 5)
18820 p
= decode_mode_spec_buf
;
18821 for (i
= 0; i
< command_loop_level
; i
++)
18824 return decode_mode_spec_buf
;
18832 if (command_loop_level
> 5)
18834 p
= decode_mode_spec_buf
;
18835 for (i
= 0; i
< command_loop_level
; i
++)
18838 return decode_mode_spec_buf
;
18845 /* Let lots_of_dashes be a string of infinite length. */
18846 if (mode_line_target
== MODE_LINE_NOPROP
||
18847 mode_line_target
== MODE_LINE_STRING
)
18849 if (field_width
<= 0
18850 || field_width
> sizeof (lots_of_dashes
))
18852 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
18853 decode_mode_spec_buf
[i
] = '-';
18854 decode_mode_spec_buf
[i
] = '\0';
18855 return decode_mode_spec_buf
;
18858 return lots_of_dashes
;
18866 /* %c and %l are ignored in `frame-title-format'.
18867 (In redisplay_internal, the frame title is drawn _before_ the
18868 windows are updated, so the stuff which depends on actual
18869 window contents (such as %l) may fail to render properly, or
18870 even crash emacs.) */
18871 if (mode_line_target
== MODE_LINE_TITLE
)
18875 int col
= (int) current_column (); /* iftc */
18876 w
->column_number_displayed
= make_number (col
);
18877 pint2str (decode_mode_spec_buf
, field_width
, col
);
18878 return decode_mode_spec_buf
;
18882 #ifndef SYSTEM_MALLOC
18884 if (NILP (Vmemory_full
))
18887 return "!MEM FULL! ";
18894 /* %F displays the frame name. */
18895 if (!NILP (f
->title
))
18896 return (char *) SDATA (f
->title
);
18897 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
18898 return (char *) SDATA (f
->name
);
18907 int size
= ZV
- BEGV
;
18908 pint2str (decode_mode_spec_buf
, field_width
, size
);
18909 return decode_mode_spec_buf
;
18914 int size
= ZV
- BEGV
;
18915 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
18916 return decode_mode_spec_buf
;
18921 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
18922 int topline
, nlines
, junk
, height
;
18924 /* %c and %l are ignored in `frame-title-format'. */
18925 if (mode_line_target
== MODE_LINE_TITLE
)
18928 startpos
= XMARKER (w
->start
)->charpos
;
18929 startpos_byte
= marker_byte_position (w
->start
);
18930 height
= WINDOW_TOTAL_LINES (w
);
18932 /* If we decided that this buffer isn't suitable for line numbers,
18933 don't forget that too fast. */
18934 if (EQ (w
->base_line_pos
, w
->buffer
))
18936 /* But do forget it, if the window shows a different buffer now. */
18937 else if (BUFFERP (w
->base_line_pos
))
18938 w
->base_line_pos
= Qnil
;
18940 /* If the buffer is very big, don't waste time. */
18941 if (INTEGERP (Vline_number_display_limit
)
18942 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
18944 w
->base_line_pos
= Qnil
;
18945 w
->base_line_number
= Qnil
;
18949 if (INTEGERP (w
->base_line_number
)
18950 && INTEGERP (w
->base_line_pos
)
18951 && XFASTINT (w
->base_line_pos
) <= startpos
)
18953 line
= XFASTINT (w
->base_line_number
);
18954 linepos
= XFASTINT (w
->base_line_pos
);
18955 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
18960 linepos
= BUF_BEGV (b
);
18961 linepos_byte
= BUF_BEGV_BYTE (b
);
18964 /* Count lines from base line to window start position. */
18965 nlines
= display_count_lines (linepos
, linepos_byte
,
18969 topline
= nlines
+ line
;
18971 /* Determine a new base line, if the old one is too close
18972 or too far away, or if we did not have one.
18973 "Too close" means it's plausible a scroll-down would
18974 go back past it. */
18975 if (startpos
== BUF_BEGV (b
))
18977 w
->base_line_number
= make_number (topline
);
18978 w
->base_line_pos
= make_number (BUF_BEGV (b
));
18980 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
18981 || linepos
== BUF_BEGV (b
))
18983 int limit
= BUF_BEGV (b
);
18984 int limit_byte
= BUF_BEGV_BYTE (b
);
18986 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
18988 if (startpos
- distance
> limit
)
18990 limit
= startpos
- distance
;
18991 limit_byte
= CHAR_TO_BYTE (limit
);
18994 nlines
= display_count_lines (startpos
, startpos_byte
,
18996 - (height
* 2 + 30),
18998 /* If we couldn't find the lines we wanted within
18999 line_number_display_limit_width chars per line,
19000 give up on line numbers for this window. */
19001 if (position
== limit_byte
&& limit
== startpos
- distance
)
19003 w
->base_line_pos
= w
->buffer
;
19004 w
->base_line_number
= Qnil
;
19008 w
->base_line_number
= make_number (topline
- nlines
);
19009 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
19012 /* Now count lines from the start pos to point. */
19013 nlines
= display_count_lines (startpos
, startpos_byte
,
19014 PT_BYTE
, PT
, &junk
);
19016 /* Record that we did display the line number. */
19017 line_number_displayed
= 1;
19019 /* Make the string to show. */
19020 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
19021 return decode_mode_spec_buf
;
19024 char* p
= decode_mode_spec_buf
;
19025 int pad
= field_width
- 2;
19031 return decode_mode_spec_buf
;
19037 obj
= b
->mode_name
;
19041 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
19047 int pos
= marker_position (w
->start
);
19048 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
19050 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
19052 if (pos
<= BUF_BEGV (b
))
19057 else if (pos
<= BUF_BEGV (b
))
19061 if (total
> 1000000)
19062 /* Do it differently for a large value, to avoid overflow. */
19063 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19065 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19066 /* We can't normally display a 3-digit number,
19067 so get us a 2-digit number that is close. */
19070 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
19071 return decode_mode_spec_buf
;
19075 /* Display percentage of size above the bottom of the screen. */
19078 int toppos
= marker_position (w
->start
);
19079 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
19080 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
19082 if (botpos
>= BUF_ZV (b
))
19084 if (toppos
<= BUF_BEGV (b
))
19091 if (total
> 1000000)
19092 /* Do it differently for a large value, to avoid overflow. */
19093 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19095 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19096 /* We can't normally display a 3-digit number,
19097 so get us a 2-digit number that is close. */
19100 if (toppos
<= BUF_BEGV (b
))
19101 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
19103 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
19104 return decode_mode_spec_buf
;
19109 /* status of process */
19110 obj
= Fget_buffer_process (Fcurrent_buffer ());
19112 return "no process";
19113 #ifdef subprocesses
19114 obj
= Fsymbol_name (Fprocess_status (obj
));
19120 int count
= inhibit_garbage_collection ();
19121 Lisp_Object val
= call1 (intern ("file-remote-p"),
19122 current_buffer
->directory
);
19123 unbind_to (count
, Qnil
);
19131 case 't': /* indicate TEXT or BINARY */
19132 #ifdef MODE_LINE_BINARY_TEXT
19133 return MODE_LINE_BINARY_TEXT (b
);
19139 /* coding-system (not including end-of-line format) */
19141 /* coding-system (including end-of-line type) */
19143 int eol_flag
= (c
== 'Z');
19144 char *p
= decode_mode_spec_buf
;
19146 if (! FRAME_WINDOW_P (f
))
19148 /* No need to mention EOL here--the terminal never needs
19149 to do EOL conversion. */
19150 p
= decode_mode_spec_coding (CODING_ID_NAME
19151 (FRAME_KEYBOARD_CODING (f
)->id
),
19153 p
= decode_mode_spec_coding (CODING_ID_NAME
19154 (FRAME_TERMINAL_CODING (f
)->id
),
19157 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
19160 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
19161 #ifdef subprocesses
19162 obj
= Fget_buffer_process (Fcurrent_buffer ());
19163 if (PROCESSP (obj
))
19165 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
19167 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
19170 #endif /* subprocesses */
19173 return decode_mode_spec_buf
;
19179 *multibyte
= STRING_MULTIBYTE (obj
);
19180 return (char *) SDATA (obj
);
19187 /* Count up to COUNT lines starting from START / START_BYTE.
19188 But don't go beyond LIMIT_BYTE.
19189 Return the number of lines thus found (always nonnegative).
19191 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
19194 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
19195 int start
, start_byte
, limit_byte
, count
;
19198 register unsigned char *cursor
;
19199 unsigned char *base
;
19201 register int ceiling
;
19202 register unsigned char *ceiling_addr
;
19203 int orig_count
= count
;
19205 /* If we are not in selective display mode,
19206 check only for newlines. */
19207 int selective_display
= (!NILP (current_buffer
->selective_display
)
19208 && !INTEGERP (current_buffer
->selective_display
));
19212 while (start_byte
< limit_byte
)
19214 ceiling
= BUFFER_CEILING_OF (start_byte
);
19215 ceiling
= min (limit_byte
- 1, ceiling
);
19216 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
19217 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
19220 if (selective_display
)
19221 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
19224 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
19227 if (cursor
!= ceiling_addr
)
19231 start_byte
+= cursor
- base
+ 1;
19232 *byte_pos_ptr
= start_byte
;
19236 if (++cursor
== ceiling_addr
)
19242 start_byte
+= cursor
- base
;
19247 while (start_byte
> limit_byte
)
19249 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
19250 ceiling
= max (limit_byte
, ceiling
);
19251 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
19252 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
19255 if (selective_display
)
19256 while (--cursor
!= ceiling_addr
19257 && *cursor
!= '\n' && *cursor
!= 015)
19260 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
19263 if (cursor
!= ceiling_addr
)
19267 start_byte
+= cursor
- base
+ 1;
19268 *byte_pos_ptr
= start_byte
;
19269 /* When scanning backwards, we should
19270 not count the newline posterior to which we stop. */
19271 return - orig_count
- 1;
19277 /* Here we add 1 to compensate for the last decrement
19278 of CURSOR, which took it past the valid range. */
19279 start_byte
+= cursor
- base
+ 1;
19283 *byte_pos_ptr
= limit_byte
;
19286 return - orig_count
+ count
;
19287 return orig_count
- count
;
19293 /***********************************************************************
19295 ***********************************************************************/
19297 /* Display a NUL-terminated string, starting with index START.
19299 If STRING is non-null, display that C string. Otherwise, the Lisp
19300 string LISP_STRING is displayed.
19302 If FACE_STRING is not nil, FACE_STRING_POS is a position in
19303 FACE_STRING. Display STRING or LISP_STRING with the face at
19304 FACE_STRING_POS in FACE_STRING:
19306 Display the string in the environment given by IT, but use the
19307 standard display table, temporarily.
19309 FIELD_WIDTH is the minimum number of output glyphs to produce.
19310 If STRING has fewer characters than FIELD_WIDTH, pad to the right
19311 with spaces. If STRING has more characters, more than FIELD_WIDTH
19312 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
19314 PRECISION is the maximum number of characters to output from
19315 STRING. PRECISION < 0 means don't truncate the string.
19317 This is roughly equivalent to printf format specifiers:
19319 FIELD_WIDTH PRECISION PRINTF
19320 ----------------------------------------
19326 MULTIBYTE zero means do not display multibyte chars, > 0 means do
19327 display them, and < 0 means obey the current buffer's value of
19328 enable_multibyte_characters.
19330 Value is the number of columns displayed. */
19333 display_string (string
, lisp_string
, face_string
, face_string_pos
,
19334 start
, it
, field_width
, precision
, max_x
, multibyte
)
19335 unsigned char *string
;
19336 Lisp_Object lisp_string
;
19337 Lisp_Object face_string
;
19338 EMACS_INT face_string_pos
;
19341 int field_width
, precision
, max_x
;
19344 int hpos_at_start
= it
->hpos
;
19345 int saved_face_id
= it
->face_id
;
19346 struct glyph_row
*row
= it
->glyph_row
;
19348 /* Initialize the iterator IT for iteration over STRING beginning
19349 with index START. */
19350 reseat_to_string (it
, string
, lisp_string
, start
,
19351 precision
, field_width
, multibyte
);
19353 /* If displaying STRING, set up the face of the iterator
19354 from LISP_STRING, if that's given. */
19355 if (STRINGP (face_string
))
19361 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
19362 0, it
->region_beg_charpos
,
19363 it
->region_end_charpos
,
19364 &endptr
, it
->base_face_id
, 0);
19365 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19366 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
19369 /* Set max_x to the maximum allowed X position. Don't let it go
19370 beyond the right edge of the window. */
19372 max_x
= it
->last_visible_x
;
19374 max_x
= min (max_x
, it
->last_visible_x
);
19376 /* Skip over display elements that are not visible. because IT->w is
19378 if (it
->current_x
< it
->first_visible_x
)
19379 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
19380 MOVE_TO_POS
| MOVE_TO_X
);
19382 row
->ascent
= it
->max_ascent
;
19383 row
->height
= it
->max_ascent
+ it
->max_descent
;
19384 row
->phys_ascent
= it
->max_phys_ascent
;
19385 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19386 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19388 /* This condition is for the case that we are called with current_x
19389 past last_visible_x. */
19390 while (it
->current_x
< max_x
)
19392 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
19394 /* Get the next display element. */
19395 if (!get_next_display_element (it
))
19398 /* Produce glyphs. */
19399 x_before
= it
->current_x
;
19400 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
19401 PRODUCE_GLYPHS (it
);
19403 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
19406 while (i
< nglyphs
)
19408 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19410 if (it
->line_wrap
!= TRUNCATE
19411 && x
+ glyph
->pixel_width
> max_x
)
19413 /* End of continued line or max_x reached. */
19414 if (CHAR_GLYPH_PADDING_P (*glyph
))
19416 /* A wide character is unbreakable. */
19417 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
19418 it
->current_x
= x_before
;
19422 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19427 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
19429 /* Glyph is at least partially visible. */
19431 if (x
< it
->first_visible_x
)
19432 it
->glyph_row
->x
= x
- it
->first_visible_x
;
19436 /* Glyph is off the left margin of the display area.
19437 Should not happen. */
19441 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19442 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19443 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19444 row
->phys_height
= max (row
->phys_height
,
19445 it
->max_phys_ascent
+ it
->max_phys_descent
);
19446 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19447 it
->max_extra_line_spacing
);
19448 x
+= glyph
->pixel_width
;
19452 /* Stop if max_x reached. */
19456 /* Stop at line ends. */
19457 if (ITERATOR_AT_END_OF_LINE_P (it
))
19459 it
->continuation_lines_width
= 0;
19463 set_iterator_to_next (it
, 1);
19465 /* Stop if truncating at the right edge. */
19466 if (it
->line_wrap
== TRUNCATE
19467 && it
->current_x
>= it
->last_visible_x
)
19469 /* Add truncation mark, but don't do it if the line is
19470 truncated at a padding space. */
19471 if (IT_CHARPOS (*it
) < it
->string_nchars
)
19473 if (!FRAME_WINDOW_P (it
->f
))
19477 if (it
->current_x
> it
->last_visible_x
)
19479 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19480 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19482 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19484 row
->used
[TEXT_AREA
] = i
;
19485 produce_special_glyphs (it
, IT_TRUNCATION
);
19488 produce_special_glyphs (it
, IT_TRUNCATION
);
19490 it
->glyph_row
->truncated_on_right_p
= 1;
19496 /* Maybe insert a truncation at the left. */
19497 if (it
->first_visible_x
19498 && IT_CHARPOS (*it
) > 0)
19500 if (!FRAME_WINDOW_P (it
->f
))
19501 insert_left_trunc_glyphs (it
);
19502 it
->glyph_row
->truncated_on_left_p
= 1;
19505 it
->face_id
= saved_face_id
;
19507 /* Value is number of columns displayed. */
19508 return it
->hpos
- hpos_at_start
;
19513 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
19514 appears as an element of LIST or as the car of an element of LIST.
19515 If PROPVAL is a list, compare each element against LIST in that
19516 way, and return 1/2 if any element of PROPVAL is found in LIST.
19517 Otherwise return 0. This function cannot quit.
19518 The return value is 2 if the text is invisible but with an ellipsis
19519 and 1 if it's invisible and without an ellipsis. */
19522 invisible_p (propval
, list
)
19523 register Lisp_Object propval
;
19526 register Lisp_Object tail
, proptail
;
19528 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19530 register Lisp_Object tem
;
19532 if (EQ (propval
, tem
))
19534 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
19535 return NILP (XCDR (tem
)) ? 1 : 2;
19538 if (CONSP (propval
))
19540 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
19542 Lisp_Object propelt
;
19543 propelt
= XCAR (proptail
);
19544 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19546 register Lisp_Object tem
;
19548 if (EQ (propelt
, tem
))
19550 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
19551 return NILP (XCDR (tem
)) ? 1 : 2;
19559 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
19560 doc
: /* Non-nil if the property makes the text invisible.
19561 POS-OR-PROP can be a marker or number, in which case it is taken to be
19562 a position in the current buffer and the value of the `invisible' property
19563 is checked; or it can be some other value, which is then presumed to be the
19564 value of the `invisible' property of the text of interest.
19565 The non-nil value returned can be t for truly invisible text or something
19566 else if the text is replaced by an ellipsis. */)
19568 Lisp_Object pos_or_prop
;
19571 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
19572 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
19574 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
19575 return (invis
== 0 ? Qnil
19577 : make_number (invis
));
19580 /* Calculate a width or height in pixels from a specification using
19581 the following elements:
19584 NUM - a (fractional) multiple of the default font width/height
19585 (NUM) - specifies exactly NUM pixels
19586 UNIT - a fixed number of pixels, see below.
19587 ELEMENT - size of a display element in pixels, see below.
19588 (NUM . SPEC) - equals NUM * SPEC
19589 (+ SPEC SPEC ...) - add pixel values
19590 (- SPEC SPEC ...) - subtract pixel values
19591 (- SPEC) - negate pixel value
19594 INT or FLOAT - a number constant
19595 SYMBOL - use symbol's (buffer local) variable binding.
19598 in - pixels per inch *)
19599 mm - pixels per 1/1000 meter *)
19600 cm - pixels per 1/100 meter *)
19601 width - width of current font in pixels.
19602 height - height of current font in pixels.
19604 *) using the ratio(s) defined in display-pixels-per-inch.
19608 left-fringe - left fringe width in pixels
19609 right-fringe - right fringe width in pixels
19611 left-margin - left margin width in pixels
19612 right-margin - right margin width in pixels
19614 scroll-bar - scroll-bar area width in pixels
19618 Pixels corresponding to 5 inches:
19621 Total width of non-text areas on left side of window (if scroll-bar is on left):
19622 '(space :width (+ left-fringe left-margin scroll-bar))
19624 Align to first text column (in header line):
19625 '(space :align-to 0)
19627 Align to middle of text area minus half the width of variable `my-image'
19628 containing a loaded image:
19629 '(space :align-to (0.5 . (- text my-image)))
19631 Width of left margin minus width of 1 character in the default font:
19632 '(space :width (- left-margin 1))
19634 Width of left margin minus width of 2 characters in the current font:
19635 '(space :width (- left-margin (2 . width)))
19637 Center 1 character over left-margin (in header line):
19638 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
19640 Different ways to express width of left fringe plus left margin minus one pixel:
19641 '(space :width (- (+ left-fringe left-margin) (1)))
19642 '(space :width (+ left-fringe left-margin (- (1))))
19643 '(space :width (+ left-fringe left-margin (-1)))
19647 #define NUMVAL(X) \
19648 ((INTEGERP (X) || FLOATP (X)) \
19653 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
19658 int width_p
, *align_to
;
19662 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
19663 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
19666 return OK_PIXELS (0);
19668 xassert (FRAME_LIVE_P (it
->f
));
19670 if (SYMBOLP (prop
))
19672 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
19674 char *unit
= SDATA (SYMBOL_NAME (prop
));
19676 if (unit
[0] == 'i' && unit
[1] == 'n')
19678 else if (unit
[0] == 'm' && unit
[1] == 'm')
19680 else if (unit
[0] == 'c' && unit
[1] == 'm')
19687 #ifdef HAVE_WINDOW_SYSTEM
19688 if (FRAME_WINDOW_P (it
->f
)
19690 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
19691 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
19693 return OK_PIXELS (ppi
/ pixels
);
19696 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
19697 || (CONSP (Vdisplay_pixels_per_inch
)
19699 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
19700 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
19702 return OK_PIXELS (ppi
/ pixels
);
19708 #ifdef HAVE_WINDOW_SYSTEM
19709 if (EQ (prop
, Qheight
))
19710 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
19711 if (EQ (prop
, Qwidth
))
19712 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
19714 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
19715 return OK_PIXELS (1);
19718 if (EQ (prop
, Qtext
))
19719 return OK_PIXELS (width_p
19720 ? window_box_width (it
->w
, TEXT_AREA
)
19721 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
19723 if (align_to
&& *align_to
< 0)
19726 if (EQ (prop
, Qleft
))
19727 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
19728 if (EQ (prop
, Qright
))
19729 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
19730 if (EQ (prop
, Qcenter
))
19731 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
19732 + window_box_width (it
->w
, TEXT_AREA
) / 2);
19733 if (EQ (prop
, Qleft_fringe
))
19734 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19735 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
19736 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
19737 if (EQ (prop
, Qright_fringe
))
19738 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19739 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19740 : window_box_right_offset (it
->w
, TEXT_AREA
));
19741 if (EQ (prop
, Qleft_margin
))
19742 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
19743 if (EQ (prop
, Qright_margin
))
19744 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
19745 if (EQ (prop
, Qscroll_bar
))
19746 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
19748 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19749 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19750 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19755 if (EQ (prop
, Qleft_fringe
))
19756 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
19757 if (EQ (prop
, Qright_fringe
))
19758 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
19759 if (EQ (prop
, Qleft_margin
))
19760 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
19761 if (EQ (prop
, Qright_margin
))
19762 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
19763 if (EQ (prop
, Qscroll_bar
))
19764 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
19767 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
19770 if (INTEGERP (prop
) || FLOATP (prop
))
19772 int base_unit
= (width_p
19773 ? FRAME_COLUMN_WIDTH (it
->f
)
19774 : FRAME_LINE_HEIGHT (it
->f
));
19775 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
19780 Lisp_Object car
= XCAR (prop
);
19781 Lisp_Object cdr
= XCDR (prop
);
19785 #ifdef HAVE_WINDOW_SYSTEM
19786 if (FRAME_WINDOW_P (it
->f
)
19787 && valid_image_p (prop
))
19789 int id
= lookup_image (it
->f
, prop
);
19790 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
19792 return OK_PIXELS (width_p
? img
->width
: img
->height
);
19795 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
19801 while (CONSP (cdr
))
19803 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
19804 font
, width_p
, align_to
))
19807 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
19812 if (EQ (car
, Qminus
))
19814 return OK_PIXELS (pixels
);
19817 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
19820 if (INTEGERP (car
) || FLOATP (car
))
19823 pixels
= XFLOATINT (car
);
19825 return OK_PIXELS (pixels
);
19826 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
19827 font
, width_p
, align_to
))
19828 return OK_PIXELS (pixels
* fact
);
19839 /***********************************************************************
19841 ***********************************************************************/
19843 #ifdef HAVE_WINDOW_SYSTEM
19848 dump_glyph_string (s
)
19849 struct glyph_string
*s
;
19851 fprintf (stderr
, "glyph string\n");
19852 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
19853 s
->x
, s
->y
, s
->width
, s
->height
);
19854 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
19855 fprintf (stderr
, " hl = %d\n", s
->hl
);
19856 fprintf (stderr
, " left overhang = %d, right = %d\n",
19857 s
->left_overhang
, s
->right_overhang
);
19858 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
19859 fprintf (stderr
, " extends to end of line = %d\n",
19860 s
->extends_to_end_of_line_p
);
19861 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
19862 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
19865 #endif /* GLYPH_DEBUG */
19867 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
19868 of XChar2b structures for S; it can't be allocated in
19869 init_glyph_string because it must be allocated via `alloca'. W
19870 is the window on which S is drawn. ROW and AREA are the glyph row
19871 and area within the row from which S is constructed. START is the
19872 index of the first glyph structure covered by S. HL is a
19873 face-override for drawing S. */
19876 #define OPTIONAL_HDC(hdc) hdc,
19877 #define DECLARE_HDC(hdc) HDC hdc;
19878 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
19879 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
19882 #ifndef OPTIONAL_HDC
19883 #define OPTIONAL_HDC(hdc)
19884 #define DECLARE_HDC(hdc)
19885 #define ALLOCATE_HDC(hdc, f)
19886 #define RELEASE_HDC(hdc, f)
19890 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
19891 struct glyph_string
*s
;
19895 struct glyph_row
*row
;
19896 enum glyph_row_area area
;
19898 enum draw_glyphs_face hl
;
19900 bzero (s
, sizeof *s
);
19902 s
->f
= XFRAME (w
->frame
);
19906 s
->display
= FRAME_X_DISPLAY (s
->f
);
19907 s
->window
= FRAME_X_WINDOW (s
->f
);
19908 s
->char2b
= char2b
;
19912 s
->first_glyph
= row
->glyphs
[area
] + start
;
19913 s
->height
= row
->height
;
19914 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
19916 /* Display the internal border below the tool-bar window. */
19917 if (WINDOWP (s
->f
->tool_bar_window
)
19918 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
19919 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
19921 s
->ybase
= s
->y
+ row
->ascent
;
19925 /* Append the list of glyph strings with head H and tail T to the list
19926 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
19929 append_glyph_string_lists (head
, tail
, h
, t
)
19930 struct glyph_string
**head
, **tail
;
19931 struct glyph_string
*h
, *t
;
19945 /* Prepend the list of glyph strings with head H and tail T to the
19946 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
19950 prepend_glyph_string_lists (head
, tail
, h
, t
)
19951 struct glyph_string
**head
, **tail
;
19952 struct glyph_string
*h
, *t
;
19966 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
19967 Set *HEAD and *TAIL to the resulting list. */
19970 append_glyph_string (head
, tail
, s
)
19971 struct glyph_string
**head
, **tail
;
19972 struct glyph_string
*s
;
19974 s
->next
= s
->prev
= NULL
;
19975 append_glyph_string_lists (head
, tail
, s
, s
);
19979 /* Get face and two-byte form of character C in face FACE_ID on frame
19980 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19981 means we want to display multibyte text. DISPLAY_P non-zero means
19982 make sure that X resources for the face returned are allocated.
19983 Value is a pointer to a realized face that is ready for display if
19984 DISPLAY_P is non-zero. */
19986 static INLINE
struct face
*
19987 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
19991 int multibyte_p
, display_p
;
19993 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19997 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
19999 if (code
!= FONT_INVALID_CODE
)
20000 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20002 STORE_XCHAR2B (char2b
, 0, 0);
20005 /* Make sure X resources of the face are allocated. */
20006 #ifdef HAVE_X_WINDOWS
20010 xassert (face
!= NULL
);
20011 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20018 /* Get face and two-byte form of character glyph GLYPH on frame F.
20019 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
20020 a pointer to a realized face that is ready for display. */
20022 static INLINE
struct face
*
20023 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
20025 struct glyph
*glyph
;
20031 xassert (glyph
->type
== CHAR_GLYPH
);
20032 face
= FACE_FROM_ID (f
, glyph
->face_id
);
20039 unsigned code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
20041 if (code
!= FONT_INVALID_CODE
)
20042 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20044 STORE_XCHAR2B (char2b
, 0, 0);
20047 /* Make sure X resources of the face are allocated. */
20048 xassert (face
!= NULL
);
20049 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20054 /* Fill glyph string S with composition components specified by S->cmp.
20056 BASE_FACE is the base face of the composition.
20057 S->cmp_from is the index of the first component for S.
20059 OVERLAPS non-zero means S should draw the foreground only, and use
20060 its physical height for clipping. See also draw_glyphs.
20062 Value is the index of a component not in S. */
20065 fill_composite_glyph_string (s
, base_face
, overlaps
)
20066 struct glyph_string
*s
;
20067 struct face
*base_face
;
20071 /* For all glyphs of this composition, starting at the offset
20072 S->cmp_from, until we reach the end of the definition or encounter a
20073 glyph that requires the different face, add it to S. */
20078 s
->for_overlaps
= overlaps
;
20081 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
20083 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
20087 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
20090 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
20091 s
->char2b
+ i
, 1, 1);
20097 s
->font
= s
->face
->font
;
20099 else if (s
->face
!= face
)
20107 /* All glyph strings for the same composition has the same width,
20108 i.e. the width set for the first component of the composition. */
20109 s
->width
= s
->first_glyph
->pixel_width
;
20111 /* If the specified font could not be loaded, use the frame's
20112 default font, but record the fact that we couldn't load it in
20113 the glyph string so that we can draw rectangles for the
20114 characters of the glyph string. */
20115 if (s
->font
== NULL
)
20117 s
->font_not_found_p
= 1;
20118 s
->font
= FRAME_FONT (s
->f
);
20121 /* Adjust base line for subscript/superscript text. */
20122 s
->ybase
+= s
->first_glyph
->voffset
;
20124 /* This glyph string must always be drawn with 16-bit functions. */
20131 fill_gstring_glyph_string (s
, face_id
, start
, end
, overlaps
)
20132 struct glyph_string
*s
;
20134 int start
, end
, overlaps
;
20136 struct glyph
*glyph
, *last
;
20137 Lisp_Object lgstring
;
20140 s
->for_overlaps
= overlaps
;
20141 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20142 last
= s
->row
->glyphs
[s
->area
] + end
;
20143 s
->cmp_id
= glyph
->u
.cmp
.id
;
20144 s
->cmp_from
= glyph
->u
.cmp
.from
;
20145 s
->cmp_to
= glyph
->u
.cmp
.to
+ 1;
20146 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20147 lgstring
= composition_gstring_from_id (s
->cmp_id
);
20148 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
20150 while (glyph
< last
20151 && glyph
->u
.cmp
.automatic
20152 && glyph
->u
.cmp
.id
== s
->cmp_id
20153 && s
->cmp_to
== glyph
->u
.cmp
.from
)
20154 s
->cmp_to
= (glyph
++)->u
.cmp
.to
+ 1;
20156 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
20158 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
20159 unsigned code
= LGLYPH_CODE (lglyph
);
20161 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
20163 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
20164 return glyph
- s
->row
->glyphs
[s
->area
];
20168 /* Fill glyph string S from a sequence of character glyphs.
20170 FACE_ID is the face id of the string. START is the index of the
20171 first glyph to consider, END is the index of the last + 1.
20172 OVERLAPS non-zero means S should draw the foreground only, and use
20173 its physical height for clipping. See also draw_glyphs.
20175 Value is the index of the first glyph not in S. */
20178 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
20179 struct glyph_string
*s
;
20181 int start
, end
, overlaps
;
20183 struct glyph
*glyph
, *last
;
20185 int glyph_not_available_p
;
20187 xassert (s
->f
== XFRAME (s
->w
->frame
));
20188 xassert (s
->nchars
== 0);
20189 xassert (start
>= 0 && end
> start
);
20191 s
->for_overlaps
= overlaps
;
20192 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20193 last
= s
->row
->glyphs
[s
->area
] + end
;
20194 voffset
= glyph
->voffset
;
20195 s
->padding_p
= glyph
->padding_p
;
20196 glyph_not_available_p
= glyph
->glyph_not_available_p
;
20198 while (glyph
< last
20199 && glyph
->type
== CHAR_GLYPH
20200 && glyph
->voffset
== voffset
20201 /* Same face id implies same font, nowadays. */
20202 && glyph
->face_id
== face_id
20203 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
20207 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
20208 s
->char2b
+ s
->nchars
,
20210 s
->two_byte_p
= two_byte_p
;
20212 xassert (s
->nchars
<= end
- start
);
20213 s
->width
+= glyph
->pixel_width
;
20214 if (glyph
++->padding_p
!= s
->padding_p
)
20218 s
->font
= s
->face
->font
;
20220 /* If the specified font could not be loaded, use the frame's font,
20221 but record the fact that we couldn't load it in
20222 S->font_not_found_p so that we can draw rectangles for the
20223 characters of the glyph string. */
20224 if (s
->font
== NULL
|| glyph_not_available_p
)
20226 s
->font_not_found_p
= 1;
20227 s
->font
= FRAME_FONT (s
->f
);
20230 /* Adjust base line for subscript/superscript text. */
20231 s
->ybase
+= voffset
;
20233 xassert (s
->face
&& s
->face
->gc
);
20234 return glyph
- s
->row
->glyphs
[s
->area
];
20238 /* Fill glyph string S from image glyph S->first_glyph. */
20241 fill_image_glyph_string (s
)
20242 struct glyph_string
*s
;
20244 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
20245 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
20247 s
->slice
= s
->first_glyph
->slice
;
20248 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
20249 s
->font
= s
->face
->font
;
20250 s
->width
= s
->first_glyph
->pixel_width
;
20252 /* Adjust base line for subscript/superscript text. */
20253 s
->ybase
+= s
->first_glyph
->voffset
;
20257 /* Fill glyph string S from a sequence of stretch glyphs.
20259 ROW is the glyph row in which the glyphs are found, AREA is the
20260 area within the row. START is the index of the first glyph to
20261 consider, END is the index of the last + 1.
20263 Value is the index of the first glyph not in S. */
20266 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
20267 struct glyph_string
*s
;
20268 struct glyph_row
*row
;
20269 enum glyph_row_area area
;
20272 struct glyph
*glyph
, *last
;
20273 int voffset
, face_id
;
20275 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
20277 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20278 last
= s
->row
->glyphs
[s
->area
] + end
;
20279 face_id
= glyph
->face_id
;
20280 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20281 s
->font
= s
->face
->font
;
20282 s
->width
= glyph
->pixel_width
;
20284 voffset
= glyph
->voffset
;
20288 && glyph
->type
== STRETCH_GLYPH
20289 && glyph
->voffset
== voffset
20290 && glyph
->face_id
== face_id
);
20292 s
->width
+= glyph
->pixel_width
;
20294 /* Adjust base line for subscript/superscript text. */
20295 s
->ybase
+= voffset
;
20297 /* The case that face->gc == 0 is handled when drawing the glyph
20298 string by calling PREPARE_FACE_FOR_DISPLAY. */
20300 return glyph
- s
->row
->glyphs
[s
->area
];
20303 static struct font_metrics
*
20304 get_per_char_metric (f
, font
, char2b
)
20309 static struct font_metrics metrics
;
20310 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
20312 if (! font
|| code
== FONT_INVALID_CODE
)
20314 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
20319 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
20320 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
20321 assumed to be zero. */
20324 x_get_glyph_overhangs (glyph
, f
, left
, right
)
20325 struct glyph
*glyph
;
20329 *left
= *right
= 0;
20331 if (glyph
->type
== CHAR_GLYPH
)
20335 struct font_metrics
*pcm
;
20337 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
20338 if (face
->font
&& (pcm
= get_per_char_metric (f
, face
->font
, &char2b
)))
20340 if (pcm
->rbearing
> pcm
->width
)
20341 *right
= pcm
->rbearing
- pcm
->width
;
20342 if (pcm
->lbearing
< 0)
20343 *left
= -pcm
->lbearing
;
20346 else if (glyph
->type
== COMPOSITE_GLYPH
)
20348 if (! glyph
->u
.cmp
.automatic
)
20350 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
20352 if (cmp
->rbearing
> cmp
->pixel_width
)
20353 *right
= cmp
->rbearing
- cmp
->pixel_width
;
20354 if (cmp
->lbearing
< 0)
20355 *left
= - cmp
->lbearing
;
20359 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
20360 struct font_metrics metrics
;
20362 composition_gstring_width (gstring
, glyph
->u
.cmp
.from
,
20363 glyph
->u
.cmp
.to
+ 1, &metrics
);
20364 if (metrics
.rbearing
> metrics
.width
)
20365 *right
= metrics
.rbearing
- metrics
.width
;
20366 if (metrics
.lbearing
< 0)
20367 *left
= - metrics
.lbearing
;
20373 /* Return the index of the first glyph preceding glyph string S that
20374 is overwritten by S because of S's left overhang. Value is -1
20375 if no glyphs are overwritten. */
20378 left_overwritten (s
)
20379 struct glyph_string
*s
;
20383 if (s
->left_overhang
)
20386 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20387 int first
= s
->first_glyph
- glyphs
;
20389 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
20390 x
-= glyphs
[i
].pixel_width
;
20401 /* Return the index of the first glyph preceding glyph string S that
20402 is overwriting S because of its right overhang. Value is -1 if no
20403 glyph in front of S overwrites S. */
20406 left_overwriting (s
)
20407 struct glyph_string
*s
;
20410 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20411 int first
= s
->first_glyph
- glyphs
;
20415 for (i
= first
- 1; i
>= 0; --i
)
20418 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
20421 x
-= glyphs
[i
].pixel_width
;
20428 /* Return the index of the last glyph following glyph string S that is
20429 overwritten by S because of S's right overhang. Value is -1 if
20430 no such glyph is found. */
20433 right_overwritten (s
)
20434 struct glyph_string
*s
;
20438 if (s
->right_overhang
)
20441 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20442 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
20443 int end
= s
->row
->used
[s
->area
];
20445 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
20446 x
+= glyphs
[i
].pixel_width
;
20455 /* Return the index of the last glyph following glyph string S that
20456 overwrites S because of its left overhang. Value is negative
20457 if no such glyph is found. */
20460 right_overwriting (s
)
20461 struct glyph_string
*s
;
20464 int end
= s
->row
->used
[s
->area
];
20465 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20466 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
20470 for (i
= first
; i
< end
; ++i
)
20473 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
20476 x
+= glyphs
[i
].pixel_width
;
20483 /* Set background width of glyph string S. START is the index of the
20484 first glyph following S. LAST_X is the right-most x-position + 1
20485 in the drawing area. */
20488 set_glyph_string_background_width (s
, start
, last_x
)
20489 struct glyph_string
*s
;
20493 /* If the face of this glyph string has to be drawn to the end of
20494 the drawing area, set S->extends_to_end_of_line_p. */
20496 if (start
== s
->row
->used
[s
->area
]
20497 && s
->area
== TEXT_AREA
20498 && ((s
->row
->fill_line_p
20499 && (s
->hl
== DRAW_NORMAL_TEXT
20500 || s
->hl
== DRAW_IMAGE_RAISED
20501 || s
->hl
== DRAW_IMAGE_SUNKEN
))
20502 || s
->hl
== DRAW_MOUSE_FACE
))
20503 s
->extends_to_end_of_line_p
= 1;
20505 /* If S extends its face to the end of the line, set its
20506 background_width to the distance to the right edge of the drawing
20508 if (s
->extends_to_end_of_line_p
)
20509 s
->background_width
= last_x
- s
->x
+ 1;
20511 s
->background_width
= s
->width
;
20515 /* Compute overhangs and x-positions for glyph string S and its
20516 predecessors, or successors. X is the starting x-position for S.
20517 BACKWARD_P non-zero means process predecessors. */
20520 compute_overhangs_and_x (s
, x
, backward_p
)
20521 struct glyph_string
*s
;
20529 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20530 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20540 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20541 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20551 /* The following macros are only called from draw_glyphs below.
20552 They reference the following parameters of that function directly:
20553 `w', `row', `area', and `overlap_p'
20554 as well as the following local variables:
20555 `s', `f', and `hdc' (in W32) */
20558 /* On W32, silently add local `hdc' variable to argument list of
20559 init_glyph_string. */
20560 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20561 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
20563 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20564 init_glyph_string (s, char2b, w, row, area, start, hl)
20567 /* Add a glyph string for a stretch glyph to the list of strings
20568 between HEAD and TAIL. START is the index of the stretch glyph in
20569 row area AREA of glyph row ROW. END is the index of the last glyph
20570 in that glyph row area. X is the current output position assigned
20571 to the new glyph string constructed. HL overrides that face of the
20572 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20573 is the right-most x-position of the drawing area. */
20575 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
20576 and below -- keep them on one line. */
20577 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20580 s = (struct glyph_string *) alloca (sizeof *s); \
20581 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20582 START = fill_stretch_glyph_string (s, row, area, START, END); \
20583 append_glyph_string (&HEAD, &TAIL, s); \
20589 /* Add a glyph string for an image glyph to the list of strings
20590 between HEAD and TAIL. START is the index of the image glyph in
20591 row area AREA of glyph row ROW. END is the index of the last glyph
20592 in that glyph row area. X is the current output position assigned
20593 to the new glyph string constructed. HL overrides that face of the
20594 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20595 is the right-most x-position of the drawing area. */
20597 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20600 s = (struct glyph_string *) alloca (sizeof *s); \
20601 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20602 fill_image_glyph_string (s); \
20603 append_glyph_string (&HEAD, &TAIL, s); \
20610 /* Add a glyph string for a sequence of character glyphs to the list
20611 of strings between HEAD and TAIL. START is the index of the first
20612 glyph in row area AREA of glyph row ROW that is part of the new
20613 glyph string. END is the index of the last glyph in that glyph row
20614 area. X is the current output position assigned to the new glyph
20615 string constructed. HL overrides that face of the glyph; e.g. it
20616 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
20617 right-most x-position of the drawing area. */
20619 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20625 face_id = (row)->glyphs[area][START].face_id; \
20627 s = (struct glyph_string *) alloca (sizeof *s); \
20628 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
20629 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20630 append_glyph_string (&HEAD, &TAIL, s); \
20632 START = fill_glyph_string (s, face_id, START, END, overlaps); \
20637 /* Add a glyph string for a composite sequence to the list of strings
20638 between HEAD and TAIL. START is the index of the first glyph in
20639 row area AREA of glyph row ROW that is part of the new glyph
20640 string. END is the index of the last glyph in that glyph row area.
20641 X is the current output position assigned to the new glyph string
20642 constructed. HL overrides that face of the glyph; e.g. it is
20643 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
20644 x-position of the drawing area. */
20646 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20648 int face_id = (row)->glyphs[area][START].face_id; \
20649 struct face *base_face = FACE_FROM_ID (f, face_id); \
20650 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
20651 struct composition *cmp = composition_table[cmp_id]; \
20653 struct glyph_string *first_s; \
20656 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
20658 /* Make glyph_strings for each glyph sequence that is drawable by \
20659 the same face, and append them to HEAD/TAIL. */ \
20660 for (n = 0; n < cmp->glyph_len;) \
20662 s = (struct glyph_string *) alloca (sizeof *s); \
20663 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20664 append_glyph_string (&(HEAD), &(TAIL), s); \
20670 n = fill_composite_glyph_string (s, base_face, overlaps); \
20678 /* Add a glyph string for a glyph-string sequence to the list of strings
20679 between HEAD and TAIL. */
20681 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20685 Lisp_Object gstring; \
20687 face_id = (row)->glyphs[area][START].face_id; \
20688 gstring = (composition_gstring_from_id \
20689 ((row)->glyphs[area][START].u.cmp.id)); \
20690 s = (struct glyph_string *) alloca (sizeof *s); \
20691 char2b = (XChar2b *) alloca ((sizeof *char2b) \
20692 * LGSTRING_GLYPH_LEN (gstring)); \
20693 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20694 append_glyph_string (&(HEAD), &(TAIL), s); \
20696 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
20700 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
20701 of AREA of glyph row ROW on window W between indices START and END.
20702 HL overrides the face for drawing glyph strings, e.g. it is
20703 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
20704 x-positions of the drawing area.
20706 This is an ugly monster macro construct because we must use alloca
20707 to allocate glyph strings (because draw_glyphs can be called
20708 asynchronously). */
20710 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20713 HEAD = TAIL = NULL; \
20714 while (START < END) \
20716 struct glyph *first_glyph = (row)->glyphs[area] + START; \
20717 switch (first_glyph->type) \
20720 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
20724 case COMPOSITE_GLYPH: \
20725 if (first_glyph->u.cmp.automatic) \
20726 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
20729 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
20733 case STRETCH_GLYPH: \
20734 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
20738 case IMAGE_GLYPH: \
20739 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
20749 set_glyph_string_background_width (s, START, LAST_X); \
20756 /* Draw glyphs between START and END in AREA of ROW on window W,
20757 starting at x-position X. X is relative to AREA in W. HL is a
20758 face-override with the following meaning:
20760 DRAW_NORMAL_TEXT draw normally
20761 DRAW_CURSOR draw in cursor face
20762 DRAW_MOUSE_FACE draw in mouse face.
20763 DRAW_INVERSE_VIDEO draw in mode line face
20764 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
20765 DRAW_IMAGE_RAISED draw an image with a raised relief around it
20767 If OVERLAPS is non-zero, draw only the foreground of characters and
20768 clip to the physical height of ROW. Non-zero value also defines
20769 the overlapping part to be drawn:
20771 OVERLAPS_PRED overlap with preceding rows
20772 OVERLAPS_SUCC overlap with succeeding rows
20773 OVERLAPS_BOTH overlap with both preceding/succeeding rows
20774 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
20776 Value is the x-position reached, relative to AREA of W. */
20779 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
20782 struct glyph_row
*row
;
20783 enum glyph_row_area area
;
20784 EMACS_INT start
, end
;
20785 enum draw_glyphs_face hl
;
20788 struct glyph_string
*head
, *tail
;
20789 struct glyph_string
*s
;
20790 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
20791 int i
, j
, x_reached
, last_x
, area_left
= 0;
20792 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20795 ALLOCATE_HDC (hdc
, f
);
20797 /* Let's rather be paranoid than getting a SEGV. */
20798 end
= min (end
, row
->used
[area
]);
20799 start
= max (0, start
);
20800 start
= min (end
, start
);
20802 /* Translate X to frame coordinates. Set last_x to the right
20803 end of the drawing area. */
20804 if (row
->full_width_p
)
20806 /* X is relative to the left edge of W, without scroll bars
20808 area_left
= WINDOW_LEFT_EDGE_X (w
);
20809 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
20813 area_left
= window_box_left (w
, area
);
20814 last_x
= area_left
+ window_box_width (w
, area
);
20818 /* Build a doubly-linked list of glyph_string structures between
20819 head and tail from what we have to draw. Note that the macro
20820 BUILD_GLYPH_STRINGS will modify its start parameter. That's
20821 the reason we use a separate variable `i'. */
20823 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
20825 x_reached
= tail
->x
+ tail
->background_width
;
20829 /* If there are any glyphs with lbearing < 0 or rbearing > width in
20830 the row, redraw some glyphs in front or following the glyph
20831 strings built above. */
20832 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
20834 struct glyph_string
*h
, *t
;
20835 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20836 int mouse_beg_col
, mouse_end_col
, check_mouse_face
= 0;
20839 /* If mouse highlighting is on, we may need to draw adjacent
20840 glyphs using mouse-face highlighting. */
20841 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
20843 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
20845 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20846 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20848 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
20850 check_mouse_face
= 1;
20851 mouse_beg_col
= (row
== mouse_beg_row
)
20852 ? dpyinfo
->mouse_face_beg_col
: 0;
20853 mouse_end_col
= (row
== mouse_end_row
)
20854 ? dpyinfo
->mouse_face_end_col
20855 : row
->used
[TEXT_AREA
];
20859 /* Compute overhangs for all glyph strings. */
20860 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
20861 for (s
= head
; s
; s
= s
->next
)
20862 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
20864 /* Prepend glyph strings for glyphs in front of the first glyph
20865 string that are overwritten because of the first glyph
20866 string's left overhang. The background of all strings
20867 prepended must be drawn because the first glyph string
20869 i
= left_overwritten (head
);
20872 enum draw_glyphs_face overlap_hl
;
20874 /* If this row contains mouse highlighting, attempt to draw
20875 the overlapped glyphs with the correct highlight. This
20876 code fails if the overlap encompasses more than one glyph
20877 and mouse-highlight spans only some of these glyphs.
20878 However, making it work perfectly involves a lot more
20879 code, and I don't know if the pathological case occurs in
20880 practice, so we'll stick to this for now. --- cyd */
20881 if (check_mouse_face
20882 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20883 overlap_hl
= DRAW_MOUSE_FACE
;
20885 overlap_hl
= DRAW_NORMAL_TEXT
;
20888 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
20889 overlap_hl
, dummy_x
, last_x
);
20890 compute_overhangs_and_x (t
, head
->x
, 1);
20891 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20895 /* Prepend glyph strings for glyphs in front of the first glyph
20896 string that overwrite that glyph string because of their
20897 right overhang. For these strings, only the foreground must
20898 be drawn, because it draws over the glyph string at `head'.
20899 The background must not be drawn because this would overwrite
20900 right overhangs of preceding glyphs for which no glyph
20902 i
= left_overwriting (head
);
20905 enum draw_glyphs_face overlap_hl
;
20907 if (check_mouse_face
20908 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20909 overlap_hl
= DRAW_MOUSE_FACE
;
20911 overlap_hl
= DRAW_NORMAL_TEXT
;
20914 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
20915 overlap_hl
, dummy_x
, last_x
);
20916 for (s
= h
; s
; s
= s
->next
)
20917 s
->background_filled_p
= 1;
20918 compute_overhangs_and_x (t
, head
->x
, 1);
20919 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20922 /* Append glyphs strings for glyphs following the last glyph
20923 string tail that are overwritten by tail. The background of
20924 these strings has to be drawn because tail's foreground draws
20926 i
= right_overwritten (tail
);
20929 enum draw_glyphs_face overlap_hl
;
20931 if (check_mouse_face
20932 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20933 overlap_hl
= DRAW_MOUSE_FACE
;
20935 overlap_hl
= DRAW_NORMAL_TEXT
;
20937 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20938 overlap_hl
, x
, last_x
);
20939 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20940 append_glyph_string_lists (&head
, &tail
, h
, t
);
20944 /* Append glyph strings for glyphs following the last glyph
20945 string tail that overwrite tail. The foreground of such
20946 glyphs has to be drawn because it writes into the background
20947 of tail. The background must not be drawn because it could
20948 paint over the foreground of following glyphs. */
20949 i
= right_overwriting (tail
);
20952 enum draw_glyphs_face overlap_hl
;
20953 if (check_mouse_face
20954 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20955 overlap_hl
= DRAW_MOUSE_FACE
;
20957 overlap_hl
= DRAW_NORMAL_TEXT
;
20960 i
++; /* We must include the Ith glyph. */
20961 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20962 overlap_hl
, x
, last_x
);
20963 for (s
= h
; s
; s
= s
->next
)
20964 s
->background_filled_p
= 1;
20965 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20966 append_glyph_string_lists (&head
, &tail
, h
, t
);
20968 if (clip_head
|| clip_tail
)
20969 for (s
= head
; s
; s
= s
->next
)
20971 s
->clip_head
= clip_head
;
20972 s
->clip_tail
= clip_tail
;
20976 /* Draw all strings. */
20977 for (s
= head
; s
; s
= s
->next
)
20978 FRAME_RIF (f
)->draw_glyph_string (s
);
20981 /* When focus a sole frame and move horizontally, this sets on_p to 0
20982 causing a failure to erase prev cursor position. */
20983 if (area
== TEXT_AREA
20984 && !row
->full_width_p
20985 /* When drawing overlapping rows, only the glyph strings'
20986 foreground is drawn, which doesn't erase a cursor
20990 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
20991 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
20992 : (tail
? tail
->x
+ tail
->background_width
: x
));
20996 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
20997 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
21001 /* Value is the x-position up to which drawn, relative to AREA of W.
21002 This doesn't include parts drawn because of overhangs. */
21003 if (row
->full_width_p
)
21004 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
21006 x_reached
-= area_left
;
21008 RELEASE_HDC (hdc
, f
);
21013 /* Expand row matrix if too narrow. Don't expand if area
21016 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
21018 if (!fonts_changed_p \
21019 && (it->glyph_row->glyphs[area] \
21020 < it->glyph_row->glyphs[area + 1])) \
21022 it->w->ncols_scale_factor++; \
21023 fonts_changed_p = 1; \
21027 /* Store one glyph for IT->char_to_display in IT->glyph_row.
21028 Called from x_produce_glyphs when IT->glyph_row is non-null. */
21034 struct glyph
*glyph
;
21035 enum glyph_row_area area
= it
->area
;
21037 xassert (it
->glyph_row
);
21038 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
21040 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21041 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21043 glyph
->charpos
= CHARPOS (it
->position
);
21044 glyph
->object
= it
->object
;
21045 if (it
->pixel_width
> 0)
21047 glyph
->pixel_width
= it
->pixel_width
;
21048 glyph
->padding_p
= 0;
21052 /* Assure at least 1-pixel width. Otherwise, cursor can't
21053 be displayed correctly. */
21054 glyph
->pixel_width
= 1;
21055 glyph
->padding_p
= 1;
21057 glyph
->ascent
= it
->ascent
;
21058 glyph
->descent
= it
->descent
;
21059 glyph
->voffset
= it
->voffset
;
21060 glyph
->type
= CHAR_GLYPH
;
21061 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21062 glyph
->multibyte_p
= it
->multibyte_p
;
21063 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21064 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21065 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21066 || it
->phys_descent
> it
->descent
);
21067 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
21068 glyph
->face_id
= it
->face_id
;
21069 glyph
->u
.ch
= it
->char_to_display
;
21070 glyph
->slice
= null_glyph_slice
;
21071 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21074 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21075 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21077 glyph
->bidi_type
= it
->bidi_it
.type
;
21079 ++it
->glyph_row
->used
[area
];
21082 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21085 /* Store one glyph for the composition IT->cmp_it.id in
21086 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
21090 append_composite_glyph (it
)
21093 struct glyph
*glyph
;
21094 enum glyph_row_area area
= it
->area
;
21096 xassert (it
->glyph_row
);
21098 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21099 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21101 glyph
->charpos
= CHARPOS (it
->position
);
21102 glyph
->object
= it
->object
;
21103 glyph
->pixel_width
= it
->pixel_width
;
21104 glyph
->ascent
= it
->ascent
;
21105 glyph
->descent
= it
->descent
;
21106 glyph
->voffset
= it
->voffset
;
21107 glyph
->type
= COMPOSITE_GLYPH
;
21108 if (it
->cmp_it
.ch
< 0)
21110 glyph
->u
.cmp
.automatic
= 0;
21111 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21115 glyph
->u
.cmp
.automatic
= 1;
21116 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21117 glyph
->u
.cmp
.from
= it
->cmp_it
.from
;
21118 glyph
->u
.cmp
.to
= it
->cmp_it
.to
- 1;
21120 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21121 glyph
->multibyte_p
= it
->multibyte_p
;
21122 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21123 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21124 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21125 || it
->phys_descent
> it
->descent
);
21126 glyph
->padding_p
= 0;
21127 glyph
->glyph_not_available_p
= 0;
21128 glyph
->face_id
= it
->face_id
;
21129 glyph
->slice
= null_glyph_slice
;
21130 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21133 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21134 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21136 glyph
->bidi_type
= it
->bidi_it
.type
;
21138 ++it
->glyph_row
->used
[area
];
21141 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21145 /* Change IT->ascent and IT->height according to the setting of
21149 take_vertical_position_into_account (it
)
21154 if (it
->voffset
< 0)
21155 /* Increase the ascent so that we can display the text higher
21157 it
->ascent
-= it
->voffset
;
21159 /* Increase the descent so that we can display the text lower
21161 it
->descent
+= it
->voffset
;
21166 /* Produce glyphs/get display metrics for the image IT is loaded with.
21167 See the description of struct display_iterator in dispextern.h for
21168 an overview of struct display_iterator. */
21171 produce_image_glyph (it
)
21176 int glyph_ascent
, crop
;
21177 struct glyph_slice slice
;
21179 xassert (it
->what
== IT_IMAGE
);
21181 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21183 /* Make sure X resources of the face is loaded. */
21184 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21186 if (it
->image_id
< 0)
21188 /* Fringe bitmap. */
21189 it
->ascent
= it
->phys_ascent
= 0;
21190 it
->descent
= it
->phys_descent
= 0;
21191 it
->pixel_width
= 0;
21196 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
21198 /* Make sure X resources of the image is loaded. */
21199 prepare_image_for_display (it
->f
, img
);
21201 slice
.x
= slice
.y
= 0;
21202 slice
.width
= img
->width
;
21203 slice
.height
= img
->height
;
21205 if (INTEGERP (it
->slice
.x
))
21206 slice
.x
= XINT (it
->slice
.x
);
21207 else if (FLOATP (it
->slice
.x
))
21208 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
21210 if (INTEGERP (it
->slice
.y
))
21211 slice
.y
= XINT (it
->slice
.y
);
21212 else if (FLOATP (it
->slice
.y
))
21213 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
21215 if (INTEGERP (it
->slice
.width
))
21216 slice
.width
= XINT (it
->slice
.width
);
21217 else if (FLOATP (it
->slice
.width
))
21218 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
21220 if (INTEGERP (it
->slice
.height
))
21221 slice
.height
= XINT (it
->slice
.height
);
21222 else if (FLOATP (it
->slice
.height
))
21223 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
21225 if (slice
.x
>= img
->width
)
21226 slice
.x
= img
->width
;
21227 if (slice
.y
>= img
->height
)
21228 slice
.y
= img
->height
;
21229 if (slice
.x
+ slice
.width
>= img
->width
)
21230 slice
.width
= img
->width
- slice
.x
;
21231 if (slice
.y
+ slice
.height
> img
->height
)
21232 slice
.height
= img
->height
- slice
.y
;
21234 if (slice
.width
== 0 || slice
.height
== 0)
21237 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
21239 it
->descent
= slice
.height
- glyph_ascent
;
21241 it
->descent
+= img
->vmargin
;
21242 if (slice
.y
+ slice
.height
== img
->height
)
21243 it
->descent
+= img
->vmargin
;
21244 it
->phys_descent
= it
->descent
;
21246 it
->pixel_width
= slice
.width
;
21248 it
->pixel_width
+= img
->hmargin
;
21249 if (slice
.x
+ slice
.width
== img
->width
)
21250 it
->pixel_width
+= img
->hmargin
;
21252 /* It's quite possible for images to have an ascent greater than
21253 their height, so don't get confused in that case. */
21254 if (it
->descent
< 0)
21259 if (face
->box
!= FACE_NO_BOX
)
21261 if (face
->box_line_width
> 0)
21264 it
->ascent
+= face
->box_line_width
;
21265 if (slice
.y
+ slice
.height
== img
->height
)
21266 it
->descent
+= face
->box_line_width
;
21269 if (it
->start_of_box_run_p
&& slice
.x
== 0)
21270 it
->pixel_width
+= eabs (face
->box_line_width
);
21271 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
21272 it
->pixel_width
+= eabs (face
->box_line_width
);
21275 take_vertical_position_into_account (it
);
21277 /* Automatically crop wide image glyphs at right edge so we can
21278 draw the cursor on same display row. */
21279 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
21280 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
21282 it
->pixel_width
-= crop
;
21283 slice
.width
-= crop
;
21288 struct glyph
*glyph
;
21289 enum glyph_row_area area
= it
->area
;
21291 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21292 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21294 glyph
->charpos
= CHARPOS (it
->position
);
21295 glyph
->object
= it
->object
;
21296 glyph
->pixel_width
= it
->pixel_width
;
21297 glyph
->ascent
= glyph_ascent
;
21298 glyph
->descent
= it
->descent
;
21299 glyph
->voffset
= it
->voffset
;
21300 glyph
->type
= IMAGE_GLYPH
;
21301 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21302 glyph
->multibyte_p
= it
->multibyte_p
;
21303 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21304 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21305 glyph
->overlaps_vertically_p
= 0;
21306 glyph
->padding_p
= 0;
21307 glyph
->glyph_not_available_p
= 0;
21308 glyph
->face_id
= it
->face_id
;
21309 glyph
->u
.img_id
= img
->id
;
21310 glyph
->slice
= slice
;
21311 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21314 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21315 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21317 glyph
->bidi_type
= it
->bidi_it
.type
;
21319 ++it
->glyph_row
->used
[area
];
21322 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21327 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
21328 of the glyph, WIDTH and HEIGHT are the width and height of the
21329 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
21332 append_stretch_glyph (it
, object
, width
, height
, ascent
)
21334 Lisp_Object object
;
21338 struct glyph
*glyph
;
21339 enum glyph_row_area area
= it
->area
;
21341 xassert (ascent
>= 0 && ascent
<= height
);
21343 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21344 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21346 glyph
->charpos
= CHARPOS (it
->position
);
21347 glyph
->object
= object
;
21348 glyph
->pixel_width
= width
;
21349 glyph
->ascent
= ascent
;
21350 glyph
->descent
= height
- ascent
;
21351 glyph
->voffset
= it
->voffset
;
21352 glyph
->type
= STRETCH_GLYPH
;
21353 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21354 glyph
->multibyte_p
= it
->multibyte_p
;
21355 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21356 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21357 glyph
->overlaps_vertically_p
= 0;
21358 glyph
->padding_p
= 0;
21359 glyph
->glyph_not_available_p
= 0;
21360 glyph
->face_id
= it
->face_id
;
21361 glyph
->u
.stretch
.ascent
= ascent
;
21362 glyph
->u
.stretch
.height
= height
;
21363 glyph
->slice
= null_glyph_slice
;
21364 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21367 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21368 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21370 glyph
->bidi_type
= it
->bidi_it
.type
;
21372 ++it
->glyph_row
->used
[area
];
21375 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21379 /* Produce a stretch glyph for iterator IT. IT->object is the value
21380 of the glyph property displayed. The value must be a list
21381 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
21384 1. `:width WIDTH' specifies that the space should be WIDTH *
21385 canonical char width wide. WIDTH may be an integer or floating
21388 2. `:relative-width FACTOR' specifies that the width of the stretch
21389 should be computed from the width of the first character having the
21390 `glyph' property, and should be FACTOR times that width.
21392 3. `:align-to HPOS' specifies that the space should be wide enough
21393 to reach HPOS, a value in canonical character units.
21395 Exactly one of the above pairs must be present.
21397 4. `:height HEIGHT' specifies that the height of the stretch produced
21398 should be HEIGHT, measured in canonical character units.
21400 5. `:relative-height FACTOR' specifies that the height of the
21401 stretch should be FACTOR times the height of the characters having
21402 the glyph property.
21404 Either none or exactly one of 4 or 5 must be present.
21406 6. `:ascent ASCENT' specifies that ASCENT percent of the height
21407 of the stretch should be used for the ascent of the stretch.
21408 ASCENT must be in the range 0 <= ASCENT <= 100. */
21411 produce_stretch_glyph (it
)
21414 /* (space :width WIDTH :height HEIGHT ...) */
21415 Lisp_Object prop
, plist
;
21416 int width
= 0, height
= 0, align_to
= -1;
21417 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
21420 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21421 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
21423 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21425 /* List should start with `space'. */
21426 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
21427 plist
= XCDR (it
->object
);
21429 /* Compute the width of the stretch. */
21430 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
21431 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
21433 /* Absolute width `:width WIDTH' specified and valid. */
21434 zero_width_ok_p
= 1;
21437 else if (prop
= Fplist_get (plist
, QCrelative_width
),
21440 /* Relative width `:relative-width FACTOR' specified and valid.
21441 Compute the width of the characters having the `glyph'
21444 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
21447 if (it
->multibyte_p
)
21449 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
21450 - IT_BYTEPOS (*it
));
21451 it2
.c
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
21454 it2
.c
= *p
, it2
.len
= 1;
21456 it2
.glyph_row
= NULL
;
21457 it2
.what
= IT_CHARACTER
;
21458 x_produce_glyphs (&it2
);
21459 width
= NUMVAL (prop
) * it2
.pixel_width
;
21461 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
21462 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
21464 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
21465 align_to
= (align_to
< 0
21467 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
21468 else if (align_to
< 0)
21469 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
21470 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
21471 zero_width_ok_p
= 1;
21474 /* Nothing specified -> width defaults to canonical char width. */
21475 width
= FRAME_COLUMN_WIDTH (it
->f
);
21477 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
21480 /* Compute height. */
21481 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
21482 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
21485 zero_height_ok_p
= 1;
21487 else if (prop
= Fplist_get (plist
, QCrelative_height
),
21489 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
21491 height
= FONT_HEIGHT (font
);
21493 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
21496 /* Compute percentage of height used for ascent. If
21497 `:ascent ASCENT' is present and valid, use that. Otherwise,
21498 derive the ascent from the font in use. */
21499 if (prop
= Fplist_get (plist
, QCascent
),
21500 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
21501 ascent
= height
* NUMVAL (prop
) / 100.0;
21502 else if (!NILP (prop
)
21503 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
21504 ascent
= min (max (0, (int)tem
), height
);
21506 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
21508 if (width
> 0 && it
->line_wrap
!= TRUNCATE
21509 && it
->current_x
+ width
> it
->last_visible_x
)
21510 width
= it
->last_visible_x
- it
->current_x
- 1;
21512 if (width
> 0 && height
> 0 && it
->glyph_row
)
21514 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
21515 if (!STRINGP (object
))
21516 object
= it
->w
->buffer
;
21517 append_stretch_glyph (it
, object
, width
, height
, ascent
);
21520 it
->pixel_width
= width
;
21521 it
->ascent
= it
->phys_ascent
= ascent
;
21522 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
21523 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
21525 take_vertical_position_into_account (it
);
21528 /* Calculate line-height and line-spacing properties.
21529 An integer value specifies explicit pixel value.
21530 A float value specifies relative value to current face height.
21531 A cons (float . face-name) specifies relative value to
21532 height of specified face font.
21534 Returns height in pixels, or nil. */
21538 calc_line_height_property (it
, val
, font
, boff
, override
)
21542 int boff
, override
;
21544 Lisp_Object face_name
= Qnil
;
21545 int ascent
, descent
, height
;
21547 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
21552 face_name
= XCAR (val
);
21554 if (!NUMBERP (val
))
21555 val
= make_number (1);
21556 if (NILP (face_name
))
21558 height
= it
->ascent
+ it
->descent
;
21563 if (NILP (face_name
))
21565 font
= FRAME_FONT (it
->f
);
21566 boff
= FRAME_BASELINE_OFFSET (it
->f
);
21568 else if (EQ (face_name
, Qt
))
21577 face_id
= lookup_named_face (it
->f
, face_name
, 0);
21579 return make_number (-1);
21581 face
= FACE_FROM_ID (it
->f
, face_id
);
21584 return make_number (-1);
21585 boff
= font
->baseline_offset
;
21586 if (font
->vertical_centering
)
21587 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21590 ascent
= FONT_BASE (font
) + boff
;
21591 descent
= FONT_DESCENT (font
) - boff
;
21595 it
->override_ascent
= ascent
;
21596 it
->override_descent
= descent
;
21597 it
->override_boff
= boff
;
21600 height
= ascent
+ descent
;
21604 height
= (int)(XFLOAT_DATA (val
) * height
);
21605 else if (INTEGERP (val
))
21606 height
*= XINT (val
);
21608 return make_number (height
);
21613 Produce glyphs/get display metrics for the display element IT is
21614 loaded with. See the description of struct it in dispextern.h
21615 for an overview of struct it. */
21618 x_produce_glyphs (it
)
21621 int extra_line_spacing
= it
->extra_line_spacing
;
21623 it
->glyph_not_available_p
= 0;
21625 if (it
->what
== IT_CHARACTER
)
21629 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21630 struct font_metrics
*pcm
;
21631 int font_not_found_p
;
21632 int boff
; /* baseline offset */
21633 /* We may change it->multibyte_p upon unibyte<->multibyte
21634 conversion. So, save the current value now and restore it
21637 Note: It seems that we don't have to record multibyte_p in
21638 struct glyph because the character code itself tells whether
21639 or not the character is multibyte. Thus, in the future, we
21640 must consider eliminating the field `multibyte_p' in the
21642 int saved_multibyte_p
= it
->multibyte_p
;
21644 /* Maybe translate single-byte characters to multibyte, or the
21646 it
->char_to_display
= it
->c
;
21647 if (!ASCII_BYTE_P (it
->c
)
21648 && ! it
->multibyte_p
)
21650 if (SINGLE_BYTE_CHAR_P (it
->c
)
21651 && unibyte_display_via_language_environment
)
21653 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
21655 /* get_next_display_element assures that this decoding
21657 it
->char_to_display
= DECODE_CHAR (unibyte
, it
->c
);
21658 it
->multibyte_p
= 1;
21659 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
,
21661 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21665 /* Get font to use. Encode IT->char_to_display. */
21666 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
21667 &char2b
, it
->multibyte_p
, 0);
21670 font_not_found_p
= font
== NULL
;
21671 if (font_not_found_p
)
21673 /* When no suitable font found, display an empty box based
21674 on the metrics of the font of the default face (or what
21676 struct face
*no_font_face
21677 = FACE_FROM_ID (it
->f
,
21678 NILP (Vface_remapping_alist
) ? DEFAULT_FACE_ID
21679 : lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
21680 font
= no_font_face
->font
;
21681 boff
= font
->baseline_offset
;
21685 boff
= font
->baseline_offset
;
21686 if (font
->vertical_centering
)
21687 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21690 if (it
->char_to_display
>= ' '
21691 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
21693 /* Either unibyte or ASCII. */
21698 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21700 if (it
->override_ascent
>= 0)
21702 it
->ascent
= it
->override_ascent
;
21703 it
->descent
= it
->override_descent
;
21704 boff
= it
->override_boff
;
21708 it
->ascent
= FONT_BASE (font
) + boff
;
21709 it
->descent
= FONT_DESCENT (font
) - boff
;
21714 it
->phys_ascent
= pcm
->ascent
+ boff
;
21715 it
->phys_descent
= pcm
->descent
- boff
;
21716 it
->pixel_width
= pcm
->width
;
21720 it
->glyph_not_available_p
= 1;
21721 it
->phys_ascent
= it
->ascent
;
21722 it
->phys_descent
= it
->descent
;
21723 it
->pixel_width
= FONT_WIDTH (font
);
21726 if (it
->constrain_row_ascent_descent_p
)
21728 if (it
->descent
> it
->max_descent
)
21730 it
->ascent
+= it
->descent
- it
->max_descent
;
21731 it
->descent
= it
->max_descent
;
21733 if (it
->ascent
> it
->max_ascent
)
21735 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21736 it
->ascent
= it
->max_ascent
;
21738 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21739 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21740 extra_line_spacing
= 0;
21743 /* If this is a space inside a region of text with
21744 `space-width' property, change its width. */
21745 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
21747 it
->pixel_width
*= XFLOATINT (it
->space_width
);
21749 /* If face has a box, add the box thickness to the character
21750 height. If character has a box line to the left and/or
21751 right, add the box line width to the character's width. */
21752 if (face
->box
!= FACE_NO_BOX
)
21754 int thick
= face
->box_line_width
;
21758 it
->ascent
+= thick
;
21759 it
->descent
+= thick
;
21764 if (it
->start_of_box_run_p
)
21765 it
->pixel_width
+= thick
;
21766 if (it
->end_of_box_run_p
)
21767 it
->pixel_width
+= thick
;
21770 /* If face has an overline, add the height of the overline
21771 (1 pixel) and a 1 pixel margin to the character height. */
21772 if (face
->overline_p
)
21773 it
->ascent
+= overline_margin
;
21775 if (it
->constrain_row_ascent_descent_p
)
21777 if (it
->ascent
> it
->max_ascent
)
21778 it
->ascent
= it
->max_ascent
;
21779 if (it
->descent
> it
->max_descent
)
21780 it
->descent
= it
->max_descent
;
21783 take_vertical_position_into_account (it
);
21785 /* If we have to actually produce glyphs, do it. */
21790 /* Translate a space with a `space-width' property
21791 into a stretch glyph. */
21792 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
21793 / FONT_HEIGHT (font
));
21794 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21795 it
->ascent
+ it
->descent
, ascent
);
21800 /* If characters with lbearing or rbearing are displayed
21801 in this line, record that fact in a flag of the
21802 glyph row. This is used to optimize X output code. */
21803 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
21804 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21806 if (! stretched_p
&& it
->pixel_width
== 0)
21807 /* We assure that all visible glyphs have at least 1-pixel
21809 it
->pixel_width
= 1;
21811 else if (it
->char_to_display
== '\n')
21813 /* A newline has no width, but we need the height of the
21814 line. But if previous part of the line sets a height,
21815 don't increase that height */
21817 Lisp_Object height
;
21818 Lisp_Object total_height
= Qnil
;
21820 it
->override_ascent
= -1;
21821 it
->pixel_width
= 0;
21824 height
= get_it_property(it
, Qline_height
);
21825 /* Split (line-height total-height) list */
21827 && CONSP (XCDR (height
))
21828 && NILP (XCDR (XCDR (height
))))
21830 total_height
= XCAR (XCDR (height
));
21831 height
= XCAR (height
);
21833 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
21835 if (it
->override_ascent
>= 0)
21837 it
->ascent
= it
->override_ascent
;
21838 it
->descent
= it
->override_descent
;
21839 boff
= it
->override_boff
;
21843 it
->ascent
= FONT_BASE (font
) + boff
;
21844 it
->descent
= FONT_DESCENT (font
) - boff
;
21847 if (EQ (height
, Qt
))
21849 if (it
->descent
> it
->max_descent
)
21851 it
->ascent
+= it
->descent
- it
->max_descent
;
21852 it
->descent
= it
->max_descent
;
21854 if (it
->ascent
> it
->max_ascent
)
21856 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21857 it
->ascent
= it
->max_ascent
;
21859 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21860 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21861 it
->constrain_row_ascent_descent_p
= 1;
21862 extra_line_spacing
= 0;
21866 Lisp_Object spacing
;
21868 it
->phys_ascent
= it
->ascent
;
21869 it
->phys_descent
= it
->descent
;
21871 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
21872 && face
->box
!= FACE_NO_BOX
21873 && face
->box_line_width
> 0)
21875 it
->ascent
+= face
->box_line_width
;
21876 it
->descent
+= face
->box_line_width
;
21879 && XINT (height
) > it
->ascent
+ it
->descent
)
21880 it
->ascent
= XINT (height
) - it
->descent
;
21882 if (!NILP (total_height
))
21883 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
21886 spacing
= get_it_property(it
, Qline_spacing
);
21887 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
21889 if (INTEGERP (spacing
))
21891 extra_line_spacing
= XINT (spacing
);
21892 if (!NILP (total_height
))
21893 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
21897 else if (it
->char_to_display
== '\t')
21899 if (font
->space_width
> 0)
21901 int tab_width
= it
->tab_width
* font
->space_width
;
21902 int x
= it
->current_x
+ it
->continuation_lines_width
;
21903 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
21905 /* If the distance from the current position to the next tab
21906 stop is less than a space character width, use the
21907 tab stop after that. */
21908 if (next_tab_x
- x
< font
->space_width
)
21909 next_tab_x
+= tab_width
;
21911 it
->pixel_width
= next_tab_x
- x
;
21913 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
21914 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21918 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21919 it
->ascent
+ it
->descent
, it
->ascent
);
21924 it
->pixel_width
= 0;
21930 /* A multi-byte character. Assume that the display width of the
21931 character is the width of the character multiplied by the
21932 width of the font. */
21934 /* If we found a font, this font should give us the right
21935 metrics. If we didn't find a font, use the frame's
21936 default font and calculate the width of the character by
21937 multiplying the width of font by the width of the
21940 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21942 if (font_not_found_p
|| !pcm
)
21944 int char_width
= CHAR_WIDTH (it
->char_to_display
);
21946 if (char_width
== 0)
21947 /* This is a non spacing character. But, as we are
21948 going to display an empty box, the box must occupy
21949 at least one column. */
21951 it
->glyph_not_available_p
= 1;
21952 it
->pixel_width
= font
->space_width
* char_width
;
21953 it
->phys_ascent
= FONT_BASE (font
) + boff
;
21954 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21958 it
->pixel_width
= pcm
->width
;
21959 it
->phys_ascent
= pcm
->ascent
+ boff
;
21960 it
->phys_descent
= pcm
->descent
- boff
;
21962 && (pcm
->lbearing
< 0
21963 || pcm
->rbearing
> pcm
->width
))
21964 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21967 it
->ascent
= FONT_BASE (font
) + boff
;
21968 it
->descent
= FONT_DESCENT (font
) - boff
;
21969 if (face
->box
!= FACE_NO_BOX
)
21971 int thick
= face
->box_line_width
;
21975 it
->ascent
+= thick
;
21976 it
->descent
+= thick
;
21981 if (it
->start_of_box_run_p
)
21982 it
->pixel_width
+= thick
;
21983 if (it
->end_of_box_run_p
)
21984 it
->pixel_width
+= thick
;
21987 /* If face has an overline, add the height of the overline
21988 (1 pixel) and a 1 pixel margin to the character height. */
21989 if (face
->overline_p
)
21990 it
->ascent
+= overline_margin
;
21992 take_vertical_position_into_account (it
);
21994 if (it
->ascent
< 0)
21996 if (it
->descent
< 0)
22001 if (it
->pixel_width
== 0)
22002 /* We assure that all visible glyphs have at least 1-pixel
22004 it
->pixel_width
= 1;
22006 it
->multibyte_p
= saved_multibyte_p
;
22008 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
22010 /* A static composition.
22012 Note: A composition is represented as one glyph in the
22013 glyph matrix. There are no padding glyphs.
22015 Important note: pixel_width, ascent, and descent are the
22016 values of what is drawn by draw_glyphs (i.e. the values of
22017 the overall glyphs composed). */
22018 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22019 int boff
; /* baseline offset */
22020 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
22021 int glyph_len
= cmp
->glyph_len
;
22022 struct font
*font
= face
->font
;
22026 /* If we have not yet calculated pixel size data of glyphs of
22027 the composition for the current face font, calculate them
22028 now. Theoretically, we have to check all fonts for the
22029 glyphs, but that requires much time and memory space. So,
22030 here we check only the font of the first glyph. This may
22031 lead to incorrect display, but it's very rare, and C-l
22032 (recenter-top-bottom) can correct the display anyway. */
22033 if (! cmp
->font
|| cmp
->font
!= font
)
22035 /* Ascent and descent of the font of the first character
22036 of this composition (adjusted by baseline offset).
22037 Ascent and descent of overall glyphs should not be less
22038 than these, respectively. */
22039 int font_ascent
, font_descent
, font_height
;
22040 /* Bounding box of the overall glyphs. */
22041 int leftmost
, rightmost
, lowest
, highest
;
22042 int lbearing
, rbearing
;
22043 int i
, width
, ascent
, descent
;
22044 int left_padded
= 0, right_padded
= 0;
22047 struct font_metrics
*pcm
;
22048 int font_not_found_p
;
22051 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
22052 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
22054 if (glyph_len
< cmp
->glyph_len
)
22056 for (i
= 0; i
< glyph_len
; i
++)
22058 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
22060 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22065 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
22066 : IT_CHARPOS (*it
));
22067 /* If no suitable font is found, use the default font. */
22068 font_not_found_p
= font
== NULL
;
22069 if (font_not_found_p
)
22071 face
= face
->ascii_face
;
22074 boff
= font
->baseline_offset
;
22075 if (font
->vertical_centering
)
22076 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22077 font_ascent
= FONT_BASE (font
) + boff
;
22078 font_descent
= FONT_DESCENT (font
) - boff
;
22079 font_height
= FONT_HEIGHT (font
);
22081 cmp
->font
= (void *) font
;
22084 if (! font_not_found_p
)
22086 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
22087 &char2b
, it
->multibyte_p
, 0);
22088 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22091 /* Initialize the bounding box. */
22094 width
= pcm
->width
;
22095 ascent
= pcm
->ascent
;
22096 descent
= pcm
->descent
;
22097 lbearing
= pcm
->lbearing
;
22098 rbearing
= pcm
->rbearing
;
22102 width
= FONT_WIDTH (font
);
22103 ascent
= FONT_BASE (font
);
22104 descent
= FONT_DESCENT (font
);
22111 lowest
= - descent
+ boff
;
22112 highest
= ascent
+ boff
;
22114 if (! font_not_found_p
22115 && font
->default_ascent
22116 && CHAR_TABLE_P (Vuse_default_ascent
)
22117 && !NILP (Faref (Vuse_default_ascent
,
22118 make_number (it
->char_to_display
))))
22119 highest
= font
->default_ascent
+ boff
;
22121 /* Draw the first glyph at the normal position. It may be
22122 shifted to right later if some other glyphs are drawn
22124 cmp
->offsets
[i
* 2] = 0;
22125 cmp
->offsets
[i
* 2 + 1] = boff
;
22126 cmp
->lbearing
= lbearing
;
22127 cmp
->rbearing
= rbearing
;
22129 /* Set cmp->offsets for the remaining glyphs. */
22130 for (i
++; i
< glyph_len
; i
++)
22132 int left
, right
, btm
, top
;
22133 int ch
= COMPOSITION_GLYPH (cmp
, i
);
22135 struct face
*this_face
;
22140 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
22141 this_face
= FACE_FROM_ID (it
->f
, face_id
);
22142 font
= this_face
->font
;
22148 this_boff
= font
->baseline_offset
;
22149 if (font
->vertical_centering
)
22150 this_boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22151 get_char_face_and_encoding (it
->f
, ch
, face_id
,
22152 &char2b
, it
->multibyte_p
, 0);
22153 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22156 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22159 width
= pcm
->width
;
22160 ascent
= pcm
->ascent
;
22161 descent
= pcm
->descent
;
22162 lbearing
= pcm
->lbearing
;
22163 rbearing
= pcm
->rbearing
;
22164 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
22166 /* Relative composition with or without
22167 alternate chars. */
22168 left
= (leftmost
+ rightmost
- width
) / 2;
22169 btm
= - descent
+ boff
;
22170 if (font
->relative_compose
22171 && (! CHAR_TABLE_P (Vignore_relative_composition
)
22172 || NILP (Faref (Vignore_relative_composition
,
22173 make_number (ch
)))))
22176 if (- descent
>= font
->relative_compose
)
22177 /* One extra pixel between two glyphs. */
22179 else if (ascent
<= 0)
22180 /* One extra pixel between two glyphs. */
22181 btm
= lowest
- 1 - ascent
- descent
;
22186 /* A composition rule is specified by an integer
22187 value that encodes global and new reference
22188 points (GREF and NREF). GREF and NREF are
22189 specified by numbers as below:
22191 0---1---2 -- ascent
22195 9--10--11 -- center
22197 ---3---4---5--- baseline
22199 6---7---8 -- descent
22201 int rule
= COMPOSITION_RULE (cmp
, i
);
22202 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
22204 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
22205 grefx
= gref
% 3, nrefx
= nref
% 3;
22206 grefy
= gref
/ 3, nrefy
= nref
/ 3;
22208 xoff
= font_height
* (xoff
- 128) / 256;
22210 yoff
= font_height
* (yoff
- 128) / 256;
22213 + grefx
* (rightmost
- leftmost
) / 2
22214 - nrefx
* width
/ 2
22217 btm
= ((grefy
== 0 ? highest
22219 : grefy
== 2 ? lowest
22220 : (highest
+ lowest
) / 2)
22221 - (nrefy
== 0 ? ascent
+ descent
22222 : nrefy
== 1 ? descent
- boff
22224 : (ascent
+ descent
) / 2)
22228 cmp
->offsets
[i
* 2] = left
;
22229 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
22231 /* Update the bounding box of the overall glyphs. */
22234 right
= left
+ width
;
22235 if (left
< leftmost
)
22237 if (right
> rightmost
)
22240 top
= btm
+ descent
+ ascent
;
22246 if (cmp
->lbearing
> left
+ lbearing
)
22247 cmp
->lbearing
= left
+ lbearing
;
22248 if (cmp
->rbearing
< left
+ rbearing
)
22249 cmp
->rbearing
= left
+ rbearing
;
22253 /* If there are glyphs whose x-offsets are negative,
22254 shift all glyphs to the right and make all x-offsets
22258 for (i
= 0; i
< cmp
->glyph_len
; i
++)
22259 cmp
->offsets
[i
* 2] -= leftmost
;
22260 rightmost
-= leftmost
;
22261 cmp
->lbearing
-= leftmost
;
22262 cmp
->rbearing
-= leftmost
;
22265 if (left_padded
&& cmp
->lbearing
< 0)
22267 for (i
= 0; i
< cmp
->glyph_len
; i
++)
22268 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
22269 rightmost
-= cmp
->lbearing
;
22270 cmp
->rbearing
-= cmp
->lbearing
;
22273 if (right_padded
&& rightmost
< cmp
->rbearing
)
22275 rightmost
= cmp
->rbearing
;
22278 cmp
->pixel_width
= rightmost
;
22279 cmp
->ascent
= highest
;
22280 cmp
->descent
= - lowest
;
22281 if (cmp
->ascent
< font_ascent
)
22282 cmp
->ascent
= font_ascent
;
22283 if (cmp
->descent
< font_descent
)
22284 cmp
->descent
= font_descent
;
22288 && (cmp
->lbearing
< 0
22289 || cmp
->rbearing
> cmp
->pixel_width
))
22290 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22292 it
->pixel_width
= cmp
->pixel_width
;
22293 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
22294 it
->descent
= it
->phys_descent
= cmp
->descent
;
22295 if (face
->box
!= FACE_NO_BOX
)
22297 int thick
= face
->box_line_width
;
22301 it
->ascent
+= thick
;
22302 it
->descent
+= thick
;
22307 if (it
->start_of_box_run_p
)
22308 it
->pixel_width
+= thick
;
22309 if (it
->end_of_box_run_p
)
22310 it
->pixel_width
+= thick
;
22313 /* If face has an overline, add the height of the overline
22314 (1 pixel) and a 1 pixel margin to the character height. */
22315 if (face
->overline_p
)
22316 it
->ascent
+= overline_margin
;
22318 take_vertical_position_into_account (it
);
22319 if (it
->ascent
< 0)
22321 if (it
->descent
< 0)
22325 append_composite_glyph (it
);
22327 else if (it
->what
== IT_COMPOSITION
)
22329 /* A dynamic (automatic) composition. */
22330 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22331 Lisp_Object gstring
;
22332 struct font_metrics metrics
;
22334 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
22336 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
22339 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
22340 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22341 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
22342 it
->descent
= it
->phys_descent
= metrics
.descent
;
22343 if (face
->box
!= FACE_NO_BOX
)
22345 int thick
= face
->box_line_width
;
22349 it
->ascent
+= thick
;
22350 it
->descent
+= thick
;
22355 if (it
->start_of_box_run_p
)
22356 it
->pixel_width
+= thick
;
22357 if (it
->end_of_box_run_p
)
22358 it
->pixel_width
+= thick
;
22360 /* If face has an overline, add the height of the overline
22361 (1 pixel) and a 1 pixel margin to the character height. */
22362 if (face
->overline_p
)
22363 it
->ascent
+= overline_margin
;
22364 take_vertical_position_into_account (it
);
22365 if (it
->ascent
< 0)
22367 if (it
->descent
< 0)
22371 append_composite_glyph (it
);
22373 else if (it
->what
== IT_IMAGE
)
22374 produce_image_glyph (it
);
22375 else if (it
->what
== IT_STRETCH
)
22376 produce_stretch_glyph (it
);
22378 /* Accumulate dimensions. Note: can't assume that it->descent > 0
22379 because this isn't true for images with `:ascent 100'. */
22380 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
22381 if (it
->area
== TEXT_AREA
)
22382 it
->current_x
+= it
->pixel_width
;
22384 if (extra_line_spacing
> 0)
22386 it
->descent
+= extra_line_spacing
;
22387 if (extra_line_spacing
> it
->max_extra_line_spacing
)
22388 it
->max_extra_line_spacing
= extra_line_spacing
;
22391 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
22392 it
->max_descent
= max (it
->max_descent
, it
->descent
);
22393 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
22394 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
22398 Output LEN glyphs starting at START at the nominal cursor position.
22399 Advance the nominal cursor over the text. The global variable
22400 updated_window contains the window being updated, updated_row is
22401 the glyph row being updated, and updated_area is the area of that
22402 row being updated. */
22405 x_write_glyphs (start
, len
)
22406 struct glyph
*start
;
22411 xassert (updated_window
&& updated_row
);
22414 /* Write glyphs. */
22416 hpos
= start
- updated_row
->glyphs
[updated_area
];
22417 x
= draw_glyphs (updated_window
, output_cursor
.x
,
22418 updated_row
, updated_area
,
22420 DRAW_NORMAL_TEXT
, 0);
22422 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
22423 if (updated_area
== TEXT_AREA
22424 && updated_window
->phys_cursor_on_p
22425 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
22426 && updated_window
->phys_cursor
.hpos
>= hpos
22427 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
22428 updated_window
->phys_cursor_on_p
= 0;
22432 /* Advance the output cursor. */
22433 output_cursor
.hpos
+= len
;
22434 output_cursor
.x
= x
;
22439 Insert LEN glyphs from START at the nominal cursor position. */
22442 x_insert_glyphs (start
, len
)
22443 struct glyph
*start
;
22448 int line_height
, shift_by_width
, shifted_region_width
;
22449 struct glyph_row
*row
;
22450 struct glyph
*glyph
;
22451 int frame_x
, frame_y
;
22454 xassert (updated_window
&& updated_row
);
22456 w
= updated_window
;
22457 f
= XFRAME (WINDOW_FRAME (w
));
22459 /* Get the height of the line we are in. */
22461 line_height
= row
->height
;
22463 /* Get the width of the glyphs to insert. */
22464 shift_by_width
= 0;
22465 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
22466 shift_by_width
+= glyph
->pixel_width
;
22468 /* Get the width of the region to shift right. */
22469 shifted_region_width
= (window_box_width (w
, updated_area
)
22474 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
22475 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
22477 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
22478 line_height
, shift_by_width
);
22480 /* Write the glyphs. */
22481 hpos
= start
- row
->glyphs
[updated_area
];
22482 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
22484 DRAW_NORMAL_TEXT
, 0);
22486 /* Advance the output cursor. */
22487 output_cursor
.hpos
+= len
;
22488 output_cursor
.x
+= shift_by_width
;
22494 Erase the current text line from the nominal cursor position
22495 (inclusive) to pixel column TO_X (exclusive). The idea is that
22496 everything from TO_X onward is already erased.
22498 TO_X is a pixel position relative to updated_area of
22499 updated_window. TO_X == -1 means clear to the end of this area. */
22502 x_clear_end_of_line (to_x
)
22506 struct window
*w
= updated_window
;
22507 int max_x
, min_y
, max_y
;
22508 int from_x
, from_y
, to_y
;
22510 xassert (updated_window
&& updated_row
);
22511 f
= XFRAME (w
->frame
);
22513 if (updated_row
->full_width_p
)
22514 max_x
= WINDOW_TOTAL_WIDTH (w
);
22516 max_x
= window_box_width (w
, updated_area
);
22517 max_y
= window_text_bottom_y (w
);
22519 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
22520 of window. For TO_X > 0, truncate to end of drawing area. */
22526 to_x
= min (to_x
, max_x
);
22528 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
22530 /* Notice if the cursor will be cleared by this operation. */
22531 if (!updated_row
->full_width_p
)
22532 notice_overwritten_cursor (w
, updated_area
,
22533 output_cursor
.x
, -1,
22535 MATRIX_ROW_BOTTOM_Y (updated_row
));
22537 from_x
= output_cursor
.x
;
22539 /* Translate to frame coordinates. */
22540 if (updated_row
->full_width_p
)
22542 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
22543 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
22547 int area_left
= window_box_left (w
, updated_area
);
22548 from_x
+= area_left
;
22552 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
22553 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
22554 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
22556 /* Prevent inadvertently clearing to end of the X window. */
22557 if (to_x
> from_x
&& to_y
> from_y
)
22560 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
22561 to_x
- from_x
, to_y
- from_y
);
22566 #endif /* HAVE_WINDOW_SYSTEM */
22570 /***********************************************************************
22572 ***********************************************************************/
22574 /* Value is the internal representation of the specified cursor type
22575 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
22576 of the bar cursor. */
22578 static enum text_cursor_kinds
22579 get_specified_cursor_type (arg
, width
)
22583 enum text_cursor_kinds type
;
22588 if (EQ (arg
, Qbox
))
22589 return FILLED_BOX_CURSOR
;
22591 if (EQ (arg
, Qhollow
))
22592 return HOLLOW_BOX_CURSOR
;
22594 if (EQ (arg
, Qbar
))
22601 && EQ (XCAR (arg
), Qbar
)
22602 && INTEGERP (XCDR (arg
))
22603 && XINT (XCDR (arg
)) >= 0)
22605 *width
= XINT (XCDR (arg
));
22609 if (EQ (arg
, Qhbar
))
22612 return HBAR_CURSOR
;
22616 && EQ (XCAR (arg
), Qhbar
)
22617 && INTEGERP (XCDR (arg
))
22618 && XINT (XCDR (arg
)) >= 0)
22620 *width
= XINT (XCDR (arg
));
22621 return HBAR_CURSOR
;
22624 /* Treat anything unknown as "hollow box cursor".
22625 It was bad to signal an error; people have trouble fixing
22626 .Xdefaults with Emacs, when it has something bad in it. */
22627 type
= HOLLOW_BOX_CURSOR
;
22632 /* Set the default cursor types for specified frame. */
22634 set_frame_cursor_types (f
, arg
)
22641 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
22642 FRAME_CURSOR_WIDTH (f
) = width
;
22644 /* By default, set up the blink-off state depending on the on-state. */
22646 tem
= Fassoc (arg
, Vblink_cursor_alist
);
22649 FRAME_BLINK_OFF_CURSOR (f
)
22650 = get_specified_cursor_type (XCDR (tem
), &width
);
22651 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
22654 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
22658 /* Return the cursor we want to be displayed in window W. Return
22659 width of bar/hbar cursor through WIDTH arg. Return with
22660 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
22661 (i.e. if the `system caret' should track this cursor).
22663 In a mini-buffer window, we want the cursor only to appear if we
22664 are reading input from this window. For the selected window, we
22665 want the cursor type given by the frame parameter or buffer local
22666 setting of cursor-type. If explicitly marked off, draw no cursor.
22667 In all other cases, we want a hollow box cursor. */
22669 static enum text_cursor_kinds
22670 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
22672 struct glyph
*glyph
;
22674 int *active_cursor
;
22676 struct frame
*f
= XFRAME (w
->frame
);
22677 struct buffer
*b
= XBUFFER (w
->buffer
);
22678 int cursor_type
= DEFAULT_CURSOR
;
22679 Lisp_Object alt_cursor
;
22680 int non_selected
= 0;
22682 *active_cursor
= 1;
22685 if (cursor_in_echo_area
22686 && FRAME_HAS_MINIBUF_P (f
)
22687 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
22689 if (w
== XWINDOW (echo_area_window
))
22691 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
22693 *width
= FRAME_CURSOR_WIDTH (f
);
22694 return FRAME_DESIRED_CURSOR (f
);
22697 return get_specified_cursor_type (b
->cursor_type
, width
);
22700 *active_cursor
= 0;
22704 /* Detect a nonselected window or nonselected frame. */
22705 else if (w
!= XWINDOW (f
->selected_window
)
22706 #ifdef HAVE_WINDOW_SYSTEM
22707 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
22711 *active_cursor
= 0;
22713 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
22719 /* Never display a cursor in a window in which cursor-type is nil. */
22720 if (NILP (b
->cursor_type
))
22723 /* Get the normal cursor type for this window. */
22724 if (EQ (b
->cursor_type
, Qt
))
22726 cursor_type
= FRAME_DESIRED_CURSOR (f
);
22727 *width
= FRAME_CURSOR_WIDTH (f
);
22730 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
22732 /* Use cursor-in-non-selected-windows instead
22733 for non-selected window or frame. */
22736 alt_cursor
= b
->cursor_in_non_selected_windows
;
22737 if (!EQ (Qt
, alt_cursor
))
22738 return get_specified_cursor_type (alt_cursor
, width
);
22739 /* t means modify the normal cursor type. */
22740 if (cursor_type
== FILLED_BOX_CURSOR
)
22741 cursor_type
= HOLLOW_BOX_CURSOR
;
22742 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
22744 return cursor_type
;
22747 /* Use normal cursor if not blinked off. */
22748 if (!w
->cursor_off_p
)
22750 #ifdef HAVE_WINDOW_SYSTEM
22751 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22753 if (cursor_type
== FILLED_BOX_CURSOR
)
22755 /* Using a block cursor on large images can be very annoying.
22756 So use a hollow cursor for "large" images.
22757 If image is not transparent (no mask), also use hollow cursor. */
22758 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22759 if (img
!= NULL
&& IMAGEP (img
->spec
))
22761 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
22762 where N = size of default frame font size.
22763 This should cover most of the "tiny" icons people may use. */
22765 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
22766 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
22767 cursor_type
= HOLLOW_BOX_CURSOR
;
22770 else if (cursor_type
!= NO_CURSOR
)
22772 /* Display current only supports BOX and HOLLOW cursors for images.
22773 So for now, unconditionally use a HOLLOW cursor when cursor is
22774 not a solid box cursor. */
22775 cursor_type
= HOLLOW_BOX_CURSOR
;
22779 return cursor_type
;
22782 /* Cursor is blinked off, so determine how to "toggle" it. */
22784 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
22785 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
22786 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
22788 /* Then see if frame has specified a specific blink off cursor type. */
22789 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
22791 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
22792 return FRAME_BLINK_OFF_CURSOR (f
);
22796 /* Some people liked having a permanently visible blinking cursor,
22797 while others had very strong opinions against it. So it was
22798 decided to remove it. KFS 2003-09-03 */
22800 /* Finally perform built-in cursor blinking:
22801 filled box <-> hollow box
22802 wide [h]bar <-> narrow [h]bar
22803 narrow [h]bar <-> no cursor
22804 other type <-> no cursor */
22806 if (cursor_type
== FILLED_BOX_CURSOR
)
22807 return HOLLOW_BOX_CURSOR
;
22809 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
22812 return cursor_type
;
22820 #ifdef HAVE_WINDOW_SYSTEM
22822 /* Notice when the text cursor of window W has been completely
22823 overwritten by a drawing operation that outputs glyphs in AREA
22824 starting at X0 and ending at X1 in the line starting at Y0 and
22825 ending at Y1. X coordinates are area-relative. X1 < 0 means all
22826 the rest of the line after X0 has been written. Y coordinates
22827 are window-relative. */
22830 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
22832 enum glyph_row_area area
;
22833 int x0
, y0
, x1
, y1
;
22835 int cx0
, cx1
, cy0
, cy1
;
22836 struct glyph_row
*row
;
22838 if (!w
->phys_cursor_on_p
)
22840 if (area
!= TEXT_AREA
)
22843 if (w
->phys_cursor
.vpos
< 0
22844 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
22845 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
22846 !(row
->enabled_p
&& row
->displays_text_p
)))
22849 if (row
->cursor_in_fringe_p
)
22851 row
->cursor_in_fringe_p
= 0;
22852 draw_fringe_bitmap (w
, row
, 0);
22853 w
->phys_cursor_on_p
= 0;
22857 cx0
= w
->phys_cursor
.x
;
22858 cx1
= cx0
+ w
->phys_cursor_width
;
22859 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
22862 /* The cursor image will be completely removed from the
22863 screen if the output area intersects the cursor area in
22864 y-direction. When we draw in [y0 y1[, and some part of
22865 the cursor is at y < y0, that part must have been drawn
22866 before. When scrolling, the cursor is erased before
22867 actually scrolling, so we don't come here. When not
22868 scrolling, the rows above the old cursor row must have
22869 changed, and in this case these rows must have written
22870 over the cursor image.
22872 Likewise if part of the cursor is below y1, with the
22873 exception of the cursor being in the first blank row at
22874 the buffer and window end because update_text_area
22875 doesn't draw that row. (Except when it does, but
22876 that's handled in update_text_area.) */
22878 cy0
= w
->phys_cursor
.y
;
22879 cy1
= cy0
+ w
->phys_cursor_height
;
22880 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
22883 w
->phys_cursor_on_p
= 0;
22886 #endif /* HAVE_WINDOW_SYSTEM */
22889 /************************************************************************
22891 ************************************************************************/
22893 #ifdef HAVE_WINDOW_SYSTEM
22896 Fix the display of area AREA of overlapping row ROW in window W
22897 with respect to the overlapping part OVERLAPS. */
22900 x_fix_overlapping_area (w
, row
, area
, overlaps
)
22902 struct glyph_row
*row
;
22903 enum glyph_row_area area
;
22911 for (i
= 0; i
< row
->used
[area
];)
22913 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
22915 int start
= i
, start_x
= x
;
22919 x
+= row
->glyphs
[area
][i
].pixel_width
;
22922 while (i
< row
->used
[area
]
22923 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
22925 draw_glyphs (w
, start_x
, row
, area
,
22927 DRAW_NORMAL_TEXT
, overlaps
);
22931 x
+= row
->glyphs
[area
][i
].pixel_width
;
22941 Draw the cursor glyph of window W in glyph row ROW. See the
22942 comment of draw_glyphs for the meaning of HL. */
22945 draw_phys_cursor_glyph (w
, row
, hl
)
22947 struct glyph_row
*row
;
22948 enum draw_glyphs_face hl
;
22950 /* If cursor hpos is out of bounds, don't draw garbage. This can
22951 happen in mini-buffer windows when switching between echo area
22952 glyphs and mini-buffer. */
22953 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
22955 int on_p
= w
->phys_cursor_on_p
;
22957 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
22958 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
22960 w
->phys_cursor_on_p
= on_p
;
22962 if (hl
== DRAW_CURSOR
)
22963 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22964 /* When we erase the cursor, and ROW is overlapped by other
22965 rows, make sure that these overlapping parts of other rows
22967 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
22969 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22971 if (row
> w
->current_matrix
->rows
22972 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
22973 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
22974 OVERLAPS_ERASED_CURSOR
);
22976 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
22977 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
22978 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
22979 OVERLAPS_ERASED_CURSOR
);
22986 Erase the image of a cursor of window W from the screen. */
22989 erase_phys_cursor (w
)
22992 struct frame
*f
= XFRAME (w
->frame
);
22993 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22994 int hpos
= w
->phys_cursor
.hpos
;
22995 int vpos
= w
->phys_cursor
.vpos
;
22996 int mouse_face_here_p
= 0;
22997 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
22998 struct glyph_row
*cursor_row
;
22999 struct glyph
*cursor_glyph
;
23000 enum draw_glyphs_face hl
;
23002 /* No cursor displayed or row invalidated => nothing to do on the
23004 if (w
->phys_cursor_type
== NO_CURSOR
)
23005 goto mark_cursor_off
;
23007 /* VPOS >= active_glyphs->nrows means that window has been resized.
23008 Don't bother to erase the cursor. */
23009 if (vpos
>= active_glyphs
->nrows
)
23010 goto mark_cursor_off
;
23012 /* If row containing cursor is marked invalid, there is nothing we
23014 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
23015 if (!cursor_row
->enabled_p
)
23016 goto mark_cursor_off
;
23018 /* If line spacing is > 0, old cursor may only be partially visible in
23019 window after split-window. So adjust visible height. */
23020 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
23021 window_text_bottom_y (w
) - cursor_row
->y
);
23023 /* If row is completely invisible, don't attempt to delete a cursor which
23024 isn't there. This can happen if cursor is at top of a window, and
23025 we switch to a buffer with a header line in that window. */
23026 if (cursor_row
->visible_height
<= 0)
23027 goto mark_cursor_off
;
23029 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
23030 if (cursor_row
->cursor_in_fringe_p
)
23032 cursor_row
->cursor_in_fringe_p
= 0;
23033 draw_fringe_bitmap (w
, cursor_row
, 0);
23034 goto mark_cursor_off
;
23037 /* This can happen when the new row is shorter than the old one.
23038 In this case, either draw_glyphs or clear_end_of_line
23039 should have cleared the cursor. Note that we wouldn't be
23040 able to erase the cursor in this case because we don't have a
23041 cursor glyph at hand. */
23042 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
23043 goto mark_cursor_off
;
23045 /* If the cursor is in the mouse face area, redisplay that when
23046 we clear the cursor. */
23047 if (! NILP (dpyinfo
->mouse_face_window
)
23048 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
23049 && (vpos
> dpyinfo
->mouse_face_beg_row
23050 || (vpos
== dpyinfo
->mouse_face_beg_row
23051 && hpos
>= dpyinfo
->mouse_face_beg_col
))
23052 && (vpos
< dpyinfo
->mouse_face_end_row
23053 || (vpos
== dpyinfo
->mouse_face_end_row
23054 && hpos
< dpyinfo
->mouse_face_end_col
))
23055 /* Don't redraw the cursor's spot in mouse face if it is at the
23056 end of a line (on a newline). The cursor appears there, but
23057 mouse highlighting does not. */
23058 && cursor_row
->used
[TEXT_AREA
] > hpos
)
23059 mouse_face_here_p
= 1;
23061 /* Maybe clear the display under the cursor. */
23062 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
23065 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
23068 cursor_glyph
= get_phys_cursor_glyph (w
);
23069 if (cursor_glyph
== NULL
)
23070 goto mark_cursor_off
;
23072 width
= cursor_glyph
->pixel_width
;
23073 left_x
= window_box_left_offset (w
, TEXT_AREA
);
23074 x
= w
->phys_cursor
.x
;
23076 width
-= left_x
- x
;
23077 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
23078 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
23079 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
23082 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
23085 /* Erase the cursor by redrawing the character underneath it. */
23086 if (mouse_face_here_p
)
23087 hl
= DRAW_MOUSE_FACE
;
23089 hl
= DRAW_NORMAL_TEXT
;
23090 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
23093 w
->phys_cursor_on_p
= 0;
23094 w
->phys_cursor_type
= NO_CURSOR
;
23099 Display or clear cursor of window W. If ON is zero, clear the
23100 cursor. If it is non-zero, display the cursor. If ON is nonzero,
23101 where to put the cursor is specified by HPOS, VPOS, X and Y. */
23104 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
23106 int on
, hpos
, vpos
, x
, y
;
23108 struct frame
*f
= XFRAME (w
->frame
);
23109 int new_cursor_type
;
23110 int new_cursor_width
;
23112 struct glyph_row
*glyph_row
;
23113 struct glyph
*glyph
;
23115 /* This is pointless on invisible frames, and dangerous on garbaged
23116 windows and frames; in the latter case, the frame or window may
23117 be in the midst of changing its size, and x and y may be off the
23119 if (! FRAME_VISIBLE_P (f
)
23120 || FRAME_GARBAGED_P (f
)
23121 || vpos
>= w
->current_matrix
->nrows
23122 || hpos
>= w
->current_matrix
->matrix_w
)
23125 /* If cursor is off and we want it off, return quickly. */
23126 if (!on
&& !w
->phys_cursor_on_p
)
23129 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
23130 /* If cursor row is not enabled, we don't really know where to
23131 display the cursor. */
23132 if (!glyph_row
->enabled_p
)
23134 w
->phys_cursor_on_p
= 0;
23139 if (!glyph_row
->exact_window_width_line_p
23140 || hpos
< glyph_row
->used
[TEXT_AREA
])
23141 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
23143 xassert (interrupt_input_blocked
);
23145 /* Set new_cursor_type to the cursor we want to be displayed. */
23146 new_cursor_type
= get_window_cursor_type (w
, glyph
,
23147 &new_cursor_width
, &active_cursor
);
23149 /* If cursor is currently being shown and we don't want it to be or
23150 it is in the wrong place, or the cursor type is not what we want,
23152 if (w
->phys_cursor_on_p
23154 || w
->phys_cursor
.x
!= x
23155 || w
->phys_cursor
.y
!= y
23156 || new_cursor_type
!= w
->phys_cursor_type
23157 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
23158 && new_cursor_width
!= w
->phys_cursor_width
)))
23159 erase_phys_cursor (w
);
23161 /* Don't check phys_cursor_on_p here because that flag is only set
23162 to zero in some cases where we know that the cursor has been
23163 completely erased, to avoid the extra work of erasing the cursor
23164 twice. In other words, phys_cursor_on_p can be 1 and the cursor
23165 still not be visible, or it has only been partly erased. */
23168 w
->phys_cursor_ascent
= glyph_row
->ascent
;
23169 w
->phys_cursor_height
= glyph_row
->height
;
23171 /* Set phys_cursor_.* before x_draw_.* is called because some
23172 of them may need the information. */
23173 w
->phys_cursor
.x
= x
;
23174 w
->phys_cursor
.y
= glyph_row
->y
;
23175 w
->phys_cursor
.hpos
= hpos
;
23176 w
->phys_cursor
.vpos
= vpos
;
23179 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
23180 new_cursor_type
, new_cursor_width
,
23181 on
, active_cursor
);
23185 /* Switch the display of W's cursor on or off, according to the value
23192 update_window_cursor (w
, on
)
23196 /* Don't update cursor in windows whose frame is in the process
23197 of being deleted. */
23198 if (w
->current_matrix
)
23201 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
23202 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
23208 /* Call update_window_cursor with parameter ON_P on all leaf windows
23209 in the window tree rooted at W. */
23212 update_cursor_in_window_tree (w
, on_p
)
23218 if (!NILP (w
->hchild
))
23219 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
23220 else if (!NILP (w
->vchild
))
23221 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
23223 update_window_cursor (w
, on_p
);
23225 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
23231 Display the cursor on window W, or clear it, according to ON_P.
23232 Don't change the cursor's position. */
23235 x_update_cursor (f
, on_p
)
23239 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
23244 Clear the cursor of window W to background color, and mark the
23245 cursor as not shown. This is used when the text where the cursor
23246 is about to be rewritten. */
23252 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
23253 update_window_cursor (w
, 0);
23258 Display the active region described by mouse_face_* according to DRAW. */
23261 show_mouse_face (dpyinfo
, draw
)
23262 Display_Info
*dpyinfo
;
23263 enum draw_glyphs_face draw
;
23265 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
23266 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23268 if (/* If window is in the process of being destroyed, don't bother
23270 w
->current_matrix
!= NULL
23271 /* Don't update mouse highlight if hidden */
23272 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
23273 /* Recognize when we are called to operate on rows that don't exist
23274 anymore. This can happen when a window is split. */
23275 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
23277 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
23278 struct glyph_row
*row
, *first
, *last
;
23280 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
23281 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
23283 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
23285 int start_hpos
, end_hpos
, start_x
;
23287 /* For all but the first row, the highlight starts at column 0. */
23290 start_hpos
= dpyinfo
->mouse_face_beg_col
;
23291 start_x
= dpyinfo
->mouse_face_beg_x
;
23300 end_hpos
= dpyinfo
->mouse_face_end_col
;
23303 end_hpos
= row
->used
[TEXT_AREA
];
23304 if (draw
== DRAW_NORMAL_TEXT
)
23305 row
->fill_line_p
= 1; /* Clear to end of line */
23308 if (end_hpos
> start_hpos
)
23310 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
23311 start_hpos
, end_hpos
,
23315 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
23319 /* When we've written over the cursor, arrange for it to
23320 be displayed again. */
23321 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
23324 display_and_set_cursor (w
, 1,
23325 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
23326 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
23331 /* Change the mouse cursor. */
23332 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
23333 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
23334 else if (draw
== DRAW_MOUSE_FACE
)
23335 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
23337 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
23341 Clear out the mouse-highlighted active region.
23342 Redraw it un-highlighted first. Value is non-zero if mouse
23343 face was actually drawn unhighlighted. */
23346 clear_mouse_face (dpyinfo
)
23347 Display_Info
*dpyinfo
;
23351 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
23353 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
23357 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
23358 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
23359 dpyinfo
->mouse_face_window
= Qnil
;
23360 dpyinfo
->mouse_face_overlay
= Qnil
;
23366 Non-zero if physical cursor of window W is within mouse face. */
23369 cursor_in_mouse_face_p (w
)
23372 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23373 int in_mouse_face
= 0;
23375 if (WINDOWP (dpyinfo
->mouse_face_window
)
23376 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
23378 int hpos
= w
->phys_cursor
.hpos
;
23379 int vpos
= w
->phys_cursor
.vpos
;
23381 if (vpos
>= dpyinfo
->mouse_face_beg_row
23382 && vpos
<= dpyinfo
->mouse_face_end_row
23383 && (vpos
> dpyinfo
->mouse_face_beg_row
23384 || hpos
>= dpyinfo
->mouse_face_beg_col
)
23385 && (vpos
< dpyinfo
->mouse_face_end_row
23386 || hpos
< dpyinfo
->mouse_face_end_col
23387 || dpyinfo
->mouse_face_past_end
))
23391 return in_mouse_face
;
23397 /* This function sets the mouse_face_* elements of DPYINFO, assuming
23398 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
23399 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
23400 for the overlay or run of text properties specifying the mouse
23401 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
23402 before-string and after-string that must also be highlighted.
23403 DISPLAY_STRING, if non-nil, is a display string that may cover some
23404 or all of the highlighted text. */
23407 mouse_face_from_buffer_pos (Lisp_Object window
,
23408 Display_Info
*dpyinfo
,
23409 EMACS_INT mouse_charpos
,
23410 EMACS_INT start_charpos
,
23411 EMACS_INT end_charpos
,
23412 Lisp_Object before_string
,
23413 Lisp_Object after_string
,
23414 Lisp_Object display_string
)
23416 struct window
*w
= XWINDOW (window
);
23417 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
23418 struct glyph_row
*row
;
23419 struct glyph
*glyph
, *end
;
23423 xassert (NILP (display_string
) || STRINGP (display_string
));
23424 xassert (NILP (before_string
) || STRINGP (before_string
));
23425 xassert (NILP (after_string
) || STRINGP (after_string
));
23427 /* Find the first highlighted glyph. */
23428 if (start_charpos
< MATRIX_ROW_START_CHARPOS (first
))
23430 dpyinfo
->mouse_face_beg_col
= 0;
23431 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
23432 dpyinfo
->mouse_face_beg_x
= first
->x
;
23433 dpyinfo
->mouse_face_beg_y
= first
->y
;
23437 row
= row_containing_pos (w
, start_charpos
, first
, NULL
, 0);
23439 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
23441 /* If the before-string or display-string contains newlines,
23442 row_containing_pos skips to its last row. Move back. */
23443 if (!NILP (before_string
) || !NILP (display_string
))
23445 struct glyph_row
*prev
;
23446 while ((prev
= row
- 1, prev
>= first
)
23447 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
23448 && prev
->used
[TEXT_AREA
] > 0)
23450 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
23451 glyph
= beg
+ prev
->used
[TEXT_AREA
];
23452 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
23454 || !(EQ (glyph
->object
, before_string
)
23455 || EQ (glyph
->object
, display_string
)))
23461 glyph
= row
->glyphs
[TEXT_AREA
];
23462 end
= glyph
+ row
->used
[TEXT_AREA
];
23464 dpyinfo
->mouse_face_beg_y
= row
->y
;
23465 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
23467 /* Skip truncation glyphs at the start of the glyph row. */
23468 if (row
->displays_text_p
)
23470 && INTEGERP (glyph
->object
)
23471 && glyph
->charpos
< 0;
23473 x
+= glyph
->pixel_width
;
23475 /* Scan the glyph row, stopping before BEFORE_STRING or
23476 DISPLAY_STRING or START_CHARPOS. */
23478 && !INTEGERP (glyph
->object
)
23479 && !EQ (glyph
->object
, before_string
)
23480 && !EQ (glyph
->object
, display_string
)
23481 && !(BUFFERP (glyph
->object
)
23482 && glyph
->charpos
>= start_charpos
);
23484 x
+= glyph
->pixel_width
;
23486 dpyinfo
->mouse_face_beg_x
= x
;
23487 dpyinfo
->mouse_face_beg_col
= glyph
- row
->glyphs
[TEXT_AREA
];
23490 /* Find the last highlighted glyph. */
23491 row
= row_containing_pos (w
, end_charpos
, first
, NULL
, 0);
23494 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
23495 dpyinfo
->mouse_face_past_end
= 1;
23497 else if (!NILP (after_string
))
23499 /* If the after-string has newlines, advance to its last row. */
23500 struct glyph_row
*next
;
23501 struct glyph_row
*last
23502 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
23504 for (next
= row
+ 1;
23506 && next
->used
[TEXT_AREA
] > 0
23507 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
23512 glyph
= row
->glyphs
[TEXT_AREA
];
23513 end
= glyph
+ row
->used
[TEXT_AREA
];
23515 dpyinfo
->mouse_face_end_y
= row
->y
;
23516 dpyinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
23518 /* Skip truncation glyphs at the start of the row. */
23519 if (row
->displays_text_p
)
23521 && INTEGERP (glyph
->object
)
23522 && glyph
->charpos
< 0;
23524 x
+= glyph
->pixel_width
;
23526 /* Scan the glyph row, stopping at END_CHARPOS or when we encounter
23529 && !INTEGERP (glyph
->object
)
23530 && !EQ (glyph
->object
, after_string
)
23531 && !(BUFFERP (glyph
->object
) && glyph
->charpos
>= end_charpos
);
23533 x
+= glyph
->pixel_width
;
23535 /* If we found AFTER_STRING, consume it and stop. */
23536 if (EQ (glyph
->object
, after_string
))
23538 for (; EQ (glyph
->object
, after_string
) && glyph
< end
; ++glyph
)
23539 x
+= glyph
->pixel_width
;
23543 /* If there's no after-string, we must check if we overshot,
23544 which might be the case if we stopped after a string glyph.
23545 That glyph may belong to a before-string or display-string
23546 associated with the end position, which must not be
23548 Lisp_Object prev_object
;
23551 while (glyph
> row
->glyphs
[TEXT_AREA
])
23553 prev_object
= (glyph
- 1)->object
;
23554 if (!STRINGP (prev_object
) || EQ (prev_object
, display_string
))
23557 pos
= string_buffer_position (w
, prev_object
, end_charpos
);
23558 if (pos
&& pos
< end_charpos
)
23561 for (; glyph
> row
->glyphs
[TEXT_AREA
]
23562 && EQ ((glyph
- 1)->object
, prev_object
);
23564 x
-= (glyph
- 1)->pixel_width
;
23568 dpyinfo
->mouse_face_end_x
= x
;
23569 dpyinfo
->mouse_face_end_col
= glyph
- row
->glyphs
[TEXT_AREA
];
23570 dpyinfo
->mouse_face_window
= window
;
23571 dpyinfo
->mouse_face_face_id
23572 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
23574 !dpyinfo
->mouse_face_hidden
, -1);
23575 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23579 /* Find the position of the glyph for position POS in OBJECT in
23580 window W's current matrix, and return in *X, *Y the pixel
23581 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
23583 RIGHT_P non-zero means return the position of the right edge of the
23584 glyph, RIGHT_P zero means return the left edge position.
23586 If no glyph for POS exists in the matrix, return the position of
23587 the glyph with the next smaller position that is in the matrix, if
23588 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
23589 exists in the matrix, return the position of the glyph with the
23590 next larger position in OBJECT.
23592 Value is non-zero if a glyph was found. */
23595 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
23598 Lisp_Object object
;
23599 int *hpos
, *vpos
, *x
, *y
;
23602 int yb
= window_text_bottom_y (w
);
23603 struct glyph_row
*r
;
23604 struct glyph
*best_glyph
= NULL
;
23605 struct glyph_row
*best_row
= NULL
;
23608 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
23609 r
->enabled_p
&& r
->y
< yb
;
23612 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
23613 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
23616 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
23617 if (EQ (g
->object
, object
))
23619 if (g
->charpos
== pos
)
23626 else if (best_glyph
== NULL
23627 || ((eabs (g
->charpos
- pos
)
23628 < eabs (best_glyph
->charpos
- pos
))
23631 : g
->charpos
> pos
)))
23645 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
23649 *x
+= best_glyph
->pixel_width
;
23654 *vpos
= best_row
- w
->current_matrix
->rows
;
23657 return best_glyph
!= NULL
;
23661 /* See if position X, Y is within a hot-spot of an image. */
23664 on_hot_spot_p (hot_spot
, x
, y
)
23665 Lisp_Object hot_spot
;
23668 if (!CONSP (hot_spot
))
23671 if (EQ (XCAR (hot_spot
), Qrect
))
23673 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
23674 Lisp_Object rect
= XCDR (hot_spot
);
23678 if (!CONSP (XCAR (rect
)))
23680 if (!CONSP (XCDR (rect
)))
23682 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
23684 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
23686 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
23688 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
23692 else if (EQ (XCAR (hot_spot
), Qcircle
))
23694 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
23695 Lisp_Object circ
= XCDR (hot_spot
);
23696 Lisp_Object lr
, lx0
, ly0
;
23698 && CONSP (XCAR (circ
))
23699 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
23700 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
23701 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
23703 double r
= XFLOATINT (lr
);
23704 double dx
= XINT (lx0
) - x
;
23705 double dy
= XINT (ly0
) - y
;
23706 return (dx
* dx
+ dy
* dy
<= r
* r
);
23709 else if (EQ (XCAR (hot_spot
), Qpoly
))
23711 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
23712 if (VECTORP (XCDR (hot_spot
)))
23714 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
23715 Lisp_Object
*poly
= v
->contents
;
23719 Lisp_Object lx
, ly
;
23722 /* Need an even number of coordinates, and at least 3 edges. */
23723 if (n
< 6 || n
& 1)
23726 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
23727 If count is odd, we are inside polygon. Pixels on edges
23728 may or may not be included depending on actual geometry of the
23730 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
23731 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
23733 x0
= XINT (lx
), y0
= XINT (ly
);
23734 for (i
= 0; i
< n
; i
+= 2)
23736 int x1
= x0
, y1
= y0
;
23737 if ((lx
= poly
[i
], !INTEGERP (lx
))
23738 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
23740 x0
= XINT (lx
), y0
= XINT (ly
);
23742 /* Does this segment cross the X line? */
23750 if (y
> y0
&& y
> y1
)
23752 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
23762 find_hot_spot (map
, x
, y
)
23766 while (CONSP (map
))
23768 if (CONSP (XCAR (map
))
23769 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
23777 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
23779 doc
: /* Lookup in image map MAP coordinates X and Y.
23780 An image map is an alist where each element has the format (AREA ID PLIST).
23781 An AREA is specified as either a rectangle, a circle, or a polygon:
23782 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
23783 pixel coordinates of the upper left and bottom right corners.
23784 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
23785 and the radius of the circle; r may be a float or integer.
23786 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
23787 vector describes one corner in the polygon.
23788 Returns the alist element for the first matching AREA in MAP. */)
23799 return find_hot_spot (map
, XINT (x
), XINT (y
));
23803 /* Display frame CURSOR, optionally using shape defined by POINTER. */
23805 define_frame_cursor1 (f
, cursor
, pointer
)
23808 Lisp_Object pointer
;
23810 /* Do not change cursor shape while dragging mouse. */
23811 if (!NILP (do_mouse_tracking
))
23814 if (!NILP (pointer
))
23816 if (EQ (pointer
, Qarrow
))
23817 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23818 else if (EQ (pointer
, Qhand
))
23819 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
23820 else if (EQ (pointer
, Qtext
))
23821 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23822 else if (EQ (pointer
, intern ("hdrag")))
23823 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23824 #ifdef HAVE_X_WINDOWS
23825 else if (EQ (pointer
, intern ("vdrag")))
23826 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
23828 else if (EQ (pointer
, intern ("hourglass")))
23829 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
23830 else if (EQ (pointer
, Qmodeline
))
23831 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
23833 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23836 if (cursor
!= No_Cursor
)
23837 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
23840 /* Take proper action when mouse has moved to the mode or header line
23841 or marginal area AREA of window W, x-position X and y-position Y.
23842 X is relative to the start of the text display area of W, so the
23843 width of bitmap areas and scroll bars must be subtracted to get a
23844 position relative to the start of the mode line. */
23847 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
23848 Lisp_Object window
;
23850 enum window_part area
;
23852 struct window
*w
= XWINDOW (window
);
23853 struct frame
*f
= XFRAME (w
->frame
);
23854 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23855 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23856 Lisp_Object pointer
= Qnil
;
23857 int charpos
, dx
, dy
, width
, height
;
23858 Lisp_Object string
, object
= Qnil
;
23859 Lisp_Object pos
, help
;
23861 Lisp_Object mouse_face
;
23862 int original_x_pixel
= x
;
23863 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
23864 struct glyph_row
*row
;
23866 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
23871 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
23872 &object
, &dx
, &dy
, &width
, &height
);
23874 row
= (area
== ON_MODE_LINE
23875 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
23876 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
23879 if (row
->mode_line_p
&& row
->enabled_p
)
23881 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
23882 end
= glyph
+ row
->used
[TEXT_AREA
];
23884 for (x0
= original_x_pixel
;
23885 glyph
< end
&& x0
>= glyph
->pixel_width
;
23887 x0
-= glyph
->pixel_width
;
23895 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
23896 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
23897 &object
, &dx
, &dy
, &width
, &height
);
23902 if (IMAGEP (object
))
23904 Lisp_Object image_map
, hotspot
;
23905 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
23907 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
23909 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23911 Lisp_Object area_id
, plist
;
23913 area_id
= XCAR (hotspot
);
23914 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23915 If so, we could look for mouse-enter, mouse-leave
23916 properties in PLIST (and do something...). */
23917 hotspot
= XCDR (hotspot
);
23918 if (CONSP (hotspot
)
23919 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23921 pointer
= Fplist_get (plist
, Qpointer
);
23922 if (NILP (pointer
))
23924 help
= Fplist_get (plist
, Qhelp_echo
);
23927 help_echo_string
= help
;
23928 /* Is this correct? ++kfs */
23929 XSETWINDOW (help_echo_window
, w
);
23930 help_echo_object
= w
->buffer
;
23931 help_echo_pos
= charpos
;
23935 if (NILP (pointer
))
23936 pointer
= Fplist_get (XCDR (object
), QCpointer
);
23939 if (STRINGP (string
))
23941 pos
= make_number (charpos
);
23942 /* If we're on a string with `help-echo' text property, arrange
23943 for the help to be displayed. This is done by setting the
23944 global variable help_echo_string to the help string. */
23947 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
23950 help_echo_string
= help
;
23951 XSETWINDOW (help_echo_window
, w
);
23952 help_echo_object
= string
;
23953 help_echo_pos
= charpos
;
23957 if (NILP (pointer
))
23958 pointer
= Fget_text_property (pos
, Qpointer
, string
);
23960 /* Change the mouse pointer according to what is under X/Y. */
23961 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
23964 map
= Fget_text_property (pos
, Qlocal_map
, string
);
23965 if (!KEYMAPP (map
))
23966 map
= Fget_text_property (pos
, Qkeymap
, string
);
23967 if (!KEYMAPP (map
))
23968 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
23971 /* Change the mouse face according to what is under X/Y. */
23972 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
23973 if (!NILP (mouse_face
)
23974 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23979 struct glyph
* tmp_glyph
;
23983 int total_pixel_width
;
23988 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
23989 Qmouse_face
, string
, Qnil
);
23991 b
= make_number (0);
23993 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
23995 e
= make_number (SCHARS (string
));
23997 /* Calculate the position(glyph position: GPOS) of GLYPH in
23998 displayed string. GPOS is different from CHARPOS.
24000 CHARPOS is the position of glyph in internal string
24001 object. A mode line string format has structures which
24002 is converted to a flatten by emacs lisp interpreter.
24003 The internal string is an element of the structures.
24004 The displayed string is the flatten string. */
24006 if (glyph
> row_start_glyph
)
24008 tmp_glyph
= glyph
- 1;
24009 while (tmp_glyph
>= row_start_glyph
24010 && tmp_glyph
->charpos
>= XINT (b
)
24011 && EQ (tmp_glyph
->object
, glyph
->object
))
24018 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
24019 displayed string holding GLYPH.
24021 GSEQ_LENGTH is different from SCHARS (STRING).
24022 SCHARS (STRING) returns the length of the internal string. */
24023 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
24024 tmp_glyph
->charpos
< XINT (e
);
24025 tmp_glyph
++, gseq_length
++)
24027 if (!EQ (tmp_glyph
->object
, glyph
->object
))
24031 total_pixel_width
= 0;
24032 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
24033 total_pixel_width
+= tmp_glyph
->pixel_width
;
24035 /* Pre calculation of re-rendering position */
24037 hpos
= (area
== ON_MODE_LINE
24038 ? (w
->current_matrix
)->nrows
- 1
24041 /* If the re-rendering position is included in the last
24042 re-rendering area, we should do nothing. */
24043 if ( EQ (window
, dpyinfo
->mouse_face_window
)
24044 && dpyinfo
->mouse_face_beg_col
<= vpos
24045 && vpos
< dpyinfo
->mouse_face_end_col
24046 && dpyinfo
->mouse_face_beg_row
== hpos
)
24049 if (clear_mouse_face (dpyinfo
))
24050 cursor
= No_Cursor
;
24052 dpyinfo
->mouse_face_beg_col
= vpos
;
24053 dpyinfo
->mouse_face_beg_row
= hpos
;
24055 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
24056 dpyinfo
->mouse_face_beg_y
= 0;
24058 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
24059 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
24061 dpyinfo
->mouse_face_end_x
= 0;
24062 dpyinfo
->mouse_face_end_y
= 0;
24064 dpyinfo
->mouse_face_past_end
= 0;
24065 dpyinfo
->mouse_face_window
= window
;
24067 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
24070 glyph
->face_id
, 1);
24071 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
24073 if (NILP (pointer
))
24076 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
24077 clear_mouse_face (dpyinfo
);
24079 define_frame_cursor1 (f
, cursor
, pointer
);
24084 Take proper action when the mouse has moved to position X, Y on
24085 frame F as regards highlighting characters that have mouse-face
24086 properties. Also de-highlighting chars where the mouse was before.
24087 X and Y can be negative or out of range. */
24090 note_mouse_highlight (f
, x
, y
)
24094 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24095 enum window_part part
;
24096 Lisp_Object window
;
24098 Cursor cursor
= No_Cursor
;
24099 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
24102 /* When a menu is active, don't highlight because this looks odd. */
24103 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
24104 if (popup_activated ())
24108 if (NILP (Vmouse_highlight
)
24109 || !f
->glyphs_initialized_p
)
24112 dpyinfo
->mouse_face_mouse_x
= x
;
24113 dpyinfo
->mouse_face_mouse_y
= y
;
24114 dpyinfo
->mouse_face_mouse_frame
= f
;
24116 if (dpyinfo
->mouse_face_defer
)
24119 if (gc_in_progress
)
24121 dpyinfo
->mouse_face_deferred_gc
= 1;
24125 /* Which window is that in? */
24126 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
24128 /* If we were displaying active text in another window, clear that.
24129 Also clear if we move out of text area in same window. */
24130 if (! EQ (window
, dpyinfo
->mouse_face_window
)
24131 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
24132 && !NILP (dpyinfo
->mouse_face_window
)))
24133 clear_mouse_face (dpyinfo
);
24135 /* Not on a window -> return. */
24136 if (!WINDOWP (window
))
24139 /* Reset help_echo_string. It will get recomputed below. */
24140 help_echo_string
= Qnil
;
24142 /* Convert to window-relative pixel coordinates. */
24143 w
= XWINDOW (window
);
24144 frame_to_window_pixel_xy (w
, &x
, &y
);
24146 /* Handle tool-bar window differently since it doesn't display a
24148 if (EQ (window
, f
->tool_bar_window
))
24150 note_tool_bar_highlight (f
, x
, y
);
24154 /* Mouse is on the mode, header line or margin? */
24155 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
24156 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
24158 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
24162 if (part
== ON_VERTICAL_BORDER
)
24164 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
24165 help_echo_string
= build_string ("drag-mouse-1: resize");
24167 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
24168 || part
== ON_SCROLL_BAR
)
24169 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24171 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
24173 /* Are we in a window whose display is up to date?
24174 And verify the buffer's text has not changed. */
24175 b
= XBUFFER (w
->buffer
);
24176 if (part
== ON_TEXT
24177 && EQ (w
->window_end_valid
, w
->buffer
)
24178 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
24179 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
24181 int hpos
, vpos
, i
, dx
, dy
, area
;
24183 struct glyph
*glyph
;
24184 Lisp_Object object
;
24185 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
24186 Lisp_Object
*overlay_vec
= NULL
;
24188 struct buffer
*obuf
;
24189 int obegv
, ozv
, same_region
;
24191 /* Find the glyph under X/Y. */
24192 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
24194 /* Look for :pointer property on image. */
24195 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
24197 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
24198 if (img
!= NULL
&& IMAGEP (img
->spec
))
24200 Lisp_Object image_map
, hotspot
;
24201 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
24203 && (hotspot
= find_hot_spot (image_map
,
24204 glyph
->slice
.x
+ dx
,
24205 glyph
->slice
.y
+ dy
),
24207 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
24209 Lisp_Object area_id
, plist
;
24211 area_id
= XCAR (hotspot
);
24212 /* Could check AREA_ID to see if we enter/leave this hot-spot.
24213 If so, we could look for mouse-enter, mouse-leave
24214 properties in PLIST (and do something...). */
24215 hotspot
= XCDR (hotspot
);
24216 if (CONSP (hotspot
)
24217 && (plist
= XCAR (hotspot
), CONSP (plist
)))
24219 pointer
= Fplist_get (plist
, Qpointer
);
24220 if (NILP (pointer
))
24222 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
24223 if (!NILP (help_echo_string
))
24225 help_echo_window
= window
;
24226 help_echo_object
= glyph
->object
;
24227 help_echo_pos
= glyph
->charpos
;
24231 if (NILP (pointer
))
24232 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
24236 /* Clear mouse face if X/Y not over text. */
24238 || area
!= TEXT_AREA
24239 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
24241 if (clear_mouse_face (dpyinfo
))
24242 cursor
= No_Cursor
;
24243 if (NILP (pointer
))
24245 if (area
!= TEXT_AREA
)
24246 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24248 pointer
= Vvoid_text_area_pointer
;
24253 pos
= glyph
->charpos
;
24254 object
= glyph
->object
;
24255 if (!STRINGP (object
) && !BUFFERP (object
))
24258 /* If we get an out-of-range value, return now; avoid an error. */
24259 if (BUFFERP (object
) && pos
> BUF_Z (b
))
24262 /* Make the window's buffer temporarily current for
24263 overlays_at and compute_char_face. */
24264 obuf
= current_buffer
;
24265 current_buffer
= b
;
24271 /* Is this char mouse-active or does it have help-echo? */
24272 position
= make_number (pos
);
24274 if (BUFFERP (object
))
24276 /* Put all the overlays we want in a vector in overlay_vec. */
24277 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
24278 /* Sort overlays into increasing priority order. */
24279 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
24284 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
24285 && vpos
>= dpyinfo
->mouse_face_beg_row
24286 && vpos
<= dpyinfo
->mouse_face_end_row
24287 && (vpos
> dpyinfo
->mouse_face_beg_row
24288 || hpos
>= dpyinfo
->mouse_face_beg_col
)
24289 && (vpos
< dpyinfo
->mouse_face_end_row
24290 || hpos
< dpyinfo
->mouse_face_end_col
24291 || dpyinfo
->mouse_face_past_end
));
24294 cursor
= No_Cursor
;
24296 /* Check mouse-face highlighting. */
24298 /* If there exists an overlay with mouse-face overlapping
24299 the one we are currently highlighting, we have to
24300 check if we enter the overlapping overlay, and then
24301 highlight only that. */
24302 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
24303 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
24305 /* Find the highest priority overlay with a mouse-face. */
24307 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
24309 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
24310 if (!NILP (mouse_face
))
24311 overlay
= overlay_vec
[i
];
24314 /* If we're highlighting the same overlay as before, there's
24315 no need to do that again. */
24316 if (!NILP (overlay
) && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
24317 goto check_help_echo
;
24318 dpyinfo
->mouse_face_overlay
= overlay
;
24320 /* Clear the display of the old active region, if any. */
24321 if (clear_mouse_face (dpyinfo
))
24322 cursor
= No_Cursor
;
24324 /* If no overlay applies, get a text property. */
24325 if (NILP (overlay
))
24326 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
24328 /* Next, compute the bounds of the mouse highlighting and
24330 if (!NILP (mouse_face
) && STRINGP (object
))
24332 /* The mouse-highlighting comes from a display string
24333 with a mouse-face. */
24337 b
= Fprevious_single_property_change
24338 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
24339 e
= Fnext_single_property_change
24340 (position
, Qmouse_face
, object
, Qnil
);
24342 b
= make_number (0);
24344 e
= make_number (SCHARS (object
) - 1);
24346 fast_find_string_pos (w
, XINT (b
), object
,
24347 &dpyinfo
->mouse_face_beg_col
,
24348 &dpyinfo
->mouse_face_beg_row
,
24349 &dpyinfo
->mouse_face_beg_x
,
24350 &dpyinfo
->mouse_face_beg_y
, 0);
24351 fast_find_string_pos (w
, XINT (e
), object
,
24352 &dpyinfo
->mouse_face_end_col
,
24353 &dpyinfo
->mouse_face_end_row
,
24354 &dpyinfo
->mouse_face_end_x
,
24355 &dpyinfo
->mouse_face_end_y
, 1);
24356 dpyinfo
->mouse_face_past_end
= 0;
24357 dpyinfo
->mouse_face_window
= window
;
24358 dpyinfo
->mouse_face_face_id
24359 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
24360 glyph
->face_id
, 1);
24361 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
24362 cursor
= No_Cursor
;
24366 /* The mouse-highlighting, if any, comes from an overlay
24367 or text property in the buffer. */
24368 Lisp_Object buffer
, display_string
;
24370 if (STRINGP (object
))
24372 /* If we are on a display string with no mouse-face,
24373 check if the text under it has one. */
24374 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
24375 int start
= MATRIX_ROW_START_CHARPOS (r
);
24376 pos
= string_buffer_position (w
, object
, start
);
24379 mouse_face
= get_char_property_and_overlay
24380 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
24381 buffer
= w
->buffer
;
24382 display_string
= object
;
24388 display_string
= Qnil
;
24391 if (!NILP (mouse_face
))
24393 Lisp_Object before
, after
;
24394 Lisp_Object before_string
, after_string
;
24396 if (NILP (overlay
))
24398 /* Handle the text property case. */
24399 before
= Fprevious_single_property_change
24400 (make_number (pos
+ 1), Qmouse_face
, buffer
,
24401 Fmarker_position (w
->start
));
24402 after
= Fnext_single_property_change
24403 (make_number (pos
), Qmouse_face
, buffer
,
24404 make_number (BUF_Z (XBUFFER (buffer
))
24405 - XFASTINT (w
->window_end_pos
)));
24406 before_string
= after_string
= Qnil
;
24410 /* Handle the overlay case. */
24411 before
= Foverlay_start (overlay
);
24412 after
= Foverlay_end (overlay
);
24413 before_string
= Foverlay_get (overlay
, Qbefore_string
);
24414 after_string
= Foverlay_get (overlay
, Qafter_string
);
24416 if (!STRINGP (before_string
)) before_string
= Qnil
;
24417 if (!STRINGP (after_string
)) after_string
= Qnil
;
24420 mouse_face_from_buffer_pos (window
, dpyinfo
, pos
,
24423 before_string
, after_string
,
24425 cursor
= No_Cursor
;
24432 /* Look for a `help-echo' property. */
24433 if (NILP (help_echo_string
)) {
24434 Lisp_Object help
, overlay
;
24436 /* Check overlays first. */
24437 help
= overlay
= Qnil
;
24438 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
24440 overlay
= overlay_vec
[i
];
24441 help
= Foverlay_get (overlay
, Qhelp_echo
);
24446 help_echo_string
= help
;
24447 help_echo_window
= window
;
24448 help_echo_object
= overlay
;
24449 help_echo_pos
= pos
;
24453 Lisp_Object object
= glyph
->object
;
24454 int charpos
= glyph
->charpos
;
24456 /* Try text properties. */
24457 if (STRINGP (object
)
24459 && charpos
< SCHARS (object
))
24461 help
= Fget_text_property (make_number (charpos
),
24462 Qhelp_echo
, object
);
24465 /* If the string itself doesn't specify a help-echo,
24466 see if the buffer text ``under'' it does. */
24467 struct glyph_row
*r
24468 = MATRIX_ROW (w
->current_matrix
, vpos
);
24469 int start
= MATRIX_ROW_START_CHARPOS (r
);
24470 EMACS_INT pos
= string_buffer_position (w
, object
, start
);
24473 help
= Fget_char_property (make_number (pos
),
24474 Qhelp_echo
, w
->buffer
);
24478 object
= w
->buffer
;
24483 else if (BUFFERP (object
)
24486 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
24491 help_echo_string
= help
;
24492 help_echo_window
= window
;
24493 help_echo_object
= object
;
24494 help_echo_pos
= charpos
;
24499 /* Look for a `pointer' property. */
24500 if (NILP (pointer
))
24502 /* Check overlays first. */
24503 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
24504 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
24506 if (NILP (pointer
))
24508 Lisp_Object object
= glyph
->object
;
24509 int charpos
= glyph
->charpos
;
24511 /* Try text properties. */
24512 if (STRINGP (object
)
24514 && charpos
< SCHARS (object
))
24516 pointer
= Fget_text_property (make_number (charpos
),
24518 if (NILP (pointer
))
24520 /* If the string itself doesn't specify a pointer,
24521 see if the buffer text ``under'' it does. */
24522 struct glyph_row
*r
24523 = MATRIX_ROW (w
->current_matrix
, vpos
);
24524 int start
= MATRIX_ROW_START_CHARPOS (r
);
24525 EMACS_INT pos
= string_buffer_position (w
, object
,
24528 pointer
= Fget_char_property (make_number (pos
),
24529 Qpointer
, w
->buffer
);
24532 else if (BUFFERP (object
)
24535 pointer
= Fget_text_property (make_number (charpos
),
24542 current_buffer
= obuf
;
24547 define_frame_cursor1 (f
, cursor
, pointer
);
24552 Clear any mouse-face on window W. This function is part of the
24553 redisplay interface, and is called from try_window_id and similar
24554 functions to ensure the mouse-highlight is off. */
24557 x_clear_window_mouse_face (w
)
24560 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
24561 Lisp_Object window
;
24564 XSETWINDOW (window
, w
);
24565 if (EQ (window
, dpyinfo
->mouse_face_window
))
24566 clear_mouse_face (dpyinfo
);
24572 Just discard the mouse face information for frame F, if any.
24573 This is used when the size of F is changed. */
24576 cancel_mouse_face (f
)
24579 Lisp_Object window
;
24580 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24582 window
= dpyinfo
->mouse_face_window
;
24583 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
24585 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
24586 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
24587 dpyinfo
->mouse_face_window
= Qnil
;
24592 #endif /* HAVE_WINDOW_SYSTEM */
24595 /***********************************************************************
24597 ***********************************************************************/
24599 #ifdef HAVE_WINDOW_SYSTEM
24601 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
24602 which intersects rectangle R. R is in window-relative coordinates. */
24605 expose_area (w
, row
, r
, area
)
24607 struct glyph_row
*row
;
24609 enum glyph_row_area area
;
24611 struct glyph
*first
= row
->glyphs
[area
];
24612 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
24613 struct glyph
*last
;
24614 int first_x
, start_x
, x
;
24616 if (area
== TEXT_AREA
&& row
->fill_line_p
)
24617 /* If row extends face to end of line write the whole line. */
24618 draw_glyphs (w
, 0, row
, area
,
24619 0, row
->used
[area
],
24620 DRAW_NORMAL_TEXT
, 0);
24623 /* Set START_X to the window-relative start position for drawing glyphs of
24624 AREA. The first glyph of the text area can be partially visible.
24625 The first glyphs of other areas cannot. */
24626 start_x
= window_box_left_offset (w
, area
);
24628 if (area
== TEXT_AREA
)
24631 /* Find the first glyph that must be redrawn. */
24633 && x
+ first
->pixel_width
< r
->x
)
24635 x
+= first
->pixel_width
;
24639 /* Find the last one. */
24643 && x
< r
->x
+ r
->width
)
24645 x
+= last
->pixel_width
;
24651 draw_glyphs (w
, first_x
- start_x
, row
, area
,
24652 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
24653 DRAW_NORMAL_TEXT
, 0);
24658 /* Redraw the parts of the glyph row ROW on window W intersecting
24659 rectangle R. R is in window-relative coordinates. Value is
24660 non-zero if mouse-face was overwritten. */
24663 expose_line (w
, row
, r
)
24665 struct glyph_row
*row
;
24668 xassert (row
->enabled_p
);
24670 if (row
->mode_line_p
|| w
->pseudo_window_p
)
24671 draw_glyphs (w
, 0, row
, TEXT_AREA
,
24672 0, row
->used
[TEXT_AREA
],
24673 DRAW_NORMAL_TEXT
, 0);
24676 if (row
->used
[LEFT_MARGIN_AREA
])
24677 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
24678 if (row
->used
[TEXT_AREA
])
24679 expose_area (w
, row
, r
, TEXT_AREA
);
24680 if (row
->used
[RIGHT_MARGIN_AREA
])
24681 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
24682 draw_row_fringe_bitmaps (w
, row
);
24685 return row
->mouse_face_p
;
24689 /* Redraw those parts of glyphs rows during expose event handling that
24690 overlap other rows. Redrawing of an exposed line writes over parts
24691 of lines overlapping that exposed line; this function fixes that.
24693 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
24694 row in W's current matrix that is exposed and overlaps other rows.
24695 LAST_OVERLAPPING_ROW is the last such row. */
24698 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
, r
)
24700 struct glyph_row
*first_overlapping_row
;
24701 struct glyph_row
*last_overlapping_row
;
24704 struct glyph_row
*row
;
24706 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
24707 if (row
->overlapping_p
)
24709 xassert (row
->enabled_p
&& !row
->mode_line_p
);
24712 if (row
->used
[LEFT_MARGIN_AREA
])
24713 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
24715 if (row
->used
[TEXT_AREA
])
24716 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
24718 if (row
->used
[RIGHT_MARGIN_AREA
])
24719 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
24725 /* Return non-zero if W's cursor intersects rectangle R. */
24728 phys_cursor_in_rect_p (w
, r
)
24732 XRectangle cr
, result
;
24733 struct glyph
*cursor_glyph
;
24734 struct glyph_row
*row
;
24736 if (w
->phys_cursor
.vpos
>= 0
24737 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
24738 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
24740 && row
->cursor_in_fringe_p
)
24742 /* Cursor is in the fringe. */
24743 cr
.x
= window_box_right_offset (w
,
24744 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
24745 ? RIGHT_MARGIN_AREA
24748 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
24749 cr
.height
= row
->height
;
24750 return x_intersect_rectangles (&cr
, r
, &result
);
24753 cursor_glyph
= get_phys_cursor_glyph (w
);
24756 /* r is relative to W's box, but w->phys_cursor.x is relative
24757 to left edge of W's TEXT area. Adjust it. */
24758 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
24759 cr
.y
= w
->phys_cursor
.y
;
24760 cr
.width
= cursor_glyph
->pixel_width
;
24761 cr
.height
= w
->phys_cursor_height
;
24762 /* ++KFS: W32 version used W32-specific IntersectRect here, but
24763 I assume the effect is the same -- and this is portable. */
24764 return x_intersect_rectangles (&cr
, r
, &result
);
24766 /* If we don't understand the format, pretend we're not in the hot-spot. */
24772 Draw a vertical window border to the right of window W if W doesn't
24773 have vertical scroll bars. */
24776 x_draw_vertical_border (w
)
24779 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24781 /* We could do better, if we knew what type of scroll-bar the adjacent
24782 windows (on either side) have... But we don't :-(
24783 However, I think this works ok. ++KFS 2003-04-25 */
24785 /* Redraw borders between horizontally adjacent windows. Don't
24786 do it for frames with vertical scroll bars because either the
24787 right scroll bar of a window, or the left scroll bar of its
24788 neighbor will suffice as a border. */
24789 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
24792 if (!WINDOW_RIGHTMOST_P (w
)
24793 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
24795 int x0
, x1
, y0
, y1
;
24797 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24800 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24803 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
24805 else if (!WINDOW_LEFTMOST_P (w
)
24806 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
24808 int x0
, x1
, y0
, y1
;
24810 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24813 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24816 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
24821 /* Redraw the part of window W intersection rectangle FR. Pixel
24822 coordinates in FR are frame-relative. Call this function with
24823 input blocked. Value is non-zero if the exposure overwrites
24827 expose_window (w
, fr
)
24831 struct frame
*f
= XFRAME (w
->frame
);
24833 int mouse_face_overwritten_p
= 0;
24835 /* If window is not yet fully initialized, do nothing. This can
24836 happen when toolkit scroll bars are used and a window is split.
24837 Reconfiguring the scroll bar will generate an expose for a newly
24839 if (w
->current_matrix
== NULL
)
24842 /* When we're currently updating the window, display and current
24843 matrix usually don't agree. Arrange for a thorough display
24845 if (w
== updated_window
)
24847 SET_FRAME_GARBAGED (f
);
24851 /* Frame-relative pixel rectangle of W. */
24852 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
24853 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
24854 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
24855 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
24857 if (x_intersect_rectangles (fr
, &wr
, &r
))
24859 int yb
= window_text_bottom_y (w
);
24860 struct glyph_row
*row
;
24861 int cursor_cleared_p
;
24862 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
24864 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
24865 r
.x
, r
.y
, r
.width
, r
.height
));
24867 /* Convert to window coordinates. */
24868 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
24869 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
24871 /* Turn off the cursor. */
24872 if (!w
->pseudo_window_p
24873 && phys_cursor_in_rect_p (w
, &r
))
24875 x_clear_cursor (w
);
24876 cursor_cleared_p
= 1;
24879 cursor_cleared_p
= 0;
24881 /* Update lines intersecting rectangle R. */
24882 first_overlapping_row
= last_overlapping_row
= NULL
;
24883 for (row
= w
->current_matrix
->rows
;
24888 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
24890 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
24891 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
24892 || (r
.y
>= y0
&& r
.y
< y1
)
24893 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
24895 /* A header line may be overlapping, but there is no need
24896 to fix overlapping areas for them. KFS 2005-02-12 */
24897 if (row
->overlapping_p
&& !row
->mode_line_p
)
24899 if (first_overlapping_row
== NULL
)
24900 first_overlapping_row
= row
;
24901 last_overlapping_row
= row
;
24905 if (expose_line (w
, row
, &r
))
24906 mouse_face_overwritten_p
= 1;
24909 else if (row
->overlapping_p
)
24911 /* We must redraw a row overlapping the exposed area. */
24913 ? y0
+ row
->phys_height
> r
.y
24914 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
24916 if (first_overlapping_row
== NULL
)
24917 first_overlapping_row
= row
;
24918 last_overlapping_row
= row
;
24926 /* Display the mode line if there is one. */
24927 if (WINDOW_WANTS_MODELINE_P (w
)
24928 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
24930 && row
->y
< r
.y
+ r
.height
)
24932 if (expose_line (w
, row
, &r
))
24933 mouse_face_overwritten_p
= 1;
24936 if (!w
->pseudo_window_p
)
24938 /* Fix the display of overlapping rows. */
24939 if (first_overlapping_row
)
24940 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
24943 /* Draw border between windows. */
24944 x_draw_vertical_border (w
);
24946 /* Turn the cursor on again. */
24947 if (cursor_cleared_p
)
24948 update_window_cursor (w
, 1);
24952 return mouse_face_overwritten_p
;
24957 /* Redraw (parts) of all windows in the window tree rooted at W that
24958 intersect R. R contains frame pixel coordinates. Value is
24959 non-zero if the exposure overwrites mouse-face. */
24962 expose_window_tree (w
, r
)
24966 struct frame
*f
= XFRAME (w
->frame
);
24967 int mouse_face_overwritten_p
= 0;
24969 while (w
&& !FRAME_GARBAGED_P (f
))
24971 if (!NILP (w
->hchild
))
24972 mouse_face_overwritten_p
24973 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
24974 else if (!NILP (w
->vchild
))
24975 mouse_face_overwritten_p
24976 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
24978 mouse_face_overwritten_p
|= expose_window (w
, r
);
24980 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
24983 return mouse_face_overwritten_p
;
24988 Redisplay an exposed area of frame F. X and Y are the upper-left
24989 corner of the exposed rectangle. W and H are width and height of
24990 the exposed area. All are pixel values. W or H zero means redraw
24991 the entire frame. */
24994 expose_frame (f
, x
, y
, w
, h
)
24999 int mouse_face_overwritten_p
= 0;
25001 TRACE ((stderr
, "expose_frame "));
25003 /* No need to redraw if frame will be redrawn soon. */
25004 if (FRAME_GARBAGED_P (f
))
25006 TRACE ((stderr
, " garbaged\n"));
25010 /* If basic faces haven't been realized yet, there is no point in
25011 trying to redraw anything. This can happen when we get an expose
25012 event while Emacs is starting, e.g. by moving another window. */
25013 if (FRAME_FACE_CACHE (f
) == NULL
25014 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
25016 TRACE ((stderr
, " no faces\n"));
25020 if (w
== 0 || h
== 0)
25023 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
25024 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
25034 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
25035 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
25037 if (WINDOWP (f
->tool_bar_window
))
25038 mouse_face_overwritten_p
25039 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
25041 #ifdef HAVE_X_WINDOWS
25043 #ifndef USE_X_TOOLKIT
25044 if (WINDOWP (f
->menu_bar_window
))
25045 mouse_face_overwritten_p
25046 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
25047 #endif /* not USE_X_TOOLKIT */
25051 /* Some window managers support a focus-follows-mouse style with
25052 delayed raising of frames. Imagine a partially obscured frame,
25053 and moving the mouse into partially obscured mouse-face on that
25054 frame. The visible part of the mouse-face will be highlighted,
25055 then the WM raises the obscured frame. With at least one WM, KDE
25056 2.1, Emacs is not getting any event for the raising of the frame
25057 (even tried with SubstructureRedirectMask), only Expose events.
25058 These expose events will draw text normally, i.e. not
25059 highlighted. Which means we must redo the highlight here.
25060 Subsume it under ``we love X''. --gerd 2001-08-15 */
25061 /* Included in Windows version because Windows most likely does not
25062 do the right thing if any third party tool offers
25063 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
25064 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
25066 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
25067 if (f
== dpyinfo
->mouse_face_mouse_frame
)
25069 int x
= dpyinfo
->mouse_face_mouse_x
;
25070 int y
= dpyinfo
->mouse_face_mouse_y
;
25071 clear_mouse_face (dpyinfo
);
25072 note_mouse_highlight (f
, x
, y
);
25079 Determine the intersection of two rectangles R1 and R2. Return
25080 the intersection in *RESULT. Value is non-zero if RESULT is not
25084 x_intersect_rectangles (r1
, r2
, result
)
25085 XRectangle
*r1
, *r2
, *result
;
25087 XRectangle
*left
, *right
;
25088 XRectangle
*upper
, *lower
;
25089 int intersection_p
= 0;
25091 /* Rearrange so that R1 is the left-most rectangle. */
25093 left
= r1
, right
= r2
;
25095 left
= r2
, right
= r1
;
25097 /* X0 of the intersection is right.x0, if this is inside R1,
25098 otherwise there is no intersection. */
25099 if (right
->x
<= left
->x
+ left
->width
)
25101 result
->x
= right
->x
;
25103 /* The right end of the intersection is the minimum of the
25104 the right ends of left and right. */
25105 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
25108 /* Same game for Y. */
25110 upper
= r1
, lower
= r2
;
25112 upper
= r2
, lower
= r1
;
25114 /* The upper end of the intersection is lower.y0, if this is inside
25115 of upper. Otherwise, there is no intersection. */
25116 if (lower
->y
<= upper
->y
+ upper
->height
)
25118 result
->y
= lower
->y
;
25120 /* The lower end of the intersection is the minimum of the lower
25121 ends of upper and lower. */
25122 result
->height
= (min (lower
->y
+ lower
->height
,
25123 upper
->y
+ upper
->height
)
25125 intersection_p
= 1;
25129 return intersection_p
;
25132 #endif /* HAVE_WINDOW_SYSTEM */
25135 /***********************************************************************
25137 ***********************************************************************/
25142 Vwith_echo_area_save_vector
= Qnil
;
25143 staticpro (&Vwith_echo_area_save_vector
);
25145 Vmessage_stack
= Qnil
;
25146 staticpro (&Vmessage_stack
);
25148 Qinhibit_redisplay
= intern_c_string ("inhibit-redisplay");
25149 staticpro (&Qinhibit_redisplay
);
25151 message_dolog_marker1
= Fmake_marker ();
25152 staticpro (&message_dolog_marker1
);
25153 message_dolog_marker2
= Fmake_marker ();
25154 staticpro (&message_dolog_marker2
);
25155 message_dolog_marker3
= Fmake_marker ();
25156 staticpro (&message_dolog_marker3
);
25159 defsubr (&Sdump_frame_glyph_matrix
);
25160 defsubr (&Sdump_glyph_matrix
);
25161 defsubr (&Sdump_glyph_row
);
25162 defsubr (&Sdump_tool_bar_row
);
25163 defsubr (&Strace_redisplay
);
25164 defsubr (&Strace_to_stderr
);
25166 #ifdef HAVE_WINDOW_SYSTEM
25167 defsubr (&Stool_bar_lines_needed
);
25168 defsubr (&Slookup_image_map
);
25170 defsubr (&Sformat_mode_line
);
25171 defsubr (&Sinvisible_p
);
25173 staticpro (&Qmenu_bar_update_hook
);
25174 Qmenu_bar_update_hook
= intern_c_string ("menu-bar-update-hook");
25176 staticpro (&Qoverriding_terminal_local_map
);
25177 Qoverriding_terminal_local_map
= intern_c_string ("overriding-terminal-local-map");
25179 staticpro (&Qoverriding_local_map
);
25180 Qoverriding_local_map
= intern_c_string ("overriding-local-map");
25182 staticpro (&Qwindow_scroll_functions
);
25183 Qwindow_scroll_functions
= intern_c_string ("window-scroll-functions");
25185 staticpro (&Qwindow_text_change_functions
);
25186 Qwindow_text_change_functions
= intern_c_string ("window-text-change-functions");
25188 staticpro (&Qredisplay_end_trigger_functions
);
25189 Qredisplay_end_trigger_functions
= intern_c_string ("redisplay-end-trigger-functions");
25191 staticpro (&Qinhibit_point_motion_hooks
);
25192 Qinhibit_point_motion_hooks
= intern_c_string ("inhibit-point-motion-hooks");
25194 Qeval
= intern_c_string ("eval");
25195 staticpro (&Qeval
);
25197 QCdata
= intern_c_string (":data");
25198 staticpro (&QCdata
);
25199 Qdisplay
= intern_c_string ("display");
25200 staticpro (&Qdisplay
);
25201 Qspace_width
= intern_c_string ("space-width");
25202 staticpro (&Qspace_width
);
25203 Qraise
= intern_c_string ("raise");
25204 staticpro (&Qraise
);
25205 Qslice
= intern_c_string ("slice");
25206 staticpro (&Qslice
);
25207 Qspace
= intern_c_string ("space");
25208 staticpro (&Qspace
);
25209 Qmargin
= intern_c_string ("margin");
25210 staticpro (&Qmargin
);
25211 Qpointer
= intern_c_string ("pointer");
25212 staticpro (&Qpointer
);
25213 Qleft_margin
= intern_c_string ("left-margin");
25214 staticpro (&Qleft_margin
);
25215 Qright_margin
= intern_c_string ("right-margin");
25216 staticpro (&Qright_margin
);
25217 Qcenter
= intern_c_string ("center");
25218 staticpro (&Qcenter
);
25219 Qline_height
= intern_c_string ("line-height");
25220 staticpro (&Qline_height
);
25221 QCalign_to
= intern_c_string (":align-to");
25222 staticpro (&QCalign_to
);
25223 QCrelative_width
= intern_c_string (":relative-width");
25224 staticpro (&QCrelative_width
);
25225 QCrelative_height
= intern_c_string (":relative-height");
25226 staticpro (&QCrelative_height
);
25227 QCeval
= intern_c_string (":eval");
25228 staticpro (&QCeval
);
25229 QCpropertize
= intern_c_string (":propertize");
25230 staticpro (&QCpropertize
);
25231 QCfile
= intern_c_string (":file");
25232 staticpro (&QCfile
);
25233 Qfontified
= intern_c_string ("fontified");
25234 staticpro (&Qfontified
);
25235 Qfontification_functions
= intern_c_string ("fontification-functions");
25236 staticpro (&Qfontification_functions
);
25237 Qtrailing_whitespace
= intern_c_string ("trailing-whitespace");
25238 staticpro (&Qtrailing_whitespace
);
25239 Qescape_glyph
= intern_c_string ("escape-glyph");
25240 staticpro (&Qescape_glyph
);
25241 Qnobreak_space
= intern_c_string ("nobreak-space");
25242 staticpro (&Qnobreak_space
);
25243 Qimage
= intern_c_string ("image");
25244 staticpro (&Qimage
);
25245 QCmap
= intern_c_string (":map");
25246 staticpro (&QCmap
);
25247 QCpointer
= intern_c_string (":pointer");
25248 staticpro (&QCpointer
);
25249 Qrect
= intern_c_string ("rect");
25250 staticpro (&Qrect
);
25251 Qcircle
= intern_c_string ("circle");
25252 staticpro (&Qcircle
);
25253 Qpoly
= intern_c_string ("poly");
25254 staticpro (&Qpoly
);
25255 Qmessage_truncate_lines
= intern_c_string ("message-truncate-lines");
25256 staticpro (&Qmessage_truncate_lines
);
25257 Qgrow_only
= intern_c_string ("grow-only");
25258 staticpro (&Qgrow_only
);
25259 Qinhibit_menubar_update
= intern_c_string ("inhibit-menubar-update");
25260 staticpro (&Qinhibit_menubar_update
);
25261 Qinhibit_eval_during_redisplay
= intern_c_string ("inhibit-eval-during-redisplay");
25262 staticpro (&Qinhibit_eval_during_redisplay
);
25263 Qposition
= intern_c_string ("position");
25264 staticpro (&Qposition
);
25265 Qbuffer_position
= intern_c_string ("buffer-position");
25266 staticpro (&Qbuffer_position
);
25267 Qobject
= intern_c_string ("object");
25268 staticpro (&Qobject
);
25269 Qbar
= intern_c_string ("bar");
25271 Qhbar
= intern_c_string ("hbar");
25272 staticpro (&Qhbar
);
25273 Qbox
= intern_c_string ("box");
25275 Qhollow
= intern_c_string ("hollow");
25276 staticpro (&Qhollow
);
25277 Qhand
= intern_c_string ("hand");
25278 staticpro (&Qhand
);
25279 Qarrow
= intern_c_string ("arrow");
25280 staticpro (&Qarrow
);
25281 Qtext
= intern_c_string ("text");
25282 staticpro (&Qtext
);
25283 Qrisky_local_variable
= intern_c_string ("risky-local-variable");
25284 staticpro (&Qrisky_local_variable
);
25285 Qinhibit_free_realized_faces
= intern_c_string ("inhibit-free-realized-faces");
25286 staticpro (&Qinhibit_free_realized_faces
);
25288 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
25289 Fcons (intern_c_string ("void-variable"), Qnil
)),
25291 staticpro (&list_of_error
);
25293 Qlast_arrow_position
= intern_c_string ("last-arrow-position");
25294 staticpro (&Qlast_arrow_position
);
25295 Qlast_arrow_string
= intern_c_string ("last-arrow-string");
25296 staticpro (&Qlast_arrow_string
);
25298 Qoverlay_arrow_string
= intern_c_string ("overlay-arrow-string");
25299 staticpro (&Qoverlay_arrow_string
);
25300 Qoverlay_arrow_bitmap
= intern_c_string ("overlay-arrow-bitmap");
25301 staticpro (&Qoverlay_arrow_bitmap
);
25303 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
25304 staticpro (&echo_buffer
[0]);
25305 staticpro (&echo_buffer
[1]);
25307 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
25308 staticpro (&echo_area_buffer
[0]);
25309 staticpro (&echo_area_buffer
[1]);
25311 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
25312 staticpro (&Vmessages_buffer_name
);
25314 mode_line_proptrans_alist
= Qnil
;
25315 staticpro (&mode_line_proptrans_alist
);
25316 mode_line_string_list
= Qnil
;
25317 staticpro (&mode_line_string_list
);
25318 mode_line_string_face
= Qnil
;
25319 staticpro (&mode_line_string_face
);
25320 mode_line_string_face_prop
= Qnil
;
25321 staticpro (&mode_line_string_face_prop
);
25322 Vmode_line_unwind_vector
= Qnil
;
25323 staticpro (&Vmode_line_unwind_vector
);
25325 help_echo_string
= Qnil
;
25326 staticpro (&help_echo_string
);
25327 help_echo_object
= Qnil
;
25328 staticpro (&help_echo_object
);
25329 help_echo_window
= Qnil
;
25330 staticpro (&help_echo_window
);
25331 previous_help_echo_string
= Qnil
;
25332 staticpro (&previous_help_echo_string
);
25333 help_echo_pos
= -1;
25335 Qright_to_left
= intern ("right-to-left");
25336 staticpro (&Qright_to_left
);
25337 Qleft_to_right
= intern ("left-to-right");
25338 staticpro (&Qleft_to_right
);
25340 #ifdef HAVE_WINDOW_SYSTEM
25341 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
25342 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
25343 For example, if a block cursor is over a tab, it will be drawn as
25344 wide as that tab on the display. */);
25345 x_stretch_cursor_p
= 0;
25348 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
25349 doc
: /* *Non-nil means highlight trailing whitespace.
25350 The face used for trailing whitespace is `trailing-whitespace'. */);
25351 Vshow_trailing_whitespace
= Qnil
;
25353 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
25354 doc
: /* *Control highlighting of nobreak space and soft hyphen.
25355 A value of t means highlight the character itself (for nobreak space,
25356 use face `nobreak-space').
25357 A value of nil means no highlighting.
25358 Other values mean display the escape glyph followed by an ordinary
25359 space or ordinary hyphen. */);
25360 Vnobreak_char_display
= Qt
;
25362 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
25363 doc
: /* *The pointer shape to show in void text areas.
25364 A value of nil means to show the text pointer. Other options are `arrow',
25365 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
25366 Vvoid_text_area_pointer
= Qarrow
;
25368 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
25369 doc
: /* Non-nil means don't actually do any redisplay.
25370 This is used for internal purposes. */);
25371 Vinhibit_redisplay
= Qnil
;
25373 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
25374 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
25375 Vglobal_mode_string
= Qnil
;
25377 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
25378 doc
: /* Marker for where to display an arrow on top of the buffer text.
25379 This must be the beginning of a line in order to work.
25380 See also `overlay-arrow-string'. */);
25381 Voverlay_arrow_position
= Qnil
;
25383 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
25384 doc
: /* String to display as an arrow in non-window frames.
25385 See also `overlay-arrow-position'. */);
25386 Voverlay_arrow_string
= make_pure_c_string ("=>");
25388 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
25389 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
25390 The symbols on this list are examined during redisplay to determine
25391 where to display overlay arrows. */);
25392 Voverlay_arrow_variable_list
25393 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
25395 DEFVAR_INT ("scroll-step", &scroll_step
,
25396 doc
: /* *The number of lines to try scrolling a window by when point moves out.
25397 If that fails to bring point back on frame, point is centered instead.
25398 If this is zero, point is always centered after it moves off frame.
25399 If you want scrolling to always be a line at a time, you should set
25400 `scroll-conservatively' to a large value rather than set this to 1. */);
25402 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
25403 doc
: /* *Scroll up to this many lines, to bring point back on screen.
25404 If point moves off-screen, redisplay will scroll by up to
25405 `scroll-conservatively' lines in order to bring point just barely
25406 onto the screen again. If that cannot be done, then redisplay
25407 recenters point as usual.
25409 A value of zero means always recenter point if it moves off screen. */);
25410 scroll_conservatively
= 0;
25412 DEFVAR_INT ("scroll-margin", &scroll_margin
,
25413 doc
: /* *Number of lines of margin at the top and bottom of a window.
25414 Recenter the window whenever point gets within this many lines
25415 of the top or bottom of the window. */);
25418 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
25419 doc
: /* Pixels per inch value for non-window system displays.
25420 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
25421 Vdisplay_pixels_per_inch
= make_float (72.0);
25424 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
25427 DEFVAR_LISP ("truncate-partial-width-windows",
25428 &Vtruncate_partial_width_windows
,
25429 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
25430 For an integer value, truncate lines in each window narrower than the
25431 full frame width, provided the window width is less than that integer;
25432 otherwise, respect the value of `truncate-lines'.
25434 For any other non-nil value, truncate lines in all windows that do
25435 not span the full frame width.
25437 A value of nil means to respect the value of `truncate-lines'.
25439 If `word-wrap' is enabled, you might want to reduce this. */);
25440 Vtruncate_partial_width_windows
= make_number (50);
25442 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
25443 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
25444 Any other value means to use the appropriate face, `mode-line',
25445 `header-line', or `menu' respectively. */);
25446 mode_line_inverse_video
= 1;
25448 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
25449 doc
: /* *Maximum buffer size for which line number should be displayed.
25450 If the buffer is bigger than this, the line number does not appear
25451 in the mode line. A value of nil means no limit. */);
25452 Vline_number_display_limit
= Qnil
;
25454 DEFVAR_INT ("line-number-display-limit-width",
25455 &line_number_display_limit_width
,
25456 doc
: /* *Maximum line width (in characters) for line number display.
25457 If the average length of the lines near point is bigger than this, then the
25458 line number may be omitted from the mode line. */);
25459 line_number_display_limit_width
= 200;
25461 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
25462 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
25463 highlight_nonselected_windows
= 0;
25465 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
25466 doc
: /* Non-nil if more than one frame is visible on this display.
25467 Minibuffer-only frames don't count, but iconified frames do.
25468 This variable is not guaranteed to be accurate except while processing
25469 `frame-title-format' and `icon-title-format'. */);
25471 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
25472 doc
: /* Template for displaying the title bar of visible frames.
25473 \(Assuming the window manager supports this feature.)
25475 This variable has the same structure as `mode-line-format', except that
25476 the %c and %l constructs are ignored. It is used only on frames for
25477 which no explicit name has been set \(see `modify-frame-parameters'). */);
25479 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
25480 doc
: /* Template for displaying the title bar of an iconified frame.
25481 \(Assuming the window manager supports this feature.)
25482 This variable has the same structure as `mode-line-format' (which see),
25483 and is used only on frames for which no explicit name has been set
25484 \(see `modify-frame-parameters'). */);
25486 = Vframe_title_format
25487 = pure_cons (intern_c_string ("multiple-frames"),
25488 pure_cons (make_pure_c_string ("%b"),
25489 pure_cons (pure_cons (empty_unibyte_string
,
25490 pure_cons (intern_c_string ("invocation-name"),
25491 pure_cons (make_pure_c_string ("@"),
25492 pure_cons (intern_c_string ("system-name"),
25496 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
25497 doc
: /* Maximum number of lines to keep in the message log buffer.
25498 If nil, disable message logging. If t, log messages but don't truncate
25499 the buffer when it becomes large. */);
25500 Vmessage_log_max
= make_number (100);
25502 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
25503 doc
: /* Functions called before redisplay, if window sizes have changed.
25504 The value should be a list of functions that take one argument.
25505 Just before redisplay, for each frame, if any of its windows have changed
25506 size since the last redisplay, or have been split or deleted,
25507 all the functions in the list are called, with the frame as argument. */);
25508 Vwindow_size_change_functions
= Qnil
;
25510 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
25511 doc
: /* List of functions to call before redisplaying a window with scrolling.
25512 Each function is called with two arguments, the window and its new
25513 display-start position. Note that these functions are also called by
25514 `set-window-buffer'. Also note that the value of `window-end' is not
25515 valid when these functions are called. */);
25516 Vwindow_scroll_functions
= Qnil
;
25518 DEFVAR_LISP ("window-text-change-functions",
25519 &Vwindow_text_change_functions
,
25520 doc
: /* Functions to call in redisplay when text in the window might change. */);
25521 Vwindow_text_change_functions
= Qnil
;
25523 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
25524 doc
: /* Functions called when redisplay of a window reaches the end trigger.
25525 Each function is called with two arguments, the window and the end trigger value.
25526 See `set-window-redisplay-end-trigger'. */);
25527 Vredisplay_end_trigger_functions
= Qnil
;
25529 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
25530 doc
: /* *Non-nil means autoselect window with mouse pointer.
25531 If nil, do not autoselect windows.
25532 A positive number means delay autoselection by that many seconds: a
25533 window is autoselected only after the mouse has remained in that
25534 window for the duration of the delay.
25535 A negative number has a similar effect, but causes windows to be
25536 autoselected only after the mouse has stopped moving. \(Because of
25537 the way Emacs compares mouse events, you will occasionally wait twice
25538 that time before the window gets selected.\)
25539 Any other value means to autoselect window instantaneously when the
25540 mouse pointer enters it.
25542 Autoselection selects the minibuffer only if it is active, and never
25543 unselects the minibuffer if it is active.
25545 When customizing this variable make sure that the actual value of
25546 `focus-follows-mouse' matches the behavior of your window manager. */);
25547 Vmouse_autoselect_window
= Qnil
;
25549 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
25550 doc
: /* *Non-nil means automatically resize tool-bars.
25551 This dynamically changes the tool-bar's height to the minimum height
25552 that is needed to make all tool-bar items visible.
25553 If value is `grow-only', the tool-bar's height is only increased
25554 automatically; to decrease the tool-bar height, use \\[recenter]. */);
25555 Vauto_resize_tool_bars
= Qt
;
25557 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
25558 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
25559 auto_raise_tool_bar_buttons_p
= 1;
25561 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
25562 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
25563 make_cursor_line_fully_visible_p
= 1;
25565 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
25566 doc
: /* *Border below tool-bar in pixels.
25567 If an integer, use it as the height of the border.
25568 If it is one of `internal-border-width' or `border-width', use the
25569 value of the corresponding frame parameter.
25570 Otherwise, no border is added below the tool-bar. */);
25571 Vtool_bar_border
= Qinternal_border_width
;
25573 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
25574 doc
: /* *Margin around tool-bar buttons in pixels.
25575 If an integer, use that for both horizontal and vertical margins.
25576 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
25577 HORZ specifying the horizontal margin, and VERT specifying the
25578 vertical margin. */);
25579 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
25581 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
25582 doc
: /* *Relief thickness of tool-bar buttons. */);
25583 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
25585 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
25586 doc
: /* List of functions to call to fontify regions of text.
25587 Each function is called with one argument POS. Functions must
25588 fontify a region starting at POS in the current buffer, and give
25589 fontified regions the property `fontified'. */);
25590 Vfontification_functions
= Qnil
;
25591 Fmake_variable_buffer_local (Qfontification_functions
);
25593 DEFVAR_BOOL ("unibyte-display-via-language-environment",
25594 &unibyte_display_via_language_environment
,
25595 doc
: /* *Non-nil means display unibyte text according to language environment.
25596 Specifically, this means that raw bytes in the range 160-255 decimal
25597 are displayed by converting them to the equivalent multibyte characters
25598 according to the current language environment. As a result, they are
25599 displayed according to the current fontset.
25601 Note that this variable affects only how these bytes are displayed,
25602 but does not change the fact they are interpreted as raw bytes. */);
25603 unibyte_display_via_language_environment
= 0;
25605 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
25606 doc
: /* *Maximum height for resizing mini-windows.
25607 If a float, it specifies a fraction of the mini-window frame's height.
25608 If an integer, it specifies a number of lines. */);
25609 Vmax_mini_window_height
= make_float (0.25);
25611 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
25612 doc
: /* *How to resize mini-windows.
25613 A value of nil means don't automatically resize mini-windows.
25614 A value of t means resize them to fit the text displayed in them.
25615 A value of `grow-only', the default, means let mini-windows grow
25616 only, until their display becomes empty, at which point the windows
25617 go back to their normal size. */);
25618 Vresize_mini_windows
= Qgrow_only
;
25620 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
25621 doc
: /* Alist specifying how to blink the cursor off.
25622 Each element has the form (ON-STATE . OFF-STATE). Whenever the
25623 `cursor-type' frame-parameter or variable equals ON-STATE,
25624 comparing using `equal', Emacs uses OFF-STATE to specify
25625 how to blink it off. ON-STATE and OFF-STATE are values for
25626 the `cursor-type' frame parameter.
25628 If a frame's ON-STATE has no entry in this list,
25629 the frame's other specifications determine how to blink the cursor off. */);
25630 Vblink_cursor_alist
= Qnil
;
25632 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
25633 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
25634 automatic_hscrolling_p
= 1;
25635 Qauto_hscroll_mode
= intern_c_string ("auto-hscroll-mode");
25636 staticpro (&Qauto_hscroll_mode
);
25638 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
25639 doc
: /* *How many columns away from the window edge point is allowed to get
25640 before automatic hscrolling will horizontally scroll the window. */);
25641 hscroll_margin
= 5;
25643 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
25644 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
25645 When point is less than `hscroll-margin' columns from the window
25646 edge, automatic hscrolling will scroll the window by the amount of columns
25647 determined by this variable. If its value is a positive integer, scroll that
25648 many columns. If it's a positive floating-point number, it specifies the
25649 fraction of the window's width to scroll. If it's nil or zero, point will be
25650 centered horizontally after the scroll. Any other value, including negative
25651 numbers, are treated as if the value were zero.
25653 Automatic hscrolling always moves point outside the scroll margin, so if
25654 point was more than scroll step columns inside the margin, the window will
25655 scroll more than the value given by the scroll step.
25657 Note that the lower bound for automatic hscrolling specified by `scroll-left'
25658 and `scroll-right' overrides this variable's effect. */);
25659 Vhscroll_step
= make_number (0);
25661 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
25662 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
25663 Bind this around calls to `message' to let it take effect. */);
25664 message_truncate_lines
= 0;
25666 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
25667 doc
: /* Normal hook run to update the menu bar definitions.
25668 Redisplay runs this hook before it redisplays the menu bar.
25669 This is used to update submenus such as Buffers,
25670 whose contents depend on various data. */);
25671 Vmenu_bar_update_hook
= Qnil
;
25673 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
25674 doc
: /* Frame for which we are updating a menu.
25675 The enable predicate for a menu binding should check this variable. */);
25676 Vmenu_updating_frame
= Qnil
;
25678 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
25679 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
25680 inhibit_menubar_update
= 0;
25682 DEFVAR_LISP ("wrap-prefix", &Vwrap_prefix
,
25683 doc
: /* Prefix prepended to all continuation lines at display time.
25684 The value may be a string, an image, or a stretch-glyph; it is
25685 interpreted in the same way as the value of a `display' text property.
25687 This variable is overridden by any `wrap-prefix' text or overlay
25690 To add a prefix to non-continuation lines, use `line-prefix'. */);
25691 Vwrap_prefix
= Qnil
;
25692 staticpro (&Qwrap_prefix
);
25693 Qwrap_prefix
= intern_c_string ("wrap-prefix");
25694 Fmake_variable_buffer_local (Qwrap_prefix
);
25696 DEFVAR_LISP ("line-prefix", &Vline_prefix
,
25697 doc
: /* Prefix prepended to all non-continuation lines at display time.
25698 The value may be a string, an image, or a stretch-glyph; it is
25699 interpreted in the same way as the value of a `display' text property.
25701 This variable is overridden by any `line-prefix' text or overlay
25704 To add a prefix to continuation lines, use `wrap-prefix'. */);
25705 Vline_prefix
= Qnil
;
25706 staticpro (&Qline_prefix
);
25707 Qline_prefix
= intern_c_string ("line-prefix");
25708 Fmake_variable_buffer_local (Qline_prefix
);
25710 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
25711 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
25712 inhibit_eval_during_redisplay
= 0;
25714 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
25715 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
25716 inhibit_free_realized_faces
= 0;
25719 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
25720 doc
: /* Inhibit try_window_id display optimization. */);
25721 inhibit_try_window_id
= 0;
25723 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
25724 doc
: /* Inhibit try_window_reusing display optimization. */);
25725 inhibit_try_window_reusing
= 0;
25727 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
25728 doc
: /* Inhibit try_cursor_movement display optimization. */);
25729 inhibit_try_cursor_movement
= 0;
25730 #endif /* GLYPH_DEBUG */
25732 DEFVAR_INT ("overline-margin", &overline_margin
,
25733 doc
: /* *Space between overline and text, in pixels.
25734 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
25735 margin to the caracter height. */);
25736 overline_margin
= 2;
25738 DEFVAR_INT ("underline-minimum-offset",
25739 &underline_minimum_offset
,
25740 doc
: /* Minimum distance between baseline and underline.
25741 This can improve legibility of underlined text at small font sizes,
25742 particularly when using variable `x-use-underline-position-properties'
25743 with fonts that specify an UNDERLINE_POSITION relatively close to the
25744 baseline. The default value is 1. */);
25745 underline_minimum_offset
= 1;
25747 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
25748 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
25749 display_hourglass_p
= 1;
25751 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
25752 doc
: /* *Seconds to wait before displaying an hourglass pointer.
25753 Value must be an integer or float. */);
25754 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
25756 hourglass_atimer
= NULL
;
25757 hourglass_shown_p
= 0;
25761 /* Initialize this module when Emacs starts. */
25766 Lisp_Object root_window
;
25767 struct window
*mini_w
;
25769 current_header_line_height
= current_mode_line_height
= -1;
25771 CHARPOS (this_line_start_pos
) = 0;
25773 mini_w
= XWINDOW (minibuf_window
);
25774 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
25776 if (!noninteractive
)
25778 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
25781 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
25782 set_window_height (root_window
,
25783 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
25785 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
25786 set_window_height (minibuf_window
, 1, 0);
25788 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
25789 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
25791 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
25792 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
25793 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
25795 /* The default ellipsis glyphs `...'. */
25796 for (i
= 0; i
< 3; ++i
)
25797 default_invis_vector
[i
] = make_number ('.');
25801 /* Allocate the buffer for frame titles.
25802 Also used for `format-mode-line'. */
25804 mode_line_noprop_buf
= (char *) xmalloc (size
);
25805 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
25806 mode_line_noprop_ptr
= mode_line_noprop_buf
;
25807 mode_line_target
= MODE_LINE_DISPLAY
;
25810 help_echo_showing_p
= 0;
25813 /* Since w32 does not support atimers, it defines its own implementation of
25814 the following three functions in w32fns.c. */
25817 /* Platform-independent portion of hourglass implementation. */
25819 /* Return non-zero if houglass timer has been started or hourglass is shown. */
25821 hourglass_started ()
25823 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
25826 /* Cancel a currently active hourglass timer, and start a new one. */
25830 #if defined (HAVE_WINDOW_SYSTEM)
25832 int secs
, usecs
= 0;
25834 cancel_hourglass ();
25836 if (INTEGERP (Vhourglass_delay
)
25837 && XINT (Vhourglass_delay
) > 0)
25838 secs
= XFASTINT (Vhourglass_delay
);
25839 else if (FLOATP (Vhourglass_delay
)
25840 && XFLOAT_DATA (Vhourglass_delay
) > 0)
25843 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
25844 secs
= XFASTINT (tem
);
25845 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
25848 secs
= DEFAULT_HOURGLASS_DELAY
;
25850 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
25851 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
25852 show_hourglass
, NULL
);
25857 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
25860 cancel_hourglass ()
25862 #if defined (HAVE_WINDOW_SYSTEM)
25863 if (hourglass_atimer
)
25865 cancel_atimer (hourglass_atimer
);
25866 hourglass_atimer
= NULL
;
25869 if (hourglass_shown_p
)
25873 #endif /* ! WINDOWSNT */
25875 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
25876 (do not change this comment) */