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 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 2, 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
, struct text_pos
*,
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
1703 static struct glyph
*
1704 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1707 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1709 struct glyph
*glyph
, *end
;
1710 struct glyph_row
*row
= NULL
;
1713 /* Find row containing Y. Give up if some row is not enabled. */
1714 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1716 row
= MATRIX_ROW (w
->current_matrix
, i
);
1717 if (!row
->enabled_p
)
1719 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1726 /* Give up if Y is not in the window. */
1727 if (i
== w
->current_matrix
->nrows
)
1730 /* Get the glyph area containing X. */
1731 if (w
->pseudo_window_p
)
1738 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1740 *area
= LEFT_MARGIN_AREA
;
1741 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1743 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1746 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1750 *area
= RIGHT_MARGIN_AREA
;
1751 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1755 /* Find glyph containing X. */
1756 glyph
= row
->glyphs
[*area
];
1757 end
= glyph
+ row
->used
[*area
];
1759 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1761 x
-= glyph
->pixel_width
;
1771 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1774 *hpos
= glyph
- row
->glyphs
[*area
];
1780 Convert frame-relative x/y to coordinates relative to window W.
1781 Takes pseudo-windows into account. */
1784 frame_to_window_pixel_xy (w
, x
, y
)
1788 if (w
->pseudo_window_p
)
1790 /* A pseudo-window is always full-width, and starts at the
1791 left edge of the frame, plus a frame border. */
1792 struct frame
*f
= XFRAME (w
->frame
);
1793 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1794 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1798 *x
-= WINDOW_LEFT_EDGE_X (w
);
1799 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1804 Return in RECTS[] at most N clipping rectangles for glyph string S.
1805 Return the number of stored rectangles. */
1808 get_glyph_string_clip_rects (s
, rects
, n
)
1809 struct glyph_string
*s
;
1810 NativeRectangle
*rects
;
1818 if (s
->row
->full_width_p
)
1820 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1821 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1822 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1824 /* Unless displaying a mode or menu bar line, which are always
1825 fully visible, clip to the visible part of the row. */
1826 if (s
->w
->pseudo_window_p
)
1827 r
.height
= s
->row
->visible_height
;
1829 r
.height
= s
->height
;
1833 /* This is a text line that may be partially visible. */
1834 r
.x
= window_box_left (s
->w
, s
->area
);
1835 r
.width
= window_box_width (s
->w
, s
->area
);
1836 r
.height
= s
->row
->visible_height
;
1840 if (r
.x
< s
->clip_head
->x
)
1842 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1843 r
.width
-= s
->clip_head
->x
- r
.x
;
1846 r
.x
= s
->clip_head
->x
;
1849 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1851 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1852 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1857 /* If S draws overlapping rows, it's sufficient to use the top and
1858 bottom of the window for clipping because this glyph string
1859 intentionally draws over other lines. */
1860 if (s
->for_overlaps
)
1862 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1863 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1865 /* Alas, the above simple strategy does not work for the
1866 environments with anti-aliased text: if the same text is
1867 drawn onto the same place multiple times, it gets thicker.
1868 If the overlap we are processing is for the erased cursor, we
1869 take the intersection with the rectagle of the cursor. */
1870 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1872 XRectangle rc
, r_save
= r
;
1874 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1875 rc
.y
= s
->w
->phys_cursor
.y
;
1876 rc
.width
= s
->w
->phys_cursor_width
;
1877 rc
.height
= s
->w
->phys_cursor_height
;
1879 x_intersect_rectangles (&r_save
, &rc
, &r
);
1884 /* Don't use S->y for clipping because it doesn't take partially
1885 visible lines into account. For example, it can be negative for
1886 partially visible lines at the top of a window. */
1887 if (!s
->row
->full_width_p
1888 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1889 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1891 r
.y
= max (0, s
->row
->y
);
1893 /* If drawing a tool-bar window, draw it over the internal border
1894 at the top of the window. */
1895 if (WINDOWP (s
->f
->tool_bar_window
)
1896 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1897 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1900 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1902 /* If drawing the cursor, don't let glyph draw outside its
1903 advertised boundaries. Cleartype does this under some circumstances. */
1904 if (s
->hl
== DRAW_CURSOR
)
1906 struct glyph
*glyph
= s
->first_glyph
;
1911 r
.width
-= s
->x
- r
.x
;
1914 r
.width
= min (r
.width
, glyph
->pixel_width
);
1916 /* If r.y is below window bottom, ensure that we still see a cursor. */
1917 height
= min (glyph
->ascent
+ glyph
->descent
,
1918 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1919 max_y
= window_text_bottom_y (s
->w
) - height
;
1920 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1921 if (s
->ybase
- glyph
->ascent
> max_y
)
1928 /* Don't draw cursor glyph taller than our actual glyph. */
1929 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1930 if (height
< r
.height
)
1932 max_y
= r
.y
+ r
.height
;
1933 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1934 r
.height
= min (max_y
- r
.y
, height
);
1939 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1940 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1942 #ifdef CONVERT_FROM_XRECT
1943 CONVERT_FROM_XRECT (r
, *rects
);
1951 /* If we are processing overlapping and allowed to return
1952 multiple clipping rectangles, we exclude the row of the glyph
1953 string from the clipping rectangle. This is to avoid drawing
1954 the same text on the environment with anti-aliasing. */
1955 #ifdef CONVERT_FROM_XRECT
1958 XRectangle
*rs
= rects
;
1960 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
1962 if (s
->for_overlaps
& OVERLAPS_PRED
)
1965 if (r
.y
+ r
.height
> row_y
)
1968 rs
[i
].height
= row_y
- r
.y
;
1974 if (s
->for_overlaps
& OVERLAPS_SUCC
)
1977 if (r
.y
< row_y
+ s
->row
->visible_height
)
1979 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
1981 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
1982 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
1991 #ifdef CONVERT_FROM_XRECT
1992 for (i
= 0; i
< n
; i
++)
1993 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2000 Return in *NR the clipping rectangle for glyph string S. */
2003 get_glyph_string_clip_rect (s
, nr
)
2004 struct glyph_string
*s
;
2005 NativeRectangle
*nr
;
2007 get_glyph_string_clip_rects (s
, nr
, 1);
2012 Return the position and height of the phys cursor in window W.
2013 Set w->phys_cursor_width to width of phys cursor.
2017 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2019 struct glyph_row
*row
;
2020 struct glyph
*glyph
;
2021 int *xp
, *yp
, *heightp
;
2023 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2024 int x
, y
, wd
, h
, h0
, y0
;
2026 /* Compute the width of the rectangle to draw. If on a stretch
2027 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2028 rectangle as wide as the glyph, but use a canonical character
2030 wd
= glyph
->pixel_width
- 1;
2035 x
= w
->phys_cursor
.x
;
2042 if (glyph
->type
== STRETCH_GLYPH
2043 && !x_stretch_cursor_p
)
2044 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2045 w
->phys_cursor_width
= wd
;
2047 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2049 /* If y is below window bottom, ensure that we still see a cursor. */
2050 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2052 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2053 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2055 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2058 h
= max (h
- (y0
- y
) + 1, h0
);
2063 y0
= window_text_bottom_y (w
) - h0
;
2071 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2072 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2077 * Remember which glyph the mouse is over.
2081 remember_mouse_glyph (f
, gx
, gy
, rect
)
2084 NativeRectangle
*rect
;
2088 struct glyph_row
*r
, *gr
, *end_row
;
2089 enum window_part part
;
2090 enum glyph_row_area area
;
2091 int x
, y
, width
, height
;
2093 /* Try to determine frame pixel position and size of the glyph under
2094 frame pixel coordinates X/Y on frame F. */
2096 if (!f
->glyphs_initialized_p
2097 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2100 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2101 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2105 w
= XWINDOW (window
);
2106 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2107 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2109 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2110 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2112 if (w
->pseudo_window_p
)
2115 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2121 case ON_LEFT_MARGIN
:
2122 area
= LEFT_MARGIN_AREA
;
2125 case ON_RIGHT_MARGIN
:
2126 area
= RIGHT_MARGIN_AREA
;
2129 case ON_HEADER_LINE
:
2131 gr
= (part
== ON_HEADER_LINE
2132 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2133 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2136 goto text_glyph_row_found
;
2143 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2144 if (r
->y
+ r
->height
> y
)
2150 text_glyph_row_found
:
2153 struct glyph
*g
= gr
->glyphs
[area
];
2154 struct glyph
*end
= g
+ gr
->used
[area
];
2156 height
= gr
->height
;
2157 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2158 if (gx
+ g
->pixel_width
> x
)
2163 if (g
->type
== IMAGE_GLYPH
)
2165 /* Don't remember when mouse is over image, as
2166 image may have hot-spots. */
2167 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2170 width
= g
->pixel_width
;
2174 /* Use nominal char spacing at end of line. */
2176 gx
+= (x
/ width
) * width
;
2179 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2180 gx
+= window_box_left_offset (w
, area
);
2184 /* Use nominal line height at end of window. */
2185 gx
= (x
/ width
) * width
;
2187 gy
+= (y
/ height
) * height
;
2191 case ON_LEFT_FRINGE
:
2192 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2193 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2194 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2195 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2198 case ON_RIGHT_FRINGE
:
2199 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2200 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2201 : window_box_right_offset (w
, TEXT_AREA
));
2202 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2206 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2208 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2209 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2210 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2212 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2216 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2217 if (r
->y
+ r
->height
> y
)
2224 height
= gr
->height
;
2227 /* Use nominal line height at end of window. */
2229 gy
+= (y
/ height
) * height
;
2236 /* If there is no glyph under the mouse, then we divide the screen
2237 into a grid of the smallest glyph in the frame, and use that
2240 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2241 round down even for negative values. */
2247 gx
= (gx
/ width
) * width
;
2248 gy
= (gy
/ height
) * height
;
2253 gx
+= WINDOW_LEFT_EDGE_X (w
);
2254 gy
+= WINDOW_TOP_EDGE_Y (w
);
2257 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2259 /* Visible feedback for debugging. */
2262 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2263 f
->output_data
.x
->normal_gc
,
2264 gx
, gy
, width
, height
);
2270 #endif /* HAVE_WINDOW_SYSTEM */
2273 /***********************************************************************
2274 Lisp form evaluation
2275 ***********************************************************************/
2277 /* Error handler for safe_eval and safe_call. */
2280 safe_eval_handler (arg
)
2283 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2288 /* Evaluate SEXPR and return the result, or nil if something went
2289 wrong. Prevent redisplay during the evaluation. */
2297 if (inhibit_eval_during_redisplay
)
2301 int count
= SPECPDL_INDEX ();
2302 struct gcpro gcpro1
;
2305 specbind (Qinhibit_redisplay
, Qt
);
2306 /* Use Qt to ensure debugger does not run,
2307 so there is no possibility of wanting to redisplay. */
2308 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
2311 val
= unbind_to (count
, val
);
2318 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2319 Return the result, or nil if something went wrong. Prevent
2320 redisplay during the evaluation. */
2323 safe_call (nargs
, args
)
2329 if (inhibit_eval_during_redisplay
)
2333 int count
= SPECPDL_INDEX ();
2334 struct gcpro gcpro1
;
2337 gcpro1
.nvars
= nargs
;
2338 specbind (Qinhibit_redisplay
, Qt
);
2339 /* Use Qt to ensure debugger does not run,
2340 so there is no possibility of wanting to redisplay. */
2341 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2344 val
= unbind_to (count
, val
);
2351 /* Call function FN with one argument ARG.
2352 Return the result, or nil if something went wrong. */
2355 safe_call1 (fn
, arg
)
2356 Lisp_Object fn
, arg
;
2358 Lisp_Object args
[2];
2361 return safe_call (2, args
);
2366 /***********************************************************************
2368 ***********************************************************************/
2372 /* Define CHECK_IT to perform sanity checks on iterators.
2373 This is for debugging. It is too slow to do unconditionally. */
2379 if (it
->method
== GET_FROM_STRING
)
2381 xassert (STRINGP (it
->string
));
2382 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2386 xassert (IT_STRING_CHARPOS (*it
) < 0);
2387 if (it
->method
== GET_FROM_BUFFER
)
2389 /* Check that character and byte positions agree. */
2390 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2395 xassert (it
->current
.dpvec_index
>= 0);
2397 xassert (it
->current
.dpvec_index
< 0);
2400 #define CHECK_IT(IT) check_it ((IT))
2404 #define CHECK_IT(IT) (void) 0
2411 /* Check that the window end of window W is what we expect it
2412 to be---the last row in the current matrix displaying text. */
2415 check_window_end (w
)
2418 if (!MINI_WINDOW_P (w
)
2419 && !NILP (w
->window_end_valid
))
2421 struct glyph_row
*row
;
2422 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2423 XFASTINT (w
->window_end_vpos
)),
2425 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2426 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2430 #define CHECK_WINDOW_END(W) check_window_end ((W))
2432 #else /* not GLYPH_DEBUG */
2434 #define CHECK_WINDOW_END(W) (void) 0
2436 #endif /* not GLYPH_DEBUG */
2440 /***********************************************************************
2441 Iterator initialization
2442 ***********************************************************************/
2444 /* Initialize IT for displaying current_buffer in window W, starting
2445 at character position CHARPOS. CHARPOS < 0 means that no buffer
2446 position is specified which is useful when the iterator is assigned
2447 a position later. BYTEPOS is the byte position corresponding to
2448 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2450 If ROW is not null, calls to produce_glyphs with IT as parameter
2451 will produce glyphs in that row.
2453 BASE_FACE_ID is the id of a base face to use. It must be one of
2454 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2455 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2456 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2458 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2459 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2460 will be initialized to use the corresponding mode line glyph row of
2461 the desired matrix of W. */
2464 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2467 int charpos
, bytepos
;
2468 struct glyph_row
*row
;
2469 enum face_id base_face_id
;
2471 int highlight_region_p
;
2473 /* Some precondition checks. */
2474 xassert (w
!= NULL
&& it
!= NULL
);
2475 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2478 /* If face attributes have been changed since the last redisplay,
2479 free realized faces now because they depend on face definitions
2480 that might have changed. Don't free faces while there might be
2481 desired matrices pending which reference these faces. */
2482 if (face_change_count
&& !inhibit_free_realized_faces
)
2484 face_change_count
= 0;
2485 free_all_realized_faces (Qnil
);
2488 /* Use one of the mode line rows of W's desired matrix if
2492 if (base_face_id
== MODE_LINE_FACE_ID
2493 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2494 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2495 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2496 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2500 bzero (it
, sizeof *it
);
2501 it
->current
.overlay_string_index
= -1;
2502 it
->current
.dpvec_index
= -1;
2503 it
->base_face_id
= base_face_id
;
2505 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2507 /* The window in which we iterate over current_buffer: */
2508 XSETWINDOW (it
->window
, w
);
2510 it
->f
= XFRAME (w
->frame
);
2512 /* Extra space between lines (on window systems only). */
2513 if (base_face_id
== DEFAULT_FACE_ID
2514 && FRAME_WINDOW_P (it
->f
))
2516 if (NATNUMP (current_buffer
->extra_line_spacing
))
2517 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2518 else if (FLOATP (current_buffer
->extra_line_spacing
))
2519 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2520 * FRAME_LINE_HEIGHT (it
->f
));
2521 else if (it
->f
->extra_line_spacing
> 0)
2522 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2523 it
->max_extra_line_spacing
= 0;
2526 /* If realized faces have been removed, e.g. because of face
2527 attribute changes of named faces, recompute them. When running
2528 in batch mode, the face cache of Vterminal_frame is null. If
2529 we happen to get called, make a dummy face cache. */
2530 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2531 init_frame_faces (it
->f
);
2532 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2533 recompute_basic_faces (it
->f
);
2535 /* Current value of the `slice', `space-width', and 'height' properties. */
2536 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2537 it
->space_width
= Qnil
;
2538 it
->font_height
= Qnil
;
2539 it
->override_ascent
= -1;
2541 /* Are control characters displayed as `^C'? */
2542 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2544 /* -1 means everything between a CR and the following line end
2545 is invisible. >0 means lines indented more than this value are
2547 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2548 ? XFASTINT (current_buffer
->selective_display
)
2549 : (!NILP (current_buffer
->selective_display
)
2551 it
->selective_display_ellipsis_p
2552 = !NILP (current_buffer
->selective_display_ellipses
);
2554 /* Display table to use. */
2555 it
->dp
= window_display_table (w
);
2557 /* Are multibyte characters enabled in current_buffer? */
2558 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2560 /* Non-zero if we should highlight the region. */
2562 = (!NILP (Vtransient_mark_mode
)
2563 && !NILP (current_buffer
->mark_active
)
2564 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2566 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2567 start and end of a visible region in window IT->w. Set both to
2568 -1 to indicate no region. */
2569 if (highlight_region_p
2570 /* Maybe highlight only in selected window. */
2571 && (/* Either show region everywhere. */
2572 highlight_nonselected_windows
2573 /* Or show region in the selected window. */
2574 || w
== XWINDOW (selected_window
)
2575 /* Or show the region if we are in the mini-buffer and W is
2576 the window the mini-buffer refers to. */
2577 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2578 && WINDOWP (minibuf_selected_window
)
2579 && w
== XWINDOW (minibuf_selected_window
))))
2581 int charpos
= marker_position (current_buffer
->mark
);
2582 it
->region_beg_charpos
= min (PT
, charpos
);
2583 it
->region_end_charpos
= max (PT
, charpos
);
2586 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2588 /* Get the position at which the redisplay_end_trigger hook should
2589 be run, if it is to be run at all. */
2590 if (MARKERP (w
->redisplay_end_trigger
)
2591 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2592 it
->redisplay_end_trigger_charpos
2593 = marker_position (w
->redisplay_end_trigger
);
2594 else if (INTEGERP (w
->redisplay_end_trigger
))
2595 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2597 /* Correct bogus values of tab_width. */
2598 it
->tab_width
= XINT (current_buffer
->tab_width
);
2599 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2602 /* Are lines in the display truncated? */
2603 it
->truncate_lines_p
2604 = (base_face_id
!= DEFAULT_FACE_ID
2605 || XINT (it
->w
->hscroll
)
2606 || (truncate_partial_width_windows
2607 && !WINDOW_FULL_WIDTH_P (it
->w
))
2608 || !NILP (current_buffer
->truncate_lines
));
2610 /* Get dimensions of truncation and continuation glyphs. These are
2611 displayed as fringe bitmaps under X, so we don't need them for such
2613 if (!FRAME_WINDOW_P (it
->f
))
2615 if (it
->truncate_lines_p
)
2617 /* We will need the truncation glyph. */
2618 xassert (it
->glyph_row
== NULL
);
2619 produce_special_glyphs (it
, IT_TRUNCATION
);
2620 it
->truncation_pixel_width
= it
->pixel_width
;
2624 /* We will need the continuation glyph. */
2625 xassert (it
->glyph_row
== NULL
);
2626 produce_special_glyphs (it
, IT_CONTINUATION
);
2627 it
->continuation_pixel_width
= it
->pixel_width
;
2630 /* Reset these values to zero because the produce_special_glyphs
2631 above has changed them. */
2632 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2633 it
->phys_ascent
= it
->phys_descent
= 0;
2636 /* Set this after getting the dimensions of truncation and
2637 continuation glyphs, so that we don't produce glyphs when calling
2638 produce_special_glyphs, above. */
2639 it
->glyph_row
= row
;
2640 it
->area
= TEXT_AREA
;
2642 /* Get the dimensions of the display area. The display area
2643 consists of the visible window area plus a horizontally scrolled
2644 part to the left of the window. All x-values are relative to the
2645 start of this total display area. */
2646 if (base_face_id
!= DEFAULT_FACE_ID
)
2648 /* Mode lines, menu bar in terminal frames. */
2649 it
->first_visible_x
= 0;
2650 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2655 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2656 it
->last_visible_x
= (it
->first_visible_x
2657 + window_box_width (w
, TEXT_AREA
));
2659 /* If we truncate lines, leave room for the truncator glyph(s) at
2660 the right margin. Otherwise, leave room for the continuation
2661 glyph(s). Truncation and continuation glyphs are not inserted
2662 for window-based redisplay. */
2663 if (!FRAME_WINDOW_P (it
->f
))
2665 if (it
->truncate_lines_p
)
2666 it
->last_visible_x
-= it
->truncation_pixel_width
;
2668 it
->last_visible_x
-= it
->continuation_pixel_width
;
2671 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2672 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2675 /* Leave room for a border glyph. */
2676 if (!FRAME_WINDOW_P (it
->f
)
2677 && !WINDOW_RIGHTMOST_P (it
->w
))
2678 it
->last_visible_x
-= 1;
2680 it
->last_visible_y
= window_text_bottom_y (w
);
2682 /* For mode lines and alike, arrange for the first glyph having a
2683 left box line if the face specifies a box. */
2684 if (base_face_id
!= DEFAULT_FACE_ID
)
2688 it
->face_id
= base_face_id
;
2690 /* If we have a boxed mode line, make the first character appear
2691 with a left box line. */
2692 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2693 if (face
->box
!= FACE_NO_BOX
)
2694 it
->start_of_box_run_p
= 1;
2697 /* If a buffer position was specified, set the iterator there,
2698 getting overlays and face properties from that position. */
2699 if (charpos
>= BUF_BEG (current_buffer
))
2701 it
->end_charpos
= ZV
;
2703 IT_CHARPOS (*it
) = charpos
;
2705 /* Compute byte position if not specified. */
2706 if (bytepos
< charpos
)
2707 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2709 IT_BYTEPOS (*it
) = bytepos
;
2711 it
->start
= it
->current
;
2713 /* Compute faces etc. */
2714 reseat (it
, it
->current
.pos
, 1);
2721 /* Initialize IT for the display of window W with window start POS. */
2724 start_display (it
, w
, pos
)
2727 struct text_pos pos
;
2729 struct glyph_row
*row
;
2730 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2732 row
= w
->desired_matrix
->rows
+ first_vpos
;
2733 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2734 it
->first_vpos
= first_vpos
;
2736 /* Don't reseat to previous visible line start if current start
2737 position is in a string or image. */
2738 if (it
->method
== GET_FROM_BUFFER
&& !it
->truncate_lines_p
)
2740 int start_at_line_beg_p
;
2741 int first_y
= it
->current_y
;
2743 /* If window start is not at a line start, skip forward to POS to
2744 get the correct continuation lines width. */
2745 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2746 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2747 if (!start_at_line_beg_p
)
2751 reseat_at_previous_visible_line_start (it
);
2752 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2754 new_x
= it
->current_x
+ it
->pixel_width
;
2756 /* If lines are continued, this line may end in the middle
2757 of a multi-glyph character (e.g. a control character
2758 displayed as \003, or in the middle of an overlay
2759 string). In this case move_it_to above will not have
2760 taken us to the start of the continuation line but to the
2761 end of the continued line. */
2762 if (it
->current_x
> 0
2763 && !it
->truncate_lines_p
/* Lines are continued. */
2764 && (/* And glyph doesn't fit on the line. */
2765 new_x
> it
->last_visible_x
2766 /* Or it fits exactly and we're on a window
2768 || (new_x
== it
->last_visible_x
2769 && FRAME_WINDOW_P (it
->f
))))
2771 if (it
->current
.dpvec_index
>= 0
2772 || it
->current
.overlay_string_index
>= 0)
2774 set_iterator_to_next (it
, 1);
2775 move_it_in_display_line_to (it
, -1, -1, 0);
2778 it
->continuation_lines_width
+= it
->current_x
;
2781 /* We're starting a new display line, not affected by the
2782 height of the continued line, so clear the appropriate
2783 fields in the iterator structure. */
2784 it
->max_ascent
= it
->max_descent
= 0;
2785 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2787 it
->current_y
= first_y
;
2789 it
->current_x
= it
->hpos
= 0;
2793 #if 0 /* Don't assert the following because start_display is sometimes
2794 called intentionally with a window start that is not at a
2795 line start. Please leave this code in as a comment. */
2797 /* Window start should be on a line start, now. */
2798 xassert (it
->continuation_lines_width
2799 || IT_CHARPOS (it
) == BEGV
2800 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2805 /* Return 1 if POS is a position in ellipses displayed for invisible
2806 text. W is the window we display, for text property lookup. */
2809 in_ellipses_for_invisible_text_p (pos
, w
)
2810 struct display_pos
*pos
;
2813 Lisp_Object prop
, window
;
2815 int charpos
= CHARPOS (pos
->pos
);
2817 /* If POS specifies a position in a display vector, this might
2818 be for an ellipsis displayed for invisible text. We won't
2819 get the iterator set up for delivering that ellipsis unless
2820 we make sure that it gets aware of the invisible text. */
2821 if (pos
->dpvec_index
>= 0
2822 && pos
->overlay_string_index
< 0
2823 && CHARPOS (pos
->string_pos
) < 0
2825 && (XSETWINDOW (window
, w
),
2826 prop
= Fget_char_property (make_number (charpos
),
2827 Qinvisible
, window
),
2828 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2830 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2832 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2839 /* Initialize IT for stepping through current_buffer in window W,
2840 starting at position POS that includes overlay string and display
2841 vector/ control character translation position information. Value
2842 is zero if there are overlay strings with newlines at POS. */
2845 init_from_display_pos (it
, w
, pos
)
2848 struct display_pos
*pos
;
2850 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2851 int i
, overlay_strings_with_newlines
= 0;
2853 /* If POS specifies a position in a display vector, this might
2854 be for an ellipsis displayed for invisible text. We won't
2855 get the iterator set up for delivering that ellipsis unless
2856 we make sure that it gets aware of the invisible text. */
2857 if (in_ellipses_for_invisible_text_p (pos
, w
))
2863 /* Keep in mind: the call to reseat in init_iterator skips invisible
2864 text, so we might end up at a position different from POS. This
2865 is only a problem when POS is a row start after a newline and an
2866 overlay starts there with an after-string, and the overlay has an
2867 invisible property. Since we don't skip invisible text in
2868 display_line and elsewhere immediately after consuming the
2869 newline before the row start, such a POS will not be in a string,
2870 but the call to init_iterator below will move us to the
2872 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2874 /* This only scans the current chunk -- it should scan all chunks.
2875 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2876 to 16 in 22.1 to make this a lesser problem. */
2877 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2879 const char *s
= SDATA (it
->overlay_strings
[i
]);
2880 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2882 while (s
< e
&& *s
!= '\n')
2887 overlay_strings_with_newlines
= 1;
2892 /* If position is within an overlay string, set up IT to the right
2894 if (pos
->overlay_string_index
>= 0)
2898 /* If the first overlay string happens to have a `display'
2899 property for an image, the iterator will be set up for that
2900 image, and we have to undo that setup first before we can
2901 correct the overlay string index. */
2902 if (it
->method
== GET_FROM_IMAGE
)
2905 /* We already have the first chunk of overlay strings in
2906 IT->overlay_strings. Load more until the one for
2907 pos->overlay_string_index is in IT->overlay_strings. */
2908 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2910 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2911 it
->current
.overlay_string_index
= 0;
2914 load_overlay_strings (it
, 0);
2915 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2919 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2920 relative_index
= (it
->current
.overlay_string_index
2921 % OVERLAY_STRING_CHUNK_SIZE
);
2922 it
->string
= it
->overlay_strings
[relative_index
];
2923 xassert (STRINGP (it
->string
));
2924 it
->current
.string_pos
= pos
->string_pos
;
2925 it
->method
= GET_FROM_STRING
;
2928 #if 0 /* This is bogus because POS not having an overlay string
2929 position does not mean it's after the string. Example: A
2930 line starting with a before-string and initialization of IT
2931 to the previous row's end position. */
2932 else if (it
->current
.overlay_string_index
>= 0)
2934 /* If POS says we're already after an overlay string ending at
2935 POS, make sure to pop the iterator because it will be in
2936 front of that overlay string. When POS is ZV, we've thereby
2937 also ``processed'' overlay strings at ZV. */
2940 xassert (it
->current
.overlay_string_index
== -1);
2941 xassert (it
->method
== GET_FROM_BUFFER
);
2942 if (CHARPOS (pos
->pos
) == ZV
)
2943 it
->overlay_strings_at_end_processed_p
= 1;
2947 if (CHARPOS (pos
->string_pos
) >= 0)
2949 /* Recorded position is not in an overlay string, but in another
2950 string. This can only be a string from a `display' property.
2951 IT should already be filled with that string. */
2952 it
->current
.string_pos
= pos
->string_pos
;
2953 xassert (STRINGP (it
->string
));
2956 /* Restore position in display vector translations, control
2957 character translations or ellipses. */
2958 if (pos
->dpvec_index
>= 0)
2960 if (it
->dpvec
== NULL
)
2961 get_next_display_element (it
);
2962 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2963 it
->current
.dpvec_index
= pos
->dpvec_index
;
2967 return !overlay_strings_with_newlines
;
2971 /* Initialize IT for stepping through current_buffer in window W
2972 starting at ROW->start. */
2975 init_to_row_start (it
, w
, row
)
2978 struct glyph_row
*row
;
2980 init_from_display_pos (it
, w
, &row
->start
);
2981 it
->start
= row
->start
;
2982 it
->continuation_lines_width
= row
->continuation_lines_width
;
2987 /* Initialize IT for stepping through current_buffer in window W
2988 starting in the line following ROW, i.e. starting at ROW->end.
2989 Value is zero if there are overlay strings with newlines at ROW's
2993 init_to_row_end (it
, w
, row
)
2996 struct glyph_row
*row
;
3000 if (init_from_display_pos (it
, w
, &row
->end
))
3002 if (row
->continued_p
)
3003 it
->continuation_lines_width
3004 = row
->continuation_lines_width
+ row
->pixel_width
;
3015 /***********************************************************************
3017 ***********************************************************************/
3019 /* Called when IT reaches IT->stop_charpos. Handle text property and
3020 overlay changes. Set IT->stop_charpos to the next position where
3027 enum prop_handled handled
;
3028 int handle_overlay_change_p
;
3032 it
->current
.dpvec_index
= -1;
3033 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3034 it
->ignore_overlay_strings_at_pos_p
= 0;
3036 /* Use face of preceding text for ellipsis (if invisible) */
3037 if (it
->selective_display_ellipsis_p
)
3038 it
->saved_face_id
= it
->face_id
;
3042 handled
= HANDLED_NORMALLY
;
3044 /* Call text property handlers. */
3045 for (p
= it_props
; p
->handler
; ++p
)
3047 handled
= p
->handler (it
);
3049 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3051 else if (handled
== HANDLED_RETURN
)
3053 /* We still want to show before and after strings from
3054 overlays even if the actual buffer text is replaced. */
3055 if (!handle_overlay_change_p
|| it
->sp
> 1)
3057 if (!get_overlay_strings_1 (it
, 0, 0))
3059 it
->ignore_overlay_strings_at_pos_p
= 1;
3060 it
->string_from_display_prop_p
= 0;
3061 handle_overlay_change_p
= 0;
3062 handled
= HANDLED_RECOMPUTE_PROPS
;
3065 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3066 handle_overlay_change_p
= 0;
3069 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3071 /* Don't check for overlay strings below when set to deliver
3072 characters from a display vector. */
3073 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3074 handle_overlay_change_p
= 0;
3076 /* Handle overlay changes. */
3077 if (handle_overlay_change_p
)
3078 handled
= handle_overlay_change (it
);
3080 /* Determine where to stop next. */
3081 if (handled
== HANDLED_NORMALLY
)
3082 compute_stop_pos (it
);
3085 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3089 /* Compute IT->stop_charpos from text property and overlay change
3090 information for IT's current position. */
3093 compute_stop_pos (it
)
3096 register INTERVAL iv
, next_iv
;
3097 Lisp_Object object
, limit
, position
;
3099 /* If nowhere else, stop at the end. */
3100 it
->stop_charpos
= it
->end_charpos
;
3102 if (STRINGP (it
->string
))
3104 /* Strings are usually short, so don't limit the search for
3106 object
= it
->string
;
3108 position
= make_number (IT_STRING_CHARPOS (*it
));
3114 /* If next overlay change is in front of the current stop pos
3115 (which is IT->end_charpos), stop there. Note: value of
3116 next_overlay_change is point-max if no overlay change
3118 charpos
= next_overlay_change (IT_CHARPOS (*it
));
3119 if (charpos
< it
->stop_charpos
)
3120 it
->stop_charpos
= charpos
;
3122 /* If showing the region, we have to stop at the region
3123 start or end because the face might change there. */
3124 if (it
->region_beg_charpos
> 0)
3126 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3127 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3128 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3129 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3132 /* Set up variables for computing the stop position from text
3133 property changes. */
3134 XSETBUFFER (object
, current_buffer
);
3135 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3136 position
= make_number (IT_CHARPOS (*it
));
3140 /* Get the interval containing IT's position. Value is a null
3141 interval if there isn't such an interval. */
3142 iv
= validate_interval_range (object
, &position
, &position
, 0);
3143 if (!NULL_INTERVAL_P (iv
))
3145 Lisp_Object values_here
[LAST_PROP_IDX
];
3148 /* Get properties here. */
3149 for (p
= it_props
; p
->handler
; ++p
)
3150 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3152 /* Look for an interval following iv that has different
3154 for (next_iv
= next_interval (iv
);
3155 (!NULL_INTERVAL_P (next_iv
)
3157 || XFASTINT (limit
) > next_iv
->position
));
3158 next_iv
= next_interval (next_iv
))
3160 for (p
= it_props
; p
->handler
; ++p
)
3162 Lisp_Object new_value
;
3164 new_value
= textget (next_iv
->plist
, *p
->name
);
3165 if (!EQ (values_here
[p
->idx
], new_value
))
3173 if (!NULL_INTERVAL_P (next_iv
))
3175 if (INTEGERP (limit
)
3176 && next_iv
->position
>= XFASTINT (limit
))
3177 /* No text property change up to limit. */
3178 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3180 /* Text properties change in next_iv. */
3181 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3185 xassert (STRINGP (it
->string
)
3186 || (it
->stop_charpos
>= BEGV
3187 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3191 /* Return the position of the next overlay change after POS in
3192 current_buffer. Value is point-max if no overlay change
3193 follows. This is like `next-overlay-change' but doesn't use
3197 next_overlay_change (pos
)
3202 Lisp_Object
*overlays
;
3205 /* Get all overlays at the given position. */
3206 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3208 /* If any of these overlays ends before endpos,
3209 use its ending point instead. */
3210 for (i
= 0; i
< noverlays
; ++i
)
3215 oend
= OVERLAY_END (overlays
[i
]);
3216 oendpos
= OVERLAY_POSITION (oend
);
3217 endpos
= min (endpos
, oendpos
);
3225 /***********************************************************************
3227 ***********************************************************************/
3229 /* Handle changes in the `fontified' property of the current buffer by
3230 calling hook functions from Qfontification_functions to fontify
3233 static enum prop_handled
3234 handle_fontified_prop (it
)
3237 Lisp_Object prop
, pos
;
3238 enum prop_handled handled
= HANDLED_NORMALLY
;
3240 if (!NILP (Vmemory_full
))
3243 /* Get the value of the `fontified' property at IT's current buffer
3244 position. (The `fontified' property doesn't have a special
3245 meaning in strings.) If the value is nil, call functions from
3246 Qfontification_functions. */
3247 if (!STRINGP (it
->string
)
3249 && !NILP (Vfontification_functions
)
3250 && !NILP (Vrun_hooks
)
3251 && (pos
= make_number (IT_CHARPOS (*it
)),
3252 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3253 /* Ignore the special cased nil value always present at EOB since
3254 no amount of fontifying will be able to change it. */
3255 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3257 int count
= SPECPDL_INDEX ();
3260 val
= Vfontification_functions
;
3261 specbind (Qfontification_functions
, Qnil
);
3263 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3264 safe_call1 (val
, pos
);
3267 Lisp_Object globals
, fn
;
3268 struct gcpro gcpro1
, gcpro2
;
3271 GCPRO2 (val
, globals
);
3273 for (; CONSP (val
); val
= XCDR (val
))
3279 /* A value of t indicates this hook has a local
3280 binding; it means to run the global binding too.
3281 In a global value, t should not occur. If it
3282 does, we must ignore it to avoid an endless
3284 for (globals
= Fdefault_value (Qfontification_functions
);
3286 globals
= XCDR (globals
))
3288 fn
= XCAR (globals
);
3290 safe_call1 (fn
, pos
);
3294 safe_call1 (fn
, pos
);
3300 unbind_to (count
, Qnil
);
3302 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3303 something. This avoids an endless loop if they failed to
3304 fontify the text for which reason ever. */
3305 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3306 handled
= HANDLED_RECOMPUTE_PROPS
;
3314 /***********************************************************************
3316 ***********************************************************************/
3318 /* Set up iterator IT from face properties at its current position.
3319 Called from handle_stop. */
3321 static enum prop_handled
3322 handle_face_prop (it
)
3325 int new_face_id
, next_stop
;
3327 if (!STRINGP (it
->string
))
3330 = face_at_buffer_position (it
->w
,
3332 it
->region_beg_charpos
,
3333 it
->region_end_charpos
,
3336 + TEXT_PROP_DISTANCE_LIMIT
),
3339 /* Is this a start of a run of characters with box face?
3340 Caveat: this can be called for a freshly initialized
3341 iterator; face_id is -1 in this case. We know that the new
3342 face will not change until limit, i.e. if the new face has a
3343 box, all characters up to limit will have one. But, as
3344 usual, we don't know whether limit is really the end. */
3345 if (new_face_id
!= it
->face_id
)
3347 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3349 /* If new face has a box but old face has not, this is
3350 the start of a run of characters with box, i.e. it has
3351 a shadow on the left side. The value of face_id of the
3352 iterator will be -1 if this is the initial call that gets
3353 the face. In this case, we have to look in front of IT's
3354 position and see whether there is a face != new_face_id. */
3355 it
->start_of_box_run_p
3356 = (new_face
->box
!= FACE_NO_BOX
3357 && (it
->face_id
>= 0
3358 || IT_CHARPOS (*it
) == BEG
3359 || new_face_id
!= face_before_it_pos (it
)));
3360 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3365 int base_face_id
, bufpos
;
3367 if (it
->current
.overlay_string_index
>= 0)
3368 bufpos
= IT_CHARPOS (*it
);
3372 /* For strings from a buffer, i.e. overlay strings or strings
3373 from a `display' property, use the face at IT's current
3374 buffer position as the base face to merge with, so that
3375 overlay strings appear in the same face as surrounding
3376 text, unless they specify their own faces. */
3377 base_face_id
= underlying_face_id (it
);
3379 new_face_id
= face_at_string_position (it
->w
,
3381 IT_STRING_CHARPOS (*it
),
3383 it
->region_beg_charpos
,
3384 it
->region_end_charpos
,
3388 #if 0 /* This shouldn't be neccessary. Let's check it. */
3389 /* If IT is used to display a mode line we would really like to
3390 use the mode line face instead of the frame's default face. */
3391 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3392 && new_face_id
== DEFAULT_FACE_ID
)
3393 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3396 /* Is this a start of a run of characters with box? Caveat:
3397 this can be called for a freshly allocated iterator; face_id
3398 is -1 is this case. We know that the new face will not
3399 change until the next check pos, i.e. if the new face has a
3400 box, all characters up to that position will have a
3401 box. But, as usual, we don't know whether that position
3402 is really the end. */
3403 if (new_face_id
!= it
->face_id
)
3405 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3406 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3408 /* If new face has a box but old face hasn't, this is the
3409 start of a run of characters with box, i.e. it has a
3410 shadow on the left side. */
3411 it
->start_of_box_run_p
3412 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3413 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3417 it
->face_id
= new_face_id
;
3418 return HANDLED_NORMALLY
;
3422 /* Return the ID of the face ``underlying'' IT's current position,
3423 which is in a string. If the iterator is associated with a
3424 buffer, return the face at IT's current buffer position.
3425 Otherwise, use the iterator's base_face_id. */
3428 underlying_face_id (it
)
3431 int face_id
= it
->base_face_id
, i
;
3433 xassert (STRINGP (it
->string
));
3435 for (i
= it
->sp
- 1; i
>= 0; --i
)
3436 if (NILP (it
->stack
[i
].string
))
3437 face_id
= it
->stack
[i
].face_id
;
3443 /* Compute the face one character before or after the current position
3444 of IT. BEFORE_P non-zero means get the face in front of IT's
3445 position. Value is the id of the face. */
3448 face_before_or_after_it_pos (it
, before_p
)
3453 int next_check_charpos
;
3454 struct text_pos pos
;
3456 xassert (it
->s
== NULL
);
3458 if (STRINGP (it
->string
))
3460 int bufpos
, base_face_id
;
3462 /* No face change past the end of the string (for the case
3463 we are padding with spaces). No face change before the
3465 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3466 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3469 /* Set pos to the position before or after IT's current position. */
3471 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3473 /* For composition, we must check the character after the
3475 pos
= (it
->what
== IT_COMPOSITION
3476 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3477 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3479 if (it
->current
.overlay_string_index
>= 0)
3480 bufpos
= IT_CHARPOS (*it
);
3484 base_face_id
= underlying_face_id (it
);
3486 /* Get the face for ASCII, or unibyte. */
3487 face_id
= face_at_string_position (it
->w
,
3491 it
->region_beg_charpos
,
3492 it
->region_end_charpos
,
3493 &next_check_charpos
,
3496 /* Correct the face for charsets different from ASCII. Do it
3497 for the multibyte case only. The face returned above is
3498 suitable for unibyte text if IT->string is unibyte. */
3499 if (STRING_MULTIBYTE (it
->string
))
3501 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3502 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3504 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3506 c
= string_char_and_length (p
, rest
, &len
);
3507 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3512 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3513 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3516 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3517 pos
= it
->current
.pos
;
3520 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3523 if (it
->what
== IT_COMPOSITION
)
3524 /* For composition, we must check the position after the
3526 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3528 INC_TEXT_POS (pos
, it
->multibyte_p
);
3531 /* Determine face for CHARSET_ASCII, or unibyte. */
3532 face_id
= face_at_buffer_position (it
->w
,
3534 it
->region_beg_charpos
,
3535 it
->region_end_charpos
,
3536 &next_check_charpos
,
3539 /* Correct the face for charsets different from ASCII. Do it
3540 for the multibyte case only. The face returned above is
3541 suitable for unibyte text if current_buffer is unibyte. */
3542 if (it
->multibyte_p
)
3544 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3545 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3546 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3555 /***********************************************************************
3557 ***********************************************************************/
3559 /* Set up iterator IT from invisible properties at its current
3560 position. Called from handle_stop. */
3562 static enum prop_handled
3563 handle_invisible_prop (it
)
3566 enum prop_handled handled
= HANDLED_NORMALLY
;
3568 if (STRINGP (it
->string
))
3570 extern Lisp_Object Qinvisible
;
3571 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3573 /* Get the value of the invisible text property at the
3574 current position. Value will be nil if there is no such
3576 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3577 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3580 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3582 handled
= HANDLED_RECOMPUTE_PROPS
;
3584 /* Get the position at which the next change of the
3585 invisible text property can be found in IT->string.
3586 Value will be nil if the property value is the same for
3587 all the rest of IT->string. */
3588 XSETINT (limit
, SCHARS (it
->string
));
3589 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3592 /* Text at current position is invisible. The next
3593 change in the property is at position end_charpos.
3594 Move IT's current position to that position. */
3595 if (INTEGERP (end_charpos
)
3596 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3598 struct text_pos old
;
3599 old
= it
->current
.string_pos
;
3600 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3601 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3605 /* The rest of the string is invisible. If this is an
3606 overlay string, proceed with the next overlay string
3607 or whatever comes and return a character from there. */
3608 if (it
->current
.overlay_string_index
>= 0)
3610 next_overlay_string (it
);
3611 /* Don't check for overlay strings when we just
3612 finished processing them. */
3613 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3617 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3618 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3625 int invis_p
, newpos
, next_stop
, start_charpos
;
3626 Lisp_Object pos
, prop
, overlay
;
3628 /* First of all, is there invisible text at this position? */
3629 start_charpos
= IT_CHARPOS (*it
);
3630 pos
= make_number (IT_CHARPOS (*it
));
3631 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3633 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3635 /* If we are on invisible text, skip over it. */
3636 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3638 /* Record whether we have to display an ellipsis for the
3640 int display_ellipsis_p
= invis_p
== 2;
3642 handled
= HANDLED_RECOMPUTE_PROPS
;
3644 /* Loop skipping over invisible text. The loop is left at
3645 ZV or with IT on the first char being visible again. */
3648 /* Try to skip some invisible text. Return value is the
3649 position reached which can be equal to IT's position
3650 if there is nothing invisible here. This skips both
3651 over invisible text properties and overlays with
3652 invisible property. */
3653 newpos
= skip_invisible (IT_CHARPOS (*it
),
3654 &next_stop
, ZV
, it
->window
);
3656 /* If we skipped nothing at all we weren't at invisible
3657 text in the first place. If everything to the end of
3658 the buffer was skipped, end the loop. */
3659 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3663 /* We skipped some characters but not necessarily
3664 all there are. Check if we ended up on visible
3665 text. Fget_char_property returns the property of
3666 the char before the given position, i.e. if we
3667 get invis_p = 0, this means that the char at
3668 newpos is visible. */
3669 pos
= make_number (newpos
);
3670 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3671 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3674 /* If we ended up on invisible text, proceed to
3675 skip starting with next_stop. */
3677 IT_CHARPOS (*it
) = next_stop
;
3679 /* If there are adjacent invisible texts, don't lose the
3680 second one's ellipsis. */
3682 display_ellipsis_p
= 1;
3686 /* The position newpos is now either ZV or on visible text. */
3687 IT_CHARPOS (*it
) = newpos
;
3688 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3690 /* If there are before-strings at the start of invisible
3691 text, and the text is invisible because of a text
3692 property, arrange to show before-strings because 20.x did
3693 it that way. (If the text is invisible because of an
3694 overlay property instead of a text property, this is
3695 already handled in the overlay code.) */
3697 && get_overlay_strings (it
, start_charpos
))
3699 handled
= HANDLED_RECOMPUTE_PROPS
;
3700 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3702 else if (display_ellipsis_p
)
3704 /* Make sure that the glyphs of the ellipsis will get
3705 correct `charpos' values. If we would not update
3706 it->position here, the glyphs would belong to the
3707 last visible character _before_ the invisible
3708 text, which confuses `set_cursor_from_row'.
3710 We use the last invisible position instead of the
3711 first because this way the cursor is always drawn on
3712 the first "." of the ellipsis, whenever PT is inside
3713 the invisible text. Otherwise the cursor would be
3714 placed _after_ the ellipsis when the point is after the
3715 first invisible character. */
3716 if (!STRINGP (it
->object
))
3718 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3719 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3721 setup_for_ellipsis (it
, 0);
3730 /* Make iterator IT return `...' next.
3731 Replaces LEN characters from buffer. */
3734 setup_for_ellipsis (it
, len
)
3738 /* Use the display table definition for `...'. Invalid glyphs
3739 will be handled by the method returning elements from dpvec. */
3740 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3742 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3743 it
->dpvec
= v
->contents
;
3744 it
->dpend
= v
->contents
+ v
->size
;
3748 /* Default `...'. */
3749 it
->dpvec
= default_invis_vector
;
3750 it
->dpend
= default_invis_vector
+ 3;
3753 it
->dpvec_char_len
= len
;
3754 it
->current
.dpvec_index
= 0;
3755 it
->dpvec_face_id
= -1;
3757 /* Remember the current face id in case glyphs specify faces.
3758 IT's face is restored in set_iterator_to_next.
3759 saved_face_id was set to preceding char's face in handle_stop. */
3760 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3761 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3763 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3769 /***********************************************************************
3771 ***********************************************************************/
3773 /* Set up iterator IT from `display' property at its current position.
3774 Called from handle_stop.
3775 We return HANDLED_RETURN if some part of the display property
3776 overrides the display of the buffer text itself.
3777 Otherwise we return HANDLED_NORMALLY. */
3779 static enum prop_handled
3780 handle_display_prop (it
)
3783 Lisp_Object prop
, object
;
3784 struct text_pos
*position
;
3785 /* Nonzero if some property replaces the display of the text itself. */
3786 int display_replaced_p
= 0;
3788 if (STRINGP (it
->string
))
3790 object
= it
->string
;
3791 position
= &it
->current
.string_pos
;
3795 XSETWINDOW (object
, it
->w
);
3796 position
= &it
->current
.pos
;
3799 /* Reset those iterator values set from display property values. */
3800 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3801 it
->space_width
= Qnil
;
3802 it
->font_height
= Qnil
;
3805 /* We don't support recursive `display' properties, i.e. string
3806 values that have a string `display' property, that have a string
3807 `display' property etc. */
3808 if (!it
->string_from_display_prop_p
)
3809 it
->area
= TEXT_AREA
;
3811 prop
= Fget_char_property (make_number (position
->charpos
),
3814 return HANDLED_NORMALLY
;
3816 if (!STRINGP (it
->string
))
3817 object
= it
->w
->buffer
;
3820 /* Simple properties. */
3821 && !EQ (XCAR (prop
), Qimage
)
3822 && !EQ (XCAR (prop
), Qspace
)
3823 && !EQ (XCAR (prop
), Qwhen
)
3824 && !EQ (XCAR (prop
), Qslice
)
3825 && !EQ (XCAR (prop
), Qspace_width
)
3826 && !EQ (XCAR (prop
), Qheight
)
3827 && !EQ (XCAR (prop
), Qraise
)
3828 /* Marginal area specifications. */
3829 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3830 && !EQ (XCAR (prop
), Qleft_fringe
)
3831 && !EQ (XCAR (prop
), Qright_fringe
)
3832 && !NILP (XCAR (prop
)))
3834 for (; CONSP (prop
); prop
= XCDR (prop
))
3836 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3837 position
, display_replaced_p
))
3838 display_replaced_p
= 1;
3841 else if (VECTORP (prop
))
3844 for (i
= 0; i
< ASIZE (prop
); ++i
)
3845 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3846 position
, display_replaced_p
))
3847 display_replaced_p
= 1;
3851 int ret
= handle_single_display_spec (it
, prop
, object
, position
, 0);
3852 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3853 return HANDLED_RECOMPUTE_PROPS
;
3855 display_replaced_p
= 1;
3858 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3862 /* Value is the position of the end of the `display' property starting
3863 at START_POS in OBJECT. */
3865 static struct text_pos
3866 display_prop_end (it
, object
, start_pos
)
3869 struct text_pos start_pos
;
3872 struct text_pos end_pos
;
3874 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3875 Qdisplay
, object
, Qnil
);
3876 CHARPOS (end_pos
) = XFASTINT (end
);
3877 if (STRINGP (object
))
3878 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3880 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3886 /* Set up IT from a single `display' specification PROP. OBJECT
3887 is the object in which the `display' property was found. *POSITION
3888 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3889 means that we previously saw a display specification which already
3890 replaced text display with something else, for example an image;
3891 we ignore such properties after the first one has been processed.
3893 If PROP is a `space' or `image' specification, and in some other
3894 cases too, set *POSITION to the position where the `display'
3897 Value is non-zero if something was found which replaces the display
3898 of buffer or string text. Specifically, the value is -1 if that
3899 "something" is "nothing". */
3902 handle_single_display_spec (it
, spec
, object
, position
,
3903 display_replaced_before_p
)
3907 struct text_pos
*position
;
3908 int display_replaced_before_p
;
3911 Lisp_Object location
, value
;
3912 struct text_pos start_pos
, save_pos
;
3915 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3916 If the result is non-nil, use VALUE instead of SPEC. */
3918 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3927 if (!NILP (form
) && !EQ (form
, Qt
))
3929 int count
= SPECPDL_INDEX ();
3930 struct gcpro gcpro1
;
3932 /* Bind `object' to the object having the `display' property, a
3933 buffer or string. Bind `position' to the position in the
3934 object where the property was found, and `buffer-position'
3935 to the current position in the buffer. */
3936 specbind (Qobject
, object
);
3937 specbind (Qposition
, make_number (CHARPOS (*position
)));
3938 specbind (Qbuffer_position
,
3939 make_number (STRINGP (object
)
3940 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3942 form
= safe_eval (form
);
3944 unbind_to (count
, Qnil
);
3950 /* Handle `(height HEIGHT)' specifications. */
3952 && EQ (XCAR (spec
), Qheight
)
3953 && CONSP (XCDR (spec
)))
3955 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3958 it
->font_height
= XCAR (XCDR (spec
));
3959 if (!NILP (it
->font_height
))
3961 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3962 int new_height
= -1;
3964 if (CONSP (it
->font_height
)
3965 && (EQ (XCAR (it
->font_height
), Qplus
)
3966 || EQ (XCAR (it
->font_height
), Qminus
))
3967 && CONSP (XCDR (it
->font_height
))
3968 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3970 /* `(+ N)' or `(- N)' where N is an integer. */
3971 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3972 if (EQ (XCAR (it
->font_height
), Qplus
))
3974 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3976 else if (FUNCTIONP (it
->font_height
))
3978 /* Call function with current height as argument.
3979 Value is the new height. */
3981 height
= safe_call1 (it
->font_height
,
3982 face
->lface
[LFACE_HEIGHT_INDEX
]);
3983 if (NUMBERP (height
))
3984 new_height
= XFLOATINT (height
);
3986 else if (NUMBERP (it
->font_height
))
3988 /* Value is a multiple of the canonical char height. */
3991 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3992 new_height
= (XFLOATINT (it
->font_height
)
3993 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3997 /* Evaluate IT->font_height with `height' bound to the
3998 current specified height to get the new height. */
3999 int count
= SPECPDL_INDEX ();
4001 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4002 value
= safe_eval (it
->font_height
);
4003 unbind_to (count
, Qnil
);
4005 if (NUMBERP (value
))
4006 new_height
= XFLOATINT (value
);
4010 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4016 /* Handle `(space_width WIDTH)'. */
4018 && EQ (XCAR (spec
), Qspace_width
)
4019 && CONSP (XCDR (spec
)))
4021 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4024 value
= XCAR (XCDR (spec
));
4025 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4026 it
->space_width
= value
;
4031 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4033 && EQ (XCAR (spec
), Qslice
))
4037 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4040 if (tem
= XCDR (spec
), CONSP (tem
))
4042 it
->slice
.x
= XCAR (tem
);
4043 if (tem
= XCDR (tem
), CONSP (tem
))
4045 it
->slice
.y
= XCAR (tem
);
4046 if (tem
= XCDR (tem
), CONSP (tem
))
4048 it
->slice
.width
= XCAR (tem
);
4049 if (tem
= XCDR (tem
), CONSP (tem
))
4050 it
->slice
.height
= XCAR (tem
);
4058 /* Handle `(raise FACTOR)'. */
4060 && EQ (XCAR (spec
), Qraise
)
4061 && CONSP (XCDR (spec
)))
4063 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4066 #ifdef HAVE_WINDOW_SYSTEM
4067 value
= XCAR (XCDR (spec
));
4068 if (NUMBERP (value
))
4070 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4071 it
->voffset
= - (XFLOATINT (value
)
4072 * (FONT_HEIGHT (face
->font
)));
4074 #endif /* HAVE_WINDOW_SYSTEM */
4079 /* Don't handle the other kinds of display specifications
4080 inside a string that we got from a `display' property. */
4081 if (it
->string_from_display_prop_p
)
4084 /* Characters having this form of property are not displayed, so
4085 we have to find the end of the property. */
4086 start_pos
= *position
;
4087 *position
= display_prop_end (it
, object
, start_pos
);
4090 /* Stop the scan at that end position--we assume that all
4091 text properties change there. */
4092 it
->stop_charpos
= position
->charpos
;
4094 /* Handle `(left-fringe BITMAP [FACE])'
4095 and `(right-fringe BITMAP [FACE])'. */
4097 && (EQ (XCAR (spec
), Qleft_fringe
)
4098 || EQ (XCAR (spec
), Qright_fringe
))
4099 && CONSP (XCDR (spec
)))
4101 int face_id
= DEFAULT_FACE_ID
;
4104 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4105 /* If we return here, POSITION has been advanced
4106 across the text with this property. */
4109 #ifdef HAVE_WINDOW_SYSTEM
4110 value
= XCAR (XCDR (spec
));
4111 if (!SYMBOLP (value
)
4112 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4113 /* If we return here, POSITION has been advanced
4114 across the text with this property. */
4117 if (CONSP (XCDR (XCDR (spec
))))
4119 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4120 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4121 'A', FRINGE_FACE_ID
, 0);
4126 /* Save current settings of IT so that we can restore them
4127 when we are finished with the glyph property value. */
4129 save_pos
= it
->position
;
4130 it
->position
= *position
;
4132 it
->position
= save_pos
;
4134 it
->area
= TEXT_AREA
;
4135 it
->what
= IT_IMAGE
;
4136 it
->image_id
= -1; /* no image */
4137 it
->position
= start_pos
;
4138 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4139 it
->method
= GET_FROM_IMAGE
;
4140 it
->face_id
= face_id
;
4142 /* Say that we haven't consumed the characters with
4143 `display' property yet. The call to pop_it in
4144 set_iterator_to_next will clean this up. */
4145 *position
= start_pos
;
4147 if (EQ (XCAR (spec
), Qleft_fringe
))
4149 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4150 it
->left_user_fringe_face_id
= face_id
;
4154 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4155 it
->right_user_fringe_face_id
= face_id
;
4157 #endif /* HAVE_WINDOW_SYSTEM */
4161 /* Prepare to handle `((margin left-margin) ...)',
4162 `((margin right-margin) ...)' and `((margin nil) ...)'
4163 prefixes for display specifications. */
4164 location
= Qunbound
;
4165 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4169 value
= XCDR (spec
);
4171 value
= XCAR (value
);
4174 if (EQ (XCAR (tem
), Qmargin
)
4175 && (tem
= XCDR (tem
),
4176 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4178 || EQ (tem
, Qleft_margin
)
4179 || EQ (tem
, Qright_margin
))))
4183 if (EQ (location
, Qunbound
))
4189 /* After this point, VALUE is the property after any
4190 margin prefix has been stripped. It must be a string,
4191 an image specification, or `(space ...)'.
4193 LOCATION specifies where to display: `left-margin',
4194 `right-margin' or nil. */
4196 valid_p
= (STRINGP (value
)
4197 #ifdef HAVE_WINDOW_SYSTEM
4198 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
4199 #endif /* not HAVE_WINDOW_SYSTEM */
4200 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4202 if (valid_p
&& !display_replaced_before_p
)
4204 /* Save current settings of IT so that we can restore them
4205 when we are finished with the glyph property value. */
4206 save_pos
= it
->position
;
4207 it
->position
= *position
;
4209 it
->position
= save_pos
;
4211 if (NILP (location
))
4212 it
->area
= TEXT_AREA
;
4213 else if (EQ (location
, Qleft_margin
))
4214 it
->area
= LEFT_MARGIN_AREA
;
4216 it
->area
= RIGHT_MARGIN_AREA
;
4218 if (STRINGP (value
))
4220 if (SCHARS (value
) == 0)
4223 return -1; /* Replaced by "", i.e. nothing. */
4226 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4227 it
->current
.overlay_string_index
= -1;
4228 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4229 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4230 it
->method
= GET_FROM_STRING
;
4231 it
->stop_charpos
= 0;
4232 it
->string_from_display_prop_p
= 1;
4233 /* Say that we haven't consumed the characters with
4234 `display' property yet. The call to pop_it in
4235 set_iterator_to_next will clean this up. */
4236 *position
= start_pos
;
4238 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4240 it
->method
= GET_FROM_STRETCH
;
4242 *position
= it
->position
= start_pos
;
4244 #ifdef HAVE_WINDOW_SYSTEM
4247 it
->what
= IT_IMAGE
;
4248 it
->image_id
= lookup_image (it
->f
, value
);
4249 it
->position
= start_pos
;
4250 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4251 it
->method
= GET_FROM_IMAGE
;
4253 /* Say that we haven't consumed the characters with
4254 `display' property yet. The call to pop_it in
4255 set_iterator_to_next will clean this up. */
4256 *position
= start_pos
;
4258 #endif /* HAVE_WINDOW_SYSTEM */
4263 /* Invalid property or property not supported. Restore
4264 POSITION to what it was before. */
4265 *position
= start_pos
;
4270 /* Check if SPEC is a display specification value whose text should be
4271 treated as intangible. */
4274 single_display_spec_intangible_p (prop
)
4277 /* Skip over `when FORM'. */
4278 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4292 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4293 we don't need to treat text as intangible. */
4294 if (EQ (XCAR (prop
), Qmargin
))
4302 || EQ (XCAR (prop
), Qleft_margin
)
4303 || EQ (XCAR (prop
), Qright_margin
))
4307 return (CONSP (prop
)
4308 && (EQ (XCAR (prop
), Qimage
)
4309 || EQ (XCAR (prop
), Qspace
)));
4313 /* Check if PROP is a display property value whose text should be
4314 treated as intangible. */
4317 display_prop_intangible_p (prop
)
4321 && CONSP (XCAR (prop
))
4322 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4324 /* A list of sub-properties. */
4325 while (CONSP (prop
))
4327 if (single_display_spec_intangible_p (XCAR (prop
)))
4332 else if (VECTORP (prop
))
4334 /* A vector of sub-properties. */
4336 for (i
= 0; i
< ASIZE (prop
); ++i
)
4337 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4341 return single_display_spec_intangible_p (prop
);
4347 /* Return 1 if PROP is a display sub-property value containing STRING. */
4350 single_display_spec_string_p (prop
, string
)
4351 Lisp_Object prop
, string
;
4353 if (EQ (string
, prop
))
4356 /* Skip over `when FORM'. */
4357 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4366 /* Skip over `margin LOCATION'. */
4367 if (EQ (XCAR (prop
), Qmargin
))
4378 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4382 /* Return 1 if STRING appears in the `display' property PROP. */
4385 display_prop_string_p (prop
, string
)
4386 Lisp_Object prop
, string
;
4389 && CONSP (XCAR (prop
))
4390 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4392 /* A list of sub-properties. */
4393 while (CONSP (prop
))
4395 if (single_display_spec_string_p (XCAR (prop
), string
))
4400 else if (VECTORP (prop
))
4402 /* A vector of sub-properties. */
4404 for (i
= 0; i
< ASIZE (prop
); ++i
)
4405 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4409 return single_display_spec_string_p (prop
, string
);
4415 /* Determine from which buffer position in W's buffer STRING comes
4416 from. AROUND_CHARPOS is an approximate position where it could
4417 be from. Value is the buffer position or 0 if it couldn't be
4420 W's buffer must be current.
4422 This function is necessary because we don't record buffer positions
4423 in glyphs generated from strings (to keep struct glyph small).
4424 This function may only use code that doesn't eval because it is
4425 called asynchronously from note_mouse_highlight. */
4428 string_buffer_position (w
, string
, around_charpos
)
4433 Lisp_Object limit
, prop
, pos
;
4434 const int MAX_DISTANCE
= 1000;
4437 pos
= make_number (around_charpos
);
4438 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4439 while (!found
&& !EQ (pos
, limit
))
4441 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4442 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4445 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4450 pos
= make_number (around_charpos
);
4451 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4452 while (!found
&& !EQ (pos
, limit
))
4454 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4455 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4458 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4463 return found
? XINT (pos
) : 0;
4468 /***********************************************************************
4469 `composition' property
4470 ***********************************************************************/
4472 /* Set up iterator IT from `composition' property at its current
4473 position. Called from handle_stop. */
4475 static enum prop_handled
4476 handle_composition_prop (it
)
4479 Lisp_Object prop
, string
;
4480 int pos
, pos_byte
, end
;
4481 enum prop_handled handled
= HANDLED_NORMALLY
;
4483 if (STRINGP (it
->string
))
4485 pos
= IT_STRING_CHARPOS (*it
);
4486 pos_byte
= IT_STRING_BYTEPOS (*it
);
4487 string
= it
->string
;
4491 pos
= IT_CHARPOS (*it
);
4492 pos_byte
= IT_BYTEPOS (*it
);
4496 /* If there's a valid composition and point is not inside of the
4497 composition (in the case that the composition is from the current
4498 buffer), draw a glyph composed from the composition components. */
4499 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
4500 && COMPOSITION_VALID_P (pos
, end
, prop
)
4501 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
4503 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4507 struct composition
*cmp
= composition_table
[id
];
4509 if (cmp
->glyph_len
== 0)
4512 if (STRINGP (it
->string
))
4514 IT_STRING_CHARPOS (*it
) = end
;
4515 IT_STRING_BYTEPOS (*it
) = string_char_to_byte (it
->string
,
4520 IT_CHARPOS (*it
) = end
;
4521 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (end
);
4523 return HANDLED_RECOMPUTE_PROPS
;
4526 it
->stop_charpos
= end
;
4529 it
->method
= GET_FROM_COMPOSITION
;
4531 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4532 /* For a terminal, draw only the first character of the
4534 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4535 it
->len
= (STRINGP (it
->string
)
4536 ? string_char_to_byte (it
->string
, end
)
4537 : CHAR_TO_BYTE (end
)) - pos_byte
;
4538 handled
= HANDLED_RETURN
;
4547 /***********************************************************************
4549 ***********************************************************************/
4551 /* The following structure is used to record overlay strings for
4552 later sorting in load_overlay_strings. */
4554 struct overlay_entry
4556 Lisp_Object overlay
;
4563 /* Set up iterator IT from overlay strings at its current position.
4564 Called from handle_stop. */
4566 static enum prop_handled
4567 handle_overlay_change (it
)
4570 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4571 return HANDLED_RECOMPUTE_PROPS
;
4573 return HANDLED_NORMALLY
;
4577 /* Set up the next overlay string for delivery by IT, if there is an
4578 overlay string to deliver. Called by set_iterator_to_next when the
4579 end of the current overlay string is reached. If there are more
4580 overlay strings to display, IT->string and
4581 IT->current.overlay_string_index are set appropriately here.
4582 Otherwise IT->string is set to nil. */
4585 next_overlay_string (it
)
4588 ++it
->current
.overlay_string_index
;
4589 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4591 /* No more overlay strings. Restore IT's settings to what
4592 they were before overlay strings were processed, and
4593 continue to deliver from current_buffer. */
4594 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4598 || it
->method
== GET_FROM_COMPOSITION
4599 || (NILP (it
->string
)
4600 && it
->method
== GET_FROM_BUFFER
4601 && it
->stop_charpos
>= BEGV
4602 && it
->stop_charpos
<= it
->end_charpos
));
4603 it
->current
.overlay_string_index
= -1;
4604 it
->n_overlay_strings
= 0;
4606 /* If we're at the end of the buffer, record that we have
4607 processed the overlay strings there already, so that
4608 next_element_from_buffer doesn't try it again. */
4609 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4610 it
->overlay_strings_at_end_processed_p
= 1;
4612 /* If we have to display `...' for invisible text, set
4613 the iterator up for that. */
4614 if (display_ellipsis_p
)
4615 setup_for_ellipsis (it
, 0);
4619 /* There are more overlay strings to process. If
4620 IT->current.overlay_string_index has advanced to a position
4621 where we must load IT->overlay_strings with more strings, do
4623 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4625 if (it
->current
.overlay_string_index
&& i
== 0)
4626 load_overlay_strings (it
, 0);
4628 /* Initialize IT to deliver display elements from the overlay
4630 it
->string
= it
->overlay_strings
[i
];
4631 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4632 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4633 it
->method
= GET_FROM_STRING
;
4634 it
->stop_charpos
= 0;
4641 /* Compare two overlay_entry structures E1 and E2. Used as a
4642 comparison function for qsort in load_overlay_strings. Overlay
4643 strings for the same position are sorted so that
4645 1. All after-strings come in front of before-strings, except
4646 when they come from the same overlay.
4648 2. Within after-strings, strings are sorted so that overlay strings
4649 from overlays with higher priorities come first.
4651 2. Within before-strings, strings are sorted so that overlay
4652 strings from overlays with higher priorities come last.
4654 Value is analogous to strcmp. */
4658 compare_overlay_entries (e1
, e2
)
4661 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4662 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4665 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4667 /* Let after-strings appear in front of before-strings if
4668 they come from different overlays. */
4669 if (EQ (entry1
->overlay
, entry2
->overlay
))
4670 result
= entry1
->after_string_p
? 1 : -1;
4672 result
= entry1
->after_string_p
? -1 : 1;
4674 else if (entry1
->after_string_p
)
4675 /* After-strings sorted in order of decreasing priority. */
4676 result
= entry2
->priority
- entry1
->priority
;
4678 /* Before-strings sorted in order of increasing priority. */
4679 result
= entry1
->priority
- entry2
->priority
;
4685 /* Load the vector IT->overlay_strings with overlay strings from IT's
4686 current buffer position, or from CHARPOS if that is > 0. Set
4687 IT->n_overlays to the total number of overlay strings found.
4689 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4690 a time. On entry into load_overlay_strings,
4691 IT->current.overlay_string_index gives the number of overlay
4692 strings that have already been loaded by previous calls to this
4695 IT->add_overlay_start contains an additional overlay start
4696 position to consider for taking overlay strings from, if non-zero.
4697 This position comes into play when the overlay has an `invisible'
4698 property, and both before and after-strings. When we've skipped to
4699 the end of the overlay, because of its `invisible' property, we
4700 nevertheless want its before-string to appear.
4701 IT->add_overlay_start will contain the overlay start position
4704 Overlay strings are sorted so that after-string strings come in
4705 front of before-string strings. Within before and after-strings,
4706 strings are sorted by overlay priority. See also function
4707 compare_overlay_entries. */
4710 load_overlay_strings (it
, charpos
)
4714 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4715 Lisp_Object overlay
, window
, str
, invisible
;
4716 struct Lisp_Overlay
*ov
;
4719 int n
= 0, i
, j
, invis_p
;
4720 struct overlay_entry
*entries
4721 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4724 charpos
= IT_CHARPOS (*it
);
4726 /* Append the overlay string STRING of overlay OVERLAY to vector
4727 `entries' which has size `size' and currently contains `n'
4728 elements. AFTER_P non-zero means STRING is an after-string of
4730 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4733 Lisp_Object priority; \
4737 int new_size = 2 * size; \
4738 struct overlay_entry *old = entries; \
4740 (struct overlay_entry *) alloca (new_size \
4741 * sizeof *entries); \
4742 bcopy (old, entries, size * sizeof *entries); \
4746 entries[n].string = (STRING); \
4747 entries[n].overlay = (OVERLAY); \
4748 priority = Foverlay_get ((OVERLAY), Qpriority); \
4749 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4750 entries[n].after_string_p = (AFTER_P); \
4755 /* Process overlay before the overlay center. */
4756 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4758 XSETMISC (overlay
, ov
);
4759 xassert (OVERLAYP (overlay
));
4760 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4761 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4766 /* Skip this overlay if it doesn't start or end at IT's current
4768 if (end
!= charpos
&& start
!= charpos
)
4771 /* Skip this overlay if it doesn't apply to IT->w. */
4772 window
= Foverlay_get (overlay
, Qwindow
);
4773 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4776 /* If the text ``under'' the overlay is invisible, both before-
4777 and after-strings from this overlay are visible; start and
4778 end position are indistinguishable. */
4779 invisible
= Foverlay_get (overlay
, Qinvisible
);
4780 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4782 /* If overlay has a non-empty before-string, record it. */
4783 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4784 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4786 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4788 /* If overlay has a non-empty after-string, record it. */
4789 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4790 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4792 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4795 /* Process overlays after the overlay center. */
4796 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4798 XSETMISC (overlay
, ov
);
4799 xassert (OVERLAYP (overlay
));
4800 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4801 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4803 if (start
> charpos
)
4806 /* Skip this overlay if it doesn't start or end at IT's current
4808 if (end
!= charpos
&& start
!= charpos
)
4811 /* Skip this overlay if it doesn't apply to IT->w. */
4812 window
= Foverlay_get (overlay
, Qwindow
);
4813 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4816 /* If the text ``under'' the overlay is invisible, it has a zero
4817 dimension, and both before- and after-strings apply. */
4818 invisible
= Foverlay_get (overlay
, Qinvisible
);
4819 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4821 /* If overlay has a non-empty before-string, record it. */
4822 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4823 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4825 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4827 /* If overlay has a non-empty after-string, record it. */
4828 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4829 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4831 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4834 #undef RECORD_OVERLAY_STRING
4838 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4840 /* Record the total number of strings to process. */
4841 it
->n_overlay_strings
= n
;
4843 /* IT->current.overlay_string_index is the number of overlay strings
4844 that have already been consumed by IT. Copy some of the
4845 remaining overlay strings to IT->overlay_strings. */
4847 j
= it
->current
.overlay_string_index
;
4848 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4849 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4855 /* Get the first chunk of overlay strings at IT's current buffer
4856 position, or at CHARPOS if that is > 0. Value is non-zero if at
4857 least one overlay string was found. */
4860 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
4864 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4865 process. This fills IT->overlay_strings with strings, and sets
4866 IT->n_overlay_strings to the total number of strings to process.
4867 IT->pos.overlay_string_index has to be set temporarily to zero
4868 because load_overlay_strings needs this; it must be set to -1
4869 when no overlay strings are found because a zero value would
4870 indicate a position in the first overlay string. */
4871 it
->current
.overlay_string_index
= 0;
4872 load_overlay_strings (it
, charpos
);
4874 /* If we found overlay strings, set up IT to deliver display
4875 elements from the first one. Otherwise set up IT to deliver
4876 from current_buffer. */
4877 if (it
->n_overlay_strings
)
4879 /* Make sure we know settings in current_buffer, so that we can
4880 restore meaningful values when we're done with the overlay
4883 compute_stop_pos (it
);
4884 xassert (it
->face_id
>= 0);
4886 /* Save IT's settings. They are restored after all overlay
4887 strings have been processed. */
4888 xassert (!compute_stop_p
|| it
->sp
== 0);
4891 /* Set up IT to deliver display elements from the first overlay
4893 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4894 it
->string
= it
->overlay_strings
[0];
4895 it
->stop_charpos
= 0;
4896 xassert (STRINGP (it
->string
));
4897 it
->end_charpos
= SCHARS (it
->string
);
4898 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4899 it
->method
= GET_FROM_STRING
;
4903 it
->current
.overlay_string_index
= -1;
4908 get_overlay_strings (it
, charpos
)
4913 it
->method
= GET_FROM_BUFFER
;
4915 (void) get_overlay_strings_1 (it
, charpos
, 1);
4919 /* Value is non-zero if we found at least one overlay string. */
4920 return STRINGP (it
->string
);
4925 /***********************************************************************
4926 Saving and restoring state
4927 ***********************************************************************/
4929 /* Save current settings of IT on IT->stack. Called, for example,
4930 before setting up IT for an overlay string, to be able to restore
4931 IT's settings to what they were after the overlay string has been
4938 struct iterator_stack_entry
*p
;
4940 xassert (it
->sp
< IT_STACK_SIZE
);
4941 p
= it
->stack
+ it
->sp
;
4943 p
->stop_charpos
= it
->stop_charpos
;
4944 xassert (it
->face_id
>= 0);
4945 p
->face_id
= it
->face_id
;
4946 p
->string
= it
->string
;
4947 p
->method
= it
->method
;
4950 case GET_FROM_IMAGE
:
4951 p
->u
.image
.object
= it
->object
;
4952 p
->u
.image
.image_id
= it
->image_id
;
4953 p
->u
.image
.slice
= it
->slice
;
4955 case GET_FROM_COMPOSITION
:
4956 p
->u
.comp
.object
= it
->object
;
4957 p
->u
.comp
.c
= it
->c
;
4958 p
->u
.comp
.len
= it
->len
;
4959 p
->u
.comp
.cmp_id
= it
->cmp_id
;
4960 p
->u
.comp
.cmp_len
= it
->cmp_len
;
4962 case GET_FROM_STRETCH
:
4963 p
->u
.stretch
.object
= it
->object
;
4966 p
->position
= it
->position
;
4967 p
->current
= it
->current
;
4968 p
->end_charpos
= it
->end_charpos
;
4969 p
->string_nchars
= it
->string_nchars
;
4971 p
->multibyte_p
= it
->multibyte_p
;
4972 p
->space_width
= it
->space_width
;
4973 p
->font_height
= it
->font_height
;
4974 p
->voffset
= it
->voffset
;
4975 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4976 p
->display_ellipsis_p
= 0;
4981 /* Restore IT's settings from IT->stack. Called, for example, when no
4982 more overlay strings must be processed, and we return to delivering
4983 display elements from a buffer, or when the end of a string from a
4984 `display' property is reached and we return to delivering display
4985 elements from an overlay string, or from a buffer. */
4991 struct iterator_stack_entry
*p
;
4993 xassert (it
->sp
> 0);
4995 p
= it
->stack
+ it
->sp
;
4996 it
->stop_charpos
= p
->stop_charpos
;
4997 it
->face_id
= p
->face_id
;
4998 it
->current
= p
->current
;
4999 it
->position
= p
->position
;
5000 it
->string
= p
->string
;
5001 if (NILP (it
->string
))
5002 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5003 it
->method
= p
->method
;
5006 case GET_FROM_IMAGE
:
5007 it
->image_id
= p
->u
.image
.image_id
;
5008 it
->object
= p
->u
.image
.object
;
5009 it
->slice
= p
->u
.image
.slice
;
5011 case GET_FROM_COMPOSITION
:
5012 it
->object
= p
->u
.comp
.object
;
5013 it
->c
= p
->u
.comp
.c
;
5014 it
->len
= p
->u
.comp
.len
;
5015 it
->cmp_id
= p
->u
.comp
.cmp_id
;
5016 it
->cmp_len
= p
->u
.comp
.cmp_len
;
5018 case GET_FROM_STRETCH
:
5019 it
->object
= p
->u
.comp
.object
;
5021 case GET_FROM_BUFFER
:
5022 it
->object
= it
->w
->buffer
;
5024 case GET_FROM_STRING
:
5025 it
->object
= it
->string
;
5028 it
->end_charpos
= p
->end_charpos
;
5029 it
->string_nchars
= p
->string_nchars
;
5031 it
->multibyte_p
= p
->multibyte_p
;
5032 it
->space_width
= p
->space_width
;
5033 it
->font_height
= p
->font_height
;
5034 it
->voffset
= p
->voffset
;
5035 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5040 /***********************************************************************
5042 ***********************************************************************/
5044 /* Set IT's current position to the previous line start. */
5047 back_to_previous_line_start (it
)
5050 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5051 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5055 /* Move IT to the next line start.
5057 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5058 we skipped over part of the text (as opposed to moving the iterator
5059 continuously over the text). Otherwise, don't change the value
5062 Newlines may come from buffer text, overlay strings, or strings
5063 displayed via the `display' property. That's the reason we can't
5064 simply use find_next_newline_no_quit.
5066 Note that this function may not skip over invisible text that is so
5067 because of text properties and immediately follows a newline. If
5068 it would, function reseat_at_next_visible_line_start, when called
5069 from set_iterator_to_next, would effectively make invisible
5070 characters following a newline part of the wrong glyph row, which
5071 leads to wrong cursor motion. */
5074 forward_to_next_line_start (it
, skipped_p
)
5078 int old_selective
, newline_found_p
, n
;
5079 const int MAX_NEWLINE_DISTANCE
= 500;
5081 /* If already on a newline, just consume it to avoid unintended
5082 skipping over invisible text below. */
5083 if (it
->what
== IT_CHARACTER
5085 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5087 set_iterator_to_next (it
, 0);
5092 /* Don't handle selective display in the following. It's (a)
5093 unnecessary because it's done by the caller, and (b) leads to an
5094 infinite recursion because next_element_from_ellipsis indirectly
5095 calls this function. */
5096 old_selective
= it
->selective
;
5099 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5100 from buffer text. */
5101 for (n
= newline_found_p
= 0;
5102 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5103 n
+= STRINGP (it
->string
) ? 0 : 1)
5105 if (!get_next_display_element (it
))
5107 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5108 set_iterator_to_next (it
, 0);
5111 /* If we didn't find a newline near enough, see if we can use a
5113 if (!newline_found_p
)
5115 int start
= IT_CHARPOS (*it
);
5116 int limit
= find_next_newline_no_quit (start
, 1);
5119 xassert (!STRINGP (it
->string
));
5121 /* If there isn't any `display' property in sight, and no
5122 overlays, we can just use the position of the newline in
5124 if (it
->stop_charpos
>= limit
5125 || ((pos
= Fnext_single_property_change (make_number (start
),
5127 Qnil
, make_number (limit
)),
5129 && next_overlay_change (start
) == ZV
))
5131 IT_CHARPOS (*it
) = limit
;
5132 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5133 *skipped_p
= newline_found_p
= 1;
5137 while (get_next_display_element (it
)
5138 && !newline_found_p
)
5140 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5141 set_iterator_to_next (it
, 0);
5146 it
->selective
= old_selective
;
5147 return newline_found_p
;
5151 /* Set IT's current position to the previous visible line start. Skip
5152 invisible text that is so either due to text properties or due to
5153 selective display. Caution: this does not change IT->current_x and
5157 back_to_previous_visible_line_start (it
)
5160 while (IT_CHARPOS (*it
) > BEGV
)
5162 back_to_previous_line_start (it
);
5164 if (IT_CHARPOS (*it
) <= BEGV
)
5167 /* If selective > 0, then lines indented more than that values
5169 if (it
->selective
> 0
5170 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5171 (double) it
->selective
)) /* iftc */
5174 /* Check the newline before point for invisibility. */
5177 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5178 Qinvisible
, it
->window
);
5179 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5183 if (IT_CHARPOS (*it
) <= BEGV
)
5190 Lisp_Object val
, overlay
;
5192 /* If newline is part of a composition, continue from start of composition */
5193 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5194 && beg
< IT_CHARPOS (*it
))
5197 /* If newline is replaced by a display property, find start of overlay
5198 or interval and continue search from that point. */
5200 pos
= --IT_CHARPOS (it2
);
5203 if (handle_display_prop (&it2
) == HANDLED_RETURN
5204 && !NILP (val
= get_char_property_and_overlay
5205 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5206 && (OVERLAYP (overlay
)
5207 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5208 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5211 /* Newline is not replaced by anything -- so we are done. */
5217 IT_CHARPOS (*it
) = beg
;
5218 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5222 it
->continuation_lines_width
= 0;
5224 xassert (IT_CHARPOS (*it
) >= BEGV
);
5225 xassert (IT_CHARPOS (*it
) == BEGV
5226 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5231 /* Reseat iterator IT at the previous visible line start. Skip
5232 invisible text that is so either due to text properties or due to
5233 selective display. At the end, update IT's overlay information,
5234 face information etc. */
5237 reseat_at_previous_visible_line_start (it
)
5240 back_to_previous_visible_line_start (it
);
5241 reseat (it
, it
->current
.pos
, 1);
5246 /* Reseat iterator IT on the next visible line start in the current
5247 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5248 preceding the line start. Skip over invisible text that is so
5249 because of selective display. Compute faces, overlays etc at the
5250 new position. Note that this function does not skip over text that
5251 is invisible because of text properties. */
5254 reseat_at_next_visible_line_start (it
, on_newline_p
)
5258 int newline_found_p
, skipped_p
= 0;
5260 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5262 /* Skip over lines that are invisible because they are indented
5263 more than the value of IT->selective. */
5264 if (it
->selective
> 0)
5265 while (IT_CHARPOS (*it
) < ZV
5266 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5267 (double) it
->selective
)) /* iftc */
5269 xassert (IT_BYTEPOS (*it
) == BEGV
5270 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5271 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5274 /* Position on the newline if that's what's requested. */
5275 if (on_newline_p
&& newline_found_p
)
5277 if (STRINGP (it
->string
))
5279 if (IT_STRING_CHARPOS (*it
) > 0)
5281 --IT_STRING_CHARPOS (*it
);
5282 --IT_STRING_BYTEPOS (*it
);
5285 else if (IT_CHARPOS (*it
) > BEGV
)
5289 reseat (it
, it
->current
.pos
, 0);
5293 reseat (it
, it
->current
.pos
, 0);
5300 /***********************************************************************
5301 Changing an iterator's position
5302 ***********************************************************************/
5304 /* Change IT's current position to POS in current_buffer. If FORCE_P
5305 is non-zero, always check for text properties at the new position.
5306 Otherwise, text properties are only looked up if POS >=
5307 IT->check_charpos of a property. */
5310 reseat (it
, pos
, force_p
)
5312 struct text_pos pos
;
5315 int original_pos
= IT_CHARPOS (*it
);
5317 reseat_1 (it
, pos
, 0);
5319 /* Determine where to check text properties. Avoid doing it
5320 where possible because text property lookup is very expensive. */
5322 || CHARPOS (pos
) > it
->stop_charpos
5323 || CHARPOS (pos
) < original_pos
)
5330 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5331 IT->stop_pos to POS, also. */
5334 reseat_1 (it
, pos
, set_stop_p
)
5336 struct text_pos pos
;
5339 /* Don't call this function when scanning a C string. */
5340 xassert (it
->s
== NULL
);
5342 /* POS must be a reasonable value. */
5343 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5345 it
->current
.pos
= it
->position
= pos
;
5346 it
->end_charpos
= ZV
;
5348 it
->current
.dpvec_index
= -1;
5349 it
->current
.overlay_string_index
= -1;
5350 IT_STRING_CHARPOS (*it
) = -1;
5351 IT_STRING_BYTEPOS (*it
) = -1;
5353 it
->method
= GET_FROM_BUFFER
;
5354 it
->object
= it
->w
->buffer
;
5355 it
->area
= TEXT_AREA
;
5356 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5358 it
->string_from_display_prop_p
= 0;
5359 it
->face_before_selective_p
= 0;
5362 it
->stop_charpos
= CHARPOS (pos
);
5366 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5367 If S is non-null, it is a C string to iterate over. Otherwise,
5368 STRING gives a Lisp string to iterate over.
5370 If PRECISION > 0, don't return more then PRECISION number of
5371 characters from the string.
5373 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5374 characters have been returned. FIELD_WIDTH < 0 means an infinite
5377 MULTIBYTE = 0 means disable processing of multibyte characters,
5378 MULTIBYTE > 0 means enable it,
5379 MULTIBYTE < 0 means use IT->multibyte_p.
5381 IT must be initialized via a prior call to init_iterator before
5382 calling this function. */
5385 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5390 int precision
, field_width
, multibyte
;
5392 /* No region in strings. */
5393 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5395 /* No text property checks performed by default, but see below. */
5396 it
->stop_charpos
= -1;
5398 /* Set iterator position and end position. */
5399 bzero (&it
->current
, sizeof it
->current
);
5400 it
->current
.overlay_string_index
= -1;
5401 it
->current
.dpvec_index
= -1;
5402 xassert (charpos
>= 0);
5404 /* If STRING is specified, use its multibyteness, otherwise use the
5405 setting of MULTIBYTE, if specified. */
5407 it
->multibyte_p
= multibyte
> 0;
5411 xassert (STRINGP (string
));
5412 it
->string
= string
;
5414 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5415 it
->method
= GET_FROM_STRING
;
5416 it
->current
.string_pos
= string_pos (charpos
, string
);
5423 /* Note that we use IT->current.pos, not it->current.string_pos,
5424 for displaying C strings. */
5425 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5426 if (it
->multibyte_p
)
5428 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5429 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5433 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5434 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5437 it
->method
= GET_FROM_C_STRING
;
5440 /* PRECISION > 0 means don't return more than PRECISION characters
5442 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5443 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5445 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5446 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5447 FIELD_WIDTH < 0 means infinite field width. This is useful for
5448 padding with `-' at the end of a mode line. */
5449 if (field_width
< 0)
5450 field_width
= INFINITY
;
5451 if (field_width
> it
->end_charpos
- charpos
)
5452 it
->end_charpos
= charpos
+ field_width
;
5454 /* Use the standard display table for displaying strings. */
5455 if (DISP_TABLE_P (Vstandard_display_table
))
5456 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5458 it
->stop_charpos
= charpos
;
5464 /***********************************************************************
5466 ***********************************************************************/
5468 /* Map enum it_method value to corresponding next_element_from_* function. */
5470 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5472 next_element_from_buffer
,
5473 next_element_from_display_vector
,
5474 next_element_from_composition
,
5475 next_element_from_string
,
5476 next_element_from_c_string
,
5477 next_element_from_image
,
5478 next_element_from_stretch
5482 /* Load IT's display element fields with information about the next
5483 display element from the current position of IT. Value is zero if
5484 end of buffer (or C string) is reached. */
5486 static struct frame
*last_escape_glyph_frame
= NULL
;
5487 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5488 static int last_escape_glyph_merged_face_id
= 0;
5491 get_next_display_element (it
)
5494 /* Non-zero means that we found a display element. Zero means that
5495 we hit the end of what we iterate over. Performance note: the
5496 function pointer `method' used here turns out to be faster than
5497 using a sequence of if-statements. */
5501 success_p
= (*get_next_element
[it
->method
]) (it
);
5503 if (it
->what
== IT_CHARACTER
)
5505 /* Map via display table or translate control characters.
5506 IT->c, IT->len etc. have been set to the next character by
5507 the function call above. If we have a display table, and it
5508 contains an entry for IT->c, translate it. Don't do this if
5509 IT->c itself comes from a display table, otherwise we could
5510 end up in an infinite recursion. (An alternative could be to
5511 count the recursion depth of this function and signal an
5512 error when a certain maximum depth is reached.) Is it worth
5514 if (success_p
&& it
->dpvec
== NULL
)
5519 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5522 struct Lisp_Vector
*v
= XVECTOR (dv
);
5524 /* Return the first character from the display table
5525 entry, if not empty. If empty, don't display the
5526 current character. */
5529 it
->dpvec_char_len
= it
->len
;
5530 it
->dpvec
= v
->contents
;
5531 it
->dpend
= v
->contents
+ v
->size
;
5532 it
->current
.dpvec_index
= 0;
5533 it
->dpvec_face_id
= -1;
5534 it
->saved_face_id
= it
->face_id
;
5535 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5540 set_iterator_to_next (it
, 0);
5545 /* Translate control characters into `\003' or `^C' form.
5546 Control characters coming from a display table entry are
5547 currently not translated because we use IT->dpvec to hold
5548 the translation. This could easily be changed but I
5549 don't believe that it is worth doing.
5551 If it->multibyte_p is nonzero, eight-bit characters and
5552 non-printable multibyte characters are also translated to
5555 If it->multibyte_p is zero, eight-bit characters that
5556 don't have corresponding multibyte char code are also
5557 translated to octal form. */
5558 else if ((it
->c
< ' '
5559 && (it
->area
!= TEXT_AREA
5560 /* In mode line, treat \n like other crl chars. */
5562 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5563 || (it
->c
!= '\n' && it
->c
!= '\t')))
5567 || !CHAR_PRINTABLE_P (it
->c
)
5568 || (!NILP (Vnobreak_char_display
)
5569 && (it
->c
== 0x8a0 || it
->c
== 0x8ad
5570 || it
->c
== 0x920 || it
->c
== 0x92d
5571 || it
->c
== 0xe20 || it
->c
== 0xe2d
5572 || it
->c
== 0xf20 || it
->c
== 0xf2d)))
5574 && (!unibyte_display_via_language_environment
5575 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
5577 /* IT->c is a control character which must be displayed
5578 either as '\003' or as `^C' where the '\\' and '^'
5579 can be defined in the display table. Fill
5580 IT->ctl_chars with glyphs for what we have to
5581 display. Then, set IT->dpvec to these glyphs. */
5584 int face_id
, lface_id
= 0 ;
5587 /* Handle control characters with ^. */
5589 if (it
->c
< 128 && it
->ctl_arrow_p
)
5591 g
= '^'; /* default glyph for Control */
5592 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5594 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5595 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5597 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5598 lface_id
= FAST_GLYPH_FACE (g
);
5602 g
= FAST_GLYPH_CHAR (g
);
5603 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5606 else if (it
->f
== last_escape_glyph_frame
5607 && it
->face_id
== last_escape_glyph_face_id
)
5609 face_id
= last_escape_glyph_merged_face_id
;
5613 /* Merge the escape-glyph face into the current face. */
5614 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5616 last_escape_glyph_frame
= it
->f
;
5617 last_escape_glyph_face_id
= it
->face_id
;
5618 last_escape_glyph_merged_face_id
= face_id
;
5621 XSETINT (it
->ctl_chars
[0], g
);
5623 XSETINT (it
->ctl_chars
[1], g
);
5625 goto display_control
;
5628 /* Handle non-break space in the mode where it only gets
5631 if (EQ (Vnobreak_char_display
, Qt
)
5632 && (it
->c
== 0x8a0 || it
->c
== 0x920
5633 || it
->c
== 0xe20 || it
->c
== 0xf20))
5635 /* Merge the no-break-space face into the current face. */
5636 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5640 XSETINT (it
->ctl_chars
[0], g
);
5642 goto display_control
;
5645 /* Handle sequences that start with the "escape glyph". */
5647 /* the default escape glyph is \. */
5648 escape_glyph
= '\\';
5651 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5652 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5654 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5655 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5659 /* The display table specified a face.
5660 Merge it into face_id and also into escape_glyph. */
5661 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5662 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5665 else if (it
->f
== last_escape_glyph_frame
5666 && it
->face_id
== last_escape_glyph_face_id
)
5668 face_id
= last_escape_glyph_merged_face_id
;
5672 /* Merge the escape-glyph face into the current face. */
5673 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5675 last_escape_glyph_frame
= it
->f
;
5676 last_escape_glyph_face_id
= it
->face_id
;
5677 last_escape_glyph_merged_face_id
= face_id
;
5680 /* Handle soft hyphens in the mode where they only get
5683 if (EQ (Vnobreak_char_display
, Qt
)
5684 && (it
->c
== 0x8ad || it
->c
== 0x92d
5685 || it
->c
== 0xe2d || it
->c
== 0xf2d))
5688 XSETINT (it
->ctl_chars
[0], g
);
5690 goto display_control
;
5693 /* Handle non-break space and soft hyphen
5694 with the escape glyph. */
5696 if (it
->c
== 0x8a0 || it
->c
== 0x8ad
5697 || it
->c
== 0x920 || it
->c
== 0x92d
5698 || it
->c
== 0xe20 || it
->c
== 0xe2d
5699 || it
->c
== 0xf20 || it
->c
== 0xf2d)
5701 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5702 g
= it
->c
= ((it
->c
& 0xf) == 0 ? ' ' : '-');
5703 XSETINT (it
->ctl_chars
[1], g
);
5705 goto display_control
;
5709 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5713 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5714 if (SINGLE_BYTE_CHAR_P (it
->c
))
5715 str
[0] = it
->c
, len
= 1;
5718 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5721 /* It's an invalid character, which shouldn't
5722 happen actually, but due to bugs it may
5723 happen. Let's print the char as is, there's
5724 not much meaningful we can do with it. */
5726 str
[1] = it
->c
>> 8;
5727 str
[2] = it
->c
>> 16;
5728 str
[3] = it
->c
>> 24;
5733 for (i
= 0; i
< len
; i
++)
5735 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5736 /* Insert three more glyphs into IT->ctl_chars for
5737 the octal display of the character. */
5738 g
= ((str
[i
] >> 6) & 7) + '0';
5739 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5740 g
= ((str
[i
] >> 3) & 7) + '0';
5741 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5742 g
= (str
[i
] & 7) + '0';
5743 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5749 /* Set up IT->dpvec and return first character from it. */
5750 it
->dpvec_char_len
= it
->len
;
5751 it
->dpvec
= it
->ctl_chars
;
5752 it
->dpend
= it
->dpvec
+ ctl_len
;
5753 it
->current
.dpvec_index
= 0;
5754 it
->dpvec_face_id
= face_id
;
5755 it
->saved_face_id
= it
->face_id
;
5756 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5762 /* Adjust face id for a multibyte character. There are no
5763 multibyte character in unibyte text. */
5766 && FRAME_WINDOW_P (it
->f
))
5768 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5769 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5773 /* Is this character the last one of a run of characters with
5774 box? If yes, set IT->end_of_box_run_p to 1. */
5781 it
->end_of_box_run_p
5782 = ((face_id
= face_after_it_pos (it
),
5783 face_id
!= it
->face_id
)
5784 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5785 face
->box
== FACE_NO_BOX
));
5788 /* Value is 0 if end of buffer or string reached. */
5793 /* Move IT to the next display element.
5795 RESEAT_P non-zero means if called on a newline in buffer text,
5796 skip to the next visible line start.
5798 Functions get_next_display_element and set_iterator_to_next are
5799 separate because I find this arrangement easier to handle than a
5800 get_next_display_element function that also increments IT's
5801 position. The way it is we can first look at an iterator's current
5802 display element, decide whether it fits on a line, and if it does,
5803 increment the iterator position. The other way around we probably
5804 would either need a flag indicating whether the iterator has to be
5805 incremented the next time, or we would have to implement a
5806 decrement position function which would not be easy to write. */
5809 set_iterator_to_next (it
, reseat_p
)
5813 /* Reset flags indicating start and end of a sequence of characters
5814 with box. Reset them at the start of this function because
5815 moving the iterator to a new position might set them. */
5816 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5820 case GET_FROM_BUFFER
:
5821 /* The current display element of IT is a character from
5822 current_buffer. Advance in the buffer, and maybe skip over
5823 invisible lines that are so because of selective display. */
5824 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5825 reseat_at_next_visible_line_start (it
, 0);
5828 xassert (it
->len
!= 0);
5829 IT_BYTEPOS (*it
) += it
->len
;
5830 IT_CHARPOS (*it
) += 1;
5831 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5835 case GET_FROM_COMPOSITION
:
5836 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5837 xassert (it
->sp
> 0);
5839 if (it
->method
== GET_FROM_STRING
)
5841 IT_STRING_BYTEPOS (*it
) += it
->len
;
5842 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5843 goto consider_string_end
;
5845 else if (it
->method
== GET_FROM_BUFFER
)
5847 IT_BYTEPOS (*it
) += it
->len
;
5848 IT_CHARPOS (*it
) += it
->cmp_len
;
5852 case GET_FROM_C_STRING
:
5853 /* Current display element of IT is from a C string. */
5854 IT_BYTEPOS (*it
) += it
->len
;
5855 IT_CHARPOS (*it
) += 1;
5858 case GET_FROM_DISPLAY_VECTOR
:
5859 /* Current display element of IT is from a display table entry.
5860 Advance in the display table definition. Reset it to null if
5861 end reached, and continue with characters from buffers/
5863 ++it
->current
.dpvec_index
;
5865 /* Restore face of the iterator to what they were before the
5866 display vector entry (these entries may contain faces). */
5867 it
->face_id
= it
->saved_face_id
;
5869 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5871 int recheck_faces
= it
->ellipsis_p
;
5874 it
->method
= GET_FROM_C_STRING
;
5875 else if (STRINGP (it
->string
))
5876 it
->method
= GET_FROM_STRING
;
5879 it
->method
= GET_FROM_BUFFER
;
5880 it
->object
= it
->w
->buffer
;
5884 it
->current
.dpvec_index
= -1;
5886 /* Skip over characters which were displayed via IT->dpvec. */
5887 if (it
->dpvec_char_len
< 0)
5888 reseat_at_next_visible_line_start (it
, 1);
5889 else if (it
->dpvec_char_len
> 0)
5891 if (it
->method
== GET_FROM_STRING
5892 && it
->n_overlay_strings
> 0)
5893 it
->ignore_overlay_strings_at_pos_p
= 1;
5894 it
->len
= it
->dpvec_char_len
;
5895 set_iterator_to_next (it
, reseat_p
);
5898 /* Maybe recheck faces after display vector */
5900 it
->stop_charpos
= IT_CHARPOS (*it
);
5904 case GET_FROM_STRING
:
5905 /* Current display element is a character from a Lisp string. */
5906 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5907 IT_STRING_BYTEPOS (*it
) += it
->len
;
5908 IT_STRING_CHARPOS (*it
) += 1;
5910 consider_string_end
:
5912 if (it
->current
.overlay_string_index
>= 0)
5914 /* IT->string is an overlay string. Advance to the
5915 next, if there is one. */
5916 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5917 next_overlay_string (it
);
5921 /* IT->string is not an overlay string. If we reached
5922 its end, and there is something on IT->stack, proceed
5923 with what is on the stack. This can be either another
5924 string, this time an overlay string, or a buffer. */
5925 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5929 if (it
->method
== GET_FROM_STRING
)
5930 goto consider_string_end
;
5935 case GET_FROM_IMAGE
:
5936 case GET_FROM_STRETCH
:
5937 /* The position etc with which we have to proceed are on
5938 the stack. The position may be at the end of a string,
5939 if the `display' property takes up the whole string. */
5940 xassert (it
->sp
> 0);
5942 if (it
->method
== GET_FROM_STRING
)
5943 goto consider_string_end
;
5947 /* There are no other methods defined, so this should be a bug. */
5951 xassert (it
->method
!= GET_FROM_STRING
5952 || (STRINGP (it
->string
)
5953 && IT_STRING_CHARPOS (*it
) >= 0));
5956 /* Load IT's display element fields with information about the next
5957 display element which comes from a display table entry or from the
5958 result of translating a control character to one of the forms `^C'
5961 IT->dpvec holds the glyphs to return as characters.
5962 IT->saved_face_id holds the face id before the display vector--
5963 it is restored into IT->face_idin set_iterator_to_next. */
5966 next_element_from_display_vector (it
)
5970 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5972 it
->face_id
= it
->saved_face_id
;
5974 if (INTEGERP (*it
->dpvec
)
5975 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5979 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5980 it
->c
= FAST_GLYPH_CHAR (g
);
5981 it
->len
= CHAR_BYTES (it
->c
);
5983 /* The entry may contain a face id to use. Such a face id is
5984 the id of a Lisp face, not a realized face. A face id of
5985 zero means no face is specified. */
5986 if (it
->dpvec_face_id
>= 0)
5987 it
->face_id
= it
->dpvec_face_id
;
5990 int lface_id
= FAST_GLYPH_FACE (g
);
5992 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5997 /* Display table entry is invalid. Return a space. */
5998 it
->c
= ' ', it
->len
= 1;
6000 /* Don't change position and object of the iterator here. They are
6001 still the values of the character that had this display table
6002 entry or was translated, and that's what we want. */
6003 it
->what
= IT_CHARACTER
;
6008 /* Load IT with the next display element from Lisp string IT->string.
6009 IT->current.string_pos is the current position within the string.
6010 If IT->current.overlay_string_index >= 0, the Lisp string is an
6014 next_element_from_string (it
)
6017 struct text_pos position
;
6019 xassert (STRINGP (it
->string
));
6020 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6021 position
= it
->current
.string_pos
;
6023 /* Time to check for invisible text? */
6024 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6025 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6029 /* Since a handler may have changed IT->method, we must
6031 return get_next_display_element (it
);
6034 if (it
->current
.overlay_string_index
>= 0)
6036 /* Get the next character from an overlay string. In overlay
6037 strings, There is no field width or padding with spaces to
6039 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6044 else if (STRING_MULTIBYTE (it
->string
))
6046 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6047 const unsigned char *s
= (SDATA (it
->string
)
6048 + IT_STRING_BYTEPOS (*it
));
6049 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
6053 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6059 /* Get the next character from a Lisp string that is not an
6060 overlay string. Such strings come from the mode line, for
6061 example. We may have to pad with spaces, or truncate the
6062 string. See also next_element_from_c_string. */
6063 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6068 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6070 /* Pad with spaces. */
6071 it
->c
= ' ', it
->len
= 1;
6072 CHARPOS (position
) = BYTEPOS (position
) = -1;
6074 else if (STRING_MULTIBYTE (it
->string
))
6076 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6077 const unsigned char *s
= (SDATA (it
->string
)
6078 + IT_STRING_BYTEPOS (*it
));
6079 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
6083 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6088 /* Record what we have and where it came from. */
6089 it
->what
= IT_CHARACTER
;
6090 it
->object
= it
->string
;
6091 it
->position
= position
;
6096 /* Load IT with next display element from C string IT->s.
6097 IT->string_nchars is the maximum number of characters to return
6098 from the string. IT->end_charpos may be greater than
6099 IT->string_nchars when this function is called, in which case we
6100 may have to return padding spaces. Value is zero if end of string
6101 reached, including padding spaces. */
6104 next_element_from_c_string (it
)
6110 it
->what
= IT_CHARACTER
;
6111 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6114 /* IT's position can be greater IT->string_nchars in case a field
6115 width or precision has been specified when the iterator was
6117 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6119 /* End of the game. */
6123 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6125 /* Pad with spaces. */
6126 it
->c
= ' ', it
->len
= 1;
6127 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6129 else if (it
->multibyte_p
)
6131 /* Implementation note: The calls to strlen apparently aren't a
6132 performance problem because there is no noticeable performance
6133 difference between Emacs running in unibyte or multibyte mode. */
6134 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6135 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
6139 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6145 /* Set up IT to return characters from an ellipsis, if appropriate.
6146 The definition of the ellipsis glyphs may come from a display table
6147 entry. This function Fills IT with the first glyph from the
6148 ellipsis if an ellipsis is to be displayed. */
6151 next_element_from_ellipsis (it
)
6154 if (it
->selective_display_ellipsis_p
)
6155 setup_for_ellipsis (it
, it
->len
);
6158 /* The face at the current position may be different from the
6159 face we find after the invisible text. Remember what it
6160 was in IT->saved_face_id, and signal that it's there by
6161 setting face_before_selective_p. */
6162 it
->saved_face_id
= it
->face_id
;
6163 it
->method
= GET_FROM_BUFFER
;
6164 it
->object
= it
->w
->buffer
;
6165 reseat_at_next_visible_line_start (it
, 1);
6166 it
->face_before_selective_p
= 1;
6169 return get_next_display_element (it
);
6173 /* Deliver an image display element. The iterator IT is already
6174 filled with image information (done in handle_display_prop). Value
6179 next_element_from_image (it
)
6182 it
->what
= IT_IMAGE
;
6187 /* Fill iterator IT with next display element from a stretch glyph
6188 property. IT->object is the value of the text property. Value is
6192 next_element_from_stretch (it
)
6195 it
->what
= IT_STRETCH
;
6200 /* Load IT with the next display element from current_buffer. Value
6201 is zero if end of buffer reached. IT->stop_charpos is the next
6202 position at which to stop and check for text properties or buffer
6206 next_element_from_buffer (it
)
6211 /* Check this assumption, otherwise, we would never enter the
6212 if-statement, below. */
6213 xassert (IT_CHARPOS (*it
) >= BEGV
6214 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
6216 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6218 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6220 int overlay_strings_follow_p
;
6222 /* End of the game, except when overlay strings follow that
6223 haven't been returned yet. */
6224 if (it
->overlay_strings_at_end_processed_p
)
6225 overlay_strings_follow_p
= 0;
6228 it
->overlay_strings_at_end_processed_p
= 1;
6229 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6232 if (overlay_strings_follow_p
)
6233 success_p
= get_next_display_element (it
);
6237 it
->position
= it
->current
.pos
;
6244 return get_next_display_element (it
);
6249 /* No face changes, overlays etc. in sight, so just return a
6250 character from current_buffer. */
6253 /* Maybe run the redisplay end trigger hook. Performance note:
6254 This doesn't seem to cost measurable time. */
6255 if (it
->redisplay_end_trigger_charpos
6257 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6258 run_redisplay_end_trigger_hook (it
);
6260 /* Get the next character, maybe multibyte. */
6261 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6262 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6264 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
6265 - IT_BYTEPOS (*it
));
6266 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
6269 it
->c
= *p
, it
->len
= 1;
6271 /* Record what we have and where it came from. */
6272 it
->what
= IT_CHARACTER
;;
6273 it
->object
= it
->w
->buffer
;
6274 it
->position
= it
->current
.pos
;
6276 /* Normally we return the character found above, except when we
6277 really want to return an ellipsis for selective display. */
6282 /* A value of selective > 0 means hide lines indented more
6283 than that number of columns. */
6284 if (it
->selective
> 0
6285 && IT_CHARPOS (*it
) + 1 < ZV
6286 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6287 IT_BYTEPOS (*it
) + 1,
6288 (double) it
->selective
)) /* iftc */
6290 success_p
= next_element_from_ellipsis (it
);
6291 it
->dpvec_char_len
= -1;
6294 else if (it
->c
== '\r' && it
->selective
== -1)
6296 /* A value of selective == -1 means that everything from the
6297 CR to the end of the line is invisible, with maybe an
6298 ellipsis displayed for it. */
6299 success_p
= next_element_from_ellipsis (it
);
6300 it
->dpvec_char_len
= -1;
6305 /* Value is zero if end of buffer reached. */
6306 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6311 /* Run the redisplay end trigger hook for IT. */
6314 run_redisplay_end_trigger_hook (it
)
6317 Lisp_Object args
[3];
6319 /* IT->glyph_row should be non-null, i.e. we should be actually
6320 displaying something, or otherwise we should not run the hook. */
6321 xassert (it
->glyph_row
);
6323 /* Set up hook arguments. */
6324 args
[0] = Qredisplay_end_trigger_functions
;
6325 args
[1] = it
->window
;
6326 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6327 it
->redisplay_end_trigger_charpos
= 0;
6329 /* Since we are *trying* to run these functions, don't try to run
6330 them again, even if they get an error. */
6331 it
->w
->redisplay_end_trigger
= Qnil
;
6332 Frun_hook_with_args (3, args
);
6334 /* Notice if it changed the face of the character we are on. */
6335 handle_face_prop (it
);
6339 /* Deliver a composition display element. The iterator IT is already
6340 filled with composition information (done in
6341 handle_composition_prop). Value is always 1. */
6344 next_element_from_composition (it
)
6347 it
->what
= IT_COMPOSITION
;
6348 it
->position
= (STRINGP (it
->string
)
6349 ? it
->current
.string_pos
6351 if (STRINGP (it
->string
))
6352 it
->object
= it
->string
;
6354 it
->object
= it
->w
->buffer
;
6360 /***********************************************************************
6361 Moving an iterator without producing glyphs
6362 ***********************************************************************/
6364 /* Check if iterator is at a position corresponding to a valid buffer
6365 position after some move_it_ call. */
6367 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6368 ((it)->method == GET_FROM_STRING \
6369 ? IT_STRING_CHARPOS (*it) == 0 \
6373 /* Move iterator IT to a specified buffer or X position within one
6374 line on the display without producing glyphs.
6376 OP should be a bit mask including some or all of these bits:
6377 MOVE_TO_X: Stop on reaching x-position TO_X.
6378 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6379 Regardless of OP's value, stop in reaching the end of the display line.
6381 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6382 This means, in particular, that TO_X includes window's horizontal
6385 The return value has several possible values that
6386 say what condition caused the scan to stop:
6388 MOVE_POS_MATCH_OR_ZV
6389 - when TO_POS or ZV was reached.
6392 -when TO_X was reached before TO_POS or ZV were reached.
6395 - when we reached the end of the display area and the line must
6399 - when we reached the end of the display area and the line is
6403 - when we stopped at a line end, i.e. a newline or a CR and selective
6406 static enum move_it_result
6407 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
6409 int to_charpos
, to_x
, op
;
6411 enum move_it_result result
= MOVE_UNDEFINED
;
6412 struct glyph_row
*saved_glyph_row
;
6414 /* Don't produce glyphs in produce_glyphs. */
6415 saved_glyph_row
= it
->glyph_row
;
6416 it
->glyph_row
= NULL
;
6418 #define BUFFER_POS_REACHED_P() \
6419 ((op & MOVE_TO_POS) != 0 \
6420 && BUFFERP (it->object) \
6421 && IT_CHARPOS (*it) >= to_charpos \
6422 && (it->method == GET_FROM_BUFFER \
6423 || (it->method == GET_FROM_DISPLAY_VECTOR \
6424 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6429 int x
, i
, ascent
= 0, descent
= 0;
6431 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
6432 if ((op
& MOVE_TO_POS
) != 0
6433 && BUFFERP (it
->object
)
6434 && it
->method
== GET_FROM_BUFFER
6435 && IT_CHARPOS (*it
) > to_charpos
)
6437 result
= MOVE_POS_MATCH_OR_ZV
;
6441 /* Stop when ZV reached.
6442 We used to stop here when TO_CHARPOS reached as well, but that is
6443 too soon if this glyph does not fit on this line. So we handle it
6444 explicitly below. */
6445 if (!get_next_display_element (it
)
6446 || (it
->truncate_lines_p
6447 && BUFFER_POS_REACHED_P ()))
6449 result
= MOVE_POS_MATCH_OR_ZV
;
6453 /* The call to produce_glyphs will get the metrics of the
6454 display element IT is loaded with. We record in x the
6455 x-position before this display element in case it does not
6459 /* Remember the line height so far in case the next element doesn't
6461 if (!it
->truncate_lines_p
)
6463 ascent
= it
->max_ascent
;
6464 descent
= it
->max_descent
;
6467 PRODUCE_GLYPHS (it
);
6469 if (it
->area
!= TEXT_AREA
)
6471 set_iterator_to_next (it
, 1);
6475 /* The number of glyphs we get back in IT->nglyphs will normally
6476 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6477 character on a terminal frame, or (iii) a line end. For the
6478 second case, IT->nglyphs - 1 padding glyphs will be present
6479 (on X frames, there is only one glyph produced for a
6480 composite character.
6482 The behavior implemented below means, for continuation lines,
6483 that as many spaces of a TAB as fit on the current line are
6484 displayed there. For terminal frames, as many glyphs of a
6485 multi-glyph character are displayed in the current line, too.
6486 This is what the old redisplay code did, and we keep it that
6487 way. Under X, the whole shape of a complex character must
6488 fit on the line or it will be completely displayed in the
6491 Note that both for tabs and padding glyphs, all glyphs have
6495 /* More than one glyph or glyph doesn't fit on line. All
6496 glyphs have the same width. */
6497 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6499 int x_before_this_char
= x
;
6500 int hpos_before_this_char
= it
->hpos
;
6502 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6504 new_x
= x
+ single_glyph_width
;
6506 /* We want to leave anything reaching TO_X to the caller. */
6507 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6509 if (BUFFER_POS_REACHED_P ())
6510 goto buffer_pos_reached
;
6512 result
= MOVE_X_REACHED
;
6515 else if (/* Lines are continued. */
6516 !it
->truncate_lines_p
6517 && (/* And glyph doesn't fit on the line. */
6518 new_x
> it
->last_visible_x
6519 /* Or it fits exactly and we're on a window
6521 || (new_x
== it
->last_visible_x
6522 && FRAME_WINDOW_P (it
->f
))))
6524 if (/* IT->hpos == 0 means the very first glyph
6525 doesn't fit on the line, e.g. a wide image. */
6527 || (new_x
== it
->last_visible_x
6528 && FRAME_WINDOW_P (it
->f
)))
6531 it
->current_x
= new_x
;
6533 /* The character's last glyph just barely fits
6535 if (i
== it
->nglyphs
- 1)
6537 /* If this is the destination position,
6538 return a position *before* it in this row,
6539 now that we know it fits in this row. */
6540 if (BUFFER_POS_REACHED_P ())
6542 it
->hpos
= hpos_before_this_char
;
6543 it
->current_x
= x_before_this_char
;
6544 result
= MOVE_POS_MATCH_OR_ZV
;
6548 set_iterator_to_next (it
, 1);
6549 #ifdef HAVE_WINDOW_SYSTEM
6550 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6552 if (!get_next_display_element (it
))
6554 result
= MOVE_POS_MATCH_OR_ZV
;
6557 if (BUFFER_POS_REACHED_P ())
6559 if (ITERATOR_AT_END_OF_LINE_P (it
))
6560 result
= MOVE_POS_MATCH_OR_ZV
;
6562 result
= MOVE_LINE_CONTINUED
;
6565 if (ITERATOR_AT_END_OF_LINE_P (it
))
6567 result
= MOVE_NEWLINE_OR_CR
;
6571 #endif /* HAVE_WINDOW_SYSTEM */
6577 it
->max_ascent
= ascent
;
6578 it
->max_descent
= descent
;
6581 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6583 result
= MOVE_LINE_CONTINUED
;
6586 else if (BUFFER_POS_REACHED_P ())
6587 goto buffer_pos_reached
;
6588 else if (new_x
> it
->first_visible_x
)
6590 /* Glyph is visible. Increment number of glyphs that
6591 would be displayed. */
6596 /* Glyph is completely off the left margin of the display
6597 area. Nothing to do. */
6601 if (result
!= MOVE_UNDEFINED
)
6604 else if (BUFFER_POS_REACHED_P ())
6608 it
->max_ascent
= ascent
;
6609 it
->max_descent
= descent
;
6610 result
= MOVE_POS_MATCH_OR_ZV
;
6613 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6615 /* Stop when TO_X specified and reached. This check is
6616 necessary here because of lines consisting of a line end,
6617 only. The line end will not produce any glyphs and we
6618 would never get MOVE_X_REACHED. */
6619 xassert (it
->nglyphs
== 0);
6620 result
= MOVE_X_REACHED
;
6624 /* Is this a line end? If yes, we're done. */
6625 if (ITERATOR_AT_END_OF_LINE_P (it
))
6627 result
= MOVE_NEWLINE_OR_CR
;
6631 /* The current display element has been consumed. Advance
6633 set_iterator_to_next (it
, 1);
6635 /* Stop if lines are truncated and IT's current x-position is
6636 past the right edge of the window now. */
6637 if (it
->truncate_lines_p
6638 && it
->current_x
>= it
->last_visible_x
)
6640 #ifdef HAVE_WINDOW_SYSTEM
6641 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6643 if (!get_next_display_element (it
)
6644 || BUFFER_POS_REACHED_P ())
6646 result
= MOVE_POS_MATCH_OR_ZV
;
6649 if (ITERATOR_AT_END_OF_LINE_P (it
))
6651 result
= MOVE_NEWLINE_OR_CR
;
6655 #endif /* HAVE_WINDOW_SYSTEM */
6656 result
= MOVE_LINE_TRUNCATED
;
6661 #undef BUFFER_POS_REACHED_P
6663 /* Restore the iterator settings altered at the beginning of this
6665 it
->glyph_row
= saved_glyph_row
;
6670 /* Move IT forward until it satisfies one or more of the criteria in
6671 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6673 OP is a bit-mask that specifies where to stop, and in particular,
6674 which of those four position arguments makes a difference. See the
6675 description of enum move_operation_enum.
6677 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6678 screen line, this function will set IT to the next position >
6682 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6684 int to_charpos
, to_x
, to_y
, to_vpos
;
6687 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6693 if (op
& MOVE_TO_VPOS
)
6695 /* If no TO_CHARPOS and no TO_X specified, stop at the
6696 start of the line TO_VPOS. */
6697 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6699 if (it
->vpos
== to_vpos
)
6705 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6709 /* TO_VPOS >= 0 means stop at TO_X in the line at
6710 TO_VPOS, or at TO_POS, whichever comes first. */
6711 if (it
->vpos
== to_vpos
)
6717 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6719 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6724 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6726 /* We have reached TO_X but not in the line we want. */
6727 skip
= move_it_in_display_line_to (it
, to_charpos
,
6729 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6737 else if (op
& MOVE_TO_Y
)
6739 struct it it_backup
;
6741 /* TO_Y specified means stop at TO_X in the line containing
6742 TO_Y---or at TO_CHARPOS if this is reached first. The
6743 problem is that we can't really tell whether the line
6744 contains TO_Y before we have completely scanned it, and
6745 this may skip past TO_X. What we do is to first scan to
6748 If TO_X is not specified, use a TO_X of zero. The reason
6749 is to make the outcome of this function more predictable.
6750 If we didn't use TO_X == 0, we would stop at the end of
6751 the line which is probably not what a caller would expect
6753 skip
= move_it_in_display_line_to (it
, to_charpos
,
6757 | (op
& MOVE_TO_POS
)));
6759 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6760 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6766 /* If TO_X was reached, we would like to know whether TO_Y
6767 is in the line. This can only be said if we know the
6768 total line height which requires us to scan the rest of
6770 if (skip
== MOVE_X_REACHED
)
6773 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6774 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6776 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6779 /* Now, decide whether TO_Y is in this line. */
6780 line_height
= it
->max_ascent
+ it
->max_descent
;
6781 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6783 if (to_y
>= it
->current_y
6784 && to_y
< it
->current_y
+ line_height
)
6786 if (skip
== MOVE_X_REACHED
)
6787 /* If TO_Y is in this line and TO_X was reached above,
6788 we scanned too far. We have to restore IT's settings
6789 to the ones before skipping. */
6793 else if (skip
== MOVE_X_REACHED
)
6796 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6803 else if (BUFFERP (it
->object
)
6804 && it
->method
== GET_FROM_BUFFER
6805 && IT_CHARPOS (*it
) >= to_charpos
)
6806 skip
= MOVE_POS_MATCH_OR_ZV
;
6808 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6812 case MOVE_POS_MATCH_OR_ZV
:
6816 case MOVE_NEWLINE_OR_CR
:
6817 set_iterator_to_next (it
, 1);
6818 it
->continuation_lines_width
= 0;
6821 case MOVE_LINE_TRUNCATED
:
6822 it
->continuation_lines_width
= 0;
6823 reseat_at_next_visible_line_start (it
, 0);
6824 if ((op
& MOVE_TO_POS
) != 0
6825 && IT_CHARPOS (*it
) > to_charpos
)
6832 case MOVE_LINE_CONTINUED
:
6833 /* For continued lines ending in a tab, some of the glyphs
6834 associated with the tab are displayed on the current
6835 line. Since it->current_x does not include these glyphs,
6836 we use it->last_visible_x instead. */
6837 it
->continuation_lines_width
+=
6838 (it
->c
== '\t') ? it
->last_visible_x
: it
->current_x
;
6845 /* Reset/increment for the next run. */
6846 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6847 it
->current_x
= it
->hpos
= 0;
6848 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6850 last_height
= it
->max_ascent
+ it
->max_descent
;
6851 last_max_ascent
= it
->max_ascent
;
6852 it
->max_ascent
= it
->max_descent
= 0;
6857 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6861 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6863 If DY > 0, move IT backward at least that many pixels. DY = 0
6864 means move IT backward to the preceding line start or BEGV. This
6865 function may move over more than DY pixels if IT->current_y - DY
6866 ends up in the middle of a line; in this case IT->current_y will be
6867 set to the top of the line moved to. */
6870 move_it_vertically_backward (it
, dy
)
6881 start_pos
= IT_CHARPOS (*it
);
6883 /* Estimate how many newlines we must move back. */
6884 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6886 /* Set the iterator's position that many lines back. */
6887 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6888 back_to_previous_visible_line_start (it
);
6890 /* Reseat the iterator here. When moving backward, we don't want
6891 reseat to skip forward over invisible text, set up the iterator
6892 to deliver from overlay strings at the new position etc. So,
6893 use reseat_1 here. */
6894 reseat_1 (it
, it
->current
.pos
, 1);
6896 /* We are now surely at a line start. */
6897 it
->current_x
= it
->hpos
= 0;
6898 it
->continuation_lines_width
= 0;
6900 /* Move forward and see what y-distance we moved. First move to the
6901 start of the next line so that we get its height. We need this
6902 height to be able to tell whether we reached the specified
6905 it2
.max_ascent
= it2
.max_descent
= 0;
6908 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6909 MOVE_TO_POS
| MOVE_TO_VPOS
);
6911 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
6912 xassert (IT_CHARPOS (*it
) >= BEGV
);
6915 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6916 xassert (IT_CHARPOS (*it
) >= BEGV
);
6917 /* H is the actual vertical distance from the position in *IT
6918 and the starting position. */
6919 h
= it2
.current_y
- it
->current_y
;
6920 /* NLINES is the distance in number of lines. */
6921 nlines
= it2
.vpos
- it
->vpos
;
6923 /* Correct IT's y and vpos position
6924 so that they are relative to the starting point. */
6930 /* DY == 0 means move to the start of the screen line. The
6931 value of nlines is > 0 if continuation lines were involved. */
6933 move_it_by_lines (it
, nlines
, 1);
6935 /* I think this assert is bogus if buffer contains
6936 invisible text or images. KFS. */
6937 xassert (IT_CHARPOS (*it
) <= start_pos
);
6942 /* The y-position we try to reach, relative to *IT.
6943 Note that H has been subtracted in front of the if-statement. */
6944 int target_y
= it
->current_y
+ h
- dy
;
6945 int y0
= it3
.current_y
;
6946 int y1
= line_bottom_y (&it3
);
6947 int line_height
= y1
- y0
;
6949 /* If we did not reach target_y, try to move further backward if
6950 we can. If we moved too far backward, try to move forward. */
6951 if (target_y
< it
->current_y
6952 /* This is heuristic. In a window that's 3 lines high, with
6953 a line height of 13 pixels each, recentering with point
6954 on the bottom line will try to move -39/2 = 19 pixels
6955 backward. Try to avoid moving into the first line. */
6956 && (it
->current_y
- target_y
6957 > min (window_box_height (it
->w
), line_height
* 2 / 3))
6958 && IT_CHARPOS (*it
) > BEGV
)
6960 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6961 target_y
- it
->current_y
));
6962 dy
= it
->current_y
- target_y
;
6963 goto move_further_back
;
6965 else if (target_y
>= it
->current_y
+ line_height
6966 && IT_CHARPOS (*it
) < ZV
)
6968 /* Should move forward by at least one line, maybe more.
6970 Note: Calling move_it_by_lines can be expensive on
6971 terminal frames, where compute_motion is used (via
6972 vmotion) to do the job, when there are very long lines
6973 and truncate-lines is nil. That's the reason for
6974 treating terminal frames specially here. */
6976 if (!FRAME_WINDOW_P (it
->f
))
6977 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6982 move_it_by_lines (it
, 1, 1);
6984 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6988 /* I think this assert is bogus if buffer contains
6989 invisible text or images. KFS. */
6990 xassert (IT_CHARPOS (*it
) >= BEGV
);
6997 /* Move IT by a specified amount of pixel lines DY. DY negative means
6998 move backwards. DY = 0 means move to start of screen line. At the
6999 end, IT will be on the start of a screen line. */
7002 move_it_vertically (it
, dy
)
7007 move_it_vertically_backward (it
, -dy
);
7010 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7011 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7012 MOVE_TO_POS
| MOVE_TO_Y
);
7013 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7015 /* If buffer ends in ZV without a newline, move to the start of
7016 the line to satisfy the post-condition. */
7017 if (IT_CHARPOS (*it
) == ZV
7019 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7020 move_it_by_lines (it
, 0, 0);
7025 /* Move iterator IT past the end of the text line it is in. */
7028 move_it_past_eol (it
)
7031 enum move_it_result rc
;
7033 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7034 if (rc
== MOVE_NEWLINE_OR_CR
)
7035 set_iterator_to_next (it
, 0);
7039 #if 0 /* Currently not used. */
7041 /* Return non-zero if some text between buffer positions START_CHARPOS
7042 and END_CHARPOS is invisible. IT->window is the window for text
7046 invisible_text_between_p (it
, start_charpos
, end_charpos
)
7048 int start_charpos
, end_charpos
;
7050 Lisp_Object prop
, limit
;
7051 int invisible_found_p
;
7053 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
7055 /* Is text at START invisible? */
7056 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
7058 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
7059 invisible_found_p
= 1;
7062 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
7064 make_number (end_charpos
));
7065 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
7068 return invisible_found_p
;
7074 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7075 negative means move up. DVPOS == 0 means move to the start of the
7076 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7077 NEED_Y_P is zero, IT->current_y will be left unchanged.
7079 Further optimization ideas: If we would know that IT->f doesn't use
7080 a face with proportional font, we could be faster for
7081 truncate-lines nil. */
7084 move_it_by_lines (it
, dvpos
, need_y_p
)
7086 int dvpos
, need_y_p
;
7088 struct position pos
;
7090 if (!FRAME_WINDOW_P (it
->f
))
7092 struct text_pos textpos
;
7094 /* We can use vmotion on frames without proportional fonts. */
7095 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
7096 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
7097 reseat (it
, textpos
, 1);
7098 it
->vpos
+= pos
.vpos
;
7099 it
->current_y
+= pos
.vpos
;
7101 else if (dvpos
== 0)
7103 /* DVPOS == 0 means move to the start of the screen line. */
7104 move_it_vertically_backward (it
, 0);
7105 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7106 /* Let next call to line_bottom_y calculate real line height */
7111 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7112 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7113 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7118 int start_charpos
, i
;
7120 /* Start at the beginning of the screen line containing IT's
7121 position. This may actually move vertically backwards,
7122 in case of overlays, so adjust dvpos accordingly. */
7124 move_it_vertically_backward (it
, 0);
7127 /* Go back -DVPOS visible lines and reseat the iterator there. */
7128 start_charpos
= IT_CHARPOS (*it
);
7129 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7130 back_to_previous_visible_line_start (it
);
7131 reseat (it
, it
->current
.pos
, 1);
7133 /* Move further back if we end up in a string or an image. */
7134 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7136 /* First try to move to start of display line. */
7138 move_it_vertically_backward (it
, 0);
7140 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7142 /* If start of line is still in string or image,
7143 move further back. */
7144 back_to_previous_visible_line_start (it
);
7145 reseat (it
, it
->current
.pos
, 1);
7149 it
->current_x
= it
->hpos
= 0;
7151 /* Above call may have moved too far if continuation lines
7152 are involved. Scan forward and see if it did. */
7154 it2
.vpos
= it2
.current_y
= 0;
7155 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7156 it
->vpos
-= it2
.vpos
;
7157 it
->current_y
-= it2
.current_y
;
7158 it
->current_x
= it
->hpos
= 0;
7160 /* If we moved too far back, move IT some lines forward. */
7161 if (it2
.vpos
> -dvpos
)
7163 int delta
= it2
.vpos
+ dvpos
;
7165 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7166 /* Move back again if we got too far ahead. */
7167 if (IT_CHARPOS (*it
) >= start_charpos
)
7173 /* Return 1 if IT points into the middle of a display vector. */
7176 in_display_vector_p (it
)
7179 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7180 && it
->current
.dpvec_index
> 0
7181 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7185 /***********************************************************************
7187 ***********************************************************************/
7190 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7194 add_to_log (format
, arg1
, arg2
)
7196 Lisp_Object arg1
, arg2
;
7198 Lisp_Object args
[3];
7199 Lisp_Object msg
, fmt
;
7202 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7205 /* Do nothing if called asynchronously. Inserting text into
7206 a buffer may call after-change-functions and alike and
7207 that would means running Lisp asynchronously. */
7208 if (handling_signal
)
7212 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7214 args
[0] = fmt
= build_string (format
);
7217 msg
= Fformat (3, args
);
7219 len
= SBYTES (msg
) + 1;
7220 SAFE_ALLOCA (buffer
, char *, len
);
7221 bcopy (SDATA (msg
), buffer
, len
);
7223 message_dolog (buffer
, len
- 1, 1, 0);
7230 /* Output a newline in the *Messages* buffer if "needs" one. */
7233 message_log_maybe_newline ()
7235 if (message_log_need_newline
)
7236 message_dolog ("", 0, 1, 0);
7240 /* Add a string M of length NBYTES to the message log, optionally
7241 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7242 nonzero, means interpret the contents of M as multibyte. This
7243 function calls low-level routines in order to bypass text property
7244 hooks, etc. which might not be safe to run.
7246 This may GC (insert may run before/after change hooks),
7247 so the buffer M must NOT point to a Lisp string. */
7250 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7252 int nbytes
, nlflag
, multibyte
;
7254 if (!NILP (Vmemory_full
))
7257 if (!NILP (Vmessage_log_max
))
7259 struct buffer
*oldbuf
;
7260 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7261 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7262 int point_at_end
= 0;
7264 Lisp_Object old_deactivate_mark
, tem
;
7265 struct gcpro gcpro1
;
7267 old_deactivate_mark
= Vdeactivate_mark
;
7268 oldbuf
= current_buffer
;
7269 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7270 current_buffer
->undo_list
= Qt
;
7272 oldpoint
= message_dolog_marker1
;
7273 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7274 oldbegv
= message_dolog_marker2
;
7275 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7276 oldzv
= message_dolog_marker3
;
7277 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7278 GCPRO1 (old_deactivate_mark
);
7286 BEGV_BYTE
= BEG_BYTE
;
7289 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7291 /* Insert the string--maybe converting multibyte to single byte
7292 or vice versa, so that all the text fits the buffer. */
7294 && NILP (current_buffer
->enable_multibyte_characters
))
7296 int i
, c
, char_bytes
;
7297 unsigned char work
[1];
7299 /* Convert a multibyte string to single-byte
7300 for the *Message* buffer. */
7301 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7303 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7304 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7306 : multibyte_char_to_unibyte (c
, Qnil
));
7307 insert_1_both (work
, 1, 1, 1, 0, 0);
7310 else if (! multibyte
7311 && ! NILP (current_buffer
->enable_multibyte_characters
))
7313 int i
, c
, char_bytes
;
7314 unsigned char *msg
= (unsigned char *) m
;
7315 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7316 /* Convert a single-byte string to multibyte
7317 for the *Message* buffer. */
7318 for (i
= 0; i
< nbytes
; i
++)
7320 c
= unibyte_char_to_multibyte (msg
[i
]);
7321 char_bytes
= CHAR_STRING (c
, str
);
7322 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7326 insert_1 (m
, nbytes
, 1, 0, 0);
7330 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7331 insert_1 ("\n", 1, 1, 0, 0);
7333 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7335 this_bol_byte
= PT_BYTE
;
7337 /* See if this line duplicates the previous one.
7338 If so, combine duplicates. */
7341 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7343 prev_bol_byte
= PT_BYTE
;
7345 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7346 this_bol
, this_bol_byte
);
7349 del_range_both (prev_bol
, prev_bol_byte
,
7350 this_bol
, this_bol_byte
, 0);
7356 /* If you change this format, don't forget to also
7357 change message_log_check_duplicate. */
7358 sprintf (dupstr
, " [%d times]", dup
);
7359 duplen
= strlen (dupstr
);
7360 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7361 insert_1 (dupstr
, duplen
, 1, 0, 1);
7366 /* If we have more than the desired maximum number of lines
7367 in the *Messages* buffer now, delete the oldest ones.
7368 This is safe because we don't have undo in this buffer. */
7370 if (NATNUMP (Vmessage_log_max
))
7372 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7373 -XFASTINT (Vmessage_log_max
) - 1, 0);
7374 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7377 BEGV
= XMARKER (oldbegv
)->charpos
;
7378 BEGV_BYTE
= marker_byte_position (oldbegv
);
7387 ZV
= XMARKER (oldzv
)->charpos
;
7388 ZV_BYTE
= marker_byte_position (oldzv
);
7392 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7394 /* We can't do Fgoto_char (oldpoint) because it will run some
7396 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7397 XMARKER (oldpoint
)->bytepos
);
7400 unchain_marker (XMARKER (oldpoint
));
7401 unchain_marker (XMARKER (oldbegv
));
7402 unchain_marker (XMARKER (oldzv
));
7404 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7405 set_buffer_internal (oldbuf
);
7407 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7408 message_log_need_newline
= !nlflag
;
7409 Vdeactivate_mark
= old_deactivate_mark
;
7414 /* We are at the end of the buffer after just having inserted a newline.
7415 (Note: We depend on the fact we won't be crossing the gap.)
7416 Check to see if the most recent message looks a lot like the previous one.
7417 Return 0 if different, 1 if the new one should just replace it, or a
7418 value N > 1 if we should also append " [N times]". */
7421 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7422 int prev_bol
, this_bol
;
7423 int prev_bol_byte
, this_bol_byte
;
7426 int len
= Z_BYTE
- 1 - this_bol_byte
;
7428 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7429 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7431 for (i
= 0; i
< len
; i
++)
7433 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7441 if (*p1
++ == ' ' && *p1
++ == '[')
7444 while (*p1
>= '0' && *p1
<= '9')
7445 n
= n
* 10 + *p1
++ - '0';
7446 if (strncmp (p1
, " times]\n", 8) == 0)
7453 /* Display an echo area message M with a specified length of NBYTES
7454 bytes. The string may include null characters. If M is 0, clear
7455 out any existing message, and let the mini-buffer text show
7458 This may GC, so the buffer M must NOT point to a Lisp string. */
7461 message2 (m
, nbytes
, multibyte
)
7466 /* First flush out any partial line written with print. */
7467 message_log_maybe_newline ();
7469 message_dolog (m
, nbytes
, 1, multibyte
);
7470 message2_nolog (m
, nbytes
, multibyte
);
7474 /* The non-logging counterpart of message2. */
7477 message2_nolog (m
, nbytes
, multibyte
)
7479 int nbytes
, multibyte
;
7481 struct frame
*sf
= SELECTED_FRAME ();
7482 message_enable_multibyte
= multibyte
;
7486 if (noninteractive_need_newline
)
7487 putc ('\n', stderr
);
7488 noninteractive_need_newline
= 0;
7490 fwrite (m
, nbytes
, 1, stderr
);
7491 if (cursor_in_echo_area
== 0)
7492 fprintf (stderr
, "\n");
7495 /* A null message buffer means that the frame hasn't really been
7496 initialized yet. Error messages get reported properly by
7497 cmd_error, so this must be just an informative message; toss it. */
7498 else if (INTERACTIVE
7499 && sf
->glyphs_initialized_p
7500 && FRAME_MESSAGE_BUF (sf
))
7502 Lisp_Object mini_window
;
7505 /* Get the frame containing the mini-buffer
7506 that the selected frame is using. */
7507 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7508 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7510 FRAME_SAMPLE_VISIBILITY (f
);
7511 if (FRAME_VISIBLE_P (sf
)
7512 && ! FRAME_VISIBLE_P (f
))
7513 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7517 set_message (m
, Qnil
, nbytes
, multibyte
);
7518 if (minibuffer_auto_raise
)
7519 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7522 clear_message (1, 1);
7524 do_pending_window_change (0);
7525 echo_area_display (1);
7526 do_pending_window_change (0);
7527 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7528 (*frame_up_to_date_hook
) (f
);
7533 /* Display an echo area message M with a specified length of NBYTES
7534 bytes. The string may include null characters. If M is not a
7535 string, clear out any existing message, and let the mini-buffer
7538 This function cancels echoing. */
7541 message3 (m
, nbytes
, multibyte
)
7546 struct gcpro gcpro1
;
7549 clear_message (1,1);
7552 /* First flush out any partial line written with print. */
7553 message_log_maybe_newline ();
7559 SAFE_ALLOCA (buffer
, char *, nbytes
);
7560 bcopy (SDATA (m
), buffer
, nbytes
);
7561 message_dolog (buffer
, nbytes
, 1, multibyte
);
7564 message3_nolog (m
, nbytes
, multibyte
);
7570 /* The non-logging version of message3.
7571 This does not cancel echoing, because it is used for echoing.
7572 Perhaps we need to make a separate function for echoing
7573 and make this cancel echoing. */
7576 message3_nolog (m
, nbytes
, multibyte
)
7578 int nbytes
, multibyte
;
7580 struct frame
*sf
= SELECTED_FRAME ();
7581 message_enable_multibyte
= multibyte
;
7585 if (noninteractive_need_newline
)
7586 putc ('\n', stderr
);
7587 noninteractive_need_newline
= 0;
7589 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7590 if (cursor_in_echo_area
== 0)
7591 fprintf (stderr
, "\n");
7594 /* A null message buffer means that the frame hasn't really been
7595 initialized yet. Error messages get reported properly by
7596 cmd_error, so this must be just an informative message; toss it. */
7597 else if (INTERACTIVE
7598 && sf
->glyphs_initialized_p
7599 && FRAME_MESSAGE_BUF (sf
))
7601 Lisp_Object mini_window
;
7605 /* Get the frame containing the mini-buffer
7606 that the selected frame is using. */
7607 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7608 frame
= XWINDOW (mini_window
)->frame
;
7611 FRAME_SAMPLE_VISIBILITY (f
);
7612 if (FRAME_VISIBLE_P (sf
)
7613 && !FRAME_VISIBLE_P (f
))
7614 Fmake_frame_visible (frame
);
7616 if (STRINGP (m
) && SCHARS (m
) > 0)
7618 set_message (NULL
, m
, nbytes
, multibyte
);
7619 if (minibuffer_auto_raise
)
7620 Fraise_frame (frame
);
7621 /* Assume we are not echoing.
7622 (If we are, echo_now will override this.) */
7623 echo_message_buffer
= Qnil
;
7626 clear_message (1, 1);
7628 do_pending_window_change (0);
7629 echo_area_display (1);
7630 do_pending_window_change (0);
7631 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7632 (*frame_up_to_date_hook
) (f
);
7637 /* Display a null-terminated echo area message M. If M is 0, clear
7638 out any existing message, and let the mini-buffer text show through.
7640 The buffer M must continue to exist until after the echo area gets
7641 cleared or some other message gets displayed there. Do not pass
7642 text that is stored in a Lisp string. Do not pass text in a buffer
7643 that was alloca'd. */
7649 message2 (m
, (m
? strlen (m
) : 0), 0);
7653 /* The non-logging counterpart of message1. */
7659 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7662 /* Display a message M which contains a single %s
7663 which gets replaced with STRING. */
7666 message_with_string (m
, string
, log
)
7671 CHECK_STRING (string
);
7677 if (noninteractive_need_newline
)
7678 putc ('\n', stderr
);
7679 noninteractive_need_newline
= 0;
7680 fprintf (stderr
, m
, SDATA (string
));
7681 if (cursor_in_echo_area
== 0)
7682 fprintf (stderr
, "\n");
7686 else if (INTERACTIVE
)
7688 /* The frame whose minibuffer we're going to display the message on.
7689 It may be larger than the selected frame, so we need
7690 to use its buffer, not the selected frame's buffer. */
7691 Lisp_Object mini_window
;
7692 struct frame
*f
, *sf
= SELECTED_FRAME ();
7694 /* Get the frame containing the minibuffer
7695 that the selected frame is using. */
7696 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7697 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7699 /* A null message buffer means that the frame hasn't really been
7700 initialized yet. Error messages get reported properly by
7701 cmd_error, so this must be just an informative message; toss it. */
7702 if (FRAME_MESSAGE_BUF (f
))
7704 Lisp_Object args
[2], message
;
7705 struct gcpro gcpro1
, gcpro2
;
7707 args
[0] = build_string (m
);
7708 args
[1] = message
= string
;
7709 GCPRO2 (args
[0], message
);
7712 message
= Fformat (2, args
);
7715 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7717 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7721 /* Print should start at the beginning of the message
7722 buffer next time. */
7723 message_buf_print
= 0;
7729 /* Dump an informative message to the minibuf. If M is 0, clear out
7730 any existing message, and let the mini-buffer text show through. */
7734 message (m
, a1
, a2
, a3
)
7736 EMACS_INT a1
, a2
, a3
;
7742 if (noninteractive_need_newline
)
7743 putc ('\n', stderr
);
7744 noninteractive_need_newline
= 0;
7745 fprintf (stderr
, m
, a1
, a2
, a3
);
7746 if (cursor_in_echo_area
== 0)
7747 fprintf (stderr
, "\n");
7751 else if (INTERACTIVE
)
7753 /* The frame whose mini-buffer we're going to display the message
7754 on. It may be larger than the selected frame, so we need to
7755 use its buffer, not the selected frame's buffer. */
7756 Lisp_Object mini_window
;
7757 struct frame
*f
, *sf
= SELECTED_FRAME ();
7759 /* Get the frame containing the mini-buffer
7760 that the selected frame is using. */
7761 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7762 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7764 /* A null message buffer means that the frame hasn't really been
7765 initialized yet. Error messages get reported properly by
7766 cmd_error, so this must be just an informative message; toss
7768 if (FRAME_MESSAGE_BUF (f
))
7779 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7780 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7782 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7783 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7785 #endif /* NO_ARG_ARRAY */
7787 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7792 /* Print should start at the beginning of the message
7793 buffer next time. */
7794 message_buf_print
= 0;
7800 /* The non-logging version of message. */
7803 message_nolog (m
, a1
, a2
, a3
)
7805 EMACS_INT a1
, a2
, a3
;
7807 Lisp_Object old_log_max
;
7808 old_log_max
= Vmessage_log_max
;
7809 Vmessage_log_max
= Qnil
;
7810 message (m
, a1
, a2
, a3
);
7811 Vmessage_log_max
= old_log_max
;
7815 /* Display the current message in the current mini-buffer. This is
7816 only called from error handlers in process.c, and is not time
7822 if (!NILP (echo_area_buffer
[0]))
7825 string
= Fcurrent_message ();
7826 message3 (string
, SBYTES (string
),
7827 !NILP (current_buffer
->enable_multibyte_characters
));
7832 /* Make sure echo area buffers in `echo_buffers' are live.
7833 If they aren't, make new ones. */
7836 ensure_echo_area_buffers ()
7840 for (i
= 0; i
< 2; ++i
)
7841 if (!BUFFERP (echo_buffer
[i
])
7842 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7845 Lisp_Object old_buffer
;
7848 old_buffer
= echo_buffer
[i
];
7849 sprintf (name
, " *Echo Area %d*", i
);
7850 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7851 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7853 for (j
= 0; j
< 2; ++j
)
7854 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7855 echo_area_buffer
[j
] = echo_buffer
[i
];
7860 /* Call FN with args A1..A4 with either the current or last displayed
7861 echo_area_buffer as current buffer.
7863 WHICH zero means use the current message buffer
7864 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7865 from echo_buffer[] and clear it.
7867 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7868 suitable buffer from echo_buffer[] and clear it.
7870 Value is what FN returns. */
7873 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7876 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7882 int this_one
, the_other
, clear_buffer_p
, rc
;
7883 int count
= SPECPDL_INDEX ();
7885 /* If buffers aren't live, make new ones. */
7886 ensure_echo_area_buffers ();
7891 this_one
= 0, the_other
= 1;
7893 this_one
= 1, the_other
= 0;
7895 /* Choose a suitable buffer from echo_buffer[] is we don't
7897 if (NILP (echo_area_buffer
[this_one
]))
7899 echo_area_buffer
[this_one
]
7900 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7901 ? echo_buffer
[the_other
]
7902 : echo_buffer
[this_one
]);
7906 buffer
= echo_area_buffer
[this_one
];
7908 /* Don't get confused by reusing the buffer used for echoing
7909 for a different purpose. */
7910 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7913 record_unwind_protect (unwind_with_echo_area_buffer
,
7914 with_echo_area_buffer_unwind_data (w
));
7916 /* Make the echo area buffer current. Note that for display
7917 purposes, it is not necessary that the displayed window's buffer
7918 == current_buffer, except for text property lookup. So, let's
7919 only set that buffer temporarily here without doing a full
7920 Fset_window_buffer. We must also change w->pointm, though,
7921 because otherwise an assertions in unshow_buffer fails, and Emacs
7923 set_buffer_internal_1 (XBUFFER (buffer
));
7927 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7930 current_buffer
->undo_list
= Qt
;
7931 current_buffer
->read_only
= Qnil
;
7932 specbind (Qinhibit_read_only
, Qt
);
7933 specbind (Qinhibit_modification_hooks
, Qt
);
7935 if (clear_buffer_p
&& Z
> BEG
)
7938 xassert (BEGV
>= BEG
);
7939 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7941 rc
= fn (a1
, a2
, a3
, a4
);
7943 xassert (BEGV
>= BEG
);
7944 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7946 unbind_to (count
, Qnil
);
7951 /* Save state that should be preserved around the call to the function
7952 FN called in with_echo_area_buffer. */
7955 with_echo_area_buffer_unwind_data (w
)
7961 /* Reduce consing by keeping one vector in
7962 Vwith_echo_area_save_vector. */
7963 vector
= Vwith_echo_area_save_vector
;
7964 Vwith_echo_area_save_vector
= Qnil
;
7967 vector
= Fmake_vector (make_number (7), Qnil
);
7969 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7970 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7971 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7975 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7976 AREF (vector
, i
) = w
->buffer
; ++i
;
7977 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7978 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7983 for (; i
< end
; ++i
)
7984 AREF (vector
, i
) = Qnil
;
7987 xassert (i
== ASIZE (vector
));
7992 /* Restore global state from VECTOR which was created by
7993 with_echo_area_buffer_unwind_data. */
7996 unwind_with_echo_area_buffer (vector
)
7999 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8000 Vdeactivate_mark
= AREF (vector
, 1);
8001 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8003 if (WINDOWP (AREF (vector
, 3)))
8006 Lisp_Object buffer
, charpos
, bytepos
;
8008 w
= XWINDOW (AREF (vector
, 3));
8009 buffer
= AREF (vector
, 4);
8010 charpos
= AREF (vector
, 5);
8011 bytepos
= AREF (vector
, 6);
8014 set_marker_both (w
->pointm
, buffer
,
8015 XFASTINT (charpos
), XFASTINT (bytepos
));
8018 Vwith_echo_area_save_vector
= vector
;
8023 /* Set up the echo area for use by print functions. MULTIBYTE_P
8024 non-zero means we will print multibyte. */
8027 setup_echo_area_for_printing (multibyte_p
)
8030 /* If we can't find an echo area any more, exit. */
8031 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8034 ensure_echo_area_buffers ();
8036 if (!message_buf_print
)
8038 /* A message has been output since the last time we printed.
8039 Choose a fresh echo area buffer. */
8040 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8041 echo_area_buffer
[0] = echo_buffer
[1];
8043 echo_area_buffer
[0] = echo_buffer
[0];
8045 /* Switch to that buffer and clear it. */
8046 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8047 current_buffer
->truncate_lines
= Qnil
;
8051 int count
= SPECPDL_INDEX ();
8052 specbind (Qinhibit_read_only
, Qt
);
8053 /* Note that undo recording is always disabled. */
8055 unbind_to (count
, Qnil
);
8057 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8059 /* Set up the buffer for the multibyteness we need. */
8061 != !NILP (current_buffer
->enable_multibyte_characters
))
8062 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8064 /* Raise the frame containing the echo area. */
8065 if (minibuffer_auto_raise
)
8067 struct frame
*sf
= SELECTED_FRAME ();
8068 Lisp_Object mini_window
;
8069 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8070 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8073 message_log_maybe_newline ();
8074 message_buf_print
= 1;
8078 if (NILP (echo_area_buffer
[0]))
8080 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8081 echo_area_buffer
[0] = echo_buffer
[1];
8083 echo_area_buffer
[0] = echo_buffer
[0];
8086 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8088 /* Someone switched buffers between print requests. */
8089 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8090 current_buffer
->truncate_lines
= Qnil
;
8096 /* Display an echo area message in window W. Value is non-zero if W's
8097 height is changed. If display_last_displayed_message_p is
8098 non-zero, display the message that was last displayed, otherwise
8099 display the current message. */
8102 display_echo_area (w
)
8105 int i
, no_message_p
, window_height_changed_p
, count
;
8107 /* Temporarily disable garbage collections while displaying the echo
8108 area. This is done because a GC can print a message itself.
8109 That message would modify the echo area buffer's contents while a
8110 redisplay of the buffer is going on, and seriously confuse
8112 count
= inhibit_garbage_collection ();
8114 /* If there is no message, we must call display_echo_area_1
8115 nevertheless because it resizes the window. But we will have to
8116 reset the echo_area_buffer in question to nil at the end because
8117 with_echo_area_buffer will sets it to an empty buffer. */
8118 i
= display_last_displayed_message_p
? 1 : 0;
8119 no_message_p
= NILP (echo_area_buffer
[i
]);
8121 window_height_changed_p
8122 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8123 display_echo_area_1
,
8124 (EMACS_INT
) w
, Qnil
, 0, 0);
8127 echo_area_buffer
[i
] = Qnil
;
8129 unbind_to (count
, Qnil
);
8130 return window_height_changed_p
;
8134 /* Helper for display_echo_area. Display the current buffer which
8135 contains the current echo area message in window W, a mini-window,
8136 a pointer to which is passed in A1. A2..A4 are currently not used.
8137 Change the height of W so that all of the message is displayed.
8138 Value is non-zero if height of W was changed. */
8141 display_echo_area_1 (a1
, a2
, a3
, a4
)
8146 struct window
*w
= (struct window
*) a1
;
8148 struct text_pos start
;
8149 int window_height_changed_p
= 0;
8151 /* Do this before displaying, so that we have a large enough glyph
8152 matrix for the display. If we can't get enough space for the
8153 whole text, display the last N lines. That works by setting w->start. */
8154 window_height_changed_p
= resize_mini_window (w
, 0);
8156 /* Use the starting position chosen by resize_mini_window. */
8157 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8160 clear_glyph_matrix (w
->desired_matrix
);
8161 XSETWINDOW (window
, w
);
8162 try_window (window
, start
, 0);
8164 return window_height_changed_p
;
8168 /* Resize the echo area window to exactly the size needed for the
8169 currently displayed message, if there is one. If a mini-buffer
8170 is active, don't shrink it. */
8173 resize_echo_area_exactly ()
8175 if (BUFFERP (echo_area_buffer
[0])
8176 && WINDOWP (echo_area_window
))
8178 struct window
*w
= XWINDOW (echo_area_window
);
8180 Lisp_Object resize_exactly
;
8182 if (minibuf_level
== 0)
8183 resize_exactly
= Qt
;
8185 resize_exactly
= Qnil
;
8187 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8188 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8191 ++windows_or_buffers_changed
;
8192 ++update_mode_lines
;
8193 redisplay_internal (0);
8199 /* Callback function for with_echo_area_buffer, when used from
8200 resize_echo_area_exactly. A1 contains a pointer to the window to
8201 resize, EXACTLY non-nil means resize the mini-window exactly to the
8202 size of the text displayed. A3 and A4 are not used. Value is what
8203 resize_mini_window returns. */
8206 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8208 Lisp_Object exactly
;
8211 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8215 /* Resize mini-window W to fit the size of its contents. EXACT:P
8216 means size the window exactly to the size needed. Otherwise, it's
8217 only enlarged until W's buffer is empty.
8219 Set W->start to the right place to begin display. If the whole
8220 contents fit, start at the beginning. Otherwise, start so as
8221 to make the end of the contents appear. This is particularly
8222 important for y-or-n-p, but seems desirable generally.
8224 Value is non-zero if the window height has been changed. */
8227 resize_mini_window (w
, exact_p
)
8231 struct frame
*f
= XFRAME (w
->frame
);
8232 int window_height_changed_p
= 0;
8234 xassert (MINI_WINDOW_P (w
));
8236 /* By default, start display at the beginning. */
8237 set_marker_both (w
->start
, w
->buffer
,
8238 BUF_BEGV (XBUFFER (w
->buffer
)),
8239 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8241 /* Don't resize windows while redisplaying a window; it would
8242 confuse redisplay functions when the size of the window they are
8243 displaying changes from under them. Such a resizing can happen,
8244 for instance, when which-func prints a long message while
8245 we are running fontification-functions. We're running these
8246 functions with safe_call which binds inhibit-redisplay to t. */
8247 if (!NILP (Vinhibit_redisplay
))
8250 /* Nil means don't try to resize. */
8251 if (NILP (Vresize_mini_windows
)
8252 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8255 if (!FRAME_MINIBUF_ONLY_P (f
))
8258 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8259 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8260 int height
, max_height
;
8261 int unit
= FRAME_LINE_HEIGHT (f
);
8262 struct text_pos start
;
8263 struct buffer
*old_current_buffer
= NULL
;
8265 if (current_buffer
!= XBUFFER (w
->buffer
))
8267 old_current_buffer
= current_buffer
;
8268 set_buffer_internal (XBUFFER (w
->buffer
));
8271 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8273 /* Compute the max. number of lines specified by the user. */
8274 if (FLOATP (Vmax_mini_window_height
))
8275 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8276 else if (INTEGERP (Vmax_mini_window_height
))
8277 max_height
= XINT (Vmax_mini_window_height
);
8279 max_height
= total_height
/ 4;
8281 /* Correct that max. height if it's bogus. */
8282 max_height
= max (1, max_height
);
8283 max_height
= min (total_height
, max_height
);
8285 /* Find out the height of the text in the window. */
8286 if (it
.truncate_lines_p
)
8291 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8292 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8293 height
= it
.current_y
+ last_height
;
8295 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8296 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8297 height
= (height
+ unit
- 1) / unit
;
8300 /* Compute a suitable window start. */
8301 if (height
> max_height
)
8303 height
= max_height
;
8304 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8305 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8306 start
= it
.current
.pos
;
8309 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8310 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8312 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8314 /* Let it grow only, until we display an empty message, in which
8315 case the window shrinks again. */
8316 if (height
> WINDOW_TOTAL_LINES (w
))
8318 int old_height
= WINDOW_TOTAL_LINES (w
);
8319 freeze_window_starts (f
, 1);
8320 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8321 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8323 else if (height
< WINDOW_TOTAL_LINES (w
)
8324 && (exact_p
|| BEGV
== ZV
))
8326 int old_height
= WINDOW_TOTAL_LINES (w
);
8327 freeze_window_starts (f
, 0);
8328 shrink_mini_window (w
);
8329 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8334 /* Always resize to exact size needed. */
8335 if (height
> WINDOW_TOTAL_LINES (w
))
8337 int old_height
= WINDOW_TOTAL_LINES (w
);
8338 freeze_window_starts (f
, 1);
8339 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8340 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8342 else if (height
< WINDOW_TOTAL_LINES (w
))
8344 int old_height
= WINDOW_TOTAL_LINES (w
);
8345 freeze_window_starts (f
, 0);
8346 shrink_mini_window (w
);
8350 freeze_window_starts (f
, 1);
8351 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8354 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8358 if (old_current_buffer
)
8359 set_buffer_internal (old_current_buffer
);
8362 return window_height_changed_p
;
8366 /* Value is the current message, a string, or nil if there is no
8374 if (NILP (echo_area_buffer
[0]))
8378 with_echo_area_buffer (0, 0, current_message_1
,
8379 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8381 echo_area_buffer
[0] = Qnil
;
8389 current_message_1 (a1
, a2
, a3
, a4
)
8394 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8397 *msg
= make_buffer_string (BEG
, Z
, 1);
8404 /* Push the current message on Vmessage_stack for later restauration
8405 by restore_message. Value is non-zero if the current message isn't
8406 empty. This is a relatively infrequent operation, so it's not
8407 worth optimizing. */
8413 msg
= current_message ();
8414 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8415 return STRINGP (msg
);
8419 /* Restore message display from the top of Vmessage_stack. */
8426 xassert (CONSP (Vmessage_stack
));
8427 msg
= XCAR (Vmessage_stack
);
8429 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8431 message3_nolog (msg
, 0, 0);
8435 /* Handler for record_unwind_protect calling pop_message. */
8438 pop_message_unwind (dummy
)
8445 /* Pop the top-most entry off Vmessage_stack. */
8450 xassert (CONSP (Vmessage_stack
));
8451 Vmessage_stack
= XCDR (Vmessage_stack
);
8455 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8456 exits. If the stack is not empty, we have a missing pop_message
8460 check_message_stack ()
8462 if (!NILP (Vmessage_stack
))
8467 /* Truncate to NCHARS what will be displayed in the echo area the next
8468 time we display it---but don't redisplay it now. */
8471 truncate_echo_area (nchars
)
8475 echo_area_buffer
[0] = Qnil
;
8476 /* A null message buffer means that the frame hasn't really been
8477 initialized yet. Error messages get reported properly by
8478 cmd_error, so this must be just an informative message; toss it. */
8479 else if (!noninteractive
8481 && !NILP (echo_area_buffer
[0]))
8483 struct frame
*sf
= SELECTED_FRAME ();
8484 if (FRAME_MESSAGE_BUF (sf
))
8485 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8490 /* Helper function for truncate_echo_area. Truncate the current
8491 message to at most NCHARS characters. */
8494 truncate_message_1 (nchars
, a2
, a3
, a4
)
8499 if (BEG
+ nchars
< Z
)
8500 del_range (BEG
+ nchars
, Z
);
8502 echo_area_buffer
[0] = Qnil
;
8507 /* Set the current message to a substring of S or STRING.
8509 If STRING is a Lisp string, set the message to the first NBYTES
8510 bytes from STRING. NBYTES zero means use the whole string. If
8511 STRING is multibyte, the message will be displayed multibyte.
8513 If S is not null, set the message to the first LEN bytes of S. LEN
8514 zero means use the whole string. MULTIBYTE_P non-zero means S is
8515 multibyte. Display the message multibyte in that case.
8517 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8518 to t before calling set_message_1 (which calls insert).
8522 set_message (s
, string
, nbytes
, multibyte_p
)
8525 int nbytes
, multibyte_p
;
8527 message_enable_multibyte
8528 = ((s
&& multibyte_p
)
8529 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8531 with_echo_area_buffer (0, 0, set_message_1
,
8532 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8533 message_buf_print
= 0;
8534 help_echo_showing_p
= 0;
8538 /* Helper function for set_message. Arguments have the same meaning
8539 as there, with A1 corresponding to S and A2 corresponding to STRING
8540 This function is called with the echo area buffer being
8544 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8547 EMACS_INT nbytes
, multibyte_p
;
8549 const char *s
= (const char *) a1
;
8550 Lisp_Object string
= a2
;
8552 /* Change multibyteness of the echo buffer appropriately. */
8553 if (message_enable_multibyte
8554 != !NILP (current_buffer
->enable_multibyte_characters
))
8555 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8557 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8559 /* Insert new message at BEG. */
8560 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8563 if (STRINGP (string
))
8568 nbytes
= SBYTES (string
);
8569 nchars
= string_byte_to_char (string
, nbytes
);
8571 /* This function takes care of single/multibyte conversion. We
8572 just have to ensure that the echo area buffer has the right
8573 setting of enable_multibyte_characters. */
8574 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8579 nbytes
= strlen (s
);
8581 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8583 /* Convert from multi-byte to single-byte. */
8585 unsigned char work
[1];
8587 /* Convert a multibyte string to single-byte. */
8588 for (i
= 0; i
< nbytes
; i
+= n
)
8590 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8591 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
8593 : multibyte_char_to_unibyte (c
, Qnil
));
8594 insert_1_both (work
, 1, 1, 1, 0, 0);
8597 else if (!multibyte_p
8598 && !NILP (current_buffer
->enable_multibyte_characters
))
8600 /* Convert from single-byte to multi-byte. */
8602 const unsigned char *msg
= (const unsigned char *) s
;
8603 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8605 /* Convert a single-byte string to multibyte. */
8606 for (i
= 0; i
< nbytes
; i
++)
8608 c
= unibyte_char_to_multibyte (msg
[i
]);
8609 n
= CHAR_STRING (c
, str
);
8610 insert_1_both (str
, 1, n
, 1, 0, 0);
8614 insert_1 (s
, nbytes
, 1, 0, 0);
8621 /* Clear messages. CURRENT_P non-zero means clear the current
8622 message. LAST_DISPLAYED_P non-zero means clear the message
8626 clear_message (current_p
, last_displayed_p
)
8627 int current_p
, last_displayed_p
;
8631 echo_area_buffer
[0] = Qnil
;
8632 message_cleared_p
= 1;
8635 if (last_displayed_p
)
8636 echo_area_buffer
[1] = Qnil
;
8638 message_buf_print
= 0;
8641 /* Clear garbaged frames.
8643 This function is used where the old redisplay called
8644 redraw_garbaged_frames which in turn called redraw_frame which in
8645 turn called clear_frame. The call to clear_frame was a source of
8646 flickering. I believe a clear_frame is not necessary. It should
8647 suffice in the new redisplay to invalidate all current matrices,
8648 and ensure a complete redisplay of all windows. */
8651 clear_garbaged_frames ()
8655 Lisp_Object tail
, frame
;
8656 int changed_count
= 0;
8658 FOR_EACH_FRAME (tail
, frame
)
8660 struct frame
*f
= XFRAME (frame
);
8662 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8666 Fredraw_frame (frame
);
8667 f
->force_flush_display_p
= 1;
8669 clear_current_matrices (f
);
8678 ++windows_or_buffers_changed
;
8683 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8684 is non-zero update selected_frame. Value is non-zero if the
8685 mini-windows height has been changed. */
8688 echo_area_display (update_frame_p
)
8691 Lisp_Object mini_window
;
8694 int window_height_changed_p
= 0;
8695 struct frame
*sf
= SELECTED_FRAME ();
8697 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8698 w
= XWINDOW (mini_window
);
8699 f
= XFRAME (WINDOW_FRAME (w
));
8701 /* Don't display if frame is invisible or not yet initialized. */
8702 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8705 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8707 #ifdef HAVE_WINDOW_SYSTEM
8708 /* When Emacs starts, selected_frame may be a visible terminal
8709 frame, even if we run under a window system. If we let this
8710 through, a message would be displayed on the terminal. */
8711 if (EQ (selected_frame
, Vterminal_frame
)
8712 && !NILP (Vwindow_system
))
8714 #endif /* HAVE_WINDOW_SYSTEM */
8717 /* Redraw garbaged frames. */
8719 clear_garbaged_frames ();
8721 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8723 echo_area_window
= mini_window
;
8724 window_height_changed_p
= display_echo_area (w
);
8725 w
->must_be_updated_p
= 1;
8727 /* Update the display, unless called from redisplay_internal.
8728 Also don't update the screen during redisplay itself. The
8729 update will happen at the end of redisplay, and an update
8730 here could cause confusion. */
8731 if (update_frame_p
&& !redisplaying_p
)
8735 /* If the display update has been interrupted by pending
8736 input, update mode lines in the frame. Due to the
8737 pending input, it might have been that redisplay hasn't
8738 been called, so that mode lines above the echo area are
8739 garbaged. This looks odd, so we prevent it here. */
8740 if (!display_completed
)
8741 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8743 if (window_height_changed_p
8744 /* Don't do this if Emacs is shutting down. Redisplay
8745 needs to run hooks. */
8746 && !NILP (Vrun_hooks
))
8748 /* Must update other windows. Likewise as in other
8749 cases, don't let this update be interrupted by
8751 int count
= SPECPDL_INDEX ();
8752 specbind (Qredisplay_dont_pause
, Qt
);
8753 windows_or_buffers_changed
= 1;
8754 redisplay_internal (0);
8755 unbind_to (count
, Qnil
);
8757 else if (FRAME_WINDOW_P (f
) && n
== 0)
8759 /* Window configuration is the same as before.
8760 Can do with a display update of the echo area,
8761 unless we displayed some mode lines. */
8762 update_single_window (w
, 1);
8763 rif
->flush_display (f
);
8766 update_frame (f
, 1, 1);
8768 /* If cursor is in the echo area, make sure that the next
8769 redisplay displays the minibuffer, so that the cursor will
8770 be replaced with what the minibuffer wants. */
8771 if (cursor_in_echo_area
)
8772 ++windows_or_buffers_changed
;
8775 else if (!EQ (mini_window
, selected_window
))
8776 windows_or_buffers_changed
++;
8778 /* The current message is now also the last one displayed. */
8779 echo_area_buffer
[1] = echo_area_buffer
[0];
8781 /* Prevent redisplay optimization in redisplay_internal by resetting
8782 this_line_start_pos. This is done because the mini-buffer now
8783 displays the message instead of its buffer text. */
8784 if (EQ (mini_window
, selected_window
))
8785 CHARPOS (this_line_start_pos
) = 0;
8787 return window_height_changed_p
;
8792 /***********************************************************************
8793 Mode Lines and Frame Titles
8794 ***********************************************************************/
8796 /* A buffer for constructing non-propertized mode-line strings and
8797 frame titles in it; allocated from the heap in init_xdisp and
8798 resized as needed in store_mode_line_noprop_char. */
8800 static char *mode_line_noprop_buf
;
8802 /* The buffer's end, and a current output position in it. */
8804 static char *mode_line_noprop_buf_end
;
8805 static char *mode_line_noprop_ptr
;
8807 #define MODE_LINE_NOPROP_LEN(start) \
8808 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8811 MODE_LINE_DISPLAY
= 0,
8817 /* Alist that caches the results of :propertize.
8818 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8819 static Lisp_Object mode_line_proptrans_alist
;
8821 /* List of strings making up the mode-line. */
8822 static Lisp_Object mode_line_string_list
;
8824 /* Base face property when building propertized mode line string. */
8825 static Lisp_Object mode_line_string_face
;
8826 static Lisp_Object mode_line_string_face_prop
;
8829 /* Unwind data for mode line strings */
8831 static Lisp_Object Vmode_line_unwind_vector
;
8834 format_mode_line_unwind_data (obuf
, save_proptrans
)
8835 struct buffer
*obuf
;
8839 /* Reduce consing by keeping one vector in
8840 Vwith_echo_area_save_vector. */
8841 vector
= Vmode_line_unwind_vector
;
8842 Vmode_line_unwind_vector
= Qnil
;
8845 vector
= Fmake_vector (make_number (7), Qnil
);
8847 AREF (vector
, 0) = make_number (mode_line_target
);
8848 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8849 AREF (vector
, 2) = mode_line_string_list
;
8850 AREF (vector
, 3) = (save_proptrans
? mode_line_proptrans_alist
: Qt
);
8851 AREF (vector
, 4) = mode_line_string_face
;
8852 AREF (vector
, 5) = mode_line_string_face_prop
;
8855 XSETBUFFER (AREF (vector
, 6), obuf
);
8857 AREF (vector
, 6) = Qnil
;
8863 unwind_format_mode_line (vector
)
8866 mode_line_target
= XINT (AREF (vector
, 0));
8867 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8868 mode_line_string_list
= AREF (vector
, 2);
8869 if (! EQ (AREF (vector
, 3), Qt
))
8870 mode_line_proptrans_alist
= AREF (vector
, 3);
8871 mode_line_string_face
= AREF (vector
, 4);
8872 mode_line_string_face_prop
= AREF (vector
, 5);
8874 if (!NILP (AREF (vector
, 6)))
8876 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8877 AREF (vector
, 6) = Qnil
;
8880 Vmode_line_unwind_vector
= vector
;
8885 /* Store a single character C for the frame title in mode_line_noprop_buf.
8886 Re-allocate mode_line_noprop_buf if necessary. */
8890 store_mode_line_noprop_char (char c
)
8892 store_mode_line_noprop_char (c
)
8896 /* If output position has reached the end of the allocated buffer,
8897 double the buffer's size. */
8898 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8900 int len
= MODE_LINE_NOPROP_LEN (0);
8901 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8902 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8903 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8904 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8907 *mode_line_noprop_ptr
++ = c
;
8911 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8912 mode_line_noprop_ptr. STR is the string to store. Do not copy
8913 characters that yield more columns than PRECISION; PRECISION <= 0
8914 means copy the whole string. Pad with spaces until FIELD_WIDTH
8915 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8916 pad. Called from display_mode_element when it is used to build a
8920 store_mode_line_noprop (str
, field_width
, precision
)
8921 const unsigned char *str
;
8922 int field_width
, precision
;
8927 /* Copy at most PRECISION chars from STR. */
8928 nbytes
= strlen (str
);
8929 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8931 store_mode_line_noprop_char (*str
++);
8933 /* Fill up with spaces until FIELD_WIDTH reached. */
8934 while (field_width
> 0
8937 store_mode_line_noprop_char (' ');
8944 /***********************************************************************
8946 ***********************************************************************/
8948 #ifdef HAVE_WINDOW_SYSTEM
8950 /* Set the title of FRAME, if it has changed. The title format is
8951 Vicon_title_format if FRAME is iconified, otherwise it is
8952 frame_title_format. */
8955 x_consider_frame_title (frame
)
8958 struct frame
*f
= XFRAME (frame
);
8960 if (FRAME_WINDOW_P (f
)
8961 || FRAME_MINIBUF_ONLY_P (f
)
8962 || f
->explicit_name
)
8964 /* Do we have more than one visible frame on this X display? */
8971 int count
= SPECPDL_INDEX ();
8973 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8975 Lisp_Object other_frame
= XCAR (tail
);
8976 struct frame
*tf
= XFRAME (other_frame
);
8979 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8980 && !FRAME_MINIBUF_ONLY_P (tf
)
8981 && !EQ (other_frame
, tip_frame
)
8982 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8986 /* Set global variable indicating that multiple frames exist. */
8987 multiple_frames
= CONSP (tail
);
8989 /* Switch to the buffer of selected window of the frame. Set up
8990 mode_line_target so that display_mode_element will output into
8991 mode_line_noprop_buf; then display the title. */
8992 record_unwind_protect (unwind_format_mode_line
,
8993 format_mode_line_unwind_data (current_buffer
, 0));
8995 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8996 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8998 mode_line_target
= MODE_LINE_TITLE
;
8999 title_start
= MODE_LINE_NOPROP_LEN (0);
9000 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9001 NULL
, DEFAULT_FACE_ID
);
9002 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9003 len
= MODE_LINE_NOPROP_LEN (title_start
);
9004 title
= mode_line_noprop_buf
+ title_start
;
9005 unbind_to (count
, Qnil
);
9007 /* Set the title only if it's changed. This avoids consing in
9008 the common case where it hasn't. (If it turns out that we've
9009 already wasted too much time by walking through the list with
9010 display_mode_element, then we might need to optimize at a
9011 higher level than this.) */
9012 if (! STRINGP (f
->name
)
9013 || SBYTES (f
->name
) != len
9014 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9015 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9019 #endif /* not HAVE_WINDOW_SYSTEM */
9024 /***********************************************************************
9026 ***********************************************************************/
9029 /* Prepare for redisplay by updating menu-bar item lists when
9030 appropriate. This can call eval. */
9033 prepare_menu_bars ()
9036 struct gcpro gcpro1
, gcpro2
;
9038 Lisp_Object tooltip_frame
;
9040 #ifdef HAVE_WINDOW_SYSTEM
9041 tooltip_frame
= tip_frame
;
9043 tooltip_frame
= Qnil
;
9046 /* Update all frame titles based on their buffer names, etc. We do
9047 this before the menu bars so that the buffer-menu will show the
9048 up-to-date frame titles. */
9049 #ifdef HAVE_WINDOW_SYSTEM
9050 if (windows_or_buffers_changed
|| update_mode_lines
)
9052 Lisp_Object tail
, frame
;
9054 FOR_EACH_FRAME (tail
, frame
)
9057 if (!EQ (frame
, tooltip_frame
)
9058 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9059 x_consider_frame_title (frame
);
9062 #endif /* HAVE_WINDOW_SYSTEM */
9064 /* Update the menu bar item lists, if appropriate. This has to be
9065 done before any actual redisplay or generation of display lines. */
9066 all_windows
= (update_mode_lines
9067 || buffer_shared
> 1
9068 || windows_or_buffers_changed
);
9071 Lisp_Object tail
, frame
;
9072 int count
= SPECPDL_INDEX ();
9073 /* 1 means that update_menu_bar has run its hooks
9074 so any further calls to update_menu_bar shouldn't do so again. */
9075 int menu_bar_hooks_run
= 0;
9077 record_unwind_save_match_data ();
9079 FOR_EACH_FRAME (tail
, frame
)
9083 /* Ignore tooltip frame. */
9084 if (EQ (frame
, tooltip_frame
))
9087 /* If a window on this frame changed size, report that to
9088 the user and clear the size-change flag. */
9089 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9091 Lisp_Object functions
;
9093 /* Clear flag first in case we get an error below. */
9094 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9095 functions
= Vwindow_size_change_functions
;
9096 GCPRO2 (tail
, functions
);
9098 while (CONSP (functions
))
9100 call1 (XCAR (functions
), frame
);
9101 functions
= XCDR (functions
);
9107 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9108 #ifdef HAVE_WINDOW_SYSTEM
9109 update_tool_bar (f
, 0);
9111 mac_update_title_bar (f
, 0);
9117 unbind_to (count
, Qnil
);
9121 struct frame
*sf
= SELECTED_FRAME ();
9122 update_menu_bar (sf
, 1, 0);
9123 #ifdef HAVE_WINDOW_SYSTEM
9124 update_tool_bar (sf
, 1);
9126 mac_update_title_bar (sf
, 1);
9131 /* Motif needs this. See comment in xmenu.c. Turn it off when
9132 pending_menu_activation is not defined. */
9133 #ifdef USE_X_TOOLKIT
9134 pending_menu_activation
= 0;
9139 /* Update the menu bar item list for frame F. This has to be done
9140 before we start to fill in any display lines, because it can call
9143 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9145 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9146 already ran the menu bar hooks for this redisplay, so there
9147 is no need to run them again. The return value is the
9148 updated value of this flag, to pass to the next call. */
9151 update_menu_bar (f
, save_match_data
, hooks_run
)
9153 int save_match_data
;
9157 register struct window
*w
;
9159 /* If called recursively during a menu update, do nothing. This can
9160 happen when, for instance, an activate-menubar-hook causes a
9162 if (inhibit_menubar_update
)
9165 window
= FRAME_SELECTED_WINDOW (f
);
9166 w
= XWINDOW (window
);
9168 #if 0 /* The if statement below this if statement used to include the
9169 condition !NILP (w->update_mode_line), rather than using
9170 update_mode_lines directly, and this if statement may have
9171 been added to make that condition work. Now the if
9172 statement below matches its comment, this isn't needed. */
9173 if (update_mode_lines
)
9174 w
->update_mode_line
= Qt
;
9177 if (FRAME_WINDOW_P (f
)
9179 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9180 || defined (USE_GTK)
9181 FRAME_EXTERNAL_MENU_BAR (f
)
9183 FRAME_MENU_BAR_LINES (f
) > 0
9185 : FRAME_MENU_BAR_LINES (f
) > 0)
9187 /* If the user has switched buffers or windows, we need to
9188 recompute to reflect the new bindings. But we'll
9189 recompute when update_mode_lines is set too; that means
9190 that people can use force-mode-line-update to request
9191 that the menu bar be recomputed. The adverse effect on
9192 the rest of the redisplay algorithm is about the same as
9193 windows_or_buffers_changed anyway. */
9194 if (windows_or_buffers_changed
9195 /* This used to test w->update_mode_line, but we believe
9196 there is no need to recompute the menu in that case. */
9197 || update_mode_lines
9198 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9199 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9200 != !NILP (w
->last_had_star
))
9201 || ((!NILP (Vtransient_mark_mode
)
9202 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9203 != !NILP (w
->region_showing
)))
9205 struct buffer
*prev
= current_buffer
;
9206 int count
= SPECPDL_INDEX ();
9208 specbind (Qinhibit_menubar_update
, Qt
);
9210 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9211 if (save_match_data
)
9212 record_unwind_save_match_data ();
9213 if (NILP (Voverriding_local_map_menu_flag
))
9215 specbind (Qoverriding_terminal_local_map
, Qnil
);
9216 specbind (Qoverriding_local_map
, Qnil
);
9221 /* Run the Lucid hook. */
9222 safe_run_hooks (Qactivate_menubar_hook
);
9224 /* If it has changed current-menubar from previous value,
9225 really recompute the menu-bar from the value. */
9226 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9227 call0 (Qrecompute_lucid_menubar
);
9229 safe_run_hooks (Qmenu_bar_update_hook
);
9234 XSETFRAME (Vmenu_updating_frame
, f
);
9235 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9237 /* Redisplay the menu bar in case we changed it. */
9238 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9239 || defined (USE_GTK)
9240 if (FRAME_WINDOW_P (f
))
9243 /* All frames on Mac OS share the same menubar. So only
9244 the selected frame should be allowed to set it. */
9245 if (f
== SELECTED_FRAME ())
9247 set_frame_menubar (f
, 0, 0);
9250 /* On a terminal screen, the menu bar is an ordinary screen
9251 line, and this makes it get updated. */
9252 w
->update_mode_line
= Qt
;
9253 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9254 /* In the non-toolkit version, the menu bar is an ordinary screen
9255 line, and this makes it get updated. */
9256 w
->update_mode_line
= Qt
;
9257 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9259 unbind_to (count
, Qnil
);
9260 set_buffer_internal_1 (prev
);
9269 /***********************************************************************
9271 ***********************************************************************/
9273 #ifdef HAVE_WINDOW_SYSTEM
9276 Nominal cursor position -- where to draw output.
9277 HPOS and VPOS are window relative glyph matrix coordinates.
9278 X and Y are window relative pixel coordinates. */
9280 struct cursor_pos output_cursor
;
9284 Set the global variable output_cursor to CURSOR. All cursor
9285 positions are relative to updated_window. */
9288 set_output_cursor (cursor
)
9289 struct cursor_pos
*cursor
;
9291 output_cursor
.hpos
= cursor
->hpos
;
9292 output_cursor
.vpos
= cursor
->vpos
;
9293 output_cursor
.x
= cursor
->x
;
9294 output_cursor
.y
= cursor
->y
;
9299 Set a nominal cursor position.
9301 HPOS and VPOS are column/row positions in a window glyph matrix. X
9302 and Y are window text area relative pixel positions.
9304 If this is done during an update, updated_window will contain the
9305 window that is being updated and the position is the future output
9306 cursor position for that window. If updated_window is null, use
9307 selected_window and display the cursor at the given position. */
9310 x_cursor_to (vpos
, hpos
, y
, x
)
9311 int vpos
, hpos
, y
, x
;
9315 /* If updated_window is not set, work on selected_window. */
9319 w
= XWINDOW (selected_window
);
9321 /* Set the output cursor. */
9322 output_cursor
.hpos
= hpos
;
9323 output_cursor
.vpos
= vpos
;
9324 output_cursor
.x
= x
;
9325 output_cursor
.y
= y
;
9327 /* If not called as part of an update, really display the cursor.
9328 This will also set the cursor position of W. */
9329 if (updated_window
== NULL
)
9332 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9333 if (rif
->flush_display_optional
)
9334 rif
->flush_display_optional (SELECTED_FRAME ());
9339 #endif /* HAVE_WINDOW_SYSTEM */
9342 /***********************************************************************
9344 ***********************************************************************/
9346 #ifdef HAVE_WINDOW_SYSTEM
9348 /* Where the mouse was last time we reported a mouse event. */
9350 FRAME_PTR last_mouse_frame
;
9352 /* Tool-bar item index of the item on which a mouse button was pressed
9355 int last_tool_bar_item
;
9358 /* Update the tool-bar item list for frame F. This has to be done
9359 before we start to fill in any display lines. Called from
9360 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9361 and restore it here. */
9364 update_tool_bar (f
, save_match_data
)
9366 int save_match_data
;
9369 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9371 int do_update
= WINDOWP (f
->tool_bar_window
)
9372 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9380 window
= FRAME_SELECTED_WINDOW (f
);
9381 w
= XWINDOW (window
);
9383 /* If the user has switched buffers or windows, we need to
9384 recompute to reflect the new bindings. But we'll
9385 recompute when update_mode_lines is set too; that means
9386 that people can use force-mode-line-update to request
9387 that the menu bar be recomputed. The adverse effect on
9388 the rest of the redisplay algorithm is about the same as
9389 windows_or_buffers_changed anyway. */
9390 if (windows_or_buffers_changed
9391 || !NILP (w
->update_mode_line
)
9392 || update_mode_lines
9393 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9394 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9395 != !NILP (w
->last_had_star
))
9396 || ((!NILP (Vtransient_mark_mode
)
9397 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9398 != !NILP (w
->region_showing
)))
9400 struct buffer
*prev
= current_buffer
;
9401 int count
= SPECPDL_INDEX ();
9402 Lisp_Object new_tool_bar
;
9404 struct gcpro gcpro1
;
9406 /* Set current_buffer to the buffer of the selected
9407 window of the frame, so that we get the right local
9409 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9411 /* Save match data, if we must. */
9412 if (save_match_data
)
9413 record_unwind_save_match_data ();
9415 /* Make sure that we don't accidentally use bogus keymaps. */
9416 if (NILP (Voverriding_local_map_menu_flag
))
9418 specbind (Qoverriding_terminal_local_map
, Qnil
);
9419 specbind (Qoverriding_local_map
, Qnil
);
9422 GCPRO1 (new_tool_bar
);
9424 /* Build desired tool-bar items from keymaps. */
9425 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9428 /* Redisplay the tool-bar if we changed it. */
9429 if (new_n_tool_bar
!= f
->n_tool_bar_items
9430 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9432 /* Redisplay that happens asynchronously due to an expose event
9433 may access f->tool_bar_items. Make sure we update both
9434 variables within BLOCK_INPUT so no such event interrupts. */
9436 f
->tool_bar_items
= new_tool_bar
;
9437 f
->n_tool_bar_items
= new_n_tool_bar
;
9438 w
->update_mode_line
= Qt
;
9444 unbind_to (count
, Qnil
);
9445 set_buffer_internal_1 (prev
);
9451 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9452 F's desired tool-bar contents. F->tool_bar_items must have
9453 been set up previously by calling prepare_menu_bars. */
9456 build_desired_tool_bar_string (f
)
9459 int i
, size
, size_needed
;
9460 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9461 Lisp_Object image
, plist
, props
;
9463 image
= plist
= props
= Qnil
;
9464 GCPRO3 (image
, plist
, props
);
9466 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9467 Otherwise, make a new string. */
9469 /* The size of the string we might be able to reuse. */
9470 size
= (STRINGP (f
->desired_tool_bar_string
)
9471 ? SCHARS (f
->desired_tool_bar_string
)
9474 /* We need one space in the string for each image. */
9475 size_needed
= f
->n_tool_bar_items
;
9477 /* Reuse f->desired_tool_bar_string, if possible. */
9478 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9479 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9483 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9484 Fremove_text_properties (make_number (0), make_number (size
),
9485 props
, f
->desired_tool_bar_string
);
9488 /* Put a `display' property on the string for the images to display,
9489 put a `menu_item' property on tool-bar items with a value that
9490 is the index of the item in F's tool-bar item vector. */
9491 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9493 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9495 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9496 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9497 int hmargin
, vmargin
, relief
, idx
, end
;
9498 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9500 /* If image is a vector, choose the image according to the
9502 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9503 if (VECTORP (image
))
9507 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9508 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9511 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9512 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9514 xassert (ASIZE (image
) >= idx
);
9515 image
= AREF (image
, idx
);
9520 /* Ignore invalid image specifications. */
9521 if (!valid_image_p (image
))
9524 /* Display the tool-bar button pressed, or depressed. */
9525 plist
= Fcopy_sequence (XCDR (image
));
9527 /* Compute margin and relief to draw. */
9528 relief
= (tool_bar_button_relief
>= 0
9529 ? tool_bar_button_relief
9530 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9531 hmargin
= vmargin
= relief
;
9533 if (INTEGERP (Vtool_bar_button_margin
)
9534 && XINT (Vtool_bar_button_margin
) > 0)
9536 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9537 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9539 else if (CONSP (Vtool_bar_button_margin
))
9541 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9542 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9543 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9545 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9546 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9547 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9550 if (auto_raise_tool_bar_buttons_p
)
9552 /* Add a `:relief' property to the image spec if the item is
9556 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9563 /* If image is selected, display it pressed, i.e. with a
9564 negative relief. If it's not selected, display it with a
9566 plist
= Fplist_put (plist
, QCrelief
,
9568 ? make_number (-relief
)
9569 : make_number (relief
)));
9574 /* Put a margin around the image. */
9575 if (hmargin
|| vmargin
)
9577 if (hmargin
== vmargin
)
9578 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9580 plist
= Fplist_put (plist
, QCmargin
,
9581 Fcons (make_number (hmargin
),
9582 make_number (vmargin
)));
9585 /* If button is not enabled, and we don't have special images
9586 for the disabled state, make the image appear disabled by
9587 applying an appropriate algorithm to it. */
9588 if (!enabled_p
&& idx
< 0)
9589 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9591 /* Put a `display' text property on the string for the image to
9592 display. Put a `menu-item' property on the string that gives
9593 the start of this item's properties in the tool-bar items
9595 image
= Fcons (Qimage
, plist
);
9596 props
= list4 (Qdisplay
, image
,
9597 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9599 /* Let the last image hide all remaining spaces in the tool bar
9600 string. The string can be longer than needed when we reuse a
9602 if (i
+ 1 == f
->n_tool_bar_items
)
9603 end
= SCHARS (f
->desired_tool_bar_string
);
9606 Fadd_text_properties (make_number (i
), make_number (end
),
9607 props
, f
->desired_tool_bar_string
);
9615 /* Display one line of the tool-bar of frame IT->f.
9617 HEIGHT specifies the desired height of the tool-bar line.
9618 If the actual height of the glyph row is less than HEIGHT, the
9619 row's height is increased to HEIGHT, and the icons are centered
9620 vertically in the new height.
9622 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
9623 count a final empty row in case the tool-bar width exactly matches
9628 display_tool_bar_line (it
, height
)
9632 struct glyph_row
*row
= it
->glyph_row
;
9633 int max_x
= it
->last_visible_x
;
9636 prepare_desired_row (row
);
9637 row
->y
= it
->current_y
;
9639 /* Note that this isn't made use of if the face hasn't a box,
9640 so there's no need to check the face here. */
9641 it
->start_of_box_run_p
= 1;
9643 while (it
->current_x
< max_x
)
9645 int x
, n_glyphs_before
, i
, nglyphs
;
9646 struct it it_before
;
9648 /* Get the next display element. */
9649 if (!get_next_display_element (it
))
9651 /* Don't count empty row if we are counting needed tool-bar lines. */
9652 if (height
< 0 && !it
->hpos
)
9657 /* Produce glyphs. */
9658 n_glyphs_before
= row
->used
[TEXT_AREA
];
9661 PRODUCE_GLYPHS (it
);
9663 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
9665 x
= it_before
.current_x
;
9668 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9670 if (x
+ glyph
->pixel_width
> max_x
)
9672 /* Glyph doesn't fit on line. Backtrack. */
9673 row
->used
[TEXT_AREA
] = n_glyphs_before
;
9675 /* If this is the only glyph on this line, it will never fit on the
9676 toolbar, so skip it. But ensure there is at least one glyph,
9677 so we don't accidentally disable the tool-bar. */
9678 if (n_glyphs_before
== 0
9679 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
9685 x
+= glyph
->pixel_width
;
9689 /* Stop at line ends. */
9690 if (ITERATOR_AT_END_OF_LINE_P (it
))
9693 set_iterator_to_next (it
, 1);
9698 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9700 /* Use default face for the border below the tool bar.
9702 FIXME: When auto-resize-tool-bars is grow-only, there is
9703 no additional border below the possibly empty tool-bar lines.
9704 So to make the extra empty lines look "normal", we have to
9705 use the tool-bar face for the border too. */
9706 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
9707 it
->face_id
= DEFAULT_FACE_ID
;
9709 extend_face_to_end_of_line (it
);
9710 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9711 last
->right_box_line_p
= 1;
9712 if (last
== row
->glyphs
[TEXT_AREA
])
9713 last
->left_box_line_p
= 1;
9715 /* Make line the desired height and center it vertically. */
9716 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
9718 /* Don't add more than one line height. */
9719 height
%= FRAME_LINE_HEIGHT (it
->f
);
9720 it
->max_ascent
+= height
/ 2;
9721 it
->max_descent
+= (height
+ 1) / 2;
9724 compute_line_metrics (it
);
9726 /* If line is empty, make it occupy the rest of the tool-bar. */
9727 if (!row
->displays_text_p
)
9729 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9730 row
->visible_height
= row
->height
;
9731 row
->ascent
= row
->phys_ascent
= 0;
9732 row
->extra_line_spacing
= 0;
9735 row
->full_width_p
= 1;
9736 row
->continued_p
= 0;
9737 row
->truncated_on_left_p
= 0;
9738 row
->truncated_on_right_p
= 0;
9740 it
->current_x
= it
->hpos
= 0;
9741 it
->current_y
+= row
->height
;
9747 /* Max tool-bar height. */
9749 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
9750 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
9752 /* Value is the number of screen lines needed to make all tool-bar
9753 items of frame F visible. The number of actual rows needed is
9754 returned in *N_ROWS if non-NULL. */
9757 tool_bar_lines_needed (f
, n_rows
)
9761 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9763 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
9764 the desired matrix, so use (unused) mode-line row as temporary row to
9765 avoid destroying the first tool-bar row. */
9766 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
9768 /* Initialize an iterator for iteration over
9769 F->desired_tool_bar_string in the tool-bar window of frame F. */
9770 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
9771 it
.first_visible_x
= 0;
9772 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9773 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9775 while (!ITERATOR_AT_END_P (&it
))
9777 clear_glyph_row (temp_row
);
9778 it
.glyph_row
= temp_row
;
9779 display_tool_bar_line (&it
, -1);
9781 clear_glyph_row (temp_row
);
9783 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
9785 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
9787 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9791 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9793 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9802 frame
= selected_frame
;
9804 CHECK_FRAME (frame
);
9807 if (WINDOWP (f
->tool_bar_window
)
9808 || (w
= XWINDOW (f
->tool_bar_window
),
9809 WINDOW_TOTAL_LINES (w
) > 0))
9811 update_tool_bar (f
, 1);
9812 if (f
->n_tool_bar_items
)
9814 build_desired_tool_bar_string (f
);
9815 nlines
= tool_bar_lines_needed (f
, NULL
);
9819 return make_number (nlines
);
9823 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9824 height should be changed. */
9827 redisplay_tool_bar (f
)
9832 struct glyph_row
*row
;
9835 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9836 update_frame_tool_bar (f
);
9840 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9841 do anything. This means you must start with tool-bar-lines
9842 non-zero to get the auto-sizing effect. Or in other words, you
9843 can turn off tool-bars by specifying tool-bar-lines zero. */
9844 if (!WINDOWP (f
->tool_bar_window
)
9845 || (w
= XWINDOW (f
->tool_bar_window
),
9846 WINDOW_TOTAL_LINES (w
) == 0))
9849 /* Set up an iterator for the tool-bar window. */
9850 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9851 it
.first_visible_x
= 0;
9852 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9855 /* Build a string that represents the contents of the tool-bar. */
9856 build_desired_tool_bar_string (f
);
9857 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9859 if (f
->n_tool_bar_rows
== 0)
9863 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
9864 nlines
!= WINDOW_TOTAL_LINES (w
)))
9866 extern Lisp_Object Qtool_bar_lines
;
9868 int old_height
= WINDOW_TOTAL_LINES (w
);
9870 XSETFRAME (frame
, f
);
9871 Fmodify_frame_parameters (frame
,
9872 Fcons (Fcons (Qtool_bar_lines
,
9873 make_number (nlines
)),
9875 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9877 clear_glyph_matrix (w
->desired_matrix
);
9878 fonts_changed_p
= 1;
9884 /* Display as many lines as needed to display all tool-bar items. */
9886 if (f
->n_tool_bar_rows
> 0)
9888 int border
, rows
, height
, extra
;
9890 if (INTEGERP (Vtool_bar_border
))
9891 border
= XINT (Vtool_bar_border
);
9892 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
9893 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
9894 else if (EQ (Vtool_bar_border
, Qborder_width
))
9895 border
= f
->border_width
;
9901 rows
= f
->n_tool_bar_rows
;
9902 height
= max (1, (it
.last_visible_y
- border
) / rows
);
9903 extra
= it
.last_visible_y
- border
- height
* rows
;
9905 while (it
.current_y
< it
.last_visible_y
)
9908 if (extra
> 0 && rows
-- > 0)
9910 h
= (extra
+ rows
- 1) / rows
;
9913 display_tool_bar_line (&it
, height
+ h
);
9918 while (it
.current_y
< it
.last_visible_y
)
9919 display_tool_bar_line (&it
, 0);
9922 /* It doesn't make much sense to try scrolling in the tool-bar
9923 window, so don't do it. */
9924 w
->desired_matrix
->no_scrolling_p
= 1;
9925 w
->must_be_updated_p
= 1;
9927 if (!NILP (Vauto_resize_tool_bars
))
9929 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
9930 int change_height_p
= 0;
9932 /* If we couldn't display everything, change the tool-bar's
9933 height if there is room for more. */
9934 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
9935 && it
.current_y
< max_tool_bar_height
)
9936 change_height_p
= 1;
9938 row
= it
.glyph_row
- 1;
9940 /* If there are blank lines at the end, except for a partially
9941 visible blank line at the end that is smaller than
9942 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9943 if (!row
->displays_text_p
9944 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9945 change_height_p
= 1;
9947 /* If row displays tool-bar items, but is partially visible,
9948 change the tool-bar's height. */
9949 if (row
->displays_text_p
9950 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
9951 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
9952 change_height_p
= 1;
9954 /* Resize windows as needed by changing the `tool-bar-lines'
9956 if (change_height_p
)
9958 extern Lisp_Object Qtool_bar_lines
;
9960 int old_height
= WINDOW_TOTAL_LINES (w
);
9962 int nlines
= tool_bar_lines_needed (f
, &nrows
);
9964 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
9965 && !f
->minimize_tool_bar_window_p
)
9966 ? (nlines
> old_height
)
9967 : (nlines
!= old_height
));
9968 f
->minimize_tool_bar_window_p
= 0;
9970 if (change_height_p
)
9972 XSETFRAME (frame
, f
);
9973 Fmodify_frame_parameters (frame
,
9974 Fcons (Fcons (Qtool_bar_lines
,
9975 make_number (nlines
)),
9977 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9979 clear_glyph_matrix (w
->desired_matrix
);
9980 f
->n_tool_bar_rows
= nrows
;
9981 fonts_changed_p
= 1;
9988 f
->minimize_tool_bar_window_p
= 0;
9993 /* Get information about the tool-bar item which is displayed in GLYPH
9994 on frame F. Return in *PROP_IDX the index where tool-bar item
9995 properties start in F->tool_bar_items. Value is zero if
9996 GLYPH doesn't display a tool-bar item. */
9999 tool_bar_item_info (f
, glyph
, prop_idx
)
10001 struct glyph
*glyph
;
10008 /* This function can be called asynchronously, which means we must
10009 exclude any possibility that Fget_text_property signals an
10011 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10012 charpos
= max (0, charpos
);
10014 /* Get the text property `menu-item' at pos. The value of that
10015 property is the start index of this item's properties in
10016 F->tool_bar_items. */
10017 prop
= Fget_text_property (make_number (charpos
),
10018 Qmenu_item
, f
->current_tool_bar_string
);
10019 if (INTEGERP (prop
))
10021 *prop_idx
= XINT (prop
);
10031 /* Get information about the tool-bar item at position X/Y on frame F.
10032 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10033 the current matrix of the tool-bar window of F, or NULL if not
10034 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10035 item in F->tool_bar_items. Value is
10037 -1 if X/Y is not on a tool-bar item
10038 0 if X/Y is on the same item that was highlighted before.
10042 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10045 struct glyph
**glyph
;
10046 int *hpos
, *vpos
, *prop_idx
;
10048 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10049 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10052 /* Find the glyph under X/Y. */
10053 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10054 if (*glyph
== NULL
)
10057 /* Get the start of this tool-bar item's properties in
10058 f->tool_bar_items. */
10059 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10062 /* Is mouse on the highlighted item? */
10063 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10064 && *vpos
>= dpyinfo
->mouse_face_beg_row
10065 && *vpos
<= dpyinfo
->mouse_face_end_row
10066 && (*vpos
> dpyinfo
->mouse_face_beg_row
10067 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10068 && (*vpos
< dpyinfo
->mouse_face_end_row
10069 || *hpos
< dpyinfo
->mouse_face_end_col
10070 || dpyinfo
->mouse_face_past_end
))
10078 Handle mouse button event on the tool-bar of frame F, at
10079 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10080 0 for button release. MODIFIERS is event modifiers for button
10084 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10087 unsigned int modifiers
;
10089 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10090 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10091 int hpos
, vpos
, prop_idx
;
10092 struct glyph
*glyph
;
10093 Lisp_Object enabled_p
;
10095 /* If not on the highlighted tool-bar item, return. */
10096 frame_to_window_pixel_xy (w
, &x
, &y
);
10097 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10100 /* If item is disabled, do nothing. */
10101 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10102 if (NILP (enabled_p
))
10107 /* Show item in pressed state. */
10108 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10109 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10110 last_tool_bar_item
= prop_idx
;
10114 Lisp_Object key
, frame
;
10115 struct input_event event
;
10116 EVENT_INIT (event
);
10118 /* Show item in released state. */
10119 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10120 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10122 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10124 XSETFRAME (frame
, f
);
10125 event
.kind
= TOOL_BAR_EVENT
;
10126 event
.frame_or_window
= frame
;
10128 kbd_buffer_store_event (&event
);
10130 event
.kind
= TOOL_BAR_EVENT
;
10131 event
.frame_or_window
= frame
;
10133 event
.modifiers
= modifiers
;
10134 kbd_buffer_store_event (&event
);
10135 last_tool_bar_item
= -1;
10140 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10141 tool-bar window-relative coordinates X/Y. Called from
10142 note_mouse_highlight. */
10145 note_tool_bar_highlight (f
, x
, y
)
10149 Lisp_Object window
= f
->tool_bar_window
;
10150 struct window
*w
= XWINDOW (window
);
10151 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10153 struct glyph
*glyph
;
10154 struct glyph_row
*row
;
10156 Lisp_Object enabled_p
;
10158 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10159 int mouse_down_p
, rc
;
10161 /* Function note_mouse_highlight is called with negative x(y
10162 values when mouse moves outside of the frame. */
10163 if (x
<= 0 || y
<= 0)
10165 clear_mouse_face (dpyinfo
);
10169 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10172 /* Not on tool-bar item. */
10173 clear_mouse_face (dpyinfo
);
10177 /* On same tool-bar item as before. */
10178 goto set_help_echo
;
10180 clear_mouse_face (dpyinfo
);
10182 /* Mouse is down, but on different tool-bar item? */
10183 mouse_down_p
= (dpyinfo
->grabbed
10184 && f
== last_mouse_frame
10185 && FRAME_LIVE_P (f
));
10187 && last_tool_bar_item
!= prop_idx
)
10190 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10191 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10193 /* If tool-bar item is not enabled, don't highlight it. */
10194 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10195 if (!NILP (enabled_p
))
10197 /* Compute the x-position of the glyph. In front and past the
10198 image is a space. We include this in the highlighted area. */
10199 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10200 for (i
= x
= 0; i
< hpos
; ++i
)
10201 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10203 /* Record this as the current active region. */
10204 dpyinfo
->mouse_face_beg_col
= hpos
;
10205 dpyinfo
->mouse_face_beg_row
= vpos
;
10206 dpyinfo
->mouse_face_beg_x
= x
;
10207 dpyinfo
->mouse_face_beg_y
= row
->y
;
10208 dpyinfo
->mouse_face_past_end
= 0;
10210 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10211 dpyinfo
->mouse_face_end_row
= vpos
;
10212 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10213 dpyinfo
->mouse_face_end_y
= row
->y
;
10214 dpyinfo
->mouse_face_window
= window
;
10215 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10217 /* Display it as active. */
10218 show_mouse_face (dpyinfo
, draw
);
10219 dpyinfo
->mouse_face_image_state
= draw
;
10224 /* Set help_echo_string to a help string to display for this tool-bar item.
10225 XTread_socket does the rest. */
10226 help_echo_object
= help_echo_window
= Qnil
;
10227 help_echo_pos
= -1;
10228 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10229 if (NILP (help_echo_string
))
10230 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10233 #endif /* HAVE_WINDOW_SYSTEM */
10237 /************************************************************************
10238 Horizontal scrolling
10239 ************************************************************************/
10241 static int hscroll_window_tree
P_ ((Lisp_Object
));
10242 static int hscroll_windows
P_ ((Lisp_Object
));
10244 /* For all leaf windows in the window tree rooted at WINDOW, set their
10245 hscroll value so that PT is (i) visible in the window, and (ii) so
10246 that it is not within a certain margin at the window's left and
10247 right border. Value is non-zero if any window's hscroll has been
10251 hscroll_window_tree (window
)
10252 Lisp_Object window
;
10254 int hscrolled_p
= 0;
10255 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10256 int hscroll_step_abs
= 0;
10257 double hscroll_step_rel
= 0;
10259 if (hscroll_relative_p
)
10261 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10262 if (hscroll_step_rel
< 0)
10264 hscroll_relative_p
= 0;
10265 hscroll_step_abs
= 0;
10268 else if (INTEGERP (Vhscroll_step
))
10270 hscroll_step_abs
= XINT (Vhscroll_step
);
10271 if (hscroll_step_abs
< 0)
10272 hscroll_step_abs
= 0;
10275 hscroll_step_abs
= 0;
10277 while (WINDOWP (window
))
10279 struct window
*w
= XWINDOW (window
);
10281 if (WINDOWP (w
->hchild
))
10282 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10283 else if (WINDOWP (w
->vchild
))
10284 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10285 else if (w
->cursor
.vpos
>= 0)
10288 int text_area_width
;
10289 struct glyph_row
*current_cursor_row
10290 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10291 struct glyph_row
*desired_cursor_row
10292 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10293 struct glyph_row
*cursor_row
10294 = (desired_cursor_row
->enabled_p
10295 ? desired_cursor_row
10296 : current_cursor_row
);
10298 text_area_width
= window_box_width (w
, TEXT_AREA
);
10300 /* Scroll when cursor is inside this scroll margin. */
10301 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10303 if ((XFASTINT (w
->hscroll
)
10304 && w
->cursor
.x
<= h_margin
)
10305 || (cursor_row
->enabled_p
10306 && cursor_row
->truncated_on_right_p
10307 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
10311 struct buffer
*saved_current_buffer
;
10315 /* Find point in a display of infinite width. */
10316 saved_current_buffer
= current_buffer
;
10317 current_buffer
= XBUFFER (w
->buffer
);
10319 if (w
== XWINDOW (selected_window
))
10320 pt
= BUF_PT (current_buffer
);
10323 pt
= marker_position (w
->pointm
);
10324 pt
= max (BEGV
, pt
);
10328 /* Move iterator to pt starting at cursor_row->start in
10329 a line with infinite width. */
10330 init_to_row_start (&it
, w
, cursor_row
);
10331 it
.last_visible_x
= INFINITY
;
10332 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10333 current_buffer
= saved_current_buffer
;
10335 /* Position cursor in window. */
10336 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10337 hscroll
= max (0, (it
.current_x
10338 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10339 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10340 : (text_area_width
/ 2))))
10341 / FRAME_COLUMN_WIDTH (it
.f
);
10342 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10344 if (hscroll_relative_p
)
10345 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10348 wanted_x
= text_area_width
10349 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10352 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10356 if (hscroll_relative_p
)
10357 wanted_x
= text_area_width
* hscroll_step_rel
10360 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10363 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10365 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10367 /* Don't call Fset_window_hscroll if value hasn't
10368 changed because it will prevent redisplay
10370 if (XFASTINT (w
->hscroll
) != hscroll
)
10372 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10373 w
->hscroll
= make_number (hscroll
);
10382 /* Value is non-zero if hscroll of any leaf window has been changed. */
10383 return hscrolled_p
;
10387 /* Set hscroll so that cursor is visible and not inside horizontal
10388 scroll margins for all windows in the tree rooted at WINDOW. See
10389 also hscroll_window_tree above. Value is non-zero if any window's
10390 hscroll has been changed. If it has, desired matrices on the frame
10391 of WINDOW are cleared. */
10394 hscroll_windows (window
)
10395 Lisp_Object window
;
10399 if (automatic_hscrolling_p
)
10401 hscrolled_p
= hscroll_window_tree (window
);
10403 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10407 return hscrolled_p
;
10412 /************************************************************************
10414 ************************************************************************/
10416 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10417 to a non-zero value. This is sometimes handy to have in a debugger
10422 /* First and last unchanged row for try_window_id. */
10424 int debug_first_unchanged_at_end_vpos
;
10425 int debug_last_unchanged_at_beg_vpos
;
10427 /* Delta vpos and y. */
10429 int debug_dvpos
, debug_dy
;
10431 /* Delta in characters and bytes for try_window_id. */
10433 int debug_delta
, debug_delta_bytes
;
10435 /* Values of window_end_pos and window_end_vpos at the end of
10438 EMACS_INT debug_end_pos
, debug_end_vpos
;
10440 /* Append a string to W->desired_matrix->method. FMT is a printf
10441 format string. A1...A9 are a supplement for a variable-length
10442 argument list. If trace_redisplay_p is non-zero also printf the
10443 resulting string to stderr. */
10446 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10449 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10452 char *method
= w
->desired_matrix
->method
;
10453 int len
= strlen (method
);
10454 int size
= sizeof w
->desired_matrix
->method
;
10455 int remaining
= size
- len
- 1;
10457 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10458 if (len
&& remaining
)
10461 --remaining
, ++len
;
10464 strncpy (method
+ len
, buffer
, remaining
);
10466 if (trace_redisplay_p
)
10467 fprintf (stderr
, "%p (%s): %s\n",
10469 ((BUFFERP (w
->buffer
)
10470 && STRINGP (XBUFFER (w
->buffer
)->name
))
10471 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10476 #endif /* GLYPH_DEBUG */
10479 /* Value is non-zero if all changes in window W, which displays
10480 current_buffer, are in the text between START and END. START is a
10481 buffer position, END is given as a distance from Z. Used in
10482 redisplay_internal for display optimization. */
10485 text_outside_line_unchanged_p (w
, start
, end
)
10489 int unchanged_p
= 1;
10491 /* If text or overlays have changed, see where. */
10492 if (XFASTINT (w
->last_modified
) < MODIFF
10493 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10495 /* Gap in the line? */
10496 if (GPT
< start
|| Z
- GPT
< end
)
10499 /* Changes start in front of the line, or end after it? */
10501 && (BEG_UNCHANGED
< start
- 1
10502 || END_UNCHANGED
< end
))
10505 /* If selective display, can't optimize if changes start at the
10506 beginning of the line. */
10508 && INTEGERP (current_buffer
->selective_display
)
10509 && XINT (current_buffer
->selective_display
) > 0
10510 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10513 /* If there are overlays at the start or end of the line, these
10514 may have overlay strings with newlines in them. A change at
10515 START, for instance, may actually concern the display of such
10516 overlay strings as well, and they are displayed on different
10517 lines. So, quickly rule out this case. (For the future, it
10518 might be desirable to implement something more telling than
10519 just BEG/END_UNCHANGED.) */
10522 if (BEG
+ BEG_UNCHANGED
== start
10523 && overlay_touches_p (start
))
10525 if (END_UNCHANGED
== end
10526 && overlay_touches_p (Z
- end
))
10531 return unchanged_p
;
10535 /* Do a frame update, taking possible shortcuts into account. This is
10536 the main external entry point for redisplay.
10538 If the last redisplay displayed an echo area message and that message
10539 is no longer requested, we clear the echo area or bring back the
10540 mini-buffer if that is in use. */
10545 redisplay_internal (0);
10550 overlay_arrow_string_or_property (var
)
10555 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10558 return Voverlay_arrow_string
;
10561 /* Return 1 if there are any overlay-arrows in current_buffer. */
10563 overlay_arrow_in_current_buffer_p ()
10567 for (vlist
= Voverlay_arrow_variable_list
;
10569 vlist
= XCDR (vlist
))
10571 Lisp_Object var
= XCAR (vlist
);
10574 if (!SYMBOLP (var
))
10576 val
= find_symbol_value (var
);
10578 && current_buffer
== XMARKER (val
)->buffer
)
10585 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
10589 overlay_arrows_changed_p ()
10593 for (vlist
= Voverlay_arrow_variable_list
;
10595 vlist
= XCDR (vlist
))
10597 Lisp_Object var
= XCAR (vlist
);
10598 Lisp_Object val
, pstr
;
10600 if (!SYMBOLP (var
))
10602 val
= find_symbol_value (var
);
10603 if (!MARKERP (val
))
10605 if (! EQ (COERCE_MARKER (val
),
10606 Fget (var
, Qlast_arrow_position
))
10607 || ! (pstr
= overlay_arrow_string_or_property (var
),
10608 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
10614 /* Mark overlay arrows to be updated on next redisplay. */
10617 update_overlay_arrows (up_to_date
)
10622 for (vlist
= Voverlay_arrow_variable_list
;
10624 vlist
= XCDR (vlist
))
10626 Lisp_Object var
= XCAR (vlist
);
10628 if (!SYMBOLP (var
))
10631 if (up_to_date
> 0)
10633 Lisp_Object val
= find_symbol_value (var
);
10634 Fput (var
, Qlast_arrow_position
,
10635 COERCE_MARKER (val
));
10636 Fput (var
, Qlast_arrow_string
,
10637 overlay_arrow_string_or_property (var
));
10639 else if (up_to_date
< 0
10640 || !NILP (Fget (var
, Qlast_arrow_position
)))
10642 Fput (var
, Qlast_arrow_position
, Qt
);
10643 Fput (var
, Qlast_arrow_string
, Qt
);
10649 /* Return overlay arrow string to display at row.
10650 Return integer (bitmap number) for arrow bitmap in left fringe.
10651 Return nil if no overlay arrow. */
10654 overlay_arrow_at_row (it
, row
)
10656 struct glyph_row
*row
;
10660 for (vlist
= Voverlay_arrow_variable_list
;
10662 vlist
= XCDR (vlist
))
10664 Lisp_Object var
= XCAR (vlist
);
10667 if (!SYMBOLP (var
))
10670 val
= find_symbol_value (var
);
10673 && current_buffer
== XMARKER (val
)->buffer
10674 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10676 if (FRAME_WINDOW_P (it
->f
)
10677 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10679 #ifdef HAVE_WINDOW_SYSTEM
10680 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10683 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10684 return make_number (fringe_bitmap
);
10687 return make_number (-1); /* Use default arrow bitmap */
10689 return overlay_arrow_string_or_property (var
);
10696 /* Return 1 if point moved out of or into a composition. Otherwise
10697 return 0. PREV_BUF and PREV_PT are the last point buffer and
10698 position. BUF and PT are the current point buffer and position. */
10701 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10702 struct buffer
*prev_buf
, *buf
;
10707 Lisp_Object buffer
;
10709 XSETBUFFER (buffer
, buf
);
10710 /* Check a composition at the last point if point moved within the
10712 if (prev_buf
== buf
)
10715 /* Point didn't move. */
10718 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10719 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10720 && COMPOSITION_VALID_P (start
, end
, prop
)
10721 && start
< prev_pt
&& end
> prev_pt
)
10722 /* The last point was within the composition. Return 1 iff
10723 point moved out of the composition. */
10724 return (pt
<= start
|| pt
>= end
);
10727 /* Check a composition at the current point. */
10728 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10729 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10730 && COMPOSITION_VALID_P (start
, end
, prop
)
10731 && start
< pt
&& end
> pt
);
10735 /* Reconsider the setting of B->clip_changed which is displayed
10739 reconsider_clip_changes (w
, b
)
10743 if (b
->clip_changed
10744 && !NILP (w
->window_end_valid
)
10745 && w
->current_matrix
->buffer
== b
10746 && w
->current_matrix
->zv
== BUF_ZV (b
)
10747 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10748 b
->clip_changed
= 0;
10750 /* If display wasn't paused, and W is not a tool bar window, see if
10751 point has been moved into or out of a composition. In that case,
10752 we set b->clip_changed to 1 to force updating the screen. If
10753 b->clip_changed has already been set to 1, we can skip this
10755 if (!b
->clip_changed
10756 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10760 if (w
== XWINDOW (selected_window
))
10761 pt
= BUF_PT (current_buffer
);
10763 pt
= marker_position (w
->pointm
);
10765 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10766 || pt
!= XINT (w
->last_point
))
10767 && check_point_in_composition (w
->current_matrix
->buffer
,
10768 XINT (w
->last_point
),
10769 XBUFFER (w
->buffer
), pt
))
10770 b
->clip_changed
= 1;
10775 /* Select FRAME to forward the values of frame-local variables into C
10776 variables so that the redisplay routines can access those values
10780 select_frame_for_redisplay (frame
)
10783 Lisp_Object tail
, sym
, val
;
10784 Lisp_Object old
= selected_frame
;
10786 selected_frame
= frame
;
10788 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10789 if (CONSP (XCAR (tail
))
10790 && (sym
= XCAR (XCAR (tail
)),
10792 && (sym
= indirect_variable (sym
),
10793 val
= SYMBOL_VALUE (sym
),
10794 (BUFFER_LOCAL_VALUEP (val
)
10795 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10796 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10797 /* Use find_symbol_value rather than Fsymbol_value
10798 to avoid an error if it is void. */
10799 find_symbol_value (sym
);
10801 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10802 if (CONSP (XCAR (tail
))
10803 && (sym
= XCAR (XCAR (tail
)),
10805 && (sym
= indirect_variable (sym
),
10806 val
= SYMBOL_VALUE (sym
),
10807 (BUFFER_LOCAL_VALUEP (val
)
10808 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10809 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10810 find_symbol_value (sym
);
10814 #define STOP_POLLING \
10815 do { if (! polling_stopped_here) stop_polling (); \
10816 polling_stopped_here = 1; } while (0)
10818 #define RESUME_POLLING \
10819 do { if (polling_stopped_here) start_polling (); \
10820 polling_stopped_here = 0; } while (0)
10823 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10824 response to any user action; therefore, we should preserve the echo
10825 area. (Actually, our caller does that job.) Perhaps in the future
10826 avoid recentering windows if it is not necessary; currently that
10827 causes some problems. */
10830 redisplay_internal (preserve_echo_area
)
10831 int preserve_echo_area
;
10833 struct window
*w
= XWINDOW (selected_window
);
10836 int must_finish
= 0;
10837 struct text_pos tlbufpos
, tlendpos
;
10838 int number_of_visible_frames
;
10841 int polling_stopped_here
= 0;
10843 /* Non-zero means redisplay has to consider all windows on all
10844 frames. Zero means, only selected_window is considered. */
10845 int consider_all_windows_p
;
10847 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10849 /* No redisplay if running in batch mode or frame is not yet fully
10850 initialized, or redisplay is explicitly turned off by setting
10851 Vinhibit_redisplay. */
10853 || !NILP (Vinhibit_redisplay
))
10856 /* Don't examine these until after testing Vinhibit_redisplay.
10857 When Emacs is shutting down, perhaps because its connection to
10858 X has dropped, we should not look at them at all. */
10859 f
= XFRAME (w
->frame
);
10860 sf
= SELECTED_FRAME ();
10862 if (!f
->glyphs_initialized_p
)
10865 /* The flag redisplay_performed_directly_p is set by
10866 direct_output_for_insert when it already did the whole screen
10867 update necessary. */
10868 if (redisplay_performed_directly_p
)
10870 redisplay_performed_directly_p
= 0;
10871 if (!hscroll_windows (selected_window
))
10875 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (MAC_OS)
10876 if (popup_activated ())
10880 /* I don't think this happens but let's be paranoid. */
10881 if (redisplaying_p
)
10884 /* Record a function that resets redisplaying_p to its old value
10885 when we leave this function. */
10886 count
= SPECPDL_INDEX ();
10887 record_unwind_protect (unwind_redisplay
,
10888 Fcons (make_number (redisplaying_p
), selected_frame
));
10890 specbind (Qinhibit_free_realized_faces
, Qnil
);
10893 Lisp_Object tail
, frame
;
10895 FOR_EACH_FRAME (tail
, frame
)
10897 struct frame
*f
= XFRAME (frame
);
10898 f
->already_hscrolled_p
= 0;
10904 reconsider_clip_changes (w
, current_buffer
);
10905 last_escape_glyph_frame
= NULL
;
10906 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
10908 /* If new fonts have been loaded that make a glyph matrix adjustment
10909 necessary, do it. */
10910 if (fonts_changed_p
)
10912 adjust_glyphs (NULL
);
10913 ++windows_or_buffers_changed
;
10914 fonts_changed_p
= 0;
10917 /* If face_change_count is non-zero, init_iterator will free all
10918 realized faces, which includes the faces referenced from current
10919 matrices. So, we can't reuse current matrices in this case. */
10920 if (face_change_count
)
10921 ++windows_or_buffers_changed
;
10923 if (! FRAME_WINDOW_P (sf
)
10924 && previous_terminal_frame
!= sf
)
10926 /* Since frames on an ASCII terminal share the same display
10927 area, displaying a different frame means redisplay the whole
10929 windows_or_buffers_changed
++;
10930 SET_FRAME_GARBAGED (sf
);
10931 XSETFRAME (Vterminal_frame
, sf
);
10933 previous_terminal_frame
= sf
;
10935 /* Set the visible flags for all frames. Do this before checking
10936 for resized or garbaged frames; they want to know if their frames
10937 are visible. See the comment in frame.h for
10938 FRAME_SAMPLE_VISIBILITY. */
10940 Lisp_Object tail
, frame
;
10942 number_of_visible_frames
= 0;
10944 FOR_EACH_FRAME (tail
, frame
)
10946 struct frame
*f
= XFRAME (frame
);
10948 FRAME_SAMPLE_VISIBILITY (f
);
10949 if (FRAME_VISIBLE_P (f
))
10950 ++number_of_visible_frames
;
10951 clear_desired_matrices (f
);
10955 /* Notice any pending interrupt request to change frame size. */
10956 do_pending_window_change (1);
10958 /* Clear frames marked as garbaged. */
10959 if (frame_garbaged
)
10960 clear_garbaged_frames ();
10962 /* Build menubar and tool-bar items. */
10963 if (NILP (Vmemory_full
))
10964 prepare_menu_bars ();
10966 if (windows_or_buffers_changed
)
10967 update_mode_lines
++;
10969 /* Detect case that we need to write or remove a star in the mode line. */
10970 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10972 w
->update_mode_line
= Qt
;
10973 if (buffer_shared
> 1)
10974 update_mode_lines
++;
10977 /* Avoid invocation of point motion hooks by `current_column' below. */
10978 count1
= SPECPDL_INDEX ();
10979 specbind (Qinhibit_point_motion_hooks
, Qt
);
10981 /* If %c is in the mode line, update it if needed. */
10982 if (!NILP (w
->column_number_displayed
)
10983 /* This alternative quickly identifies a common case
10984 where no change is needed. */
10985 && !(PT
== XFASTINT (w
->last_point
)
10986 && XFASTINT (w
->last_modified
) >= MODIFF
10987 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10988 && (XFASTINT (w
->column_number_displayed
)
10989 != (int) current_column ())) /* iftc */
10990 w
->update_mode_line
= Qt
;
10992 unbind_to (count1
, Qnil
);
10994 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10996 /* The variable buffer_shared is set in redisplay_window and
10997 indicates that we redisplay a buffer in different windows. See
10999 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11000 || cursor_type_changed
);
11002 /* If specs for an arrow have changed, do thorough redisplay
11003 to ensure we remove any arrow that should no longer exist. */
11004 if (overlay_arrows_changed_p ())
11005 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11007 /* Normally the message* functions will have already displayed and
11008 updated the echo area, but the frame may have been trashed, or
11009 the update may have been preempted, so display the echo area
11010 again here. Checking message_cleared_p captures the case that
11011 the echo area should be cleared. */
11012 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11013 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11014 || (message_cleared_p
11015 && minibuf_level
== 0
11016 /* If the mini-window is currently selected, this means the
11017 echo-area doesn't show through. */
11018 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11020 int window_height_changed_p
= echo_area_display (0);
11023 /* If we don't display the current message, don't clear the
11024 message_cleared_p flag, because, if we did, we wouldn't clear
11025 the echo area in the next redisplay which doesn't preserve
11027 if (!display_last_displayed_message_p
)
11028 message_cleared_p
= 0;
11030 if (fonts_changed_p
)
11032 else if (window_height_changed_p
)
11034 consider_all_windows_p
= 1;
11035 ++update_mode_lines
;
11036 ++windows_or_buffers_changed
;
11038 /* If window configuration was changed, frames may have been
11039 marked garbaged. Clear them or we will experience
11040 surprises wrt scrolling. */
11041 if (frame_garbaged
)
11042 clear_garbaged_frames ();
11045 else if (EQ (selected_window
, minibuf_window
)
11046 && (current_buffer
->clip_changed
11047 || XFASTINT (w
->last_modified
) < MODIFF
11048 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11049 && resize_mini_window (w
, 0))
11051 /* Resized active mini-window to fit the size of what it is
11052 showing if its contents might have changed. */
11054 consider_all_windows_p
= 1;
11055 ++windows_or_buffers_changed
;
11056 ++update_mode_lines
;
11058 /* If window configuration was changed, frames may have been
11059 marked garbaged. Clear them or we will experience
11060 surprises wrt scrolling. */
11061 if (frame_garbaged
)
11062 clear_garbaged_frames ();
11066 /* If showing the region, and mark has changed, we must redisplay
11067 the whole window. The assignment to this_line_start_pos prevents
11068 the optimization directly below this if-statement. */
11069 if (((!NILP (Vtransient_mark_mode
)
11070 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11071 != !NILP (w
->region_showing
))
11072 || (!NILP (w
->region_showing
)
11073 && !EQ (w
->region_showing
,
11074 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11075 CHARPOS (this_line_start_pos
) = 0;
11077 /* Optimize the case that only the line containing the cursor in the
11078 selected window has changed. Variables starting with this_ are
11079 set in display_line and record information about the line
11080 containing the cursor. */
11081 tlbufpos
= this_line_start_pos
;
11082 tlendpos
= this_line_end_pos
;
11083 if (!consider_all_windows_p
11084 && CHARPOS (tlbufpos
) > 0
11085 && NILP (w
->update_mode_line
)
11086 && !current_buffer
->clip_changed
11087 && !current_buffer
->prevent_redisplay_optimizations_p
11088 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11089 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11090 /* Make sure recorded data applies to current buffer, etc. */
11091 && this_line_buffer
== current_buffer
11092 && current_buffer
== XBUFFER (w
->buffer
)
11093 && NILP (w
->force_start
)
11094 && NILP (w
->optional_new_start
)
11095 /* Point must be on the line that we have info recorded about. */
11096 && PT
>= CHARPOS (tlbufpos
)
11097 && PT
<= Z
- CHARPOS (tlendpos
)
11098 /* All text outside that line, including its final newline,
11099 must be unchanged */
11100 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11101 CHARPOS (tlendpos
)))
11103 if (CHARPOS (tlbufpos
) > BEGV
11104 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11105 && (CHARPOS (tlbufpos
) == ZV
11106 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11107 /* Former continuation line has disappeared by becoming empty */
11109 else if (XFASTINT (w
->last_modified
) < MODIFF
11110 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11111 || MINI_WINDOW_P (w
))
11113 /* We have to handle the case of continuation around a
11114 wide-column character (See the comment in indent.c around
11117 For instance, in the following case:
11119 -------- Insert --------
11120 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11121 J_I_ ==> J_I_ `^^' are cursors.
11125 As we have to redraw the line above, we should goto cancel. */
11128 int line_height_before
= this_line_pixel_height
;
11130 /* Note that start_display will handle the case that the
11131 line starting at tlbufpos is a continuation lines. */
11132 start_display (&it
, w
, tlbufpos
);
11134 /* Implementation note: It this still necessary? */
11135 if (it
.current_x
!= this_line_start_x
)
11138 TRACE ((stderr
, "trying display optimization 1\n"));
11139 w
->cursor
.vpos
= -1;
11140 overlay_arrow_seen
= 0;
11141 it
.vpos
= this_line_vpos
;
11142 it
.current_y
= this_line_y
;
11143 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11144 display_line (&it
);
11146 /* If line contains point, is not continued,
11147 and ends at same distance from eob as before, we win */
11148 if (w
->cursor
.vpos
>= 0
11149 /* Line is not continued, otherwise this_line_start_pos
11150 would have been set to 0 in display_line. */
11151 && CHARPOS (this_line_start_pos
)
11152 /* Line ends as before. */
11153 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11154 /* Line has same height as before. Otherwise other lines
11155 would have to be shifted up or down. */
11156 && this_line_pixel_height
== line_height_before
)
11158 /* If this is not the window's last line, we must adjust
11159 the charstarts of the lines below. */
11160 if (it
.current_y
< it
.last_visible_y
)
11162 struct glyph_row
*row
11163 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11164 int delta
, delta_bytes
;
11166 if (Z
- CHARPOS (tlendpos
) == ZV
)
11168 /* This line ends at end of (accessible part of)
11169 buffer. There is no newline to count. */
11171 - CHARPOS (tlendpos
)
11172 - MATRIX_ROW_START_CHARPOS (row
));
11173 delta_bytes
= (Z_BYTE
11174 - BYTEPOS (tlendpos
)
11175 - MATRIX_ROW_START_BYTEPOS (row
));
11179 /* This line ends in a newline. Must take
11180 account of the newline and the rest of the
11181 text that follows. */
11183 - CHARPOS (tlendpos
)
11184 - MATRIX_ROW_START_CHARPOS (row
));
11185 delta_bytes
= (Z_BYTE
11186 - BYTEPOS (tlendpos
)
11187 - MATRIX_ROW_START_BYTEPOS (row
));
11190 increment_matrix_positions (w
->current_matrix
,
11191 this_line_vpos
+ 1,
11192 w
->current_matrix
->nrows
,
11193 delta
, delta_bytes
);
11196 /* If this row displays text now but previously didn't,
11197 or vice versa, w->window_end_vpos may have to be
11199 if ((it
.glyph_row
- 1)->displays_text_p
)
11201 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11202 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11204 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11205 && this_line_vpos
> 0)
11206 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11207 w
->window_end_valid
= Qnil
;
11209 /* Update hint: No need to try to scroll in update_window. */
11210 w
->desired_matrix
->no_scrolling_p
= 1;
11213 *w
->desired_matrix
->method
= 0;
11214 debug_method_add (w
, "optimization 1");
11216 #ifdef HAVE_WINDOW_SYSTEM
11217 update_window_fringes (w
, 0);
11224 else if (/* Cursor position hasn't changed. */
11225 PT
== XFASTINT (w
->last_point
)
11226 /* Make sure the cursor was last displayed
11227 in this window. Otherwise we have to reposition it. */
11228 && 0 <= w
->cursor
.vpos
11229 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11233 do_pending_window_change (1);
11235 /* We used to always goto end_of_redisplay here, but this
11236 isn't enough if we have a blinking cursor. */
11237 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11238 goto end_of_redisplay
;
11242 /* If highlighting the region, or if the cursor is in the echo area,
11243 then we can't just move the cursor. */
11244 else if (! (!NILP (Vtransient_mark_mode
)
11245 && !NILP (current_buffer
->mark_active
))
11246 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11247 || highlight_nonselected_windows
)
11248 && NILP (w
->region_showing
)
11249 && NILP (Vshow_trailing_whitespace
)
11250 && !cursor_in_echo_area
)
11253 struct glyph_row
*row
;
11255 /* Skip from tlbufpos to PT and see where it is. Note that
11256 PT may be in invisible text. If so, we will end at the
11257 next visible position. */
11258 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11259 NULL
, DEFAULT_FACE_ID
);
11260 it
.current_x
= this_line_start_x
;
11261 it
.current_y
= this_line_y
;
11262 it
.vpos
= this_line_vpos
;
11264 /* The call to move_it_to stops in front of PT, but
11265 moves over before-strings. */
11266 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11268 if (it
.vpos
== this_line_vpos
11269 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11272 xassert (this_line_vpos
== it
.vpos
);
11273 xassert (this_line_y
== it
.current_y
);
11274 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11276 *w
->desired_matrix
->method
= 0;
11277 debug_method_add (w
, "optimization 3");
11286 /* Text changed drastically or point moved off of line. */
11287 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11290 CHARPOS (this_line_start_pos
) = 0;
11291 consider_all_windows_p
|= buffer_shared
> 1;
11292 ++clear_face_cache_count
;
11293 #ifdef HAVE_WINDOW_SYSTEM
11294 ++clear_image_cache_count
;
11297 /* Build desired matrices, and update the display. If
11298 consider_all_windows_p is non-zero, do it for all windows on all
11299 frames. Otherwise do it for selected_window, only. */
11301 if (consider_all_windows_p
)
11303 Lisp_Object tail
, frame
;
11305 FOR_EACH_FRAME (tail
, frame
)
11306 XFRAME (frame
)->updated_p
= 0;
11308 /* Recompute # windows showing selected buffer. This will be
11309 incremented each time such a window is displayed. */
11312 FOR_EACH_FRAME (tail
, frame
)
11314 struct frame
*f
= XFRAME (frame
);
11316 if (FRAME_WINDOW_P (f
) || f
== sf
)
11318 if (! EQ (frame
, selected_frame
))
11319 /* Select the frame, for the sake of frame-local
11321 select_frame_for_redisplay (frame
);
11323 /* Mark all the scroll bars to be removed; we'll redeem
11324 the ones we want when we redisplay their windows. */
11325 if (condemn_scroll_bars_hook
)
11326 condemn_scroll_bars_hook (f
);
11328 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11329 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11331 /* Any scroll bars which redisplay_windows should have
11332 nuked should now go away. */
11333 if (judge_scroll_bars_hook
)
11334 judge_scroll_bars_hook (f
);
11336 /* If fonts changed, display again. */
11337 /* ??? rms: I suspect it is a mistake to jump all the way
11338 back to retry here. It should just retry this frame. */
11339 if (fonts_changed_p
)
11342 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11344 /* See if we have to hscroll. */
11345 if (!f
->already_hscrolled_p
)
11347 f
->already_hscrolled_p
= 1;
11348 if (hscroll_windows (f
->root_window
))
11352 /* Prevent various kinds of signals during display
11353 update. stdio is not robust about handling
11354 signals, which can cause an apparent I/O
11356 if (interrupt_input
)
11357 unrequest_sigio ();
11360 /* Update the display. */
11361 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11362 pause
|= update_frame (f
, 0, 0);
11363 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
11375 /* Do the mark_window_display_accurate after all windows have
11376 been redisplayed because this call resets flags in buffers
11377 which are needed for proper redisplay. */
11378 FOR_EACH_FRAME (tail
, frame
)
11380 struct frame
*f
= XFRAME (frame
);
11383 mark_window_display_accurate (f
->root_window
, 1);
11384 if (frame_up_to_date_hook
)
11385 frame_up_to_date_hook (f
);
11390 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11392 Lisp_Object mini_window
;
11393 struct frame
*mini_frame
;
11395 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11396 /* Use list_of_error, not Qerror, so that
11397 we catch only errors and don't run the debugger. */
11398 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11400 redisplay_window_error
);
11402 /* Compare desired and current matrices, perform output. */
11405 /* If fonts changed, display again. */
11406 if (fonts_changed_p
)
11409 /* Prevent various kinds of signals during display update.
11410 stdio is not robust about handling signals,
11411 which can cause an apparent I/O error. */
11412 if (interrupt_input
)
11413 unrequest_sigio ();
11416 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11418 if (hscroll_windows (selected_window
))
11421 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11422 pause
= update_frame (sf
, 0, 0);
11425 /* We may have called echo_area_display at the top of this
11426 function. If the echo area is on another frame, that may
11427 have put text on a frame other than the selected one, so the
11428 above call to update_frame would not have caught it. Catch
11430 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11431 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11433 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11435 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11436 pause
|= update_frame (mini_frame
, 0, 0);
11437 if (!pause
&& hscroll_windows (mini_window
))
11442 /* If display was paused because of pending input, make sure we do a
11443 thorough update the next time. */
11446 /* Prevent the optimization at the beginning of
11447 redisplay_internal that tries a single-line update of the
11448 line containing the cursor in the selected window. */
11449 CHARPOS (this_line_start_pos
) = 0;
11451 /* Let the overlay arrow be updated the next time. */
11452 update_overlay_arrows (0);
11454 /* If we pause after scrolling, some rows in the current
11455 matrices of some windows are not valid. */
11456 if (!WINDOW_FULL_WIDTH_P (w
)
11457 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11458 update_mode_lines
= 1;
11462 if (!consider_all_windows_p
)
11464 /* This has already been done above if
11465 consider_all_windows_p is set. */
11466 mark_window_display_accurate_1 (w
, 1);
11468 /* Say overlay arrows are up to date. */
11469 update_overlay_arrows (1);
11471 if (frame_up_to_date_hook
!= 0)
11472 frame_up_to_date_hook (sf
);
11475 update_mode_lines
= 0;
11476 windows_or_buffers_changed
= 0;
11477 cursor_type_changed
= 0;
11480 /* Start SIGIO interrupts coming again. Having them off during the
11481 code above makes it less likely one will discard output, but not
11482 impossible, since there might be stuff in the system buffer here.
11483 But it is much hairier to try to do anything about that. */
11484 if (interrupt_input
)
11488 /* If a frame has become visible which was not before, redisplay
11489 again, so that we display it. Expose events for such a frame
11490 (which it gets when becoming visible) don't call the parts of
11491 redisplay constructing glyphs, so simply exposing a frame won't
11492 display anything in this case. So, we have to display these
11493 frames here explicitly. */
11496 Lisp_Object tail
, frame
;
11499 FOR_EACH_FRAME (tail
, frame
)
11501 int this_is_visible
= 0;
11503 if (XFRAME (frame
)->visible
)
11504 this_is_visible
= 1;
11505 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11506 if (XFRAME (frame
)->visible
)
11507 this_is_visible
= 1;
11509 if (this_is_visible
)
11513 if (new_count
!= number_of_visible_frames
)
11514 windows_or_buffers_changed
++;
11517 /* Change frame size now if a change is pending. */
11518 do_pending_window_change (1);
11520 /* If we just did a pending size change, or have additional
11521 visible frames, redisplay again. */
11522 if (windows_or_buffers_changed
&& !pause
)
11525 /* Clear the face cache eventually. */
11526 if (consider_all_windows_p
)
11528 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11530 clear_face_cache (0);
11531 clear_face_cache_count
= 0;
11533 #ifdef HAVE_WINDOW_SYSTEM
11534 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11536 Lisp_Object tail
, frame
;
11537 FOR_EACH_FRAME (tail
, frame
)
11539 struct frame
*f
= XFRAME (frame
);
11540 if (FRAME_WINDOW_P (f
))
11541 clear_image_cache (f
, 0);
11543 clear_image_cache_count
= 0;
11545 #endif /* HAVE_WINDOW_SYSTEM */
11549 unbind_to (count
, Qnil
);
11554 /* Redisplay, but leave alone any recent echo area message unless
11555 another message has been requested in its place.
11557 This is useful in situations where you need to redisplay but no
11558 user action has occurred, making it inappropriate for the message
11559 area to be cleared. See tracking_off and
11560 wait_reading_process_output for examples of these situations.
11562 FROM_WHERE is an integer saying from where this function was
11563 called. This is useful for debugging. */
11566 redisplay_preserve_echo_area (from_where
)
11569 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
11571 if (!NILP (echo_area_buffer
[1]))
11573 /* We have a previously displayed message, but no current
11574 message. Redisplay the previous message. */
11575 display_last_displayed_message_p
= 1;
11576 redisplay_internal (1);
11577 display_last_displayed_message_p
= 0;
11580 redisplay_internal (1);
11582 if (rif
!= NULL
&& rif
->flush_display_optional
)
11583 rif
->flush_display_optional (NULL
);
11587 /* Function registered with record_unwind_protect in
11588 redisplay_internal. Reset redisplaying_p to the value it had
11589 before redisplay_internal was called, and clear
11590 prevent_freeing_realized_faces_p. It also selects the previously
11594 unwind_redisplay (val
)
11597 Lisp_Object old_redisplaying_p
, old_frame
;
11599 old_redisplaying_p
= XCAR (val
);
11600 redisplaying_p
= XFASTINT (old_redisplaying_p
);
11601 old_frame
= XCDR (val
);
11602 if (! EQ (old_frame
, selected_frame
))
11603 select_frame_for_redisplay (old_frame
);
11608 /* Mark the display of window W as accurate or inaccurate. If
11609 ACCURATE_P is non-zero mark display of W as accurate. If
11610 ACCURATE_P is zero, arrange for W to be redisplayed the next time
11611 redisplay_internal is called. */
11614 mark_window_display_accurate_1 (w
, accurate_p
)
11618 if (BUFFERP (w
->buffer
))
11620 struct buffer
*b
= XBUFFER (w
->buffer
);
11623 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
11624 w
->last_overlay_modified
11625 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
11627 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
11631 b
->clip_changed
= 0;
11632 b
->prevent_redisplay_optimizations_p
= 0;
11634 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
11635 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
11636 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
11637 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
11639 w
->current_matrix
->buffer
= b
;
11640 w
->current_matrix
->begv
= BUF_BEGV (b
);
11641 w
->current_matrix
->zv
= BUF_ZV (b
);
11643 w
->last_cursor
= w
->cursor
;
11644 w
->last_cursor_off_p
= w
->cursor_off_p
;
11646 if (w
== XWINDOW (selected_window
))
11647 w
->last_point
= make_number (BUF_PT (b
));
11649 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
11655 w
->window_end_valid
= w
->buffer
;
11656 #if 0 /* This is incorrect with variable-height lines. */
11657 xassert (XINT (w
->window_end_vpos
)
11658 < (WINDOW_TOTAL_LINES (w
)
11659 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
11661 w
->update_mode_line
= Qnil
;
11666 /* Mark the display of windows in the window tree rooted at WINDOW as
11667 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
11668 windows as accurate. If ACCURATE_P is zero, arrange for windows to
11669 be redisplayed the next time redisplay_internal is called. */
11672 mark_window_display_accurate (window
, accurate_p
)
11673 Lisp_Object window
;
11678 for (; !NILP (window
); window
= w
->next
)
11680 w
= XWINDOW (window
);
11681 mark_window_display_accurate_1 (w
, accurate_p
);
11683 if (!NILP (w
->vchild
))
11684 mark_window_display_accurate (w
->vchild
, accurate_p
);
11685 if (!NILP (w
->hchild
))
11686 mark_window_display_accurate (w
->hchild
, accurate_p
);
11691 update_overlay_arrows (1);
11695 /* Force a thorough redisplay the next time by setting
11696 last_arrow_position and last_arrow_string to t, which is
11697 unequal to any useful value of Voverlay_arrow_... */
11698 update_overlay_arrows (-1);
11703 /* Return value in display table DP (Lisp_Char_Table *) for character
11704 C. Since a display table doesn't have any parent, we don't have to
11705 follow parent. Do not call this function directly but use the
11706 macro DISP_CHAR_VECTOR. */
11709 disp_char_vector (dp
, c
)
11710 struct Lisp_Char_Table
*dp
;
11716 if (SINGLE_BYTE_CHAR_P (c
))
11717 return (dp
->contents
[c
]);
11719 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
11722 else if (code
[2] < 32)
11725 /* Here, the possible range of code[0] (== charset ID) is
11726 128..max_charset. Since the top level char table contains data
11727 for multibyte characters after 256th element, we must increment
11728 code[0] by 128 to get a correct index. */
11730 code
[3] = -1; /* anchor */
11732 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
11734 val
= dp
->contents
[code
[i
]];
11735 if (!SUB_CHAR_TABLE_P (val
))
11736 return (NILP (val
) ? dp
->defalt
: val
);
11739 /* Here, val is a sub char table. We return the default value of
11741 return (dp
->defalt
);
11746 /***********************************************************************
11748 ***********************************************************************/
11750 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11753 redisplay_windows (window
)
11754 Lisp_Object window
;
11756 while (!NILP (window
))
11758 struct window
*w
= XWINDOW (window
);
11760 if (!NILP (w
->hchild
))
11761 redisplay_windows (w
->hchild
);
11762 else if (!NILP (w
->vchild
))
11763 redisplay_windows (w
->vchild
);
11766 displayed_buffer
= XBUFFER (w
->buffer
);
11767 /* Use list_of_error, not Qerror, so that
11768 we catch only errors and don't run the debugger. */
11769 internal_condition_case_1 (redisplay_window_0
, window
,
11771 redisplay_window_error
);
11779 redisplay_window_error ()
11781 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11786 redisplay_window_0 (window
)
11787 Lisp_Object window
;
11789 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11790 redisplay_window (window
, 0);
11795 redisplay_window_1 (window
)
11796 Lisp_Object window
;
11798 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11799 redisplay_window (window
, 1);
11804 /* Increment GLYPH until it reaches END or CONDITION fails while
11805 adding (GLYPH)->pixel_width to X. */
11807 #define SKIP_GLYPHS(glyph, end, x, condition) \
11810 (x) += (glyph)->pixel_width; \
11813 while ((glyph) < (end) && (condition))
11816 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11817 DELTA is the number of bytes by which positions recorded in ROW
11818 differ from current buffer positions.
11820 Return 0 if cursor is not on this row. 1 otherwise. */
11823 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11825 struct glyph_row
*row
;
11826 struct glyph_matrix
*matrix
;
11827 int delta
, delta_bytes
, dy
, dvpos
;
11829 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11830 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11831 struct glyph
*cursor
= NULL
;
11832 /* The first glyph that starts a sequence of glyphs from string. */
11833 struct glyph
*string_start
;
11834 /* The X coordinate of string_start. */
11835 int string_start_x
;
11836 /* The last known character position. */
11837 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11838 /* The last known character position before string_start. */
11839 int string_before_pos
;
11842 int cursor_from_overlay_pos
= 0;
11843 int pt_old
= PT
- delta
;
11845 /* Skip over glyphs not having an object at the start of the row.
11846 These are special glyphs like truncation marks on terminal
11848 if (row
->displays_text_p
)
11850 && INTEGERP (glyph
->object
)
11851 && glyph
->charpos
< 0)
11853 x
+= glyph
->pixel_width
;
11857 string_start
= NULL
;
11859 && !INTEGERP (glyph
->object
)
11860 && (!BUFFERP (glyph
->object
)
11861 || (last_pos
= glyph
->charpos
) < pt_old
))
11863 if (! STRINGP (glyph
->object
))
11865 string_start
= NULL
;
11866 x
+= glyph
->pixel_width
;
11868 if (cursor_from_overlay_pos
11869 && last_pos
>= cursor_from_overlay_pos
)
11871 cursor_from_overlay_pos
= 0;
11877 if (string_start
== NULL
)
11879 string_before_pos
= last_pos
;
11880 string_start
= glyph
;
11881 string_start_x
= x
;
11883 /* Skip all glyphs from string. */
11888 if ((cursor
== NULL
|| glyph
> cursor
)
11889 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
11890 Qcursor
, (glyph
)->object
),
11892 && (pos
= string_buffer_position (w
, glyph
->object
,
11893 string_before_pos
),
11894 (pos
== 0 /* From overlay */
11895 || pos
== pt_old
)))
11897 /* Estimate overlay buffer position from the buffer
11898 positions of the glyphs before and after the overlay.
11899 Add 1 to last_pos so that if point corresponds to the
11900 glyph right after the overlay, we still use a 'cursor'
11901 property found in that overlay. */
11902 cursor_from_overlay_pos
= (pos
? 0 : last_pos
11903 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
11907 x
+= glyph
->pixel_width
;
11910 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
11914 if (cursor
!= NULL
)
11919 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
11921 /* Scan back over the ellipsis glyphs, decrementing positions. */
11922 while (glyph
> row
->glyphs
[TEXT_AREA
]
11923 && (glyph
- 1)->charpos
== last_pos
)
11924 glyph
--, x
-= glyph
->pixel_width
;
11925 /* That loop always goes one position too far,
11926 including the glyph before the ellipsis.
11927 So scan forward over that one. */
11928 x
+= glyph
->pixel_width
;
11931 else if (string_start
11932 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
11934 /* We may have skipped over point because the previous glyphs
11935 are from string. As there's no easy way to know the
11936 character position of the current glyph, find the correct
11937 glyph on point by scanning from string_start again. */
11939 Lisp_Object string
;
11940 struct glyph
*stop
= glyph
;
11943 limit
= make_number (pt_old
+ 1);
11944 glyph
= string_start
;
11945 x
= string_start_x
;
11946 string
= glyph
->object
;
11947 pos
= string_buffer_position (w
, string
, string_before_pos
);
11948 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
11949 because we always put cursor after overlay strings. */
11950 while (pos
== 0 && glyph
< stop
)
11952 string
= glyph
->object
;
11953 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
11955 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
11958 while (glyph
< stop
)
11960 pos
= XINT (Fnext_single_char_property_change
11961 (make_number (pos
), Qdisplay
, Qnil
, limit
));
11964 /* Skip glyphs from the same string. */
11965 string
= glyph
->object
;
11966 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
11967 /* Skip glyphs from an overlay. */
11968 while (glyph
< stop
11969 && ! string_buffer_position (w
, glyph
->object
, pos
))
11971 string
= glyph
->object
;
11972 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
11976 /* If we reached the end of the line, and end was from a string,
11977 cursor is not on this line. */
11978 if (glyph
== end
&& row
->continued_p
)
11982 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
11984 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
11985 w
->cursor
.y
= row
->y
+ dy
;
11987 if (w
== XWINDOW (selected_window
))
11989 if (!row
->continued_p
11990 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
11993 this_line_buffer
= XBUFFER (w
->buffer
);
11995 CHARPOS (this_line_start_pos
)
11996 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
11997 BYTEPOS (this_line_start_pos
)
11998 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12000 CHARPOS (this_line_end_pos
)
12001 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12002 BYTEPOS (this_line_end_pos
)
12003 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12005 this_line_y
= w
->cursor
.y
;
12006 this_line_pixel_height
= row
->height
;
12007 this_line_vpos
= w
->cursor
.vpos
;
12008 this_line_start_x
= row
->x
;
12011 CHARPOS (this_line_start_pos
) = 0;
12018 /* Run window scroll functions, if any, for WINDOW with new window
12019 start STARTP. Sets the window start of WINDOW to that position.
12021 We assume that the window's buffer is really current. */
12023 static INLINE
struct text_pos
12024 run_window_scroll_functions (window
, startp
)
12025 Lisp_Object window
;
12026 struct text_pos startp
;
12028 struct window
*w
= XWINDOW (window
);
12029 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12031 if (current_buffer
!= XBUFFER (w
->buffer
))
12034 if (!NILP (Vwindow_scroll_functions
))
12036 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12037 make_number (CHARPOS (startp
)));
12038 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12039 /* In case the hook functions switch buffers. */
12040 if (current_buffer
!= XBUFFER (w
->buffer
))
12041 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12048 /* Make sure the line containing the cursor is fully visible.
12049 A value of 1 means there is nothing to be done.
12050 (Either the line is fully visible, or it cannot be made so,
12051 or we cannot tell.)
12053 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12054 is higher than window.
12056 A value of 0 means the caller should do scrolling
12057 as if point had gone off the screen. */
12060 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12063 int current_matrix_p
;
12065 struct glyph_matrix
*matrix
;
12066 struct glyph_row
*row
;
12069 if (!make_cursor_line_fully_visible_p
)
12072 /* It's not always possible to find the cursor, e.g, when a window
12073 is full of overlay strings. Don't do anything in that case. */
12074 if (w
->cursor
.vpos
< 0)
12077 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12078 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12080 /* If the cursor row is not partially visible, there's nothing to do. */
12081 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12084 /* If the row the cursor is in is taller than the window's height,
12085 it's not clear what to do, so do nothing. */
12086 window_height
= window_box_height (w
);
12087 if (row
->height
>= window_height
)
12089 if (!force_p
|| MINI_WINDOW_P (w
)
12090 || w
->vscroll
|| w
->cursor
.vpos
== 0)
12096 /* This code used to try to scroll the window just enough to make
12097 the line visible. It returned 0 to say that the caller should
12098 allocate larger glyph matrices. */
12100 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
12102 int dy
= row
->height
- row
->visible_height
;
12105 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12107 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
12109 int dy
= - (row
->height
- row
->visible_height
);
12112 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12115 /* When we change the cursor y-position of the selected window,
12116 change this_line_y as well so that the display optimization for
12117 the cursor line of the selected window in redisplay_internal uses
12118 the correct y-position. */
12119 if (w
== XWINDOW (selected_window
))
12120 this_line_y
= w
->cursor
.y
;
12122 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
12123 redisplay with larger matrices. */
12124 if (matrix
->nrows
< required_matrix_height (w
))
12126 fonts_changed_p
= 1;
12135 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
12136 non-zero means only WINDOW is redisplayed in redisplay_internal.
12137 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
12138 in redisplay_window to bring a partially visible line into view in
12139 the case that only the cursor has moved.
12141 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
12142 last screen line's vertical height extends past the end of the screen.
12146 1 if scrolling succeeded
12148 0 if scrolling didn't find point.
12150 -1 if new fonts have been loaded so that we must interrupt
12151 redisplay, adjust glyph matrices, and try again. */
12157 SCROLLING_NEED_LARGER_MATRICES
12161 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
12162 scroll_step
, temp_scroll_step
, last_line_misfit
)
12163 Lisp_Object window
;
12164 int just_this_one_p
;
12165 EMACS_INT scroll_conservatively
, scroll_step
;
12166 int temp_scroll_step
;
12167 int last_line_misfit
;
12169 struct window
*w
= XWINDOW (window
);
12170 struct frame
*f
= XFRAME (w
->frame
);
12171 struct text_pos scroll_margin_pos
;
12172 struct text_pos pos
;
12173 struct text_pos startp
;
12175 Lisp_Object window_end
;
12176 int this_scroll_margin
;
12180 int amount_to_scroll
= 0;
12181 Lisp_Object aggressive
;
12183 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
12186 debug_method_add (w
, "try_scrolling");
12189 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12191 /* Compute scroll margin height in pixels. We scroll when point is
12192 within this distance from the top or bottom of the window. */
12193 if (scroll_margin
> 0)
12195 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12196 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12199 this_scroll_margin
= 0;
12201 /* Force scroll_conservatively to have a reasonable value so it doesn't
12202 cause an overflow while computing how much to scroll. */
12203 if (scroll_conservatively
)
12204 scroll_conservatively
= min (scroll_conservatively
,
12205 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
12207 /* Compute how much we should try to scroll maximally to bring point
12209 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
12210 scroll_max
= max (scroll_step
,
12211 max (scroll_conservatively
, temp_scroll_step
));
12212 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
12213 || NUMBERP (current_buffer
->scroll_up_aggressively
))
12214 /* We're trying to scroll because of aggressive scrolling
12215 but no scroll_step is set. Choose an arbitrary one. Maybe
12216 there should be a variable for this. */
12220 scroll_max
*= FRAME_LINE_HEIGHT (f
);
12222 /* Decide whether we have to scroll down. Start at the window end
12223 and move this_scroll_margin up to find the position of the scroll
12225 window_end
= Fwindow_end (window
, Qt
);
12229 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
12230 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
12232 if (this_scroll_margin
|| extra_scroll_margin_lines
)
12234 start_display (&it
, w
, scroll_margin_pos
);
12235 if (this_scroll_margin
)
12236 move_it_vertically_backward (&it
, this_scroll_margin
);
12237 if (extra_scroll_margin_lines
)
12238 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
12239 scroll_margin_pos
= it
.current
.pos
;
12242 if (PT
>= CHARPOS (scroll_margin_pos
))
12246 /* Point is in the scroll margin at the bottom of the window, or
12247 below. Compute a new window start that makes point visible. */
12249 /* Compute the distance from the scroll margin to PT.
12250 Give up if the distance is greater than scroll_max. */
12251 start_display (&it
, w
, scroll_margin_pos
);
12253 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12254 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12256 /* To make point visible, we have to move the window start
12257 down so that the line the cursor is in is visible, which
12258 means we have to add in the height of the cursor line. */
12259 dy
= line_bottom_y (&it
) - y0
;
12261 if (dy
> scroll_max
)
12262 return SCROLLING_FAILED
;
12264 /* Move the window start down. If scrolling conservatively,
12265 move it just enough down to make point visible. If
12266 scroll_step is set, move it down by scroll_step. */
12267 start_display (&it
, w
, startp
);
12269 if (scroll_conservatively
)
12270 /* Set AMOUNT_TO_SCROLL to at least one line,
12271 and at most scroll_conservatively lines. */
12273 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12274 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12275 else if (scroll_step
|| temp_scroll_step
)
12276 amount_to_scroll
= scroll_max
;
12279 aggressive
= current_buffer
->scroll_up_aggressively
;
12280 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12281 if (NUMBERP (aggressive
))
12283 double float_amount
= XFLOATINT (aggressive
) * height
;
12284 amount_to_scroll
= float_amount
;
12285 if (amount_to_scroll
== 0 && float_amount
> 0)
12286 amount_to_scroll
= 1;
12290 if (amount_to_scroll
<= 0)
12291 return SCROLLING_FAILED
;
12293 /* If moving by amount_to_scroll leaves STARTP unchanged,
12294 move it down one screen line. */
12296 move_it_vertically (&it
, amount_to_scroll
);
12297 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12298 move_it_by_lines (&it
, 1, 1);
12299 startp
= it
.current
.pos
;
12303 /* See if point is inside the scroll margin at the top of the
12305 scroll_margin_pos
= startp
;
12306 if (this_scroll_margin
)
12308 start_display (&it
, w
, startp
);
12309 move_it_vertically (&it
, this_scroll_margin
);
12310 scroll_margin_pos
= it
.current
.pos
;
12313 if (PT
< CHARPOS (scroll_margin_pos
))
12315 /* Point is in the scroll margin at the top of the window or
12316 above what is displayed in the window. */
12319 /* Compute the vertical distance from PT to the scroll
12320 margin position. Give up if distance is greater than
12322 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12323 start_display (&it
, w
, pos
);
12325 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12326 it
.last_visible_y
, -1,
12327 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12328 dy
= it
.current_y
- y0
;
12329 if (dy
> scroll_max
)
12330 return SCROLLING_FAILED
;
12332 /* Compute new window start. */
12333 start_display (&it
, w
, startp
);
12335 if (scroll_conservatively
)
12337 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12338 else if (scroll_step
|| temp_scroll_step
)
12339 amount_to_scroll
= scroll_max
;
12342 aggressive
= current_buffer
->scroll_down_aggressively
;
12343 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12344 if (NUMBERP (aggressive
))
12346 double float_amount
= XFLOATINT (aggressive
) * height
;
12347 amount_to_scroll
= float_amount
;
12348 if (amount_to_scroll
== 0 && float_amount
> 0)
12349 amount_to_scroll
= 1;
12353 if (amount_to_scroll
<= 0)
12354 return SCROLLING_FAILED
;
12356 move_it_vertically_backward (&it
, amount_to_scroll
);
12357 startp
= it
.current
.pos
;
12361 /* Run window scroll functions. */
12362 startp
= run_window_scroll_functions (window
, startp
);
12364 /* Display the window. Give up if new fonts are loaded, or if point
12366 if (!try_window (window
, startp
, 0))
12367 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12368 else if (w
->cursor
.vpos
< 0)
12370 clear_glyph_matrix (w
->desired_matrix
);
12371 rc
= SCROLLING_FAILED
;
12375 /* Maybe forget recorded base line for line number display. */
12376 if (!just_this_one_p
12377 || current_buffer
->clip_changed
12378 || BEG_UNCHANGED
< CHARPOS (startp
))
12379 w
->base_line_number
= Qnil
;
12381 /* If cursor ends up on a partially visible line,
12382 treat that as being off the bottom of the screen. */
12383 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12385 clear_glyph_matrix (w
->desired_matrix
);
12386 ++extra_scroll_margin_lines
;
12389 rc
= SCROLLING_SUCCESS
;
12396 /* Compute a suitable window start for window W if display of W starts
12397 on a continuation line. Value is non-zero if a new window start
12400 The new window start will be computed, based on W's width, starting
12401 from the start of the continued line. It is the start of the
12402 screen line with the minimum distance from the old start W->start. */
12405 compute_window_start_on_continuation_line (w
)
12408 struct text_pos pos
, start_pos
;
12409 int window_start_changed_p
= 0;
12411 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12413 /* If window start is on a continuation line... Window start may be
12414 < BEGV in case there's invisible text at the start of the
12415 buffer (M-x rmail, for example). */
12416 if (CHARPOS (start_pos
) > BEGV
12417 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12420 struct glyph_row
*row
;
12422 /* Handle the case that the window start is out of range. */
12423 if (CHARPOS (start_pos
) < BEGV
)
12424 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12425 else if (CHARPOS (start_pos
) > ZV
)
12426 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12428 /* Find the start of the continued line. This should be fast
12429 because scan_buffer is fast (newline cache). */
12430 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12431 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12432 row
, DEFAULT_FACE_ID
);
12433 reseat_at_previous_visible_line_start (&it
);
12435 /* If the line start is "too far" away from the window start,
12436 say it takes too much time to compute a new window start. */
12437 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12438 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12440 int min_distance
, distance
;
12442 /* Move forward by display lines to find the new window
12443 start. If window width was enlarged, the new start can
12444 be expected to be > the old start. If window width was
12445 decreased, the new window start will be < the old start.
12446 So, we're looking for the display line start with the
12447 minimum distance from the old window start. */
12448 pos
= it
.current
.pos
;
12449 min_distance
= INFINITY
;
12450 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12451 distance
< min_distance
)
12453 min_distance
= distance
;
12454 pos
= it
.current
.pos
;
12455 move_it_by_lines (&it
, 1, 0);
12458 /* Set the window start there. */
12459 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12460 window_start_changed_p
= 1;
12464 return window_start_changed_p
;
12468 /* Try cursor movement in case text has not changed in window WINDOW,
12469 with window start STARTP. Value is
12471 CURSOR_MOVEMENT_SUCCESS if successful
12473 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12475 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12476 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12477 we want to scroll as if scroll-step were set to 1. See the code.
12479 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12480 which case we have to abort this redisplay, and adjust matrices
12485 CURSOR_MOVEMENT_SUCCESS
,
12486 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12487 CURSOR_MOVEMENT_MUST_SCROLL
,
12488 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12492 try_cursor_movement (window
, startp
, scroll_step
)
12493 Lisp_Object window
;
12494 struct text_pos startp
;
12497 struct window
*w
= XWINDOW (window
);
12498 struct frame
*f
= XFRAME (w
->frame
);
12499 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12502 if (inhibit_try_cursor_movement
)
12506 /* Handle case where text has not changed, only point, and it has
12507 not moved off the frame. */
12508 if (/* Point may be in this window. */
12509 PT
>= CHARPOS (startp
)
12510 /* Selective display hasn't changed. */
12511 && !current_buffer
->clip_changed
12512 /* Function force-mode-line-update is used to force a thorough
12513 redisplay. It sets either windows_or_buffers_changed or
12514 update_mode_lines. So don't take a shortcut here for these
12516 && !update_mode_lines
12517 && !windows_or_buffers_changed
12518 && !cursor_type_changed
12519 /* Can't use this case if highlighting a region. When a
12520 region exists, cursor movement has to do more than just
12522 && !(!NILP (Vtransient_mark_mode
)
12523 && !NILP (current_buffer
->mark_active
))
12524 && NILP (w
->region_showing
)
12525 && NILP (Vshow_trailing_whitespace
)
12526 /* Right after splitting windows, last_point may be nil. */
12527 && INTEGERP (w
->last_point
)
12528 /* This code is not used for mini-buffer for the sake of the case
12529 of redisplaying to replace an echo area message; since in
12530 that case the mini-buffer contents per se are usually
12531 unchanged. This code is of no real use in the mini-buffer
12532 since the handling of this_line_start_pos, etc., in redisplay
12533 handles the same cases. */
12534 && !EQ (window
, minibuf_window
)
12535 /* When splitting windows or for new windows, it happens that
12536 redisplay is called with a nil window_end_vpos or one being
12537 larger than the window. This should really be fixed in
12538 window.c. I don't have this on my list, now, so we do
12539 approximately the same as the old redisplay code. --gerd. */
12540 && INTEGERP (w
->window_end_vpos
)
12541 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12542 && (FRAME_WINDOW_P (f
)
12543 || !overlay_arrow_in_current_buffer_p ()))
12545 int this_scroll_margin
, top_scroll_margin
;
12546 struct glyph_row
*row
= NULL
;
12549 debug_method_add (w
, "cursor movement");
12552 /* Scroll if point within this distance from the top or bottom
12553 of the window. This is a pixel value. */
12554 this_scroll_margin
= max (0, scroll_margin
);
12555 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12556 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12558 top_scroll_margin
= this_scroll_margin
;
12559 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12560 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12562 /* Start with the row the cursor was displayed during the last
12563 not paused redisplay. Give up if that row is not valid. */
12564 if (w
->last_cursor
.vpos
< 0
12565 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12566 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12569 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12570 if (row
->mode_line_p
)
12572 if (!row
->enabled_p
)
12573 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12576 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12579 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12581 if (PT
> XFASTINT (w
->last_point
))
12583 /* Point has moved forward. */
12584 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12585 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12587 xassert (row
->enabled_p
);
12591 /* The end position of a row equals the start position
12592 of the next row. If PT is there, we would rather
12593 display it in the next line. */
12594 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12595 && MATRIX_ROW_END_CHARPOS (row
) == PT
12596 && !cursor_row_p (w
, row
))
12599 /* If within the scroll margin, scroll. Note that
12600 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
12601 the next line would be drawn, and that
12602 this_scroll_margin can be zero. */
12603 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
12604 || PT
> MATRIX_ROW_END_CHARPOS (row
)
12605 /* Line is completely visible last line in window
12606 and PT is to be set in the next line. */
12607 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
12608 && PT
== MATRIX_ROW_END_CHARPOS (row
)
12609 && !row
->ends_at_zv_p
12610 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12613 else if (PT
< XFASTINT (w
->last_point
))
12615 /* Cursor has to be moved backward. Note that PT >=
12616 CHARPOS (startp) because of the outer if-statement. */
12617 while (!row
->mode_line_p
12618 && (MATRIX_ROW_START_CHARPOS (row
) > PT
12619 || (MATRIX_ROW_START_CHARPOS (row
) == PT
12620 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
12621 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
12622 row
> w
->current_matrix
->rows
12623 && (row
-1)->ends_in_newline_from_string_p
))))
12624 && (row
->y
> top_scroll_margin
12625 || CHARPOS (startp
) == BEGV
))
12627 xassert (row
->enabled_p
);
12631 /* Consider the following case: Window starts at BEGV,
12632 there is invisible, intangible text at BEGV, so that
12633 display starts at some point START > BEGV. It can
12634 happen that we are called with PT somewhere between
12635 BEGV and START. Try to handle that case. */
12636 if (row
< w
->current_matrix
->rows
12637 || row
->mode_line_p
)
12639 row
= w
->current_matrix
->rows
;
12640 if (row
->mode_line_p
)
12644 /* Due to newlines in overlay strings, we may have to
12645 skip forward over overlay strings. */
12646 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12647 && MATRIX_ROW_END_CHARPOS (row
) == PT
12648 && !cursor_row_p (w
, row
))
12651 /* If within the scroll margin, scroll. */
12652 if (row
->y
< top_scroll_margin
12653 && CHARPOS (startp
) != BEGV
)
12658 /* Cursor did not move. So don't scroll even if cursor line
12659 is partially visible, as it was so before. */
12660 rc
= CURSOR_MOVEMENT_SUCCESS
;
12663 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
12664 || PT
> MATRIX_ROW_END_CHARPOS (row
))
12666 /* if PT is not in the glyph row, give up. */
12667 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12669 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
12670 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
12671 && make_cursor_line_fully_visible_p
)
12673 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
12674 && !row
->ends_at_zv_p
12675 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12676 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12677 else if (row
->height
> window_box_height (w
))
12679 /* If we end up in a partially visible line, let's
12680 make it fully visible, except when it's taller
12681 than the window, in which case we can't do much
12684 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12688 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12689 if (!cursor_row_fully_visible_p (w
, 0, 1))
12690 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12692 rc
= CURSOR_MOVEMENT_SUCCESS
;
12696 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12701 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
12703 rc
= CURSOR_MOVEMENT_SUCCESS
;
12708 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12709 && MATRIX_ROW_START_CHARPOS (row
) == PT
12710 && cursor_row_p (w
, row
));
12719 set_vertical_scroll_bar (w
)
12722 int start
, end
, whole
;
12724 /* Calculate the start and end positions for the current window.
12725 At some point, it would be nice to choose between scrollbars
12726 which reflect the whole buffer size, with special markers
12727 indicating narrowing, and scrollbars which reflect only the
12730 Note that mini-buffers sometimes aren't displaying any text. */
12731 if (!MINI_WINDOW_P (w
)
12732 || (w
== XWINDOW (minibuf_window
)
12733 && NILP (echo_area_buffer
[0])))
12735 struct buffer
*buf
= XBUFFER (w
->buffer
);
12736 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12737 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12738 /* I don't think this is guaranteed to be right. For the
12739 moment, we'll pretend it is. */
12740 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12744 if (whole
< (end
- start
))
12745 whole
= end
- start
;
12748 start
= end
= whole
= 0;
12750 /* Indicate what this scroll bar ought to be displaying now. */
12751 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
12755 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
12756 selected_window is redisplayed.
12758 We can return without actually redisplaying the window if
12759 fonts_changed_p is nonzero. In that case, redisplay_internal will
12763 redisplay_window (window
, just_this_one_p
)
12764 Lisp_Object window
;
12765 int just_this_one_p
;
12767 struct window
*w
= XWINDOW (window
);
12768 struct frame
*f
= XFRAME (w
->frame
);
12769 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12770 struct buffer
*old
= current_buffer
;
12771 struct text_pos lpoint
, opoint
, startp
;
12772 int update_mode_line
;
12775 /* Record it now because it's overwritten. */
12776 int current_matrix_up_to_date_p
= 0;
12777 int used_current_matrix_p
= 0;
12778 /* This is less strict than current_matrix_up_to_date_p.
12779 It indictes that the buffer contents and narrowing are unchanged. */
12780 int buffer_unchanged_p
= 0;
12781 int temp_scroll_step
= 0;
12782 int count
= SPECPDL_INDEX ();
12784 int centering_position
= -1;
12785 int last_line_misfit
= 0;
12786 int save_beg_unchanged
, save_end_unchanged
;
12788 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12791 /* W must be a leaf window here. */
12792 xassert (!NILP (w
->buffer
));
12794 *w
->desired_matrix
->method
= 0;
12797 specbind (Qinhibit_point_motion_hooks
, Qt
);
12799 reconsider_clip_changes (w
, buffer
);
12801 /* Has the mode line to be updated? */
12802 update_mode_line
= (!NILP (w
->update_mode_line
)
12803 || update_mode_lines
12804 || buffer
->clip_changed
12805 || buffer
->prevent_redisplay_optimizations_p
);
12807 if (MINI_WINDOW_P (w
))
12809 if (w
== XWINDOW (echo_area_window
)
12810 && !NILP (echo_area_buffer
[0]))
12812 if (update_mode_line
)
12813 /* We may have to update a tty frame's menu bar or a
12814 tool-bar. Example `M-x C-h C-h C-g'. */
12815 goto finish_menu_bars
;
12817 /* We've already displayed the echo area glyphs in this window. */
12818 goto finish_scroll_bars
;
12820 else if ((w
!= XWINDOW (minibuf_window
)
12821 || minibuf_level
== 0)
12822 /* When buffer is nonempty, redisplay window normally. */
12823 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12824 /* Quail displays non-mini buffers in minibuffer window.
12825 In that case, redisplay the window normally. */
12826 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12828 /* W is a mini-buffer window, but it's not active, so clear
12830 int yb
= window_text_bottom_y (w
);
12831 struct glyph_row
*row
;
12834 for (y
= 0, row
= w
->desired_matrix
->rows
;
12836 y
+= row
->height
, ++row
)
12837 blank_row (w
, row
, y
);
12838 goto finish_scroll_bars
;
12841 clear_glyph_matrix (w
->desired_matrix
);
12844 /* Otherwise set up data on this window; select its buffer and point
12846 /* Really select the buffer, for the sake of buffer-local
12848 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12849 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12851 save_beg_unchanged
= BEG_UNCHANGED
;
12852 save_end_unchanged
= END_UNCHANGED
;
12854 current_matrix_up_to_date_p
12855 = (!NILP (w
->window_end_valid
)
12856 && !current_buffer
->clip_changed
12857 && !current_buffer
->prevent_redisplay_optimizations_p
12858 && XFASTINT (w
->last_modified
) >= MODIFF
12859 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12862 = (!NILP (w
->window_end_valid
)
12863 && !current_buffer
->clip_changed
12864 && XFASTINT (w
->last_modified
) >= MODIFF
12865 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12867 /* When windows_or_buffers_changed is non-zero, we can't rely on
12868 the window end being valid, so set it to nil there. */
12869 if (windows_or_buffers_changed
)
12871 /* If window starts on a continuation line, maybe adjust the
12872 window start in case the window's width changed. */
12873 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12874 compute_window_start_on_continuation_line (w
);
12876 w
->window_end_valid
= Qnil
;
12879 /* Some sanity checks. */
12880 CHECK_WINDOW_END (w
);
12881 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12883 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12886 /* If %c is in mode line, update it if needed. */
12887 if (!NILP (w
->column_number_displayed
)
12888 /* This alternative quickly identifies a common case
12889 where no change is needed. */
12890 && !(PT
== XFASTINT (w
->last_point
)
12891 && XFASTINT (w
->last_modified
) >= MODIFF
12892 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12893 && (XFASTINT (w
->column_number_displayed
)
12894 != (int) current_column ())) /* iftc */
12895 update_mode_line
= 1;
12897 /* Count number of windows showing the selected buffer. An indirect
12898 buffer counts as its base buffer. */
12899 if (!just_this_one_p
)
12901 struct buffer
*current_base
, *window_base
;
12902 current_base
= current_buffer
;
12903 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12904 if (current_base
->base_buffer
)
12905 current_base
= current_base
->base_buffer
;
12906 if (window_base
->base_buffer
)
12907 window_base
= window_base
->base_buffer
;
12908 if (current_base
== window_base
)
12912 /* Point refers normally to the selected window. For any other
12913 window, set up appropriate value. */
12914 if (!EQ (window
, selected_window
))
12916 int new_pt
= XMARKER (w
->pointm
)->charpos
;
12917 int new_pt_byte
= marker_byte_position (w
->pointm
);
12921 new_pt_byte
= BEGV_BYTE
;
12922 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
12924 else if (new_pt
> (ZV
- 1))
12927 new_pt_byte
= ZV_BYTE
;
12928 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
12931 /* We don't use SET_PT so that the point-motion hooks don't run. */
12932 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
12935 /* If any of the character widths specified in the display table
12936 have changed, invalidate the width run cache. It's true that
12937 this may be a bit late to catch such changes, but the rest of
12938 redisplay goes (non-fatally) haywire when the display table is
12939 changed, so why should we worry about doing any better? */
12940 if (current_buffer
->width_run_cache
)
12942 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
12944 if (! disptab_matches_widthtab (disptab
,
12945 XVECTOR (current_buffer
->width_table
)))
12947 invalidate_region_cache (current_buffer
,
12948 current_buffer
->width_run_cache
,
12950 recompute_width_table (current_buffer
, disptab
);
12954 /* If window-start is screwed up, choose a new one. */
12955 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12958 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12960 /* If someone specified a new starting point but did not insist,
12961 check whether it can be used. */
12962 if (!NILP (w
->optional_new_start
)
12963 && CHARPOS (startp
) >= BEGV
12964 && CHARPOS (startp
) <= ZV
)
12966 w
->optional_new_start
= Qnil
;
12967 start_display (&it
, w
, startp
);
12968 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12969 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12970 if (IT_CHARPOS (it
) == PT
)
12971 w
->force_start
= Qt
;
12972 /* IT may overshoot PT if text at PT is invisible. */
12973 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12974 w
->force_start
= Qt
;
12979 /* Handle case where place to start displaying has been specified,
12980 unless the specified location is outside the accessible range. */
12981 if (!NILP (w
->force_start
)
12982 || w
->frozen_window_start_p
)
12984 /* We set this later on if we have to adjust point. */
12988 w
->force_start
= Qnil
;
12990 w
->window_end_valid
= Qnil
;
12992 /* Forget any recorded base line for line number display. */
12993 if (!buffer_unchanged_p
)
12994 w
->base_line_number
= Qnil
;
12996 /* Redisplay the mode line. Select the buffer properly for that.
12997 Also, run the hook window-scroll-functions
12998 because we have scrolled. */
12999 /* Note, we do this after clearing force_start because
13000 if there's an error, it is better to forget about force_start
13001 than to get into an infinite loop calling the hook functions
13002 and having them get more errors. */
13003 if (!update_mode_line
13004 || ! NILP (Vwindow_scroll_functions
))
13006 update_mode_line
= 1;
13007 w
->update_mode_line
= Qt
;
13008 startp
= run_window_scroll_functions (window
, startp
);
13011 w
->last_modified
= make_number (0);
13012 w
->last_overlay_modified
= make_number (0);
13013 if (CHARPOS (startp
) < BEGV
)
13014 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
13015 else if (CHARPOS (startp
) > ZV
)
13016 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
13018 /* Redisplay, then check if cursor has been set during the
13019 redisplay. Give up if new fonts were loaded. */
13020 val
= try_window (window
, startp
, 1);
13023 w
->force_start
= Qt
;
13024 clear_glyph_matrix (w
->desired_matrix
);
13025 goto need_larger_matrices
;
13027 /* Point was outside the scroll margins. */
13029 new_vpos
= window_box_height (w
) / 2;
13031 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
13033 /* If point does not appear, try to move point so it does
13034 appear. The desired matrix has been built above, so we
13035 can use it here. */
13036 new_vpos
= window_box_height (w
) / 2;
13039 if (!cursor_row_fully_visible_p (w
, 0, 0))
13041 /* Point does appear, but on a line partly visible at end of window.
13042 Move it back to a fully-visible line. */
13043 new_vpos
= window_box_height (w
);
13046 /* If we need to move point for either of the above reasons,
13047 now actually do it. */
13050 struct glyph_row
*row
;
13052 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13053 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13056 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13057 MATRIX_ROW_START_BYTEPOS (row
));
13059 if (w
!= XWINDOW (selected_window
))
13060 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13061 else if (current_buffer
== old
)
13062 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13064 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13066 /* If we are highlighting the region, then we just changed
13067 the region, so redisplay to show it. */
13068 if (!NILP (Vtransient_mark_mode
)
13069 && !NILP (current_buffer
->mark_active
))
13071 clear_glyph_matrix (w
->desired_matrix
);
13072 if (!try_window (window
, startp
, 0))
13073 goto need_larger_matrices
;
13078 debug_method_add (w
, "forced window start");
13083 /* Handle case where text has not changed, only point, and it has
13084 not moved off the frame, and we are not retrying after hscroll.
13085 (current_matrix_up_to_date_p is nonzero when retrying.) */
13086 if (current_matrix_up_to_date_p
13087 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13088 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13092 case CURSOR_MOVEMENT_SUCCESS
:
13093 used_current_matrix_p
= 1;
13096 #if 0 /* try_cursor_movement never returns this value. */
13097 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
13098 goto need_larger_matrices
;
13101 case CURSOR_MOVEMENT_MUST_SCROLL
:
13102 goto try_to_scroll
;
13108 /* If current starting point was originally the beginning of a line
13109 but no longer is, find a new starting point. */
13110 else if (!NILP (w
->start_at_line_beg
)
13111 && !(CHARPOS (startp
) <= BEGV
13112 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13115 debug_method_add (w
, "recenter 1");
13120 /* Try scrolling with try_window_id. Value is > 0 if update has
13121 been done, it is -1 if we know that the same window start will
13122 not work. It is 0 if unsuccessful for some other reason. */
13123 else if ((tem
= try_window_id (w
)) != 0)
13126 debug_method_add (w
, "try_window_id %d", tem
);
13129 if (fonts_changed_p
)
13130 goto need_larger_matrices
;
13134 /* Otherwise try_window_id has returned -1 which means that we
13135 don't want the alternative below this comment to execute. */
13137 else if (CHARPOS (startp
) >= BEGV
13138 && CHARPOS (startp
) <= ZV
13139 && PT
>= CHARPOS (startp
)
13140 && (CHARPOS (startp
) < ZV
13141 /* Avoid starting at end of buffer. */
13142 || CHARPOS (startp
) == BEGV
13143 || (XFASTINT (w
->last_modified
) >= MODIFF
13144 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
13147 /* If first window line is a continuation line, and window start
13148 is inside the modified region, but the first change is before
13149 current window start, we must select a new window start.
13151 However, if this is the result of a down-mouse event (e.g. by
13152 extending the mouse-drag-overlay), we don't want to select a
13153 new window start, since that would change the position under
13154 the mouse, resulting in an unwanted mouse-movement rather
13155 than a simple mouse-click. */
13156 if (NILP (w
->start_at_line_beg
)
13157 && NILP (do_mouse_tracking
)
13158 && CHARPOS (startp
) > BEGV
13159 && CHARPOS (startp
) > BEG
+ save_beg_unchanged
13160 && CHARPOS (startp
) <= Z
- save_end_unchanged
)
13162 w
->force_start
= Qt
;
13163 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13164 compute_window_start_on_continuation_line (w
);
13165 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13170 debug_method_add (w
, "same window start");
13173 /* Try to redisplay starting at same place as before.
13174 If point has not moved off frame, accept the results. */
13175 if (!current_matrix_up_to_date_p
13176 /* Don't use try_window_reusing_current_matrix in this case
13177 because a window scroll function can have changed the
13179 || !NILP (Vwindow_scroll_functions
)
13180 || MINI_WINDOW_P (w
)
13181 || !(used_current_matrix_p
13182 = try_window_reusing_current_matrix (w
)))
13184 IF_DEBUG (debug_method_add (w
, "1"));
13185 if (try_window (window
, startp
, 1) < 0)
13186 /* -1 means we need to scroll.
13187 0 means we need new matrices, but fonts_changed_p
13188 is set in that case, so we will detect it below. */
13189 goto try_to_scroll
;
13192 if (fonts_changed_p
)
13193 goto need_larger_matrices
;
13195 if (w
->cursor
.vpos
>= 0)
13197 if (!just_this_one_p
13198 || current_buffer
->clip_changed
13199 || BEG_UNCHANGED
< CHARPOS (startp
))
13200 /* Forget any recorded base line for line number display. */
13201 w
->base_line_number
= Qnil
;
13203 if (!cursor_row_fully_visible_p (w
, 1, 0))
13205 clear_glyph_matrix (w
->desired_matrix
);
13206 last_line_misfit
= 1;
13208 /* Drop through and scroll. */
13213 clear_glyph_matrix (w
->desired_matrix
);
13218 w
->last_modified
= make_number (0);
13219 w
->last_overlay_modified
= make_number (0);
13221 /* Redisplay the mode line. Select the buffer properly for that. */
13222 if (!update_mode_line
)
13224 update_mode_line
= 1;
13225 w
->update_mode_line
= Qt
;
13228 /* Try to scroll by specified few lines. */
13229 if ((scroll_conservatively
13231 || temp_scroll_step
13232 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13233 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13234 && !current_buffer
->clip_changed
13235 && CHARPOS (startp
) >= BEGV
13236 && CHARPOS (startp
) <= ZV
)
13238 /* The function returns -1 if new fonts were loaded, 1 if
13239 successful, 0 if not successful. */
13240 int rc
= try_scrolling (window
, just_this_one_p
,
13241 scroll_conservatively
,
13243 temp_scroll_step
, last_line_misfit
);
13246 case SCROLLING_SUCCESS
:
13249 case SCROLLING_NEED_LARGER_MATRICES
:
13250 goto need_larger_matrices
;
13252 case SCROLLING_FAILED
:
13260 /* Finally, just choose place to start which centers point */
13263 if (centering_position
< 0)
13264 centering_position
= window_box_height (w
) / 2;
13267 debug_method_add (w
, "recenter");
13270 /* w->vscroll = 0; */
13272 /* Forget any previously recorded base line for line number display. */
13273 if (!buffer_unchanged_p
)
13274 w
->base_line_number
= Qnil
;
13276 /* Move backward half the height of the window. */
13277 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13278 it
.current_y
= it
.last_visible_y
;
13279 move_it_vertically_backward (&it
, centering_position
);
13280 xassert (IT_CHARPOS (it
) >= BEGV
);
13282 /* The function move_it_vertically_backward may move over more
13283 than the specified y-distance. If it->w is small, e.g. a
13284 mini-buffer window, we may end up in front of the window's
13285 display area. Start displaying at the start of the line
13286 containing PT in this case. */
13287 if (it
.current_y
<= 0)
13289 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13290 move_it_vertically_backward (&it
, 0);
13292 /* I think this assert is bogus if buffer contains
13293 invisible text or images. KFS. */
13294 xassert (IT_CHARPOS (it
) <= PT
);
13299 it
.current_x
= it
.hpos
= 0;
13301 /* Set startp here explicitly in case that helps avoid an infinite loop
13302 in case the window-scroll-functions functions get errors. */
13303 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13305 /* Run scroll hooks. */
13306 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13308 /* Redisplay the window. */
13309 if (!current_matrix_up_to_date_p
13310 || windows_or_buffers_changed
13311 || cursor_type_changed
13312 /* Don't use try_window_reusing_current_matrix in this case
13313 because it can have changed the buffer. */
13314 || !NILP (Vwindow_scroll_functions
)
13315 || !just_this_one_p
13316 || MINI_WINDOW_P (w
)
13317 || !(used_current_matrix_p
13318 = try_window_reusing_current_matrix (w
)))
13319 try_window (window
, startp
, 0);
13321 /* If new fonts have been loaded (due to fontsets), give up. We
13322 have to start a new redisplay since we need to re-adjust glyph
13324 if (fonts_changed_p
)
13325 goto need_larger_matrices
;
13327 /* If cursor did not appear assume that the middle of the window is
13328 in the first line of the window. Do it again with the next line.
13329 (Imagine a window of height 100, displaying two lines of height
13330 60. Moving back 50 from it->last_visible_y will end in the first
13332 if (w
->cursor
.vpos
< 0)
13334 if (!NILP (w
->window_end_valid
)
13335 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13337 clear_glyph_matrix (w
->desired_matrix
);
13338 move_it_by_lines (&it
, 1, 0);
13339 try_window (window
, it
.current
.pos
, 0);
13341 else if (PT
< IT_CHARPOS (it
))
13343 clear_glyph_matrix (w
->desired_matrix
);
13344 move_it_by_lines (&it
, -1, 0);
13345 try_window (window
, it
.current
.pos
, 0);
13349 /* Not much we can do about it. */
13353 /* Consider the following case: Window starts at BEGV, there is
13354 invisible, intangible text at BEGV, so that display starts at
13355 some point START > BEGV. It can happen that we are called with
13356 PT somewhere between BEGV and START. Try to handle that case. */
13357 if (w
->cursor
.vpos
< 0)
13359 struct glyph_row
*row
= w
->current_matrix
->rows
;
13360 if (row
->mode_line_p
)
13362 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13365 if (!cursor_row_fully_visible_p (w
, 0, 0))
13367 /* If vscroll is enabled, disable it and try again. */
13371 clear_glyph_matrix (w
->desired_matrix
);
13375 /* If centering point failed to make the whole line visible,
13376 put point at the top instead. That has to make the whole line
13377 visible, if it can be done. */
13378 if (centering_position
== 0)
13381 clear_glyph_matrix (w
->desired_matrix
);
13382 centering_position
= 0;
13388 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13389 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13390 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13393 /* Display the mode line, if we must. */
13394 if ((update_mode_line
13395 /* If window not full width, must redo its mode line
13396 if (a) the window to its side is being redone and
13397 (b) we do a frame-based redisplay. This is a consequence
13398 of how inverted lines are drawn in frame-based redisplay. */
13399 || (!just_this_one_p
13400 && !FRAME_WINDOW_P (f
)
13401 && !WINDOW_FULL_WIDTH_P (w
))
13402 /* Line number to display. */
13403 || INTEGERP (w
->base_line_pos
)
13404 /* Column number is displayed and different from the one displayed. */
13405 || (!NILP (w
->column_number_displayed
)
13406 && (XFASTINT (w
->column_number_displayed
)
13407 != (int) current_column ()))) /* iftc */
13408 /* This means that the window has a mode line. */
13409 && (WINDOW_WANTS_MODELINE_P (w
)
13410 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13412 display_mode_lines (w
);
13414 /* If mode line height has changed, arrange for a thorough
13415 immediate redisplay using the correct mode line height. */
13416 if (WINDOW_WANTS_MODELINE_P (w
)
13417 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13419 fonts_changed_p
= 1;
13420 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13421 = DESIRED_MODE_LINE_HEIGHT (w
);
13424 /* If top line height has changed, arrange for a thorough
13425 immediate redisplay using the correct mode line height. */
13426 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13427 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13429 fonts_changed_p
= 1;
13430 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13431 = DESIRED_HEADER_LINE_HEIGHT (w
);
13434 if (fonts_changed_p
)
13435 goto need_larger_matrices
;
13438 if (!line_number_displayed
13439 && !BUFFERP (w
->base_line_pos
))
13441 w
->base_line_pos
= Qnil
;
13442 w
->base_line_number
= Qnil
;
13447 /* When we reach a frame's selected window, redo the frame's menu bar. */
13448 if (update_mode_line
13449 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13451 int redisplay_menu_p
= 0;
13452 int redisplay_tool_bar_p
= 0;
13454 if (FRAME_WINDOW_P (f
))
13456 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
13457 || defined (USE_GTK)
13458 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13460 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13464 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13466 if (redisplay_menu_p
)
13467 display_menu_bar (w
);
13469 #ifdef HAVE_WINDOW_SYSTEM
13471 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13473 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13474 && (FRAME_TOOL_BAR_LINES (f
) > 0
13475 || !NILP (Vauto_resize_tool_bars
));
13479 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
13481 extern int ignore_mouse_drag_p
;
13482 ignore_mouse_drag_p
= 1;
13487 #ifdef HAVE_WINDOW_SYSTEM
13488 if (FRAME_WINDOW_P (f
)
13489 && update_window_fringes (w
, (just_this_one_p
13490 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13491 || w
->pseudo_window_p
)))
13495 if (draw_window_fringes (w
, 1))
13496 x_draw_vertical_border (w
);
13500 #endif /* HAVE_WINDOW_SYSTEM */
13502 /* We go to this label, with fonts_changed_p nonzero,
13503 if it is necessary to try again using larger glyph matrices.
13504 We have to redeem the scroll bar even in this case,
13505 because the loop in redisplay_internal expects that. */
13506 need_larger_matrices
:
13508 finish_scroll_bars
:
13510 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13512 /* Set the thumb's position and size. */
13513 set_vertical_scroll_bar (w
);
13515 /* Note that we actually used the scroll bar attached to this
13516 window, so it shouldn't be deleted at the end of redisplay. */
13517 redeem_scroll_bar_hook (w
);
13520 /* Restore current_buffer and value of point in it. */
13521 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13522 set_buffer_internal_1 (old
);
13523 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13525 unbind_to (count
, Qnil
);
13529 /* Build the complete desired matrix of WINDOW with a window start
13530 buffer position POS.
13532 Value is 1 if successful. It is zero if fonts were loaded during
13533 redisplay which makes re-adjusting glyph matrices necessary, and -1
13534 if point would appear in the scroll margins.
13535 (We check that only if CHECK_MARGINS is nonzero. */
13538 try_window (window
, pos
, check_margins
)
13539 Lisp_Object window
;
13540 struct text_pos pos
;
13543 struct window
*w
= XWINDOW (window
);
13545 struct glyph_row
*last_text_row
= NULL
;
13546 struct frame
*f
= XFRAME (w
->frame
);
13548 /* Make POS the new window start. */
13549 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13551 /* Mark cursor position as unknown. No overlay arrow seen. */
13552 w
->cursor
.vpos
= -1;
13553 overlay_arrow_seen
= 0;
13555 /* Initialize iterator and info to start at POS. */
13556 start_display (&it
, w
, pos
);
13558 /* Display all lines of W. */
13559 while (it
.current_y
< it
.last_visible_y
)
13561 if (display_line (&it
))
13562 last_text_row
= it
.glyph_row
- 1;
13563 if (fonts_changed_p
)
13567 /* Don't let the cursor end in the scroll margins. */
13569 && !MINI_WINDOW_P (w
))
13571 int this_scroll_margin
;
13573 this_scroll_margin
= max (0, scroll_margin
);
13574 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13575 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13577 if ((w
->cursor
.y
>= 0 /* not vscrolled */
13578 && w
->cursor
.y
< this_scroll_margin
13579 && CHARPOS (pos
) > BEGV
13580 && IT_CHARPOS (it
) < ZV
)
13581 /* rms: considering make_cursor_line_fully_visible_p here
13582 seems to give wrong results. We don't want to recenter
13583 when the last line is partly visible, we want to allow
13584 that case to be handled in the usual way. */
13585 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
13587 w
->cursor
.vpos
= -1;
13588 clear_glyph_matrix (w
->desired_matrix
);
13593 /* If bottom moved off end of frame, change mode line percentage. */
13594 if (XFASTINT (w
->window_end_pos
) <= 0
13595 && Z
!= IT_CHARPOS (it
))
13596 w
->update_mode_line
= Qt
;
13598 /* Set window_end_pos to the offset of the last character displayed
13599 on the window from the end of current_buffer. Set
13600 window_end_vpos to its row number. */
13603 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
13604 w
->window_end_bytepos
13605 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13607 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13609 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13610 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
13611 ->displays_text_p
);
13615 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13616 w
->window_end_pos
= make_number (Z
- ZV
);
13617 w
->window_end_vpos
= make_number (0);
13620 /* But that is not valid info until redisplay finishes. */
13621 w
->window_end_valid
= Qnil
;
13627 /************************************************************************
13628 Window redisplay reusing current matrix when buffer has not changed
13629 ************************************************************************/
13631 /* Try redisplay of window W showing an unchanged buffer with a
13632 different window start than the last time it was displayed by
13633 reusing its current matrix. Value is non-zero if successful.
13634 W->start is the new window start. */
13637 try_window_reusing_current_matrix (w
)
13640 struct frame
*f
= XFRAME (w
->frame
);
13641 struct glyph_row
*row
, *bottom_row
;
13644 struct text_pos start
, new_start
;
13645 int nrows_scrolled
, i
;
13646 struct glyph_row
*last_text_row
;
13647 struct glyph_row
*last_reused_text_row
;
13648 struct glyph_row
*start_row
;
13649 int start_vpos
, min_y
, max_y
;
13652 if (inhibit_try_window_reusing
)
13656 if (/* This function doesn't handle terminal frames. */
13657 !FRAME_WINDOW_P (f
)
13658 /* Don't try to reuse the display if windows have been split
13660 || windows_or_buffers_changed
13661 || cursor_type_changed
)
13664 /* Can't do this if region may have changed. */
13665 if ((!NILP (Vtransient_mark_mode
)
13666 && !NILP (current_buffer
->mark_active
))
13667 || !NILP (w
->region_showing
)
13668 || !NILP (Vshow_trailing_whitespace
))
13671 /* If top-line visibility has changed, give up. */
13672 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13673 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
13676 /* Give up if old or new display is scrolled vertically. We could
13677 make this function handle this, but right now it doesn't. */
13678 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13679 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
13682 /* The variable new_start now holds the new window start. The old
13683 start `start' can be determined from the current matrix. */
13684 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
13685 start
= start_row
->start
.pos
;
13686 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13688 /* Clear the desired matrix for the display below. */
13689 clear_glyph_matrix (w
->desired_matrix
);
13691 if (CHARPOS (new_start
) <= CHARPOS (start
))
13695 /* Don't use this method if the display starts with an ellipsis
13696 displayed for invisible text. It's not easy to handle that case
13697 below, and it's certainly not worth the effort since this is
13698 not a frequent case. */
13699 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
13702 IF_DEBUG (debug_method_add (w
, "twu1"));
13704 /* Display up to a row that can be reused. The variable
13705 last_text_row is set to the last row displayed that displays
13706 text. Note that it.vpos == 0 if or if not there is a
13707 header-line; it's not the same as the MATRIX_ROW_VPOS! */
13708 start_display (&it
, w
, new_start
);
13709 first_row_y
= it
.current_y
;
13710 w
->cursor
.vpos
= -1;
13711 last_text_row
= last_reused_text_row
= NULL
;
13713 while (it
.current_y
< it
.last_visible_y
13714 && !fonts_changed_p
)
13716 /* If we have reached into the characters in the START row,
13717 that means the line boundaries have changed. So we
13718 can't start copying with the row START. Maybe it will
13719 work to start copying with the following row. */
13720 while (IT_CHARPOS (it
) > CHARPOS (start
))
13722 /* Advance to the next row as the "start". */
13724 start
= start_row
->start
.pos
;
13725 /* If there are no more rows to try, or just one, give up. */
13726 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
13727 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
13728 || CHARPOS (start
) == ZV
)
13730 clear_glyph_matrix (w
->desired_matrix
);
13734 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13736 /* If we have reached alignment,
13737 we can copy the rest of the rows. */
13738 if (IT_CHARPOS (it
) == CHARPOS (start
))
13741 if (display_line (&it
))
13742 last_text_row
= it
.glyph_row
- 1;
13745 /* A value of current_y < last_visible_y means that we stopped
13746 at the previous window start, which in turn means that we
13747 have at least one reusable row. */
13748 if (it
.current_y
< it
.last_visible_y
)
13750 /* IT.vpos always starts from 0; it counts text lines. */
13751 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
13753 /* Find PT if not already found in the lines displayed. */
13754 if (w
->cursor
.vpos
< 0)
13756 int dy
= it
.current_y
- start_row
->y
;
13758 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13759 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
13761 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
13762 dy
, nrows_scrolled
);
13765 clear_glyph_matrix (w
->desired_matrix
);
13770 /* Scroll the display. Do it before the current matrix is
13771 changed. The problem here is that update has not yet
13772 run, i.e. part of the current matrix is not up to date.
13773 scroll_run_hook will clear the cursor, and use the
13774 current matrix to get the height of the row the cursor is
13776 run
.current_y
= start_row
->y
;
13777 run
.desired_y
= it
.current_y
;
13778 run
.height
= it
.last_visible_y
- it
.current_y
;
13780 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
13783 rif
->update_window_begin_hook (w
);
13784 rif
->clear_window_mouse_face (w
);
13785 rif
->scroll_run_hook (w
, &run
);
13786 rif
->update_window_end_hook (w
, 0, 0);
13790 /* Shift current matrix down by nrows_scrolled lines. */
13791 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13792 rotate_matrix (w
->current_matrix
,
13794 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13797 /* Disable lines that must be updated. */
13798 for (i
= 0; i
< nrows_scrolled
; ++i
)
13799 (start_row
+ i
)->enabled_p
= 0;
13801 /* Re-compute Y positions. */
13802 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13803 max_y
= it
.last_visible_y
;
13804 for (row
= start_row
+ nrows_scrolled
;
13808 row
->y
= it
.current_y
;
13809 row
->visible_height
= row
->height
;
13811 if (row
->y
< min_y
)
13812 row
->visible_height
-= min_y
- row
->y
;
13813 if (row
->y
+ row
->height
> max_y
)
13814 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13815 row
->redraw_fringe_bitmaps_p
= 1;
13817 it
.current_y
+= row
->height
;
13819 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13820 last_reused_text_row
= row
;
13821 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13825 /* Disable lines in the current matrix which are now
13826 below the window. */
13827 for (++row
; row
< bottom_row
; ++row
)
13828 row
->enabled_p
= row
->mode_line_p
= 0;
13831 /* Update window_end_pos etc.; last_reused_text_row is the last
13832 reused row from the current matrix containing text, if any.
13833 The value of last_text_row is the last displayed line
13834 containing text. */
13835 if (last_reused_text_row
)
13837 w
->window_end_bytepos
13838 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13840 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13842 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13843 w
->current_matrix
));
13845 else if (last_text_row
)
13847 w
->window_end_bytepos
13848 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13850 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13852 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13856 /* This window must be completely empty. */
13857 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13858 w
->window_end_pos
= make_number (Z
- ZV
);
13859 w
->window_end_vpos
= make_number (0);
13861 w
->window_end_valid
= Qnil
;
13863 /* Update hint: don't try scrolling again in update_window. */
13864 w
->desired_matrix
->no_scrolling_p
= 1;
13867 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13871 else if (CHARPOS (new_start
) > CHARPOS (start
))
13873 struct glyph_row
*pt_row
, *row
;
13874 struct glyph_row
*first_reusable_row
;
13875 struct glyph_row
*first_row_to_display
;
13877 int yb
= window_text_bottom_y (w
);
13879 /* Find the row starting at new_start, if there is one. Don't
13880 reuse a partially visible line at the end. */
13881 first_reusable_row
= start_row
;
13882 while (first_reusable_row
->enabled_p
13883 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13884 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13885 < CHARPOS (new_start
)))
13886 ++first_reusable_row
;
13888 /* Give up if there is no row to reuse. */
13889 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13890 || !first_reusable_row
->enabled_p
13891 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13892 != CHARPOS (new_start
)))
13895 /* We can reuse fully visible rows beginning with
13896 first_reusable_row to the end of the window. Set
13897 first_row_to_display to the first row that cannot be reused.
13898 Set pt_row to the row containing point, if there is any. */
13900 for (first_row_to_display
= first_reusable_row
;
13901 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13902 ++first_row_to_display
)
13904 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
13905 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
13906 pt_row
= first_row_to_display
;
13909 /* Start displaying at the start of first_row_to_display. */
13910 xassert (first_row_to_display
->y
< yb
);
13911 init_to_row_start (&it
, w
, first_row_to_display
);
13913 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
13915 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
13917 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
13918 + WINDOW_HEADER_LINE_HEIGHT (w
));
13920 /* Display lines beginning with first_row_to_display in the
13921 desired matrix. Set last_text_row to the last row displayed
13922 that displays text. */
13923 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
13924 if (pt_row
== NULL
)
13925 w
->cursor
.vpos
= -1;
13926 last_text_row
= NULL
;
13927 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
13928 if (display_line (&it
))
13929 last_text_row
= it
.glyph_row
- 1;
13931 /* Give up If point isn't in a row displayed or reused. */
13932 if (w
->cursor
.vpos
< 0)
13934 clear_glyph_matrix (w
->desired_matrix
);
13938 /* If point is in a reused row, adjust y and vpos of the cursor
13942 w
->cursor
.vpos
-= nrows_scrolled
;
13943 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
13946 /* Scroll the display. */
13947 run
.current_y
= first_reusable_row
->y
;
13948 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13949 run
.height
= it
.last_visible_y
- run
.current_y
;
13950 dy
= run
.current_y
- run
.desired_y
;
13955 rif
->update_window_begin_hook (w
);
13956 rif
->clear_window_mouse_face (w
);
13957 rif
->scroll_run_hook (w
, &run
);
13958 rif
->update_window_end_hook (w
, 0, 0);
13962 /* Adjust Y positions of reused rows. */
13963 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13964 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13965 max_y
= it
.last_visible_y
;
13966 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
13969 row
->visible_height
= row
->height
;
13970 if (row
->y
< min_y
)
13971 row
->visible_height
-= min_y
- row
->y
;
13972 if (row
->y
+ row
->height
> max_y
)
13973 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13974 row
->redraw_fringe_bitmaps_p
= 1;
13977 /* Scroll the current matrix. */
13978 xassert (nrows_scrolled
> 0);
13979 rotate_matrix (w
->current_matrix
,
13981 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13984 /* Disable rows not reused. */
13985 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
13986 row
->enabled_p
= 0;
13988 /* Point may have moved to a different line, so we cannot assume that
13989 the previous cursor position is valid; locate the correct row. */
13992 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
13993 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
13997 w
->cursor
.y
= row
->y
;
13999 if (row
< bottom_row
)
14001 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14002 while (glyph
->charpos
< PT
)
14005 w
->cursor
.x
+= glyph
->pixel_width
;
14011 /* Adjust window end. A null value of last_text_row means that
14012 the window end is in reused rows which in turn means that
14013 only its vpos can have changed. */
14016 w
->window_end_bytepos
14017 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14019 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14021 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14026 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
14029 w
->window_end_valid
= Qnil
;
14030 w
->desired_matrix
->no_scrolling_p
= 1;
14033 debug_method_add (w
, "try_window_reusing_current_matrix 2");
14043 /************************************************************************
14044 Window redisplay reusing current matrix when buffer has changed
14045 ************************************************************************/
14047 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
14048 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
14050 static struct glyph_row
*
14051 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
14052 struct glyph_row
*));
14055 /* Return the last row in MATRIX displaying text. If row START is
14056 non-null, start searching with that row. IT gives the dimensions
14057 of the display. Value is null if matrix is empty; otherwise it is
14058 a pointer to the row found. */
14060 static struct glyph_row
*
14061 find_last_row_displaying_text (matrix
, it
, start
)
14062 struct glyph_matrix
*matrix
;
14064 struct glyph_row
*start
;
14066 struct glyph_row
*row
, *row_found
;
14068 /* Set row_found to the last row in IT->w's current matrix
14069 displaying text. The loop looks funny but think of partially
14072 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14073 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14075 xassert (row
->enabled_p
);
14077 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
14086 /* Return the last row in the current matrix of W that is not affected
14087 by changes at the start of current_buffer that occurred since W's
14088 current matrix was built. Value is null if no such row exists.
14090 BEG_UNCHANGED us the number of characters unchanged at the start of
14091 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
14092 first changed character in current_buffer. Characters at positions <
14093 BEG + BEG_UNCHANGED are at the same buffer positions as they were
14094 when the current matrix was built. */
14096 static struct glyph_row
*
14097 find_last_unchanged_at_beg_row (w
)
14100 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
14101 struct glyph_row
*row
;
14102 struct glyph_row
*row_found
= NULL
;
14103 int yb
= window_text_bottom_y (w
);
14105 /* Find the last row displaying unchanged text. */
14106 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14107 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14108 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
14110 if (/* If row ends before first_changed_pos, it is unchanged,
14111 except in some case. */
14112 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
14113 /* When row ends in ZV and we write at ZV it is not
14115 && !row
->ends_at_zv_p
14116 /* When first_changed_pos is the end of a continued line,
14117 row is not unchanged because it may be no longer
14119 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
14120 && (row
->continued_p
14121 || row
->exact_window_width_line_p
)))
14124 /* Stop if last visible row. */
14125 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
14135 /* Find the first glyph row in the current matrix of W that is not
14136 affected by changes at the end of current_buffer since the
14137 time W's current matrix was built.
14139 Return in *DELTA the number of chars by which buffer positions in
14140 unchanged text at the end of current_buffer must be adjusted.
14142 Return in *DELTA_BYTES the corresponding number of bytes.
14144 Value is null if no such row exists, i.e. all rows are affected by
14147 static struct glyph_row
*
14148 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
14150 int *delta
, *delta_bytes
;
14152 struct glyph_row
*row
;
14153 struct glyph_row
*row_found
= NULL
;
14155 *delta
= *delta_bytes
= 0;
14157 /* Display must not have been paused, otherwise the current matrix
14158 is not up to date. */
14159 if (NILP (w
->window_end_valid
))
14162 /* A value of window_end_pos >= END_UNCHANGED means that the window
14163 end is in the range of changed text. If so, there is no
14164 unchanged row at the end of W's current matrix. */
14165 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
14168 /* Set row to the last row in W's current matrix displaying text. */
14169 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14171 /* If matrix is entirely empty, no unchanged row exists. */
14172 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14174 /* The value of row is the last glyph row in the matrix having a
14175 meaningful buffer position in it. The end position of row
14176 corresponds to window_end_pos. This allows us to translate
14177 buffer positions in the current matrix to current buffer
14178 positions for characters not in changed text. */
14179 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14180 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14181 int last_unchanged_pos
, last_unchanged_pos_old
;
14182 struct glyph_row
*first_text_row
14183 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14185 *delta
= Z
- Z_old
;
14186 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14188 /* Set last_unchanged_pos to the buffer position of the last
14189 character in the buffer that has not been changed. Z is the
14190 index + 1 of the last character in current_buffer, i.e. by
14191 subtracting END_UNCHANGED we get the index of the last
14192 unchanged character, and we have to add BEG to get its buffer
14194 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
14195 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
14197 /* Search backward from ROW for a row displaying a line that
14198 starts at a minimum position >= last_unchanged_pos_old. */
14199 for (; row
> first_text_row
; --row
)
14201 /* This used to abort, but it can happen.
14202 It is ok to just stop the search instead here. KFS. */
14203 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14206 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
14211 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
14218 /* Make sure that glyph rows in the current matrix of window W
14219 reference the same glyph memory as corresponding rows in the
14220 frame's frame matrix. This function is called after scrolling W's
14221 current matrix on a terminal frame in try_window_id and
14222 try_window_reusing_current_matrix. */
14225 sync_frame_with_window_matrix_rows (w
)
14228 struct frame
*f
= XFRAME (w
->frame
);
14229 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
14231 /* Preconditions: W must be a leaf window and full-width. Its frame
14232 must have a frame matrix. */
14233 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
14234 xassert (WINDOW_FULL_WIDTH_P (w
));
14235 xassert (!FRAME_WINDOW_P (f
));
14237 /* If W is a full-width window, glyph pointers in W's current matrix
14238 have, by definition, to be the same as glyph pointers in the
14239 corresponding frame matrix. Note that frame matrices have no
14240 marginal areas (see build_frame_matrix). */
14241 window_row
= w
->current_matrix
->rows
;
14242 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14243 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14244 while (window_row
< window_row_end
)
14246 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14247 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14249 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14250 frame_row
->glyphs
[TEXT_AREA
] = start
;
14251 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14252 frame_row
->glyphs
[LAST_AREA
] = end
;
14254 /* Disable frame rows whose corresponding window rows have
14255 been disabled in try_window_id. */
14256 if (!window_row
->enabled_p
)
14257 frame_row
->enabled_p
= 0;
14259 ++window_row
, ++frame_row
;
14264 /* Find the glyph row in window W containing CHARPOS. Consider all
14265 rows between START and END (not inclusive). END null means search
14266 all rows to the end of the display area of W. Value is the row
14267 containing CHARPOS or null. */
14270 row_containing_pos (w
, charpos
, start
, end
, dy
)
14273 struct glyph_row
*start
, *end
;
14276 struct glyph_row
*row
= start
;
14279 /* If we happen to start on a header-line, skip that. */
14280 if (row
->mode_line_p
)
14283 if ((end
&& row
>= end
) || !row
->enabled_p
)
14286 last_y
= window_text_bottom_y (w
) - dy
;
14290 /* Give up if we have gone too far. */
14291 if (end
&& row
>= end
)
14293 /* This formerly returned if they were equal.
14294 I think that both quantities are of a "last plus one" type;
14295 if so, when they are equal, the row is within the screen. -- rms. */
14296 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14299 /* If it is in this row, return this row. */
14300 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14301 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14302 /* The end position of a row equals the start
14303 position of the next row. If CHARPOS is there, we
14304 would rather display it in the next line, except
14305 when this line ends in ZV. */
14306 && !row
->ends_at_zv_p
14307 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14308 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14315 /* Try to redisplay window W by reusing its existing display. W's
14316 current matrix must be up to date when this function is called,
14317 i.e. window_end_valid must not be nil.
14321 1 if display has been updated
14322 0 if otherwise unsuccessful
14323 -1 if redisplay with same window start is known not to succeed
14325 The following steps are performed:
14327 1. Find the last row in the current matrix of W that is not
14328 affected by changes at the start of current_buffer. If no such row
14331 2. Find the first row in W's current matrix that is not affected by
14332 changes at the end of current_buffer. Maybe there is no such row.
14334 3. Display lines beginning with the row + 1 found in step 1 to the
14335 row found in step 2 or, if step 2 didn't find a row, to the end of
14338 4. If cursor is not known to appear on the window, give up.
14340 5. If display stopped at the row found in step 2, scroll the
14341 display and current matrix as needed.
14343 6. Maybe display some lines at the end of W, if we must. This can
14344 happen under various circumstances, like a partially visible line
14345 becoming fully visible, or because newly displayed lines are displayed
14346 in smaller font sizes.
14348 7. Update W's window end information. */
14354 struct frame
*f
= XFRAME (w
->frame
);
14355 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14356 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14357 struct glyph_row
*last_unchanged_at_beg_row
;
14358 struct glyph_row
*first_unchanged_at_end_row
;
14359 struct glyph_row
*row
;
14360 struct glyph_row
*bottom_row
;
14363 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14364 struct text_pos start_pos
;
14366 int first_unchanged_at_end_vpos
= 0;
14367 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14368 struct text_pos start
;
14369 int first_changed_charpos
, last_changed_charpos
;
14372 if (inhibit_try_window_id
)
14376 /* This is handy for debugging. */
14378 #define GIVE_UP(X) \
14380 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14384 #define GIVE_UP(X) return 0
14387 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14389 /* Don't use this for mini-windows because these can show
14390 messages and mini-buffers, and we don't handle that here. */
14391 if (MINI_WINDOW_P (w
))
14394 /* This flag is used to prevent redisplay optimizations. */
14395 if (windows_or_buffers_changed
|| cursor_type_changed
)
14398 /* Verify that narrowing has not changed.
14399 Also verify that we were not told to prevent redisplay optimizations.
14400 It would be nice to further
14401 reduce the number of cases where this prevents try_window_id. */
14402 if (current_buffer
->clip_changed
14403 || current_buffer
->prevent_redisplay_optimizations_p
)
14406 /* Window must either use window-based redisplay or be full width. */
14407 if (!FRAME_WINDOW_P (f
)
14408 && (!line_ins_del_ok
14409 || !WINDOW_FULL_WIDTH_P (w
)))
14412 /* Give up if point is not known NOT to appear in W. */
14413 if (PT
< CHARPOS (start
))
14416 /* Another way to prevent redisplay optimizations. */
14417 if (XFASTINT (w
->last_modified
) == 0)
14420 /* Verify that window is not hscrolled. */
14421 if (XFASTINT (w
->hscroll
) != 0)
14424 /* Verify that display wasn't paused. */
14425 if (NILP (w
->window_end_valid
))
14428 /* Can't use this if highlighting a region because a cursor movement
14429 will do more than just set the cursor. */
14430 if (!NILP (Vtransient_mark_mode
)
14431 && !NILP (current_buffer
->mark_active
))
14434 /* Likewise if highlighting trailing whitespace. */
14435 if (!NILP (Vshow_trailing_whitespace
))
14438 /* Likewise if showing a region. */
14439 if (!NILP (w
->region_showing
))
14442 /* Can use this if overlay arrow position and or string have changed. */
14443 if (overlay_arrows_changed_p ())
14447 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14448 only if buffer has really changed. The reason is that the gap is
14449 initially at Z for freshly visited files. The code below would
14450 set end_unchanged to 0 in that case. */
14451 if (MODIFF
> SAVE_MODIFF
14452 /* This seems to happen sometimes after saving a buffer. */
14453 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14455 if (GPT
- BEG
< BEG_UNCHANGED
)
14456 BEG_UNCHANGED
= GPT
- BEG
;
14457 if (Z
- GPT
< END_UNCHANGED
)
14458 END_UNCHANGED
= Z
- GPT
;
14461 /* The position of the first and last character that has been changed. */
14462 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14463 last_changed_charpos
= Z
- END_UNCHANGED
;
14465 /* If window starts after a line end, and the last change is in
14466 front of that newline, then changes don't affect the display.
14467 This case happens with stealth-fontification. Note that although
14468 the display is unchanged, glyph positions in the matrix have to
14469 be adjusted, of course. */
14470 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14471 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14472 && ((last_changed_charpos
< CHARPOS (start
)
14473 && CHARPOS (start
) == BEGV
)
14474 || (last_changed_charpos
< CHARPOS (start
) - 1
14475 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14477 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14478 struct glyph_row
*r0
;
14480 /* Compute how many chars/bytes have been added to or removed
14481 from the buffer. */
14482 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14483 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14485 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14487 /* Give up if PT is not in the window. Note that it already has
14488 been checked at the start of try_window_id that PT is not in
14489 front of the window start. */
14490 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14493 /* If window start is unchanged, we can reuse the whole matrix
14494 as is, after adjusting glyph positions. No need to compute
14495 the window end again, since its offset from Z hasn't changed. */
14496 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14497 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14498 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14499 /* PT must not be in a partially visible line. */
14500 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14501 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14503 /* Adjust positions in the glyph matrix. */
14504 if (delta
|| delta_bytes
)
14506 struct glyph_row
*r1
14507 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14508 increment_matrix_positions (w
->current_matrix
,
14509 MATRIX_ROW_VPOS (r0
, current_matrix
),
14510 MATRIX_ROW_VPOS (r1
, current_matrix
),
14511 delta
, delta_bytes
);
14514 /* Set the cursor. */
14515 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14517 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14524 /* Handle the case that changes are all below what is displayed in
14525 the window, and that PT is in the window. This shortcut cannot
14526 be taken if ZV is visible in the window, and text has been added
14527 there that is visible in the window. */
14528 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14529 /* ZV is not visible in the window, or there are no
14530 changes at ZV, actually. */
14531 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14532 || first_changed_charpos
== last_changed_charpos
))
14534 struct glyph_row
*r0
;
14536 /* Give up if PT is not in the window. Note that it already has
14537 been checked at the start of try_window_id that PT is not in
14538 front of the window start. */
14539 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14542 /* If window start is unchanged, we can reuse the whole matrix
14543 as is, without changing glyph positions since no text has
14544 been added/removed in front of the window end. */
14545 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14546 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14547 /* PT must not be in a partially visible line. */
14548 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14549 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14551 /* We have to compute the window end anew since text
14552 can have been added/removed after it. */
14554 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14555 w
->window_end_bytepos
14556 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14558 /* Set the cursor. */
14559 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14561 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14568 /* Give up if window start is in the changed area.
14570 The condition used to read
14572 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
14574 but why that was tested escapes me at the moment. */
14575 if (CHARPOS (start
) >= first_changed_charpos
14576 && CHARPOS (start
) <= last_changed_charpos
)
14579 /* Check that window start agrees with the start of the first glyph
14580 row in its current matrix. Check this after we know the window
14581 start is not in changed text, otherwise positions would not be
14583 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14584 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
14587 /* Give up if the window ends in strings. Overlay strings
14588 at the end are difficult to handle, so don't try. */
14589 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
14590 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
14593 /* Compute the position at which we have to start displaying new
14594 lines. Some of the lines at the top of the window might be
14595 reusable because they are not displaying changed text. Find the
14596 last row in W's current matrix not affected by changes at the
14597 start of current_buffer. Value is null if changes start in the
14598 first line of window. */
14599 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
14600 if (last_unchanged_at_beg_row
)
14602 /* Avoid starting to display in the moddle of a character, a TAB
14603 for instance. This is easier than to set up the iterator
14604 exactly, and it's not a frequent case, so the additional
14605 effort wouldn't really pay off. */
14606 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
14607 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
14608 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
14609 --last_unchanged_at_beg_row
;
14611 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
14614 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
14616 start_pos
= it
.current
.pos
;
14618 /* Start displaying new lines in the desired matrix at the same
14619 vpos we would use in the current matrix, i.e. below
14620 last_unchanged_at_beg_row. */
14621 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
14623 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14624 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
14626 xassert (it
.hpos
== 0 && it
.current_x
== 0);
14630 /* There are no reusable lines at the start of the window.
14631 Start displaying in the first text line. */
14632 start_display (&it
, w
, start
);
14633 it
.vpos
= it
.first_vpos
;
14634 start_pos
= it
.current
.pos
;
14637 /* Find the first row that is not affected by changes at the end of
14638 the buffer. Value will be null if there is no unchanged row, in
14639 which case we must redisplay to the end of the window. delta
14640 will be set to the value by which buffer positions beginning with
14641 first_unchanged_at_end_row have to be adjusted due to text
14643 first_unchanged_at_end_row
14644 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
14645 IF_DEBUG (debug_delta
= delta
);
14646 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
14648 /* Set stop_pos to the buffer position up to which we will have to
14649 display new lines. If first_unchanged_at_end_row != NULL, this
14650 is the buffer position of the start of the line displayed in that
14651 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
14652 that we don't stop at a buffer position. */
14654 if (first_unchanged_at_end_row
)
14656 xassert (last_unchanged_at_beg_row
== NULL
14657 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
14659 /* If this is a continuation line, move forward to the next one
14660 that isn't. Changes in lines above affect this line.
14661 Caution: this may move first_unchanged_at_end_row to a row
14662 not displaying text. */
14663 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
14664 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14665 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14666 < it
.last_visible_y
))
14667 ++first_unchanged_at_end_row
;
14669 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14670 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14671 >= it
.last_visible_y
))
14672 first_unchanged_at_end_row
= NULL
;
14675 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
14677 first_unchanged_at_end_vpos
14678 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
14679 xassert (stop_pos
>= Z
- END_UNCHANGED
);
14682 else if (last_unchanged_at_beg_row
== NULL
)
14688 /* Either there is no unchanged row at the end, or the one we have
14689 now displays text. This is a necessary condition for the window
14690 end pos calculation at the end of this function. */
14691 xassert (first_unchanged_at_end_row
== NULL
14692 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
14694 debug_last_unchanged_at_beg_vpos
14695 = (last_unchanged_at_beg_row
14696 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
14698 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
14700 #endif /* GLYPH_DEBUG != 0 */
14703 /* Display new lines. Set last_text_row to the last new line
14704 displayed which has text on it, i.e. might end up as being the
14705 line where the window_end_vpos is. */
14706 w
->cursor
.vpos
= -1;
14707 last_text_row
= NULL
;
14708 overlay_arrow_seen
= 0;
14709 while (it
.current_y
< it
.last_visible_y
14710 && !fonts_changed_p
14711 && (first_unchanged_at_end_row
== NULL
14712 || IT_CHARPOS (it
) < stop_pos
))
14714 if (display_line (&it
))
14715 last_text_row
= it
.glyph_row
- 1;
14718 if (fonts_changed_p
)
14722 /* Compute differences in buffer positions, y-positions etc. for
14723 lines reused at the bottom of the window. Compute what we can
14725 if (first_unchanged_at_end_row
14726 /* No lines reused because we displayed everything up to the
14727 bottom of the window. */
14728 && it
.current_y
< it
.last_visible_y
)
14731 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
14733 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
14734 run
.current_y
= first_unchanged_at_end_row
->y
;
14735 run
.desired_y
= run
.current_y
+ dy
;
14736 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
14740 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
14741 first_unchanged_at_end_row
= NULL
;
14743 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
14746 /* Find the cursor if not already found. We have to decide whether
14747 PT will appear on this window (it sometimes doesn't, but this is
14748 not a very frequent case.) This decision has to be made before
14749 the current matrix is altered. A value of cursor.vpos < 0 means
14750 that PT is either in one of the lines beginning at
14751 first_unchanged_at_end_row or below the window. Don't care for
14752 lines that might be displayed later at the window end; as
14753 mentioned, this is not a frequent case. */
14754 if (w
->cursor
.vpos
< 0)
14756 /* Cursor in unchanged rows at the top? */
14757 if (PT
< CHARPOS (start_pos
)
14758 && last_unchanged_at_beg_row
)
14760 row
= row_containing_pos (w
, PT
,
14761 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
14762 last_unchanged_at_beg_row
+ 1, 0);
14764 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14767 /* Start from first_unchanged_at_end_row looking for PT. */
14768 else if (first_unchanged_at_end_row
)
14770 row
= row_containing_pos (w
, PT
- delta
,
14771 first_unchanged_at_end_row
, NULL
, 0);
14773 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
14774 delta_bytes
, dy
, dvpos
);
14777 /* Give up if cursor was not found. */
14778 if (w
->cursor
.vpos
< 0)
14780 clear_glyph_matrix (w
->desired_matrix
);
14785 /* Don't let the cursor end in the scroll margins. */
14787 int this_scroll_margin
, cursor_height
;
14789 this_scroll_margin
= max (0, scroll_margin
);
14790 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14791 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14792 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
14794 if ((w
->cursor
.y
< this_scroll_margin
14795 && CHARPOS (start
) > BEGV
)
14796 /* Old redisplay didn't take scroll margin into account at the bottom,
14797 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14798 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14799 ? cursor_height
+ this_scroll_margin
14800 : 1)) > it
.last_visible_y
)
14802 w
->cursor
.vpos
= -1;
14803 clear_glyph_matrix (w
->desired_matrix
);
14808 /* Scroll the display. Do it before changing the current matrix so
14809 that xterm.c doesn't get confused about where the cursor glyph is
14811 if (dy
&& run
.height
)
14815 if (FRAME_WINDOW_P (f
))
14817 rif
->update_window_begin_hook (w
);
14818 rif
->clear_window_mouse_face (w
);
14819 rif
->scroll_run_hook (w
, &run
);
14820 rif
->update_window_end_hook (w
, 0, 0);
14824 /* Terminal frame. In this case, dvpos gives the number of
14825 lines to scroll by; dvpos < 0 means scroll up. */
14826 int first_unchanged_at_end_vpos
14827 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14828 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14829 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14830 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14831 + window_internal_height (w
));
14833 /* Perform the operation on the screen. */
14836 /* Scroll last_unchanged_at_beg_row to the end of the
14837 window down dvpos lines. */
14838 set_terminal_window (end
);
14840 /* On dumb terminals delete dvpos lines at the end
14841 before inserting dvpos empty lines. */
14842 if (!scroll_region_ok
)
14843 ins_del_lines (end
- dvpos
, -dvpos
);
14845 /* Insert dvpos empty lines in front of
14846 last_unchanged_at_beg_row. */
14847 ins_del_lines (from
, dvpos
);
14849 else if (dvpos
< 0)
14851 /* Scroll up last_unchanged_at_beg_vpos to the end of
14852 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14853 set_terminal_window (end
);
14855 /* Delete dvpos lines in front of
14856 last_unchanged_at_beg_vpos. ins_del_lines will set
14857 the cursor to the given vpos and emit |dvpos| delete
14859 ins_del_lines (from
+ dvpos
, dvpos
);
14861 /* On a dumb terminal insert dvpos empty lines at the
14863 if (!scroll_region_ok
)
14864 ins_del_lines (end
+ dvpos
, -dvpos
);
14867 set_terminal_window (0);
14873 /* Shift reused rows of the current matrix to the right position.
14874 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14876 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14877 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14880 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14881 bottom_vpos
, dvpos
);
14882 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14885 else if (dvpos
> 0)
14887 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14888 bottom_vpos
, dvpos
);
14889 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14890 first_unchanged_at_end_vpos
+ dvpos
, 0);
14893 /* For frame-based redisplay, make sure that current frame and window
14894 matrix are in sync with respect to glyph memory. */
14895 if (!FRAME_WINDOW_P (f
))
14896 sync_frame_with_window_matrix_rows (w
);
14898 /* Adjust buffer positions in reused rows. */
14899 if (delta
|| delta_bytes
)
14900 increment_matrix_positions (current_matrix
,
14901 first_unchanged_at_end_vpos
+ dvpos
,
14902 bottom_vpos
, delta
, delta_bytes
);
14904 /* Adjust Y positions. */
14906 shift_glyph_matrix (w
, current_matrix
,
14907 first_unchanged_at_end_vpos
+ dvpos
,
14910 if (first_unchanged_at_end_row
)
14912 first_unchanged_at_end_row
+= dvpos
;
14913 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
14914 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
14915 first_unchanged_at_end_row
= NULL
;
14918 /* If scrolling up, there may be some lines to display at the end of
14920 last_text_row_at_end
= NULL
;
14923 /* Scrolling up can leave for example a partially visible line
14924 at the end of the window to be redisplayed. */
14925 /* Set last_row to the glyph row in the current matrix where the
14926 window end line is found. It has been moved up or down in
14927 the matrix by dvpos. */
14928 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
14929 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
14931 /* If last_row is the window end line, it should display text. */
14932 xassert (last_row
->displays_text_p
);
14934 /* If window end line was partially visible before, begin
14935 displaying at that line. Otherwise begin displaying with the
14936 line following it. */
14937 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
14939 init_to_row_start (&it
, w
, last_row
);
14940 it
.vpos
= last_vpos
;
14941 it
.current_y
= last_row
->y
;
14945 init_to_row_end (&it
, w
, last_row
);
14946 it
.vpos
= 1 + last_vpos
;
14947 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
14951 /* We may start in a continuation line. If so, we have to
14952 get the right continuation_lines_width and current_x. */
14953 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
14954 it
.hpos
= it
.current_x
= 0;
14956 /* Display the rest of the lines at the window end. */
14957 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14958 while (it
.current_y
< it
.last_visible_y
14959 && !fonts_changed_p
)
14961 /* Is it always sure that the display agrees with lines in
14962 the current matrix? I don't think so, so we mark rows
14963 displayed invalid in the current matrix by setting their
14964 enabled_p flag to zero. */
14965 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
14966 if (display_line (&it
))
14967 last_text_row_at_end
= it
.glyph_row
- 1;
14971 /* Update window_end_pos and window_end_vpos. */
14972 if (first_unchanged_at_end_row
14973 && !last_text_row_at_end
)
14975 /* Window end line if one of the preserved rows from the current
14976 matrix. Set row to the last row displaying text in current
14977 matrix starting at first_unchanged_at_end_row, after
14979 xassert (first_unchanged_at_end_row
->displays_text_p
);
14980 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
14981 first_unchanged_at_end_row
);
14982 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
14984 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14985 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14987 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
14988 xassert (w
->window_end_bytepos
>= 0);
14989 IF_DEBUG (debug_method_add (w
, "A"));
14991 else if (last_text_row_at_end
)
14994 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
14995 w
->window_end_bytepos
14996 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
14998 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
14999 xassert (w
->window_end_bytepos
>= 0);
15000 IF_DEBUG (debug_method_add (w
, "B"));
15002 else if (last_text_row
)
15004 /* We have displayed either to the end of the window or at the
15005 end of the window, i.e. the last row with text is to be found
15006 in the desired matrix. */
15008 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15009 w
->window_end_bytepos
15010 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15012 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
15013 xassert (w
->window_end_bytepos
>= 0);
15015 else if (first_unchanged_at_end_row
== NULL
15016 && last_text_row
== NULL
15017 && last_text_row_at_end
== NULL
)
15019 /* Displayed to end of window, but no line containing text was
15020 displayed. Lines were deleted at the end of the window. */
15021 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
15022 int vpos
= XFASTINT (w
->window_end_vpos
);
15023 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
15024 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
15027 row
== NULL
&& vpos
>= first_vpos
;
15028 --vpos
, --current_row
, --desired_row
)
15030 if (desired_row
->enabled_p
)
15032 if (desired_row
->displays_text_p
)
15035 else if (current_row
->displays_text_p
)
15039 xassert (row
!= NULL
);
15040 w
->window_end_vpos
= make_number (vpos
+ 1);
15041 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15042 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15043 xassert (w
->window_end_bytepos
>= 0);
15044 IF_DEBUG (debug_method_add (w
, "C"));
15049 #if 0 /* This leads to problems, for instance when the cursor is
15050 at ZV, and the cursor line displays no text. */
15051 /* Disable rows below what's displayed in the window. This makes
15052 debugging easier. */
15053 enable_glyph_matrix_rows (current_matrix
,
15054 XFASTINT (w
->window_end_vpos
) + 1,
15058 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
15059 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
15061 /* Record that display has not been completed. */
15062 w
->window_end_valid
= Qnil
;
15063 w
->desired_matrix
->no_scrolling_p
= 1;
15071 /***********************************************************************
15072 More debugging support
15073 ***********************************************************************/
15077 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
15078 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
15079 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
15082 /* Dump the contents of glyph matrix MATRIX on stderr.
15084 GLYPHS 0 means don't show glyph contents.
15085 GLYPHS 1 means show glyphs in short form
15086 GLYPHS > 1 means show glyphs in long form. */
15089 dump_glyph_matrix (matrix
, glyphs
)
15090 struct glyph_matrix
*matrix
;
15094 for (i
= 0; i
< matrix
->nrows
; ++i
)
15095 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
15099 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
15100 the glyph row and area where the glyph comes from. */
15103 dump_glyph (row
, glyph
, area
)
15104 struct glyph_row
*row
;
15105 struct glyph
*glyph
;
15108 if (glyph
->type
== CHAR_GLYPH
)
15111 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15112 glyph
- row
->glyphs
[TEXT_AREA
],
15115 (BUFFERP (glyph
->object
)
15117 : (STRINGP (glyph
->object
)
15120 glyph
->pixel_width
,
15122 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
15126 glyph
->left_box_line_p
,
15127 glyph
->right_box_line_p
);
15129 else if (glyph
->type
== STRETCH_GLYPH
)
15132 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15133 glyph
- row
->glyphs
[TEXT_AREA
],
15136 (BUFFERP (glyph
->object
)
15138 : (STRINGP (glyph
->object
)
15141 glyph
->pixel_width
,
15145 glyph
->left_box_line_p
,
15146 glyph
->right_box_line_p
);
15148 else if (glyph
->type
== IMAGE_GLYPH
)
15151 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15152 glyph
- row
->glyphs
[TEXT_AREA
],
15155 (BUFFERP (glyph
->object
)
15157 : (STRINGP (glyph
->object
)
15160 glyph
->pixel_width
,
15164 glyph
->left_box_line_p
,
15165 glyph
->right_box_line_p
);
15167 else if (glyph
->type
== COMPOSITE_GLYPH
)
15170 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15171 glyph
- row
->glyphs
[TEXT_AREA
],
15174 (BUFFERP (glyph
->object
)
15176 : (STRINGP (glyph
->object
)
15179 glyph
->pixel_width
,
15183 glyph
->left_box_line_p
,
15184 glyph
->right_box_line_p
);
15189 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
15190 GLYPHS 0 means don't show glyph contents.
15191 GLYPHS 1 means show glyphs in short form
15192 GLYPHS > 1 means show glyphs in long form. */
15195 dump_glyph_row (row
, vpos
, glyphs
)
15196 struct glyph_row
*row
;
15201 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
15202 fprintf (stderr
, "======================================================================\n");
15204 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
15205 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
15207 MATRIX_ROW_START_CHARPOS (row
),
15208 MATRIX_ROW_END_CHARPOS (row
),
15209 row
->used
[TEXT_AREA
],
15210 row
->contains_overlapping_glyphs_p
,
15212 row
->truncated_on_left_p
,
15213 row
->truncated_on_right_p
,
15215 MATRIX_ROW_CONTINUATION_LINE_P (row
),
15216 row
->displays_text_p
,
15219 row
->ends_in_middle_of_char_p
,
15220 row
->starts_in_middle_of_char_p
,
15226 row
->visible_height
,
15229 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
15230 row
->end
.overlay_string_index
,
15231 row
->continuation_lines_width
);
15232 fprintf (stderr
, "%9d %5d\n",
15233 CHARPOS (row
->start
.string_pos
),
15234 CHARPOS (row
->end
.string_pos
));
15235 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
15236 row
->end
.dpvec_index
);
15243 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15245 struct glyph
*glyph
= row
->glyphs
[area
];
15246 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
15248 /* Glyph for a line end in text. */
15249 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
15252 if (glyph
< glyph_end
)
15253 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15255 for (; glyph
< glyph_end
; ++glyph
)
15256 dump_glyph (row
, glyph
, area
);
15259 else if (glyphs
== 1)
15263 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15265 char *s
= (char *) alloca (row
->used
[area
] + 1);
15268 for (i
= 0; i
< row
->used
[area
]; ++i
)
15270 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15271 if (glyph
->type
== CHAR_GLYPH
15272 && glyph
->u
.ch
< 0x80
15273 && glyph
->u
.ch
>= ' ')
15274 s
[i
] = glyph
->u
.ch
;
15280 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15286 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15287 Sdump_glyph_matrix
, 0, 1, "p",
15288 doc
: /* Dump the current matrix of the selected window to stderr.
15289 Shows contents of glyph row structures. With non-nil
15290 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15291 glyphs in short form, otherwise show glyphs in long form. */)
15293 Lisp_Object glyphs
;
15295 struct window
*w
= XWINDOW (selected_window
);
15296 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15298 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15299 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15300 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15301 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15302 fprintf (stderr
, "=============================================\n");
15303 dump_glyph_matrix (w
->current_matrix
,
15304 NILP (glyphs
) ? 0 : XINT (glyphs
));
15309 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15310 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15313 struct frame
*f
= XFRAME (selected_frame
);
15314 dump_glyph_matrix (f
->current_matrix
, 1);
15319 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15320 doc
: /* Dump glyph row ROW to stderr.
15321 GLYPH 0 means don't dump glyphs.
15322 GLYPH 1 means dump glyphs in short form.
15323 GLYPH > 1 or omitted means dump glyphs in long form. */)
15325 Lisp_Object row
, glyphs
;
15327 struct glyph_matrix
*matrix
;
15330 CHECK_NUMBER (row
);
15331 matrix
= XWINDOW (selected_window
)->current_matrix
;
15333 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15334 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15336 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15341 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15342 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15343 GLYPH 0 means don't dump glyphs.
15344 GLYPH 1 means dump glyphs in short form.
15345 GLYPH > 1 or omitted means dump glyphs in long form. */)
15347 Lisp_Object row
, glyphs
;
15349 struct frame
*sf
= SELECTED_FRAME ();
15350 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15353 CHECK_NUMBER (row
);
15355 if (vpos
>= 0 && vpos
< m
->nrows
)
15356 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15357 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15362 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15363 doc
: /* Toggle tracing of redisplay.
15364 With ARG, turn tracing on if and only if ARG is positive. */)
15369 trace_redisplay_p
= !trace_redisplay_p
;
15372 arg
= Fprefix_numeric_value (arg
);
15373 trace_redisplay_p
= XINT (arg
) > 0;
15380 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15381 doc
: /* Like `format', but print result to stderr.
15382 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15387 Lisp_Object s
= Fformat (nargs
, args
);
15388 fprintf (stderr
, "%s", SDATA (s
));
15392 #endif /* GLYPH_DEBUG */
15396 /***********************************************************************
15397 Building Desired Matrix Rows
15398 ***********************************************************************/
15400 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15401 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15403 static struct glyph_row
*
15404 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15406 Lisp_Object overlay_arrow_string
;
15408 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15409 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15410 struct buffer
*old
= current_buffer
;
15411 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15412 int arrow_len
= SCHARS (overlay_arrow_string
);
15413 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15414 const unsigned char *p
;
15417 int n_glyphs_before
;
15419 set_buffer_temp (buffer
);
15420 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15421 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15422 SET_TEXT_POS (it
.position
, 0, 0);
15424 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15426 while (p
< arrow_end
)
15428 Lisp_Object face
, ilisp
;
15430 /* Get the next character. */
15432 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15434 it
.c
= *p
, it
.len
= 1;
15437 /* Get its face. */
15438 ilisp
= make_number (p
- arrow_string
);
15439 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15440 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15442 /* Compute its width, get its glyphs. */
15443 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15444 SET_TEXT_POS (it
.position
, -1, -1);
15445 PRODUCE_GLYPHS (&it
);
15447 /* If this character doesn't fit any more in the line, we have
15448 to remove some glyphs. */
15449 if (it
.current_x
> it
.last_visible_x
)
15451 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15456 set_buffer_temp (old
);
15457 return it
.glyph_row
;
15461 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15462 glyphs are only inserted for terminal frames since we can't really
15463 win with truncation glyphs when partially visible glyphs are
15464 involved. Which glyphs to insert is determined by
15465 produce_special_glyphs. */
15468 insert_left_trunc_glyphs (it
)
15471 struct it truncate_it
;
15472 struct glyph
*from
, *end
, *to
, *toend
;
15474 xassert (!FRAME_WINDOW_P (it
->f
));
15476 /* Get the truncation glyphs. */
15478 truncate_it
.current_x
= 0;
15479 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15480 truncate_it
.glyph_row
= &scratch_glyph_row
;
15481 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15482 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15483 truncate_it
.object
= make_number (0);
15484 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15486 /* Overwrite glyphs from IT with truncation glyphs. */
15487 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15488 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15489 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15490 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15495 /* There may be padding glyphs left over. Overwrite them too. */
15496 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15498 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15504 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15508 /* Compute the pixel height and width of IT->glyph_row.
15510 Most of the time, ascent and height of a display line will be equal
15511 to the max_ascent and max_height values of the display iterator
15512 structure. This is not the case if
15514 1. We hit ZV without displaying anything. In this case, max_ascent
15515 and max_height will be zero.
15517 2. We have some glyphs that don't contribute to the line height.
15518 (The glyph row flag contributes_to_line_height_p is for future
15519 pixmap extensions).
15521 The first case is easily covered by using default values because in
15522 these cases, the line height does not really matter, except that it
15523 must not be zero. */
15526 compute_line_metrics (it
)
15529 struct glyph_row
*row
= it
->glyph_row
;
15532 if (FRAME_WINDOW_P (it
->f
))
15534 int i
, min_y
, max_y
;
15536 /* The line may consist of one space only, that was added to
15537 place the cursor on it. If so, the row's height hasn't been
15539 if (row
->height
== 0)
15541 if (it
->max_ascent
+ it
->max_descent
== 0)
15542 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15543 row
->ascent
= it
->max_ascent
;
15544 row
->height
= it
->max_ascent
+ it
->max_descent
;
15545 row
->phys_ascent
= it
->max_phys_ascent
;
15546 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15547 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15550 /* Compute the width of this line. */
15551 row
->pixel_width
= row
->x
;
15552 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15553 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15555 xassert (row
->pixel_width
>= 0);
15556 xassert (row
->ascent
>= 0 && row
->height
> 0);
15558 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15559 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15561 /* If first line's physical ascent is larger than its logical
15562 ascent, use the physical ascent, and make the row taller.
15563 This makes accented characters fully visible. */
15564 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
15565 && row
->phys_ascent
> row
->ascent
)
15567 row
->height
+= row
->phys_ascent
- row
->ascent
;
15568 row
->ascent
= row
->phys_ascent
;
15571 /* Compute how much of the line is visible. */
15572 row
->visible_height
= row
->height
;
15574 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
15575 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
15577 if (row
->y
< min_y
)
15578 row
->visible_height
-= min_y
- row
->y
;
15579 if (row
->y
+ row
->height
> max_y
)
15580 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15584 row
->pixel_width
= row
->used
[TEXT_AREA
];
15585 if (row
->continued_p
)
15586 row
->pixel_width
-= it
->continuation_pixel_width
;
15587 else if (row
->truncated_on_right_p
)
15588 row
->pixel_width
-= it
->truncation_pixel_width
;
15589 row
->ascent
= row
->phys_ascent
= 0;
15590 row
->height
= row
->phys_height
= row
->visible_height
= 1;
15591 row
->extra_line_spacing
= 0;
15594 /* Compute a hash code for this row. */
15596 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15597 for (i
= 0; i
< row
->used
[area
]; ++i
)
15598 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
15599 + row
->glyphs
[area
][i
].u
.val
15600 + row
->glyphs
[area
][i
].face_id
15601 + row
->glyphs
[area
][i
].padding_p
15602 + (row
->glyphs
[area
][i
].type
<< 2));
15604 it
->max_ascent
= it
->max_descent
= 0;
15605 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
15609 /* Append one space to the glyph row of iterator IT if doing a
15610 window-based redisplay. The space has the same face as
15611 IT->face_id. Value is non-zero if a space was added.
15613 This function is called to make sure that there is always one glyph
15614 at the end of a glyph row that the cursor can be set on under
15615 window-systems. (If there weren't such a glyph we would not know
15616 how wide and tall a box cursor should be displayed).
15618 At the same time this space let's a nicely handle clearing to the
15619 end of the line if the row ends in italic text. */
15622 append_space_for_newline (it
, default_face_p
)
15624 int default_face_p
;
15626 if (FRAME_WINDOW_P (it
->f
))
15628 int n
= it
->glyph_row
->used
[TEXT_AREA
];
15630 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
15631 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
15633 /* Save some values that must not be changed.
15634 Must save IT->c and IT->len because otherwise
15635 ITERATOR_AT_END_P wouldn't work anymore after
15636 append_space_for_newline has been called. */
15637 enum display_element_type saved_what
= it
->what
;
15638 int saved_c
= it
->c
, saved_len
= it
->len
;
15639 int saved_x
= it
->current_x
;
15640 int saved_face_id
= it
->face_id
;
15641 struct text_pos saved_pos
;
15642 Lisp_Object saved_object
;
15645 saved_object
= it
->object
;
15646 saved_pos
= it
->position
;
15648 it
->what
= IT_CHARACTER
;
15649 bzero (&it
->position
, sizeof it
->position
);
15650 it
->object
= make_number (0);
15654 if (default_face_p
)
15655 it
->face_id
= DEFAULT_FACE_ID
;
15656 else if (it
->face_before_selective_p
)
15657 it
->face_id
= it
->saved_face_id
;
15658 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15659 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
15661 PRODUCE_GLYPHS (it
);
15663 it
->override_ascent
= -1;
15664 it
->constrain_row_ascent_descent_p
= 0;
15665 it
->current_x
= saved_x
;
15666 it
->object
= saved_object
;
15667 it
->position
= saved_pos
;
15668 it
->what
= saved_what
;
15669 it
->face_id
= saved_face_id
;
15670 it
->len
= saved_len
;
15680 /* Extend the face of the last glyph in the text area of IT->glyph_row
15681 to the end of the display line. Called from display_line.
15682 If the glyph row is empty, add a space glyph to it so that we
15683 know the face to draw. Set the glyph row flag fill_line_p. */
15686 extend_face_to_end_of_line (it
)
15690 struct frame
*f
= it
->f
;
15692 /* If line is already filled, do nothing. */
15693 if (it
->current_x
>= it
->last_visible_x
)
15696 /* Face extension extends the background and box of IT->face_id
15697 to the end of the line. If the background equals the background
15698 of the frame, we don't have to do anything. */
15699 if (it
->face_before_selective_p
)
15700 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
15702 face
= FACE_FROM_ID (f
, it
->face_id
);
15704 if (FRAME_WINDOW_P (f
)
15705 && it
->glyph_row
->displays_text_p
15706 && face
->box
== FACE_NO_BOX
15707 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
15711 /* Set the glyph row flag indicating that the face of the last glyph
15712 in the text area has to be drawn to the end of the text area. */
15713 it
->glyph_row
->fill_line_p
= 1;
15715 /* If current character of IT is not ASCII, make sure we have the
15716 ASCII face. This will be automatically undone the next time
15717 get_next_display_element returns a multibyte character. Note
15718 that the character will always be single byte in unibyte text. */
15719 if (!SINGLE_BYTE_CHAR_P (it
->c
))
15721 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
15724 if (FRAME_WINDOW_P (f
))
15726 /* If the row is empty, add a space with the current face of IT,
15727 so that we know which face to draw. */
15728 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
15730 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
15731 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
15732 it
->glyph_row
->used
[TEXT_AREA
] = 1;
15737 /* Save some values that must not be changed. */
15738 int saved_x
= it
->current_x
;
15739 struct text_pos saved_pos
;
15740 Lisp_Object saved_object
;
15741 enum display_element_type saved_what
= it
->what
;
15742 int saved_face_id
= it
->face_id
;
15744 saved_object
= it
->object
;
15745 saved_pos
= it
->position
;
15747 it
->what
= IT_CHARACTER
;
15748 bzero (&it
->position
, sizeof it
->position
);
15749 it
->object
= make_number (0);
15752 it
->face_id
= face
->id
;
15754 PRODUCE_GLYPHS (it
);
15756 while (it
->current_x
<= it
->last_visible_x
)
15757 PRODUCE_GLYPHS (it
);
15759 /* Don't count these blanks really. It would let us insert a left
15760 truncation glyph below and make us set the cursor on them, maybe. */
15761 it
->current_x
= saved_x
;
15762 it
->object
= saved_object
;
15763 it
->position
= saved_pos
;
15764 it
->what
= saved_what
;
15765 it
->face_id
= saved_face_id
;
15770 /* Value is non-zero if text starting at CHARPOS in current_buffer is
15771 trailing whitespace. */
15774 trailing_whitespace_p (charpos
)
15777 int bytepos
= CHAR_TO_BYTE (charpos
);
15780 while (bytepos
< ZV_BYTE
15781 && (c
= FETCH_CHAR (bytepos
),
15782 c
== ' ' || c
== '\t'))
15785 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
15787 if (bytepos
!= PT_BYTE
)
15794 /* Highlight trailing whitespace, if any, in ROW. */
15797 highlight_trailing_whitespace (f
, row
)
15799 struct glyph_row
*row
;
15801 int used
= row
->used
[TEXT_AREA
];
15805 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
15806 struct glyph
*glyph
= start
+ used
- 1;
15808 /* Skip over glyphs inserted to display the cursor at the
15809 end of a line, for extending the face of the last glyph
15810 to the end of the line on terminals, and for truncation
15811 and continuation glyphs. */
15812 while (glyph
>= start
15813 && glyph
->type
== CHAR_GLYPH
15814 && INTEGERP (glyph
->object
))
15817 /* If last glyph is a space or stretch, and it's trailing
15818 whitespace, set the face of all trailing whitespace glyphs in
15819 IT->glyph_row to `trailing-whitespace'. */
15821 && BUFFERP (glyph
->object
)
15822 && (glyph
->type
== STRETCH_GLYPH
15823 || (glyph
->type
== CHAR_GLYPH
15824 && glyph
->u
.ch
== ' '))
15825 && trailing_whitespace_p (glyph
->charpos
))
15827 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
15831 while (glyph
>= start
15832 && BUFFERP (glyph
->object
)
15833 && (glyph
->type
== STRETCH_GLYPH
15834 || (glyph
->type
== CHAR_GLYPH
15835 && glyph
->u
.ch
== ' ')))
15836 (glyph
--)->face_id
= face_id
;
15842 /* Value is non-zero if glyph row ROW in window W should be
15843 used to hold the cursor. */
15846 cursor_row_p (w
, row
)
15848 struct glyph_row
*row
;
15850 int cursor_row_p
= 1;
15852 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15854 /* Suppose the row ends on a string.
15855 Unless the row is continued, that means it ends on a newline
15856 in the string. If it's anything other than a display string
15857 (e.g. a before-string from an overlay), we don't want the
15858 cursor there. (This heuristic seems to give the optimal
15859 behavior for the various types of multi-line strings.) */
15860 if (CHARPOS (row
->end
.string_pos
) >= 0)
15862 if (row
->continued_p
)
15866 /* Check for `display' property. */
15867 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
15868 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
15869 struct glyph
*glyph
;
15872 for (glyph
= end
; glyph
>= beg
; --glyph
)
15873 if (STRINGP (glyph
->object
))
15876 = Fget_char_property (make_number (PT
),
15880 && display_prop_string_p (prop
, glyph
->object
));
15885 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15887 /* If the row ends in middle of a real character,
15888 and the line is continued, we want the cursor here.
15889 That's because MATRIX_ROW_END_CHARPOS would equal
15890 PT if PT is before the character. */
15891 if (!row
->ends_in_ellipsis_p
)
15892 cursor_row_p
= row
->continued_p
;
15894 /* If the row ends in an ellipsis, then
15895 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15896 We want that position to be displayed after the ellipsis. */
15899 /* If the row ends at ZV, display the cursor at the end of that
15900 row instead of at the start of the row below. */
15901 else if (row
->ends_at_zv_p
)
15907 return cursor_row_p
;
15911 /* Construct the glyph row IT->glyph_row in the desired matrix of
15912 IT->w from text at the current position of IT. See dispextern.h
15913 for an overview of struct it. Value is non-zero if
15914 IT->glyph_row displays text, as opposed to a line displaying ZV
15921 struct glyph_row
*row
= it
->glyph_row
;
15922 Lisp_Object overlay_arrow_string
;
15924 /* We always start displaying at hpos zero even if hscrolled. */
15925 xassert (it
->hpos
== 0 && it
->current_x
== 0);
15927 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
15928 >= it
->w
->desired_matrix
->nrows
)
15930 it
->w
->nrows_scale_factor
++;
15931 fonts_changed_p
= 1;
15935 /* Is IT->w showing the region? */
15936 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
15938 /* Clear the result glyph row and enable it. */
15939 prepare_desired_row (row
);
15941 row
->y
= it
->current_y
;
15942 row
->start
= it
->start
;
15943 row
->continuation_lines_width
= it
->continuation_lines_width
;
15944 row
->displays_text_p
= 1;
15945 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
15946 it
->starts_in_middle_of_char_p
= 0;
15948 /* Arrange the overlays nicely for our purposes. Usually, we call
15949 display_line on only one line at a time, in which case this
15950 can't really hurt too much, or we call it on lines which appear
15951 one after another in the buffer, in which case all calls to
15952 recenter_overlay_lists but the first will be pretty cheap. */
15953 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
15955 /* Move over display elements that are not visible because we are
15956 hscrolled. This may stop at an x-position < IT->first_visible_x
15957 if the first glyph is partially visible or if we hit a line end. */
15958 if (it
->current_x
< it
->first_visible_x
)
15960 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
15961 MOVE_TO_POS
| MOVE_TO_X
);
15964 /* Get the initial row height. This is either the height of the
15965 text hscrolled, if there is any, or zero. */
15966 row
->ascent
= it
->max_ascent
;
15967 row
->height
= it
->max_ascent
+ it
->max_descent
;
15968 row
->phys_ascent
= it
->max_phys_ascent
;
15969 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15970 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15972 /* Loop generating characters. The loop is left with IT on the next
15973 character to display. */
15976 int n_glyphs_before
, hpos_before
, x_before
;
15978 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
15980 /* Retrieve the next thing to display. Value is zero if end of
15982 if (!get_next_display_element (it
))
15984 /* Maybe add a space at the end of this line that is used to
15985 display the cursor there under X. Set the charpos of the
15986 first glyph of blank lines not corresponding to any text
15988 #ifdef HAVE_WINDOW_SYSTEM
15989 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15990 row
->exact_window_width_line_p
= 1;
15992 #endif /* HAVE_WINDOW_SYSTEM */
15993 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
15994 || row
->used
[TEXT_AREA
] == 0)
15996 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
15997 row
->displays_text_p
= 0;
15999 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
16000 && (!MINI_WINDOW_P (it
->w
)
16001 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
16002 row
->indicate_empty_line_p
= 1;
16005 it
->continuation_lines_width
= 0;
16006 row
->ends_at_zv_p
= 1;
16010 /* Now, get the metrics of what we want to display. This also
16011 generates glyphs in `row' (which is IT->glyph_row). */
16012 n_glyphs_before
= row
->used
[TEXT_AREA
];
16015 /* Remember the line height so far in case the next element doesn't
16016 fit on the line. */
16017 if (!it
->truncate_lines_p
)
16019 ascent
= it
->max_ascent
;
16020 descent
= it
->max_descent
;
16021 phys_ascent
= it
->max_phys_ascent
;
16022 phys_descent
= it
->max_phys_descent
;
16025 PRODUCE_GLYPHS (it
);
16027 /* If this display element was in marginal areas, continue with
16029 if (it
->area
!= TEXT_AREA
)
16031 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16032 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16033 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16034 row
->phys_height
= max (row
->phys_height
,
16035 it
->max_phys_ascent
+ it
->max_phys_descent
);
16036 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16037 it
->max_extra_line_spacing
);
16038 set_iterator_to_next (it
, 1);
16042 /* Does the display element fit on the line? If we truncate
16043 lines, we should draw past the right edge of the window. If
16044 we don't truncate, we want to stop so that we can display the
16045 continuation glyph before the right margin. If lines are
16046 continued, there are two possible strategies for characters
16047 resulting in more than 1 glyph (e.g. tabs): Display as many
16048 glyphs as possible in this line and leave the rest for the
16049 continuation line, or display the whole element in the next
16050 line. Original redisplay did the former, so we do it also. */
16051 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
16052 hpos_before
= it
->hpos
;
16055 if (/* Not a newline. */
16057 /* Glyphs produced fit entirely in the line. */
16058 && it
->current_x
< it
->last_visible_x
)
16060 it
->hpos
+= nglyphs
;
16061 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16062 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16063 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16064 row
->phys_height
= max (row
->phys_height
,
16065 it
->max_phys_ascent
+ it
->max_phys_descent
);
16066 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16067 it
->max_extra_line_spacing
);
16068 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
16069 row
->x
= x
- it
->first_visible_x
;
16074 struct glyph
*glyph
;
16076 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
16078 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16079 new_x
= x
+ glyph
->pixel_width
;
16081 if (/* Lines are continued. */
16082 !it
->truncate_lines_p
16083 && (/* Glyph doesn't fit on the line. */
16084 new_x
> it
->last_visible_x
16085 /* Or it fits exactly on a window system frame. */
16086 || (new_x
== it
->last_visible_x
16087 && FRAME_WINDOW_P (it
->f
))))
16089 /* End of a continued line. */
16092 || (new_x
== it
->last_visible_x
16093 && FRAME_WINDOW_P (it
->f
)))
16095 /* Current glyph is the only one on the line or
16096 fits exactly on the line. We must continue
16097 the line because we can't draw the cursor
16098 after the glyph. */
16099 row
->continued_p
= 1;
16100 it
->current_x
= new_x
;
16101 it
->continuation_lines_width
+= new_x
;
16103 if (i
== nglyphs
- 1)
16105 set_iterator_to_next (it
, 1);
16106 #ifdef HAVE_WINDOW_SYSTEM
16107 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16109 if (!get_next_display_element (it
))
16111 row
->exact_window_width_line_p
= 1;
16112 it
->continuation_lines_width
= 0;
16113 row
->continued_p
= 0;
16114 row
->ends_at_zv_p
= 1;
16116 else if (ITERATOR_AT_END_OF_LINE_P (it
))
16118 row
->continued_p
= 0;
16119 row
->exact_window_width_line_p
= 1;
16122 #endif /* HAVE_WINDOW_SYSTEM */
16125 else if (CHAR_GLYPH_PADDING_P (*glyph
)
16126 && !FRAME_WINDOW_P (it
->f
))
16128 /* A padding glyph that doesn't fit on this line.
16129 This means the whole character doesn't fit
16131 row
->used
[TEXT_AREA
] = n_glyphs_before
;
16133 /* Fill the rest of the row with continuation
16134 glyphs like in 20.x. */
16135 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
16136 < row
->glyphs
[1 + TEXT_AREA
])
16137 produce_special_glyphs (it
, IT_CONTINUATION
);
16139 row
->continued_p
= 1;
16140 it
->current_x
= x_before
;
16141 it
->continuation_lines_width
+= x_before
;
16143 /* Restore the height to what it was before the
16144 element not fitting on the line. */
16145 it
->max_ascent
= ascent
;
16146 it
->max_descent
= descent
;
16147 it
->max_phys_ascent
= phys_ascent
;
16148 it
->max_phys_descent
= phys_descent
;
16150 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
16152 /* A TAB that extends past the right edge of the
16153 window. This produces a single glyph on
16154 window system frames. We leave the glyph in
16155 this row and let it fill the row, but don't
16156 consume the TAB. */
16157 it
->continuation_lines_width
+= it
->last_visible_x
;
16158 row
->ends_in_middle_of_char_p
= 1;
16159 row
->continued_p
= 1;
16160 glyph
->pixel_width
= it
->last_visible_x
- x
;
16161 it
->starts_in_middle_of_char_p
= 1;
16165 /* Something other than a TAB that draws past
16166 the right edge of the window. Restore
16167 positions to values before the element. */
16168 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16170 /* Display continuation glyphs. */
16171 if (!FRAME_WINDOW_P (it
->f
))
16172 produce_special_glyphs (it
, IT_CONTINUATION
);
16173 row
->continued_p
= 1;
16175 it
->current_x
= x_before
;
16176 it
->continuation_lines_width
+= x
;
16177 extend_face_to_end_of_line (it
);
16179 if (nglyphs
> 1 && i
> 0)
16181 row
->ends_in_middle_of_char_p
= 1;
16182 it
->starts_in_middle_of_char_p
= 1;
16185 /* Restore the height to what it was before the
16186 element not fitting on the line. */
16187 it
->max_ascent
= ascent
;
16188 it
->max_descent
= descent
;
16189 it
->max_phys_ascent
= phys_ascent
;
16190 it
->max_phys_descent
= phys_descent
;
16195 else if (new_x
> it
->first_visible_x
)
16197 /* Increment number of glyphs actually displayed. */
16200 if (x
< it
->first_visible_x
)
16201 /* Glyph is partially visible, i.e. row starts at
16202 negative X position. */
16203 row
->x
= x
- it
->first_visible_x
;
16207 /* Glyph is completely off the left margin of the
16208 window. This should not happen because of the
16209 move_it_in_display_line at the start of this
16210 function, unless the text display area of the
16211 window is empty. */
16212 xassert (it
->first_visible_x
<= it
->last_visible_x
);
16216 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16217 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16218 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16219 row
->phys_height
= max (row
->phys_height
,
16220 it
->max_phys_ascent
+ it
->max_phys_descent
);
16221 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16222 it
->max_extra_line_spacing
);
16224 /* End of this display line if row is continued. */
16225 if (row
->continued_p
|| row
->ends_at_zv_p
)
16230 /* Is this a line end? If yes, we're also done, after making
16231 sure that a non-default face is extended up to the right
16232 margin of the window. */
16233 if (ITERATOR_AT_END_OF_LINE_P (it
))
16235 int used_before
= row
->used
[TEXT_AREA
];
16237 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
16239 #ifdef HAVE_WINDOW_SYSTEM
16240 /* Add a space at the end of the line that is used to
16241 display the cursor there. */
16242 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16243 append_space_for_newline (it
, 0);
16244 #endif /* HAVE_WINDOW_SYSTEM */
16246 /* Extend the face to the end of the line. */
16247 extend_face_to_end_of_line (it
);
16249 /* Make sure we have the position. */
16250 if (used_before
== 0)
16251 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
16253 /* Consume the line end. This skips over invisible lines. */
16254 set_iterator_to_next (it
, 1);
16255 it
->continuation_lines_width
= 0;
16259 /* Proceed with next display element. Note that this skips
16260 over lines invisible because of selective display. */
16261 set_iterator_to_next (it
, 1);
16263 /* If we truncate lines, we are done when the last displayed
16264 glyphs reach past the right margin of the window. */
16265 if (it
->truncate_lines_p
16266 && (FRAME_WINDOW_P (it
->f
)
16267 ? (it
->current_x
>= it
->last_visible_x
)
16268 : (it
->current_x
> it
->last_visible_x
)))
16270 /* Maybe add truncation glyphs. */
16271 if (!FRAME_WINDOW_P (it
->f
))
16275 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16276 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16279 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16281 row
->used
[TEXT_AREA
] = i
;
16282 produce_special_glyphs (it
, IT_TRUNCATION
);
16285 #ifdef HAVE_WINDOW_SYSTEM
16288 /* Don't truncate if we can overflow newline into fringe. */
16289 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16291 if (!get_next_display_element (it
))
16293 it
->continuation_lines_width
= 0;
16294 row
->ends_at_zv_p
= 1;
16295 row
->exact_window_width_line_p
= 1;
16298 if (ITERATOR_AT_END_OF_LINE_P (it
))
16300 row
->exact_window_width_line_p
= 1;
16301 goto at_end_of_line
;
16305 #endif /* HAVE_WINDOW_SYSTEM */
16307 row
->truncated_on_right_p
= 1;
16308 it
->continuation_lines_width
= 0;
16309 reseat_at_next_visible_line_start (it
, 0);
16310 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16311 it
->hpos
= hpos_before
;
16312 it
->current_x
= x_before
;
16317 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16318 at the left window margin. */
16319 if (it
->first_visible_x
16320 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16322 if (!FRAME_WINDOW_P (it
->f
))
16323 insert_left_trunc_glyphs (it
);
16324 row
->truncated_on_left_p
= 1;
16327 /* If the start of this line is the overlay arrow-position, then
16328 mark this glyph row as the one containing the overlay arrow.
16329 This is clearly a mess with variable size fonts. It would be
16330 better to let it be displayed like cursors under X. */
16331 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16332 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16333 !NILP (overlay_arrow_string
)))
16335 /* Overlay arrow in window redisplay is a fringe bitmap. */
16336 if (STRINGP (overlay_arrow_string
))
16338 struct glyph_row
*arrow_row
16339 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
16340 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
16341 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
16342 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
16343 struct glyph
*p2
, *end
;
16345 /* Copy the arrow glyphs. */
16346 while (glyph
< arrow_end
)
16349 /* Throw away padding glyphs. */
16351 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16352 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
16358 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
16363 xassert (INTEGERP (overlay_arrow_string
));
16364 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
16366 overlay_arrow_seen
= 1;
16369 /* Compute pixel dimensions of this line. */
16370 compute_line_metrics (it
);
16372 /* Remember the position at which this line ends. */
16373 row
->end
= it
->current
;
16375 /* Record whether this row ends inside an ellipsis. */
16376 row
->ends_in_ellipsis_p
16377 = (it
->method
== GET_FROM_DISPLAY_VECTOR
16378 && it
->ellipsis_p
);
16380 /* Save fringe bitmaps in this row. */
16381 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
16382 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
16383 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
16384 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
16386 it
->left_user_fringe_bitmap
= 0;
16387 it
->left_user_fringe_face_id
= 0;
16388 it
->right_user_fringe_bitmap
= 0;
16389 it
->right_user_fringe_face_id
= 0;
16391 /* Maybe set the cursor. */
16392 if (it
->w
->cursor
.vpos
< 0
16393 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
16394 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
16395 && cursor_row_p (it
->w
, row
))
16396 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
16398 /* Highlight trailing whitespace. */
16399 if (!NILP (Vshow_trailing_whitespace
))
16400 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
16402 /* Prepare for the next line. This line starts horizontally at (X
16403 HPOS) = (0 0). Vertical positions are incremented. As a
16404 convenience for the caller, IT->glyph_row is set to the next
16406 it
->current_x
= it
->hpos
= 0;
16407 it
->current_y
+= row
->height
;
16410 it
->start
= it
->current
;
16411 return row
->displays_text_p
;
16416 /***********************************************************************
16418 ***********************************************************************/
16420 /* Redisplay the menu bar in the frame for window W.
16422 The menu bar of X frames that don't have X toolkit support is
16423 displayed in a special window W->frame->menu_bar_window.
16425 The menu bar of terminal frames is treated specially as far as
16426 glyph matrices are concerned. Menu bar lines are not part of
16427 windows, so the update is done directly on the frame matrix rows
16428 for the menu bar. */
16431 display_menu_bar (w
)
16434 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16439 /* Don't do all this for graphical frames. */
16441 if (!NILP (Vwindow_system
))
16444 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
16449 if (FRAME_MAC_P (f
))
16453 #ifdef USE_X_TOOLKIT
16454 xassert (!FRAME_WINDOW_P (f
));
16455 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
16456 it
.first_visible_x
= 0;
16457 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16458 #else /* not USE_X_TOOLKIT */
16459 if (FRAME_WINDOW_P (f
))
16461 /* Menu bar lines are displayed in the desired matrix of the
16462 dummy window menu_bar_window. */
16463 struct window
*menu_w
;
16464 xassert (WINDOWP (f
->menu_bar_window
));
16465 menu_w
= XWINDOW (f
->menu_bar_window
);
16466 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
16468 it
.first_visible_x
= 0;
16469 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16473 /* This is a TTY frame, i.e. character hpos/vpos are used as
16475 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
16477 it
.first_visible_x
= 0;
16478 it
.last_visible_x
= FRAME_COLS (f
);
16480 #endif /* not USE_X_TOOLKIT */
16482 if (! mode_line_inverse_video
)
16483 /* Force the menu-bar to be displayed in the default face. */
16484 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16486 /* Clear all rows of the menu bar. */
16487 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
16489 struct glyph_row
*row
= it
.glyph_row
+ i
;
16490 clear_glyph_row (row
);
16491 row
->enabled_p
= 1;
16492 row
->full_width_p
= 1;
16495 /* Display all items of the menu bar. */
16496 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
16497 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
16499 Lisp_Object string
;
16501 /* Stop at nil string. */
16502 string
= AREF (items
, i
+ 1);
16506 /* Remember where item was displayed. */
16507 AREF (items
, i
+ 3) = make_number (it
.hpos
);
16509 /* Display the item, pad with one space. */
16510 if (it
.current_x
< it
.last_visible_x
)
16511 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
16512 SCHARS (string
) + 1, 0, 0, -1);
16515 /* Fill out the line with spaces. */
16516 if (it
.current_x
< it
.last_visible_x
)
16517 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
16519 /* Compute the total height of the lines. */
16520 compute_line_metrics (&it
);
16525 /***********************************************************************
16527 ***********************************************************************/
16529 /* Redisplay mode lines in the window tree whose root is WINDOW. If
16530 FORCE is non-zero, redisplay mode lines unconditionally.
16531 Otherwise, redisplay only mode lines that are garbaged. Value is
16532 the number of windows whose mode lines were redisplayed. */
16535 redisplay_mode_lines (window
, force
)
16536 Lisp_Object window
;
16541 while (!NILP (window
))
16543 struct window
*w
= XWINDOW (window
);
16545 if (WINDOWP (w
->hchild
))
16546 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
16547 else if (WINDOWP (w
->vchild
))
16548 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
16550 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
16551 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
16553 struct text_pos lpoint
;
16554 struct buffer
*old
= current_buffer
;
16556 /* Set the window's buffer for the mode line display. */
16557 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16558 set_buffer_internal_1 (XBUFFER (w
->buffer
));
16560 /* Point refers normally to the selected window. For any
16561 other window, set up appropriate value. */
16562 if (!EQ (window
, selected_window
))
16564 struct text_pos pt
;
16566 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
16567 if (CHARPOS (pt
) < BEGV
)
16568 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16569 else if (CHARPOS (pt
) > (ZV
- 1))
16570 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
16572 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
16575 /* Display mode lines. */
16576 clear_glyph_matrix (w
->desired_matrix
);
16577 if (display_mode_lines (w
))
16580 w
->must_be_updated_p
= 1;
16583 /* Restore old settings. */
16584 set_buffer_internal_1 (old
);
16585 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16595 /* Display the mode and/or top line of window W. Value is the number
16596 of mode lines displayed. */
16599 display_mode_lines (w
)
16602 Lisp_Object old_selected_window
, old_selected_frame
;
16605 old_selected_frame
= selected_frame
;
16606 selected_frame
= w
->frame
;
16607 old_selected_window
= selected_window
;
16608 XSETWINDOW (selected_window
, w
);
16610 /* These will be set while the mode line specs are processed. */
16611 line_number_displayed
= 0;
16612 w
->column_number_displayed
= Qnil
;
16614 if (WINDOW_WANTS_MODELINE_P (w
))
16616 struct window
*sel_w
= XWINDOW (old_selected_window
);
16618 /* Select mode line face based on the real selected window. */
16619 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
16620 current_buffer
->mode_line_format
);
16624 if (WINDOW_WANTS_HEADER_LINE_P (w
))
16626 display_mode_line (w
, HEADER_LINE_FACE_ID
,
16627 current_buffer
->header_line_format
);
16631 selected_frame
= old_selected_frame
;
16632 selected_window
= old_selected_window
;
16637 /* Display mode or top line of window W. FACE_ID specifies which line
16638 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
16639 FORMAT is the mode line format to display. Value is the pixel
16640 height of the mode line displayed. */
16643 display_mode_line (w
, face_id
, format
)
16645 enum face_id face_id
;
16646 Lisp_Object format
;
16650 int count
= SPECPDL_INDEX ();
16652 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16653 /* Don't extend on a previously drawn mode-line.
16654 This may happen if called from pos_visible_p. */
16655 it
.glyph_row
->enabled_p
= 0;
16656 prepare_desired_row (it
.glyph_row
);
16658 it
.glyph_row
->mode_line_p
= 1;
16660 if (! mode_line_inverse_video
)
16661 /* Force the mode-line to be displayed in the default face. */
16662 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16664 record_unwind_protect (unwind_format_mode_line
,
16665 format_mode_line_unwind_data (NULL
, 0));
16667 mode_line_target
= MODE_LINE_DISPLAY
;
16669 /* Temporarily make frame's keyboard the current kboard so that
16670 kboard-local variables in the mode_line_format will get the right
16672 push_frame_kboard (it
.f
);
16673 record_unwind_save_match_data ();
16674 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16675 pop_frame_kboard ();
16677 unbind_to (count
, Qnil
);
16679 /* Fill up with spaces. */
16680 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
16682 compute_line_metrics (&it
);
16683 it
.glyph_row
->full_width_p
= 1;
16684 it
.glyph_row
->continued_p
= 0;
16685 it
.glyph_row
->truncated_on_left_p
= 0;
16686 it
.glyph_row
->truncated_on_right_p
= 0;
16688 /* Make a 3D mode-line have a shadow at its right end. */
16689 face
= FACE_FROM_ID (it
.f
, face_id
);
16690 extend_face_to_end_of_line (&it
);
16691 if (face
->box
!= FACE_NO_BOX
)
16693 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
16694 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
16695 last
->right_box_line_p
= 1;
16698 return it
.glyph_row
->height
;
16701 /* Move element ELT in LIST to the front of LIST.
16702 Return the updated list. */
16705 move_elt_to_front (elt
, list
)
16706 Lisp_Object elt
, list
;
16708 register Lisp_Object tail
, prev
;
16709 register Lisp_Object tem
;
16713 while (CONSP (tail
))
16719 /* Splice out the link TAIL. */
16721 list
= XCDR (tail
);
16723 Fsetcdr (prev
, XCDR (tail
));
16725 /* Now make it the first. */
16726 Fsetcdr (tail
, list
);
16731 tail
= XCDR (tail
);
16735 /* Not found--return unchanged LIST. */
16739 /* Contribute ELT to the mode line for window IT->w. How it
16740 translates into text depends on its data type.
16742 IT describes the display environment in which we display, as usual.
16744 DEPTH is the depth in recursion. It is used to prevent
16745 infinite recursion here.
16747 FIELD_WIDTH is the number of characters the display of ELT should
16748 occupy in the mode line, and PRECISION is the maximum number of
16749 characters to display from ELT's representation. See
16750 display_string for details.
16752 Returns the hpos of the end of the text generated by ELT.
16754 PROPS is a property list to add to any string we encounter.
16756 If RISKY is nonzero, remove (disregard) any properties in any string
16757 we encounter, and ignore :eval and :propertize.
16759 The global variable `mode_line_target' determines whether the
16760 output is passed to `store_mode_line_noprop',
16761 `store_mode_line_string', or `display_string'. */
16764 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
16767 int field_width
, precision
;
16768 Lisp_Object elt
, props
;
16771 int n
= 0, field
, prec
;
16776 elt
= build_string ("*too-deep*");
16780 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
16784 /* A string: output it and check for %-constructs within it. */
16788 if (SCHARS (elt
) > 0
16789 && (!NILP (props
) || risky
))
16791 Lisp_Object oprops
, aelt
;
16792 oprops
= Ftext_properties_at (make_number (0), elt
);
16794 /* If the starting string's properties are not what
16795 we want, translate the string. Also, if the string
16796 is risky, do that anyway. */
16798 if (NILP (Fequal (props
, oprops
)) || risky
)
16800 /* If the starting string has properties,
16801 merge the specified ones onto the existing ones. */
16802 if (! NILP (oprops
) && !risky
)
16806 oprops
= Fcopy_sequence (oprops
);
16808 while (CONSP (tem
))
16810 oprops
= Fplist_put (oprops
, XCAR (tem
),
16811 XCAR (XCDR (tem
)));
16812 tem
= XCDR (XCDR (tem
));
16817 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
16818 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
16820 /* AELT is what we want. Move it to the front
16821 without consing. */
16823 mode_line_proptrans_alist
16824 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
16830 /* If AELT has the wrong props, it is useless.
16831 so get rid of it. */
16833 mode_line_proptrans_alist
16834 = Fdelq (aelt
, mode_line_proptrans_alist
);
16836 elt
= Fcopy_sequence (elt
);
16837 Fset_text_properties (make_number (0), Flength (elt
),
16839 /* Add this item to mode_line_proptrans_alist. */
16840 mode_line_proptrans_alist
16841 = Fcons (Fcons (elt
, props
),
16842 mode_line_proptrans_alist
);
16843 /* Truncate mode_line_proptrans_alist
16844 to at most 50 elements. */
16845 tem
= Fnthcdr (make_number (50),
16846 mode_line_proptrans_alist
);
16848 XSETCDR (tem
, Qnil
);
16857 prec
= precision
- n
;
16858 switch (mode_line_target
)
16860 case MODE_LINE_NOPROP
:
16861 case MODE_LINE_TITLE
:
16862 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
16864 case MODE_LINE_STRING
:
16865 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
16867 case MODE_LINE_DISPLAY
:
16868 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
16869 0, prec
, 0, STRING_MULTIBYTE (elt
));
16876 /* Handle the non-literal case. */
16878 while ((precision
<= 0 || n
< precision
)
16879 && SREF (elt
, offset
) != 0
16880 && (mode_line_target
!= MODE_LINE_DISPLAY
16881 || it
->current_x
< it
->last_visible_x
))
16883 int last_offset
= offset
;
16885 /* Advance to end of string or next format specifier. */
16886 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
16889 if (offset
- 1 != last_offset
)
16891 int nchars
, nbytes
;
16893 /* Output to end of string or up to '%'. Field width
16894 is length of string. Don't output more than
16895 PRECISION allows us. */
16898 prec
= c_string_width (SDATA (elt
) + last_offset
,
16899 offset
- last_offset
, precision
- n
,
16902 switch (mode_line_target
)
16904 case MODE_LINE_NOPROP
:
16905 case MODE_LINE_TITLE
:
16906 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
16908 case MODE_LINE_STRING
:
16910 int bytepos
= last_offset
;
16911 int charpos
= string_byte_to_char (elt
, bytepos
);
16912 int endpos
= (precision
<= 0
16913 ? string_byte_to_char (elt
, offset
)
16914 : charpos
+ nchars
);
16916 n
+= store_mode_line_string (NULL
,
16917 Fsubstring (elt
, make_number (charpos
),
16918 make_number (endpos
)),
16922 case MODE_LINE_DISPLAY
:
16924 int bytepos
= last_offset
;
16925 int charpos
= string_byte_to_char (elt
, bytepos
);
16927 if (precision
<= 0)
16928 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
16929 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
16931 STRING_MULTIBYTE (elt
));
16936 else /* c == '%' */
16938 int percent_position
= offset
;
16940 /* Get the specified minimum width. Zero means
16943 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
16944 field
= field
* 10 + c
- '0';
16946 /* Don't pad beyond the total padding allowed. */
16947 if (field_width
- n
> 0 && field
> field_width
- n
)
16948 field
= field_width
- n
;
16950 /* Note that either PRECISION <= 0 or N < PRECISION. */
16951 prec
= precision
- n
;
16954 n
+= display_mode_element (it
, depth
, field
, prec
,
16955 Vglobal_mode_string
, props
,
16960 int bytepos
, charpos
;
16961 unsigned char *spec
;
16963 bytepos
= percent_position
;
16964 charpos
= (STRING_MULTIBYTE (elt
)
16965 ? string_byte_to_char (elt
, bytepos
)
16969 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
16971 switch (mode_line_target
)
16973 case MODE_LINE_NOPROP
:
16974 case MODE_LINE_TITLE
:
16975 n
+= store_mode_line_noprop (spec
, field
, prec
);
16977 case MODE_LINE_STRING
:
16979 int len
= strlen (spec
);
16980 Lisp_Object tem
= make_string (spec
, len
);
16981 props
= Ftext_properties_at (make_number (charpos
), elt
);
16982 /* Should only keep face property in props */
16983 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
16986 case MODE_LINE_DISPLAY
:
16988 int nglyphs_before
, nwritten
;
16990 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16991 nwritten
= display_string (spec
, Qnil
, elt
,
16996 /* Assign to the glyphs written above the
16997 string where the `%x' came from, position
17001 struct glyph
*glyph
17002 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
17006 for (i
= 0; i
< nwritten
; ++i
)
17008 glyph
[i
].object
= elt
;
17009 glyph
[i
].charpos
= charpos
;
17026 /* A symbol: process the value of the symbol recursively
17027 as if it appeared here directly. Avoid error if symbol void.
17028 Special case: if value of symbol is a string, output the string
17031 register Lisp_Object tem
;
17033 /* If the variable is not marked as risky to set
17034 then its contents are risky to use. */
17035 if (NILP (Fget (elt
, Qrisky_local_variable
)))
17038 tem
= Fboundp (elt
);
17041 tem
= Fsymbol_value (elt
);
17042 /* If value is a string, output that string literally:
17043 don't check for % within it. */
17047 if (!EQ (tem
, elt
))
17049 /* Give up right away for nil or t. */
17059 register Lisp_Object car
, tem
;
17061 /* A cons cell: five distinct cases.
17062 If first element is :eval or :propertize, do something special.
17063 If first element is a string or a cons, process all the elements
17064 and effectively concatenate them.
17065 If first element is a negative number, truncate displaying cdr to
17066 at most that many characters. If positive, pad (with spaces)
17067 to at least that many characters.
17068 If first element is a symbol, process the cadr or caddr recursively
17069 according to whether the symbol's value is non-nil or nil. */
17071 if (EQ (car
, QCeval
))
17073 /* An element of the form (:eval FORM) means evaluate FORM
17074 and use the result as mode line elements. */
17079 if (CONSP (XCDR (elt
)))
17082 spec
= safe_eval (XCAR (XCDR (elt
)));
17083 n
+= display_mode_element (it
, depth
, field_width
- n
,
17084 precision
- n
, spec
, props
,
17088 else if (EQ (car
, QCpropertize
))
17090 /* An element of the form (:propertize ELT PROPS...)
17091 means display ELT but applying properties PROPS. */
17096 if (CONSP (XCDR (elt
)))
17097 n
+= display_mode_element (it
, depth
, field_width
- n
,
17098 precision
- n
, XCAR (XCDR (elt
)),
17099 XCDR (XCDR (elt
)), risky
);
17101 else if (SYMBOLP (car
))
17103 tem
= Fboundp (car
);
17107 /* elt is now the cdr, and we know it is a cons cell.
17108 Use its car if CAR has a non-nil value. */
17111 tem
= Fsymbol_value (car
);
17118 /* Symbol's value is nil (or symbol is unbound)
17119 Get the cddr of the original list
17120 and if possible find the caddr and use that. */
17124 else if (!CONSP (elt
))
17129 else if (INTEGERP (car
))
17131 register int lim
= XINT (car
);
17135 /* Negative int means reduce maximum width. */
17136 if (precision
<= 0)
17139 precision
= min (precision
, -lim
);
17143 /* Padding specified. Don't let it be more than
17144 current maximum. */
17146 lim
= min (precision
, lim
);
17148 /* If that's more padding than already wanted, queue it.
17149 But don't reduce padding already specified even if
17150 that is beyond the current truncation point. */
17151 field_width
= max (lim
, field_width
);
17155 else if (STRINGP (car
) || CONSP (car
))
17157 register int limit
= 50;
17158 /* Limit is to protect against circular lists. */
17161 && (precision
<= 0 || n
< precision
))
17163 n
+= display_mode_element (it
, depth
,
17164 /* Do padding only after the last
17165 element in the list. */
17166 (! CONSP (XCDR (elt
))
17169 precision
- n
, XCAR (elt
),
17179 elt
= build_string ("*invalid*");
17183 /* Pad to FIELD_WIDTH. */
17184 if (field_width
> 0 && n
< field_width
)
17186 switch (mode_line_target
)
17188 case MODE_LINE_NOPROP
:
17189 case MODE_LINE_TITLE
:
17190 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
17192 case MODE_LINE_STRING
:
17193 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
17195 case MODE_LINE_DISPLAY
:
17196 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
17205 /* Store a mode-line string element in mode_line_string_list.
17207 If STRING is non-null, display that C string. Otherwise, the Lisp
17208 string LISP_STRING is displayed.
17210 FIELD_WIDTH is the minimum number of output glyphs to produce.
17211 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17212 with spaces. FIELD_WIDTH <= 0 means don't pad.
17214 PRECISION is the maximum number of characters to output from
17215 STRING. PRECISION <= 0 means don't truncate the string.
17217 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
17218 properties to the string.
17220 PROPS are the properties to add to the string.
17221 The mode_line_string_face face property is always added to the string.
17225 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
17227 Lisp_Object lisp_string
;
17236 if (string
!= NULL
)
17238 len
= strlen (string
);
17239 if (precision
> 0 && len
> precision
)
17241 lisp_string
= make_string (string
, len
);
17243 props
= mode_line_string_face_prop
;
17244 else if (!NILP (mode_line_string_face
))
17246 Lisp_Object face
= Fplist_get (props
, Qface
);
17247 props
= Fcopy_sequence (props
);
17249 face
= mode_line_string_face
;
17251 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17252 props
= Fplist_put (props
, Qface
, face
);
17254 Fadd_text_properties (make_number (0), make_number (len
),
17255 props
, lisp_string
);
17259 len
= XFASTINT (Flength (lisp_string
));
17260 if (precision
> 0 && len
> precision
)
17263 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
17266 if (!NILP (mode_line_string_face
))
17270 props
= Ftext_properties_at (make_number (0), lisp_string
);
17271 face
= Fplist_get (props
, Qface
);
17273 face
= mode_line_string_face
;
17275 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17276 props
= Fcons (Qface
, Fcons (face
, Qnil
));
17278 lisp_string
= Fcopy_sequence (lisp_string
);
17281 Fadd_text_properties (make_number (0), make_number (len
),
17282 props
, lisp_string
);
17287 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17291 if (field_width
> len
)
17293 field_width
-= len
;
17294 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17296 Fadd_text_properties (make_number (0), make_number (field_width
),
17297 props
, lisp_string
);
17298 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17306 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17308 doc
: /* Format a string out of a mode line format specification.
17309 First arg FORMAT specifies the mode line format (see `mode-line-format'
17310 for details) to use.
17312 Optional second arg FACE specifies the face property to put
17313 on all characters for which no face is specified.
17314 The value t means whatever face the window's mode line currently uses
17315 \(either `mode-line' or `mode-line-inactive', depending).
17316 A value of nil means the default is no face property.
17317 If FACE is an integer, the value string has no text properties.
17319 Optional third and fourth args WINDOW and BUFFER specify the window
17320 and buffer to use as the context for the formatting (defaults
17321 are the selected window and the window's buffer). */)
17322 (format
, face
, window
, buffer
)
17323 Lisp_Object format
, face
, window
, buffer
;
17328 struct buffer
*old_buffer
= NULL
;
17330 int no_props
= INTEGERP (face
);
17331 int count
= SPECPDL_INDEX ();
17333 int string_start
= 0;
17336 window
= selected_window
;
17337 CHECK_WINDOW (window
);
17338 w
= XWINDOW (window
);
17341 buffer
= w
->buffer
;
17342 CHECK_BUFFER (buffer
);
17345 return build_string ("");
17353 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
17354 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
17358 face_id
= DEFAULT_FACE_ID
;
17360 if (XBUFFER (buffer
) != current_buffer
)
17361 old_buffer
= current_buffer
;
17363 /* Save things including mode_line_proptrans_alist,
17364 and set that to nil so that we don't alter the outer value. */
17365 record_unwind_protect (unwind_format_mode_line
,
17366 format_mode_line_unwind_data (old_buffer
, 1));
17367 mode_line_proptrans_alist
= Qnil
;
17370 set_buffer_internal_1 (XBUFFER (buffer
));
17372 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17376 mode_line_target
= MODE_LINE_NOPROP
;
17377 mode_line_string_face_prop
= Qnil
;
17378 mode_line_string_list
= Qnil
;
17379 string_start
= MODE_LINE_NOPROP_LEN (0);
17383 mode_line_target
= MODE_LINE_STRING
;
17384 mode_line_string_list
= Qnil
;
17385 mode_line_string_face
= face
;
17386 mode_line_string_face_prop
17387 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
17390 push_frame_kboard (it
.f
);
17391 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17392 pop_frame_kboard ();
17396 len
= MODE_LINE_NOPROP_LEN (string_start
);
17397 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
17401 mode_line_string_list
= Fnreverse (mode_line_string_list
);
17402 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
17403 make_string ("", 0));
17406 unbind_to (count
, Qnil
);
17410 /* Write a null-terminated, right justified decimal representation of
17411 the positive integer D to BUF using a minimal field width WIDTH. */
17414 pint2str (buf
, width
, d
)
17415 register char *buf
;
17416 register int width
;
17419 register char *p
= buf
;
17427 *p
++ = d
% 10 + '0';
17432 for (width
-= (int) (p
- buf
); width
> 0; --width
)
17443 /* Write a null-terminated, right justified decimal and "human
17444 readable" representation of the nonnegative integer D to BUF using
17445 a minimal field width WIDTH. D should be smaller than 999.5e24. */
17447 static const char power_letter
[] =
17461 pint2hrstr (buf
, width
, d
)
17466 /* We aim to represent the nonnegative integer D as
17467 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
17470 /* -1 means: do not use TENTHS. */
17474 /* Length of QUOTIENT.TENTHS as a string. */
17480 if (1000 <= quotient
)
17482 /* Scale to the appropriate EXPONENT. */
17485 remainder
= quotient
% 1000;
17489 while (1000 <= quotient
);
17491 /* Round to nearest and decide whether to use TENTHS or not. */
17494 tenths
= remainder
/ 100;
17495 if (50 <= remainder
% 100)
17502 if (quotient
== 10)
17510 if (500 <= remainder
)
17512 if (quotient
< 999)
17523 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
17524 if (tenths
== -1 && quotient
<= 99)
17531 p
= psuffix
= buf
+ max (width
, length
);
17533 /* Print EXPONENT. */
17535 *psuffix
++ = power_letter
[exponent
];
17538 /* Print TENTHS. */
17541 *--p
= '0' + tenths
;
17545 /* Print QUOTIENT. */
17548 int digit
= quotient
% 10;
17549 *--p
= '0' + digit
;
17551 while ((quotient
/= 10) != 0);
17553 /* Print leading spaces. */
17558 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
17559 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
17560 type of CODING_SYSTEM. Return updated pointer into BUF. */
17562 static unsigned char invalid_eol_type
[] = "(*invalid*)";
17565 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
17566 Lisp_Object coding_system
;
17567 register char *buf
;
17571 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
17572 const unsigned char *eol_str
;
17574 /* The EOL conversion we are using. */
17575 Lisp_Object eoltype
;
17577 val
= Fget (coding_system
, Qcoding_system
);
17580 if (!VECTORP (val
)) /* Not yet decided. */
17585 eoltype
= eol_mnemonic_undecided
;
17586 /* Don't mention EOL conversion if it isn't decided. */
17590 Lisp_Object eolvalue
;
17592 eolvalue
= Fget (coding_system
, Qeol_type
);
17595 *buf
++ = XFASTINT (AREF (val
, 1));
17599 /* The EOL conversion that is normal on this system. */
17601 if (NILP (eolvalue
)) /* Not yet decided. */
17602 eoltype
= eol_mnemonic_undecided
;
17603 else if (VECTORP (eolvalue
)) /* Not yet decided. */
17604 eoltype
= eol_mnemonic_undecided
;
17605 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
17606 eoltype
= (XFASTINT (eolvalue
) == 0
17607 ? eol_mnemonic_unix
17608 : (XFASTINT (eolvalue
) == 1
17609 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
17615 /* Mention the EOL conversion if it is not the usual one. */
17616 if (STRINGP (eoltype
))
17618 eol_str
= SDATA (eoltype
);
17619 eol_str_len
= SBYTES (eoltype
);
17621 else if (INTEGERP (eoltype
)
17622 && CHAR_VALID_P (XINT (eoltype
), 0))
17624 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
17625 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
17630 eol_str
= invalid_eol_type
;
17631 eol_str_len
= sizeof (invalid_eol_type
) - 1;
17633 bcopy (eol_str
, buf
, eol_str_len
);
17634 buf
+= eol_str_len
;
17640 /* Return a string for the output of a mode line %-spec for window W,
17641 generated by character C. PRECISION >= 0 means don't return a
17642 string longer than that value. FIELD_WIDTH > 0 means pad the
17643 string returned with spaces to that value. Return 1 in *MULTIBYTE
17644 if the result is multibyte text.
17646 Note we operate on the current buffer for most purposes,
17647 the exception being w->base_line_pos. */
17649 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
17652 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
17655 int field_width
, precision
;
17659 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17660 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
17661 struct buffer
*b
= current_buffer
;
17669 if (!NILP (b
->read_only
))
17671 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17676 /* This differs from %* only for a modified read-only buffer. */
17677 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17679 if (!NILP (b
->read_only
))
17684 /* This differs from %* in ignoring read-only-ness. */
17685 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17697 if (command_loop_level
> 5)
17699 p
= decode_mode_spec_buf
;
17700 for (i
= 0; i
< command_loop_level
; i
++)
17703 return decode_mode_spec_buf
;
17711 if (command_loop_level
> 5)
17713 p
= decode_mode_spec_buf
;
17714 for (i
= 0; i
< command_loop_level
; i
++)
17717 return decode_mode_spec_buf
;
17724 /* Let lots_of_dashes be a string of infinite length. */
17725 if (mode_line_target
== MODE_LINE_NOPROP
||
17726 mode_line_target
== MODE_LINE_STRING
)
17728 if (field_width
<= 0
17729 || field_width
> sizeof (lots_of_dashes
))
17731 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
17732 decode_mode_spec_buf
[i
] = '-';
17733 decode_mode_spec_buf
[i
] = '\0';
17734 return decode_mode_spec_buf
;
17737 return lots_of_dashes
;
17745 /* %c and %l are ignored in `frame-title-format'.
17746 (In redisplay_internal, the frame title is drawn _before_ the
17747 windows are updated, so the stuff which depends on actual
17748 window contents (such as %l) may fail to render properly, or
17749 even crash emacs.) */
17750 if (mode_line_target
== MODE_LINE_TITLE
)
17754 int col
= (int) current_column (); /* iftc */
17755 w
->column_number_displayed
= make_number (col
);
17756 pint2str (decode_mode_spec_buf
, field_width
, col
);
17757 return decode_mode_spec_buf
;
17761 #ifndef SYSTEM_MALLOC
17763 if (NILP (Vmemory_full
))
17766 return "!MEM FULL! ";
17773 /* %F displays the frame name. */
17774 if (!NILP (f
->title
))
17775 return (char *) SDATA (f
->title
);
17776 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
17777 return (char *) SDATA (f
->name
);
17786 int size
= ZV
- BEGV
;
17787 pint2str (decode_mode_spec_buf
, field_width
, size
);
17788 return decode_mode_spec_buf
;
17793 int size
= ZV
- BEGV
;
17794 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
17795 return decode_mode_spec_buf
;
17800 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
17801 int topline
, nlines
, junk
, height
;
17803 /* %c and %l are ignored in `frame-title-format'. */
17804 if (mode_line_target
== MODE_LINE_TITLE
)
17807 startpos
= XMARKER (w
->start
)->charpos
;
17808 startpos_byte
= marker_byte_position (w
->start
);
17809 height
= WINDOW_TOTAL_LINES (w
);
17811 /* If we decided that this buffer isn't suitable for line numbers,
17812 don't forget that too fast. */
17813 if (EQ (w
->base_line_pos
, w
->buffer
))
17815 /* But do forget it, if the window shows a different buffer now. */
17816 else if (BUFFERP (w
->base_line_pos
))
17817 w
->base_line_pos
= Qnil
;
17819 /* If the buffer is very big, don't waste time. */
17820 if (INTEGERP (Vline_number_display_limit
)
17821 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
17823 w
->base_line_pos
= Qnil
;
17824 w
->base_line_number
= Qnil
;
17828 if (!NILP (w
->base_line_number
)
17829 && !NILP (w
->base_line_pos
)
17830 && XFASTINT (w
->base_line_pos
) <= startpos
)
17832 line
= XFASTINT (w
->base_line_number
);
17833 linepos
= XFASTINT (w
->base_line_pos
);
17834 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
17839 linepos
= BUF_BEGV (b
);
17840 linepos_byte
= BUF_BEGV_BYTE (b
);
17843 /* Count lines from base line to window start position. */
17844 nlines
= display_count_lines (linepos
, linepos_byte
,
17848 topline
= nlines
+ line
;
17850 /* Determine a new base line, if the old one is too close
17851 or too far away, or if we did not have one.
17852 "Too close" means it's plausible a scroll-down would
17853 go back past it. */
17854 if (startpos
== BUF_BEGV (b
))
17856 w
->base_line_number
= make_number (topline
);
17857 w
->base_line_pos
= make_number (BUF_BEGV (b
));
17859 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
17860 || linepos
== BUF_BEGV (b
))
17862 int limit
= BUF_BEGV (b
);
17863 int limit_byte
= BUF_BEGV_BYTE (b
);
17865 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
17867 if (startpos
- distance
> limit
)
17869 limit
= startpos
- distance
;
17870 limit_byte
= CHAR_TO_BYTE (limit
);
17873 nlines
= display_count_lines (startpos
, startpos_byte
,
17875 - (height
* 2 + 30),
17877 /* If we couldn't find the lines we wanted within
17878 line_number_display_limit_width chars per line,
17879 give up on line numbers for this window. */
17880 if (position
== limit_byte
&& limit
== startpos
- distance
)
17882 w
->base_line_pos
= w
->buffer
;
17883 w
->base_line_number
= Qnil
;
17887 w
->base_line_number
= make_number (topline
- nlines
);
17888 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
17891 /* Now count lines from the start pos to point. */
17892 nlines
= display_count_lines (startpos
, startpos_byte
,
17893 PT_BYTE
, PT
, &junk
);
17895 /* Record that we did display the line number. */
17896 line_number_displayed
= 1;
17898 /* Make the string to show. */
17899 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
17900 return decode_mode_spec_buf
;
17903 char* p
= decode_mode_spec_buf
;
17904 int pad
= field_width
- 2;
17910 return decode_mode_spec_buf
;
17916 obj
= b
->mode_name
;
17920 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
17926 int pos
= marker_position (w
->start
);
17927 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17929 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
17931 if (pos
<= BUF_BEGV (b
))
17936 else if (pos
<= BUF_BEGV (b
))
17940 if (total
> 1000000)
17941 /* Do it differently for a large value, to avoid overflow. */
17942 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17944 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17945 /* We can't normally display a 3-digit number,
17946 so get us a 2-digit number that is close. */
17949 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17950 return decode_mode_spec_buf
;
17954 /* Display percentage of size above the bottom of the screen. */
17957 int toppos
= marker_position (w
->start
);
17958 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
17959 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17961 if (botpos
>= BUF_ZV (b
))
17963 if (toppos
<= BUF_BEGV (b
))
17970 if (total
> 1000000)
17971 /* Do it differently for a large value, to avoid overflow. */
17972 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17974 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17975 /* We can't normally display a 3-digit number,
17976 so get us a 2-digit number that is close. */
17979 if (toppos
<= BUF_BEGV (b
))
17980 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
17982 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17983 return decode_mode_spec_buf
;
17988 /* status of process */
17989 obj
= Fget_buffer_process (Fcurrent_buffer ());
17991 return "no process";
17992 #ifdef subprocesses
17993 obj
= Fsymbol_name (Fprocess_status (obj
));
17997 case 't': /* indicate TEXT or BINARY */
17998 #ifdef MODE_LINE_BINARY_TEXT
17999 return MODE_LINE_BINARY_TEXT (b
);
18005 /* coding-system (not including end-of-line format) */
18007 /* coding-system (including end-of-line type) */
18009 int eol_flag
= (c
== 'Z');
18010 char *p
= decode_mode_spec_buf
;
18012 if (! FRAME_WINDOW_P (f
))
18014 /* No need to mention EOL here--the terminal never needs
18015 to do EOL conversion. */
18016 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
18017 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
18019 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
18022 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
18023 #ifdef subprocesses
18024 obj
= Fget_buffer_process (Fcurrent_buffer ());
18025 if (PROCESSP (obj
))
18027 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
18029 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
18032 #endif /* subprocesses */
18035 return decode_mode_spec_buf
;
18041 *multibyte
= STRING_MULTIBYTE (obj
);
18042 return (char *) SDATA (obj
);
18049 /* Count up to COUNT lines starting from START / START_BYTE.
18050 But don't go beyond LIMIT_BYTE.
18051 Return the number of lines thus found (always nonnegative).
18053 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
18056 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
18057 int start
, start_byte
, limit_byte
, count
;
18060 register unsigned char *cursor
;
18061 unsigned char *base
;
18063 register int ceiling
;
18064 register unsigned char *ceiling_addr
;
18065 int orig_count
= count
;
18067 /* If we are not in selective display mode,
18068 check only for newlines. */
18069 int selective_display
= (!NILP (current_buffer
->selective_display
)
18070 && !INTEGERP (current_buffer
->selective_display
));
18074 while (start_byte
< limit_byte
)
18076 ceiling
= BUFFER_CEILING_OF (start_byte
);
18077 ceiling
= min (limit_byte
- 1, ceiling
);
18078 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
18079 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
18082 if (selective_display
)
18083 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
18086 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
18089 if (cursor
!= ceiling_addr
)
18093 start_byte
+= cursor
- base
+ 1;
18094 *byte_pos_ptr
= start_byte
;
18098 if (++cursor
== ceiling_addr
)
18104 start_byte
+= cursor
- base
;
18109 while (start_byte
> limit_byte
)
18111 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
18112 ceiling
= max (limit_byte
, ceiling
);
18113 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
18114 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
18117 if (selective_display
)
18118 while (--cursor
!= ceiling_addr
18119 && *cursor
!= '\n' && *cursor
!= 015)
18122 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
18125 if (cursor
!= ceiling_addr
)
18129 start_byte
+= cursor
- base
+ 1;
18130 *byte_pos_ptr
= start_byte
;
18131 /* When scanning backwards, we should
18132 not count the newline posterior to which we stop. */
18133 return - orig_count
- 1;
18139 /* Here we add 1 to compensate for the last decrement
18140 of CURSOR, which took it past the valid range. */
18141 start_byte
+= cursor
- base
+ 1;
18145 *byte_pos_ptr
= limit_byte
;
18148 return - orig_count
+ count
;
18149 return orig_count
- count
;
18155 /***********************************************************************
18157 ***********************************************************************/
18159 /* Display a NUL-terminated string, starting with index START.
18161 If STRING is non-null, display that C string. Otherwise, the Lisp
18162 string LISP_STRING is displayed.
18164 If FACE_STRING is not nil, FACE_STRING_POS is a position in
18165 FACE_STRING. Display STRING or LISP_STRING with the face at
18166 FACE_STRING_POS in FACE_STRING:
18168 Display the string in the environment given by IT, but use the
18169 standard display table, temporarily.
18171 FIELD_WIDTH is the minimum number of output glyphs to produce.
18172 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18173 with spaces. If STRING has more characters, more than FIELD_WIDTH
18174 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
18176 PRECISION is the maximum number of characters to output from
18177 STRING. PRECISION < 0 means don't truncate the string.
18179 This is roughly equivalent to printf format specifiers:
18181 FIELD_WIDTH PRECISION PRINTF
18182 ----------------------------------------
18188 MULTIBYTE zero means do not display multibyte chars, > 0 means do
18189 display them, and < 0 means obey the current buffer's value of
18190 enable_multibyte_characters.
18192 Value is the number of columns displayed. */
18195 display_string (string
, lisp_string
, face_string
, face_string_pos
,
18196 start
, it
, field_width
, precision
, max_x
, multibyte
)
18197 unsigned char *string
;
18198 Lisp_Object lisp_string
;
18199 Lisp_Object face_string
;
18200 int face_string_pos
;
18203 int field_width
, precision
, max_x
;
18206 int hpos_at_start
= it
->hpos
;
18207 int saved_face_id
= it
->face_id
;
18208 struct glyph_row
*row
= it
->glyph_row
;
18210 /* Initialize the iterator IT for iteration over STRING beginning
18211 with index START. */
18212 reseat_to_string (it
, string
, lisp_string
, start
,
18213 precision
, field_width
, multibyte
);
18215 /* If displaying STRING, set up the face of the iterator
18216 from LISP_STRING, if that's given. */
18217 if (STRINGP (face_string
))
18223 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
18224 0, it
->region_beg_charpos
,
18225 it
->region_end_charpos
,
18226 &endptr
, it
->base_face_id
, 0);
18227 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18228 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
18231 /* Set max_x to the maximum allowed X position. Don't let it go
18232 beyond the right edge of the window. */
18234 max_x
= it
->last_visible_x
;
18236 max_x
= min (max_x
, it
->last_visible_x
);
18238 /* Skip over display elements that are not visible. because IT->w is
18240 if (it
->current_x
< it
->first_visible_x
)
18241 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
18242 MOVE_TO_POS
| MOVE_TO_X
);
18244 row
->ascent
= it
->max_ascent
;
18245 row
->height
= it
->max_ascent
+ it
->max_descent
;
18246 row
->phys_ascent
= it
->max_phys_ascent
;
18247 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18248 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18250 /* This condition is for the case that we are called with current_x
18251 past last_visible_x. */
18252 while (it
->current_x
< max_x
)
18254 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
18256 /* Get the next display element. */
18257 if (!get_next_display_element (it
))
18260 /* Produce glyphs. */
18261 x_before
= it
->current_x
;
18262 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18263 PRODUCE_GLYPHS (it
);
18265 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
18268 while (i
< nglyphs
)
18270 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18272 if (!it
->truncate_lines_p
18273 && x
+ glyph
->pixel_width
> max_x
)
18275 /* End of continued line or max_x reached. */
18276 if (CHAR_GLYPH_PADDING_P (*glyph
))
18278 /* A wide character is unbreakable. */
18279 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18280 it
->current_x
= x_before
;
18284 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18289 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
18291 /* Glyph is at least partially visible. */
18293 if (x
< it
->first_visible_x
)
18294 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18298 /* Glyph is off the left margin of the display area.
18299 Should not happen. */
18303 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18304 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18305 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18306 row
->phys_height
= max (row
->phys_height
,
18307 it
->max_phys_ascent
+ it
->max_phys_descent
);
18308 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18309 it
->max_extra_line_spacing
);
18310 x
+= glyph
->pixel_width
;
18314 /* Stop if max_x reached. */
18318 /* Stop at line ends. */
18319 if (ITERATOR_AT_END_OF_LINE_P (it
))
18321 it
->continuation_lines_width
= 0;
18325 set_iterator_to_next (it
, 1);
18327 /* Stop if truncating at the right edge. */
18328 if (it
->truncate_lines_p
18329 && it
->current_x
>= it
->last_visible_x
)
18331 /* Add truncation mark, but don't do it if the line is
18332 truncated at a padding space. */
18333 if (IT_CHARPOS (*it
) < it
->string_nchars
)
18335 if (!FRAME_WINDOW_P (it
->f
))
18339 if (it
->current_x
> it
->last_visible_x
)
18341 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18342 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18344 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18346 row
->used
[TEXT_AREA
] = i
;
18347 produce_special_glyphs (it
, IT_TRUNCATION
);
18350 produce_special_glyphs (it
, IT_TRUNCATION
);
18352 it
->glyph_row
->truncated_on_right_p
= 1;
18358 /* Maybe insert a truncation at the left. */
18359 if (it
->first_visible_x
18360 && IT_CHARPOS (*it
) > 0)
18362 if (!FRAME_WINDOW_P (it
->f
))
18363 insert_left_trunc_glyphs (it
);
18364 it
->glyph_row
->truncated_on_left_p
= 1;
18367 it
->face_id
= saved_face_id
;
18369 /* Value is number of columns displayed. */
18370 return it
->hpos
- hpos_at_start
;
18375 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
18376 appears as an element of LIST or as the car of an element of LIST.
18377 If PROPVAL is a list, compare each element against LIST in that
18378 way, and return 1/2 if any element of PROPVAL is found in LIST.
18379 Otherwise return 0. This function cannot quit.
18380 The return value is 2 if the text is invisible but with an ellipsis
18381 and 1 if it's invisible and without an ellipsis. */
18384 invisible_p (propval
, list
)
18385 register Lisp_Object propval
;
18388 register Lisp_Object tail
, proptail
;
18390 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18392 register Lisp_Object tem
;
18394 if (EQ (propval
, tem
))
18396 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
18397 return NILP (XCDR (tem
)) ? 1 : 2;
18400 if (CONSP (propval
))
18402 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
18404 Lisp_Object propelt
;
18405 propelt
= XCAR (proptail
);
18406 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18408 register Lisp_Object tem
;
18410 if (EQ (propelt
, tem
))
18412 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
18413 return NILP (XCDR (tem
)) ? 1 : 2;
18421 /* Calculate a width or height in pixels from a specification using
18422 the following elements:
18425 NUM - a (fractional) multiple of the default font width/height
18426 (NUM) - specifies exactly NUM pixels
18427 UNIT - a fixed number of pixels, see below.
18428 ELEMENT - size of a display element in pixels, see below.
18429 (NUM . SPEC) - equals NUM * SPEC
18430 (+ SPEC SPEC ...) - add pixel values
18431 (- SPEC SPEC ...) - subtract pixel values
18432 (- SPEC) - negate pixel value
18435 INT or FLOAT - a number constant
18436 SYMBOL - use symbol's (buffer local) variable binding.
18439 in - pixels per inch *)
18440 mm - pixels per 1/1000 meter *)
18441 cm - pixels per 1/100 meter *)
18442 width - width of current font in pixels.
18443 height - height of current font in pixels.
18445 *) using the ratio(s) defined in display-pixels-per-inch.
18449 left-fringe - left fringe width in pixels
18450 right-fringe - right fringe width in pixels
18452 left-margin - left margin width in pixels
18453 right-margin - right margin width in pixels
18455 scroll-bar - scroll-bar area width in pixels
18459 Pixels corresponding to 5 inches:
18462 Total width of non-text areas on left side of window (if scroll-bar is on left):
18463 '(space :width (+ left-fringe left-margin scroll-bar))
18465 Align to first text column (in header line):
18466 '(space :align-to 0)
18468 Align to middle of text area minus half the width of variable `my-image'
18469 containing a loaded image:
18470 '(space :align-to (0.5 . (- text my-image)))
18472 Width of left margin minus width of 1 character in the default font:
18473 '(space :width (- left-margin 1))
18475 Width of left margin minus width of 2 characters in the current font:
18476 '(space :width (- left-margin (2 . width)))
18478 Center 1 character over left-margin (in header line):
18479 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
18481 Different ways to express width of left fringe plus left margin minus one pixel:
18482 '(space :width (- (+ left-fringe left-margin) (1)))
18483 '(space :width (+ left-fringe left-margin (- (1))))
18484 '(space :width (+ left-fringe left-margin (-1)))
18488 #define NUMVAL(X) \
18489 ((INTEGERP (X) || FLOATP (X)) \
18494 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
18499 int width_p
, *align_to
;
18503 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
18504 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
18507 return OK_PIXELS (0);
18509 if (SYMBOLP (prop
))
18511 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18513 char *unit
= SDATA (SYMBOL_NAME (prop
));
18515 if (unit
[0] == 'i' && unit
[1] == 'n')
18517 else if (unit
[0] == 'm' && unit
[1] == 'm')
18519 else if (unit
[0] == 'c' && unit
[1] == 'm')
18526 #ifdef HAVE_WINDOW_SYSTEM
18527 if (FRAME_WINDOW_P (it
->f
)
18529 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
18530 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
18532 return OK_PIXELS (ppi
/ pixels
);
18535 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18536 || (CONSP (Vdisplay_pixels_per_inch
)
18538 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18539 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18541 return OK_PIXELS (ppi
/ pixels
);
18547 #ifdef HAVE_WINDOW_SYSTEM
18548 if (EQ (prop
, Qheight
))
18549 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
18550 if (EQ (prop
, Qwidth
))
18551 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
18553 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
18554 return OK_PIXELS (1);
18557 if (EQ (prop
, Qtext
))
18558 return OK_PIXELS (width_p
18559 ? window_box_width (it
->w
, TEXT_AREA
)
18560 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
18562 if (align_to
&& *align_to
< 0)
18565 if (EQ (prop
, Qleft
))
18566 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
18567 if (EQ (prop
, Qright
))
18568 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
18569 if (EQ (prop
, Qcenter
))
18570 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
18571 + window_box_width (it
->w
, TEXT_AREA
) / 2);
18572 if (EQ (prop
, Qleft_fringe
))
18573 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18574 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
18575 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
18576 if (EQ (prop
, Qright_fringe
))
18577 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18578 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18579 : window_box_right_offset (it
->w
, TEXT_AREA
));
18580 if (EQ (prop
, Qleft_margin
))
18581 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
18582 if (EQ (prop
, Qright_margin
))
18583 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
18584 if (EQ (prop
, Qscroll_bar
))
18585 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18587 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18588 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18589 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18594 if (EQ (prop
, Qleft_fringe
))
18595 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18596 if (EQ (prop
, Qright_fringe
))
18597 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18598 if (EQ (prop
, Qleft_margin
))
18599 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18600 if (EQ (prop
, Qright_margin
))
18601 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18602 if (EQ (prop
, Qscroll_bar
))
18603 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18606 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18609 if (INTEGERP (prop
) || FLOATP (prop
))
18611 int base_unit
= (width_p
18612 ? FRAME_COLUMN_WIDTH (it
->f
)
18613 : FRAME_LINE_HEIGHT (it
->f
));
18614 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18619 Lisp_Object car
= XCAR (prop
);
18620 Lisp_Object cdr
= XCDR (prop
);
18624 #ifdef HAVE_WINDOW_SYSTEM
18625 if (valid_image_p (prop
))
18627 int id
= lookup_image (it
->f
, prop
);
18628 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
18630 return OK_PIXELS (width_p
? img
->width
: img
->height
);
18633 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18639 while (CONSP (cdr
))
18641 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
18642 font
, width_p
, align_to
))
18645 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18650 if (EQ (car
, Qminus
))
18652 return OK_PIXELS (pixels
);
18655 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18658 if (INTEGERP (car
) || FLOATP (car
))
18661 pixels
= XFLOATINT (car
);
18663 return OK_PIXELS (pixels
);
18664 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
18665 font
, width_p
, align_to
))
18666 return OK_PIXELS (pixels
* fact
);
18677 /***********************************************************************
18679 ***********************************************************************/
18681 #ifdef HAVE_WINDOW_SYSTEM
18686 dump_glyph_string (s
)
18687 struct glyph_string
*s
;
18689 fprintf (stderr
, "glyph string\n");
18690 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
18691 s
->x
, s
->y
, s
->width
, s
->height
);
18692 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
18693 fprintf (stderr
, " hl = %d\n", s
->hl
);
18694 fprintf (stderr
, " left overhang = %d, right = %d\n",
18695 s
->left_overhang
, s
->right_overhang
);
18696 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
18697 fprintf (stderr
, " extends to end of line = %d\n",
18698 s
->extends_to_end_of_line_p
);
18699 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
18700 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
18703 #endif /* GLYPH_DEBUG */
18705 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
18706 of XChar2b structures for S; it can't be allocated in
18707 init_glyph_string because it must be allocated via `alloca'. W
18708 is the window on which S is drawn. ROW and AREA are the glyph row
18709 and area within the row from which S is constructed. START is the
18710 index of the first glyph structure covered by S. HL is a
18711 face-override for drawing S. */
18714 #define OPTIONAL_HDC(hdc) hdc,
18715 #define DECLARE_HDC(hdc) HDC hdc;
18716 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
18717 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
18720 #ifndef OPTIONAL_HDC
18721 #define OPTIONAL_HDC(hdc)
18722 #define DECLARE_HDC(hdc)
18723 #define ALLOCATE_HDC(hdc, f)
18724 #define RELEASE_HDC(hdc, f)
18728 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
18729 struct glyph_string
*s
;
18733 struct glyph_row
*row
;
18734 enum glyph_row_area area
;
18736 enum draw_glyphs_face hl
;
18738 bzero (s
, sizeof *s
);
18740 s
->f
= XFRAME (w
->frame
);
18744 s
->display
= FRAME_X_DISPLAY (s
->f
);
18745 s
->window
= FRAME_X_WINDOW (s
->f
);
18746 s
->char2b
= char2b
;
18750 s
->first_glyph
= row
->glyphs
[area
] + start
;
18751 s
->height
= row
->height
;
18752 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
18754 /* Display the internal border below the tool-bar window. */
18755 if (WINDOWP (s
->f
->tool_bar_window
)
18756 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
18757 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
18759 s
->ybase
= s
->y
+ row
->ascent
;
18763 /* Append the list of glyph strings with head H and tail T to the list
18764 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
18767 append_glyph_string_lists (head
, tail
, h
, t
)
18768 struct glyph_string
**head
, **tail
;
18769 struct glyph_string
*h
, *t
;
18783 /* Prepend the list of glyph strings with head H and tail T to the
18784 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
18788 prepend_glyph_string_lists (head
, tail
, h
, t
)
18789 struct glyph_string
**head
, **tail
;
18790 struct glyph_string
*h
, *t
;
18804 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
18805 Set *HEAD and *TAIL to the resulting list. */
18808 append_glyph_string (head
, tail
, s
)
18809 struct glyph_string
**head
, **tail
;
18810 struct glyph_string
*s
;
18812 s
->next
= s
->prev
= NULL
;
18813 append_glyph_string_lists (head
, tail
, s
, s
);
18817 /* Get face and two-byte form of character glyph GLYPH on frame F.
18818 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
18819 a pointer to a realized face that is ready for display. */
18821 static INLINE
struct face
*
18822 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
18824 struct glyph
*glyph
;
18830 xassert (glyph
->type
== CHAR_GLYPH
);
18831 face
= FACE_FROM_ID (f
, glyph
->face_id
);
18836 if (!glyph
->multibyte_p
)
18838 /* Unibyte case. We don't have to encode, but we have to make
18839 sure to use a face suitable for unibyte. */
18840 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18842 else if (glyph
->u
.ch
< 128)
18844 /* Case of ASCII in a face known to fit ASCII. */
18845 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18849 int c1
, c2
, charset
;
18851 /* Split characters into bytes. If c2 is -1 afterwards, C is
18852 really a one-byte character so that byte1 is zero. */
18853 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
18855 STORE_XCHAR2B (char2b
, c1
, c2
);
18857 STORE_XCHAR2B (char2b
, 0, c1
);
18859 /* Maybe encode the character in *CHAR2B. */
18860 if (charset
!= CHARSET_ASCII
)
18862 struct font_info
*font_info
18863 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18866 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
18870 /* Make sure X resources of the face are allocated. */
18871 xassert (face
!= NULL
);
18872 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18877 /* Fill glyph string S with composition components specified by S->cmp.
18879 FACES is an array of faces for all components of this composition.
18880 S->gidx is the index of the first component for S.
18882 OVERLAPS non-zero means S should draw the foreground only, and use
18883 its physical height for clipping. See also draw_glyphs.
18885 Value is the index of a component not in S. */
18888 fill_composite_glyph_string (s
, faces
, overlaps
)
18889 struct glyph_string
*s
;
18890 struct face
**faces
;
18897 s
->for_overlaps
= overlaps
;
18899 s
->face
= faces
[s
->gidx
];
18900 s
->font
= s
->face
->font
;
18901 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18903 /* For all glyphs of this composition, starting at the offset
18904 S->gidx, until we reach the end of the definition or encounter a
18905 glyph that requires the different face, add it to S. */
18907 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
18910 /* All glyph strings for the same composition has the same width,
18911 i.e. the width set for the first component of the composition. */
18913 s
->width
= s
->first_glyph
->pixel_width
;
18915 /* If the specified font could not be loaded, use the frame's
18916 default font, but record the fact that we couldn't load it in
18917 the glyph string so that we can draw rectangles for the
18918 characters of the glyph string. */
18919 if (s
->font
== NULL
)
18921 s
->font_not_found_p
= 1;
18922 s
->font
= FRAME_FONT (s
->f
);
18925 /* Adjust base line for subscript/superscript text. */
18926 s
->ybase
+= s
->first_glyph
->voffset
;
18928 xassert (s
->face
&& s
->face
->gc
);
18930 /* This glyph string must always be drawn with 16-bit functions. */
18933 return s
->gidx
+ s
->nchars
;
18937 /* Fill glyph string S from a sequence of character glyphs.
18939 FACE_ID is the face id of the string. START is the index of the
18940 first glyph to consider, END is the index of the last + 1.
18941 OVERLAPS non-zero means S should draw the foreground only, and use
18942 its physical height for clipping. See also draw_glyphs.
18944 Value is the index of the first glyph not in S. */
18947 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
18948 struct glyph_string
*s
;
18950 int start
, end
, overlaps
;
18952 struct glyph
*glyph
, *last
;
18954 int glyph_not_available_p
;
18956 xassert (s
->f
== XFRAME (s
->w
->frame
));
18957 xassert (s
->nchars
== 0);
18958 xassert (start
>= 0 && end
> start
);
18960 s
->for_overlaps
= overlaps
,
18961 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18962 last
= s
->row
->glyphs
[s
->area
] + end
;
18963 voffset
= glyph
->voffset
;
18965 glyph_not_available_p
= glyph
->glyph_not_available_p
;
18967 while (glyph
< last
18968 && glyph
->type
== CHAR_GLYPH
18969 && glyph
->voffset
== voffset
18970 /* Same face id implies same font, nowadays. */
18971 && glyph
->face_id
== face_id
18972 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
18976 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
18977 s
->char2b
+ s
->nchars
,
18979 s
->two_byte_p
= two_byte_p
;
18981 xassert (s
->nchars
<= end
- start
);
18982 s
->width
+= glyph
->pixel_width
;
18986 s
->font
= s
->face
->font
;
18987 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18989 /* If the specified font could not be loaded, use the frame's font,
18990 but record the fact that we couldn't load it in
18991 S->font_not_found_p so that we can draw rectangles for the
18992 characters of the glyph string. */
18993 if (s
->font
== NULL
|| glyph_not_available_p
)
18995 s
->font_not_found_p
= 1;
18996 s
->font
= FRAME_FONT (s
->f
);
18999 /* Adjust base line for subscript/superscript text. */
19000 s
->ybase
+= voffset
;
19002 xassert (s
->face
&& s
->face
->gc
);
19003 return glyph
- s
->row
->glyphs
[s
->area
];
19007 /* Fill glyph string S from image glyph S->first_glyph. */
19010 fill_image_glyph_string (s
)
19011 struct glyph_string
*s
;
19013 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
19014 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
19016 s
->slice
= s
->first_glyph
->slice
;
19017 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
19018 s
->font
= s
->face
->font
;
19019 s
->width
= s
->first_glyph
->pixel_width
;
19021 /* Adjust base line for subscript/superscript text. */
19022 s
->ybase
+= s
->first_glyph
->voffset
;
19026 /* Fill glyph string S from a sequence of stretch glyphs.
19028 ROW is the glyph row in which the glyphs are found, AREA is the
19029 area within the row. START is the index of the first glyph to
19030 consider, END is the index of the last + 1.
19032 Value is the index of the first glyph not in S. */
19035 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
19036 struct glyph_string
*s
;
19037 struct glyph_row
*row
;
19038 enum glyph_row_area area
;
19041 struct glyph
*glyph
, *last
;
19042 int voffset
, face_id
;
19044 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
19046 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19047 last
= s
->row
->glyphs
[s
->area
] + end
;
19048 face_id
= glyph
->face_id
;
19049 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19050 s
->font
= s
->face
->font
;
19051 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
19052 s
->width
= glyph
->pixel_width
;
19054 voffset
= glyph
->voffset
;
19058 && glyph
->type
== STRETCH_GLYPH
19059 && glyph
->voffset
== voffset
19060 && glyph
->face_id
== face_id
);
19062 s
->width
+= glyph
->pixel_width
;
19064 /* Adjust base line for subscript/superscript text. */
19065 s
->ybase
+= voffset
;
19067 /* The case that face->gc == 0 is handled when drawing the glyph
19068 string by calling PREPARE_FACE_FOR_DISPLAY. */
19070 return glyph
- s
->row
->glyphs
[s
->area
];
19075 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
19076 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
19077 assumed to be zero. */
19080 x_get_glyph_overhangs (glyph
, f
, left
, right
)
19081 struct glyph
*glyph
;
19085 *left
= *right
= 0;
19087 if (glyph
->type
== CHAR_GLYPH
)
19091 struct font_info
*font_info
;
19095 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
19097 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
19098 if (font
/* ++KFS: Should this be font_info ? */
19099 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
19101 if (pcm
->rbearing
> pcm
->width
)
19102 *right
= pcm
->rbearing
- pcm
->width
;
19103 if (pcm
->lbearing
< 0)
19104 *left
= -pcm
->lbearing
;
19110 /* Return the index of the first glyph preceding glyph string S that
19111 is overwritten by S because of S's left overhang. Value is -1
19112 if no glyphs are overwritten. */
19115 left_overwritten (s
)
19116 struct glyph_string
*s
;
19120 if (s
->left_overhang
)
19123 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19124 int first
= s
->first_glyph
- glyphs
;
19126 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
19127 x
-= glyphs
[i
].pixel_width
;
19138 /* Return the index of the first glyph preceding glyph string S that
19139 is overwriting S because of its right overhang. Value is -1 if no
19140 glyph in front of S overwrites S. */
19143 left_overwriting (s
)
19144 struct glyph_string
*s
;
19147 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19148 int first
= s
->first_glyph
- glyphs
;
19152 for (i
= first
- 1; i
>= 0; --i
)
19155 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19158 x
-= glyphs
[i
].pixel_width
;
19165 /* Return the index of the last glyph following glyph string S that is
19166 not overwritten by S because of S's right overhang. Value is -1 if
19167 no such glyph is found. */
19170 right_overwritten (s
)
19171 struct glyph_string
*s
;
19175 if (s
->right_overhang
)
19178 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19179 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19180 int end
= s
->row
->used
[s
->area
];
19182 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
19183 x
+= glyphs
[i
].pixel_width
;
19192 /* Return the index of the last glyph following glyph string S that
19193 overwrites S because of its left overhang. Value is negative
19194 if no such glyph is found. */
19197 right_overwriting (s
)
19198 struct glyph_string
*s
;
19201 int end
= s
->row
->used
[s
->area
];
19202 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19203 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19207 for (i
= first
; i
< end
; ++i
)
19210 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19213 x
+= glyphs
[i
].pixel_width
;
19220 /* Get face and two-byte form of character C in face FACE_ID on frame
19221 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19222 means we want to display multibyte text. DISPLAY_P non-zero means
19223 make sure that X resources for the face returned are allocated.
19224 Value is a pointer to a realized face that is ready for display if
19225 DISPLAY_P is non-zero. */
19227 static INLINE
struct face
*
19228 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
19232 int multibyte_p
, display_p
;
19234 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19238 /* Unibyte case. We don't have to encode, but we have to make
19239 sure to use a face suitable for unibyte. */
19240 STORE_XCHAR2B (char2b
, 0, c
);
19241 face_id
= FACE_FOR_CHAR (f
, face
, c
);
19242 face
= FACE_FROM_ID (f
, face_id
);
19246 /* Case of ASCII in a face known to fit ASCII. */
19247 STORE_XCHAR2B (char2b
, 0, c
);
19251 int c1
, c2
, charset
;
19253 /* Split characters into bytes. If c2 is -1 afterwards, C is
19254 really a one-byte character so that byte1 is zero. */
19255 SPLIT_CHAR (c
, charset
, c1
, c2
);
19257 STORE_XCHAR2B (char2b
, c1
, c2
);
19259 STORE_XCHAR2B (char2b
, 0, c1
);
19261 /* Maybe encode the character in *CHAR2B. */
19262 if (face
->font
!= NULL
)
19264 struct font_info
*font_info
19265 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
19267 rif
->encode_char (c
, char2b
, font_info
, 0);
19271 /* Make sure X resources of the face are allocated. */
19272 #ifdef HAVE_X_WINDOWS
19276 xassert (face
!= NULL
);
19277 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19284 /* Set background width of glyph string S. START is the index of the
19285 first glyph following S. LAST_X is the right-most x-position + 1
19286 in the drawing area. */
19289 set_glyph_string_background_width (s
, start
, last_x
)
19290 struct glyph_string
*s
;
19294 /* If the face of this glyph string has to be drawn to the end of
19295 the drawing area, set S->extends_to_end_of_line_p. */
19297 if (start
== s
->row
->used
[s
->area
]
19298 && s
->area
== TEXT_AREA
19299 && ((s
->row
->fill_line_p
19300 && (s
->hl
== DRAW_NORMAL_TEXT
19301 || s
->hl
== DRAW_IMAGE_RAISED
19302 || s
->hl
== DRAW_IMAGE_SUNKEN
))
19303 || s
->hl
== DRAW_MOUSE_FACE
))
19304 s
->extends_to_end_of_line_p
= 1;
19306 /* If S extends its face to the end of the line, set its
19307 background_width to the distance to the right edge of the drawing
19309 if (s
->extends_to_end_of_line_p
)
19310 s
->background_width
= last_x
- s
->x
+ 1;
19312 s
->background_width
= s
->width
;
19316 /* Compute overhangs and x-positions for glyph string S and its
19317 predecessors, or successors. X is the starting x-position for S.
19318 BACKWARD_P non-zero means process predecessors. */
19321 compute_overhangs_and_x (s
, x
, backward_p
)
19322 struct glyph_string
*s
;
19330 if (rif
->compute_glyph_string_overhangs
)
19331 rif
->compute_glyph_string_overhangs (s
);
19341 if (rif
->compute_glyph_string_overhangs
)
19342 rif
->compute_glyph_string_overhangs (s
);
19352 /* The following macros are only called from draw_glyphs below.
19353 They reference the following parameters of that function directly:
19354 `w', `row', `area', and `overlap_p'
19355 as well as the following local variables:
19356 `s', `f', and `hdc' (in W32) */
19359 /* On W32, silently add local `hdc' variable to argument list of
19360 init_glyph_string. */
19361 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19362 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
19364 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19365 init_glyph_string (s, char2b, w, row, area, start, hl)
19368 /* Add a glyph string for a stretch glyph to the list of strings
19369 between HEAD and TAIL. START is the index of the stretch glyph in
19370 row area AREA of glyph row ROW. END is the index of the last glyph
19371 in that glyph row area. X is the current output position assigned
19372 to the new glyph string constructed. HL overrides that face of the
19373 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19374 is the right-most x-position of the drawing area. */
19376 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
19377 and below -- keep them on one line. */
19378 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19381 s = (struct glyph_string *) alloca (sizeof *s); \
19382 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19383 START = fill_stretch_glyph_string (s, row, area, START, END); \
19384 append_glyph_string (&HEAD, &TAIL, s); \
19390 /* Add a glyph string for an image glyph to the list of strings
19391 between HEAD and TAIL. START is the index of the image glyph in
19392 row area AREA of glyph row ROW. END is the index of the last glyph
19393 in that glyph row area. X is the current output position assigned
19394 to the new glyph string constructed. HL overrides that face of the
19395 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19396 is the right-most x-position of the drawing area. */
19398 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19401 s = (struct glyph_string *) alloca (sizeof *s); \
19402 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19403 fill_image_glyph_string (s); \
19404 append_glyph_string (&HEAD, &TAIL, s); \
19411 /* Add a glyph string for a sequence of character glyphs to the list
19412 of strings between HEAD and TAIL. START is the index of the first
19413 glyph in row area AREA of glyph row ROW that is part of the new
19414 glyph string. END is the index of the last glyph in that glyph row
19415 area. X is the current output position assigned to the new glyph
19416 string constructed. HL overrides that face of the glyph; e.g. it
19417 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
19418 right-most x-position of the drawing area. */
19420 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19426 c = (row)->glyphs[area][START].u.ch; \
19427 face_id = (row)->glyphs[area][START].face_id; \
19429 s = (struct glyph_string *) alloca (sizeof *s); \
19430 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
19431 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
19432 append_glyph_string (&HEAD, &TAIL, s); \
19434 START = fill_glyph_string (s, face_id, START, END, overlaps); \
19439 /* Add a glyph string for a composite sequence to the list of strings
19440 between HEAD and TAIL. START is the index of the first glyph in
19441 row area AREA of glyph row ROW that is part of the new glyph
19442 string. END is the index of the last glyph in that glyph row area.
19443 X is the current output position assigned to the new glyph string
19444 constructed. HL overrides that face of the glyph; e.g. it is
19445 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
19446 x-position of the drawing area. */
19448 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19450 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
19451 int face_id = (row)->glyphs[area][START].face_id; \
19452 struct face *base_face = FACE_FROM_ID (f, face_id); \
19453 struct composition *cmp = composition_table[cmp_id]; \
19454 int glyph_len = cmp->glyph_len; \
19456 struct face **faces; \
19457 struct glyph_string *first_s = NULL; \
19460 base_face = base_face->ascii_face; \
19461 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
19462 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
19463 /* At first, fill in `char2b' and `faces'. */ \
19464 for (n = 0; n < glyph_len; n++) \
19466 int c = COMPOSITION_GLYPH (cmp, n); \
19467 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
19468 faces[n] = FACE_FROM_ID (f, this_face_id); \
19469 get_char_face_and_encoding (f, c, this_face_id, \
19470 char2b + n, 1, 1); \
19473 /* Make glyph_strings for each glyph sequence that is drawable by \
19474 the same face, and append them to HEAD/TAIL. */ \
19475 for (n = 0; n < cmp->glyph_len;) \
19477 s = (struct glyph_string *) alloca (sizeof *s); \
19478 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
19479 append_glyph_string (&(HEAD), &(TAIL), s); \
19487 n = fill_composite_glyph_string (s, faces, overlaps); \
19495 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
19496 of AREA of glyph row ROW on window W between indices START and END.
19497 HL overrides the face for drawing glyph strings, e.g. it is
19498 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
19499 x-positions of the drawing area.
19501 This is an ugly monster macro construct because we must use alloca
19502 to allocate glyph strings (because draw_glyphs can be called
19503 asynchronously). */
19505 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19508 HEAD = TAIL = NULL; \
19509 while (START < END) \
19511 struct glyph *first_glyph = (row)->glyphs[area] + START; \
19512 switch (first_glyph->type) \
19515 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
19519 case COMPOSITE_GLYPH: \
19520 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
19524 case STRETCH_GLYPH: \
19525 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
19529 case IMAGE_GLYPH: \
19530 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
19538 set_glyph_string_background_width (s, START, LAST_X); \
19545 /* Draw glyphs between START and END in AREA of ROW on window W,
19546 starting at x-position X. X is relative to AREA in W. HL is a
19547 face-override with the following meaning:
19549 DRAW_NORMAL_TEXT draw normally
19550 DRAW_CURSOR draw in cursor face
19551 DRAW_MOUSE_FACE draw in mouse face.
19552 DRAW_INVERSE_VIDEO draw in mode line face
19553 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
19554 DRAW_IMAGE_RAISED draw an image with a raised relief around it
19556 If OVERLAPS is non-zero, draw only the foreground of characters and
19557 clip to the physical height of ROW. Non-zero value also defines
19558 the overlapping part to be drawn:
19560 OVERLAPS_PRED overlap with preceding rows
19561 OVERLAPS_SUCC overlap with succeeding rows
19562 OVERLAPS_BOTH overlap with both preceding/succeeding rows
19563 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
19565 Value is the x-position reached, relative to AREA of W. */
19568 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
19571 struct glyph_row
*row
;
19572 enum glyph_row_area area
;
19574 enum draw_glyphs_face hl
;
19577 struct glyph_string
*head
, *tail
;
19578 struct glyph_string
*s
;
19579 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
19580 int last_x
, area_width
;
19583 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19586 ALLOCATE_HDC (hdc
, f
);
19588 /* Let's rather be paranoid than getting a SEGV. */
19589 end
= min (end
, row
->used
[area
]);
19590 start
= max (0, start
);
19591 start
= min (end
, start
);
19593 /* Translate X to frame coordinates. Set last_x to the right
19594 end of the drawing area. */
19595 if (row
->full_width_p
)
19597 /* X is relative to the left edge of W, without scroll bars
19599 x
+= WINDOW_LEFT_EDGE_X (w
);
19600 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
19604 int area_left
= window_box_left (w
, area
);
19606 area_width
= window_box_width (w
, area
);
19607 last_x
= area_left
+ area_width
;
19610 /* Build a doubly-linked list of glyph_string structures between
19611 head and tail from what we have to draw. Note that the macro
19612 BUILD_GLYPH_STRINGS will modify its start parameter. That's
19613 the reason we use a separate variable `i'. */
19615 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
19617 x_reached
= tail
->x
+ tail
->background_width
;
19621 /* If there are any glyphs with lbearing < 0 or rbearing > width in
19622 the row, redraw some glyphs in front or following the glyph
19623 strings built above. */
19624 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
19627 struct glyph_string
*h
, *t
;
19629 /* Compute overhangs for all glyph strings. */
19630 if (rif
->compute_glyph_string_overhangs
)
19631 for (s
= head
; s
; s
= s
->next
)
19632 rif
->compute_glyph_string_overhangs (s
);
19634 /* Prepend glyph strings for glyphs in front of the first glyph
19635 string that are overwritten because of the first glyph
19636 string's left overhang. The background of all strings
19637 prepended must be drawn because the first glyph string
19639 i
= left_overwritten (head
);
19643 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
19644 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19646 compute_overhangs_and_x (t
, head
->x
, 1);
19647 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19651 /* Prepend glyph strings for glyphs in front of the first glyph
19652 string that overwrite that glyph string because of their
19653 right overhang. For these strings, only the foreground must
19654 be drawn, because it draws over the glyph string at `head'.
19655 The background must not be drawn because this would overwrite
19656 right overhangs of preceding glyphs for which no glyph
19658 i
= left_overwriting (head
);
19662 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
19663 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19664 for (s
= h
; s
; s
= s
->next
)
19665 s
->background_filled_p
= 1;
19666 compute_overhangs_and_x (t
, head
->x
, 1);
19667 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19670 /* Append glyphs strings for glyphs following the last glyph
19671 string tail that are overwritten by tail. The background of
19672 these strings has to be drawn because tail's foreground draws
19674 i
= right_overwritten (tail
);
19677 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19678 DRAW_NORMAL_TEXT
, x
, last_x
);
19679 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19680 append_glyph_string_lists (&head
, &tail
, h
, t
);
19684 /* Append glyph strings for glyphs following the last glyph
19685 string tail that overwrite tail. The foreground of such
19686 glyphs has to be drawn because it writes into the background
19687 of tail. The background must not be drawn because it could
19688 paint over the foreground of following glyphs. */
19689 i
= right_overwriting (tail
);
19693 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19694 DRAW_NORMAL_TEXT
, x
, last_x
);
19695 for (s
= h
; s
; s
= s
->next
)
19696 s
->background_filled_p
= 1;
19697 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19698 append_glyph_string_lists (&head
, &tail
, h
, t
);
19700 if (clip_head
|| clip_tail
)
19701 for (s
= head
; s
; s
= s
->next
)
19703 s
->clip_head
= clip_head
;
19704 s
->clip_tail
= clip_tail
;
19708 /* Draw all strings. */
19709 for (s
= head
; s
; s
= s
->next
)
19710 rif
->draw_glyph_string (s
);
19712 if (area
== TEXT_AREA
19713 && !row
->full_width_p
19714 /* When drawing overlapping rows, only the glyph strings'
19715 foreground is drawn, which doesn't erase a cursor
19719 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
19720 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
19721 : (tail
? tail
->x
+ tail
->background_width
: x
));
19723 int text_left
= window_box_left (w
, TEXT_AREA
);
19727 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
19728 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
19731 /* Value is the x-position up to which drawn, relative to AREA of W.
19732 This doesn't include parts drawn because of overhangs. */
19733 if (row
->full_width_p
)
19734 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
19736 x_reached
-= window_box_left (w
, area
);
19738 RELEASE_HDC (hdc
, f
);
19743 /* Expand row matrix if too narrow. Don't expand if area
19746 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
19748 if (!fonts_changed_p \
19749 && (it->glyph_row->glyphs[area] \
19750 < it->glyph_row->glyphs[area + 1])) \
19752 it->w->ncols_scale_factor++; \
19753 fonts_changed_p = 1; \
19757 /* Store one glyph for IT->char_to_display in IT->glyph_row.
19758 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19764 struct glyph
*glyph
;
19765 enum glyph_row_area area
= it
->area
;
19767 xassert (it
->glyph_row
);
19768 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
19770 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19771 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19773 glyph
->charpos
= CHARPOS (it
->position
);
19774 glyph
->object
= it
->object
;
19775 glyph
->pixel_width
= it
->pixel_width
;
19776 glyph
->ascent
= it
->ascent
;
19777 glyph
->descent
= it
->descent
;
19778 glyph
->voffset
= it
->voffset
;
19779 glyph
->type
= CHAR_GLYPH
;
19780 glyph
->multibyte_p
= it
->multibyte_p
;
19781 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19782 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19783 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19784 || it
->phys_descent
> it
->descent
);
19785 glyph
->padding_p
= 0;
19786 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
19787 glyph
->face_id
= it
->face_id
;
19788 glyph
->u
.ch
= it
->char_to_display
;
19789 glyph
->slice
= null_glyph_slice
;
19790 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19791 ++it
->glyph_row
->used
[area
];
19794 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19797 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
19798 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19801 append_composite_glyph (it
)
19804 struct glyph
*glyph
;
19805 enum glyph_row_area area
= it
->area
;
19807 xassert (it
->glyph_row
);
19809 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19810 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19812 glyph
->charpos
= CHARPOS (it
->position
);
19813 glyph
->object
= it
->object
;
19814 glyph
->pixel_width
= it
->pixel_width
;
19815 glyph
->ascent
= it
->ascent
;
19816 glyph
->descent
= it
->descent
;
19817 glyph
->voffset
= it
->voffset
;
19818 glyph
->type
= COMPOSITE_GLYPH
;
19819 glyph
->multibyte_p
= it
->multibyte_p
;
19820 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19821 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19822 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19823 || it
->phys_descent
> it
->descent
);
19824 glyph
->padding_p
= 0;
19825 glyph
->glyph_not_available_p
= 0;
19826 glyph
->face_id
= it
->face_id
;
19827 glyph
->u
.cmp_id
= it
->cmp_id
;
19828 glyph
->slice
= null_glyph_slice
;
19829 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19830 ++it
->glyph_row
->used
[area
];
19833 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19837 /* Change IT->ascent and IT->height according to the setting of
19841 take_vertical_position_into_account (it
)
19846 if (it
->voffset
< 0)
19847 /* Increase the ascent so that we can display the text higher
19849 it
->ascent
-= it
->voffset
;
19851 /* Increase the descent so that we can display the text lower
19853 it
->descent
+= it
->voffset
;
19858 /* Produce glyphs/get display metrics for the image IT is loaded with.
19859 See the description of struct display_iterator in dispextern.h for
19860 an overview of struct display_iterator. */
19863 produce_image_glyph (it
)
19868 int glyph_ascent
, crop
;
19869 struct glyph_slice slice
;
19871 xassert (it
->what
== IT_IMAGE
);
19873 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19875 /* Make sure X resources of the face is loaded. */
19876 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19878 if (it
->image_id
< 0)
19880 /* Fringe bitmap. */
19881 it
->ascent
= it
->phys_ascent
= 0;
19882 it
->descent
= it
->phys_descent
= 0;
19883 it
->pixel_width
= 0;
19888 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
19890 /* Make sure X resources of the image is loaded. */
19891 prepare_image_for_display (it
->f
, img
);
19893 slice
.x
= slice
.y
= 0;
19894 slice
.width
= img
->width
;
19895 slice
.height
= img
->height
;
19897 if (INTEGERP (it
->slice
.x
))
19898 slice
.x
= XINT (it
->slice
.x
);
19899 else if (FLOATP (it
->slice
.x
))
19900 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
19902 if (INTEGERP (it
->slice
.y
))
19903 slice
.y
= XINT (it
->slice
.y
);
19904 else if (FLOATP (it
->slice
.y
))
19905 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
19907 if (INTEGERP (it
->slice
.width
))
19908 slice
.width
= XINT (it
->slice
.width
);
19909 else if (FLOATP (it
->slice
.width
))
19910 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
19912 if (INTEGERP (it
->slice
.height
))
19913 slice
.height
= XINT (it
->slice
.height
);
19914 else if (FLOATP (it
->slice
.height
))
19915 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
19917 if (slice
.x
>= img
->width
)
19918 slice
.x
= img
->width
;
19919 if (slice
.y
>= img
->height
)
19920 slice
.y
= img
->height
;
19921 if (slice
.x
+ slice
.width
>= img
->width
)
19922 slice
.width
= img
->width
- slice
.x
;
19923 if (slice
.y
+ slice
.height
> img
->height
)
19924 slice
.height
= img
->height
- slice
.y
;
19926 if (slice
.width
== 0 || slice
.height
== 0)
19929 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
19931 it
->descent
= slice
.height
- glyph_ascent
;
19933 it
->descent
+= img
->vmargin
;
19934 if (slice
.y
+ slice
.height
== img
->height
)
19935 it
->descent
+= img
->vmargin
;
19936 it
->phys_descent
= it
->descent
;
19938 it
->pixel_width
= slice
.width
;
19940 it
->pixel_width
+= img
->hmargin
;
19941 if (slice
.x
+ slice
.width
== img
->width
)
19942 it
->pixel_width
+= img
->hmargin
;
19944 /* It's quite possible for images to have an ascent greater than
19945 their height, so don't get confused in that case. */
19946 if (it
->descent
< 0)
19949 #if 0 /* this breaks image tiling */
19950 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
19951 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
19952 if (face_ascent
> it
->ascent
)
19953 it
->ascent
= it
->phys_ascent
= face_ascent
;
19958 if (face
->box
!= FACE_NO_BOX
)
19960 if (face
->box_line_width
> 0)
19963 it
->ascent
+= face
->box_line_width
;
19964 if (slice
.y
+ slice
.height
== img
->height
)
19965 it
->descent
+= face
->box_line_width
;
19968 if (it
->start_of_box_run_p
&& slice
.x
== 0)
19969 it
->pixel_width
+= abs (face
->box_line_width
);
19970 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
19971 it
->pixel_width
+= abs (face
->box_line_width
);
19974 take_vertical_position_into_account (it
);
19976 /* Automatically crop wide image glyphs at right edge so we can
19977 draw the cursor on same display row. */
19978 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
19979 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
19981 it
->pixel_width
-= crop
;
19982 slice
.width
-= crop
;
19987 struct glyph
*glyph
;
19988 enum glyph_row_area area
= it
->area
;
19990 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19991 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19993 glyph
->charpos
= CHARPOS (it
->position
);
19994 glyph
->object
= it
->object
;
19995 glyph
->pixel_width
= it
->pixel_width
;
19996 glyph
->ascent
= glyph_ascent
;
19997 glyph
->descent
= it
->descent
;
19998 glyph
->voffset
= it
->voffset
;
19999 glyph
->type
= IMAGE_GLYPH
;
20000 glyph
->multibyte_p
= it
->multibyte_p
;
20001 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20002 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20003 glyph
->overlaps_vertically_p
= 0;
20004 glyph
->padding_p
= 0;
20005 glyph
->glyph_not_available_p
= 0;
20006 glyph
->face_id
= it
->face_id
;
20007 glyph
->u
.img_id
= img
->id
;
20008 glyph
->slice
= slice
;
20009 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20010 ++it
->glyph_row
->used
[area
];
20013 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20018 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
20019 of the glyph, WIDTH and HEIGHT are the width and height of the
20020 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
20023 append_stretch_glyph (it
, object
, width
, height
, ascent
)
20025 Lisp_Object object
;
20029 struct glyph
*glyph
;
20030 enum glyph_row_area area
= it
->area
;
20032 xassert (ascent
>= 0 && ascent
<= height
);
20034 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20035 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20037 glyph
->charpos
= CHARPOS (it
->position
);
20038 glyph
->object
= object
;
20039 glyph
->pixel_width
= width
;
20040 glyph
->ascent
= ascent
;
20041 glyph
->descent
= height
- ascent
;
20042 glyph
->voffset
= it
->voffset
;
20043 glyph
->type
= STRETCH_GLYPH
;
20044 glyph
->multibyte_p
= it
->multibyte_p
;
20045 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20046 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20047 glyph
->overlaps_vertically_p
= 0;
20048 glyph
->padding_p
= 0;
20049 glyph
->glyph_not_available_p
= 0;
20050 glyph
->face_id
= it
->face_id
;
20051 glyph
->u
.stretch
.ascent
= ascent
;
20052 glyph
->u
.stretch
.height
= height
;
20053 glyph
->slice
= null_glyph_slice
;
20054 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20055 ++it
->glyph_row
->used
[area
];
20058 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20062 /* Produce a stretch glyph for iterator IT. IT->object is the value
20063 of the glyph property displayed. The value must be a list
20064 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
20067 1. `:width WIDTH' specifies that the space should be WIDTH *
20068 canonical char width wide. WIDTH may be an integer or floating
20071 2. `:relative-width FACTOR' specifies that the width of the stretch
20072 should be computed from the width of the first character having the
20073 `glyph' property, and should be FACTOR times that width.
20075 3. `:align-to HPOS' specifies that the space should be wide enough
20076 to reach HPOS, a value in canonical character units.
20078 Exactly one of the above pairs must be present.
20080 4. `:height HEIGHT' specifies that the height of the stretch produced
20081 should be HEIGHT, measured in canonical character units.
20083 5. `:relative-height FACTOR' specifies that the height of the
20084 stretch should be FACTOR times the height of the characters having
20085 the glyph property.
20087 Either none or exactly one of 4 or 5 must be present.
20089 6. `:ascent ASCENT' specifies that ASCENT percent of the height
20090 of the stretch should be used for the ascent of the stretch.
20091 ASCENT must be in the range 0 <= ASCENT <= 100. */
20094 produce_stretch_glyph (it
)
20097 /* (space :width WIDTH :height HEIGHT ...) */
20098 Lisp_Object prop
, plist
;
20099 int width
= 0, height
= 0, align_to
= -1;
20100 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
20103 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20104 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
20106 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20108 /* List should start with `space'. */
20109 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
20110 plist
= XCDR (it
->object
);
20112 /* Compute the width of the stretch. */
20113 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
20114 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
20116 /* Absolute width `:width WIDTH' specified and valid. */
20117 zero_width_ok_p
= 1;
20120 else if (prop
= Fplist_get (plist
, QCrelative_width
),
20123 /* Relative width `:relative-width FACTOR' specified and valid.
20124 Compute the width of the characters having the `glyph'
20127 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
20130 if (it
->multibyte_p
)
20132 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
20133 - IT_BYTEPOS (*it
));
20134 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
20137 it2
.c
= *p
, it2
.len
= 1;
20139 it2
.glyph_row
= NULL
;
20140 it2
.what
= IT_CHARACTER
;
20141 x_produce_glyphs (&it2
);
20142 width
= NUMVAL (prop
) * it2
.pixel_width
;
20144 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
20145 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
20147 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
20148 align_to
= (align_to
< 0
20150 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
20151 else if (align_to
< 0)
20152 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
20153 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
20154 zero_width_ok_p
= 1;
20157 /* Nothing specified -> width defaults to canonical char width. */
20158 width
= FRAME_COLUMN_WIDTH (it
->f
);
20160 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
20163 /* Compute height. */
20164 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
20165 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20168 zero_height_ok_p
= 1;
20170 else if (prop
= Fplist_get (plist
, QCrelative_height
),
20172 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
20174 height
= FONT_HEIGHT (font
);
20176 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
20179 /* Compute percentage of height used for ascent. If
20180 `:ascent ASCENT' is present and valid, use that. Otherwise,
20181 derive the ascent from the font in use. */
20182 if (prop
= Fplist_get (plist
, QCascent
),
20183 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
20184 ascent
= height
* NUMVAL (prop
) / 100.0;
20185 else if (!NILP (prop
)
20186 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20187 ascent
= min (max (0, (int)tem
), height
);
20189 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
20191 if (width
> 0 && !it
->truncate_lines_p
20192 && it
->current_x
+ width
> it
->last_visible_x
)
20193 width
= it
->last_visible_x
- it
->current_x
- 1;
20195 if (width
> 0 && height
> 0 && it
->glyph_row
)
20197 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
20198 if (!STRINGP (object
))
20199 object
= it
->w
->buffer
;
20200 append_stretch_glyph (it
, object
, width
, height
, ascent
);
20203 it
->pixel_width
= width
;
20204 it
->ascent
= it
->phys_ascent
= ascent
;
20205 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
20206 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
20208 take_vertical_position_into_account (it
);
20211 /* Get line-height and line-spacing property at point.
20212 If line-height has format (HEIGHT TOTAL), return TOTAL
20213 in TOTAL_HEIGHT. */
20216 get_line_height_property (it
, prop
)
20220 Lisp_Object position
;
20222 if (STRINGP (it
->object
))
20223 position
= make_number (IT_STRING_CHARPOS (*it
));
20224 else if (BUFFERP (it
->object
))
20225 position
= make_number (IT_CHARPOS (*it
));
20229 return Fget_char_property (position
, prop
, it
->object
);
20232 /* Calculate line-height and line-spacing properties.
20233 An integer value specifies explicit pixel value.
20234 A float value specifies relative value to current face height.
20235 A cons (float . face-name) specifies relative value to
20236 height of specified face font.
20238 Returns height in pixels, or nil. */
20242 calc_line_height_property (it
, val
, font
, boff
, override
)
20246 int boff
, override
;
20248 Lisp_Object face_name
= Qnil
;
20249 int ascent
, descent
, height
;
20251 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
20256 face_name
= XCAR (val
);
20258 if (!NUMBERP (val
))
20259 val
= make_number (1);
20260 if (NILP (face_name
))
20262 height
= it
->ascent
+ it
->descent
;
20267 if (NILP (face_name
))
20269 font
= FRAME_FONT (it
->f
);
20270 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20272 else if (EQ (face_name
, Qt
))
20280 struct font_info
*font_info
;
20282 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
20284 return make_number (-1);
20286 face
= FACE_FROM_ID (it
->f
, face_id
);
20289 return make_number (-1);
20291 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20292 boff
= font_info
->baseline_offset
;
20293 if (font_info
->vertical_centering
)
20294 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20297 ascent
= FONT_BASE (font
) + boff
;
20298 descent
= FONT_DESCENT (font
) - boff
;
20302 it
->override_ascent
= ascent
;
20303 it
->override_descent
= descent
;
20304 it
->override_boff
= boff
;
20307 height
= ascent
+ descent
;
20311 height
= (int)(XFLOAT_DATA (val
) * height
);
20312 else if (INTEGERP (val
))
20313 height
*= XINT (val
);
20315 return make_number (height
);
20320 Produce glyphs/get display metrics for the display element IT is
20321 loaded with. See the description of struct it in dispextern.h
20322 for an overview of struct it. */
20325 x_produce_glyphs (it
)
20328 int extra_line_spacing
= it
->extra_line_spacing
;
20330 it
->glyph_not_available_p
= 0;
20332 if (it
->what
== IT_CHARACTER
)
20336 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20338 int font_not_found_p
;
20339 struct font_info
*font_info
;
20340 int boff
; /* baseline offset */
20341 /* We may change it->multibyte_p upon unibyte<->multibyte
20342 conversion. So, save the current value now and restore it
20345 Note: It seems that we don't have to record multibyte_p in
20346 struct glyph because the character code itself tells if or
20347 not the character is multibyte. Thus, in the future, we must
20348 consider eliminating the field `multibyte_p' in the struct
20350 int saved_multibyte_p
= it
->multibyte_p
;
20352 /* Maybe translate single-byte characters to multibyte, or the
20354 it
->char_to_display
= it
->c
;
20355 if (!ASCII_BYTE_P (it
->c
))
20357 if (unibyte_display_via_language_environment
20358 && SINGLE_BYTE_CHAR_P (it
->c
)
20360 || !NILP (Vnonascii_translation_table
)))
20362 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20363 it
->multibyte_p
= 1;
20364 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20365 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20367 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
20368 && !it
->multibyte_p
)
20370 it
->multibyte_p
= 1;
20371 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20372 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20376 /* Get font to use. Encode IT->char_to_display. */
20377 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20378 &char2b
, it
->multibyte_p
, 0);
20381 /* When no suitable font found, use the default font. */
20382 font_not_found_p
= font
== NULL
;
20383 if (font_not_found_p
)
20385 font
= FRAME_FONT (it
->f
);
20386 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20391 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20392 boff
= font_info
->baseline_offset
;
20393 if (font_info
->vertical_centering
)
20394 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20397 if (it
->char_to_display
>= ' '
20398 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
20400 /* Either unibyte or ASCII. */
20405 pcm
= rif
->per_char_metric (font
, &char2b
,
20406 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
20408 if (it
->override_ascent
>= 0)
20410 it
->ascent
= it
->override_ascent
;
20411 it
->descent
= it
->override_descent
;
20412 boff
= it
->override_boff
;
20416 it
->ascent
= FONT_BASE (font
) + boff
;
20417 it
->descent
= FONT_DESCENT (font
) - boff
;
20422 it
->phys_ascent
= pcm
->ascent
+ boff
;
20423 it
->phys_descent
= pcm
->descent
- boff
;
20424 it
->pixel_width
= pcm
->width
;
20428 it
->glyph_not_available_p
= 1;
20429 it
->phys_ascent
= it
->ascent
;
20430 it
->phys_descent
= it
->descent
;
20431 it
->pixel_width
= FONT_WIDTH (font
);
20434 if (it
->constrain_row_ascent_descent_p
)
20436 if (it
->descent
> it
->max_descent
)
20438 it
->ascent
+= it
->descent
- it
->max_descent
;
20439 it
->descent
= it
->max_descent
;
20441 if (it
->ascent
> it
->max_ascent
)
20443 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20444 it
->ascent
= it
->max_ascent
;
20446 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20447 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20448 extra_line_spacing
= 0;
20451 /* If this is a space inside a region of text with
20452 `space-width' property, change its width. */
20453 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
20455 it
->pixel_width
*= XFLOATINT (it
->space_width
);
20457 /* If face has a box, add the box thickness to the character
20458 height. If character has a box line to the left and/or
20459 right, add the box line width to the character's width. */
20460 if (face
->box
!= FACE_NO_BOX
)
20462 int thick
= face
->box_line_width
;
20466 it
->ascent
+= thick
;
20467 it
->descent
+= thick
;
20472 if (it
->start_of_box_run_p
)
20473 it
->pixel_width
+= thick
;
20474 if (it
->end_of_box_run_p
)
20475 it
->pixel_width
+= thick
;
20478 /* If face has an overline, add the height of the overline
20479 (1 pixel) and a 1 pixel margin to the character height. */
20480 if (face
->overline_p
)
20481 it
->ascent
+= overline_margin
;
20483 if (it
->constrain_row_ascent_descent_p
)
20485 if (it
->ascent
> it
->max_ascent
)
20486 it
->ascent
= it
->max_ascent
;
20487 if (it
->descent
> it
->max_descent
)
20488 it
->descent
= it
->max_descent
;
20491 take_vertical_position_into_account (it
);
20493 /* If we have to actually produce glyphs, do it. */
20498 /* Translate a space with a `space-width' property
20499 into a stretch glyph. */
20500 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
20501 / FONT_HEIGHT (font
));
20502 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20503 it
->ascent
+ it
->descent
, ascent
);
20508 /* If characters with lbearing or rbearing are displayed
20509 in this line, record that fact in a flag of the
20510 glyph row. This is used to optimize X output code. */
20511 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
20512 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20515 else if (it
->char_to_display
== '\n')
20517 /* A newline has no width but we need the height of the line.
20518 But if previous part of the line set a height, don't
20519 increase that height */
20521 Lisp_Object height
;
20522 Lisp_Object total_height
= Qnil
;
20524 it
->override_ascent
= -1;
20525 it
->pixel_width
= 0;
20528 height
= get_line_height_property(it
, Qline_height
);
20529 /* Split (line-height total-height) list */
20531 && CONSP (XCDR (height
))
20532 && NILP (XCDR (XCDR (height
))))
20534 total_height
= XCAR (XCDR (height
));
20535 height
= XCAR (height
);
20537 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
20539 if (it
->override_ascent
>= 0)
20541 it
->ascent
= it
->override_ascent
;
20542 it
->descent
= it
->override_descent
;
20543 boff
= it
->override_boff
;
20547 it
->ascent
= FONT_BASE (font
) + boff
;
20548 it
->descent
= FONT_DESCENT (font
) - boff
;
20551 if (EQ (height
, Qt
))
20553 if (it
->descent
> it
->max_descent
)
20555 it
->ascent
+= it
->descent
- it
->max_descent
;
20556 it
->descent
= it
->max_descent
;
20558 if (it
->ascent
> it
->max_ascent
)
20560 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20561 it
->ascent
= it
->max_ascent
;
20563 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20564 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20565 it
->constrain_row_ascent_descent_p
= 1;
20566 extra_line_spacing
= 0;
20570 Lisp_Object spacing
;
20572 it
->phys_ascent
= it
->ascent
;
20573 it
->phys_descent
= it
->descent
;
20575 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
20576 && face
->box
!= FACE_NO_BOX
20577 && face
->box_line_width
> 0)
20579 it
->ascent
+= face
->box_line_width
;
20580 it
->descent
+= face
->box_line_width
;
20583 && XINT (height
) > it
->ascent
+ it
->descent
)
20584 it
->ascent
= XINT (height
) - it
->descent
;
20586 if (!NILP (total_height
))
20587 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
20590 spacing
= get_line_height_property(it
, Qline_spacing
);
20591 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
20593 if (INTEGERP (spacing
))
20595 extra_line_spacing
= XINT (spacing
);
20596 if (!NILP (total_height
))
20597 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
20601 else if (it
->char_to_display
== '\t')
20603 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
20604 int x
= it
->current_x
+ it
->continuation_lines_width
;
20605 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
20607 /* If the distance from the current position to the next tab
20608 stop is less than a space character width, use the
20609 tab stop after that. */
20610 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
20611 next_tab_x
+= tab_width
;
20613 it
->pixel_width
= next_tab_x
- x
;
20615 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
20616 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20620 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20621 it
->ascent
+ it
->descent
, it
->ascent
);
20626 /* A multi-byte character. Assume that the display width of the
20627 character is the width of the character multiplied by the
20628 width of the font. */
20630 /* If we found a font, this font should give us the right
20631 metrics. If we didn't find a font, use the frame's
20632 default font and calculate the width of the character
20633 from the charset width; this is what old redisplay code
20636 pcm
= rif
->per_char_metric (font
, &char2b
,
20637 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
20639 if (font_not_found_p
|| !pcm
)
20641 int charset
= CHAR_CHARSET (it
->char_to_display
);
20643 it
->glyph_not_available_p
= 1;
20644 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
20645 * CHARSET_WIDTH (charset
));
20646 it
->phys_ascent
= FONT_BASE (font
) + boff
;
20647 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20651 it
->pixel_width
= pcm
->width
;
20652 it
->phys_ascent
= pcm
->ascent
+ boff
;
20653 it
->phys_descent
= pcm
->descent
- boff
;
20655 && (pcm
->lbearing
< 0
20656 || pcm
->rbearing
> pcm
->width
))
20657 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20660 it
->ascent
= FONT_BASE (font
) + boff
;
20661 it
->descent
= FONT_DESCENT (font
) - boff
;
20662 if (face
->box
!= FACE_NO_BOX
)
20664 int thick
= face
->box_line_width
;
20668 it
->ascent
+= thick
;
20669 it
->descent
+= thick
;
20674 if (it
->start_of_box_run_p
)
20675 it
->pixel_width
+= thick
;
20676 if (it
->end_of_box_run_p
)
20677 it
->pixel_width
+= thick
;
20680 /* If face has an overline, add the height of the overline
20681 (1 pixel) and a 1 pixel margin to the character height. */
20682 if (face
->overline_p
)
20683 it
->ascent
+= overline_margin
;
20685 take_vertical_position_into_account (it
);
20690 it
->multibyte_p
= saved_multibyte_p
;
20692 else if (it
->what
== IT_COMPOSITION
)
20694 /* Note: A composition is represented as one glyph in the
20695 glyph matrix. There are no padding glyphs. */
20698 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20700 int font_not_found_p
;
20701 struct font_info
*font_info
;
20702 int boff
; /* baseline offset */
20703 struct composition
*cmp
= composition_table
[it
->cmp_id
];
20705 /* Maybe translate single-byte characters to multibyte. */
20706 it
->char_to_display
= it
->c
;
20707 if (unibyte_display_via_language_environment
20708 && SINGLE_BYTE_CHAR_P (it
->c
)
20711 && !NILP (Vnonascii_translation_table
))))
20713 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20716 /* Get face and font to use. Encode IT->char_to_display. */
20717 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20718 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20719 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20720 &char2b
, it
->multibyte_p
, 0);
20723 /* When no suitable font found, use the default font. */
20724 font_not_found_p
= font
== NULL
;
20725 if (font_not_found_p
)
20727 font
= FRAME_FONT (it
->f
);
20728 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20733 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20734 boff
= font_info
->baseline_offset
;
20735 if (font_info
->vertical_centering
)
20736 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20739 /* There are no padding glyphs, so there is only one glyph to
20740 produce for the composition. Important is that pixel_width,
20741 ascent and descent are the values of what is drawn by
20742 draw_glyphs (i.e. the values of the overall glyphs composed). */
20745 /* If we have not yet calculated pixel size data of glyphs of
20746 the composition for the current face font, calculate them
20747 now. Theoretically, we have to check all fonts for the
20748 glyphs, but that requires much time and memory space. So,
20749 here we check only the font of the first glyph. This leads
20750 to incorrect display very rarely, and C-l (recenter) can
20751 correct the display anyway. */
20752 if (cmp
->font
!= (void *) font
)
20754 /* Ascent and descent of the font of the first character of
20755 this composition (adjusted by baseline offset). Ascent
20756 and descent of overall glyphs should not be less than
20757 them respectively. */
20758 int font_ascent
= FONT_BASE (font
) + boff
;
20759 int font_descent
= FONT_DESCENT (font
) - boff
;
20760 /* Bounding box of the overall glyphs. */
20761 int leftmost
, rightmost
, lowest
, highest
;
20762 int i
, width
, ascent
, descent
;
20764 cmp
->font
= (void *) font
;
20766 /* Initialize the bounding box. */
20768 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20769 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
20771 width
= pcm
->width
;
20772 ascent
= pcm
->ascent
;
20773 descent
= pcm
->descent
;
20777 width
= FONT_WIDTH (font
);
20778 ascent
= FONT_BASE (font
);
20779 descent
= FONT_DESCENT (font
);
20783 lowest
= - descent
+ boff
;
20784 highest
= ascent
+ boff
;
20788 && font_info
->default_ascent
20789 && CHAR_TABLE_P (Vuse_default_ascent
)
20790 && !NILP (Faref (Vuse_default_ascent
,
20791 make_number (it
->char_to_display
))))
20792 highest
= font_info
->default_ascent
+ boff
;
20794 /* Draw the first glyph at the normal position. It may be
20795 shifted to right later if some other glyphs are drawn at
20797 cmp
->offsets
[0] = 0;
20798 cmp
->offsets
[1] = boff
;
20800 /* Set cmp->offsets for the remaining glyphs. */
20801 for (i
= 1; i
< cmp
->glyph_len
; i
++)
20803 int left
, right
, btm
, top
;
20804 int ch
= COMPOSITION_GLYPH (cmp
, i
);
20805 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
20807 face
= FACE_FROM_ID (it
->f
, face_id
);
20808 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
20809 &char2b
, it
->multibyte_p
, 0);
20813 font
= FRAME_FONT (it
->f
);
20814 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20820 = 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
;
20827 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20828 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
20830 width
= pcm
->width
;
20831 ascent
= pcm
->ascent
;
20832 descent
= pcm
->descent
;
20836 width
= FONT_WIDTH (font
);
20841 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
20843 /* Relative composition with or without
20844 alternate chars. */
20845 left
= (leftmost
+ rightmost
- width
) / 2;
20846 btm
= - descent
+ boff
;
20847 if (font_info
&& font_info
->relative_compose
20848 && (! CHAR_TABLE_P (Vignore_relative_composition
)
20849 || NILP (Faref (Vignore_relative_composition
,
20850 make_number (ch
)))))
20853 if (- descent
>= font_info
->relative_compose
)
20854 /* One extra pixel between two glyphs. */
20856 else if (ascent
<= 0)
20857 /* One extra pixel between two glyphs. */
20858 btm
= lowest
- 1 - ascent
- descent
;
20863 /* A composition rule is specified by an integer
20864 value that encodes global and new reference
20865 points (GREF and NREF). GREF and NREF are
20866 specified by numbers as below:
20868 0---1---2 -- ascent
20872 9--10--11 -- center
20874 ---3---4---5--- baseline
20876 6---7---8 -- descent
20878 int rule
= COMPOSITION_RULE (cmp
, i
);
20879 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
20881 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
20882 grefx
= gref
% 3, nrefx
= nref
% 3;
20883 grefy
= gref
/ 3, nrefy
= nref
/ 3;
20886 + grefx
* (rightmost
- leftmost
) / 2
20887 - nrefx
* width
/ 2);
20888 btm
= ((grefy
== 0 ? highest
20890 : grefy
== 2 ? lowest
20891 : (highest
+ lowest
) / 2)
20892 - (nrefy
== 0 ? ascent
+ descent
20893 : nrefy
== 1 ? descent
- boff
20895 : (ascent
+ descent
) / 2));
20898 cmp
->offsets
[i
* 2] = left
;
20899 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
20901 /* Update the bounding box of the overall glyphs. */
20902 right
= left
+ width
;
20903 top
= btm
+ descent
+ ascent
;
20904 if (left
< leftmost
)
20906 if (right
> rightmost
)
20914 /* If there are glyphs whose x-offsets are negative,
20915 shift all glyphs to the right and make all x-offsets
20919 for (i
= 0; i
< cmp
->glyph_len
; i
++)
20920 cmp
->offsets
[i
* 2] -= leftmost
;
20921 rightmost
-= leftmost
;
20924 cmp
->pixel_width
= rightmost
;
20925 cmp
->ascent
= highest
;
20926 cmp
->descent
= - lowest
;
20927 if (cmp
->ascent
< font_ascent
)
20928 cmp
->ascent
= font_ascent
;
20929 if (cmp
->descent
< font_descent
)
20930 cmp
->descent
= font_descent
;
20933 it
->pixel_width
= cmp
->pixel_width
;
20934 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
20935 it
->descent
= it
->phys_descent
= cmp
->descent
;
20937 if (face
->box
!= FACE_NO_BOX
)
20939 int thick
= face
->box_line_width
;
20943 it
->ascent
+= thick
;
20944 it
->descent
+= thick
;
20949 if (it
->start_of_box_run_p
)
20950 it
->pixel_width
+= thick
;
20951 if (it
->end_of_box_run_p
)
20952 it
->pixel_width
+= thick
;
20955 /* If face has an overline, add the height of the overline
20956 (1 pixel) and a 1 pixel margin to the character height. */
20957 if (face
->overline_p
)
20958 it
->ascent
+= overline_margin
;
20960 take_vertical_position_into_account (it
);
20963 append_composite_glyph (it
);
20965 else if (it
->what
== IT_IMAGE
)
20966 produce_image_glyph (it
);
20967 else if (it
->what
== IT_STRETCH
)
20968 produce_stretch_glyph (it
);
20970 /* Accumulate dimensions. Note: can't assume that it->descent > 0
20971 because this isn't true for images with `:ascent 100'. */
20972 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
20973 if (it
->area
== TEXT_AREA
)
20974 it
->current_x
+= it
->pixel_width
;
20976 if (extra_line_spacing
> 0)
20978 it
->descent
+= extra_line_spacing
;
20979 if (extra_line_spacing
> it
->max_extra_line_spacing
)
20980 it
->max_extra_line_spacing
= extra_line_spacing
;
20983 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
20984 it
->max_descent
= max (it
->max_descent
, it
->descent
);
20985 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
20986 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
20990 Output LEN glyphs starting at START at the nominal cursor position.
20991 Advance the nominal cursor over the text. The global variable
20992 updated_window contains the window being updated, updated_row is
20993 the glyph row being updated, and updated_area is the area of that
20994 row being updated. */
20997 x_write_glyphs (start
, len
)
20998 struct glyph
*start
;
21003 xassert (updated_window
&& updated_row
);
21006 /* Write glyphs. */
21008 hpos
= start
- updated_row
->glyphs
[updated_area
];
21009 x
= draw_glyphs (updated_window
, output_cursor
.x
,
21010 updated_row
, updated_area
,
21012 DRAW_NORMAL_TEXT
, 0);
21014 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
21015 if (updated_area
== TEXT_AREA
21016 && updated_window
->phys_cursor_on_p
21017 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
21018 && updated_window
->phys_cursor
.hpos
>= hpos
21019 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
21020 updated_window
->phys_cursor_on_p
= 0;
21024 /* Advance the output cursor. */
21025 output_cursor
.hpos
+= len
;
21026 output_cursor
.x
= x
;
21031 Insert LEN glyphs from START at the nominal cursor position. */
21034 x_insert_glyphs (start
, len
)
21035 struct glyph
*start
;
21040 int line_height
, shift_by_width
, shifted_region_width
;
21041 struct glyph_row
*row
;
21042 struct glyph
*glyph
;
21043 int frame_x
, frame_y
, hpos
;
21045 xassert (updated_window
&& updated_row
);
21047 w
= updated_window
;
21048 f
= XFRAME (WINDOW_FRAME (w
));
21050 /* Get the height of the line we are in. */
21052 line_height
= row
->height
;
21054 /* Get the width of the glyphs to insert. */
21055 shift_by_width
= 0;
21056 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
21057 shift_by_width
+= glyph
->pixel_width
;
21059 /* Get the width of the region to shift right. */
21060 shifted_region_width
= (window_box_width (w
, updated_area
)
21065 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
21066 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
21068 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
21069 line_height
, shift_by_width
);
21071 /* Write the glyphs. */
21072 hpos
= start
- row
->glyphs
[updated_area
];
21073 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
21075 DRAW_NORMAL_TEXT
, 0);
21077 /* Advance the output cursor. */
21078 output_cursor
.hpos
+= len
;
21079 output_cursor
.x
+= shift_by_width
;
21085 Erase the current text line from the nominal cursor position
21086 (inclusive) to pixel column TO_X (exclusive). The idea is that
21087 everything from TO_X onward is already erased.
21089 TO_X is a pixel position relative to updated_area of
21090 updated_window. TO_X == -1 means clear to the end of this area. */
21093 x_clear_end_of_line (to_x
)
21097 struct window
*w
= updated_window
;
21098 int max_x
, min_y
, max_y
;
21099 int from_x
, from_y
, to_y
;
21101 xassert (updated_window
&& updated_row
);
21102 f
= XFRAME (w
->frame
);
21104 if (updated_row
->full_width_p
)
21105 max_x
= WINDOW_TOTAL_WIDTH (w
);
21107 max_x
= window_box_width (w
, updated_area
);
21108 max_y
= window_text_bottom_y (w
);
21110 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
21111 of window. For TO_X > 0, truncate to end of drawing area. */
21117 to_x
= min (to_x
, max_x
);
21119 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
21121 /* Notice if the cursor will be cleared by this operation. */
21122 if (!updated_row
->full_width_p
)
21123 notice_overwritten_cursor (w
, updated_area
,
21124 output_cursor
.x
, -1,
21126 MATRIX_ROW_BOTTOM_Y (updated_row
));
21128 from_x
= output_cursor
.x
;
21130 /* Translate to frame coordinates. */
21131 if (updated_row
->full_width_p
)
21133 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
21134 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
21138 int area_left
= window_box_left (w
, updated_area
);
21139 from_x
+= area_left
;
21143 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
21144 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
21145 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
21147 /* Prevent inadvertently clearing to end of the X window. */
21148 if (to_x
> from_x
&& to_y
> from_y
)
21151 rif
->clear_frame_area (f
, from_x
, from_y
,
21152 to_x
- from_x
, to_y
- from_y
);
21157 #endif /* HAVE_WINDOW_SYSTEM */
21161 /***********************************************************************
21163 ***********************************************************************/
21165 /* Value is the internal representation of the specified cursor type
21166 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
21167 of the bar cursor. */
21169 static enum text_cursor_kinds
21170 get_specified_cursor_type (arg
, width
)
21174 enum text_cursor_kinds type
;
21179 if (EQ (arg
, Qbox
))
21180 return FILLED_BOX_CURSOR
;
21182 if (EQ (arg
, Qhollow
))
21183 return HOLLOW_BOX_CURSOR
;
21185 if (EQ (arg
, Qbar
))
21192 && EQ (XCAR (arg
), Qbar
)
21193 && INTEGERP (XCDR (arg
))
21194 && XINT (XCDR (arg
)) >= 0)
21196 *width
= XINT (XCDR (arg
));
21200 if (EQ (arg
, Qhbar
))
21203 return HBAR_CURSOR
;
21207 && EQ (XCAR (arg
), Qhbar
)
21208 && INTEGERP (XCDR (arg
))
21209 && XINT (XCDR (arg
)) >= 0)
21211 *width
= XINT (XCDR (arg
));
21212 return HBAR_CURSOR
;
21215 /* Treat anything unknown as "hollow box cursor".
21216 It was bad to signal an error; people have trouble fixing
21217 .Xdefaults with Emacs, when it has something bad in it. */
21218 type
= HOLLOW_BOX_CURSOR
;
21223 /* Set the default cursor types for specified frame. */
21225 set_frame_cursor_types (f
, arg
)
21232 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
21233 FRAME_CURSOR_WIDTH (f
) = width
;
21235 /* By default, set up the blink-off state depending on the on-state. */
21237 tem
= Fassoc (arg
, Vblink_cursor_alist
);
21240 FRAME_BLINK_OFF_CURSOR (f
)
21241 = get_specified_cursor_type (XCDR (tem
), &width
);
21242 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
21245 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
21249 /* Return the cursor we want to be displayed in window W. Return
21250 width of bar/hbar cursor through WIDTH arg. Return with
21251 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
21252 (i.e. if the `system caret' should track this cursor).
21254 In a mini-buffer window, we want the cursor only to appear if we
21255 are reading input from this window. For the selected window, we
21256 want the cursor type given by the frame parameter or buffer local
21257 setting of cursor-type. If explicitly marked off, draw no cursor.
21258 In all other cases, we want a hollow box cursor. */
21260 static enum text_cursor_kinds
21261 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
21263 struct glyph
*glyph
;
21265 int *active_cursor
;
21267 struct frame
*f
= XFRAME (w
->frame
);
21268 struct buffer
*b
= XBUFFER (w
->buffer
);
21269 int cursor_type
= DEFAULT_CURSOR
;
21270 Lisp_Object alt_cursor
;
21271 int non_selected
= 0;
21273 *active_cursor
= 1;
21276 if (cursor_in_echo_area
21277 && FRAME_HAS_MINIBUF_P (f
)
21278 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
21280 if (w
== XWINDOW (echo_area_window
))
21282 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
21284 *width
= FRAME_CURSOR_WIDTH (f
);
21285 return FRAME_DESIRED_CURSOR (f
);
21288 return get_specified_cursor_type (b
->cursor_type
, width
);
21291 *active_cursor
= 0;
21295 /* Nonselected window or nonselected frame. */
21296 else if (w
!= XWINDOW (f
->selected_window
)
21297 #ifdef HAVE_WINDOW_SYSTEM
21298 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
21302 *active_cursor
= 0;
21304 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
21310 /* Never display a cursor in a window in which cursor-type is nil. */
21311 if (NILP (b
->cursor_type
))
21314 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
21317 alt_cursor
= b
->cursor_in_non_selected_windows
;
21318 return get_specified_cursor_type (alt_cursor
, width
);
21321 /* Get the normal cursor type for this window. */
21322 if (EQ (b
->cursor_type
, Qt
))
21324 cursor_type
= FRAME_DESIRED_CURSOR (f
);
21325 *width
= FRAME_CURSOR_WIDTH (f
);
21328 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
21330 /* Use normal cursor if not blinked off. */
21331 if (!w
->cursor_off_p
)
21333 #ifdef HAVE_WINDOW_SYSTEM
21334 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21336 if (cursor_type
== FILLED_BOX_CURSOR
)
21338 /* Using a block cursor on large images can be very annoying.
21339 So use a hollow cursor for "large" images.
21340 If image is not transparent (no mask), also use hollow cursor. */
21341 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21342 if (img
!= NULL
&& IMAGEP (img
->spec
))
21344 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
21345 where N = size of default frame font size.
21346 This should cover most of the "tiny" icons people may use. */
21348 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
21349 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
21350 cursor_type
= HOLLOW_BOX_CURSOR
;
21353 else if (cursor_type
!= NO_CURSOR
)
21355 /* Display current only supports BOX and HOLLOW cursors for images.
21356 So for now, unconditionally use a HOLLOW cursor when cursor is
21357 not a solid box cursor. */
21358 cursor_type
= HOLLOW_BOX_CURSOR
;
21362 return cursor_type
;
21365 /* Cursor is blinked off, so determine how to "toggle" it. */
21367 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
21368 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
21369 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
21371 /* Then see if frame has specified a specific blink off cursor type. */
21372 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
21374 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
21375 return FRAME_BLINK_OFF_CURSOR (f
);
21379 /* Some people liked having a permanently visible blinking cursor,
21380 while others had very strong opinions against it. So it was
21381 decided to remove it. KFS 2003-09-03 */
21383 /* Finally perform built-in cursor blinking:
21384 filled box <-> hollow box
21385 wide [h]bar <-> narrow [h]bar
21386 narrow [h]bar <-> no cursor
21387 other type <-> no cursor */
21389 if (cursor_type
== FILLED_BOX_CURSOR
)
21390 return HOLLOW_BOX_CURSOR
;
21392 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
21395 return cursor_type
;
21403 #ifdef HAVE_WINDOW_SYSTEM
21405 /* Notice when the text cursor of window W has been completely
21406 overwritten by a drawing operation that outputs glyphs in AREA
21407 starting at X0 and ending at X1 in the line starting at Y0 and
21408 ending at Y1. X coordinates are area-relative. X1 < 0 means all
21409 the rest of the line after X0 has been written. Y coordinates
21410 are window-relative. */
21413 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
21415 enum glyph_row_area area
;
21416 int x0
, y0
, x1
, y1
;
21418 int cx0
, cx1
, cy0
, cy1
;
21419 struct glyph_row
*row
;
21421 if (!w
->phys_cursor_on_p
)
21423 if (area
!= TEXT_AREA
)
21426 if (w
->phys_cursor
.vpos
< 0
21427 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
21428 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
21429 !(row
->enabled_p
&& row
->displays_text_p
)))
21432 if (row
->cursor_in_fringe_p
)
21434 row
->cursor_in_fringe_p
= 0;
21435 draw_fringe_bitmap (w
, row
, 0);
21436 w
->phys_cursor_on_p
= 0;
21440 cx0
= w
->phys_cursor
.x
;
21441 cx1
= cx0
+ w
->phys_cursor_width
;
21442 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
21445 /* The cursor image will be completely removed from the
21446 screen if the output area intersects the cursor area in
21447 y-direction. When we draw in [y0 y1[, and some part of
21448 the cursor is at y < y0, that part must have been drawn
21449 before. When scrolling, the cursor is erased before
21450 actually scrolling, so we don't come here. When not
21451 scrolling, the rows above the old cursor row must have
21452 changed, and in this case these rows must have written
21453 over the cursor image.
21455 Likewise if part of the cursor is below y1, with the
21456 exception of the cursor being in the first blank row at
21457 the buffer and window end because update_text_area
21458 doesn't draw that row. (Except when it does, but
21459 that's handled in update_text_area.) */
21461 cy0
= w
->phys_cursor
.y
;
21462 cy1
= cy0
+ w
->phys_cursor_height
;
21463 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
21466 w
->phys_cursor_on_p
= 0;
21469 #endif /* HAVE_WINDOW_SYSTEM */
21472 /************************************************************************
21474 ************************************************************************/
21476 #ifdef HAVE_WINDOW_SYSTEM
21479 Fix the display of area AREA of overlapping row ROW in window W
21480 with respect to the overlapping part OVERLAPS. */
21483 x_fix_overlapping_area (w
, row
, area
, overlaps
)
21485 struct glyph_row
*row
;
21486 enum glyph_row_area area
;
21494 for (i
= 0; i
< row
->used
[area
];)
21496 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
21498 int start
= i
, start_x
= x
;
21502 x
+= row
->glyphs
[area
][i
].pixel_width
;
21505 while (i
< row
->used
[area
]
21506 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
21508 draw_glyphs (w
, start_x
, row
, area
,
21510 DRAW_NORMAL_TEXT
, overlaps
);
21514 x
+= row
->glyphs
[area
][i
].pixel_width
;
21524 Draw the cursor glyph of window W in glyph row ROW. See the
21525 comment of draw_glyphs for the meaning of HL. */
21528 draw_phys_cursor_glyph (w
, row
, hl
)
21530 struct glyph_row
*row
;
21531 enum draw_glyphs_face hl
;
21533 /* If cursor hpos is out of bounds, don't draw garbage. This can
21534 happen in mini-buffer windows when switching between echo area
21535 glyphs and mini-buffer. */
21536 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
21538 int on_p
= w
->phys_cursor_on_p
;
21540 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
21541 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
21543 w
->phys_cursor_on_p
= on_p
;
21545 if (hl
== DRAW_CURSOR
)
21546 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21547 /* When we erase the cursor, and ROW is overlapped by other
21548 rows, make sure that these overlapping parts of other rows
21550 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
21552 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21554 if (row
> w
->current_matrix
->rows
21555 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
21556 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
21557 OVERLAPS_ERASED_CURSOR
);
21559 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
21560 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
21561 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
21562 OVERLAPS_ERASED_CURSOR
);
21569 Erase the image of a cursor of window W from the screen. */
21572 erase_phys_cursor (w
)
21575 struct frame
*f
= XFRAME (w
->frame
);
21576 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21577 int hpos
= w
->phys_cursor
.hpos
;
21578 int vpos
= w
->phys_cursor
.vpos
;
21579 int mouse_face_here_p
= 0;
21580 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
21581 struct glyph_row
*cursor_row
;
21582 struct glyph
*cursor_glyph
;
21583 enum draw_glyphs_face hl
;
21585 /* No cursor displayed or row invalidated => nothing to do on the
21587 if (w
->phys_cursor_type
== NO_CURSOR
)
21588 goto mark_cursor_off
;
21590 /* VPOS >= active_glyphs->nrows means that window has been resized.
21591 Don't bother to erase the cursor. */
21592 if (vpos
>= active_glyphs
->nrows
)
21593 goto mark_cursor_off
;
21595 /* If row containing cursor is marked invalid, there is nothing we
21597 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
21598 if (!cursor_row
->enabled_p
)
21599 goto mark_cursor_off
;
21601 /* If line spacing is > 0, old cursor may only be partially visible in
21602 window after split-window. So adjust visible height. */
21603 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
21604 window_text_bottom_y (w
) - cursor_row
->y
);
21606 /* If row is completely invisible, don't attempt to delete a cursor which
21607 isn't there. This can happen if cursor is at top of a window, and
21608 we switch to a buffer with a header line in that window. */
21609 if (cursor_row
->visible_height
<= 0)
21610 goto mark_cursor_off
;
21612 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
21613 if (cursor_row
->cursor_in_fringe_p
)
21615 cursor_row
->cursor_in_fringe_p
= 0;
21616 draw_fringe_bitmap (w
, cursor_row
, 0);
21617 goto mark_cursor_off
;
21620 /* This can happen when the new row is shorter than the old one.
21621 In this case, either draw_glyphs or clear_end_of_line
21622 should have cleared the cursor. Note that we wouldn't be
21623 able to erase the cursor in this case because we don't have a
21624 cursor glyph at hand. */
21625 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
21626 goto mark_cursor_off
;
21628 /* If the cursor is in the mouse face area, redisplay that when
21629 we clear the cursor. */
21630 if (! NILP (dpyinfo
->mouse_face_window
)
21631 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
21632 && (vpos
> dpyinfo
->mouse_face_beg_row
21633 || (vpos
== dpyinfo
->mouse_face_beg_row
21634 && hpos
>= dpyinfo
->mouse_face_beg_col
))
21635 && (vpos
< dpyinfo
->mouse_face_end_row
21636 || (vpos
== dpyinfo
->mouse_face_end_row
21637 && hpos
< dpyinfo
->mouse_face_end_col
))
21638 /* Don't redraw the cursor's spot in mouse face if it is at the
21639 end of a line (on a newline). The cursor appears there, but
21640 mouse highlighting does not. */
21641 && cursor_row
->used
[TEXT_AREA
] > hpos
)
21642 mouse_face_here_p
= 1;
21644 /* Maybe clear the display under the cursor. */
21645 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
21648 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
21651 cursor_glyph
= get_phys_cursor_glyph (w
);
21652 if (cursor_glyph
== NULL
)
21653 goto mark_cursor_off
;
21655 width
= cursor_glyph
->pixel_width
;
21656 left_x
= window_box_left_offset (w
, TEXT_AREA
);
21657 x
= w
->phys_cursor
.x
;
21659 width
-= left_x
- x
;
21660 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
21661 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
21662 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
21665 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
21668 /* Erase the cursor by redrawing the character underneath it. */
21669 if (mouse_face_here_p
)
21670 hl
= DRAW_MOUSE_FACE
;
21672 hl
= DRAW_NORMAL_TEXT
;
21673 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
21676 w
->phys_cursor_on_p
= 0;
21677 w
->phys_cursor_type
= NO_CURSOR
;
21682 Display or clear cursor of window W. If ON is zero, clear the
21683 cursor. If it is non-zero, display the cursor. If ON is nonzero,
21684 where to put the cursor is specified by HPOS, VPOS, X and Y. */
21687 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
21689 int on
, hpos
, vpos
, x
, y
;
21691 struct frame
*f
= XFRAME (w
->frame
);
21692 int new_cursor_type
;
21693 int new_cursor_width
;
21695 struct glyph_row
*glyph_row
;
21696 struct glyph
*glyph
;
21698 /* This is pointless on invisible frames, and dangerous on garbaged
21699 windows and frames; in the latter case, the frame or window may
21700 be in the midst of changing its size, and x and y may be off the
21702 if (! FRAME_VISIBLE_P (f
)
21703 || FRAME_GARBAGED_P (f
)
21704 || vpos
>= w
->current_matrix
->nrows
21705 || hpos
>= w
->current_matrix
->matrix_w
)
21708 /* If cursor is off and we want it off, return quickly. */
21709 if (!on
&& !w
->phys_cursor_on_p
)
21712 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
21713 /* If cursor row is not enabled, we don't really know where to
21714 display the cursor. */
21715 if (!glyph_row
->enabled_p
)
21717 w
->phys_cursor_on_p
= 0;
21722 if (!glyph_row
->exact_window_width_line_p
21723 || hpos
< glyph_row
->used
[TEXT_AREA
])
21724 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
21726 xassert (interrupt_input_blocked
);
21728 /* Set new_cursor_type to the cursor we want to be displayed. */
21729 new_cursor_type
= get_window_cursor_type (w
, glyph
,
21730 &new_cursor_width
, &active_cursor
);
21732 /* If cursor is currently being shown and we don't want it to be or
21733 it is in the wrong place, or the cursor type is not what we want,
21735 if (w
->phys_cursor_on_p
21737 || w
->phys_cursor
.x
!= x
21738 || w
->phys_cursor
.y
!= y
21739 || new_cursor_type
!= w
->phys_cursor_type
21740 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
21741 && new_cursor_width
!= w
->phys_cursor_width
)))
21742 erase_phys_cursor (w
);
21744 /* Don't check phys_cursor_on_p here because that flag is only set
21745 to zero in some cases where we know that the cursor has been
21746 completely erased, to avoid the extra work of erasing the cursor
21747 twice. In other words, phys_cursor_on_p can be 1 and the cursor
21748 still not be visible, or it has only been partly erased. */
21751 w
->phys_cursor_ascent
= glyph_row
->ascent
;
21752 w
->phys_cursor_height
= glyph_row
->height
;
21754 /* Set phys_cursor_.* before x_draw_.* is called because some
21755 of them may need the information. */
21756 w
->phys_cursor
.x
= x
;
21757 w
->phys_cursor
.y
= glyph_row
->y
;
21758 w
->phys_cursor
.hpos
= hpos
;
21759 w
->phys_cursor
.vpos
= vpos
;
21762 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
21763 new_cursor_type
, new_cursor_width
,
21764 on
, active_cursor
);
21768 /* Switch the display of W's cursor on or off, according to the value
21772 update_window_cursor (w
, on
)
21776 /* Don't update cursor in windows whose frame is in the process
21777 of being deleted. */
21778 if (w
->current_matrix
)
21781 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21782 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21788 /* Call update_window_cursor with parameter ON_P on all leaf windows
21789 in the window tree rooted at W. */
21792 update_cursor_in_window_tree (w
, on_p
)
21798 if (!NILP (w
->hchild
))
21799 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
21800 else if (!NILP (w
->vchild
))
21801 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
21803 update_window_cursor (w
, on_p
);
21805 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
21811 Display the cursor on window W, or clear it, according to ON_P.
21812 Don't change the cursor's position. */
21815 x_update_cursor (f
, on_p
)
21819 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
21824 Clear the cursor of window W to background color, and mark the
21825 cursor as not shown. This is used when the text where the cursor
21826 is is about to be rewritten. */
21832 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
21833 update_window_cursor (w
, 0);
21838 Display the active region described by mouse_face_* according to DRAW. */
21841 show_mouse_face (dpyinfo
, draw
)
21842 Display_Info
*dpyinfo
;
21843 enum draw_glyphs_face draw
;
21845 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
21846 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21848 if (/* If window is in the process of being destroyed, don't bother
21850 w
->current_matrix
!= NULL
21851 /* Don't update mouse highlight if hidden */
21852 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
21853 /* Recognize when we are called to operate on rows that don't exist
21854 anymore. This can happen when a window is split. */
21855 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
21857 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
21858 struct glyph_row
*row
, *first
, *last
;
21860 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
21861 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
21863 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
21865 int start_hpos
, end_hpos
, start_x
;
21867 /* For all but the first row, the highlight starts at column 0. */
21870 start_hpos
= dpyinfo
->mouse_face_beg_col
;
21871 start_x
= dpyinfo
->mouse_face_beg_x
;
21880 end_hpos
= dpyinfo
->mouse_face_end_col
;
21883 end_hpos
= row
->used
[TEXT_AREA
];
21884 if (draw
== DRAW_NORMAL_TEXT
)
21885 row
->fill_line_p
= 1; /* Clear to end of line */
21888 if (end_hpos
> start_hpos
)
21890 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
21891 start_hpos
, end_hpos
,
21895 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
21899 /* When we've written over the cursor, arrange for it to
21900 be displayed again. */
21901 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
21904 display_and_set_cursor (w
, 1,
21905 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21906 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21911 /* Change the mouse cursor. */
21912 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
21913 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
21914 else if (draw
== DRAW_MOUSE_FACE
)
21915 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
21917 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
21921 Clear out the mouse-highlighted active region.
21922 Redraw it un-highlighted first. Value is non-zero if mouse
21923 face was actually drawn unhighlighted. */
21926 clear_mouse_face (dpyinfo
)
21927 Display_Info
*dpyinfo
;
21931 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
21933 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
21937 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21938 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21939 dpyinfo
->mouse_face_window
= Qnil
;
21940 dpyinfo
->mouse_face_overlay
= Qnil
;
21946 Non-zero if physical cursor of window W is within mouse face. */
21949 cursor_in_mouse_face_p (w
)
21952 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21953 int in_mouse_face
= 0;
21955 if (WINDOWP (dpyinfo
->mouse_face_window
)
21956 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
21958 int hpos
= w
->phys_cursor
.hpos
;
21959 int vpos
= w
->phys_cursor
.vpos
;
21961 if (vpos
>= dpyinfo
->mouse_face_beg_row
21962 && vpos
<= dpyinfo
->mouse_face_end_row
21963 && (vpos
> dpyinfo
->mouse_face_beg_row
21964 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21965 && (vpos
< dpyinfo
->mouse_face_end_row
21966 || hpos
< dpyinfo
->mouse_face_end_col
21967 || dpyinfo
->mouse_face_past_end
))
21971 return in_mouse_face
;
21977 /* Find the glyph matrix position of buffer position CHARPOS in window
21978 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
21979 current glyphs must be up to date. If CHARPOS is above window
21980 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
21981 of last line in W. In the row containing CHARPOS, stop before glyphs
21982 having STOP as object. */
21984 #if 1 /* This is a version of fast_find_position that's more correct
21985 in the presence of hscrolling, for example. I didn't install
21986 it right away because the problem fixed is minor, it failed
21987 in 20.x as well, and I think it's too risky to install
21988 so near the release of 21.1. 2001-09-25 gerd. */
21991 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
21994 int *hpos
, *vpos
, *x
, *y
;
21997 struct glyph_row
*row
, *first
;
21998 struct glyph
*glyph
, *end
;
22001 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22002 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
22007 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
22011 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
22014 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22018 /* If whole rows or last part of a row came from a display overlay,
22019 row_containing_pos will skip over such rows because their end pos
22020 equals the start pos of the overlay or interval.
22022 Move back if we have a STOP object and previous row's
22023 end glyph came from STOP. */
22026 struct glyph_row
*prev
;
22027 while ((prev
= row
- 1, prev
>= first
)
22028 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
22029 && prev
->used
[TEXT_AREA
] > 0)
22031 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
22032 glyph
= beg
+ prev
->used
[TEXT_AREA
];
22033 while (--glyph
>= beg
22034 && INTEGERP (glyph
->object
));
22036 || !EQ (stop
, glyph
->object
))
22044 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22046 glyph
= row
->glyphs
[TEXT_AREA
];
22047 end
= glyph
+ row
->used
[TEXT_AREA
];
22049 /* Skip over glyphs not having an object at the start of the row.
22050 These are special glyphs like truncation marks on terminal
22052 if (row
->displays_text_p
)
22054 && INTEGERP (glyph
->object
)
22055 && !EQ (stop
, glyph
->object
)
22056 && glyph
->charpos
< 0)
22058 *x
+= glyph
->pixel_width
;
22063 && !INTEGERP (glyph
->object
)
22064 && !EQ (stop
, glyph
->object
)
22065 && (!BUFFERP (glyph
->object
)
22066 || glyph
->charpos
< charpos
))
22068 *x
+= glyph
->pixel_width
;
22072 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
22079 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
22082 int *hpos
, *vpos
, *x
, *y
;
22087 int maybe_next_line_p
= 0;
22088 int line_start_position
;
22089 int yb
= window_text_bottom_y (w
);
22090 struct glyph_row
*row
, *best_row
;
22091 int row_vpos
, best_row_vpos
;
22094 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22095 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22097 while (row
->y
< yb
)
22099 if (row
->used
[TEXT_AREA
])
22100 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
22102 line_start_position
= 0;
22104 if (line_start_position
> pos
)
22106 /* If the position sought is the end of the buffer,
22107 don't include the blank lines at the bottom of the window. */
22108 else if (line_start_position
== pos
22109 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
22111 maybe_next_line_p
= 1;
22114 else if (line_start_position
> 0)
22117 best_row_vpos
= row_vpos
;
22120 if (row
->y
+ row
->height
>= yb
)
22127 /* Find the right column within BEST_ROW. */
22129 current_x
= best_row
->x
;
22130 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
22132 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
22133 int charpos
= glyph
->charpos
;
22135 if (BUFFERP (glyph
->object
))
22137 if (charpos
== pos
)
22140 *vpos
= best_row_vpos
;
22145 else if (charpos
> pos
)
22148 else if (EQ (glyph
->object
, stop
))
22153 current_x
+= glyph
->pixel_width
;
22156 /* If we're looking for the end of the buffer,
22157 and we didn't find it in the line we scanned,
22158 use the start of the following line. */
22159 if (maybe_next_line_p
)
22164 current_x
= best_row
->x
;
22167 *vpos
= best_row_vpos
;
22168 *hpos
= lastcol
+ 1;
22177 /* Find the position of the glyph for position POS in OBJECT in
22178 window W's current matrix, and return in *X, *Y the pixel
22179 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
22181 RIGHT_P non-zero means return the position of the right edge of the
22182 glyph, RIGHT_P zero means return the left edge position.
22184 If no glyph for POS exists in the matrix, return the position of
22185 the glyph with the next smaller position that is in the matrix, if
22186 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
22187 exists in the matrix, return the position of the glyph with the
22188 next larger position in OBJECT.
22190 Value is non-zero if a glyph was found. */
22193 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
22196 Lisp_Object object
;
22197 int *hpos
, *vpos
, *x
, *y
;
22200 int yb
= window_text_bottom_y (w
);
22201 struct glyph_row
*r
;
22202 struct glyph
*best_glyph
= NULL
;
22203 struct glyph_row
*best_row
= NULL
;
22206 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22207 r
->enabled_p
&& r
->y
< yb
;
22210 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
22211 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
22214 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
22215 if (EQ (g
->object
, object
))
22217 if (g
->charpos
== pos
)
22224 else if (best_glyph
== NULL
22225 || ((abs (g
->charpos
- pos
)
22226 < abs (best_glyph
->charpos
- pos
))
22229 : g
->charpos
> pos
)))
22243 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
22247 *x
+= best_glyph
->pixel_width
;
22252 *vpos
= best_row
- w
->current_matrix
->rows
;
22255 return best_glyph
!= NULL
;
22259 /* See if position X, Y is within a hot-spot of an image. */
22262 on_hot_spot_p (hot_spot
, x
, y
)
22263 Lisp_Object hot_spot
;
22266 if (!CONSP (hot_spot
))
22269 if (EQ (XCAR (hot_spot
), Qrect
))
22271 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
22272 Lisp_Object rect
= XCDR (hot_spot
);
22276 if (!CONSP (XCAR (rect
)))
22278 if (!CONSP (XCDR (rect
)))
22280 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
22282 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
22284 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
22286 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
22290 else if (EQ (XCAR (hot_spot
), Qcircle
))
22292 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
22293 Lisp_Object circ
= XCDR (hot_spot
);
22294 Lisp_Object lr
, lx0
, ly0
;
22296 && CONSP (XCAR (circ
))
22297 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
22298 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
22299 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
22301 double r
= XFLOATINT (lr
);
22302 double dx
= XINT (lx0
) - x
;
22303 double dy
= XINT (ly0
) - y
;
22304 return (dx
* dx
+ dy
* dy
<= r
* r
);
22307 else if (EQ (XCAR (hot_spot
), Qpoly
))
22309 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
22310 if (VECTORP (XCDR (hot_spot
)))
22312 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
22313 Lisp_Object
*poly
= v
->contents
;
22317 Lisp_Object lx
, ly
;
22320 /* Need an even number of coordinates, and at least 3 edges. */
22321 if (n
< 6 || n
& 1)
22324 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
22325 If count is odd, we are inside polygon. Pixels on edges
22326 may or may not be included depending on actual geometry of the
22328 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
22329 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
22331 x0
= XINT (lx
), y0
= XINT (ly
);
22332 for (i
= 0; i
< n
; i
+= 2)
22334 int x1
= x0
, y1
= y0
;
22335 if ((lx
= poly
[i
], !INTEGERP (lx
))
22336 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
22338 x0
= XINT (lx
), y0
= XINT (ly
);
22340 /* Does this segment cross the X line? */
22348 if (y
> y0
&& y
> y1
)
22350 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
22356 /* If we don't understand the format, pretend we're not in the hot-spot. */
22361 find_hot_spot (map
, x
, y
)
22365 while (CONSP (map
))
22367 if (CONSP (XCAR (map
))
22368 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
22376 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
22378 doc
: /* Lookup in image map MAP coordinates X and Y.
22379 An image map is an alist where each element has the format (AREA ID PLIST).
22380 An AREA is specified as either a rectangle, a circle, or a polygon:
22381 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
22382 pixel coordinates of the upper left and bottom right corners.
22383 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
22384 and the radius of the circle; r may be a float or integer.
22385 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
22386 vector describes one corner in the polygon.
22387 Returns the alist element for the first matching AREA in MAP. */)
22398 return find_hot_spot (map
, XINT (x
), XINT (y
));
22402 /* Display frame CURSOR, optionally using shape defined by POINTER. */
22404 define_frame_cursor1 (f
, cursor
, pointer
)
22407 Lisp_Object pointer
;
22409 /* Do not change cursor shape while dragging mouse. */
22410 if (!NILP (do_mouse_tracking
))
22413 if (!NILP (pointer
))
22415 if (EQ (pointer
, Qarrow
))
22416 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22417 else if (EQ (pointer
, Qhand
))
22418 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
22419 else if (EQ (pointer
, Qtext
))
22420 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22421 else if (EQ (pointer
, intern ("hdrag")))
22422 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22423 #ifdef HAVE_X_WINDOWS
22424 else if (EQ (pointer
, intern ("vdrag")))
22425 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
22427 else if (EQ (pointer
, intern ("hourglass")))
22428 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
22429 else if (EQ (pointer
, Qmodeline
))
22430 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
22432 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22435 if (cursor
!= No_Cursor
)
22436 rif
->define_frame_cursor (f
, cursor
);
22439 /* Take proper action when mouse has moved to the mode or header line
22440 or marginal area AREA of window W, x-position X and y-position Y.
22441 X is relative to the start of the text display area of W, so the
22442 width of bitmap areas and scroll bars must be subtracted to get a
22443 position relative to the start of the mode line. */
22446 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
22447 Lisp_Object window
;
22449 enum window_part area
;
22451 struct window
*w
= XWINDOW (window
);
22452 struct frame
*f
= XFRAME (w
->frame
);
22453 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22454 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22455 Lisp_Object pointer
= Qnil
;
22456 int charpos
, dx
, dy
, width
, height
;
22457 Lisp_Object string
, object
= Qnil
;
22458 Lisp_Object pos
, help
;
22460 Lisp_Object mouse_face
;
22461 int original_x_pixel
= x
;
22462 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
22463 struct glyph_row
*row
;
22465 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
22470 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
22471 &object
, &dx
, &dy
, &width
, &height
);
22473 row
= (area
== ON_MODE_LINE
22474 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
22475 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
22478 if (row
->mode_line_p
&& row
->enabled_p
)
22480 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
22481 end
= glyph
+ row
->used
[TEXT_AREA
];
22483 for (x0
= original_x_pixel
;
22484 glyph
< end
&& x0
>= glyph
->pixel_width
;
22486 x0
-= glyph
->pixel_width
;
22494 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
22495 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
22496 &object
, &dx
, &dy
, &width
, &height
);
22501 if (IMAGEP (object
))
22503 Lisp_Object image_map
, hotspot
;
22504 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
22506 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
22508 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22510 Lisp_Object area_id
, plist
;
22512 area_id
= XCAR (hotspot
);
22513 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22514 If so, we could look for mouse-enter, mouse-leave
22515 properties in PLIST (and do something...). */
22516 hotspot
= XCDR (hotspot
);
22517 if (CONSP (hotspot
)
22518 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22520 pointer
= Fplist_get (plist
, Qpointer
);
22521 if (NILP (pointer
))
22523 help
= Fplist_get (plist
, Qhelp_echo
);
22526 help_echo_string
= help
;
22527 /* Is this correct? ++kfs */
22528 XSETWINDOW (help_echo_window
, w
);
22529 help_echo_object
= w
->buffer
;
22530 help_echo_pos
= charpos
;
22534 if (NILP (pointer
))
22535 pointer
= Fplist_get (XCDR (object
), QCpointer
);
22538 if (STRINGP (string
))
22540 pos
= make_number (charpos
);
22541 /* If we're on a string with `help-echo' text property, arrange
22542 for the help to be displayed. This is done by setting the
22543 global variable help_echo_string to the help string. */
22546 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
22549 help_echo_string
= help
;
22550 XSETWINDOW (help_echo_window
, w
);
22551 help_echo_object
= string
;
22552 help_echo_pos
= charpos
;
22556 if (NILP (pointer
))
22557 pointer
= Fget_text_property (pos
, Qpointer
, string
);
22559 /* Change the mouse pointer according to what is under X/Y. */
22560 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
22563 map
= Fget_text_property (pos
, Qlocal_map
, string
);
22564 if (!KEYMAPP (map
))
22565 map
= Fget_text_property (pos
, Qkeymap
, string
);
22566 if (!KEYMAPP (map
))
22567 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
22570 /* Change the mouse face according to what is under X/Y. */
22571 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
22572 if (!NILP (mouse_face
)
22573 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22578 struct glyph
* tmp_glyph
;
22582 int total_pixel_width
;
22587 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
22588 Qmouse_face
, string
, Qnil
);
22590 b
= make_number (0);
22592 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
22594 e
= make_number (SCHARS (string
));
22596 /* Calculate the position(glyph position: GPOS) of GLYPH in
22597 displayed string. GPOS is different from CHARPOS.
22599 CHARPOS is the position of glyph in internal string
22600 object. A mode line string format has structures which
22601 is converted to a flatten by emacs lisp interpreter.
22602 The internal string is an element of the structures.
22603 The displayed string is the flatten string. */
22605 if (glyph
> row_start_glyph
)
22607 tmp_glyph
= glyph
- 1;
22608 while (tmp_glyph
>= row_start_glyph
22609 && tmp_glyph
->charpos
>= XINT (b
)
22610 && EQ (tmp_glyph
->object
, glyph
->object
))
22617 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
22618 displayed string holding GLYPH.
22620 GSEQ_LENGTH is different from SCHARS (STRING).
22621 SCHARS (STRING) returns the length of the internal string. */
22622 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
22623 tmp_glyph
->charpos
< XINT (e
);
22624 tmp_glyph
++, gseq_length
++)
22626 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22630 total_pixel_width
= 0;
22631 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
22632 total_pixel_width
+= tmp_glyph
->pixel_width
;
22634 /* Pre calculation of re-rendering position */
22636 hpos
= (area
== ON_MODE_LINE
22637 ? (w
->current_matrix
)->nrows
- 1
22640 /* If the re-rendering position is included in the last
22641 re-rendering area, we should do nothing. */
22642 if ( EQ (window
, dpyinfo
->mouse_face_window
)
22643 && dpyinfo
->mouse_face_beg_col
<= vpos
22644 && vpos
< dpyinfo
->mouse_face_end_col
22645 && dpyinfo
->mouse_face_beg_row
== hpos
)
22648 if (clear_mouse_face (dpyinfo
))
22649 cursor
= No_Cursor
;
22651 dpyinfo
->mouse_face_beg_col
= vpos
;
22652 dpyinfo
->mouse_face_beg_row
= hpos
;
22654 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
22655 dpyinfo
->mouse_face_beg_y
= 0;
22657 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
22658 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
22660 dpyinfo
->mouse_face_end_x
= 0;
22661 dpyinfo
->mouse_face_end_y
= 0;
22663 dpyinfo
->mouse_face_past_end
= 0;
22664 dpyinfo
->mouse_face_window
= window
;
22666 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
22669 glyph
->face_id
, 1);
22670 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22672 if (NILP (pointer
))
22675 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22676 clear_mouse_face (dpyinfo
);
22678 define_frame_cursor1 (f
, cursor
, pointer
);
22683 Take proper action when the mouse has moved to position X, Y on
22684 frame F as regards highlighting characters that have mouse-face
22685 properties. Also de-highlighting chars where the mouse was before.
22686 X and Y can be negative or out of range. */
22689 note_mouse_highlight (f
, x
, y
)
22693 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22694 enum window_part part
;
22695 Lisp_Object window
;
22697 Cursor cursor
= No_Cursor
;
22698 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
22701 /* When a menu is active, don't highlight because this looks odd. */
22702 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (MAC_OS)
22703 if (popup_activated ())
22707 if (NILP (Vmouse_highlight
)
22708 || !f
->glyphs_initialized_p
)
22711 dpyinfo
->mouse_face_mouse_x
= x
;
22712 dpyinfo
->mouse_face_mouse_y
= y
;
22713 dpyinfo
->mouse_face_mouse_frame
= f
;
22715 if (dpyinfo
->mouse_face_defer
)
22718 if (gc_in_progress
)
22720 dpyinfo
->mouse_face_deferred_gc
= 1;
22724 /* Which window is that in? */
22725 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
22727 /* If we were displaying active text in another window, clear that.
22728 Also clear if we move out of text area in same window. */
22729 if (! EQ (window
, dpyinfo
->mouse_face_window
)
22730 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
22731 && !NILP (dpyinfo
->mouse_face_window
)))
22732 clear_mouse_face (dpyinfo
);
22734 /* Not on a window -> return. */
22735 if (!WINDOWP (window
))
22738 /* Reset help_echo_string. It will get recomputed below. */
22739 help_echo_string
= Qnil
;
22741 /* Convert to window-relative pixel coordinates. */
22742 w
= XWINDOW (window
);
22743 frame_to_window_pixel_xy (w
, &x
, &y
);
22745 /* Handle tool-bar window differently since it doesn't display a
22747 if (EQ (window
, f
->tool_bar_window
))
22749 note_tool_bar_highlight (f
, x
, y
);
22753 /* Mouse is on the mode, header line or margin? */
22754 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
22755 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
22757 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
22761 if (part
== ON_VERTICAL_BORDER
)
22763 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22764 help_echo_string
= build_string ("drag-mouse-1: resize");
22766 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
22767 || part
== ON_SCROLL_BAR
)
22768 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22770 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22772 /* Are we in a window whose display is up to date?
22773 And verify the buffer's text has not changed. */
22774 b
= XBUFFER (w
->buffer
);
22775 if (part
== ON_TEXT
22776 && EQ (w
->window_end_valid
, w
->buffer
)
22777 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
22778 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
22780 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
22781 struct glyph
*glyph
;
22782 Lisp_Object object
;
22783 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
22784 Lisp_Object
*overlay_vec
= NULL
;
22786 struct buffer
*obuf
;
22787 int obegv
, ozv
, same_region
;
22789 /* Find the glyph under X/Y. */
22790 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
22792 /* Look for :pointer property on image. */
22793 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22795 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22796 if (img
!= NULL
&& IMAGEP (img
->spec
))
22798 Lisp_Object image_map
, hotspot
;
22799 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
22801 && (hotspot
= find_hot_spot (image_map
,
22802 glyph
->slice
.x
+ dx
,
22803 glyph
->slice
.y
+ dy
),
22805 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22807 Lisp_Object area_id
, plist
;
22809 area_id
= XCAR (hotspot
);
22810 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22811 If so, we could look for mouse-enter, mouse-leave
22812 properties in PLIST (and do something...). */
22813 hotspot
= XCDR (hotspot
);
22814 if (CONSP (hotspot
)
22815 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22817 pointer
= Fplist_get (plist
, Qpointer
);
22818 if (NILP (pointer
))
22820 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
22821 if (!NILP (help_echo_string
))
22823 help_echo_window
= window
;
22824 help_echo_object
= glyph
->object
;
22825 help_echo_pos
= glyph
->charpos
;
22829 if (NILP (pointer
))
22830 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
22834 /* Clear mouse face if X/Y not over text. */
22836 || area
!= TEXT_AREA
22837 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
22839 if (clear_mouse_face (dpyinfo
))
22840 cursor
= No_Cursor
;
22841 if (NILP (pointer
))
22843 if (area
!= TEXT_AREA
)
22844 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22846 pointer
= Vvoid_text_area_pointer
;
22851 pos
= glyph
->charpos
;
22852 object
= glyph
->object
;
22853 if (!STRINGP (object
) && !BUFFERP (object
))
22856 /* If we get an out-of-range value, return now; avoid an error. */
22857 if (BUFFERP (object
) && pos
> BUF_Z (b
))
22860 /* Make the window's buffer temporarily current for
22861 overlays_at and compute_char_face. */
22862 obuf
= current_buffer
;
22863 current_buffer
= b
;
22869 /* Is this char mouse-active or does it have help-echo? */
22870 position
= make_number (pos
);
22872 if (BUFFERP (object
))
22874 /* Put all the overlays we want in a vector in overlay_vec. */
22875 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
22876 /* Sort overlays into increasing priority order. */
22877 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
22882 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
22883 && vpos
>= dpyinfo
->mouse_face_beg_row
22884 && vpos
<= dpyinfo
->mouse_face_end_row
22885 && (vpos
> dpyinfo
->mouse_face_beg_row
22886 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22887 && (vpos
< dpyinfo
->mouse_face_end_row
22888 || hpos
< dpyinfo
->mouse_face_end_col
22889 || dpyinfo
->mouse_face_past_end
));
22892 cursor
= No_Cursor
;
22894 /* Check mouse-face highlighting. */
22896 /* If there exists an overlay with mouse-face overlapping
22897 the one we are currently highlighting, we have to
22898 check if we enter the overlapping overlay, and then
22899 highlight only that. */
22900 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
22901 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
22903 /* Find the highest priority overlay that has a mouse-face
22906 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
22908 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
22909 if (!NILP (mouse_face
))
22910 overlay
= overlay_vec
[i
];
22913 /* If we're actually highlighting the same overlay as
22914 before, there's no need to do that again. */
22915 if (!NILP (overlay
)
22916 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
22917 goto check_help_echo
;
22919 dpyinfo
->mouse_face_overlay
= overlay
;
22921 /* Clear the display of the old active region, if any. */
22922 if (clear_mouse_face (dpyinfo
))
22923 cursor
= No_Cursor
;
22925 /* If no overlay applies, get a text property. */
22926 if (NILP (overlay
))
22927 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
22929 /* Handle the overlay case. */
22930 if (!NILP (overlay
))
22932 /* Find the range of text around this char that
22933 should be active. */
22934 Lisp_Object before
, after
;
22937 before
= Foverlay_start (overlay
);
22938 after
= Foverlay_end (overlay
);
22939 /* Record this as the current active region. */
22940 fast_find_position (w
, XFASTINT (before
),
22941 &dpyinfo
->mouse_face_beg_col
,
22942 &dpyinfo
->mouse_face_beg_row
,
22943 &dpyinfo
->mouse_face_beg_x
,
22944 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22946 dpyinfo
->mouse_face_past_end
22947 = !fast_find_position (w
, XFASTINT (after
),
22948 &dpyinfo
->mouse_face_end_col
,
22949 &dpyinfo
->mouse_face_end_row
,
22950 &dpyinfo
->mouse_face_end_x
,
22951 &dpyinfo
->mouse_face_end_y
, Qnil
);
22952 dpyinfo
->mouse_face_window
= window
;
22954 dpyinfo
->mouse_face_face_id
22955 = face_at_buffer_position (w
, pos
, 0, 0,
22957 !dpyinfo
->mouse_face_hidden
);
22959 /* Display it as active. */
22960 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22961 cursor
= No_Cursor
;
22963 /* Handle the text property case. */
22964 else if (!NILP (mouse_face
) && BUFFERP (object
))
22966 /* Find the range of text around this char that
22967 should be active. */
22968 Lisp_Object before
, after
, beginning
, end
;
22971 beginning
= Fmarker_position (w
->start
);
22972 end
= make_number (BUF_Z (XBUFFER (object
))
22973 - XFASTINT (w
->window_end_pos
));
22975 = Fprevious_single_property_change (make_number (pos
+ 1),
22977 object
, beginning
);
22979 = Fnext_single_property_change (position
, Qmouse_face
,
22982 /* Record this as the current active region. */
22983 fast_find_position (w
, XFASTINT (before
),
22984 &dpyinfo
->mouse_face_beg_col
,
22985 &dpyinfo
->mouse_face_beg_row
,
22986 &dpyinfo
->mouse_face_beg_x
,
22987 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22988 dpyinfo
->mouse_face_past_end
22989 = !fast_find_position (w
, XFASTINT (after
),
22990 &dpyinfo
->mouse_face_end_col
,
22991 &dpyinfo
->mouse_face_end_row
,
22992 &dpyinfo
->mouse_face_end_x
,
22993 &dpyinfo
->mouse_face_end_y
, Qnil
);
22994 dpyinfo
->mouse_face_window
= window
;
22996 if (BUFFERP (object
))
22997 dpyinfo
->mouse_face_face_id
22998 = face_at_buffer_position (w
, pos
, 0, 0,
23000 !dpyinfo
->mouse_face_hidden
);
23002 /* Display it as active. */
23003 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23004 cursor
= No_Cursor
;
23006 else if (!NILP (mouse_face
) && STRINGP (object
))
23011 b
= Fprevious_single_property_change (make_number (pos
+ 1),
23014 e
= Fnext_single_property_change (position
, Qmouse_face
,
23017 b
= make_number (0);
23019 e
= make_number (SCHARS (object
) - 1);
23021 fast_find_string_pos (w
, XINT (b
), object
,
23022 &dpyinfo
->mouse_face_beg_col
,
23023 &dpyinfo
->mouse_face_beg_row
,
23024 &dpyinfo
->mouse_face_beg_x
,
23025 &dpyinfo
->mouse_face_beg_y
, 0);
23026 fast_find_string_pos (w
, XINT (e
), object
,
23027 &dpyinfo
->mouse_face_end_col
,
23028 &dpyinfo
->mouse_face_end_row
,
23029 &dpyinfo
->mouse_face_end_x
,
23030 &dpyinfo
->mouse_face_end_y
, 1);
23031 dpyinfo
->mouse_face_past_end
= 0;
23032 dpyinfo
->mouse_face_window
= window
;
23033 dpyinfo
->mouse_face_face_id
23034 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
23035 glyph
->face_id
, 1);
23036 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23037 cursor
= No_Cursor
;
23039 else if (STRINGP (object
) && NILP (mouse_face
))
23041 /* A string which doesn't have mouse-face, but
23042 the text ``under'' it might have. */
23043 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
23044 int start
= MATRIX_ROW_START_CHARPOS (r
);
23046 pos
= string_buffer_position (w
, object
, start
);
23048 mouse_face
= get_char_property_and_overlay (make_number (pos
),
23052 if (!NILP (mouse_face
) && !NILP (overlay
))
23054 Lisp_Object before
= Foverlay_start (overlay
);
23055 Lisp_Object after
= Foverlay_end (overlay
);
23058 /* Note that we might not be able to find position
23059 BEFORE in the glyph matrix if the overlay is
23060 entirely covered by a `display' property. In
23061 this case, we overshoot. So let's stop in
23062 the glyph matrix before glyphs for OBJECT. */
23063 fast_find_position (w
, XFASTINT (before
),
23064 &dpyinfo
->mouse_face_beg_col
,
23065 &dpyinfo
->mouse_face_beg_row
,
23066 &dpyinfo
->mouse_face_beg_x
,
23067 &dpyinfo
->mouse_face_beg_y
,
23070 dpyinfo
->mouse_face_past_end
23071 = !fast_find_position (w
, XFASTINT (after
),
23072 &dpyinfo
->mouse_face_end_col
,
23073 &dpyinfo
->mouse_face_end_row
,
23074 &dpyinfo
->mouse_face_end_x
,
23075 &dpyinfo
->mouse_face_end_y
,
23077 dpyinfo
->mouse_face_window
= window
;
23078 dpyinfo
->mouse_face_face_id
23079 = face_at_buffer_position (w
, pos
, 0, 0,
23081 !dpyinfo
->mouse_face_hidden
);
23083 /* Display it as active. */
23084 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23085 cursor
= No_Cursor
;
23092 /* Look for a `help-echo' property. */
23093 if (NILP (help_echo_string
)) {
23094 Lisp_Object help
, overlay
;
23096 /* Check overlays first. */
23097 help
= overlay
= Qnil
;
23098 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
23100 overlay
= overlay_vec
[i
];
23101 help
= Foverlay_get (overlay
, Qhelp_echo
);
23106 help_echo_string
= help
;
23107 help_echo_window
= window
;
23108 help_echo_object
= overlay
;
23109 help_echo_pos
= pos
;
23113 Lisp_Object object
= glyph
->object
;
23114 int charpos
= glyph
->charpos
;
23116 /* Try text properties. */
23117 if (STRINGP (object
)
23119 && charpos
< SCHARS (object
))
23121 help
= Fget_text_property (make_number (charpos
),
23122 Qhelp_echo
, object
);
23125 /* If the string itself doesn't specify a help-echo,
23126 see if the buffer text ``under'' it does. */
23127 struct glyph_row
*r
23128 = MATRIX_ROW (w
->current_matrix
, vpos
);
23129 int start
= MATRIX_ROW_START_CHARPOS (r
);
23130 int pos
= string_buffer_position (w
, object
, start
);
23133 help
= Fget_char_property (make_number (pos
),
23134 Qhelp_echo
, w
->buffer
);
23138 object
= w
->buffer
;
23143 else if (BUFFERP (object
)
23146 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
23151 help_echo_string
= help
;
23152 help_echo_window
= window
;
23153 help_echo_object
= object
;
23154 help_echo_pos
= charpos
;
23159 /* Look for a `pointer' property. */
23160 if (NILP (pointer
))
23162 /* Check overlays first. */
23163 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
23164 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
23166 if (NILP (pointer
))
23168 Lisp_Object object
= glyph
->object
;
23169 int charpos
= glyph
->charpos
;
23171 /* Try text properties. */
23172 if (STRINGP (object
)
23174 && charpos
< SCHARS (object
))
23176 pointer
= Fget_text_property (make_number (charpos
),
23178 if (NILP (pointer
))
23180 /* If the string itself doesn't specify a pointer,
23181 see if the buffer text ``under'' it does. */
23182 struct glyph_row
*r
23183 = MATRIX_ROW (w
->current_matrix
, vpos
);
23184 int start
= MATRIX_ROW_START_CHARPOS (r
);
23185 int pos
= string_buffer_position (w
, object
, start
);
23187 pointer
= Fget_char_property (make_number (pos
),
23188 Qpointer
, w
->buffer
);
23191 else if (BUFFERP (object
)
23194 pointer
= Fget_text_property (make_number (charpos
),
23201 current_buffer
= obuf
;
23206 define_frame_cursor1 (f
, cursor
, pointer
);
23211 Clear any mouse-face on window W. This function is part of the
23212 redisplay interface, and is called from try_window_id and similar
23213 functions to ensure the mouse-highlight is off. */
23216 x_clear_window_mouse_face (w
)
23219 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23220 Lisp_Object window
;
23223 XSETWINDOW (window
, w
);
23224 if (EQ (window
, dpyinfo
->mouse_face_window
))
23225 clear_mouse_face (dpyinfo
);
23231 Just discard the mouse face information for frame F, if any.
23232 This is used when the size of F is changed. */
23235 cancel_mouse_face (f
)
23238 Lisp_Object window
;
23239 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23241 window
= dpyinfo
->mouse_face_window
;
23242 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
23244 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
23245 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
23246 dpyinfo
->mouse_face_window
= Qnil
;
23251 #endif /* HAVE_WINDOW_SYSTEM */
23254 /***********************************************************************
23256 ***********************************************************************/
23258 #ifdef HAVE_WINDOW_SYSTEM
23260 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
23261 which intersects rectangle R. R is in window-relative coordinates. */
23264 expose_area (w
, row
, r
, area
)
23266 struct glyph_row
*row
;
23268 enum glyph_row_area area
;
23270 struct glyph
*first
= row
->glyphs
[area
];
23271 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
23272 struct glyph
*last
;
23273 int first_x
, start_x
, x
;
23275 if (area
== TEXT_AREA
&& row
->fill_line_p
)
23276 /* If row extends face to end of line write the whole line. */
23277 draw_glyphs (w
, 0, row
, area
,
23278 0, row
->used
[area
],
23279 DRAW_NORMAL_TEXT
, 0);
23282 /* Set START_X to the window-relative start position for drawing glyphs of
23283 AREA. The first glyph of the text area can be partially visible.
23284 The first glyphs of other areas cannot. */
23285 start_x
= window_box_left_offset (w
, area
);
23287 if (area
== TEXT_AREA
)
23290 /* Find the first glyph that must be redrawn. */
23292 && x
+ first
->pixel_width
< r
->x
)
23294 x
+= first
->pixel_width
;
23298 /* Find the last one. */
23302 && x
< r
->x
+ r
->width
)
23304 x
+= last
->pixel_width
;
23310 draw_glyphs (w
, first_x
- start_x
, row
, area
,
23311 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
23312 DRAW_NORMAL_TEXT
, 0);
23317 /* Redraw the parts of the glyph row ROW on window W intersecting
23318 rectangle R. R is in window-relative coordinates. Value is
23319 non-zero if mouse-face was overwritten. */
23322 expose_line (w
, row
, r
)
23324 struct glyph_row
*row
;
23327 xassert (row
->enabled_p
);
23329 if (row
->mode_line_p
|| w
->pseudo_window_p
)
23330 draw_glyphs (w
, 0, row
, TEXT_AREA
,
23331 0, row
->used
[TEXT_AREA
],
23332 DRAW_NORMAL_TEXT
, 0);
23335 if (row
->used
[LEFT_MARGIN_AREA
])
23336 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
23337 if (row
->used
[TEXT_AREA
])
23338 expose_area (w
, row
, r
, TEXT_AREA
);
23339 if (row
->used
[RIGHT_MARGIN_AREA
])
23340 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
23341 draw_row_fringe_bitmaps (w
, row
);
23344 return row
->mouse_face_p
;
23348 /* Redraw those parts of glyphs rows during expose event handling that
23349 overlap other rows. Redrawing of an exposed line writes over parts
23350 of lines overlapping that exposed line; this function fixes that.
23352 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
23353 row in W's current matrix that is exposed and overlaps other rows.
23354 LAST_OVERLAPPING_ROW is the last such row. */
23357 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
23359 struct glyph_row
*first_overlapping_row
;
23360 struct glyph_row
*last_overlapping_row
;
23362 struct glyph_row
*row
;
23364 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
23365 if (row
->overlapping_p
)
23367 xassert (row
->enabled_p
&& !row
->mode_line_p
);
23369 if (row
->used
[LEFT_MARGIN_AREA
])
23370 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
23372 if (row
->used
[TEXT_AREA
])
23373 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
23375 if (row
->used
[RIGHT_MARGIN_AREA
])
23376 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
23381 /* Return non-zero if W's cursor intersects rectangle R. */
23384 phys_cursor_in_rect_p (w
, r
)
23388 XRectangle cr
, result
;
23389 struct glyph
*cursor_glyph
;
23391 cursor_glyph
= get_phys_cursor_glyph (w
);
23394 /* r is relative to W's box, but w->phys_cursor.x is relative
23395 to left edge of W's TEXT area. Adjust it. */
23396 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
23397 cr
.y
= w
->phys_cursor
.y
;
23398 cr
.width
= cursor_glyph
->pixel_width
;
23399 cr
.height
= w
->phys_cursor_height
;
23400 /* ++KFS: W32 version used W32-specific IntersectRect here, but
23401 I assume the effect is the same -- and this is portable. */
23402 return x_intersect_rectangles (&cr
, r
, &result
);
23410 Draw a vertical window border to the right of window W if W doesn't
23411 have vertical scroll bars. */
23414 x_draw_vertical_border (w
)
23417 /* We could do better, if we knew what type of scroll-bar the adjacent
23418 windows (on either side) have... But we don't :-(
23419 However, I think this works ok. ++KFS 2003-04-25 */
23421 /* Redraw borders between horizontally adjacent windows. Don't
23422 do it for frames with vertical scroll bars because either the
23423 right scroll bar of a window, or the left scroll bar of its
23424 neighbor will suffice as a border. */
23425 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
23428 if (!WINDOW_RIGHTMOST_P (w
)
23429 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
23431 int x0
, x1
, y0
, y1
;
23433 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23436 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23439 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
23441 else if (!WINDOW_LEFTMOST_P (w
)
23442 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
23444 int x0
, x1
, y0
, y1
;
23446 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23449 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23452 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
23457 /* Redraw the part of window W intersection rectangle FR. Pixel
23458 coordinates in FR are frame-relative. Call this function with
23459 input blocked. Value is non-zero if the exposure overwrites
23463 expose_window (w
, fr
)
23467 struct frame
*f
= XFRAME (w
->frame
);
23469 int mouse_face_overwritten_p
= 0;
23471 /* If window is not yet fully initialized, do nothing. This can
23472 happen when toolkit scroll bars are used and a window is split.
23473 Reconfiguring the scroll bar will generate an expose for a newly
23475 if (w
->current_matrix
== NULL
)
23478 /* When we're currently updating the window, display and current
23479 matrix usually don't agree. Arrange for a thorough display
23481 if (w
== updated_window
)
23483 SET_FRAME_GARBAGED (f
);
23487 /* Frame-relative pixel rectangle of W. */
23488 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
23489 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
23490 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
23491 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
23493 if (x_intersect_rectangles (fr
, &wr
, &r
))
23495 int yb
= window_text_bottom_y (w
);
23496 struct glyph_row
*row
;
23497 int cursor_cleared_p
;
23498 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
23500 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
23501 r
.x
, r
.y
, r
.width
, r
.height
));
23503 /* Convert to window coordinates. */
23504 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
23505 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
23507 /* Turn off the cursor. */
23508 if (!w
->pseudo_window_p
23509 && phys_cursor_in_rect_p (w
, &r
))
23511 x_clear_cursor (w
);
23512 cursor_cleared_p
= 1;
23515 cursor_cleared_p
= 0;
23517 /* Update lines intersecting rectangle R. */
23518 first_overlapping_row
= last_overlapping_row
= NULL
;
23519 for (row
= w
->current_matrix
->rows
;
23524 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
23526 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
23527 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
23528 || (r
.y
>= y0
&& r
.y
< y1
)
23529 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
23531 /* A header line may be overlapping, but there is no need
23532 to fix overlapping areas for them. KFS 2005-02-12 */
23533 if (row
->overlapping_p
&& !row
->mode_line_p
)
23535 if (first_overlapping_row
== NULL
)
23536 first_overlapping_row
= row
;
23537 last_overlapping_row
= row
;
23540 if (expose_line (w
, row
, &r
))
23541 mouse_face_overwritten_p
= 1;
23548 /* Display the mode line if there is one. */
23549 if (WINDOW_WANTS_MODELINE_P (w
)
23550 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
23552 && row
->y
< r
.y
+ r
.height
)
23554 if (expose_line (w
, row
, &r
))
23555 mouse_face_overwritten_p
= 1;
23558 if (!w
->pseudo_window_p
)
23560 /* Fix the display of overlapping rows. */
23561 if (first_overlapping_row
)
23562 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
23564 /* Draw border between windows. */
23565 x_draw_vertical_border (w
);
23567 /* Turn the cursor on again. */
23568 if (cursor_cleared_p
)
23569 update_window_cursor (w
, 1);
23573 return mouse_face_overwritten_p
;
23578 /* Redraw (parts) of all windows in the window tree rooted at W that
23579 intersect R. R contains frame pixel coordinates. Value is
23580 non-zero if the exposure overwrites mouse-face. */
23583 expose_window_tree (w
, r
)
23587 struct frame
*f
= XFRAME (w
->frame
);
23588 int mouse_face_overwritten_p
= 0;
23590 while (w
&& !FRAME_GARBAGED_P (f
))
23592 if (!NILP (w
->hchild
))
23593 mouse_face_overwritten_p
23594 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
23595 else if (!NILP (w
->vchild
))
23596 mouse_face_overwritten_p
23597 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
23599 mouse_face_overwritten_p
|= expose_window (w
, r
);
23601 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
23604 return mouse_face_overwritten_p
;
23609 Redisplay an exposed area of frame F. X and Y are the upper-left
23610 corner of the exposed rectangle. W and H are width and height of
23611 the exposed area. All are pixel values. W or H zero means redraw
23612 the entire frame. */
23615 expose_frame (f
, x
, y
, w
, h
)
23620 int mouse_face_overwritten_p
= 0;
23622 TRACE ((stderr
, "expose_frame "));
23624 /* No need to redraw if frame will be redrawn soon. */
23625 if (FRAME_GARBAGED_P (f
))
23627 TRACE ((stderr
, " garbaged\n"));
23631 /* If basic faces haven't been realized yet, there is no point in
23632 trying to redraw anything. This can happen when we get an expose
23633 event while Emacs is starting, e.g. by moving another window. */
23634 if (FRAME_FACE_CACHE (f
) == NULL
23635 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
23637 TRACE ((stderr
, " no faces\n"));
23641 if (w
== 0 || h
== 0)
23644 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
23645 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
23655 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
23656 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
23658 if (WINDOWP (f
->tool_bar_window
))
23659 mouse_face_overwritten_p
23660 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
23662 #ifdef HAVE_X_WINDOWS
23664 #ifndef USE_X_TOOLKIT
23665 if (WINDOWP (f
->menu_bar_window
))
23666 mouse_face_overwritten_p
23667 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
23668 #endif /* not USE_X_TOOLKIT */
23672 /* Some window managers support a focus-follows-mouse style with
23673 delayed raising of frames. Imagine a partially obscured frame,
23674 and moving the mouse into partially obscured mouse-face on that
23675 frame. The visible part of the mouse-face will be highlighted,
23676 then the WM raises the obscured frame. With at least one WM, KDE
23677 2.1, Emacs is not getting any event for the raising of the frame
23678 (even tried with SubstructureRedirectMask), only Expose events.
23679 These expose events will draw text normally, i.e. not
23680 highlighted. Which means we must redo the highlight here.
23681 Subsume it under ``we love X''. --gerd 2001-08-15 */
23682 /* Included in Windows version because Windows most likely does not
23683 do the right thing if any third party tool offers
23684 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
23685 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
23687 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23688 if (f
== dpyinfo
->mouse_face_mouse_frame
)
23690 int x
= dpyinfo
->mouse_face_mouse_x
;
23691 int y
= dpyinfo
->mouse_face_mouse_y
;
23692 clear_mouse_face (dpyinfo
);
23693 note_mouse_highlight (f
, x
, y
);
23700 Determine the intersection of two rectangles R1 and R2. Return
23701 the intersection in *RESULT. Value is non-zero if RESULT is not
23705 x_intersect_rectangles (r1
, r2
, result
)
23706 XRectangle
*r1
, *r2
, *result
;
23708 XRectangle
*left
, *right
;
23709 XRectangle
*upper
, *lower
;
23710 int intersection_p
= 0;
23712 /* Rearrange so that R1 is the left-most rectangle. */
23714 left
= r1
, right
= r2
;
23716 left
= r2
, right
= r1
;
23718 /* X0 of the intersection is right.x0, if this is inside R1,
23719 otherwise there is no intersection. */
23720 if (right
->x
<= left
->x
+ left
->width
)
23722 result
->x
= right
->x
;
23724 /* The right end of the intersection is the minimum of the
23725 the right ends of left and right. */
23726 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
23729 /* Same game for Y. */
23731 upper
= r1
, lower
= r2
;
23733 upper
= r2
, lower
= r1
;
23735 /* The upper end of the intersection is lower.y0, if this is inside
23736 of upper. Otherwise, there is no intersection. */
23737 if (lower
->y
<= upper
->y
+ upper
->height
)
23739 result
->y
= lower
->y
;
23741 /* The lower end of the intersection is the minimum of the lower
23742 ends of upper and lower. */
23743 result
->height
= (min (lower
->y
+ lower
->height
,
23744 upper
->y
+ upper
->height
)
23746 intersection_p
= 1;
23750 return intersection_p
;
23753 #endif /* HAVE_WINDOW_SYSTEM */
23756 /***********************************************************************
23758 ***********************************************************************/
23763 Vwith_echo_area_save_vector
= Qnil
;
23764 staticpro (&Vwith_echo_area_save_vector
);
23766 Vmessage_stack
= Qnil
;
23767 staticpro (&Vmessage_stack
);
23769 Qinhibit_redisplay
= intern ("inhibit-redisplay");
23770 staticpro (&Qinhibit_redisplay
);
23772 message_dolog_marker1
= Fmake_marker ();
23773 staticpro (&message_dolog_marker1
);
23774 message_dolog_marker2
= Fmake_marker ();
23775 staticpro (&message_dolog_marker2
);
23776 message_dolog_marker3
= Fmake_marker ();
23777 staticpro (&message_dolog_marker3
);
23780 defsubr (&Sdump_frame_glyph_matrix
);
23781 defsubr (&Sdump_glyph_matrix
);
23782 defsubr (&Sdump_glyph_row
);
23783 defsubr (&Sdump_tool_bar_row
);
23784 defsubr (&Strace_redisplay
);
23785 defsubr (&Strace_to_stderr
);
23787 #ifdef HAVE_WINDOW_SYSTEM
23788 defsubr (&Stool_bar_lines_needed
);
23789 defsubr (&Slookup_image_map
);
23791 defsubr (&Sformat_mode_line
);
23793 staticpro (&Qmenu_bar_update_hook
);
23794 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
23796 staticpro (&Qoverriding_terminal_local_map
);
23797 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
23799 staticpro (&Qoverriding_local_map
);
23800 Qoverriding_local_map
= intern ("overriding-local-map");
23802 staticpro (&Qwindow_scroll_functions
);
23803 Qwindow_scroll_functions
= intern ("window-scroll-functions");
23805 staticpro (&Qredisplay_end_trigger_functions
);
23806 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
23808 staticpro (&Qinhibit_point_motion_hooks
);
23809 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
23811 QCdata
= intern (":data");
23812 staticpro (&QCdata
);
23813 Qdisplay
= intern ("display");
23814 staticpro (&Qdisplay
);
23815 Qspace_width
= intern ("space-width");
23816 staticpro (&Qspace_width
);
23817 Qraise
= intern ("raise");
23818 staticpro (&Qraise
);
23819 Qslice
= intern ("slice");
23820 staticpro (&Qslice
);
23821 Qspace
= intern ("space");
23822 staticpro (&Qspace
);
23823 Qmargin
= intern ("margin");
23824 staticpro (&Qmargin
);
23825 Qpointer
= intern ("pointer");
23826 staticpro (&Qpointer
);
23827 Qleft_margin
= intern ("left-margin");
23828 staticpro (&Qleft_margin
);
23829 Qright_margin
= intern ("right-margin");
23830 staticpro (&Qright_margin
);
23831 Qcenter
= intern ("center");
23832 staticpro (&Qcenter
);
23833 Qline_height
= intern ("line-height");
23834 staticpro (&Qline_height
);
23835 QCalign_to
= intern (":align-to");
23836 staticpro (&QCalign_to
);
23837 QCrelative_width
= intern (":relative-width");
23838 staticpro (&QCrelative_width
);
23839 QCrelative_height
= intern (":relative-height");
23840 staticpro (&QCrelative_height
);
23841 QCeval
= intern (":eval");
23842 staticpro (&QCeval
);
23843 QCpropertize
= intern (":propertize");
23844 staticpro (&QCpropertize
);
23845 QCfile
= intern (":file");
23846 staticpro (&QCfile
);
23847 Qfontified
= intern ("fontified");
23848 staticpro (&Qfontified
);
23849 Qfontification_functions
= intern ("fontification-functions");
23850 staticpro (&Qfontification_functions
);
23851 Qtrailing_whitespace
= intern ("trailing-whitespace");
23852 staticpro (&Qtrailing_whitespace
);
23853 Qescape_glyph
= intern ("escape-glyph");
23854 staticpro (&Qescape_glyph
);
23855 Qnobreak_space
= intern ("nobreak-space");
23856 staticpro (&Qnobreak_space
);
23857 Qimage
= intern ("image");
23858 staticpro (&Qimage
);
23859 QCmap
= intern (":map");
23860 staticpro (&QCmap
);
23861 QCpointer
= intern (":pointer");
23862 staticpro (&QCpointer
);
23863 Qrect
= intern ("rect");
23864 staticpro (&Qrect
);
23865 Qcircle
= intern ("circle");
23866 staticpro (&Qcircle
);
23867 Qpoly
= intern ("poly");
23868 staticpro (&Qpoly
);
23869 Qmessage_truncate_lines
= intern ("message-truncate-lines");
23870 staticpro (&Qmessage_truncate_lines
);
23871 Qgrow_only
= intern ("grow-only");
23872 staticpro (&Qgrow_only
);
23873 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
23874 staticpro (&Qinhibit_menubar_update
);
23875 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
23876 staticpro (&Qinhibit_eval_during_redisplay
);
23877 Qposition
= intern ("position");
23878 staticpro (&Qposition
);
23879 Qbuffer_position
= intern ("buffer-position");
23880 staticpro (&Qbuffer_position
);
23881 Qobject
= intern ("object");
23882 staticpro (&Qobject
);
23883 Qbar
= intern ("bar");
23885 Qhbar
= intern ("hbar");
23886 staticpro (&Qhbar
);
23887 Qbox
= intern ("box");
23889 Qhollow
= intern ("hollow");
23890 staticpro (&Qhollow
);
23891 Qhand
= intern ("hand");
23892 staticpro (&Qhand
);
23893 Qarrow
= intern ("arrow");
23894 staticpro (&Qarrow
);
23895 Qtext
= intern ("text");
23896 staticpro (&Qtext
);
23897 Qrisky_local_variable
= intern ("risky-local-variable");
23898 staticpro (&Qrisky_local_variable
);
23899 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
23900 staticpro (&Qinhibit_free_realized_faces
);
23902 list_of_error
= Fcons (Fcons (intern ("error"),
23903 Fcons (intern ("void-variable"), Qnil
)),
23905 staticpro (&list_of_error
);
23907 Qlast_arrow_position
= intern ("last-arrow-position");
23908 staticpro (&Qlast_arrow_position
);
23909 Qlast_arrow_string
= intern ("last-arrow-string");
23910 staticpro (&Qlast_arrow_string
);
23912 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
23913 staticpro (&Qoverlay_arrow_string
);
23914 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
23915 staticpro (&Qoverlay_arrow_bitmap
);
23917 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
23918 staticpro (&echo_buffer
[0]);
23919 staticpro (&echo_buffer
[1]);
23921 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
23922 staticpro (&echo_area_buffer
[0]);
23923 staticpro (&echo_area_buffer
[1]);
23925 Vmessages_buffer_name
= build_string ("*Messages*");
23926 staticpro (&Vmessages_buffer_name
);
23928 mode_line_proptrans_alist
= Qnil
;
23929 staticpro (&mode_line_proptrans_alist
);
23930 mode_line_string_list
= Qnil
;
23931 staticpro (&mode_line_string_list
);
23932 mode_line_string_face
= Qnil
;
23933 staticpro (&mode_line_string_face
);
23934 mode_line_string_face_prop
= Qnil
;
23935 staticpro (&mode_line_string_face_prop
);
23936 Vmode_line_unwind_vector
= Qnil
;
23937 staticpro (&Vmode_line_unwind_vector
);
23939 help_echo_string
= Qnil
;
23940 staticpro (&help_echo_string
);
23941 help_echo_object
= Qnil
;
23942 staticpro (&help_echo_object
);
23943 help_echo_window
= Qnil
;
23944 staticpro (&help_echo_window
);
23945 previous_help_echo_string
= Qnil
;
23946 staticpro (&previous_help_echo_string
);
23947 help_echo_pos
= -1;
23949 #ifdef HAVE_WINDOW_SYSTEM
23950 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
23951 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
23952 For example, if a block cursor is over a tab, it will be drawn as
23953 wide as that tab on the display. */);
23954 x_stretch_cursor_p
= 0;
23957 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
23958 doc
: /* *Non-nil means highlight trailing whitespace.
23959 The face used for trailing whitespace is `trailing-whitespace'. */);
23960 Vshow_trailing_whitespace
= Qnil
;
23962 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
23963 doc
: /* *Control highlighting of nobreak space and soft hyphen.
23964 A value of t means highlight the character itself (for nobreak space,
23965 use face `nobreak-space').
23966 A value of nil means no highlighting.
23967 Other values mean display the escape glyph followed by an ordinary
23968 space or ordinary hyphen. */);
23969 Vnobreak_char_display
= Qt
;
23971 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
23972 doc
: /* *The pointer shape to show in void text areas.
23973 A value of nil means to show the text pointer. Other options are `arrow',
23974 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
23975 Vvoid_text_area_pointer
= Qarrow
;
23977 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
23978 doc
: /* Non-nil means don't actually do any redisplay.
23979 This is used for internal purposes. */);
23980 Vinhibit_redisplay
= Qnil
;
23982 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
23983 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
23984 Vglobal_mode_string
= Qnil
;
23986 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
23987 doc
: /* Marker for where to display an arrow on top of the buffer text.
23988 This must be the beginning of a line in order to work.
23989 See also `overlay-arrow-string'. */);
23990 Voverlay_arrow_position
= Qnil
;
23992 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
23993 doc
: /* String to display as an arrow in non-window frames.
23994 See also `overlay-arrow-position'. */);
23995 Voverlay_arrow_string
= build_string ("=>");
23997 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
23998 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
23999 The symbols on this list are examined during redisplay to determine
24000 where to display overlay arrows. */);
24001 Voverlay_arrow_variable_list
24002 = Fcons (intern ("overlay-arrow-position"), Qnil
);
24004 DEFVAR_INT ("scroll-step", &scroll_step
,
24005 doc
: /* *The number of lines to try scrolling a window by when point moves out.
24006 If that fails to bring point back on frame, point is centered instead.
24007 If this is zero, point is always centered after it moves off frame.
24008 If you want scrolling to always be a line at a time, you should set
24009 `scroll-conservatively' to a large value rather than set this to 1. */);
24011 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
24012 doc
: /* *Scroll up to this many lines, to bring point back on screen.
24013 A value of zero means to scroll the text to center point vertically
24014 in the window. */);
24015 scroll_conservatively
= 0;
24017 DEFVAR_INT ("scroll-margin", &scroll_margin
,
24018 doc
: /* *Number of lines of margin at the top and bottom of a window.
24019 Recenter the window whenever point gets within this many lines
24020 of the top or bottom of the window. */);
24023 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
24024 doc
: /* Pixels per inch value for non-window system displays.
24025 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
24026 Vdisplay_pixels_per_inch
= make_float (72.0);
24029 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
24032 DEFVAR_BOOL ("truncate-partial-width-windows",
24033 &truncate_partial_width_windows
,
24034 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
24035 truncate_partial_width_windows
= 1;
24037 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
24038 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
24039 Any other value means to use the appropriate face, `mode-line',
24040 `header-line', or `menu' respectively. */);
24041 mode_line_inverse_video
= 1;
24043 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
24044 doc
: /* *Maximum buffer size for which line number should be displayed.
24045 If the buffer is bigger than this, the line number does not appear
24046 in the mode line. A value of nil means no limit. */);
24047 Vline_number_display_limit
= Qnil
;
24049 DEFVAR_INT ("line-number-display-limit-width",
24050 &line_number_display_limit_width
,
24051 doc
: /* *Maximum line width (in characters) for line number display.
24052 If the average length of the lines near point is bigger than this, then the
24053 line number may be omitted from the mode line. */);
24054 line_number_display_limit_width
= 200;
24056 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
24057 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
24058 highlight_nonselected_windows
= 0;
24060 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
24061 doc
: /* Non-nil if more than one frame is visible on this display.
24062 Minibuffer-only frames don't count, but iconified frames do.
24063 This variable is not guaranteed to be accurate except while processing
24064 `frame-title-format' and `icon-title-format'. */);
24066 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
24067 doc
: /* Template for displaying the title bar of visible frames.
24068 \(Assuming the window manager supports this feature.)
24070 This variable has the same structure as `mode-line-format', except that
24071 the %c and %l constructs are ignored. It is used only on frames for
24072 which no explicit name has been set \(see `modify-frame-parameters'). */);
24074 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
24075 doc
: /* Template for displaying the title bar of an iconified frame.
24076 \(Assuming the window manager supports this feature.)
24077 This variable has the same structure as `mode-line-format' (which see),
24078 and is used only on frames for which no explicit name has been set
24079 \(see `modify-frame-parameters'). */);
24081 = Vframe_title_format
24082 = Fcons (intern ("multiple-frames"),
24083 Fcons (build_string ("%b"),
24084 Fcons (Fcons (empty_string
,
24085 Fcons (intern ("invocation-name"),
24086 Fcons (build_string ("@"),
24087 Fcons (intern ("system-name"),
24091 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
24092 doc
: /* Maximum number of lines to keep in the message log buffer.
24093 If nil, disable message logging. If t, log messages but don't truncate
24094 the buffer when it becomes large. */);
24095 Vmessage_log_max
= make_number (100);
24097 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
24098 doc
: /* Functions called before redisplay, if window sizes have changed.
24099 The value should be a list of functions that take one argument.
24100 Just before redisplay, for each frame, if any of its windows have changed
24101 size since the last redisplay, or have been split or deleted,
24102 all the functions in the list are called, with the frame as argument. */);
24103 Vwindow_size_change_functions
= Qnil
;
24105 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
24106 doc
: /* List of functions to call before redisplaying a window with scrolling.
24107 Each function is called with two arguments, the window
24108 and its new display-start position. Note that the value of `window-end'
24109 is not valid when these functions are called. */);
24110 Vwindow_scroll_functions
= Qnil
;
24112 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
24113 doc
: /* Functions called when redisplay of a window reaches the end trigger.
24114 Each function is called with two arguments, the window and the end trigger value.
24115 See `set-window-redisplay-end-trigger'. */);
24116 Vredisplay_end_trigger_functions
= Qnil
;
24118 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
24119 doc
: /* *Non-nil means autoselect window with mouse pointer.
24120 If nil, do not autoselect windows.
24121 A positive number means delay autoselection by that many seconds: a
24122 window is autoselected only after the mouse has remained in that
24123 window for the duration of the delay.
24124 A negative number has a similar effect, but causes windows to be
24125 autoselected only after the mouse has stopped moving. \(Because of
24126 the way Emacs compares mouse events, you will occasionally wait twice
24127 that time before the window gets selected.\)
24128 Any other value means to autoselect window instantaneously when the
24129 mouse pointer enters it.
24131 Autoselection selects the minibuffer only if it is active, and never
24132 unselects the minibuffer if it is active. */);
24133 Vmouse_autoselect_window
= Qnil
;
24135 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
24136 doc
: /* *Non-nil means automatically resize tool-bars.
24137 This dynamically changes the tool-bar's height to the minimum height
24138 that is needed to make all tool-bar items visible.
24139 If value is `grow-only', the tool-bar's height is only increased
24140 automatically; to decreace the tool-bar height, use \\[recenter]. */);
24141 Vauto_resize_tool_bars
= Qt
;
24143 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
24144 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
24145 auto_raise_tool_bar_buttons_p
= 1;
24147 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
24148 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
24149 make_cursor_line_fully_visible_p
= 1;
24151 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
24152 doc
: /* *Border below tool-bar in pixels.
24153 If an integer, use it as the height of the border.
24154 If it is one of `internal-border-width' or `border-width', use the
24155 value of the corresponding frame parameter.
24156 Otherwise, no border is added below the tool-bar. */);
24157 Vtool_bar_border
= Qinternal_border_width
;
24159 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
24160 doc
: /* *Margin around tool-bar buttons in pixels.
24161 If an integer, use that for both horizontal and vertical margins.
24162 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
24163 HORZ specifying the horizontal margin, and VERT specifying the
24164 vertical margin. */);
24165 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
24167 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
24168 doc
: /* *Relief thickness of tool-bar buttons. */);
24169 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
24171 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
24172 doc
: /* List of functions to call to fontify regions of text.
24173 Each function is called with one argument POS. Functions must
24174 fontify a region starting at POS in the current buffer, and give
24175 fontified regions the property `fontified'. */);
24176 Vfontification_functions
= Qnil
;
24177 Fmake_variable_buffer_local (Qfontification_functions
);
24179 DEFVAR_BOOL ("unibyte-display-via-language-environment",
24180 &unibyte_display_via_language_environment
,
24181 doc
: /* *Non-nil means display unibyte text according to language environment.
24182 Specifically this means that unibyte non-ASCII characters
24183 are displayed by converting them to the equivalent multibyte characters
24184 according to the current language environment. As a result, they are
24185 displayed according to the current fontset. */);
24186 unibyte_display_via_language_environment
= 0;
24188 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
24189 doc
: /* *Maximum height for resizing mini-windows.
24190 If a float, it specifies a fraction of the mini-window frame's height.
24191 If an integer, it specifies a number of lines. */);
24192 Vmax_mini_window_height
= make_float (0.25);
24194 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
24195 doc
: /* *How to resize mini-windows.
24196 A value of nil means don't automatically resize mini-windows.
24197 A value of t means resize them to fit the text displayed in them.
24198 A value of `grow-only', the default, means let mini-windows grow
24199 only, until their display becomes empty, at which point the windows
24200 go back to their normal size. */);
24201 Vresize_mini_windows
= Qgrow_only
;
24203 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
24204 doc
: /* Alist specifying how to blink the cursor off.
24205 Each element has the form (ON-STATE . OFF-STATE). Whenever the
24206 `cursor-type' frame-parameter or variable equals ON-STATE,
24207 comparing using `equal', Emacs uses OFF-STATE to specify
24208 how to blink it off. ON-STATE and OFF-STATE are values for
24209 the `cursor-type' frame parameter.
24211 If a frame's ON-STATE has no entry in this list,
24212 the frame's other specifications determine how to blink the cursor off. */);
24213 Vblink_cursor_alist
= Qnil
;
24215 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
24216 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
24217 automatic_hscrolling_p
= 1;
24219 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
24220 doc
: /* *How many columns away from the window edge point is allowed to get
24221 before automatic hscrolling will horizontally scroll the window. */);
24222 hscroll_margin
= 5;
24224 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
24225 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
24226 When point is less than `hscroll-margin' columns from the window
24227 edge, automatic hscrolling will scroll the window by the amount of columns
24228 determined by this variable. If its value is a positive integer, scroll that
24229 many columns. If it's a positive floating-point number, it specifies the
24230 fraction of the window's width to scroll. If it's nil or zero, point will be
24231 centered horizontally after the scroll. Any other value, including negative
24232 numbers, are treated as if the value were zero.
24234 Automatic hscrolling always moves point outside the scroll margin, so if
24235 point was more than scroll step columns inside the margin, the window will
24236 scroll more than the value given by the scroll step.
24238 Note that the lower bound for automatic hscrolling specified by `scroll-left'
24239 and `scroll-right' overrides this variable's effect. */);
24240 Vhscroll_step
= make_number (0);
24242 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
24243 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
24244 Bind this around calls to `message' to let it take effect. */);
24245 message_truncate_lines
= 0;
24247 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
24248 doc
: /* Normal hook run to update the menu bar definitions.
24249 Redisplay runs this hook before it redisplays the menu bar.
24250 This is used to update submenus such as Buffers,
24251 whose contents depend on various data. */);
24252 Vmenu_bar_update_hook
= Qnil
;
24254 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
24255 doc
: /* Frame for which we are updating a menu.
24256 The enable predicate for a menu binding should check this variable. */);
24257 Vmenu_updating_frame
= Qnil
;
24259 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
24260 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
24261 inhibit_menubar_update
= 0;
24263 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
24264 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
24265 inhibit_eval_during_redisplay
= 0;
24267 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
24268 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
24269 inhibit_free_realized_faces
= 0;
24272 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
24273 doc
: /* Inhibit try_window_id display optimization. */);
24274 inhibit_try_window_id
= 0;
24276 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
24277 doc
: /* Inhibit try_window_reusing display optimization. */);
24278 inhibit_try_window_reusing
= 0;
24280 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
24281 doc
: /* Inhibit try_cursor_movement display optimization. */);
24282 inhibit_try_cursor_movement
= 0;
24283 #endif /* GLYPH_DEBUG */
24285 DEFVAR_INT ("overline-margin", &overline_margin
,
24286 doc
: /* *Space between overline and text, in pixels.
24287 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
24288 margin to the caracter height. */);
24289 overline_margin
= 2;
24293 /* Initialize this module when Emacs starts. */
24298 Lisp_Object root_window
;
24299 struct window
*mini_w
;
24301 current_header_line_height
= current_mode_line_height
= -1;
24303 CHARPOS (this_line_start_pos
) = 0;
24305 mini_w
= XWINDOW (minibuf_window
);
24306 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
24308 if (!noninteractive
)
24310 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
24313 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
24314 set_window_height (root_window
,
24315 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
24317 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
24318 set_window_height (minibuf_window
, 1, 0);
24320 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
24321 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
24323 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
24324 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
24325 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
24327 /* The default ellipsis glyphs `...'. */
24328 for (i
= 0; i
< 3; ++i
)
24329 default_invis_vector
[i
] = make_number ('.');
24333 /* Allocate the buffer for frame titles.
24334 Also used for `format-mode-line'. */
24336 mode_line_noprop_buf
= (char *) xmalloc (size
);
24337 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
24338 mode_line_noprop_ptr
= mode_line_noprop_buf
;
24339 mode_line_target
= MODE_LINE_DISPLAY
;
24342 help_echo_showing_p
= 0;
24346 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
24347 (do not change this comment) */