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 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, or (at your option)
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; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
27 Emacs separates the task of updating the display from code
28 modifying global state, e.g. buffer text. This way functions
29 operating on buffers don't also have to be concerned with updating
32 Updating the display is triggered by the Lisp interpreter when it
33 decides it's time to do it. This is done either automatically for
34 you as part of the interpreter's command loop or as the result of
35 calling Lisp functions like `sit-for'. The C function `redisplay'
36 in xdisp.c is the only entry into the inner redisplay code. (Or,
37 let's say almost---see the description of direct update
40 The following diagram shows how redisplay code is invoked. As you
41 can see, Lisp calls redisplay and vice versa. Under window systems
42 like X, some portions of the redisplay code are also called
43 asynchronously during mouse movement or expose events. It is very
44 important that these code parts do NOT use the C library (malloc,
45 free) because many C libraries under Unix are not reentrant. They
46 may also NOT call functions of the Lisp interpreter which could
47 change the interpreter's state. If you don't follow these rules,
48 you will encounter bugs which are very hard to explain.
50 (Direct functions, see below)
51 direct_output_for_insert,
52 direct_forward_char (dispnew.c)
53 +---------------------------------+
56 +--------------+ redisplay +----------------+
57 | Lisp machine |---------------->| Redisplay code |<--+
58 +--------------+ (xdisp.c) +----------------+ |
60 +----------------------------------+ |
61 Don't use this path when called |
64 expose_window (asynchronous) |
66 X expose events -----+
68 What does redisplay do? Obviously, it has to figure out somehow what
69 has been changed since the last time the display has been updated,
70 and to make these changes visible. Preferably it would do that in
71 a moderately intelligent way, i.e. fast.
73 Changes in buffer text can be deduced from window and buffer
74 structures, and from some global variables like `beg_unchanged' and
75 `end_unchanged'. The contents of the display are additionally
76 recorded in a `glyph matrix', a two-dimensional matrix of glyph
77 structures. Each row in such a matrix corresponds to a line on the
78 display, and each glyph in a row corresponds to a column displaying
79 a character, an image, or what else. This matrix is called the
80 `current glyph matrix' or `current matrix' in redisplay
83 For buffer parts that have been changed since the last update, a
84 second glyph matrix is constructed, the so called `desired glyph
85 matrix' or short `desired matrix'. Current and desired matrix are
86 then compared to find a cheap way to update the display, e.g. by
87 reusing part of the display by scrolling lines.
92 You will find a lot of redisplay optimizations when you start
93 looking at the innards of redisplay. The overall goal of all these
94 optimizations is to make redisplay fast because it is done
97 Two optimizations are not found in xdisp.c. These are the direct
98 operations mentioned above. As the name suggests they follow a
99 different principle than the rest of redisplay. Instead of
100 building a desired matrix and then comparing it with the current
101 display, they perform their actions directly on the display and on
104 One direct operation updates the display after one character has
105 been entered. The other one moves the cursor by one position
106 forward or backward. You find these functions under the names
107 `direct_output_for_insert' and `direct_output_forward_char' in
113 Desired matrices are always built per Emacs window. The function
114 `display_line' is the central function to look at if you are
115 interested. It constructs one row in a desired matrix given an
116 iterator structure containing both a buffer position and a
117 description of the environment in which the text is to be
118 displayed. But this is too early, read on.
120 Characters and pixmaps displayed for a range of buffer text depend
121 on various settings of buffers and windows, on overlays and text
122 properties, on display tables, on selective display. The good news
123 is that all this hairy stuff is hidden behind a small set of
124 interface functions taking an iterator structure (struct it)
127 Iteration over things to be displayed is then simple. It is
128 started by initializing an iterator with a call to init_iterator.
129 Calls to get_next_display_element fill the iterator structure with
130 relevant information about the next thing to display. Calls to
131 set_iterator_to_next move the iterator to the next thing.
133 Besides this, an iterator also contains information about the
134 display environment in which glyphs for display elements are to be
135 produced. It has fields for the width and height of the display,
136 the information whether long lines are truncated or continued, a
137 current X and Y position, and lots of other stuff you can better
140 Glyphs in a desired matrix are normally constructed in a loop
141 calling get_next_display_element and then produce_glyphs. The call
142 to produce_glyphs will fill the iterator structure with pixel
143 information about the element being displayed and at the same time
144 produce glyphs for it. If the display element fits on the line
145 being displayed, set_iterator_to_next is called next, otherwise the
146 glyphs produced are discarded.
151 That just couldn't be all, could it? What about terminal types not
152 supporting operations on sub-windows of the screen? To update the
153 display on such a terminal, window-based glyph matrices are not
154 well suited. To be able to reuse part of the display (scrolling
155 lines up and down), we must instead have a view of the whole
156 screen. This is what `frame matrices' are for. They are a trick.
158 Frames on terminals like above have a glyph pool. Windows on such
159 a frame sub-allocate their glyph memory from their frame's glyph
160 pool. The frame itself is given its own glyph matrices. By
161 coincidence---or maybe something else---rows in window glyph
162 matrices are slices of corresponding rows in frame matrices. Thus
163 writing to window matrices implicitly updates a frame matrix which
164 provides us with the view of the whole screen that we originally
165 wanted to have without having to move many bytes around. To be
166 honest, there is a little bit more done, but not much more. If you
167 plan to extend that code, take a look at dispnew.c. The function
168 build_frame_matrix is a good starting point. */
174 #include "keyboard.h"
177 #include "termchar.h"
178 #include "dispextern.h"
182 #include "commands.h"
186 #include "termhooks.h"
187 #include "intervals.h"
190 #include "region-cache.h"
192 #include "blockinput.h"
194 #ifdef HAVE_X_WINDOWS
204 #ifndef FRAME_X_OUTPUT
205 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
208 #define INFINITY 10000000
210 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
212 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
213 extern int pending_menu_activation
;
216 extern int interrupt_input
;
217 extern int command_loop_level
;
219 extern Lisp_Object do_mouse_tracking
;
221 extern int minibuffer_auto_raise
;
222 extern Lisp_Object Vminibuffer_list
;
224 extern Lisp_Object Qface
;
225 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
227 extern Lisp_Object Voverriding_local_map
;
228 extern Lisp_Object Voverriding_local_map_menu_flag
;
229 extern Lisp_Object Qmenu_item
;
230 extern Lisp_Object Qwhen
;
231 extern Lisp_Object Qhelp_echo
;
233 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
234 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
235 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
236 Lisp_Object Qinhibit_point_motion_hooks
;
237 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
238 Lisp_Object Qfontified
;
239 Lisp_Object Qgrow_only
;
240 Lisp_Object Qinhibit_eval_during_redisplay
;
241 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
244 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
247 Lisp_Object Qarrow
, Qhand
, Qtext
;
249 Lisp_Object Qrisky_local_variable
;
251 /* Holds the list (error). */
252 Lisp_Object list_of_error
;
254 /* Functions called to fontify regions of text. */
256 Lisp_Object Vfontification_functions
;
257 Lisp_Object Qfontification_functions
;
259 /* Non-nil means automatically select any window when the mouse
260 cursor moves into it. */
261 Lisp_Object Vmouse_autoselect_window
;
263 /* Non-zero means draw tool bar buttons raised when the mouse moves
266 int auto_raise_tool_bar_buttons_p
;
268 /* Non-zero means to reposition window if cursor line is only partially visible. */
270 int make_cursor_line_fully_visible_p
;
272 /* Margin below tool bar in pixels. 0 or nil means no margin.
273 If value is `internal-border-width' or `border-width',
274 the corresponding frame parameter is used. */
276 Lisp_Object Vtool_bar_border
;
278 /* Margin around tool bar buttons in pixels. */
280 Lisp_Object Vtool_bar_button_margin
;
282 /* Thickness of shadow to draw around tool bar buttons. */
284 EMACS_INT tool_bar_button_relief
;
286 /* Non-nil means automatically resize tool-bars so that all tool-bar
287 items are visible, and no blank lines remain.
289 If value is `grow-only', only make tool-bar bigger. */
291 Lisp_Object Vauto_resize_tool_bars
;
293 /* Non-zero means draw block and hollow cursor as wide as the glyph
294 under it. For example, if a block cursor is over a tab, it will be
295 drawn as wide as that tab on the display. */
297 int x_stretch_cursor_p
;
299 /* Non-nil means don't actually do any redisplay. */
301 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
303 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
305 int inhibit_eval_during_redisplay
;
307 /* Names of text properties relevant for redisplay. */
309 Lisp_Object Qdisplay
;
310 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
312 /* Symbols used in text property values. */
314 Lisp_Object Vdisplay_pixels_per_inch
;
315 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
316 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
319 Lisp_Object Qmargin
, Qpointer
;
320 Lisp_Object Qline_height
;
321 extern Lisp_Object Qheight
;
322 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
323 extern Lisp_Object Qscroll_bar
;
324 extern Lisp_Object Qcursor
;
326 /* Non-nil means highlight trailing whitespace. */
328 Lisp_Object Vshow_trailing_whitespace
;
330 /* Non-nil means escape non-break space and hyphens. */
332 Lisp_Object Vnobreak_char_display
;
334 #ifdef HAVE_WINDOW_SYSTEM
335 extern Lisp_Object Voverflow_newline_into_fringe
;
337 /* Test if overflow newline into fringe. Called with iterator IT
338 at or past right window margin, and with IT->current_x set. */
340 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
341 (!NILP (Voverflow_newline_into_fringe) \
342 && FRAME_WINDOW_P (it->f) \
343 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
344 && it->current_x == it->last_visible_x)
346 #endif /* HAVE_WINDOW_SYSTEM */
348 /* Non-nil means show the text cursor in void text areas
349 i.e. in blank areas after eol and eob. This used to be
350 the default in 21.3. */
352 Lisp_Object Vvoid_text_area_pointer
;
354 /* Name of the face used to highlight trailing whitespace. */
356 Lisp_Object Qtrailing_whitespace
;
358 /* Name and number of the face used to highlight escape glyphs. */
360 Lisp_Object Qescape_glyph
;
362 /* Name and number of the face used to highlight non-breaking spaces. */
364 Lisp_Object Qnobreak_space
;
366 /* The symbol `image' which is the car of the lists used to represent
371 /* The image map types. */
372 Lisp_Object QCmap
, QCpointer
;
373 Lisp_Object Qrect
, Qcircle
, Qpoly
;
375 /* Non-zero means print newline to stdout before next mini-buffer
378 int noninteractive_need_newline
;
380 /* Non-zero means print newline to message log before next message. */
382 static int message_log_need_newline
;
384 /* Three markers that message_dolog uses.
385 It could allocate them itself, but that causes trouble
386 in handling memory-full errors. */
387 static Lisp_Object message_dolog_marker1
;
388 static Lisp_Object message_dolog_marker2
;
389 static Lisp_Object message_dolog_marker3
;
391 /* The buffer position of the first character appearing entirely or
392 partially on the line of the selected window which contains the
393 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
394 redisplay optimization in redisplay_internal. */
396 static struct text_pos this_line_start_pos
;
398 /* Number of characters past the end of the line above, including the
399 terminating newline. */
401 static struct text_pos this_line_end_pos
;
403 /* The vertical positions and the height of this line. */
405 static int this_line_vpos
;
406 static int this_line_y
;
407 static int this_line_pixel_height
;
409 /* X position at which this display line starts. Usually zero;
410 negative if first character is partially visible. */
412 static int this_line_start_x
;
414 /* Buffer that this_line_.* variables are referring to. */
416 static struct buffer
*this_line_buffer
;
418 /* Nonzero means truncate lines in all windows less wide than the
421 int truncate_partial_width_windows
;
423 /* A flag to control how to display unibyte 8-bit character. */
425 int unibyte_display_via_language_environment
;
427 /* Nonzero means we have more than one non-mini-buffer-only frame.
428 Not guaranteed to be accurate except while parsing
429 frame-title-format. */
433 Lisp_Object Vglobal_mode_string
;
436 /* List of variables (symbols) which hold markers for overlay arrows.
437 The symbols on this list are examined during redisplay to determine
438 where to display overlay arrows. */
440 Lisp_Object Voverlay_arrow_variable_list
;
442 /* Marker for where to display an arrow on top of the buffer text. */
444 Lisp_Object Voverlay_arrow_position
;
446 /* String to display for the arrow. Only used on terminal frames. */
448 Lisp_Object Voverlay_arrow_string
;
450 /* Values of those variables at last redisplay are stored as
451 properties on `overlay-arrow-position' symbol. However, if
452 Voverlay_arrow_position is a marker, last-arrow-position is its
453 numerical position. */
455 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
457 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
458 properties on a symbol in overlay-arrow-variable-list. */
460 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
462 /* Like mode-line-format, but for the title bar on a visible frame. */
464 Lisp_Object Vframe_title_format
;
466 /* Like mode-line-format, but for the title bar on an iconified frame. */
468 Lisp_Object Vicon_title_format
;
470 /* List of functions to call when a window's size changes. These
471 functions get one arg, a frame on which one or more windows' sizes
474 static Lisp_Object Vwindow_size_change_functions
;
476 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
478 /* Nonzero if an overlay arrow has been displayed in this window. */
480 static int overlay_arrow_seen
;
482 /* Nonzero means highlight the region even in nonselected windows. */
484 int highlight_nonselected_windows
;
486 /* If cursor motion alone moves point off frame, try scrolling this
487 many lines up or down if that will bring it back. */
489 static EMACS_INT scroll_step
;
491 /* Nonzero means scroll just far enough to bring point back on the
492 screen, when appropriate. */
494 static EMACS_INT scroll_conservatively
;
496 /* Recenter the window whenever point gets within this many lines of
497 the top or bottom of the window. This value is translated into a
498 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
499 that there is really a fixed pixel height scroll margin. */
501 EMACS_INT scroll_margin
;
503 /* Number of windows showing the buffer of the selected window (or
504 another buffer with the same base buffer). keyboard.c refers to
509 /* Vector containing glyphs for an ellipsis `...'. */
511 static Lisp_Object default_invis_vector
[3];
513 /* Zero means display the mode-line/header-line/menu-bar in the default face
514 (this slightly odd definition is for compatibility with previous versions
515 of emacs), non-zero means display them using their respective faces.
517 This variable is deprecated. */
519 int mode_line_inverse_video
;
521 /* Prompt to display in front of the mini-buffer contents. */
523 Lisp_Object minibuf_prompt
;
525 /* Width of current mini-buffer prompt. Only set after display_line
526 of the line that contains the prompt. */
528 int minibuf_prompt_width
;
530 /* This is the window where the echo area message was displayed. It
531 is always a mini-buffer window, but it may not be the same window
532 currently active as a mini-buffer. */
534 Lisp_Object echo_area_window
;
536 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
537 pushes the current message and the value of
538 message_enable_multibyte on the stack, the function restore_message
539 pops the stack and displays MESSAGE again. */
541 Lisp_Object Vmessage_stack
;
543 /* Nonzero means multibyte characters were enabled when the echo area
544 message was specified. */
546 int message_enable_multibyte
;
548 /* Nonzero if we should redraw the mode lines on the next redisplay. */
550 int update_mode_lines
;
552 /* Nonzero if window sizes or contents have changed since last
553 redisplay that finished. */
555 int windows_or_buffers_changed
;
557 /* Nonzero means a frame's cursor type has been changed. */
559 int cursor_type_changed
;
561 /* Nonzero after display_mode_line if %l was used and it displayed a
564 int line_number_displayed
;
566 /* Maximum buffer size for which to display line numbers. */
568 Lisp_Object Vline_number_display_limit
;
570 /* Line width to consider when repositioning for line number display. */
572 static EMACS_INT line_number_display_limit_width
;
574 /* Number of lines to keep in the message log buffer. t means
575 infinite. nil means don't log at all. */
577 Lisp_Object Vmessage_log_max
;
579 /* The name of the *Messages* buffer, a string. */
581 static Lisp_Object Vmessages_buffer_name
;
583 /* Index 0 is the buffer that holds the current (desired) echo area message,
584 or nil if none is desired right now.
586 Index 1 is the buffer that holds the previously displayed echo area message,
587 or nil to indicate no message. This is normally what's on the screen now.
589 These two can point to the same buffer. That happens when the last
590 message output by the user (or made by echoing) has been displayed. */
592 Lisp_Object echo_area_buffer
[2];
594 /* Permanent pointers to the two buffers that are used for echo area
595 purposes. Once the two buffers are made, and their pointers are
596 placed here, these two slots remain unchanged unless those buffers
597 need to be created afresh. */
599 static Lisp_Object echo_buffer
[2];
601 /* A vector saved used in with_area_buffer to reduce consing. */
603 static Lisp_Object Vwith_echo_area_save_vector
;
605 /* Non-zero means display_echo_area should display the last echo area
606 message again. Set by redisplay_preserve_echo_area. */
608 static int display_last_displayed_message_p
;
610 /* Nonzero if echo area is being used by print; zero if being used by
613 int message_buf_print
;
615 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
617 Lisp_Object Qinhibit_menubar_update
;
618 int inhibit_menubar_update
;
620 /* When evaluating expressions from menu bar items (enable conditions,
621 for instance), this is the frame they are being processed for. */
623 Lisp_Object Vmenu_updating_frame
;
625 /* Maximum height for resizing mini-windows. Either a float
626 specifying a fraction of the available height, or an integer
627 specifying a number of lines. */
629 Lisp_Object Vmax_mini_window_height
;
631 /* Non-zero means messages should be displayed with truncated
632 lines instead of being continued. */
634 int message_truncate_lines
;
635 Lisp_Object Qmessage_truncate_lines
;
637 /* Set to 1 in clear_message to make redisplay_internal aware
638 of an emptied echo area. */
640 static int message_cleared_p
;
642 /* How to blink the default frame cursor off. */
643 Lisp_Object Vblink_cursor_alist
;
645 /* A scratch glyph row with contents used for generating truncation
646 glyphs. Also used in direct_output_for_insert. */
648 #define MAX_SCRATCH_GLYPHS 100
649 struct glyph_row scratch_glyph_row
;
650 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
652 /* Ascent and height of the last line processed by move_it_to. */
654 static int last_max_ascent
, last_height
;
656 /* Non-zero if there's a help-echo in the echo area. */
658 int help_echo_showing_p
;
660 /* If >= 0, computed, exact values of mode-line and header-line height
661 to use in the macros CURRENT_MODE_LINE_HEIGHT and
662 CURRENT_HEADER_LINE_HEIGHT. */
664 int current_mode_line_height
, current_header_line_height
;
666 /* The maximum distance to look ahead for text properties. Values
667 that are too small let us call compute_char_face and similar
668 functions too often which is expensive. Values that are too large
669 let us call compute_char_face and alike too often because we
670 might not be interested in text properties that far away. */
672 #define TEXT_PROP_DISTANCE_LIMIT 100
676 /* Variables to turn off display optimizations from Lisp. */
678 int inhibit_try_window_id
, inhibit_try_window_reusing
;
679 int inhibit_try_cursor_movement
;
681 /* Non-zero means print traces of redisplay if compiled with
684 int trace_redisplay_p
;
686 #endif /* GLYPH_DEBUG */
688 #ifdef DEBUG_TRACE_MOVE
689 /* Non-zero means trace with TRACE_MOVE to stderr. */
692 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
694 #define TRACE_MOVE(x) (void) 0
697 /* Non-zero means automatically scroll windows horizontally to make
700 int automatic_hscrolling_p
;
702 /* How close to the margin can point get before the window is scrolled
704 EMACS_INT hscroll_margin
;
706 /* How much to scroll horizontally when point is inside the above margin. */
707 Lisp_Object Vhscroll_step
;
709 /* The variable `resize-mini-windows'. If nil, don't resize
710 mini-windows. If t, always resize them to fit the text they
711 display. If `grow-only', let mini-windows grow only until they
714 Lisp_Object Vresize_mini_windows
;
716 /* Buffer being redisplayed -- for redisplay_window_error. */
718 struct buffer
*displayed_buffer
;
720 /* Space between overline and text. */
722 EMACS_INT overline_margin
;
724 /* Value returned from text property handlers (see below). */
729 HANDLED_RECOMPUTE_PROPS
,
730 HANDLED_OVERLAY_STRING_CONSUMED
,
734 /* A description of text properties that redisplay is interested
739 /* The name of the property. */
742 /* A unique index for the property. */
745 /* A handler function called to set up iterator IT from the property
746 at IT's current position. Value is used to steer handle_stop. */
747 enum prop_handled (*handler
) P_ ((struct it
*it
));
750 static enum prop_handled handle_face_prop
P_ ((struct it
*));
751 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
752 static enum prop_handled handle_display_prop
P_ ((struct it
*));
753 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
754 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
755 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
757 /* Properties handled by iterators. */
759 static struct props it_props
[] =
761 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
762 /* Handle `face' before `display' because some sub-properties of
763 `display' need to know the face. */
764 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
765 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
766 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
767 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
771 /* Value is the position described by X. If X is a marker, value is
772 the marker_position of X. Otherwise, value is X. */
774 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
776 /* Enumeration returned by some move_it_.* functions internally. */
780 /* Not used. Undefined value. */
783 /* Move ended at the requested buffer position or ZV. */
784 MOVE_POS_MATCH_OR_ZV
,
786 /* Move ended at the requested X pixel position. */
789 /* Move within a line ended at the end of a line that must be
793 /* Move within a line ended at the end of a line that would
794 be displayed truncated. */
797 /* Move within a line ended at a line end. */
801 /* This counter is used to clear the face cache every once in a while
802 in redisplay_internal. It is incremented for each redisplay.
803 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
806 #define CLEAR_FACE_CACHE_COUNT 500
807 static int clear_face_cache_count
;
809 /* Similarly for the image cache. */
811 #ifdef HAVE_WINDOW_SYSTEM
812 #define CLEAR_IMAGE_CACHE_COUNT 101
813 static int clear_image_cache_count
;
816 /* Record the previous terminal frame we displayed. */
818 static struct frame
*previous_terminal_frame
;
820 /* Non-zero while redisplay_internal is in progress. */
824 /* Non-zero means don't free realized faces. Bound while freeing
825 realized faces is dangerous because glyph matrices might still
828 int inhibit_free_realized_faces
;
829 Lisp_Object Qinhibit_free_realized_faces
;
831 /* If a string, XTread_socket generates an event to display that string.
832 (The display is done in read_char.) */
834 Lisp_Object help_echo_string
;
835 Lisp_Object help_echo_window
;
836 Lisp_Object help_echo_object
;
839 /* Temporary variable for XTread_socket. */
841 Lisp_Object previous_help_echo_string
;
843 /* Null glyph slice */
845 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
848 /* Function prototypes. */
850 static void setup_for_ellipsis
P_ ((struct it
*, int));
851 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
852 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
853 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
854 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
855 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
856 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
859 static int invisible_text_between_p
P_ ((struct it
*, int, int));
862 static void pint2str
P_ ((char *, int, int));
863 static void pint2hrstr
P_ ((char *, int, int));
864 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
866 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
867 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
868 static void store_mode_line_noprop_char
P_ ((char));
869 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
870 static void x_consider_frame_title
P_ ((Lisp_Object
));
871 static void handle_stop
P_ ((struct it
*));
872 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
873 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
874 static void ensure_echo_area_buffers
P_ ((void));
875 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
876 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
877 static int with_echo_area_buffer
P_ ((struct window
*, int,
878 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
879 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
880 static void clear_garbaged_frames
P_ ((void));
881 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
882 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
883 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
884 static int display_echo_area
P_ ((struct window
*));
885 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
886 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
887 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
888 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
889 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
891 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
892 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
893 static void insert_left_trunc_glyphs
P_ ((struct it
*));
894 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
896 static void extend_face_to_end_of_line
P_ ((struct it
*));
897 static int append_space_for_newline
P_ ((struct it
*, int));
898 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
899 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
900 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
901 static int trailing_whitespace_p
P_ ((int));
902 static int message_log_check_duplicate
P_ ((int, int, int, int));
903 static void push_it
P_ ((struct it
*));
904 static void pop_it
P_ ((struct it
*));
905 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
906 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
907 static void redisplay_internal
P_ ((int));
908 static int echo_area_display
P_ ((int));
909 static void redisplay_windows
P_ ((Lisp_Object
));
910 static void redisplay_window
P_ ((Lisp_Object
, int));
911 static Lisp_Object
redisplay_window_error ();
912 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
913 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
914 static int update_menu_bar
P_ ((struct frame
*, int, int));
915 static int try_window_reusing_current_matrix
P_ ((struct window
*));
916 static int try_window_id
P_ ((struct window
*));
917 static int display_line
P_ ((struct it
*));
918 static int display_mode_lines
P_ ((struct window
*));
919 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
920 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
921 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
922 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
923 static void display_menu_bar
P_ ((struct window
*));
924 static int display_count_lines
P_ ((int, int, int, int, int *));
925 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
926 int, int, struct it
*, int, int, int, int));
927 static void compute_line_metrics
P_ ((struct it
*));
928 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
929 static int get_overlay_strings
P_ ((struct it
*, int));
930 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
931 static void next_overlay_string
P_ ((struct it
*));
932 static void reseat
P_ ((struct it
*, struct text_pos
, int));
933 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
934 static void back_to_previous_visible_line_start
P_ ((struct it
*));
935 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
936 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
937 static int next_element_from_ellipsis
P_ ((struct it
*));
938 static int next_element_from_display_vector
P_ ((struct it
*));
939 static int next_element_from_string
P_ ((struct it
*));
940 static int next_element_from_c_string
P_ ((struct it
*));
941 static int next_element_from_buffer
P_ ((struct it
*));
942 static int next_element_from_composition
P_ ((struct it
*));
943 static int next_element_from_image
P_ ((struct it
*));
944 static int next_element_from_stretch
P_ ((struct it
*));
945 static void load_overlay_strings
P_ ((struct it
*, int));
946 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
947 struct display_pos
*));
948 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
949 Lisp_Object
, int, int, int, int));
950 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
952 void move_it_vertically_backward
P_ ((struct it
*, int));
953 static void init_to_row_start
P_ ((struct it
*, struct window
*,
954 struct glyph_row
*));
955 static int init_to_row_end
P_ ((struct it
*, struct window
*,
956 struct glyph_row
*));
957 static void back_to_previous_line_start
P_ ((struct it
*));
958 static int forward_to_next_line_start
P_ ((struct it
*, int *));
959 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
961 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
962 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
963 static int number_of_chars
P_ ((unsigned char *, int));
964 static void compute_stop_pos
P_ ((struct it
*));
965 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
967 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
968 static int next_overlay_change
P_ ((int));
969 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
970 Lisp_Object
, Lisp_Object
,
971 struct text_pos
*, int));
972 static int underlying_face_id
P_ ((struct it
*));
973 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
976 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
977 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
979 #ifdef HAVE_WINDOW_SYSTEM
981 static void update_tool_bar
P_ ((struct frame
*, int));
982 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
983 static int redisplay_tool_bar
P_ ((struct frame
*));
984 static void display_tool_bar_line
P_ ((struct it
*, int));
985 static void notice_overwritten_cursor
P_ ((struct window
*,
987 int, int, int, int));
991 #endif /* HAVE_WINDOW_SYSTEM */
994 /***********************************************************************
995 Window display dimensions
996 ***********************************************************************/
998 /* Return the bottom boundary y-position for text lines in window W.
999 This is the first y position at which a line cannot start.
1000 It is relative to the top of the window.
1002 This is the height of W minus the height of a mode line, if any. */
1005 window_text_bottom_y (w
)
1008 int height
= WINDOW_TOTAL_HEIGHT (w
);
1010 if (WINDOW_WANTS_MODELINE_P (w
))
1011 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1015 /* Return the pixel width of display area AREA of window W. AREA < 0
1016 means return the total width of W, not including fringes to
1017 the left and right of the window. */
1020 window_box_width (w
, area
)
1024 int cols
= XFASTINT (w
->total_cols
);
1027 if (!w
->pseudo_window_p
)
1029 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1031 if (area
== TEXT_AREA
)
1033 if (INTEGERP (w
->left_margin_cols
))
1034 cols
-= XFASTINT (w
->left_margin_cols
);
1035 if (INTEGERP (w
->right_margin_cols
))
1036 cols
-= XFASTINT (w
->right_margin_cols
);
1037 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1039 else if (area
== LEFT_MARGIN_AREA
)
1041 cols
= (INTEGERP (w
->left_margin_cols
)
1042 ? XFASTINT (w
->left_margin_cols
) : 0);
1045 else if (area
== RIGHT_MARGIN_AREA
)
1047 cols
= (INTEGERP (w
->right_margin_cols
)
1048 ? XFASTINT (w
->right_margin_cols
) : 0);
1053 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1057 /* Return the pixel height of the display area of window W, not
1058 including mode lines of W, if any. */
1061 window_box_height (w
)
1064 struct frame
*f
= XFRAME (w
->frame
);
1065 int height
= WINDOW_TOTAL_HEIGHT (w
);
1067 xassert (height
>= 0);
1069 /* Note: the code below that determines the mode-line/header-line
1070 height is essentially the same as that contained in the macro
1071 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1072 the appropriate glyph row has its `mode_line_p' flag set,
1073 and if it doesn't, uses estimate_mode_line_height instead. */
1075 if (WINDOW_WANTS_MODELINE_P (w
))
1077 struct glyph_row
*ml_row
1078 = (w
->current_matrix
&& w
->current_matrix
->rows
1079 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1081 if (ml_row
&& ml_row
->mode_line_p
)
1082 height
-= ml_row
->height
;
1084 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1087 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1089 struct glyph_row
*hl_row
1090 = (w
->current_matrix
&& w
->current_matrix
->rows
1091 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1093 if (hl_row
&& hl_row
->mode_line_p
)
1094 height
-= hl_row
->height
;
1096 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1099 /* With a very small font and a mode-line that's taller than
1100 default, we might end up with a negative height. */
1101 return max (0, height
);
1104 /* Return the window-relative coordinate of the left edge of display
1105 area AREA of window W. AREA < 0 means return the left edge of the
1106 whole window, to the right of the left fringe of W. */
1109 window_box_left_offset (w
, area
)
1115 if (w
->pseudo_window_p
)
1118 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1120 if (area
== TEXT_AREA
)
1121 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1122 + window_box_width (w
, LEFT_MARGIN_AREA
));
1123 else if (area
== RIGHT_MARGIN_AREA
)
1124 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1125 + window_box_width (w
, LEFT_MARGIN_AREA
)
1126 + window_box_width (w
, TEXT_AREA
)
1127 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1129 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1130 else if (area
== LEFT_MARGIN_AREA
1131 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1132 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1138 /* Return the window-relative coordinate of the right edge of display
1139 area AREA of window W. AREA < 0 means return the left edge of the
1140 whole window, to the left of the right fringe of W. */
1143 window_box_right_offset (w
, area
)
1147 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1150 /* Return the frame-relative coordinate of the left edge of display
1151 area AREA of window W. AREA < 0 means return the left edge of the
1152 whole window, to the right of the left fringe of W. */
1155 window_box_left (w
, area
)
1159 struct frame
*f
= XFRAME (w
->frame
);
1162 if (w
->pseudo_window_p
)
1163 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1165 x
= (WINDOW_LEFT_EDGE_X (w
)
1166 + window_box_left_offset (w
, area
));
1172 /* Return the frame-relative coordinate of the right edge of display
1173 area AREA of window W. AREA < 0 means return the left edge of the
1174 whole window, to the left of the right fringe of W. */
1177 window_box_right (w
, area
)
1181 return window_box_left (w
, area
) + window_box_width (w
, area
);
1184 /* Get the bounding box of the display area AREA of window W, without
1185 mode lines, in frame-relative coordinates. AREA < 0 means the
1186 whole window, not including the left and right fringes of
1187 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1188 coordinates of the upper-left corner of the box. Return in
1189 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1192 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1195 int *box_x
, *box_y
, *box_width
, *box_height
;
1198 *box_width
= window_box_width (w
, area
);
1200 *box_height
= window_box_height (w
);
1202 *box_x
= window_box_left (w
, area
);
1205 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1206 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1207 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1212 /* Get the bounding box of the display area AREA of window W, without
1213 mode lines. AREA < 0 means the whole window, not including the
1214 left and right fringe of the window. Return in *TOP_LEFT_X
1215 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1216 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1217 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1221 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1222 bottom_right_x
, bottom_right_y
)
1225 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1227 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1229 *bottom_right_x
+= *top_left_x
;
1230 *bottom_right_y
+= *top_left_y
;
1235 /***********************************************************************
1237 ***********************************************************************/
1239 /* Return the bottom y-position of the line the iterator IT is in.
1240 This can modify IT's settings. */
1246 int line_height
= it
->max_ascent
+ it
->max_descent
;
1247 int line_top_y
= it
->current_y
;
1249 if (line_height
== 0)
1252 line_height
= last_height
;
1253 else if (IT_CHARPOS (*it
) < ZV
)
1255 move_it_by_lines (it
, 1, 1);
1256 line_height
= (it
->max_ascent
|| it
->max_descent
1257 ? it
->max_ascent
+ it
->max_descent
1262 struct glyph_row
*row
= it
->glyph_row
;
1264 /* Use the default character height. */
1265 it
->glyph_row
= NULL
;
1266 it
->what
= IT_CHARACTER
;
1269 PRODUCE_GLYPHS (it
);
1270 line_height
= it
->ascent
+ it
->descent
;
1271 it
->glyph_row
= row
;
1275 return line_top_y
+ line_height
;
1279 /* Return 1 if position CHARPOS is visible in window W.
1280 CHARPOS < 0 means return info about WINDOW_END position.
1281 If visible, set *X and *Y to pixel coordinates of top left corner.
1282 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1283 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1286 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1288 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1291 struct text_pos top
;
1293 struct buffer
*old_buffer
= NULL
;
1298 if (XBUFFER (w
->buffer
) != current_buffer
)
1300 old_buffer
= current_buffer
;
1301 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1304 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1306 /* Compute exact mode line heights. */
1307 if (WINDOW_WANTS_MODELINE_P (w
))
1308 current_mode_line_height
1309 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1310 current_buffer
->mode_line_format
);
1312 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1313 current_header_line_height
1314 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1315 current_buffer
->header_line_format
);
1317 start_display (&it
, w
, top
);
1318 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1319 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1321 /* Note that we may overshoot because of invisible text. */
1322 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1324 int top_x
= it
.current_x
;
1325 int top_y
= it
.current_y
;
1326 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1327 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1329 if (top_y
< window_top_y
)
1330 visible_p
= bottom_y
> window_top_y
;
1331 else if (top_y
< it
.last_visible_y
)
1336 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1337 *rtop
= max (0, window_top_y
- top_y
);
1338 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1339 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1340 - max (top_y
, window_top_y
)));
1349 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1350 move_it_by_lines (&it
, 1, 0);
1351 if (charpos
< IT_CHARPOS (it
)
1352 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1355 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1357 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1358 *rtop
= max (0, -it2
.current_y
);
1359 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1360 - it
.last_visible_y
));
1361 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1363 - max (it2
.current_y
,
1364 WINDOW_HEADER_LINE_HEIGHT (w
))));
1370 set_buffer_internal_1 (old_buffer
);
1372 current_header_line_height
= current_mode_line_height
= -1;
1374 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1375 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1378 /* Debugging code. */
1380 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1381 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1383 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1390 /* Return the next character from STR which is MAXLEN bytes long.
1391 Return in *LEN the length of the character. This is like
1392 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1393 we find one, we return a `?', but with the length of the invalid
1397 string_char_and_length (str
, maxlen
, len
)
1398 const unsigned char *str
;
1403 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1404 if (!CHAR_VALID_P (c
, 1))
1405 /* We may not change the length here because other places in Emacs
1406 don't use this function, i.e. they silently accept invalid
1415 /* Given a position POS containing a valid character and byte position
1416 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1418 static struct text_pos
1419 string_pos_nchars_ahead (pos
, string
, nchars
)
1420 struct text_pos pos
;
1424 xassert (STRINGP (string
) && nchars
>= 0);
1426 if (STRING_MULTIBYTE (string
))
1428 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1429 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1434 string_char_and_length (p
, rest
, &len
);
1435 p
+= len
, rest
-= len
;
1436 xassert (rest
>= 0);
1438 BYTEPOS (pos
) += len
;
1442 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1448 /* Value is the text position, i.e. character and byte position,
1449 for character position CHARPOS in STRING. */
1451 static INLINE
struct text_pos
1452 string_pos (charpos
, string
)
1456 struct text_pos pos
;
1457 xassert (STRINGP (string
));
1458 xassert (charpos
>= 0);
1459 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1464 /* Value is a text position, i.e. character and byte position, for
1465 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1466 means recognize multibyte characters. */
1468 static struct text_pos
1469 c_string_pos (charpos
, s
, multibyte_p
)
1474 struct text_pos pos
;
1476 xassert (s
!= NULL
);
1477 xassert (charpos
>= 0);
1481 int rest
= strlen (s
), len
;
1483 SET_TEXT_POS (pos
, 0, 0);
1486 string_char_and_length (s
, rest
, &len
);
1487 s
+= len
, rest
-= len
;
1488 xassert (rest
>= 0);
1490 BYTEPOS (pos
) += len
;
1494 SET_TEXT_POS (pos
, charpos
, charpos
);
1500 /* Value is the number of characters in C string S. MULTIBYTE_P
1501 non-zero means recognize multibyte characters. */
1504 number_of_chars (s
, multibyte_p
)
1512 int rest
= strlen (s
), len
;
1513 unsigned char *p
= (unsigned char *) s
;
1515 for (nchars
= 0; rest
> 0; ++nchars
)
1517 string_char_and_length (p
, rest
, &len
);
1518 rest
-= len
, p
+= len
;
1522 nchars
= strlen (s
);
1528 /* Compute byte position NEWPOS->bytepos corresponding to
1529 NEWPOS->charpos. POS is a known position in string STRING.
1530 NEWPOS->charpos must be >= POS.charpos. */
1533 compute_string_pos (newpos
, pos
, string
)
1534 struct text_pos
*newpos
, pos
;
1537 xassert (STRINGP (string
));
1538 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1540 if (STRING_MULTIBYTE (string
))
1541 *newpos
= string_pos_nchars_ahead (pos
, string
,
1542 CHARPOS (*newpos
) - CHARPOS (pos
));
1544 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1548 Return an estimation of the pixel height of mode or top lines on
1549 frame F. FACE_ID specifies what line's height to estimate. */
1552 estimate_mode_line_height (f
, face_id
)
1554 enum face_id face_id
;
1556 #ifdef HAVE_WINDOW_SYSTEM
1557 if (FRAME_WINDOW_P (f
))
1559 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1561 /* This function is called so early when Emacs starts that the face
1562 cache and mode line face are not yet initialized. */
1563 if (FRAME_FACE_CACHE (f
))
1565 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1569 height
= FONT_HEIGHT (face
->font
);
1570 if (face
->box_line_width
> 0)
1571 height
+= 2 * face
->box_line_width
;
1582 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1583 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1584 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1585 not force the value into range. */
1588 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1590 register int pix_x
, pix_y
;
1592 NativeRectangle
*bounds
;
1596 #ifdef HAVE_WINDOW_SYSTEM
1597 if (FRAME_WINDOW_P (f
))
1599 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1600 even for negative values. */
1602 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1604 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1606 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1607 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1610 STORE_NATIVE_RECT (*bounds
,
1611 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1612 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1613 FRAME_COLUMN_WIDTH (f
) - 1,
1614 FRAME_LINE_HEIGHT (f
) - 1);
1620 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1621 pix_x
= FRAME_TOTAL_COLS (f
);
1625 else if (pix_y
> FRAME_LINES (f
))
1626 pix_y
= FRAME_LINES (f
);
1636 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1637 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1638 can't tell the positions because W's display is not up to date,
1642 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1645 int *frame_x
, *frame_y
;
1647 #ifdef HAVE_WINDOW_SYSTEM
1648 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1652 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1653 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1655 if (display_completed
)
1657 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1658 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1659 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1665 hpos
+= glyph
->pixel_width
;
1669 /* If first glyph is partially visible, its first visible position is still 0. */
1681 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1682 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1693 #ifdef HAVE_WINDOW_SYSTEM
1695 /* Find the glyph under window-relative coordinates X/Y in window W.
1696 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1697 strings. Return in *HPOS and *VPOS the row and column number of
1698 the glyph found. Return in *AREA the glyph area containing X.
1699 Value is a pointer to the glyph found or null if X/Y is not on
1700 text, or we can't tell because W's current matrix is not up to
1707 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1710 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1712 struct glyph
*glyph
, *end
;
1713 struct glyph_row
*row
= NULL
;
1716 /* Find row containing Y. Give up if some row is not enabled. */
1717 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1719 row
= MATRIX_ROW (w
->current_matrix
, i
);
1720 if (!row
->enabled_p
)
1722 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1729 /* Give up if Y is not in the window. */
1730 if (i
== w
->current_matrix
->nrows
)
1733 /* Get the glyph area containing X. */
1734 if (w
->pseudo_window_p
)
1741 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1743 *area
= LEFT_MARGIN_AREA
;
1744 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1746 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1749 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1753 *area
= RIGHT_MARGIN_AREA
;
1754 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1758 /* Find glyph containing X. */
1759 glyph
= row
->glyphs
[*area
];
1760 end
= glyph
+ row
->used
[*area
];
1762 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1764 x
-= glyph
->pixel_width
;
1774 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1777 *hpos
= glyph
- row
->glyphs
[*area
];
1783 Convert frame-relative x/y to coordinates relative to window W.
1784 Takes pseudo-windows into account. */
1787 frame_to_window_pixel_xy (w
, x
, y
)
1791 if (w
->pseudo_window_p
)
1793 /* A pseudo-window is always full-width, and starts at the
1794 left edge of the frame, plus a frame border. */
1795 struct frame
*f
= XFRAME (w
->frame
);
1796 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1797 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1801 *x
-= WINDOW_LEFT_EDGE_X (w
);
1802 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1807 Return in RECTS[] at most N clipping rectangles for glyph string S.
1808 Return the number of stored rectangles. */
1811 get_glyph_string_clip_rects (s
, rects
, n
)
1812 struct glyph_string
*s
;
1813 NativeRectangle
*rects
;
1821 if (s
->row
->full_width_p
)
1823 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1824 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1825 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1827 /* Unless displaying a mode or menu bar line, which are always
1828 fully visible, clip to the visible part of the row. */
1829 if (s
->w
->pseudo_window_p
)
1830 r
.height
= s
->row
->visible_height
;
1832 r
.height
= s
->height
;
1836 /* This is a text line that may be partially visible. */
1837 r
.x
= window_box_left (s
->w
, s
->area
);
1838 r
.width
= window_box_width (s
->w
, s
->area
);
1839 r
.height
= s
->row
->visible_height
;
1843 if (r
.x
< s
->clip_head
->x
)
1845 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1846 r
.width
-= s
->clip_head
->x
- r
.x
;
1849 r
.x
= s
->clip_head
->x
;
1852 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1854 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1855 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1860 /* If S draws overlapping rows, it's sufficient to use the top and
1861 bottom of the window for clipping because this glyph string
1862 intentionally draws over other lines. */
1863 if (s
->for_overlaps
)
1865 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1866 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1868 /* Alas, the above simple strategy does not work for the
1869 environments with anti-aliased text: if the same text is
1870 drawn onto the same place multiple times, it gets thicker.
1871 If the overlap we are processing is for the erased cursor, we
1872 take the intersection with the rectagle of the cursor. */
1873 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1875 XRectangle rc
, r_save
= r
;
1877 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1878 rc
.y
= s
->w
->phys_cursor
.y
;
1879 rc
.width
= s
->w
->phys_cursor_width
;
1880 rc
.height
= s
->w
->phys_cursor_height
;
1882 x_intersect_rectangles (&r_save
, &rc
, &r
);
1887 /* Don't use S->y for clipping because it doesn't take partially
1888 visible lines into account. For example, it can be negative for
1889 partially visible lines at the top of a window. */
1890 if (!s
->row
->full_width_p
1891 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1892 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1894 r
.y
= max (0, s
->row
->y
);
1896 /* If drawing a tool-bar window, draw it over the internal border
1897 at the top of the window. */
1898 if (WINDOWP (s
->f
->tool_bar_window
)
1899 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1900 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1903 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1905 /* If drawing the cursor, don't let glyph draw outside its
1906 advertised boundaries. Cleartype does this under some circumstances. */
1907 if (s
->hl
== DRAW_CURSOR
)
1909 struct glyph
*glyph
= s
->first_glyph
;
1914 r
.width
-= s
->x
- r
.x
;
1917 r
.width
= min (r
.width
, glyph
->pixel_width
);
1919 /* If r.y is below window bottom, ensure that we still see a cursor. */
1920 height
= min (glyph
->ascent
+ glyph
->descent
,
1921 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1922 max_y
= window_text_bottom_y (s
->w
) - height
;
1923 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1924 if (s
->ybase
- glyph
->ascent
> max_y
)
1931 /* Don't draw cursor glyph taller than our actual glyph. */
1932 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1933 if (height
< r
.height
)
1935 max_y
= r
.y
+ r
.height
;
1936 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1937 r
.height
= min (max_y
- r
.y
, height
);
1942 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1943 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1945 #ifdef CONVERT_FROM_XRECT
1946 CONVERT_FROM_XRECT (r
, *rects
);
1954 /* If we are processing overlapping and allowed to return
1955 multiple clipping rectangles, we exclude the row of the glyph
1956 string from the clipping rectangle. This is to avoid drawing
1957 the same text on the environment with anti-aliasing. */
1958 #ifdef CONVERT_FROM_XRECT
1961 XRectangle
*rs
= rects
;
1963 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
1965 if (s
->for_overlaps
& OVERLAPS_PRED
)
1968 if (r
.y
+ r
.height
> row_y
)
1971 rs
[i
].height
= row_y
- r
.y
;
1977 if (s
->for_overlaps
& OVERLAPS_SUCC
)
1980 if (r
.y
< row_y
+ s
->row
->visible_height
)
1982 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
1984 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
1985 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
1994 #ifdef CONVERT_FROM_XRECT
1995 for (i
= 0; i
< n
; i
++)
1996 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2003 Return in *NR the clipping rectangle for glyph string S. */
2006 get_glyph_string_clip_rect (s
, nr
)
2007 struct glyph_string
*s
;
2008 NativeRectangle
*nr
;
2010 get_glyph_string_clip_rects (s
, nr
, 1);
2015 Return the position and height of the phys cursor in window W.
2016 Set w->phys_cursor_width to width of phys cursor.
2020 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2022 struct glyph_row
*row
;
2023 struct glyph
*glyph
;
2024 int *xp
, *yp
, *heightp
;
2026 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2027 int x
, y
, wd
, h
, h0
, y0
;
2029 /* Compute the width of the rectangle to draw. If on a stretch
2030 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2031 rectangle as wide as the glyph, but use a canonical character
2033 wd
= glyph
->pixel_width
- 1;
2038 x
= w
->phys_cursor
.x
;
2045 if (glyph
->type
== STRETCH_GLYPH
2046 && !x_stretch_cursor_p
)
2047 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2048 w
->phys_cursor_width
= wd
;
2050 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2052 /* If y is below window bottom, ensure that we still see a cursor. */
2053 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2055 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2056 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2058 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2061 h
= max (h
- (y0
- y
) + 1, h0
);
2066 y0
= window_text_bottom_y (w
) - h0
;
2074 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2075 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2080 * Remember which glyph the mouse is over.
2084 remember_mouse_glyph (f
, gx
, gy
, rect
)
2087 NativeRectangle
*rect
;
2091 struct glyph_row
*r
, *gr
, *end_row
;
2092 enum window_part part
;
2093 enum glyph_row_area area
;
2094 int x
, y
, width
, height
;
2096 /* Try to determine frame pixel position and size of the glyph under
2097 frame pixel coordinates X/Y on frame F. */
2099 if (!f
->glyphs_initialized_p
2100 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2103 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2104 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2108 w
= XWINDOW (window
);
2109 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2110 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2112 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2113 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2115 if (w
->pseudo_window_p
)
2118 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2124 case ON_LEFT_MARGIN
:
2125 area
= LEFT_MARGIN_AREA
;
2128 case ON_RIGHT_MARGIN
:
2129 area
= RIGHT_MARGIN_AREA
;
2132 case ON_HEADER_LINE
:
2134 gr
= (part
== ON_HEADER_LINE
2135 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2136 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2139 goto text_glyph_row_found
;
2146 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2147 if (r
->y
+ r
->height
> y
)
2153 text_glyph_row_found
:
2156 struct glyph
*g
= gr
->glyphs
[area
];
2157 struct glyph
*end
= g
+ gr
->used
[area
];
2159 height
= gr
->height
;
2160 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2161 if (gx
+ g
->pixel_width
> x
)
2166 if (g
->type
== IMAGE_GLYPH
)
2168 /* Don't remember when mouse is over image, as
2169 image may have hot-spots. */
2170 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2173 width
= g
->pixel_width
;
2177 /* Use nominal char spacing at end of line. */
2179 gx
+= (x
/ width
) * width
;
2182 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2183 gx
+= window_box_left_offset (w
, area
);
2187 /* Use nominal line height at end of window. */
2188 gx
= (x
/ width
) * width
;
2190 gy
+= (y
/ height
) * height
;
2194 case ON_LEFT_FRINGE
:
2195 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2196 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2197 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2198 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2201 case ON_RIGHT_FRINGE
:
2202 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2203 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2204 : window_box_right_offset (w
, TEXT_AREA
));
2205 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2209 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2211 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2212 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2213 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2215 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2219 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2220 if (r
->y
+ r
->height
> y
)
2227 height
= gr
->height
;
2230 /* Use nominal line height at end of window. */
2232 gy
+= (y
/ height
) * height
;
2239 /* If there is no glyph under the mouse, then we divide the screen
2240 into a grid of the smallest glyph in the frame, and use that
2243 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2244 round down even for negative values. */
2250 gx
= (gx
/ width
) * width
;
2251 gy
= (gy
/ height
) * height
;
2256 gx
+= WINDOW_LEFT_EDGE_X (w
);
2257 gy
+= WINDOW_TOP_EDGE_Y (w
);
2260 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2262 /* Visible feedback for debugging. */
2265 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2266 f
->output_data
.x
->normal_gc
,
2267 gx
, gy
, width
, height
);
2273 #endif /* HAVE_WINDOW_SYSTEM */
2276 /***********************************************************************
2277 Lisp form evaluation
2278 ***********************************************************************/
2280 /* Error handler for safe_eval and safe_call. */
2283 safe_eval_handler (arg
)
2286 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2291 /* Evaluate SEXPR and return the result, or nil if something went
2292 wrong. Prevent redisplay during the evaluation. */
2300 if (inhibit_eval_during_redisplay
)
2304 int count
= SPECPDL_INDEX ();
2305 struct gcpro gcpro1
;
2308 specbind (Qinhibit_redisplay
, Qt
);
2309 /* Use Qt to ensure debugger does not run,
2310 so there is no possibility of wanting to redisplay. */
2311 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
2314 val
= unbind_to (count
, val
);
2321 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2322 Return the result, or nil if something went wrong. Prevent
2323 redisplay during the evaluation. */
2326 safe_call (nargs
, args
)
2332 if (inhibit_eval_during_redisplay
)
2336 int count
= SPECPDL_INDEX ();
2337 struct gcpro gcpro1
;
2340 gcpro1
.nvars
= nargs
;
2341 specbind (Qinhibit_redisplay
, Qt
);
2342 /* Use Qt to ensure debugger does not run,
2343 so there is no possibility of wanting to redisplay. */
2344 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2347 val
= unbind_to (count
, val
);
2354 /* Call function FN with one argument ARG.
2355 Return the result, or nil if something went wrong. */
2358 safe_call1 (fn
, arg
)
2359 Lisp_Object fn
, arg
;
2361 Lisp_Object args
[2];
2364 return safe_call (2, args
);
2369 /***********************************************************************
2371 ***********************************************************************/
2375 /* Define CHECK_IT to perform sanity checks on iterators.
2376 This is for debugging. It is too slow to do unconditionally. */
2382 if (it
->method
== GET_FROM_STRING
)
2384 xassert (STRINGP (it
->string
));
2385 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2389 xassert (IT_STRING_CHARPOS (*it
) < 0);
2390 if (it
->method
== GET_FROM_BUFFER
)
2392 /* Check that character and byte positions agree. */
2393 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2398 xassert (it
->current
.dpvec_index
>= 0);
2400 xassert (it
->current
.dpvec_index
< 0);
2403 #define CHECK_IT(IT) check_it ((IT))
2407 #define CHECK_IT(IT) (void) 0
2414 /* Check that the window end of window W is what we expect it
2415 to be---the last row in the current matrix displaying text. */
2418 check_window_end (w
)
2421 if (!MINI_WINDOW_P (w
)
2422 && !NILP (w
->window_end_valid
))
2424 struct glyph_row
*row
;
2425 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2426 XFASTINT (w
->window_end_vpos
)),
2428 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2429 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2433 #define CHECK_WINDOW_END(W) check_window_end ((W))
2435 #else /* not GLYPH_DEBUG */
2437 #define CHECK_WINDOW_END(W) (void) 0
2439 #endif /* not GLYPH_DEBUG */
2443 /***********************************************************************
2444 Iterator initialization
2445 ***********************************************************************/
2447 /* Initialize IT for displaying current_buffer in window W, starting
2448 at character position CHARPOS. CHARPOS < 0 means that no buffer
2449 position is specified which is useful when the iterator is assigned
2450 a position later. BYTEPOS is the byte position corresponding to
2451 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2453 If ROW is not null, calls to produce_glyphs with IT as parameter
2454 will produce glyphs in that row.
2456 BASE_FACE_ID is the id of a base face to use. It must be one of
2457 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2458 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2459 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2461 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2462 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2463 will be initialized to use the corresponding mode line glyph row of
2464 the desired matrix of W. */
2467 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2470 int charpos
, bytepos
;
2471 struct glyph_row
*row
;
2472 enum face_id base_face_id
;
2474 int highlight_region_p
;
2476 /* Some precondition checks. */
2477 xassert (w
!= NULL
&& it
!= NULL
);
2478 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2481 /* If face attributes have been changed since the last redisplay,
2482 free realized faces now because they depend on face definitions
2483 that might have changed. Don't free faces while there might be
2484 desired matrices pending which reference these faces. */
2485 if (face_change_count
&& !inhibit_free_realized_faces
)
2487 face_change_count
= 0;
2488 free_all_realized_faces (Qnil
);
2491 /* Use one of the mode line rows of W's desired matrix if
2495 if (base_face_id
== MODE_LINE_FACE_ID
2496 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2497 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2498 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2499 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2503 bzero (it
, sizeof *it
);
2504 it
->current
.overlay_string_index
= -1;
2505 it
->current
.dpvec_index
= -1;
2506 it
->base_face_id
= base_face_id
;
2508 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2510 /* The window in which we iterate over current_buffer: */
2511 XSETWINDOW (it
->window
, w
);
2513 it
->f
= XFRAME (w
->frame
);
2515 /* Extra space between lines (on window systems only). */
2516 if (base_face_id
== DEFAULT_FACE_ID
2517 && FRAME_WINDOW_P (it
->f
))
2519 if (NATNUMP (current_buffer
->extra_line_spacing
))
2520 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2521 else if (FLOATP (current_buffer
->extra_line_spacing
))
2522 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2523 * FRAME_LINE_HEIGHT (it
->f
));
2524 else if (it
->f
->extra_line_spacing
> 0)
2525 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2526 it
->max_extra_line_spacing
= 0;
2529 /* If realized faces have been removed, e.g. because of face
2530 attribute changes of named faces, recompute them. When running
2531 in batch mode, the face cache of Vterminal_frame is null. If
2532 we happen to get called, make a dummy face cache. */
2533 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2534 init_frame_faces (it
->f
);
2535 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2536 recompute_basic_faces (it
->f
);
2538 /* Current value of the `slice', `space-width', and 'height' properties. */
2539 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2540 it
->space_width
= Qnil
;
2541 it
->font_height
= Qnil
;
2542 it
->override_ascent
= -1;
2544 /* Are control characters displayed as `^C'? */
2545 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2547 /* -1 means everything between a CR and the following line end
2548 is invisible. >0 means lines indented more than this value are
2550 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2551 ? XFASTINT (current_buffer
->selective_display
)
2552 : (!NILP (current_buffer
->selective_display
)
2554 it
->selective_display_ellipsis_p
2555 = !NILP (current_buffer
->selective_display_ellipses
);
2557 /* Display table to use. */
2558 it
->dp
= window_display_table (w
);
2560 /* Are multibyte characters enabled in current_buffer? */
2561 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2563 /* Non-zero if we should highlight the region. */
2565 = (!NILP (Vtransient_mark_mode
)
2566 && !NILP (current_buffer
->mark_active
)
2567 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2569 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2570 start and end of a visible region in window IT->w. Set both to
2571 -1 to indicate no region. */
2572 if (highlight_region_p
2573 /* Maybe highlight only in selected window. */
2574 && (/* Either show region everywhere. */
2575 highlight_nonselected_windows
2576 /* Or show region in the selected window. */
2577 || w
== XWINDOW (selected_window
)
2578 /* Or show the region if we are in the mini-buffer and W is
2579 the window the mini-buffer refers to. */
2580 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2581 && WINDOWP (minibuf_selected_window
)
2582 && w
== XWINDOW (minibuf_selected_window
))))
2584 int charpos
= marker_position (current_buffer
->mark
);
2585 it
->region_beg_charpos
= min (PT
, charpos
);
2586 it
->region_end_charpos
= max (PT
, charpos
);
2589 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2591 /* Get the position at which the redisplay_end_trigger hook should
2592 be run, if it is to be run at all. */
2593 if (MARKERP (w
->redisplay_end_trigger
)
2594 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2595 it
->redisplay_end_trigger_charpos
2596 = marker_position (w
->redisplay_end_trigger
);
2597 else if (INTEGERP (w
->redisplay_end_trigger
))
2598 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2600 /* Correct bogus values of tab_width. */
2601 it
->tab_width
= XINT (current_buffer
->tab_width
);
2602 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2605 /* Are lines in the display truncated? */
2606 it
->truncate_lines_p
2607 = (base_face_id
!= DEFAULT_FACE_ID
2608 || XINT (it
->w
->hscroll
)
2609 || (truncate_partial_width_windows
2610 && !WINDOW_FULL_WIDTH_P (it
->w
))
2611 || !NILP (current_buffer
->truncate_lines
));
2613 /* Get dimensions of truncation and continuation glyphs. These are
2614 displayed as fringe bitmaps under X, so we don't need them for such
2616 if (!FRAME_WINDOW_P (it
->f
))
2618 if (it
->truncate_lines_p
)
2620 /* We will need the truncation glyph. */
2621 xassert (it
->glyph_row
== NULL
);
2622 produce_special_glyphs (it
, IT_TRUNCATION
);
2623 it
->truncation_pixel_width
= it
->pixel_width
;
2627 /* We will need the continuation glyph. */
2628 xassert (it
->glyph_row
== NULL
);
2629 produce_special_glyphs (it
, IT_CONTINUATION
);
2630 it
->continuation_pixel_width
= it
->pixel_width
;
2633 /* Reset these values to zero because the produce_special_glyphs
2634 above has changed them. */
2635 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2636 it
->phys_ascent
= it
->phys_descent
= 0;
2639 /* Set this after getting the dimensions of truncation and
2640 continuation glyphs, so that we don't produce glyphs when calling
2641 produce_special_glyphs, above. */
2642 it
->glyph_row
= row
;
2643 it
->area
= TEXT_AREA
;
2645 /* Get the dimensions of the display area. The display area
2646 consists of the visible window area plus a horizontally scrolled
2647 part to the left of the window. All x-values are relative to the
2648 start of this total display area. */
2649 if (base_face_id
!= DEFAULT_FACE_ID
)
2651 /* Mode lines, menu bar in terminal frames. */
2652 it
->first_visible_x
= 0;
2653 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2658 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2659 it
->last_visible_x
= (it
->first_visible_x
2660 + window_box_width (w
, TEXT_AREA
));
2662 /* If we truncate lines, leave room for the truncator glyph(s) at
2663 the right margin. Otherwise, leave room for the continuation
2664 glyph(s). Truncation and continuation glyphs are not inserted
2665 for window-based redisplay. */
2666 if (!FRAME_WINDOW_P (it
->f
))
2668 if (it
->truncate_lines_p
)
2669 it
->last_visible_x
-= it
->truncation_pixel_width
;
2671 it
->last_visible_x
-= it
->continuation_pixel_width
;
2674 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2675 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2678 /* Leave room for a border glyph. */
2679 if (!FRAME_WINDOW_P (it
->f
)
2680 && !WINDOW_RIGHTMOST_P (it
->w
))
2681 it
->last_visible_x
-= 1;
2683 it
->last_visible_y
= window_text_bottom_y (w
);
2685 /* For mode lines and alike, arrange for the first glyph having a
2686 left box line if the face specifies a box. */
2687 if (base_face_id
!= DEFAULT_FACE_ID
)
2691 it
->face_id
= base_face_id
;
2693 /* If we have a boxed mode line, make the first character appear
2694 with a left box line. */
2695 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2696 if (face
->box
!= FACE_NO_BOX
)
2697 it
->start_of_box_run_p
= 1;
2700 /* If a buffer position was specified, set the iterator there,
2701 getting overlays and face properties from that position. */
2702 if (charpos
>= BUF_BEG (current_buffer
))
2704 it
->end_charpos
= ZV
;
2706 IT_CHARPOS (*it
) = charpos
;
2708 /* Compute byte position if not specified. */
2709 if (bytepos
< charpos
)
2710 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2712 IT_BYTEPOS (*it
) = bytepos
;
2714 it
->start
= it
->current
;
2716 /* Compute faces etc. */
2717 reseat (it
, it
->current
.pos
, 1);
2724 /* Initialize IT for the display of window W with window start POS. */
2727 start_display (it
, w
, pos
)
2730 struct text_pos pos
;
2732 struct glyph_row
*row
;
2733 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2735 row
= w
->desired_matrix
->rows
+ first_vpos
;
2736 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2737 it
->first_vpos
= first_vpos
;
2739 /* Don't reseat to previous visible line start if current start
2740 position is in a string or image. */
2741 if (it
->method
== GET_FROM_BUFFER
&& !it
->truncate_lines_p
)
2743 int start_at_line_beg_p
;
2744 int first_y
= it
->current_y
;
2746 /* If window start is not at a line start, skip forward to POS to
2747 get the correct continuation lines width. */
2748 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2749 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2750 if (!start_at_line_beg_p
)
2754 reseat_at_previous_visible_line_start (it
);
2755 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2757 new_x
= it
->current_x
+ it
->pixel_width
;
2759 /* If lines are continued, this line may end in the middle
2760 of a multi-glyph character (e.g. a control character
2761 displayed as \003, or in the middle of an overlay
2762 string). In this case move_it_to above will not have
2763 taken us to the start of the continuation line but to the
2764 end of the continued line. */
2765 if (it
->current_x
> 0
2766 && !it
->truncate_lines_p
/* Lines are continued. */
2767 && (/* And glyph doesn't fit on the line. */
2768 new_x
> it
->last_visible_x
2769 /* Or it fits exactly and we're on a window
2771 || (new_x
== it
->last_visible_x
2772 && FRAME_WINDOW_P (it
->f
))))
2774 if (it
->current
.dpvec_index
>= 0
2775 || it
->current
.overlay_string_index
>= 0)
2777 set_iterator_to_next (it
, 1);
2778 move_it_in_display_line_to (it
, -1, -1, 0);
2781 it
->continuation_lines_width
+= it
->current_x
;
2784 /* We're starting a new display line, not affected by the
2785 height of the continued line, so clear the appropriate
2786 fields in the iterator structure. */
2787 it
->max_ascent
= it
->max_descent
= 0;
2788 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2790 it
->current_y
= first_y
;
2792 it
->current_x
= it
->hpos
= 0;
2796 #if 0 /* Don't assert the following because start_display is sometimes
2797 called intentionally with a window start that is not at a
2798 line start. Please leave this code in as a comment. */
2800 /* Window start should be on a line start, now. */
2801 xassert (it
->continuation_lines_width
2802 || IT_CHARPOS (it
) == BEGV
2803 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2808 /* Return 1 if POS is a position in ellipses displayed for invisible
2809 text. W is the window we display, for text property lookup. */
2812 in_ellipses_for_invisible_text_p (pos
, w
)
2813 struct display_pos
*pos
;
2816 Lisp_Object prop
, window
;
2818 int charpos
= CHARPOS (pos
->pos
);
2820 /* If POS specifies a position in a display vector, this might
2821 be for an ellipsis displayed for invisible text. We won't
2822 get the iterator set up for delivering that ellipsis unless
2823 we make sure that it gets aware of the invisible text. */
2824 if (pos
->dpvec_index
>= 0
2825 && pos
->overlay_string_index
< 0
2826 && CHARPOS (pos
->string_pos
) < 0
2828 && (XSETWINDOW (window
, w
),
2829 prop
= Fget_char_property (make_number (charpos
),
2830 Qinvisible
, window
),
2831 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2833 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2835 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2842 /* Initialize IT for stepping through current_buffer in window W,
2843 starting at position POS that includes overlay string and display
2844 vector/ control character translation position information. Value
2845 is zero if there are overlay strings with newlines at POS. */
2848 init_from_display_pos (it
, w
, pos
)
2851 struct display_pos
*pos
;
2853 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2854 int i
, overlay_strings_with_newlines
= 0;
2856 /* If POS specifies a position in a display vector, this might
2857 be for an ellipsis displayed for invisible text. We won't
2858 get the iterator set up for delivering that ellipsis unless
2859 we make sure that it gets aware of the invisible text. */
2860 if (in_ellipses_for_invisible_text_p (pos
, w
))
2866 /* Keep in mind: the call to reseat in init_iterator skips invisible
2867 text, so we might end up at a position different from POS. This
2868 is only a problem when POS is a row start after a newline and an
2869 overlay starts there with an after-string, and the overlay has an
2870 invisible property. Since we don't skip invisible text in
2871 display_line and elsewhere immediately after consuming the
2872 newline before the row start, such a POS will not be in a string,
2873 but the call to init_iterator below will move us to the
2875 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2877 /* This only scans the current chunk -- it should scan all chunks.
2878 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2879 to 16 in 22.1 to make this a lesser problem. */
2880 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2882 const char *s
= SDATA (it
->overlay_strings
[i
]);
2883 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2885 while (s
< e
&& *s
!= '\n')
2890 overlay_strings_with_newlines
= 1;
2895 /* If position is within an overlay string, set up IT to the right
2897 if (pos
->overlay_string_index
>= 0)
2901 /* If the first overlay string happens to have a `display'
2902 property for an image, the iterator will be set up for that
2903 image, and we have to undo that setup first before we can
2904 correct the overlay string index. */
2905 if (it
->method
== GET_FROM_IMAGE
)
2908 /* We already have the first chunk of overlay strings in
2909 IT->overlay_strings. Load more until the one for
2910 pos->overlay_string_index is in IT->overlay_strings. */
2911 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2913 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2914 it
->current
.overlay_string_index
= 0;
2917 load_overlay_strings (it
, 0);
2918 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2922 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2923 relative_index
= (it
->current
.overlay_string_index
2924 % OVERLAY_STRING_CHUNK_SIZE
);
2925 it
->string
= it
->overlay_strings
[relative_index
];
2926 xassert (STRINGP (it
->string
));
2927 it
->current
.string_pos
= pos
->string_pos
;
2928 it
->method
= GET_FROM_STRING
;
2931 #if 0 /* This is bogus because POS not having an overlay string
2932 position does not mean it's after the string. Example: A
2933 line starting with a before-string and initialization of IT
2934 to the previous row's end position. */
2935 else if (it
->current
.overlay_string_index
>= 0)
2937 /* If POS says we're already after an overlay string ending at
2938 POS, make sure to pop the iterator because it will be in
2939 front of that overlay string. When POS is ZV, we've thereby
2940 also ``processed'' overlay strings at ZV. */
2943 xassert (it
->current
.overlay_string_index
== -1);
2944 xassert (it
->method
== GET_FROM_BUFFER
);
2945 if (CHARPOS (pos
->pos
) == ZV
)
2946 it
->overlay_strings_at_end_processed_p
= 1;
2950 if (CHARPOS (pos
->string_pos
) >= 0)
2952 /* Recorded position is not in an overlay string, but in another
2953 string. This can only be a string from a `display' property.
2954 IT should already be filled with that string. */
2955 it
->current
.string_pos
= pos
->string_pos
;
2956 xassert (STRINGP (it
->string
));
2959 /* Restore position in display vector translations, control
2960 character translations or ellipses. */
2961 if (pos
->dpvec_index
>= 0)
2963 if (it
->dpvec
== NULL
)
2964 get_next_display_element (it
);
2965 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2966 it
->current
.dpvec_index
= pos
->dpvec_index
;
2970 return !overlay_strings_with_newlines
;
2974 /* Initialize IT for stepping through current_buffer in window W
2975 starting at ROW->start. */
2978 init_to_row_start (it
, w
, row
)
2981 struct glyph_row
*row
;
2983 init_from_display_pos (it
, w
, &row
->start
);
2984 it
->start
= row
->start
;
2985 it
->continuation_lines_width
= row
->continuation_lines_width
;
2990 /* Initialize IT for stepping through current_buffer in window W
2991 starting in the line following ROW, i.e. starting at ROW->end.
2992 Value is zero if there are overlay strings with newlines at ROW's
2996 init_to_row_end (it
, w
, row
)
2999 struct glyph_row
*row
;
3003 if (init_from_display_pos (it
, w
, &row
->end
))
3005 if (row
->continued_p
)
3006 it
->continuation_lines_width
3007 = row
->continuation_lines_width
+ row
->pixel_width
;
3018 /***********************************************************************
3020 ***********************************************************************/
3022 /* Called when IT reaches IT->stop_charpos. Handle text property and
3023 overlay changes. Set IT->stop_charpos to the next position where
3030 enum prop_handled handled
;
3031 int handle_overlay_change_p
;
3035 it
->current
.dpvec_index
= -1;
3036 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3037 it
->ignore_overlay_strings_at_pos_p
= 0;
3039 /* Use face of preceding text for ellipsis (if invisible) */
3040 if (it
->selective_display_ellipsis_p
)
3041 it
->saved_face_id
= it
->face_id
;
3045 handled
= HANDLED_NORMALLY
;
3047 /* Call text property handlers. */
3048 for (p
= it_props
; p
->handler
; ++p
)
3050 handled
= p
->handler (it
);
3052 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3054 else if (handled
== HANDLED_RETURN
)
3056 /* We still want to show before and after strings from
3057 overlays even if the actual buffer text is replaced. */
3058 if (!handle_overlay_change_p
|| it
->sp
> 1)
3060 if (!get_overlay_strings_1 (it
, 0, 0))
3062 it
->ignore_overlay_strings_at_pos_p
= 1;
3063 it
->string_from_display_prop_p
= 0;
3064 handle_overlay_change_p
= 0;
3065 handled
= HANDLED_RECOMPUTE_PROPS
;
3068 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3069 handle_overlay_change_p
= 0;
3072 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3074 /* Don't check for overlay strings below when set to deliver
3075 characters from a display vector. */
3076 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3077 handle_overlay_change_p
= 0;
3079 /* Handle overlay changes.
3080 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3081 if it finds overlays. */
3082 if (handle_overlay_change_p
)
3083 handled
= handle_overlay_change (it
);
3086 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3088 /* Determine where to stop next. */
3089 if (handled
== HANDLED_NORMALLY
)
3090 compute_stop_pos (it
);
3094 /* Compute IT->stop_charpos from text property and overlay change
3095 information for IT's current position. */
3098 compute_stop_pos (it
)
3101 register INTERVAL iv
, next_iv
;
3102 Lisp_Object object
, limit
, position
;
3104 /* If nowhere else, stop at the end. */
3105 it
->stop_charpos
= it
->end_charpos
;
3107 if (STRINGP (it
->string
))
3109 /* Strings are usually short, so don't limit the search for
3111 object
= it
->string
;
3113 position
= make_number (IT_STRING_CHARPOS (*it
));
3119 /* If next overlay change is in front of the current stop pos
3120 (which is IT->end_charpos), stop there. Note: value of
3121 next_overlay_change is point-max if no overlay change
3123 charpos
= next_overlay_change (IT_CHARPOS (*it
));
3124 if (charpos
< it
->stop_charpos
)
3125 it
->stop_charpos
= charpos
;
3127 /* If showing the region, we have to stop at the region
3128 start or end because the face might change there. */
3129 if (it
->region_beg_charpos
> 0)
3131 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3132 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3133 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3134 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3137 /* Set up variables for computing the stop position from text
3138 property changes. */
3139 XSETBUFFER (object
, current_buffer
);
3140 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3141 position
= make_number (IT_CHARPOS (*it
));
3145 /* Get the interval containing IT's position. Value is a null
3146 interval if there isn't such an interval. */
3147 iv
= validate_interval_range (object
, &position
, &position
, 0);
3148 if (!NULL_INTERVAL_P (iv
))
3150 Lisp_Object values_here
[LAST_PROP_IDX
];
3153 /* Get properties here. */
3154 for (p
= it_props
; p
->handler
; ++p
)
3155 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3157 /* Look for an interval following iv that has different
3159 for (next_iv
= next_interval (iv
);
3160 (!NULL_INTERVAL_P (next_iv
)
3162 || XFASTINT (limit
) > next_iv
->position
));
3163 next_iv
= next_interval (next_iv
))
3165 for (p
= it_props
; p
->handler
; ++p
)
3167 Lisp_Object new_value
;
3169 new_value
= textget (next_iv
->plist
, *p
->name
);
3170 if (!EQ (values_here
[p
->idx
], new_value
))
3178 if (!NULL_INTERVAL_P (next_iv
))
3180 if (INTEGERP (limit
)
3181 && next_iv
->position
>= XFASTINT (limit
))
3182 /* No text property change up to limit. */
3183 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3185 /* Text properties change in next_iv. */
3186 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3190 xassert (STRINGP (it
->string
)
3191 || (it
->stop_charpos
>= BEGV
3192 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3196 /* Return the position of the next overlay change after POS in
3197 current_buffer. Value is point-max if no overlay change
3198 follows. This is like `next-overlay-change' but doesn't use
3202 next_overlay_change (pos
)
3207 Lisp_Object
*overlays
;
3210 /* Get all overlays at the given position. */
3211 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3213 /* If any of these overlays ends before endpos,
3214 use its ending point instead. */
3215 for (i
= 0; i
< noverlays
; ++i
)
3220 oend
= OVERLAY_END (overlays
[i
]);
3221 oendpos
= OVERLAY_POSITION (oend
);
3222 endpos
= min (endpos
, oendpos
);
3230 /***********************************************************************
3232 ***********************************************************************/
3234 /* Handle changes in the `fontified' property of the current buffer by
3235 calling hook functions from Qfontification_functions to fontify
3238 static enum prop_handled
3239 handle_fontified_prop (it
)
3242 Lisp_Object prop
, pos
;
3243 enum prop_handled handled
= HANDLED_NORMALLY
;
3245 if (!NILP (Vmemory_full
))
3248 /* Get the value of the `fontified' property at IT's current buffer
3249 position. (The `fontified' property doesn't have a special
3250 meaning in strings.) If the value is nil, call functions from
3251 Qfontification_functions. */
3252 if (!STRINGP (it
->string
)
3254 && !NILP (Vfontification_functions
)
3255 && !NILP (Vrun_hooks
)
3256 && (pos
= make_number (IT_CHARPOS (*it
)),
3257 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3258 /* Ignore the special cased nil value always present at EOB since
3259 no amount of fontifying will be able to change it. */
3260 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3262 int count
= SPECPDL_INDEX ();
3265 val
= Vfontification_functions
;
3266 specbind (Qfontification_functions
, Qnil
);
3268 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3269 safe_call1 (val
, pos
);
3272 Lisp_Object globals
, fn
;
3273 struct gcpro gcpro1
, gcpro2
;
3276 GCPRO2 (val
, globals
);
3278 for (; CONSP (val
); val
= XCDR (val
))
3284 /* A value of t indicates this hook has a local
3285 binding; it means to run the global binding too.
3286 In a global value, t should not occur. If it
3287 does, we must ignore it to avoid an endless
3289 for (globals
= Fdefault_value (Qfontification_functions
);
3291 globals
= XCDR (globals
))
3293 fn
= XCAR (globals
);
3295 safe_call1 (fn
, pos
);
3299 safe_call1 (fn
, pos
);
3305 unbind_to (count
, Qnil
);
3307 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3308 something. This avoids an endless loop if they failed to
3309 fontify the text for which reason ever. */
3310 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3311 handled
= HANDLED_RECOMPUTE_PROPS
;
3319 /***********************************************************************
3321 ***********************************************************************/
3323 /* Set up iterator IT from face properties at its current position.
3324 Called from handle_stop. */
3326 static enum prop_handled
3327 handle_face_prop (it
)
3330 int new_face_id
, next_stop
;
3332 if (!STRINGP (it
->string
))
3335 = face_at_buffer_position (it
->w
,
3337 it
->region_beg_charpos
,
3338 it
->region_end_charpos
,
3341 + TEXT_PROP_DISTANCE_LIMIT
),
3344 /* Is this a start of a run of characters with box face?
3345 Caveat: this can be called for a freshly initialized
3346 iterator; face_id is -1 in this case. We know that the new
3347 face will not change until limit, i.e. if the new face has a
3348 box, all characters up to limit will have one. But, as
3349 usual, we don't know whether limit is really the end. */
3350 if (new_face_id
!= it
->face_id
)
3352 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3354 /* If new face has a box but old face has not, this is
3355 the start of a run of characters with box, i.e. it has
3356 a shadow on the left side. The value of face_id of the
3357 iterator will be -1 if this is the initial call that gets
3358 the face. In this case, we have to look in front of IT's
3359 position and see whether there is a face != new_face_id. */
3360 it
->start_of_box_run_p
3361 = (new_face
->box
!= FACE_NO_BOX
3362 && (it
->face_id
>= 0
3363 || IT_CHARPOS (*it
) == BEG
3364 || new_face_id
!= face_before_it_pos (it
)));
3365 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3370 int base_face_id
, bufpos
;
3372 Lisp_Object from_overlay
3373 = (it
->current
.overlay_string_index
>= 0
3374 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3377 /* See if we got to this string directly or indirectly from
3378 an overlay property. That includes the before-string or
3379 after-string of an overlay, strings in display properties
3380 provided by an overlay, their text properties, etc.
3382 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3383 if (! NILP (from_overlay
))
3384 for (i
= it
->sp
- 1; i
>= 0; i
--)
3386 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3388 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3389 else if (! NILP (it
->stack
[i
].from_overlay
))
3390 from_overlay
= it
->stack
[i
].from_overlay
;
3392 if (!NILP (from_overlay
))
3396 if (! NILP (from_overlay
))
3398 bufpos
= IT_CHARPOS (*it
);
3399 /* For a string from an overlay, the base face depends
3400 only on text properties and ignores overlays. */
3402 = face_for_overlay_string (it
->w
,
3404 it
->region_beg_charpos
,
3405 it
->region_end_charpos
,
3408 + TEXT_PROP_DISTANCE_LIMIT
),
3416 /* For strings from a `display' property, use the face at
3417 IT's current buffer position as the base face to merge
3418 with, so that overlay strings appear in the same face as
3419 surrounding text, unless they specify their own
3421 base_face_id
= underlying_face_id (it
);
3424 new_face_id
= face_at_string_position (it
->w
,
3426 IT_STRING_CHARPOS (*it
),
3428 it
->region_beg_charpos
,
3429 it
->region_end_charpos
,
3433 #if 0 /* This shouldn't be neccessary. Let's check it. */
3434 /* If IT is used to display a mode line we would really like to
3435 use the mode line face instead of the frame's default face. */
3436 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3437 && new_face_id
== DEFAULT_FACE_ID
)
3438 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3441 /* Is this a start of a run of characters with box? Caveat:
3442 this can be called for a freshly allocated iterator; face_id
3443 is -1 is this case. We know that the new face will not
3444 change until the next check pos, i.e. if the new face has a
3445 box, all characters up to that position will have a
3446 box. But, as usual, we don't know whether that position
3447 is really the end. */
3448 if (new_face_id
!= it
->face_id
)
3450 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3451 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3453 /* If new face has a box but old face hasn't, this is the
3454 start of a run of characters with box, i.e. it has a
3455 shadow on the left side. */
3456 it
->start_of_box_run_p
3457 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3458 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3462 it
->face_id
= new_face_id
;
3463 return HANDLED_NORMALLY
;
3467 /* Return the ID of the face ``underlying'' IT's current position,
3468 which is in a string. If the iterator is associated with a
3469 buffer, return the face at IT's current buffer position.
3470 Otherwise, use the iterator's base_face_id. */
3473 underlying_face_id (it
)
3476 int face_id
= it
->base_face_id
, i
;
3478 xassert (STRINGP (it
->string
));
3480 for (i
= it
->sp
- 1; i
>= 0; --i
)
3481 if (NILP (it
->stack
[i
].string
))
3482 face_id
= it
->stack
[i
].face_id
;
3488 /* Compute the face one character before or after the current position
3489 of IT. BEFORE_P non-zero means get the face in front of IT's
3490 position. Value is the id of the face. */
3493 face_before_or_after_it_pos (it
, before_p
)
3498 int next_check_charpos
;
3499 struct text_pos pos
;
3501 xassert (it
->s
== NULL
);
3503 if (STRINGP (it
->string
))
3505 int bufpos
, base_face_id
;
3507 /* No face change past the end of the string (for the case
3508 we are padding with spaces). No face change before the
3510 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3511 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3514 /* Set pos to the position before or after IT's current position. */
3516 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3518 /* For composition, we must check the character after the
3520 pos
= (it
->what
== IT_COMPOSITION
3521 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3522 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3524 if (it
->current
.overlay_string_index
>= 0)
3525 bufpos
= IT_CHARPOS (*it
);
3529 base_face_id
= underlying_face_id (it
);
3531 /* Get the face for ASCII, or unibyte. */
3532 face_id
= face_at_string_position (it
->w
,
3536 it
->region_beg_charpos
,
3537 it
->region_end_charpos
,
3538 &next_check_charpos
,
3541 /* Correct the face for charsets different from ASCII. Do it
3542 for the multibyte case only. The face returned above is
3543 suitable for unibyte text if IT->string is unibyte. */
3544 if (STRING_MULTIBYTE (it
->string
))
3546 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3547 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3549 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3551 c
= string_char_and_length (p
, rest
, &len
);
3552 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3557 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3558 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3561 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3562 pos
= it
->current
.pos
;
3565 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3568 if (it
->what
== IT_COMPOSITION
)
3569 /* For composition, we must check the position after the
3571 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3573 INC_TEXT_POS (pos
, it
->multibyte_p
);
3576 /* Determine face for CHARSET_ASCII, or unibyte. */
3577 face_id
= face_at_buffer_position (it
->w
,
3579 it
->region_beg_charpos
,
3580 it
->region_end_charpos
,
3581 &next_check_charpos
,
3584 /* Correct the face for charsets different from ASCII. Do it
3585 for the multibyte case only. The face returned above is
3586 suitable for unibyte text if current_buffer is unibyte. */
3587 if (it
->multibyte_p
)
3589 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3590 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3591 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3600 /***********************************************************************
3602 ***********************************************************************/
3604 /* Set up iterator IT from invisible properties at its current
3605 position. Called from handle_stop. */
3607 static enum prop_handled
3608 handle_invisible_prop (it
)
3611 enum prop_handled handled
= HANDLED_NORMALLY
;
3613 if (STRINGP (it
->string
))
3615 extern Lisp_Object Qinvisible
;
3616 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3618 /* Get the value of the invisible text property at the
3619 current position. Value will be nil if there is no such
3621 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3622 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3625 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3627 handled
= HANDLED_RECOMPUTE_PROPS
;
3629 /* Get the position at which the next change of the
3630 invisible text property can be found in IT->string.
3631 Value will be nil if the property value is the same for
3632 all the rest of IT->string. */
3633 XSETINT (limit
, SCHARS (it
->string
));
3634 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3637 /* Text at current position is invisible. The next
3638 change in the property is at position end_charpos.
3639 Move IT's current position to that position. */
3640 if (INTEGERP (end_charpos
)
3641 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3643 struct text_pos old
;
3644 old
= it
->current
.string_pos
;
3645 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3646 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3650 /* The rest of the string is invisible. If this is an
3651 overlay string, proceed with the next overlay string
3652 or whatever comes and return a character from there. */
3653 if (it
->current
.overlay_string_index
>= 0)
3655 next_overlay_string (it
);
3656 /* Don't check for overlay strings when we just
3657 finished processing them. */
3658 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3662 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3663 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3670 int invis_p
, newpos
, next_stop
, start_charpos
;
3671 Lisp_Object pos
, prop
, overlay
;
3673 /* First of all, is there invisible text at this position? */
3674 start_charpos
= IT_CHARPOS (*it
);
3675 pos
= make_number (IT_CHARPOS (*it
));
3676 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3678 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3680 /* If we are on invisible text, skip over it. */
3681 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3683 /* Record whether we have to display an ellipsis for the
3685 int display_ellipsis_p
= invis_p
== 2;
3687 handled
= HANDLED_RECOMPUTE_PROPS
;
3689 /* Loop skipping over invisible text. The loop is left at
3690 ZV or with IT on the first char being visible again. */
3693 /* Try to skip some invisible text. Return value is the
3694 position reached which can be equal to IT's position
3695 if there is nothing invisible here. This skips both
3696 over invisible text properties and overlays with
3697 invisible property. */
3698 newpos
= skip_invisible (IT_CHARPOS (*it
),
3699 &next_stop
, ZV
, it
->window
);
3701 /* If we skipped nothing at all we weren't at invisible
3702 text in the first place. If everything to the end of
3703 the buffer was skipped, end the loop. */
3704 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3708 /* We skipped some characters but not necessarily
3709 all there are. Check if we ended up on visible
3710 text. Fget_char_property returns the property of
3711 the char before the given position, i.e. if we
3712 get invis_p = 0, this means that the char at
3713 newpos is visible. */
3714 pos
= make_number (newpos
);
3715 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3716 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3719 /* If we ended up on invisible text, proceed to
3720 skip starting with next_stop. */
3722 IT_CHARPOS (*it
) = next_stop
;
3724 /* If there are adjacent invisible texts, don't lose the
3725 second one's ellipsis. */
3727 display_ellipsis_p
= 1;
3731 /* The position newpos is now either ZV or on visible text. */
3732 IT_CHARPOS (*it
) = newpos
;
3733 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3735 /* If there are before-strings at the start of invisible
3736 text, and the text is invisible because of a text
3737 property, arrange to show before-strings because 20.x did
3738 it that way. (If the text is invisible because of an
3739 overlay property instead of a text property, this is
3740 already handled in the overlay code.) */
3742 && get_overlay_strings (it
, start_charpos
))
3744 handled
= HANDLED_RECOMPUTE_PROPS
;
3745 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3747 else if (display_ellipsis_p
)
3749 /* Make sure that the glyphs of the ellipsis will get
3750 correct `charpos' values. If we would not update
3751 it->position here, the glyphs would belong to the
3752 last visible character _before_ the invisible
3753 text, which confuses `set_cursor_from_row'.
3755 We use the last invisible position instead of the
3756 first because this way the cursor is always drawn on
3757 the first "." of the ellipsis, whenever PT is inside
3758 the invisible text. Otherwise the cursor would be
3759 placed _after_ the ellipsis when the point is after the
3760 first invisible character. */
3761 if (!STRINGP (it
->object
))
3763 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3764 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3766 setup_for_ellipsis (it
, 0);
3767 /* Let the ellipsis display before
3768 considering any properties of the following char.
3769 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3770 handled
= HANDLED_RETURN
;
3779 /* Make iterator IT return `...' next.
3780 Replaces LEN characters from buffer. */
3783 setup_for_ellipsis (it
, len
)
3787 /* Use the display table definition for `...'. Invalid glyphs
3788 will be handled by the method returning elements from dpvec. */
3789 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3791 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3792 it
->dpvec
= v
->contents
;
3793 it
->dpend
= v
->contents
+ v
->size
;
3797 /* Default `...'. */
3798 it
->dpvec
= default_invis_vector
;
3799 it
->dpend
= default_invis_vector
+ 3;
3802 it
->dpvec_char_len
= len
;
3803 it
->current
.dpvec_index
= 0;
3804 it
->dpvec_face_id
= -1;
3806 /* Remember the current face id in case glyphs specify faces.
3807 IT's face is restored in set_iterator_to_next.
3808 saved_face_id was set to preceding char's face in handle_stop. */
3809 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3810 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3812 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3818 /***********************************************************************
3820 ***********************************************************************/
3822 /* Set up iterator IT from `display' property at its current position.
3823 Called from handle_stop.
3824 We return HANDLED_RETURN if some part of the display property
3825 overrides the display of the buffer text itself.
3826 Otherwise we return HANDLED_NORMALLY. */
3828 static enum prop_handled
3829 handle_display_prop (it
)
3832 Lisp_Object prop
, object
, overlay
;
3833 struct text_pos
*position
;
3834 /* Nonzero if some property replaces the display of the text itself. */
3835 int display_replaced_p
= 0;
3837 if (STRINGP (it
->string
))
3839 object
= it
->string
;
3840 position
= &it
->current
.string_pos
;
3844 XSETWINDOW (object
, it
->w
);
3845 position
= &it
->current
.pos
;
3848 /* Reset those iterator values set from display property values. */
3849 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3850 it
->space_width
= Qnil
;
3851 it
->font_height
= Qnil
;
3854 /* We don't support recursive `display' properties, i.e. string
3855 values that have a string `display' property, that have a string
3856 `display' property etc. */
3857 if (!it
->string_from_display_prop_p
)
3858 it
->area
= TEXT_AREA
;
3860 prop
= get_char_property_and_overlay (make_number (position
->charpos
),
3861 Qdisplay
, object
, &overlay
);
3863 return HANDLED_NORMALLY
;
3864 /* Now OVERLAY is the overlay that gave us this property, or nil
3865 if it was a text property. */
3867 if (!STRINGP (it
->string
))
3868 object
= it
->w
->buffer
;
3871 /* Simple properties. */
3872 && !EQ (XCAR (prop
), Qimage
)
3873 && !EQ (XCAR (prop
), Qspace
)
3874 && !EQ (XCAR (prop
), Qwhen
)
3875 && !EQ (XCAR (prop
), Qslice
)
3876 && !EQ (XCAR (prop
), Qspace_width
)
3877 && !EQ (XCAR (prop
), Qheight
)
3878 && !EQ (XCAR (prop
), Qraise
)
3879 /* Marginal area specifications. */
3880 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3881 && !EQ (XCAR (prop
), Qleft_fringe
)
3882 && !EQ (XCAR (prop
), Qright_fringe
)
3883 && !NILP (XCAR (prop
)))
3885 for (; CONSP (prop
); prop
= XCDR (prop
))
3887 if (handle_single_display_spec (it
, XCAR (prop
), object
, overlay
,
3888 position
, display_replaced_p
))
3890 display_replaced_p
= 1;
3891 /* If some text in a string is replaced, `position' no
3892 longer points to the position of `object'. */
3893 if (STRINGP (object
))
3898 else if (VECTORP (prop
))
3901 for (i
= 0; i
< ASIZE (prop
); ++i
)
3902 if (handle_single_display_spec (it
, AREF (prop
, i
), object
, overlay
,
3903 position
, display_replaced_p
))
3905 display_replaced_p
= 1;
3906 /* If some text in a string is replaced, `position' no
3907 longer points to the position of `object'. */
3908 if (STRINGP (object
))
3914 int ret
= handle_single_display_spec (it
, prop
, object
, overlay
,
3916 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3917 return HANDLED_RECOMPUTE_PROPS
;
3919 display_replaced_p
= 1;
3922 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3926 /* Value is the position of the end of the `display' property starting
3927 at START_POS in OBJECT. */
3929 static struct text_pos
3930 display_prop_end (it
, object
, start_pos
)
3933 struct text_pos start_pos
;
3936 struct text_pos end_pos
;
3938 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3939 Qdisplay
, object
, Qnil
);
3940 CHARPOS (end_pos
) = XFASTINT (end
);
3941 if (STRINGP (object
))
3942 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3944 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3950 /* Set up IT from a single `display' specification PROP. OBJECT
3951 is the object in which the `display' property was found. *POSITION
3952 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3953 means that we previously saw a display specification which already
3954 replaced text display with something else, for example an image;
3955 we ignore such properties after the first one has been processed.
3957 OVERLAY is the overlay this `display' property came from,
3958 or nil if it was a text property.
3960 If PROP is a `space' or `image' specification, and in some other
3961 cases too, set *POSITION to the position where the `display'
3964 Value is non-zero if something was found which replaces the display
3965 of buffer or string text. Specifically, the value is -1 if that
3966 "something" is "nothing". */
3969 handle_single_display_spec (it
, spec
, object
, overlay
, position
,
3970 display_replaced_before_p
)
3974 Lisp_Object overlay
;
3975 struct text_pos
*position
;
3976 int display_replaced_before_p
;
3979 Lisp_Object location
, value
;
3980 struct text_pos start_pos
, save_pos
;
3983 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3984 If the result is non-nil, use VALUE instead of SPEC. */
3986 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3995 if (!NILP (form
) && !EQ (form
, Qt
))
3997 int count
= SPECPDL_INDEX ();
3998 struct gcpro gcpro1
;
4000 /* Bind `object' to the object having the `display' property, a
4001 buffer or string. Bind `position' to the position in the
4002 object where the property was found, and `buffer-position'
4003 to the current position in the buffer. */
4004 specbind (Qobject
, object
);
4005 specbind (Qposition
, make_number (CHARPOS (*position
)));
4006 specbind (Qbuffer_position
,
4007 make_number (STRINGP (object
)
4008 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
4010 form
= safe_eval (form
);
4012 unbind_to (count
, Qnil
);
4018 /* Handle `(height HEIGHT)' specifications. */
4020 && EQ (XCAR (spec
), Qheight
)
4021 && CONSP (XCDR (spec
)))
4023 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4026 it
->font_height
= XCAR (XCDR (spec
));
4027 if (!NILP (it
->font_height
))
4029 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4030 int new_height
= -1;
4032 if (CONSP (it
->font_height
)
4033 && (EQ (XCAR (it
->font_height
), Qplus
)
4034 || EQ (XCAR (it
->font_height
), Qminus
))
4035 && CONSP (XCDR (it
->font_height
))
4036 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4038 /* `(+ N)' or `(- N)' where N is an integer. */
4039 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4040 if (EQ (XCAR (it
->font_height
), Qplus
))
4042 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4044 else if (FUNCTIONP (it
->font_height
))
4046 /* Call function with current height as argument.
4047 Value is the new height. */
4049 height
= safe_call1 (it
->font_height
,
4050 face
->lface
[LFACE_HEIGHT_INDEX
]);
4051 if (NUMBERP (height
))
4052 new_height
= XFLOATINT (height
);
4054 else if (NUMBERP (it
->font_height
))
4056 /* Value is a multiple of the canonical char height. */
4059 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
4060 new_height
= (XFLOATINT (it
->font_height
)
4061 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4065 /* Evaluate IT->font_height with `height' bound to the
4066 current specified height to get the new height. */
4067 int count
= SPECPDL_INDEX ();
4069 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4070 value
= safe_eval (it
->font_height
);
4071 unbind_to (count
, Qnil
);
4073 if (NUMBERP (value
))
4074 new_height
= XFLOATINT (value
);
4078 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4084 /* Handle `(space-width WIDTH)'. */
4086 && EQ (XCAR (spec
), Qspace_width
)
4087 && CONSP (XCDR (spec
)))
4089 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4092 value
= XCAR (XCDR (spec
));
4093 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4094 it
->space_width
= value
;
4099 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4101 && EQ (XCAR (spec
), Qslice
))
4105 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4108 if (tem
= XCDR (spec
), CONSP (tem
))
4110 it
->slice
.x
= XCAR (tem
);
4111 if (tem
= XCDR (tem
), CONSP (tem
))
4113 it
->slice
.y
= XCAR (tem
);
4114 if (tem
= XCDR (tem
), CONSP (tem
))
4116 it
->slice
.width
= XCAR (tem
);
4117 if (tem
= XCDR (tem
), CONSP (tem
))
4118 it
->slice
.height
= XCAR (tem
);
4126 /* Handle `(raise FACTOR)'. */
4128 && EQ (XCAR (spec
), Qraise
)
4129 && CONSP (XCDR (spec
)))
4131 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4134 #ifdef HAVE_WINDOW_SYSTEM
4135 value
= XCAR (XCDR (spec
));
4136 if (NUMBERP (value
))
4138 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4139 it
->voffset
= - (XFLOATINT (value
)
4140 * (FONT_HEIGHT (face
->font
)));
4142 #endif /* HAVE_WINDOW_SYSTEM */
4147 /* Don't handle the other kinds of display specifications
4148 inside a string that we got from a `display' property. */
4149 if (it
->string_from_display_prop_p
)
4152 /* Characters having this form of property are not displayed, so
4153 we have to find the end of the property. */
4154 start_pos
= *position
;
4155 *position
= display_prop_end (it
, object
, start_pos
);
4158 /* Stop the scan at that end position--we assume that all
4159 text properties change there. */
4160 it
->stop_charpos
= position
->charpos
;
4162 /* Handle `(left-fringe BITMAP [FACE])'
4163 and `(right-fringe BITMAP [FACE])'. */
4165 && (EQ (XCAR (spec
), Qleft_fringe
)
4166 || EQ (XCAR (spec
), Qright_fringe
))
4167 && CONSP (XCDR (spec
)))
4169 int face_id
= DEFAULT_FACE_ID
;
4172 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4173 /* If we return here, POSITION has been advanced
4174 across the text with this property. */
4177 #ifdef HAVE_WINDOW_SYSTEM
4178 value
= XCAR (XCDR (spec
));
4179 if (!SYMBOLP (value
)
4180 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4181 /* If we return here, POSITION has been advanced
4182 across the text with this property. */
4185 if (CONSP (XCDR (XCDR (spec
))))
4187 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4188 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4189 'A', FRINGE_FACE_ID
, 0);
4194 /* Save current settings of IT so that we can restore them
4195 when we are finished with the glyph property value. */
4197 save_pos
= it
->position
;
4198 it
->position
= *position
;
4200 it
->position
= save_pos
;
4202 it
->area
= TEXT_AREA
;
4203 it
->what
= IT_IMAGE
;
4204 it
->image_id
= -1; /* no image */
4205 it
->position
= start_pos
;
4206 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4207 it
->method
= GET_FROM_IMAGE
;
4208 it
->from_overlay
= Qnil
;
4209 it
->face_id
= face_id
;
4211 /* Say that we haven't consumed the characters with
4212 `display' property yet. The call to pop_it in
4213 set_iterator_to_next will clean this up. */
4214 *position
= start_pos
;
4216 if (EQ (XCAR (spec
), Qleft_fringe
))
4218 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4219 it
->left_user_fringe_face_id
= face_id
;
4223 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4224 it
->right_user_fringe_face_id
= face_id
;
4226 #endif /* HAVE_WINDOW_SYSTEM */
4230 /* Prepare to handle `((margin left-margin) ...)',
4231 `((margin right-margin) ...)' and `((margin nil) ...)'
4232 prefixes for display specifications. */
4233 location
= Qunbound
;
4234 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4238 value
= XCDR (spec
);
4240 value
= XCAR (value
);
4243 if (EQ (XCAR (tem
), Qmargin
)
4244 && (tem
= XCDR (tem
),
4245 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4247 || EQ (tem
, Qleft_margin
)
4248 || EQ (tem
, Qright_margin
))))
4252 if (EQ (location
, Qunbound
))
4258 /* After this point, VALUE is the property after any
4259 margin prefix has been stripped. It must be a string,
4260 an image specification, or `(space ...)'.
4262 LOCATION specifies where to display: `left-margin',
4263 `right-margin' or nil. */
4265 valid_p
= (STRINGP (value
)
4266 #ifdef HAVE_WINDOW_SYSTEM
4267 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
4268 #endif /* not HAVE_WINDOW_SYSTEM */
4269 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4271 if (valid_p
&& !display_replaced_before_p
)
4273 /* Save current settings of IT so that we can restore them
4274 when we are finished with the glyph property value. */
4275 save_pos
= it
->position
;
4276 it
->position
= *position
;
4278 it
->position
= save_pos
;
4279 it
->from_overlay
= overlay
;
4281 if (NILP (location
))
4282 it
->area
= TEXT_AREA
;
4283 else if (EQ (location
, Qleft_margin
))
4284 it
->area
= LEFT_MARGIN_AREA
;
4286 it
->area
= RIGHT_MARGIN_AREA
;
4288 if (STRINGP (value
))
4290 if (SCHARS (value
) == 0)
4293 return -1; /* Replaced by "", i.e. nothing. */
4296 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4297 it
->current
.overlay_string_index
= -1;
4298 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4299 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4300 it
->method
= GET_FROM_STRING
;
4301 it
->stop_charpos
= 0;
4302 it
->string_from_display_prop_p
= 1;
4303 /* Say that we haven't consumed the characters with
4304 `display' property yet. The call to pop_it in
4305 set_iterator_to_next will clean this up. */
4306 if (BUFFERP (object
))
4307 *position
= start_pos
;
4309 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4311 it
->method
= GET_FROM_STRETCH
;
4313 *position
= it
->position
= start_pos
;
4315 #ifdef HAVE_WINDOW_SYSTEM
4318 it
->what
= IT_IMAGE
;
4319 it
->image_id
= lookup_image (it
->f
, value
);
4320 it
->position
= start_pos
;
4321 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4322 it
->method
= GET_FROM_IMAGE
;
4324 /* Say that we haven't consumed the characters with
4325 `display' property yet. The call to pop_it in
4326 set_iterator_to_next will clean this up. */
4327 *position
= start_pos
;
4329 #endif /* HAVE_WINDOW_SYSTEM */
4334 /* Invalid property or property not supported. Restore
4335 POSITION to what it was before. */
4336 *position
= start_pos
;
4341 /* Check if SPEC is a display specification value whose text should be
4342 treated as intangible. */
4345 single_display_spec_intangible_p (prop
)
4348 /* Skip over `when FORM'. */
4349 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4363 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4364 we don't need to treat text as intangible. */
4365 if (EQ (XCAR (prop
), Qmargin
))
4373 || EQ (XCAR (prop
), Qleft_margin
)
4374 || EQ (XCAR (prop
), Qright_margin
))
4378 return (CONSP (prop
)
4379 && (EQ (XCAR (prop
), Qimage
)
4380 || EQ (XCAR (prop
), Qspace
)));
4384 /* Check if PROP is a display property value whose text should be
4385 treated as intangible. */
4388 display_prop_intangible_p (prop
)
4392 && CONSP (XCAR (prop
))
4393 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4395 /* A list of sub-properties. */
4396 while (CONSP (prop
))
4398 if (single_display_spec_intangible_p (XCAR (prop
)))
4403 else if (VECTORP (prop
))
4405 /* A vector of sub-properties. */
4407 for (i
= 0; i
< ASIZE (prop
); ++i
)
4408 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4412 return single_display_spec_intangible_p (prop
);
4418 /* Return 1 if PROP is a display sub-property value containing STRING. */
4421 single_display_spec_string_p (prop
, string
)
4422 Lisp_Object prop
, string
;
4424 if (EQ (string
, prop
))
4427 /* Skip over `when FORM'. */
4428 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4437 /* Skip over `margin LOCATION'. */
4438 if (EQ (XCAR (prop
), Qmargin
))
4449 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4453 /* Return 1 if STRING appears in the `display' property PROP. */
4456 display_prop_string_p (prop
, string
)
4457 Lisp_Object prop
, string
;
4460 && CONSP (XCAR (prop
))
4461 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4463 /* A list of sub-properties. */
4464 while (CONSP (prop
))
4466 if (single_display_spec_string_p (XCAR (prop
), string
))
4471 else if (VECTORP (prop
))
4473 /* A vector of sub-properties. */
4475 for (i
= 0; i
< ASIZE (prop
); ++i
)
4476 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4480 return single_display_spec_string_p (prop
, string
);
4486 /* Determine from which buffer position in W's buffer STRING comes
4487 from. AROUND_CHARPOS is an approximate position where it could
4488 be from. Value is the buffer position or 0 if it couldn't be
4491 W's buffer must be current.
4493 This function is necessary because we don't record buffer positions
4494 in glyphs generated from strings (to keep struct glyph small).
4495 This function may only use code that doesn't eval because it is
4496 called asynchronously from note_mouse_highlight. */
4499 string_buffer_position (w
, string
, around_charpos
)
4504 Lisp_Object limit
, prop
, pos
;
4505 const int MAX_DISTANCE
= 1000;
4508 pos
= make_number (around_charpos
);
4509 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4510 while (!found
&& !EQ (pos
, limit
))
4512 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4513 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4516 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4521 pos
= make_number (around_charpos
);
4522 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4523 while (!found
&& !EQ (pos
, limit
))
4525 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4526 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4529 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4534 return found
? XINT (pos
) : 0;
4539 /***********************************************************************
4540 `composition' property
4541 ***********************************************************************/
4543 /* Set up iterator IT from `composition' property at its current
4544 position. Called from handle_stop. */
4546 static enum prop_handled
4547 handle_composition_prop (it
)
4550 Lisp_Object prop
, string
;
4551 int pos
, pos_byte
, end
;
4552 enum prop_handled handled
= HANDLED_NORMALLY
;
4554 if (STRINGP (it
->string
))
4556 pos
= IT_STRING_CHARPOS (*it
);
4557 pos_byte
= IT_STRING_BYTEPOS (*it
);
4558 string
= it
->string
;
4562 pos
= IT_CHARPOS (*it
);
4563 pos_byte
= IT_BYTEPOS (*it
);
4567 /* If there's a valid composition and point is not inside of the
4568 composition (in the case that the composition is from the current
4569 buffer), draw a glyph composed from the composition components. */
4570 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
4571 && COMPOSITION_VALID_P (pos
, end
, prop
)
4572 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
4574 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4578 struct composition
*cmp
= composition_table
[id
];
4580 if (cmp
->glyph_len
== 0)
4583 if (STRINGP (it
->string
))
4585 IT_STRING_CHARPOS (*it
) = end
;
4586 IT_STRING_BYTEPOS (*it
) = string_char_to_byte (it
->string
,
4591 IT_CHARPOS (*it
) = end
;
4592 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (end
);
4594 return HANDLED_RECOMPUTE_PROPS
;
4597 it
->stop_charpos
= end
;
4600 it
->method
= GET_FROM_COMPOSITION
;
4602 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4603 /* For a terminal, draw only the first character of the
4605 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4606 it
->len
= (STRINGP (it
->string
)
4607 ? string_char_to_byte (it
->string
, end
)
4608 : CHAR_TO_BYTE (end
)) - pos_byte
;
4609 handled
= HANDLED_RETURN
;
4618 /***********************************************************************
4620 ***********************************************************************/
4622 /* The following structure is used to record overlay strings for
4623 later sorting in load_overlay_strings. */
4625 struct overlay_entry
4627 Lisp_Object overlay
;
4634 /* Set up iterator IT from overlay strings at its current position.
4635 Called from handle_stop. */
4637 static enum prop_handled
4638 handle_overlay_change (it
)
4641 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4642 return HANDLED_RECOMPUTE_PROPS
;
4644 return HANDLED_NORMALLY
;
4648 /* Set up the next overlay string for delivery by IT, if there is an
4649 overlay string to deliver. Called by set_iterator_to_next when the
4650 end of the current overlay string is reached. If there are more
4651 overlay strings to display, IT->string and
4652 IT->current.overlay_string_index are set appropriately here.
4653 Otherwise IT->string is set to nil. */
4656 next_overlay_string (it
)
4659 ++it
->current
.overlay_string_index
;
4660 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4662 /* No more overlay strings. Restore IT's settings to what
4663 they were before overlay strings were processed, and
4664 continue to deliver from current_buffer. */
4665 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4669 || it
->method
== GET_FROM_COMPOSITION
4670 || (NILP (it
->string
)
4671 && it
->method
== GET_FROM_BUFFER
4672 && it
->stop_charpos
>= BEGV
4673 && it
->stop_charpos
<= it
->end_charpos
));
4674 it
->current
.overlay_string_index
= -1;
4675 it
->n_overlay_strings
= 0;
4677 /* If we're at the end of the buffer, record that we have
4678 processed the overlay strings there already, so that
4679 next_element_from_buffer doesn't try it again. */
4680 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4681 it
->overlay_strings_at_end_processed_p
= 1;
4683 /* If we have to display `...' for invisible text, set
4684 the iterator up for that. */
4685 if (display_ellipsis_p
)
4686 setup_for_ellipsis (it
, 0);
4690 /* There are more overlay strings to process. If
4691 IT->current.overlay_string_index has advanced to a position
4692 where we must load IT->overlay_strings with more strings, do
4694 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4696 if (it
->current
.overlay_string_index
&& i
== 0)
4697 load_overlay_strings (it
, 0);
4699 /* Initialize IT to deliver display elements from the overlay
4701 it
->string
= it
->overlay_strings
[i
];
4702 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4703 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4704 it
->method
= GET_FROM_STRING
;
4705 it
->stop_charpos
= 0;
4712 /* Compare two overlay_entry structures E1 and E2. Used as a
4713 comparison function for qsort in load_overlay_strings. Overlay
4714 strings for the same position are sorted so that
4716 1. All after-strings come in front of before-strings, except
4717 when they come from the same overlay.
4719 2. Within after-strings, strings are sorted so that overlay strings
4720 from overlays with higher priorities come first.
4722 2. Within before-strings, strings are sorted so that overlay
4723 strings from overlays with higher priorities come last.
4725 Value is analogous to strcmp. */
4729 compare_overlay_entries (e1
, e2
)
4732 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4733 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4736 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4738 /* Let after-strings appear in front of before-strings if
4739 they come from different overlays. */
4740 if (EQ (entry1
->overlay
, entry2
->overlay
))
4741 result
= entry1
->after_string_p
? 1 : -1;
4743 result
= entry1
->after_string_p
? -1 : 1;
4745 else if (entry1
->after_string_p
)
4746 /* After-strings sorted in order of decreasing priority. */
4747 result
= entry2
->priority
- entry1
->priority
;
4749 /* Before-strings sorted in order of increasing priority. */
4750 result
= entry1
->priority
- entry2
->priority
;
4756 /* Load the vector IT->overlay_strings with overlay strings from IT's
4757 current buffer position, or from CHARPOS if that is > 0. Set
4758 IT->n_overlays to the total number of overlay strings found.
4760 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4761 a time. On entry into load_overlay_strings,
4762 IT->current.overlay_string_index gives the number of overlay
4763 strings that have already been loaded by previous calls to this
4766 IT->add_overlay_start contains an additional overlay start
4767 position to consider for taking overlay strings from, if non-zero.
4768 This position comes into play when the overlay has an `invisible'
4769 property, and both before and after-strings. When we've skipped to
4770 the end of the overlay, because of its `invisible' property, we
4771 nevertheless want its before-string to appear.
4772 IT->add_overlay_start will contain the overlay start position
4775 Overlay strings are sorted so that after-string strings come in
4776 front of before-string strings. Within before and after-strings,
4777 strings are sorted by overlay priority. See also function
4778 compare_overlay_entries. */
4781 load_overlay_strings (it
, charpos
)
4785 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4786 Lisp_Object overlay
, window
, str
, invisible
;
4787 struct Lisp_Overlay
*ov
;
4790 int n
= 0, i
, j
, invis_p
;
4791 struct overlay_entry
*entries
4792 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4795 charpos
= IT_CHARPOS (*it
);
4797 /* Append the overlay string STRING of overlay OVERLAY to vector
4798 `entries' which has size `size' and currently contains `n'
4799 elements. AFTER_P non-zero means STRING is an after-string of
4801 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4804 Lisp_Object priority; \
4808 int new_size = 2 * size; \
4809 struct overlay_entry *old = entries; \
4811 (struct overlay_entry *) alloca (new_size \
4812 * sizeof *entries); \
4813 bcopy (old, entries, size * sizeof *entries); \
4817 entries[n].string = (STRING); \
4818 entries[n].overlay = (OVERLAY); \
4819 priority = Foverlay_get ((OVERLAY), Qpriority); \
4820 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4821 entries[n].after_string_p = (AFTER_P); \
4826 /* Process overlay before the overlay center. */
4827 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4829 XSETMISC (overlay
, ov
);
4830 xassert (OVERLAYP (overlay
));
4831 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4832 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4837 /* Skip this overlay if it doesn't start or end at IT's current
4839 if (end
!= charpos
&& start
!= charpos
)
4842 /* Skip this overlay if it doesn't apply to IT->w. */
4843 window
= Foverlay_get (overlay
, Qwindow
);
4844 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4847 /* If the text ``under'' the overlay is invisible, both before-
4848 and after-strings from this overlay are visible; start and
4849 end position are indistinguishable. */
4850 invisible
= Foverlay_get (overlay
, Qinvisible
);
4851 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4853 /* If overlay has a non-empty before-string, record it. */
4854 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4855 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4857 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4859 /* If overlay has a non-empty after-string, record it. */
4860 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4861 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4863 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4866 /* Process overlays after the overlay center. */
4867 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4869 XSETMISC (overlay
, ov
);
4870 xassert (OVERLAYP (overlay
));
4871 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4872 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4874 if (start
> charpos
)
4877 /* Skip this overlay if it doesn't start or end at IT's current
4879 if (end
!= charpos
&& start
!= charpos
)
4882 /* Skip this overlay if it doesn't apply to IT->w. */
4883 window
= Foverlay_get (overlay
, Qwindow
);
4884 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4887 /* If the text ``under'' the overlay is invisible, it has a zero
4888 dimension, and both before- and after-strings apply. */
4889 invisible
= Foverlay_get (overlay
, Qinvisible
);
4890 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4892 /* If overlay has a non-empty before-string, record it. */
4893 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4894 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4896 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4898 /* If overlay has a non-empty after-string, record it. */
4899 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4900 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4902 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4905 #undef RECORD_OVERLAY_STRING
4909 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4911 /* Record the total number of strings to process. */
4912 it
->n_overlay_strings
= n
;
4914 /* IT->current.overlay_string_index is the number of overlay strings
4915 that have already been consumed by IT. Copy some of the
4916 remaining overlay strings to IT->overlay_strings. */
4918 j
= it
->current
.overlay_string_index
;
4919 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4921 it
->overlay_strings
[i
] = entries
[j
].string
;
4922 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
4929 /* Get the first chunk of overlay strings at IT's current buffer
4930 position, or at CHARPOS if that is > 0. Value is non-zero if at
4931 least one overlay string was found. */
4934 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
4939 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4940 process. This fills IT->overlay_strings with strings, and sets
4941 IT->n_overlay_strings to the total number of strings to process.
4942 IT->pos.overlay_string_index has to be set temporarily to zero
4943 because load_overlay_strings needs this; it must be set to -1
4944 when no overlay strings are found because a zero value would
4945 indicate a position in the first overlay string. */
4946 it
->current
.overlay_string_index
= 0;
4947 load_overlay_strings (it
, charpos
);
4949 /* If we found overlay strings, set up IT to deliver display
4950 elements from the first one. Otherwise set up IT to deliver
4951 from current_buffer. */
4952 if (it
->n_overlay_strings
)
4954 /* Make sure we know settings in current_buffer, so that we can
4955 restore meaningful values when we're done with the overlay
4958 compute_stop_pos (it
);
4959 xassert (it
->face_id
>= 0);
4961 /* Save IT's settings. They are restored after all overlay
4962 strings have been processed. */
4963 xassert (!compute_stop_p
|| it
->sp
== 0);
4966 /* Set up IT to deliver display elements from the first overlay
4968 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4969 it
->string
= it
->overlay_strings
[0];
4970 it
->from_overlay
= Qnil
;
4971 it
->stop_charpos
= 0;
4972 xassert (STRINGP (it
->string
));
4973 it
->end_charpos
= SCHARS (it
->string
);
4974 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4975 it
->method
= GET_FROM_STRING
;
4979 it
->current
.overlay_string_index
= -1;
4984 get_overlay_strings (it
, charpos
)
4989 it
->method
= GET_FROM_BUFFER
;
4991 (void) get_overlay_strings_1 (it
, charpos
, 1);
4995 /* Value is non-zero if we found at least one overlay string. */
4996 return STRINGP (it
->string
);
5001 /***********************************************************************
5002 Saving and restoring state
5003 ***********************************************************************/
5005 /* Save current settings of IT on IT->stack. Called, for example,
5006 before setting up IT for an overlay string, to be able to restore
5007 IT's settings to what they were after the overlay string has been
5014 struct iterator_stack_entry
*p
;
5016 xassert (it
->sp
< IT_STACK_SIZE
);
5017 p
= it
->stack
+ it
->sp
;
5019 p
->stop_charpos
= it
->stop_charpos
;
5020 xassert (it
->face_id
>= 0);
5021 p
->face_id
= it
->face_id
;
5022 p
->string
= it
->string
;
5023 p
->method
= it
->method
;
5024 p
->from_overlay
= it
->from_overlay
;
5027 case GET_FROM_IMAGE
:
5028 p
->u
.image
.object
= it
->object
;
5029 p
->u
.image
.image_id
= it
->image_id
;
5030 p
->u
.image
.slice
= it
->slice
;
5032 case GET_FROM_COMPOSITION
:
5033 p
->u
.comp
.object
= it
->object
;
5034 p
->u
.comp
.c
= it
->c
;
5035 p
->u
.comp
.len
= it
->len
;
5036 p
->u
.comp
.cmp_id
= it
->cmp_id
;
5037 p
->u
.comp
.cmp_len
= it
->cmp_len
;
5039 case GET_FROM_STRETCH
:
5040 p
->u
.stretch
.object
= it
->object
;
5043 p
->position
= it
->position
;
5044 p
->current
= it
->current
;
5045 p
->end_charpos
= it
->end_charpos
;
5046 p
->string_nchars
= it
->string_nchars
;
5048 p
->multibyte_p
= it
->multibyte_p
;
5049 p
->space_width
= it
->space_width
;
5050 p
->font_height
= it
->font_height
;
5051 p
->voffset
= it
->voffset
;
5052 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5053 p
->display_ellipsis_p
= 0;
5058 /* Restore IT's settings from IT->stack. Called, for example, when no
5059 more overlay strings must be processed, and we return to delivering
5060 display elements from a buffer, or when the end of a string from a
5061 `display' property is reached and we return to delivering display
5062 elements from an overlay string, or from a buffer. */
5068 struct iterator_stack_entry
*p
;
5070 xassert (it
->sp
> 0);
5072 p
= it
->stack
+ it
->sp
;
5073 it
->stop_charpos
= p
->stop_charpos
;
5074 it
->face_id
= p
->face_id
;
5075 it
->current
= p
->current
;
5076 it
->position
= p
->position
;
5077 it
->string
= p
->string
;
5078 it
->from_overlay
= p
->from_overlay
;
5079 if (NILP (it
->string
))
5080 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5081 it
->method
= p
->method
;
5084 case GET_FROM_IMAGE
:
5085 it
->image_id
= p
->u
.image
.image_id
;
5086 it
->object
= p
->u
.image
.object
;
5087 it
->slice
= p
->u
.image
.slice
;
5089 case GET_FROM_COMPOSITION
:
5090 it
->object
= p
->u
.comp
.object
;
5091 it
->c
= p
->u
.comp
.c
;
5092 it
->len
= p
->u
.comp
.len
;
5093 it
->cmp_id
= p
->u
.comp
.cmp_id
;
5094 it
->cmp_len
= p
->u
.comp
.cmp_len
;
5096 case GET_FROM_STRETCH
:
5097 it
->object
= p
->u
.comp
.object
;
5099 case GET_FROM_BUFFER
:
5100 it
->object
= it
->w
->buffer
;
5102 case GET_FROM_STRING
:
5103 it
->object
= it
->string
;
5106 it
->end_charpos
= p
->end_charpos
;
5107 it
->string_nchars
= p
->string_nchars
;
5109 it
->multibyte_p
= p
->multibyte_p
;
5110 it
->space_width
= p
->space_width
;
5111 it
->font_height
= p
->font_height
;
5112 it
->voffset
= p
->voffset
;
5113 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5118 /***********************************************************************
5120 ***********************************************************************/
5122 /* Set IT's current position to the previous line start. */
5125 back_to_previous_line_start (it
)
5128 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5129 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5133 /* Move IT to the next line start.
5135 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5136 we skipped over part of the text (as opposed to moving the iterator
5137 continuously over the text). Otherwise, don't change the value
5140 Newlines may come from buffer text, overlay strings, or strings
5141 displayed via the `display' property. That's the reason we can't
5142 simply use find_next_newline_no_quit.
5144 Note that this function may not skip over invisible text that is so
5145 because of text properties and immediately follows a newline. If
5146 it would, function reseat_at_next_visible_line_start, when called
5147 from set_iterator_to_next, would effectively make invisible
5148 characters following a newline part of the wrong glyph row, which
5149 leads to wrong cursor motion. */
5152 forward_to_next_line_start (it
, skipped_p
)
5156 int old_selective
, newline_found_p
, n
;
5157 const int MAX_NEWLINE_DISTANCE
= 500;
5159 /* If already on a newline, just consume it to avoid unintended
5160 skipping over invisible text below. */
5161 if (it
->what
== IT_CHARACTER
5163 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5165 set_iterator_to_next (it
, 0);
5170 /* Don't handle selective display in the following. It's (a)
5171 unnecessary because it's done by the caller, and (b) leads to an
5172 infinite recursion because next_element_from_ellipsis indirectly
5173 calls this function. */
5174 old_selective
= it
->selective
;
5177 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5178 from buffer text. */
5179 for (n
= newline_found_p
= 0;
5180 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5181 n
+= STRINGP (it
->string
) ? 0 : 1)
5183 if (!get_next_display_element (it
))
5185 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5186 set_iterator_to_next (it
, 0);
5189 /* If we didn't find a newline near enough, see if we can use a
5191 if (!newline_found_p
)
5193 int start
= IT_CHARPOS (*it
);
5194 int limit
= find_next_newline_no_quit (start
, 1);
5197 xassert (!STRINGP (it
->string
));
5199 /* If there isn't any `display' property in sight, and no
5200 overlays, we can just use the position of the newline in
5202 if (it
->stop_charpos
>= limit
5203 || ((pos
= Fnext_single_property_change (make_number (start
),
5205 Qnil
, make_number (limit
)),
5207 && next_overlay_change (start
) == ZV
))
5209 IT_CHARPOS (*it
) = limit
;
5210 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5211 *skipped_p
= newline_found_p
= 1;
5215 while (get_next_display_element (it
)
5216 && !newline_found_p
)
5218 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5219 set_iterator_to_next (it
, 0);
5224 it
->selective
= old_selective
;
5225 return newline_found_p
;
5229 /* Set IT's current position to the previous visible line start. Skip
5230 invisible text that is so either due to text properties or due to
5231 selective display. Caution: this does not change IT->current_x and
5235 back_to_previous_visible_line_start (it
)
5238 while (IT_CHARPOS (*it
) > BEGV
)
5240 back_to_previous_line_start (it
);
5242 if (IT_CHARPOS (*it
) <= BEGV
)
5245 /* If selective > 0, then lines indented more than that values
5247 if (it
->selective
> 0
5248 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5249 (double) it
->selective
)) /* iftc */
5252 /* Check the newline before point for invisibility. */
5255 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5256 Qinvisible
, it
->window
);
5257 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5261 if (IT_CHARPOS (*it
) <= BEGV
)
5268 Lisp_Object val
, overlay
;
5270 /* If newline is part of a composition, continue from start of composition */
5271 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5272 && beg
< IT_CHARPOS (*it
))
5275 /* If newline is replaced by a display property, find start of overlay
5276 or interval and continue search from that point. */
5278 pos
= --IT_CHARPOS (it2
);
5281 if (handle_display_prop (&it2
) == HANDLED_RETURN
5282 && !NILP (val
= get_char_property_and_overlay
5283 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5284 && (OVERLAYP (overlay
)
5285 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5286 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5289 /* Newline is not replaced by anything -- so we are done. */
5295 IT_CHARPOS (*it
) = beg
;
5296 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5300 it
->continuation_lines_width
= 0;
5302 xassert (IT_CHARPOS (*it
) >= BEGV
);
5303 xassert (IT_CHARPOS (*it
) == BEGV
5304 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5309 /* Reseat iterator IT at the previous visible line start. Skip
5310 invisible text that is so either due to text properties or due to
5311 selective display. At the end, update IT's overlay information,
5312 face information etc. */
5315 reseat_at_previous_visible_line_start (it
)
5318 back_to_previous_visible_line_start (it
);
5319 reseat (it
, it
->current
.pos
, 1);
5324 /* Reseat iterator IT on the next visible line start in the current
5325 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5326 preceding the line start. Skip over invisible text that is so
5327 because of selective display. Compute faces, overlays etc at the
5328 new position. Note that this function does not skip over text that
5329 is invisible because of text properties. */
5332 reseat_at_next_visible_line_start (it
, on_newline_p
)
5336 int newline_found_p
, skipped_p
= 0;
5338 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5340 /* Skip over lines that are invisible because they are indented
5341 more than the value of IT->selective. */
5342 if (it
->selective
> 0)
5343 while (IT_CHARPOS (*it
) < ZV
5344 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5345 (double) it
->selective
)) /* iftc */
5347 xassert (IT_BYTEPOS (*it
) == BEGV
5348 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5349 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5352 /* Position on the newline if that's what's requested. */
5353 if (on_newline_p
&& newline_found_p
)
5355 if (STRINGP (it
->string
))
5357 if (IT_STRING_CHARPOS (*it
) > 0)
5359 --IT_STRING_CHARPOS (*it
);
5360 --IT_STRING_BYTEPOS (*it
);
5363 else if (IT_CHARPOS (*it
) > BEGV
)
5367 reseat (it
, it
->current
.pos
, 0);
5371 reseat (it
, it
->current
.pos
, 0);
5378 /***********************************************************************
5379 Changing an iterator's position
5380 ***********************************************************************/
5382 /* Change IT's current position to POS in current_buffer. If FORCE_P
5383 is non-zero, always check for text properties at the new position.
5384 Otherwise, text properties are only looked up if POS >=
5385 IT->check_charpos of a property. */
5388 reseat (it
, pos
, force_p
)
5390 struct text_pos pos
;
5393 int original_pos
= IT_CHARPOS (*it
);
5395 reseat_1 (it
, pos
, 0);
5397 /* Determine where to check text properties. Avoid doing it
5398 where possible because text property lookup is very expensive. */
5400 || CHARPOS (pos
) > it
->stop_charpos
5401 || CHARPOS (pos
) < original_pos
)
5408 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5409 IT->stop_pos to POS, also. */
5412 reseat_1 (it
, pos
, set_stop_p
)
5414 struct text_pos pos
;
5417 /* Don't call this function when scanning a C string. */
5418 xassert (it
->s
== NULL
);
5420 /* POS must be a reasonable value. */
5421 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5423 it
->current
.pos
= it
->position
= pos
;
5424 it
->end_charpos
= ZV
;
5426 it
->current
.dpvec_index
= -1;
5427 it
->current
.overlay_string_index
= -1;
5428 IT_STRING_CHARPOS (*it
) = -1;
5429 IT_STRING_BYTEPOS (*it
) = -1;
5431 it
->method
= GET_FROM_BUFFER
;
5432 it
->object
= it
->w
->buffer
;
5433 it
->area
= TEXT_AREA
;
5434 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5436 it
->string_from_display_prop_p
= 0;
5437 it
->face_before_selective_p
= 0;
5440 it
->stop_charpos
= CHARPOS (pos
);
5444 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5445 If S is non-null, it is a C string to iterate over. Otherwise,
5446 STRING gives a Lisp string to iterate over.
5448 If PRECISION > 0, don't return more then PRECISION number of
5449 characters from the string.
5451 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5452 characters have been returned. FIELD_WIDTH < 0 means an infinite
5455 MULTIBYTE = 0 means disable processing of multibyte characters,
5456 MULTIBYTE > 0 means enable it,
5457 MULTIBYTE < 0 means use IT->multibyte_p.
5459 IT must be initialized via a prior call to init_iterator before
5460 calling this function. */
5463 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5468 int precision
, field_width
, multibyte
;
5470 /* No region in strings. */
5471 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5473 /* No text property checks performed by default, but see below. */
5474 it
->stop_charpos
= -1;
5476 /* Set iterator position and end position. */
5477 bzero (&it
->current
, sizeof it
->current
);
5478 it
->current
.overlay_string_index
= -1;
5479 it
->current
.dpvec_index
= -1;
5480 xassert (charpos
>= 0);
5482 /* If STRING is specified, use its multibyteness, otherwise use the
5483 setting of MULTIBYTE, if specified. */
5485 it
->multibyte_p
= multibyte
> 0;
5489 xassert (STRINGP (string
));
5490 it
->string
= string
;
5492 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5493 it
->method
= GET_FROM_STRING
;
5494 it
->current
.string_pos
= string_pos (charpos
, string
);
5501 /* Note that we use IT->current.pos, not it->current.string_pos,
5502 for displaying C strings. */
5503 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5504 if (it
->multibyte_p
)
5506 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5507 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5511 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5512 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5515 it
->method
= GET_FROM_C_STRING
;
5518 /* PRECISION > 0 means don't return more than PRECISION characters
5520 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5521 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5523 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5524 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5525 FIELD_WIDTH < 0 means infinite field width. This is useful for
5526 padding with `-' at the end of a mode line. */
5527 if (field_width
< 0)
5528 field_width
= INFINITY
;
5529 if (field_width
> it
->end_charpos
- charpos
)
5530 it
->end_charpos
= charpos
+ field_width
;
5532 /* Use the standard display table for displaying strings. */
5533 if (DISP_TABLE_P (Vstandard_display_table
))
5534 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5536 it
->stop_charpos
= charpos
;
5542 /***********************************************************************
5544 ***********************************************************************/
5546 /* Map enum it_method value to corresponding next_element_from_* function. */
5548 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5550 next_element_from_buffer
,
5551 next_element_from_display_vector
,
5552 next_element_from_composition
,
5553 next_element_from_string
,
5554 next_element_from_c_string
,
5555 next_element_from_image
,
5556 next_element_from_stretch
5560 /* Load IT's display element fields with information about the next
5561 display element from the current position of IT. Value is zero if
5562 end of buffer (or C string) is reached. */
5564 static struct frame
*last_escape_glyph_frame
= NULL
;
5565 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5566 static int last_escape_glyph_merged_face_id
= 0;
5569 get_next_display_element (it
)
5572 /* Non-zero means that we found a display element. Zero means that
5573 we hit the end of what we iterate over. Performance note: the
5574 function pointer `method' used here turns out to be faster than
5575 using a sequence of if-statements. */
5579 success_p
= (*get_next_element
[it
->method
]) (it
);
5581 if (it
->what
== IT_CHARACTER
)
5583 /* Map via display table or translate control characters.
5584 IT->c, IT->len etc. have been set to the next character by
5585 the function call above. If we have a display table, and it
5586 contains an entry for IT->c, translate it. Don't do this if
5587 IT->c itself comes from a display table, otherwise we could
5588 end up in an infinite recursion. (An alternative could be to
5589 count the recursion depth of this function and signal an
5590 error when a certain maximum depth is reached.) Is it worth
5592 if (success_p
&& it
->dpvec
== NULL
)
5597 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5600 struct Lisp_Vector
*v
= XVECTOR (dv
);
5602 /* Return the first character from the display table
5603 entry, if not empty. If empty, don't display the
5604 current character. */
5607 it
->dpvec_char_len
= it
->len
;
5608 it
->dpvec
= v
->contents
;
5609 it
->dpend
= v
->contents
+ v
->size
;
5610 it
->current
.dpvec_index
= 0;
5611 it
->dpvec_face_id
= -1;
5612 it
->saved_face_id
= it
->face_id
;
5613 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5618 set_iterator_to_next (it
, 0);
5623 /* Translate control characters into `\003' or `^C' form.
5624 Control characters coming from a display table entry are
5625 currently not translated because we use IT->dpvec to hold
5626 the translation. This could easily be changed but I
5627 don't believe that it is worth doing.
5629 If it->multibyte_p is nonzero, eight-bit characters and
5630 non-printable multibyte characters are also translated to
5633 If it->multibyte_p is zero, eight-bit characters that
5634 don't have corresponding multibyte char code are also
5635 translated to octal form. */
5636 else if ((it
->c
< ' '
5637 && (it
->area
!= TEXT_AREA
5638 /* In mode line, treat \n like other crl chars. */
5640 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5641 || (it
->c
!= '\n' && it
->c
!= '\t')))
5645 || !CHAR_PRINTABLE_P (it
->c
)
5646 || (!NILP (Vnobreak_char_display
)
5647 && (it
->c
== 0x8a0 || it
->c
== 0x8ad
5648 || it
->c
== 0x920 || it
->c
== 0x92d
5649 || it
->c
== 0xe20 || it
->c
== 0xe2d
5650 || it
->c
== 0xf20 || it
->c
== 0xf2d)))
5652 && (!unibyte_display_via_language_environment
5653 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
5655 /* IT->c is a control character which must be displayed
5656 either as '\003' or as `^C' where the '\\' and '^'
5657 can be defined in the display table. Fill
5658 IT->ctl_chars with glyphs for what we have to
5659 display. Then, set IT->dpvec to these glyphs. */
5662 int face_id
, lface_id
= 0 ;
5665 /* Handle control characters with ^. */
5667 if (it
->c
< 128 && it
->ctl_arrow_p
)
5669 g
= '^'; /* default glyph for Control */
5670 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5672 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5673 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5675 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5676 lface_id
= FAST_GLYPH_FACE (g
);
5680 g
= FAST_GLYPH_CHAR (g
);
5681 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5684 else if (it
->f
== last_escape_glyph_frame
5685 && it
->face_id
== last_escape_glyph_face_id
)
5687 face_id
= last_escape_glyph_merged_face_id
;
5691 /* Merge the escape-glyph face into the current face. */
5692 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5694 last_escape_glyph_frame
= it
->f
;
5695 last_escape_glyph_face_id
= it
->face_id
;
5696 last_escape_glyph_merged_face_id
= face_id
;
5699 XSETINT (it
->ctl_chars
[0], g
);
5701 XSETINT (it
->ctl_chars
[1], g
);
5703 goto display_control
;
5706 /* Handle non-break space in the mode where it only gets
5709 if (EQ (Vnobreak_char_display
, Qt
)
5710 && (it
->c
== 0x8a0 || it
->c
== 0x920
5711 || it
->c
== 0xe20 || it
->c
== 0xf20))
5713 /* Merge the no-break-space face into the current face. */
5714 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5718 XSETINT (it
->ctl_chars
[0], g
);
5720 goto display_control
;
5723 /* Handle sequences that start with the "escape glyph". */
5725 /* the default escape glyph is \. */
5726 escape_glyph
= '\\';
5729 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5730 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5732 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5733 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5737 /* The display table specified a face.
5738 Merge it into face_id and also into escape_glyph. */
5739 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5740 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5743 else if (it
->f
== last_escape_glyph_frame
5744 && it
->face_id
== last_escape_glyph_face_id
)
5746 face_id
= last_escape_glyph_merged_face_id
;
5750 /* Merge the escape-glyph face into the current face. */
5751 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5753 last_escape_glyph_frame
= it
->f
;
5754 last_escape_glyph_face_id
= it
->face_id
;
5755 last_escape_glyph_merged_face_id
= face_id
;
5758 /* Handle soft hyphens in the mode where they only get
5761 if (EQ (Vnobreak_char_display
, Qt
)
5762 && (it
->c
== 0x8ad || it
->c
== 0x92d
5763 || it
->c
== 0xe2d || it
->c
== 0xf2d))
5766 XSETINT (it
->ctl_chars
[0], g
);
5768 goto display_control
;
5771 /* Handle non-break space and soft hyphen
5772 with the escape glyph. */
5774 if (it
->c
== 0x8a0 || it
->c
== 0x8ad
5775 || it
->c
== 0x920 || it
->c
== 0x92d
5776 || it
->c
== 0xe20 || it
->c
== 0xe2d
5777 || it
->c
== 0xf20 || it
->c
== 0xf2d)
5779 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5780 g
= it
->c
= ((it
->c
& 0xf) == 0 ? ' ' : '-');
5781 XSETINT (it
->ctl_chars
[1], g
);
5783 goto display_control
;
5787 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5791 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5792 if (SINGLE_BYTE_CHAR_P (it
->c
))
5793 str
[0] = it
->c
, len
= 1;
5796 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5799 /* It's an invalid character, which shouldn't
5800 happen actually, but due to bugs it may
5801 happen. Let's print the char as is, there's
5802 not much meaningful we can do with it. */
5804 str
[1] = it
->c
>> 8;
5805 str
[2] = it
->c
>> 16;
5806 str
[3] = it
->c
>> 24;
5811 for (i
= 0; i
< len
; i
++)
5813 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5814 /* Insert three more glyphs into IT->ctl_chars for
5815 the octal display of the character. */
5816 g
= ((str
[i
] >> 6) & 7) + '0';
5817 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5818 g
= ((str
[i
] >> 3) & 7) + '0';
5819 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5820 g
= (str
[i
] & 7) + '0';
5821 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5827 /* Set up IT->dpvec and return first character from it. */
5828 it
->dpvec_char_len
= it
->len
;
5829 it
->dpvec
= it
->ctl_chars
;
5830 it
->dpend
= it
->dpvec
+ ctl_len
;
5831 it
->current
.dpvec_index
= 0;
5832 it
->dpvec_face_id
= face_id
;
5833 it
->saved_face_id
= it
->face_id
;
5834 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5840 /* Adjust face id for a multibyte character. There are no
5841 multibyte character in unibyte text. */
5844 && FRAME_WINDOW_P (it
->f
))
5846 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5847 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5851 /* Is this character the last one of a run of characters with
5852 box? If yes, set IT->end_of_box_run_p to 1. */
5859 it
->end_of_box_run_p
5860 = ((face_id
= face_after_it_pos (it
),
5861 face_id
!= it
->face_id
)
5862 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5863 face
->box
== FACE_NO_BOX
));
5866 /* Value is 0 if end of buffer or string reached. */
5871 /* Move IT to the next display element.
5873 RESEAT_P non-zero means if called on a newline in buffer text,
5874 skip to the next visible line start.
5876 Functions get_next_display_element and set_iterator_to_next are
5877 separate because I find this arrangement easier to handle than a
5878 get_next_display_element function that also increments IT's
5879 position. The way it is we can first look at an iterator's current
5880 display element, decide whether it fits on a line, and if it does,
5881 increment the iterator position. The other way around we probably
5882 would either need a flag indicating whether the iterator has to be
5883 incremented the next time, or we would have to implement a
5884 decrement position function which would not be easy to write. */
5887 set_iterator_to_next (it
, reseat_p
)
5891 /* Reset flags indicating start and end of a sequence of characters
5892 with box. Reset them at the start of this function because
5893 moving the iterator to a new position might set them. */
5894 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5898 case GET_FROM_BUFFER
:
5899 /* The current display element of IT is a character from
5900 current_buffer. Advance in the buffer, and maybe skip over
5901 invisible lines that are so because of selective display. */
5902 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5903 reseat_at_next_visible_line_start (it
, 0);
5906 xassert (it
->len
!= 0);
5907 IT_BYTEPOS (*it
) += it
->len
;
5908 IT_CHARPOS (*it
) += 1;
5909 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5913 case GET_FROM_COMPOSITION
:
5914 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5915 xassert (it
->sp
> 0);
5917 if (it
->method
== GET_FROM_STRING
)
5919 IT_STRING_BYTEPOS (*it
) += it
->len
;
5920 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5921 goto consider_string_end
;
5923 else if (it
->method
== GET_FROM_BUFFER
)
5925 IT_BYTEPOS (*it
) += it
->len
;
5926 IT_CHARPOS (*it
) += it
->cmp_len
;
5930 case GET_FROM_C_STRING
:
5931 /* Current display element of IT is from a C string. */
5932 IT_BYTEPOS (*it
) += it
->len
;
5933 IT_CHARPOS (*it
) += 1;
5936 case GET_FROM_DISPLAY_VECTOR
:
5937 /* Current display element of IT is from a display table entry.
5938 Advance in the display table definition. Reset it to null if
5939 end reached, and continue with characters from buffers/
5941 ++it
->current
.dpvec_index
;
5943 /* Restore face of the iterator to what they were before the
5944 display vector entry (these entries may contain faces). */
5945 it
->face_id
= it
->saved_face_id
;
5947 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5949 int recheck_faces
= it
->ellipsis_p
;
5952 it
->method
= GET_FROM_C_STRING
;
5953 else if (STRINGP (it
->string
))
5954 it
->method
= GET_FROM_STRING
;
5957 it
->method
= GET_FROM_BUFFER
;
5958 it
->object
= it
->w
->buffer
;
5962 it
->current
.dpvec_index
= -1;
5964 /* Skip over characters which were displayed via IT->dpvec. */
5965 if (it
->dpvec_char_len
< 0)
5966 reseat_at_next_visible_line_start (it
, 1);
5967 else if (it
->dpvec_char_len
> 0)
5969 if (it
->method
== GET_FROM_STRING
5970 && it
->n_overlay_strings
> 0)
5971 it
->ignore_overlay_strings_at_pos_p
= 1;
5972 it
->len
= it
->dpvec_char_len
;
5973 set_iterator_to_next (it
, reseat_p
);
5976 /* Maybe recheck faces after display vector */
5978 it
->stop_charpos
= IT_CHARPOS (*it
);
5982 case GET_FROM_STRING
:
5983 /* Current display element is a character from a Lisp string. */
5984 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5985 IT_STRING_BYTEPOS (*it
) += it
->len
;
5986 IT_STRING_CHARPOS (*it
) += 1;
5988 consider_string_end
:
5990 if (it
->current
.overlay_string_index
>= 0)
5992 /* IT->string is an overlay string. Advance to the
5993 next, if there is one. */
5994 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5995 next_overlay_string (it
);
5999 /* IT->string is not an overlay string. If we reached
6000 its end, and there is something on IT->stack, proceed
6001 with what is on the stack. This can be either another
6002 string, this time an overlay string, or a buffer. */
6003 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6007 if (it
->method
== GET_FROM_STRING
)
6008 goto consider_string_end
;
6013 case GET_FROM_IMAGE
:
6014 case GET_FROM_STRETCH
:
6015 /* The position etc with which we have to proceed are on
6016 the stack. The position may be at the end of a string,
6017 if the `display' property takes up the whole string. */
6018 xassert (it
->sp
> 0);
6020 if (it
->method
== GET_FROM_STRING
)
6021 goto consider_string_end
;
6025 /* There are no other methods defined, so this should be a bug. */
6029 xassert (it
->method
!= GET_FROM_STRING
6030 || (STRINGP (it
->string
)
6031 && IT_STRING_CHARPOS (*it
) >= 0));
6034 /* Load IT's display element fields with information about the next
6035 display element which comes from a display table entry or from the
6036 result of translating a control character to one of the forms `^C'
6039 IT->dpvec holds the glyphs to return as characters.
6040 IT->saved_face_id holds the face id before the display vector--
6041 it is restored into IT->face_idin set_iterator_to_next. */
6044 next_element_from_display_vector (it
)
6048 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6050 it
->face_id
= it
->saved_face_id
;
6052 if (INTEGERP (*it
->dpvec
)
6053 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
6057 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
6058 it
->c
= FAST_GLYPH_CHAR (g
);
6059 it
->len
= CHAR_BYTES (it
->c
);
6061 /* The entry may contain a face id to use. Such a face id is
6062 the id of a Lisp face, not a realized face. A face id of
6063 zero means no face is specified. */
6064 if (it
->dpvec_face_id
>= 0)
6065 it
->face_id
= it
->dpvec_face_id
;
6068 int lface_id
= FAST_GLYPH_FACE (g
);
6070 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6075 /* Display table entry is invalid. Return a space. */
6076 it
->c
= ' ', it
->len
= 1;
6078 /* Don't change position and object of the iterator here. They are
6079 still the values of the character that had this display table
6080 entry or was translated, and that's what we want. */
6081 it
->what
= IT_CHARACTER
;
6086 /* Load IT with the next display element from Lisp string IT->string.
6087 IT->current.string_pos is the current position within the string.
6088 If IT->current.overlay_string_index >= 0, the Lisp string is an
6092 next_element_from_string (it
)
6095 struct text_pos position
;
6097 xassert (STRINGP (it
->string
));
6098 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6099 position
= it
->current
.string_pos
;
6101 /* Time to check for invisible text? */
6102 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6103 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6107 /* Since a handler may have changed IT->method, we must
6109 return get_next_display_element (it
);
6112 if (it
->current
.overlay_string_index
>= 0)
6114 /* Get the next character from an overlay string. In overlay
6115 strings, There is no field width or padding with spaces to
6117 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6122 else if (STRING_MULTIBYTE (it
->string
))
6124 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6125 const unsigned char *s
= (SDATA (it
->string
)
6126 + IT_STRING_BYTEPOS (*it
));
6127 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
6131 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6137 /* Get the next character from a Lisp string that is not an
6138 overlay string. Such strings come from the mode line, for
6139 example. We may have to pad with spaces, or truncate the
6140 string. See also next_element_from_c_string. */
6141 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6146 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6148 /* Pad with spaces. */
6149 it
->c
= ' ', it
->len
= 1;
6150 CHARPOS (position
) = BYTEPOS (position
) = -1;
6152 else if (STRING_MULTIBYTE (it
->string
))
6154 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6155 const unsigned char *s
= (SDATA (it
->string
)
6156 + IT_STRING_BYTEPOS (*it
));
6157 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
6161 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6166 /* Record what we have and where it came from. */
6167 it
->what
= IT_CHARACTER
;
6168 it
->object
= it
->string
;
6169 it
->position
= position
;
6174 /* Load IT with next display element from C string IT->s.
6175 IT->string_nchars is the maximum number of characters to return
6176 from the string. IT->end_charpos may be greater than
6177 IT->string_nchars when this function is called, in which case we
6178 may have to return padding spaces. Value is zero if end of string
6179 reached, including padding spaces. */
6182 next_element_from_c_string (it
)
6188 it
->what
= IT_CHARACTER
;
6189 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6192 /* IT's position can be greater IT->string_nchars in case a field
6193 width or precision has been specified when the iterator was
6195 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6197 /* End of the game. */
6201 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6203 /* Pad with spaces. */
6204 it
->c
= ' ', it
->len
= 1;
6205 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6207 else if (it
->multibyte_p
)
6209 /* Implementation note: The calls to strlen apparently aren't a
6210 performance problem because there is no noticeable performance
6211 difference between Emacs running in unibyte or multibyte mode. */
6212 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6213 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
6217 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6223 /* Set up IT to return characters from an ellipsis, if appropriate.
6224 The definition of the ellipsis glyphs may come from a display table
6225 entry. This function Fills IT with the first glyph from the
6226 ellipsis if an ellipsis is to be displayed. */
6229 next_element_from_ellipsis (it
)
6232 if (it
->selective_display_ellipsis_p
)
6233 setup_for_ellipsis (it
, it
->len
);
6236 /* The face at the current position may be different from the
6237 face we find after the invisible text. Remember what it
6238 was in IT->saved_face_id, and signal that it's there by
6239 setting face_before_selective_p. */
6240 it
->saved_face_id
= it
->face_id
;
6241 it
->method
= GET_FROM_BUFFER
;
6242 it
->object
= it
->w
->buffer
;
6243 reseat_at_next_visible_line_start (it
, 1);
6244 it
->face_before_selective_p
= 1;
6247 return get_next_display_element (it
);
6251 /* Deliver an image display element. The iterator IT is already
6252 filled with image information (done in handle_display_prop). Value
6257 next_element_from_image (it
)
6260 it
->what
= IT_IMAGE
;
6265 /* Fill iterator IT with next display element from a stretch glyph
6266 property. IT->object is the value of the text property. Value is
6270 next_element_from_stretch (it
)
6273 it
->what
= IT_STRETCH
;
6278 /* Load IT with the next display element from current_buffer. Value
6279 is zero if end of buffer reached. IT->stop_charpos is the next
6280 position at which to stop and check for text properties or buffer
6284 next_element_from_buffer (it
)
6289 /* Check this assumption, otherwise, we would never enter the
6290 if-statement, below. */
6291 xassert (IT_CHARPOS (*it
) >= BEGV
6292 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
6294 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6296 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6298 int overlay_strings_follow_p
;
6300 /* End of the game, except when overlay strings follow that
6301 haven't been returned yet. */
6302 if (it
->overlay_strings_at_end_processed_p
)
6303 overlay_strings_follow_p
= 0;
6306 it
->overlay_strings_at_end_processed_p
= 1;
6307 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6310 if (overlay_strings_follow_p
)
6311 success_p
= get_next_display_element (it
);
6315 it
->position
= it
->current
.pos
;
6322 return get_next_display_element (it
);
6327 /* No face changes, overlays etc. in sight, so just return a
6328 character from current_buffer. */
6331 /* Maybe run the redisplay end trigger hook. Performance note:
6332 This doesn't seem to cost measurable time. */
6333 if (it
->redisplay_end_trigger_charpos
6335 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6336 run_redisplay_end_trigger_hook (it
);
6338 /* Get the next character, maybe multibyte. */
6339 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6340 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6342 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
6343 - IT_BYTEPOS (*it
));
6344 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
6347 it
->c
= *p
, it
->len
= 1;
6349 /* Record what we have and where it came from. */
6350 it
->what
= IT_CHARACTER
;
6351 it
->object
= it
->w
->buffer
;
6352 it
->position
= it
->current
.pos
;
6354 /* Normally we return the character found above, except when we
6355 really want to return an ellipsis for selective display. */
6360 /* A value of selective > 0 means hide lines indented more
6361 than that number of columns. */
6362 if (it
->selective
> 0
6363 && IT_CHARPOS (*it
) + 1 < ZV
6364 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6365 IT_BYTEPOS (*it
) + 1,
6366 (double) it
->selective
)) /* iftc */
6368 success_p
= next_element_from_ellipsis (it
);
6369 it
->dpvec_char_len
= -1;
6372 else if (it
->c
== '\r' && it
->selective
== -1)
6374 /* A value of selective == -1 means that everything from the
6375 CR to the end of the line is invisible, with maybe an
6376 ellipsis displayed for it. */
6377 success_p
= next_element_from_ellipsis (it
);
6378 it
->dpvec_char_len
= -1;
6383 /* Value is zero if end of buffer reached. */
6384 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6389 /* Run the redisplay end trigger hook for IT. */
6392 run_redisplay_end_trigger_hook (it
)
6395 Lisp_Object args
[3];
6397 /* IT->glyph_row should be non-null, i.e. we should be actually
6398 displaying something, or otherwise we should not run the hook. */
6399 xassert (it
->glyph_row
);
6401 /* Set up hook arguments. */
6402 args
[0] = Qredisplay_end_trigger_functions
;
6403 args
[1] = it
->window
;
6404 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6405 it
->redisplay_end_trigger_charpos
= 0;
6407 /* Since we are *trying* to run these functions, don't try to run
6408 them again, even if they get an error. */
6409 it
->w
->redisplay_end_trigger
= Qnil
;
6410 Frun_hook_with_args (3, args
);
6412 /* Notice if it changed the face of the character we are on. */
6413 handle_face_prop (it
);
6417 /* Deliver a composition display element. The iterator IT is already
6418 filled with composition information (done in
6419 handle_composition_prop). Value is always 1. */
6422 next_element_from_composition (it
)
6425 it
->what
= IT_COMPOSITION
;
6426 it
->position
= (STRINGP (it
->string
)
6427 ? it
->current
.string_pos
6429 if (STRINGP (it
->string
))
6430 it
->object
= it
->string
;
6432 it
->object
= it
->w
->buffer
;
6438 /***********************************************************************
6439 Moving an iterator without producing glyphs
6440 ***********************************************************************/
6442 /* Check if iterator is at a position corresponding to a valid buffer
6443 position after some move_it_ call. */
6445 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6446 ((it)->method == GET_FROM_STRING \
6447 ? IT_STRING_CHARPOS (*it) == 0 \
6451 /* Move iterator IT to a specified buffer or X position within one
6452 line on the display without producing glyphs.
6454 OP should be a bit mask including some or all of these bits:
6455 MOVE_TO_X: Stop on reaching x-position TO_X.
6456 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6457 Regardless of OP's value, stop in reaching the end of the display line.
6459 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6460 This means, in particular, that TO_X includes window's horizontal
6463 The return value has several possible values that
6464 say what condition caused the scan to stop:
6466 MOVE_POS_MATCH_OR_ZV
6467 - when TO_POS or ZV was reached.
6470 -when TO_X was reached before TO_POS or ZV were reached.
6473 - when we reached the end of the display area and the line must
6477 - when we reached the end of the display area and the line is
6481 - when we stopped at a line end, i.e. a newline or a CR and selective
6484 static enum move_it_result
6485 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
6487 int to_charpos
, to_x
, op
;
6489 enum move_it_result result
= MOVE_UNDEFINED
;
6490 struct glyph_row
*saved_glyph_row
;
6492 /* Don't produce glyphs in produce_glyphs. */
6493 saved_glyph_row
= it
->glyph_row
;
6494 it
->glyph_row
= NULL
;
6496 #define BUFFER_POS_REACHED_P() \
6497 ((op & MOVE_TO_POS) != 0 \
6498 && BUFFERP (it->object) \
6499 && IT_CHARPOS (*it) >= to_charpos \
6500 && (it->method == GET_FROM_BUFFER \
6501 || (it->method == GET_FROM_DISPLAY_VECTOR \
6502 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6507 int x
, i
, ascent
= 0, descent
= 0;
6509 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
6510 if ((op
& MOVE_TO_POS
) != 0
6511 && BUFFERP (it
->object
)
6512 && it
->method
== GET_FROM_BUFFER
6513 && IT_CHARPOS (*it
) > to_charpos
)
6515 result
= MOVE_POS_MATCH_OR_ZV
;
6519 /* Stop when ZV reached.
6520 We used to stop here when TO_CHARPOS reached as well, but that is
6521 too soon if this glyph does not fit on this line. So we handle it
6522 explicitly below. */
6523 if (!get_next_display_element (it
)
6524 || (it
->truncate_lines_p
6525 && BUFFER_POS_REACHED_P ()))
6527 result
= MOVE_POS_MATCH_OR_ZV
;
6531 /* The call to produce_glyphs will get the metrics of the
6532 display element IT is loaded with. We record in x the
6533 x-position before this display element in case it does not
6537 /* Remember the line height so far in case the next element doesn't
6539 if (!it
->truncate_lines_p
)
6541 ascent
= it
->max_ascent
;
6542 descent
= it
->max_descent
;
6545 PRODUCE_GLYPHS (it
);
6547 if (it
->area
!= TEXT_AREA
)
6549 set_iterator_to_next (it
, 1);
6553 /* The number of glyphs we get back in IT->nglyphs will normally
6554 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6555 character on a terminal frame, or (iii) a line end. For the
6556 second case, IT->nglyphs - 1 padding glyphs will be present
6557 (on X frames, there is only one glyph produced for a
6558 composite character.
6560 The behavior implemented below means, for continuation lines,
6561 that as many spaces of a TAB as fit on the current line are
6562 displayed there. For terminal frames, as many glyphs of a
6563 multi-glyph character are displayed in the current line, too.
6564 This is what the old redisplay code did, and we keep it that
6565 way. Under X, the whole shape of a complex character must
6566 fit on the line or it will be completely displayed in the
6569 Note that both for tabs and padding glyphs, all glyphs have
6573 /* More than one glyph or glyph doesn't fit on line. All
6574 glyphs have the same width. */
6575 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6577 int x_before_this_char
= x
;
6578 int hpos_before_this_char
= it
->hpos
;
6580 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6582 new_x
= x
+ single_glyph_width
;
6584 /* We want to leave anything reaching TO_X to the caller. */
6585 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6587 if (BUFFER_POS_REACHED_P ())
6588 goto buffer_pos_reached
;
6590 result
= MOVE_X_REACHED
;
6593 else if (/* Lines are continued. */
6594 !it
->truncate_lines_p
6595 && (/* And glyph doesn't fit on the line. */
6596 new_x
> it
->last_visible_x
6597 /* Or it fits exactly and we're on a window
6599 || (new_x
== it
->last_visible_x
6600 && FRAME_WINDOW_P (it
->f
))))
6602 if (/* IT->hpos == 0 means the very first glyph
6603 doesn't fit on the line, e.g. a wide image. */
6605 || (new_x
== it
->last_visible_x
6606 && FRAME_WINDOW_P (it
->f
)))
6609 it
->current_x
= new_x
;
6611 /* The character's last glyph just barely fits
6613 if (i
== it
->nglyphs
- 1)
6615 /* If this is the destination position,
6616 return a position *before* it in this row,
6617 now that we know it fits in this row. */
6618 if (BUFFER_POS_REACHED_P ())
6620 it
->hpos
= hpos_before_this_char
;
6621 it
->current_x
= x_before_this_char
;
6622 result
= MOVE_POS_MATCH_OR_ZV
;
6626 set_iterator_to_next (it
, 1);
6627 #ifdef HAVE_WINDOW_SYSTEM
6628 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6630 if (!get_next_display_element (it
))
6632 result
= MOVE_POS_MATCH_OR_ZV
;
6635 if (BUFFER_POS_REACHED_P ())
6637 if (ITERATOR_AT_END_OF_LINE_P (it
))
6638 result
= MOVE_POS_MATCH_OR_ZV
;
6640 result
= MOVE_LINE_CONTINUED
;
6643 if (ITERATOR_AT_END_OF_LINE_P (it
))
6645 result
= MOVE_NEWLINE_OR_CR
;
6649 #endif /* HAVE_WINDOW_SYSTEM */
6655 it
->max_ascent
= ascent
;
6656 it
->max_descent
= descent
;
6659 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6661 result
= MOVE_LINE_CONTINUED
;
6664 else if (BUFFER_POS_REACHED_P ())
6665 goto buffer_pos_reached
;
6666 else if (new_x
> it
->first_visible_x
)
6668 /* Glyph is visible. Increment number of glyphs that
6669 would be displayed. */
6674 /* Glyph is completely off the left margin of the display
6675 area. Nothing to do. */
6679 if (result
!= MOVE_UNDEFINED
)
6682 else if (BUFFER_POS_REACHED_P ())
6686 it
->max_ascent
= ascent
;
6687 it
->max_descent
= descent
;
6688 result
= MOVE_POS_MATCH_OR_ZV
;
6691 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6693 /* Stop when TO_X specified and reached. This check is
6694 necessary here because of lines consisting of a line end,
6695 only. The line end will not produce any glyphs and we
6696 would never get MOVE_X_REACHED. */
6697 xassert (it
->nglyphs
== 0);
6698 result
= MOVE_X_REACHED
;
6702 /* Is this a line end? If yes, we're done. */
6703 if (ITERATOR_AT_END_OF_LINE_P (it
))
6705 result
= MOVE_NEWLINE_OR_CR
;
6709 /* The current display element has been consumed. Advance
6711 set_iterator_to_next (it
, 1);
6713 /* Stop if lines are truncated and IT's current x-position is
6714 past the right edge of the window now. */
6715 if (it
->truncate_lines_p
6716 && it
->current_x
>= it
->last_visible_x
)
6718 #ifdef HAVE_WINDOW_SYSTEM
6719 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6721 if (!get_next_display_element (it
)
6722 || BUFFER_POS_REACHED_P ())
6724 result
= MOVE_POS_MATCH_OR_ZV
;
6727 if (ITERATOR_AT_END_OF_LINE_P (it
))
6729 result
= MOVE_NEWLINE_OR_CR
;
6733 #endif /* HAVE_WINDOW_SYSTEM */
6734 result
= MOVE_LINE_TRUNCATED
;
6739 #undef BUFFER_POS_REACHED_P
6741 /* Restore the iterator settings altered at the beginning of this
6743 it
->glyph_row
= saved_glyph_row
;
6748 /* Move IT forward until it satisfies one or more of the criteria in
6749 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6751 OP is a bit-mask that specifies where to stop, and in particular,
6752 which of those four position arguments makes a difference. See the
6753 description of enum move_operation_enum.
6755 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6756 screen line, this function will set IT to the next position >
6760 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6762 int to_charpos
, to_x
, to_y
, to_vpos
;
6765 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6771 if (op
& MOVE_TO_VPOS
)
6773 /* If no TO_CHARPOS and no TO_X specified, stop at the
6774 start of the line TO_VPOS. */
6775 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6777 if (it
->vpos
== to_vpos
)
6783 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6787 /* TO_VPOS >= 0 means stop at TO_X in the line at
6788 TO_VPOS, or at TO_POS, whichever comes first. */
6789 if (it
->vpos
== to_vpos
)
6795 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6797 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6802 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6804 /* We have reached TO_X but not in the line we want. */
6805 skip
= move_it_in_display_line_to (it
, to_charpos
,
6807 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6815 else if (op
& MOVE_TO_Y
)
6817 struct it it_backup
;
6819 /* TO_Y specified means stop at TO_X in the line containing
6820 TO_Y---or at TO_CHARPOS if this is reached first. The
6821 problem is that we can't really tell whether the line
6822 contains TO_Y before we have completely scanned it, and
6823 this may skip past TO_X. What we do is to first scan to
6826 If TO_X is not specified, use a TO_X of zero. The reason
6827 is to make the outcome of this function more predictable.
6828 If we didn't use TO_X == 0, we would stop at the end of
6829 the line which is probably not what a caller would expect
6831 skip
= move_it_in_display_line_to (it
, to_charpos
,
6835 | (op
& MOVE_TO_POS
)));
6837 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6838 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6844 /* If TO_X was reached, we would like to know whether TO_Y
6845 is in the line. This can only be said if we know the
6846 total line height which requires us to scan the rest of
6848 if (skip
== MOVE_X_REACHED
)
6851 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6852 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6854 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6857 /* Now, decide whether TO_Y is in this line. */
6858 line_height
= it
->max_ascent
+ it
->max_descent
;
6859 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6861 if (to_y
>= it
->current_y
6862 && to_y
< it
->current_y
+ line_height
)
6864 if (skip
== MOVE_X_REACHED
)
6865 /* If TO_Y is in this line and TO_X was reached above,
6866 we scanned too far. We have to restore IT's settings
6867 to the ones before skipping. */
6871 else if (skip
== MOVE_X_REACHED
)
6874 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6881 else if (BUFFERP (it
->object
)
6882 && it
->method
== GET_FROM_BUFFER
6883 && IT_CHARPOS (*it
) >= to_charpos
)
6884 skip
= MOVE_POS_MATCH_OR_ZV
;
6886 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6890 case MOVE_POS_MATCH_OR_ZV
:
6894 case MOVE_NEWLINE_OR_CR
:
6895 set_iterator_to_next (it
, 1);
6896 it
->continuation_lines_width
= 0;
6899 case MOVE_LINE_TRUNCATED
:
6900 it
->continuation_lines_width
= 0;
6901 reseat_at_next_visible_line_start (it
, 0);
6902 if ((op
& MOVE_TO_POS
) != 0
6903 && IT_CHARPOS (*it
) > to_charpos
)
6910 case MOVE_LINE_CONTINUED
:
6911 /* For continued lines ending in a tab, some of the glyphs
6912 associated with the tab are displayed on the current
6913 line. Since it->current_x does not include these glyphs,
6914 we use it->last_visible_x instead. */
6915 it
->continuation_lines_width
+=
6916 (it
->c
== '\t') ? it
->last_visible_x
: it
->current_x
;
6923 /* Reset/increment for the next run. */
6924 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6925 it
->current_x
= it
->hpos
= 0;
6926 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6928 last_height
= it
->max_ascent
+ it
->max_descent
;
6929 last_max_ascent
= it
->max_ascent
;
6930 it
->max_ascent
= it
->max_descent
= 0;
6935 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6939 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6941 If DY > 0, move IT backward at least that many pixels. DY = 0
6942 means move IT backward to the preceding line start or BEGV. This
6943 function may move over more than DY pixels if IT->current_y - DY
6944 ends up in the middle of a line; in this case IT->current_y will be
6945 set to the top of the line moved to. */
6948 move_it_vertically_backward (it
, dy
)
6959 start_pos
= IT_CHARPOS (*it
);
6961 /* Estimate how many newlines we must move back. */
6962 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6964 /* Set the iterator's position that many lines back. */
6965 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6966 back_to_previous_visible_line_start (it
);
6968 /* Reseat the iterator here. When moving backward, we don't want
6969 reseat to skip forward over invisible text, set up the iterator
6970 to deliver from overlay strings at the new position etc. So,
6971 use reseat_1 here. */
6972 reseat_1 (it
, it
->current
.pos
, 1);
6974 /* We are now surely at a line start. */
6975 it
->current_x
= it
->hpos
= 0;
6976 it
->continuation_lines_width
= 0;
6978 /* Move forward and see what y-distance we moved. First move to the
6979 start of the next line so that we get its height. We need this
6980 height to be able to tell whether we reached the specified
6983 it2
.max_ascent
= it2
.max_descent
= 0;
6986 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6987 MOVE_TO_POS
| MOVE_TO_VPOS
);
6989 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
6990 xassert (IT_CHARPOS (*it
) >= BEGV
);
6993 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6994 xassert (IT_CHARPOS (*it
) >= BEGV
);
6995 /* H is the actual vertical distance from the position in *IT
6996 and the starting position. */
6997 h
= it2
.current_y
- it
->current_y
;
6998 /* NLINES is the distance in number of lines. */
6999 nlines
= it2
.vpos
- it
->vpos
;
7001 /* Correct IT's y and vpos position
7002 so that they are relative to the starting point. */
7008 /* DY == 0 means move to the start of the screen line. The
7009 value of nlines is > 0 if continuation lines were involved. */
7011 move_it_by_lines (it
, nlines
, 1);
7013 /* I think this assert is bogus if buffer contains
7014 invisible text or images. KFS. */
7015 xassert (IT_CHARPOS (*it
) <= start_pos
);
7020 /* The y-position we try to reach, relative to *IT.
7021 Note that H has been subtracted in front of the if-statement. */
7022 int target_y
= it
->current_y
+ h
- dy
;
7023 int y0
= it3
.current_y
;
7024 int y1
= line_bottom_y (&it3
);
7025 int line_height
= y1
- y0
;
7027 /* If we did not reach target_y, try to move further backward if
7028 we can. If we moved too far backward, try to move forward. */
7029 if (target_y
< it
->current_y
7030 /* This is heuristic. In a window that's 3 lines high, with
7031 a line height of 13 pixels each, recentering with point
7032 on the bottom line will try to move -39/2 = 19 pixels
7033 backward. Try to avoid moving into the first line. */
7034 && (it
->current_y
- target_y
7035 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7036 && IT_CHARPOS (*it
) > BEGV
)
7038 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7039 target_y
- it
->current_y
));
7040 dy
= it
->current_y
- target_y
;
7041 goto move_further_back
;
7043 else if (target_y
>= it
->current_y
+ line_height
7044 && IT_CHARPOS (*it
) < ZV
)
7046 /* Should move forward by at least one line, maybe more.
7048 Note: Calling move_it_by_lines can be expensive on
7049 terminal frames, where compute_motion is used (via
7050 vmotion) to do the job, when there are very long lines
7051 and truncate-lines is nil. That's the reason for
7052 treating terminal frames specially here. */
7054 if (!FRAME_WINDOW_P (it
->f
))
7055 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7060 move_it_by_lines (it
, 1, 1);
7062 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7066 /* I think this assert is bogus if buffer contains
7067 invisible text or images. KFS. */
7068 xassert (IT_CHARPOS (*it
) >= BEGV
);
7075 /* Move IT by a specified amount of pixel lines DY. DY negative means
7076 move backwards. DY = 0 means move to start of screen line. At the
7077 end, IT will be on the start of a screen line. */
7080 move_it_vertically (it
, dy
)
7085 move_it_vertically_backward (it
, -dy
);
7088 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7089 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7090 MOVE_TO_POS
| MOVE_TO_Y
);
7091 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7093 /* If buffer ends in ZV without a newline, move to the start of
7094 the line to satisfy the post-condition. */
7095 if (IT_CHARPOS (*it
) == ZV
7097 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7098 move_it_by_lines (it
, 0, 0);
7103 /* Move iterator IT past the end of the text line it is in. */
7106 move_it_past_eol (it
)
7109 enum move_it_result rc
;
7111 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7112 if (rc
== MOVE_NEWLINE_OR_CR
)
7113 set_iterator_to_next (it
, 0);
7117 #if 0 /* Currently not used. */
7119 /* Return non-zero if some text between buffer positions START_CHARPOS
7120 and END_CHARPOS is invisible. IT->window is the window for text
7124 invisible_text_between_p (it
, start_charpos
, end_charpos
)
7126 int start_charpos
, end_charpos
;
7128 Lisp_Object prop
, limit
;
7129 int invisible_found_p
;
7131 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
7133 /* Is text at START invisible? */
7134 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
7136 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
7137 invisible_found_p
= 1;
7140 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
7142 make_number (end_charpos
));
7143 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
7146 return invisible_found_p
;
7152 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7153 negative means move up. DVPOS == 0 means move to the start of the
7154 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7155 NEED_Y_P is zero, IT->current_y will be left unchanged.
7157 Further optimization ideas: If we would know that IT->f doesn't use
7158 a face with proportional font, we could be faster for
7159 truncate-lines nil. */
7162 move_it_by_lines (it
, dvpos
, need_y_p
)
7164 int dvpos
, need_y_p
;
7166 struct position pos
;
7168 /* The commented-out optimization uses vmotion on terminals. This
7169 gives bad results, because elements like it->what, on which
7170 callers such as pos_visible_p rely, aren't updated. */
7171 /* if (!FRAME_WINDOW_P (it->f))
7173 struct text_pos textpos;
7175 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7176 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7177 reseat (it, textpos, 1);
7178 it->vpos += pos.vpos;
7179 it->current_y += pos.vpos;
7185 /* DVPOS == 0 means move to the start of the screen line. */
7186 move_it_vertically_backward (it
, 0);
7187 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7188 /* Let next call to line_bottom_y calculate real line height */
7193 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7194 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7195 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7200 int start_charpos
, i
;
7202 /* Start at the beginning of the screen line containing IT's
7203 position. This may actually move vertically backwards,
7204 in case of overlays, so adjust dvpos accordingly. */
7206 move_it_vertically_backward (it
, 0);
7209 /* Go back -DVPOS visible lines and reseat the iterator there. */
7210 start_charpos
= IT_CHARPOS (*it
);
7211 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7212 back_to_previous_visible_line_start (it
);
7213 reseat (it
, it
->current
.pos
, 1);
7215 /* Move further back if we end up in a string or an image. */
7216 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7218 /* First try to move to start of display line. */
7220 move_it_vertically_backward (it
, 0);
7222 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7224 /* If start of line is still in string or image,
7225 move further back. */
7226 back_to_previous_visible_line_start (it
);
7227 reseat (it
, it
->current
.pos
, 1);
7231 it
->current_x
= it
->hpos
= 0;
7233 /* Above call may have moved too far if continuation lines
7234 are involved. Scan forward and see if it did. */
7236 it2
.vpos
= it2
.current_y
= 0;
7237 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7238 it
->vpos
-= it2
.vpos
;
7239 it
->current_y
-= it2
.current_y
;
7240 it
->current_x
= it
->hpos
= 0;
7242 /* If we moved too far back, move IT some lines forward. */
7243 if (it2
.vpos
> -dvpos
)
7245 int delta
= it2
.vpos
+ dvpos
;
7247 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7248 /* Move back again if we got too far ahead. */
7249 if (IT_CHARPOS (*it
) >= start_charpos
)
7255 /* Return 1 if IT points into the middle of a display vector. */
7258 in_display_vector_p (it
)
7261 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7262 && it
->current
.dpvec_index
> 0
7263 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7267 /***********************************************************************
7269 ***********************************************************************/
7272 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7276 add_to_log (format
, arg1
, arg2
)
7278 Lisp_Object arg1
, arg2
;
7280 Lisp_Object args
[3];
7281 Lisp_Object msg
, fmt
;
7284 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7287 /* Do nothing if called asynchronously. Inserting text into
7288 a buffer may call after-change-functions and alike and
7289 that would means running Lisp asynchronously. */
7290 if (handling_signal
)
7294 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7296 args
[0] = fmt
= build_string (format
);
7299 msg
= Fformat (3, args
);
7301 len
= SBYTES (msg
) + 1;
7302 SAFE_ALLOCA (buffer
, char *, len
);
7303 bcopy (SDATA (msg
), buffer
, len
);
7305 message_dolog (buffer
, len
- 1, 1, 0);
7312 /* Output a newline in the *Messages* buffer if "needs" one. */
7315 message_log_maybe_newline ()
7317 if (message_log_need_newline
)
7318 message_dolog ("", 0, 1, 0);
7322 /* Add a string M of length NBYTES to the message log, optionally
7323 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7324 nonzero, means interpret the contents of M as multibyte. This
7325 function calls low-level routines in order to bypass text property
7326 hooks, etc. which might not be safe to run.
7328 This may GC (insert may run before/after change hooks),
7329 so the buffer M must NOT point to a Lisp string. */
7332 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7334 int nbytes
, nlflag
, multibyte
;
7336 if (!NILP (Vmemory_full
))
7339 if (!NILP (Vmessage_log_max
))
7341 struct buffer
*oldbuf
;
7342 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7343 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7344 int point_at_end
= 0;
7346 Lisp_Object old_deactivate_mark
, tem
;
7347 struct gcpro gcpro1
;
7349 old_deactivate_mark
= Vdeactivate_mark
;
7350 oldbuf
= current_buffer
;
7351 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7352 current_buffer
->undo_list
= Qt
;
7354 oldpoint
= message_dolog_marker1
;
7355 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7356 oldbegv
= message_dolog_marker2
;
7357 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7358 oldzv
= message_dolog_marker3
;
7359 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7360 GCPRO1 (old_deactivate_mark
);
7368 BEGV_BYTE
= BEG_BYTE
;
7371 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7373 /* Insert the string--maybe converting multibyte to single byte
7374 or vice versa, so that all the text fits the buffer. */
7376 && NILP (current_buffer
->enable_multibyte_characters
))
7378 int i
, c
, char_bytes
;
7379 unsigned char work
[1];
7381 /* Convert a multibyte string to single-byte
7382 for the *Message* buffer. */
7383 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7385 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7386 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7388 : multibyte_char_to_unibyte (c
, Qnil
));
7389 insert_1_both (work
, 1, 1, 1, 0, 0);
7392 else if (! multibyte
7393 && ! NILP (current_buffer
->enable_multibyte_characters
))
7395 int i
, c
, char_bytes
;
7396 unsigned char *msg
= (unsigned char *) m
;
7397 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7398 /* Convert a single-byte string to multibyte
7399 for the *Message* buffer. */
7400 for (i
= 0; i
< nbytes
; i
++)
7402 c
= unibyte_char_to_multibyte (msg
[i
]);
7403 char_bytes
= CHAR_STRING (c
, str
);
7404 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7408 insert_1 (m
, nbytes
, 1, 0, 0);
7412 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7413 insert_1 ("\n", 1, 1, 0, 0);
7415 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7417 this_bol_byte
= PT_BYTE
;
7419 /* See if this line duplicates the previous one.
7420 If so, combine duplicates. */
7423 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7425 prev_bol_byte
= PT_BYTE
;
7427 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7428 this_bol
, this_bol_byte
);
7431 del_range_both (prev_bol
, prev_bol_byte
,
7432 this_bol
, this_bol_byte
, 0);
7438 /* If you change this format, don't forget to also
7439 change message_log_check_duplicate. */
7440 sprintf (dupstr
, " [%d times]", dup
);
7441 duplen
= strlen (dupstr
);
7442 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7443 insert_1 (dupstr
, duplen
, 1, 0, 1);
7448 /* If we have more than the desired maximum number of lines
7449 in the *Messages* buffer now, delete the oldest ones.
7450 This is safe because we don't have undo in this buffer. */
7452 if (NATNUMP (Vmessage_log_max
))
7454 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7455 -XFASTINT (Vmessage_log_max
) - 1, 0);
7456 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7459 BEGV
= XMARKER (oldbegv
)->charpos
;
7460 BEGV_BYTE
= marker_byte_position (oldbegv
);
7469 ZV
= XMARKER (oldzv
)->charpos
;
7470 ZV_BYTE
= marker_byte_position (oldzv
);
7474 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7476 /* We can't do Fgoto_char (oldpoint) because it will run some
7478 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7479 XMARKER (oldpoint
)->bytepos
);
7482 unchain_marker (XMARKER (oldpoint
));
7483 unchain_marker (XMARKER (oldbegv
));
7484 unchain_marker (XMARKER (oldzv
));
7486 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7487 set_buffer_internal (oldbuf
);
7489 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7490 message_log_need_newline
= !nlflag
;
7491 Vdeactivate_mark
= old_deactivate_mark
;
7496 /* We are at the end of the buffer after just having inserted a newline.
7497 (Note: We depend on the fact we won't be crossing the gap.)
7498 Check to see if the most recent message looks a lot like the previous one.
7499 Return 0 if different, 1 if the new one should just replace it, or a
7500 value N > 1 if we should also append " [N times]". */
7503 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7504 int prev_bol
, this_bol
;
7505 int prev_bol_byte
, this_bol_byte
;
7508 int len
= Z_BYTE
- 1 - this_bol_byte
;
7510 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7511 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7513 for (i
= 0; i
< len
; i
++)
7515 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7523 if (*p1
++ == ' ' && *p1
++ == '[')
7526 while (*p1
>= '0' && *p1
<= '9')
7527 n
= n
* 10 + *p1
++ - '0';
7528 if (strncmp (p1
, " times]\n", 8) == 0)
7535 /* Display an echo area message M with a specified length of NBYTES
7536 bytes. The string may include null characters. If M is 0, clear
7537 out any existing message, and let the mini-buffer text show
7540 This may GC, so the buffer M must NOT point to a Lisp string. */
7543 message2 (m
, nbytes
, multibyte
)
7548 /* First flush out any partial line written with print. */
7549 message_log_maybe_newline ();
7551 message_dolog (m
, nbytes
, 1, multibyte
);
7552 message2_nolog (m
, nbytes
, multibyte
);
7556 /* The non-logging counterpart of message2. */
7559 message2_nolog (m
, nbytes
, multibyte
)
7561 int nbytes
, multibyte
;
7563 struct frame
*sf
= SELECTED_FRAME ();
7564 message_enable_multibyte
= multibyte
;
7568 if (noninteractive_need_newline
)
7569 putc ('\n', stderr
);
7570 noninteractive_need_newline
= 0;
7572 fwrite (m
, nbytes
, 1, stderr
);
7573 if (cursor_in_echo_area
== 0)
7574 fprintf (stderr
, "\n");
7577 /* A null message buffer means that the frame hasn't really been
7578 initialized yet. Error messages get reported properly by
7579 cmd_error, so this must be just an informative message; toss it. */
7580 else if (INTERACTIVE
7581 && sf
->glyphs_initialized_p
7582 && FRAME_MESSAGE_BUF (sf
))
7584 Lisp_Object mini_window
;
7587 /* Get the frame containing the mini-buffer
7588 that the selected frame is using. */
7589 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7590 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7592 FRAME_SAMPLE_VISIBILITY (f
);
7593 if (FRAME_VISIBLE_P (sf
)
7594 && ! FRAME_VISIBLE_P (f
))
7595 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7599 set_message (m
, Qnil
, nbytes
, multibyte
);
7600 if (minibuffer_auto_raise
)
7601 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7604 clear_message (1, 1);
7606 do_pending_window_change (0);
7607 echo_area_display (1);
7608 do_pending_window_change (0);
7609 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7610 (*frame_up_to_date_hook
) (f
);
7615 /* Display an echo area message M with a specified length of NBYTES
7616 bytes. The string may include null characters. If M is not a
7617 string, clear out any existing message, and let the mini-buffer
7620 This function cancels echoing. */
7623 message3 (m
, nbytes
, multibyte
)
7628 struct gcpro gcpro1
;
7631 clear_message (1,1);
7634 /* First flush out any partial line written with print. */
7635 message_log_maybe_newline ();
7641 SAFE_ALLOCA (buffer
, char *, nbytes
);
7642 bcopy (SDATA (m
), buffer
, nbytes
);
7643 message_dolog (buffer
, nbytes
, 1, multibyte
);
7646 message3_nolog (m
, nbytes
, multibyte
);
7652 /* The non-logging version of message3.
7653 This does not cancel echoing, because it is used for echoing.
7654 Perhaps we need to make a separate function for echoing
7655 and make this cancel echoing. */
7658 message3_nolog (m
, nbytes
, multibyte
)
7660 int nbytes
, multibyte
;
7662 struct frame
*sf
= SELECTED_FRAME ();
7663 message_enable_multibyte
= multibyte
;
7667 if (noninteractive_need_newline
)
7668 putc ('\n', stderr
);
7669 noninteractive_need_newline
= 0;
7671 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7672 if (cursor_in_echo_area
== 0)
7673 fprintf (stderr
, "\n");
7676 /* A null message buffer means that the frame hasn't really been
7677 initialized yet. Error messages get reported properly by
7678 cmd_error, so this must be just an informative message; toss it. */
7679 else if (INTERACTIVE
7680 && sf
->glyphs_initialized_p
7681 && FRAME_MESSAGE_BUF (sf
))
7683 Lisp_Object mini_window
;
7687 /* Get the frame containing the mini-buffer
7688 that the selected frame is using. */
7689 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7690 frame
= XWINDOW (mini_window
)->frame
;
7693 FRAME_SAMPLE_VISIBILITY (f
);
7694 if (FRAME_VISIBLE_P (sf
)
7695 && !FRAME_VISIBLE_P (f
))
7696 Fmake_frame_visible (frame
);
7698 if (STRINGP (m
) && SCHARS (m
) > 0)
7700 set_message (NULL
, m
, nbytes
, multibyte
);
7701 if (minibuffer_auto_raise
)
7702 Fraise_frame (frame
);
7703 /* Assume we are not echoing.
7704 (If we are, echo_now will override this.) */
7705 echo_message_buffer
= Qnil
;
7708 clear_message (1, 1);
7710 do_pending_window_change (0);
7711 echo_area_display (1);
7712 do_pending_window_change (0);
7713 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7714 (*frame_up_to_date_hook
) (f
);
7719 /* Display a null-terminated echo area message M. If M is 0, clear
7720 out any existing message, and let the mini-buffer text show through.
7722 The buffer M must continue to exist until after the echo area gets
7723 cleared or some other message gets displayed there. Do not pass
7724 text that is stored in a Lisp string. Do not pass text in a buffer
7725 that was alloca'd. */
7731 message2 (m
, (m
? strlen (m
) : 0), 0);
7735 /* The non-logging counterpart of message1. */
7741 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7744 /* Display a message M which contains a single %s
7745 which gets replaced with STRING. */
7748 message_with_string (m
, string
, log
)
7753 CHECK_STRING (string
);
7759 if (noninteractive_need_newline
)
7760 putc ('\n', stderr
);
7761 noninteractive_need_newline
= 0;
7762 fprintf (stderr
, m
, SDATA (string
));
7763 if (cursor_in_echo_area
== 0)
7764 fprintf (stderr
, "\n");
7768 else if (INTERACTIVE
)
7770 /* The frame whose minibuffer we're going to display the message on.
7771 It may be larger than the selected frame, so we need
7772 to use its buffer, not the selected frame's buffer. */
7773 Lisp_Object mini_window
;
7774 struct frame
*f
, *sf
= SELECTED_FRAME ();
7776 /* Get the frame containing the minibuffer
7777 that the selected frame is using. */
7778 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7779 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7781 /* A null message buffer means that the frame hasn't really been
7782 initialized yet. Error messages get reported properly by
7783 cmd_error, so this must be just an informative message; toss it. */
7784 if (FRAME_MESSAGE_BUF (f
))
7786 Lisp_Object args
[2], message
;
7787 struct gcpro gcpro1
, gcpro2
;
7789 args
[0] = build_string (m
);
7790 args
[1] = message
= string
;
7791 GCPRO2 (args
[0], message
);
7794 message
= Fformat (2, args
);
7797 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7799 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7803 /* Print should start at the beginning of the message
7804 buffer next time. */
7805 message_buf_print
= 0;
7811 /* Dump an informative message to the minibuf. If M is 0, clear out
7812 any existing message, and let the mini-buffer text show through. */
7816 message (m
, a1
, a2
, a3
)
7818 EMACS_INT a1
, a2
, a3
;
7824 if (noninteractive_need_newline
)
7825 putc ('\n', stderr
);
7826 noninteractive_need_newline
= 0;
7827 fprintf (stderr
, m
, a1
, a2
, a3
);
7828 if (cursor_in_echo_area
== 0)
7829 fprintf (stderr
, "\n");
7833 else if (INTERACTIVE
)
7835 /* The frame whose mini-buffer we're going to display the message
7836 on. It may be larger than the selected frame, so we need to
7837 use its buffer, not the selected frame's buffer. */
7838 Lisp_Object mini_window
;
7839 struct frame
*f
, *sf
= SELECTED_FRAME ();
7841 /* Get the frame containing the mini-buffer
7842 that the selected frame is using. */
7843 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7844 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7846 /* A null message buffer means that the frame hasn't really been
7847 initialized yet. Error messages get reported properly by
7848 cmd_error, so this must be just an informative message; toss
7850 if (FRAME_MESSAGE_BUF (f
))
7861 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7862 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7864 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7865 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7867 #endif /* NO_ARG_ARRAY */
7869 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7874 /* Print should start at the beginning of the message
7875 buffer next time. */
7876 message_buf_print
= 0;
7882 /* The non-logging version of message. */
7885 message_nolog (m
, a1
, a2
, a3
)
7887 EMACS_INT a1
, a2
, a3
;
7889 Lisp_Object old_log_max
;
7890 old_log_max
= Vmessage_log_max
;
7891 Vmessage_log_max
= Qnil
;
7892 message (m
, a1
, a2
, a3
);
7893 Vmessage_log_max
= old_log_max
;
7897 /* Display the current message in the current mini-buffer. This is
7898 only called from error handlers in process.c, and is not time
7904 if (!NILP (echo_area_buffer
[0]))
7907 string
= Fcurrent_message ();
7908 message3 (string
, SBYTES (string
),
7909 !NILP (current_buffer
->enable_multibyte_characters
));
7914 /* Make sure echo area buffers in `echo_buffers' are live.
7915 If they aren't, make new ones. */
7918 ensure_echo_area_buffers ()
7922 for (i
= 0; i
< 2; ++i
)
7923 if (!BUFFERP (echo_buffer
[i
])
7924 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7927 Lisp_Object old_buffer
;
7930 old_buffer
= echo_buffer
[i
];
7931 sprintf (name
, " *Echo Area %d*", i
);
7932 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7933 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7935 for (j
= 0; j
< 2; ++j
)
7936 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7937 echo_area_buffer
[j
] = echo_buffer
[i
];
7942 /* Call FN with args A1..A4 with either the current or last displayed
7943 echo_area_buffer as current buffer.
7945 WHICH zero means use the current message buffer
7946 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7947 from echo_buffer[] and clear it.
7949 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7950 suitable buffer from echo_buffer[] and clear it.
7952 Value is what FN returns. */
7955 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7958 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7964 int this_one
, the_other
, clear_buffer_p
, rc
;
7965 int count
= SPECPDL_INDEX ();
7967 /* If buffers aren't live, make new ones. */
7968 ensure_echo_area_buffers ();
7973 this_one
= 0, the_other
= 1;
7975 this_one
= 1, the_other
= 0;
7977 /* Choose a suitable buffer from echo_buffer[] is we don't
7979 if (NILP (echo_area_buffer
[this_one
]))
7981 echo_area_buffer
[this_one
]
7982 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7983 ? echo_buffer
[the_other
]
7984 : echo_buffer
[this_one
]);
7988 buffer
= echo_area_buffer
[this_one
];
7990 /* Don't get confused by reusing the buffer used for echoing
7991 for a different purpose. */
7992 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7995 record_unwind_protect (unwind_with_echo_area_buffer
,
7996 with_echo_area_buffer_unwind_data (w
));
7998 /* Make the echo area buffer current. Note that for display
7999 purposes, it is not necessary that the displayed window's buffer
8000 == current_buffer, except for text property lookup. So, let's
8001 only set that buffer temporarily here without doing a full
8002 Fset_window_buffer. We must also change w->pointm, though,
8003 because otherwise an assertions in unshow_buffer fails, and Emacs
8005 set_buffer_internal_1 (XBUFFER (buffer
));
8009 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8012 current_buffer
->undo_list
= Qt
;
8013 current_buffer
->read_only
= Qnil
;
8014 specbind (Qinhibit_read_only
, Qt
);
8015 specbind (Qinhibit_modification_hooks
, Qt
);
8017 if (clear_buffer_p
&& Z
> BEG
)
8020 xassert (BEGV
>= BEG
);
8021 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8023 rc
= fn (a1
, a2
, a3
, a4
);
8025 xassert (BEGV
>= BEG
);
8026 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8028 unbind_to (count
, Qnil
);
8033 /* Save state that should be preserved around the call to the function
8034 FN called in with_echo_area_buffer. */
8037 with_echo_area_buffer_unwind_data (w
)
8043 /* Reduce consing by keeping one vector in
8044 Vwith_echo_area_save_vector. */
8045 vector
= Vwith_echo_area_save_vector
;
8046 Vwith_echo_area_save_vector
= Qnil
;
8049 vector
= Fmake_vector (make_number (7), Qnil
);
8051 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
8052 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
8053 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
8057 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
8058 AREF (vector
, i
) = w
->buffer
; ++i
;
8059 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
8060 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
8065 for (; i
< end
; ++i
)
8066 AREF (vector
, i
) = Qnil
;
8069 xassert (i
== ASIZE (vector
));
8074 /* Restore global state from VECTOR which was created by
8075 with_echo_area_buffer_unwind_data. */
8078 unwind_with_echo_area_buffer (vector
)
8081 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8082 Vdeactivate_mark
= AREF (vector
, 1);
8083 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8085 if (WINDOWP (AREF (vector
, 3)))
8088 Lisp_Object buffer
, charpos
, bytepos
;
8090 w
= XWINDOW (AREF (vector
, 3));
8091 buffer
= AREF (vector
, 4);
8092 charpos
= AREF (vector
, 5);
8093 bytepos
= AREF (vector
, 6);
8096 set_marker_both (w
->pointm
, buffer
,
8097 XFASTINT (charpos
), XFASTINT (bytepos
));
8100 Vwith_echo_area_save_vector
= vector
;
8105 /* Set up the echo area for use by print functions. MULTIBYTE_P
8106 non-zero means we will print multibyte. */
8109 setup_echo_area_for_printing (multibyte_p
)
8112 /* If we can't find an echo area any more, exit. */
8113 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8116 ensure_echo_area_buffers ();
8118 if (!message_buf_print
)
8120 /* A message has been output since the last time we printed.
8121 Choose a fresh echo area buffer. */
8122 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8123 echo_area_buffer
[0] = echo_buffer
[1];
8125 echo_area_buffer
[0] = echo_buffer
[0];
8127 /* Switch to that buffer and clear it. */
8128 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8129 current_buffer
->truncate_lines
= Qnil
;
8133 int count
= SPECPDL_INDEX ();
8134 specbind (Qinhibit_read_only
, Qt
);
8135 /* Note that undo recording is always disabled. */
8137 unbind_to (count
, Qnil
);
8139 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8141 /* Set up the buffer for the multibyteness we need. */
8143 != !NILP (current_buffer
->enable_multibyte_characters
))
8144 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8146 /* Raise the frame containing the echo area. */
8147 if (minibuffer_auto_raise
)
8149 struct frame
*sf
= SELECTED_FRAME ();
8150 Lisp_Object mini_window
;
8151 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8152 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8155 message_log_maybe_newline ();
8156 message_buf_print
= 1;
8160 if (NILP (echo_area_buffer
[0]))
8162 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8163 echo_area_buffer
[0] = echo_buffer
[1];
8165 echo_area_buffer
[0] = echo_buffer
[0];
8168 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8170 /* Someone switched buffers between print requests. */
8171 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8172 current_buffer
->truncate_lines
= Qnil
;
8178 /* Display an echo area message in window W. Value is non-zero if W's
8179 height is changed. If display_last_displayed_message_p is
8180 non-zero, display the message that was last displayed, otherwise
8181 display the current message. */
8184 display_echo_area (w
)
8187 int i
, no_message_p
, window_height_changed_p
, count
;
8189 /* Temporarily disable garbage collections while displaying the echo
8190 area. This is done because a GC can print a message itself.
8191 That message would modify the echo area buffer's contents while a
8192 redisplay of the buffer is going on, and seriously confuse
8194 count
= inhibit_garbage_collection ();
8196 /* If there is no message, we must call display_echo_area_1
8197 nevertheless because it resizes the window. But we will have to
8198 reset the echo_area_buffer in question to nil at the end because
8199 with_echo_area_buffer will sets it to an empty buffer. */
8200 i
= display_last_displayed_message_p
? 1 : 0;
8201 no_message_p
= NILP (echo_area_buffer
[i
]);
8203 window_height_changed_p
8204 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8205 display_echo_area_1
,
8206 (EMACS_INT
) w
, Qnil
, 0, 0);
8209 echo_area_buffer
[i
] = Qnil
;
8211 unbind_to (count
, Qnil
);
8212 return window_height_changed_p
;
8216 /* Helper for display_echo_area. Display the current buffer which
8217 contains the current echo area message in window W, a mini-window,
8218 a pointer to which is passed in A1. A2..A4 are currently not used.
8219 Change the height of W so that all of the message is displayed.
8220 Value is non-zero if height of W was changed. */
8223 display_echo_area_1 (a1
, a2
, a3
, a4
)
8228 struct window
*w
= (struct window
*) a1
;
8230 struct text_pos start
;
8231 int window_height_changed_p
= 0;
8233 /* Do this before displaying, so that we have a large enough glyph
8234 matrix for the display. If we can't get enough space for the
8235 whole text, display the last N lines. That works by setting w->start. */
8236 window_height_changed_p
= resize_mini_window (w
, 0);
8238 /* Use the starting position chosen by resize_mini_window. */
8239 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8242 clear_glyph_matrix (w
->desired_matrix
);
8243 XSETWINDOW (window
, w
);
8244 try_window (window
, start
, 0);
8246 return window_height_changed_p
;
8250 /* Resize the echo area window to exactly the size needed for the
8251 currently displayed message, if there is one. If a mini-buffer
8252 is active, don't shrink it. */
8255 resize_echo_area_exactly ()
8257 if (BUFFERP (echo_area_buffer
[0])
8258 && WINDOWP (echo_area_window
))
8260 struct window
*w
= XWINDOW (echo_area_window
);
8262 Lisp_Object resize_exactly
;
8264 if (minibuf_level
== 0)
8265 resize_exactly
= Qt
;
8267 resize_exactly
= Qnil
;
8269 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8270 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8273 ++windows_or_buffers_changed
;
8274 ++update_mode_lines
;
8275 redisplay_internal (0);
8281 /* Callback function for with_echo_area_buffer, when used from
8282 resize_echo_area_exactly. A1 contains a pointer to the window to
8283 resize, EXACTLY non-nil means resize the mini-window exactly to the
8284 size of the text displayed. A3 and A4 are not used. Value is what
8285 resize_mini_window returns. */
8288 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8290 Lisp_Object exactly
;
8293 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8297 /* Resize mini-window W to fit the size of its contents. EXACT_P
8298 means size the window exactly to the size needed. Otherwise, it's
8299 only enlarged until W's buffer is empty.
8301 Set W->start to the right place to begin display. If the whole
8302 contents fit, start at the beginning. Otherwise, start so as
8303 to make the end of the contents appear. This is particularly
8304 important for y-or-n-p, but seems desirable generally.
8306 Value is non-zero if the window height has been changed. */
8309 resize_mini_window (w
, exact_p
)
8313 struct frame
*f
= XFRAME (w
->frame
);
8314 int window_height_changed_p
= 0;
8316 xassert (MINI_WINDOW_P (w
));
8318 /* By default, start display at the beginning. */
8319 set_marker_both (w
->start
, w
->buffer
,
8320 BUF_BEGV (XBUFFER (w
->buffer
)),
8321 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8323 /* Don't resize windows while redisplaying a window; it would
8324 confuse redisplay functions when the size of the window they are
8325 displaying changes from under them. Such a resizing can happen,
8326 for instance, when which-func prints a long message while
8327 we are running fontification-functions. We're running these
8328 functions with safe_call which binds inhibit-redisplay to t. */
8329 if (!NILP (Vinhibit_redisplay
))
8332 /* Nil means don't try to resize. */
8333 if (NILP (Vresize_mini_windows
)
8334 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8337 if (!FRAME_MINIBUF_ONLY_P (f
))
8340 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8341 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8342 int height
, max_height
;
8343 int unit
= FRAME_LINE_HEIGHT (f
);
8344 struct text_pos start
;
8345 struct buffer
*old_current_buffer
= NULL
;
8347 if (current_buffer
!= XBUFFER (w
->buffer
))
8349 old_current_buffer
= current_buffer
;
8350 set_buffer_internal (XBUFFER (w
->buffer
));
8353 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8355 /* Compute the max. number of lines specified by the user. */
8356 if (FLOATP (Vmax_mini_window_height
))
8357 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8358 else if (INTEGERP (Vmax_mini_window_height
))
8359 max_height
= XINT (Vmax_mini_window_height
);
8361 max_height
= total_height
/ 4;
8363 /* Correct that max. height if it's bogus. */
8364 max_height
= max (1, max_height
);
8365 max_height
= min (total_height
, max_height
);
8367 /* Find out the height of the text in the window. */
8368 if (it
.truncate_lines_p
)
8373 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8374 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8375 height
= it
.current_y
+ last_height
;
8377 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8378 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8379 height
= (height
+ unit
- 1) / unit
;
8382 /* Compute a suitable window start. */
8383 if (height
> max_height
)
8385 height
= max_height
;
8386 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8387 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8388 start
= it
.current
.pos
;
8391 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8392 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8394 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8396 /* Let it grow only, until we display an empty message, in which
8397 case the window shrinks again. */
8398 if (height
> WINDOW_TOTAL_LINES (w
))
8400 int old_height
= WINDOW_TOTAL_LINES (w
);
8401 freeze_window_starts (f
, 1);
8402 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8403 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8405 else if (height
< WINDOW_TOTAL_LINES (w
)
8406 && (exact_p
|| BEGV
== ZV
))
8408 int old_height
= WINDOW_TOTAL_LINES (w
);
8409 freeze_window_starts (f
, 0);
8410 shrink_mini_window (w
);
8411 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8416 /* Always resize to exact size needed. */
8417 if (height
> WINDOW_TOTAL_LINES (w
))
8419 int old_height
= WINDOW_TOTAL_LINES (w
);
8420 freeze_window_starts (f
, 1);
8421 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8422 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8424 else if (height
< WINDOW_TOTAL_LINES (w
))
8426 int old_height
= WINDOW_TOTAL_LINES (w
);
8427 freeze_window_starts (f
, 0);
8428 shrink_mini_window (w
);
8432 freeze_window_starts (f
, 1);
8433 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8436 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8440 if (old_current_buffer
)
8441 set_buffer_internal (old_current_buffer
);
8444 return window_height_changed_p
;
8448 /* Value is the current message, a string, or nil if there is no
8456 if (NILP (echo_area_buffer
[0]))
8460 with_echo_area_buffer (0, 0, current_message_1
,
8461 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8463 echo_area_buffer
[0] = Qnil
;
8471 current_message_1 (a1
, a2
, a3
, a4
)
8476 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8479 *msg
= make_buffer_string (BEG
, Z
, 1);
8486 /* Push the current message on Vmessage_stack for later restauration
8487 by restore_message. Value is non-zero if the current message isn't
8488 empty. This is a relatively infrequent operation, so it's not
8489 worth optimizing. */
8495 msg
= current_message ();
8496 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8497 return STRINGP (msg
);
8501 /* Restore message display from the top of Vmessage_stack. */
8508 xassert (CONSP (Vmessage_stack
));
8509 msg
= XCAR (Vmessage_stack
);
8511 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8513 message3_nolog (msg
, 0, 0);
8517 /* Handler for record_unwind_protect calling pop_message. */
8520 pop_message_unwind (dummy
)
8527 /* Pop the top-most entry off Vmessage_stack. */
8532 xassert (CONSP (Vmessage_stack
));
8533 Vmessage_stack
= XCDR (Vmessage_stack
);
8537 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8538 exits. If the stack is not empty, we have a missing pop_message
8542 check_message_stack ()
8544 if (!NILP (Vmessage_stack
))
8549 /* Truncate to NCHARS what will be displayed in the echo area the next
8550 time we display it---but don't redisplay it now. */
8553 truncate_echo_area (nchars
)
8557 echo_area_buffer
[0] = Qnil
;
8558 /* A null message buffer means that the frame hasn't really been
8559 initialized yet. Error messages get reported properly by
8560 cmd_error, so this must be just an informative message; toss it. */
8561 else if (!noninteractive
8563 && !NILP (echo_area_buffer
[0]))
8565 struct frame
*sf
= SELECTED_FRAME ();
8566 if (FRAME_MESSAGE_BUF (sf
))
8567 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8572 /* Helper function for truncate_echo_area. Truncate the current
8573 message to at most NCHARS characters. */
8576 truncate_message_1 (nchars
, a2
, a3
, a4
)
8581 if (BEG
+ nchars
< Z
)
8582 del_range (BEG
+ nchars
, Z
);
8584 echo_area_buffer
[0] = Qnil
;
8589 /* Set the current message to a substring of S or STRING.
8591 If STRING is a Lisp string, set the message to the first NBYTES
8592 bytes from STRING. NBYTES zero means use the whole string. If
8593 STRING is multibyte, the message will be displayed multibyte.
8595 If S is not null, set the message to the first LEN bytes of S. LEN
8596 zero means use the whole string. MULTIBYTE_P non-zero means S is
8597 multibyte. Display the message multibyte in that case.
8599 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8600 to t before calling set_message_1 (which calls insert).
8604 set_message (s
, string
, nbytes
, multibyte_p
)
8607 int nbytes
, multibyte_p
;
8609 message_enable_multibyte
8610 = ((s
&& multibyte_p
)
8611 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8613 with_echo_area_buffer (0, 0, set_message_1
,
8614 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8615 message_buf_print
= 0;
8616 help_echo_showing_p
= 0;
8620 /* Helper function for set_message. Arguments have the same meaning
8621 as there, with A1 corresponding to S and A2 corresponding to STRING
8622 This function is called with the echo area buffer being
8626 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8629 EMACS_INT nbytes
, multibyte_p
;
8631 const char *s
= (const char *) a1
;
8632 Lisp_Object string
= a2
;
8634 /* Change multibyteness of the echo buffer appropriately. */
8635 if (message_enable_multibyte
8636 != !NILP (current_buffer
->enable_multibyte_characters
))
8637 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8639 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8641 /* Insert new message at BEG. */
8642 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8645 if (STRINGP (string
))
8650 nbytes
= SBYTES (string
);
8651 nchars
= string_byte_to_char (string
, nbytes
);
8653 /* This function takes care of single/multibyte conversion. We
8654 just have to ensure that the echo area buffer has the right
8655 setting of enable_multibyte_characters. */
8656 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8661 nbytes
= strlen (s
);
8663 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8665 /* Convert from multi-byte to single-byte. */
8667 unsigned char work
[1];
8669 /* Convert a multibyte string to single-byte. */
8670 for (i
= 0; i
< nbytes
; i
+= n
)
8672 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8673 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
8675 : multibyte_char_to_unibyte (c
, Qnil
));
8676 insert_1_both (work
, 1, 1, 1, 0, 0);
8679 else if (!multibyte_p
8680 && !NILP (current_buffer
->enable_multibyte_characters
))
8682 /* Convert from single-byte to multi-byte. */
8684 const unsigned char *msg
= (const unsigned char *) s
;
8685 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8687 /* Convert a single-byte string to multibyte. */
8688 for (i
= 0; i
< nbytes
; i
++)
8690 c
= unibyte_char_to_multibyte (msg
[i
]);
8691 n
= CHAR_STRING (c
, str
);
8692 insert_1_both (str
, 1, n
, 1, 0, 0);
8696 insert_1 (s
, nbytes
, 1, 0, 0);
8703 /* Clear messages. CURRENT_P non-zero means clear the current
8704 message. LAST_DISPLAYED_P non-zero means clear the message
8708 clear_message (current_p
, last_displayed_p
)
8709 int current_p
, last_displayed_p
;
8713 echo_area_buffer
[0] = Qnil
;
8714 message_cleared_p
= 1;
8717 if (last_displayed_p
)
8718 echo_area_buffer
[1] = Qnil
;
8720 message_buf_print
= 0;
8723 /* Clear garbaged frames.
8725 This function is used where the old redisplay called
8726 redraw_garbaged_frames which in turn called redraw_frame which in
8727 turn called clear_frame. The call to clear_frame was a source of
8728 flickering. I believe a clear_frame is not necessary. It should
8729 suffice in the new redisplay to invalidate all current matrices,
8730 and ensure a complete redisplay of all windows. */
8733 clear_garbaged_frames ()
8737 Lisp_Object tail
, frame
;
8738 int changed_count
= 0;
8740 FOR_EACH_FRAME (tail
, frame
)
8742 struct frame
*f
= XFRAME (frame
);
8744 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8748 Fredraw_frame (frame
);
8749 f
->force_flush_display_p
= 1;
8751 clear_current_matrices (f
);
8760 ++windows_or_buffers_changed
;
8765 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8766 is non-zero update selected_frame. Value is non-zero if the
8767 mini-windows height has been changed. */
8770 echo_area_display (update_frame_p
)
8773 Lisp_Object mini_window
;
8776 int window_height_changed_p
= 0;
8777 struct frame
*sf
= SELECTED_FRAME ();
8779 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8780 w
= XWINDOW (mini_window
);
8781 f
= XFRAME (WINDOW_FRAME (w
));
8783 /* Don't display if frame is invisible or not yet initialized. */
8784 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8787 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8789 #ifdef HAVE_WINDOW_SYSTEM
8790 /* When Emacs starts, selected_frame may be a visible terminal
8791 frame, even if we run under a window system. If we let this
8792 through, a message would be displayed on the terminal. */
8793 if (EQ (selected_frame
, Vterminal_frame
)
8794 && !NILP (Vwindow_system
))
8796 #endif /* HAVE_WINDOW_SYSTEM */
8799 /* Redraw garbaged frames. */
8801 clear_garbaged_frames ();
8803 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8805 echo_area_window
= mini_window
;
8806 window_height_changed_p
= display_echo_area (w
);
8807 w
->must_be_updated_p
= 1;
8809 /* Update the display, unless called from redisplay_internal.
8810 Also don't update the screen during redisplay itself. The
8811 update will happen at the end of redisplay, and an update
8812 here could cause confusion. */
8813 if (update_frame_p
&& !redisplaying_p
)
8817 /* If the display update has been interrupted by pending
8818 input, update mode lines in the frame. Due to the
8819 pending input, it might have been that redisplay hasn't
8820 been called, so that mode lines above the echo area are
8821 garbaged. This looks odd, so we prevent it here. */
8822 if (!display_completed
)
8823 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8825 if (window_height_changed_p
8826 /* Don't do this if Emacs is shutting down. Redisplay
8827 needs to run hooks. */
8828 && !NILP (Vrun_hooks
))
8830 /* Must update other windows. Likewise as in other
8831 cases, don't let this update be interrupted by
8833 int count
= SPECPDL_INDEX ();
8834 specbind (Qredisplay_dont_pause
, Qt
);
8835 windows_or_buffers_changed
= 1;
8836 redisplay_internal (0);
8837 unbind_to (count
, Qnil
);
8839 else if (FRAME_WINDOW_P (f
) && n
== 0)
8841 /* Window configuration is the same as before.
8842 Can do with a display update of the echo area,
8843 unless we displayed some mode lines. */
8844 update_single_window (w
, 1);
8845 rif
->flush_display (f
);
8848 update_frame (f
, 1, 1);
8850 /* If cursor is in the echo area, make sure that the next
8851 redisplay displays the minibuffer, so that the cursor will
8852 be replaced with what the minibuffer wants. */
8853 if (cursor_in_echo_area
)
8854 ++windows_or_buffers_changed
;
8857 else if (!EQ (mini_window
, selected_window
))
8858 windows_or_buffers_changed
++;
8860 /* The current message is now also the last one displayed. */
8861 echo_area_buffer
[1] = echo_area_buffer
[0];
8863 /* Prevent redisplay optimization in redisplay_internal by resetting
8864 this_line_start_pos. This is done because the mini-buffer now
8865 displays the message instead of its buffer text. */
8866 if (EQ (mini_window
, selected_window
))
8867 CHARPOS (this_line_start_pos
) = 0;
8869 return window_height_changed_p
;
8874 /***********************************************************************
8875 Mode Lines and Frame Titles
8876 ***********************************************************************/
8878 /* A buffer for constructing non-propertized mode-line strings and
8879 frame titles in it; allocated from the heap in init_xdisp and
8880 resized as needed in store_mode_line_noprop_char. */
8882 static char *mode_line_noprop_buf
;
8884 /* The buffer's end, and a current output position in it. */
8886 static char *mode_line_noprop_buf_end
;
8887 static char *mode_line_noprop_ptr
;
8889 #define MODE_LINE_NOPROP_LEN(start) \
8890 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8893 MODE_LINE_DISPLAY
= 0,
8899 /* Alist that caches the results of :propertize.
8900 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8901 static Lisp_Object mode_line_proptrans_alist
;
8903 /* List of strings making up the mode-line. */
8904 static Lisp_Object mode_line_string_list
;
8906 /* Base face property when building propertized mode line string. */
8907 static Lisp_Object mode_line_string_face
;
8908 static Lisp_Object mode_line_string_face_prop
;
8911 /* Unwind data for mode line strings */
8913 static Lisp_Object Vmode_line_unwind_vector
;
8916 format_mode_line_unwind_data (obuf
, save_proptrans
)
8917 struct buffer
*obuf
;
8921 /* Reduce consing by keeping one vector in
8922 Vwith_echo_area_save_vector. */
8923 vector
= Vmode_line_unwind_vector
;
8924 Vmode_line_unwind_vector
= Qnil
;
8927 vector
= Fmake_vector (make_number (7), Qnil
);
8929 AREF (vector
, 0) = make_number (mode_line_target
);
8930 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8931 AREF (vector
, 2) = mode_line_string_list
;
8932 AREF (vector
, 3) = (save_proptrans
? mode_line_proptrans_alist
: Qt
);
8933 AREF (vector
, 4) = mode_line_string_face
;
8934 AREF (vector
, 5) = mode_line_string_face_prop
;
8937 XSETBUFFER (AREF (vector
, 6), obuf
);
8939 AREF (vector
, 6) = Qnil
;
8945 unwind_format_mode_line (vector
)
8948 mode_line_target
= XINT (AREF (vector
, 0));
8949 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8950 mode_line_string_list
= AREF (vector
, 2);
8951 if (! EQ (AREF (vector
, 3), Qt
))
8952 mode_line_proptrans_alist
= AREF (vector
, 3);
8953 mode_line_string_face
= AREF (vector
, 4);
8954 mode_line_string_face_prop
= AREF (vector
, 5);
8956 if (!NILP (AREF (vector
, 6)))
8958 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8959 AREF (vector
, 6) = Qnil
;
8962 Vmode_line_unwind_vector
= vector
;
8967 /* Store a single character C for the frame title in mode_line_noprop_buf.
8968 Re-allocate mode_line_noprop_buf if necessary. */
8972 store_mode_line_noprop_char (char c
)
8974 store_mode_line_noprop_char (c
)
8978 /* If output position has reached the end of the allocated buffer,
8979 double the buffer's size. */
8980 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8982 int len
= MODE_LINE_NOPROP_LEN (0);
8983 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8984 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8985 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8986 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8989 *mode_line_noprop_ptr
++ = c
;
8993 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8994 mode_line_noprop_ptr. STR is the string to store. Do not copy
8995 characters that yield more columns than PRECISION; PRECISION <= 0
8996 means copy the whole string. Pad with spaces until FIELD_WIDTH
8997 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8998 pad. Called from display_mode_element when it is used to build a
9002 store_mode_line_noprop (str
, field_width
, precision
)
9003 const unsigned char *str
;
9004 int field_width
, precision
;
9009 /* Copy at most PRECISION chars from STR. */
9010 nbytes
= strlen (str
);
9011 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9013 store_mode_line_noprop_char (*str
++);
9015 /* Fill up with spaces until FIELD_WIDTH reached. */
9016 while (field_width
> 0
9019 store_mode_line_noprop_char (' ');
9026 /***********************************************************************
9028 ***********************************************************************/
9030 #ifdef HAVE_WINDOW_SYSTEM
9032 /* Set the title of FRAME, if it has changed. The title format is
9033 Vicon_title_format if FRAME is iconified, otherwise it is
9034 frame_title_format. */
9037 x_consider_frame_title (frame
)
9040 struct frame
*f
= XFRAME (frame
);
9042 if (FRAME_WINDOW_P (f
)
9043 || FRAME_MINIBUF_ONLY_P (f
)
9044 || f
->explicit_name
)
9046 /* Do we have more than one visible frame on this X display? */
9053 int count
= SPECPDL_INDEX ();
9055 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9057 Lisp_Object other_frame
= XCAR (tail
);
9058 struct frame
*tf
= XFRAME (other_frame
);
9061 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9062 && !FRAME_MINIBUF_ONLY_P (tf
)
9063 && !EQ (other_frame
, tip_frame
)
9064 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9068 /* Set global variable indicating that multiple frames exist. */
9069 multiple_frames
= CONSP (tail
);
9071 /* Switch to the buffer of selected window of the frame. Set up
9072 mode_line_target so that display_mode_element will output into
9073 mode_line_noprop_buf; then display the title. */
9074 record_unwind_protect (unwind_format_mode_line
,
9075 format_mode_line_unwind_data (current_buffer
, 0));
9077 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9078 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9080 mode_line_target
= MODE_LINE_TITLE
;
9081 title_start
= MODE_LINE_NOPROP_LEN (0);
9082 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9083 NULL
, DEFAULT_FACE_ID
);
9084 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9085 len
= MODE_LINE_NOPROP_LEN (title_start
);
9086 title
= mode_line_noprop_buf
+ title_start
;
9087 unbind_to (count
, Qnil
);
9089 /* Set the title only if it's changed. This avoids consing in
9090 the common case where it hasn't. (If it turns out that we've
9091 already wasted too much time by walking through the list with
9092 display_mode_element, then we might need to optimize at a
9093 higher level than this.) */
9094 if (! STRINGP (f
->name
)
9095 || SBYTES (f
->name
) != len
9096 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9097 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9101 #endif /* not HAVE_WINDOW_SYSTEM */
9106 /***********************************************************************
9108 ***********************************************************************/
9111 /* Prepare for redisplay by updating menu-bar item lists when
9112 appropriate. This can call eval. */
9115 prepare_menu_bars ()
9118 struct gcpro gcpro1
, gcpro2
;
9120 Lisp_Object tooltip_frame
;
9122 #ifdef HAVE_WINDOW_SYSTEM
9123 tooltip_frame
= tip_frame
;
9125 tooltip_frame
= Qnil
;
9128 /* Update all frame titles based on their buffer names, etc. We do
9129 this before the menu bars so that the buffer-menu will show the
9130 up-to-date frame titles. */
9131 #ifdef HAVE_WINDOW_SYSTEM
9132 if (windows_or_buffers_changed
|| update_mode_lines
)
9134 Lisp_Object tail
, frame
;
9136 FOR_EACH_FRAME (tail
, frame
)
9139 if (!EQ (frame
, tooltip_frame
)
9140 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9141 x_consider_frame_title (frame
);
9144 #endif /* HAVE_WINDOW_SYSTEM */
9146 /* Update the menu bar item lists, if appropriate. This has to be
9147 done before any actual redisplay or generation of display lines. */
9148 all_windows
= (update_mode_lines
9149 || buffer_shared
> 1
9150 || windows_or_buffers_changed
);
9153 Lisp_Object tail
, frame
;
9154 int count
= SPECPDL_INDEX ();
9155 /* 1 means that update_menu_bar has run its hooks
9156 so any further calls to update_menu_bar shouldn't do so again. */
9157 int menu_bar_hooks_run
= 0;
9159 record_unwind_save_match_data ();
9161 FOR_EACH_FRAME (tail
, frame
)
9165 /* Ignore tooltip frame. */
9166 if (EQ (frame
, tooltip_frame
))
9169 /* If a window on this frame changed size, report that to
9170 the user and clear the size-change flag. */
9171 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9173 Lisp_Object functions
;
9175 /* Clear flag first in case we get an error below. */
9176 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9177 functions
= Vwindow_size_change_functions
;
9178 GCPRO2 (tail
, functions
);
9180 while (CONSP (functions
))
9182 call1 (XCAR (functions
), frame
);
9183 functions
= XCDR (functions
);
9189 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9190 #ifdef HAVE_WINDOW_SYSTEM
9191 update_tool_bar (f
, 0);
9193 mac_update_title_bar (f
, 0);
9199 unbind_to (count
, Qnil
);
9203 struct frame
*sf
= SELECTED_FRAME ();
9204 update_menu_bar (sf
, 1, 0);
9205 #ifdef HAVE_WINDOW_SYSTEM
9206 update_tool_bar (sf
, 1);
9208 mac_update_title_bar (sf
, 1);
9213 /* Motif needs this. See comment in xmenu.c. Turn it off when
9214 pending_menu_activation is not defined. */
9215 #ifdef USE_X_TOOLKIT
9216 pending_menu_activation
= 0;
9221 /* Update the menu bar item list for frame F. This has to be done
9222 before we start to fill in any display lines, because it can call
9225 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9227 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9228 already ran the menu bar hooks for this redisplay, so there
9229 is no need to run them again. The return value is the
9230 updated value of this flag, to pass to the next call. */
9233 update_menu_bar (f
, save_match_data
, hooks_run
)
9235 int save_match_data
;
9239 register struct window
*w
;
9241 /* If called recursively during a menu update, do nothing. This can
9242 happen when, for instance, an activate-menubar-hook causes a
9244 if (inhibit_menubar_update
)
9247 window
= FRAME_SELECTED_WINDOW (f
);
9248 w
= XWINDOW (window
);
9250 #if 0 /* The if statement below this if statement used to include the
9251 condition !NILP (w->update_mode_line), rather than using
9252 update_mode_lines directly, and this if statement may have
9253 been added to make that condition work. Now the if
9254 statement below matches its comment, this isn't needed. */
9255 if (update_mode_lines
)
9256 w
->update_mode_line
= Qt
;
9259 if (FRAME_WINDOW_P (f
)
9261 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9262 || defined (USE_GTK)
9263 FRAME_EXTERNAL_MENU_BAR (f
)
9265 FRAME_MENU_BAR_LINES (f
) > 0
9267 : FRAME_MENU_BAR_LINES (f
) > 0)
9269 /* If the user has switched buffers or windows, we need to
9270 recompute to reflect the new bindings. But we'll
9271 recompute when update_mode_lines is set too; that means
9272 that people can use force-mode-line-update to request
9273 that the menu bar be recomputed. The adverse effect on
9274 the rest of the redisplay algorithm is about the same as
9275 windows_or_buffers_changed anyway. */
9276 if (windows_or_buffers_changed
9277 /* This used to test w->update_mode_line, but we believe
9278 there is no need to recompute the menu in that case. */
9279 || update_mode_lines
9280 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9281 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9282 != !NILP (w
->last_had_star
))
9283 || ((!NILP (Vtransient_mark_mode
)
9284 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9285 != !NILP (w
->region_showing
)))
9287 struct buffer
*prev
= current_buffer
;
9288 int count
= SPECPDL_INDEX ();
9290 specbind (Qinhibit_menubar_update
, Qt
);
9292 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9293 if (save_match_data
)
9294 record_unwind_save_match_data ();
9295 if (NILP (Voverriding_local_map_menu_flag
))
9297 specbind (Qoverriding_terminal_local_map
, Qnil
);
9298 specbind (Qoverriding_local_map
, Qnil
);
9303 /* Run the Lucid hook. */
9304 safe_run_hooks (Qactivate_menubar_hook
);
9306 /* If it has changed current-menubar from previous value,
9307 really recompute the menu-bar from the value. */
9308 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9309 call0 (Qrecompute_lucid_menubar
);
9311 safe_run_hooks (Qmenu_bar_update_hook
);
9316 XSETFRAME (Vmenu_updating_frame
, f
);
9317 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9319 /* Redisplay the menu bar in case we changed it. */
9320 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9321 || defined (USE_GTK)
9322 if (FRAME_WINDOW_P (f
))
9325 /* All frames on Mac OS share the same menubar. So only
9326 the selected frame should be allowed to set it. */
9327 if (f
== SELECTED_FRAME ())
9329 set_frame_menubar (f
, 0, 0);
9332 /* On a terminal screen, the menu bar is an ordinary screen
9333 line, and this makes it get updated. */
9334 w
->update_mode_line
= Qt
;
9335 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9336 /* In the non-toolkit version, the menu bar is an ordinary screen
9337 line, and this makes it get updated. */
9338 w
->update_mode_line
= Qt
;
9339 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9341 unbind_to (count
, Qnil
);
9342 set_buffer_internal_1 (prev
);
9351 /***********************************************************************
9353 ***********************************************************************/
9355 #ifdef HAVE_WINDOW_SYSTEM
9358 Nominal cursor position -- where to draw output.
9359 HPOS and VPOS are window relative glyph matrix coordinates.
9360 X and Y are window relative pixel coordinates. */
9362 struct cursor_pos output_cursor
;
9366 Set the global variable output_cursor to CURSOR. All cursor
9367 positions are relative to updated_window. */
9370 set_output_cursor (cursor
)
9371 struct cursor_pos
*cursor
;
9373 output_cursor
.hpos
= cursor
->hpos
;
9374 output_cursor
.vpos
= cursor
->vpos
;
9375 output_cursor
.x
= cursor
->x
;
9376 output_cursor
.y
= cursor
->y
;
9381 Set a nominal cursor position.
9383 HPOS and VPOS are column/row positions in a window glyph matrix. X
9384 and Y are window text area relative pixel positions.
9386 If this is done during an update, updated_window will contain the
9387 window that is being updated and the position is the future output
9388 cursor position for that window. If updated_window is null, use
9389 selected_window and display the cursor at the given position. */
9392 x_cursor_to (vpos
, hpos
, y
, x
)
9393 int vpos
, hpos
, y
, x
;
9397 /* If updated_window is not set, work on selected_window. */
9401 w
= XWINDOW (selected_window
);
9403 /* Set the output cursor. */
9404 output_cursor
.hpos
= hpos
;
9405 output_cursor
.vpos
= vpos
;
9406 output_cursor
.x
= x
;
9407 output_cursor
.y
= y
;
9409 /* If not called as part of an update, really display the cursor.
9410 This will also set the cursor position of W. */
9411 if (updated_window
== NULL
)
9414 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9415 if (rif
->flush_display_optional
)
9416 rif
->flush_display_optional (SELECTED_FRAME ());
9421 #endif /* HAVE_WINDOW_SYSTEM */
9424 /***********************************************************************
9426 ***********************************************************************/
9428 #ifdef HAVE_WINDOW_SYSTEM
9430 /* Where the mouse was last time we reported a mouse event. */
9432 FRAME_PTR last_mouse_frame
;
9434 /* Tool-bar item index of the item on which a mouse button was pressed
9437 int last_tool_bar_item
;
9440 /* Update the tool-bar item list for frame F. This has to be done
9441 before we start to fill in any display lines. Called from
9442 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9443 and restore it here. */
9446 update_tool_bar (f
, save_match_data
)
9448 int save_match_data
;
9450 #if defined (USE_GTK) || USE_MAC_TOOLBAR
9451 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9453 int do_update
= WINDOWP (f
->tool_bar_window
)
9454 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9462 window
= FRAME_SELECTED_WINDOW (f
);
9463 w
= XWINDOW (window
);
9465 /* If the user has switched buffers or windows, we need to
9466 recompute to reflect the new bindings. But we'll
9467 recompute when update_mode_lines is set too; that means
9468 that people can use force-mode-line-update to request
9469 that the menu bar be recomputed. The adverse effect on
9470 the rest of the redisplay algorithm is about the same as
9471 windows_or_buffers_changed anyway. */
9472 if (windows_or_buffers_changed
9473 || !NILP (w
->update_mode_line
)
9474 || update_mode_lines
9475 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9476 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9477 != !NILP (w
->last_had_star
))
9478 || ((!NILP (Vtransient_mark_mode
)
9479 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9480 != !NILP (w
->region_showing
)))
9482 struct buffer
*prev
= current_buffer
;
9483 int count
= SPECPDL_INDEX ();
9484 Lisp_Object new_tool_bar
;
9486 struct gcpro gcpro1
;
9488 /* Set current_buffer to the buffer of the selected
9489 window of the frame, so that we get the right local
9491 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9493 /* Save match data, if we must. */
9494 if (save_match_data
)
9495 record_unwind_save_match_data ();
9497 /* Make sure that we don't accidentally use bogus keymaps. */
9498 if (NILP (Voverriding_local_map_menu_flag
))
9500 specbind (Qoverriding_terminal_local_map
, Qnil
);
9501 specbind (Qoverriding_local_map
, Qnil
);
9504 GCPRO1 (new_tool_bar
);
9506 /* Build desired tool-bar items from keymaps. */
9507 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9510 /* Redisplay the tool-bar if we changed it. */
9511 if (new_n_tool_bar
!= f
->n_tool_bar_items
9512 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9514 /* Redisplay that happens asynchronously due to an expose event
9515 may access f->tool_bar_items. Make sure we update both
9516 variables within BLOCK_INPUT so no such event interrupts. */
9518 f
->tool_bar_items
= new_tool_bar
;
9519 f
->n_tool_bar_items
= new_n_tool_bar
;
9520 w
->update_mode_line
= Qt
;
9526 unbind_to (count
, Qnil
);
9527 set_buffer_internal_1 (prev
);
9533 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9534 F's desired tool-bar contents. F->tool_bar_items must have
9535 been set up previously by calling prepare_menu_bars. */
9538 build_desired_tool_bar_string (f
)
9541 int i
, size
, size_needed
;
9542 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9543 Lisp_Object image
, plist
, props
;
9545 image
= plist
= props
= Qnil
;
9546 GCPRO3 (image
, plist
, props
);
9548 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9549 Otherwise, make a new string. */
9551 /* The size of the string we might be able to reuse. */
9552 size
= (STRINGP (f
->desired_tool_bar_string
)
9553 ? SCHARS (f
->desired_tool_bar_string
)
9556 /* We need one space in the string for each image. */
9557 size_needed
= f
->n_tool_bar_items
;
9559 /* Reuse f->desired_tool_bar_string, if possible. */
9560 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9561 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9565 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9566 Fremove_text_properties (make_number (0), make_number (size
),
9567 props
, f
->desired_tool_bar_string
);
9570 /* Put a `display' property on the string for the images to display,
9571 put a `menu_item' property on tool-bar items with a value that
9572 is the index of the item in F's tool-bar item vector. */
9573 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9575 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9577 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9578 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9579 int hmargin
, vmargin
, relief
, idx
, end
;
9580 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9582 /* If image is a vector, choose the image according to the
9584 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9585 if (VECTORP (image
))
9589 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9590 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9593 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9594 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9596 xassert (ASIZE (image
) >= idx
);
9597 image
= AREF (image
, idx
);
9602 /* Ignore invalid image specifications. */
9603 if (!valid_image_p (image
))
9606 /* Display the tool-bar button pressed, or depressed. */
9607 plist
= Fcopy_sequence (XCDR (image
));
9609 /* Compute margin and relief to draw. */
9610 relief
= (tool_bar_button_relief
>= 0
9611 ? tool_bar_button_relief
9612 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9613 hmargin
= vmargin
= relief
;
9615 if (INTEGERP (Vtool_bar_button_margin
)
9616 && XINT (Vtool_bar_button_margin
) > 0)
9618 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9619 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9621 else if (CONSP (Vtool_bar_button_margin
))
9623 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9624 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9625 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9627 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9628 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9629 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9632 if (auto_raise_tool_bar_buttons_p
)
9634 /* Add a `:relief' property to the image spec if the item is
9638 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9645 /* If image is selected, display it pressed, i.e. with a
9646 negative relief. If it's not selected, display it with a
9648 plist
= Fplist_put (plist
, QCrelief
,
9650 ? make_number (-relief
)
9651 : make_number (relief
)));
9656 /* Put a margin around the image. */
9657 if (hmargin
|| vmargin
)
9659 if (hmargin
== vmargin
)
9660 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9662 plist
= Fplist_put (plist
, QCmargin
,
9663 Fcons (make_number (hmargin
),
9664 make_number (vmargin
)));
9667 /* If button is not enabled, and we don't have special images
9668 for the disabled state, make the image appear disabled by
9669 applying an appropriate algorithm to it. */
9670 if (!enabled_p
&& idx
< 0)
9671 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9673 /* Put a `display' text property on the string for the image to
9674 display. Put a `menu-item' property on the string that gives
9675 the start of this item's properties in the tool-bar items
9677 image
= Fcons (Qimage
, plist
);
9678 props
= list4 (Qdisplay
, image
,
9679 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9681 /* Let the last image hide all remaining spaces in the tool bar
9682 string. The string can be longer than needed when we reuse a
9684 if (i
+ 1 == f
->n_tool_bar_items
)
9685 end
= SCHARS (f
->desired_tool_bar_string
);
9688 Fadd_text_properties (make_number (i
), make_number (end
),
9689 props
, f
->desired_tool_bar_string
);
9697 /* Display one line of the tool-bar of frame IT->f.
9699 HEIGHT specifies the desired height of the tool-bar line.
9700 If the actual height of the glyph row is less than HEIGHT, the
9701 row's height is increased to HEIGHT, and the icons are centered
9702 vertically in the new height.
9704 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
9705 count a final empty row in case the tool-bar width exactly matches
9710 display_tool_bar_line (it
, height
)
9714 struct glyph_row
*row
= it
->glyph_row
;
9715 int max_x
= it
->last_visible_x
;
9718 prepare_desired_row (row
);
9719 row
->y
= it
->current_y
;
9721 /* Note that this isn't made use of if the face hasn't a box,
9722 so there's no need to check the face here. */
9723 it
->start_of_box_run_p
= 1;
9725 while (it
->current_x
< max_x
)
9727 int x
, n_glyphs_before
, i
, nglyphs
;
9728 struct it it_before
;
9730 /* Get the next display element. */
9731 if (!get_next_display_element (it
))
9733 /* Don't count empty row if we are counting needed tool-bar lines. */
9734 if (height
< 0 && !it
->hpos
)
9739 /* Produce glyphs. */
9740 n_glyphs_before
= row
->used
[TEXT_AREA
];
9743 PRODUCE_GLYPHS (it
);
9745 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
9747 x
= it_before
.current_x
;
9750 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9752 if (x
+ glyph
->pixel_width
> max_x
)
9754 /* Glyph doesn't fit on line. Backtrack. */
9755 row
->used
[TEXT_AREA
] = n_glyphs_before
;
9757 /* If this is the only glyph on this line, it will never fit on the
9758 toolbar, so skip it. But ensure there is at least one glyph,
9759 so we don't accidentally disable the tool-bar. */
9760 if (n_glyphs_before
== 0
9761 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
9767 x
+= glyph
->pixel_width
;
9771 /* Stop at line ends. */
9772 if (ITERATOR_AT_END_OF_LINE_P (it
))
9775 set_iterator_to_next (it
, 1);
9780 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9782 /* Use default face for the border below the tool bar.
9784 FIXME: When auto-resize-tool-bars is grow-only, there is
9785 no additional border below the possibly empty tool-bar lines.
9786 So to make the extra empty lines look "normal", we have to
9787 use the tool-bar face for the border too. */
9788 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
9789 it
->face_id
= DEFAULT_FACE_ID
;
9791 extend_face_to_end_of_line (it
);
9792 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9793 last
->right_box_line_p
= 1;
9794 if (last
== row
->glyphs
[TEXT_AREA
])
9795 last
->left_box_line_p
= 1;
9797 /* Make line the desired height and center it vertically. */
9798 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
9800 /* Don't add more than one line height. */
9801 height
%= FRAME_LINE_HEIGHT (it
->f
);
9802 it
->max_ascent
+= height
/ 2;
9803 it
->max_descent
+= (height
+ 1) / 2;
9806 compute_line_metrics (it
);
9808 /* If line is empty, make it occupy the rest of the tool-bar. */
9809 if (!row
->displays_text_p
)
9811 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9812 row
->visible_height
= row
->height
;
9813 row
->ascent
= row
->phys_ascent
= 0;
9814 row
->extra_line_spacing
= 0;
9817 row
->full_width_p
= 1;
9818 row
->continued_p
= 0;
9819 row
->truncated_on_left_p
= 0;
9820 row
->truncated_on_right_p
= 0;
9822 it
->current_x
= it
->hpos
= 0;
9823 it
->current_y
+= row
->height
;
9829 /* Max tool-bar height. */
9831 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
9832 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
9834 /* Value is the number of screen lines needed to make all tool-bar
9835 items of frame F visible. The number of actual rows needed is
9836 returned in *N_ROWS if non-NULL. */
9839 tool_bar_lines_needed (f
, n_rows
)
9843 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9845 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
9846 the desired matrix, so use (unused) mode-line row as temporary row to
9847 avoid destroying the first tool-bar row. */
9848 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
9850 /* Initialize an iterator for iteration over
9851 F->desired_tool_bar_string in the tool-bar window of frame F. */
9852 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
9853 it
.first_visible_x
= 0;
9854 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9855 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9857 while (!ITERATOR_AT_END_P (&it
))
9859 clear_glyph_row (temp_row
);
9860 it
.glyph_row
= temp_row
;
9861 display_tool_bar_line (&it
, -1);
9863 clear_glyph_row (temp_row
);
9865 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
9867 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
9869 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9873 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9875 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9884 frame
= selected_frame
;
9886 CHECK_FRAME (frame
);
9889 if (WINDOWP (f
->tool_bar_window
)
9890 || (w
= XWINDOW (f
->tool_bar_window
),
9891 WINDOW_TOTAL_LINES (w
) > 0))
9893 update_tool_bar (f
, 1);
9894 if (f
->n_tool_bar_items
)
9896 build_desired_tool_bar_string (f
);
9897 nlines
= tool_bar_lines_needed (f
, NULL
);
9901 return make_number (nlines
);
9905 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9906 height should be changed. */
9909 redisplay_tool_bar (f
)
9914 struct glyph_row
*row
;
9916 #if defined (USE_GTK) || USE_MAC_TOOLBAR
9917 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9918 update_frame_tool_bar (f
);
9922 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9923 do anything. This means you must start with tool-bar-lines
9924 non-zero to get the auto-sizing effect. Or in other words, you
9925 can turn off tool-bars by specifying tool-bar-lines zero. */
9926 if (!WINDOWP (f
->tool_bar_window
)
9927 || (w
= XWINDOW (f
->tool_bar_window
),
9928 WINDOW_TOTAL_LINES (w
) == 0))
9931 /* Set up an iterator for the tool-bar window. */
9932 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9933 it
.first_visible_x
= 0;
9934 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9937 /* Build a string that represents the contents of the tool-bar. */
9938 build_desired_tool_bar_string (f
);
9939 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9941 if (f
->n_tool_bar_rows
== 0)
9945 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
9946 nlines
!= WINDOW_TOTAL_LINES (w
)))
9948 extern Lisp_Object Qtool_bar_lines
;
9950 int old_height
= WINDOW_TOTAL_LINES (w
);
9952 XSETFRAME (frame
, f
);
9953 Fmodify_frame_parameters (frame
,
9954 Fcons (Fcons (Qtool_bar_lines
,
9955 make_number (nlines
)),
9957 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9959 clear_glyph_matrix (w
->desired_matrix
);
9960 fonts_changed_p
= 1;
9966 /* Display as many lines as needed to display all tool-bar items. */
9968 if (f
->n_tool_bar_rows
> 0)
9970 int border
, rows
, height
, extra
;
9972 if (INTEGERP (Vtool_bar_border
))
9973 border
= XINT (Vtool_bar_border
);
9974 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
9975 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
9976 else if (EQ (Vtool_bar_border
, Qborder_width
))
9977 border
= f
->border_width
;
9983 rows
= f
->n_tool_bar_rows
;
9984 height
= max (1, (it
.last_visible_y
- border
) / rows
);
9985 extra
= it
.last_visible_y
- border
- height
* rows
;
9987 while (it
.current_y
< it
.last_visible_y
)
9990 if (extra
> 0 && rows
-- > 0)
9992 h
= (extra
+ rows
- 1) / rows
;
9995 display_tool_bar_line (&it
, height
+ h
);
10000 while (it
.current_y
< it
.last_visible_y
)
10001 display_tool_bar_line (&it
, 0);
10004 /* It doesn't make much sense to try scrolling in the tool-bar
10005 window, so don't do it. */
10006 w
->desired_matrix
->no_scrolling_p
= 1;
10007 w
->must_be_updated_p
= 1;
10009 if (!NILP (Vauto_resize_tool_bars
))
10011 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10012 int change_height_p
= 0;
10014 /* If we couldn't display everything, change the tool-bar's
10015 height if there is room for more. */
10016 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10017 && it
.current_y
< max_tool_bar_height
)
10018 change_height_p
= 1;
10020 row
= it
.glyph_row
- 1;
10022 /* If there are blank lines at the end, except for a partially
10023 visible blank line at the end that is smaller than
10024 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10025 if (!row
->displays_text_p
10026 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10027 change_height_p
= 1;
10029 /* If row displays tool-bar items, but is partially visible,
10030 change the tool-bar's height. */
10031 if (row
->displays_text_p
10032 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10033 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10034 change_height_p
= 1;
10036 /* Resize windows as needed by changing the `tool-bar-lines'
10037 frame parameter. */
10038 if (change_height_p
)
10040 extern Lisp_Object Qtool_bar_lines
;
10042 int old_height
= WINDOW_TOTAL_LINES (w
);
10044 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10046 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10047 && !f
->minimize_tool_bar_window_p
)
10048 ? (nlines
> old_height
)
10049 : (nlines
!= old_height
));
10050 f
->minimize_tool_bar_window_p
= 0;
10052 if (change_height_p
)
10054 XSETFRAME (frame
, f
);
10055 Fmodify_frame_parameters (frame
,
10056 Fcons (Fcons (Qtool_bar_lines
,
10057 make_number (nlines
)),
10059 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10061 clear_glyph_matrix (w
->desired_matrix
);
10062 f
->n_tool_bar_rows
= nrows
;
10063 fonts_changed_p
= 1;
10070 f
->minimize_tool_bar_window_p
= 0;
10075 /* Get information about the tool-bar item which is displayed in GLYPH
10076 on frame F. Return in *PROP_IDX the index where tool-bar item
10077 properties start in F->tool_bar_items. Value is zero if
10078 GLYPH doesn't display a tool-bar item. */
10081 tool_bar_item_info (f
, glyph
, prop_idx
)
10083 struct glyph
*glyph
;
10090 /* This function can be called asynchronously, which means we must
10091 exclude any possibility that Fget_text_property signals an
10093 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10094 charpos
= max (0, charpos
);
10096 /* Get the text property `menu-item' at pos. The value of that
10097 property is the start index of this item's properties in
10098 F->tool_bar_items. */
10099 prop
= Fget_text_property (make_number (charpos
),
10100 Qmenu_item
, f
->current_tool_bar_string
);
10101 if (INTEGERP (prop
))
10103 *prop_idx
= XINT (prop
);
10113 /* Get information about the tool-bar item at position X/Y on frame F.
10114 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10115 the current matrix of the tool-bar window of F, or NULL if not
10116 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10117 item in F->tool_bar_items. Value is
10119 -1 if X/Y is not on a tool-bar item
10120 0 if X/Y is on the same item that was highlighted before.
10124 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10127 struct glyph
**glyph
;
10128 int *hpos
, *vpos
, *prop_idx
;
10130 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10131 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10134 /* Find the glyph under X/Y. */
10135 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10136 if (*glyph
== NULL
)
10139 /* Get the start of this tool-bar item's properties in
10140 f->tool_bar_items. */
10141 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10144 /* Is mouse on the highlighted item? */
10145 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10146 && *vpos
>= dpyinfo
->mouse_face_beg_row
10147 && *vpos
<= dpyinfo
->mouse_face_end_row
10148 && (*vpos
> dpyinfo
->mouse_face_beg_row
10149 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10150 && (*vpos
< dpyinfo
->mouse_face_end_row
10151 || *hpos
< dpyinfo
->mouse_face_end_col
10152 || dpyinfo
->mouse_face_past_end
))
10160 Handle mouse button event on the tool-bar of frame F, at
10161 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10162 0 for button release. MODIFIERS is event modifiers for button
10166 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10169 unsigned int modifiers
;
10171 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10172 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10173 int hpos
, vpos
, prop_idx
;
10174 struct glyph
*glyph
;
10175 Lisp_Object enabled_p
;
10177 /* If not on the highlighted tool-bar item, return. */
10178 frame_to_window_pixel_xy (w
, &x
, &y
);
10179 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10182 /* If item is disabled, do nothing. */
10183 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10184 if (NILP (enabled_p
))
10189 /* Show item in pressed state. */
10190 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10191 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10192 last_tool_bar_item
= prop_idx
;
10196 Lisp_Object key
, frame
;
10197 struct input_event event
;
10198 EVENT_INIT (event
);
10200 /* Show item in released state. */
10201 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10202 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10204 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10206 XSETFRAME (frame
, f
);
10207 event
.kind
= TOOL_BAR_EVENT
;
10208 event
.frame_or_window
= frame
;
10210 kbd_buffer_store_event (&event
);
10212 event
.kind
= TOOL_BAR_EVENT
;
10213 event
.frame_or_window
= frame
;
10215 event
.modifiers
= modifiers
;
10216 kbd_buffer_store_event (&event
);
10217 last_tool_bar_item
= -1;
10222 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10223 tool-bar window-relative coordinates X/Y. Called from
10224 note_mouse_highlight. */
10227 note_tool_bar_highlight (f
, x
, y
)
10231 Lisp_Object window
= f
->tool_bar_window
;
10232 struct window
*w
= XWINDOW (window
);
10233 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10235 struct glyph
*glyph
;
10236 struct glyph_row
*row
;
10238 Lisp_Object enabled_p
;
10240 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10241 int mouse_down_p
, rc
;
10243 /* Function note_mouse_highlight is called with negative x(y
10244 values when mouse moves outside of the frame. */
10245 if (x
<= 0 || y
<= 0)
10247 clear_mouse_face (dpyinfo
);
10251 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10254 /* Not on tool-bar item. */
10255 clear_mouse_face (dpyinfo
);
10259 /* On same tool-bar item as before. */
10260 goto set_help_echo
;
10262 clear_mouse_face (dpyinfo
);
10264 /* Mouse is down, but on different tool-bar item? */
10265 mouse_down_p
= (dpyinfo
->grabbed
10266 && f
== last_mouse_frame
10267 && FRAME_LIVE_P (f
));
10269 && last_tool_bar_item
!= prop_idx
)
10272 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10273 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10275 /* If tool-bar item is not enabled, don't highlight it. */
10276 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10277 if (!NILP (enabled_p
))
10279 /* Compute the x-position of the glyph. In front and past the
10280 image is a space. We include this in the highlighted area. */
10281 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10282 for (i
= x
= 0; i
< hpos
; ++i
)
10283 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10285 /* Record this as the current active region. */
10286 dpyinfo
->mouse_face_beg_col
= hpos
;
10287 dpyinfo
->mouse_face_beg_row
= vpos
;
10288 dpyinfo
->mouse_face_beg_x
= x
;
10289 dpyinfo
->mouse_face_beg_y
= row
->y
;
10290 dpyinfo
->mouse_face_past_end
= 0;
10292 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10293 dpyinfo
->mouse_face_end_row
= vpos
;
10294 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10295 dpyinfo
->mouse_face_end_y
= row
->y
;
10296 dpyinfo
->mouse_face_window
= window
;
10297 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10299 /* Display it as active. */
10300 show_mouse_face (dpyinfo
, draw
);
10301 dpyinfo
->mouse_face_image_state
= draw
;
10306 /* Set help_echo_string to a help string to display for this tool-bar item.
10307 XTread_socket does the rest. */
10308 help_echo_object
= help_echo_window
= Qnil
;
10309 help_echo_pos
= -1;
10310 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10311 if (NILP (help_echo_string
))
10312 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10315 #endif /* HAVE_WINDOW_SYSTEM */
10319 /************************************************************************
10320 Horizontal scrolling
10321 ************************************************************************/
10323 static int hscroll_window_tree
P_ ((Lisp_Object
));
10324 static int hscroll_windows
P_ ((Lisp_Object
));
10326 /* For all leaf windows in the window tree rooted at WINDOW, set their
10327 hscroll value so that PT is (i) visible in the window, and (ii) so
10328 that it is not within a certain margin at the window's left and
10329 right border. Value is non-zero if any window's hscroll has been
10333 hscroll_window_tree (window
)
10334 Lisp_Object window
;
10336 int hscrolled_p
= 0;
10337 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10338 int hscroll_step_abs
= 0;
10339 double hscroll_step_rel
= 0;
10341 if (hscroll_relative_p
)
10343 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10344 if (hscroll_step_rel
< 0)
10346 hscroll_relative_p
= 0;
10347 hscroll_step_abs
= 0;
10350 else if (INTEGERP (Vhscroll_step
))
10352 hscroll_step_abs
= XINT (Vhscroll_step
);
10353 if (hscroll_step_abs
< 0)
10354 hscroll_step_abs
= 0;
10357 hscroll_step_abs
= 0;
10359 while (WINDOWP (window
))
10361 struct window
*w
= XWINDOW (window
);
10363 if (WINDOWP (w
->hchild
))
10364 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10365 else if (WINDOWP (w
->vchild
))
10366 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10367 else if (w
->cursor
.vpos
>= 0)
10370 int text_area_width
;
10371 struct glyph_row
*current_cursor_row
10372 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10373 struct glyph_row
*desired_cursor_row
10374 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10375 struct glyph_row
*cursor_row
10376 = (desired_cursor_row
->enabled_p
10377 ? desired_cursor_row
10378 : current_cursor_row
);
10380 text_area_width
= window_box_width (w
, TEXT_AREA
);
10382 /* Scroll when cursor is inside this scroll margin. */
10383 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10385 if ((XFASTINT (w
->hscroll
)
10386 && w
->cursor
.x
<= h_margin
)
10387 || (cursor_row
->enabled_p
10388 && cursor_row
->truncated_on_right_p
10389 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
10393 struct buffer
*saved_current_buffer
;
10397 /* Find point in a display of infinite width. */
10398 saved_current_buffer
= current_buffer
;
10399 current_buffer
= XBUFFER (w
->buffer
);
10401 if (w
== XWINDOW (selected_window
))
10402 pt
= BUF_PT (current_buffer
);
10405 pt
= marker_position (w
->pointm
);
10406 pt
= max (BEGV
, pt
);
10410 /* Move iterator to pt starting at cursor_row->start in
10411 a line with infinite width. */
10412 init_to_row_start (&it
, w
, cursor_row
);
10413 it
.last_visible_x
= INFINITY
;
10414 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10415 current_buffer
= saved_current_buffer
;
10417 /* Position cursor in window. */
10418 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10419 hscroll
= max (0, (it
.current_x
10420 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10421 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10422 : (text_area_width
/ 2))))
10423 / FRAME_COLUMN_WIDTH (it
.f
);
10424 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10426 if (hscroll_relative_p
)
10427 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10430 wanted_x
= text_area_width
10431 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10434 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10438 if (hscroll_relative_p
)
10439 wanted_x
= text_area_width
* hscroll_step_rel
10442 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10445 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10447 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10449 /* Don't call Fset_window_hscroll if value hasn't
10450 changed because it will prevent redisplay
10452 if (XFASTINT (w
->hscroll
) != hscroll
)
10454 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10455 w
->hscroll
= make_number (hscroll
);
10464 /* Value is non-zero if hscroll of any leaf window has been changed. */
10465 return hscrolled_p
;
10469 /* Set hscroll so that cursor is visible and not inside horizontal
10470 scroll margins for all windows in the tree rooted at WINDOW. See
10471 also hscroll_window_tree above. Value is non-zero if any window's
10472 hscroll has been changed. If it has, desired matrices on the frame
10473 of WINDOW are cleared. */
10476 hscroll_windows (window
)
10477 Lisp_Object window
;
10481 if (automatic_hscrolling_p
)
10483 hscrolled_p
= hscroll_window_tree (window
);
10485 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10489 return hscrolled_p
;
10494 /************************************************************************
10496 ************************************************************************/
10498 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10499 to a non-zero value. This is sometimes handy to have in a debugger
10504 /* First and last unchanged row for try_window_id. */
10506 int debug_first_unchanged_at_end_vpos
;
10507 int debug_last_unchanged_at_beg_vpos
;
10509 /* Delta vpos and y. */
10511 int debug_dvpos
, debug_dy
;
10513 /* Delta in characters and bytes for try_window_id. */
10515 int debug_delta
, debug_delta_bytes
;
10517 /* Values of window_end_pos and window_end_vpos at the end of
10520 EMACS_INT debug_end_pos
, debug_end_vpos
;
10522 /* Append a string to W->desired_matrix->method. FMT is a printf
10523 format string. A1...A9 are a supplement for a variable-length
10524 argument list. If trace_redisplay_p is non-zero also printf the
10525 resulting string to stderr. */
10528 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10531 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10534 char *method
= w
->desired_matrix
->method
;
10535 int len
= strlen (method
);
10536 int size
= sizeof w
->desired_matrix
->method
;
10537 int remaining
= size
- len
- 1;
10539 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10540 if (len
&& remaining
)
10543 --remaining
, ++len
;
10546 strncpy (method
+ len
, buffer
, remaining
);
10548 if (trace_redisplay_p
)
10549 fprintf (stderr
, "%p (%s): %s\n",
10551 ((BUFFERP (w
->buffer
)
10552 && STRINGP (XBUFFER (w
->buffer
)->name
))
10553 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10558 #endif /* GLYPH_DEBUG */
10561 /* Value is non-zero if all changes in window W, which displays
10562 current_buffer, are in the text between START and END. START is a
10563 buffer position, END is given as a distance from Z. Used in
10564 redisplay_internal for display optimization. */
10567 text_outside_line_unchanged_p (w
, start
, end
)
10571 int unchanged_p
= 1;
10573 /* If text or overlays have changed, see where. */
10574 if (XFASTINT (w
->last_modified
) < MODIFF
10575 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10577 /* Gap in the line? */
10578 if (GPT
< start
|| Z
- GPT
< end
)
10581 /* Changes start in front of the line, or end after it? */
10583 && (BEG_UNCHANGED
< start
- 1
10584 || END_UNCHANGED
< end
))
10587 /* If selective display, can't optimize if changes start at the
10588 beginning of the line. */
10590 && INTEGERP (current_buffer
->selective_display
)
10591 && XINT (current_buffer
->selective_display
) > 0
10592 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10595 /* If there are overlays at the start or end of the line, these
10596 may have overlay strings with newlines in them. A change at
10597 START, for instance, may actually concern the display of such
10598 overlay strings as well, and they are displayed on different
10599 lines. So, quickly rule out this case. (For the future, it
10600 might be desirable to implement something more telling than
10601 just BEG/END_UNCHANGED.) */
10604 if (BEG
+ BEG_UNCHANGED
== start
10605 && overlay_touches_p (start
))
10607 if (END_UNCHANGED
== end
10608 && overlay_touches_p (Z
- end
))
10613 return unchanged_p
;
10617 /* Do a frame update, taking possible shortcuts into account. This is
10618 the main external entry point for redisplay.
10620 If the last redisplay displayed an echo area message and that message
10621 is no longer requested, we clear the echo area or bring back the
10622 mini-buffer if that is in use. */
10627 redisplay_internal (0);
10632 overlay_arrow_string_or_property (var
)
10637 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10640 return Voverlay_arrow_string
;
10643 /* Return 1 if there are any overlay-arrows in current_buffer. */
10645 overlay_arrow_in_current_buffer_p ()
10649 for (vlist
= Voverlay_arrow_variable_list
;
10651 vlist
= XCDR (vlist
))
10653 Lisp_Object var
= XCAR (vlist
);
10656 if (!SYMBOLP (var
))
10658 val
= find_symbol_value (var
);
10660 && current_buffer
== XMARKER (val
)->buffer
)
10667 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
10671 overlay_arrows_changed_p ()
10675 for (vlist
= Voverlay_arrow_variable_list
;
10677 vlist
= XCDR (vlist
))
10679 Lisp_Object var
= XCAR (vlist
);
10680 Lisp_Object val
, pstr
;
10682 if (!SYMBOLP (var
))
10684 val
= find_symbol_value (var
);
10685 if (!MARKERP (val
))
10687 if (! EQ (COERCE_MARKER (val
),
10688 Fget (var
, Qlast_arrow_position
))
10689 || ! (pstr
= overlay_arrow_string_or_property (var
),
10690 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
10696 /* Mark overlay arrows to be updated on next redisplay. */
10699 update_overlay_arrows (up_to_date
)
10704 for (vlist
= Voverlay_arrow_variable_list
;
10706 vlist
= XCDR (vlist
))
10708 Lisp_Object var
= XCAR (vlist
);
10710 if (!SYMBOLP (var
))
10713 if (up_to_date
> 0)
10715 Lisp_Object val
= find_symbol_value (var
);
10716 Fput (var
, Qlast_arrow_position
,
10717 COERCE_MARKER (val
));
10718 Fput (var
, Qlast_arrow_string
,
10719 overlay_arrow_string_or_property (var
));
10721 else if (up_to_date
< 0
10722 || !NILP (Fget (var
, Qlast_arrow_position
)))
10724 Fput (var
, Qlast_arrow_position
, Qt
);
10725 Fput (var
, Qlast_arrow_string
, Qt
);
10731 /* Return overlay arrow string to display at row.
10732 Return integer (bitmap number) for arrow bitmap in left fringe.
10733 Return nil if no overlay arrow. */
10736 overlay_arrow_at_row (it
, row
)
10738 struct glyph_row
*row
;
10742 for (vlist
= Voverlay_arrow_variable_list
;
10744 vlist
= XCDR (vlist
))
10746 Lisp_Object var
= XCAR (vlist
);
10749 if (!SYMBOLP (var
))
10752 val
= find_symbol_value (var
);
10755 && current_buffer
== XMARKER (val
)->buffer
10756 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10758 if (FRAME_WINDOW_P (it
->f
)
10759 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10761 #ifdef HAVE_WINDOW_SYSTEM
10762 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10765 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10766 return make_number (fringe_bitmap
);
10769 return make_number (-1); /* Use default arrow bitmap */
10771 return overlay_arrow_string_or_property (var
);
10778 /* Return 1 if point moved out of or into a composition. Otherwise
10779 return 0. PREV_BUF and PREV_PT are the last point buffer and
10780 position. BUF and PT are the current point buffer and position. */
10783 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10784 struct buffer
*prev_buf
, *buf
;
10789 Lisp_Object buffer
;
10791 XSETBUFFER (buffer
, buf
);
10792 /* Check a composition at the last point if point moved within the
10794 if (prev_buf
== buf
)
10797 /* Point didn't move. */
10800 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10801 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10802 && COMPOSITION_VALID_P (start
, end
, prop
)
10803 && start
< prev_pt
&& end
> prev_pt
)
10804 /* The last point was within the composition. Return 1 iff
10805 point moved out of the composition. */
10806 return (pt
<= start
|| pt
>= end
);
10809 /* Check a composition at the current point. */
10810 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10811 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10812 && COMPOSITION_VALID_P (start
, end
, prop
)
10813 && start
< pt
&& end
> pt
);
10817 /* Reconsider the setting of B->clip_changed which is displayed
10821 reconsider_clip_changes (w
, b
)
10825 if (b
->clip_changed
10826 && !NILP (w
->window_end_valid
)
10827 && w
->current_matrix
->buffer
== b
10828 && w
->current_matrix
->zv
== BUF_ZV (b
)
10829 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10830 b
->clip_changed
= 0;
10832 /* If display wasn't paused, and W is not a tool bar window, see if
10833 point has been moved into or out of a composition. In that case,
10834 we set b->clip_changed to 1 to force updating the screen. If
10835 b->clip_changed has already been set to 1, we can skip this
10837 if (!b
->clip_changed
10838 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10842 if (w
== XWINDOW (selected_window
))
10843 pt
= BUF_PT (current_buffer
);
10845 pt
= marker_position (w
->pointm
);
10847 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10848 || pt
!= XINT (w
->last_point
))
10849 && check_point_in_composition (w
->current_matrix
->buffer
,
10850 XINT (w
->last_point
),
10851 XBUFFER (w
->buffer
), pt
))
10852 b
->clip_changed
= 1;
10857 /* Select FRAME to forward the values of frame-local variables into C
10858 variables so that the redisplay routines can access those values
10862 select_frame_for_redisplay (frame
)
10865 Lisp_Object tail
, sym
, val
;
10866 Lisp_Object old
= selected_frame
;
10868 selected_frame
= frame
;
10870 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10871 if (CONSP (XCAR (tail
))
10872 && (sym
= XCAR (XCAR (tail
)),
10874 && (sym
= indirect_variable (sym
),
10875 val
= SYMBOL_VALUE (sym
),
10876 (BUFFER_LOCAL_VALUEP (val
)
10877 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10878 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10879 /* Use find_symbol_value rather than Fsymbol_value
10880 to avoid an error if it is void. */
10881 find_symbol_value (sym
);
10883 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10884 if (CONSP (XCAR (tail
))
10885 && (sym
= XCAR (XCAR (tail
)),
10887 && (sym
= indirect_variable (sym
),
10888 val
= SYMBOL_VALUE (sym
),
10889 (BUFFER_LOCAL_VALUEP (val
)
10890 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10891 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10892 find_symbol_value (sym
);
10896 #define STOP_POLLING \
10897 do { if (! polling_stopped_here) stop_polling (); \
10898 polling_stopped_here = 1; } while (0)
10900 #define RESUME_POLLING \
10901 do { if (polling_stopped_here) start_polling (); \
10902 polling_stopped_here = 0; } while (0)
10905 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10906 response to any user action; therefore, we should preserve the echo
10907 area. (Actually, our caller does that job.) Perhaps in the future
10908 avoid recentering windows if it is not necessary; currently that
10909 causes some problems. */
10912 redisplay_internal (preserve_echo_area
)
10913 int preserve_echo_area
;
10915 struct window
*w
= XWINDOW (selected_window
);
10918 int must_finish
= 0;
10919 struct text_pos tlbufpos
, tlendpos
;
10920 int number_of_visible_frames
;
10923 int polling_stopped_here
= 0;
10925 /* Non-zero means redisplay has to consider all windows on all
10926 frames. Zero means, only selected_window is considered. */
10927 int consider_all_windows_p
;
10929 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10931 /* No redisplay if running in batch mode or frame is not yet fully
10932 initialized, or redisplay is explicitly turned off by setting
10933 Vinhibit_redisplay. */
10935 || !NILP (Vinhibit_redisplay
))
10938 /* Don't examine these until after testing Vinhibit_redisplay.
10939 When Emacs is shutting down, perhaps because its connection to
10940 X has dropped, we should not look at them at all. */
10941 f
= XFRAME (w
->frame
);
10942 sf
= SELECTED_FRAME ();
10944 if (!f
->glyphs_initialized_p
)
10947 /* The flag redisplay_performed_directly_p is set by
10948 direct_output_for_insert when it already did the whole screen
10949 update necessary. */
10950 if (redisplay_performed_directly_p
)
10952 redisplay_performed_directly_p
= 0;
10953 if (!hscroll_windows (selected_window
))
10957 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (MAC_OS)
10958 if (popup_activated ())
10962 /* I don't think this happens but let's be paranoid. */
10963 if (redisplaying_p
)
10966 /* Record a function that resets redisplaying_p to its old value
10967 when we leave this function. */
10968 count
= SPECPDL_INDEX ();
10969 record_unwind_protect (unwind_redisplay
,
10970 Fcons (make_number (redisplaying_p
), selected_frame
));
10972 specbind (Qinhibit_free_realized_faces
, Qnil
);
10975 Lisp_Object tail
, frame
;
10977 FOR_EACH_FRAME (tail
, frame
)
10979 struct frame
*f
= XFRAME (frame
);
10980 f
->already_hscrolled_p
= 0;
10986 reconsider_clip_changes (w
, current_buffer
);
10987 last_escape_glyph_frame
= NULL
;
10988 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
10990 /* If new fonts have been loaded that make a glyph matrix adjustment
10991 necessary, do it. */
10992 if (fonts_changed_p
)
10994 adjust_glyphs (NULL
);
10995 ++windows_or_buffers_changed
;
10996 fonts_changed_p
= 0;
10999 /* If face_change_count is non-zero, init_iterator will free all
11000 realized faces, which includes the faces referenced from current
11001 matrices. So, we can't reuse current matrices in this case. */
11002 if (face_change_count
)
11003 ++windows_or_buffers_changed
;
11005 if (! FRAME_WINDOW_P (sf
)
11006 && previous_terminal_frame
!= sf
)
11008 /* Since frames on an ASCII terminal share the same display
11009 area, displaying a different frame means redisplay the whole
11011 windows_or_buffers_changed
++;
11012 SET_FRAME_GARBAGED (sf
);
11013 XSETFRAME (Vterminal_frame
, sf
);
11015 previous_terminal_frame
= sf
;
11017 /* Set the visible flags for all frames. Do this before checking
11018 for resized or garbaged frames; they want to know if their frames
11019 are visible. See the comment in frame.h for
11020 FRAME_SAMPLE_VISIBILITY. */
11022 Lisp_Object tail
, frame
;
11024 number_of_visible_frames
= 0;
11026 FOR_EACH_FRAME (tail
, frame
)
11028 struct frame
*f
= XFRAME (frame
);
11030 FRAME_SAMPLE_VISIBILITY (f
);
11031 if (FRAME_VISIBLE_P (f
))
11032 ++number_of_visible_frames
;
11033 clear_desired_matrices (f
);
11037 /* Notice any pending interrupt request to change frame size. */
11038 do_pending_window_change (1);
11040 /* Clear frames marked as garbaged. */
11041 if (frame_garbaged
)
11042 clear_garbaged_frames ();
11044 /* Build menubar and tool-bar items. */
11045 if (NILP (Vmemory_full
))
11046 prepare_menu_bars ();
11048 if (windows_or_buffers_changed
)
11049 update_mode_lines
++;
11051 /* Detect case that we need to write or remove a star in the mode line. */
11052 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11054 w
->update_mode_line
= Qt
;
11055 if (buffer_shared
> 1)
11056 update_mode_lines
++;
11059 /* Avoid invocation of point motion hooks by `current_column' below. */
11060 count1
= SPECPDL_INDEX ();
11061 specbind (Qinhibit_point_motion_hooks
, Qt
);
11063 /* If %c is in the mode line, update it if needed. */
11064 if (!NILP (w
->column_number_displayed
)
11065 /* This alternative quickly identifies a common case
11066 where no change is needed. */
11067 && !(PT
== XFASTINT (w
->last_point
)
11068 && XFASTINT (w
->last_modified
) >= MODIFF
11069 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11070 && (XFASTINT (w
->column_number_displayed
)
11071 != (int) current_column ())) /* iftc */
11072 w
->update_mode_line
= Qt
;
11074 unbind_to (count1
, Qnil
);
11076 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11078 /* The variable buffer_shared is set in redisplay_window and
11079 indicates that we redisplay a buffer in different windows. See
11081 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11082 || cursor_type_changed
);
11084 /* If specs for an arrow have changed, do thorough redisplay
11085 to ensure we remove any arrow that should no longer exist. */
11086 if (overlay_arrows_changed_p ())
11087 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11089 /* Normally the message* functions will have already displayed and
11090 updated the echo area, but the frame may have been trashed, or
11091 the update may have been preempted, so display the echo area
11092 again here. Checking message_cleared_p captures the case that
11093 the echo area should be cleared. */
11094 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11095 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11096 || (message_cleared_p
11097 && minibuf_level
== 0
11098 /* If the mini-window is currently selected, this means the
11099 echo-area doesn't show through. */
11100 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11102 int window_height_changed_p
= echo_area_display (0);
11105 /* If we don't display the current message, don't clear the
11106 message_cleared_p flag, because, if we did, we wouldn't clear
11107 the echo area in the next redisplay which doesn't preserve
11109 if (!display_last_displayed_message_p
)
11110 message_cleared_p
= 0;
11112 if (fonts_changed_p
)
11114 else if (window_height_changed_p
)
11116 consider_all_windows_p
= 1;
11117 ++update_mode_lines
;
11118 ++windows_or_buffers_changed
;
11120 /* If window configuration was changed, frames may have been
11121 marked garbaged. Clear them or we will experience
11122 surprises wrt scrolling. */
11123 if (frame_garbaged
)
11124 clear_garbaged_frames ();
11127 else if (EQ (selected_window
, minibuf_window
)
11128 && (current_buffer
->clip_changed
11129 || XFASTINT (w
->last_modified
) < MODIFF
11130 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11131 && resize_mini_window (w
, 0))
11133 /* Resized active mini-window to fit the size of what it is
11134 showing if its contents might have changed. */
11136 consider_all_windows_p
= 1;
11137 ++windows_or_buffers_changed
;
11138 ++update_mode_lines
;
11140 /* If window configuration was changed, frames may have been
11141 marked garbaged. Clear them or we will experience
11142 surprises wrt scrolling. */
11143 if (frame_garbaged
)
11144 clear_garbaged_frames ();
11148 /* If showing the region, and mark has changed, we must redisplay
11149 the whole window. The assignment to this_line_start_pos prevents
11150 the optimization directly below this if-statement. */
11151 if (((!NILP (Vtransient_mark_mode
)
11152 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11153 != !NILP (w
->region_showing
))
11154 || (!NILP (w
->region_showing
)
11155 && !EQ (w
->region_showing
,
11156 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11157 CHARPOS (this_line_start_pos
) = 0;
11159 /* Optimize the case that only the line containing the cursor in the
11160 selected window has changed. Variables starting with this_ are
11161 set in display_line and record information about the line
11162 containing the cursor. */
11163 tlbufpos
= this_line_start_pos
;
11164 tlendpos
= this_line_end_pos
;
11165 if (!consider_all_windows_p
11166 && CHARPOS (tlbufpos
) > 0
11167 && NILP (w
->update_mode_line
)
11168 && !current_buffer
->clip_changed
11169 && !current_buffer
->prevent_redisplay_optimizations_p
11170 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11171 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11172 /* Make sure recorded data applies to current buffer, etc. */
11173 && this_line_buffer
== current_buffer
11174 && current_buffer
== XBUFFER (w
->buffer
)
11175 && NILP (w
->force_start
)
11176 && NILP (w
->optional_new_start
)
11177 /* Point must be on the line that we have info recorded about. */
11178 && PT
>= CHARPOS (tlbufpos
)
11179 && PT
<= Z
- CHARPOS (tlendpos
)
11180 /* All text outside that line, including its final newline,
11181 must be unchanged */
11182 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11183 CHARPOS (tlendpos
)))
11185 if (CHARPOS (tlbufpos
) > BEGV
11186 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11187 && (CHARPOS (tlbufpos
) == ZV
11188 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11189 /* Former continuation line has disappeared by becoming empty */
11191 else if (XFASTINT (w
->last_modified
) < MODIFF
11192 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11193 || MINI_WINDOW_P (w
))
11195 /* We have to handle the case of continuation around a
11196 wide-column character (See the comment in indent.c around
11199 For instance, in the following case:
11201 -------- Insert --------
11202 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11203 J_I_ ==> J_I_ `^^' are cursors.
11207 As we have to redraw the line above, we should goto cancel. */
11210 int line_height_before
= this_line_pixel_height
;
11212 /* Note that start_display will handle the case that the
11213 line starting at tlbufpos is a continuation lines. */
11214 start_display (&it
, w
, tlbufpos
);
11216 /* Implementation note: It this still necessary? */
11217 if (it
.current_x
!= this_line_start_x
)
11220 TRACE ((stderr
, "trying display optimization 1\n"));
11221 w
->cursor
.vpos
= -1;
11222 overlay_arrow_seen
= 0;
11223 it
.vpos
= this_line_vpos
;
11224 it
.current_y
= this_line_y
;
11225 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11226 display_line (&it
);
11228 /* If line contains point, is not continued,
11229 and ends at same distance from eob as before, we win */
11230 if (w
->cursor
.vpos
>= 0
11231 /* Line is not continued, otherwise this_line_start_pos
11232 would have been set to 0 in display_line. */
11233 && CHARPOS (this_line_start_pos
)
11234 /* Line ends as before. */
11235 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11236 /* Line has same height as before. Otherwise other lines
11237 would have to be shifted up or down. */
11238 && this_line_pixel_height
== line_height_before
)
11240 /* If this is not the window's last line, we must adjust
11241 the charstarts of the lines below. */
11242 if (it
.current_y
< it
.last_visible_y
)
11244 struct glyph_row
*row
11245 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11246 int delta
, delta_bytes
;
11248 if (Z
- CHARPOS (tlendpos
) == ZV
)
11250 /* This line ends at end of (accessible part of)
11251 buffer. There is no newline to count. */
11253 - CHARPOS (tlendpos
)
11254 - MATRIX_ROW_START_CHARPOS (row
));
11255 delta_bytes
= (Z_BYTE
11256 - BYTEPOS (tlendpos
)
11257 - MATRIX_ROW_START_BYTEPOS (row
));
11261 /* This line ends in a newline. Must take
11262 account of the newline and the rest of the
11263 text that follows. */
11265 - CHARPOS (tlendpos
)
11266 - MATRIX_ROW_START_CHARPOS (row
));
11267 delta_bytes
= (Z_BYTE
11268 - BYTEPOS (tlendpos
)
11269 - MATRIX_ROW_START_BYTEPOS (row
));
11272 increment_matrix_positions (w
->current_matrix
,
11273 this_line_vpos
+ 1,
11274 w
->current_matrix
->nrows
,
11275 delta
, delta_bytes
);
11278 /* If this row displays text now but previously didn't,
11279 or vice versa, w->window_end_vpos may have to be
11281 if ((it
.glyph_row
- 1)->displays_text_p
)
11283 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11284 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11286 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11287 && this_line_vpos
> 0)
11288 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11289 w
->window_end_valid
= Qnil
;
11291 /* Update hint: No need to try to scroll in update_window. */
11292 w
->desired_matrix
->no_scrolling_p
= 1;
11295 *w
->desired_matrix
->method
= 0;
11296 debug_method_add (w
, "optimization 1");
11298 #ifdef HAVE_WINDOW_SYSTEM
11299 update_window_fringes (w
, 0);
11306 else if (/* Cursor position hasn't changed. */
11307 PT
== XFASTINT (w
->last_point
)
11308 /* Make sure the cursor was last displayed
11309 in this window. Otherwise we have to reposition it. */
11310 && 0 <= w
->cursor
.vpos
11311 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11315 do_pending_window_change (1);
11317 /* We used to always goto end_of_redisplay here, but this
11318 isn't enough if we have a blinking cursor. */
11319 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11320 goto end_of_redisplay
;
11324 /* If highlighting the region, or if the cursor is in the echo area,
11325 then we can't just move the cursor. */
11326 else if (! (!NILP (Vtransient_mark_mode
)
11327 && !NILP (current_buffer
->mark_active
))
11328 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11329 || highlight_nonselected_windows
)
11330 && NILP (w
->region_showing
)
11331 && NILP (Vshow_trailing_whitespace
)
11332 && !cursor_in_echo_area
)
11335 struct glyph_row
*row
;
11337 /* Skip from tlbufpos to PT and see where it is. Note that
11338 PT may be in invisible text. If so, we will end at the
11339 next visible position. */
11340 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11341 NULL
, DEFAULT_FACE_ID
);
11342 it
.current_x
= this_line_start_x
;
11343 it
.current_y
= this_line_y
;
11344 it
.vpos
= this_line_vpos
;
11346 /* The call to move_it_to stops in front of PT, but
11347 moves over before-strings. */
11348 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11350 if (it
.vpos
== this_line_vpos
11351 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11354 xassert (this_line_vpos
== it
.vpos
);
11355 xassert (this_line_y
== it
.current_y
);
11356 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11358 *w
->desired_matrix
->method
= 0;
11359 debug_method_add (w
, "optimization 3");
11368 /* Text changed drastically or point moved off of line. */
11369 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11372 CHARPOS (this_line_start_pos
) = 0;
11373 consider_all_windows_p
|= buffer_shared
> 1;
11374 ++clear_face_cache_count
;
11375 #ifdef HAVE_WINDOW_SYSTEM
11376 ++clear_image_cache_count
;
11379 /* Build desired matrices, and update the display. If
11380 consider_all_windows_p is non-zero, do it for all windows on all
11381 frames. Otherwise do it for selected_window, only. */
11383 if (consider_all_windows_p
)
11385 Lisp_Object tail
, frame
;
11387 FOR_EACH_FRAME (tail
, frame
)
11388 XFRAME (frame
)->updated_p
= 0;
11390 /* Recompute # windows showing selected buffer. This will be
11391 incremented each time such a window is displayed. */
11394 FOR_EACH_FRAME (tail
, frame
)
11396 struct frame
*f
= XFRAME (frame
);
11398 if (FRAME_WINDOW_P (f
) || f
== sf
)
11400 if (! EQ (frame
, selected_frame
))
11401 /* Select the frame, for the sake of frame-local
11403 select_frame_for_redisplay (frame
);
11405 /* Mark all the scroll bars to be removed; we'll redeem
11406 the ones we want when we redisplay their windows. */
11407 if (condemn_scroll_bars_hook
)
11408 condemn_scroll_bars_hook (f
);
11410 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11411 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11413 /* Any scroll bars which redisplay_windows should have
11414 nuked should now go away. */
11415 if (judge_scroll_bars_hook
)
11416 judge_scroll_bars_hook (f
);
11418 /* If fonts changed, display again. */
11419 /* ??? rms: I suspect it is a mistake to jump all the way
11420 back to retry here. It should just retry this frame. */
11421 if (fonts_changed_p
)
11424 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11426 /* See if we have to hscroll. */
11427 if (!f
->already_hscrolled_p
)
11429 f
->already_hscrolled_p
= 1;
11430 if (hscroll_windows (f
->root_window
))
11434 /* Prevent various kinds of signals during display
11435 update. stdio is not robust about handling
11436 signals, which can cause an apparent I/O
11438 if (interrupt_input
)
11439 unrequest_sigio ();
11442 /* Update the display. */
11443 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11444 pause
|= update_frame (f
, 0, 0);
11445 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
11457 /* Do the mark_window_display_accurate after all windows have
11458 been redisplayed because this call resets flags in buffers
11459 which are needed for proper redisplay. */
11460 FOR_EACH_FRAME (tail
, frame
)
11462 struct frame
*f
= XFRAME (frame
);
11465 mark_window_display_accurate (f
->root_window
, 1);
11466 if (frame_up_to_date_hook
)
11467 frame_up_to_date_hook (f
);
11472 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11474 Lisp_Object mini_window
;
11475 struct frame
*mini_frame
;
11477 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11478 /* Use list_of_error, not Qerror, so that
11479 we catch only errors and don't run the debugger. */
11480 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11482 redisplay_window_error
);
11484 /* Compare desired and current matrices, perform output. */
11487 /* If fonts changed, display again. */
11488 if (fonts_changed_p
)
11491 /* Prevent various kinds of signals during display update.
11492 stdio is not robust about handling signals,
11493 which can cause an apparent I/O error. */
11494 if (interrupt_input
)
11495 unrequest_sigio ();
11498 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11500 if (hscroll_windows (selected_window
))
11503 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11504 pause
= update_frame (sf
, 0, 0);
11507 /* We may have called echo_area_display at the top of this
11508 function. If the echo area is on another frame, that may
11509 have put text on a frame other than the selected one, so the
11510 above call to update_frame would not have caught it. Catch
11512 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11513 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11515 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11517 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11518 pause
|= update_frame (mini_frame
, 0, 0);
11519 if (!pause
&& hscroll_windows (mini_window
))
11524 /* If display was paused because of pending input, make sure we do a
11525 thorough update the next time. */
11528 /* Prevent the optimization at the beginning of
11529 redisplay_internal that tries a single-line update of the
11530 line containing the cursor in the selected window. */
11531 CHARPOS (this_line_start_pos
) = 0;
11533 /* Let the overlay arrow be updated the next time. */
11534 update_overlay_arrows (0);
11536 /* If we pause after scrolling, some rows in the current
11537 matrices of some windows are not valid. */
11538 if (!WINDOW_FULL_WIDTH_P (w
)
11539 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11540 update_mode_lines
= 1;
11544 if (!consider_all_windows_p
)
11546 /* This has already been done above if
11547 consider_all_windows_p is set. */
11548 mark_window_display_accurate_1 (w
, 1);
11550 /* Say overlay arrows are up to date. */
11551 update_overlay_arrows (1);
11553 if (frame_up_to_date_hook
!= 0)
11554 frame_up_to_date_hook (sf
);
11557 update_mode_lines
= 0;
11558 windows_or_buffers_changed
= 0;
11559 cursor_type_changed
= 0;
11562 /* Start SIGIO interrupts coming again. Having them off during the
11563 code above makes it less likely one will discard output, but not
11564 impossible, since there might be stuff in the system buffer here.
11565 But it is much hairier to try to do anything about that. */
11566 if (interrupt_input
)
11570 /* If a frame has become visible which was not before, redisplay
11571 again, so that we display it. Expose events for such a frame
11572 (which it gets when becoming visible) don't call the parts of
11573 redisplay constructing glyphs, so simply exposing a frame won't
11574 display anything in this case. So, we have to display these
11575 frames here explicitly. */
11578 Lisp_Object tail
, frame
;
11581 FOR_EACH_FRAME (tail
, frame
)
11583 int this_is_visible
= 0;
11585 if (XFRAME (frame
)->visible
)
11586 this_is_visible
= 1;
11587 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11588 if (XFRAME (frame
)->visible
)
11589 this_is_visible
= 1;
11591 if (this_is_visible
)
11595 if (new_count
!= number_of_visible_frames
)
11596 windows_or_buffers_changed
++;
11599 /* Change frame size now if a change is pending. */
11600 do_pending_window_change (1);
11602 /* If we just did a pending size change, or have additional
11603 visible frames, redisplay again. */
11604 if (windows_or_buffers_changed
&& !pause
)
11607 /* Clear the face cache eventually. */
11608 if (consider_all_windows_p
)
11610 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11612 clear_face_cache (0);
11613 clear_face_cache_count
= 0;
11615 #ifdef HAVE_WINDOW_SYSTEM
11616 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11618 Lisp_Object tail
, frame
;
11619 FOR_EACH_FRAME (tail
, frame
)
11621 struct frame
*f
= XFRAME (frame
);
11622 if (FRAME_WINDOW_P (f
))
11623 clear_image_cache (f
, 0);
11625 clear_image_cache_count
= 0;
11627 #endif /* HAVE_WINDOW_SYSTEM */
11631 unbind_to (count
, Qnil
);
11636 /* Redisplay, but leave alone any recent echo area message unless
11637 another message has been requested in its place.
11639 This is useful in situations where you need to redisplay but no
11640 user action has occurred, making it inappropriate for the message
11641 area to be cleared. See tracking_off and
11642 wait_reading_process_output for examples of these situations.
11644 FROM_WHERE is an integer saying from where this function was
11645 called. This is useful for debugging. */
11648 redisplay_preserve_echo_area (from_where
)
11651 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
11653 if (!NILP (echo_area_buffer
[1]))
11655 /* We have a previously displayed message, but no current
11656 message. Redisplay the previous message. */
11657 display_last_displayed_message_p
= 1;
11658 redisplay_internal (1);
11659 display_last_displayed_message_p
= 0;
11662 redisplay_internal (1);
11664 if (rif
!= NULL
&& rif
->flush_display_optional
)
11665 rif
->flush_display_optional (NULL
);
11669 /* Function registered with record_unwind_protect in
11670 redisplay_internal. Reset redisplaying_p to the value it had
11671 before redisplay_internal was called, and clear
11672 prevent_freeing_realized_faces_p. It also selects the previously
11676 unwind_redisplay (val
)
11679 Lisp_Object old_redisplaying_p
, old_frame
;
11681 old_redisplaying_p
= XCAR (val
);
11682 redisplaying_p
= XFASTINT (old_redisplaying_p
);
11683 old_frame
= XCDR (val
);
11684 if (! EQ (old_frame
, selected_frame
))
11685 select_frame_for_redisplay (old_frame
);
11690 /* Mark the display of window W as accurate or inaccurate. If
11691 ACCURATE_P is non-zero mark display of W as accurate. If
11692 ACCURATE_P is zero, arrange for W to be redisplayed the next time
11693 redisplay_internal is called. */
11696 mark_window_display_accurate_1 (w
, accurate_p
)
11700 if (BUFFERP (w
->buffer
))
11702 struct buffer
*b
= XBUFFER (w
->buffer
);
11705 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
11706 w
->last_overlay_modified
11707 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
11709 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
11713 b
->clip_changed
= 0;
11714 b
->prevent_redisplay_optimizations_p
= 0;
11716 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
11717 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
11718 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
11719 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
11721 w
->current_matrix
->buffer
= b
;
11722 w
->current_matrix
->begv
= BUF_BEGV (b
);
11723 w
->current_matrix
->zv
= BUF_ZV (b
);
11725 w
->last_cursor
= w
->cursor
;
11726 w
->last_cursor_off_p
= w
->cursor_off_p
;
11728 if (w
== XWINDOW (selected_window
))
11729 w
->last_point
= make_number (BUF_PT (b
));
11731 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
11737 w
->window_end_valid
= w
->buffer
;
11738 #if 0 /* This is incorrect with variable-height lines. */
11739 xassert (XINT (w
->window_end_vpos
)
11740 < (WINDOW_TOTAL_LINES (w
)
11741 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
11743 w
->update_mode_line
= Qnil
;
11748 /* Mark the display of windows in the window tree rooted at WINDOW as
11749 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
11750 windows as accurate. If ACCURATE_P is zero, arrange for windows to
11751 be redisplayed the next time redisplay_internal is called. */
11754 mark_window_display_accurate (window
, accurate_p
)
11755 Lisp_Object window
;
11760 for (; !NILP (window
); window
= w
->next
)
11762 w
= XWINDOW (window
);
11763 mark_window_display_accurate_1 (w
, accurate_p
);
11765 if (!NILP (w
->vchild
))
11766 mark_window_display_accurate (w
->vchild
, accurate_p
);
11767 if (!NILP (w
->hchild
))
11768 mark_window_display_accurate (w
->hchild
, accurate_p
);
11773 update_overlay_arrows (1);
11777 /* Force a thorough redisplay the next time by setting
11778 last_arrow_position and last_arrow_string to t, which is
11779 unequal to any useful value of Voverlay_arrow_... */
11780 update_overlay_arrows (-1);
11785 /* Return value in display table DP (Lisp_Char_Table *) for character
11786 C. Since a display table doesn't have any parent, we don't have to
11787 follow parent. Do not call this function directly but use the
11788 macro DISP_CHAR_VECTOR. */
11791 disp_char_vector (dp
, c
)
11792 struct Lisp_Char_Table
*dp
;
11798 if (SINGLE_BYTE_CHAR_P (c
))
11799 return (dp
->contents
[c
]);
11801 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
11804 else if (code
[2] < 32)
11807 /* Here, the possible range of code[0] (== charset ID) is
11808 128..max_charset. Since the top level char table contains data
11809 for multibyte characters after 256th element, we must increment
11810 code[0] by 128 to get a correct index. */
11812 code
[3] = -1; /* anchor */
11814 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
11816 val
= dp
->contents
[code
[i
]];
11817 if (!SUB_CHAR_TABLE_P (val
))
11818 return (NILP (val
) ? dp
->defalt
: val
);
11821 /* Here, val is a sub char table. We return the default value of
11823 return (dp
->defalt
);
11828 /***********************************************************************
11830 ***********************************************************************/
11832 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11835 redisplay_windows (window
)
11836 Lisp_Object window
;
11838 while (!NILP (window
))
11840 struct window
*w
= XWINDOW (window
);
11842 if (!NILP (w
->hchild
))
11843 redisplay_windows (w
->hchild
);
11844 else if (!NILP (w
->vchild
))
11845 redisplay_windows (w
->vchild
);
11848 displayed_buffer
= XBUFFER (w
->buffer
);
11849 /* Use list_of_error, not Qerror, so that
11850 we catch only errors and don't run the debugger. */
11851 internal_condition_case_1 (redisplay_window_0
, window
,
11853 redisplay_window_error
);
11861 redisplay_window_error ()
11863 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11868 redisplay_window_0 (window
)
11869 Lisp_Object window
;
11871 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11872 redisplay_window (window
, 0);
11877 redisplay_window_1 (window
)
11878 Lisp_Object window
;
11880 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11881 redisplay_window (window
, 1);
11886 /* Increment GLYPH until it reaches END or CONDITION fails while
11887 adding (GLYPH)->pixel_width to X. */
11889 #define SKIP_GLYPHS(glyph, end, x, condition) \
11892 (x) += (glyph)->pixel_width; \
11895 while ((glyph) < (end) && (condition))
11898 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11899 DELTA is the number of bytes by which positions recorded in ROW
11900 differ from current buffer positions.
11902 Return 0 if cursor is not on this row. 1 otherwise. */
11905 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11907 struct glyph_row
*row
;
11908 struct glyph_matrix
*matrix
;
11909 int delta
, delta_bytes
, dy
, dvpos
;
11911 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11912 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11913 struct glyph
*cursor
= NULL
;
11914 /* The first glyph that starts a sequence of glyphs from string. */
11915 struct glyph
*string_start
;
11916 /* The X coordinate of string_start. */
11917 int string_start_x
;
11918 /* The last known character position. */
11919 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11920 /* The last known character position before string_start. */
11921 int string_before_pos
;
11924 int cursor_from_overlay_pos
= 0;
11925 int pt_old
= PT
- delta
;
11927 /* Skip over glyphs not having an object at the start of the row.
11928 These are special glyphs like truncation marks on terminal
11930 if (row
->displays_text_p
)
11932 && INTEGERP (glyph
->object
)
11933 && glyph
->charpos
< 0)
11935 x
+= glyph
->pixel_width
;
11939 string_start
= NULL
;
11941 && !INTEGERP (glyph
->object
)
11942 && (!BUFFERP (glyph
->object
)
11943 || (last_pos
= glyph
->charpos
) < pt_old
))
11945 if (! STRINGP (glyph
->object
))
11947 string_start
= NULL
;
11948 x
+= glyph
->pixel_width
;
11950 if (cursor_from_overlay_pos
11951 && last_pos
>= cursor_from_overlay_pos
)
11953 cursor_from_overlay_pos
= 0;
11959 if (string_start
== NULL
)
11961 string_before_pos
= last_pos
;
11962 string_start
= glyph
;
11963 string_start_x
= x
;
11965 /* Skip all glyphs from string. */
11970 if ((cursor
== NULL
|| glyph
> cursor
)
11971 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
11972 Qcursor
, (glyph
)->object
),
11974 && (pos
= string_buffer_position (w
, glyph
->object
,
11975 string_before_pos
),
11976 (pos
== 0 /* From overlay */
11977 || pos
== pt_old
)))
11979 /* Estimate overlay buffer position from the buffer
11980 positions of the glyphs before and after the overlay.
11981 Add 1 to last_pos so that if point corresponds to the
11982 glyph right after the overlay, we still use a 'cursor'
11983 property found in that overlay. */
11984 cursor_from_overlay_pos
= (pos
? 0 : last_pos
11985 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
11989 x
+= glyph
->pixel_width
;
11992 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
11996 if (cursor
!= NULL
)
12001 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
12003 /* Scan back over the ellipsis glyphs, decrementing positions. */
12004 while (glyph
> row
->glyphs
[TEXT_AREA
]
12005 && (glyph
- 1)->charpos
== last_pos
)
12006 glyph
--, x
-= glyph
->pixel_width
;
12007 /* That loop always goes one position too far,
12008 including the glyph before the ellipsis.
12009 So scan forward over that one. */
12010 x
+= glyph
->pixel_width
;
12013 else if (string_start
12014 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
12016 /* We may have skipped over point because the previous glyphs
12017 are from string. As there's no easy way to know the
12018 character position of the current glyph, find the correct
12019 glyph on point by scanning from string_start again. */
12021 Lisp_Object string
;
12022 struct glyph
*stop
= glyph
;
12025 limit
= make_number (pt_old
+ 1);
12026 glyph
= string_start
;
12027 x
= string_start_x
;
12028 string
= glyph
->object
;
12029 pos
= string_buffer_position (w
, string
, string_before_pos
);
12030 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
12031 because we always put cursor after overlay strings. */
12032 while (pos
== 0 && glyph
< stop
)
12034 string
= glyph
->object
;
12035 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12037 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
12040 while (glyph
< stop
)
12042 pos
= XINT (Fnext_single_char_property_change
12043 (make_number (pos
), Qdisplay
, Qnil
, limit
));
12046 /* Skip glyphs from the same string. */
12047 string
= glyph
->object
;
12048 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12049 /* Skip glyphs from an overlay. */
12050 while (glyph
< stop
12051 && ! string_buffer_position (w
, glyph
->object
, pos
))
12053 string
= glyph
->object
;
12054 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12058 /* If we reached the end of the line, and end was from a string,
12059 cursor is not on this line. */
12060 if (glyph
== end
&& row
->continued_p
)
12064 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12066 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12067 w
->cursor
.y
= row
->y
+ dy
;
12069 if (w
== XWINDOW (selected_window
))
12071 if (!row
->continued_p
12072 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12075 this_line_buffer
= XBUFFER (w
->buffer
);
12077 CHARPOS (this_line_start_pos
)
12078 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12079 BYTEPOS (this_line_start_pos
)
12080 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12082 CHARPOS (this_line_end_pos
)
12083 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12084 BYTEPOS (this_line_end_pos
)
12085 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12087 this_line_y
= w
->cursor
.y
;
12088 this_line_pixel_height
= row
->height
;
12089 this_line_vpos
= w
->cursor
.vpos
;
12090 this_line_start_x
= row
->x
;
12093 CHARPOS (this_line_start_pos
) = 0;
12100 /* Run window scroll functions, if any, for WINDOW with new window
12101 start STARTP. Sets the window start of WINDOW to that position.
12103 We assume that the window's buffer is really current. */
12105 static INLINE
struct text_pos
12106 run_window_scroll_functions (window
, startp
)
12107 Lisp_Object window
;
12108 struct text_pos startp
;
12110 struct window
*w
= XWINDOW (window
);
12111 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12113 if (current_buffer
!= XBUFFER (w
->buffer
))
12116 if (!NILP (Vwindow_scroll_functions
))
12118 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12119 make_number (CHARPOS (startp
)));
12120 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12121 /* In case the hook functions switch buffers. */
12122 if (current_buffer
!= XBUFFER (w
->buffer
))
12123 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12130 /* Make sure the line containing the cursor is fully visible.
12131 A value of 1 means there is nothing to be done.
12132 (Either the line is fully visible, or it cannot be made so,
12133 or we cannot tell.)
12135 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12136 is higher than window.
12138 A value of 0 means the caller should do scrolling
12139 as if point had gone off the screen. */
12142 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12145 int current_matrix_p
;
12147 struct glyph_matrix
*matrix
;
12148 struct glyph_row
*row
;
12151 if (!make_cursor_line_fully_visible_p
)
12154 /* It's not always possible to find the cursor, e.g, when a window
12155 is full of overlay strings. Don't do anything in that case. */
12156 if (w
->cursor
.vpos
< 0)
12159 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12160 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12162 /* If the cursor row is not partially visible, there's nothing to do. */
12163 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12166 /* If the row the cursor is in is taller than the window's height,
12167 it's not clear what to do, so do nothing. */
12168 window_height
= window_box_height (w
);
12169 if (row
->height
>= window_height
)
12171 if (!force_p
|| MINI_WINDOW_P (w
)
12172 || w
->vscroll
|| w
->cursor
.vpos
== 0)
12178 /* This code used to try to scroll the window just enough to make
12179 the line visible. It returned 0 to say that the caller should
12180 allocate larger glyph matrices. */
12182 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
12184 int dy
= row
->height
- row
->visible_height
;
12187 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12189 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
12191 int dy
= - (row
->height
- row
->visible_height
);
12194 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12197 /* When we change the cursor y-position of the selected window,
12198 change this_line_y as well so that the display optimization for
12199 the cursor line of the selected window in redisplay_internal uses
12200 the correct y-position. */
12201 if (w
== XWINDOW (selected_window
))
12202 this_line_y
= w
->cursor
.y
;
12204 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
12205 redisplay with larger matrices. */
12206 if (matrix
->nrows
< required_matrix_height (w
))
12208 fonts_changed_p
= 1;
12217 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
12218 non-zero means only WINDOW is redisplayed in redisplay_internal.
12219 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
12220 in redisplay_window to bring a partially visible line into view in
12221 the case that only the cursor has moved.
12223 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
12224 last screen line's vertical height extends past the end of the screen.
12228 1 if scrolling succeeded
12230 0 if scrolling didn't find point.
12232 -1 if new fonts have been loaded so that we must interrupt
12233 redisplay, adjust glyph matrices, and try again. */
12239 SCROLLING_NEED_LARGER_MATRICES
12243 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
12244 scroll_step
, temp_scroll_step
, last_line_misfit
)
12245 Lisp_Object window
;
12246 int just_this_one_p
;
12247 EMACS_INT scroll_conservatively
, scroll_step
;
12248 int temp_scroll_step
;
12249 int last_line_misfit
;
12251 struct window
*w
= XWINDOW (window
);
12252 struct frame
*f
= XFRAME (w
->frame
);
12253 struct text_pos scroll_margin_pos
;
12254 struct text_pos pos
;
12255 struct text_pos startp
;
12257 Lisp_Object window_end
;
12258 int this_scroll_margin
;
12262 int amount_to_scroll
= 0;
12263 Lisp_Object aggressive
;
12265 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
12268 debug_method_add (w
, "try_scrolling");
12271 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12273 /* Compute scroll margin height in pixels. We scroll when point is
12274 within this distance from the top or bottom of the window. */
12275 if (scroll_margin
> 0)
12277 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12278 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12281 this_scroll_margin
= 0;
12283 /* Force scroll_conservatively to have a reasonable value so it doesn't
12284 cause an overflow while computing how much to scroll. */
12285 if (scroll_conservatively
)
12286 scroll_conservatively
= min (scroll_conservatively
,
12287 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
12289 /* Compute how much we should try to scroll maximally to bring point
12291 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
12292 scroll_max
= max (scroll_step
,
12293 max (scroll_conservatively
, temp_scroll_step
));
12294 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
12295 || NUMBERP (current_buffer
->scroll_up_aggressively
))
12296 /* We're trying to scroll because of aggressive scrolling
12297 but no scroll_step is set. Choose an arbitrary one. Maybe
12298 there should be a variable for this. */
12302 scroll_max
*= FRAME_LINE_HEIGHT (f
);
12304 /* Decide whether we have to scroll down. Start at the window end
12305 and move this_scroll_margin up to find the position of the scroll
12307 window_end
= Fwindow_end (window
, Qt
);
12311 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
12312 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
12314 if (this_scroll_margin
|| extra_scroll_margin_lines
)
12316 start_display (&it
, w
, scroll_margin_pos
);
12317 if (this_scroll_margin
)
12318 move_it_vertically_backward (&it
, this_scroll_margin
);
12319 if (extra_scroll_margin_lines
)
12320 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
12321 scroll_margin_pos
= it
.current
.pos
;
12324 if (PT
>= CHARPOS (scroll_margin_pos
))
12328 /* Point is in the scroll margin at the bottom of the window, or
12329 below. Compute a new window start that makes point visible. */
12331 /* Compute the distance from the scroll margin to PT.
12332 Give up if the distance is greater than scroll_max. */
12333 start_display (&it
, w
, scroll_margin_pos
);
12335 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12336 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12338 /* To make point visible, we have to move the window start
12339 down so that the line the cursor is in is visible, which
12340 means we have to add in the height of the cursor line. */
12341 dy
= line_bottom_y (&it
) - y0
;
12343 if (dy
> scroll_max
)
12344 return SCROLLING_FAILED
;
12346 /* Move the window start down. If scrolling conservatively,
12347 move it just enough down to make point visible. If
12348 scroll_step is set, move it down by scroll_step. */
12349 start_display (&it
, w
, startp
);
12351 if (scroll_conservatively
)
12352 /* Set AMOUNT_TO_SCROLL to at least one line,
12353 and at most scroll_conservatively lines. */
12355 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12356 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12357 else if (scroll_step
|| temp_scroll_step
)
12358 amount_to_scroll
= scroll_max
;
12361 aggressive
= current_buffer
->scroll_up_aggressively
;
12362 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12363 if (NUMBERP (aggressive
))
12365 double float_amount
= XFLOATINT (aggressive
) * height
;
12366 amount_to_scroll
= float_amount
;
12367 if (amount_to_scroll
== 0 && float_amount
> 0)
12368 amount_to_scroll
= 1;
12372 if (amount_to_scroll
<= 0)
12373 return SCROLLING_FAILED
;
12375 /* If moving by amount_to_scroll leaves STARTP unchanged,
12376 move it down one screen line. */
12378 move_it_vertically (&it
, amount_to_scroll
);
12379 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12380 move_it_by_lines (&it
, 1, 1);
12381 startp
= it
.current
.pos
;
12385 /* See if point is inside the scroll margin at the top of the
12387 scroll_margin_pos
= startp
;
12388 if (this_scroll_margin
)
12390 start_display (&it
, w
, startp
);
12391 move_it_vertically (&it
, this_scroll_margin
);
12392 scroll_margin_pos
= it
.current
.pos
;
12395 if (PT
< CHARPOS (scroll_margin_pos
))
12397 /* Point is in the scroll margin at the top of the window or
12398 above what is displayed in the window. */
12401 /* Compute the vertical distance from PT to the scroll
12402 margin position. Give up if distance is greater than
12404 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12405 start_display (&it
, w
, pos
);
12407 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12408 it
.last_visible_y
, -1,
12409 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12410 dy
= it
.current_y
- y0
;
12411 if (dy
> scroll_max
)
12412 return SCROLLING_FAILED
;
12414 /* Compute new window start. */
12415 start_display (&it
, w
, startp
);
12417 if (scroll_conservatively
)
12419 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12420 else if (scroll_step
|| temp_scroll_step
)
12421 amount_to_scroll
= scroll_max
;
12424 aggressive
= current_buffer
->scroll_down_aggressively
;
12425 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12426 if (NUMBERP (aggressive
))
12428 double float_amount
= XFLOATINT (aggressive
) * height
;
12429 amount_to_scroll
= float_amount
;
12430 if (amount_to_scroll
== 0 && float_amount
> 0)
12431 amount_to_scroll
= 1;
12435 if (amount_to_scroll
<= 0)
12436 return SCROLLING_FAILED
;
12438 move_it_vertically_backward (&it
, amount_to_scroll
);
12439 startp
= it
.current
.pos
;
12443 /* Run window scroll functions. */
12444 startp
= run_window_scroll_functions (window
, startp
);
12446 /* Display the window. Give up if new fonts are loaded, or if point
12448 if (!try_window (window
, startp
, 0))
12449 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12450 else if (w
->cursor
.vpos
< 0)
12452 clear_glyph_matrix (w
->desired_matrix
);
12453 rc
= SCROLLING_FAILED
;
12457 /* Maybe forget recorded base line for line number display. */
12458 if (!just_this_one_p
12459 || current_buffer
->clip_changed
12460 || BEG_UNCHANGED
< CHARPOS (startp
))
12461 w
->base_line_number
= Qnil
;
12463 /* If cursor ends up on a partially visible line,
12464 treat that as being off the bottom of the screen. */
12465 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12467 clear_glyph_matrix (w
->desired_matrix
);
12468 ++extra_scroll_margin_lines
;
12471 rc
= SCROLLING_SUCCESS
;
12478 /* Compute a suitable window start for window W if display of W starts
12479 on a continuation line. Value is non-zero if a new window start
12482 The new window start will be computed, based on W's width, starting
12483 from the start of the continued line. It is the start of the
12484 screen line with the minimum distance from the old start W->start. */
12487 compute_window_start_on_continuation_line (w
)
12490 struct text_pos pos
, start_pos
;
12491 int window_start_changed_p
= 0;
12493 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12495 /* If window start is on a continuation line... Window start may be
12496 < BEGV in case there's invisible text at the start of the
12497 buffer (M-x rmail, for example). */
12498 if (CHARPOS (start_pos
) > BEGV
12499 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12502 struct glyph_row
*row
;
12504 /* Handle the case that the window start is out of range. */
12505 if (CHARPOS (start_pos
) < BEGV
)
12506 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12507 else if (CHARPOS (start_pos
) > ZV
)
12508 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12510 /* Find the start of the continued line. This should be fast
12511 because scan_buffer is fast (newline cache). */
12512 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12513 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12514 row
, DEFAULT_FACE_ID
);
12515 reseat_at_previous_visible_line_start (&it
);
12517 /* If the line start is "too far" away from the window start,
12518 say it takes too much time to compute a new window start. */
12519 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12520 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12522 int min_distance
, distance
;
12524 /* Move forward by display lines to find the new window
12525 start. If window width was enlarged, the new start can
12526 be expected to be > the old start. If window width was
12527 decreased, the new window start will be < the old start.
12528 So, we're looking for the display line start with the
12529 minimum distance from the old window start. */
12530 pos
= it
.current
.pos
;
12531 min_distance
= INFINITY
;
12532 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12533 distance
< min_distance
)
12535 min_distance
= distance
;
12536 pos
= it
.current
.pos
;
12537 move_it_by_lines (&it
, 1, 0);
12540 /* Set the window start there. */
12541 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12542 window_start_changed_p
= 1;
12546 return window_start_changed_p
;
12550 /* Try cursor movement in case text has not changed in window WINDOW,
12551 with window start STARTP. Value is
12553 CURSOR_MOVEMENT_SUCCESS if successful
12555 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12557 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12558 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12559 we want to scroll as if scroll-step were set to 1. See the code.
12561 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12562 which case we have to abort this redisplay, and adjust matrices
12567 CURSOR_MOVEMENT_SUCCESS
,
12568 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12569 CURSOR_MOVEMENT_MUST_SCROLL
,
12570 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12574 try_cursor_movement (window
, startp
, scroll_step
)
12575 Lisp_Object window
;
12576 struct text_pos startp
;
12579 struct window
*w
= XWINDOW (window
);
12580 struct frame
*f
= XFRAME (w
->frame
);
12581 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12584 if (inhibit_try_cursor_movement
)
12588 /* Handle case where text has not changed, only point, and it has
12589 not moved off the frame. */
12590 if (/* Point may be in this window. */
12591 PT
>= CHARPOS (startp
)
12592 /* Selective display hasn't changed. */
12593 && !current_buffer
->clip_changed
12594 /* Function force-mode-line-update is used to force a thorough
12595 redisplay. It sets either windows_or_buffers_changed or
12596 update_mode_lines. So don't take a shortcut here for these
12598 && !update_mode_lines
12599 && !windows_or_buffers_changed
12600 && !cursor_type_changed
12601 /* Can't use this case if highlighting a region. When a
12602 region exists, cursor movement has to do more than just
12604 && !(!NILP (Vtransient_mark_mode
)
12605 && !NILP (current_buffer
->mark_active
))
12606 && NILP (w
->region_showing
)
12607 && NILP (Vshow_trailing_whitespace
)
12608 /* Right after splitting windows, last_point may be nil. */
12609 && INTEGERP (w
->last_point
)
12610 /* This code is not used for mini-buffer for the sake of the case
12611 of redisplaying to replace an echo area message; since in
12612 that case the mini-buffer contents per se are usually
12613 unchanged. This code is of no real use in the mini-buffer
12614 since the handling of this_line_start_pos, etc., in redisplay
12615 handles the same cases. */
12616 && !EQ (window
, minibuf_window
)
12617 /* When splitting windows or for new windows, it happens that
12618 redisplay is called with a nil window_end_vpos or one being
12619 larger than the window. This should really be fixed in
12620 window.c. I don't have this on my list, now, so we do
12621 approximately the same as the old redisplay code. --gerd. */
12622 && INTEGERP (w
->window_end_vpos
)
12623 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12624 && (FRAME_WINDOW_P (f
)
12625 || !overlay_arrow_in_current_buffer_p ()))
12627 int this_scroll_margin
, top_scroll_margin
;
12628 struct glyph_row
*row
= NULL
;
12631 debug_method_add (w
, "cursor movement");
12634 /* Scroll if point within this distance from the top or bottom
12635 of the window. This is a pixel value. */
12636 this_scroll_margin
= max (0, scroll_margin
);
12637 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12638 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12640 top_scroll_margin
= this_scroll_margin
;
12641 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12642 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12644 /* Start with the row the cursor was displayed during the last
12645 not paused redisplay. Give up if that row is not valid. */
12646 if (w
->last_cursor
.vpos
< 0
12647 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12648 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12651 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12652 if (row
->mode_line_p
)
12654 if (!row
->enabled_p
)
12655 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12658 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12661 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12663 if (PT
> XFASTINT (w
->last_point
))
12665 /* Point has moved forward. */
12666 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12667 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12669 xassert (row
->enabled_p
);
12673 /* The end position of a row equals the start position
12674 of the next row. If PT is there, we would rather
12675 display it in the next line. */
12676 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12677 && MATRIX_ROW_END_CHARPOS (row
) == PT
12678 && !cursor_row_p (w
, row
))
12681 /* If within the scroll margin, scroll. Note that
12682 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
12683 the next line would be drawn, and that
12684 this_scroll_margin can be zero. */
12685 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
12686 || PT
> MATRIX_ROW_END_CHARPOS (row
)
12687 /* Line is completely visible last line in window
12688 and PT is to be set in the next line. */
12689 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
12690 && PT
== MATRIX_ROW_END_CHARPOS (row
)
12691 && !row
->ends_at_zv_p
12692 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12695 else if (PT
< XFASTINT (w
->last_point
))
12697 /* Cursor has to be moved backward. Note that PT >=
12698 CHARPOS (startp) because of the outer if-statement. */
12699 while (!row
->mode_line_p
12700 && (MATRIX_ROW_START_CHARPOS (row
) > PT
12701 || (MATRIX_ROW_START_CHARPOS (row
) == PT
12702 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
12703 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
12704 row
> w
->current_matrix
->rows
12705 && (row
-1)->ends_in_newline_from_string_p
))))
12706 && (row
->y
> top_scroll_margin
12707 || CHARPOS (startp
) == BEGV
))
12709 xassert (row
->enabled_p
);
12713 /* Consider the following case: Window starts at BEGV,
12714 there is invisible, intangible text at BEGV, so that
12715 display starts at some point START > BEGV. It can
12716 happen that we are called with PT somewhere between
12717 BEGV and START. Try to handle that case. */
12718 if (row
< w
->current_matrix
->rows
12719 || row
->mode_line_p
)
12721 row
= w
->current_matrix
->rows
;
12722 if (row
->mode_line_p
)
12726 /* Due to newlines in overlay strings, we may have to
12727 skip forward over overlay strings. */
12728 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12729 && MATRIX_ROW_END_CHARPOS (row
) == PT
12730 && !cursor_row_p (w
, row
))
12733 /* If within the scroll margin, scroll. */
12734 if (row
->y
< top_scroll_margin
12735 && CHARPOS (startp
) != BEGV
)
12740 /* Cursor did not move. So don't scroll even if cursor line
12741 is partially visible, as it was so before. */
12742 rc
= CURSOR_MOVEMENT_SUCCESS
;
12745 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
12746 || PT
> MATRIX_ROW_END_CHARPOS (row
))
12748 /* if PT is not in the glyph row, give up. */
12749 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12751 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
12752 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
12753 && make_cursor_line_fully_visible_p
)
12755 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
12756 && !row
->ends_at_zv_p
12757 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12758 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12759 else if (row
->height
> window_box_height (w
))
12761 /* If we end up in a partially visible line, let's
12762 make it fully visible, except when it's taller
12763 than the window, in which case we can't do much
12766 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12770 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12771 if (!cursor_row_fully_visible_p (w
, 0, 1))
12772 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12774 rc
= CURSOR_MOVEMENT_SUCCESS
;
12778 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12783 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
12785 rc
= CURSOR_MOVEMENT_SUCCESS
;
12790 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12791 && MATRIX_ROW_START_CHARPOS (row
) == PT
12792 && cursor_row_p (w
, row
));
12801 set_vertical_scroll_bar (w
)
12804 int start
, end
, whole
;
12806 /* Calculate the start and end positions for the current window.
12807 At some point, it would be nice to choose between scrollbars
12808 which reflect the whole buffer size, with special markers
12809 indicating narrowing, and scrollbars which reflect only the
12812 Note that mini-buffers sometimes aren't displaying any text. */
12813 if (!MINI_WINDOW_P (w
)
12814 || (w
== XWINDOW (minibuf_window
)
12815 && NILP (echo_area_buffer
[0])))
12817 struct buffer
*buf
= XBUFFER (w
->buffer
);
12818 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12819 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12820 /* I don't think this is guaranteed to be right. For the
12821 moment, we'll pretend it is. */
12822 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12826 if (whole
< (end
- start
))
12827 whole
= end
- start
;
12830 start
= end
= whole
= 0;
12832 /* Indicate what this scroll bar ought to be displaying now. */
12833 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
12837 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
12838 selected_window is redisplayed.
12840 We can return without actually redisplaying the window if
12841 fonts_changed_p is nonzero. In that case, redisplay_internal will
12845 redisplay_window (window
, just_this_one_p
)
12846 Lisp_Object window
;
12847 int just_this_one_p
;
12849 struct window
*w
= XWINDOW (window
);
12850 struct frame
*f
= XFRAME (w
->frame
);
12851 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12852 struct buffer
*old
= current_buffer
;
12853 struct text_pos lpoint
, opoint
, startp
;
12854 int update_mode_line
;
12857 /* Record it now because it's overwritten. */
12858 int current_matrix_up_to_date_p
= 0;
12859 int used_current_matrix_p
= 0;
12860 /* This is less strict than current_matrix_up_to_date_p.
12861 It indictes that the buffer contents and narrowing are unchanged. */
12862 int buffer_unchanged_p
= 0;
12863 int temp_scroll_step
= 0;
12864 int count
= SPECPDL_INDEX ();
12866 int centering_position
= -1;
12867 int last_line_misfit
= 0;
12868 int save_beg_unchanged
, save_end_unchanged
;
12870 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12873 /* W must be a leaf window here. */
12874 xassert (!NILP (w
->buffer
));
12876 *w
->desired_matrix
->method
= 0;
12879 specbind (Qinhibit_point_motion_hooks
, Qt
);
12881 reconsider_clip_changes (w
, buffer
);
12883 /* Has the mode line to be updated? */
12884 update_mode_line
= (!NILP (w
->update_mode_line
)
12885 || update_mode_lines
12886 || buffer
->clip_changed
12887 || buffer
->prevent_redisplay_optimizations_p
);
12889 if (MINI_WINDOW_P (w
))
12891 if (w
== XWINDOW (echo_area_window
)
12892 && !NILP (echo_area_buffer
[0]))
12894 if (update_mode_line
)
12895 /* We may have to update a tty frame's menu bar or a
12896 tool-bar. Example `M-x C-h C-h C-g'. */
12897 goto finish_menu_bars
;
12899 /* We've already displayed the echo area glyphs in this window. */
12900 goto finish_scroll_bars
;
12902 else if ((w
!= XWINDOW (minibuf_window
)
12903 || minibuf_level
== 0)
12904 /* When buffer is nonempty, redisplay window normally. */
12905 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12906 /* Quail displays non-mini buffers in minibuffer window.
12907 In that case, redisplay the window normally. */
12908 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12910 /* W is a mini-buffer window, but it's not active, so clear
12912 int yb
= window_text_bottom_y (w
);
12913 struct glyph_row
*row
;
12916 for (y
= 0, row
= w
->desired_matrix
->rows
;
12918 y
+= row
->height
, ++row
)
12919 blank_row (w
, row
, y
);
12920 goto finish_scroll_bars
;
12923 clear_glyph_matrix (w
->desired_matrix
);
12926 /* Otherwise set up data on this window; select its buffer and point
12928 /* Really select the buffer, for the sake of buffer-local
12930 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12931 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12933 save_beg_unchanged
= BEG_UNCHANGED
;
12934 save_end_unchanged
= END_UNCHANGED
;
12936 current_matrix_up_to_date_p
12937 = (!NILP (w
->window_end_valid
)
12938 && !current_buffer
->clip_changed
12939 && !current_buffer
->prevent_redisplay_optimizations_p
12940 && XFASTINT (w
->last_modified
) >= MODIFF
12941 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12944 = (!NILP (w
->window_end_valid
)
12945 && !current_buffer
->clip_changed
12946 && XFASTINT (w
->last_modified
) >= MODIFF
12947 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12949 /* When windows_or_buffers_changed is non-zero, we can't rely on
12950 the window end being valid, so set it to nil there. */
12951 if (windows_or_buffers_changed
)
12953 /* If window starts on a continuation line, maybe adjust the
12954 window start in case the window's width changed. */
12955 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12956 compute_window_start_on_continuation_line (w
);
12958 w
->window_end_valid
= Qnil
;
12961 /* Some sanity checks. */
12962 CHECK_WINDOW_END (w
);
12963 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12965 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12968 /* If %c is in mode line, update it if needed. */
12969 if (!NILP (w
->column_number_displayed
)
12970 /* This alternative quickly identifies a common case
12971 where no change is needed. */
12972 && !(PT
== XFASTINT (w
->last_point
)
12973 && XFASTINT (w
->last_modified
) >= MODIFF
12974 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12975 && (XFASTINT (w
->column_number_displayed
)
12976 != (int) current_column ())) /* iftc */
12977 update_mode_line
= 1;
12979 /* Count number of windows showing the selected buffer. An indirect
12980 buffer counts as its base buffer. */
12981 if (!just_this_one_p
)
12983 struct buffer
*current_base
, *window_base
;
12984 current_base
= current_buffer
;
12985 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12986 if (current_base
->base_buffer
)
12987 current_base
= current_base
->base_buffer
;
12988 if (window_base
->base_buffer
)
12989 window_base
= window_base
->base_buffer
;
12990 if (current_base
== window_base
)
12994 /* Point refers normally to the selected window. For any other
12995 window, set up appropriate value. */
12996 if (!EQ (window
, selected_window
))
12998 int new_pt
= XMARKER (w
->pointm
)->charpos
;
12999 int new_pt_byte
= marker_byte_position (w
->pointm
);
13003 new_pt_byte
= BEGV_BYTE
;
13004 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13006 else if (new_pt
> (ZV
- 1))
13009 new_pt_byte
= ZV_BYTE
;
13010 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13013 /* We don't use SET_PT so that the point-motion hooks don't run. */
13014 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
13017 /* If any of the character widths specified in the display table
13018 have changed, invalidate the width run cache. It's true that
13019 this may be a bit late to catch such changes, but the rest of
13020 redisplay goes (non-fatally) haywire when the display table is
13021 changed, so why should we worry about doing any better? */
13022 if (current_buffer
->width_run_cache
)
13024 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
13026 if (! disptab_matches_widthtab (disptab
,
13027 XVECTOR (current_buffer
->width_table
)))
13029 invalidate_region_cache (current_buffer
,
13030 current_buffer
->width_run_cache
,
13032 recompute_width_table (current_buffer
, disptab
);
13036 /* If window-start is screwed up, choose a new one. */
13037 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
13040 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13042 /* If someone specified a new starting point but did not insist,
13043 check whether it can be used. */
13044 if (!NILP (w
->optional_new_start
)
13045 && CHARPOS (startp
) >= BEGV
13046 && CHARPOS (startp
) <= ZV
)
13048 w
->optional_new_start
= Qnil
;
13049 start_display (&it
, w
, startp
);
13050 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
13051 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13052 if (IT_CHARPOS (it
) == PT
)
13053 w
->force_start
= Qt
;
13054 /* IT may overshoot PT if text at PT is invisible. */
13055 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
13056 w
->force_start
= Qt
;
13061 /* Handle case where place to start displaying has been specified,
13062 unless the specified location is outside the accessible range. */
13063 if (!NILP (w
->force_start
)
13064 || w
->frozen_window_start_p
)
13066 /* We set this later on if we have to adjust point. */
13070 w
->force_start
= Qnil
;
13072 w
->window_end_valid
= Qnil
;
13074 /* Forget any recorded base line for line number display. */
13075 if (!buffer_unchanged_p
)
13076 w
->base_line_number
= Qnil
;
13078 /* Redisplay the mode line. Select the buffer properly for that.
13079 Also, run the hook window-scroll-functions
13080 because we have scrolled. */
13081 /* Note, we do this after clearing force_start because
13082 if there's an error, it is better to forget about force_start
13083 than to get into an infinite loop calling the hook functions
13084 and having them get more errors. */
13085 if (!update_mode_line
13086 || ! NILP (Vwindow_scroll_functions
))
13088 update_mode_line
= 1;
13089 w
->update_mode_line
= Qt
;
13090 startp
= run_window_scroll_functions (window
, startp
);
13093 w
->last_modified
= make_number (0);
13094 w
->last_overlay_modified
= make_number (0);
13095 if (CHARPOS (startp
) < BEGV
)
13096 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
13097 else if (CHARPOS (startp
) > ZV
)
13098 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
13100 /* Redisplay, then check if cursor has been set during the
13101 redisplay. Give up if new fonts were loaded. */
13102 val
= try_window (window
, startp
, 1);
13105 w
->force_start
= Qt
;
13106 clear_glyph_matrix (w
->desired_matrix
);
13107 goto need_larger_matrices
;
13109 /* Point was outside the scroll margins. */
13111 new_vpos
= window_box_height (w
) / 2;
13113 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
13115 /* If point does not appear, try to move point so it does
13116 appear. The desired matrix has been built above, so we
13117 can use it here. */
13118 new_vpos
= window_box_height (w
) / 2;
13121 if (!cursor_row_fully_visible_p (w
, 0, 0))
13123 /* Point does appear, but on a line partly visible at end of window.
13124 Move it back to a fully-visible line. */
13125 new_vpos
= window_box_height (w
);
13128 /* If we need to move point for either of the above reasons,
13129 now actually do it. */
13132 struct glyph_row
*row
;
13134 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13135 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13138 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13139 MATRIX_ROW_START_BYTEPOS (row
));
13141 if (w
!= XWINDOW (selected_window
))
13142 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13143 else if (current_buffer
== old
)
13144 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13146 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13148 /* If we are highlighting the region, then we just changed
13149 the region, so redisplay to show it. */
13150 if (!NILP (Vtransient_mark_mode
)
13151 && !NILP (current_buffer
->mark_active
))
13153 clear_glyph_matrix (w
->desired_matrix
);
13154 if (!try_window (window
, startp
, 0))
13155 goto need_larger_matrices
;
13160 debug_method_add (w
, "forced window start");
13165 /* Handle case where text has not changed, only point, and it has
13166 not moved off the frame, and we are not retrying after hscroll.
13167 (current_matrix_up_to_date_p is nonzero when retrying.) */
13168 if (current_matrix_up_to_date_p
13169 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13170 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13174 case CURSOR_MOVEMENT_SUCCESS
:
13175 used_current_matrix_p
= 1;
13178 #if 0 /* try_cursor_movement never returns this value. */
13179 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
13180 goto need_larger_matrices
;
13183 case CURSOR_MOVEMENT_MUST_SCROLL
:
13184 goto try_to_scroll
;
13190 /* If current starting point was originally the beginning of a line
13191 but no longer is, find a new starting point. */
13192 else if (!NILP (w
->start_at_line_beg
)
13193 && !(CHARPOS (startp
) <= BEGV
13194 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13197 debug_method_add (w
, "recenter 1");
13202 /* Try scrolling with try_window_id. Value is > 0 if update has
13203 been done, it is -1 if we know that the same window start will
13204 not work. It is 0 if unsuccessful for some other reason. */
13205 else if ((tem
= try_window_id (w
)) != 0)
13208 debug_method_add (w
, "try_window_id %d", tem
);
13211 if (fonts_changed_p
)
13212 goto need_larger_matrices
;
13216 /* Otherwise try_window_id has returned -1 which means that we
13217 don't want the alternative below this comment to execute. */
13219 else if (CHARPOS (startp
) >= BEGV
13220 && CHARPOS (startp
) <= ZV
13221 && PT
>= CHARPOS (startp
)
13222 && (CHARPOS (startp
) < ZV
13223 /* Avoid starting at end of buffer. */
13224 || CHARPOS (startp
) == BEGV
13225 || (XFASTINT (w
->last_modified
) >= MODIFF
13226 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
13229 /* If first window line is a continuation line, and window start
13230 is inside the modified region, but the first change is before
13231 current window start, we must select a new window start.
13233 However, if this is the result of a down-mouse event (e.g. by
13234 extending the mouse-drag-overlay), we don't want to select a
13235 new window start, since that would change the position under
13236 the mouse, resulting in an unwanted mouse-movement rather
13237 than a simple mouse-click. */
13238 if (NILP (w
->start_at_line_beg
)
13239 && NILP (do_mouse_tracking
)
13240 && CHARPOS (startp
) > BEGV
13241 && CHARPOS (startp
) > BEG
+ save_beg_unchanged
13242 && CHARPOS (startp
) <= Z
- save_end_unchanged
)
13244 w
->force_start
= Qt
;
13245 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13246 compute_window_start_on_continuation_line (w
);
13247 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13252 debug_method_add (w
, "same window start");
13255 /* Try to redisplay starting at same place as before.
13256 If point has not moved off frame, accept the results. */
13257 if (!current_matrix_up_to_date_p
13258 /* Don't use try_window_reusing_current_matrix in this case
13259 because a window scroll function can have changed the
13261 || !NILP (Vwindow_scroll_functions
)
13262 || MINI_WINDOW_P (w
)
13263 || !(used_current_matrix_p
13264 = try_window_reusing_current_matrix (w
)))
13266 IF_DEBUG (debug_method_add (w
, "1"));
13267 if (try_window (window
, startp
, 1) < 0)
13268 /* -1 means we need to scroll.
13269 0 means we need new matrices, but fonts_changed_p
13270 is set in that case, so we will detect it below. */
13271 goto try_to_scroll
;
13274 if (fonts_changed_p
)
13275 goto need_larger_matrices
;
13277 if (w
->cursor
.vpos
>= 0)
13279 if (!just_this_one_p
13280 || current_buffer
->clip_changed
13281 || BEG_UNCHANGED
< CHARPOS (startp
))
13282 /* Forget any recorded base line for line number display. */
13283 w
->base_line_number
= Qnil
;
13285 if (!cursor_row_fully_visible_p (w
, 1, 0))
13287 clear_glyph_matrix (w
->desired_matrix
);
13288 last_line_misfit
= 1;
13290 /* Drop through and scroll. */
13295 clear_glyph_matrix (w
->desired_matrix
);
13300 w
->last_modified
= make_number (0);
13301 w
->last_overlay_modified
= make_number (0);
13303 /* Redisplay the mode line. Select the buffer properly for that. */
13304 if (!update_mode_line
)
13306 update_mode_line
= 1;
13307 w
->update_mode_line
= Qt
;
13310 /* Try to scroll by specified few lines. */
13311 if ((scroll_conservatively
13313 || temp_scroll_step
13314 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13315 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13316 && !current_buffer
->clip_changed
13317 && CHARPOS (startp
) >= BEGV
13318 && CHARPOS (startp
) <= ZV
)
13320 /* The function returns -1 if new fonts were loaded, 1 if
13321 successful, 0 if not successful. */
13322 int rc
= try_scrolling (window
, just_this_one_p
,
13323 scroll_conservatively
,
13325 temp_scroll_step
, last_line_misfit
);
13328 case SCROLLING_SUCCESS
:
13331 case SCROLLING_NEED_LARGER_MATRICES
:
13332 goto need_larger_matrices
;
13334 case SCROLLING_FAILED
:
13342 /* Finally, just choose place to start which centers point */
13345 if (centering_position
< 0)
13346 centering_position
= window_box_height (w
) / 2;
13349 debug_method_add (w
, "recenter");
13352 /* w->vscroll = 0; */
13354 /* Forget any previously recorded base line for line number display. */
13355 if (!buffer_unchanged_p
)
13356 w
->base_line_number
= Qnil
;
13358 /* Move backward half the height of the window. */
13359 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13360 it
.current_y
= it
.last_visible_y
;
13361 move_it_vertically_backward (&it
, centering_position
);
13362 xassert (IT_CHARPOS (it
) >= BEGV
);
13364 /* The function move_it_vertically_backward may move over more
13365 than the specified y-distance. If it->w is small, e.g. a
13366 mini-buffer window, we may end up in front of the window's
13367 display area. Start displaying at the start of the line
13368 containing PT in this case. */
13369 if (it
.current_y
<= 0)
13371 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13372 move_it_vertically_backward (&it
, 0);
13374 /* I think this assert is bogus if buffer contains
13375 invisible text or images. KFS. */
13376 xassert (IT_CHARPOS (it
) <= PT
);
13381 it
.current_x
= it
.hpos
= 0;
13383 /* Set startp here explicitly in case that helps avoid an infinite loop
13384 in case the window-scroll-functions functions get errors. */
13385 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13387 /* Run scroll hooks. */
13388 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13390 /* Redisplay the window. */
13391 if (!current_matrix_up_to_date_p
13392 || windows_or_buffers_changed
13393 || cursor_type_changed
13394 /* Don't use try_window_reusing_current_matrix in this case
13395 because it can have changed the buffer. */
13396 || !NILP (Vwindow_scroll_functions
)
13397 || !just_this_one_p
13398 || MINI_WINDOW_P (w
)
13399 || !(used_current_matrix_p
13400 = try_window_reusing_current_matrix (w
)))
13401 try_window (window
, startp
, 0);
13403 /* If new fonts have been loaded (due to fontsets), give up. We
13404 have to start a new redisplay since we need to re-adjust glyph
13406 if (fonts_changed_p
)
13407 goto need_larger_matrices
;
13409 /* If cursor did not appear assume that the middle of the window is
13410 in the first line of the window. Do it again with the next line.
13411 (Imagine a window of height 100, displaying two lines of height
13412 60. Moving back 50 from it->last_visible_y will end in the first
13414 if (w
->cursor
.vpos
< 0)
13416 if (!NILP (w
->window_end_valid
)
13417 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13419 clear_glyph_matrix (w
->desired_matrix
);
13420 move_it_by_lines (&it
, 1, 0);
13421 try_window (window
, it
.current
.pos
, 0);
13423 else if (PT
< IT_CHARPOS (it
))
13425 clear_glyph_matrix (w
->desired_matrix
);
13426 move_it_by_lines (&it
, -1, 0);
13427 try_window (window
, it
.current
.pos
, 0);
13431 /* Not much we can do about it. */
13435 /* Consider the following case: Window starts at BEGV, there is
13436 invisible, intangible text at BEGV, so that display starts at
13437 some point START > BEGV. It can happen that we are called with
13438 PT somewhere between BEGV and START. Try to handle that case. */
13439 if (w
->cursor
.vpos
< 0)
13441 struct glyph_row
*row
= w
->current_matrix
->rows
;
13442 if (row
->mode_line_p
)
13444 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13447 if (!cursor_row_fully_visible_p (w
, 0, 0))
13449 /* If vscroll is enabled, disable it and try again. */
13453 clear_glyph_matrix (w
->desired_matrix
);
13457 /* If centering point failed to make the whole line visible,
13458 put point at the top instead. That has to make the whole line
13459 visible, if it can be done. */
13460 if (centering_position
== 0)
13463 clear_glyph_matrix (w
->desired_matrix
);
13464 centering_position
= 0;
13470 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13471 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13472 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13475 /* Display the mode line, if we must. */
13476 if ((update_mode_line
13477 /* If window not full width, must redo its mode line
13478 if (a) the window to its side is being redone and
13479 (b) we do a frame-based redisplay. This is a consequence
13480 of how inverted lines are drawn in frame-based redisplay. */
13481 || (!just_this_one_p
13482 && !FRAME_WINDOW_P (f
)
13483 && !WINDOW_FULL_WIDTH_P (w
))
13484 /* Line number to display. */
13485 || INTEGERP (w
->base_line_pos
)
13486 /* Column number is displayed and different from the one displayed. */
13487 || (!NILP (w
->column_number_displayed
)
13488 && (XFASTINT (w
->column_number_displayed
)
13489 != (int) current_column ()))) /* iftc */
13490 /* This means that the window has a mode line. */
13491 && (WINDOW_WANTS_MODELINE_P (w
)
13492 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13494 display_mode_lines (w
);
13496 /* If mode line height has changed, arrange for a thorough
13497 immediate redisplay using the correct mode line height. */
13498 if (WINDOW_WANTS_MODELINE_P (w
)
13499 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13501 fonts_changed_p
= 1;
13502 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13503 = DESIRED_MODE_LINE_HEIGHT (w
);
13506 /* If top line height has changed, arrange for a thorough
13507 immediate redisplay using the correct mode line height. */
13508 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13509 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13511 fonts_changed_p
= 1;
13512 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13513 = DESIRED_HEADER_LINE_HEIGHT (w
);
13516 if (fonts_changed_p
)
13517 goto need_larger_matrices
;
13520 if (!line_number_displayed
13521 && !BUFFERP (w
->base_line_pos
))
13523 w
->base_line_pos
= Qnil
;
13524 w
->base_line_number
= Qnil
;
13529 /* When we reach a frame's selected window, redo the frame's menu bar. */
13530 if (update_mode_line
13531 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13533 int redisplay_menu_p
= 0;
13534 int redisplay_tool_bar_p
= 0;
13536 if (FRAME_WINDOW_P (f
))
13538 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
13539 || defined (USE_GTK)
13540 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13542 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13546 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13548 if (redisplay_menu_p
)
13549 display_menu_bar (w
);
13551 #ifdef HAVE_WINDOW_SYSTEM
13552 #if defined (USE_GTK) || USE_MAC_TOOLBAR
13553 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13555 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13556 && (FRAME_TOOL_BAR_LINES (f
) > 0
13557 || !NILP (Vauto_resize_tool_bars
));
13561 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
13563 extern int ignore_mouse_drag_p
;
13564 ignore_mouse_drag_p
= 1;
13569 #ifdef HAVE_WINDOW_SYSTEM
13570 if (FRAME_WINDOW_P (f
)
13571 && update_window_fringes (w
, (just_this_one_p
13572 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13573 || w
->pseudo_window_p
)))
13577 if (draw_window_fringes (w
, 1))
13578 x_draw_vertical_border (w
);
13582 #endif /* HAVE_WINDOW_SYSTEM */
13584 /* We go to this label, with fonts_changed_p nonzero,
13585 if it is necessary to try again using larger glyph matrices.
13586 We have to redeem the scroll bar even in this case,
13587 because the loop in redisplay_internal expects that. */
13588 need_larger_matrices
:
13590 finish_scroll_bars
:
13592 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13594 /* Set the thumb's position and size. */
13595 set_vertical_scroll_bar (w
);
13597 /* Note that we actually used the scroll bar attached to this
13598 window, so it shouldn't be deleted at the end of redisplay. */
13599 redeem_scroll_bar_hook (w
);
13602 /* Restore current_buffer and value of point in it. */
13603 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13604 set_buffer_internal_1 (old
);
13605 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
13606 shorter. This can be caused by log truncation in *Messages*. */
13607 if (CHARPOS (lpoint
) <= ZV
)
13608 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13610 unbind_to (count
, Qnil
);
13614 /* Build the complete desired matrix of WINDOW with a window start
13615 buffer position POS.
13617 Value is 1 if successful. It is zero if fonts were loaded during
13618 redisplay which makes re-adjusting glyph matrices necessary, and -1
13619 if point would appear in the scroll margins.
13620 (We check that only if CHECK_MARGINS is nonzero. */
13623 try_window (window
, pos
, check_margins
)
13624 Lisp_Object window
;
13625 struct text_pos pos
;
13628 struct window
*w
= XWINDOW (window
);
13630 struct glyph_row
*last_text_row
= NULL
;
13631 struct frame
*f
= XFRAME (w
->frame
);
13633 /* Make POS the new window start. */
13634 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13636 /* Mark cursor position as unknown. No overlay arrow seen. */
13637 w
->cursor
.vpos
= -1;
13638 overlay_arrow_seen
= 0;
13640 /* Initialize iterator and info to start at POS. */
13641 start_display (&it
, w
, pos
);
13643 /* Display all lines of W. */
13644 while (it
.current_y
< it
.last_visible_y
)
13646 if (display_line (&it
))
13647 last_text_row
= it
.glyph_row
- 1;
13648 if (fonts_changed_p
)
13652 /* Don't let the cursor end in the scroll margins. */
13654 && !MINI_WINDOW_P (w
))
13656 int this_scroll_margin
;
13658 this_scroll_margin
= max (0, scroll_margin
);
13659 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13660 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13662 if ((w
->cursor
.y
>= 0 /* not vscrolled */
13663 && w
->cursor
.y
< this_scroll_margin
13664 && CHARPOS (pos
) > BEGV
13665 && IT_CHARPOS (it
) < ZV
)
13666 /* rms: considering make_cursor_line_fully_visible_p here
13667 seems to give wrong results. We don't want to recenter
13668 when the last line is partly visible, we want to allow
13669 that case to be handled in the usual way. */
13670 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
13672 w
->cursor
.vpos
= -1;
13673 clear_glyph_matrix (w
->desired_matrix
);
13678 /* If bottom moved off end of frame, change mode line percentage. */
13679 if (XFASTINT (w
->window_end_pos
) <= 0
13680 && Z
!= IT_CHARPOS (it
))
13681 w
->update_mode_line
= Qt
;
13683 /* Set window_end_pos to the offset of the last character displayed
13684 on the window from the end of current_buffer. Set
13685 window_end_vpos to its row number. */
13688 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
13689 w
->window_end_bytepos
13690 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13692 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13694 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13695 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
13696 ->displays_text_p
);
13700 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13701 w
->window_end_pos
= make_number (Z
- ZV
);
13702 w
->window_end_vpos
= make_number (0);
13705 /* But that is not valid info until redisplay finishes. */
13706 w
->window_end_valid
= Qnil
;
13712 /************************************************************************
13713 Window redisplay reusing current matrix when buffer has not changed
13714 ************************************************************************/
13716 /* Try redisplay of window W showing an unchanged buffer with a
13717 different window start than the last time it was displayed by
13718 reusing its current matrix. Value is non-zero if successful.
13719 W->start is the new window start. */
13722 try_window_reusing_current_matrix (w
)
13725 struct frame
*f
= XFRAME (w
->frame
);
13726 struct glyph_row
*row
, *bottom_row
;
13729 struct text_pos start
, new_start
;
13730 int nrows_scrolled
, i
;
13731 struct glyph_row
*last_text_row
;
13732 struct glyph_row
*last_reused_text_row
;
13733 struct glyph_row
*start_row
;
13734 int start_vpos
, min_y
, max_y
;
13737 if (inhibit_try_window_reusing
)
13741 if (/* This function doesn't handle terminal frames. */
13742 !FRAME_WINDOW_P (f
)
13743 /* Don't try to reuse the display if windows have been split
13745 || windows_or_buffers_changed
13746 || cursor_type_changed
)
13749 /* Can't do this if region may have changed. */
13750 if ((!NILP (Vtransient_mark_mode
)
13751 && !NILP (current_buffer
->mark_active
))
13752 || !NILP (w
->region_showing
)
13753 || !NILP (Vshow_trailing_whitespace
))
13756 /* If top-line visibility has changed, give up. */
13757 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13758 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
13761 /* Give up if old or new display is scrolled vertically. We could
13762 make this function handle this, but right now it doesn't. */
13763 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13764 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
13767 /* The variable new_start now holds the new window start. The old
13768 start `start' can be determined from the current matrix. */
13769 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
13770 start
= start_row
->start
.pos
;
13771 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13773 /* Clear the desired matrix for the display below. */
13774 clear_glyph_matrix (w
->desired_matrix
);
13776 if (CHARPOS (new_start
) <= CHARPOS (start
))
13780 /* Don't use this method if the display starts with an ellipsis
13781 displayed for invisible text. It's not easy to handle that case
13782 below, and it's certainly not worth the effort since this is
13783 not a frequent case. */
13784 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
13787 IF_DEBUG (debug_method_add (w
, "twu1"));
13789 /* Display up to a row that can be reused. The variable
13790 last_text_row is set to the last row displayed that displays
13791 text. Note that it.vpos == 0 if or if not there is a
13792 header-line; it's not the same as the MATRIX_ROW_VPOS! */
13793 start_display (&it
, w
, new_start
);
13794 first_row_y
= it
.current_y
;
13795 w
->cursor
.vpos
= -1;
13796 last_text_row
= last_reused_text_row
= NULL
;
13798 while (it
.current_y
< it
.last_visible_y
13799 && !fonts_changed_p
)
13801 /* If we have reached into the characters in the START row,
13802 that means the line boundaries have changed. So we
13803 can't start copying with the row START. Maybe it will
13804 work to start copying with the following row. */
13805 while (IT_CHARPOS (it
) > CHARPOS (start
))
13807 /* Advance to the next row as the "start". */
13809 start
= start_row
->start
.pos
;
13810 /* If there are no more rows to try, or just one, give up. */
13811 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
13812 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
13813 || CHARPOS (start
) == ZV
)
13815 clear_glyph_matrix (w
->desired_matrix
);
13819 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13821 /* If we have reached alignment,
13822 we can copy the rest of the rows. */
13823 if (IT_CHARPOS (it
) == CHARPOS (start
))
13826 if (display_line (&it
))
13827 last_text_row
= it
.glyph_row
- 1;
13830 /* A value of current_y < last_visible_y means that we stopped
13831 at the previous window start, which in turn means that we
13832 have at least one reusable row. */
13833 if (it
.current_y
< it
.last_visible_y
)
13835 /* IT.vpos always starts from 0; it counts text lines. */
13836 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
13838 /* Find PT if not already found in the lines displayed. */
13839 if (w
->cursor
.vpos
< 0)
13841 int dy
= it
.current_y
- start_row
->y
;
13843 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13844 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
13846 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
13847 dy
, nrows_scrolled
);
13850 clear_glyph_matrix (w
->desired_matrix
);
13855 /* Scroll the display. Do it before the current matrix is
13856 changed. The problem here is that update has not yet
13857 run, i.e. part of the current matrix is not up to date.
13858 scroll_run_hook will clear the cursor, and use the
13859 current matrix to get the height of the row the cursor is
13861 run
.current_y
= start_row
->y
;
13862 run
.desired_y
= it
.current_y
;
13863 run
.height
= it
.last_visible_y
- it
.current_y
;
13865 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
13868 rif
->update_window_begin_hook (w
);
13869 rif
->clear_window_mouse_face (w
);
13870 rif
->scroll_run_hook (w
, &run
);
13871 rif
->update_window_end_hook (w
, 0, 0);
13875 /* Shift current matrix down by nrows_scrolled lines. */
13876 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13877 rotate_matrix (w
->current_matrix
,
13879 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13882 /* Disable lines that must be updated. */
13883 for (i
= 0; i
< nrows_scrolled
; ++i
)
13884 (start_row
+ i
)->enabled_p
= 0;
13886 /* Re-compute Y positions. */
13887 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13888 max_y
= it
.last_visible_y
;
13889 for (row
= start_row
+ nrows_scrolled
;
13893 row
->y
= it
.current_y
;
13894 row
->visible_height
= row
->height
;
13896 if (row
->y
< min_y
)
13897 row
->visible_height
-= min_y
- row
->y
;
13898 if (row
->y
+ row
->height
> max_y
)
13899 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13900 row
->redraw_fringe_bitmaps_p
= 1;
13902 it
.current_y
+= row
->height
;
13904 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13905 last_reused_text_row
= row
;
13906 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13910 /* Disable lines in the current matrix which are now
13911 below the window. */
13912 for (++row
; row
< bottom_row
; ++row
)
13913 row
->enabled_p
= row
->mode_line_p
= 0;
13916 /* Update window_end_pos etc.; last_reused_text_row is the last
13917 reused row from the current matrix containing text, if any.
13918 The value of last_text_row is the last displayed line
13919 containing text. */
13920 if (last_reused_text_row
)
13922 w
->window_end_bytepos
13923 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13925 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13927 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13928 w
->current_matrix
));
13930 else if (last_text_row
)
13932 w
->window_end_bytepos
13933 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13935 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13937 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13941 /* This window must be completely empty. */
13942 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13943 w
->window_end_pos
= make_number (Z
- ZV
);
13944 w
->window_end_vpos
= make_number (0);
13946 w
->window_end_valid
= Qnil
;
13948 /* Update hint: don't try scrolling again in update_window. */
13949 w
->desired_matrix
->no_scrolling_p
= 1;
13952 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13956 else if (CHARPOS (new_start
) > CHARPOS (start
))
13958 struct glyph_row
*pt_row
, *row
;
13959 struct glyph_row
*first_reusable_row
;
13960 struct glyph_row
*first_row_to_display
;
13962 int yb
= window_text_bottom_y (w
);
13964 /* Find the row starting at new_start, if there is one. Don't
13965 reuse a partially visible line at the end. */
13966 first_reusable_row
= start_row
;
13967 while (first_reusable_row
->enabled_p
13968 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13969 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13970 < CHARPOS (new_start
)))
13971 ++first_reusable_row
;
13973 /* Give up if there is no row to reuse. */
13974 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13975 || !first_reusable_row
->enabled_p
13976 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13977 != CHARPOS (new_start
)))
13980 /* We can reuse fully visible rows beginning with
13981 first_reusable_row to the end of the window. Set
13982 first_row_to_display to the first row that cannot be reused.
13983 Set pt_row to the row containing point, if there is any. */
13985 for (first_row_to_display
= first_reusable_row
;
13986 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13987 ++first_row_to_display
)
13989 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
13990 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
13991 pt_row
= first_row_to_display
;
13994 /* Start displaying at the start of first_row_to_display. */
13995 xassert (first_row_to_display
->y
< yb
);
13996 init_to_row_start (&it
, w
, first_row_to_display
);
13998 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
14000 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
14002 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
14003 + WINDOW_HEADER_LINE_HEIGHT (w
));
14005 /* Display lines beginning with first_row_to_display in the
14006 desired matrix. Set last_text_row to the last row displayed
14007 that displays text. */
14008 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
14009 if (pt_row
== NULL
)
14010 w
->cursor
.vpos
= -1;
14011 last_text_row
= NULL
;
14012 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
14013 if (display_line (&it
))
14014 last_text_row
= it
.glyph_row
- 1;
14016 /* Give up If point isn't in a row displayed or reused. */
14017 if (w
->cursor
.vpos
< 0)
14019 clear_glyph_matrix (w
->desired_matrix
);
14023 /* If point is in a reused row, adjust y and vpos of the cursor
14027 w
->cursor
.vpos
-= nrows_scrolled
;
14028 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
14031 /* Scroll the display. */
14032 run
.current_y
= first_reusable_row
->y
;
14033 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14034 run
.height
= it
.last_visible_y
- run
.current_y
;
14035 dy
= run
.current_y
- run
.desired_y
;
14040 rif
->update_window_begin_hook (w
);
14041 rif
->clear_window_mouse_face (w
);
14042 rif
->scroll_run_hook (w
, &run
);
14043 rif
->update_window_end_hook (w
, 0, 0);
14047 /* Adjust Y positions of reused rows. */
14048 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14049 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14050 max_y
= it
.last_visible_y
;
14051 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
14054 row
->visible_height
= row
->height
;
14055 if (row
->y
< min_y
)
14056 row
->visible_height
-= min_y
- row
->y
;
14057 if (row
->y
+ row
->height
> max_y
)
14058 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14059 row
->redraw_fringe_bitmaps_p
= 1;
14062 /* Scroll the current matrix. */
14063 xassert (nrows_scrolled
> 0);
14064 rotate_matrix (w
->current_matrix
,
14066 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14069 /* Disable rows not reused. */
14070 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
14071 row
->enabled_p
= 0;
14073 /* Point may have moved to a different line, so we cannot assume that
14074 the previous cursor position is valid; locate the correct row. */
14077 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
14078 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
14082 w
->cursor
.y
= row
->y
;
14084 if (row
< bottom_row
)
14086 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14087 while (glyph
->charpos
< PT
)
14090 w
->cursor
.x
+= glyph
->pixel_width
;
14096 /* Adjust window end. A null value of last_text_row means that
14097 the window end is in reused rows which in turn means that
14098 only its vpos can have changed. */
14101 w
->window_end_bytepos
14102 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14104 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14106 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14111 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
14114 w
->window_end_valid
= Qnil
;
14115 w
->desired_matrix
->no_scrolling_p
= 1;
14118 debug_method_add (w
, "try_window_reusing_current_matrix 2");
14128 /************************************************************************
14129 Window redisplay reusing current matrix when buffer has changed
14130 ************************************************************************/
14132 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
14133 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
14135 static struct glyph_row
*
14136 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
14137 struct glyph_row
*));
14140 /* Return the last row in MATRIX displaying text. If row START is
14141 non-null, start searching with that row. IT gives the dimensions
14142 of the display. Value is null if matrix is empty; otherwise it is
14143 a pointer to the row found. */
14145 static struct glyph_row
*
14146 find_last_row_displaying_text (matrix
, it
, start
)
14147 struct glyph_matrix
*matrix
;
14149 struct glyph_row
*start
;
14151 struct glyph_row
*row
, *row_found
;
14153 /* Set row_found to the last row in IT->w's current matrix
14154 displaying text. The loop looks funny but think of partially
14157 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14158 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14160 xassert (row
->enabled_p
);
14162 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
14171 /* Return the last row in the current matrix of W that is not affected
14172 by changes at the start of current_buffer that occurred since W's
14173 current matrix was built. Value is null if no such row exists.
14175 BEG_UNCHANGED us the number of characters unchanged at the start of
14176 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
14177 first changed character in current_buffer. Characters at positions <
14178 BEG + BEG_UNCHANGED are at the same buffer positions as they were
14179 when the current matrix was built. */
14181 static struct glyph_row
*
14182 find_last_unchanged_at_beg_row (w
)
14185 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
14186 struct glyph_row
*row
;
14187 struct glyph_row
*row_found
= NULL
;
14188 int yb
= window_text_bottom_y (w
);
14190 /* Find the last row displaying unchanged text. */
14191 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14192 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14193 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
14195 if (/* If row ends before first_changed_pos, it is unchanged,
14196 except in some case. */
14197 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
14198 /* When row ends in ZV and we write at ZV it is not
14200 && !row
->ends_at_zv_p
14201 /* When first_changed_pos is the end of a continued line,
14202 row is not unchanged because it may be no longer
14204 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
14205 && (row
->continued_p
14206 || row
->exact_window_width_line_p
)))
14209 /* Stop if last visible row. */
14210 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
14220 /* Find the first glyph row in the current matrix of W that is not
14221 affected by changes at the end of current_buffer since the
14222 time W's current matrix was built.
14224 Return in *DELTA the number of chars by which buffer positions in
14225 unchanged text at the end of current_buffer must be adjusted.
14227 Return in *DELTA_BYTES the corresponding number of bytes.
14229 Value is null if no such row exists, i.e. all rows are affected by
14232 static struct glyph_row
*
14233 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
14235 int *delta
, *delta_bytes
;
14237 struct glyph_row
*row
;
14238 struct glyph_row
*row_found
= NULL
;
14240 *delta
= *delta_bytes
= 0;
14242 /* Display must not have been paused, otherwise the current matrix
14243 is not up to date. */
14244 if (NILP (w
->window_end_valid
))
14247 /* A value of window_end_pos >= END_UNCHANGED means that the window
14248 end is in the range of changed text. If so, there is no
14249 unchanged row at the end of W's current matrix. */
14250 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
14253 /* Set row to the last row in W's current matrix displaying text. */
14254 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14256 /* If matrix is entirely empty, no unchanged row exists. */
14257 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14259 /* The value of row is the last glyph row in the matrix having a
14260 meaningful buffer position in it. The end position of row
14261 corresponds to window_end_pos. This allows us to translate
14262 buffer positions in the current matrix to current buffer
14263 positions for characters not in changed text. */
14264 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14265 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14266 int last_unchanged_pos
, last_unchanged_pos_old
;
14267 struct glyph_row
*first_text_row
14268 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14270 *delta
= Z
- Z_old
;
14271 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14273 /* Set last_unchanged_pos to the buffer position of the last
14274 character in the buffer that has not been changed. Z is the
14275 index + 1 of the last character in current_buffer, i.e. by
14276 subtracting END_UNCHANGED we get the index of the last
14277 unchanged character, and we have to add BEG to get its buffer
14279 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
14280 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
14282 /* Search backward from ROW for a row displaying a line that
14283 starts at a minimum position >= last_unchanged_pos_old. */
14284 for (; row
> first_text_row
; --row
)
14286 /* This used to abort, but it can happen.
14287 It is ok to just stop the search instead here. KFS. */
14288 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14291 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
14296 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
14303 /* Make sure that glyph rows in the current matrix of window W
14304 reference the same glyph memory as corresponding rows in the
14305 frame's frame matrix. This function is called after scrolling W's
14306 current matrix on a terminal frame in try_window_id and
14307 try_window_reusing_current_matrix. */
14310 sync_frame_with_window_matrix_rows (w
)
14313 struct frame
*f
= XFRAME (w
->frame
);
14314 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
14316 /* Preconditions: W must be a leaf window and full-width. Its frame
14317 must have a frame matrix. */
14318 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
14319 xassert (WINDOW_FULL_WIDTH_P (w
));
14320 xassert (!FRAME_WINDOW_P (f
));
14322 /* If W is a full-width window, glyph pointers in W's current matrix
14323 have, by definition, to be the same as glyph pointers in the
14324 corresponding frame matrix. Note that frame matrices have no
14325 marginal areas (see build_frame_matrix). */
14326 window_row
= w
->current_matrix
->rows
;
14327 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14328 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14329 while (window_row
< window_row_end
)
14331 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14332 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14334 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14335 frame_row
->glyphs
[TEXT_AREA
] = start
;
14336 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14337 frame_row
->glyphs
[LAST_AREA
] = end
;
14339 /* Disable frame rows whose corresponding window rows have
14340 been disabled in try_window_id. */
14341 if (!window_row
->enabled_p
)
14342 frame_row
->enabled_p
= 0;
14344 ++window_row
, ++frame_row
;
14349 /* Find the glyph row in window W containing CHARPOS. Consider all
14350 rows between START and END (not inclusive). END null means search
14351 all rows to the end of the display area of W. Value is the row
14352 containing CHARPOS or null. */
14355 row_containing_pos (w
, charpos
, start
, end
, dy
)
14358 struct glyph_row
*start
, *end
;
14361 struct glyph_row
*row
= start
;
14364 /* If we happen to start on a header-line, skip that. */
14365 if (row
->mode_line_p
)
14368 if ((end
&& row
>= end
) || !row
->enabled_p
)
14371 last_y
= window_text_bottom_y (w
) - dy
;
14375 /* Give up if we have gone too far. */
14376 if (end
&& row
>= end
)
14378 /* This formerly returned if they were equal.
14379 I think that both quantities are of a "last plus one" type;
14380 if so, when they are equal, the row is within the screen. -- rms. */
14381 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14384 /* If it is in this row, return this row. */
14385 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14386 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14387 /* The end position of a row equals the start
14388 position of the next row. If CHARPOS is there, we
14389 would rather display it in the next line, except
14390 when this line ends in ZV. */
14391 && !row
->ends_at_zv_p
14392 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14393 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14400 /* Try to redisplay window W by reusing its existing display. W's
14401 current matrix must be up to date when this function is called,
14402 i.e. window_end_valid must not be nil.
14406 1 if display has been updated
14407 0 if otherwise unsuccessful
14408 -1 if redisplay with same window start is known not to succeed
14410 The following steps are performed:
14412 1. Find the last row in the current matrix of W that is not
14413 affected by changes at the start of current_buffer. If no such row
14416 2. Find the first row in W's current matrix that is not affected by
14417 changes at the end of current_buffer. Maybe there is no such row.
14419 3. Display lines beginning with the row + 1 found in step 1 to the
14420 row found in step 2 or, if step 2 didn't find a row, to the end of
14423 4. If cursor is not known to appear on the window, give up.
14425 5. If display stopped at the row found in step 2, scroll the
14426 display and current matrix as needed.
14428 6. Maybe display some lines at the end of W, if we must. This can
14429 happen under various circumstances, like a partially visible line
14430 becoming fully visible, or because newly displayed lines are displayed
14431 in smaller font sizes.
14433 7. Update W's window end information. */
14439 struct frame
*f
= XFRAME (w
->frame
);
14440 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14441 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14442 struct glyph_row
*last_unchanged_at_beg_row
;
14443 struct glyph_row
*first_unchanged_at_end_row
;
14444 struct glyph_row
*row
;
14445 struct glyph_row
*bottom_row
;
14448 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14449 struct text_pos start_pos
;
14451 int first_unchanged_at_end_vpos
= 0;
14452 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14453 struct text_pos start
;
14454 int first_changed_charpos
, last_changed_charpos
;
14457 if (inhibit_try_window_id
)
14461 /* This is handy for debugging. */
14463 #define GIVE_UP(X) \
14465 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14469 #define GIVE_UP(X) return 0
14472 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14474 /* Don't use this for mini-windows because these can show
14475 messages and mini-buffers, and we don't handle that here. */
14476 if (MINI_WINDOW_P (w
))
14479 /* This flag is used to prevent redisplay optimizations. */
14480 if (windows_or_buffers_changed
|| cursor_type_changed
)
14483 /* Verify that narrowing has not changed.
14484 Also verify that we were not told to prevent redisplay optimizations.
14485 It would be nice to further
14486 reduce the number of cases where this prevents try_window_id. */
14487 if (current_buffer
->clip_changed
14488 || current_buffer
->prevent_redisplay_optimizations_p
)
14491 /* Window must either use window-based redisplay or be full width. */
14492 if (!FRAME_WINDOW_P (f
)
14493 && (!line_ins_del_ok
14494 || !WINDOW_FULL_WIDTH_P (w
)))
14497 /* Give up if point is not known NOT to appear in W. */
14498 if (PT
< CHARPOS (start
))
14501 /* Another way to prevent redisplay optimizations. */
14502 if (XFASTINT (w
->last_modified
) == 0)
14505 /* Verify that window is not hscrolled. */
14506 if (XFASTINT (w
->hscroll
) != 0)
14509 /* Verify that display wasn't paused. */
14510 if (NILP (w
->window_end_valid
))
14513 /* Can't use this if highlighting a region because a cursor movement
14514 will do more than just set the cursor. */
14515 if (!NILP (Vtransient_mark_mode
)
14516 && !NILP (current_buffer
->mark_active
))
14519 /* Likewise if highlighting trailing whitespace. */
14520 if (!NILP (Vshow_trailing_whitespace
))
14523 /* Likewise if showing a region. */
14524 if (!NILP (w
->region_showing
))
14527 /* Can use this if overlay arrow position and or string have changed. */
14528 if (overlay_arrows_changed_p ())
14532 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14533 only if buffer has really changed. The reason is that the gap is
14534 initially at Z for freshly visited files. The code below would
14535 set end_unchanged to 0 in that case. */
14536 if (MODIFF
> SAVE_MODIFF
14537 /* This seems to happen sometimes after saving a buffer. */
14538 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14540 if (GPT
- BEG
< BEG_UNCHANGED
)
14541 BEG_UNCHANGED
= GPT
- BEG
;
14542 if (Z
- GPT
< END_UNCHANGED
)
14543 END_UNCHANGED
= Z
- GPT
;
14546 /* The position of the first and last character that has been changed. */
14547 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14548 last_changed_charpos
= Z
- END_UNCHANGED
;
14550 /* If window starts after a line end, and the last change is in
14551 front of that newline, then changes don't affect the display.
14552 This case happens with stealth-fontification. Note that although
14553 the display is unchanged, glyph positions in the matrix have to
14554 be adjusted, of course. */
14555 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14556 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14557 && ((last_changed_charpos
< CHARPOS (start
)
14558 && CHARPOS (start
) == BEGV
)
14559 || (last_changed_charpos
< CHARPOS (start
) - 1
14560 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14562 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14563 struct glyph_row
*r0
;
14565 /* Compute how many chars/bytes have been added to or removed
14566 from the buffer. */
14567 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14568 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14570 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14572 /* Give up if PT is not in the window. Note that it already has
14573 been checked at the start of try_window_id that PT is not in
14574 front of the window start. */
14575 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14578 /* If window start is unchanged, we can reuse the whole matrix
14579 as is, after adjusting glyph positions. No need to compute
14580 the window end again, since its offset from Z hasn't changed. */
14581 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14582 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14583 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14584 /* PT must not be in a partially visible line. */
14585 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14586 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14588 /* Adjust positions in the glyph matrix. */
14589 if (delta
|| delta_bytes
)
14591 struct glyph_row
*r1
14592 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14593 increment_matrix_positions (w
->current_matrix
,
14594 MATRIX_ROW_VPOS (r0
, current_matrix
),
14595 MATRIX_ROW_VPOS (r1
, current_matrix
),
14596 delta
, delta_bytes
);
14599 /* Set the cursor. */
14600 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14602 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14609 /* Handle the case that changes are all below what is displayed in
14610 the window, and that PT is in the window. This shortcut cannot
14611 be taken if ZV is visible in the window, and text has been added
14612 there that is visible in the window. */
14613 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14614 /* ZV is not visible in the window, or there are no
14615 changes at ZV, actually. */
14616 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14617 || first_changed_charpos
== last_changed_charpos
))
14619 struct glyph_row
*r0
;
14621 /* Give up if PT is not in the window. Note that it already has
14622 been checked at the start of try_window_id that PT is not in
14623 front of the window start. */
14624 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14627 /* If window start is unchanged, we can reuse the whole matrix
14628 as is, without changing glyph positions since no text has
14629 been added/removed in front of the window end. */
14630 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14631 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14632 /* PT must not be in a partially visible line. */
14633 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14634 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14636 /* We have to compute the window end anew since text
14637 can have been added/removed after it. */
14639 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14640 w
->window_end_bytepos
14641 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14643 /* Set the cursor. */
14644 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14646 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14653 /* Give up if window start is in the changed area.
14655 The condition used to read
14657 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
14659 but why that was tested escapes me at the moment. */
14660 if (CHARPOS (start
) >= first_changed_charpos
14661 && CHARPOS (start
) <= last_changed_charpos
)
14664 /* Check that window start agrees with the start of the first glyph
14665 row in its current matrix. Check this after we know the window
14666 start is not in changed text, otherwise positions would not be
14668 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14669 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
14672 /* Give up if the window ends in strings. Overlay strings
14673 at the end are difficult to handle, so don't try. */
14674 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
14675 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
14678 /* Compute the position at which we have to start displaying new
14679 lines. Some of the lines at the top of the window might be
14680 reusable because they are not displaying changed text. Find the
14681 last row in W's current matrix not affected by changes at the
14682 start of current_buffer. Value is null if changes start in the
14683 first line of window. */
14684 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
14685 if (last_unchanged_at_beg_row
)
14687 /* Avoid starting to display in the moddle of a character, a TAB
14688 for instance. This is easier than to set up the iterator
14689 exactly, and it's not a frequent case, so the additional
14690 effort wouldn't really pay off. */
14691 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
14692 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
14693 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
14694 --last_unchanged_at_beg_row
;
14696 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
14699 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
14701 start_pos
= it
.current
.pos
;
14703 /* Start displaying new lines in the desired matrix at the same
14704 vpos we would use in the current matrix, i.e. below
14705 last_unchanged_at_beg_row. */
14706 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
14708 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14709 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
14711 xassert (it
.hpos
== 0 && it
.current_x
== 0);
14715 /* There are no reusable lines at the start of the window.
14716 Start displaying in the first text line. */
14717 start_display (&it
, w
, start
);
14718 it
.vpos
= it
.first_vpos
;
14719 start_pos
= it
.current
.pos
;
14722 /* Find the first row that is not affected by changes at the end of
14723 the buffer. Value will be null if there is no unchanged row, in
14724 which case we must redisplay to the end of the window. delta
14725 will be set to the value by which buffer positions beginning with
14726 first_unchanged_at_end_row have to be adjusted due to text
14728 first_unchanged_at_end_row
14729 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
14730 IF_DEBUG (debug_delta
= delta
);
14731 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
14733 /* Set stop_pos to the buffer position up to which we will have to
14734 display new lines. If first_unchanged_at_end_row != NULL, this
14735 is the buffer position of the start of the line displayed in that
14736 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
14737 that we don't stop at a buffer position. */
14739 if (first_unchanged_at_end_row
)
14741 xassert (last_unchanged_at_beg_row
== NULL
14742 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
14744 /* If this is a continuation line, move forward to the next one
14745 that isn't. Changes in lines above affect this line.
14746 Caution: this may move first_unchanged_at_end_row to a row
14747 not displaying text. */
14748 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
14749 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14750 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14751 < it
.last_visible_y
))
14752 ++first_unchanged_at_end_row
;
14754 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14755 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14756 >= it
.last_visible_y
))
14757 first_unchanged_at_end_row
= NULL
;
14760 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
14762 first_unchanged_at_end_vpos
14763 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
14764 xassert (stop_pos
>= Z
- END_UNCHANGED
);
14767 else if (last_unchanged_at_beg_row
== NULL
)
14773 /* Either there is no unchanged row at the end, or the one we have
14774 now displays text. This is a necessary condition for the window
14775 end pos calculation at the end of this function. */
14776 xassert (first_unchanged_at_end_row
== NULL
14777 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
14779 debug_last_unchanged_at_beg_vpos
14780 = (last_unchanged_at_beg_row
14781 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
14783 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
14785 #endif /* GLYPH_DEBUG != 0 */
14788 /* Display new lines. Set last_text_row to the last new line
14789 displayed which has text on it, i.e. might end up as being the
14790 line where the window_end_vpos is. */
14791 w
->cursor
.vpos
= -1;
14792 last_text_row
= NULL
;
14793 overlay_arrow_seen
= 0;
14794 while (it
.current_y
< it
.last_visible_y
14795 && !fonts_changed_p
14796 && (first_unchanged_at_end_row
== NULL
14797 || IT_CHARPOS (it
) < stop_pos
))
14799 if (display_line (&it
))
14800 last_text_row
= it
.glyph_row
- 1;
14803 if (fonts_changed_p
)
14807 /* Compute differences in buffer positions, y-positions etc. for
14808 lines reused at the bottom of the window. Compute what we can
14810 if (first_unchanged_at_end_row
14811 /* No lines reused because we displayed everything up to the
14812 bottom of the window. */
14813 && it
.current_y
< it
.last_visible_y
)
14816 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
14818 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
14819 run
.current_y
= first_unchanged_at_end_row
->y
;
14820 run
.desired_y
= run
.current_y
+ dy
;
14821 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
14825 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
14826 first_unchanged_at_end_row
= NULL
;
14828 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
14831 /* Find the cursor if not already found. We have to decide whether
14832 PT will appear on this window (it sometimes doesn't, but this is
14833 not a very frequent case.) This decision has to be made before
14834 the current matrix is altered. A value of cursor.vpos < 0 means
14835 that PT is either in one of the lines beginning at
14836 first_unchanged_at_end_row or below the window. Don't care for
14837 lines that might be displayed later at the window end; as
14838 mentioned, this is not a frequent case. */
14839 if (w
->cursor
.vpos
< 0)
14841 /* Cursor in unchanged rows at the top? */
14842 if (PT
< CHARPOS (start_pos
)
14843 && last_unchanged_at_beg_row
)
14845 row
= row_containing_pos (w
, PT
,
14846 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
14847 last_unchanged_at_beg_row
+ 1, 0);
14849 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14852 /* Start from first_unchanged_at_end_row looking for PT. */
14853 else if (first_unchanged_at_end_row
)
14855 row
= row_containing_pos (w
, PT
- delta
,
14856 first_unchanged_at_end_row
, NULL
, 0);
14858 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
14859 delta_bytes
, dy
, dvpos
);
14862 /* Give up if cursor was not found. */
14863 if (w
->cursor
.vpos
< 0)
14865 clear_glyph_matrix (w
->desired_matrix
);
14870 /* Don't let the cursor end in the scroll margins. */
14872 int this_scroll_margin
, cursor_height
;
14874 this_scroll_margin
= max (0, scroll_margin
);
14875 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14876 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14877 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
14879 if ((w
->cursor
.y
< this_scroll_margin
14880 && CHARPOS (start
) > BEGV
)
14881 /* Old redisplay didn't take scroll margin into account at the bottom,
14882 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14883 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14884 ? cursor_height
+ this_scroll_margin
14885 : 1)) > it
.last_visible_y
)
14887 w
->cursor
.vpos
= -1;
14888 clear_glyph_matrix (w
->desired_matrix
);
14893 /* Scroll the display. Do it before changing the current matrix so
14894 that xterm.c doesn't get confused about where the cursor glyph is
14896 if (dy
&& run
.height
)
14900 if (FRAME_WINDOW_P (f
))
14902 rif
->update_window_begin_hook (w
);
14903 rif
->clear_window_mouse_face (w
);
14904 rif
->scroll_run_hook (w
, &run
);
14905 rif
->update_window_end_hook (w
, 0, 0);
14909 /* Terminal frame. In this case, dvpos gives the number of
14910 lines to scroll by; dvpos < 0 means scroll up. */
14911 int first_unchanged_at_end_vpos
14912 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14913 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14914 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14915 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14916 + window_internal_height (w
));
14918 /* Perform the operation on the screen. */
14921 /* Scroll last_unchanged_at_beg_row to the end of the
14922 window down dvpos lines. */
14923 set_terminal_window (end
);
14925 /* On dumb terminals delete dvpos lines at the end
14926 before inserting dvpos empty lines. */
14927 if (!scroll_region_ok
)
14928 ins_del_lines (end
- dvpos
, -dvpos
);
14930 /* Insert dvpos empty lines in front of
14931 last_unchanged_at_beg_row. */
14932 ins_del_lines (from
, dvpos
);
14934 else if (dvpos
< 0)
14936 /* Scroll up last_unchanged_at_beg_vpos to the end of
14937 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14938 set_terminal_window (end
);
14940 /* Delete dvpos lines in front of
14941 last_unchanged_at_beg_vpos. ins_del_lines will set
14942 the cursor to the given vpos and emit |dvpos| delete
14944 ins_del_lines (from
+ dvpos
, dvpos
);
14946 /* On a dumb terminal insert dvpos empty lines at the
14948 if (!scroll_region_ok
)
14949 ins_del_lines (end
+ dvpos
, -dvpos
);
14952 set_terminal_window (0);
14958 /* Shift reused rows of the current matrix to the right position.
14959 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14961 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14962 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14965 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14966 bottom_vpos
, dvpos
);
14967 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14970 else if (dvpos
> 0)
14972 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14973 bottom_vpos
, dvpos
);
14974 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14975 first_unchanged_at_end_vpos
+ dvpos
, 0);
14978 /* For frame-based redisplay, make sure that current frame and window
14979 matrix are in sync with respect to glyph memory. */
14980 if (!FRAME_WINDOW_P (f
))
14981 sync_frame_with_window_matrix_rows (w
);
14983 /* Adjust buffer positions in reused rows. */
14984 if (delta
|| delta_bytes
)
14985 increment_matrix_positions (current_matrix
,
14986 first_unchanged_at_end_vpos
+ dvpos
,
14987 bottom_vpos
, delta
, delta_bytes
);
14989 /* Adjust Y positions. */
14991 shift_glyph_matrix (w
, current_matrix
,
14992 first_unchanged_at_end_vpos
+ dvpos
,
14995 if (first_unchanged_at_end_row
)
14997 first_unchanged_at_end_row
+= dvpos
;
14998 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
14999 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
15000 first_unchanged_at_end_row
= NULL
;
15003 /* If scrolling up, there may be some lines to display at the end of
15005 last_text_row_at_end
= NULL
;
15008 /* Scrolling up can leave for example a partially visible line
15009 at the end of the window to be redisplayed. */
15010 /* Set last_row to the glyph row in the current matrix where the
15011 window end line is found. It has been moved up or down in
15012 the matrix by dvpos. */
15013 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
15014 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
15016 /* If last_row is the window end line, it should display text. */
15017 xassert (last_row
->displays_text_p
);
15019 /* If window end line was partially visible before, begin
15020 displaying at that line. Otherwise begin displaying with the
15021 line following it. */
15022 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
15024 init_to_row_start (&it
, w
, last_row
);
15025 it
.vpos
= last_vpos
;
15026 it
.current_y
= last_row
->y
;
15030 init_to_row_end (&it
, w
, last_row
);
15031 it
.vpos
= 1 + last_vpos
;
15032 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
15036 /* We may start in a continuation line. If so, we have to
15037 get the right continuation_lines_width and current_x. */
15038 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
15039 it
.hpos
= it
.current_x
= 0;
15041 /* Display the rest of the lines at the window end. */
15042 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15043 while (it
.current_y
< it
.last_visible_y
15044 && !fonts_changed_p
)
15046 /* Is it always sure that the display agrees with lines in
15047 the current matrix? I don't think so, so we mark rows
15048 displayed invalid in the current matrix by setting their
15049 enabled_p flag to zero. */
15050 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
15051 if (display_line (&it
))
15052 last_text_row_at_end
= it
.glyph_row
- 1;
15056 /* Update window_end_pos and window_end_vpos. */
15057 if (first_unchanged_at_end_row
15058 && !last_text_row_at_end
)
15060 /* Window end line if one of the preserved rows from the current
15061 matrix. Set row to the last row displaying text in current
15062 matrix starting at first_unchanged_at_end_row, after
15064 xassert (first_unchanged_at_end_row
->displays_text_p
);
15065 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
15066 first_unchanged_at_end_row
);
15067 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
15069 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15070 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15072 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
15073 xassert (w
->window_end_bytepos
>= 0);
15074 IF_DEBUG (debug_method_add (w
, "A"));
15076 else if (last_text_row_at_end
)
15079 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
15080 w
->window_end_bytepos
15081 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
15083 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
15084 xassert (w
->window_end_bytepos
>= 0);
15085 IF_DEBUG (debug_method_add (w
, "B"));
15087 else if (last_text_row
)
15089 /* We have displayed either to the end of the window or at the
15090 end of the window, i.e. the last row with text is to be found
15091 in the desired matrix. */
15093 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15094 w
->window_end_bytepos
15095 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15097 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
15098 xassert (w
->window_end_bytepos
>= 0);
15100 else if (first_unchanged_at_end_row
== NULL
15101 && last_text_row
== NULL
15102 && last_text_row_at_end
== NULL
)
15104 /* Displayed to end of window, but no line containing text was
15105 displayed. Lines were deleted at the end of the window. */
15106 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
15107 int vpos
= XFASTINT (w
->window_end_vpos
);
15108 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
15109 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
15112 row
== NULL
&& vpos
>= first_vpos
;
15113 --vpos
, --current_row
, --desired_row
)
15115 if (desired_row
->enabled_p
)
15117 if (desired_row
->displays_text_p
)
15120 else if (current_row
->displays_text_p
)
15124 xassert (row
!= NULL
);
15125 w
->window_end_vpos
= make_number (vpos
+ 1);
15126 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15127 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15128 xassert (w
->window_end_bytepos
>= 0);
15129 IF_DEBUG (debug_method_add (w
, "C"));
15134 #if 0 /* This leads to problems, for instance when the cursor is
15135 at ZV, and the cursor line displays no text. */
15136 /* Disable rows below what's displayed in the window. This makes
15137 debugging easier. */
15138 enable_glyph_matrix_rows (current_matrix
,
15139 XFASTINT (w
->window_end_vpos
) + 1,
15143 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
15144 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
15146 /* Record that display has not been completed. */
15147 w
->window_end_valid
= Qnil
;
15148 w
->desired_matrix
->no_scrolling_p
= 1;
15156 /***********************************************************************
15157 More debugging support
15158 ***********************************************************************/
15162 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
15163 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
15164 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
15167 /* Dump the contents of glyph matrix MATRIX on stderr.
15169 GLYPHS 0 means don't show glyph contents.
15170 GLYPHS 1 means show glyphs in short form
15171 GLYPHS > 1 means show glyphs in long form. */
15174 dump_glyph_matrix (matrix
, glyphs
)
15175 struct glyph_matrix
*matrix
;
15179 for (i
= 0; i
< matrix
->nrows
; ++i
)
15180 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
15184 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
15185 the glyph row and area where the glyph comes from. */
15188 dump_glyph (row
, glyph
, area
)
15189 struct glyph_row
*row
;
15190 struct glyph
*glyph
;
15193 if (glyph
->type
== CHAR_GLYPH
)
15196 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15197 glyph
- row
->glyphs
[TEXT_AREA
],
15200 (BUFFERP (glyph
->object
)
15202 : (STRINGP (glyph
->object
)
15205 glyph
->pixel_width
,
15207 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
15211 glyph
->left_box_line_p
,
15212 glyph
->right_box_line_p
);
15214 else if (glyph
->type
== STRETCH_GLYPH
)
15217 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15218 glyph
- row
->glyphs
[TEXT_AREA
],
15221 (BUFFERP (glyph
->object
)
15223 : (STRINGP (glyph
->object
)
15226 glyph
->pixel_width
,
15230 glyph
->left_box_line_p
,
15231 glyph
->right_box_line_p
);
15233 else if (glyph
->type
== IMAGE_GLYPH
)
15236 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15237 glyph
- row
->glyphs
[TEXT_AREA
],
15240 (BUFFERP (glyph
->object
)
15242 : (STRINGP (glyph
->object
)
15245 glyph
->pixel_width
,
15249 glyph
->left_box_line_p
,
15250 glyph
->right_box_line_p
);
15252 else if (glyph
->type
== COMPOSITE_GLYPH
)
15255 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15256 glyph
- row
->glyphs
[TEXT_AREA
],
15259 (BUFFERP (glyph
->object
)
15261 : (STRINGP (glyph
->object
)
15264 glyph
->pixel_width
,
15268 glyph
->left_box_line_p
,
15269 glyph
->right_box_line_p
);
15274 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
15275 GLYPHS 0 means don't show glyph contents.
15276 GLYPHS 1 means show glyphs in short form
15277 GLYPHS > 1 means show glyphs in long form. */
15280 dump_glyph_row (row
, vpos
, glyphs
)
15281 struct glyph_row
*row
;
15286 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
15287 fprintf (stderr
, "======================================================================\n");
15289 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
15290 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
15292 MATRIX_ROW_START_CHARPOS (row
),
15293 MATRIX_ROW_END_CHARPOS (row
),
15294 row
->used
[TEXT_AREA
],
15295 row
->contains_overlapping_glyphs_p
,
15297 row
->truncated_on_left_p
,
15298 row
->truncated_on_right_p
,
15300 MATRIX_ROW_CONTINUATION_LINE_P (row
),
15301 row
->displays_text_p
,
15304 row
->ends_in_middle_of_char_p
,
15305 row
->starts_in_middle_of_char_p
,
15311 row
->visible_height
,
15314 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
15315 row
->end
.overlay_string_index
,
15316 row
->continuation_lines_width
);
15317 fprintf (stderr
, "%9d %5d\n",
15318 CHARPOS (row
->start
.string_pos
),
15319 CHARPOS (row
->end
.string_pos
));
15320 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
15321 row
->end
.dpvec_index
);
15328 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15330 struct glyph
*glyph
= row
->glyphs
[area
];
15331 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
15333 /* Glyph for a line end in text. */
15334 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
15337 if (glyph
< glyph_end
)
15338 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15340 for (; glyph
< glyph_end
; ++glyph
)
15341 dump_glyph (row
, glyph
, area
);
15344 else if (glyphs
== 1)
15348 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15350 char *s
= (char *) alloca (row
->used
[area
] + 1);
15353 for (i
= 0; i
< row
->used
[area
]; ++i
)
15355 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15356 if (glyph
->type
== CHAR_GLYPH
15357 && glyph
->u
.ch
< 0x80
15358 && glyph
->u
.ch
>= ' ')
15359 s
[i
] = glyph
->u
.ch
;
15365 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15371 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15372 Sdump_glyph_matrix
, 0, 1, "p",
15373 doc
: /* Dump the current matrix of the selected window to stderr.
15374 Shows contents of glyph row structures. With non-nil
15375 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15376 glyphs in short form, otherwise show glyphs in long form. */)
15378 Lisp_Object glyphs
;
15380 struct window
*w
= XWINDOW (selected_window
);
15381 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15383 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15384 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15385 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15386 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15387 fprintf (stderr
, "=============================================\n");
15388 dump_glyph_matrix (w
->current_matrix
,
15389 NILP (glyphs
) ? 0 : XINT (glyphs
));
15394 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15395 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15398 struct frame
*f
= XFRAME (selected_frame
);
15399 dump_glyph_matrix (f
->current_matrix
, 1);
15404 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15405 doc
: /* Dump glyph row ROW to stderr.
15406 GLYPH 0 means don't dump glyphs.
15407 GLYPH 1 means dump glyphs in short form.
15408 GLYPH > 1 or omitted means dump glyphs in long form. */)
15410 Lisp_Object row
, glyphs
;
15412 struct glyph_matrix
*matrix
;
15415 CHECK_NUMBER (row
);
15416 matrix
= XWINDOW (selected_window
)->current_matrix
;
15418 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15419 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15421 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15426 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15427 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15428 GLYPH 0 means don't dump glyphs.
15429 GLYPH 1 means dump glyphs in short form.
15430 GLYPH > 1 or omitted means dump glyphs in long form. */)
15432 Lisp_Object row
, glyphs
;
15434 struct frame
*sf
= SELECTED_FRAME ();
15435 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15438 CHECK_NUMBER (row
);
15440 if (vpos
>= 0 && vpos
< m
->nrows
)
15441 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15442 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15447 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15448 doc
: /* Toggle tracing of redisplay.
15449 With ARG, turn tracing on if and only if ARG is positive. */)
15454 trace_redisplay_p
= !trace_redisplay_p
;
15457 arg
= Fprefix_numeric_value (arg
);
15458 trace_redisplay_p
= XINT (arg
) > 0;
15465 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15466 doc
: /* Like `format', but print result to stderr.
15467 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15472 Lisp_Object s
= Fformat (nargs
, args
);
15473 fprintf (stderr
, "%s", SDATA (s
));
15477 #endif /* GLYPH_DEBUG */
15481 /***********************************************************************
15482 Building Desired Matrix Rows
15483 ***********************************************************************/
15485 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15486 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15488 static struct glyph_row
*
15489 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15491 Lisp_Object overlay_arrow_string
;
15493 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15494 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15495 struct buffer
*old
= current_buffer
;
15496 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15497 int arrow_len
= SCHARS (overlay_arrow_string
);
15498 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15499 const unsigned char *p
;
15502 int n_glyphs_before
;
15504 set_buffer_temp (buffer
);
15505 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15506 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15507 SET_TEXT_POS (it
.position
, 0, 0);
15509 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15511 while (p
< arrow_end
)
15513 Lisp_Object face
, ilisp
;
15515 /* Get the next character. */
15517 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15519 it
.c
= *p
, it
.len
= 1;
15522 /* Get its face. */
15523 ilisp
= make_number (p
- arrow_string
);
15524 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15525 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15527 /* Compute its width, get its glyphs. */
15528 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15529 SET_TEXT_POS (it
.position
, -1, -1);
15530 PRODUCE_GLYPHS (&it
);
15532 /* If this character doesn't fit any more in the line, we have
15533 to remove some glyphs. */
15534 if (it
.current_x
> it
.last_visible_x
)
15536 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15541 set_buffer_temp (old
);
15542 return it
.glyph_row
;
15546 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15547 glyphs are only inserted for terminal frames since we can't really
15548 win with truncation glyphs when partially visible glyphs are
15549 involved. Which glyphs to insert is determined by
15550 produce_special_glyphs. */
15553 insert_left_trunc_glyphs (it
)
15556 struct it truncate_it
;
15557 struct glyph
*from
, *end
, *to
, *toend
;
15559 xassert (!FRAME_WINDOW_P (it
->f
));
15561 /* Get the truncation glyphs. */
15563 truncate_it
.current_x
= 0;
15564 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15565 truncate_it
.glyph_row
= &scratch_glyph_row
;
15566 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15567 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15568 truncate_it
.object
= make_number (0);
15569 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15571 /* Overwrite glyphs from IT with truncation glyphs. */
15572 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15573 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15574 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15575 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15580 /* There may be padding glyphs left over. Overwrite them too. */
15581 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15583 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15589 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15593 /* Compute the pixel height and width of IT->glyph_row.
15595 Most of the time, ascent and height of a display line will be equal
15596 to the max_ascent and max_height values of the display iterator
15597 structure. This is not the case if
15599 1. We hit ZV without displaying anything. In this case, max_ascent
15600 and max_height will be zero.
15602 2. We have some glyphs that don't contribute to the line height.
15603 (The glyph row flag contributes_to_line_height_p is for future
15604 pixmap extensions).
15606 The first case is easily covered by using default values because in
15607 these cases, the line height does not really matter, except that it
15608 must not be zero. */
15611 compute_line_metrics (it
)
15614 struct glyph_row
*row
= it
->glyph_row
;
15617 if (FRAME_WINDOW_P (it
->f
))
15619 int i
, min_y
, max_y
;
15621 /* The line may consist of one space only, that was added to
15622 place the cursor on it. If so, the row's height hasn't been
15624 if (row
->height
== 0)
15626 if (it
->max_ascent
+ it
->max_descent
== 0)
15627 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15628 row
->ascent
= it
->max_ascent
;
15629 row
->height
= it
->max_ascent
+ it
->max_descent
;
15630 row
->phys_ascent
= it
->max_phys_ascent
;
15631 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15632 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15635 /* Compute the width of this line. */
15636 row
->pixel_width
= row
->x
;
15637 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15638 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15640 xassert (row
->pixel_width
>= 0);
15641 xassert (row
->ascent
>= 0 && row
->height
> 0);
15643 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15644 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15646 /* If first line's physical ascent is larger than its logical
15647 ascent, use the physical ascent, and make the row taller.
15648 This makes accented characters fully visible. */
15649 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
15650 && row
->phys_ascent
> row
->ascent
)
15652 row
->height
+= row
->phys_ascent
- row
->ascent
;
15653 row
->ascent
= row
->phys_ascent
;
15656 /* Compute how much of the line is visible. */
15657 row
->visible_height
= row
->height
;
15659 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
15660 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
15662 if (row
->y
< min_y
)
15663 row
->visible_height
-= min_y
- row
->y
;
15664 if (row
->y
+ row
->height
> max_y
)
15665 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15669 row
->pixel_width
= row
->used
[TEXT_AREA
];
15670 if (row
->continued_p
)
15671 row
->pixel_width
-= it
->continuation_pixel_width
;
15672 else if (row
->truncated_on_right_p
)
15673 row
->pixel_width
-= it
->truncation_pixel_width
;
15674 row
->ascent
= row
->phys_ascent
= 0;
15675 row
->height
= row
->phys_height
= row
->visible_height
= 1;
15676 row
->extra_line_spacing
= 0;
15679 /* Compute a hash code for this row. */
15681 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15682 for (i
= 0; i
< row
->used
[area
]; ++i
)
15683 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
15684 + row
->glyphs
[area
][i
].u
.val
15685 + row
->glyphs
[area
][i
].face_id
15686 + row
->glyphs
[area
][i
].padding_p
15687 + (row
->glyphs
[area
][i
].type
<< 2));
15689 it
->max_ascent
= it
->max_descent
= 0;
15690 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
15694 /* Append one space to the glyph row of iterator IT if doing a
15695 window-based redisplay. The space has the same face as
15696 IT->face_id. Value is non-zero if a space was added.
15698 This function is called to make sure that there is always one glyph
15699 at the end of a glyph row that the cursor can be set on under
15700 window-systems. (If there weren't such a glyph we would not know
15701 how wide and tall a box cursor should be displayed).
15703 At the same time this space let's a nicely handle clearing to the
15704 end of the line if the row ends in italic text. */
15707 append_space_for_newline (it
, default_face_p
)
15709 int default_face_p
;
15711 if (FRAME_WINDOW_P (it
->f
))
15713 int n
= it
->glyph_row
->used
[TEXT_AREA
];
15715 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
15716 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
15718 /* Save some values that must not be changed.
15719 Must save IT->c and IT->len because otherwise
15720 ITERATOR_AT_END_P wouldn't work anymore after
15721 append_space_for_newline has been called. */
15722 enum display_element_type saved_what
= it
->what
;
15723 int saved_c
= it
->c
, saved_len
= it
->len
;
15724 int saved_x
= it
->current_x
;
15725 int saved_face_id
= it
->face_id
;
15726 struct text_pos saved_pos
;
15727 Lisp_Object saved_object
;
15730 saved_object
= it
->object
;
15731 saved_pos
= it
->position
;
15733 it
->what
= IT_CHARACTER
;
15734 bzero (&it
->position
, sizeof it
->position
);
15735 it
->object
= make_number (0);
15739 if (default_face_p
)
15740 it
->face_id
= DEFAULT_FACE_ID
;
15741 else if (it
->face_before_selective_p
)
15742 it
->face_id
= it
->saved_face_id
;
15743 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15744 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
15746 PRODUCE_GLYPHS (it
);
15748 it
->override_ascent
= -1;
15749 it
->constrain_row_ascent_descent_p
= 0;
15750 it
->current_x
= saved_x
;
15751 it
->object
= saved_object
;
15752 it
->position
= saved_pos
;
15753 it
->what
= saved_what
;
15754 it
->face_id
= saved_face_id
;
15755 it
->len
= saved_len
;
15765 /* Extend the face of the last glyph in the text area of IT->glyph_row
15766 to the end of the display line. Called from display_line.
15767 If the glyph row is empty, add a space glyph to it so that we
15768 know the face to draw. Set the glyph row flag fill_line_p. */
15771 extend_face_to_end_of_line (it
)
15775 struct frame
*f
= it
->f
;
15777 /* If line is already filled, do nothing. */
15778 if (it
->current_x
>= it
->last_visible_x
)
15781 /* Face extension extends the background and box of IT->face_id
15782 to the end of the line. If the background equals the background
15783 of the frame, we don't have to do anything. */
15784 if (it
->face_before_selective_p
)
15785 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
15787 face
= FACE_FROM_ID (f
, it
->face_id
);
15789 if (FRAME_WINDOW_P (f
)
15790 && it
->glyph_row
->displays_text_p
15791 && face
->box
== FACE_NO_BOX
15792 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
15796 /* Set the glyph row flag indicating that the face of the last glyph
15797 in the text area has to be drawn to the end of the text area. */
15798 it
->glyph_row
->fill_line_p
= 1;
15800 /* If current character of IT is not ASCII, make sure we have the
15801 ASCII face. This will be automatically undone the next time
15802 get_next_display_element returns a multibyte character. Note
15803 that the character will always be single byte in unibyte text. */
15804 if (!SINGLE_BYTE_CHAR_P (it
->c
))
15806 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
15809 if (FRAME_WINDOW_P (f
))
15811 /* If the row is empty, add a space with the current face of IT,
15812 so that we know which face to draw. */
15813 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
15815 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
15816 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
15817 it
->glyph_row
->used
[TEXT_AREA
] = 1;
15822 /* Save some values that must not be changed. */
15823 int saved_x
= it
->current_x
;
15824 struct text_pos saved_pos
;
15825 Lisp_Object saved_object
;
15826 enum display_element_type saved_what
= it
->what
;
15827 int saved_face_id
= it
->face_id
;
15829 saved_object
= it
->object
;
15830 saved_pos
= it
->position
;
15832 it
->what
= IT_CHARACTER
;
15833 bzero (&it
->position
, sizeof it
->position
);
15834 it
->object
= make_number (0);
15837 it
->face_id
= face
->id
;
15839 PRODUCE_GLYPHS (it
);
15841 while (it
->current_x
<= it
->last_visible_x
)
15842 PRODUCE_GLYPHS (it
);
15844 /* Don't count these blanks really. It would let us insert a left
15845 truncation glyph below and make us set the cursor on them, maybe. */
15846 it
->current_x
= saved_x
;
15847 it
->object
= saved_object
;
15848 it
->position
= saved_pos
;
15849 it
->what
= saved_what
;
15850 it
->face_id
= saved_face_id
;
15855 /* Value is non-zero if text starting at CHARPOS in current_buffer is
15856 trailing whitespace. */
15859 trailing_whitespace_p (charpos
)
15862 int bytepos
= CHAR_TO_BYTE (charpos
);
15865 while (bytepos
< ZV_BYTE
15866 && (c
= FETCH_CHAR (bytepos
),
15867 c
== ' ' || c
== '\t'))
15870 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
15872 if (bytepos
!= PT_BYTE
)
15879 /* Highlight trailing whitespace, if any, in ROW. */
15882 highlight_trailing_whitespace (f
, row
)
15884 struct glyph_row
*row
;
15886 int used
= row
->used
[TEXT_AREA
];
15890 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
15891 struct glyph
*glyph
= start
+ used
- 1;
15893 /* Skip over glyphs inserted to display the cursor at the
15894 end of a line, for extending the face of the last glyph
15895 to the end of the line on terminals, and for truncation
15896 and continuation glyphs. */
15897 while (glyph
>= start
15898 && glyph
->type
== CHAR_GLYPH
15899 && INTEGERP (glyph
->object
))
15902 /* If last glyph is a space or stretch, and it's trailing
15903 whitespace, set the face of all trailing whitespace glyphs in
15904 IT->glyph_row to `trailing-whitespace'. */
15906 && BUFFERP (glyph
->object
)
15907 && (glyph
->type
== STRETCH_GLYPH
15908 || (glyph
->type
== CHAR_GLYPH
15909 && glyph
->u
.ch
== ' '))
15910 && trailing_whitespace_p (glyph
->charpos
))
15912 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
15916 while (glyph
>= start
15917 && BUFFERP (glyph
->object
)
15918 && (glyph
->type
== STRETCH_GLYPH
15919 || (glyph
->type
== CHAR_GLYPH
15920 && glyph
->u
.ch
== ' ')))
15921 (glyph
--)->face_id
= face_id
;
15927 /* Value is non-zero if glyph row ROW in window W should be
15928 used to hold the cursor. */
15931 cursor_row_p (w
, row
)
15933 struct glyph_row
*row
;
15935 int cursor_row_p
= 1;
15937 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15939 /* Suppose the row ends on a string.
15940 Unless the row is continued, that means it ends on a newline
15941 in the string. If it's anything other than a display string
15942 (e.g. a before-string from an overlay), we don't want the
15943 cursor there. (This heuristic seems to give the optimal
15944 behavior for the various types of multi-line strings.) */
15945 if (CHARPOS (row
->end
.string_pos
) >= 0)
15947 if (row
->continued_p
)
15951 /* Check for `display' property. */
15952 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
15953 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
15954 struct glyph
*glyph
;
15957 for (glyph
= end
; glyph
>= beg
; --glyph
)
15958 if (STRINGP (glyph
->object
))
15961 = Fget_char_property (make_number (PT
),
15965 && display_prop_string_p (prop
, glyph
->object
));
15970 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15972 /* If the row ends in middle of a real character,
15973 and the line is continued, we want the cursor here.
15974 That's because MATRIX_ROW_END_CHARPOS would equal
15975 PT if PT is before the character. */
15976 if (!row
->ends_in_ellipsis_p
)
15977 cursor_row_p
= row
->continued_p
;
15979 /* If the row ends in an ellipsis, then
15980 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15981 We want that position to be displayed after the ellipsis. */
15984 /* If the row ends at ZV, display the cursor at the end of that
15985 row instead of at the start of the row below. */
15986 else if (row
->ends_at_zv_p
)
15992 return cursor_row_p
;
15996 /* Construct the glyph row IT->glyph_row in the desired matrix of
15997 IT->w from text at the current position of IT. See dispextern.h
15998 for an overview of struct it. Value is non-zero if
15999 IT->glyph_row displays text, as opposed to a line displaying ZV
16006 struct glyph_row
*row
= it
->glyph_row
;
16007 Lisp_Object overlay_arrow_string
;
16009 /* We always start displaying at hpos zero even if hscrolled. */
16010 xassert (it
->hpos
== 0 && it
->current_x
== 0);
16012 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
16013 >= it
->w
->desired_matrix
->nrows
)
16015 it
->w
->nrows_scale_factor
++;
16016 fonts_changed_p
= 1;
16020 /* Is IT->w showing the region? */
16021 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
16023 /* Clear the result glyph row and enable it. */
16024 prepare_desired_row (row
);
16026 row
->y
= it
->current_y
;
16027 row
->start
= it
->start
;
16028 row
->continuation_lines_width
= it
->continuation_lines_width
;
16029 row
->displays_text_p
= 1;
16030 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
16031 it
->starts_in_middle_of_char_p
= 0;
16033 /* Arrange the overlays nicely for our purposes. Usually, we call
16034 display_line on only one line at a time, in which case this
16035 can't really hurt too much, or we call it on lines which appear
16036 one after another in the buffer, in which case all calls to
16037 recenter_overlay_lists but the first will be pretty cheap. */
16038 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
16040 /* Move over display elements that are not visible because we are
16041 hscrolled. This may stop at an x-position < IT->first_visible_x
16042 if the first glyph is partially visible or if we hit a line end. */
16043 if (it
->current_x
< it
->first_visible_x
)
16045 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
16046 MOVE_TO_POS
| MOVE_TO_X
);
16049 /* Get the initial row height. This is either the height of the
16050 text hscrolled, if there is any, or zero. */
16051 row
->ascent
= it
->max_ascent
;
16052 row
->height
= it
->max_ascent
+ it
->max_descent
;
16053 row
->phys_ascent
= it
->max_phys_ascent
;
16054 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16055 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16057 /* Loop generating characters. The loop is left with IT on the next
16058 character to display. */
16061 int n_glyphs_before
, hpos_before
, x_before
;
16063 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
16065 /* Retrieve the next thing to display. Value is zero if end of
16067 if (!get_next_display_element (it
))
16069 /* Maybe add a space at the end of this line that is used to
16070 display the cursor there under X. Set the charpos of the
16071 first glyph of blank lines not corresponding to any text
16073 #ifdef HAVE_WINDOW_SYSTEM
16074 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16075 row
->exact_window_width_line_p
= 1;
16077 #endif /* HAVE_WINDOW_SYSTEM */
16078 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
16079 || row
->used
[TEXT_AREA
] == 0)
16081 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
16082 row
->displays_text_p
= 0;
16084 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
16085 && (!MINI_WINDOW_P (it
->w
)
16086 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
16087 row
->indicate_empty_line_p
= 1;
16090 it
->continuation_lines_width
= 0;
16091 row
->ends_at_zv_p
= 1;
16095 /* Now, get the metrics of what we want to display. This also
16096 generates glyphs in `row' (which is IT->glyph_row). */
16097 n_glyphs_before
= row
->used
[TEXT_AREA
];
16100 /* Remember the line height so far in case the next element doesn't
16101 fit on the line. */
16102 if (!it
->truncate_lines_p
)
16104 ascent
= it
->max_ascent
;
16105 descent
= it
->max_descent
;
16106 phys_ascent
= it
->max_phys_ascent
;
16107 phys_descent
= it
->max_phys_descent
;
16110 PRODUCE_GLYPHS (it
);
16112 /* If this display element was in marginal areas, continue with
16114 if (it
->area
!= TEXT_AREA
)
16116 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16117 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16118 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16119 row
->phys_height
= max (row
->phys_height
,
16120 it
->max_phys_ascent
+ it
->max_phys_descent
);
16121 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16122 it
->max_extra_line_spacing
);
16123 set_iterator_to_next (it
, 1);
16127 /* Does the display element fit on the line? If we truncate
16128 lines, we should draw past the right edge of the window. If
16129 we don't truncate, we want to stop so that we can display the
16130 continuation glyph before the right margin. If lines are
16131 continued, there are two possible strategies for characters
16132 resulting in more than 1 glyph (e.g. tabs): Display as many
16133 glyphs as possible in this line and leave the rest for the
16134 continuation line, or display the whole element in the next
16135 line. Original redisplay did the former, so we do it also. */
16136 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
16137 hpos_before
= it
->hpos
;
16140 if (/* Not a newline. */
16142 /* Glyphs produced fit entirely in the line. */
16143 && it
->current_x
< it
->last_visible_x
)
16145 it
->hpos
+= nglyphs
;
16146 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16147 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16148 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16149 row
->phys_height
= max (row
->phys_height
,
16150 it
->max_phys_ascent
+ it
->max_phys_descent
);
16151 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16152 it
->max_extra_line_spacing
);
16153 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
16154 row
->x
= x
- it
->first_visible_x
;
16159 struct glyph
*glyph
;
16161 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
16163 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16164 new_x
= x
+ glyph
->pixel_width
;
16166 if (/* Lines are continued. */
16167 !it
->truncate_lines_p
16168 && (/* Glyph doesn't fit on the line. */
16169 new_x
> it
->last_visible_x
16170 /* Or it fits exactly on a window system frame. */
16171 || (new_x
== it
->last_visible_x
16172 && FRAME_WINDOW_P (it
->f
))))
16174 /* End of a continued line. */
16177 || (new_x
== it
->last_visible_x
16178 && FRAME_WINDOW_P (it
->f
)))
16180 /* Current glyph is the only one on the line or
16181 fits exactly on the line. We must continue
16182 the line because we can't draw the cursor
16183 after the glyph. */
16184 row
->continued_p
= 1;
16185 it
->current_x
= new_x
;
16186 it
->continuation_lines_width
+= new_x
;
16188 if (i
== nglyphs
- 1)
16190 set_iterator_to_next (it
, 1);
16191 #ifdef HAVE_WINDOW_SYSTEM
16192 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16194 if (!get_next_display_element (it
))
16196 row
->exact_window_width_line_p
= 1;
16197 it
->continuation_lines_width
= 0;
16198 row
->continued_p
= 0;
16199 row
->ends_at_zv_p
= 1;
16201 else if (ITERATOR_AT_END_OF_LINE_P (it
))
16203 row
->continued_p
= 0;
16204 row
->exact_window_width_line_p
= 1;
16207 #endif /* HAVE_WINDOW_SYSTEM */
16210 else if (CHAR_GLYPH_PADDING_P (*glyph
)
16211 && !FRAME_WINDOW_P (it
->f
))
16213 /* A padding glyph that doesn't fit on this line.
16214 This means the whole character doesn't fit
16216 row
->used
[TEXT_AREA
] = n_glyphs_before
;
16218 /* Fill the rest of the row with continuation
16219 glyphs like in 20.x. */
16220 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
16221 < row
->glyphs
[1 + TEXT_AREA
])
16222 produce_special_glyphs (it
, IT_CONTINUATION
);
16224 row
->continued_p
= 1;
16225 it
->current_x
= x_before
;
16226 it
->continuation_lines_width
+= x_before
;
16228 /* Restore the height to what it was before the
16229 element not fitting on the line. */
16230 it
->max_ascent
= ascent
;
16231 it
->max_descent
= descent
;
16232 it
->max_phys_ascent
= phys_ascent
;
16233 it
->max_phys_descent
= phys_descent
;
16235 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
16237 /* A TAB that extends past the right edge of the
16238 window. This produces a single glyph on
16239 window system frames. We leave the glyph in
16240 this row and let it fill the row, but don't
16241 consume the TAB. */
16242 it
->continuation_lines_width
+= it
->last_visible_x
;
16243 row
->ends_in_middle_of_char_p
= 1;
16244 row
->continued_p
= 1;
16245 glyph
->pixel_width
= it
->last_visible_x
- x
;
16246 it
->starts_in_middle_of_char_p
= 1;
16250 /* Something other than a TAB that draws past
16251 the right edge of the window. Restore
16252 positions to values before the element. */
16253 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16255 /* Display continuation glyphs. */
16256 if (!FRAME_WINDOW_P (it
->f
))
16257 produce_special_glyphs (it
, IT_CONTINUATION
);
16258 row
->continued_p
= 1;
16260 it
->current_x
= x_before
;
16261 it
->continuation_lines_width
+= x
;
16262 extend_face_to_end_of_line (it
);
16264 if (nglyphs
> 1 && i
> 0)
16266 row
->ends_in_middle_of_char_p
= 1;
16267 it
->starts_in_middle_of_char_p
= 1;
16270 /* Restore the height to what it was before the
16271 element not fitting on the line. */
16272 it
->max_ascent
= ascent
;
16273 it
->max_descent
= descent
;
16274 it
->max_phys_ascent
= phys_ascent
;
16275 it
->max_phys_descent
= phys_descent
;
16280 else if (new_x
> it
->first_visible_x
)
16282 /* Increment number of glyphs actually displayed. */
16285 if (x
< it
->first_visible_x
)
16286 /* Glyph is partially visible, i.e. row starts at
16287 negative X position. */
16288 row
->x
= x
- it
->first_visible_x
;
16292 /* Glyph is completely off the left margin of the
16293 window. This should not happen because of the
16294 move_it_in_display_line at the start of this
16295 function, unless the text display area of the
16296 window is empty. */
16297 xassert (it
->first_visible_x
<= it
->last_visible_x
);
16301 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16302 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16303 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16304 row
->phys_height
= max (row
->phys_height
,
16305 it
->max_phys_ascent
+ it
->max_phys_descent
);
16306 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16307 it
->max_extra_line_spacing
);
16309 /* End of this display line if row is continued. */
16310 if (row
->continued_p
|| row
->ends_at_zv_p
)
16315 /* Is this a line end? If yes, we're also done, after making
16316 sure that a non-default face is extended up to the right
16317 margin of the window. */
16318 if (ITERATOR_AT_END_OF_LINE_P (it
))
16320 int used_before
= row
->used
[TEXT_AREA
];
16322 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
16324 #ifdef HAVE_WINDOW_SYSTEM
16325 /* Add a space at the end of the line that is used to
16326 display the cursor there. */
16327 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16328 append_space_for_newline (it
, 0);
16329 #endif /* HAVE_WINDOW_SYSTEM */
16331 /* Extend the face to the end of the line. */
16332 extend_face_to_end_of_line (it
);
16334 /* Make sure we have the position. */
16335 if (used_before
== 0)
16336 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
16338 /* Consume the line end. This skips over invisible lines. */
16339 set_iterator_to_next (it
, 1);
16340 it
->continuation_lines_width
= 0;
16344 /* Proceed with next display element. Note that this skips
16345 over lines invisible because of selective display. */
16346 set_iterator_to_next (it
, 1);
16348 /* If we truncate lines, we are done when the last displayed
16349 glyphs reach past the right margin of the window. */
16350 if (it
->truncate_lines_p
16351 && (FRAME_WINDOW_P (it
->f
)
16352 ? (it
->current_x
>= it
->last_visible_x
)
16353 : (it
->current_x
> it
->last_visible_x
)))
16355 /* Maybe add truncation glyphs. */
16356 if (!FRAME_WINDOW_P (it
->f
))
16360 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16361 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16364 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16366 row
->used
[TEXT_AREA
] = i
;
16367 produce_special_glyphs (it
, IT_TRUNCATION
);
16370 #ifdef HAVE_WINDOW_SYSTEM
16373 /* Don't truncate if we can overflow newline into fringe. */
16374 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16376 if (!get_next_display_element (it
))
16378 it
->continuation_lines_width
= 0;
16379 row
->ends_at_zv_p
= 1;
16380 row
->exact_window_width_line_p
= 1;
16383 if (ITERATOR_AT_END_OF_LINE_P (it
))
16385 row
->exact_window_width_line_p
= 1;
16386 goto at_end_of_line
;
16390 #endif /* HAVE_WINDOW_SYSTEM */
16392 row
->truncated_on_right_p
= 1;
16393 it
->continuation_lines_width
= 0;
16394 reseat_at_next_visible_line_start (it
, 0);
16395 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16396 it
->hpos
= hpos_before
;
16397 it
->current_x
= x_before
;
16402 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16403 at the left window margin. */
16404 if (it
->first_visible_x
16405 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16407 if (!FRAME_WINDOW_P (it
->f
))
16408 insert_left_trunc_glyphs (it
);
16409 row
->truncated_on_left_p
= 1;
16412 /* If the start of this line is the overlay arrow-position, then
16413 mark this glyph row as the one containing the overlay arrow.
16414 This is clearly a mess with variable size fonts. It would be
16415 better to let it be displayed like cursors under X. */
16416 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16417 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16418 !NILP (overlay_arrow_string
)))
16420 /* Overlay arrow in window redisplay is a fringe bitmap. */
16421 if (STRINGP (overlay_arrow_string
))
16423 struct glyph_row
*arrow_row
16424 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
16425 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
16426 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
16427 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
16428 struct glyph
*p2
, *end
;
16430 /* Copy the arrow glyphs. */
16431 while (glyph
< arrow_end
)
16434 /* Throw away padding glyphs. */
16436 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16437 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
16443 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
16448 xassert (INTEGERP (overlay_arrow_string
));
16449 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
16451 overlay_arrow_seen
= 1;
16454 /* Compute pixel dimensions of this line. */
16455 compute_line_metrics (it
);
16457 /* Remember the position at which this line ends. */
16458 row
->end
= it
->current
;
16460 /* Record whether this row ends inside an ellipsis. */
16461 row
->ends_in_ellipsis_p
16462 = (it
->method
== GET_FROM_DISPLAY_VECTOR
16463 && it
->ellipsis_p
);
16465 /* Save fringe bitmaps in this row. */
16466 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
16467 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
16468 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
16469 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
16471 it
->left_user_fringe_bitmap
= 0;
16472 it
->left_user_fringe_face_id
= 0;
16473 it
->right_user_fringe_bitmap
= 0;
16474 it
->right_user_fringe_face_id
= 0;
16476 /* Maybe set the cursor. */
16477 if (it
->w
->cursor
.vpos
< 0
16478 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
16479 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
16480 && cursor_row_p (it
->w
, row
))
16481 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
16483 /* Highlight trailing whitespace. */
16484 if (!NILP (Vshow_trailing_whitespace
))
16485 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
16487 /* Prepare for the next line. This line starts horizontally at (X
16488 HPOS) = (0 0). Vertical positions are incremented. As a
16489 convenience for the caller, IT->glyph_row is set to the next
16491 it
->current_x
= it
->hpos
= 0;
16492 it
->current_y
+= row
->height
;
16495 it
->start
= it
->current
;
16496 return row
->displays_text_p
;
16501 /***********************************************************************
16503 ***********************************************************************/
16505 /* Redisplay the menu bar in the frame for window W.
16507 The menu bar of X frames that don't have X toolkit support is
16508 displayed in a special window W->frame->menu_bar_window.
16510 The menu bar of terminal frames is treated specially as far as
16511 glyph matrices are concerned. Menu bar lines are not part of
16512 windows, so the update is done directly on the frame matrix rows
16513 for the menu bar. */
16516 display_menu_bar (w
)
16519 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16524 /* Don't do all this for graphical frames. */
16526 if (!NILP (Vwindow_system
))
16529 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
16534 if (FRAME_MAC_P (f
))
16538 #ifdef USE_X_TOOLKIT
16539 xassert (!FRAME_WINDOW_P (f
));
16540 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
16541 it
.first_visible_x
= 0;
16542 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16543 #else /* not USE_X_TOOLKIT */
16544 if (FRAME_WINDOW_P (f
))
16546 /* Menu bar lines are displayed in the desired matrix of the
16547 dummy window menu_bar_window. */
16548 struct window
*menu_w
;
16549 xassert (WINDOWP (f
->menu_bar_window
));
16550 menu_w
= XWINDOW (f
->menu_bar_window
);
16551 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
16553 it
.first_visible_x
= 0;
16554 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16558 /* This is a TTY frame, i.e. character hpos/vpos are used as
16560 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
16562 it
.first_visible_x
= 0;
16563 it
.last_visible_x
= FRAME_COLS (f
);
16565 #endif /* not USE_X_TOOLKIT */
16567 if (! mode_line_inverse_video
)
16568 /* Force the menu-bar to be displayed in the default face. */
16569 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16571 /* Clear all rows of the menu bar. */
16572 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
16574 struct glyph_row
*row
= it
.glyph_row
+ i
;
16575 clear_glyph_row (row
);
16576 row
->enabled_p
= 1;
16577 row
->full_width_p
= 1;
16580 /* Display all items of the menu bar. */
16581 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
16582 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
16584 Lisp_Object string
;
16586 /* Stop at nil string. */
16587 string
= AREF (items
, i
+ 1);
16591 /* Remember where item was displayed. */
16592 AREF (items
, i
+ 3) = make_number (it
.hpos
);
16594 /* Display the item, pad with one space. */
16595 if (it
.current_x
< it
.last_visible_x
)
16596 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
16597 SCHARS (string
) + 1, 0, 0, -1);
16600 /* Fill out the line with spaces. */
16601 if (it
.current_x
< it
.last_visible_x
)
16602 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
16604 /* Compute the total height of the lines. */
16605 compute_line_metrics (&it
);
16610 /***********************************************************************
16612 ***********************************************************************/
16614 /* Redisplay mode lines in the window tree whose root is WINDOW. If
16615 FORCE is non-zero, redisplay mode lines unconditionally.
16616 Otherwise, redisplay only mode lines that are garbaged. Value is
16617 the number of windows whose mode lines were redisplayed. */
16620 redisplay_mode_lines (window
, force
)
16621 Lisp_Object window
;
16626 while (!NILP (window
))
16628 struct window
*w
= XWINDOW (window
);
16630 if (WINDOWP (w
->hchild
))
16631 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
16632 else if (WINDOWP (w
->vchild
))
16633 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
16635 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
16636 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
16638 struct text_pos lpoint
;
16639 struct buffer
*old
= current_buffer
;
16641 /* Set the window's buffer for the mode line display. */
16642 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16643 set_buffer_internal_1 (XBUFFER (w
->buffer
));
16645 /* Point refers normally to the selected window. For any
16646 other window, set up appropriate value. */
16647 if (!EQ (window
, selected_window
))
16649 struct text_pos pt
;
16651 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
16652 if (CHARPOS (pt
) < BEGV
)
16653 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16654 else if (CHARPOS (pt
) > (ZV
- 1))
16655 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
16657 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
16660 /* Display mode lines. */
16661 clear_glyph_matrix (w
->desired_matrix
);
16662 if (display_mode_lines (w
))
16665 w
->must_be_updated_p
= 1;
16668 /* Restore old settings. */
16669 set_buffer_internal_1 (old
);
16670 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16680 /* Display the mode and/or top line of window W. Value is the number
16681 of mode lines displayed. */
16684 display_mode_lines (w
)
16687 Lisp_Object old_selected_window
, old_selected_frame
;
16690 old_selected_frame
= selected_frame
;
16691 selected_frame
= w
->frame
;
16692 old_selected_window
= selected_window
;
16693 XSETWINDOW (selected_window
, w
);
16695 /* These will be set while the mode line specs are processed. */
16696 line_number_displayed
= 0;
16697 w
->column_number_displayed
= Qnil
;
16699 if (WINDOW_WANTS_MODELINE_P (w
))
16701 struct window
*sel_w
= XWINDOW (old_selected_window
);
16703 /* Select mode line face based on the real selected window. */
16704 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
16705 current_buffer
->mode_line_format
);
16709 if (WINDOW_WANTS_HEADER_LINE_P (w
))
16711 display_mode_line (w
, HEADER_LINE_FACE_ID
,
16712 current_buffer
->header_line_format
);
16716 selected_frame
= old_selected_frame
;
16717 selected_window
= old_selected_window
;
16722 /* Display mode or top line of window W. FACE_ID specifies which line
16723 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
16724 FORMAT is the mode line format to display. Value is the pixel
16725 height of the mode line displayed. */
16728 display_mode_line (w
, face_id
, format
)
16730 enum face_id face_id
;
16731 Lisp_Object format
;
16735 int count
= SPECPDL_INDEX ();
16737 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16738 /* Don't extend on a previously drawn mode-line.
16739 This may happen if called from pos_visible_p. */
16740 it
.glyph_row
->enabled_p
= 0;
16741 prepare_desired_row (it
.glyph_row
);
16743 it
.glyph_row
->mode_line_p
= 1;
16745 if (! mode_line_inverse_video
)
16746 /* Force the mode-line to be displayed in the default face. */
16747 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16749 record_unwind_protect (unwind_format_mode_line
,
16750 format_mode_line_unwind_data (NULL
, 0));
16752 mode_line_target
= MODE_LINE_DISPLAY
;
16754 /* Temporarily make frame's keyboard the current kboard so that
16755 kboard-local variables in the mode_line_format will get the right
16757 push_frame_kboard (it
.f
);
16758 record_unwind_save_match_data ();
16759 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16760 pop_frame_kboard ();
16762 unbind_to (count
, Qnil
);
16764 /* Fill up with spaces. */
16765 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
16767 compute_line_metrics (&it
);
16768 it
.glyph_row
->full_width_p
= 1;
16769 it
.glyph_row
->continued_p
= 0;
16770 it
.glyph_row
->truncated_on_left_p
= 0;
16771 it
.glyph_row
->truncated_on_right_p
= 0;
16773 /* Make a 3D mode-line have a shadow at its right end. */
16774 face
= FACE_FROM_ID (it
.f
, face_id
);
16775 extend_face_to_end_of_line (&it
);
16776 if (face
->box
!= FACE_NO_BOX
)
16778 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
16779 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
16780 last
->right_box_line_p
= 1;
16783 return it
.glyph_row
->height
;
16786 /* Move element ELT in LIST to the front of LIST.
16787 Return the updated list. */
16790 move_elt_to_front (elt
, list
)
16791 Lisp_Object elt
, list
;
16793 register Lisp_Object tail
, prev
;
16794 register Lisp_Object tem
;
16798 while (CONSP (tail
))
16804 /* Splice out the link TAIL. */
16806 list
= XCDR (tail
);
16808 Fsetcdr (prev
, XCDR (tail
));
16810 /* Now make it the first. */
16811 Fsetcdr (tail
, list
);
16816 tail
= XCDR (tail
);
16820 /* Not found--return unchanged LIST. */
16824 /* Contribute ELT to the mode line for window IT->w. How it
16825 translates into text depends on its data type.
16827 IT describes the display environment in which we display, as usual.
16829 DEPTH is the depth in recursion. It is used to prevent
16830 infinite recursion here.
16832 FIELD_WIDTH is the number of characters the display of ELT should
16833 occupy in the mode line, and PRECISION is the maximum number of
16834 characters to display from ELT's representation. See
16835 display_string for details.
16837 Returns the hpos of the end of the text generated by ELT.
16839 PROPS is a property list to add to any string we encounter.
16841 If RISKY is nonzero, remove (disregard) any properties in any string
16842 we encounter, and ignore :eval and :propertize.
16844 The global variable `mode_line_target' determines whether the
16845 output is passed to `store_mode_line_noprop',
16846 `store_mode_line_string', or `display_string'. */
16849 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
16852 int field_width
, precision
;
16853 Lisp_Object elt
, props
;
16856 int n
= 0, field
, prec
;
16861 elt
= build_string ("*too-deep*");
16865 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
16869 /* A string: output it and check for %-constructs within it. */
16873 if (SCHARS (elt
) > 0
16874 && (!NILP (props
) || risky
))
16876 Lisp_Object oprops
, aelt
;
16877 oprops
= Ftext_properties_at (make_number (0), elt
);
16879 /* If the starting string's properties are not what
16880 we want, translate the string. Also, if the string
16881 is risky, do that anyway. */
16883 if (NILP (Fequal (props
, oprops
)) || risky
)
16885 /* If the starting string has properties,
16886 merge the specified ones onto the existing ones. */
16887 if (! NILP (oprops
) && !risky
)
16891 oprops
= Fcopy_sequence (oprops
);
16893 while (CONSP (tem
))
16895 oprops
= Fplist_put (oprops
, XCAR (tem
),
16896 XCAR (XCDR (tem
)));
16897 tem
= XCDR (XCDR (tem
));
16902 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
16903 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
16905 /* AELT is what we want. Move it to the front
16906 without consing. */
16908 mode_line_proptrans_alist
16909 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
16915 /* If AELT has the wrong props, it is useless.
16916 so get rid of it. */
16918 mode_line_proptrans_alist
16919 = Fdelq (aelt
, mode_line_proptrans_alist
);
16921 elt
= Fcopy_sequence (elt
);
16922 Fset_text_properties (make_number (0), Flength (elt
),
16924 /* Add this item to mode_line_proptrans_alist. */
16925 mode_line_proptrans_alist
16926 = Fcons (Fcons (elt
, props
),
16927 mode_line_proptrans_alist
);
16928 /* Truncate mode_line_proptrans_alist
16929 to at most 50 elements. */
16930 tem
= Fnthcdr (make_number (50),
16931 mode_line_proptrans_alist
);
16933 XSETCDR (tem
, Qnil
);
16942 prec
= precision
- n
;
16943 switch (mode_line_target
)
16945 case MODE_LINE_NOPROP
:
16946 case MODE_LINE_TITLE
:
16947 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
16949 case MODE_LINE_STRING
:
16950 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
16952 case MODE_LINE_DISPLAY
:
16953 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
16954 0, prec
, 0, STRING_MULTIBYTE (elt
));
16961 /* Handle the non-literal case. */
16963 while ((precision
<= 0 || n
< precision
)
16964 && SREF (elt
, offset
) != 0
16965 && (mode_line_target
!= MODE_LINE_DISPLAY
16966 || it
->current_x
< it
->last_visible_x
))
16968 int last_offset
= offset
;
16970 /* Advance to end of string or next format specifier. */
16971 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
16974 if (offset
- 1 != last_offset
)
16976 int nchars
, nbytes
;
16978 /* Output to end of string or up to '%'. Field width
16979 is length of string. Don't output more than
16980 PRECISION allows us. */
16983 prec
= c_string_width (SDATA (elt
) + last_offset
,
16984 offset
- last_offset
, precision
- n
,
16987 switch (mode_line_target
)
16989 case MODE_LINE_NOPROP
:
16990 case MODE_LINE_TITLE
:
16991 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
16993 case MODE_LINE_STRING
:
16995 int bytepos
= last_offset
;
16996 int charpos
= string_byte_to_char (elt
, bytepos
);
16997 int endpos
= (precision
<= 0
16998 ? string_byte_to_char (elt
, offset
)
16999 : charpos
+ nchars
);
17001 n
+= store_mode_line_string (NULL
,
17002 Fsubstring (elt
, make_number (charpos
),
17003 make_number (endpos
)),
17007 case MODE_LINE_DISPLAY
:
17009 int bytepos
= last_offset
;
17010 int charpos
= string_byte_to_char (elt
, bytepos
);
17012 if (precision
<= 0)
17013 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
17014 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
17016 STRING_MULTIBYTE (elt
));
17021 else /* c == '%' */
17023 int percent_position
= offset
;
17025 /* Get the specified minimum width. Zero means
17028 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
17029 field
= field
* 10 + c
- '0';
17031 /* Don't pad beyond the total padding allowed. */
17032 if (field_width
- n
> 0 && field
> field_width
- n
)
17033 field
= field_width
- n
;
17035 /* Note that either PRECISION <= 0 or N < PRECISION. */
17036 prec
= precision
- n
;
17039 n
+= display_mode_element (it
, depth
, field
, prec
,
17040 Vglobal_mode_string
, props
,
17045 int bytepos
, charpos
;
17046 unsigned char *spec
;
17048 bytepos
= percent_position
;
17049 charpos
= (STRING_MULTIBYTE (elt
)
17050 ? string_byte_to_char (elt
, bytepos
)
17054 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
17056 switch (mode_line_target
)
17058 case MODE_LINE_NOPROP
:
17059 case MODE_LINE_TITLE
:
17060 n
+= store_mode_line_noprop (spec
, field
, prec
);
17062 case MODE_LINE_STRING
:
17064 int len
= strlen (spec
);
17065 Lisp_Object tem
= make_string (spec
, len
);
17066 props
= Ftext_properties_at (make_number (charpos
), elt
);
17067 /* Should only keep face property in props */
17068 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
17071 case MODE_LINE_DISPLAY
:
17073 int nglyphs_before
, nwritten
;
17075 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17076 nwritten
= display_string (spec
, Qnil
, elt
,
17081 /* Assign to the glyphs written above the
17082 string where the `%x' came from, position
17086 struct glyph
*glyph
17087 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
17091 for (i
= 0; i
< nwritten
; ++i
)
17093 glyph
[i
].object
= elt
;
17094 glyph
[i
].charpos
= charpos
;
17111 /* A symbol: process the value of the symbol recursively
17112 as if it appeared here directly. Avoid error if symbol void.
17113 Special case: if value of symbol is a string, output the string
17116 register Lisp_Object tem
;
17118 /* If the variable is not marked as risky to set
17119 then its contents are risky to use. */
17120 if (NILP (Fget (elt
, Qrisky_local_variable
)))
17123 tem
= Fboundp (elt
);
17126 tem
= Fsymbol_value (elt
);
17127 /* If value is a string, output that string literally:
17128 don't check for % within it. */
17132 if (!EQ (tem
, elt
))
17134 /* Give up right away for nil or t. */
17144 register Lisp_Object car
, tem
;
17146 /* A cons cell: five distinct cases.
17147 If first element is :eval or :propertize, do something special.
17148 If first element is a string or a cons, process all the elements
17149 and effectively concatenate them.
17150 If first element is a negative number, truncate displaying cdr to
17151 at most that many characters. If positive, pad (with spaces)
17152 to at least that many characters.
17153 If first element is a symbol, process the cadr or caddr recursively
17154 according to whether the symbol's value is non-nil or nil. */
17156 if (EQ (car
, QCeval
))
17158 /* An element of the form (:eval FORM) means evaluate FORM
17159 and use the result as mode line elements. */
17164 if (CONSP (XCDR (elt
)))
17167 spec
= safe_eval (XCAR (XCDR (elt
)));
17168 n
+= display_mode_element (it
, depth
, field_width
- n
,
17169 precision
- n
, spec
, props
,
17173 else if (EQ (car
, QCpropertize
))
17175 /* An element of the form (:propertize ELT PROPS...)
17176 means display ELT but applying properties PROPS. */
17181 if (CONSP (XCDR (elt
)))
17182 n
+= display_mode_element (it
, depth
, field_width
- n
,
17183 precision
- n
, XCAR (XCDR (elt
)),
17184 XCDR (XCDR (elt
)), risky
);
17186 else if (SYMBOLP (car
))
17188 tem
= Fboundp (car
);
17192 /* elt is now the cdr, and we know it is a cons cell.
17193 Use its car if CAR has a non-nil value. */
17196 tem
= Fsymbol_value (car
);
17203 /* Symbol's value is nil (or symbol is unbound)
17204 Get the cddr of the original list
17205 and if possible find the caddr and use that. */
17209 else if (!CONSP (elt
))
17214 else if (INTEGERP (car
))
17216 register int lim
= XINT (car
);
17220 /* Negative int means reduce maximum width. */
17221 if (precision
<= 0)
17224 precision
= min (precision
, -lim
);
17228 /* Padding specified. Don't let it be more than
17229 current maximum. */
17231 lim
= min (precision
, lim
);
17233 /* If that's more padding than already wanted, queue it.
17234 But don't reduce padding already specified even if
17235 that is beyond the current truncation point. */
17236 field_width
= max (lim
, field_width
);
17240 else if (STRINGP (car
) || CONSP (car
))
17242 register int limit
= 50;
17243 /* Limit is to protect against circular lists. */
17246 && (precision
<= 0 || n
< precision
))
17248 n
+= display_mode_element (it
, depth
,
17249 /* Do padding only after the last
17250 element in the list. */
17251 (! CONSP (XCDR (elt
))
17254 precision
- n
, XCAR (elt
),
17264 elt
= build_string ("*invalid*");
17268 /* Pad to FIELD_WIDTH. */
17269 if (field_width
> 0 && n
< field_width
)
17271 switch (mode_line_target
)
17273 case MODE_LINE_NOPROP
:
17274 case MODE_LINE_TITLE
:
17275 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
17277 case MODE_LINE_STRING
:
17278 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
17280 case MODE_LINE_DISPLAY
:
17281 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
17290 /* Store a mode-line string element in mode_line_string_list.
17292 If STRING is non-null, display that C string. Otherwise, the Lisp
17293 string LISP_STRING is displayed.
17295 FIELD_WIDTH is the minimum number of output glyphs to produce.
17296 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17297 with spaces. FIELD_WIDTH <= 0 means don't pad.
17299 PRECISION is the maximum number of characters to output from
17300 STRING. PRECISION <= 0 means don't truncate the string.
17302 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
17303 properties to the string.
17305 PROPS are the properties to add to the string.
17306 The mode_line_string_face face property is always added to the string.
17310 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
17312 Lisp_Object lisp_string
;
17321 if (string
!= NULL
)
17323 len
= strlen (string
);
17324 if (precision
> 0 && len
> precision
)
17326 lisp_string
= make_string (string
, len
);
17328 props
= mode_line_string_face_prop
;
17329 else if (!NILP (mode_line_string_face
))
17331 Lisp_Object face
= Fplist_get (props
, Qface
);
17332 props
= Fcopy_sequence (props
);
17334 face
= mode_line_string_face
;
17336 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17337 props
= Fplist_put (props
, Qface
, face
);
17339 Fadd_text_properties (make_number (0), make_number (len
),
17340 props
, lisp_string
);
17344 len
= XFASTINT (Flength (lisp_string
));
17345 if (precision
> 0 && len
> precision
)
17348 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
17351 if (!NILP (mode_line_string_face
))
17355 props
= Ftext_properties_at (make_number (0), lisp_string
);
17356 face
= Fplist_get (props
, Qface
);
17358 face
= mode_line_string_face
;
17360 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17361 props
= Fcons (Qface
, Fcons (face
, Qnil
));
17363 lisp_string
= Fcopy_sequence (lisp_string
);
17366 Fadd_text_properties (make_number (0), make_number (len
),
17367 props
, lisp_string
);
17372 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17376 if (field_width
> len
)
17378 field_width
-= len
;
17379 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17381 Fadd_text_properties (make_number (0), make_number (field_width
),
17382 props
, lisp_string
);
17383 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17391 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17393 doc
: /* Format a string out of a mode line format specification.
17394 First arg FORMAT specifies the mode line format (see `mode-line-format'
17395 for details) to use.
17397 Optional second arg FACE specifies the face property to put
17398 on all characters for which no face is specified.
17399 The value t means whatever face the window's mode line currently uses
17400 \(either `mode-line' or `mode-line-inactive', depending).
17401 A value of nil means the default is no face property.
17402 If FACE is an integer, the value string has no text properties.
17404 Optional third and fourth args WINDOW and BUFFER specify the window
17405 and buffer to use as the context for the formatting (defaults
17406 are the selected window and the window's buffer). */)
17407 (format
, face
, window
, buffer
)
17408 Lisp_Object format
, face
, window
, buffer
;
17413 struct buffer
*old_buffer
= NULL
;
17415 int no_props
= INTEGERP (face
);
17416 int count
= SPECPDL_INDEX ();
17418 int string_start
= 0;
17421 window
= selected_window
;
17422 CHECK_WINDOW (window
);
17423 w
= XWINDOW (window
);
17426 buffer
= w
->buffer
;
17427 CHECK_BUFFER (buffer
);
17429 /* Make formatting the modeline a non-op when noninteractive, otherwise
17430 there will be problems later caused by a partially initialized frame. */
17431 if (NILP (format
) || noninteractive
)
17432 return build_string ("");
17440 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
17441 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
17445 face_id
= DEFAULT_FACE_ID
;
17447 if (XBUFFER (buffer
) != current_buffer
)
17448 old_buffer
= current_buffer
;
17450 /* Save things including mode_line_proptrans_alist,
17451 and set that to nil so that we don't alter the outer value. */
17452 record_unwind_protect (unwind_format_mode_line
,
17453 format_mode_line_unwind_data (old_buffer
, 1));
17454 mode_line_proptrans_alist
= Qnil
;
17457 set_buffer_internal_1 (XBUFFER (buffer
));
17459 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17463 mode_line_target
= MODE_LINE_NOPROP
;
17464 mode_line_string_face_prop
= Qnil
;
17465 mode_line_string_list
= Qnil
;
17466 string_start
= MODE_LINE_NOPROP_LEN (0);
17470 mode_line_target
= MODE_LINE_STRING
;
17471 mode_line_string_list
= Qnil
;
17472 mode_line_string_face
= face
;
17473 mode_line_string_face_prop
17474 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
17477 push_frame_kboard (it
.f
);
17478 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17479 pop_frame_kboard ();
17483 len
= MODE_LINE_NOPROP_LEN (string_start
);
17484 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
17488 mode_line_string_list
= Fnreverse (mode_line_string_list
);
17489 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
17490 make_string ("", 0));
17493 unbind_to (count
, Qnil
);
17497 /* Write a null-terminated, right justified decimal representation of
17498 the positive integer D to BUF using a minimal field width WIDTH. */
17501 pint2str (buf
, width
, d
)
17502 register char *buf
;
17503 register int width
;
17506 register char *p
= buf
;
17514 *p
++ = d
% 10 + '0';
17519 for (width
-= (int) (p
- buf
); width
> 0; --width
)
17530 /* Write a null-terminated, right justified decimal and "human
17531 readable" representation of the nonnegative integer D to BUF using
17532 a minimal field width WIDTH. D should be smaller than 999.5e24. */
17534 static const char power_letter
[] =
17548 pint2hrstr (buf
, width
, d
)
17553 /* We aim to represent the nonnegative integer D as
17554 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
17557 /* -1 means: do not use TENTHS. */
17561 /* Length of QUOTIENT.TENTHS as a string. */
17567 if (1000 <= quotient
)
17569 /* Scale to the appropriate EXPONENT. */
17572 remainder
= quotient
% 1000;
17576 while (1000 <= quotient
);
17578 /* Round to nearest and decide whether to use TENTHS or not. */
17581 tenths
= remainder
/ 100;
17582 if (50 <= remainder
% 100)
17589 if (quotient
== 10)
17597 if (500 <= remainder
)
17599 if (quotient
< 999)
17610 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
17611 if (tenths
== -1 && quotient
<= 99)
17618 p
= psuffix
= buf
+ max (width
, length
);
17620 /* Print EXPONENT. */
17622 *psuffix
++ = power_letter
[exponent
];
17625 /* Print TENTHS. */
17628 *--p
= '0' + tenths
;
17632 /* Print QUOTIENT. */
17635 int digit
= quotient
% 10;
17636 *--p
= '0' + digit
;
17638 while ((quotient
/= 10) != 0);
17640 /* Print leading spaces. */
17645 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
17646 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
17647 type of CODING_SYSTEM. Return updated pointer into BUF. */
17649 static unsigned char invalid_eol_type
[] = "(*invalid*)";
17652 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
17653 Lisp_Object coding_system
;
17654 register char *buf
;
17658 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
17659 const unsigned char *eol_str
;
17661 /* The EOL conversion we are using. */
17662 Lisp_Object eoltype
;
17664 val
= Fget (coding_system
, Qcoding_system
);
17667 if (!VECTORP (val
)) /* Not yet decided. */
17672 eoltype
= eol_mnemonic_undecided
;
17673 /* Don't mention EOL conversion if it isn't decided. */
17677 Lisp_Object eolvalue
;
17679 eolvalue
= Fget (coding_system
, Qeol_type
);
17682 *buf
++ = XFASTINT (AREF (val
, 1));
17686 /* The EOL conversion that is normal on this system. */
17688 if (NILP (eolvalue
)) /* Not yet decided. */
17689 eoltype
= eol_mnemonic_undecided
;
17690 else if (VECTORP (eolvalue
)) /* Not yet decided. */
17691 eoltype
= eol_mnemonic_undecided
;
17692 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
17693 eoltype
= (XFASTINT (eolvalue
) == 0
17694 ? eol_mnemonic_unix
17695 : (XFASTINT (eolvalue
) == 1
17696 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
17702 /* Mention the EOL conversion if it is not the usual one. */
17703 if (STRINGP (eoltype
))
17705 eol_str
= SDATA (eoltype
);
17706 eol_str_len
= SBYTES (eoltype
);
17708 else if (INTEGERP (eoltype
)
17709 && CHAR_VALID_P (XINT (eoltype
), 0))
17711 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
17712 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
17717 eol_str
= invalid_eol_type
;
17718 eol_str_len
= sizeof (invalid_eol_type
) - 1;
17720 bcopy (eol_str
, buf
, eol_str_len
);
17721 buf
+= eol_str_len
;
17727 /* Return a string for the output of a mode line %-spec for window W,
17728 generated by character C. PRECISION >= 0 means don't return a
17729 string longer than that value. FIELD_WIDTH > 0 means pad the
17730 string returned with spaces to that value. Return 1 in *MULTIBYTE
17731 if the result is multibyte text.
17733 Note we operate on the current buffer for most purposes,
17734 the exception being w->base_line_pos. */
17736 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
17739 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
17742 int field_width
, precision
;
17746 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17747 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
17748 struct buffer
*b
= current_buffer
;
17756 if (!NILP (b
->read_only
))
17758 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17763 /* This differs from %* only for a modified read-only buffer. */
17764 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17766 if (!NILP (b
->read_only
))
17771 /* This differs from %* in ignoring read-only-ness. */
17772 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17784 if (command_loop_level
> 5)
17786 p
= decode_mode_spec_buf
;
17787 for (i
= 0; i
< command_loop_level
; i
++)
17790 return decode_mode_spec_buf
;
17798 if (command_loop_level
> 5)
17800 p
= decode_mode_spec_buf
;
17801 for (i
= 0; i
< command_loop_level
; i
++)
17804 return decode_mode_spec_buf
;
17811 /* Let lots_of_dashes be a string of infinite length. */
17812 if (mode_line_target
== MODE_LINE_NOPROP
||
17813 mode_line_target
== MODE_LINE_STRING
)
17815 if (field_width
<= 0
17816 || field_width
> sizeof (lots_of_dashes
))
17818 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
17819 decode_mode_spec_buf
[i
] = '-';
17820 decode_mode_spec_buf
[i
] = '\0';
17821 return decode_mode_spec_buf
;
17824 return lots_of_dashes
;
17832 /* %c and %l are ignored in `frame-title-format'.
17833 (In redisplay_internal, the frame title is drawn _before_ the
17834 windows are updated, so the stuff which depends on actual
17835 window contents (such as %l) may fail to render properly, or
17836 even crash emacs.) */
17837 if (mode_line_target
== MODE_LINE_TITLE
)
17841 int col
= (int) current_column (); /* iftc */
17842 w
->column_number_displayed
= make_number (col
);
17843 pint2str (decode_mode_spec_buf
, field_width
, col
);
17844 return decode_mode_spec_buf
;
17848 #ifndef SYSTEM_MALLOC
17850 if (NILP (Vmemory_full
))
17853 return "!MEM FULL! ";
17860 /* %F displays the frame name. */
17861 if (!NILP (f
->title
))
17862 return (char *) SDATA (f
->title
);
17863 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
17864 return (char *) SDATA (f
->name
);
17873 int size
= ZV
- BEGV
;
17874 pint2str (decode_mode_spec_buf
, field_width
, size
);
17875 return decode_mode_spec_buf
;
17880 int size
= ZV
- BEGV
;
17881 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
17882 return decode_mode_spec_buf
;
17887 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
17888 int topline
, nlines
, junk
, height
;
17890 /* %c and %l are ignored in `frame-title-format'. */
17891 if (mode_line_target
== MODE_LINE_TITLE
)
17894 startpos
= XMARKER (w
->start
)->charpos
;
17895 startpos_byte
= marker_byte_position (w
->start
);
17896 height
= WINDOW_TOTAL_LINES (w
);
17898 /* If we decided that this buffer isn't suitable for line numbers,
17899 don't forget that too fast. */
17900 if (EQ (w
->base_line_pos
, w
->buffer
))
17902 /* But do forget it, if the window shows a different buffer now. */
17903 else if (BUFFERP (w
->base_line_pos
))
17904 w
->base_line_pos
= Qnil
;
17906 /* If the buffer is very big, don't waste time. */
17907 if (INTEGERP (Vline_number_display_limit
)
17908 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
17910 w
->base_line_pos
= Qnil
;
17911 w
->base_line_number
= Qnil
;
17915 if (!NILP (w
->base_line_number
)
17916 && !NILP (w
->base_line_pos
)
17917 && XFASTINT (w
->base_line_pos
) <= startpos
)
17919 line
= XFASTINT (w
->base_line_number
);
17920 linepos
= XFASTINT (w
->base_line_pos
);
17921 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
17926 linepos
= BUF_BEGV (b
);
17927 linepos_byte
= BUF_BEGV_BYTE (b
);
17930 /* Count lines from base line to window start position. */
17931 nlines
= display_count_lines (linepos
, linepos_byte
,
17935 topline
= nlines
+ line
;
17937 /* Determine a new base line, if the old one is too close
17938 or too far away, or if we did not have one.
17939 "Too close" means it's plausible a scroll-down would
17940 go back past it. */
17941 if (startpos
== BUF_BEGV (b
))
17943 w
->base_line_number
= make_number (topline
);
17944 w
->base_line_pos
= make_number (BUF_BEGV (b
));
17946 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
17947 || linepos
== BUF_BEGV (b
))
17949 int limit
= BUF_BEGV (b
);
17950 int limit_byte
= BUF_BEGV_BYTE (b
);
17952 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
17954 if (startpos
- distance
> limit
)
17956 limit
= startpos
- distance
;
17957 limit_byte
= CHAR_TO_BYTE (limit
);
17960 nlines
= display_count_lines (startpos
, startpos_byte
,
17962 - (height
* 2 + 30),
17964 /* If we couldn't find the lines we wanted within
17965 line_number_display_limit_width chars per line,
17966 give up on line numbers for this window. */
17967 if (position
== limit_byte
&& limit
== startpos
- distance
)
17969 w
->base_line_pos
= w
->buffer
;
17970 w
->base_line_number
= Qnil
;
17974 w
->base_line_number
= make_number (topline
- nlines
);
17975 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
17978 /* Now count lines from the start pos to point. */
17979 nlines
= display_count_lines (startpos
, startpos_byte
,
17980 PT_BYTE
, PT
, &junk
);
17982 /* Record that we did display the line number. */
17983 line_number_displayed
= 1;
17985 /* Make the string to show. */
17986 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
17987 return decode_mode_spec_buf
;
17990 char* p
= decode_mode_spec_buf
;
17991 int pad
= field_width
- 2;
17997 return decode_mode_spec_buf
;
18003 obj
= b
->mode_name
;
18007 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
18013 int pos
= marker_position (w
->start
);
18014 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18016 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
18018 if (pos
<= BUF_BEGV (b
))
18023 else if (pos
<= BUF_BEGV (b
))
18027 if (total
> 1000000)
18028 /* Do it differently for a large value, to avoid overflow. */
18029 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18031 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18032 /* We can't normally display a 3-digit number,
18033 so get us a 2-digit number that is close. */
18036 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18037 return decode_mode_spec_buf
;
18041 /* Display percentage of size above the bottom of the screen. */
18044 int toppos
= marker_position (w
->start
);
18045 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
18046 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18048 if (botpos
>= BUF_ZV (b
))
18050 if (toppos
<= BUF_BEGV (b
))
18057 if (total
> 1000000)
18058 /* Do it differently for a large value, to avoid overflow. */
18059 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18061 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18062 /* We can't normally display a 3-digit number,
18063 so get us a 2-digit number that is close. */
18066 if (toppos
<= BUF_BEGV (b
))
18067 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
18069 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18070 return decode_mode_spec_buf
;
18075 /* status of process */
18076 obj
= Fget_buffer_process (Fcurrent_buffer ());
18078 return "no process";
18079 #ifdef subprocesses
18080 obj
= Fsymbol_name (Fprocess_status (obj
));
18084 case 't': /* indicate TEXT or BINARY */
18085 #ifdef MODE_LINE_BINARY_TEXT
18086 return MODE_LINE_BINARY_TEXT (b
);
18092 /* coding-system (not including end-of-line format) */
18094 /* coding-system (including end-of-line type) */
18096 int eol_flag
= (c
== 'Z');
18097 char *p
= decode_mode_spec_buf
;
18099 if (! FRAME_WINDOW_P (f
))
18101 /* No need to mention EOL here--the terminal never needs
18102 to do EOL conversion. */
18103 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
18104 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
18106 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
18109 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
18110 #ifdef subprocesses
18111 obj
= Fget_buffer_process (Fcurrent_buffer ());
18112 if (PROCESSP (obj
))
18114 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
18116 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
18119 #endif /* subprocesses */
18122 return decode_mode_spec_buf
;
18128 *multibyte
= STRING_MULTIBYTE (obj
);
18129 return (char *) SDATA (obj
);
18136 /* Count up to COUNT lines starting from START / START_BYTE.
18137 But don't go beyond LIMIT_BYTE.
18138 Return the number of lines thus found (always nonnegative).
18140 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
18143 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
18144 int start
, start_byte
, limit_byte
, count
;
18147 register unsigned char *cursor
;
18148 unsigned char *base
;
18150 register int ceiling
;
18151 register unsigned char *ceiling_addr
;
18152 int orig_count
= count
;
18154 /* If we are not in selective display mode,
18155 check only for newlines. */
18156 int selective_display
= (!NILP (current_buffer
->selective_display
)
18157 && !INTEGERP (current_buffer
->selective_display
));
18161 while (start_byte
< limit_byte
)
18163 ceiling
= BUFFER_CEILING_OF (start_byte
);
18164 ceiling
= min (limit_byte
- 1, ceiling
);
18165 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
18166 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
18169 if (selective_display
)
18170 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
18173 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
18176 if (cursor
!= ceiling_addr
)
18180 start_byte
+= cursor
- base
+ 1;
18181 *byte_pos_ptr
= start_byte
;
18185 if (++cursor
== ceiling_addr
)
18191 start_byte
+= cursor
- base
;
18196 while (start_byte
> limit_byte
)
18198 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
18199 ceiling
= max (limit_byte
, ceiling
);
18200 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
18201 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
18204 if (selective_display
)
18205 while (--cursor
!= ceiling_addr
18206 && *cursor
!= '\n' && *cursor
!= 015)
18209 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
18212 if (cursor
!= ceiling_addr
)
18216 start_byte
+= cursor
- base
+ 1;
18217 *byte_pos_ptr
= start_byte
;
18218 /* When scanning backwards, we should
18219 not count the newline posterior to which we stop. */
18220 return - orig_count
- 1;
18226 /* Here we add 1 to compensate for the last decrement
18227 of CURSOR, which took it past the valid range. */
18228 start_byte
+= cursor
- base
+ 1;
18232 *byte_pos_ptr
= limit_byte
;
18235 return - orig_count
+ count
;
18236 return orig_count
- count
;
18242 /***********************************************************************
18244 ***********************************************************************/
18246 /* Display a NUL-terminated string, starting with index START.
18248 If STRING is non-null, display that C string. Otherwise, the Lisp
18249 string LISP_STRING is displayed.
18251 If FACE_STRING is not nil, FACE_STRING_POS is a position in
18252 FACE_STRING. Display STRING or LISP_STRING with the face at
18253 FACE_STRING_POS in FACE_STRING:
18255 Display the string in the environment given by IT, but use the
18256 standard display table, temporarily.
18258 FIELD_WIDTH is the minimum number of output glyphs to produce.
18259 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18260 with spaces. If STRING has more characters, more than FIELD_WIDTH
18261 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
18263 PRECISION is the maximum number of characters to output from
18264 STRING. PRECISION < 0 means don't truncate the string.
18266 This is roughly equivalent to printf format specifiers:
18268 FIELD_WIDTH PRECISION PRINTF
18269 ----------------------------------------
18275 MULTIBYTE zero means do not display multibyte chars, > 0 means do
18276 display them, and < 0 means obey the current buffer's value of
18277 enable_multibyte_characters.
18279 Value is the number of columns displayed. */
18282 display_string (string
, lisp_string
, face_string
, face_string_pos
,
18283 start
, it
, field_width
, precision
, max_x
, multibyte
)
18284 unsigned char *string
;
18285 Lisp_Object lisp_string
;
18286 Lisp_Object face_string
;
18287 int face_string_pos
;
18290 int field_width
, precision
, max_x
;
18293 int hpos_at_start
= it
->hpos
;
18294 int saved_face_id
= it
->face_id
;
18295 struct glyph_row
*row
= it
->glyph_row
;
18297 /* Initialize the iterator IT for iteration over STRING beginning
18298 with index START. */
18299 reseat_to_string (it
, string
, lisp_string
, start
,
18300 precision
, field_width
, multibyte
);
18302 /* If displaying STRING, set up the face of the iterator
18303 from LISP_STRING, if that's given. */
18304 if (STRINGP (face_string
))
18310 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
18311 0, it
->region_beg_charpos
,
18312 it
->region_end_charpos
,
18313 &endptr
, it
->base_face_id
, 0);
18314 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18315 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
18318 /* Set max_x to the maximum allowed X position. Don't let it go
18319 beyond the right edge of the window. */
18321 max_x
= it
->last_visible_x
;
18323 max_x
= min (max_x
, it
->last_visible_x
);
18325 /* Skip over display elements that are not visible. because IT->w is
18327 if (it
->current_x
< it
->first_visible_x
)
18328 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
18329 MOVE_TO_POS
| MOVE_TO_X
);
18331 row
->ascent
= it
->max_ascent
;
18332 row
->height
= it
->max_ascent
+ it
->max_descent
;
18333 row
->phys_ascent
= it
->max_phys_ascent
;
18334 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18335 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18337 /* This condition is for the case that we are called with current_x
18338 past last_visible_x. */
18339 while (it
->current_x
< max_x
)
18341 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
18343 /* Get the next display element. */
18344 if (!get_next_display_element (it
))
18347 /* Produce glyphs. */
18348 x_before
= it
->current_x
;
18349 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18350 PRODUCE_GLYPHS (it
);
18352 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
18355 while (i
< nglyphs
)
18357 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18359 if (!it
->truncate_lines_p
18360 && x
+ glyph
->pixel_width
> max_x
)
18362 /* End of continued line or max_x reached. */
18363 if (CHAR_GLYPH_PADDING_P (*glyph
))
18365 /* A wide character is unbreakable. */
18366 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18367 it
->current_x
= x_before
;
18371 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18376 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
18378 /* Glyph is at least partially visible. */
18380 if (x
< it
->first_visible_x
)
18381 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18385 /* Glyph is off the left margin of the display area.
18386 Should not happen. */
18390 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18391 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18392 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18393 row
->phys_height
= max (row
->phys_height
,
18394 it
->max_phys_ascent
+ it
->max_phys_descent
);
18395 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18396 it
->max_extra_line_spacing
);
18397 x
+= glyph
->pixel_width
;
18401 /* Stop if max_x reached. */
18405 /* Stop at line ends. */
18406 if (ITERATOR_AT_END_OF_LINE_P (it
))
18408 it
->continuation_lines_width
= 0;
18412 set_iterator_to_next (it
, 1);
18414 /* Stop if truncating at the right edge. */
18415 if (it
->truncate_lines_p
18416 && it
->current_x
>= it
->last_visible_x
)
18418 /* Add truncation mark, but don't do it if the line is
18419 truncated at a padding space. */
18420 if (IT_CHARPOS (*it
) < it
->string_nchars
)
18422 if (!FRAME_WINDOW_P (it
->f
))
18426 if (it
->current_x
> it
->last_visible_x
)
18428 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18429 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18431 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18433 row
->used
[TEXT_AREA
] = i
;
18434 produce_special_glyphs (it
, IT_TRUNCATION
);
18437 produce_special_glyphs (it
, IT_TRUNCATION
);
18439 it
->glyph_row
->truncated_on_right_p
= 1;
18445 /* Maybe insert a truncation at the left. */
18446 if (it
->first_visible_x
18447 && IT_CHARPOS (*it
) > 0)
18449 if (!FRAME_WINDOW_P (it
->f
))
18450 insert_left_trunc_glyphs (it
);
18451 it
->glyph_row
->truncated_on_left_p
= 1;
18454 it
->face_id
= saved_face_id
;
18456 /* Value is number of columns displayed. */
18457 return it
->hpos
- hpos_at_start
;
18462 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
18463 appears as an element of LIST or as the car of an element of LIST.
18464 If PROPVAL is a list, compare each element against LIST in that
18465 way, and return 1/2 if any element of PROPVAL is found in LIST.
18466 Otherwise return 0. This function cannot quit.
18467 The return value is 2 if the text is invisible but with an ellipsis
18468 and 1 if it's invisible and without an ellipsis. */
18471 invisible_p (propval
, list
)
18472 register Lisp_Object propval
;
18475 register Lisp_Object tail
, proptail
;
18477 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18479 register Lisp_Object tem
;
18481 if (EQ (propval
, tem
))
18483 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
18484 return NILP (XCDR (tem
)) ? 1 : 2;
18487 if (CONSP (propval
))
18489 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
18491 Lisp_Object propelt
;
18492 propelt
= XCAR (proptail
);
18493 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18495 register Lisp_Object tem
;
18497 if (EQ (propelt
, tem
))
18499 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
18500 return NILP (XCDR (tem
)) ? 1 : 2;
18508 /* Calculate a width or height in pixels from a specification using
18509 the following elements:
18512 NUM - a (fractional) multiple of the default font width/height
18513 (NUM) - specifies exactly NUM pixels
18514 UNIT - a fixed number of pixels, see below.
18515 ELEMENT - size of a display element in pixels, see below.
18516 (NUM . SPEC) - equals NUM * SPEC
18517 (+ SPEC SPEC ...) - add pixel values
18518 (- SPEC SPEC ...) - subtract pixel values
18519 (- SPEC) - negate pixel value
18522 INT or FLOAT - a number constant
18523 SYMBOL - use symbol's (buffer local) variable binding.
18526 in - pixels per inch *)
18527 mm - pixels per 1/1000 meter *)
18528 cm - pixels per 1/100 meter *)
18529 width - width of current font in pixels.
18530 height - height of current font in pixels.
18532 *) using the ratio(s) defined in display-pixels-per-inch.
18536 left-fringe - left fringe width in pixels
18537 right-fringe - right fringe width in pixels
18539 left-margin - left margin width in pixels
18540 right-margin - right margin width in pixels
18542 scroll-bar - scroll-bar area width in pixels
18546 Pixels corresponding to 5 inches:
18549 Total width of non-text areas on left side of window (if scroll-bar is on left):
18550 '(space :width (+ left-fringe left-margin scroll-bar))
18552 Align to first text column (in header line):
18553 '(space :align-to 0)
18555 Align to middle of text area minus half the width of variable `my-image'
18556 containing a loaded image:
18557 '(space :align-to (0.5 . (- text my-image)))
18559 Width of left margin minus width of 1 character in the default font:
18560 '(space :width (- left-margin 1))
18562 Width of left margin minus width of 2 characters in the current font:
18563 '(space :width (- left-margin (2 . width)))
18565 Center 1 character over left-margin (in header line):
18566 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
18568 Different ways to express width of left fringe plus left margin minus one pixel:
18569 '(space :width (- (+ left-fringe left-margin) (1)))
18570 '(space :width (+ left-fringe left-margin (- (1))))
18571 '(space :width (+ left-fringe left-margin (-1)))
18575 #define NUMVAL(X) \
18576 ((INTEGERP (X) || FLOATP (X)) \
18581 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
18586 int width_p
, *align_to
;
18590 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
18591 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
18594 return OK_PIXELS (0);
18596 if (SYMBOLP (prop
))
18598 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18600 char *unit
= SDATA (SYMBOL_NAME (prop
));
18602 if (unit
[0] == 'i' && unit
[1] == 'n')
18604 else if (unit
[0] == 'm' && unit
[1] == 'm')
18606 else if (unit
[0] == 'c' && unit
[1] == 'm')
18613 #ifdef HAVE_WINDOW_SYSTEM
18614 if (FRAME_WINDOW_P (it
->f
)
18616 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
18617 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
18619 return OK_PIXELS (ppi
/ pixels
);
18622 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18623 || (CONSP (Vdisplay_pixels_per_inch
)
18625 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18626 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18628 return OK_PIXELS (ppi
/ pixels
);
18634 #ifdef HAVE_WINDOW_SYSTEM
18635 if (EQ (prop
, Qheight
))
18636 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
18637 if (EQ (prop
, Qwidth
))
18638 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
18640 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
18641 return OK_PIXELS (1);
18644 if (EQ (prop
, Qtext
))
18645 return OK_PIXELS (width_p
18646 ? window_box_width (it
->w
, TEXT_AREA
)
18647 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
18649 if (align_to
&& *align_to
< 0)
18652 if (EQ (prop
, Qleft
))
18653 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
18654 if (EQ (prop
, Qright
))
18655 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
18656 if (EQ (prop
, Qcenter
))
18657 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
18658 + window_box_width (it
->w
, TEXT_AREA
) / 2);
18659 if (EQ (prop
, Qleft_fringe
))
18660 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18661 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
18662 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
18663 if (EQ (prop
, Qright_fringe
))
18664 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18665 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18666 : window_box_right_offset (it
->w
, TEXT_AREA
));
18667 if (EQ (prop
, Qleft_margin
))
18668 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
18669 if (EQ (prop
, Qright_margin
))
18670 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
18671 if (EQ (prop
, Qscroll_bar
))
18672 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18674 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18675 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18676 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18681 if (EQ (prop
, Qleft_fringe
))
18682 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18683 if (EQ (prop
, Qright_fringe
))
18684 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18685 if (EQ (prop
, Qleft_margin
))
18686 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18687 if (EQ (prop
, Qright_margin
))
18688 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18689 if (EQ (prop
, Qscroll_bar
))
18690 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18693 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18696 if (INTEGERP (prop
) || FLOATP (prop
))
18698 int base_unit
= (width_p
18699 ? FRAME_COLUMN_WIDTH (it
->f
)
18700 : FRAME_LINE_HEIGHT (it
->f
));
18701 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18706 Lisp_Object car
= XCAR (prop
);
18707 Lisp_Object cdr
= XCDR (prop
);
18711 #ifdef HAVE_WINDOW_SYSTEM
18712 if (valid_image_p (prop
))
18714 int id
= lookup_image (it
->f
, prop
);
18715 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
18717 return OK_PIXELS (width_p
? img
->width
: img
->height
);
18720 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18726 while (CONSP (cdr
))
18728 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
18729 font
, width_p
, align_to
))
18732 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18737 if (EQ (car
, Qminus
))
18739 return OK_PIXELS (pixels
);
18742 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18745 if (INTEGERP (car
) || FLOATP (car
))
18748 pixels
= XFLOATINT (car
);
18750 return OK_PIXELS (pixels
);
18751 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
18752 font
, width_p
, align_to
))
18753 return OK_PIXELS (pixels
* fact
);
18764 /***********************************************************************
18766 ***********************************************************************/
18768 #ifdef HAVE_WINDOW_SYSTEM
18773 dump_glyph_string (s
)
18774 struct glyph_string
*s
;
18776 fprintf (stderr
, "glyph string\n");
18777 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
18778 s
->x
, s
->y
, s
->width
, s
->height
);
18779 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
18780 fprintf (stderr
, " hl = %d\n", s
->hl
);
18781 fprintf (stderr
, " left overhang = %d, right = %d\n",
18782 s
->left_overhang
, s
->right_overhang
);
18783 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
18784 fprintf (stderr
, " extends to end of line = %d\n",
18785 s
->extends_to_end_of_line_p
);
18786 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
18787 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
18790 #endif /* GLYPH_DEBUG */
18792 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
18793 of XChar2b structures for S; it can't be allocated in
18794 init_glyph_string because it must be allocated via `alloca'. W
18795 is the window on which S is drawn. ROW and AREA are the glyph row
18796 and area within the row from which S is constructed. START is the
18797 index of the first glyph structure covered by S. HL is a
18798 face-override for drawing S. */
18801 #define OPTIONAL_HDC(hdc) hdc,
18802 #define DECLARE_HDC(hdc) HDC hdc;
18803 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
18804 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
18807 #ifndef OPTIONAL_HDC
18808 #define OPTIONAL_HDC(hdc)
18809 #define DECLARE_HDC(hdc)
18810 #define ALLOCATE_HDC(hdc, f)
18811 #define RELEASE_HDC(hdc, f)
18815 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
18816 struct glyph_string
*s
;
18820 struct glyph_row
*row
;
18821 enum glyph_row_area area
;
18823 enum draw_glyphs_face hl
;
18825 bzero (s
, sizeof *s
);
18827 s
->f
= XFRAME (w
->frame
);
18831 s
->display
= FRAME_X_DISPLAY (s
->f
);
18832 s
->window
= FRAME_X_WINDOW (s
->f
);
18833 s
->char2b
= char2b
;
18837 s
->first_glyph
= row
->glyphs
[area
] + start
;
18838 s
->height
= row
->height
;
18839 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
18841 /* Display the internal border below the tool-bar window. */
18842 if (WINDOWP (s
->f
->tool_bar_window
)
18843 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
18844 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
18846 s
->ybase
= s
->y
+ row
->ascent
;
18850 /* Append the list of glyph strings with head H and tail T to the list
18851 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
18854 append_glyph_string_lists (head
, tail
, h
, t
)
18855 struct glyph_string
**head
, **tail
;
18856 struct glyph_string
*h
, *t
;
18870 /* Prepend the list of glyph strings with head H and tail T to the
18871 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
18875 prepend_glyph_string_lists (head
, tail
, h
, t
)
18876 struct glyph_string
**head
, **tail
;
18877 struct glyph_string
*h
, *t
;
18891 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
18892 Set *HEAD and *TAIL to the resulting list. */
18895 append_glyph_string (head
, tail
, s
)
18896 struct glyph_string
**head
, **tail
;
18897 struct glyph_string
*s
;
18899 s
->next
= s
->prev
= NULL
;
18900 append_glyph_string_lists (head
, tail
, s
, s
);
18904 /* Get face and two-byte form of character glyph GLYPH on frame F.
18905 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
18906 a pointer to a realized face that is ready for display. */
18908 static INLINE
struct face
*
18909 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
18911 struct glyph
*glyph
;
18917 xassert (glyph
->type
== CHAR_GLYPH
);
18918 face
= FACE_FROM_ID (f
, glyph
->face_id
);
18923 if (!glyph
->multibyte_p
)
18925 /* Unibyte case. We don't have to encode, but we have to make
18926 sure to use a face suitable for unibyte. */
18927 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18929 else if (glyph
->u
.ch
< 128)
18931 /* Case of ASCII in a face known to fit ASCII. */
18932 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18936 int c1
, c2
, charset
;
18938 /* Split characters into bytes. If c2 is -1 afterwards, C is
18939 really a one-byte character so that byte1 is zero. */
18940 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
18942 STORE_XCHAR2B (char2b
, c1
, c2
);
18944 STORE_XCHAR2B (char2b
, 0, c1
);
18946 /* Maybe encode the character in *CHAR2B. */
18947 if (charset
!= CHARSET_ASCII
)
18949 struct font_info
*font_info
18950 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18953 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
18957 /* Make sure X resources of the face are allocated. */
18958 xassert (face
!= NULL
);
18959 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18964 /* Fill glyph string S with composition components specified by S->cmp.
18966 FACES is an array of faces for all components of this composition.
18967 S->gidx is the index of the first component for S.
18969 OVERLAPS non-zero means S should draw the foreground only, and use
18970 its physical height for clipping. See also draw_glyphs.
18972 Value is the index of a component not in S. */
18975 fill_composite_glyph_string (s
, faces
, overlaps
)
18976 struct glyph_string
*s
;
18977 struct face
**faces
;
18984 s
->for_overlaps
= overlaps
;
18986 s
->face
= faces
[s
->gidx
];
18987 s
->font
= s
->face
->font
;
18988 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18990 /* For all glyphs of this composition, starting at the offset
18991 S->gidx, until we reach the end of the definition or encounter a
18992 glyph that requires the different face, add it to S. */
18994 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
18997 /* All glyph strings for the same composition has the same width,
18998 i.e. the width set for the first component of the composition. */
19000 s
->width
= s
->first_glyph
->pixel_width
;
19002 /* If the specified font could not be loaded, use the frame's
19003 default font, but record the fact that we couldn't load it in
19004 the glyph string so that we can draw rectangles for the
19005 characters of the glyph string. */
19006 if (s
->font
== NULL
)
19008 s
->font_not_found_p
= 1;
19009 s
->font
= FRAME_FONT (s
->f
);
19012 /* Adjust base line for subscript/superscript text. */
19013 s
->ybase
+= s
->first_glyph
->voffset
;
19015 xassert (s
->face
&& s
->face
->gc
);
19017 /* This glyph string must always be drawn with 16-bit functions. */
19020 return s
->gidx
+ s
->nchars
;
19024 /* Fill glyph string S from a sequence of character glyphs.
19026 FACE_ID is the face id of the string. START is the index of the
19027 first glyph to consider, END is the index of the last + 1.
19028 OVERLAPS non-zero means S should draw the foreground only, and use
19029 its physical height for clipping. See also draw_glyphs.
19031 Value is the index of the first glyph not in S. */
19034 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
19035 struct glyph_string
*s
;
19037 int start
, end
, overlaps
;
19039 struct glyph
*glyph
, *last
;
19041 int glyph_not_available_p
;
19043 xassert (s
->f
== XFRAME (s
->w
->frame
));
19044 xassert (s
->nchars
== 0);
19045 xassert (start
>= 0 && end
> start
);
19047 s
->for_overlaps
= overlaps
,
19048 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19049 last
= s
->row
->glyphs
[s
->area
] + end
;
19050 voffset
= glyph
->voffset
;
19052 glyph_not_available_p
= glyph
->glyph_not_available_p
;
19054 while (glyph
< last
19055 && glyph
->type
== CHAR_GLYPH
19056 && glyph
->voffset
== voffset
19057 /* Same face id implies same font, nowadays. */
19058 && glyph
->face_id
== face_id
19059 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
19063 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
19064 s
->char2b
+ s
->nchars
,
19066 s
->two_byte_p
= two_byte_p
;
19068 xassert (s
->nchars
<= end
- start
);
19069 s
->width
+= glyph
->pixel_width
;
19073 s
->font
= s
->face
->font
;
19074 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
19076 /* If the specified font could not be loaded, use the frame's font,
19077 but record the fact that we couldn't load it in
19078 S->font_not_found_p so that we can draw rectangles for the
19079 characters of the glyph string. */
19080 if (s
->font
== NULL
|| glyph_not_available_p
)
19082 s
->font_not_found_p
= 1;
19083 s
->font
= FRAME_FONT (s
->f
);
19086 /* Adjust base line for subscript/superscript text. */
19087 s
->ybase
+= voffset
;
19089 xassert (s
->face
&& s
->face
->gc
);
19090 return glyph
- s
->row
->glyphs
[s
->area
];
19094 /* Fill glyph string S from image glyph S->first_glyph. */
19097 fill_image_glyph_string (s
)
19098 struct glyph_string
*s
;
19100 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
19101 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
19103 s
->slice
= s
->first_glyph
->slice
;
19104 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
19105 s
->font
= s
->face
->font
;
19106 s
->width
= s
->first_glyph
->pixel_width
;
19108 /* Adjust base line for subscript/superscript text. */
19109 s
->ybase
+= s
->first_glyph
->voffset
;
19113 /* Fill glyph string S from a sequence of stretch glyphs.
19115 ROW is the glyph row in which the glyphs are found, AREA is the
19116 area within the row. START is the index of the first glyph to
19117 consider, END is the index of the last + 1.
19119 Value is the index of the first glyph not in S. */
19122 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
19123 struct glyph_string
*s
;
19124 struct glyph_row
*row
;
19125 enum glyph_row_area area
;
19128 struct glyph
*glyph
, *last
;
19129 int voffset
, face_id
;
19131 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
19133 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19134 last
= s
->row
->glyphs
[s
->area
] + end
;
19135 face_id
= glyph
->face_id
;
19136 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19137 s
->font
= s
->face
->font
;
19138 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
19139 s
->width
= glyph
->pixel_width
;
19141 voffset
= glyph
->voffset
;
19145 && glyph
->type
== STRETCH_GLYPH
19146 && glyph
->voffset
== voffset
19147 && glyph
->face_id
== face_id
);
19149 s
->width
+= glyph
->pixel_width
;
19151 /* Adjust base line for subscript/superscript text. */
19152 s
->ybase
+= voffset
;
19154 /* The case that face->gc == 0 is handled when drawing the glyph
19155 string by calling PREPARE_FACE_FOR_DISPLAY. */
19157 return glyph
- s
->row
->glyphs
[s
->area
];
19162 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
19163 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
19164 assumed to be zero. */
19167 x_get_glyph_overhangs (glyph
, f
, left
, right
)
19168 struct glyph
*glyph
;
19172 *left
= *right
= 0;
19174 if (glyph
->type
== CHAR_GLYPH
)
19178 struct font_info
*font_info
;
19182 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
19184 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
19185 if (font
/* ++KFS: Should this be font_info ? */
19186 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
19188 if (pcm
->rbearing
> pcm
->width
)
19189 *right
= pcm
->rbearing
- pcm
->width
;
19190 if (pcm
->lbearing
< 0)
19191 *left
= -pcm
->lbearing
;
19197 /* Return the index of the first glyph preceding glyph string S that
19198 is overwritten by S because of S's left overhang. Value is -1
19199 if no glyphs are overwritten. */
19202 left_overwritten (s
)
19203 struct glyph_string
*s
;
19207 if (s
->left_overhang
)
19210 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19211 int first
= s
->first_glyph
- glyphs
;
19213 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
19214 x
-= glyphs
[i
].pixel_width
;
19225 /* Return the index of the first glyph preceding glyph string S that
19226 is overwriting S because of its right overhang. Value is -1 if no
19227 glyph in front of S overwrites S. */
19230 left_overwriting (s
)
19231 struct glyph_string
*s
;
19234 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19235 int first
= s
->first_glyph
- glyphs
;
19239 for (i
= first
- 1; i
>= 0; --i
)
19242 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19245 x
-= glyphs
[i
].pixel_width
;
19252 /* Return the index of the last glyph following glyph string S that is
19253 not overwritten by S because of S's right overhang. Value is -1 if
19254 no such glyph is found. */
19257 right_overwritten (s
)
19258 struct glyph_string
*s
;
19262 if (s
->right_overhang
)
19265 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19266 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19267 int end
= s
->row
->used
[s
->area
];
19269 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
19270 x
+= glyphs
[i
].pixel_width
;
19279 /* Return the index of the last glyph following glyph string S that
19280 overwrites S because of its left overhang. Value is negative
19281 if no such glyph is found. */
19284 right_overwriting (s
)
19285 struct glyph_string
*s
;
19288 int end
= s
->row
->used
[s
->area
];
19289 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19290 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19294 for (i
= first
; i
< end
; ++i
)
19297 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19300 x
+= glyphs
[i
].pixel_width
;
19307 /* Get face and two-byte form of character C in face FACE_ID on frame
19308 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19309 means we want to display multibyte text. DISPLAY_P non-zero means
19310 make sure that X resources for the face returned are allocated.
19311 Value is a pointer to a realized face that is ready for display if
19312 DISPLAY_P is non-zero. */
19314 static INLINE
struct face
*
19315 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
19319 int multibyte_p
, display_p
;
19321 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19325 /* Unibyte case. We don't have to encode, but we have to make
19326 sure to use a face suitable for unibyte. */
19327 STORE_XCHAR2B (char2b
, 0, c
);
19328 face_id
= FACE_FOR_CHAR (f
, face
, c
);
19329 face
= FACE_FROM_ID (f
, face_id
);
19333 /* Case of ASCII in a face known to fit ASCII. */
19334 STORE_XCHAR2B (char2b
, 0, c
);
19338 int c1
, c2
, charset
;
19340 /* Split characters into bytes. If c2 is -1 afterwards, C is
19341 really a one-byte character so that byte1 is zero. */
19342 SPLIT_CHAR (c
, charset
, c1
, c2
);
19344 STORE_XCHAR2B (char2b
, c1
, c2
);
19346 STORE_XCHAR2B (char2b
, 0, c1
);
19348 /* Maybe encode the character in *CHAR2B. */
19349 if (face
->font
!= NULL
)
19351 struct font_info
*font_info
19352 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
19354 rif
->encode_char (c
, char2b
, font_info
, 0);
19358 /* Make sure X resources of the face are allocated. */
19359 #ifdef HAVE_X_WINDOWS
19363 xassert (face
!= NULL
);
19364 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19371 /* Set background width of glyph string S. START is the index of the
19372 first glyph following S. LAST_X is the right-most x-position + 1
19373 in the drawing area. */
19376 set_glyph_string_background_width (s
, start
, last_x
)
19377 struct glyph_string
*s
;
19381 /* If the face of this glyph string has to be drawn to the end of
19382 the drawing area, set S->extends_to_end_of_line_p. */
19384 if (start
== s
->row
->used
[s
->area
]
19385 && s
->area
== TEXT_AREA
19386 && ((s
->row
->fill_line_p
19387 && (s
->hl
== DRAW_NORMAL_TEXT
19388 || s
->hl
== DRAW_IMAGE_RAISED
19389 || s
->hl
== DRAW_IMAGE_SUNKEN
))
19390 || s
->hl
== DRAW_MOUSE_FACE
))
19391 s
->extends_to_end_of_line_p
= 1;
19393 /* If S extends its face to the end of the line, set its
19394 background_width to the distance to the right edge of the drawing
19396 if (s
->extends_to_end_of_line_p
)
19397 s
->background_width
= last_x
- s
->x
+ 1;
19399 s
->background_width
= s
->width
;
19403 /* Compute overhangs and x-positions for glyph string S and its
19404 predecessors, or successors. X is the starting x-position for S.
19405 BACKWARD_P non-zero means process predecessors. */
19408 compute_overhangs_and_x (s
, x
, backward_p
)
19409 struct glyph_string
*s
;
19417 if (rif
->compute_glyph_string_overhangs
)
19418 rif
->compute_glyph_string_overhangs (s
);
19428 if (rif
->compute_glyph_string_overhangs
)
19429 rif
->compute_glyph_string_overhangs (s
);
19439 /* The following macros are only called from draw_glyphs below.
19440 They reference the following parameters of that function directly:
19441 `w', `row', `area', and `overlap_p'
19442 as well as the following local variables:
19443 `s', `f', and `hdc' (in W32) */
19446 /* On W32, silently add local `hdc' variable to argument list of
19447 init_glyph_string. */
19448 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19449 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
19451 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19452 init_glyph_string (s, char2b, w, row, area, start, hl)
19455 /* Add a glyph string for a stretch glyph to the list of strings
19456 between HEAD and TAIL. START is the index of the stretch glyph in
19457 row area AREA of glyph row ROW. END is the index of the last glyph
19458 in that glyph row area. X is the current output position assigned
19459 to the new glyph string constructed. HL overrides that face of the
19460 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19461 is the right-most x-position of the drawing area. */
19463 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
19464 and below -- keep them on one line. */
19465 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19468 s = (struct glyph_string *) alloca (sizeof *s); \
19469 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19470 START = fill_stretch_glyph_string (s, row, area, START, END); \
19471 append_glyph_string (&HEAD, &TAIL, s); \
19477 /* Add a glyph string for an image glyph to the list of strings
19478 between HEAD and TAIL. START is the index of the image glyph in
19479 row area AREA of glyph row ROW. END is the index of the last glyph
19480 in that glyph row area. X is the current output position assigned
19481 to the new glyph string constructed. HL overrides that face of the
19482 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19483 is the right-most x-position of the drawing area. */
19485 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19488 s = (struct glyph_string *) alloca (sizeof *s); \
19489 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19490 fill_image_glyph_string (s); \
19491 append_glyph_string (&HEAD, &TAIL, s); \
19498 /* Add a glyph string for a sequence of character glyphs to the list
19499 of strings between HEAD and TAIL. START is the index of the first
19500 glyph in row area AREA of glyph row ROW that is part of the new
19501 glyph string. END is the index of the last glyph in that glyph row
19502 area. X is the current output position assigned to the new glyph
19503 string constructed. HL overrides that face of the glyph; e.g. it
19504 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
19505 right-most x-position of the drawing area. */
19507 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19513 c = (row)->glyphs[area][START].u.ch; \
19514 face_id = (row)->glyphs[area][START].face_id; \
19516 s = (struct glyph_string *) alloca (sizeof *s); \
19517 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
19518 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
19519 append_glyph_string (&HEAD, &TAIL, s); \
19521 START = fill_glyph_string (s, face_id, START, END, overlaps); \
19526 /* Add a glyph string for a composite sequence to the list of strings
19527 between HEAD and TAIL. START is the index of the first glyph in
19528 row area AREA of glyph row ROW that is part of the new glyph
19529 string. END is the index of the last glyph in that glyph row area.
19530 X is the current output position assigned to the new glyph string
19531 constructed. HL overrides that face of the glyph; e.g. it is
19532 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
19533 x-position of the drawing area. */
19535 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19537 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
19538 int face_id = (row)->glyphs[area][START].face_id; \
19539 struct face *base_face = FACE_FROM_ID (f, face_id); \
19540 struct composition *cmp = composition_table[cmp_id]; \
19541 int glyph_len = cmp->glyph_len; \
19543 struct face **faces; \
19544 struct glyph_string *first_s = NULL; \
19547 base_face = base_face->ascii_face; \
19548 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
19549 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
19550 /* At first, fill in `char2b' and `faces'. */ \
19551 for (n = 0; n < glyph_len; n++) \
19553 int c = COMPOSITION_GLYPH (cmp, n); \
19554 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
19555 faces[n] = FACE_FROM_ID (f, this_face_id); \
19556 get_char_face_and_encoding (f, c, this_face_id, \
19557 char2b + n, 1, 1); \
19560 /* Make glyph_strings for each glyph sequence that is drawable by \
19561 the same face, and append them to HEAD/TAIL. */ \
19562 for (n = 0; n < cmp->glyph_len;) \
19564 s = (struct glyph_string *) alloca (sizeof *s); \
19565 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
19566 append_glyph_string (&(HEAD), &(TAIL), s); \
19574 n = fill_composite_glyph_string (s, faces, overlaps); \
19582 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
19583 of AREA of glyph row ROW on window W between indices START and END.
19584 HL overrides the face for drawing glyph strings, e.g. it is
19585 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
19586 x-positions of the drawing area.
19588 This is an ugly monster macro construct because we must use alloca
19589 to allocate glyph strings (because draw_glyphs can be called
19590 asynchronously). */
19592 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19595 HEAD = TAIL = NULL; \
19596 while (START < END) \
19598 struct glyph *first_glyph = (row)->glyphs[area] + START; \
19599 switch (first_glyph->type) \
19602 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
19606 case COMPOSITE_GLYPH: \
19607 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
19611 case STRETCH_GLYPH: \
19612 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
19616 case IMAGE_GLYPH: \
19617 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
19625 set_glyph_string_background_width (s, START, LAST_X); \
19632 /* Draw glyphs between START and END in AREA of ROW on window W,
19633 starting at x-position X. X is relative to AREA in W. HL is a
19634 face-override with the following meaning:
19636 DRAW_NORMAL_TEXT draw normally
19637 DRAW_CURSOR draw in cursor face
19638 DRAW_MOUSE_FACE draw in mouse face.
19639 DRAW_INVERSE_VIDEO draw in mode line face
19640 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
19641 DRAW_IMAGE_RAISED draw an image with a raised relief around it
19643 If OVERLAPS is non-zero, draw only the foreground of characters and
19644 clip to the physical height of ROW. Non-zero value also defines
19645 the overlapping part to be drawn:
19647 OVERLAPS_PRED overlap with preceding rows
19648 OVERLAPS_SUCC overlap with succeeding rows
19649 OVERLAPS_BOTH overlap with both preceding/succeeding rows
19650 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
19652 Value is the x-position reached, relative to AREA of W. */
19655 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
19658 struct glyph_row
*row
;
19659 enum glyph_row_area area
;
19661 enum draw_glyphs_face hl
;
19664 struct glyph_string
*head
, *tail
;
19665 struct glyph_string
*s
;
19666 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
19667 int last_x
, area_width
;
19670 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19673 ALLOCATE_HDC (hdc
, f
);
19675 /* Let's rather be paranoid than getting a SEGV. */
19676 end
= min (end
, row
->used
[area
]);
19677 start
= max (0, start
);
19678 start
= min (end
, start
);
19680 /* Translate X to frame coordinates. Set last_x to the right
19681 end of the drawing area. */
19682 if (row
->full_width_p
)
19684 /* X is relative to the left edge of W, without scroll bars
19686 x
+= WINDOW_LEFT_EDGE_X (w
);
19687 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
19691 int area_left
= window_box_left (w
, area
);
19693 area_width
= window_box_width (w
, area
);
19694 last_x
= area_left
+ area_width
;
19697 /* Build a doubly-linked list of glyph_string structures between
19698 head and tail from what we have to draw. Note that the macro
19699 BUILD_GLYPH_STRINGS will modify its start parameter. That's
19700 the reason we use a separate variable `i'. */
19702 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
19704 x_reached
= tail
->x
+ tail
->background_width
;
19708 /* If there are any glyphs with lbearing < 0 or rbearing > width in
19709 the row, redraw some glyphs in front or following the glyph
19710 strings built above. */
19711 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
19714 struct glyph_string
*h
, *t
;
19716 /* Compute overhangs for all glyph strings. */
19717 if (rif
->compute_glyph_string_overhangs
)
19718 for (s
= head
; s
; s
= s
->next
)
19719 rif
->compute_glyph_string_overhangs (s
);
19721 /* Prepend glyph strings for glyphs in front of the first glyph
19722 string that are overwritten because of the first glyph
19723 string's left overhang. The background of all strings
19724 prepended must be drawn because the first glyph string
19726 i
= left_overwritten (head
);
19730 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
19731 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19733 compute_overhangs_and_x (t
, head
->x
, 1);
19734 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19738 /* Prepend glyph strings for glyphs in front of the first glyph
19739 string that overwrite that glyph string because of their
19740 right overhang. For these strings, only the foreground must
19741 be drawn, because it draws over the glyph string at `head'.
19742 The background must not be drawn because this would overwrite
19743 right overhangs of preceding glyphs for which no glyph
19745 i
= left_overwriting (head
);
19749 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
19750 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19751 for (s
= h
; s
; s
= s
->next
)
19752 s
->background_filled_p
= 1;
19753 compute_overhangs_and_x (t
, head
->x
, 1);
19754 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19757 /* Append glyphs strings for glyphs following the last glyph
19758 string tail that are overwritten by tail. The background of
19759 these strings has to be drawn because tail's foreground draws
19761 i
= right_overwritten (tail
);
19764 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19765 DRAW_NORMAL_TEXT
, x
, last_x
);
19766 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19767 append_glyph_string_lists (&head
, &tail
, h
, t
);
19771 /* Append glyph strings for glyphs following the last glyph
19772 string tail that overwrite tail. The foreground of such
19773 glyphs has to be drawn because it writes into the background
19774 of tail. The background must not be drawn because it could
19775 paint over the foreground of following glyphs. */
19776 i
= right_overwriting (tail
);
19780 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19781 DRAW_NORMAL_TEXT
, x
, last_x
);
19782 for (s
= h
; s
; s
= s
->next
)
19783 s
->background_filled_p
= 1;
19784 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19785 append_glyph_string_lists (&head
, &tail
, h
, t
);
19787 if (clip_head
|| clip_tail
)
19788 for (s
= head
; s
; s
= s
->next
)
19790 s
->clip_head
= clip_head
;
19791 s
->clip_tail
= clip_tail
;
19795 /* Draw all strings. */
19796 for (s
= head
; s
; s
= s
->next
)
19797 rif
->draw_glyph_string (s
);
19799 if (area
== TEXT_AREA
19800 && !row
->full_width_p
19801 /* When drawing overlapping rows, only the glyph strings'
19802 foreground is drawn, which doesn't erase a cursor
19806 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
19807 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
19808 : (tail
? tail
->x
+ tail
->background_width
: x
));
19810 int text_left
= window_box_left (w
, TEXT_AREA
);
19814 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
19815 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
19818 /* Value is the x-position up to which drawn, relative to AREA of W.
19819 This doesn't include parts drawn because of overhangs. */
19820 if (row
->full_width_p
)
19821 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
19823 x_reached
-= window_box_left (w
, area
);
19825 RELEASE_HDC (hdc
, f
);
19830 /* Expand row matrix if too narrow. Don't expand if area
19833 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
19835 if (!fonts_changed_p \
19836 && (it->glyph_row->glyphs[area] \
19837 < it->glyph_row->glyphs[area + 1])) \
19839 it->w->ncols_scale_factor++; \
19840 fonts_changed_p = 1; \
19844 /* Store one glyph for IT->char_to_display in IT->glyph_row.
19845 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19851 struct glyph
*glyph
;
19852 enum glyph_row_area area
= it
->area
;
19854 xassert (it
->glyph_row
);
19855 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
19857 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19858 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19860 glyph
->charpos
= CHARPOS (it
->position
);
19861 glyph
->object
= it
->object
;
19862 glyph
->pixel_width
= it
->pixel_width
;
19863 glyph
->ascent
= it
->ascent
;
19864 glyph
->descent
= it
->descent
;
19865 glyph
->voffset
= it
->voffset
;
19866 glyph
->type
= CHAR_GLYPH
;
19867 glyph
->multibyte_p
= it
->multibyte_p
;
19868 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19869 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19870 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19871 || it
->phys_descent
> it
->descent
);
19872 glyph
->padding_p
= 0;
19873 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
19874 glyph
->face_id
= it
->face_id
;
19875 glyph
->u
.ch
= it
->char_to_display
;
19876 glyph
->slice
= null_glyph_slice
;
19877 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19878 ++it
->glyph_row
->used
[area
];
19881 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19884 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
19885 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19888 append_composite_glyph (it
)
19891 struct glyph
*glyph
;
19892 enum glyph_row_area area
= it
->area
;
19894 xassert (it
->glyph_row
);
19896 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19897 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19899 glyph
->charpos
= CHARPOS (it
->position
);
19900 glyph
->object
= it
->object
;
19901 glyph
->pixel_width
= it
->pixel_width
;
19902 glyph
->ascent
= it
->ascent
;
19903 glyph
->descent
= it
->descent
;
19904 glyph
->voffset
= it
->voffset
;
19905 glyph
->type
= COMPOSITE_GLYPH
;
19906 glyph
->multibyte_p
= it
->multibyte_p
;
19907 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19908 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19909 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19910 || it
->phys_descent
> it
->descent
);
19911 glyph
->padding_p
= 0;
19912 glyph
->glyph_not_available_p
= 0;
19913 glyph
->face_id
= it
->face_id
;
19914 glyph
->u
.cmp_id
= it
->cmp_id
;
19915 glyph
->slice
= null_glyph_slice
;
19916 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19917 ++it
->glyph_row
->used
[area
];
19920 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19924 /* Change IT->ascent and IT->height according to the setting of
19928 take_vertical_position_into_account (it
)
19933 if (it
->voffset
< 0)
19934 /* Increase the ascent so that we can display the text higher
19936 it
->ascent
-= it
->voffset
;
19938 /* Increase the descent so that we can display the text lower
19940 it
->descent
+= it
->voffset
;
19945 /* Produce glyphs/get display metrics for the image IT is loaded with.
19946 See the description of struct display_iterator in dispextern.h for
19947 an overview of struct display_iterator. */
19950 produce_image_glyph (it
)
19955 int glyph_ascent
, crop
;
19956 struct glyph_slice slice
;
19958 xassert (it
->what
== IT_IMAGE
);
19960 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19962 /* Make sure X resources of the face is loaded. */
19963 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19965 if (it
->image_id
< 0)
19967 /* Fringe bitmap. */
19968 it
->ascent
= it
->phys_ascent
= 0;
19969 it
->descent
= it
->phys_descent
= 0;
19970 it
->pixel_width
= 0;
19975 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
19977 /* Make sure X resources of the image is loaded. */
19978 prepare_image_for_display (it
->f
, img
);
19980 slice
.x
= slice
.y
= 0;
19981 slice
.width
= img
->width
;
19982 slice
.height
= img
->height
;
19984 if (INTEGERP (it
->slice
.x
))
19985 slice
.x
= XINT (it
->slice
.x
);
19986 else if (FLOATP (it
->slice
.x
))
19987 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
19989 if (INTEGERP (it
->slice
.y
))
19990 slice
.y
= XINT (it
->slice
.y
);
19991 else if (FLOATP (it
->slice
.y
))
19992 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
19994 if (INTEGERP (it
->slice
.width
))
19995 slice
.width
= XINT (it
->slice
.width
);
19996 else if (FLOATP (it
->slice
.width
))
19997 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
19999 if (INTEGERP (it
->slice
.height
))
20000 slice
.height
= XINT (it
->slice
.height
);
20001 else if (FLOATP (it
->slice
.height
))
20002 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
20004 if (slice
.x
>= img
->width
)
20005 slice
.x
= img
->width
;
20006 if (slice
.y
>= img
->height
)
20007 slice
.y
= img
->height
;
20008 if (slice
.x
+ slice
.width
>= img
->width
)
20009 slice
.width
= img
->width
- slice
.x
;
20010 if (slice
.y
+ slice
.height
> img
->height
)
20011 slice
.height
= img
->height
- slice
.y
;
20013 if (slice
.width
== 0 || slice
.height
== 0)
20016 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
20018 it
->descent
= slice
.height
- glyph_ascent
;
20020 it
->descent
+= img
->vmargin
;
20021 if (slice
.y
+ slice
.height
== img
->height
)
20022 it
->descent
+= img
->vmargin
;
20023 it
->phys_descent
= it
->descent
;
20025 it
->pixel_width
= slice
.width
;
20027 it
->pixel_width
+= img
->hmargin
;
20028 if (slice
.x
+ slice
.width
== img
->width
)
20029 it
->pixel_width
+= img
->hmargin
;
20031 /* It's quite possible for images to have an ascent greater than
20032 their height, so don't get confused in that case. */
20033 if (it
->descent
< 0)
20036 #if 0 /* this breaks image tiling */
20037 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
20038 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
20039 if (face_ascent
> it
->ascent
)
20040 it
->ascent
= it
->phys_ascent
= face_ascent
;
20045 if (face
->box
!= FACE_NO_BOX
)
20047 if (face
->box_line_width
> 0)
20050 it
->ascent
+= face
->box_line_width
;
20051 if (slice
.y
+ slice
.height
== img
->height
)
20052 it
->descent
+= face
->box_line_width
;
20055 if (it
->start_of_box_run_p
&& slice
.x
== 0)
20056 it
->pixel_width
+= abs (face
->box_line_width
);
20057 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
20058 it
->pixel_width
+= abs (face
->box_line_width
);
20061 take_vertical_position_into_account (it
);
20063 /* Automatically crop wide image glyphs at right edge so we can
20064 draw the cursor on same display row. */
20065 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
20066 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
20068 it
->pixel_width
-= crop
;
20069 slice
.width
-= crop
;
20074 struct glyph
*glyph
;
20075 enum glyph_row_area area
= it
->area
;
20077 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20078 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20080 glyph
->charpos
= CHARPOS (it
->position
);
20081 glyph
->object
= it
->object
;
20082 glyph
->pixel_width
= it
->pixel_width
;
20083 glyph
->ascent
= glyph_ascent
;
20084 glyph
->descent
= it
->descent
;
20085 glyph
->voffset
= it
->voffset
;
20086 glyph
->type
= IMAGE_GLYPH
;
20087 glyph
->multibyte_p
= it
->multibyte_p
;
20088 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20089 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20090 glyph
->overlaps_vertically_p
= 0;
20091 glyph
->padding_p
= 0;
20092 glyph
->glyph_not_available_p
= 0;
20093 glyph
->face_id
= it
->face_id
;
20094 glyph
->u
.img_id
= img
->id
;
20095 glyph
->slice
= slice
;
20096 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20097 ++it
->glyph_row
->used
[area
];
20100 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20105 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
20106 of the glyph, WIDTH and HEIGHT are the width and height of the
20107 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
20110 append_stretch_glyph (it
, object
, width
, height
, ascent
)
20112 Lisp_Object object
;
20116 struct glyph
*glyph
;
20117 enum glyph_row_area area
= it
->area
;
20119 xassert (ascent
>= 0 && ascent
<= height
);
20121 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20122 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20124 glyph
->charpos
= CHARPOS (it
->position
);
20125 glyph
->object
= object
;
20126 glyph
->pixel_width
= width
;
20127 glyph
->ascent
= ascent
;
20128 glyph
->descent
= height
- ascent
;
20129 glyph
->voffset
= it
->voffset
;
20130 glyph
->type
= STRETCH_GLYPH
;
20131 glyph
->multibyte_p
= it
->multibyte_p
;
20132 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20133 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20134 glyph
->overlaps_vertically_p
= 0;
20135 glyph
->padding_p
= 0;
20136 glyph
->glyph_not_available_p
= 0;
20137 glyph
->face_id
= it
->face_id
;
20138 glyph
->u
.stretch
.ascent
= ascent
;
20139 glyph
->u
.stretch
.height
= height
;
20140 glyph
->slice
= null_glyph_slice
;
20141 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20142 ++it
->glyph_row
->used
[area
];
20145 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20149 /* Produce a stretch glyph for iterator IT. IT->object is the value
20150 of the glyph property displayed. The value must be a list
20151 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
20154 1. `:width WIDTH' specifies that the space should be WIDTH *
20155 canonical char width wide. WIDTH may be an integer or floating
20158 2. `:relative-width FACTOR' specifies that the width of the stretch
20159 should be computed from the width of the first character having the
20160 `glyph' property, and should be FACTOR times that width.
20162 3. `:align-to HPOS' specifies that the space should be wide enough
20163 to reach HPOS, a value in canonical character units.
20165 Exactly one of the above pairs must be present.
20167 4. `:height HEIGHT' specifies that the height of the stretch produced
20168 should be HEIGHT, measured in canonical character units.
20170 5. `:relative-height FACTOR' specifies that the height of the
20171 stretch should be FACTOR times the height of the characters having
20172 the glyph property.
20174 Either none or exactly one of 4 or 5 must be present.
20176 6. `:ascent ASCENT' specifies that ASCENT percent of the height
20177 of the stretch should be used for the ascent of the stretch.
20178 ASCENT must be in the range 0 <= ASCENT <= 100. */
20181 produce_stretch_glyph (it
)
20184 /* (space :width WIDTH :height HEIGHT ...) */
20185 Lisp_Object prop
, plist
;
20186 int width
= 0, height
= 0, align_to
= -1;
20187 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
20190 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20191 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
20193 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20195 /* List should start with `space'. */
20196 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
20197 plist
= XCDR (it
->object
);
20199 /* Compute the width of the stretch. */
20200 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
20201 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
20203 /* Absolute width `:width WIDTH' specified and valid. */
20204 zero_width_ok_p
= 1;
20207 else if (prop
= Fplist_get (plist
, QCrelative_width
),
20210 /* Relative width `:relative-width FACTOR' specified and valid.
20211 Compute the width of the characters having the `glyph'
20214 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
20217 if (it
->multibyte_p
)
20219 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
20220 - IT_BYTEPOS (*it
));
20221 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
20224 it2
.c
= *p
, it2
.len
= 1;
20226 it2
.glyph_row
= NULL
;
20227 it2
.what
= IT_CHARACTER
;
20228 x_produce_glyphs (&it2
);
20229 width
= NUMVAL (prop
) * it2
.pixel_width
;
20231 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
20232 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
20234 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
20235 align_to
= (align_to
< 0
20237 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
20238 else if (align_to
< 0)
20239 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
20240 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
20241 zero_width_ok_p
= 1;
20244 /* Nothing specified -> width defaults to canonical char width. */
20245 width
= FRAME_COLUMN_WIDTH (it
->f
);
20247 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
20250 /* Compute height. */
20251 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
20252 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20255 zero_height_ok_p
= 1;
20257 else if (prop
= Fplist_get (plist
, QCrelative_height
),
20259 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
20261 height
= FONT_HEIGHT (font
);
20263 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
20266 /* Compute percentage of height used for ascent. If
20267 `:ascent ASCENT' is present and valid, use that. Otherwise,
20268 derive the ascent from the font in use. */
20269 if (prop
= Fplist_get (plist
, QCascent
),
20270 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
20271 ascent
= height
* NUMVAL (prop
) / 100.0;
20272 else if (!NILP (prop
)
20273 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20274 ascent
= min (max (0, (int)tem
), height
);
20276 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
20278 if (width
> 0 && !it
->truncate_lines_p
20279 && it
->current_x
+ width
> it
->last_visible_x
)
20280 width
= it
->last_visible_x
- it
->current_x
- 1;
20282 if (width
> 0 && height
> 0 && it
->glyph_row
)
20284 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
20285 if (!STRINGP (object
))
20286 object
= it
->w
->buffer
;
20287 append_stretch_glyph (it
, object
, width
, height
, ascent
);
20290 it
->pixel_width
= width
;
20291 it
->ascent
= it
->phys_ascent
= ascent
;
20292 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
20293 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
20295 take_vertical_position_into_account (it
);
20298 /* Get line-height and line-spacing property at point.
20299 If line-height has format (HEIGHT TOTAL), return TOTAL
20300 in TOTAL_HEIGHT. */
20303 get_line_height_property (it
, prop
)
20307 Lisp_Object position
;
20309 if (STRINGP (it
->object
))
20310 position
= make_number (IT_STRING_CHARPOS (*it
));
20311 else if (BUFFERP (it
->object
))
20312 position
= make_number (IT_CHARPOS (*it
));
20316 return Fget_char_property (position
, prop
, it
->object
);
20319 /* Calculate line-height and line-spacing properties.
20320 An integer value specifies explicit pixel value.
20321 A float value specifies relative value to current face height.
20322 A cons (float . face-name) specifies relative value to
20323 height of specified face font.
20325 Returns height in pixels, or nil. */
20329 calc_line_height_property (it
, val
, font
, boff
, override
)
20333 int boff
, override
;
20335 Lisp_Object face_name
= Qnil
;
20336 int ascent
, descent
, height
;
20338 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
20343 face_name
= XCAR (val
);
20345 if (!NUMBERP (val
))
20346 val
= make_number (1);
20347 if (NILP (face_name
))
20349 height
= it
->ascent
+ it
->descent
;
20354 if (NILP (face_name
))
20356 font
= FRAME_FONT (it
->f
);
20357 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20359 else if (EQ (face_name
, Qt
))
20367 struct font_info
*font_info
;
20369 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
20371 return make_number (-1);
20373 face
= FACE_FROM_ID (it
->f
, face_id
);
20376 return make_number (-1);
20378 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20379 boff
= font_info
->baseline_offset
;
20380 if (font_info
->vertical_centering
)
20381 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20384 ascent
= FONT_BASE (font
) + boff
;
20385 descent
= FONT_DESCENT (font
) - boff
;
20389 it
->override_ascent
= ascent
;
20390 it
->override_descent
= descent
;
20391 it
->override_boff
= boff
;
20394 height
= ascent
+ descent
;
20398 height
= (int)(XFLOAT_DATA (val
) * height
);
20399 else if (INTEGERP (val
))
20400 height
*= XINT (val
);
20402 return make_number (height
);
20407 Produce glyphs/get display metrics for the display element IT is
20408 loaded with. See the description of struct it in dispextern.h
20409 for an overview of struct it. */
20412 x_produce_glyphs (it
)
20415 int extra_line_spacing
= it
->extra_line_spacing
;
20417 it
->glyph_not_available_p
= 0;
20419 if (it
->what
== IT_CHARACTER
)
20423 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20425 int font_not_found_p
;
20426 struct font_info
*font_info
;
20427 int boff
; /* baseline offset */
20428 /* We may change it->multibyte_p upon unibyte<->multibyte
20429 conversion. So, save the current value now and restore it
20432 Note: It seems that we don't have to record multibyte_p in
20433 struct glyph because the character code itself tells if or
20434 not the character is multibyte. Thus, in the future, we must
20435 consider eliminating the field `multibyte_p' in the struct
20437 int saved_multibyte_p
= it
->multibyte_p
;
20439 /* Maybe translate single-byte characters to multibyte, or the
20441 it
->char_to_display
= it
->c
;
20442 if (!ASCII_BYTE_P (it
->c
))
20444 if (unibyte_display_via_language_environment
20445 && SINGLE_BYTE_CHAR_P (it
->c
)
20447 || !NILP (Vnonascii_translation_table
)))
20449 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20450 it
->multibyte_p
= 1;
20451 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20452 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20454 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
20455 && !it
->multibyte_p
)
20457 it
->multibyte_p
= 1;
20458 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20459 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20463 /* Get font to use. Encode IT->char_to_display. */
20464 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20465 &char2b
, it
->multibyte_p
, 0);
20468 /* When no suitable font found, use the default font. */
20469 font_not_found_p
= font
== NULL
;
20470 if (font_not_found_p
)
20472 font
= FRAME_FONT (it
->f
);
20473 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20478 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20479 boff
= font_info
->baseline_offset
;
20480 if (font_info
->vertical_centering
)
20481 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20484 if (it
->char_to_display
>= ' '
20485 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
20487 /* Either unibyte or ASCII. */
20492 pcm
= rif
->per_char_metric (font
, &char2b
,
20493 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
20495 if (it
->override_ascent
>= 0)
20497 it
->ascent
= it
->override_ascent
;
20498 it
->descent
= it
->override_descent
;
20499 boff
= it
->override_boff
;
20503 it
->ascent
= FONT_BASE (font
) + boff
;
20504 it
->descent
= FONT_DESCENT (font
) - boff
;
20509 it
->phys_ascent
= pcm
->ascent
+ boff
;
20510 it
->phys_descent
= pcm
->descent
- boff
;
20511 it
->pixel_width
= pcm
->width
;
20515 it
->glyph_not_available_p
= 1;
20516 it
->phys_ascent
= it
->ascent
;
20517 it
->phys_descent
= it
->descent
;
20518 it
->pixel_width
= FONT_WIDTH (font
);
20521 if (it
->constrain_row_ascent_descent_p
)
20523 if (it
->descent
> it
->max_descent
)
20525 it
->ascent
+= it
->descent
- it
->max_descent
;
20526 it
->descent
= it
->max_descent
;
20528 if (it
->ascent
> it
->max_ascent
)
20530 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20531 it
->ascent
= it
->max_ascent
;
20533 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20534 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20535 extra_line_spacing
= 0;
20538 /* If this is a space inside a region of text with
20539 `space-width' property, change its width. */
20540 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
20542 it
->pixel_width
*= XFLOATINT (it
->space_width
);
20544 /* If face has a box, add the box thickness to the character
20545 height. If character has a box line to the left and/or
20546 right, add the box line width to the character's width. */
20547 if (face
->box
!= FACE_NO_BOX
)
20549 int thick
= face
->box_line_width
;
20553 it
->ascent
+= thick
;
20554 it
->descent
+= thick
;
20559 if (it
->start_of_box_run_p
)
20560 it
->pixel_width
+= thick
;
20561 if (it
->end_of_box_run_p
)
20562 it
->pixel_width
+= thick
;
20565 /* If face has an overline, add the height of the overline
20566 (1 pixel) and a 1 pixel margin to the character height. */
20567 if (face
->overline_p
)
20568 it
->ascent
+= overline_margin
;
20570 if (it
->constrain_row_ascent_descent_p
)
20572 if (it
->ascent
> it
->max_ascent
)
20573 it
->ascent
= it
->max_ascent
;
20574 if (it
->descent
> it
->max_descent
)
20575 it
->descent
= it
->max_descent
;
20578 take_vertical_position_into_account (it
);
20580 /* If we have to actually produce glyphs, do it. */
20585 /* Translate a space with a `space-width' property
20586 into a stretch glyph. */
20587 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
20588 / FONT_HEIGHT (font
));
20589 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20590 it
->ascent
+ it
->descent
, ascent
);
20595 /* If characters with lbearing or rbearing are displayed
20596 in this line, record that fact in a flag of the
20597 glyph row. This is used to optimize X output code. */
20598 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
20599 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20602 else if (it
->char_to_display
== '\n')
20604 /* A newline has no width but we need the height of the line.
20605 But if previous part of the line set a height, don't
20606 increase that height */
20608 Lisp_Object height
;
20609 Lisp_Object total_height
= Qnil
;
20611 it
->override_ascent
= -1;
20612 it
->pixel_width
= 0;
20615 height
= get_line_height_property(it
, Qline_height
);
20616 /* Split (line-height total-height) list */
20618 && CONSP (XCDR (height
))
20619 && NILP (XCDR (XCDR (height
))))
20621 total_height
= XCAR (XCDR (height
));
20622 height
= XCAR (height
);
20624 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
20626 if (it
->override_ascent
>= 0)
20628 it
->ascent
= it
->override_ascent
;
20629 it
->descent
= it
->override_descent
;
20630 boff
= it
->override_boff
;
20634 it
->ascent
= FONT_BASE (font
) + boff
;
20635 it
->descent
= FONT_DESCENT (font
) - boff
;
20638 if (EQ (height
, Qt
))
20640 if (it
->descent
> it
->max_descent
)
20642 it
->ascent
+= it
->descent
- it
->max_descent
;
20643 it
->descent
= it
->max_descent
;
20645 if (it
->ascent
> it
->max_ascent
)
20647 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20648 it
->ascent
= it
->max_ascent
;
20650 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20651 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20652 it
->constrain_row_ascent_descent_p
= 1;
20653 extra_line_spacing
= 0;
20657 Lisp_Object spacing
;
20659 it
->phys_ascent
= it
->ascent
;
20660 it
->phys_descent
= it
->descent
;
20662 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
20663 && face
->box
!= FACE_NO_BOX
20664 && face
->box_line_width
> 0)
20666 it
->ascent
+= face
->box_line_width
;
20667 it
->descent
+= face
->box_line_width
;
20670 && XINT (height
) > it
->ascent
+ it
->descent
)
20671 it
->ascent
= XINT (height
) - it
->descent
;
20673 if (!NILP (total_height
))
20674 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
20677 spacing
= get_line_height_property(it
, Qline_spacing
);
20678 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
20680 if (INTEGERP (spacing
))
20682 extra_line_spacing
= XINT (spacing
);
20683 if (!NILP (total_height
))
20684 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
20688 else if (it
->char_to_display
== '\t')
20690 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
20691 int x
= it
->current_x
+ it
->continuation_lines_width
;
20692 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
20694 /* If the distance from the current position to the next tab
20695 stop is less than a space character width, use the
20696 tab stop after that. */
20697 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
20698 next_tab_x
+= tab_width
;
20700 it
->pixel_width
= next_tab_x
- x
;
20702 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
20703 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20707 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20708 it
->ascent
+ it
->descent
, it
->ascent
);
20713 /* A multi-byte character. Assume that the display width of the
20714 character is the width of the character multiplied by the
20715 width of the font. */
20717 /* If we found a font, this font should give us the right
20718 metrics. If we didn't find a font, use the frame's
20719 default font and calculate the width of the character
20720 from the charset width; this is what old redisplay code
20723 pcm
= rif
->per_char_metric (font
, &char2b
,
20724 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
20726 if (font_not_found_p
|| !pcm
)
20728 int charset
= CHAR_CHARSET (it
->char_to_display
);
20730 it
->glyph_not_available_p
= 1;
20731 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
20732 * CHARSET_WIDTH (charset
));
20733 it
->phys_ascent
= FONT_BASE (font
) + boff
;
20734 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20738 it
->pixel_width
= pcm
->width
;
20739 it
->phys_ascent
= pcm
->ascent
+ boff
;
20740 it
->phys_descent
= pcm
->descent
- boff
;
20742 && (pcm
->lbearing
< 0
20743 || pcm
->rbearing
> pcm
->width
))
20744 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20747 it
->ascent
= FONT_BASE (font
) + boff
;
20748 it
->descent
= FONT_DESCENT (font
) - boff
;
20749 if (face
->box
!= FACE_NO_BOX
)
20751 int thick
= face
->box_line_width
;
20755 it
->ascent
+= thick
;
20756 it
->descent
+= thick
;
20761 if (it
->start_of_box_run_p
)
20762 it
->pixel_width
+= thick
;
20763 if (it
->end_of_box_run_p
)
20764 it
->pixel_width
+= thick
;
20767 /* If face has an overline, add the height of the overline
20768 (1 pixel) and a 1 pixel margin to the character height. */
20769 if (face
->overline_p
)
20770 it
->ascent
+= overline_margin
;
20772 take_vertical_position_into_account (it
);
20777 it
->multibyte_p
= saved_multibyte_p
;
20779 else if (it
->what
== IT_COMPOSITION
)
20781 /* Note: A composition is represented as one glyph in the
20782 glyph matrix. There are no padding glyphs. */
20785 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20787 int font_not_found_p
;
20788 struct font_info
*font_info
;
20789 int boff
; /* baseline offset */
20790 struct composition
*cmp
= composition_table
[it
->cmp_id
];
20792 /* Maybe translate single-byte characters to multibyte. */
20793 it
->char_to_display
= it
->c
;
20794 if (unibyte_display_via_language_environment
20795 && SINGLE_BYTE_CHAR_P (it
->c
)
20798 && !NILP (Vnonascii_translation_table
))))
20800 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20803 /* Get face and font to use. Encode IT->char_to_display. */
20804 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20805 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20806 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20807 &char2b
, it
->multibyte_p
, 0);
20810 /* When no suitable font found, use the default font. */
20811 font_not_found_p
= font
== NULL
;
20812 if (font_not_found_p
)
20814 font
= FRAME_FONT (it
->f
);
20815 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20820 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20821 boff
= font_info
->baseline_offset
;
20822 if (font_info
->vertical_centering
)
20823 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20826 /* There are no padding glyphs, so there is only one glyph to
20827 produce for the composition. Important is that pixel_width,
20828 ascent and descent are the values of what is drawn by
20829 draw_glyphs (i.e. the values of the overall glyphs composed). */
20832 /* If we have not yet calculated pixel size data of glyphs of
20833 the composition for the current face font, calculate them
20834 now. Theoretically, we have to check all fonts for the
20835 glyphs, but that requires much time and memory space. So,
20836 here we check only the font of the first glyph. This leads
20837 to incorrect display very rarely, and C-l (recenter) can
20838 correct the display anyway. */
20839 if (cmp
->font
!= (void *) font
)
20841 /* Ascent and descent of the font of the first character of
20842 this composition (adjusted by baseline offset). Ascent
20843 and descent of overall glyphs should not be less than
20844 them respectively. */
20845 int font_ascent
= FONT_BASE (font
) + boff
;
20846 int font_descent
= FONT_DESCENT (font
) - boff
;
20847 /* Bounding box of the overall glyphs. */
20848 int leftmost
, rightmost
, lowest
, highest
;
20849 int i
, width
, ascent
, descent
;
20851 cmp
->font
= (void *) font
;
20853 /* Initialize the bounding box. */
20855 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20856 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
20858 width
= pcm
->width
;
20859 ascent
= pcm
->ascent
;
20860 descent
= pcm
->descent
;
20864 width
= FONT_WIDTH (font
);
20865 ascent
= FONT_BASE (font
);
20866 descent
= FONT_DESCENT (font
);
20870 lowest
= - descent
+ boff
;
20871 highest
= ascent
+ boff
;
20875 && font_info
->default_ascent
20876 && CHAR_TABLE_P (Vuse_default_ascent
)
20877 && !NILP (Faref (Vuse_default_ascent
,
20878 make_number (it
->char_to_display
))))
20879 highest
= font_info
->default_ascent
+ boff
;
20881 /* Draw the first glyph at the normal position. It may be
20882 shifted to right later if some other glyphs are drawn at
20884 cmp
->offsets
[0] = 0;
20885 cmp
->offsets
[1] = boff
;
20887 /* Set cmp->offsets for the remaining glyphs. */
20888 for (i
= 1; i
< cmp
->glyph_len
; i
++)
20890 int left
, right
, btm
, top
;
20891 int ch
= COMPOSITION_GLYPH (cmp
, i
);
20892 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
20894 face
= FACE_FROM_ID (it
->f
, face_id
);
20895 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
20896 &char2b
, it
->multibyte_p
, 0);
20900 font
= FRAME_FONT (it
->f
);
20901 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20907 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20908 boff
= font_info
->baseline_offset
;
20909 if (font_info
->vertical_centering
)
20910 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20914 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20915 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
20917 width
= pcm
->width
;
20918 ascent
= pcm
->ascent
;
20919 descent
= pcm
->descent
;
20923 width
= FONT_WIDTH (font
);
20928 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
20930 /* Relative composition with or without
20931 alternate chars. */
20932 left
= (leftmost
+ rightmost
- width
) / 2;
20933 btm
= - descent
+ boff
;
20934 if (font_info
&& font_info
->relative_compose
20935 && (! CHAR_TABLE_P (Vignore_relative_composition
)
20936 || NILP (Faref (Vignore_relative_composition
,
20937 make_number (ch
)))))
20940 if (- descent
>= font_info
->relative_compose
)
20941 /* One extra pixel between two glyphs. */
20943 else if (ascent
<= 0)
20944 /* One extra pixel between two glyphs. */
20945 btm
= lowest
- 1 - ascent
- descent
;
20950 /* A composition rule is specified by an integer
20951 value that encodes global and new reference
20952 points (GREF and NREF). GREF and NREF are
20953 specified by numbers as below:
20955 0---1---2 -- ascent
20959 9--10--11 -- center
20961 ---3---4---5--- baseline
20963 6---7---8 -- descent
20965 int rule
= COMPOSITION_RULE (cmp
, i
);
20966 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
20968 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
20969 grefx
= gref
% 3, nrefx
= nref
% 3;
20970 grefy
= gref
/ 3, nrefy
= nref
/ 3;
20973 + grefx
* (rightmost
- leftmost
) / 2
20974 - nrefx
* width
/ 2);
20975 btm
= ((grefy
== 0 ? highest
20977 : grefy
== 2 ? lowest
20978 : (highest
+ lowest
) / 2)
20979 - (nrefy
== 0 ? ascent
+ descent
20980 : nrefy
== 1 ? descent
- boff
20982 : (ascent
+ descent
) / 2));
20985 cmp
->offsets
[i
* 2] = left
;
20986 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
20988 /* Update the bounding box of the overall glyphs. */
20989 right
= left
+ width
;
20990 top
= btm
+ descent
+ ascent
;
20991 if (left
< leftmost
)
20993 if (right
> rightmost
)
21001 /* If there are glyphs whose x-offsets are negative,
21002 shift all glyphs to the right and make all x-offsets
21006 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21007 cmp
->offsets
[i
* 2] -= leftmost
;
21008 rightmost
-= leftmost
;
21011 cmp
->pixel_width
= rightmost
;
21012 cmp
->ascent
= highest
;
21013 cmp
->descent
= - lowest
;
21014 if (cmp
->ascent
< font_ascent
)
21015 cmp
->ascent
= font_ascent
;
21016 if (cmp
->descent
< font_descent
)
21017 cmp
->descent
= font_descent
;
21020 it
->pixel_width
= cmp
->pixel_width
;
21021 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
21022 it
->descent
= it
->phys_descent
= cmp
->descent
;
21024 if (face
->box
!= FACE_NO_BOX
)
21026 int thick
= face
->box_line_width
;
21030 it
->ascent
+= thick
;
21031 it
->descent
+= thick
;
21036 if (it
->start_of_box_run_p
)
21037 it
->pixel_width
+= thick
;
21038 if (it
->end_of_box_run_p
)
21039 it
->pixel_width
+= thick
;
21042 /* If face has an overline, add the height of the overline
21043 (1 pixel) and a 1 pixel margin to the character height. */
21044 if (face
->overline_p
)
21045 it
->ascent
+= overline_margin
;
21047 take_vertical_position_into_account (it
);
21050 append_composite_glyph (it
);
21052 else if (it
->what
== IT_IMAGE
)
21053 produce_image_glyph (it
);
21054 else if (it
->what
== IT_STRETCH
)
21055 produce_stretch_glyph (it
);
21057 /* Accumulate dimensions. Note: can't assume that it->descent > 0
21058 because this isn't true for images with `:ascent 100'. */
21059 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
21060 if (it
->area
== TEXT_AREA
)
21061 it
->current_x
+= it
->pixel_width
;
21063 if (extra_line_spacing
> 0)
21065 it
->descent
+= extra_line_spacing
;
21066 if (extra_line_spacing
> it
->max_extra_line_spacing
)
21067 it
->max_extra_line_spacing
= extra_line_spacing
;
21070 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
21071 it
->max_descent
= max (it
->max_descent
, it
->descent
);
21072 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
21073 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
21077 Output LEN glyphs starting at START at the nominal cursor position.
21078 Advance the nominal cursor over the text. The global variable
21079 updated_window contains the window being updated, updated_row is
21080 the glyph row being updated, and updated_area is the area of that
21081 row being updated. */
21084 x_write_glyphs (start
, len
)
21085 struct glyph
*start
;
21090 xassert (updated_window
&& updated_row
);
21093 /* Write glyphs. */
21095 hpos
= start
- updated_row
->glyphs
[updated_area
];
21096 x
= draw_glyphs (updated_window
, output_cursor
.x
,
21097 updated_row
, updated_area
,
21099 DRAW_NORMAL_TEXT
, 0);
21101 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
21102 if (updated_area
== TEXT_AREA
21103 && updated_window
->phys_cursor_on_p
21104 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
21105 && updated_window
->phys_cursor
.hpos
>= hpos
21106 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
21107 updated_window
->phys_cursor_on_p
= 0;
21111 /* Advance the output cursor. */
21112 output_cursor
.hpos
+= len
;
21113 output_cursor
.x
= x
;
21118 Insert LEN glyphs from START at the nominal cursor position. */
21121 x_insert_glyphs (start
, len
)
21122 struct glyph
*start
;
21127 int line_height
, shift_by_width
, shifted_region_width
;
21128 struct glyph_row
*row
;
21129 struct glyph
*glyph
;
21130 int frame_x
, frame_y
, hpos
;
21132 xassert (updated_window
&& updated_row
);
21134 w
= updated_window
;
21135 f
= XFRAME (WINDOW_FRAME (w
));
21137 /* Get the height of the line we are in. */
21139 line_height
= row
->height
;
21141 /* Get the width of the glyphs to insert. */
21142 shift_by_width
= 0;
21143 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
21144 shift_by_width
+= glyph
->pixel_width
;
21146 /* Get the width of the region to shift right. */
21147 shifted_region_width
= (window_box_width (w
, updated_area
)
21152 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
21153 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
21155 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
21156 line_height
, shift_by_width
);
21158 /* Write the glyphs. */
21159 hpos
= start
- row
->glyphs
[updated_area
];
21160 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
21162 DRAW_NORMAL_TEXT
, 0);
21164 /* Advance the output cursor. */
21165 output_cursor
.hpos
+= len
;
21166 output_cursor
.x
+= shift_by_width
;
21172 Erase the current text line from the nominal cursor position
21173 (inclusive) to pixel column TO_X (exclusive). The idea is that
21174 everything from TO_X onward is already erased.
21176 TO_X is a pixel position relative to updated_area of
21177 updated_window. TO_X == -1 means clear to the end of this area. */
21180 x_clear_end_of_line (to_x
)
21184 struct window
*w
= updated_window
;
21185 int max_x
, min_y
, max_y
;
21186 int from_x
, from_y
, to_y
;
21188 xassert (updated_window
&& updated_row
);
21189 f
= XFRAME (w
->frame
);
21191 if (updated_row
->full_width_p
)
21192 max_x
= WINDOW_TOTAL_WIDTH (w
);
21194 max_x
= window_box_width (w
, updated_area
);
21195 max_y
= window_text_bottom_y (w
);
21197 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
21198 of window. For TO_X > 0, truncate to end of drawing area. */
21204 to_x
= min (to_x
, max_x
);
21206 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
21208 /* Notice if the cursor will be cleared by this operation. */
21209 if (!updated_row
->full_width_p
)
21210 notice_overwritten_cursor (w
, updated_area
,
21211 output_cursor
.x
, -1,
21213 MATRIX_ROW_BOTTOM_Y (updated_row
));
21215 from_x
= output_cursor
.x
;
21217 /* Translate to frame coordinates. */
21218 if (updated_row
->full_width_p
)
21220 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
21221 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
21225 int area_left
= window_box_left (w
, updated_area
);
21226 from_x
+= area_left
;
21230 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
21231 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
21232 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
21234 /* Prevent inadvertently clearing to end of the X window. */
21235 if (to_x
> from_x
&& to_y
> from_y
)
21238 rif
->clear_frame_area (f
, from_x
, from_y
,
21239 to_x
- from_x
, to_y
- from_y
);
21244 #endif /* HAVE_WINDOW_SYSTEM */
21248 /***********************************************************************
21250 ***********************************************************************/
21252 /* Value is the internal representation of the specified cursor type
21253 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
21254 of the bar cursor. */
21256 static enum text_cursor_kinds
21257 get_specified_cursor_type (arg
, width
)
21261 enum text_cursor_kinds type
;
21266 if (EQ (arg
, Qbox
))
21267 return FILLED_BOX_CURSOR
;
21269 if (EQ (arg
, Qhollow
))
21270 return HOLLOW_BOX_CURSOR
;
21272 if (EQ (arg
, Qbar
))
21279 && EQ (XCAR (arg
), Qbar
)
21280 && INTEGERP (XCDR (arg
))
21281 && XINT (XCDR (arg
)) >= 0)
21283 *width
= XINT (XCDR (arg
));
21287 if (EQ (arg
, Qhbar
))
21290 return HBAR_CURSOR
;
21294 && EQ (XCAR (arg
), Qhbar
)
21295 && INTEGERP (XCDR (arg
))
21296 && XINT (XCDR (arg
)) >= 0)
21298 *width
= XINT (XCDR (arg
));
21299 return HBAR_CURSOR
;
21302 /* Treat anything unknown as "hollow box cursor".
21303 It was bad to signal an error; people have trouble fixing
21304 .Xdefaults with Emacs, when it has something bad in it. */
21305 type
= HOLLOW_BOX_CURSOR
;
21310 /* Set the default cursor types for specified frame. */
21312 set_frame_cursor_types (f
, arg
)
21319 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
21320 FRAME_CURSOR_WIDTH (f
) = width
;
21322 /* By default, set up the blink-off state depending on the on-state. */
21324 tem
= Fassoc (arg
, Vblink_cursor_alist
);
21327 FRAME_BLINK_OFF_CURSOR (f
)
21328 = get_specified_cursor_type (XCDR (tem
), &width
);
21329 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
21332 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
21336 /* Return the cursor we want to be displayed in window W. Return
21337 width of bar/hbar cursor through WIDTH arg. Return with
21338 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
21339 (i.e. if the `system caret' should track this cursor).
21341 In a mini-buffer window, we want the cursor only to appear if we
21342 are reading input from this window. For the selected window, we
21343 want the cursor type given by the frame parameter or buffer local
21344 setting of cursor-type. If explicitly marked off, draw no cursor.
21345 In all other cases, we want a hollow box cursor. */
21347 static enum text_cursor_kinds
21348 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
21350 struct glyph
*glyph
;
21352 int *active_cursor
;
21354 struct frame
*f
= XFRAME (w
->frame
);
21355 struct buffer
*b
= XBUFFER (w
->buffer
);
21356 int cursor_type
= DEFAULT_CURSOR
;
21357 Lisp_Object alt_cursor
;
21358 int non_selected
= 0;
21360 *active_cursor
= 1;
21363 if (cursor_in_echo_area
21364 && FRAME_HAS_MINIBUF_P (f
)
21365 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
21367 if (w
== XWINDOW (echo_area_window
))
21369 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
21371 *width
= FRAME_CURSOR_WIDTH (f
);
21372 return FRAME_DESIRED_CURSOR (f
);
21375 return get_specified_cursor_type (b
->cursor_type
, width
);
21378 *active_cursor
= 0;
21382 /* Detect a nonselected window or nonselected frame. */
21383 else if (w
!= XWINDOW (f
->selected_window
)
21384 #ifdef HAVE_WINDOW_SYSTEM
21385 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
21389 *active_cursor
= 0;
21391 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
21397 /* Never display a cursor in a window in which cursor-type is nil. */
21398 if (NILP (b
->cursor_type
))
21401 /* Get the normal cursor type for this window. */
21402 if (EQ (b
->cursor_type
, Qt
))
21404 cursor_type
= FRAME_DESIRED_CURSOR (f
);
21405 *width
= FRAME_CURSOR_WIDTH (f
);
21408 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
21410 /* Use cursor-in-non-selected-windows instead
21411 for non-selected window or frame. */
21414 alt_cursor
= b
->cursor_in_non_selected_windows
;
21415 if (!EQ (Qt
, alt_cursor
))
21416 return get_specified_cursor_type (alt_cursor
, width
);
21417 /* t means modify the normal cursor type. */
21418 if (cursor_type
== FILLED_BOX_CURSOR
)
21419 cursor_type
= HOLLOW_BOX_CURSOR
;
21420 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
21422 return cursor_type
;
21425 /* Use normal cursor if not blinked off. */
21426 if (!w
->cursor_off_p
)
21428 #ifdef HAVE_WINDOW_SYSTEM
21429 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21431 if (cursor_type
== FILLED_BOX_CURSOR
)
21433 /* Using a block cursor on large images can be very annoying.
21434 So use a hollow cursor for "large" images.
21435 If image is not transparent (no mask), also use hollow cursor. */
21436 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21437 if (img
!= NULL
&& IMAGEP (img
->spec
))
21439 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
21440 where N = size of default frame font size.
21441 This should cover most of the "tiny" icons people may use. */
21443 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
21444 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
21445 cursor_type
= HOLLOW_BOX_CURSOR
;
21448 else if (cursor_type
!= NO_CURSOR
)
21450 /* Display current only supports BOX and HOLLOW cursors for images.
21451 So for now, unconditionally use a HOLLOW cursor when cursor is
21452 not a solid box cursor. */
21453 cursor_type
= HOLLOW_BOX_CURSOR
;
21457 return cursor_type
;
21460 /* Cursor is blinked off, so determine how to "toggle" it. */
21462 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
21463 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
21464 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
21466 /* Then see if frame has specified a specific blink off cursor type. */
21467 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
21469 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
21470 return FRAME_BLINK_OFF_CURSOR (f
);
21474 /* Some people liked having a permanently visible blinking cursor,
21475 while others had very strong opinions against it. So it was
21476 decided to remove it. KFS 2003-09-03 */
21478 /* Finally perform built-in cursor blinking:
21479 filled box <-> hollow box
21480 wide [h]bar <-> narrow [h]bar
21481 narrow [h]bar <-> no cursor
21482 other type <-> no cursor */
21484 if (cursor_type
== FILLED_BOX_CURSOR
)
21485 return HOLLOW_BOX_CURSOR
;
21487 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
21490 return cursor_type
;
21498 #ifdef HAVE_WINDOW_SYSTEM
21500 /* Notice when the text cursor of window W has been completely
21501 overwritten by a drawing operation that outputs glyphs in AREA
21502 starting at X0 and ending at X1 in the line starting at Y0 and
21503 ending at Y1. X coordinates are area-relative. X1 < 0 means all
21504 the rest of the line after X0 has been written. Y coordinates
21505 are window-relative. */
21508 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
21510 enum glyph_row_area area
;
21511 int x0
, y0
, x1
, y1
;
21513 int cx0
, cx1
, cy0
, cy1
;
21514 struct glyph_row
*row
;
21516 if (!w
->phys_cursor_on_p
)
21518 if (area
!= TEXT_AREA
)
21521 if (w
->phys_cursor
.vpos
< 0
21522 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
21523 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
21524 !(row
->enabled_p
&& row
->displays_text_p
)))
21527 if (row
->cursor_in_fringe_p
)
21529 row
->cursor_in_fringe_p
= 0;
21530 draw_fringe_bitmap (w
, row
, 0);
21531 w
->phys_cursor_on_p
= 0;
21535 cx0
= w
->phys_cursor
.x
;
21536 cx1
= cx0
+ w
->phys_cursor_width
;
21537 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
21540 /* The cursor image will be completely removed from the
21541 screen if the output area intersects the cursor area in
21542 y-direction. When we draw in [y0 y1[, and some part of
21543 the cursor is at y < y0, that part must have been drawn
21544 before. When scrolling, the cursor is erased before
21545 actually scrolling, so we don't come here. When not
21546 scrolling, the rows above the old cursor row must have
21547 changed, and in this case these rows must have written
21548 over the cursor image.
21550 Likewise if part of the cursor is below y1, with the
21551 exception of the cursor being in the first blank row at
21552 the buffer and window end because update_text_area
21553 doesn't draw that row. (Except when it does, but
21554 that's handled in update_text_area.) */
21556 cy0
= w
->phys_cursor
.y
;
21557 cy1
= cy0
+ w
->phys_cursor_height
;
21558 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
21561 w
->phys_cursor_on_p
= 0;
21564 #endif /* HAVE_WINDOW_SYSTEM */
21567 /************************************************************************
21569 ************************************************************************/
21571 #ifdef HAVE_WINDOW_SYSTEM
21574 Fix the display of area AREA of overlapping row ROW in window W
21575 with respect to the overlapping part OVERLAPS. */
21578 x_fix_overlapping_area (w
, row
, area
, overlaps
)
21580 struct glyph_row
*row
;
21581 enum glyph_row_area area
;
21589 for (i
= 0; i
< row
->used
[area
];)
21591 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
21593 int start
= i
, start_x
= x
;
21597 x
+= row
->glyphs
[area
][i
].pixel_width
;
21600 while (i
< row
->used
[area
]
21601 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
21603 draw_glyphs (w
, start_x
, row
, area
,
21605 DRAW_NORMAL_TEXT
, overlaps
);
21609 x
+= row
->glyphs
[area
][i
].pixel_width
;
21619 Draw the cursor glyph of window W in glyph row ROW. See the
21620 comment of draw_glyphs for the meaning of HL. */
21623 draw_phys_cursor_glyph (w
, row
, hl
)
21625 struct glyph_row
*row
;
21626 enum draw_glyphs_face hl
;
21628 /* If cursor hpos is out of bounds, don't draw garbage. This can
21629 happen in mini-buffer windows when switching between echo area
21630 glyphs and mini-buffer. */
21631 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
21633 int on_p
= w
->phys_cursor_on_p
;
21635 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
21636 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
21638 w
->phys_cursor_on_p
= on_p
;
21640 if (hl
== DRAW_CURSOR
)
21641 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21642 /* When we erase the cursor, and ROW is overlapped by other
21643 rows, make sure that these overlapping parts of other rows
21645 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
21647 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21649 if (row
> w
->current_matrix
->rows
21650 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
21651 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
21652 OVERLAPS_ERASED_CURSOR
);
21654 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
21655 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
21656 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
21657 OVERLAPS_ERASED_CURSOR
);
21664 Erase the image of a cursor of window W from the screen. */
21667 erase_phys_cursor (w
)
21670 struct frame
*f
= XFRAME (w
->frame
);
21671 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21672 int hpos
= w
->phys_cursor
.hpos
;
21673 int vpos
= w
->phys_cursor
.vpos
;
21674 int mouse_face_here_p
= 0;
21675 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
21676 struct glyph_row
*cursor_row
;
21677 struct glyph
*cursor_glyph
;
21678 enum draw_glyphs_face hl
;
21680 /* No cursor displayed or row invalidated => nothing to do on the
21682 if (w
->phys_cursor_type
== NO_CURSOR
)
21683 goto mark_cursor_off
;
21685 /* VPOS >= active_glyphs->nrows means that window has been resized.
21686 Don't bother to erase the cursor. */
21687 if (vpos
>= active_glyphs
->nrows
)
21688 goto mark_cursor_off
;
21690 /* If row containing cursor is marked invalid, there is nothing we
21692 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
21693 if (!cursor_row
->enabled_p
)
21694 goto mark_cursor_off
;
21696 /* If line spacing is > 0, old cursor may only be partially visible in
21697 window after split-window. So adjust visible height. */
21698 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
21699 window_text_bottom_y (w
) - cursor_row
->y
);
21701 /* If row is completely invisible, don't attempt to delete a cursor which
21702 isn't there. This can happen if cursor is at top of a window, and
21703 we switch to a buffer with a header line in that window. */
21704 if (cursor_row
->visible_height
<= 0)
21705 goto mark_cursor_off
;
21707 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
21708 if (cursor_row
->cursor_in_fringe_p
)
21710 cursor_row
->cursor_in_fringe_p
= 0;
21711 draw_fringe_bitmap (w
, cursor_row
, 0);
21712 goto mark_cursor_off
;
21715 /* This can happen when the new row is shorter than the old one.
21716 In this case, either draw_glyphs or clear_end_of_line
21717 should have cleared the cursor. Note that we wouldn't be
21718 able to erase the cursor in this case because we don't have a
21719 cursor glyph at hand. */
21720 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
21721 goto mark_cursor_off
;
21723 /* If the cursor is in the mouse face area, redisplay that when
21724 we clear the cursor. */
21725 if (! NILP (dpyinfo
->mouse_face_window
)
21726 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
21727 && (vpos
> dpyinfo
->mouse_face_beg_row
21728 || (vpos
== dpyinfo
->mouse_face_beg_row
21729 && hpos
>= dpyinfo
->mouse_face_beg_col
))
21730 && (vpos
< dpyinfo
->mouse_face_end_row
21731 || (vpos
== dpyinfo
->mouse_face_end_row
21732 && hpos
< dpyinfo
->mouse_face_end_col
))
21733 /* Don't redraw the cursor's spot in mouse face if it is at the
21734 end of a line (on a newline). The cursor appears there, but
21735 mouse highlighting does not. */
21736 && cursor_row
->used
[TEXT_AREA
] > hpos
)
21737 mouse_face_here_p
= 1;
21739 /* Maybe clear the display under the cursor. */
21740 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
21743 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
21746 cursor_glyph
= get_phys_cursor_glyph (w
);
21747 if (cursor_glyph
== NULL
)
21748 goto mark_cursor_off
;
21750 width
= cursor_glyph
->pixel_width
;
21751 left_x
= window_box_left_offset (w
, TEXT_AREA
);
21752 x
= w
->phys_cursor
.x
;
21754 width
-= left_x
- x
;
21755 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
21756 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
21757 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
21760 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
21763 /* Erase the cursor by redrawing the character underneath it. */
21764 if (mouse_face_here_p
)
21765 hl
= DRAW_MOUSE_FACE
;
21767 hl
= DRAW_NORMAL_TEXT
;
21768 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
21771 w
->phys_cursor_on_p
= 0;
21772 w
->phys_cursor_type
= NO_CURSOR
;
21777 Display or clear cursor of window W. If ON is zero, clear the
21778 cursor. If it is non-zero, display the cursor. If ON is nonzero,
21779 where to put the cursor is specified by HPOS, VPOS, X and Y. */
21782 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
21784 int on
, hpos
, vpos
, x
, y
;
21786 struct frame
*f
= XFRAME (w
->frame
);
21787 int new_cursor_type
;
21788 int new_cursor_width
;
21790 struct glyph_row
*glyph_row
;
21791 struct glyph
*glyph
;
21793 /* This is pointless on invisible frames, and dangerous on garbaged
21794 windows and frames; in the latter case, the frame or window may
21795 be in the midst of changing its size, and x and y may be off the
21797 if (! FRAME_VISIBLE_P (f
)
21798 || FRAME_GARBAGED_P (f
)
21799 || vpos
>= w
->current_matrix
->nrows
21800 || hpos
>= w
->current_matrix
->matrix_w
)
21803 /* If cursor is off and we want it off, return quickly. */
21804 if (!on
&& !w
->phys_cursor_on_p
)
21807 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
21808 /* If cursor row is not enabled, we don't really know where to
21809 display the cursor. */
21810 if (!glyph_row
->enabled_p
)
21812 w
->phys_cursor_on_p
= 0;
21817 if (!glyph_row
->exact_window_width_line_p
21818 || hpos
< glyph_row
->used
[TEXT_AREA
])
21819 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
21821 xassert (interrupt_input_blocked
);
21823 /* Set new_cursor_type to the cursor we want to be displayed. */
21824 new_cursor_type
= get_window_cursor_type (w
, glyph
,
21825 &new_cursor_width
, &active_cursor
);
21827 /* If cursor is currently being shown and we don't want it to be or
21828 it is in the wrong place, or the cursor type is not what we want,
21830 if (w
->phys_cursor_on_p
21832 || w
->phys_cursor
.x
!= x
21833 || w
->phys_cursor
.y
!= y
21834 || new_cursor_type
!= w
->phys_cursor_type
21835 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
21836 && new_cursor_width
!= w
->phys_cursor_width
)))
21837 erase_phys_cursor (w
);
21839 /* Don't check phys_cursor_on_p here because that flag is only set
21840 to zero in some cases where we know that the cursor has been
21841 completely erased, to avoid the extra work of erasing the cursor
21842 twice. In other words, phys_cursor_on_p can be 1 and the cursor
21843 still not be visible, or it has only been partly erased. */
21846 w
->phys_cursor_ascent
= glyph_row
->ascent
;
21847 w
->phys_cursor_height
= glyph_row
->height
;
21849 /* Set phys_cursor_.* before x_draw_.* is called because some
21850 of them may need the information. */
21851 w
->phys_cursor
.x
= x
;
21852 w
->phys_cursor
.y
= glyph_row
->y
;
21853 w
->phys_cursor
.hpos
= hpos
;
21854 w
->phys_cursor
.vpos
= vpos
;
21857 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
21858 new_cursor_type
, new_cursor_width
,
21859 on
, active_cursor
);
21863 /* Switch the display of W's cursor on or off, according to the value
21867 update_window_cursor (w
, on
)
21871 /* Don't update cursor in windows whose frame is in the process
21872 of being deleted. */
21873 if (w
->current_matrix
)
21876 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21877 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21883 /* Call update_window_cursor with parameter ON_P on all leaf windows
21884 in the window tree rooted at W. */
21887 update_cursor_in_window_tree (w
, on_p
)
21893 if (!NILP (w
->hchild
))
21894 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
21895 else if (!NILP (w
->vchild
))
21896 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
21898 update_window_cursor (w
, on_p
);
21900 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
21906 Display the cursor on window W, or clear it, according to ON_P.
21907 Don't change the cursor's position. */
21910 x_update_cursor (f
, on_p
)
21914 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
21919 Clear the cursor of window W to background color, and mark the
21920 cursor as not shown. This is used when the text where the cursor
21921 is is about to be rewritten. */
21927 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
21928 update_window_cursor (w
, 0);
21933 Display the active region described by mouse_face_* according to DRAW. */
21936 show_mouse_face (dpyinfo
, draw
)
21937 Display_Info
*dpyinfo
;
21938 enum draw_glyphs_face draw
;
21940 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
21941 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21943 if (/* If window is in the process of being destroyed, don't bother
21945 w
->current_matrix
!= NULL
21946 /* Don't update mouse highlight if hidden */
21947 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
21948 /* Recognize when we are called to operate on rows that don't exist
21949 anymore. This can happen when a window is split. */
21950 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
21952 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
21953 struct glyph_row
*row
, *first
, *last
;
21955 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
21956 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
21958 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
21960 int start_hpos
, end_hpos
, start_x
;
21962 /* For all but the first row, the highlight starts at column 0. */
21965 start_hpos
= dpyinfo
->mouse_face_beg_col
;
21966 start_x
= dpyinfo
->mouse_face_beg_x
;
21975 end_hpos
= dpyinfo
->mouse_face_end_col
;
21978 end_hpos
= row
->used
[TEXT_AREA
];
21979 if (draw
== DRAW_NORMAL_TEXT
)
21980 row
->fill_line_p
= 1; /* Clear to end of line */
21983 if (end_hpos
> start_hpos
)
21985 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
21986 start_hpos
, end_hpos
,
21990 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
21994 /* When we've written over the cursor, arrange for it to
21995 be displayed again. */
21996 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
21999 display_and_set_cursor (w
, 1,
22000 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22001 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22006 /* Change the mouse cursor. */
22007 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
22008 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
22009 else if (draw
== DRAW_MOUSE_FACE
)
22010 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
22012 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
22016 Clear out the mouse-highlighted active region.
22017 Redraw it un-highlighted first. Value is non-zero if mouse
22018 face was actually drawn unhighlighted. */
22021 clear_mouse_face (dpyinfo
)
22022 Display_Info
*dpyinfo
;
22026 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
22028 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
22032 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22033 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22034 dpyinfo
->mouse_face_window
= Qnil
;
22035 dpyinfo
->mouse_face_overlay
= Qnil
;
22041 Non-zero if physical cursor of window W is within mouse face. */
22044 cursor_in_mouse_face_p (w
)
22047 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22048 int in_mouse_face
= 0;
22050 if (WINDOWP (dpyinfo
->mouse_face_window
)
22051 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
22053 int hpos
= w
->phys_cursor
.hpos
;
22054 int vpos
= w
->phys_cursor
.vpos
;
22056 if (vpos
>= dpyinfo
->mouse_face_beg_row
22057 && vpos
<= dpyinfo
->mouse_face_end_row
22058 && (vpos
> dpyinfo
->mouse_face_beg_row
22059 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22060 && (vpos
< dpyinfo
->mouse_face_end_row
22061 || hpos
< dpyinfo
->mouse_face_end_col
22062 || dpyinfo
->mouse_face_past_end
))
22066 return in_mouse_face
;
22072 /* Find the glyph matrix position of buffer position CHARPOS in window
22073 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
22074 current glyphs must be up to date. If CHARPOS is above window
22075 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
22076 of last line in W. In the row containing CHARPOS, stop before glyphs
22077 having STOP as object. */
22079 #if 1 /* This is a version of fast_find_position that's more correct
22080 in the presence of hscrolling, for example. I didn't install
22081 it right away because the problem fixed is minor, it failed
22082 in 20.x as well, and I think it's too risky to install
22083 so near the release of 21.1. 2001-09-25 gerd. */
22085 #ifndef HAVE_CARBON
22089 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
22092 int *hpos
, *vpos
, *x
, *y
;
22095 struct glyph_row
*row
, *first
;
22096 struct glyph
*glyph
, *end
;
22099 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22100 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
22105 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
22109 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
22112 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22116 /* If whole rows or last part of a row came from a display overlay,
22117 row_containing_pos will skip over such rows because their end pos
22118 equals the start pos of the overlay or interval.
22120 Move back if we have a STOP object and previous row's
22121 end glyph came from STOP. */
22124 struct glyph_row
*prev
;
22125 while ((prev
= row
- 1, prev
>= first
)
22126 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
22127 && prev
->used
[TEXT_AREA
] > 0)
22129 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
22130 glyph
= beg
+ prev
->used
[TEXT_AREA
];
22131 while (--glyph
>= beg
22132 && INTEGERP (glyph
->object
));
22134 || !EQ (stop
, glyph
->object
))
22142 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22144 glyph
= row
->glyphs
[TEXT_AREA
];
22145 end
= glyph
+ row
->used
[TEXT_AREA
];
22147 /* Skip over glyphs not having an object at the start of the row.
22148 These are special glyphs like truncation marks on terminal
22150 if (row
->displays_text_p
)
22152 && INTEGERP (glyph
->object
)
22153 && !EQ (stop
, glyph
->object
)
22154 && glyph
->charpos
< 0)
22156 *x
+= glyph
->pixel_width
;
22161 && !INTEGERP (glyph
->object
)
22162 && !EQ (stop
, glyph
->object
)
22163 && (!BUFFERP (glyph
->object
)
22164 || glyph
->charpos
< charpos
))
22166 *x
+= glyph
->pixel_width
;
22170 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
22177 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
22180 int *hpos
, *vpos
, *x
, *y
;
22185 int maybe_next_line_p
= 0;
22186 int line_start_position
;
22187 int yb
= window_text_bottom_y (w
);
22188 struct glyph_row
*row
, *best_row
;
22189 int row_vpos
, best_row_vpos
;
22192 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22193 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22195 while (row
->y
< yb
)
22197 if (row
->used
[TEXT_AREA
])
22198 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
22200 line_start_position
= 0;
22202 if (line_start_position
> pos
)
22204 /* If the position sought is the end of the buffer,
22205 don't include the blank lines at the bottom of the window. */
22206 else if (line_start_position
== pos
22207 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
22209 maybe_next_line_p
= 1;
22212 else if (line_start_position
> 0)
22215 best_row_vpos
= row_vpos
;
22218 if (row
->y
+ row
->height
>= yb
)
22225 /* Find the right column within BEST_ROW. */
22227 current_x
= best_row
->x
;
22228 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
22230 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
22231 int charpos
= glyph
->charpos
;
22233 if (BUFFERP (glyph
->object
))
22235 if (charpos
== pos
)
22238 *vpos
= best_row_vpos
;
22243 else if (charpos
> pos
)
22246 else if (EQ (glyph
->object
, stop
))
22251 current_x
+= glyph
->pixel_width
;
22254 /* If we're looking for the end of the buffer,
22255 and we didn't find it in the line we scanned,
22256 use the start of the following line. */
22257 if (maybe_next_line_p
)
22262 current_x
= best_row
->x
;
22265 *vpos
= best_row_vpos
;
22266 *hpos
= lastcol
+ 1;
22275 /* Find the position of the glyph for position POS in OBJECT in
22276 window W's current matrix, and return in *X, *Y the pixel
22277 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
22279 RIGHT_P non-zero means return the position of the right edge of the
22280 glyph, RIGHT_P zero means return the left edge position.
22282 If no glyph for POS exists in the matrix, return the position of
22283 the glyph with the next smaller position that is in the matrix, if
22284 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
22285 exists in the matrix, return the position of the glyph with the
22286 next larger position in OBJECT.
22288 Value is non-zero if a glyph was found. */
22291 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
22294 Lisp_Object object
;
22295 int *hpos
, *vpos
, *x
, *y
;
22298 int yb
= window_text_bottom_y (w
);
22299 struct glyph_row
*r
;
22300 struct glyph
*best_glyph
= NULL
;
22301 struct glyph_row
*best_row
= NULL
;
22304 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22305 r
->enabled_p
&& r
->y
< yb
;
22308 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
22309 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
22312 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
22313 if (EQ (g
->object
, object
))
22315 if (g
->charpos
== pos
)
22322 else if (best_glyph
== NULL
22323 || ((abs (g
->charpos
- pos
)
22324 < abs (best_glyph
->charpos
- pos
))
22327 : g
->charpos
> pos
)))
22341 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
22345 *x
+= best_glyph
->pixel_width
;
22350 *vpos
= best_row
- w
->current_matrix
->rows
;
22353 return best_glyph
!= NULL
;
22357 /* See if position X, Y is within a hot-spot of an image. */
22360 on_hot_spot_p (hot_spot
, x
, y
)
22361 Lisp_Object hot_spot
;
22364 if (!CONSP (hot_spot
))
22367 if (EQ (XCAR (hot_spot
), Qrect
))
22369 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
22370 Lisp_Object rect
= XCDR (hot_spot
);
22374 if (!CONSP (XCAR (rect
)))
22376 if (!CONSP (XCDR (rect
)))
22378 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
22380 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
22382 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
22384 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
22388 else if (EQ (XCAR (hot_spot
), Qcircle
))
22390 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
22391 Lisp_Object circ
= XCDR (hot_spot
);
22392 Lisp_Object lr
, lx0
, ly0
;
22394 && CONSP (XCAR (circ
))
22395 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
22396 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
22397 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
22399 double r
= XFLOATINT (lr
);
22400 double dx
= XINT (lx0
) - x
;
22401 double dy
= XINT (ly0
) - y
;
22402 return (dx
* dx
+ dy
* dy
<= r
* r
);
22405 else if (EQ (XCAR (hot_spot
), Qpoly
))
22407 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
22408 if (VECTORP (XCDR (hot_spot
)))
22410 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
22411 Lisp_Object
*poly
= v
->contents
;
22415 Lisp_Object lx
, ly
;
22418 /* Need an even number of coordinates, and at least 3 edges. */
22419 if (n
< 6 || n
& 1)
22422 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
22423 If count is odd, we are inside polygon. Pixels on edges
22424 may or may not be included depending on actual geometry of the
22426 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
22427 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
22429 x0
= XINT (lx
), y0
= XINT (ly
);
22430 for (i
= 0; i
< n
; i
+= 2)
22432 int x1
= x0
, y1
= y0
;
22433 if ((lx
= poly
[i
], !INTEGERP (lx
))
22434 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
22436 x0
= XINT (lx
), y0
= XINT (ly
);
22438 /* Does this segment cross the X line? */
22446 if (y
> y0
&& y
> y1
)
22448 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
22454 /* If we don't understand the format, pretend we're not in the hot-spot. */
22459 find_hot_spot (map
, x
, y
)
22463 while (CONSP (map
))
22465 if (CONSP (XCAR (map
))
22466 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
22474 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
22476 doc
: /* Lookup in image map MAP coordinates X and Y.
22477 An image map is an alist where each element has the format (AREA ID PLIST).
22478 An AREA is specified as either a rectangle, a circle, or a polygon:
22479 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
22480 pixel coordinates of the upper left and bottom right corners.
22481 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
22482 and the radius of the circle; r may be a float or integer.
22483 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
22484 vector describes one corner in the polygon.
22485 Returns the alist element for the first matching AREA in MAP. */)
22496 return find_hot_spot (map
, XINT (x
), XINT (y
));
22500 /* Display frame CURSOR, optionally using shape defined by POINTER. */
22502 define_frame_cursor1 (f
, cursor
, pointer
)
22505 Lisp_Object pointer
;
22507 /* Do not change cursor shape while dragging mouse. */
22508 if (!NILP (do_mouse_tracking
))
22511 if (!NILP (pointer
))
22513 if (EQ (pointer
, Qarrow
))
22514 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22515 else if (EQ (pointer
, Qhand
))
22516 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
22517 else if (EQ (pointer
, Qtext
))
22518 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22519 else if (EQ (pointer
, intern ("hdrag")))
22520 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22521 #ifdef HAVE_X_WINDOWS
22522 else if (EQ (pointer
, intern ("vdrag")))
22523 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
22525 else if (EQ (pointer
, intern ("hourglass")))
22526 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
22527 else if (EQ (pointer
, Qmodeline
))
22528 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
22530 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22533 if (cursor
!= No_Cursor
)
22534 rif
->define_frame_cursor (f
, cursor
);
22537 /* Take proper action when mouse has moved to the mode or header line
22538 or marginal area AREA of window W, x-position X and y-position Y.
22539 X is relative to the start of the text display area of W, so the
22540 width of bitmap areas and scroll bars must be subtracted to get a
22541 position relative to the start of the mode line. */
22544 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
22545 Lisp_Object window
;
22547 enum window_part area
;
22549 struct window
*w
= XWINDOW (window
);
22550 struct frame
*f
= XFRAME (w
->frame
);
22551 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22552 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22553 Lisp_Object pointer
= Qnil
;
22554 int charpos
, dx
, dy
, width
, height
;
22555 Lisp_Object string
, object
= Qnil
;
22556 Lisp_Object pos
, help
;
22558 Lisp_Object mouse_face
;
22559 int original_x_pixel
= x
;
22560 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
22561 struct glyph_row
*row
;
22563 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
22568 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
22569 &object
, &dx
, &dy
, &width
, &height
);
22571 row
= (area
== ON_MODE_LINE
22572 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
22573 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
22576 if (row
->mode_line_p
&& row
->enabled_p
)
22578 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
22579 end
= glyph
+ row
->used
[TEXT_AREA
];
22581 for (x0
= original_x_pixel
;
22582 glyph
< end
&& x0
>= glyph
->pixel_width
;
22584 x0
-= glyph
->pixel_width
;
22592 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
22593 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
22594 &object
, &dx
, &dy
, &width
, &height
);
22599 if (IMAGEP (object
))
22601 Lisp_Object image_map
, hotspot
;
22602 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
22604 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
22606 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22608 Lisp_Object area_id
, plist
;
22610 area_id
= XCAR (hotspot
);
22611 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22612 If so, we could look for mouse-enter, mouse-leave
22613 properties in PLIST (and do something...). */
22614 hotspot
= XCDR (hotspot
);
22615 if (CONSP (hotspot
)
22616 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22618 pointer
= Fplist_get (plist
, Qpointer
);
22619 if (NILP (pointer
))
22621 help
= Fplist_get (plist
, Qhelp_echo
);
22624 help_echo_string
= help
;
22625 /* Is this correct? ++kfs */
22626 XSETWINDOW (help_echo_window
, w
);
22627 help_echo_object
= w
->buffer
;
22628 help_echo_pos
= charpos
;
22632 if (NILP (pointer
))
22633 pointer
= Fplist_get (XCDR (object
), QCpointer
);
22636 if (STRINGP (string
))
22638 pos
= make_number (charpos
);
22639 /* If we're on a string with `help-echo' text property, arrange
22640 for the help to be displayed. This is done by setting the
22641 global variable help_echo_string to the help string. */
22644 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
22647 help_echo_string
= help
;
22648 XSETWINDOW (help_echo_window
, w
);
22649 help_echo_object
= string
;
22650 help_echo_pos
= charpos
;
22654 if (NILP (pointer
))
22655 pointer
= Fget_text_property (pos
, Qpointer
, string
);
22657 /* Change the mouse pointer according to what is under X/Y. */
22658 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
22661 map
= Fget_text_property (pos
, Qlocal_map
, string
);
22662 if (!KEYMAPP (map
))
22663 map
= Fget_text_property (pos
, Qkeymap
, string
);
22664 if (!KEYMAPP (map
))
22665 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
22668 /* Change the mouse face according to what is under X/Y. */
22669 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
22670 if (!NILP (mouse_face
)
22671 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22676 struct glyph
* tmp_glyph
;
22680 int total_pixel_width
;
22685 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
22686 Qmouse_face
, string
, Qnil
);
22688 b
= make_number (0);
22690 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
22692 e
= make_number (SCHARS (string
));
22694 /* Calculate the position(glyph position: GPOS) of GLYPH in
22695 displayed string. GPOS is different from CHARPOS.
22697 CHARPOS is the position of glyph in internal string
22698 object. A mode line string format has structures which
22699 is converted to a flatten by emacs lisp interpreter.
22700 The internal string is an element of the structures.
22701 The displayed string is the flatten string. */
22703 if (glyph
> row_start_glyph
)
22705 tmp_glyph
= glyph
- 1;
22706 while (tmp_glyph
>= row_start_glyph
22707 && tmp_glyph
->charpos
>= XINT (b
)
22708 && EQ (tmp_glyph
->object
, glyph
->object
))
22715 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
22716 displayed string holding GLYPH.
22718 GSEQ_LENGTH is different from SCHARS (STRING).
22719 SCHARS (STRING) returns the length of the internal string. */
22720 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
22721 tmp_glyph
->charpos
< XINT (e
);
22722 tmp_glyph
++, gseq_length
++)
22724 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22728 total_pixel_width
= 0;
22729 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
22730 total_pixel_width
+= tmp_glyph
->pixel_width
;
22732 /* Pre calculation of re-rendering position */
22734 hpos
= (area
== ON_MODE_LINE
22735 ? (w
->current_matrix
)->nrows
- 1
22738 /* If the re-rendering position is included in the last
22739 re-rendering area, we should do nothing. */
22740 if ( EQ (window
, dpyinfo
->mouse_face_window
)
22741 && dpyinfo
->mouse_face_beg_col
<= vpos
22742 && vpos
< dpyinfo
->mouse_face_end_col
22743 && dpyinfo
->mouse_face_beg_row
== hpos
)
22746 if (clear_mouse_face (dpyinfo
))
22747 cursor
= No_Cursor
;
22749 dpyinfo
->mouse_face_beg_col
= vpos
;
22750 dpyinfo
->mouse_face_beg_row
= hpos
;
22752 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
22753 dpyinfo
->mouse_face_beg_y
= 0;
22755 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
22756 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
22758 dpyinfo
->mouse_face_end_x
= 0;
22759 dpyinfo
->mouse_face_end_y
= 0;
22761 dpyinfo
->mouse_face_past_end
= 0;
22762 dpyinfo
->mouse_face_window
= window
;
22764 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
22767 glyph
->face_id
, 1);
22768 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22770 if (NILP (pointer
))
22773 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22774 clear_mouse_face (dpyinfo
);
22776 define_frame_cursor1 (f
, cursor
, pointer
);
22781 Take proper action when the mouse has moved to position X, Y on
22782 frame F as regards highlighting characters that have mouse-face
22783 properties. Also de-highlighting chars where the mouse was before.
22784 X and Y can be negative or out of range. */
22787 note_mouse_highlight (f
, x
, y
)
22791 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22792 enum window_part part
;
22793 Lisp_Object window
;
22795 Cursor cursor
= No_Cursor
;
22796 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
22799 /* When a menu is active, don't highlight because this looks odd. */
22800 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (MAC_OS)
22801 if (popup_activated ())
22805 if (NILP (Vmouse_highlight
)
22806 || !f
->glyphs_initialized_p
)
22809 dpyinfo
->mouse_face_mouse_x
= x
;
22810 dpyinfo
->mouse_face_mouse_y
= y
;
22811 dpyinfo
->mouse_face_mouse_frame
= f
;
22813 if (dpyinfo
->mouse_face_defer
)
22816 if (gc_in_progress
)
22818 dpyinfo
->mouse_face_deferred_gc
= 1;
22822 /* Which window is that in? */
22823 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
22825 /* If we were displaying active text in another window, clear that.
22826 Also clear if we move out of text area in same window. */
22827 if (! EQ (window
, dpyinfo
->mouse_face_window
)
22828 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
22829 && !NILP (dpyinfo
->mouse_face_window
)))
22830 clear_mouse_face (dpyinfo
);
22832 /* Not on a window -> return. */
22833 if (!WINDOWP (window
))
22836 /* Reset help_echo_string. It will get recomputed below. */
22837 help_echo_string
= Qnil
;
22839 /* Convert to window-relative pixel coordinates. */
22840 w
= XWINDOW (window
);
22841 frame_to_window_pixel_xy (w
, &x
, &y
);
22843 /* Handle tool-bar window differently since it doesn't display a
22845 if (EQ (window
, f
->tool_bar_window
))
22847 note_tool_bar_highlight (f
, x
, y
);
22851 /* Mouse is on the mode, header line or margin? */
22852 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
22853 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
22855 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
22859 if (part
== ON_VERTICAL_BORDER
)
22861 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22862 help_echo_string
= build_string ("drag-mouse-1: resize");
22864 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
22865 || part
== ON_SCROLL_BAR
)
22866 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22868 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22870 /* Are we in a window whose display is up to date?
22871 And verify the buffer's text has not changed. */
22872 b
= XBUFFER (w
->buffer
);
22873 if (part
== ON_TEXT
22874 && EQ (w
->window_end_valid
, w
->buffer
)
22875 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
22876 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
22878 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
22879 struct glyph
*glyph
;
22880 Lisp_Object object
;
22881 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
22882 Lisp_Object
*overlay_vec
= NULL
;
22884 struct buffer
*obuf
;
22885 int obegv
, ozv
, same_region
;
22887 /* Find the glyph under X/Y. */
22888 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
22890 /* Look for :pointer property on image. */
22891 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22893 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22894 if (img
!= NULL
&& IMAGEP (img
->spec
))
22896 Lisp_Object image_map
, hotspot
;
22897 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
22899 && (hotspot
= find_hot_spot (image_map
,
22900 glyph
->slice
.x
+ dx
,
22901 glyph
->slice
.y
+ dy
),
22903 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22905 Lisp_Object area_id
, plist
;
22907 area_id
= XCAR (hotspot
);
22908 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22909 If so, we could look for mouse-enter, mouse-leave
22910 properties in PLIST (and do something...). */
22911 hotspot
= XCDR (hotspot
);
22912 if (CONSP (hotspot
)
22913 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22915 pointer
= Fplist_get (plist
, Qpointer
);
22916 if (NILP (pointer
))
22918 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
22919 if (!NILP (help_echo_string
))
22921 help_echo_window
= window
;
22922 help_echo_object
= glyph
->object
;
22923 help_echo_pos
= glyph
->charpos
;
22927 if (NILP (pointer
))
22928 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
22932 /* Clear mouse face if X/Y not over text. */
22934 || area
!= TEXT_AREA
22935 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
22937 if (clear_mouse_face (dpyinfo
))
22938 cursor
= No_Cursor
;
22939 if (NILP (pointer
))
22941 if (area
!= TEXT_AREA
)
22942 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22944 pointer
= Vvoid_text_area_pointer
;
22949 pos
= glyph
->charpos
;
22950 object
= glyph
->object
;
22951 if (!STRINGP (object
) && !BUFFERP (object
))
22954 /* If we get an out-of-range value, return now; avoid an error. */
22955 if (BUFFERP (object
) && pos
> BUF_Z (b
))
22958 /* Make the window's buffer temporarily current for
22959 overlays_at and compute_char_face. */
22960 obuf
= current_buffer
;
22961 current_buffer
= b
;
22967 /* Is this char mouse-active or does it have help-echo? */
22968 position
= make_number (pos
);
22970 if (BUFFERP (object
))
22972 /* Put all the overlays we want in a vector in overlay_vec. */
22973 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
22974 /* Sort overlays into increasing priority order. */
22975 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
22980 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
22981 && vpos
>= dpyinfo
->mouse_face_beg_row
22982 && vpos
<= dpyinfo
->mouse_face_end_row
22983 && (vpos
> dpyinfo
->mouse_face_beg_row
22984 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22985 && (vpos
< dpyinfo
->mouse_face_end_row
22986 || hpos
< dpyinfo
->mouse_face_end_col
22987 || dpyinfo
->mouse_face_past_end
));
22990 cursor
= No_Cursor
;
22992 /* Check mouse-face highlighting. */
22994 /* If there exists an overlay with mouse-face overlapping
22995 the one we are currently highlighting, we have to
22996 check if we enter the overlapping overlay, and then
22997 highlight only that. */
22998 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
22999 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
23001 /* Find the highest priority overlay that has a mouse-face
23004 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
23006 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
23007 if (!NILP (mouse_face
))
23008 overlay
= overlay_vec
[i
];
23011 /* If we're actually highlighting the same overlay as
23012 before, there's no need to do that again. */
23013 if (!NILP (overlay
)
23014 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
23015 goto check_help_echo
;
23017 dpyinfo
->mouse_face_overlay
= overlay
;
23019 /* Clear the display of the old active region, if any. */
23020 if (clear_mouse_face (dpyinfo
))
23021 cursor
= No_Cursor
;
23023 /* If no overlay applies, get a text property. */
23024 if (NILP (overlay
))
23025 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
23027 /* Handle the overlay case. */
23028 if (!NILP (overlay
))
23030 /* Find the range of text around this char that
23031 should be active. */
23032 Lisp_Object before
, after
;
23035 before
= Foverlay_start (overlay
);
23036 after
= Foverlay_end (overlay
);
23037 /* Record this as the current active region. */
23038 fast_find_position (w
, XFASTINT (before
),
23039 &dpyinfo
->mouse_face_beg_col
,
23040 &dpyinfo
->mouse_face_beg_row
,
23041 &dpyinfo
->mouse_face_beg_x
,
23042 &dpyinfo
->mouse_face_beg_y
, Qnil
);
23044 dpyinfo
->mouse_face_past_end
23045 = !fast_find_position (w
, XFASTINT (after
),
23046 &dpyinfo
->mouse_face_end_col
,
23047 &dpyinfo
->mouse_face_end_row
,
23048 &dpyinfo
->mouse_face_end_x
,
23049 &dpyinfo
->mouse_face_end_y
, Qnil
);
23050 dpyinfo
->mouse_face_window
= window
;
23052 dpyinfo
->mouse_face_face_id
23053 = face_at_buffer_position (w
, pos
, 0, 0,
23055 !dpyinfo
->mouse_face_hidden
);
23057 /* Display it as active. */
23058 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23059 cursor
= No_Cursor
;
23061 /* Handle the text property case. */
23062 else if (!NILP (mouse_face
) && BUFFERP (object
))
23064 /* Find the range of text around this char that
23065 should be active. */
23066 Lisp_Object before
, after
, beginning
, end
;
23069 beginning
= Fmarker_position (w
->start
);
23070 end
= make_number (BUF_Z (XBUFFER (object
))
23071 - XFASTINT (w
->window_end_pos
));
23073 = Fprevious_single_property_change (make_number (pos
+ 1),
23075 object
, beginning
);
23077 = Fnext_single_property_change (position
, Qmouse_face
,
23080 /* Record this as the current active region. */
23081 fast_find_position (w
, XFASTINT (before
),
23082 &dpyinfo
->mouse_face_beg_col
,
23083 &dpyinfo
->mouse_face_beg_row
,
23084 &dpyinfo
->mouse_face_beg_x
,
23085 &dpyinfo
->mouse_face_beg_y
, Qnil
);
23086 dpyinfo
->mouse_face_past_end
23087 = !fast_find_position (w
, XFASTINT (after
),
23088 &dpyinfo
->mouse_face_end_col
,
23089 &dpyinfo
->mouse_face_end_row
,
23090 &dpyinfo
->mouse_face_end_x
,
23091 &dpyinfo
->mouse_face_end_y
, Qnil
);
23092 dpyinfo
->mouse_face_window
= window
;
23094 if (BUFFERP (object
))
23095 dpyinfo
->mouse_face_face_id
23096 = face_at_buffer_position (w
, pos
, 0, 0,
23098 !dpyinfo
->mouse_face_hidden
);
23100 /* Display it as active. */
23101 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23102 cursor
= No_Cursor
;
23104 else if (!NILP (mouse_face
) && STRINGP (object
))
23109 b
= Fprevious_single_property_change (make_number (pos
+ 1),
23112 e
= Fnext_single_property_change (position
, Qmouse_face
,
23115 b
= make_number (0);
23117 e
= make_number (SCHARS (object
) - 1);
23119 fast_find_string_pos (w
, XINT (b
), object
,
23120 &dpyinfo
->mouse_face_beg_col
,
23121 &dpyinfo
->mouse_face_beg_row
,
23122 &dpyinfo
->mouse_face_beg_x
,
23123 &dpyinfo
->mouse_face_beg_y
, 0);
23124 fast_find_string_pos (w
, XINT (e
), object
,
23125 &dpyinfo
->mouse_face_end_col
,
23126 &dpyinfo
->mouse_face_end_row
,
23127 &dpyinfo
->mouse_face_end_x
,
23128 &dpyinfo
->mouse_face_end_y
, 1);
23129 dpyinfo
->mouse_face_past_end
= 0;
23130 dpyinfo
->mouse_face_window
= window
;
23131 dpyinfo
->mouse_face_face_id
23132 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
23133 glyph
->face_id
, 1);
23134 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23135 cursor
= No_Cursor
;
23137 else if (STRINGP (object
) && NILP (mouse_face
))
23139 /* A string which doesn't have mouse-face, but
23140 the text ``under'' it might have. */
23141 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
23142 int start
= MATRIX_ROW_START_CHARPOS (r
);
23144 pos
= string_buffer_position (w
, object
, start
);
23146 mouse_face
= get_char_property_and_overlay (make_number (pos
),
23150 if (!NILP (mouse_face
) && !NILP (overlay
))
23152 Lisp_Object before
= Foverlay_start (overlay
);
23153 Lisp_Object after
= Foverlay_end (overlay
);
23156 /* Note that we might not be able to find position
23157 BEFORE in the glyph matrix if the overlay is
23158 entirely covered by a `display' property. In
23159 this case, we overshoot. So let's stop in
23160 the glyph matrix before glyphs for OBJECT. */
23161 fast_find_position (w
, XFASTINT (before
),
23162 &dpyinfo
->mouse_face_beg_col
,
23163 &dpyinfo
->mouse_face_beg_row
,
23164 &dpyinfo
->mouse_face_beg_x
,
23165 &dpyinfo
->mouse_face_beg_y
,
23168 dpyinfo
->mouse_face_past_end
23169 = !fast_find_position (w
, XFASTINT (after
),
23170 &dpyinfo
->mouse_face_end_col
,
23171 &dpyinfo
->mouse_face_end_row
,
23172 &dpyinfo
->mouse_face_end_x
,
23173 &dpyinfo
->mouse_face_end_y
,
23175 dpyinfo
->mouse_face_window
= window
;
23176 dpyinfo
->mouse_face_face_id
23177 = face_at_buffer_position (w
, pos
, 0, 0,
23179 !dpyinfo
->mouse_face_hidden
);
23181 /* Display it as active. */
23182 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23183 cursor
= No_Cursor
;
23190 /* Look for a `help-echo' property. */
23191 if (NILP (help_echo_string
)) {
23192 Lisp_Object help
, overlay
;
23194 /* Check overlays first. */
23195 help
= overlay
= Qnil
;
23196 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
23198 overlay
= overlay_vec
[i
];
23199 help
= Foverlay_get (overlay
, Qhelp_echo
);
23204 help_echo_string
= help
;
23205 help_echo_window
= window
;
23206 help_echo_object
= overlay
;
23207 help_echo_pos
= pos
;
23211 Lisp_Object object
= glyph
->object
;
23212 int charpos
= glyph
->charpos
;
23214 /* Try text properties. */
23215 if (STRINGP (object
)
23217 && charpos
< SCHARS (object
))
23219 help
= Fget_text_property (make_number (charpos
),
23220 Qhelp_echo
, object
);
23223 /* If the string itself doesn't specify a help-echo,
23224 see if the buffer text ``under'' it does. */
23225 struct glyph_row
*r
23226 = MATRIX_ROW (w
->current_matrix
, vpos
);
23227 int start
= MATRIX_ROW_START_CHARPOS (r
);
23228 int pos
= string_buffer_position (w
, object
, start
);
23231 help
= Fget_char_property (make_number (pos
),
23232 Qhelp_echo
, w
->buffer
);
23236 object
= w
->buffer
;
23241 else if (BUFFERP (object
)
23244 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
23249 help_echo_string
= help
;
23250 help_echo_window
= window
;
23251 help_echo_object
= object
;
23252 help_echo_pos
= charpos
;
23257 /* Look for a `pointer' property. */
23258 if (NILP (pointer
))
23260 /* Check overlays first. */
23261 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
23262 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
23264 if (NILP (pointer
))
23266 Lisp_Object object
= glyph
->object
;
23267 int charpos
= glyph
->charpos
;
23269 /* Try text properties. */
23270 if (STRINGP (object
)
23272 && charpos
< SCHARS (object
))
23274 pointer
= Fget_text_property (make_number (charpos
),
23276 if (NILP (pointer
))
23278 /* If the string itself doesn't specify a pointer,
23279 see if the buffer text ``under'' it does. */
23280 struct glyph_row
*r
23281 = MATRIX_ROW (w
->current_matrix
, vpos
);
23282 int start
= MATRIX_ROW_START_CHARPOS (r
);
23283 int pos
= string_buffer_position (w
, object
, start
);
23285 pointer
= Fget_char_property (make_number (pos
),
23286 Qpointer
, w
->buffer
);
23289 else if (BUFFERP (object
)
23292 pointer
= Fget_text_property (make_number (charpos
),
23299 current_buffer
= obuf
;
23304 define_frame_cursor1 (f
, cursor
, pointer
);
23309 Clear any mouse-face on window W. This function is part of the
23310 redisplay interface, and is called from try_window_id and similar
23311 functions to ensure the mouse-highlight is off. */
23314 x_clear_window_mouse_face (w
)
23317 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23318 Lisp_Object window
;
23321 XSETWINDOW (window
, w
);
23322 if (EQ (window
, dpyinfo
->mouse_face_window
))
23323 clear_mouse_face (dpyinfo
);
23329 Just discard the mouse face information for frame F, if any.
23330 This is used when the size of F is changed. */
23333 cancel_mouse_face (f
)
23336 Lisp_Object window
;
23337 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23339 window
= dpyinfo
->mouse_face_window
;
23340 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
23342 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
23343 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
23344 dpyinfo
->mouse_face_window
= Qnil
;
23349 #endif /* HAVE_WINDOW_SYSTEM */
23352 /***********************************************************************
23354 ***********************************************************************/
23356 #ifdef HAVE_WINDOW_SYSTEM
23358 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
23359 which intersects rectangle R. R is in window-relative coordinates. */
23362 expose_area (w
, row
, r
, area
)
23364 struct glyph_row
*row
;
23366 enum glyph_row_area area
;
23368 struct glyph
*first
= row
->glyphs
[area
];
23369 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
23370 struct glyph
*last
;
23371 int first_x
, start_x
, x
;
23373 if (area
== TEXT_AREA
&& row
->fill_line_p
)
23374 /* If row extends face to end of line write the whole line. */
23375 draw_glyphs (w
, 0, row
, area
,
23376 0, row
->used
[area
],
23377 DRAW_NORMAL_TEXT
, 0);
23380 /* Set START_X to the window-relative start position for drawing glyphs of
23381 AREA. The first glyph of the text area can be partially visible.
23382 The first glyphs of other areas cannot. */
23383 start_x
= window_box_left_offset (w
, area
);
23385 if (area
== TEXT_AREA
)
23388 /* Find the first glyph that must be redrawn. */
23390 && x
+ first
->pixel_width
< r
->x
)
23392 x
+= first
->pixel_width
;
23396 /* Find the last one. */
23400 && x
< r
->x
+ r
->width
)
23402 x
+= last
->pixel_width
;
23408 draw_glyphs (w
, first_x
- start_x
, row
, area
,
23409 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
23410 DRAW_NORMAL_TEXT
, 0);
23415 /* Redraw the parts of the glyph row ROW on window W intersecting
23416 rectangle R. R is in window-relative coordinates. Value is
23417 non-zero if mouse-face was overwritten. */
23420 expose_line (w
, row
, r
)
23422 struct glyph_row
*row
;
23425 xassert (row
->enabled_p
);
23427 if (row
->mode_line_p
|| w
->pseudo_window_p
)
23428 draw_glyphs (w
, 0, row
, TEXT_AREA
,
23429 0, row
->used
[TEXT_AREA
],
23430 DRAW_NORMAL_TEXT
, 0);
23433 if (row
->used
[LEFT_MARGIN_AREA
])
23434 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
23435 if (row
->used
[TEXT_AREA
])
23436 expose_area (w
, row
, r
, TEXT_AREA
);
23437 if (row
->used
[RIGHT_MARGIN_AREA
])
23438 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
23439 draw_row_fringe_bitmaps (w
, row
);
23442 return row
->mouse_face_p
;
23446 /* Redraw those parts of glyphs rows during expose event handling that
23447 overlap other rows. Redrawing of an exposed line writes over parts
23448 of lines overlapping that exposed line; this function fixes that.
23450 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
23451 row in W's current matrix that is exposed and overlaps other rows.
23452 LAST_OVERLAPPING_ROW is the last such row. */
23455 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
23457 struct glyph_row
*first_overlapping_row
;
23458 struct glyph_row
*last_overlapping_row
;
23460 struct glyph_row
*row
;
23462 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
23463 if (row
->overlapping_p
)
23465 xassert (row
->enabled_p
&& !row
->mode_line_p
);
23467 if (row
->used
[LEFT_MARGIN_AREA
])
23468 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
23470 if (row
->used
[TEXT_AREA
])
23471 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
23473 if (row
->used
[RIGHT_MARGIN_AREA
])
23474 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
23479 /* Return non-zero if W's cursor intersects rectangle R. */
23482 phys_cursor_in_rect_p (w
, r
)
23486 XRectangle cr
, result
;
23487 struct glyph
*cursor_glyph
;
23488 struct glyph_row
*row
;
23490 if (w
->phys_cursor
.vpos
>= 0
23491 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
23492 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
23494 && row
->cursor_in_fringe_p
)
23496 /* Cursor is in the fringe. */
23497 cr
.x
= window_box_right_offset (w
,
23498 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
23499 ? RIGHT_MARGIN_AREA
23502 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
23503 cr
.height
= row
->height
;
23504 return x_intersect_rectangles (&cr
, r
, &result
);
23507 cursor_glyph
= get_phys_cursor_glyph (w
);
23510 /* r is relative to W's box, but w->phys_cursor.x is relative
23511 to left edge of W's TEXT area. Adjust it. */
23512 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
23513 cr
.y
= w
->phys_cursor
.y
;
23514 cr
.width
= cursor_glyph
->pixel_width
;
23515 cr
.height
= w
->phys_cursor_height
;
23516 /* ++KFS: W32 version used W32-specific IntersectRect here, but
23517 I assume the effect is the same -- and this is portable. */
23518 return x_intersect_rectangles (&cr
, r
, &result
);
23526 Draw a vertical window border to the right of window W if W doesn't
23527 have vertical scroll bars. */
23530 x_draw_vertical_border (w
)
23533 /* We could do better, if we knew what type of scroll-bar the adjacent
23534 windows (on either side) have... But we don't :-(
23535 However, I think this works ok. ++KFS 2003-04-25 */
23537 /* Redraw borders between horizontally adjacent windows. Don't
23538 do it for frames with vertical scroll bars because either the
23539 right scroll bar of a window, or the left scroll bar of its
23540 neighbor will suffice as a border. */
23541 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
23544 if (!WINDOW_RIGHTMOST_P (w
)
23545 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
23547 int x0
, x1
, y0
, y1
;
23549 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23552 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23555 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
23557 else if (!WINDOW_LEFTMOST_P (w
)
23558 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
23560 int x0
, x1
, y0
, y1
;
23562 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23565 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23568 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
23573 /* Redraw the part of window W intersection rectangle FR. Pixel
23574 coordinates in FR are frame-relative. Call this function with
23575 input blocked. Value is non-zero if the exposure overwrites
23579 expose_window (w
, fr
)
23583 struct frame
*f
= XFRAME (w
->frame
);
23585 int mouse_face_overwritten_p
= 0;
23587 /* If window is not yet fully initialized, do nothing. This can
23588 happen when toolkit scroll bars are used and a window is split.
23589 Reconfiguring the scroll bar will generate an expose for a newly
23591 if (w
->current_matrix
== NULL
)
23594 /* When we're currently updating the window, display and current
23595 matrix usually don't agree. Arrange for a thorough display
23597 if (w
== updated_window
)
23599 SET_FRAME_GARBAGED (f
);
23603 /* Frame-relative pixel rectangle of W. */
23604 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
23605 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
23606 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
23607 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
23609 if (x_intersect_rectangles (fr
, &wr
, &r
))
23611 int yb
= window_text_bottom_y (w
);
23612 struct glyph_row
*row
;
23613 int cursor_cleared_p
;
23614 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
23616 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
23617 r
.x
, r
.y
, r
.width
, r
.height
));
23619 /* Convert to window coordinates. */
23620 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
23621 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
23623 /* Turn off the cursor. */
23624 if (!w
->pseudo_window_p
23625 && phys_cursor_in_rect_p (w
, &r
))
23627 x_clear_cursor (w
);
23628 cursor_cleared_p
= 1;
23631 cursor_cleared_p
= 0;
23633 /* Update lines intersecting rectangle R. */
23634 first_overlapping_row
= last_overlapping_row
= NULL
;
23635 for (row
= w
->current_matrix
->rows
;
23640 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
23642 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
23643 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
23644 || (r
.y
>= y0
&& r
.y
< y1
)
23645 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
23647 /* A header line may be overlapping, but there is no need
23648 to fix overlapping areas for them. KFS 2005-02-12 */
23649 if (row
->overlapping_p
&& !row
->mode_line_p
)
23651 if (first_overlapping_row
== NULL
)
23652 first_overlapping_row
= row
;
23653 last_overlapping_row
= row
;
23656 if (expose_line (w
, row
, &r
))
23657 mouse_face_overwritten_p
= 1;
23664 /* Display the mode line if there is one. */
23665 if (WINDOW_WANTS_MODELINE_P (w
)
23666 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
23668 && row
->y
< r
.y
+ r
.height
)
23670 if (expose_line (w
, row
, &r
))
23671 mouse_face_overwritten_p
= 1;
23674 if (!w
->pseudo_window_p
)
23676 /* Fix the display of overlapping rows. */
23677 if (first_overlapping_row
)
23678 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
23680 /* Draw border between windows. */
23681 x_draw_vertical_border (w
);
23683 /* Turn the cursor on again. */
23684 if (cursor_cleared_p
)
23685 update_window_cursor (w
, 1);
23689 return mouse_face_overwritten_p
;
23694 /* Redraw (parts) of all windows in the window tree rooted at W that
23695 intersect R. R contains frame pixel coordinates. Value is
23696 non-zero if the exposure overwrites mouse-face. */
23699 expose_window_tree (w
, r
)
23703 struct frame
*f
= XFRAME (w
->frame
);
23704 int mouse_face_overwritten_p
= 0;
23706 while (w
&& !FRAME_GARBAGED_P (f
))
23708 if (!NILP (w
->hchild
))
23709 mouse_face_overwritten_p
23710 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
23711 else if (!NILP (w
->vchild
))
23712 mouse_face_overwritten_p
23713 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
23715 mouse_face_overwritten_p
|= expose_window (w
, r
);
23717 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
23720 return mouse_face_overwritten_p
;
23725 Redisplay an exposed area of frame F. X and Y are the upper-left
23726 corner of the exposed rectangle. W and H are width and height of
23727 the exposed area. All are pixel values. W or H zero means redraw
23728 the entire frame. */
23731 expose_frame (f
, x
, y
, w
, h
)
23736 int mouse_face_overwritten_p
= 0;
23738 TRACE ((stderr
, "expose_frame "));
23740 /* No need to redraw if frame will be redrawn soon. */
23741 if (FRAME_GARBAGED_P (f
))
23743 TRACE ((stderr
, " garbaged\n"));
23747 /* If basic faces haven't been realized yet, there is no point in
23748 trying to redraw anything. This can happen when we get an expose
23749 event while Emacs is starting, e.g. by moving another window. */
23750 if (FRAME_FACE_CACHE (f
) == NULL
23751 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
23753 TRACE ((stderr
, " no faces\n"));
23757 if (w
== 0 || h
== 0)
23760 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
23761 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
23771 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
23772 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
23774 if (WINDOWP (f
->tool_bar_window
))
23775 mouse_face_overwritten_p
23776 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
23778 #ifdef HAVE_X_WINDOWS
23780 #ifndef USE_X_TOOLKIT
23781 if (WINDOWP (f
->menu_bar_window
))
23782 mouse_face_overwritten_p
23783 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
23784 #endif /* not USE_X_TOOLKIT */
23788 /* Some window managers support a focus-follows-mouse style with
23789 delayed raising of frames. Imagine a partially obscured frame,
23790 and moving the mouse into partially obscured mouse-face on that
23791 frame. The visible part of the mouse-face will be highlighted,
23792 then the WM raises the obscured frame. With at least one WM, KDE
23793 2.1, Emacs is not getting any event for the raising of the frame
23794 (even tried with SubstructureRedirectMask), only Expose events.
23795 These expose events will draw text normally, i.e. not
23796 highlighted. Which means we must redo the highlight here.
23797 Subsume it under ``we love X''. --gerd 2001-08-15 */
23798 /* Included in Windows version because Windows most likely does not
23799 do the right thing if any third party tool offers
23800 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
23801 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
23803 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23804 if (f
== dpyinfo
->mouse_face_mouse_frame
)
23806 int x
= dpyinfo
->mouse_face_mouse_x
;
23807 int y
= dpyinfo
->mouse_face_mouse_y
;
23808 clear_mouse_face (dpyinfo
);
23809 note_mouse_highlight (f
, x
, y
);
23816 Determine the intersection of two rectangles R1 and R2. Return
23817 the intersection in *RESULT. Value is non-zero if RESULT is not
23821 x_intersect_rectangles (r1
, r2
, result
)
23822 XRectangle
*r1
, *r2
, *result
;
23824 XRectangle
*left
, *right
;
23825 XRectangle
*upper
, *lower
;
23826 int intersection_p
= 0;
23828 /* Rearrange so that R1 is the left-most rectangle. */
23830 left
= r1
, right
= r2
;
23832 left
= r2
, right
= r1
;
23834 /* X0 of the intersection is right.x0, if this is inside R1,
23835 otherwise there is no intersection. */
23836 if (right
->x
<= left
->x
+ left
->width
)
23838 result
->x
= right
->x
;
23840 /* The right end of the intersection is the minimum of the
23841 the right ends of left and right. */
23842 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
23845 /* Same game for Y. */
23847 upper
= r1
, lower
= r2
;
23849 upper
= r2
, lower
= r1
;
23851 /* The upper end of the intersection is lower.y0, if this is inside
23852 of upper. Otherwise, there is no intersection. */
23853 if (lower
->y
<= upper
->y
+ upper
->height
)
23855 result
->y
= lower
->y
;
23857 /* The lower end of the intersection is the minimum of the lower
23858 ends of upper and lower. */
23859 result
->height
= (min (lower
->y
+ lower
->height
,
23860 upper
->y
+ upper
->height
)
23862 intersection_p
= 1;
23866 return intersection_p
;
23869 #endif /* HAVE_WINDOW_SYSTEM */
23872 /***********************************************************************
23874 ***********************************************************************/
23879 Vwith_echo_area_save_vector
= Qnil
;
23880 staticpro (&Vwith_echo_area_save_vector
);
23882 Vmessage_stack
= Qnil
;
23883 staticpro (&Vmessage_stack
);
23885 Qinhibit_redisplay
= intern ("inhibit-redisplay");
23886 staticpro (&Qinhibit_redisplay
);
23888 message_dolog_marker1
= Fmake_marker ();
23889 staticpro (&message_dolog_marker1
);
23890 message_dolog_marker2
= Fmake_marker ();
23891 staticpro (&message_dolog_marker2
);
23892 message_dolog_marker3
= Fmake_marker ();
23893 staticpro (&message_dolog_marker3
);
23896 defsubr (&Sdump_frame_glyph_matrix
);
23897 defsubr (&Sdump_glyph_matrix
);
23898 defsubr (&Sdump_glyph_row
);
23899 defsubr (&Sdump_tool_bar_row
);
23900 defsubr (&Strace_redisplay
);
23901 defsubr (&Strace_to_stderr
);
23903 #ifdef HAVE_WINDOW_SYSTEM
23904 defsubr (&Stool_bar_lines_needed
);
23905 defsubr (&Slookup_image_map
);
23907 defsubr (&Sformat_mode_line
);
23909 staticpro (&Qmenu_bar_update_hook
);
23910 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
23912 staticpro (&Qoverriding_terminal_local_map
);
23913 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
23915 staticpro (&Qoverriding_local_map
);
23916 Qoverriding_local_map
= intern ("overriding-local-map");
23918 staticpro (&Qwindow_scroll_functions
);
23919 Qwindow_scroll_functions
= intern ("window-scroll-functions");
23921 staticpro (&Qredisplay_end_trigger_functions
);
23922 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
23924 staticpro (&Qinhibit_point_motion_hooks
);
23925 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
23927 QCdata
= intern (":data");
23928 staticpro (&QCdata
);
23929 Qdisplay
= intern ("display");
23930 staticpro (&Qdisplay
);
23931 Qspace_width
= intern ("space-width");
23932 staticpro (&Qspace_width
);
23933 Qraise
= intern ("raise");
23934 staticpro (&Qraise
);
23935 Qslice
= intern ("slice");
23936 staticpro (&Qslice
);
23937 Qspace
= intern ("space");
23938 staticpro (&Qspace
);
23939 Qmargin
= intern ("margin");
23940 staticpro (&Qmargin
);
23941 Qpointer
= intern ("pointer");
23942 staticpro (&Qpointer
);
23943 Qleft_margin
= intern ("left-margin");
23944 staticpro (&Qleft_margin
);
23945 Qright_margin
= intern ("right-margin");
23946 staticpro (&Qright_margin
);
23947 Qcenter
= intern ("center");
23948 staticpro (&Qcenter
);
23949 Qline_height
= intern ("line-height");
23950 staticpro (&Qline_height
);
23951 QCalign_to
= intern (":align-to");
23952 staticpro (&QCalign_to
);
23953 QCrelative_width
= intern (":relative-width");
23954 staticpro (&QCrelative_width
);
23955 QCrelative_height
= intern (":relative-height");
23956 staticpro (&QCrelative_height
);
23957 QCeval
= intern (":eval");
23958 staticpro (&QCeval
);
23959 QCpropertize
= intern (":propertize");
23960 staticpro (&QCpropertize
);
23961 QCfile
= intern (":file");
23962 staticpro (&QCfile
);
23963 Qfontified
= intern ("fontified");
23964 staticpro (&Qfontified
);
23965 Qfontification_functions
= intern ("fontification-functions");
23966 staticpro (&Qfontification_functions
);
23967 Qtrailing_whitespace
= intern ("trailing-whitespace");
23968 staticpro (&Qtrailing_whitespace
);
23969 Qescape_glyph
= intern ("escape-glyph");
23970 staticpro (&Qescape_glyph
);
23971 Qnobreak_space
= intern ("nobreak-space");
23972 staticpro (&Qnobreak_space
);
23973 Qimage
= intern ("image");
23974 staticpro (&Qimage
);
23975 QCmap
= intern (":map");
23976 staticpro (&QCmap
);
23977 QCpointer
= intern (":pointer");
23978 staticpro (&QCpointer
);
23979 Qrect
= intern ("rect");
23980 staticpro (&Qrect
);
23981 Qcircle
= intern ("circle");
23982 staticpro (&Qcircle
);
23983 Qpoly
= intern ("poly");
23984 staticpro (&Qpoly
);
23985 Qmessage_truncate_lines
= intern ("message-truncate-lines");
23986 staticpro (&Qmessage_truncate_lines
);
23987 Qgrow_only
= intern ("grow-only");
23988 staticpro (&Qgrow_only
);
23989 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
23990 staticpro (&Qinhibit_menubar_update
);
23991 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
23992 staticpro (&Qinhibit_eval_during_redisplay
);
23993 Qposition
= intern ("position");
23994 staticpro (&Qposition
);
23995 Qbuffer_position
= intern ("buffer-position");
23996 staticpro (&Qbuffer_position
);
23997 Qobject
= intern ("object");
23998 staticpro (&Qobject
);
23999 Qbar
= intern ("bar");
24001 Qhbar
= intern ("hbar");
24002 staticpro (&Qhbar
);
24003 Qbox
= intern ("box");
24005 Qhollow
= intern ("hollow");
24006 staticpro (&Qhollow
);
24007 Qhand
= intern ("hand");
24008 staticpro (&Qhand
);
24009 Qarrow
= intern ("arrow");
24010 staticpro (&Qarrow
);
24011 Qtext
= intern ("text");
24012 staticpro (&Qtext
);
24013 Qrisky_local_variable
= intern ("risky-local-variable");
24014 staticpro (&Qrisky_local_variable
);
24015 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
24016 staticpro (&Qinhibit_free_realized_faces
);
24018 list_of_error
= Fcons (Fcons (intern ("error"),
24019 Fcons (intern ("void-variable"), Qnil
)),
24021 staticpro (&list_of_error
);
24023 Qlast_arrow_position
= intern ("last-arrow-position");
24024 staticpro (&Qlast_arrow_position
);
24025 Qlast_arrow_string
= intern ("last-arrow-string");
24026 staticpro (&Qlast_arrow_string
);
24028 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
24029 staticpro (&Qoverlay_arrow_string
);
24030 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
24031 staticpro (&Qoverlay_arrow_bitmap
);
24033 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
24034 staticpro (&echo_buffer
[0]);
24035 staticpro (&echo_buffer
[1]);
24037 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
24038 staticpro (&echo_area_buffer
[0]);
24039 staticpro (&echo_area_buffer
[1]);
24041 Vmessages_buffer_name
= build_string ("*Messages*");
24042 staticpro (&Vmessages_buffer_name
);
24044 mode_line_proptrans_alist
= Qnil
;
24045 staticpro (&mode_line_proptrans_alist
);
24046 mode_line_string_list
= Qnil
;
24047 staticpro (&mode_line_string_list
);
24048 mode_line_string_face
= Qnil
;
24049 staticpro (&mode_line_string_face
);
24050 mode_line_string_face_prop
= Qnil
;
24051 staticpro (&mode_line_string_face_prop
);
24052 Vmode_line_unwind_vector
= Qnil
;
24053 staticpro (&Vmode_line_unwind_vector
);
24055 help_echo_string
= Qnil
;
24056 staticpro (&help_echo_string
);
24057 help_echo_object
= Qnil
;
24058 staticpro (&help_echo_object
);
24059 help_echo_window
= Qnil
;
24060 staticpro (&help_echo_window
);
24061 previous_help_echo_string
= Qnil
;
24062 staticpro (&previous_help_echo_string
);
24063 help_echo_pos
= -1;
24065 #ifdef HAVE_WINDOW_SYSTEM
24066 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
24067 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
24068 For example, if a block cursor is over a tab, it will be drawn as
24069 wide as that tab on the display. */);
24070 x_stretch_cursor_p
= 0;
24073 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
24074 doc
: /* *Non-nil means highlight trailing whitespace.
24075 The face used for trailing whitespace is `trailing-whitespace'. */);
24076 Vshow_trailing_whitespace
= Qnil
;
24078 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
24079 doc
: /* *Control highlighting of nobreak space and soft hyphen.
24080 A value of t means highlight the character itself (for nobreak space,
24081 use face `nobreak-space').
24082 A value of nil means no highlighting.
24083 Other values mean display the escape glyph followed by an ordinary
24084 space or ordinary hyphen. */);
24085 Vnobreak_char_display
= Qt
;
24087 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
24088 doc
: /* *The pointer shape to show in void text areas.
24089 A value of nil means to show the text pointer. Other options are `arrow',
24090 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
24091 Vvoid_text_area_pointer
= Qarrow
;
24093 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
24094 doc
: /* Non-nil means don't actually do any redisplay.
24095 This is used for internal purposes. */);
24096 Vinhibit_redisplay
= Qnil
;
24098 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
24099 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
24100 Vglobal_mode_string
= Qnil
;
24102 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
24103 doc
: /* Marker for where to display an arrow on top of the buffer text.
24104 This must be the beginning of a line in order to work.
24105 See also `overlay-arrow-string'. */);
24106 Voverlay_arrow_position
= Qnil
;
24108 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
24109 doc
: /* String to display as an arrow in non-window frames.
24110 See also `overlay-arrow-position'. */);
24111 Voverlay_arrow_string
= build_string ("=>");
24113 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
24114 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
24115 The symbols on this list are examined during redisplay to determine
24116 where to display overlay arrows. */);
24117 Voverlay_arrow_variable_list
24118 = Fcons (intern ("overlay-arrow-position"), Qnil
);
24120 DEFVAR_INT ("scroll-step", &scroll_step
,
24121 doc
: /* *The number of lines to try scrolling a window by when point moves out.
24122 If that fails to bring point back on frame, point is centered instead.
24123 If this is zero, point is always centered after it moves off frame.
24124 If you want scrolling to always be a line at a time, you should set
24125 `scroll-conservatively' to a large value rather than set this to 1. */);
24127 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
24128 doc
: /* *Scroll up to this many lines, to bring point back on screen.
24129 If point moves off-screen, redisplay will scroll by up to
24130 `scroll-conservatively' lines in order to bring point just barely
24131 onto the screen again. If that cannot be done, then redisplay
24132 recenters point as usual.
24134 A value of zero means always recenter point if it moves off screen. */);
24135 scroll_conservatively
= 0;
24137 DEFVAR_INT ("scroll-margin", &scroll_margin
,
24138 doc
: /* *Number of lines of margin at the top and bottom of a window.
24139 Recenter the window whenever point gets within this many lines
24140 of the top or bottom of the window. */);
24143 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
24144 doc
: /* Pixels per inch value for non-window system displays.
24145 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
24146 Vdisplay_pixels_per_inch
= make_float (72.0);
24149 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
24152 DEFVAR_BOOL ("truncate-partial-width-windows",
24153 &truncate_partial_width_windows
,
24154 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
24155 truncate_partial_width_windows
= 1;
24157 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
24158 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
24159 Any other value means to use the appropriate face, `mode-line',
24160 `header-line', or `menu' respectively. */);
24161 mode_line_inverse_video
= 1;
24163 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
24164 doc
: /* *Maximum buffer size for which line number should be displayed.
24165 If the buffer is bigger than this, the line number does not appear
24166 in the mode line. A value of nil means no limit. */);
24167 Vline_number_display_limit
= Qnil
;
24169 DEFVAR_INT ("line-number-display-limit-width",
24170 &line_number_display_limit_width
,
24171 doc
: /* *Maximum line width (in characters) for line number display.
24172 If the average length of the lines near point is bigger than this, then the
24173 line number may be omitted from the mode line. */);
24174 line_number_display_limit_width
= 200;
24176 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
24177 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
24178 highlight_nonselected_windows
= 0;
24180 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
24181 doc
: /* Non-nil if more than one frame is visible on this display.
24182 Minibuffer-only frames don't count, but iconified frames do.
24183 This variable is not guaranteed to be accurate except while processing
24184 `frame-title-format' and `icon-title-format'. */);
24186 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
24187 doc
: /* Template for displaying the title bar of visible frames.
24188 \(Assuming the window manager supports this feature.)
24190 This variable has the same structure as `mode-line-format', except that
24191 the %c and %l constructs are ignored. It is used only on frames for
24192 which no explicit name has been set \(see `modify-frame-parameters'). */);
24194 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
24195 doc
: /* Template for displaying the title bar of an iconified frame.
24196 \(Assuming the window manager supports this feature.)
24197 This variable has the same structure as `mode-line-format' (which see),
24198 and is used only on frames for which no explicit name has been set
24199 \(see `modify-frame-parameters'). */);
24201 = Vframe_title_format
24202 = Fcons (intern ("multiple-frames"),
24203 Fcons (build_string ("%b"),
24204 Fcons (Fcons (empty_string
,
24205 Fcons (intern ("invocation-name"),
24206 Fcons (build_string ("@"),
24207 Fcons (intern ("system-name"),
24211 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
24212 doc
: /* Maximum number of lines to keep in the message log buffer.
24213 If nil, disable message logging. If t, log messages but don't truncate
24214 the buffer when it becomes large. */);
24215 Vmessage_log_max
= make_number (100);
24217 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
24218 doc
: /* Functions called before redisplay, if window sizes have changed.
24219 The value should be a list of functions that take one argument.
24220 Just before redisplay, for each frame, if any of its windows have changed
24221 size since the last redisplay, or have been split or deleted,
24222 all the functions in the list are called, with the frame as argument. */);
24223 Vwindow_size_change_functions
= Qnil
;
24225 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
24226 doc
: /* List of functions to call before redisplaying a window with scrolling.
24227 Each function is called with two arguments, the window
24228 and its new display-start position. Note that the value of `window-end'
24229 is not valid when these functions are called. */);
24230 Vwindow_scroll_functions
= Qnil
;
24232 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
24233 doc
: /* Functions called when redisplay of a window reaches the end trigger.
24234 Each function is called with two arguments, the window and the end trigger value.
24235 See `set-window-redisplay-end-trigger'. */);
24236 Vredisplay_end_trigger_functions
= Qnil
;
24238 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
24239 doc
: /* *Non-nil means autoselect window with mouse pointer.
24240 If nil, do not autoselect windows.
24241 A positive number means delay autoselection by that many seconds: a
24242 window is autoselected only after the mouse has remained in that
24243 window for the duration of the delay.
24244 A negative number has a similar effect, but causes windows to be
24245 autoselected only after the mouse has stopped moving. \(Because of
24246 the way Emacs compares mouse events, you will occasionally wait twice
24247 that time before the window gets selected.\)
24248 Any other value means to autoselect window instantaneously when the
24249 mouse pointer enters it.
24251 Autoselection selects the minibuffer only if it is active, and never
24252 unselects the minibuffer if it is active.
24254 When customizing this variable make sure that the actual value of
24255 `focus-follows-mouse' matches the behavior of your window manager. */);
24256 Vmouse_autoselect_window
= Qnil
;
24258 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
24259 doc
: /* *Non-nil means automatically resize tool-bars.
24260 This dynamically changes the tool-bar's height to the minimum height
24261 that is needed to make all tool-bar items visible.
24262 If value is `grow-only', the tool-bar's height is only increased
24263 automatically; to decrease the tool-bar height, use \\[recenter]. */);
24264 Vauto_resize_tool_bars
= Qt
;
24266 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
24267 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
24268 auto_raise_tool_bar_buttons_p
= 1;
24270 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
24271 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
24272 make_cursor_line_fully_visible_p
= 1;
24274 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
24275 doc
: /* *Border below tool-bar in pixels.
24276 If an integer, use it as the height of the border.
24277 If it is one of `internal-border-width' or `border-width', use the
24278 value of the corresponding frame parameter.
24279 Otherwise, no border is added below the tool-bar. */);
24280 Vtool_bar_border
= Qinternal_border_width
;
24282 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
24283 doc
: /* *Margin around tool-bar buttons in pixels.
24284 If an integer, use that for both horizontal and vertical margins.
24285 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
24286 HORZ specifying the horizontal margin, and VERT specifying the
24287 vertical margin. */);
24288 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
24290 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
24291 doc
: /* *Relief thickness of tool-bar buttons. */);
24292 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
24294 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
24295 doc
: /* List of functions to call to fontify regions of text.
24296 Each function is called with one argument POS. Functions must
24297 fontify a region starting at POS in the current buffer, and give
24298 fontified regions the property `fontified'. */);
24299 Vfontification_functions
= Qnil
;
24300 Fmake_variable_buffer_local (Qfontification_functions
);
24302 DEFVAR_BOOL ("unibyte-display-via-language-environment",
24303 &unibyte_display_via_language_environment
,
24304 doc
: /* *Non-nil means display unibyte text according to language environment.
24305 Specifically this means that unibyte non-ASCII characters
24306 are displayed by converting them to the equivalent multibyte characters
24307 according to the current language environment. As a result, they are
24308 displayed according to the current fontset. */);
24309 unibyte_display_via_language_environment
= 0;
24311 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
24312 doc
: /* *Maximum height for resizing mini-windows.
24313 If a float, it specifies a fraction of the mini-window frame's height.
24314 If an integer, it specifies a number of lines. */);
24315 Vmax_mini_window_height
= make_float (0.25);
24317 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
24318 doc
: /* *How to resize mini-windows.
24319 A value of nil means don't automatically resize mini-windows.
24320 A value of t means resize them to fit the text displayed in them.
24321 A value of `grow-only', the default, means let mini-windows grow
24322 only, until their display becomes empty, at which point the windows
24323 go back to their normal size. */);
24324 Vresize_mini_windows
= Qgrow_only
;
24326 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
24327 doc
: /* Alist specifying how to blink the cursor off.
24328 Each element has the form (ON-STATE . OFF-STATE). Whenever the
24329 `cursor-type' frame-parameter or variable equals ON-STATE,
24330 comparing using `equal', Emacs uses OFF-STATE to specify
24331 how to blink it off. ON-STATE and OFF-STATE are values for
24332 the `cursor-type' frame parameter.
24334 If a frame's ON-STATE has no entry in this list,
24335 the frame's other specifications determine how to blink the cursor off. */);
24336 Vblink_cursor_alist
= Qnil
;
24338 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
24339 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
24340 automatic_hscrolling_p
= 1;
24342 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
24343 doc
: /* *How many columns away from the window edge point is allowed to get
24344 before automatic hscrolling will horizontally scroll the window. */);
24345 hscroll_margin
= 5;
24347 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
24348 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
24349 When point is less than `hscroll-margin' columns from the window
24350 edge, automatic hscrolling will scroll the window by the amount of columns
24351 determined by this variable. If its value is a positive integer, scroll that
24352 many columns. If it's a positive floating-point number, it specifies the
24353 fraction of the window's width to scroll. If it's nil or zero, point will be
24354 centered horizontally after the scroll. Any other value, including negative
24355 numbers, are treated as if the value were zero.
24357 Automatic hscrolling always moves point outside the scroll margin, so if
24358 point was more than scroll step columns inside the margin, the window will
24359 scroll more than the value given by the scroll step.
24361 Note that the lower bound for automatic hscrolling specified by `scroll-left'
24362 and `scroll-right' overrides this variable's effect. */);
24363 Vhscroll_step
= make_number (0);
24365 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
24366 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
24367 Bind this around calls to `message' to let it take effect. */);
24368 message_truncate_lines
= 0;
24370 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
24371 doc
: /* Normal hook run to update the menu bar definitions.
24372 Redisplay runs this hook before it redisplays the menu bar.
24373 This is used to update submenus such as Buffers,
24374 whose contents depend on various data. */);
24375 Vmenu_bar_update_hook
= Qnil
;
24377 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
24378 doc
: /* Frame for which we are updating a menu.
24379 The enable predicate for a menu binding should check this variable. */);
24380 Vmenu_updating_frame
= Qnil
;
24382 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
24383 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
24384 inhibit_menubar_update
= 0;
24386 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
24387 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
24388 inhibit_eval_during_redisplay
= 0;
24390 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
24391 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
24392 inhibit_free_realized_faces
= 0;
24395 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
24396 doc
: /* Inhibit try_window_id display optimization. */);
24397 inhibit_try_window_id
= 0;
24399 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
24400 doc
: /* Inhibit try_window_reusing display optimization. */);
24401 inhibit_try_window_reusing
= 0;
24403 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
24404 doc
: /* Inhibit try_cursor_movement display optimization. */);
24405 inhibit_try_cursor_movement
= 0;
24406 #endif /* GLYPH_DEBUG */
24408 DEFVAR_INT ("overline-margin", &overline_margin
,
24409 doc
: /* *Space between overline and text, in pixels.
24410 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
24411 margin to the caracter height. */);
24412 overline_margin
= 2;
24416 /* Initialize this module when Emacs starts. */
24421 Lisp_Object root_window
;
24422 struct window
*mini_w
;
24424 current_header_line_height
= current_mode_line_height
= -1;
24426 CHARPOS (this_line_start_pos
) = 0;
24428 mini_w
= XWINDOW (minibuf_window
);
24429 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
24431 if (!noninteractive
)
24433 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
24436 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
24437 set_window_height (root_window
,
24438 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
24440 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
24441 set_window_height (minibuf_window
, 1, 0);
24443 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
24444 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
24446 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
24447 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
24448 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
24450 /* The default ellipsis glyphs `...'. */
24451 for (i
= 0; i
< 3; ++i
)
24452 default_invis_vector
[i
] = make_number ('.');
24456 /* Allocate the buffer for frame titles.
24457 Also used for `format-mode-line'. */
24459 mode_line_noprop_buf
= (char *) xmalloc (size
);
24460 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
24461 mode_line_noprop_ptr
= mode_line_noprop_buf
;
24462 mode_line_target
= MODE_LINE_DISPLAY
;
24465 help_echo_showing_p
= 0;
24469 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
24470 (do not change this comment) */