1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
3 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
27 Emacs separates the task of updating the display from code
28 modifying global state, e.g. buffer text. This way functions
29 operating on buffers don't also have to be concerned with updating
32 Updating the display is triggered by the Lisp interpreter when it
33 decides it's time to do it. This is done either automatically for
34 you as part of the interpreter's command loop or as the result of
35 calling Lisp functions like `sit-for'. The C function `redisplay'
36 in xdisp.c is the only entry into the inner redisplay code. (Or,
37 let's say almost---see the description of direct update
40 The following diagram shows how redisplay code is invoked. As you
41 can see, Lisp calls redisplay and vice versa. Under window systems
42 like X, some portions of the redisplay code are also called
43 asynchronously during mouse movement or expose events. It is very
44 important that these code parts do NOT use the C library (malloc,
45 free) because many C libraries under Unix are not reentrant. They
46 may also NOT call functions of the Lisp interpreter which could
47 change the interpreter's state. If you don't follow these rules,
48 you will encounter bugs which are very hard to explain.
50 (Direct functions, see below)
51 direct_output_for_insert,
52 direct_forward_char (dispnew.c)
53 +---------------------------------+
56 +--------------+ redisplay +----------------+
57 | Lisp machine |---------------->| Redisplay code |<--+
58 +--------------+ (xdisp.c) +----------------+ |
60 +----------------------------------+ |
61 Don't use this path when called |
64 expose_window (asynchronous) |
66 X expose events -----+
68 What does redisplay do? Obviously, it has to figure out somehow what
69 has been changed since the last time the display has been updated,
70 and to make these changes visible. Preferably it would do that in
71 a moderately intelligent way, i.e. fast.
73 Changes in buffer text can be deduced from window and buffer
74 structures, and from some global variables like `beg_unchanged' and
75 `end_unchanged'. The contents of the display are additionally
76 recorded in a `glyph matrix', a two-dimensional matrix of glyph
77 structures. Each row in such a matrix corresponds to a line on the
78 display, and each glyph in a row corresponds to a column displaying
79 a character, an image, or what else. This matrix is called the
80 `current glyph matrix' or `current matrix' in redisplay
83 For buffer parts that have been changed since the last update, a
84 second glyph matrix is constructed, the so called `desired glyph
85 matrix' or short `desired matrix'. Current and desired matrix are
86 then compared to find a cheap way to update the display, e.g. by
87 reusing part of the display by scrolling lines.
92 You will find a lot of redisplay optimizations when you start
93 looking at the innards of redisplay. The overall goal of all these
94 optimizations is to make redisplay fast because it is done
97 Two optimizations are not found in xdisp.c. These are the direct
98 operations mentioned above. As the name suggests they follow a
99 different principle than the rest of redisplay. Instead of
100 building a desired matrix and then comparing it with the current
101 display, they perform their actions directly on the display and on
104 One direct operation updates the display after one character has
105 been entered. The other one moves the cursor by one position
106 forward or backward. You find these functions under the names
107 `direct_output_for_insert' and `direct_output_forward_char' in
113 Desired matrices are always built per Emacs window. The function
114 `display_line' is the central function to look at if you are
115 interested. It constructs one row in a desired matrix given an
116 iterator structure containing both a buffer position and a
117 description of the environment in which the text is to be
118 displayed. But this is too early, read on.
120 Characters and pixmaps displayed for a range of buffer text depend
121 on various settings of buffers and windows, on overlays and text
122 properties, on display tables, on selective display. The good news
123 is that all this hairy stuff is hidden behind a small set of
124 interface functions taking an iterator structure (struct it)
127 Iteration over things to be displayed is then simple. It is
128 started by initializing an iterator with a call to init_iterator.
129 Calls to get_next_display_element fill the iterator structure with
130 relevant information about the next thing to display. Calls to
131 set_iterator_to_next move the iterator to the next thing.
133 Besides this, an iterator also contains information about the
134 display environment in which glyphs for display elements are to be
135 produced. It has fields for the width and height of the display,
136 the information whether long lines are truncated or continued, a
137 current X and Y position, and lots of other stuff you can better
140 Glyphs in a desired matrix are normally constructed in a loop
141 calling get_next_display_element and then produce_glyphs. The call
142 to produce_glyphs will fill the iterator structure with pixel
143 information about the element being displayed and at the same time
144 produce glyphs for it. If the display element fits on the line
145 being displayed, set_iterator_to_next is called next, otherwise the
146 glyphs produced are discarded.
151 That just couldn't be all, could it? What about terminal types not
152 supporting operations on sub-windows of the screen? To update the
153 display on such a terminal, window-based glyph matrices are not
154 well suited. To be able to reuse part of the display (scrolling
155 lines up and down), we must instead have a view of the whole
156 screen. This is what `frame matrices' are for. They are a trick.
158 Frames on terminals like above have a glyph pool. Windows on such
159 a frame sub-allocate their glyph memory from their frame's glyph
160 pool. The frame itself is given its own glyph matrices. By
161 coincidence---or maybe something else---rows in window glyph
162 matrices are slices of corresponding rows in frame matrices. Thus
163 writing to window matrices implicitly updates a frame matrix which
164 provides us with the view of the whole screen that we originally
165 wanted to have without having to move many bytes around. To be
166 honest, there is a little bit more done, but not much more. If you
167 plan to extend that code, take a look at dispnew.c. The function
168 build_frame_matrix is a good starting point. */
174 #include "keyboard.h"
177 #include "termchar.h"
178 #include "dispextern.h"
182 #include "commands.h"
186 #include "termhooks.h"
187 #include "intervals.h"
190 #include "region-cache.h"
192 #include "blockinput.h"
194 #ifdef HAVE_X_WINDOWS
204 #ifndef FRAME_X_OUTPUT
205 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
208 #define INFINITY 10000000
210 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
212 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
213 extern int pending_menu_activation
;
216 extern int interrupt_input
;
217 extern int command_loop_level
;
219 extern Lisp_Object do_mouse_tracking
;
221 extern int minibuffer_auto_raise
;
222 extern Lisp_Object Vminibuffer_list
;
224 extern Lisp_Object Qface
;
225 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
227 extern Lisp_Object Voverriding_local_map
;
228 extern Lisp_Object Voverriding_local_map_menu_flag
;
229 extern Lisp_Object Qmenu_item
;
230 extern Lisp_Object Qwhen
;
231 extern Lisp_Object Qhelp_echo
;
233 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
234 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
235 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
236 Lisp_Object Qinhibit_point_motion_hooks
;
237 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
238 Lisp_Object Qfontified
;
239 Lisp_Object Qgrow_only
;
240 Lisp_Object Qinhibit_eval_during_redisplay
;
241 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
244 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
247 Lisp_Object Qarrow
, Qhand
, Qtext
;
249 Lisp_Object Qrisky_local_variable
;
251 /* Holds the list (error). */
252 Lisp_Object list_of_error
;
254 /* Functions called to fontify regions of text. */
256 Lisp_Object Vfontification_functions
;
257 Lisp_Object Qfontification_functions
;
259 /* Non-nil means automatically select any window when the mouse
260 cursor moves into it. */
261 Lisp_Object Vmouse_autoselect_window
;
263 /* Non-zero means draw tool bar buttons raised when the mouse moves
266 int auto_raise_tool_bar_buttons_p
;
268 /* Non-zero means to reposition window if cursor line is only partially visible. */
270 int make_cursor_line_fully_visible_p
;
272 /* Margin below tool bar in pixels. 0 or nil means no margin.
273 If value is `internal-border-width' or `border-width',
274 the corresponding frame parameter is used. */
276 Lisp_Object Vtool_bar_border
;
278 /* Margin around tool bar buttons in pixels. */
280 Lisp_Object Vtool_bar_button_margin
;
282 /* Thickness of shadow to draw around tool bar buttons. */
284 EMACS_INT tool_bar_button_relief
;
286 /* Non-nil means automatically resize tool-bars so that all tool-bar
287 items are visible, and no blank lines remain.
289 If value is `grow-only', only make tool-bar bigger. */
291 Lisp_Object Vauto_resize_tool_bars
;
293 /* Non-zero means draw block and hollow cursor as wide as the glyph
294 under it. For example, if a block cursor is over a tab, it will be
295 drawn as wide as that tab on the display. */
297 int x_stretch_cursor_p
;
299 /* Non-nil means don't actually do any redisplay. */
301 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
303 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
305 int inhibit_eval_during_redisplay
;
307 /* Names of text properties relevant for redisplay. */
309 Lisp_Object Qdisplay
;
310 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
312 /* Symbols used in text property values. */
314 Lisp_Object Vdisplay_pixels_per_inch
;
315 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
316 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
319 Lisp_Object Qmargin
, Qpointer
;
320 Lisp_Object Qline_height
;
321 extern Lisp_Object Qheight
;
322 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
323 extern Lisp_Object Qscroll_bar
;
324 extern Lisp_Object Qcursor
;
326 /* Non-nil means highlight trailing whitespace. */
328 Lisp_Object Vshow_trailing_whitespace
;
330 /* Non-nil means escape non-break space and hyphens. */
332 Lisp_Object Vnobreak_char_display
;
334 #ifdef HAVE_WINDOW_SYSTEM
335 extern Lisp_Object Voverflow_newline_into_fringe
;
337 /* Test if overflow newline into fringe. Called with iterator IT
338 at or past right window margin, and with IT->current_x set. */
340 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
341 (!NILP (Voverflow_newline_into_fringe) \
342 && FRAME_WINDOW_P (it->f) \
343 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
344 && it->current_x == it->last_visible_x)
346 #endif /* HAVE_WINDOW_SYSTEM */
348 /* Non-nil means show the text cursor in void text areas
349 i.e. in blank areas after eol and eob. This used to be
350 the default in 21.3. */
352 Lisp_Object Vvoid_text_area_pointer
;
354 /* Name of the face used to highlight trailing whitespace. */
356 Lisp_Object Qtrailing_whitespace
;
358 /* Name and number of the face used to highlight escape glyphs. */
360 Lisp_Object Qescape_glyph
;
362 /* Name and number of the face used to highlight non-breaking spaces. */
364 Lisp_Object Qnobreak_space
;
366 /* The symbol `image' which is the car of the lists used to represent
371 /* The image map types. */
372 Lisp_Object QCmap
, QCpointer
;
373 Lisp_Object Qrect
, Qcircle
, Qpoly
;
375 /* Non-zero means print newline to stdout before next mini-buffer
378 int noninteractive_need_newline
;
380 /* Non-zero means print newline to message log before next message. */
382 static int message_log_need_newline
;
384 /* Three markers that message_dolog uses.
385 It could allocate them itself, but that causes trouble
386 in handling memory-full errors. */
387 static Lisp_Object message_dolog_marker1
;
388 static Lisp_Object message_dolog_marker2
;
389 static Lisp_Object message_dolog_marker3
;
391 /* The buffer position of the first character appearing entirely or
392 partially on the line of the selected window which contains the
393 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
394 redisplay optimization in redisplay_internal. */
396 static struct text_pos this_line_start_pos
;
398 /* Number of characters past the end of the line above, including the
399 terminating newline. */
401 static struct text_pos this_line_end_pos
;
403 /* The vertical positions and the height of this line. */
405 static int this_line_vpos
;
406 static int this_line_y
;
407 static int this_line_pixel_height
;
409 /* X position at which this display line starts. Usually zero;
410 negative if first character is partially visible. */
412 static int this_line_start_x
;
414 /* Buffer that this_line_.* variables are referring to. */
416 static struct buffer
*this_line_buffer
;
418 /* Nonzero means truncate lines in all windows less wide than the
421 int truncate_partial_width_windows
;
423 /* A flag to control how to display unibyte 8-bit character. */
425 int unibyte_display_via_language_environment
;
427 /* Nonzero means we have more than one non-mini-buffer-only frame.
428 Not guaranteed to be accurate except while parsing
429 frame-title-format. */
433 Lisp_Object Vglobal_mode_string
;
436 /* List of variables (symbols) which hold markers for overlay arrows.
437 The symbols on this list are examined during redisplay to determine
438 where to display overlay arrows. */
440 Lisp_Object Voverlay_arrow_variable_list
;
442 /* Marker for where to display an arrow on top of the buffer text. */
444 Lisp_Object Voverlay_arrow_position
;
446 /* String to display for the arrow. Only used on terminal frames. */
448 Lisp_Object Voverlay_arrow_string
;
450 /* Values of those variables at last redisplay are stored as
451 properties on `overlay-arrow-position' symbol. However, if
452 Voverlay_arrow_position is a marker, last-arrow-position is its
453 numerical position. */
455 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
457 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
458 properties on a symbol in overlay-arrow-variable-list. */
460 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
462 /* Like mode-line-format, but for the title bar on a visible frame. */
464 Lisp_Object Vframe_title_format
;
466 /* Like mode-line-format, but for the title bar on an iconified frame. */
468 Lisp_Object Vicon_title_format
;
470 /* List of functions to call when a window's size changes. These
471 functions get one arg, a frame on which one or more windows' sizes
474 static Lisp_Object Vwindow_size_change_functions
;
476 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
478 /* Nonzero if an overlay arrow has been displayed in this window. */
480 static int overlay_arrow_seen
;
482 /* Nonzero means highlight the region even in nonselected windows. */
484 int highlight_nonselected_windows
;
486 /* If cursor motion alone moves point off frame, try scrolling this
487 many lines up or down if that will bring it back. */
489 static EMACS_INT scroll_step
;
491 /* Nonzero means scroll just far enough to bring point back on the
492 screen, when appropriate. */
494 static EMACS_INT scroll_conservatively
;
496 /* Recenter the window whenever point gets within this many lines of
497 the top or bottom of the window. This value is translated into a
498 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
499 that there is really a fixed pixel height scroll margin. */
501 EMACS_INT scroll_margin
;
503 /* Number of windows showing the buffer of the selected window (or
504 another buffer with the same base buffer). keyboard.c refers to
509 /* Vector containing glyphs for an ellipsis `...'. */
511 static Lisp_Object default_invis_vector
[3];
513 /* Zero means display the mode-line/header-line/menu-bar in the default face
514 (this slightly odd definition is for compatibility with previous versions
515 of emacs), non-zero means display them using their respective faces.
517 This variable is deprecated. */
519 int mode_line_inverse_video
;
521 /* Prompt to display in front of the mini-buffer contents. */
523 Lisp_Object minibuf_prompt
;
525 /* Width of current mini-buffer prompt. Only set after display_line
526 of the line that contains the prompt. */
528 int minibuf_prompt_width
;
530 /* This is the window where the echo area message was displayed. It
531 is always a mini-buffer window, but it may not be the same window
532 currently active as a mini-buffer. */
534 Lisp_Object echo_area_window
;
536 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
537 pushes the current message and the value of
538 message_enable_multibyte on the stack, the function restore_message
539 pops the stack and displays MESSAGE again. */
541 Lisp_Object Vmessage_stack
;
543 /* Nonzero means multibyte characters were enabled when the echo area
544 message was specified. */
546 int message_enable_multibyte
;
548 /* Nonzero if we should redraw the mode lines on the next redisplay. */
550 int update_mode_lines
;
552 /* Nonzero if window sizes or contents have changed since last
553 redisplay that finished. */
555 int windows_or_buffers_changed
;
557 /* Nonzero means a frame's cursor type has been changed. */
559 int cursor_type_changed
;
561 /* Nonzero after display_mode_line if %l was used and it displayed a
564 int line_number_displayed
;
566 /* Maximum buffer size for which to display line numbers. */
568 Lisp_Object Vline_number_display_limit
;
570 /* Line width to consider when repositioning for line number display. */
572 static EMACS_INT line_number_display_limit_width
;
574 /* Number of lines to keep in the message log buffer. t means
575 infinite. nil means don't log at all. */
577 Lisp_Object Vmessage_log_max
;
579 /* The name of the *Messages* buffer, a string. */
581 static Lisp_Object Vmessages_buffer_name
;
583 /* Current, index 0, and last displayed echo area message. Either
584 buffers from echo_buffers, or nil to indicate no message. */
586 Lisp_Object echo_area_buffer
[2];
588 /* The buffers referenced from echo_area_buffer. */
590 static Lisp_Object echo_buffer
[2];
592 /* A vector saved used in with_area_buffer to reduce consing. */
594 static Lisp_Object Vwith_echo_area_save_vector
;
596 /* Non-zero means display_echo_area should display the last echo area
597 message again. Set by redisplay_preserve_echo_area. */
599 static int display_last_displayed_message_p
;
601 /* Nonzero if echo area is being used by print; zero if being used by
604 int message_buf_print
;
606 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
608 Lisp_Object Qinhibit_menubar_update
;
609 int inhibit_menubar_update
;
611 /* When evaluating expressions from menu bar items (enable conditions,
612 for instance), this is the frame they are being processed for. */
614 Lisp_Object Vmenu_updating_frame
;
616 /* Maximum height for resizing mini-windows. Either a float
617 specifying a fraction of the available height, or an integer
618 specifying a number of lines. */
620 Lisp_Object Vmax_mini_window_height
;
622 /* Non-zero means messages should be displayed with truncated
623 lines instead of being continued. */
625 int message_truncate_lines
;
626 Lisp_Object Qmessage_truncate_lines
;
628 /* Set to 1 in clear_message to make redisplay_internal aware
629 of an emptied echo area. */
631 static int message_cleared_p
;
633 /* How to blink the default frame cursor off. */
634 Lisp_Object Vblink_cursor_alist
;
636 /* A scratch glyph row with contents used for generating truncation
637 glyphs. Also used in direct_output_for_insert. */
639 #define MAX_SCRATCH_GLYPHS 100
640 struct glyph_row scratch_glyph_row
;
641 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
643 /* Ascent and height of the last line processed by move_it_to. */
645 static int last_max_ascent
, last_height
;
647 /* Non-zero if there's a help-echo in the echo area. */
649 int help_echo_showing_p
;
651 /* If >= 0, computed, exact values of mode-line and header-line height
652 to use in the macros CURRENT_MODE_LINE_HEIGHT and
653 CURRENT_HEADER_LINE_HEIGHT. */
655 int current_mode_line_height
, current_header_line_height
;
657 /* The maximum distance to look ahead for text properties. Values
658 that are too small let us call compute_char_face and similar
659 functions too often which is expensive. Values that are too large
660 let us call compute_char_face and alike too often because we
661 might not be interested in text properties that far away. */
663 #define TEXT_PROP_DISTANCE_LIMIT 100
667 /* Variables to turn off display optimizations from Lisp. */
669 int inhibit_try_window_id
, inhibit_try_window_reusing
;
670 int inhibit_try_cursor_movement
;
672 /* Non-zero means print traces of redisplay if compiled with
675 int trace_redisplay_p
;
677 #endif /* GLYPH_DEBUG */
679 #ifdef DEBUG_TRACE_MOVE
680 /* Non-zero means trace with TRACE_MOVE to stderr. */
683 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
685 #define TRACE_MOVE(x) (void) 0
688 /* Non-zero means automatically scroll windows horizontally to make
691 int automatic_hscrolling_p
;
692 Lisp_Object Qauto_hscroll_mode
;
694 /* How close to the margin can point get before the window is scrolled
696 EMACS_INT hscroll_margin
;
698 /* How much to scroll horizontally when point is inside the above margin. */
699 Lisp_Object Vhscroll_step
;
701 /* The variable `resize-mini-windows'. If nil, don't resize
702 mini-windows. If t, always resize them to fit the text they
703 display. If `grow-only', let mini-windows grow only until they
706 Lisp_Object Vresize_mini_windows
;
708 /* Buffer being redisplayed -- for redisplay_window_error. */
710 struct buffer
*displayed_buffer
;
712 /* Space between overline and text. */
714 EMACS_INT overline_margin
;
716 /* Value returned from text property handlers (see below). */
721 HANDLED_RECOMPUTE_PROPS
,
722 HANDLED_OVERLAY_STRING_CONSUMED
,
726 /* A description of text properties that redisplay is interested
731 /* The name of the property. */
734 /* A unique index for the property. */
737 /* A handler function called to set up iterator IT from the property
738 at IT's current position. Value is used to steer handle_stop. */
739 enum prop_handled (*handler
) P_ ((struct it
*it
));
742 static enum prop_handled handle_face_prop
P_ ((struct it
*));
743 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
744 static enum prop_handled handle_display_prop
P_ ((struct it
*));
745 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
746 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
747 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
749 /* Properties handled by iterators. */
751 static struct props it_props
[] =
753 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
754 /* Handle `face' before `display' because some sub-properties of
755 `display' need to know the face. */
756 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
757 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
758 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
759 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
763 /* Value is the position described by X. If X is a marker, value is
764 the marker_position of X. Otherwise, value is X. */
766 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
768 /* Enumeration returned by some move_it_.* functions internally. */
772 /* Not used. Undefined value. */
775 /* Move ended at the requested buffer position or ZV. */
776 MOVE_POS_MATCH_OR_ZV
,
778 /* Move ended at the requested X pixel position. */
781 /* Move within a line ended at the end of a line that must be
785 /* Move within a line ended at the end of a line that would
786 be displayed truncated. */
789 /* Move within a line ended at a line end. */
793 /* This counter is used to clear the face cache every once in a while
794 in redisplay_internal. It is incremented for each redisplay.
795 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
798 #define CLEAR_FACE_CACHE_COUNT 500
799 static int clear_face_cache_count
;
801 /* Similarly for the image cache. */
803 #ifdef HAVE_WINDOW_SYSTEM
804 #define CLEAR_IMAGE_CACHE_COUNT 101
805 static int clear_image_cache_count
;
808 /* Non-zero while redisplay_internal is in progress. */
812 /* Non-zero means don't free realized faces. Bound while freeing
813 realized faces is dangerous because glyph matrices might still
816 int inhibit_free_realized_faces
;
817 Lisp_Object Qinhibit_free_realized_faces
;
819 /* If a string, XTread_socket generates an event to display that string.
820 (The display is done in read_char.) */
822 Lisp_Object help_echo_string
;
823 Lisp_Object help_echo_window
;
824 Lisp_Object help_echo_object
;
827 /* Temporary variable for XTread_socket. */
829 Lisp_Object previous_help_echo_string
;
831 /* Null glyph slice */
833 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
836 /* Function prototypes. */
838 static void setup_for_ellipsis
P_ ((struct it
*, int));
839 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
840 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
841 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
842 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
843 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
844 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
847 static int invisible_text_between_p
P_ ((struct it
*, int, int));
850 static void pint2str
P_ ((char *, int, int));
851 static void pint2hrstr
P_ ((char *, int, int));
852 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
854 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
855 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
856 static void store_mode_line_noprop_char
P_ ((char));
857 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
858 static void x_consider_frame_title
P_ ((Lisp_Object
));
859 static void handle_stop
P_ ((struct it
*));
860 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
861 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
862 static void ensure_echo_area_buffers
P_ ((void));
863 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
864 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
865 static int with_echo_area_buffer
P_ ((struct window
*, int,
866 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
867 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
868 static void clear_garbaged_frames
P_ ((void));
869 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
870 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
871 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
872 static int display_echo_area
P_ ((struct window
*));
873 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
874 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
875 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
876 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
877 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
879 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
880 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
881 static void insert_left_trunc_glyphs
P_ ((struct it
*));
882 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
884 static void extend_face_to_end_of_line
P_ ((struct it
*));
885 static int append_space_for_newline
P_ ((struct it
*, int));
886 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
887 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
888 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
889 static int trailing_whitespace_p
P_ ((int));
890 static int message_log_check_duplicate
P_ ((int, int, int, int));
891 static void push_it
P_ ((struct it
*));
892 static void pop_it
P_ ((struct it
*));
893 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
894 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
895 static void redisplay_internal
P_ ((int));
896 static int echo_area_display
P_ ((int));
897 static void redisplay_windows
P_ ((Lisp_Object
));
898 static void redisplay_window
P_ ((Lisp_Object
, int));
899 static Lisp_Object
redisplay_window_error ();
900 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
901 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
902 static int update_menu_bar
P_ ((struct frame
*, int, int));
903 static int try_window_reusing_current_matrix
P_ ((struct window
*));
904 static int try_window_id
P_ ((struct window
*));
905 static int display_line
P_ ((struct it
*));
906 static int display_mode_lines
P_ ((struct window
*));
907 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
908 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
909 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
910 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
911 static void display_menu_bar
P_ ((struct window
*));
912 static int display_count_lines
P_ ((int, int, int, int, int *));
913 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
914 int, int, struct it
*, int, int, int, int));
915 static void compute_line_metrics
P_ ((struct it
*));
916 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
917 static int get_overlay_strings
P_ ((struct it
*, int));
918 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
919 static void next_overlay_string
P_ ((struct it
*));
920 static void reseat
P_ ((struct it
*, struct text_pos
, int));
921 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
922 static void back_to_previous_visible_line_start
P_ ((struct it
*));
923 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
924 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
925 static int next_element_from_ellipsis
P_ ((struct it
*));
926 static int next_element_from_display_vector
P_ ((struct it
*));
927 static int next_element_from_string
P_ ((struct it
*));
928 static int next_element_from_c_string
P_ ((struct it
*));
929 static int next_element_from_buffer
P_ ((struct it
*));
930 static int next_element_from_composition
P_ ((struct it
*));
931 static int next_element_from_image
P_ ((struct it
*));
932 static int next_element_from_stretch
P_ ((struct it
*));
933 static void load_overlay_strings
P_ ((struct it
*, int));
934 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
935 struct display_pos
*));
936 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
937 Lisp_Object
, int, int, int, int));
938 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
940 void move_it_vertically_backward
P_ ((struct it
*, int));
941 static void init_to_row_start
P_ ((struct it
*, struct window
*,
942 struct glyph_row
*));
943 static int init_to_row_end
P_ ((struct it
*, struct window
*,
944 struct glyph_row
*));
945 static void back_to_previous_line_start
P_ ((struct it
*));
946 static int forward_to_next_line_start
P_ ((struct it
*, int *));
947 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
949 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
950 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
951 static int number_of_chars
P_ ((unsigned char *, int));
952 static void compute_stop_pos
P_ ((struct it
*));
953 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
955 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
956 static int next_overlay_change
P_ ((int));
957 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
958 Lisp_Object
, Lisp_Object
,
959 struct text_pos
*, int));
960 static int underlying_face_id
P_ ((struct it
*));
961 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
964 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
965 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
967 #ifdef HAVE_WINDOW_SYSTEM
969 static void update_tool_bar
P_ ((struct frame
*, int));
970 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
971 static int redisplay_tool_bar
P_ ((struct frame
*));
972 static void display_tool_bar_line
P_ ((struct it
*, int));
973 static void notice_overwritten_cursor
P_ ((struct window
*,
975 int, int, int, int));
979 #endif /* HAVE_WINDOW_SYSTEM */
982 /***********************************************************************
983 Window display dimensions
984 ***********************************************************************/
986 /* Return the bottom boundary y-position for text lines in window W.
987 This is the first y position at which a line cannot start.
988 It is relative to the top of the window.
990 This is the height of W minus the height of a mode line, if any. */
993 window_text_bottom_y (w
)
996 int height
= WINDOW_TOTAL_HEIGHT (w
);
998 if (WINDOW_WANTS_MODELINE_P (w
))
999 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1003 /* Return the pixel width of display area AREA of window W. AREA < 0
1004 means return the total width of W, not including fringes to
1005 the left and right of the window. */
1008 window_box_width (w
, area
)
1012 int cols
= XFASTINT (w
->total_cols
);
1015 if (!w
->pseudo_window_p
)
1017 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1019 if (area
== TEXT_AREA
)
1021 if (INTEGERP (w
->left_margin_cols
))
1022 cols
-= XFASTINT (w
->left_margin_cols
);
1023 if (INTEGERP (w
->right_margin_cols
))
1024 cols
-= XFASTINT (w
->right_margin_cols
);
1025 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1027 else if (area
== LEFT_MARGIN_AREA
)
1029 cols
= (INTEGERP (w
->left_margin_cols
)
1030 ? XFASTINT (w
->left_margin_cols
) : 0);
1033 else if (area
== RIGHT_MARGIN_AREA
)
1035 cols
= (INTEGERP (w
->right_margin_cols
)
1036 ? XFASTINT (w
->right_margin_cols
) : 0);
1041 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1045 /* Return the pixel height of the display area of window W, not
1046 including mode lines of W, if any. */
1049 window_box_height (w
)
1052 struct frame
*f
= XFRAME (w
->frame
);
1053 int height
= WINDOW_TOTAL_HEIGHT (w
);
1055 xassert (height
>= 0);
1057 /* Note: the code below that determines the mode-line/header-line
1058 height is essentially the same as that contained in the macro
1059 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1060 the appropriate glyph row has its `mode_line_p' flag set,
1061 and if it doesn't, uses estimate_mode_line_height instead. */
1063 if (WINDOW_WANTS_MODELINE_P (w
))
1065 struct glyph_row
*ml_row
1066 = (w
->current_matrix
&& w
->current_matrix
->rows
1067 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1069 if (ml_row
&& ml_row
->mode_line_p
)
1070 height
-= ml_row
->height
;
1072 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1075 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1077 struct glyph_row
*hl_row
1078 = (w
->current_matrix
&& w
->current_matrix
->rows
1079 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1081 if (hl_row
&& hl_row
->mode_line_p
)
1082 height
-= hl_row
->height
;
1084 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1087 /* With a very small font and a mode-line that's taller than
1088 default, we might end up with a negative height. */
1089 return max (0, height
);
1092 /* Return the window-relative coordinate of the left edge of display
1093 area AREA of window W. AREA < 0 means return the left edge of the
1094 whole window, to the right of the left fringe of W. */
1097 window_box_left_offset (w
, area
)
1103 if (w
->pseudo_window_p
)
1106 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1108 if (area
== TEXT_AREA
)
1109 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1110 + window_box_width (w
, LEFT_MARGIN_AREA
));
1111 else if (area
== RIGHT_MARGIN_AREA
)
1112 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1113 + window_box_width (w
, LEFT_MARGIN_AREA
)
1114 + window_box_width (w
, TEXT_AREA
)
1115 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1117 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1118 else if (area
== LEFT_MARGIN_AREA
1119 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1120 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1126 /* Return the window-relative coordinate of the right edge of display
1127 area AREA of window W. AREA < 0 means return the left edge of the
1128 whole window, to the left of the right fringe of W. */
1131 window_box_right_offset (w
, area
)
1135 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1138 /* Return the frame-relative coordinate of the left edge of display
1139 area AREA of window W. AREA < 0 means return the left edge of the
1140 whole window, to the right of the left fringe of W. */
1143 window_box_left (w
, area
)
1147 struct frame
*f
= XFRAME (w
->frame
);
1150 if (w
->pseudo_window_p
)
1151 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1153 x
= (WINDOW_LEFT_EDGE_X (w
)
1154 + window_box_left_offset (w
, area
));
1160 /* Return the frame-relative coordinate of the right edge of display
1161 area AREA of window W. AREA < 0 means return the left edge of the
1162 whole window, to the left of the right fringe of W. */
1165 window_box_right (w
, area
)
1169 return window_box_left (w
, area
) + window_box_width (w
, area
);
1172 /* Get the bounding box of the display area AREA of window W, without
1173 mode lines, in frame-relative coordinates. AREA < 0 means the
1174 whole window, not including the left and right fringes of
1175 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1176 coordinates of the upper-left corner of the box. Return in
1177 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1180 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1183 int *box_x
, *box_y
, *box_width
, *box_height
;
1186 *box_width
= window_box_width (w
, area
);
1188 *box_height
= window_box_height (w
);
1190 *box_x
= window_box_left (w
, area
);
1193 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1194 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1195 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1200 /* Get the bounding box of the display area AREA of window W, without
1201 mode lines. AREA < 0 means the whole window, not including the
1202 left and right fringe of the window. Return in *TOP_LEFT_X
1203 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1204 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1205 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1209 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1210 bottom_right_x
, bottom_right_y
)
1213 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1215 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1217 *bottom_right_x
+= *top_left_x
;
1218 *bottom_right_y
+= *top_left_y
;
1223 /***********************************************************************
1225 ***********************************************************************/
1227 /* Return the bottom y-position of the line the iterator IT is in.
1228 This can modify IT's settings. */
1234 int line_height
= it
->max_ascent
+ it
->max_descent
;
1235 int line_top_y
= it
->current_y
;
1237 if (line_height
== 0)
1240 line_height
= last_height
;
1241 else if (IT_CHARPOS (*it
) < ZV
)
1243 move_it_by_lines (it
, 1, 1);
1244 line_height
= (it
->max_ascent
|| it
->max_descent
1245 ? it
->max_ascent
+ it
->max_descent
1250 struct glyph_row
*row
= it
->glyph_row
;
1252 /* Use the default character height. */
1253 it
->glyph_row
= NULL
;
1254 it
->what
= IT_CHARACTER
;
1257 PRODUCE_GLYPHS (it
);
1258 line_height
= it
->ascent
+ it
->descent
;
1259 it
->glyph_row
= row
;
1263 return line_top_y
+ line_height
;
1267 /* Return 1 if position CHARPOS is visible in window W.
1268 CHARPOS < 0 means return info about WINDOW_END position.
1269 If visible, set *X and *Y to pixel coordinates of top left corner.
1270 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1271 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1274 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1276 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1279 struct text_pos top
;
1281 struct buffer
*old_buffer
= NULL
;
1286 if (XBUFFER (w
->buffer
) != current_buffer
)
1288 old_buffer
= current_buffer
;
1289 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1292 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1294 /* Compute exact mode line heights. */
1295 if (WINDOW_WANTS_MODELINE_P (w
))
1296 current_mode_line_height
1297 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1298 current_buffer
->mode_line_format
);
1300 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1301 current_header_line_height
1302 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1303 current_buffer
->header_line_format
);
1305 start_display (&it
, w
, top
);
1306 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1307 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1309 /* Note that we may overshoot because of invisible text. */
1310 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1312 int top_x
= it
.current_x
;
1313 int top_y
= it
.current_y
;
1314 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1315 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1317 if (top_y
< window_top_y
)
1318 visible_p
= bottom_y
> window_top_y
;
1319 else if (top_y
< it
.last_visible_y
)
1324 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1325 *rtop
= max (0, window_top_y
- top_y
);
1326 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1327 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1328 - max (top_y
, window_top_y
)));
1337 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1338 move_it_by_lines (&it
, 1, 0);
1339 if (charpos
< IT_CHARPOS (it
)
1340 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1343 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1345 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1346 *rtop
= max (0, -it2
.current_y
);
1347 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1348 - it
.last_visible_y
));
1349 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1351 - max (it2
.current_y
,
1352 WINDOW_HEADER_LINE_HEIGHT (w
))));
1358 set_buffer_internal_1 (old_buffer
);
1360 current_header_line_height
= current_mode_line_height
= -1;
1362 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1363 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1366 /* Debugging code. */
1368 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1369 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1371 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1378 /* Return the next character from STR which is MAXLEN bytes long.
1379 Return in *LEN the length of the character. This is like
1380 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1381 we find one, we return a `?', but with the length of the invalid
1385 string_char_and_length (str
, maxlen
, len
)
1386 const unsigned char *str
;
1391 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1392 if (!CHAR_VALID_P (c
, 1))
1393 /* We may not change the length here because other places in Emacs
1394 don't use this function, i.e. they silently accept invalid
1403 /* Given a position POS containing a valid character and byte position
1404 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1406 static struct text_pos
1407 string_pos_nchars_ahead (pos
, string
, nchars
)
1408 struct text_pos pos
;
1412 xassert (STRINGP (string
) && nchars
>= 0);
1414 if (STRING_MULTIBYTE (string
))
1416 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1417 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1422 string_char_and_length (p
, rest
, &len
);
1423 p
+= len
, rest
-= len
;
1424 xassert (rest
>= 0);
1426 BYTEPOS (pos
) += len
;
1430 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1436 /* Value is the text position, i.e. character and byte position,
1437 for character position CHARPOS in STRING. */
1439 static INLINE
struct text_pos
1440 string_pos (charpos
, string
)
1444 struct text_pos pos
;
1445 xassert (STRINGP (string
));
1446 xassert (charpos
>= 0);
1447 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1452 /* Value is a text position, i.e. character and byte position, for
1453 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1454 means recognize multibyte characters. */
1456 static struct text_pos
1457 c_string_pos (charpos
, s
, multibyte_p
)
1462 struct text_pos pos
;
1464 xassert (s
!= NULL
);
1465 xassert (charpos
>= 0);
1469 int rest
= strlen (s
), len
;
1471 SET_TEXT_POS (pos
, 0, 0);
1474 string_char_and_length (s
, rest
, &len
);
1475 s
+= len
, rest
-= len
;
1476 xassert (rest
>= 0);
1478 BYTEPOS (pos
) += len
;
1482 SET_TEXT_POS (pos
, charpos
, charpos
);
1488 /* Value is the number of characters in C string S. MULTIBYTE_P
1489 non-zero means recognize multibyte characters. */
1492 number_of_chars (s
, multibyte_p
)
1500 int rest
= strlen (s
), len
;
1501 unsigned char *p
= (unsigned char *) s
;
1503 for (nchars
= 0; rest
> 0; ++nchars
)
1505 string_char_and_length (p
, rest
, &len
);
1506 rest
-= len
, p
+= len
;
1510 nchars
= strlen (s
);
1516 /* Compute byte position NEWPOS->bytepos corresponding to
1517 NEWPOS->charpos. POS is a known position in string STRING.
1518 NEWPOS->charpos must be >= POS.charpos. */
1521 compute_string_pos (newpos
, pos
, string
)
1522 struct text_pos
*newpos
, pos
;
1525 xassert (STRINGP (string
));
1526 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1528 if (STRING_MULTIBYTE (string
))
1529 *newpos
= string_pos_nchars_ahead (pos
, string
,
1530 CHARPOS (*newpos
) - CHARPOS (pos
));
1532 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1536 Return an estimation of the pixel height of mode or top lines on
1537 frame F. FACE_ID specifies what line's height to estimate. */
1540 estimate_mode_line_height (f
, face_id
)
1542 enum face_id face_id
;
1544 #ifdef HAVE_WINDOW_SYSTEM
1545 if (FRAME_WINDOW_P (f
))
1547 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1549 /* This function is called so early when Emacs starts that the face
1550 cache and mode line face are not yet initialized. */
1551 if (FRAME_FACE_CACHE (f
))
1553 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1557 height
= FONT_HEIGHT (face
->font
);
1558 if (face
->box_line_width
> 0)
1559 height
+= 2 * face
->box_line_width
;
1570 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1571 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1572 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1573 not force the value into range. */
1576 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1578 register int pix_x
, pix_y
;
1580 NativeRectangle
*bounds
;
1584 #ifdef HAVE_WINDOW_SYSTEM
1585 if (FRAME_WINDOW_P (f
))
1587 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1588 even for negative values. */
1590 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1592 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1594 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1595 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1598 STORE_NATIVE_RECT (*bounds
,
1599 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1600 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1601 FRAME_COLUMN_WIDTH (f
) - 1,
1602 FRAME_LINE_HEIGHT (f
) - 1);
1608 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1609 pix_x
= FRAME_TOTAL_COLS (f
);
1613 else if (pix_y
> FRAME_LINES (f
))
1614 pix_y
= FRAME_LINES (f
);
1624 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1625 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1626 can't tell the positions because W's display is not up to date,
1630 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1633 int *frame_x
, *frame_y
;
1635 #ifdef HAVE_WINDOW_SYSTEM
1636 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1640 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1641 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1643 if (display_completed
)
1645 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1646 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1647 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1653 hpos
+= glyph
->pixel_width
;
1657 /* If first glyph is partially visible, its first visible position is still 0. */
1669 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1670 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1681 #ifdef HAVE_WINDOW_SYSTEM
1683 /* Find the glyph under window-relative coordinates X/Y in window W.
1684 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1685 strings. Return in *HPOS and *VPOS the row and column number of
1686 the glyph found. Return in *AREA the glyph area containing X.
1687 Value is a pointer to the glyph found or null if X/Y is not on
1688 text, or we can't tell because W's current matrix is not up to
1691 static struct glyph
*
1692 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1695 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1697 struct glyph
*glyph
, *end
;
1698 struct glyph_row
*row
= NULL
;
1701 /* Find row containing Y. Give up if some row is not enabled. */
1702 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1704 row
= MATRIX_ROW (w
->current_matrix
, i
);
1705 if (!row
->enabled_p
)
1707 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1714 /* Give up if Y is not in the window. */
1715 if (i
== w
->current_matrix
->nrows
)
1718 /* Get the glyph area containing X. */
1719 if (w
->pseudo_window_p
)
1726 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1728 *area
= LEFT_MARGIN_AREA
;
1729 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1731 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1734 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1738 *area
= RIGHT_MARGIN_AREA
;
1739 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1743 /* Find glyph containing X. */
1744 glyph
= row
->glyphs
[*area
];
1745 end
= glyph
+ row
->used
[*area
];
1747 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1749 x
-= glyph
->pixel_width
;
1759 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1762 *hpos
= glyph
- row
->glyphs
[*area
];
1768 Convert frame-relative x/y to coordinates relative to window W.
1769 Takes pseudo-windows into account. */
1772 frame_to_window_pixel_xy (w
, x
, y
)
1776 if (w
->pseudo_window_p
)
1778 /* A pseudo-window is always full-width, and starts at the
1779 left edge of the frame, plus a frame border. */
1780 struct frame
*f
= XFRAME (w
->frame
);
1781 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1782 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1786 *x
-= WINDOW_LEFT_EDGE_X (w
);
1787 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1792 Return in RECTS[] at most N clipping rectangles for glyph string S.
1793 Return the number of stored rectangles. */
1796 get_glyph_string_clip_rects (s
, rects
, n
)
1797 struct glyph_string
*s
;
1798 NativeRectangle
*rects
;
1806 if (s
->row
->full_width_p
)
1808 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1809 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1810 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1812 /* Unless displaying a mode or menu bar line, which are always
1813 fully visible, clip to the visible part of the row. */
1814 if (s
->w
->pseudo_window_p
)
1815 r
.height
= s
->row
->visible_height
;
1817 r
.height
= s
->height
;
1821 /* This is a text line that may be partially visible. */
1822 r
.x
= window_box_left (s
->w
, s
->area
);
1823 r
.width
= window_box_width (s
->w
, s
->area
);
1824 r
.height
= s
->row
->visible_height
;
1828 if (r
.x
< s
->clip_head
->x
)
1830 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1831 r
.width
-= s
->clip_head
->x
- r
.x
;
1834 r
.x
= s
->clip_head
->x
;
1837 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1839 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1840 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1845 /* If S draws overlapping rows, it's sufficient to use the top and
1846 bottom of the window for clipping because this glyph string
1847 intentionally draws over other lines. */
1848 if (s
->for_overlaps
)
1850 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1851 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1853 /* Alas, the above simple strategy does not work for the
1854 environments with anti-aliased text: if the same text is
1855 drawn onto the same place multiple times, it gets thicker.
1856 If the overlap we are processing is for the erased cursor, we
1857 take the intersection with the rectagle of the cursor. */
1858 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1860 XRectangle rc
, r_save
= r
;
1862 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1863 rc
.y
= s
->w
->phys_cursor
.y
;
1864 rc
.width
= s
->w
->phys_cursor_width
;
1865 rc
.height
= s
->w
->phys_cursor_height
;
1867 x_intersect_rectangles (&r_save
, &rc
, &r
);
1872 /* Don't use S->y for clipping because it doesn't take partially
1873 visible lines into account. For example, it can be negative for
1874 partially visible lines at the top of a window. */
1875 if (!s
->row
->full_width_p
1876 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1877 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1879 r
.y
= max (0, s
->row
->y
);
1881 /* If drawing a tool-bar window, draw it over the internal border
1882 at the top of the window. */
1883 if (WINDOWP (s
->f
->tool_bar_window
)
1884 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1885 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1888 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1890 /* If drawing the cursor, don't let glyph draw outside its
1891 advertised boundaries. Cleartype does this under some circumstances. */
1892 if (s
->hl
== DRAW_CURSOR
)
1894 struct glyph
*glyph
= s
->first_glyph
;
1899 r
.width
-= s
->x
- r
.x
;
1902 r
.width
= min (r
.width
, glyph
->pixel_width
);
1904 /* If r.y is below window bottom, ensure that we still see a cursor. */
1905 height
= min (glyph
->ascent
+ glyph
->descent
,
1906 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1907 max_y
= window_text_bottom_y (s
->w
) - height
;
1908 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1909 if (s
->ybase
- glyph
->ascent
> max_y
)
1916 /* Don't draw cursor glyph taller than our actual glyph. */
1917 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1918 if (height
< r
.height
)
1920 max_y
= r
.y
+ r
.height
;
1921 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1922 r
.height
= min (max_y
- r
.y
, height
);
1927 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1928 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1930 #ifdef CONVERT_FROM_XRECT
1931 CONVERT_FROM_XRECT (r
, *rects
);
1939 /* If we are processing overlapping and allowed to return
1940 multiple clipping rectangles, we exclude the row of the glyph
1941 string from the clipping rectangle. This is to avoid drawing
1942 the same text on the environment with anti-aliasing. */
1943 #ifdef CONVERT_FROM_XRECT
1946 XRectangle
*rs
= rects
;
1948 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
1950 if (s
->for_overlaps
& OVERLAPS_PRED
)
1953 if (r
.y
+ r
.height
> row_y
)
1956 rs
[i
].height
= row_y
- r
.y
;
1962 if (s
->for_overlaps
& OVERLAPS_SUCC
)
1965 if (r
.y
< row_y
+ s
->row
->visible_height
)
1967 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
1969 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
1970 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
1979 #ifdef CONVERT_FROM_XRECT
1980 for (i
= 0; i
< n
; i
++)
1981 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
1988 Return in *NR the clipping rectangle for glyph string S. */
1991 get_glyph_string_clip_rect (s
, nr
)
1992 struct glyph_string
*s
;
1993 NativeRectangle
*nr
;
1995 get_glyph_string_clip_rects (s
, nr
, 1);
2000 Return the position and height of the phys cursor in window W.
2001 Set w->phys_cursor_width to width of phys cursor.
2005 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2007 struct glyph_row
*row
;
2008 struct glyph
*glyph
;
2009 int *xp
, *yp
, *heightp
;
2011 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2012 int x
, y
, wd
, h
, h0
, y0
;
2014 /* Compute the width of the rectangle to draw. If on a stretch
2015 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2016 rectangle as wide as the glyph, but use a canonical character
2018 wd
= glyph
->pixel_width
- 1;
2023 x
= w
->phys_cursor
.x
;
2030 if (glyph
->type
== STRETCH_GLYPH
2031 && !x_stretch_cursor_p
)
2032 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2033 w
->phys_cursor_width
= wd
;
2035 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2037 /* If y is below window bottom, ensure that we still see a cursor. */
2038 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2040 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2041 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2043 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2046 h
= max (h
- (y0
- y
) + 1, h0
);
2051 y0
= window_text_bottom_y (w
) - h0
;
2059 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2060 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2065 * Remember which glyph the mouse is over.
2069 remember_mouse_glyph (f
, gx
, gy
, rect
)
2072 NativeRectangle
*rect
;
2076 struct glyph_row
*r
, *gr
, *end_row
;
2077 enum window_part part
;
2078 enum glyph_row_area area
;
2079 int x
, y
, width
, height
;
2081 /* Try to determine frame pixel position and size of the glyph under
2082 frame pixel coordinates X/Y on frame F. */
2084 if (!f
->glyphs_initialized_p
2085 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2088 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2089 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2093 w
= XWINDOW (window
);
2094 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2095 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2097 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2098 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2100 if (w
->pseudo_window_p
)
2103 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2109 case ON_LEFT_MARGIN
:
2110 area
= LEFT_MARGIN_AREA
;
2113 case ON_RIGHT_MARGIN
:
2114 area
= RIGHT_MARGIN_AREA
;
2117 case ON_HEADER_LINE
:
2119 gr
= (part
== ON_HEADER_LINE
2120 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2121 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2124 goto text_glyph_row_found
;
2131 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2132 if (r
->y
+ r
->height
> y
)
2138 text_glyph_row_found
:
2141 struct glyph
*g
= gr
->glyphs
[area
];
2142 struct glyph
*end
= g
+ gr
->used
[area
];
2144 height
= gr
->height
;
2145 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2146 if (gx
+ g
->pixel_width
> x
)
2151 if (g
->type
== IMAGE_GLYPH
)
2153 /* Don't remember when mouse is over image, as
2154 image may have hot-spots. */
2155 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2158 width
= g
->pixel_width
;
2162 /* Use nominal char spacing at end of line. */
2164 gx
+= (x
/ width
) * width
;
2167 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2168 gx
+= window_box_left_offset (w
, area
);
2172 /* Use nominal line height at end of window. */
2173 gx
= (x
/ width
) * width
;
2175 gy
+= (y
/ height
) * height
;
2179 case ON_LEFT_FRINGE
:
2180 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2181 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2182 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2183 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2186 case ON_RIGHT_FRINGE
:
2187 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2188 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2189 : window_box_right_offset (w
, TEXT_AREA
));
2190 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2194 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2196 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2197 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2198 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2200 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2204 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2205 if (r
->y
+ r
->height
> y
)
2212 height
= gr
->height
;
2215 /* Use nominal line height at end of window. */
2217 gy
+= (y
/ height
) * height
;
2224 /* If there is no glyph under the mouse, then we divide the screen
2225 into a grid of the smallest glyph in the frame, and use that
2228 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2229 round down even for negative values. */
2235 gx
= (gx
/ width
) * width
;
2236 gy
= (gy
/ height
) * height
;
2241 gx
+= WINDOW_LEFT_EDGE_X (w
);
2242 gy
+= WINDOW_TOP_EDGE_Y (w
);
2245 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2247 /* Visible feedback for debugging. */
2250 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2251 f
->output_data
.x
->normal_gc
,
2252 gx
, gy
, width
, height
);
2258 #endif /* HAVE_WINDOW_SYSTEM */
2261 /***********************************************************************
2262 Lisp form evaluation
2263 ***********************************************************************/
2265 /* Error handler for safe_eval and safe_call. */
2268 safe_eval_handler (arg
)
2271 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2276 /* Evaluate SEXPR and return the result, or nil if something went
2277 wrong. Prevent redisplay during the evaluation. */
2285 if (inhibit_eval_during_redisplay
)
2289 int count
= SPECPDL_INDEX ();
2290 struct gcpro gcpro1
;
2293 specbind (Qinhibit_redisplay
, Qt
);
2294 /* Use Qt to ensure debugger does not run,
2295 so there is no possibility of wanting to redisplay. */
2296 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
2299 val
= unbind_to (count
, val
);
2306 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2307 Return the result, or nil if something went wrong. Prevent
2308 redisplay during the evaluation. */
2311 safe_call (nargs
, args
)
2317 if (inhibit_eval_during_redisplay
)
2321 int count
= SPECPDL_INDEX ();
2322 struct gcpro gcpro1
;
2325 gcpro1
.nvars
= nargs
;
2326 specbind (Qinhibit_redisplay
, Qt
);
2327 /* Use Qt to ensure debugger does not run,
2328 so there is no possibility of wanting to redisplay. */
2329 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2332 val
= unbind_to (count
, val
);
2339 /* Call function FN with one argument ARG.
2340 Return the result, or nil if something went wrong. */
2343 safe_call1 (fn
, arg
)
2344 Lisp_Object fn
, arg
;
2346 Lisp_Object args
[2];
2349 return safe_call (2, args
);
2354 /***********************************************************************
2356 ***********************************************************************/
2360 /* Define CHECK_IT to perform sanity checks on iterators.
2361 This is for debugging. It is too slow to do unconditionally. */
2367 if (it
->method
== GET_FROM_STRING
)
2369 xassert (STRINGP (it
->string
));
2370 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2374 xassert (IT_STRING_CHARPOS (*it
) < 0);
2375 if (it
->method
== GET_FROM_BUFFER
)
2377 /* Check that character and byte positions agree. */
2378 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2383 xassert (it
->current
.dpvec_index
>= 0);
2385 xassert (it
->current
.dpvec_index
< 0);
2388 #define CHECK_IT(IT) check_it ((IT))
2392 #define CHECK_IT(IT) (void) 0
2399 /* Check that the window end of window W is what we expect it
2400 to be---the last row in the current matrix displaying text. */
2403 check_window_end (w
)
2406 if (!MINI_WINDOW_P (w
)
2407 && !NILP (w
->window_end_valid
))
2409 struct glyph_row
*row
;
2410 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2411 XFASTINT (w
->window_end_vpos
)),
2413 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2414 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2418 #define CHECK_WINDOW_END(W) check_window_end ((W))
2420 #else /* not GLYPH_DEBUG */
2422 #define CHECK_WINDOW_END(W) (void) 0
2424 #endif /* not GLYPH_DEBUG */
2428 /***********************************************************************
2429 Iterator initialization
2430 ***********************************************************************/
2432 /* Initialize IT for displaying current_buffer in window W, starting
2433 at character position CHARPOS. CHARPOS < 0 means that no buffer
2434 position is specified which is useful when the iterator is assigned
2435 a position later. BYTEPOS is the byte position corresponding to
2436 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2438 If ROW is not null, calls to produce_glyphs with IT as parameter
2439 will produce glyphs in that row.
2441 BASE_FACE_ID is the id of a base face to use. It must be one of
2442 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2443 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2444 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2446 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2447 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2448 will be initialized to use the corresponding mode line glyph row of
2449 the desired matrix of W. */
2452 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2455 int charpos
, bytepos
;
2456 struct glyph_row
*row
;
2457 enum face_id base_face_id
;
2459 int highlight_region_p
;
2461 /* Some precondition checks. */
2462 xassert (w
!= NULL
&& it
!= NULL
);
2463 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2466 /* If face attributes have been changed since the last redisplay,
2467 free realized faces now because they depend on face definitions
2468 that might have changed. Don't free faces while there might be
2469 desired matrices pending which reference these faces. */
2470 if (face_change_count
&& !inhibit_free_realized_faces
)
2472 face_change_count
= 0;
2473 free_all_realized_faces (Qnil
);
2476 /* Use one of the mode line rows of W's desired matrix if
2480 if (base_face_id
== MODE_LINE_FACE_ID
2481 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2482 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2483 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2484 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2488 bzero (it
, sizeof *it
);
2489 it
->current
.overlay_string_index
= -1;
2490 it
->current
.dpvec_index
= -1;
2491 it
->base_face_id
= base_face_id
;
2493 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2495 /* The window in which we iterate over current_buffer: */
2496 XSETWINDOW (it
->window
, w
);
2498 it
->f
= XFRAME (w
->frame
);
2500 /* Extra space between lines (on window systems only). */
2501 if (base_face_id
== DEFAULT_FACE_ID
2502 && FRAME_WINDOW_P (it
->f
))
2504 if (NATNUMP (current_buffer
->extra_line_spacing
))
2505 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2506 else if (FLOATP (current_buffer
->extra_line_spacing
))
2507 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2508 * FRAME_LINE_HEIGHT (it
->f
));
2509 else if (it
->f
->extra_line_spacing
> 0)
2510 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2511 it
->max_extra_line_spacing
= 0;
2514 /* If realized faces have been removed, e.g. because of face
2515 attribute changes of named faces, recompute them. When running
2516 in batch mode, the face cache of the initial frame is null. If
2517 we happen to get called, make a dummy face cache. */
2518 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2519 init_frame_faces (it
->f
);
2520 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2521 recompute_basic_faces (it
->f
);
2523 /* Current value of the `slice', `space-width', and 'height' properties. */
2524 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2525 it
->space_width
= Qnil
;
2526 it
->font_height
= Qnil
;
2527 it
->override_ascent
= -1;
2529 /* Are control characters displayed as `^C'? */
2530 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2532 /* -1 means everything between a CR and the following line end
2533 is invisible. >0 means lines indented more than this value are
2535 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2536 ? XFASTINT (current_buffer
->selective_display
)
2537 : (!NILP (current_buffer
->selective_display
)
2539 it
->selective_display_ellipsis_p
2540 = !NILP (current_buffer
->selective_display_ellipses
);
2542 /* Display table to use. */
2543 it
->dp
= window_display_table (w
);
2545 /* Are multibyte characters enabled in current_buffer? */
2546 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2548 /* Non-zero if we should highlight the region. */
2550 = (!NILP (Vtransient_mark_mode
)
2551 && !NILP (current_buffer
->mark_active
)
2552 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2554 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2555 start and end of a visible region in window IT->w. Set both to
2556 -1 to indicate no region. */
2557 if (highlight_region_p
2558 /* Maybe highlight only in selected window. */
2559 && (/* Either show region everywhere. */
2560 highlight_nonselected_windows
2561 /* Or show region in the selected window. */
2562 || w
== XWINDOW (selected_window
)
2563 /* Or show the region if we are in the mini-buffer and W is
2564 the window the mini-buffer refers to. */
2565 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2566 && WINDOWP (minibuf_selected_window
)
2567 && w
== XWINDOW (minibuf_selected_window
))))
2569 int charpos
= marker_position (current_buffer
->mark
);
2570 it
->region_beg_charpos
= min (PT
, charpos
);
2571 it
->region_end_charpos
= max (PT
, charpos
);
2574 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2576 /* Get the position at which the redisplay_end_trigger hook should
2577 be run, if it is to be run at all. */
2578 if (MARKERP (w
->redisplay_end_trigger
)
2579 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2580 it
->redisplay_end_trigger_charpos
2581 = marker_position (w
->redisplay_end_trigger
);
2582 else if (INTEGERP (w
->redisplay_end_trigger
))
2583 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2585 /* Correct bogus values of tab_width. */
2586 it
->tab_width
= XINT (current_buffer
->tab_width
);
2587 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2590 /* Are lines in the display truncated? */
2591 it
->truncate_lines_p
2592 = (base_face_id
!= DEFAULT_FACE_ID
2593 || XINT (it
->w
->hscroll
)
2594 || (truncate_partial_width_windows
2595 && !WINDOW_FULL_WIDTH_P (it
->w
))
2596 || !NILP (current_buffer
->truncate_lines
));
2598 /* Get dimensions of truncation and continuation glyphs. These are
2599 displayed as fringe bitmaps under X, so we don't need them for such
2601 if (!FRAME_WINDOW_P (it
->f
))
2603 if (it
->truncate_lines_p
)
2605 /* We will need the truncation glyph. */
2606 xassert (it
->glyph_row
== NULL
);
2607 produce_special_glyphs (it
, IT_TRUNCATION
);
2608 it
->truncation_pixel_width
= it
->pixel_width
;
2612 /* We will need the continuation glyph. */
2613 xassert (it
->glyph_row
== NULL
);
2614 produce_special_glyphs (it
, IT_CONTINUATION
);
2615 it
->continuation_pixel_width
= it
->pixel_width
;
2618 /* Reset these values to zero because the produce_special_glyphs
2619 above has changed them. */
2620 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2621 it
->phys_ascent
= it
->phys_descent
= 0;
2624 /* Set this after getting the dimensions of truncation and
2625 continuation glyphs, so that we don't produce glyphs when calling
2626 produce_special_glyphs, above. */
2627 it
->glyph_row
= row
;
2628 it
->area
= TEXT_AREA
;
2630 /* Get the dimensions of the display area. The display area
2631 consists of the visible window area plus a horizontally scrolled
2632 part to the left of the window. All x-values are relative to the
2633 start of this total display area. */
2634 if (base_face_id
!= DEFAULT_FACE_ID
)
2636 /* Mode lines, menu bar in terminal frames. */
2637 it
->first_visible_x
= 0;
2638 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2643 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2644 it
->last_visible_x
= (it
->first_visible_x
2645 + window_box_width (w
, TEXT_AREA
));
2647 /* If we truncate lines, leave room for the truncator glyph(s) at
2648 the right margin. Otherwise, leave room for the continuation
2649 glyph(s). Truncation and continuation glyphs are not inserted
2650 for window-based redisplay. */
2651 if (!FRAME_WINDOW_P (it
->f
))
2653 if (it
->truncate_lines_p
)
2654 it
->last_visible_x
-= it
->truncation_pixel_width
;
2656 it
->last_visible_x
-= it
->continuation_pixel_width
;
2659 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2660 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2663 /* Leave room for a border glyph. */
2664 if (!FRAME_WINDOW_P (it
->f
)
2665 && !WINDOW_RIGHTMOST_P (it
->w
))
2666 it
->last_visible_x
-= 1;
2668 it
->last_visible_y
= window_text_bottom_y (w
);
2670 /* For mode lines and alike, arrange for the first glyph having a
2671 left box line if the face specifies a box. */
2672 if (base_face_id
!= DEFAULT_FACE_ID
)
2676 it
->face_id
= base_face_id
;
2678 /* If we have a boxed mode line, make the first character appear
2679 with a left box line. */
2680 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2681 if (face
->box
!= FACE_NO_BOX
)
2682 it
->start_of_box_run_p
= 1;
2685 /* If a buffer position was specified, set the iterator there,
2686 getting overlays and face properties from that position. */
2687 if (charpos
>= BUF_BEG (current_buffer
))
2689 it
->end_charpos
= ZV
;
2691 IT_CHARPOS (*it
) = charpos
;
2693 /* Compute byte position if not specified. */
2694 if (bytepos
< charpos
)
2695 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2697 IT_BYTEPOS (*it
) = bytepos
;
2699 it
->start
= it
->current
;
2701 /* Compute faces etc. */
2702 reseat (it
, it
->current
.pos
, 1);
2709 /* Initialize IT for the display of window W with window start POS. */
2712 start_display (it
, w
, pos
)
2715 struct text_pos pos
;
2717 struct glyph_row
*row
;
2718 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2720 row
= w
->desired_matrix
->rows
+ first_vpos
;
2721 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2722 it
->first_vpos
= first_vpos
;
2724 /* Don't reseat to previous visible line start if current start
2725 position is in a string or image. */
2726 if (it
->method
== GET_FROM_BUFFER
&& !it
->truncate_lines_p
)
2728 int start_at_line_beg_p
;
2729 int first_y
= it
->current_y
;
2731 /* If window start is not at a line start, skip forward to POS to
2732 get the correct continuation lines width. */
2733 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2734 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2735 if (!start_at_line_beg_p
)
2739 reseat_at_previous_visible_line_start (it
);
2740 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2742 new_x
= it
->current_x
+ it
->pixel_width
;
2744 /* If lines are continued, this line may end in the middle
2745 of a multi-glyph character (e.g. a control character
2746 displayed as \003, or in the middle of an overlay
2747 string). In this case move_it_to above will not have
2748 taken us to the start of the continuation line but to the
2749 end of the continued line. */
2750 if (it
->current_x
> 0
2751 && !it
->truncate_lines_p
/* Lines are continued. */
2752 && (/* And glyph doesn't fit on the line. */
2753 new_x
> it
->last_visible_x
2754 /* Or it fits exactly and we're on a window
2756 || (new_x
== it
->last_visible_x
2757 && FRAME_WINDOW_P (it
->f
))))
2759 if (it
->current
.dpvec_index
>= 0
2760 || it
->current
.overlay_string_index
>= 0)
2762 set_iterator_to_next (it
, 1);
2763 move_it_in_display_line_to (it
, -1, -1, 0);
2766 it
->continuation_lines_width
+= it
->current_x
;
2769 /* We're starting a new display line, not affected by the
2770 height of the continued line, so clear the appropriate
2771 fields in the iterator structure. */
2772 it
->max_ascent
= it
->max_descent
= 0;
2773 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2775 it
->current_y
= first_y
;
2777 it
->current_x
= it
->hpos
= 0;
2781 #if 0 /* Don't assert the following because start_display is sometimes
2782 called intentionally with a window start that is not at a
2783 line start. Please leave this code in as a comment. */
2785 /* Window start should be on a line start, now. */
2786 xassert (it
->continuation_lines_width
2787 || IT_CHARPOS (it
) == BEGV
2788 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2793 /* Return 1 if POS is a position in ellipses displayed for invisible
2794 text. W is the window we display, for text property lookup. */
2797 in_ellipses_for_invisible_text_p (pos
, w
)
2798 struct display_pos
*pos
;
2801 Lisp_Object prop
, window
;
2803 int charpos
= CHARPOS (pos
->pos
);
2805 /* If POS specifies a position in a display vector, this might
2806 be for an ellipsis displayed for invisible text. We won't
2807 get the iterator set up for delivering that ellipsis unless
2808 we make sure that it gets aware of the invisible text. */
2809 if (pos
->dpvec_index
>= 0
2810 && pos
->overlay_string_index
< 0
2811 && CHARPOS (pos
->string_pos
) < 0
2813 && (XSETWINDOW (window
, w
),
2814 prop
= Fget_char_property (make_number (charpos
),
2815 Qinvisible
, window
),
2816 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2818 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2820 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2827 /* Initialize IT for stepping through current_buffer in window W,
2828 starting at position POS that includes overlay string and display
2829 vector/ control character translation position information. Value
2830 is zero if there are overlay strings with newlines at POS. */
2833 init_from_display_pos (it
, w
, pos
)
2836 struct display_pos
*pos
;
2838 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2839 int i
, overlay_strings_with_newlines
= 0;
2841 /* If POS specifies a position in a display vector, this might
2842 be for an ellipsis displayed for invisible text. We won't
2843 get the iterator set up for delivering that ellipsis unless
2844 we make sure that it gets aware of the invisible text. */
2845 if (in_ellipses_for_invisible_text_p (pos
, w
))
2851 /* Keep in mind: the call to reseat in init_iterator skips invisible
2852 text, so we might end up at a position different from POS. This
2853 is only a problem when POS is a row start after a newline and an
2854 overlay starts there with an after-string, and the overlay has an
2855 invisible property. Since we don't skip invisible text in
2856 display_line and elsewhere immediately after consuming the
2857 newline before the row start, such a POS will not be in a string,
2858 but the call to init_iterator below will move us to the
2860 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2862 /* This only scans the current chunk -- it should scan all chunks.
2863 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2864 to 16 in 22.1 to make this a lesser problem. */
2865 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2867 const char *s
= SDATA (it
->overlay_strings
[i
]);
2868 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2870 while (s
< e
&& *s
!= '\n')
2875 overlay_strings_with_newlines
= 1;
2880 /* If position is within an overlay string, set up IT to the right
2882 if (pos
->overlay_string_index
>= 0)
2886 /* If the first overlay string happens to have a `display'
2887 property for an image, the iterator will be set up for that
2888 image, and we have to undo that setup first before we can
2889 correct the overlay string index. */
2890 if (it
->method
== GET_FROM_IMAGE
)
2893 /* We already have the first chunk of overlay strings in
2894 IT->overlay_strings. Load more until the one for
2895 pos->overlay_string_index is in IT->overlay_strings. */
2896 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2898 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2899 it
->current
.overlay_string_index
= 0;
2902 load_overlay_strings (it
, 0);
2903 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2907 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2908 relative_index
= (it
->current
.overlay_string_index
2909 % OVERLAY_STRING_CHUNK_SIZE
);
2910 it
->string
= it
->overlay_strings
[relative_index
];
2911 xassert (STRINGP (it
->string
));
2912 it
->current
.string_pos
= pos
->string_pos
;
2913 it
->method
= GET_FROM_STRING
;
2916 #if 0 /* This is bogus because POS not having an overlay string
2917 position does not mean it's after the string. Example: A
2918 line starting with a before-string and initialization of IT
2919 to the previous row's end position. */
2920 else if (it
->current
.overlay_string_index
>= 0)
2922 /* If POS says we're already after an overlay string ending at
2923 POS, make sure to pop the iterator because it will be in
2924 front of that overlay string. When POS is ZV, we've thereby
2925 also ``processed'' overlay strings at ZV. */
2928 xassert (it
->current
.overlay_string_index
== -1);
2929 xassert (it
->method
== GET_FROM_BUFFER
);
2930 if (CHARPOS (pos
->pos
) == ZV
)
2931 it
->overlay_strings_at_end_processed_p
= 1;
2935 if (CHARPOS (pos
->string_pos
) >= 0)
2937 /* Recorded position is not in an overlay string, but in another
2938 string. This can only be a string from a `display' property.
2939 IT should already be filled with that string. */
2940 it
->current
.string_pos
= pos
->string_pos
;
2941 xassert (STRINGP (it
->string
));
2944 /* Restore position in display vector translations, control
2945 character translations or ellipses. */
2946 if (pos
->dpvec_index
>= 0)
2948 if (it
->dpvec
== NULL
)
2949 get_next_display_element (it
);
2950 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2951 it
->current
.dpvec_index
= pos
->dpvec_index
;
2955 return !overlay_strings_with_newlines
;
2959 /* Initialize IT for stepping through current_buffer in window W
2960 starting at ROW->start. */
2963 init_to_row_start (it
, w
, row
)
2966 struct glyph_row
*row
;
2968 init_from_display_pos (it
, w
, &row
->start
);
2969 it
->start
= row
->start
;
2970 it
->continuation_lines_width
= row
->continuation_lines_width
;
2975 /* Initialize IT for stepping through current_buffer in window W
2976 starting in the line following ROW, i.e. starting at ROW->end.
2977 Value is zero if there are overlay strings with newlines at ROW's
2981 init_to_row_end (it
, w
, row
)
2984 struct glyph_row
*row
;
2988 if (init_from_display_pos (it
, w
, &row
->end
))
2990 if (row
->continued_p
)
2991 it
->continuation_lines_width
2992 = row
->continuation_lines_width
+ row
->pixel_width
;
3003 /***********************************************************************
3005 ***********************************************************************/
3007 /* Called when IT reaches IT->stop_charpos. Handle text property and
3008 overlay changes. Set IT->stop_charpos to the next position where
3015 enum prop_handled handled
;
3016 int handle_overlay_change_p
;
3020 it
->current
.dpvec_index
= -1;
3021 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3022 it
->ignore_overlay_strings_at_pos_p
= 0;
3024 /* Use face of preceding text for ellipsis (if invisible) */
3025 if (it
->selective_display_ellipsis_p
)
3026 it
->saved_face_id
= it
->face_id
;
3030 handled
= HANDLED_NORMALLY
;
3032 /* Call text property handlers. */
3033 for (p
= it_props
; p
->handler
; ++p
)
3035 handled
= p
->handler (it
);
3037 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3039 else if (handled
== HANDLED_RETURN
)
3041 /* We still want to show before and after strings from
3042 overlays even if the actual buffer text is replaced. */
3043 if (!handle_overlay_change_p
|| it
->sp
> 1)
3045 if (!get_overlay_strings_1 (it
, 0, 0))
3047 it
->ignore_overlay_strings_at_pos_p
= 1;
3048 it
->string_from_display_prop_p
= 0;
3049 handle_overlay_change_p
= 0;
3050 handled
= HANDLED_RECOMPUTE_PROPS
;
3053 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3054 handle_overlay_change_p
= 0;
3057 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3059 /* Don't check for overlay strings below when set to deliver
3060 characters from a display vector. */
3061 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3062 handle_overlay_change_p
= 0;
3064 /* Handle overlay changes.
3065 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3066 if it finds overlays. */
3067 if (handle_overlay_change_p
)
3068 handled
= handle_overlay_change (it
);
3071 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3073 /* Determine where to stop next. */
3074 if (handled
== HANDLED_NORMALLY
)
3075 compute_stop_pos (it
);
3079 /* Compute IT->stop_charpos from text property and overlay change
3080 information for IT's current position. */
3083 compute_stop_pos (it
)
3086 register INTERVAL iv
, next_iv
;
3087 Lisp_Object object
, limit
, position
;
3089 /* If nowhere else, stop at the end. */
3090 it
->stop_charpos
= it
->end_charpos
;
3092 if (STRINGP (it
->string
))
3094 /* Strings are usually short, so don't limit the search for
3096 object
= it
->string
;
3098 position
= make_number (IT_STRING_CHARPOS (*it
));
3104 /* If next overlay change is in front of the current stop pos
3105 (which is IT->end_charpos), stop there. Note: value of
3106 next_overlay_change is point-max if no overlay change
3108 charpos
= next_overlay_change (IT_CHARPOS (*it
));
3109 if (charpos
< it
->stop_charpos
)
3110 it
->stop_charpos
= charpos
;
3112 /* If showing the region, we have to stop at the region
3113 start or end because the face might change there. */
3114 if (it
->region_beg_charpos
> 0)
3116 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3117 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3118 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3119 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3122 /* Set up variables for computing the stop position from text
3123 property changes. */
3124 XSETBUFFER (object
, current_buffer
);
3125 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3126 position
= make_number (IT_CHARPOS (*it
));
3130 /* Get the interval containing IT's position. Value is a null
3131 interval if there isn't such an interval. */
3132 iv
= validate_interval_range (object
, &position
, &position
, 0);
3133 if (!NULL_INTERVAL_P (iv
))
3135 Lisp_Object values_here
[LAST_PROP_IDX
];
3138 /* Get properties here. */
3139 for (p
= it_props
; p
->handler
; ++p
)
3140 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3142 /* Look for an interval following iv that has different
3144 for (next_iv
= next_interval (iv
);
3145 (!NULL_INTERVAL_P (next_iv
)
3147 || XFASTINT (limit
) > next_iv
->position
));
3148 next_iv
= next_interval (next_iv
))
3150 for (p
= it_props
; p
->handler
; ++p
)
3152 Lisp_Object new_value
;
3154 new_value
= textget (next_iv
->plist
, *p
->name
);
3155 if (!EQ (values_here
[p
->idx
], new_value
))
3163 if (!NULL_INTERVAL_P (next_iv
))
3165 if (INTEGERP (limit
)
3166 && next_iv
->position
>= XFASTINT (limit
))
3167 /* No text property change up to limit. */
3168 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3170 /* Text properties change in next_iv. */
3171 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3175 xassert (STRINGP (it
->string
)
3176 || (it
->stop_charpos
>= BEGV
3177 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3181 /* Return the position of the next overlay change after POS in
3182 current_buffer. Value is point-max if no overlay change
3183 follows. This is like `next-overlay-change' but doesn't use
3187 next_overlay_change (pos
)
3192 Lisp_Object
*overlays
;
3195 /* Get all overlays at the given position. */
3196 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3198 /* If any of these overlays ends before endpos,
3199 use its ending point instead. */
3200 for (i
= 0; i
< noverlays
; ++i
)
3205 oend
= OVERLAY_END (overlays
[i
]);
3206 oendpos
= OVERLAY_POSITION (oend
);
3207 endpos
= min (endpos
, oendpos
);
3215 /***********************************************************************
3217 ***********************************************************************/
3219 /* Handle changes in the `fontified' property of the current buffer by
3220 calling hook functions from Qfontification_functions to fontify
3223 static enum prop_handled
3224 handle_fontified_prop (it
)
3227 Lisp_Object prop
, pos
;
3228 enum prop_handled handled
= HANDLED_NORMALLY
;
3230 if (!NILP (Vmemory_full
))
3233 /* Get the value of the `fontified' property at IT's current buffer
3234 position. (The `fontified' property doesn't have a special
3235 meaning in strings.) If the value is nil, call functions from
3236 Qfontification_functions. */
3237 if (!STRINGP (it
->string
)
3239 && !NILP (Vfontification_functions
)
3240 && !NILP (Vrun_hooks
)
3241 && (pos
= make_number (IT_CHARPOS (*it
)),
3242 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3243 /* Ignore the special cased nil value always present at EOB since
3244 no amount of fontifying will be able to change it. */
3245 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3247 int count
= SPECPDL_INDEX ();
3250 val
= Vfontification_functions
;
3251 specbind (Qfontification_functions
, Qnil
);
3253 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3254 safe_call1 (val
, pos
);
3257 Lisp_Object globals
, fn
;
3258 struct gcpro gcpro1
, gcpro2
;
3261 GCPRO2 (val
, globals
);
3263 for (; CONSP (val
); val
= XCDR (val
))
3269 /* A value of t indicates this hook has a local
3270 binding; it means to run the global binding too.
3271 In a global value, t should not occur. If it
3272 does, we must ignore it to avoid an endless
3274 for (globals
= Fdefault_value (Qfontification_functions
);
3276 globals
= XCDR (globals
))
3278 fn
= XCAR (globals
);
3280 safe_call1 (fn
, pos
);
3284 safe_call1 (fn
, pos
);
3290 unbind_to (count
, Qnil
);
3292 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3293 something. This avoids an endless loop if they failed to
3294 fontify the text for which reason ever. */
3295 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3296 handled
= HANDLED_RECOMPUTE_PROPS
;
3304 /***********************************************************************
3306 ***********************************************************************/
3308 /* Set up iterator IT from face properties at its current position.
3309 Called from handle_stop. */
3311 static enum prop_handled
3312 handle_face_prop (it
)
3315 int new_face_id
, next_stop
;
3317 if (!STRINGP (it
->string
))
3320 = face_at_buffer_position (it
->w
,
3322 it
->region_beg_charpos
,
3323 it
->region_end_charpos
,
3326 + TEXT_PROP_DISTANCE_LIMIT
),
3329 /* Is this a start of a run of characters with box face?
3330 Caveat: this can be called for a freshly initialized
3331 iterator; face_id is -1 in this case. We know that the new
3332 face will not change until limit, i.e. if the new face has a
3333 box, all characters up to limit will have one. But, as
3334 usual, we don't know whether limit is really the end. */
3335 if (new_face_id
!= it
->face_id
)
3337 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3339 /* If new face has a box but old face has not, this is
3340 the start of a run of characters with box, i.e. it has
3341 a shadow on the left side. The value of face_id of the
3342 iterator will be -1 if this is the initial call that gets
3343 the face. In this case, we have to look in front of IT's
3344 position and see whether there is a face != new_face_id. */
3345 it
->start_of_box_run_p
3346 = (new_face
->box
!= FACE_NO_BOX
3347 && (it
->face_id
>= 0
3348 || IT_CHARPOS (*it
) == BEG
3349 || new_face_id
!= face_before_it_pos (it
)));
3350 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3355 int base_face_id
, bufpos
;
3357 Lisp_Object from_overlay
3358 = (it
->current
.overlay_string_index
>= 0
3359 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3362 /* See if we got to this string directly or indirectly from
3363 an overlay property. That includes the before-string or
3364 after-string of an overlay, strings in display properties
3365 provided by an overlay, their text properties, etc.
3367 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3368 if (! NILP (from_overlay
))
3369 for (i
= it
->sp
- 1; i
>= 0; i
--)
3371 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3373 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3374 else if (! NILP (it
->stack
[i
].from_overlay
))
3375 from_overlay
= it
->stack
[i
].from_overlay
;
3377 if (!NILP (from_overlay
))
3381 if (! NILP (from_overlay
))
3383 bufpos
= IT_CHARPOS (*it
);
3384 /* For a string from an overlay, the base face depends
3385 only on text properties and ignores overlays. */
3387 = face_for_overlay_string (it
->w
,
3389 it
->region_beg_charpos
,
3390 it
->region_end_charpos
,
3393 + TEXT_PROP_DISTANCE_LIMIT
),
3401 /* For strings from a `display' property, use the face at
3402 IT's current buffer position as the base face to merge
3403 with, so that overlay strings appear in the same face as
3404 surrounding text, unless they specify their own
3406 base_face_id
= underlying_face_id (it
);
3409 new_face_id
= face_at_string_position (it
->w
,
3411 IT_STRING_CHARPOS (*it
),
3413 it
->region_beg_charpos
,
3414 it
->region_end_charpos
,
3418 #if 0 /* This shouldn't be neccessary. Let's check it. */
3419 /* If IT is used to display a mode line we would really like to
3420 use the mode line face instead of the frame's default face. */
3421 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3422 && new_face_id
== DEFAULT_FACE_ID
)
3423 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3426 /* Is this a start of a run of characters with box? Caveat:
3427 this can be called for a freshly allocated iterator; face_id
3428 is -1 is this case. We know that the new face will not
3429 change until the next check pos, i.e. if the new face has a
3430 box, all characters up to that position will have a
3431 box. But, as usual, we don't know whether that position
3432 is really the end. */
3433 if (new_face_id
!= it
->face_id
)
3435 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3436 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3438 /* If new face has a box but old face hasn't, this is the
3439 start of a run of characters with box, i.e. it has a
3440 shadow on the left side. */
3441 it
->start_of_box_run_p
3442 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3443 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3447 it
->face_id
= new_face_id
;
3448 return HANDLED_NORMALLY
;
3452 /* Return the ID of the face ``underlying'' IT's current position,
3453 which is in a string. If the iterator is associated with a
3454 buffer, return the face at IT's current buffer position.
3455 Otherwise, use the iterator's base_face_id. */
3458 underlying_face_id (it
)
3461 int face_id
= it
->base_face_id
, i
;
3463 xassert (STRINGP (it
->string
));
3465 for (i
= it
->sp
- 1; i
>= 0; --i
)
3466 if (NILP (it
->stack
[i
].string
))
3467 face_id
= it
->stack
[i
].face_id
;
3473 /* Compute the face one character before or after the current position
3474 of IT. BEFORE_P non-zero means get the face in front of IT's
3475 position. Value is the id of the face. */
3478 face_before_or_after_it_pos (it
, before_p
)
3483 int next_check_charpos
;
3484 struct text_pos pos
;
3486 xassert (it
->s
== NULL
);
3488 if (STRINGP (it
->string
))
3490 int bufpos
, base_face_id
;
3492 /* No face change past the end of the string (for the case
3493 we are padding with spaces). No face change before the
3495 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3496 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3499 /* Set pos to the position before or after IT's current position. */
3501 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3503 /* For composition, we must check the character after the
3505 pos
= (it
->what
== IT_COMPOSITION
3506 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3507 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3509 if (it
->current
.overlay_string_index
>= 0)
3510 bufpos
= IT_CHARPOS (*it
);
3514 base_face_id
= underlying_face_id (it
);
3516 /* Get the face for ASCII, or unibyte. */
3517 face_id
= face_at_string_position (it
->w
,
3521 it
->region_beg_charpos
,
3522 it
->region_end_charpos
,
3523 &next_check_charpos
,
3526 /* Correct the face for charsets different from ASCII. Do it
3527 for the multibyte case only. The face returned above is
3528 suitable for unibyte text if IT->string is unibyte. */
3529 if (STRING_MULTIBYTE (it
->string
))
3531 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3532 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3534 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3536 c
= string_char_and_length (p
, rest
, &len
);
3537 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3542 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3543 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3546 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3547 pos
= it
->current
.pos
;
3550 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3553 if (it
->what
== IT_COMPOSITION
)
3554 /* For composition, we must check the position after the
3556 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3558 INC_TEXT_POS (pos
, it
->multibyte_p
);
3561 /* Determine face for CHARSET_ASCII, or unibyte. */
3562 face_id
= face_at_buffer_position (it
->w
,
3564 it
->region_beg_charpos
,
3565 it
->region_end_charpos
,
3566 &next_check_charpos
,
3569 /* Correct the face for charsets different from ASCII. Do it
3570 for the multibyte case only. The face returned above is
3571 suitable for unibyte text if current_buffer is unibyte. */
3572 if (it
->multibyte_p
)
3574 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3575 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3576 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3585 /***********************************************************************
3587 ***********************************************************************/
3589 /* Set up iterator IT from invisible properties at its current
3590 position. Called from handle_stop. */
3592 static enum prop_handled
3593 handle_invisible_prop (it
)
3596 enum prop_handled handled
= HANDLED_NORMALLY
;
3598 if (STRINGP (it
->string
))
3600 extern Lisp_Object Qinvisible
;
3601 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3603 /* Get the value of the invisible text property at the
3604 current position. Value will be nil if there is no such
3606 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3607 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3610 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3612 handled
= HANDLED_RECOMPUTE_PROPS
;
3614 /* Get the position at which the next change of the
3615 invisible text property can be found in IT->string.
3616 Value will be nil if the property value is the same for
3617 all the rest of IT->string. */
3618 XSETINT (limit
, SCHARS (it
->string
));
3619 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3622 /* Text at current position is invisible. The next
3623 change in the property is at position end_charpos.
3624 Move IT's current position to that position. */
3625 if (INTEGERP (end_charpos
)
3626 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3628 struct text_pos old
;
3629 old
= it
->current
.string_pos
;
3630 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3631 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3635 /* The rest of the string is invisible. If this is an
3636 overlay string, proceed with the next overlay string
3637 or whatever comes and return a character from there. */
3638 if (it
->current
.overlay_string_index
>= 0)
3640 next_overlay_string (it
);
3641 /* Don't check for overlay strings when we just
3642 finished processing them. */
3643 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3647 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3648 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3656 EMACS_INT newpos
, next_stop
, start_charpos
;
3657 Lisp_Object pos
, prop
, overlay
;
3659 /* First of all, is there invisible text at this position? */
3660 start_charpos
= IT_CHARPOS (*it
);
3661 pos
= make_number (IT_CHARPOS (*it
));
3662 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3664 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3666 /* If we are on invisible text, skip over it. */
3667 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3669 /* Record whether we have to display an ellipsis for the
3671 int display_ellipsis_p
= invis_p
== 2;
3673 handled
= HANDLED_RECOMPUTE_PROPS
;
3675 /* Loop skipping over invisible text. The loop is left at
3676 ZV or with IT on the first char being visible again. */
3679 /* Try to skip some invisible text. Return value is the
3680 position reached which can be equal to IT's position
3681 if there is nothing invisible here. This skips both
3682 over invisible text properties and overlays with
3683 invisible property. */
3684 newpos
= skip_invisible (IT_CHARPOS (*it
),
3685 &next_stop
, ZV
, it
->window
);
3687 /* If we skipped nothing at all we weren't at invisible
3688 text in the first place. If everything to the end of
3689 the buffer was skipped, end the loop. */
3690 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3694 /* We skipped some characters but not necessarily
3695 all there are. Check if we ended up on visible
3696 text. Fget_char_property returns the property of
3697 the char before the given position, i.e. if we
3698 get invis_p = 0, this means that the char at
3699 newpos is visible. */
3700 pos
= make_number (newpos
);
3701 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3702 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3705 /* If we ended up on invisible text, proceed to
3706 skip starting with next_stop. */
3708 IT_CHARPOS (*it
) = next_stop
;
3710 /* If there are adjacent invisible texts, don't lose the
3711 second one's ellipsis. */
3713 display_ellipsis_p
= 1;
3717 /* The position newpos is now either ZV or on visible text. */
3718 IT_CHARPOS (*it
) = newpos
;
3719 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3721 /* If there are before-strings at the start of invisible
3722 text, and the text is invisible because of a text
3723 property, arrange to show before-strings because 20.x did
3724 it that way. (If the text is invisible because of an
3725 overlay property instead of a text property, this is
3726 already handled in the overlay code.) */
3728 && get_overlay_strings (it
, start_charpos
))
3730 handled
= HANDLED_RECOMPUTE_PROPS
;
3731 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3733 else if (display_ellipsis_p
)
3735 /* Make sure that the glyphs of the ellipsis will get
3736 correct `charpos' values. If we would not update
3737 it->position here, the glyphs would belong to the
3738 last visible character _before_ the invisible
3739 text, which confuses `set_cursor_from_row'.
3741 We use the last invisible position instead of the
3742 first because this way the cursor is always drawn on
3743 the first "." of the ellipsis, whenever PT is inside
3744 the invisible text. Otherwise the cursor would be
3745 placed _after_ the ellipsis when the point is after the
3746 first invisible character. */
3747 if (!STRINGP (it
->object
))
3749 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3750 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3752 setup_for_ellipsis (it
, 0);
3753 /* Let the ellipsis display before
3754 considering any properties of the following char.
3755 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3756 handled
= HANDLED_RETURN
;
3765 /* Make iterator IT return `...' next.
3766 Replaces LEN characters from buffer. */
3769 setup_for_ellipsis (it
, len
)
3773 /* Use the display table definition for `...'. Invalid glyphs
3774 will be handled by the method returning elements from dpvec. */
3775 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3777 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3778 it
->dpvec
= v
->contents
;
3779 it
->dpend
= v
->contents
+ v
->size
;
3783 /* Default `...'. */
3784 it
->dpvec
= default_invis_vector
;
3785 it
->dpend
= default_invis_vector
+ 3;
3788 it
->dpvec_char_len
= len
;
3789 it
->current
.dpvec_index
= 0;
3790 it
->dpvec_face_id
= -1;
3792 /* Remember the current face id in case glyphs specify faces.
3793 IT's face is restored in set_iterator_to_next.
3794 saved_face_id was set to preceding char's face in handle_stop. */
3795 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3796 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3798 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3804 /***********************************************************************
3806 ***********************************************************************/
3808 /* Set up iterator IT from `display' property at its current position.
3809 Called from handle_stop.
3810 We return HANDLED_RETURN if some part of the display property
3811 overrides the display of the buffer text itself.
3812 Otherwise we return HANDLED_NORMALLY. */
3814 static enum prop_handled
3815 handle_display_prop (it
)
3818 Lisp_Object prop
, object
, overlay
;
3819 struct text_pos
*position
;
3820 /* Nonzero if some property replaces the display of the text itself. */
3821 int display_replaced_p
= 0;
3823 if (STRINGP (it
->string
))
3825 object
= it
->string
;
3826 position
= &it
->current
.string_pos
;
3830 XSETWINDOW (object
, it
->w
);
3831 position
= &it
->current
.pos
;
3834 /* Reset those iterator values set from display property values. */
3835 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3836 it
->space_width
= Qnil
;
3837 it
->font_height
= Qnil
;
3840 /* We don't support recursive `display' properties, i.e. string
3841 values that have a string `display' property, that have a string
3842 `display' property etc. */
3843 if (!it
->string_from_display_prop_p
)
3844 it
->area
= TEXT_AREA
;
3846 prop
= get_char_property_and_overlay (make_number (position
->charpos
),
3847 Qdisplay
, object
, &overlay
);
3849 return HANDLED_NORMALLY
;
3850 /* Now OVERLAY is the overlay that gave us this property, or nil
3851 if it was a text property. */
3853 if (!STRINGP (it
->string
))
3854 object
= it
->w
->buffer
;
3857 /* Simple properties. */
3858 && !EQ (XCAR (prop
), Qimage
)
3859 && !EQ (XCAR (prop
), Qspace
)
3860 && !EQ (XCAR (prop
), Qwhen
)
3861 && !EQ (XCAR (prop
), Qslice
)
3862 && !EQ (XCAR (prop
), Qspace_width
)
3863 && !EQ (XCAR (prop
), Qheight
)
3864 && !EQ (XCAR (prop
), Qraise
)
3865 /* Marginal area specifications. */
3866 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3867 && !EQ (XCAR (prop
), Qleft_fringe
)
3868 && !EQ (XCAR (prop
), Qright_fringe
)
3869 && !NILP (XCAR (prop
)))
3871 for (; CONSP (prop
); prop
= XCDR (prop
))
3873 if (handle_single_display_spec (it
, XCAR (prop
), object
, overlay
,
3874 position
, display_replaced_p
))
3876 display_replaced_p
= 1;
3877 /* If some text in a string is replaced, `position' no
3878 longer points to the position of `object'. */
3879 if (STRINGP (object
))
3884 else if (VECTORP (prop
))
3887 for (i
= 0; i
< ASIZE (prop
); ++i
)
3888 if (handle_single_display_spec (it
, AREF (prop
, i
), object
, overlay
,
3889 position
, display_replaced_p
))
3891 display_replaced_p
= 1;
3892 /* If some text in a string is replaced, `position' no
3893 longer points to the position of `object'. */
3894 if (STRINGP (object
))
3900 int ret
= handle_single_display_spec (it
, prop
, object
, overlay
,
3902 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3903 return HANDLED_RECOMPUTE_PROPS
;
3905 display_replaced_p
= 1;
3908 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3912 /* Value is the position of the end of the `display' property starting
3913 at START_POS in OBJECT. */
3915 static struct text_pos
3916 display_prop_end (it
, object
, start_pos
)
3919 struct text_pos start_pos
;
3922 struct text_pos end_pos
;
3924 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3925 Qdisplay
, object
, Qnil
);
3926 CHARPOS (end_pos
) = XFASTINT (end
);
3927 if (STRINGP (object
))
3928 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3930 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3936 /* Set up IT from a single `display' specification PROP. OBJECT
3937 is the object in which the `display' property was found. *POSITION
3938 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3939 means that we previously saw a display specification which already
3940 replaced text display with something else, for example an image;
3941 we ignore such properties after the first one has been processed.
3943 OVERLAY is the overlay this `display' property came from,
3944 or nil if it was a text property.
3946 If PROP is a `space' or `image' specification, and in some other
3947 cases too, set *POSITION to the position where the `display'
3950 Value is non-zero if something was found which replaces the display
3951 of buffer or string text. Specifically, the value is -1 if that
3952 "something" is "nothing". */
3955 handle_single_display_spec (it
, spec
, object
, overlay
, position
,
3956 display_replaced_before_p
)
3960 Lisp_Object overlay
;
3961 struct text_pos
*position
;
3962 int display_replaced_before_p
;
3965 Lisp_Object location
, value
;
3966 struct text_pos start_pos
, save_pos
;
3969 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3970 If the result is non-nil, use VALUE instead of SPEC. */
3972 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3981 if (!NILP (form
) && !EQ (form
, Qt
))
3983 int count
= SPECPDL_INDEX ();
3984 struct gcpro gcpro1
;
3986 /* Bind `object' to the object having the `display' property, a
3987 buffer or string. Bind `position' to the position in the
3988 object where the property was found, and `buffer-position'
3989 to the current position in the buffer. */
3990 specbind (Qobject
, object
);
3991 specbind (Qposition
, make_number (CHARPOS (*position
)));
3992 specbind (Qbuffer_position
,
3993 make_number (STRINGP (object
)
3994 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3996 form
= safe_eval (form
);
3998 unbind_to (count
, Qnil
);
4004 /* Handle `(height HEIGHT)' specifications. */
4006 && EQ (XCAR (spec
), Qheight
)
4007 && CONSP (XCDR (spec
)))
4009 if (!FRAME_WINDOW_P (it
->f
))
4012 it
->font_height
= XCAR (XCDR (spec
));
4013 if (!NILP (it
->font_height
))
4015 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4016 int new_height
= -1;
4018 if (CONSP (it
->font_height
)
4019 && (EQ (XCAR (it
->font_height
), Qplus
)
4020 || EQ (XCAR (it
->font_height
), Qminus
))
4021 && CONSP (XCDR (it
->font_height
))
4022 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4024 /* `(+ N)' or `(- N)' where N is an integer. */
4025 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4026 if (EQ (XCAR (it
->font_height
), Qplus
))
4028 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4030 else if (FUNCTIONP (it
->font_height
))
4032 /* Call function with current height as argument.
4033 Value is the new height. */
4035 height
= safe_call1 (it
->font_height
,
4036 face
->lface
[LFACE_HEIGHT_INDEX
]);
4037 if (NUMBERP (height
))
4038 new_height
= XFLOATINT (height
);
4040 else if (NUMBERP (it
->font_height
))
4042 /* Value is a multiple of the canonical char height. */
4045 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
4046 new_height
= (XFLOATINT (it
->font_height
)
4047 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4051 /* Evaluate IT->font_height with `height' bound to the
4052 current specified height to get the new height. */
4053 int count
= SPECPDL_INDEX ();
4055 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4056 value
= safe_eval (it
->font_height
);
4057 unbind_to (count
, Qnil
);
4059 if (NUMBERP (value
))
4060 new_height
= XFLOATINT (value
);
4064 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4070 /* Handle `(space-width WIDTH)'. */
4072 && EQ (XCAR (spec
), Qspace_width
)
4073 && CONSP (XCDR (spec
)))
4075 if (!FRAME_WINDOW_P (it
->f
))
4078 value
= XCAR (XCDR (spec
));
4079 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4080 it
->space_width
= value
;
4085 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4087 && EQ (XCAR (spec
), Qslice
))
4091 if (!FRAME_WINDOW_P (it
->f
))
4094 if (tem
= XCDR (spec
), CONSP (tem
))
4096 it
->slice
.x
= XCAR (tem
);
4097 if (tem
= XCDR (tem
), CONSP (tem
))
4099 it
->slice
.y
= XCAR (tem
);
4100 if (tem
= XCDR (tem
), CONSP (tem
))
4102 it
->slice
.width
= XCAR (tem
);
4103 if (tem
= XCDR (tem
), CONSP (tem
))
4104 it
->slice
.height
= XCAR (tem
);
4112 /* Handle `(raise FACTOR)'. */
4114 && EQ (XCAR (spec
), Qraise
)
4115 && CONSP (XCDR (spec
)))
4117 if (!FRAME_WINDOW_P (it
->f
))
4120 #ifdef HAVE_WINDOW_SYSTEM
4121 value
= XCAR (XCDR (spec
));
4122 if (NUMBERP (value
))
4124 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4125 it
->voffset
= - (XFLOATINT (value
)
4126 * (FONT_HEIGHT (face
->font
)));
4128 #endif /* HAVE_WINDOW_SYSTEM */
4133 /* Don't handle the other kinds of display specifications
4134 inside a string that we got from a `display' property. */
4135 if (it
->string_from_display_prop_p
)
4138 /* Characters having this form of property are not displayed, so
4139 we have to find the end of the property. */
4140 start_pos
= *position
;
4141 *position
= display_prop_end (it
, object
, start_pos
);
4144 /* Stop the scan at that end position--we assume that all
4145 text properties change there. */
4146 it
->stop_charpos
= position
->charpos
;
4148 /* Handle `(left-fringe BITMAP [FACE])'
4149 and `(right-fringe BITMAP [FACE])'. */
4151 && (EQ (XCAR (spec
), Qleft_fringe
)
4152 || EQ (XCAR (spec
), Qright_fringe
))
4153 && CONSP (XCDR (spec
)))
4155 int face_id
= DEFAULT_FACE_ID
;
4158 if (!FRAME_WINDOW_P (it
->f
))
4159 /* If we return here, POSITION has been advanced
4160 across the text with this property. */
4163 #ifdef HAVE_WINDOW_SYSTEM
4164 value
= XCAR (XCDR (spec
));
4165 if (!SYMBOLP (value
)
4166 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4167 /* If we return here, POSITION has been advanced
4168 across the text with this property. */
4171 if (CONSP (XCDR (XCDR (spec
))))
4173 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4174 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4175 'A', FRINGE_FACE_ID
, 0);
4180 /* Save current settings of IT so that we can restore them
4181 when we are finished with the glyph property value. */
4183 save_pos
= it
->position
;
4184 it
->position
= *position
;
4186 it
->position
= save_pos
;
4188 it
->area
= TEXT_AREA
;
4189 it
->what
= IT_IMAGE
;
4190 it
->image_id
= -1; /* no image */
4191 it
->position
= start_pos
;
4192 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4193 it
->method
= GET_FROM_IMAGE
;
4194 it
->from_overlay
= Qnil
;
4195 it
->face_id
= face_id
;
4197 /* Say that we haven't consumed the characters with
4198 `display' property yet. The call to pop_it in
4199 set_iterator_to_next will clean this up. */
4200 *position
= start_pos
;
4202 if (EQ (XCAR (spec
), Qleft_fringe
))
4204 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4205 it
->left_user_fringe_face_id
= face_id
;
4209 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4210 it
->right_user_fringe_face_id
= face_id
;
4212 #endif /* HAVE_WINDOW_SYSTEM */
4216 /* Prepare to handle `((margin left-margin) ...)',
4217 `((margin right-margin) ...)' and `((margin nil) ...)'
4218 prefixes for display specifications. */
4219 location
= Qunbound
;
4220 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4224 value
= XCDR (spec
);
4226 value
= XCAR (value
);
4229 if (EQ (XCAR (tem
), Qmargin
)
4230 && (tem
= XCDR (tem
),
4231 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4233 || EQ (tem
, Qleft_margin
)
4234 || EQ (tem
, Qright_margin
))))
4238 if (EQ (location
, Qunbound
))
4244 /* After this point, VALUE is the property after any
4245 margin prefix has been stripped. It must be a string,
4246 an image specification, or `(space ...)'.
4248 LOCATION specifies where to display: `left-margin',
4249 `right-margin' or nil. */
4251 valid_p
= (STRINGP (value
)
4252 #ifdef HAVE_WINDOW_SYSTEM
4253 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4254 #endif /* not HAVE_WINDOW_SYSTEM */
4255 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4257 if (valid_p
&& !display_replaced_before_p
)
4259 /* Save current settings of IT so that we can restore them
4260 when we are finished with the glyph property value. */
4261 save_pos
= it
->position
;
4262 it
->position
= *position
;
4264 it
->position
= save_pos
;
4265 it
->from_overlay
= overlay
;
4267 if (NILP (location
))
4268 it
->area
= TEXT_AREA
;
4269 else if (EQ (location
, Qleft_margin
))
4270 it
->area
= LEFT_MARGIN_AREA
;
4272 it
->area
= RIGHT_MARGIN_AREA
;
4274 if (STRINGP (value
))
4276 if (SCHARS (value
) == 0)
4279 return -1; /* Replaced by "", i.e. nothing. */
4282 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4283 it
->current
.overlay_string_index
= -1;
4284 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4285 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4286 it
->method
= GET_FROM_STRING
;
4287 it
->stop_charpos
= 0;
4288 it
->string_from_display_prop_p
= 1;
4289 /* Say that we haven't consumed the characters with
4290 `display' property yet. The call to pop_it in
4291 set_iterator_to_next will clean this up. */
4292 if (BUFFERP (object
))
4293 it
->current
.pos
= start_pos
;
4295 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4297 it
->method
= GET_FROM_STRETCH
;
4299 it
->position
= start_pos
;
4300 if (BUFFERP (object
))
4301 it
->current
.pos
= start_pos
;
4303 #ifdef HAVE_WINDOW_SYSTEM
4306 it
->what
= IT_IMAGE
;
4307 it
->image_id
= lookup_image (it
->f
, value
);
4308 it
->position
= start_pos
;
4309 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4310 it
->method
= GET_FROM_IMAGE
;
4312 /* Say that we haven't consumed the characters with
4313 `display' property yet. The call to pop_it in
4314 set_iterator_to_next will clean this up. */
4315 if (BUFFERP (object
))
4316 it
->current
.pos
= start_pos
;
4318 #endif /* HAVE_WINDOW_SYSTEM */
4323 /* Invalid property or property not supported. Restore
4324 POSITION to what it was before. */
4325 *position
= start_pos
;
4330 /* Check if SPEC is a display sub-property value whose text should be
4331 treated as intangible. */
4334 single_display_spec_intangible_p (prop
)
4337 /* Skip over `when FORM'. */
4338 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4352 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4353 we don't need to treat text as intangible. */
4354 if (EQ (XCAR (prop
), Qmargin
))
4362 || EQ (XCAR (prop
), Qleft_margin
)
4363 || EQ (XCAR (prop
), Qright_margin
))
4367 return (CONSP (prop
)
4368 && (EQ (XCAR (prop
), Qimage
)
4369 || EQ (XCAR (prop
), Qspace
)));
4373 /* Check if PROP is a display property value whose text should be
4374 treated as intangible. */
4377 display_prop_intangible_p (prop
)
4381 && CONSP (XCAR (prop
))
4382 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4384 /* A list of sub-properties. */
4385 while (CONSP (prop
))
4387 if (single_display_spec_intangible_p (XCAR (prop
)))
4392 else if (VECTORP (prop
))
4394 /* A vector of sub-properties. */
4396 for (i
= 0; i
< ASIZE (prop
); ++i
)
4397 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4401 return single_display_spec_intangible_p (prop
);
4407 /* Return 1 if PROP is a display sub-property value containing STRING. */
4410 single_display_spec_string_p (prop
, string
)
4411 Lisp_Object prop
, string
;
4413 if (EQ (string
, prop
))
4416 /* Skip over `when FORM'. */
4417 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4426 /* Skip over `margin LOCATION'. */
4427 if (EQ (XCAR (prop
), Qmargin
))
4438 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4442 /* Return 1 if STRING appears in the `display' property PROP. */
4445 display_prop_string_p (prop
, string
)
4446 Lisp_Object prop
, string
;
4449 && CONSP (XCAR (prop
))
4450 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4452 /* A list of sub-properties. */
4453 while (CONSP (prop
))
4455 if (single_display_spec_string_p (XCAR (prop
), string
))
4460 else if (VECTORP (prop
))
4462 /* A vector of sub-properties. */
4464 for (i
= 0; i
< ASIZE (prop
); ++i
)
4465 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4469 return single_display_spec_string_p (prop
, string
);
4475 /* Determine from which buffer position in W's buffer STRING comes
4476 from. AROUND_CHARPOS is an approximate position where it could
4477 be from. Value is the buffer position or 0 if it couldn't be
4480 W's buffer must be current.
4482 This function is necessary because we don't record buffer positions
4483 in glyphs generated from strings (to keep struct glyph small).
4484 This function may only use code that doesn't eval because it is
4485 called asynchronously from note_mouse_highlight. */
4488 string_buffer_position (w
, string
, around_charpos
)
4493 Lisp_Object limit
, prop
, pos
;
4494 const int MAX_DISTANCE
= 1000;
4497 pos
= make_number (around_charpos
);
4498 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4499 while (!found
&& !EQ (pos
, limit
))
4501 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4502 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4505 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4510 pos
= make_number (around_charpos
);
4511 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4512 while (!found
&& !EQ (pos
, limit
))
4514 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4515 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4518 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4523 return found
? XINT (pos
) : 0;
4528 /***********************************************************************
4529 `composition' property
4530 ***********************************************************************/
4532 /* Set up iterator IT from `composition' property at its current
4533 position. Called from handle_stop. */
4535 static enum prop_handled
4536 handle_composition_prop (it
)
4539 Lisp_Object prop
, string
;
4540 int pos
, pos_byte
, end
;
4541 enum prop_handled handled
= HANDLED_NORMALLY
;
4543 if (STRINGP (it
->string
))
4545 pos
= IT_STRING_CHARPOS (*it
);
4546 pos_byte
= IT_STRING_BYTEPOS (*it
);
4547 string
= it
->string
;
4551 pos
= IT_CHARPOS (*it
);
4552 pos_byte
= IT_BYTEPOS (*it
);
4556 /* If there's a valid composition and point is not inside of the
4557 composition (in the case that the composition is from the current
4558 buffer), draw a glyph composed from the composition components. */
4559 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
4560 && COMPOSITION_VALID_P (pos
, end
, prop
)
4561 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
4563 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4567 struct composition
*cmp
= composition_table
[id
];
4569 if (cmp
->glyph_len
== 0)
4572 if (STRINGP (it
->string
))
4574 IT_STRING_CHARPOS (*it
) = end
;
4575 IT_STRING_BYTEPOS (*it
) = string_char_to_byte (it
->string
,
4580 IT_CHARPOS (*it
) = end
;
4581 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (end
);
4583 return HANDLED_RECOMPUTE_PROPS
;
4586 it
->stop_charpos
= end
;
4589 it
->method
= GET_FROM_COMPOSITION
;
4591 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4592 /* For a terminal, draw only the first character of the
4594 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4595 it
->len
= (STRINGP (it
->string
)
4596 ? string_char_to_byte (it
->string
, end
)
4597 : CHAR_TO_BYTE (end
)) - pos_byte
;
4598 handled
= HANDLED_RETURN
;
4607 /***********************************************************************
4609 ***********************************************************************/
4611 /* The following structure is used to record overlay strings for
4612 later sorting in load_overlay_strings. */
4614 struct overlay_entry
4616 Lisp_Object overlay
;
4623 /* Set up iterator IT from overlay strings at its current position.
4624 Called from handle_stop. */
4626 static enum prop_handled
4627 handle_overlay_change (it
)
4630 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4631 return HANDLED_RECOMPUTE_PROPS
;
4633 return HANDLED_NORMALLY
;
4637 /* Set up the next overlay string for delivery by IT, if there is an
4638 overlay string to deliver. Called by set_iterator_to_next when the
4639 end of the current overlay string is reached. If there are more
4640 overlay strings to display, IT->string and
4641 IT->current.overlay_string_index are set appropriately here.
4642 Otherwise IT->string is set to nil. */
4645 next_overlay_string (it
)
4648 ++it
->current
.overlay_string_index
;
4649 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4651 /* No more overlay strings. Restore IT's settings to what
4652 they were before overlay strings were processed, and
4653 continue to deliver from current_buffer. */
4654 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4658 || it
->method
== GET_FROM_COMPOSITION
4659 || (NILP (it
->string
)
4660 && it
->method
== GET_FROM_BUFFER
4661 && it
->stop_charpos
>= BEGV
4662 && it
->stop_charpos
<= it
->end_charpos
));
4663 it
->current
.overlay_string_index
= -1;
4664 it
->n_overlay_strings
= 0;
4666 /* If we're at the end of the buffer, record that we have
4667 processed the overlay strings there already, so that
4668 next_element_from_buffer doesn't try it again. */
4669 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4670 it
->overlay_strings_at_end_processed_p
= 1;
4672 /* If we have to display `...' for invisible text, set
4673 the iterator up for that. */
4674 if (display_ellipsis_p
)
4675 setup_for_ellipsis (it
, 0);
4679 /* There are more overlay strings to process. If
4680 IT->current.overlay_string_index has advanced to a position
4681 where we must load IT->overlay_strings with more strings, do
4683 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4685 if (it
->current
.overlay_string_index
&& i
== 0)
4686 load_overlay_strings (it
, 0);
4688 /* Initialize IT to deliver display elements from the overlay
4690 it
->string
= it
->overlay_strings
[i
];
4691 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4692 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4693 it
->method
= GET_FROM_STRING
;
4694 it
->stop_charpos
= 0;
4701 /* Compare two overlay_entry structures E1 and E2. Used as a
4702 comparison function for qsort in load_overlay_strings. Overlay
4703 strings for the same position are sorted so that
4705 1. All after-strings come in front of before-strings, except
4706 when they come from the same overlay.
4708 2. Within after-strings, strings are sorted so that overlay strings
4709 from overlays with higher priorities come first.
4711 2. Within before-strings, strings are sorted so that overlay
4712 strings from overlays with higher priorities come last.
4714 Value is analogous to strcmp. */
4718 compare_overlay_entries (e1
, e2
)
4721 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4722 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4725 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4727 /* Let after-strings appear in front of before-strings if
4728 they come from different overlays. */
4729 if (EQ (entry1
->overlay
, entry2
->overlay
))
4730 result
= entry1
->after_string_p
? 1 : -1;
4732 result
= entry1
->after_string_p
? -1 : 1;
4734 else if (entry1
->after_string_p
)
4735 /* After-strings sorted in order of decreasing priority. */
4736 result
= entry2
->priority
- entry1
->priority
;
4738 /* Before-strings sorted in order of increasing priority. */
4739 result
= entry1
->priority
- entry2
->priority
;
4745 /* Load the vector IT->overlay_strings with overlay strings from IT's
4746 current buffer position, or from CHARPOS if that is > 0. Set
4747 IT->n_overlays to the total number of overlay strings found.
4749 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4750 a time. On entry into load_overlay_strings,
4751 IT->current.overlay_string_index gives the number of overlay
4752 strings that have already been loaded by previous calls to this
4755 IT->add_overlay_start contains an additional overlay start
4756 position to consider for taking overlay strings from, if non-zero.
4757 This position comes into play when the overlay has an `invisible'
4758 property, and both before and after-strings. When we've skipped to
4759 the end of the overlay, because of its `invisible' property, we
4760 nevertheless want its before-string to appear.
4761 IT->add_overlay_start will contain the overlay start position
4764 Overlay strings are sorted so that after-string strings come in
4765 front of before-string strings. Within before and after-strings,
4766 strings are sorted by overlay priority. See also function
4767 compare_overlay_entries. */
4770 load_overlay_strings (it
, charpos
)
4774 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4775 Lisp_Object overlay
, window
, str
, invisible
;
4776 struct Lisp_Overlay
*ov
;
4779 int n
= 0, i
, j
, invis_p
;
4780 struct overlay_entry
*entries
4781 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4784 charpos
= IT_CHARPOS (*it
);
4786 /* Append the overlay string STRING of overlay OVERLAY to vector
4787 `entries' which has size `size' and currently contains `n'
4788 elements. AFTER_P non-zero means STRING is an after-string of
4790 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4793 Lisp_Object priority; \
4797 int new_size = 2 * size; \
4798 struct overlay_entry *old = entries; \
4800 (struct overlay_entry *) alloca (new_size \
4801 * sizeof *entries); \
4802 bcopy (old, entries, size * sizeof *entries); \
4806 entries[n].string = (STRING); \
4807 entries[n].overlay = (OVERLAY); \
4808 priority = Foverlay_get ((OVERLAY), Qpriority); \
4809 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4810 entries[n].after_string_p = (AFTER_P); \
4815 /* Process overlay before the overlay center. */
4816 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4818 XSETMISC (overlay
, ov
);
4819 xassert (OVERLAYP (overlay
));
4820 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4821 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4826 /* Skip this overlay if it doesn't start or end at IT's current
4828 if (end
!= charpos
&& start
!= charpos
)
4831 /* Skip this overlay if it doesn't apply to IT->w. */
4832 window
= Foverlay_get (overlay
, Qwindow
);
4833 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4836 /* If the text ``under'' the overlay is invisible, both before-
4837 and after-strings from this overlay are visible; start and
4838 end position are indistinguishable. */
4839 invisible
= Foverlay_get (overlay
, Qinvisible
);
4840 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4842 /* If overlay has a non-empty before-string, record it. */
4843 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4844 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4846 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4848 /* If overlay has a non-empty after-string, record it. */
4849 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4850 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4852 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4855 /* Process overlays after the overlay center. */
4856 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4858 XSETMISC (overlay
, ov
);
4859 xassert (OVERLAYP (overlay
));
4860 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4861 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4863 if (start
> charpos
)
4866 /* Skip this overlay if it doesn't start or end at IT's current
4868 if (end
!= charpos
&& start
!= charpos
)
4871 /* Skip this overlay if it doesn't apply to IT->w. */
4872 window
= Foverlay_get (overlay
, Qwindow
);
4873 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4876 /* If the text ``under'' the overlay is invisible, it has a zero
4877 dimension, and both before- and after-strings apply. */
4878 invisible
= Foverlay_get (overlay
, Qinvisible
);
4879 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4881 /* If overlay has a non-empty before-string, record it. */
4882 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4883 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4885 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4887 /* If overlay has a non-empty after-string, record it. */
4888 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4889 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4891 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4894 #undef RECORD_OVERLAY_STRING
4898 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4900 /* Record the total number of strings to process. */
4901 it
->n_overlay_strings
= n
;
4903 /* IT->current.overlay_string_index is the number of overlay strings
4904 that have already been consumed by IT. Copy some of the
4905 remaining overlay strings to IT->overlay_strings. */
4907 j
= it
->current
.overlay_string_index
;
4908 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4910 it
->overlay_strings
[i
] = entries
[j
].string
;
4911 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
4918 /* Get the first chunk of overlay strings at IT's current buffer
4919 position, or at CHARPOS if that is > 0. Value is non-zero if at
4920 least one overlay string was found. */
4923 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
4927 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4928 process. This fills IT->overlay_strings with strings, and sets
4929 IT->n_overlay_strings to the total number of strings to process.
4930 IT->pos.overlay_string_index has to be set temporarily to zero
4931 because load_overlay_strings needs this; it must be set to -1
4932 when no overlay strings are found because a zero value would
4933 indicate a position in the first overlay string. */
4934 it
->current
.overlay_string_index
= 0;
4935 load_overlay_strings (it
, charpos
);
4937 /* If we found overlay strings, set up IT to deliver display
4938 elements from the first one. Otherwise set up IT to deliver
4939 from current_buffer. */
4940 if (it
->n_overlay_strings
)
4942 /* Make sure we know settings in current_buffer, so that we can
4943 restore meaningful values when we're done with the overlay
4946 compute_stop_pos (it
);
4947 xassert (it
->face_id
>= 0);
4949 /* Save IT's settings. They are restored after all overlay
4950 strings have been processed. */
4951 xassert (!compute_stop_p
|| it
->sp
== 0);
4954 /* Set up IT to deliver display elements from the first overlay
4956 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4957 it
->string
= it
->overlay_strings
[0];
4958 it
->from_overlay
= Qnil
;
4959 it
->stop_charpos
= 0;
4960 xassert (STRINGP (it
->string
));
4961 it
->end_charpos
= SCHARS (it
->string
);
4962 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4963 it
->method
= GET_FROM_STRING
;
4967 it
->current
.overlay_string_index
= -1;
4972 get_overlay_strings (it
, charpos
)
4977 it
->method
= GET_FROM_BUFFER
;
4979 (void) get_overlay_strings_1 (it
, charpos
, 1);
4983 /* Value is non-zero if we found at least one overlay string. */
4984 return STRINGP (it
->string
);
4989 /***********************************************************************
4990 Saving and restoring state
4991 ***********************************************************************/
4993 /* Save current settings of IT on IT->stack. Called, for example,
4994 before setting up IT for an overlay string, to be able to restore
4995 IT's settings to what they were after the overlay string has been
5002 struct iterator_stack_entry
*p
;
5004 xassert (it
->sp
< IT_STACK_SIZE
);
5005 p
= it
->stack
+ it
->sp
;
5007 p
->stop_charpos
= it
->stop_charpos
;
5008 xassert (it
->face_id
>= 0);
5009 p
->face_id
= it
->face_id
;
5010 p
->string
= it
->string
;
5011 p
->method
= it
->method
;
5012 p
->from_overlay
= it
->from_overlay
;
5015 case GET_FROM_IMAGE
:
5016 p
->u
.image
.object
= it
->object
;
5017 p
->u
.image
.image_id
= it
->image_id
;
5018 p
->u
.image
.slice
= it
->slice
;
5020 case GET_FROM_COMPOSITION
:
5021 p
->u
.comp
.object
= it
->object
;
5022 p
->u
.comp
.c
= it
->c
;
5023 p
->u
.comp
.len
= it
->len
;
5024 p
->u
.comp
.cmp_id
= it
->cmp_id
;
5025 p
->u
.comp
.cmp_len
= it
->cmp_len
;
5027 case GET_FROM_STRETCH
:
5028 p
->u
.stretch
.object
= it
->object
;
5031 p
->position
= it
->position
;
5032 p
->current
= it
->current
;
5033 p
->end_charpos
= it
->end_charpos
;
5034 p
->string_nchars
= it
->string_nchars
;
5036 p
->multibyte_p
= it
->multibyte_p
;
5037 p
->space_width
= it
->space_width
;
5038 p
->font_height
= it
->font_height
;
5039 p
->voffset
= it
->voffset
;
5040 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5041 p
->display_ellipsis_p
= 0;
5046 /* Restore IT's settings from IT->stack. Called, for example, when no
5047 more overlay strings must be processed, and we return to delivering
5048 display elements from a buffer, or when the end of a string from a
5049 `display' property is reached and we return to delivering display
5050 elements from an overlay string, or from a buffer. */
5056 struct iterator_stack_entry
*p
;
5058 xassert (it
->sp
> 0);
5060 p
= it
->stack
+ it
->sp
;
5061 it
->stop_charpos
= p
->stop_charpos
;
5062 it
->face_id
= p
->face_id
;
5063 it
->current
= p
->current
;
5064 it
->position
= p
->position
;
5065 it
->string
= p
->string
;
5066 it
->from_overlay
= p
->from_overlay
;
5067 if (NILP (it
->string
))
5068 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5069 it
->method
= p
->method
;
5072 case GET_FROM_IMAGE
:
5073 it
->image_id
= p
->u
.image
.image_id
;
5074 it
->object
= p
->u
.image
.object
;
5075 it
->slice
= p
->u
.image
.slice
;
5077 case GET_FROM_COMPOSITION
:
5078 it
->object
= p
->u
.comp
.object
;
5079 it
->c
= p
->u
.comp
.c
;
5080 it
->len
= p
->u
.comp
.len
;
5081 it
->cmp_id
= p
->u
.comp
.cmp_id
;
5082 it
->cmp_len
= p
->u
.comp
.cmp_len
;
5084 case GET_FROM_STRETCH
:
5085 it
->object
= p
->u
.comp
.object
;
5087 case GET_FROM_BUFFER
:
5088 it
->object
= it
->w
->buffer
;
5090 case GET_FROM_STRING
:
5091 it
->object
= it
->string
;
5094 it
->end_charpos
= p
->end_charpos
;
5095 it
->string_nchars
= p
->string_nchars
;
5097 it
->multibyte_p
= p
->multibyte_p
;
5098 it
->space_width
= p
->space_width
;
5099 it
->font_height
= p
->font_height
;
5100 it
->voffset
= p
->voffset
;
5101 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5106 /***********************************************************************
5108 ***********************************************************************/
5110 /* Set IT's current position to the previous line start. */
5113 back_to_previous_line_start (it
)
5116 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5117 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5121 /* Move IT to the next line start.
5123 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5124 we skipped over part of the text (as opposed to moving the iterator
5125 continuously over the text). Otherwise, don't change the value
5128 Newlines may come from buffer text, overlay strings, or strings
5129 displayed via the `display' property. That's the reason we can't
5130 simply use find_next_newline_no_quit.
5132 Note that this function may not skip over invisible text that is so
5133 because of text properties and immediately follows a newline. If
5134 it would, function reseat_at_next_visible_line_start, when called
5135 from set_iterator_to_next, would effectively make invisible
5136 characters following a newline part of the wrong glyph row, which
5137 leads to wrong cursor motion. */
5140 forward_to_next_line_start (it
, skipped_p
)
5144 int old_selective
, newline_found_p
, n
;
5145 const int MAX_NEWLINE_DISTANCE
= 500;
5147 /* If already on a newline, just consume it to avoid unintended
5148 skipping over invisible text below. */
5149 if (it
->what
== IT_CHARACTER
5151 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5153 set_iterator_to_next (it
, 0);
5158 /* Don't handle selective display in the following. It's (a)
5159 unnecessary because it's done by the caller, and (b) leads to an
5160 infinite recursion because next_element_from_ellipsis indirectly
5161 calls this function. */
5162 old_selective
= it
->selective
;
5165 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5166 from buffer text. */
5167 for (n
= newline_found_p
= 0;
5168 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5169 n
+= STRINGP (it
->string
) ? 0 : 1)
5171 if (!get_next_display_element (it
))
5173 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5174 set_iterator_to_next (it
, 0);
5177 /* If we didn't find a newline near enough, see if we can use a
5179 if (!newline_found_p
)
5181 int start
= IT_CHARPOS (*it
);
5182 int limit
= find_next_newline_no_quit (start
, 1);
5185 xassert (!STRINGP (it
->string
));
5187 /* If there isn't any `display' property in sight, and no
5188 overlays, we can just use the position of the newline in
5190 if (it
->stop_charpos
>= limit
5191 || ((pos
= Fnext_single_property_change (make_number (start
),
5193 Qnil
, make_number (limit
)),
5195 && next_overlay_change (start
) == ZV
))
5197 IT_CHARPOS (*it
) = limit
;
5198 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5199 *skipped_p
= newline_found_p
= 1;
5203 while (get_next_display_element (it
)
5204 && !newline_found_p
)
5206 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5207 set_iterator_to_next (it
, 0);
5212 it
->selective
= old_selective
;
5213 return newline_found_p
;
5217 /* Set IT's current position to the previous visible line start. Skip
5218 invisible text that is so either due to text properties or due to
5219 selective display. Caution: this does not change IT->current_x and
5223 back_to_previous_visible_line_start (it
)
5226 while (IT_CHARPOS (*it
) > BEGV
)
5228 back_to_previous_line_start (it
);
5230 if (IT_CHARPOS (*it
) <= BEGV
)
5233 /* If selective > 0, then lines indented more than that values
5235 if (it
->selective
> 0
5236 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5237 (double) it
->selective
)) /* iftc */
5240 /* Check the newline before point for invisibility. */
5243 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5244 Qinvisible
, it
->window
);
5245 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5249 if (IT_CHARPOS (*it
) <= BEGV
)
5256 Lisp_Object val
, overlay
;
5258 /* If newline is part of a composition, continue from start of composition */
5259 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5260 && beg
< IT_CHARPOS (*it
))
5263 /* If newline is replaced by a display property, find start of overlay
5264 or interval and continue search from that point. */
5266 pos
= --IT_CHARPOS (it2
);
5269 if (handle_display_prop (&it2
) == HANDLED_RETURN
5270 && !NILP (val
= get_char_property_and_overlay
5271 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5272 && (OVERLAYP (overlay
)
5273 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5274 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5277 /* Newline is not replaced by anything -- so we are done. */
5283 IT_CHARPOS (*it
) = beg
;
5284 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5288 it
->continuation_lines_width
= 0;
5290 xassert (IT_CHARPOS (*it
) >= BEGV
);
5291 xassert (IT_CHARPOS (*it
) == BEGV
5292 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5297 /* Reseat iterator IT at the previous visible line start. Skip
5298 invisible text that is so either due to text properties or due to
5299 selective display. At the end, update IT's overlay information,
5300 face information etc. */
5303 reseat_at_previous_visible_line_start (it
)
5306 back_to_previous_visible_line_start (it
);
5307 reseat (it
, it
->current
.pos
, 1);
5312 /* Reseat iterator IT on the next visible line start in the current
5313 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5314 preceding the line start. Skip over invisible text that is so
5315 because of selective display. Compute faces, overlays etc at the
5316 new position. Note that this function does not skip over text that
5317 is invisible because of text properties. */
5320 reseat_at_next_visible_line_start (it
, on_newline_p
)
5324 int newline_found_p
, skipped_p
= 0;
5326 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5328 /* Skip over lines that are invisible because they are indented
5329 more than the value of IT->selective. */
5330 if (it
->selective
> 0)
5331 while (IT_CHARPOS (*it
) < ZV
5332 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5333 (double) it
->selective
)) /* iftc */
5335 xassert (IT_BYTEPOS (*it
) == BEGV
5336 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5337 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5340 /* Position on the newline if that's what's requested. */
5341 if (on_newline_p
&& newline_found_p
)
5343 if (STRINGP (it
->string
))
5345 if (IT_STRING_CHARPOS (*it
) > 0)
5347 --IT_STRING_CHARPOS (*it
);
5348 --IT_STRING_BYTEPOS (*it
);
5351 else if (IT_CHARPOS (*it
) > BEGV
)
5355 reseat (it
, it
->current
.pos
, 0);
5359 reseat (it
, it
->current
.pos
, 0);
5366 /***********************************************************************
5367 Changing an iterator's position
5368 ***********************************************************************/
5370 /* Change IT's current position to POS in current_buffer. If FORCE_P
5371 is non-zero, always check for text properties at the new position.
5372 Otherwise, text properties are only looked up if POS >=
5373 IT->check_charpos of a property. */
5376 reseat (it
, pos
, force_p
)
5378 struct text_pos pos
;
5381 int original_pos
= IT_CHARPOS (*it
);
5383 reseat_1 (it
, pos
, 0);
5385 /* Determine where to check text properties. Avoid doing it
5386 where possible because text property lookup is very expensive. */
5388 || CHARPOS (pos
) > it
->stop_charpos
5389 || CHARPOS (pos
) < original_pos
)
5396 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5397 IT->stop_pos to POS, also. */
5400 reseat_1 (it
, pos
, set_stop_p
)
5402 struct text_pos pos
;
5405 /* Don't call this function when scanning a C string. */
5406 xassert (it
->s
== NULL
);
5408 /* POS must be a reasonable value. */
5409 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5411 it
->current
.pos
= it
->position
= pos
;
5412 it
->end_charpos
= ZV
;
5414 it
->current
.dpvec_index
= -1;
5415 it
->current
.overlay_string_index
= -1;
5416 IT_STRING_CHARPOS (*it
) = -1;
5417 IT_STRING_BYTEPOS (*it
) = -1;
5419 it
->method
= GET_FROM_BUFFER
;
5420 it
->object
= it
->w
->buffer
;
5421 it
->area
= TEXT_AREA
;
5422 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5424 it
->string_from_display_prop_p
= 0;
5425 it
->face_before_selective_p
= 0;
5428 it
->stop_charpos
= CHARPOS (pos
);
5432 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5433 If S is non-null, it is a C string to iterate over. Otherwise,
5434 STRING gives a Lisp string to iterate over.
5436 If PRECISION > 0, don't return more then PRECISION number of
5437 characters from the string.
5439 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5440 characters have been returned. FIELD_WIDTH < 0 means an infinite
5443 MULTIBYTE = 0 means disable processing of multibyte characters,
5444 MULTIBYTE > 0 means enable it,
5445 MULTIBYTE < 0 means use IT->multibyte_p.
5447 IT must be initialized via a prior call to init_iterator before
5448 calling this function. */
5451 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5456 int precision
, field_width
, multibyte
;
5458 /* No region in strings. */
5459 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5461 /* No text property checks performed by default, but see below. */
5462 it
->stop_charpos
= -1;
5464 /* Set iterator position and end position. */
5465 bzero (&it
->current
, sizeof it
->current
);
5466 it
->current
.overlay_string_index
= -1;
5467 it
->current
.dpvec_index
= -1;
5468 xassert (charpos
>= 0);
5470 /* If STRING is specified, use its multibyteness, otherwise use the
5471 setting of MULTIBYTE, if specified. */
5473 it
->multibyte_p
= multibyte
> 0;
5477 xassert (STRINGP (string
));
5478 it
->string
= string
;
5480 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5481 it
->method
= GET_FROM_STRING
;
5482 it
->current
.string_pos
= string_pos (charpos
, string
);
5489 /* Note that we use IT->current.pos, not it->current.string_pos,
5490 for displaying C strings. */
5491 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5492 if (it
->multibyte_p
)
5494 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5495 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5499 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5500 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5503 it
->method
= GET_FROM_C_STRING
;
5506 /* PRECISION > 0 means don't return more than PRECISION characters
5508 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5509 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5511 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5512 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5513 FIELD_WIDTH < 0 means infinite field width. This is useful for
5514 padding with `-' at the end of a mode line. */
5515 if (field_width
< 0)
5516 field_width
= INFINITY
;
5517 if (field_width
> it
->end_charpos
- charpos
)
5518 it
->end_charpos
= charpos
+ field_width
;
5520 /* Use the standard display table for displaying strings. */
5521 if (DISP_TABLE_P (Vstandard_display_table
))
5522 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5524 it
->stop_charpos
= charpos
;
5530 /***********************************************************************
5532 ***********************************************************************/
5534 /* Map enum it_method value to corresponding next_element_from_* function. */
5536 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5538 next_element_from_buffer
,
5539 next_element_from_display_vector
,
5540 next_element_from_composition
,
5541 next_element_from_string
,
5542 next_element_from_c_string
,
5543 next_element_from_image
,
5544 next_element_from_stretch
5548 /* Load IT's display element fields with information about the next
5549 display element from the current position of IT. Value is zero if
5550 end of buffer (or C string) is reached. */
5552 static struct frame
*last_escape_glyph_frame
= NULL
;
5553 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5554 static int last_escape_glyph_merged_face_id
= 0;
5557 get_next_display_element (it
)
5560 /* Non-zero means that we found a display element. Zero means that
5561 we hit the end of what we iterate over. Performance note: the
5562 function pointer `method' used here turns out to be faster than
5563 using a sequence of if-statements. */
5567 success_p
= (*get_next_element
[it
->method
]) (it
);
5569 if (it
->what
== IT_CHARACTER
)
5571 /* Map via display table or translate control characters.
5572 IT->c, IT->len etc. have been set to the next character by
5573 the function call above. If we have a display table, and it
5574 contains an entry for IT->c, translate it. Don't do this if
5575 IT->c itself comes from a display table, otherwise we could
5576 end up in an infinite recursion. (An alternative could be to
5577 count the recursion depth of this function and signal an
5578 error when a certain maximum depth is reached.) Is it worth
5580 if (success_p
&& it
->dpvec
== NULL
)
5585 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5588 struct Lisp_Vector
*v
= XVECTOR (dv
);
5590 /* Return the first character from the display table
5591 entry, if not empty. If empty, don't display the
5592 current character. */
5595 it
->dpvec_char_len
= it
->len
;
5596 it
->dpvec
= v
->contents
;
5597 it
->dpend
= v
->contents
+ v
->size
;
5598 it
->current
.dpvec_index
= 0;
5599 it
->dpvec_face_id
= -1;
5600 it
->saved_face_id
= it
->face_id
;
5601 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5606 set_iterator_to_next (it
, 0);
5611 /* Translate control characters into `\003' or `^C' form.
5612 Control characters coming from a display table entry are
5613 currently not translated because we use IT->dpvec to hold
5614 the translation. This could easily be changed but I
5615 don't believe that it is worth doing.
5617 If it->multibyte_p is nonzero, eight-bit characters and
5618 non-printable multibyte characters are also translated to
5621 If it->multibyte_p is zero, eight-bit characters that
5622 don't have corresponding multibyte char code are also
5623 translated to octal form. */
5624 else if ((it
->c
< ' '
5625 && (it
->area
!= TEXT_AREA
5626 /* In mode line, treat \n like other crl chars. */
5628 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5629 || (it
->c
!= '\n' && it
->c
!= '\t')))
5633 || !CHAR_PRINTABLE_P (it
->c
)
5634 || (!NILP (Vnobreak_char_display
)
5635 && (it
->c
== 0x8a0 || it
->c
== 0x8ad
5636 || it
->c
== 0x920 || it
->c
== 0x92d
5637 || it
->c
== 0xe20 || it
->c
== 0xe2d
5638 || it
->c
== 0xf20 || it
->c
== 0xf2d)))
5640 && (!unibyte_display_via_language_environment
5641 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
5643 /* IT->c is a control character which must be displayed
5644 either as '\003' or as `^C' where the '\\' and '^'
5645 can be defined in the display table. Fill
5646 IT->ctl_chars with glyphs for what we have to
5647 display. Then, set IT->dpvec to these glyphs. */
5650 int face_id
, lface_id
= 0 ;
5653 /* Handle control characters with ^. */
5655 if (it
->c
< 128 && it
->ctl_arrow_p
)
5657 g
= '^'; /* default glyph for Control */
5658 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5660 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5661 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5663 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5664 lface_id
= FAST_GLYPH_FACE (g
);
5668 g
= FAST_GLYPH_CHAR (g
);
5669 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5672 else if (it
->f
== last_escape_glyph_frame
5673 && it
->face_id
== last_escape_glyph_face_id
)
5675 face_id
= last_escape_glyph_merged_face_id
;
5679 /* Merge the escape-glyph face into the current face. */
5680 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5682 last_escape_glyph_frame
= it
->f
;
5683 last_escape_glyph_face_id
= it
->face_id
;
5684 last_escape_glyph_merged_face_id
= face_id
;
5687 XSETINT (it
->ctl_chars
[0], g
);
5689 XSETINT (it
->ctl_chars
[1], g
);
5691 goto display_control
;
5694 /* Handle non-break space in the mode where it only gets
5697 if (EQ (Vnobreak_char_display
, Qt
)
5698 && (it
->c
== 0x8a0 || it
->c
== 0x920
5699 || it
->c
== 0xe20 || it
->c
== 0xf20))
5701 /* Merge the no-break-space face into the current face. */
5702 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5706 XSETINT (it
->ctl_chars
[0], g
);
5708 goto display_control
;
5711 /* Handle sequences that start with the "escape glyph". */
5713 /* the default escape glyph is \. */
5714 escape_glyph
= '\\';
5717 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5718 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5720 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5721 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5725 /* The display table specified a face.
5726 Merge it into face_id and also into escape_glyph. */
5727 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5728 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5731 else if (it
->f
== last_escape_glyph_frame
5732 && it
->face_id
== last_escape_glyph_face_id
)
5734 face_id
= last_escape_glyph_merged_face_id
;
5738 /* Merge the escape-glyph face into the current face. */
5739 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5741 last_escape_glyph_frame
= it
->f
;
5742 last_escape_glyph_face_id
= it
->face_id
;
5743 last_escape_glyph_merged_face_id
= face_id
;
5746 /* Handle soft hyphens in the mode where they only get
5749 if (EQ (Vnobreak_char_display
, Qt
)
5750 && (it
->c
== 0x8ad || it
->c
== 0x92d
5751 || it
->c
== 0xe2d || it
->c
== 0xf2d))
5754 XSETINT (it
->ctl_chars
[0], g
);
5756 goto display_control
;
5759 /* Handle non-break space and soft hyphen
5760 with the escape glyph. */
5762 if (it
->c
== 0x8a0 || it
->c
== 0x8ad
5763 || it
->c
== 0x920 || it
->c
== 0x92d
5764 || it
->c
== 0xe20 || it
->c
== 0xe2d
5765 || it
->c
== 0xf20 || it
->c
== 0xf2d)
5767 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5768 g
= it
->c
= ((it
->c
& 0xf) == 0 ? ' ' : '-');
5769 XSETINT (it
->ctl_chars
[1], g
);
5771 goto display_control
;
5775 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5779 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5780 if (SINGLE_BYTE_CHAR_P (it
->c
))
5781 str
[0] = it
->c
, len
= 1;
5784 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5787 /* It's an invalid character, which shouldn't
5788 happen actually, but due to bugs it may
5789 happen. Let's print the char as is, there's
5790 not much meaningful we can do with it. */
5792 str
[1] = it
->c
>> 8;
5793 str
[2] = it
->c
>> 16;
5794 str
[3] = it
->c
>> 24;
5799 for (i
= 0; i
< len
; i
++)
5801 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5802 /* Insert three more glyphs into IT->ctl_chars for
5803 the octal display of the character. */
5804 g
= ((str
[i
] >> 6) & 7) + '0';
5805 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5806 g
= ((str
[i
] >> 3) & 7) + '0';
5807 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5808 g
= (str
[i
] & 7) + '0';
5809 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5815 /* Set up IT->dpvec and return first character from it. */
5816 it
->dpvec_char_len
= it
->len
;
5817 it
->dpvec
= it
->ctl_chars
;
5818 it
->dpend
= it
->dpvec
+ ctl_len
;
5819 it
->current
.dpvec_index
= 0;
5820 it
->dpvec_face_id
= face_id
;
5821 it
->saved_face_id
= it
->face_id
;
5822 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5828 /* Adjust face id for a multibyte character. There are no
5829 multibyte character in unibyte text. */
5832 && FRAME_WINDOW_P (it
->f
))
5834 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5835 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5839 /* Is this character the last one of a run of characters with
5840 box? If yes, set IT->end_of_box_run_p to 1. */
5847 it
->end_of_box_run_p
5848 = ((face_id
= face_after_it_pos (it
),
5849 face_id
!= it
->face_id
)
5850 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5851 face
->box
== FACE_NO_BOX
));
5854 /* Value is 0 if end of buffer or string reached. */
5859 /* Move IT to the next display element.
5861 RESEAT_P non-zero means if called on a newline in buffer text,
5862 skip to the next visible line start.
5864 Functions get_next_display_element and set_iterator_to_next are
5865 separate because I find this arrangement easier to handle than a
5866 get_next_display_element function that also increments IT's
5867 position. The way it is we can first look at an iterator's current
5868 display element, decide whether it fits on a line, and if it does,
5869 increment the iterator position. The other way around we probably
5870 would either need a flag indicating whether the iterator has to be
5871 incremented the next time, or we would have to implement a
5872 decrement position function which would not be easy to write. */
5875 set_iterator_to_next (it
, reseat_p
)
5879 /* Reset flags indicating start and end of a sequence of characters
5880 with box. Reset them at the start of this function because
5881 moving the iterator to a new position might set them. */
5882 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5886 case GET_FROM_BUFFER
:
5887 /* The current display element of IT is a character from
5888 current_buffer. Advance in the buffer, and maybe skip over
5889 invisible lines that are so because of selective display. */
5890 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5891 reseat_at_next_visible_line_start (it
, 0);
5894 xassert (it
->len
!= 0);
5895 IT_BYTEPOS (*it
) += it
->len
;
5896 IT_CHARPOS (*it
) += 1;
5897 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5901 case GET_FROM_COMPOSITION
:
5902 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5903 xassert (it
->sp
> 0);
5905 if (it
->method
== GET_FROM_STRING
)
5907 IT_STRING_BYTEPOS (*it
) += it
->len
;
5908 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5909 goto consider_string_end
;
5911 else if (it
->method
== GET_FROM_BUFFER
)
5913 IT_BYTEPOS (*it
) += it
->len
;
5914 IT_CHARPOS (*it
) += it
->cmp_len
;
5918 case GET_FROM_C_STRING
:
5919 /* Current display element of IT is from a C string. */
5920 IT_BYTEPOS (*it
) += it
->len
;
5921 IT_CHARPOS (*it
) += 1;
5924 case GET_FROM_DISPLAY_VECTOR
:
5925 /* Current display element of IT is from a display table entry.
5926 Advance in the display table definition. Reset it to null if
5927 end reached, and continue with characters from buffers/
5929 ++it
->current
.dpvec_index
;
5931 /* Restore face of the iterator to what they were before the
5932 display vector entry (these entries may contain faces). */
5933 it
->face_id
= it
->saved_face_id
;
5935 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5937 int recheck_faces
= it
->ellipsis_p
;
5940 it
->method
= GET_FROM_C_STRING
;
5941 else if (STRINGP (it
->string
))
5942 it
->method
= GET_FROM_STRING
;
5945 it
->method
= GET_FROM_BUFFER
;
5946 it
->object
= it
->w
->buffer
;
5950 it
->current
.dpvec_index
= -1;
5952 /* Skip over characters which were displayed via IT->dpvec. */
5953 if (it
->dpvec_char_len
< 0)
5954 reseat_at_next_visible_line_start (it
, 1);
5955 else if (it
->dpvec_char_len
> 0)
5957 if (it
->method
== GET_FROM_STRING
5958 && it
->n_overlay_strings
> 0)
5959 it
->ignore_overlay_strings_at_pos_p
= 1;
5960 it
->len
= it
->dpvec_char_len
;
5961 set_iterator_to_next (it
, reseat_p
);
5964 /* Maybe recheck faces after display vector */
5966 it
->stop_charpos
= IT_CHARPOS (*it
);
5970 case GET_FROM_STRING
:
5971 /* Current display element is a character from a Lisp string. */
5972 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5973 IT_STRING_BYTEPOS (*it
) += it
->len
;
5974 IT_STRING_CHARPOS (*it
) += 1;
5976 consider_string_end
:
5978 if (it
->current
.overlay_string_index
>= 0)
5980 /* IT->string is an overlay string. Advance to the
5981 next, if there is one. */
5982 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5983 next_overlay_string (it
);
5987 /* IT->string is not an overlay string. If we reached
5988 its end, and there is something on IT->stack, proceed
5989 with what is on the stack. This can be either another
5990 string, this time an overlay string, or a buffer. */
5991 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5995 if (it
->method
== GET_FROM_STRING
)
5996 goto consider_string_end
;
6001 case GET_FROM_IMAGE
:
6002 case GET_FROM_STRETCH
:
6003 /* The position etc with which we have to proceed are on
6004 the stack. The position may be at the end of a string,
6005 if the `display' property takes up the whole string. */
6006 xassert (it
->sp
> 0);
6008 if (it
->method
== GET_FROM_STRING
)
6009 goto consider_string_end
;
6013 /* There are no other methods defined, so this should be a bug. */
6017 xassert (it
->method
!= GET_FROM_STRING
6018 || (STRINGP (it
->string
)
6019 && IT_STRING_CHARPOS (*it
) >= 0));
6022 /* Load IT's display element fields with information about the next
6023 display element which comes from a display table entry or from the
6024 result of translating a control character to one of the forms `^C'
6027 IT->dpvec holds the glyphs to return as characters.
6028 IT->saved_face_id holds the face id before the display vector--
6029 it is restored into IT->face_idin set_iterator_to_next. */
6032 next_element_from_display_vector (it
)
6036 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6038 it
->face_id
= it
->saved_face_id
;
6040 if (INTEGERP (*it
->dpvec
)
6041 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
6045 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
6046 it
->c
= FAST_GLYPH_CHAR (g
);
6047 it
->len
= CHAR_BYTES (it
->c
);
6049 /* The entry may contain a face id to use. Such a face id is
6050 the id of a Lisp face, not a realized face. A face id of
6051 zero means no face is specified. */
6052 if (it
->dpvec_face_id
>= 0)
6053 it
->face_id
= it
->dpvec_face_id
;
6056 int lface_id
= FAST_GLYPH_FACE (g
);
6058 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6063 /* Display table entry is invalid. Return a space. */
6064 it
->c
= ' ', it
->len
= 1;
6066 /* Don't change position and object of the iterator here. They are
6067 still the values of the character that had this display table
6068 entry or was translated, and that's what we want. */
6069 it
->what
= IT_CHARACTER
;
6074 /* Load IT with the next display element from Lisp string IT->string.
6075 IT->current.string_pos is the current position within the string.
6076 If IT->current.overlay_string_index >= 0, the Lisp string is an
6080 next_element_from_string (it
)
6083 struct text_pos position
;
6085 xassert (STRINGP (it
->string
));
6086 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6087 position
= it
->current
.string_pos
;
6089 /* Time to check for invisible text? */
6090 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6091 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6095 /* Since a handler may have changed IT->method, we must
6097 return get_next_display_element (it
);
6100 if (it
->current
.overlay_string_index
>= 0)
6102 /* Get the next character from an overlay string. In overlay
6103 strings, There is no field width or padding with spaces to
6105 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6110 else if (STRING_MULTIBYTE (it
->string
))
6112 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6113 const unsigned char *s
= (SDATA (it
->string
)
6114 + IT_STRING_BYTEPOS (*it
));
6115 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
6119 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6125 /* Get the next character from a Lisp string that is not an
6126 overlay string. Such strings come from the mode line, for
6127 example. We may have to pad with spaces, or truncate the
6128 string. See also next_element_from_c_string. */
6129 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6134 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6136 /* Pad with spaces. */
6137 it
->c
= ' ', it
->len
= 1;
6138 CHARPOS (position
) = BYTEPOS (position
) = -1;
6140 else if (STRING_MULTIBYTE (it
->string
))
6142 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6143 const unsigned char *s
= (SDATA (it
->string
)
6144 + IT_STRING_BYTEPOS (*it
));
6145 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
6149 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6154 /* Record what we have and where it came from. */
6155 it
->what
= IT_CHARACTER
;
6156 it
->object
= it
->string
;
6157 it
->position
= position
;
6162 /* Load IT with next display element from C string IT->s.
6163 IT->string_nchars is the maximum number of characters to return
6164 from the string. IT->end_charpos may be greater than
6165 IT->string_nchars when this function is called, in which case we
6166 may have to return padding spaces. Value is zero if end of string
6167 reached, including padding spaces. */
6170 next_element_from_c_string (it
)
6176 it
->what
= IT_CHARACTER
;
6177 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6180 /* IT's position can be greater IT->string_nchars in case a field
6181 width or precision has been specified when the iterator was
6183 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6185 /* End of the game. */
6189 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6191 /* Pad with spaces. */
6192 it
->c
= ' ', it
->len
= 1;
6193 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6195 else if (it
->multibyte_p
)
6197 /* Implementation note: The calls to strlen apparently aren't a
6198 performance problem because there is no noticeable performance
6199 difference between Emacs running in unibyte or multibyte mode. */
6200 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6201 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
6205 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6211 /* Set up IT to return characters from an ellipsis, if appropriate.
6212 The definition of the ellipsis glyphs may come from a display table
6213 entry. This function Fills IT with the first glyph from the
6214 ellipsis if an ellipsis is to be displayed. */
6217 next_element_from_ellipsis (it
)
6220 if (it
->selective_display_ellipsis_p
)
6221 setup_for_ellipsis (it
, it
->len
);
6224 /* The face at the current position may be different from the
6225 face we find after the invisible text. Remember what it
6226 was in IT->saved_face_id, and signal that it's there by
6227 setting face_before_selective_p. */
6228 it
->saved_face_id
= it
->face_id
;
6229 it
->method
= GET_FROM_BUFFER
;
6230 it
->object
= it
->w
->buffer
;
6231 reseat_at_next_visible_line_start (it
, 1);
6232 it
->face_before_selective_p
= 1;
6235 return get_next_display_element (it
);
6239 /* Deliver an image display element. The iterator IT is already
6240 filled with image information (done in handle_display_prop). Value
6245 next_element_from_image (it
)
6248 it
->what
= IT_IMAGE
;
6253 /* Fill iterator IT with next display element from a stretch glyph
6254 property. IT->object is the value of the text property. Value is
6258 next_element_from_stretch (it
)
6261 it
->what
= IT_STRETCH
;
6266 /* Load IT with the next display element from current_buffer. Value
6267 is zero if end of buffer reached. IT->stop_charpos is the next
6268 position at which to stop and check for text properties or buffer
6272 next_element_from_buffer (it
)
6277 /* Check this assumption, otherwise, we would never enter the
6278 if-statement, below. */
6279 xassert (IT_CHARPOS (*it
) >= BEGV
6280 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
6282 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6284 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6286 int overlay_strings_follow_p
;
6288 /* End of the game, except when overlay strings follow that
6289 haven't been returned yet. */
6290 if (it
->overlay_strings_at_end_processed_p
)
6291 overlay_strings_follow_p
= 0;
6294 it
->overlay_strings_at_end_processed_p
= 1;
6295 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6298 if (overlay_strings_follow_p
)
6299 success_p
= get_next_display_element (it
);
6303 it
->position
= it
->current
.pos
;
6310 return get_next_display_element (it
);
6315 /* No face changes, overlays etc. in sight, so just return a
6316 character from current_buffer. */
6319 /* Maybe run the redisplay end trigger hook. Performance note:
6320 This doesn't seem to cost measurable time. */
6321 if (it
->redisplay_end_trigger_charpos
6323 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6324 run_redisplay_end_trigger_hook (it
);
6326 /* Get the next character, maybe multibyte. */
6327 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6328 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6330 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
6331 - IT_BYTEPOS (*it
));
6332 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
6335 it
->c
= *p
, it
->len
= 1;
6337 /* Record what we have and where it came from. */
6338 it
->what
= IT_CHARACTER
;
6339 it
->object
= it
->w
->buffer
;
6340 it
->position
= it
->current
.pos
;
6342 /* Normally we return the character found above, except when we
6343 really want to return an ellipsis for selective display. */
6348 /* A value of selective > 0 means hide lines indented more
6349 than that number of columns. */
6350 if (it
->selective
> 0
6351 && IT_CHARPOS (*it
) + 1 < ZV
6352 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6353 IT_BYTEPOS (*it
) + 1,
6354 (double) it
->selective
)) /* iftc */
6356 success_p
= next_element_from_ellipsis (it
);
6357 it
->dpvec_char_len
= -1;
6360 else if (it
->c
== '\r' && it
->selective
== -1)
6362 /* A value of selective == -1 means that everything from the
6363 CR to the end of the line is invisible, with maybe an
6364 ellipsis displayed for it. */
6365 success_p
= next_element_from_ellipsis (it
);
6366 it
->dpvec_char_len
= -1;
6371 /* Value is zero if end of buffer reached. */
6372 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6377 /* Run the redisplay end trigger hook for IT. */
6380 run_redisplay_end_trigger_hook (it
)
6383 Lisp_Object args
[3];
6385 /* IT->glyph_row should be non-null, i.e. we should be actually
6386 displaying something, or otherwise we should not run the hook. */
6387 xassert (it
->glyph_row
);
6389 /* Set up hook arguments. */
6390 args
[0] = Qredisplay_end_trigger_functions
;
6391 args
[1] = it
->window
;
6392 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6393 it
->redisplay_end_trigger_charpos
= 0;
6395 /* Since we are *trying* to run these functions, don't try to run
6396 them again, even if they get an error. */
6397 it
->w
->redisplay_end_trigger
= Qnil
;
6398 Frun_hook_with_args (3, args
);
6400 /* Notice if it changed the face of the character we are on. */
6401 handle_face_prop (it
);
6405 /* Deliver a composition display element. The iterator IT is already
6406 filled with composition information (done in
6407 handle_composition_prop). Value is always 1. */
6410 next_element_from_composition (it
)
6413 it
->what
= IT_COMPOSITION
;
6414 it
->position
= (STRINGP (it
->string
)
6415 ? it
->current
.string_pos
6417 if (STRINGP (it
->string
))
6418 it
->object
= it
->string
;
6420 it
->object
= it
->w
->buffer
;
6426 /***********************************************************************
6427 Moving an iterator without producing glyphs
6428 ***********************************************************************/
6430 /* Check if iterator is at a position corresponding to a valid buffer
6431 position after some move_it_ call. */
6433 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6434 ((it)->method == GET_FROM_STRING \
6435 ? IT_STRING_CHARPOS (*it) == 0 \
6439 /* Move iterator IT to a specified buffer or X position within one
6440 line on the display without producing glyphs.
6442 OP should be a bit mask including some or all of these bits:
6443 MOVE_TO_X: Stop on reaching x-position TO_X.
6444 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6445 Regardless of OP's value, stop in reaching the end of the display line.
6447 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6448 This means, in particular, that TO_X includes window's horizontal
6451 The return value has several possible values that
6452 say what condition caused the scan to stop:
6454 MOVE_POS_MATCH_OR_ZV
6455 - when TO_POS or ZV was reached.
6458 -when TO_X was reached before TO_POS or ZV were reached.
6461 - when we reached the end of the display area and the line must
6465 - when we reached the end of the display area and the line is
6469 - when we stopped at a line end, i.e. a newline or a CR and selective
6472 static enum move_it_result
6473 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
6475 int to_charpos
, to_x
, op
;
6477 enum move_it_result result
= MOVE_UNDEFINED
;
6478 struct glyph_row
*saved_glyph_row
;
6480 /* Don't produce glyphs in produce_glyphs. */
6481 saved_glyph_row
= it
->glyph_row
;
6482 it
->glyph_row
= NULL
;
6484 #define BUFFER_POS_REACHED_P() \
6485 ((op & MOVE_TO_POS) != 0 \
6486 && BUFFERP (it->object) \
6487 && IT_CHARPOS (*it) >= to_charpos \
6488 && (it->method == GET_FROM_BUFFER \
6489 || (it->method == GET_FROM_DISPLAY_VECTOR \
6490 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6495 int x
, i
, ascent
= 0, descent
= 0;
6497 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
6498 if ((op
& MOVE_TO_POS
) != 0
6499 && BUFFERP (it
->object
)
6500 && it
->method
== GET_FROM_BUFFER
6501 && IT_CHARPOS (*it
) > to_charpos
)
6503 result
= MOVE_POS_MATCH_OR_ZV
;
6507 /* Stop when ZV reached.
6508 We used to stop here when TO_CHARPOS reached as well, but that is
6509 too soon if this glyph does not fit on this line. So we handle it
6510 explicitly below. */
6511 if (!get_next_display_element (it
)
6512 || (it
->truncate_lines_p
6513 && BUFFER_POS_REACHED_P ()))
6515 result
= MOVE_POS_MATCH_OR_ZV
;
6519 /* The call to produce_glyphs will get the metrics of the
6520 display element IT is loaded with. We record in x the
6521 x-position before this display element in case it does not
6525 /* Remember the line height so far in case the next element doesn't
6527 if (!it
->truncate_lines_p
)
6529 ascent
= it
->max_ascent
;
6530 descent
= it
->max_descent
;
6533 PRODUCE_GLYPHS (it
);
6535 if (it
->area
!= TEXT_AREA
)
6537 set_iterator_to_next (it
, 1);
6541 /* The number of glyphs we get back in IT->nglyphs will normally
6542 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6543 character on a terminal frame, or (iii) a line end. For the
6544 second case, IT->nglyphs - 1 padding glyphs will be present
6545 (on X frames, there is only one glyph produced for a
6546 composite character.
6548 The behavior implemented below means, for continuation lines,
6549 that as many spaces of a TAB as fit on the current line are
6550 displayed there. For terminal frames, as many glyphs of a
6551 multi-glyph character are displayed in the current line, too.
6552 This is what the old redisplay code did, and we keep it that
6553 way. Under X, the whole shape of a complex character must
6554 fit on the line or it will be completely displayed in the
6557 Note that both for tabs and padding glyphs, all glyphs have
6561 /* More than one glyph or glyph doesn't fit on line. All
6562 glyphs have the same width. */
6563 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6565 int x_before_this_char
= x
;
6566 int hpos_before_this_char
= it
->hpos
;
6568 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6570 new_x
= x
+ single_glyph_width
;
6572 /* We want to leave anything reaching TO_X to the caller. */
6573 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6575 if (BUFFER_POS_REACHED_P ())
6576 goto buffer_pos_reached
;
6578 result
= MOVE_X_REACHED
;
6581 else if (/* Lines are continued. */
6582 !it
->truncate_lines_p
6583 && (/* And glyph doesn't fit on the line. */
6584 new_x
> it
->last_visible_x
6585 /* Or it fits exactly and we're on a window
6587 || (new_x
== it
->last_visible_x
6588 && FRAME_WINDOW_P (it
->f
))))
6590 if (/* IT->hpos == 0 means the very first glyph
6591 doesn't fit on the line, e.g. a wide image. */
6593 || (new_x
== it
->last_visible_x
6594 && FRAME_WINDOW_P (it
->f
)))
6597 it
->current_x
= new_x
;
6599 /* The character's last glyph just barely fits
6601 if (i
== it
->nglyphs
- 1)
6603 /* If this is the destination position,
6604 return a position *before* it in this row,
6605 now that we know it fits in this row. */
6606 if (BUFFER_POS_REACHED_P ())
6608 it
->hpos
= hpos_before_this_char
;
6609 it
->current_x
= x_before_this_char
;
6610 result
= MOVE_POS_MATCH_OR_ZV
;
6614 set_iterator_to_next (it
, 1);
6615 #ifdef HAVE_WINDOW_SYSTEM
6616 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6618 if (!get_next_display_element (it
))
6620 result
= MOVE_POS_MATCH_OR_ZV
;
6623 if (BUFFER_POS_REACHED_P ())
6625 if (ITERATOR_AT_END_OF_LINE_P (it
))
6626 result
= MOVE_POS_MATCH_OR_ZV
;
6628 result
= MOVE_LINE_CONTINUED
;
6631 if (ITERATOR_AT_END_OF_LINE_P (it
))
6633 result
= MOVE_NEWLINE_OR_CR
;
6637 #endif /* HAVE_WINDOW_SYSTEM */
6643 it
->max_ascent
= ascent
;
6644 it
->max_descent
= descent
;
6647 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6649 result
= MOVE_LINE_CONTINUED
;
6652 else if (BUFFER_POS_REACHED_P ())
6653 goto buffer_pos_reached
;
6654 else if (new_x
> it
->first_visible_x
)
6656 /* Glyph is visible. Increment number of glyphs that
6657 would be displayed. */
6662 /* Glyph is completely off the left margin of the display
6663 area. Nothing to do. */
6667 if (result
!= MOVE_UNDEFINED
)
6670 else if (BUFFER_POS_REACHED_P ())
6674 it
->max_ascent
= ascent
;
6675 it
->max_descent
= descent
;
6676 result
= MOVE_POS_MATCH_OR_ZV
;
6679 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6681 /* Stop when TO_X specified and reached. This check is
6682 necessary here because of lines consisting of a line end,
6683 only. The line end will not produce any glyphs and we
6684 would never get MOVE_X_REACHED. */
6685 xassert (it
->nglyphs
== 0);
6686 result
= MOVE_X_REACHED
;
6690 /* Is this a line end? If yes, we're done. */
6691 if (ITERATOR_AT_END_OF_LINE_P (it
))
6693 result
= MOVE_NEWLINE_OR_CR
;
6697 /* The current display element has been consumed. Advance
6699 set_iterator_to_next (it
, 1);
6701 /* Stop if lines are truncated and IT's current x-position is
6702 past the right edge of the window now. */
6703 if (it
->truncate_lines_p
6704 && it
->current_x
>= it
->last_visible_x
)
6706 #ifdef HAVE_WINDOW_SYSTEM
6707 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6709 if (!get_next_display_element (it
)
6710 || BUFFER_POS_REACHED_P ())
6712 result
= MOVE_POS_MATCH_OR_ZV
;
6715 if (ITERATOR_AT_END_OF_LINE_P (it
))
6717 result
= MOVE_NEWLINE_OR_CR
;
6721 #endif /* HAVE_WINDOW_SYSTEM */
6722 result
= MOVE_LINE_TRUNCATED
;
6727 #undef BUFFER_POS_REACHED_P
6729 /* Restore the iterator settings altered at the beginning of this
6731 it
->glyph_row
= saved_glyph_row
;
6736 /* Move IT forward until it satisfies one or more of the criteria in
6737 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6739 OP is a bit-mask that specifies where to stop, and in particular,
6740 which of those four position arguments makes a difference. See the
6741 description of enum move_operation_enum.
6743 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6744 screen line, this function will set IT to the next position >
6748 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6750 int to_charpos
, to_x
, to_y
, to_vpos
;
6753 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6759 if (op
& MOVE_TO_VPOS
)
6761 /* If no TO_CHARPOS and no TO_X specified, stop at the
6762 start of the line TO_VPOS. */
6763 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6765 if (it
->vpos
== to_vpos
)
6771 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6775 /* TO_VPOS >= 0 means stop at TO_X in the line at
6776 TO_VPOS, or at TO_POS, whichever comes first. */
6777 if (it
->vpos
== to_vpos
)
6783 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6785 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6790 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6792 /* We have reached TO_X but not in the line we want. */
6793 skip
= move_it_in_display_line_to (it
, to_charpos
,
6795 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6803 else if (op
& MOVE_TO_Y
)
6805 struct it it_backup
;
6807 /* TO_Y specified means stop at TO_X in the line containing
6808 TO_Y---or at TO_CHARPOS if this is reached first. The
6809 problem is that we can't really tell whether the line
6810 contains TO_Y before we have completely scanned it, and
6811 this may skip past TO_X. What we do is to first scan to
6814 If TO_X is not specified, use a TO_X of zero. The reason
6815 is to make the outcome of this function more predictable.
6816 If we didn't use TO_X == 0, we would stop at the end of
6817 the line which is probably not what a caller would expect
6819 skip
= move_it_in_display_line_to (it
, to_charpos
,
6823 | (op
& MOVE_TO_POS
)));
6825 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6826 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6832 /* If TO_X was reached, we would like to know whether TO_Y
6833 is in the line. This can only be said if we know the
6834 total line height which requires us to scan the rest of
6836 if (skip
== MOVE_X_REACHED
)
6839 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6840 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6842 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6845 /* Now, decide whether TO_Y is in this line. */
6846 line_height
= it
->max_ascent
+ it
->max_descent
;
6847 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6849 if (to_y
>= it
->current_y
6850 && to_y
< it
->current_y
+ line_height
)
6852 if (skip
== MOVE_X_REACHED
)
6853 /* If TO_Y is in this line and TO_X was reached above,
6854 we scanned too far. We have to restore IT's settings
6855 to the ones before skipping. */
6859 else if (skip
== MOVE_X_REACHED
)
6862 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6869 else if (BUFFERP (it
->object
)
6870 && it
->method
== GET_FROM_BUFFER
6871 && IT_CHARPOS (*it
) >= to_charpos
)
6872 skip
= MOVE_POS_MATCH_OR_ZV
;
6874 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6878 case MOVE_POS_MATCH_OR_ZV
:
6882 case MOVE_NEWLINE_OR_CR
:
6883 set_iterator_to_next (it
, 1);
6884 it
->continuation_lines_width
= 0;
6887 case MOVE_LINE_TRUNCATED
:
6888 it
->continuation_lines_width
= 0;
6889 reseat_at_next_visible_line_start (it
, 0);
6890 if ((op
& MOVE_TO_POS
) != 0
6891 && IT_CHARPOS (*it
) > to_charpos
)
6898 case MOVE_LINE_CONTINUED
:
6899 /* For continued lines ending in a tab, some of the glyphs
6900 associated with the tab are displayed on the current
6901 line. Since it->current_x does not include these glyphs,
6902 we use it->last_visible_x instead. */
6903 it
->continuation_lines_width
+=
6904 (it
->c
== '\t') ? it
->last_visible_x
: it
->current_x
;
6911 /* Reset/increment for the next run. */
6912 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6913 it
->current_x
= it
->hpos
= 0;
6914 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6916 last_height
= it
->max_ascent
+ it
->max_descent
;
6917 last_max_ascent
= it
->max_ascent
;
6918 it
->max_ascent
= it
->max_descent
= 0;
6923 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6927 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6929 If DY > 0, move IT backward at least that many pixels. DY = 0
6930 means move IT backward to the preceding line start or BEGV. This
6931 function may move over more than DY pixels if IT->current_y - DY
6932 ends up in the middle of a line; in this case IT->current_y will be
6933 set to the top of the line moved to. */
6936 move_it_vertically_backward (it
, dy
)
6947 start_pos
= IT_CHARPOS (*it
);
6949 /* Estimate how many newlines we must move back. */
6950 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6952 /* Set the iterator's position that many lines back. */
6953 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6954 back_to_previous_visible_line_start (it
);
6956 /* Reseat the iterator here. When moving backward, we don't want
6957 reseat to skip forward over invisible text, set up the iterator
6958 to deliver from overlay strings at the new position etc. So,
6959 use reseat_1 here. */
6960 reseat_1 (it
, it
->current
.pos
, 1);
6962 /* We are now surely at a line start. */
6963 it
->current_x
= it
->hpos
= 0;
6964 it
->continuation_lines_width
= 0;
6966 /* Move forward and see what y-distance we moved. First move to the
6967 start of the next line so that we get its height. We need this
6968 height to be able to tell whether we reached the specified
6971 it2
.max_ascent
= it2
.max_descent
= 0;
6974 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6975 MOVE_TO_POS
| MOVE_TO_VPOS
);
6977 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
6978 xassert (IT_CHARPOS (*it
) >= BEGV
);
6981 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6982 xassert (IT_CHARPOS (*it
) >= BEGV
);
6983 /* H is the actual vertical distance from the position in *IT
6984 and the starting position. */
6985 h
= it2
.current_y
- it
->current_y
;
6986 /* NLINES is the distance in number of lines. */
6987 nlines
= it2
.vpos
- it
->vpos
;
6989 /* Correct IT's y and vpos position
6990 so that they are relative to the starting point. */
6996 /* DY == 0 means move to the start of the screen line. The
6997 value of nlines is > 0 if continuation lines were involved. */
6999 move_it_by_lines (it
, nlines
, 1);
7001 /* I think this assert is bogus if buffer contains
7002 invisible text or images. KFS. */
7003 xassert (IT_CHARPOS (*it
) <= start_pos
);
7008 /* The y-position we try to reach, relative to *IT.
7009 Note that H has been subtracted in front of the if-statement. */
7010 int target_y
= it
->current_y
+ h
- dy
;
7011 int y0
= it3
.current_y
;
7012 int y1
= line_bottom_y (&it3
);
7013 int line_height
= y1
- y0
;
7015 /* If we did not reach target_y, try to move further backward if
7016 we can. If we moved too far backward, try to move forward. */
7017 if (target_y
< it
->current_y
7018 /* This is heuristic. In a window that's 3 lines high, with
7019 a line height of 13 pixels each, recentering with point
7020 on the bottom line will try to move -39/2 = 19 pixels
7021 backward. Try to avoid moving into the first line. */
7022 && (it
->current_y
- target_y
7023 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7024 && IT_CHARPOS (*it
) > BEGV
)
7026 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7027 target_y
- it
->current_y
));
7028 dy
= it
->current_y
- target_y
;
7029 goto move_further_back
;
7031 else if (target_y
>= it
->current_y
+ line_height
7032 && IT_CHARPOS (*it
) < ZV
)
7034 /* Should move forward by at least one line, maybe more.
7036 Note: Calling move_it_by_lines can be expensive on
7037 terminal frames, where compute_motion is used (via
7038 vmotion) to do the job, when there are very long lines
7039 and truncate-lines is nil. That's the reason for
7040 treating terminal frames specially here. */
7042 if (!FRAME_WINDOW_P (it
->f
))
7043 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7048 move_it_by_lines (it
, 1, 1);
7050 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7054 /* I think this assert is bogus if buffer contains
7055 invisible text or images. KFS. */
7056 xassert (IT_CHARPOS (*it
) >= BEGV
);
7063 /* Move IT by a specified amount of pixel lines DY. DY negative means
7064 move backwards. DY = 0 means move to start of screen line. At the
7065 end, IT will be on the start of a screen line. */
7068 move_it_vertically (it
, dy
)
7073 move_it_vertically_backward (it
, -dy
);
7076 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7077 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7078 MOVE_TO_POS
| MOVE_TO_Y
);
7079 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7081 /* If buffer ends in ZV without a newline, move to the start of
7082 the line to satisfy the post-condition. */
7083 if (IT_CHARPOS (*it
) == ZV
7085 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7086 move_it_by_lines (it
, 0, 0);
7091 /* Move iterator IT past the end of the text line it is in. */
7094 move_it_past_eol (it
)
7097 enum move_it_result rc
;
7099 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7100 if (rc
== MOVE_NEWLINE_OR_CR
)
7101 set_iterator_to_next (it
, 0);
7105 #if 0 /* Currently not used. */
7107 /* Return non-zero if some text between buffer positions START_CHARPOS
7108 and END_CHARPOS is invisible. IT->window is the window for text
7112 invisible_text_between_p (it
, start_charpos
, end_charpos
)
7114 int start_charpos
, end_charpos
;
7116 Lisp_Object prop
, limit
;
7117 int invisible_found_p
;
7119 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
7121 /* Is text at START invisible? */
7122 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
7124 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
7125 invisible_found_p
= 1;
7128 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
7130 make_number (end_charpos
));
7131 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
7134 return invisible_found_p
;
7140 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7141 negative means move up. DVPOS == 0 means move to the start of the
7142 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7143 NEED_Y_P is zero, IT->current_y will be left unchanged.
7145 Further optimization ideas: If we would know that IT->f doesn't use
7146 a face with proportional font, we could be faster for
7147 truncate-lines nil. */
7150 move_it_by_lines (it
, dvpos
, need_y_p
)
7152 int dvpos
, need_y_p
;
7154 struct position pos
;
7156 /* The commented-out optimization uses vmotion on terminals. This
7157 gives bad results, because elements like it->what, on which
7158 callers such as pos_visible_p rely, aren't updated. */
7159 /* if (!FRAME_WINDOW_P (it->f))
7161 struct text_pos textpos;
7163 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7164 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7165 reseat (it, textpos, 1);
7166 it->vpos += pos.vpos;
7167 it->current_y += pos.vpos;
7173 /* DVPOS == 0 means move to the start of the screen line. */
7174 move_it_vertically_backward (it
, 0);
7175 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7176 /* Let next call to line_bottom_y calculate real line height */
7181 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7182 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7183 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7188 int start_charpos
, i
;
7190 /* Start at the beginning of the screen line containing IT's
7191 position. This may actually move vertically backwards,
7192 in case of overlays, so adjust dvpos accordingly. */
7194 move_it_vertically_backward (it
, 0);
7197 /* Go back -DVPOS visible lines and reseat the iterator there. */
7198 start_charpos
= IT_CHARPOS (*it
);
7199 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7200 back_to_previous_visible_line_start (it
);
7201 reseat (it
, it
->current
.pos
, 1);
7203 /* Move further back if we end up in a string or an image. */
7204 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7206 /* First try to move to start of display line. */
7208 move_it_vertically_backward (it
, 0);
7210 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7212 /* If start of line is still in string or image,
7213 move further back. */
7214 back_to_previous_visible_line_start (it
);
7215 reseat (it
, it
->current
.pos
, 1);
7219 it
->current_x
= it
->hpos
= 0;
7221 /* Above call may have moved too far if continuation lines
7222 are involved. Scan forward and see if it did. */
7224 it2
.vpos
= it2
.current_y
= 0;
7225 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7226 it
->vpos
-= it2
.vpos
;
7227 it
->current_y
-= it2
.current_y
;
7228 it
->current_x
= it
->hpos
= 0;
7230 /* If we moved too far back, move IT some lines forward. */
7231 if (it2
.vpos
> -dvpos
)
7233 int delta
= it2
.vpos
+ dvpos
;
7235 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7236 /* Move back again if we got too far ahead. */
7237 if (IT_CHARPOS (*it
) >= start_charpos
)
7243 /* Return 1 if IT points into the middle of a display vector. */
7246 in_display_vector_p (it
)
7249 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7250 && it
->current
.dpvec_index
> 0
7251 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7255 /***********************************************************************
7257 ***********************************************************************/
7260 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7264 add_to_log (format
, arg1
, arg2
)
7266 Lisp_Object arg1
, arg2
;
7268 Lisp_Object args
[3];
7269 Lisp_Object msg
, fmt
;
7272 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7275 /* Do nothing if called asynchronously. Inserting text into
7276 a buffer may call after-change-functions and alike and
7277 that would means running Lisp asynchronously. */
7278 if (handling_signal
)
7282 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7284 args
[0] = fmt
= build_string (format
);
7287 msg
= Fformat (3, args
);
7289 len
= SBYTES (msg
) + 1;
7290 SAFE_ALLOCA (buffer
, char *, len
);
7291 bcopy (SDATA (msg
), buffer
, len
);
7293 message_dolog (buffer
, len
- 1, 1, 0);
7300 /* Output a newline in the *Messages* buffer if "needs" one. */
7303 message_log_maybe_newline ()
7305 if (message_log_need_newline
)
7306 message_dolog ("", 0, 1, 0);
7310 /* Add a string M of length NBYTES to the message log, optionally
7311 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7312 nonzero, means interpret the contents of M as multibyte. This
7313 function calls low-level routines in order to bypass text property
7314 hooks, etc. which might not be safe to run.
7316 This may GC (insert may run before/after change hooks),
7317 so the buffer M must NOT point to a Lisp string. */
7320 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7322 int nbytes
, nlflag
, multibyte
;
7324 if (!NILP (Vmemory_full
))
7327 if (!NILP (Vmessage_log_max
))
7329 struct buffer
*oldbuf
;
7330 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7331 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7332 int point_at_end
= 0;
7334 Lisp_Object old_deactivate_mark
, tem
;
7335 struct gcpro gcpro1
;
7337 old_deactivate_mark
= Vdeactivate_mark
;
7338 oldbuf
= current_buffer
;
7339 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7340 current_buffer
->undo_list
= Qt
;
7342 oldpoint
= message_dolog_marker1
;
7343 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7344 oldbegv
= message_dolog_marker2
;
7345 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7346 oldzv
= message_dolog_marker3
;
7347 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7348 GCPRO1 (old_deactivate_mark
);
7356 BEGV_BYTE
= BEG_BYTE
;
7359 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7361 /* Insert the string--maybe converting multibyte to single byte
7362 or vice versa, so that all the text fits the buffer. */
7364 && NILP (current_buffer
->enable_multibyte_characters
))
7366 int i
, c
, char_bytes
;
7367 unsigned char work
[1];
7369 /* Convert a multibyte string to single-byte
7370 for the *Message* buffer. */
7371 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7373 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7374 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7376 : multibyte_char_to_unibyte (c
, Qnil
));
7377 insert_1_both (work
, 1, 1, 1, 0, 0);
7380 else if (! multibyte
7381 && ! NILP (current_buffer
->enable_multibyte_characters
))
7383 int i
, c
, char_bytes
;
7384 unsigned char *msg
= (unsigned char *) m
;
7385 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7386 /* Convert a single-byte string to multibyte
7387 for the *Message* buffer. */
7388 for (i
= 0; i
< nbytes
; i
++)
7390 c
= unibyte_char_to_multibyte (msg
[i
]);
7391 char_bytes
= CHAR_STRING (c
, str
);
7392 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7396 insert_1 (m
, nbytes
, 1, 0, 0);
7400 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7401 insert_1 ("\n", 1, 1, 0, 0);
7403 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7405 this_bol_byte
= PT_BYTE
;
7407 /* See if this line duplicates the previous one.
7408 If so, combine duplicates. */
7411 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7413 prev_bol_byte
= PT_BYTE
;
7415 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7416 this_bol
, this_bol_byte
);
7419 del_range_both (prev_bol
, prev_bol_byte
,
7420 this_bol
, this_bol_byte
, 0);
7426 /* If you change this format, don't forget to also
7427 change message_log_check_duplicate. */
7428 sprintf (dupstr
, " [%d times]", dup
);
7429 duplen
= strlen (dupstr
);
7430 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7431 insert_1 (dupstr
, duplen
, 1, 0, 1);
7436 /* If we have more than the desired maximum number of lines
7437 in the *Messages* buffer now, delete the oldest ones.
7438 This is safe because we don't have undo in this buffer. */
7440 if (NATNUMP (Vmessage_log_max
))
7442 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7443 -XFASTINT (Vmessage_log_max
) - 1, 0);
7444 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7447 BEGV
= XMARKER (oldbegv
)->charpos
;
7448 BEGV_BYTE
= marker_byte_position (oldbegv
);
7457 ZV
= XMARKER (oldzv
)->charpos
;
7458 ZV_BYTE
= marker_byte_position (oldzv
);
7462 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7464 /* We can't do Fgoto_char (oldpoint) because it will run some
7466 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7467 XMARKER (oldpoint
)->bytepos
);
7470 unchain_marker (XMARKER (oldpoint
));
7471 unchain_marker (XMARKER (oldbegv
));
7472 unchain_marker (XMARKER (oldzv
));
7474 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7475 set_buffer_internal (oldbuf
);
7477 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7478 message_log_need_newline
= !nlflag
;
7479 Vdeactivate_mark
= old_deactivate_mark
;
7484 /* We are at the end of the buffer after just having inserted a newline.
7485 (Note: We depend on the fact we won't be crossing the gap.)
7486 Check to see if the most recent message looks a lot like the previous one.
7487 Return 0 if different, 1 if the new one should just replace it, or a
7488 value N > 1 if we should also append " [N times]". */
7491 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7492 int prev_bol
, this_bol
;
7493 int prev_bol_byte
, this_bol_byte
;
7496 int len
= Z_BYTE
- 1 - this_bol_byte
;
7498 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7499 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7501 for (i
= 0; i
< len
; i
++)
7503 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7511 if (*p1
++ == ' ' && *p1
++ == '[')
7514 while (*p1
>= '0' && *p1
<= '9')
7515 n
= n
* 10 + *p1
++ - '0';
7516 if (strncmp (p1
, " times]\n", 8) == 0)
7523 /* Display an echo area message M with a specified length of NBYTES
7524 bytes. The string may include null characters. If M is 0, clear
7525 out any existing message, and let the mini-buffer text show
7528 This may GC, so the buffer M must NOT point to a Lisp string. */
7531 message2 (m
, nbytes
, multibyte
)
7536 /* First flush out any partial line written with print. */
7537 message_log_maybe_newline ();
7539 message_dolog (m
, nbytes
, 1, multibyte
);
7540 message2_nolog (m
, nbytes
, multibyte
);
7544 /* The non-logging counterpart of message2. */
7547 message2_nolog (m
, nbytes
, multibyte
)
7549 int nbytes
, multibyte
;
7551 struct frame
*sf
= SELECTED_FRAME ();
7552 message_enable_multibyte
= multibyte
;
7556 if (noninteractive_need_newline
)
7557 putc ('\n', stderr
);
7558 noninteractive_need_newline
= 0;
7560 fwrite (m
, nbytes
, 1, stderr
);
7561 if (cursor_in_echo_area
== 0)
7562 fprintf (stderr
, "\n");
7565 /* A null message buffer means that the frame hasn't really been
7566 initialized yet. Error messages get reported properly by
7567 cmd_error, so this must be just an informative message; toss it. */
7568 else if (INTERACTIVE
7569 && sf
->glyphs_initialized_p
7570 && FRAME_MESSAGE_BUF (sf
))
7572 Lisp_Object mini_window
;
7575 /* Get the frame containing the mini-buffer
7576 that the selected frame is using. */
7577 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7578 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7580 FRAME_SAMPLE_VISIBILITY (f
);
7581 if (FRAME_VISIBLE_P (sf
)
7582 && ! FRAME_VISIBLE_P (f
))
7583 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7587 set_message (m
, Qnil
, nbytes
, multibyte
);
7588 if (minibuffer_auto_raise
)
7589 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7592 clear_message (1, 1);
7594 do_pending_window_change (0);
7595 echo_area_display (1);
7596 do_pending_window_change (0);
7597 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7598 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7603 /* Display an echo area message M with a specified length of NBYTES
7604 bytes. The string may include null characters. If M is not a
7605 string, clear out any existing message, and let the mini-buffer
7608 This function cancels echoing. */
7611 message3 (m
, nbytes
, multibyte
)
7616 struct gcpro gcpro1
;
7619 clear_message (1,1);
7622 /* First flush out any partial line written with print. */
7623 message_log_maybe_newline ();
7629 SAFE_ALLOCA (buffer
, char *, nbytes
);
7630 bcopy (SDATA (m
), buffer
, nbytes
);
7631 message_dolog (buffer
, nbytes
, 1, multibyte
);
7634 message3_nolog (m
, nbytes
, multibyte
);
7640 /* The non-logging version of message3.
7641 This does not cancel echoing, because it is used for echoing.
7642 Perhaps we need to make a separate function for echoing
7643 and make this cancel echoing. */
7646 message3_nolog (m
, nbytes
, multibyte
)
7648 int nbytes
, multibyte
;
7650 struct frame
*sf
= SELECTED_FRAME ();
7651 message_enable_multibyte
= multibyte
;
7655 if (noninteractive_need_newline
)
7656 putc ('\n', stderr
);
7657 noninteractive_need_newline
= 0;
7659 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7660 if (cursor_in_echo_area
== 0)
7661 fprintf (stderr
, "\n");
7664 /* A null message buffer means that the frame hasn't really been
7665 initialized yet. Error messages get reported properly by
7666 cmd_error, so this must be just an informative message; toss it. */
7667 else if (INTERACTIVE
7668 && sf
->glyphs_initialized_p
7669 && FRAME_MESSAGE_BUF (sf
))
7671 Lisp_Object mini_window
;
7675 /* Get the frame containing the mini-buffer
7676 that the selected frame is using. */
7677 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7678 frame
= XWINDOW (mini_window
)->frame
;
7681 FRAME_SAMPLE_VISIBILITY (f
);
7682 if (FRAME_VISIBLE_P (sf
)
7683 && !FRAME_VISIBLE_P (f
))
7684 Fmake_frame_visible (frame
);
7686 if (STRINGP (m
) && SCHARS (m
) > 0)
7688 set_message (NULL
, m
, nbytes
, multibyte
);
7689 if (minibuffer_auto_raise
)
7690 Fraise_frame (frame
);
7691 /* Assume we are not echoing.
7692 (If we are, echo_now will override this.) */
7693 echo_message_buffer
= Qnil
;
7696 clear_message (1, 1);
7698 do_pending_window_change (0);
7699 echo_area_display (1);
7700 do_pending_window_change (0);
7701 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7702 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7707 /* Display a null-terminated echo area message M. If M is 0, clear
7708 out any existing message, and let the mini-buffer text show through.
7710 The buffer M must continue to exist until after the echo area gets
7711 cleared or some other message gets displayed there. Do not pass
7712 text that is stored in a Lisp string. Do not pass text in a buffer
7713 that was alloca'd. */
7719 message2 (m
, (m
? strlen (m
) : 0), 0);
7723 /* The non-logging counterpart of message1. */
7729 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7732 /* Display a message M which contains a single %s
7733 which gets replaced with STRING. */
7736 message_with_string (m
, string
, log
)
7741 CHECK_STRING (string
);
7747 if (noninteractive_need_newline
)
7748 putc ('\n', stderr
);
7749 noninteractive_need_newline
= 0;
7750 fprintf (stderr
, m
, SDATA (string
));
7751 if (cursor_in_echo_area
== 0)
7752 fprintf (stderr
, "\n");
7756 else if (INTERACTIVE
)
7758 /* The frame whose minibuffer we're going to display the message on.
7759 It may be larger than the selected frame, so we need
7760 to use its buffer, not the selected frame's buffer. */
7761 Lisp_Object mini_window
;
7762 struct frame
*f
, *sf
= SELECTED_FRAME ();
7764 /* Get the frame containing the minibuffer
7765 that the selected frame is using. */
7766 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7767 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7769 /* A null message buffer means that the frame hasn't really been
7770 initialized yet. Error messages get reported properly by
7771 cmd_error, so this must be just an informative message; toss it. */
7772 if (FRAME_MESSAGE_BUF (f
))
7774 Lisp_Object args
[2], message
;
7775 struct gcpro gcpro1
, gcpro2
;
7777 args
[0] = build_string (m
);
7778 args
[1] = message
= string
;
7779 GCPRO2 (args
[0], message
);
7782 message
= Fformat (2, args
);
7785 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7787 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7791 /* Print should start at the beginning of the message
7792 buffer next time. */
7793 message_buf_print
= 0;
7799 /* Dump an informative message to the minibuf. If M is 0, clear out
7800 any existing message, and let the mini-buffer text show through. */
7804 message (m
, a1
, a2
, a3
)
7806 EMACS_INT a1
, a2
, a3
;
7812 if (noninteractive_need_newline
)
7813 putc ('\n', stderr
);
7814 noninteractive_need_newline
= 0;
7815 fprintf (stderr
, m
, a1
, a2
, a3
);
7816 if (cursor_in_echo_area
== 0)
7817 fprintf (stderr
, "\n");
7821 else if (INTERACTIVE
)
7823 /* The frame whose mini-buffer we're going to display the message
7824 on. It may be larger than the selected frame, so we need to
7825 use its buffer, not the selected frame's buffer. */
7826 Lisp_Object mini_window
;
7827 struct frame
*f
, *sf
= SELECTED_FRAME ();
7829 /* Get the frame containing the mini-buffer
7830 that the selected frame is using. */
7831 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7832 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7834 /* A null message buffer means that the frame hasn't really been
7835 initialized yet. Error messages get reported properly by
7836 cmd_error, so this must be just an informative message; toss
7838 if (FRAME_MESSAGE_BUF (f
))
7849 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7850 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7852 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7853 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7855 #endif /* NO_ARG_ARRAY */
7857 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7862 /* Print should start at the beginning of the message
7863 buffer next time. */
7864 message_buf_print
= 0;
7870 /* The non-logging version of message. */
7873 message_nolog (m
, a1
, a2
, a3
)
7875 EMACS_INT a1
, a2
, a3
;
7877 Lisp_Object old_log_max
;
7878 old_log_max
= Vmessage_log_max
;
7879 Vmessage_log_max
= Qnil
;
7880 message (m
, a1
, a2
, a3
);
7881 Vmessage_log_max
= old_log_max
;
7885 /* Display the current message in the current mini-buffer. This is
7886 only called from error handlers in process.c, and is not time
7892 if (!NILP (echo_area_buffer
[0]))
7895 string
= Fcurrent_message ();
7896 message3 (string
, SBYTES (string
),
7897 !NILP (current_buffer
->enable_multibyte_characters
));
7902 /* Make sure echo area buffers in `echo_buffers' are live.
7903 If they aren't, make new ones. */
7906 ensure_echo_area_buffers ()
7910 for (i
= 0; i
< 2; ++i
)
7911 if (!BUFFERP (echo_buffer
[i
])
7912 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7915 Lisp_Object old_buffer
;
7918 old_buffer
= echo_buffer
[i
];
7919 sprintf (name
, " *Echo Area %d*", i
);
7920 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7921 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7923 for (j
= 0; j
< 2; ++j
)
7924 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7925 echo_area_buffer
[j
] = echo_buffer
[i
];
7930 /* Call FN with args A1..A4 with either the current or last displayed
7931 echo_area_buffer as current buffer.
7933 WHICH zero means use the current message buffer
7934 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7935 from echo_buffer[] and clear it.
7937 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7938 suitable buffer from echo_buffer[] and clear it.
7940 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
7941 that the current message becomes the last displayed one, make
7942 choose a suitable buffer for echo_area_buffer[0], and clear it.
7944 Value is what FN returns. */
7947 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7950 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7956 int this_one
, the_other
, clear_buffer_p
, rc
;
7957 int count
= SPECPDL_INDEX ();
7959 /* If buffers aren't live, make new ones. */
7960 ensure_echo_area_buffers ();
7965 this_one
= 0, the_other
= 1;
7967 this_one
= 1, the_other
= 0;
7970 this_one
= 0, the_other
= 1;
7973 /* We need a fresh one in case the current echo buffer equals
7974 the one containing the last displayed echo area message. */
7975 if (!NILP (echo_area_buffer
[this_one
])
7976 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
7977 echo_area_buffer
[this_one
] = Qnil
;
7980 /* Choose a suitable buffer from echo_buffer[] is we don't
7982 if (NILP (echo_area_buffer
[this_one
]))
7984 echo_area_buffer
[this_one
]
7985 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7986 ? echo_buffer
[the_other
]
7987 : echo_buffer
[this_one
]);
7991 buffer
= echo_area_buffer
[this_one
];
7993 /* Don't get confused by reusing the buffer used for echoing
7994 for a different purpose. */
7995 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7998 record_unwind_protect (unwind_with_echo_area_buffer
,
7999 with_echo_area_buffer_unwind_data (w
));
8001 /* Make the echo area buffer current. Note that for display
8002 purposes, it is not necessary that the displayed window's buffer
8003 == current_buffer, except for text property lookup. So, let's
8004 only set that buffer temporarily here without doing a full
8005 Fset_window_buffer. We must also change w->pointm, though,
8006 because otherwise an assertions in unshow_buffer fails, and Emacs
8008 set_buffer_internal_1 (XBUFFER (buffer
));
8012 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8015 current_buffer
->undo_list
= Qt
;
8016 current_buffer
->read_only
= Qnil
;
8017 specbind (Qinhibit_read_only
, Qt
);
8018 specbind (Qinhibit_modification_hooks
, Qt
);
8020 if (clear_buffer_p
&& Z
> BEG
)
8023 xassert (BEGV
>= BEG
);
8024 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8026 rc
= fn (a1
, a2
, a3
, a4
);
8028 xassert (BEGV
>= BEG
);
8029 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8031 unbind_to (count
, Qnil
);
8036 /* Save state that should be preserved around the call to the function
8037 FN called in with_echo_area_buffer. */
8040 with_echo_area_buffer_unwind_data (w
)
8046 /* Reduce consing by keeping one vector in
8047 Vwith_echo_area_save_vector. */
8048 vector
= Vwith_echo_area_save_vector
;
8049 Vwith_echo_area_save_vector
= Qnil
;
8052 vector
= Fmake_vector (make_number (7), Qnil
);
8054 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
8055 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
8056 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
8060 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
8061 AREF (vector
, i
) = w
->buffer
; ++i
;
8062 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
8063 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
8068 for (; i
< end
; ++i
)
8069 AREF (vector
, i
) = Qnil
;
8072 xassert (i
== ASIZE (vector
));
8077 /* Restore global state from VECTOR which was created by
8078 with_echo_area_buffer_unwind_data. */
8081 unwind_with_echo_area_buffer (vector
)
8084 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8085 Vdeactivate_mark
= AREF (vector
, 1);
8086 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8088 if (WINDOWP (AREF (vector
, 3)))
8091 Lisp_Object buffer
, charpos
, bytepos
;
8093 w
= XWINDOW (AREF (vector
, 3));
8094 buffer
= AREF (vector
, 4);
8095 charpos
= AREF (vector
, 5);
8096 bytepos
= AREF (vector
, 6);
8099 set_marker_both (w
->pointm
, buffer
,
8100 XFASTINT (charpos
), XFASTINT (bytepos
));
8103 Vwith_echo_area_save_vector
= vector
;
8108 /* Set up the echo area for use by print functions. MULTIBYTE_P
8109 non-zero means we will print multibyte. */
8112 setup_echo_area_for_printing (multibyte_p
)
8115 /* If we can't find an echo area any more, exit. */
8116 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8119 ensure_echo_area_buffers ();
8121 if (!message_buf_print
)
8123 /* A message has been output since the last time we printed.
8124 Choose a fresh echo area buffer. */
8125 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8126 echo_area_buffer
[0] = echo_buffer
[1];
8128 echo_area_buffer
[0] = echo_buffer
[0];
8130 /* Switch to that buffer and clear it. */
8131 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8132 current_buffer
->truncate_lines
= Qnil
;
8136 int count
= SPECPDL_INDEX ();
8137 specbind (Qinhibit_read_only
, Qt
);
8138 /* Note that undo recording is always disabled. */
8140 unbind_to (count
, Qnil
);
8142 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8144 /* Set up the buffer for the multibyteness we need. */
8146 != !NILP (current_buffer
->enable_multibyte_characters
))
8147 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8149 /* Raise the frame containing the echo area. */
8150 if (minibuffer_auto_raise
)
8152 struct frame
*sf
= SELECTED_FRAME ();
8153 Lisp_Object mini_window
;
8154 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8155 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8158 message_log_maybe_newline ();
8159 message_buf_print
= 1;
8163 if (NILP (echo_area_buffer
[0]))
8165 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8166 echo_area_buffer
[0] = echo_buffer
[1];
8168 echo_area_buffer
[0] = echo_buffer
[0];
8171 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8173 /* Someone switched buffers between print requests. */
8174 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8175 current_buffer
->truncate_lines
= Qnil
;
8181 /* Display an echo area message in window W. Value is non-zero if W's
8182 height is changed. If display_last_displayed_message_p is
8183 non-zero, display the message that was last displayed, otherwise
8184 display the current message. */
8187 display_echo_area (w
)
8190 int i
, no_message_p
, window_height_changed_p
, count
;
8192 /* Temporarily disable garbage collections while displaying the echo
8193 area. This is done because a GC can print a message itself.
8194 That message would modify the echo area buffer's contents while a
8195 redisplay of the buffer is going on, and seriously confuse
8197 count
= inhibit_garbage_collection ();
8199 /* If there is no message, we must call display_echo_area_1
8200 nevertheless because it resizes the window. But we will have to
8201 reset the echo_area_buffer in question to nil at the end because
8202 with_echo_area_buffer will sets it to an empty buffer. */
8203 i
= display_last_displayed_message_p
? 1 : 0;
8204 no_message_p
= NILP (echo_area_buffer
[i
]);
8206 window_height_changed_p
8207 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8208 display_echo_area_1
,
8209 (EMACS_INT
) w
, Qnil
, 0, 0);
8212 echo_area_buffer
[i
] = Qnil
;
8214 unbind_to (count
, Qnil
);
8215 return window_height_changed_p
;
8219 /* Helper for display_echo_area. Display the current buffer which
8220 contains the current echo area message in window W, a mini-window,
8221 a pointer to which is passed in A1. A2..A4 are currently not used.
8222 Change the height of W so that all of the message is displayed.
8223 Value is non-zero if height of W was changed. */
8226 display_echo_area_1 (a1
, a2
, a3
, a4
)
8231 struct window
*w
= (struct window
*) a1
;
8233 struct text_pos start
;
8234 int window_height_changed_p
= 0;
8236 /* Do this before displaying, so that we have a large enough glyph
8237 matrix for the display. If we can't get enough space for the
8238 whole text, display the last N lines. That works by setting w->start. */
8239 window_height_changed_p
= resize_mini_window (w
, 0);
8241 /* Use the starting position chosen by resize_mini_window. */
8242 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8245 clear_glyph_matrix (w
->desired_matrix
);
8246 XSETWINDOW (window
, w
);
8247 try_window (window
, start
, 0);
8249 return window_height_changed_p
;
8253 /* Resize the echo area window to exactly the size needed for the
8254 currently displayed message, if there is one. If a mini-buffer
8255 is active, don't shrink it. */
8258 resize_echo_area_exactly ()
8260 if (BUFFERP (echo_area_buffer
[0])
8261 && WINDOWP (echo_area_window
))
8263 struct window
*w
= XWINDOW (echo_area_window
);
8265 Lisp_Object resize_exactly
;
8267 if (minibuf_level
== 0)
8268 resize_exactly
= Qt
;
8270 resize_exactly
= Qnil
;
8272 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8273 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8276 ++windows_or_buffers_changed
;
8277 ++update_mode_lines
;
8278 redisplay_internal (0);
8284 /* Callback function for with_echo_area_buffer, when used from
8285 resize_echo_area_exactly. A1 contains a pointer to the window to
8286 resize, EXACTLY non-nil means resize the mini-window exactly to the
8287 size of the text displayed. A3 and A4 are not used. Value is what
8288 resize_mini_window returns. */
8291 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8293 Lisp_Object exactly
;
8296 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8300 /* Resize mini-window W to fit the size of its contents. EXACT:P
8301 means size the window exactly to the size needed. Otherwise, it's
8302 only enlarged until W's buffer is empty.
8304 Set W->start to the right place to begin display. If the whole
8305 contents fit, start at the beginning. Otherwise, start so as
8306 to make the end of the contents appear. This is particularly
8307 important for y-or-n-p, but seems desirable generally.
8309 Value is non-zero if the window height has been changed. */
8312 resize_mini_window (w
, exact_p
)
8316 struct frame
*f
= XFRAME (w
->frame
);
8317 int window_height_changed_p
= 0;
8319 xassert (MINI_WINDOW_P (w
));
8321 /* By default, start display at the beginning. */
8322 set_marker_both (w
->start
, w
->buffer
,
8323 BUF_BEGV (XBUFFER (w
->buffer
)),
8324 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8326 /* Don't resize windows while redisplaying a window; it would
8327 confuse redisplay functions when the size of the window they are
8328 displaying changes from under them. Such a resizing can happen,
8329 for instance, when which-func prints a long message while
8330 we are running fontification-functions. We're running these
8331 functions with safe_call which binds inhibit-redisplay to t. */
8332 if (!NILP (Vinhibit_redisplay
))
8335 /* Nil means don't try to resize. */
8336 if (NILP (Vresize_mini_windows
)
8337 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8340 if (!FRAME_MINIBUF_ONLY_P (f
))
8343 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8344 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8345 int height
, max_height
;
8346 int unit
= FRAME_LINE_HEIGHT (f
);
8347 struct text_pos start
;
8348 struct buffer
*old_current_buffer
= NULL
;
8350 if (current_buffer
!= XBUFFER (w
->buffer
))
8352 old_current_buffer
= current_buffer
;
8353 set_buffer_internal (XBUFFER (w
->buffer
));
8356 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8358 /* Compute the max. number of lines specified by the user. */
8359 if (FLOATP (Vmax_mini_window_height
))
8360 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8361 else if (INTEGERP (Vmax_mini_window_height
))
8362 max_height
= XINT (Vmax_mini_window_height
);
8364 max_height
= total_height
/ 4;
8366 /* Correct that max. height if it's bogus. */
8367 max_height
= max (1, max_height
);
8368 max_height
= min (total_height
, max_height
);
8370 /* Find out the height of the text in the window. */
8371 if (it
.truncate_lines_p
)
8376 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8377 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8378 height
= it
.current_y
+ last_height
;
8380 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8381 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8382 height
= (height
+ unit
- 1) / unit
;
8385 /* Compute a suitable window start. */
8386 if (height
> max_height
)
8388 height
= max_height
;
8389 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8390 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8391 start
= it
.current
.pos
;
8394 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8395 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8397 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8399 /* Let it grow only, until we display an empty message, in which
8400 case the window shrinks again. */
8401 if (height
> WINDOW_TOTAL_LINES (w
))
8403 int old_height
= WINDOW_TOTAL_LINES (w
);
8404 freeze_window_starts (f
, 1);
8405 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8406 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8408 else if (height
< WINDOW_TOTAL_LINES (w
)
8409 && (exact_p
|| BEGV
== ZV
))
8411 int old_height
= WINDOW_TOTAL_LINES (w
);
8412 freeze_window_starts (f
, 0);
8413 shrink_mini_window (w
);
8414 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8419 /* Always resize to exact size needed. */
8420 if (height
> WINDOW_TOTAL_LINES (w
))
8422 int old_height
= WINDOW_TOTAL_LINES (w
);
8423 freeze_window_starts (f
, 1);
8424 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8425 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8427 else if (height
< WINDOW_TOTAL_LINES (w
))
8429 int old_height
= WINDOW_TOTAL_LINES (w
);
8430 freeze_window_starts (f
, 0);
8431 shrink_mini_window (w
);
8435 freeze_window_starts (f
, 1);
8436 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8439 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8443 if (old_current_buffer
)
8444 set_buffer_internal (old_current_buffer
);
8447 return window_height_changed_p
;
8451 /* Value is the current message, a string, or nil if there is no
8459 if (NILP (echo_area_buffer
[0]))
8463 with_echo_area_buffer (0, 0, current_message_1
,
8464 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8466 echo_area_buffer
[0] = Qnil
;
8474 current_message_1 (a1
, a2
, a3
, a4
)
8479 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8482 *msg
= make_buffer_string (BEG
, Z
, 1);
8489 /* Push the current message on Vmessage_stack for later restauration
8490 by restore_message. Value is non-zero if the current message isn't
8491 empty. This is a relatively infrequent operation, so it's not
8492 worth optimizing. */
8498 msg
= current_message ();
8499 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8500 return STRINGP (msg
);
8504 /* Restore message display from the top of Vmessage_stack. */
8511 xassert (CONSP (Vmessage_stack
));
8512 msg
= XCAR (Vmessage_stack
);
8514 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8516 message3_nolog (msg
, 0, 0);
8520 /* Handler for record_unwind_protect calling pop_message. */
8523 pop_message_unwind (dummy
)
8530 /* Pop the top-most entry off Vmessage_stack. */
8535 xassert (CONSP (Vmessage_stack
));
8536 Vmessage_stack
= XCDR (Vmessage_stack
);
8540 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8541 exits. If the stack is not empty, we have a missing pop_message
8545 check_message_stack ()
8547 if (!NILP (Vmessage_stack
))
8552 /* Truncate to NCHARS what will be displayed in the echo area the next
8553 time we display it---but don't redisplay it now. */
8556 truncate_echo_area (nchars
)
8560 echo_area_buffer
[0] = Qnil
;
8561 /* A null message buffer means that the frame hasn't really been
8562 initialized yet. Error messages get reported properly by
8563 cmd_error, so this must be just an informative message; toss it. */
8564 else if (!noninteractive
8566 && !NILP (echo_area_buffer
[0]))
8568 struct frame
*sf
= SELECTED_FRAME ();
8569 if (FRAME_MESSAGE_BUF (sf
))
8570 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8575 /* Helper function for truncate_echo_area. Truncate the current
8576 message to at most NCHARS characters. */
8579 truncate_message_1 (nchars
, a2
, a3
, a4
)
8584 if (BEG
+ nchars
< Z
)
8585 del_range (BEG
+ nchars
, Z
);
8587 echo_area_buffer
[0] = Qnil
;
8592 /* Set the current message to a substring of S or STRING.
8594 If STRING is a Lisp string, set the message to the first NBYTES
8595 bytes from STRING. NBYTES zero means use the whole string. If
8596 STRING is multibyte, the message will be displayed multibyte.
8598 If S is not null, set the message to the first LEN bytes of S. LEN
8599 zero means use the whole string. MULTIBYTE_P non-zero means S is
8600 multibyte. Display the message multibyte in that case.
8602 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8603 to t before calling set_message_1 (which calls insert).
8607 set_message (s
, string
, nbytes
, multibyte_p
)
8610 int nbytes
, multibyte_p
;
8612 message_enable_multibyte
8613 = ((s
&& multibyte_p
)
8614 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8616 with_echo_area_buffer (0, -1, set_message_1
,
8617 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8618 message_buf_print
= 0;
8619 help_echo_showing_p
= 0;
8623 /* Helper function for set_message. Arguments have the same meaning
8624 as there, with A1 corresponding to S and A2 corresponding to STRING
8625 This function is called with the echo area buffer being
8629 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8632 EMACS_INT nbytes
, multibyte_p
;
8634 const char *s
= (const char *) a1
;
8635 Lisp_Object string
= a2
;
8637 /* Change multibyteness of the echo buffer appropriately. */
8638 if (message_enable_multibyte
8639 != !NILP (current_buffer
->enable_multibyte_characters
))
8640 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8642 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8644 /* Insert new message at BEG. */
8645 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8647 if (STRINGP (string
))
8652 nbytes
= SBYTES (string
);
8653 nchars
= string_byte_to_char (string
, nbytes
);
8655 /* This function takes care of single/multibyte conversion. We
8656 just have to ensure that the echo area buffer has the right
8657 setting of enable_multibyte_characters. */
8658 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8663 nbytes
= strlen (s
);
8665 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8667 /* Convert from multi-byte to single-byte. */
8669 unsigned char work
[1];
8671 /* Convert a multibyte string to single-byte. */
8672 for (i
= 0; i
< nbytes
; i
+= n
)
8674 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8675 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
8677 : multibyte_char_to_unibyte (c
, Qnil
));
8678 insert_1_both (work
, 1, 1, 1, 0, 0);
8681 else if (!multibyte_p
8682 && !NILP (current_buffer
->enable_multibyte_characters
))
8684 /* Convert from single-byte to multi-byte. */
8686 const unsigned char *msg
= (const unsigned char *) s
;
8687 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8689 /* Convert a single-byte string to multibyte. */
8690 for (i
= 0; i
< nbytes
; i
++)
8692 c
= unibyte_char_to_multibyte (msg
[i
]);
8693 n
= CHAR_STRING (c
, str
);
8694 insert_1_both (str
, 1, n
, 1, 0, 0);
8698 insert_1 (s
, nbytes
, 1, 0, 0);
8705 /* Clear messages. CURRENT_P non-zero means clear the current
8706 message. LAST_DISPLAYED_P non-zero means clear the message
8710 clear_message (current_p
, last_displayed_p
)
8711 int current_p
, last_displayed_p
;
8715 echo_area_buffer
[0] = Qnil
;
8716 message_cleared_p
= 1;
8719 if (last_displayed_p
)
8720 echo_area_buffer
[1] = Qnil
;
8722 message_buf_print
= 0;
8725 /* Clear garbaged frames.
8727 This function is used where the old redisplay called
8728 redraw_garbaged_frames which in turn called redraw_frame which in
8729 turn called clear_frame. The call to clear_frame was a source of
8730 flickering. I believe a clear_frame is not necessary. It should
8731 suffice in the new redisplay to invalidate all current matrices,
8732 and ensure a complete redisplay of all windows. */
8735 clear_garbaged_frames ()
8739 Lisp_Object tail
, frame
;
8740 int changed_count
= 0;
8742 FOR_EACH_FRAME (tail
, frame
)
8744 struct frame
*f
= XFRAME (frame
);
8746 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8750 Fredraw_frame (frame
);
8751 f
->force_flush_display_p
= 1;
8753 clear_current_matrices (f
);
8762 ++windows_or_buffers_changed
;
8767 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8768 is non-zero update selected_frame. Value is non-zero if the
8769 mini-windows height has been changed. */
8772 echo_area_display (update_frame_p
)
8775 Lisp_Object mini_window
;
8778 int window_height_changed_p
= 0;
8779 struct frame
*sf
= SELECTED_FRAME ();
8781 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8782 w
= XWINDOW (mini_window
);
8783 f
= XFRAME (WINDOW_FRAME (w
));
8785 /* Don't display if frame is invisible or not yet initialized. */
8786 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8789 #ifdef HAVE_WINDOW_SYSTEM
8790 /* When Emacs starts, selected_frame may be the initial terminal
8791 frame. If we let this through, a message would be displayed on
8793 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
8795 #endif /* HAVE_WINDOW_SYSTEM */
8797 /* Redraw garbaged frames. */
8799 clear_garbaged_frames ();
8801 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8803 echo_area_window
= mini_window
;
8804 window_height_changed_p
= display_echo_area (w
);
8805 w
->must_be_updated_p
= 1;
8807 /* Update the display, unless called from redisplay_internal.
8808 Also don't update the screen during redisplay itself. The
8809 update will happen at the end of redisplay, and an update
8810 here could cause confusion. */
8811 if (update_frame_p
&& !redisplaying_p
)
8815 /* If the display update has been interrupted by pending
8816 input, update mode lines in the frame. Due to the
8817 pending input, it might have been that redisplay hasn't
8818 been called, so that mode lines above the echo area are
8819 garbaged. This looks odd, so we prevent it here. */
8820 if (!display_completed
)
8821 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8823 if (window_height_changed_p
8824 /* Don't do this if Emacs is shutting down. Redisplay
8825 needs to run hooks. */
8826 && !NILP (Vrun_hooks
))
8828 /* Must update other windows. Likewise as in other
8829 cases, don't let this update be interrupted by
8831 int count
= SPECPDL_INDEX ();
8832 specbind (Qredisplay_dont_pause
, Qt
);
8833 windows_or_buffers_changed
= 1;
8834 redisplay_internal (0);
8835 unbind_to (count
, Qnil
);
8837 else if (FRAME_WINDOW_P (f
) && n
== 0)
8839 /* Window configuration is the same as before.
8840 Can do with a display update of the echo area,
8841 unless we displayed some mode lines. */
8842 update_single_window (w
, 1);
8843 FRAME_RIF (f
)->flush_display (f
);
8846 update_frame (f
, 1, 1);
8848 /* If cursor is in the echo area, make sure that the next
8849 redisplay displays the minibuffer, so that the cursor will
8850 be replaced with what the minibuffer wants. */
8851 if (cursor_in_echo_area
)
8852 ++windows_or_buffers_changed
;
8855 else if (!EQ (mini_window
, selected_window
))
8856 windows_or_buffers_changed
++;
8858 /* Last displayed message is now the current message. */
8859 echo_area_buffer
[1] = echo_area_buffer
[0];
8860 /* Inform read_char that we're not echoing. */
8861 echo_message_buffer
= Qnil
;
8863 /* Prevent redisplay optimization in redisplay_internal by resetting
8864 this_line_start_pos. This is done because the mini-buffer now
8865 displays the message instead of its buffer text. */
8866 if (EQ (mini_window
, selected_window
))
8867 CHARPOS (this_line_start_pos
) = 0;
8869 return window_height_changed_p
;
8874 /***********************************************************************
8875 Mode Lines and Frame Titles
8876 ***********************************************************************/
8878 /* A buffer for constructing non-propertized mode-line strings and
8879 frame titles in it; allocated from the heap in init_xdisp and
8880 resized as needed in store_mode_line_noprop_char. */
8882 static char *mode_line_noprop_buf
;
8884 /* The buffer's end, and a current output position in it. */
8886 static char *mode_line_noprop_buf_end
;
8887 static char *mode_line_noprop_ptr
;
8889 #define MODE_LINE_NOPROP_LEN(start) \
8890 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8893 MODE_LINE_DISPLAY
= 0,
8899 /* Alist that caches the results of :propertize.
8900 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8901 static Lisp_Object mode_line_proptrans_alist
;
8903 /* List of strings making up the mode-line. */
8904 static Lisp_Object mode_line_string_list
;
8906 /* Base face property when building propertized mode line string. */
8907 static Lisp_Object mode_line_string_face
;
8908 static Lisp_Object mode_line_string_face_prop
;
8911 /* Unwind data for mode line strings */
8913 static Lisp_Object Vmode_line_unwind_vector
;
8916 format_mode_line_unwind_data (obuf
, save_proptrans
)
8917 struct buffer
*obuf
;
8921 /* Reduce consing by keeping one vector in
8922 Vwith_echo_area_save_vector. */
8923 vector
= Vmode_line_unwind_vector
;
8924 Vmode_line_unwind_vector
= Qnil
;
8927 vector
= Fmake_vector (make_number (7), Qnil
);
8929 AREF (vector
, 0) = make_number (mode_line_target
);
8930 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8931 AREF (vector
, 2) = mode_line_string_list
;
8932 AREF (vector
, 3) = (save_proptrans
? mode_line_proptrans_alist
: Qt
);
8933 AREF (vector
, 4) = mode_line_string_face
;
8934 AREF (vector
, 5) = mode_line_string_face_prop
;
8937 XSETBUFFER (AREF (vector
, 6), obuf
);
8939 AREF (vector
, 6) = Qnil
;
8945 unwind_format_mode_line (vector
)
8948 mode_line_target
= XINT (AREF (vector
, 0));
8949 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8950 mode_line_string_list
= AREF (vector
, 2);
8951 if (! EQ (AREF (vector
, 3), Qt
))
8952 mode_line_proptrans_alist
= AREF (vector
, 3);
8953 mode_line_string_face
= AREF (vector
, 4);
8954 mode_line_string_face_prop
= AREF (vector
, 5);
8956 if (!NILP (AREF (vector
, 6)))
8958 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8959 AREF (vector
, 6) = Qnil
;
8962 Vmode_line_unwind_vector
= vector
;
8967 /* Store a single character C for the frame title in mode_line_noprop_buf.
8968 Re-allocate mode_line_noprop_buf if necessary. */
8972 store_mode_line_noprop_char (char c
)
8974 store_mode_line_noprop_char (c
)
8978 /* If output position has reached the end of the allocated buffer,
8979 double the buffer's size. */
8980 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8982 int len
= MODE_LINE_NOPROP_LEN (0);
8983 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8984 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8985 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8986 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8989 *mode_line_noprop_ptr
++ = c
;
8993 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8994 mode_line_noprop_ptr. STR is the string to store. Do not copy
8995 characters that yield more columns than PRECISION; PRECISION <= 0
8996 means copy the whole string. Pad with spaces until FIELD_WIDTH
8997 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8998 pad. Called from display_mode_element when it is used to build a
9002 store_mode_line_noprop (str
, field_width
, precision
)
9003 const unsigned char *str
;
9004 int field_width
, precision
;
9009 /* Copy at most PRECISION chars from STR. */
9010 nbytes
= strlen (str
);
9011 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9013 store_mode_line_noprop_char (*str
++);
9015 /* Fill up with spaces until FIELD_WIDTH reached. */
9016 while (field_width
> 0
9019 store_mode_line_noprop_char (' ');
9026 /***********************************************************************
9028 ***********************************************************************/
9030 #ifdef HAVE_WINDOW_SYSTEM
9032 /* Set the title of FRAME, if it has changed. The title format is
9033 Vicon_title_format if FRAME is iconified, otherwise it is
9034 frame_title_format. */
9037 x_consider_frame_title (frame
)
9040 struct frame
*f
= XFRAME (frame
);
9042 if (FRAME_WINDOW_P (f
)
9043 || FRAME_MINIBUF_ONLY_P (f
)
9044 || f
->explicit_name
)
9046 /* Do we have more than one visible frame on this X display? */
9053 int count
= SPECPDL_INDEX ();
9055 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9057 Lisp_Object other_frame
= XCAR (tail
);
9058 struct frame
*tf
= XFRAME (other_frame
);
9061 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9062 && !FRAME_MINIBUF_ONLY_P (tf
)
9063 && !EQ (other_frame
, tip_frame
)
9064 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9068 /* Set global variable indicating that multiple frames exist. */
9069 multiple_frames
= CONSP (tail
);
9071 /* Switch to the buffer of selected window of the frame. Set up
9072 mode_line_target so that display_mode_element will output into
9073 mode_line_noprop_buf; then display the title. */
9074 record_unwind_protect (unwind_format_mode_line
,
9075 format_mode_line_unwind_data (current_buffer
, 0));
9077 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9078 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9080 mode_line_target
= MODE_LINE_TITLE
;
9081 title_start
= MODE_LINE_NOPROP_LEN (0);
9082 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9083 NULL
, DEFAULT_FACE_ID
);
9084 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9085 len
= MODE_LINE_NOPROP_LEN (title_start
);
9086 title
= mode_line_noprop_buf
+ title_start
;
9087 unbind_to (count
, Qnil
);
9089 /* Set the title only if it's changed. This avoids consing in
9090 the common case where it hasn't. (If it turns out that we've
9091 already wasted too much time by walking through the list with
9092 display_mode_element, then we might need to optimize at a
9093 higher level than this.) */
9094 if (! STRINGP (f
->name
)
9095 || SBYTES (f
->name
) != len
9096 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9097 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9101 #endif /* not HAVE_WINDOW_SYSTEM */
9106 /***********************************************************************
9108 ***********************************************************************/
9111 /* Prepare for redisplay by updating menu-bar item lists when
9112 appropriate. This can call eval. */
9115 prepare_menu_bars ()
9118 struct gcpro gcpro1
, gcpro2
;
9120 Lisp_Object tooltip_frame
;
9122 #ifdef HAVE_WINDOW_SYSTEM
9123 tooltip_frame
= tip_frame
;
9125 tooltip_frame
= Qnil
;
9128 /* Update all frame titles based on their buffer names, etc. We do
9129 this before the menu bars so that the buffer-menu will show the
9130 up-to-date frame titles. */
9131 #ifdef HAVE_WINDOW_SYSTEM
9132 if (windows_or_buffers_changed
|| update_mode_lines
)
9134 Lisp_Object tail
, frame
;
9136 FOR_EACH_FRAME (tail
, frame
)
9139 if (!EQ (frame
, tooltip_frame
)
9140 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9141 x_consider_frame_title (frame
);
9144 #endif /* HAVE_WINDOW_SYSTEM */
9146 /* Update the menu bar item lists, if appropriate. This has to be
9147 done before any actual redisplay or generation of display lines. */
9148 all_windows
= (update_mode_lines
9149 || buffer_shared
> 1
9150 || windows_or_buffers_changed
);
9153 Lisp_Object tail
, frame
;
9154 int count
= SPECPDL_INDEX ();
9155 /* 1 means that update_menu_bar has run its hooks
9156 so any further calls to update_menu_bar shouldn't do so again. */
9157 int menu_bar_hooks_run
= 0;
9159 record_unwind_save_match_data ();
9161 FOR_EACH_FRAME (tail
, frame
)
9165 /* Ignore tooltip frame. */
9166 if (EQ (frame
, tooltip_frame
))
9169 /* If a window on this frame changed size, report that to
9170 the user and clear the size-change flag. */
9171 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9173 Lisp_Object functions
;
9175 /* Clear flag first in case we get an error below. */
9176 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9177 functions
= Vwindow_size_change_functions
;
9178 GCPRO2 (tail
, functions
);
9180 while (CONSP (functions
))
9182 call1 (XCAR (functions
), frame
);
9183 functions
= XCDR (functions
);
9189 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9190 #ifdef HAVE_WINDOW_SYSTEM
9191 update_tool_bar (f
, 0);
9193 mac_update_title_bar (f
, 0);
9199 unbind_to (count
, Qnil
);
9203 struct frame
*sf
= SELECTED_FRAME ();
9204 update_menu_bar (sf
, 1, 0);
9205 #ifdef HAVE_WINDOW_SYSTEM
9206 update_tool_bar (sf
, 1);
9208 mac_update_title_bar (sf
, 1);
9213 /* Motif needs this. See comment in xmenu.c. Turn it off when
9214 pending_menu_activation is not defined. */
9215 #ifdef USE_X_TOOLKIT
9216 pending_menu_activation
= 0;
9221 /* Update the menu bar item list for frame F. This has to be done
9222 before we start to fill in any display lines, because it can call
9225 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9227 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9228 already ran the menu bar hooks for this redisplay, so there
9229 is no need to run them again. The return value is the
9230 updated value of this flag, to pass to the next call. */
9233 update_menu_bar (f
, save_match_data
, hooks_run
)
9235 int save_match_data
;
9239 register struct window
*w
;
9241 /* If called recursively during a menu update, do nothing. This can
9242 happen when, for instance, an activate-menubar-hook causes a
9244 if (inhibit_menubar_update
)
9247 window
= FRAME_SELECTED_WINDOW (f
);
9248 w
= XWINDOW (window
);
9250 #if 0 /* The if statement below this if statement used to include the
9251 condition !NILP (w->update_mode_line), rather than using
9252 update_mode_lines directly, and this if statement may have
9253 been added to make that condition work. Now the if
9254 statement below matches its comment, this isn't needed. */
9255 if (update_mode_lines
)
9256 w
->update_mode_line
= Qt
;
9259 if (FRAME_WINDOW_P (f
)
9261 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9262 || defined (USE_GTK)
9263 FRAME_EXTERNAL_MENU_BAR (f
)
9265 FRAME_MENU_BAR_LINES (f
) > 0
9267 : FRAME_MENU_BAR_LINES (f
) > 0)
9269 /* If the user has switched buffers or windows, we need to
9270 recompute to reflect the new bindings. But we'll
9271 recompute when update_mode_lines is set too; that means
9272 that people can use force-mode-line-update to request
9273 that the menu bar be recomputed. The adverse effect on
9274 the rest of the redisplay algorithm is about the same as
9275 windows_or_buffers_changed anyway. */
9276 if (windows_or_buffers_changed
9277 /* This used to test w->update_mode_line, but we believe
9278 there is no need to recompute the menu in that case. */
9279 || update_mode_lines
9280 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9281 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9282 != !NILP (w
->last_had_star
))
9283 || ((!NILP (Vtransient_mark_mode
)
9284 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9285 != !NILP (w
->region_showing
)))
9287 struct buffer
*prev
= current_buffer
;
9288 int count
= SPECPDL_INDEX ();
9290 specbind (Qinhibit_menubar_update
, Qt
);
9292 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9293 if (save_match_data
)
9294 record_unwind_save_match_data ();
9295 if (NILP (Voverriding_local_map_menu_flag
))
9297 specbind (Qoverriding_terminal_local_map
, Qnil
);
9298 specbind (Qoverriding_local_map
, Qnil
);
9303 /* Run the Lucid hook. */
9304 safe_run_hooks (Qactivate_menubar_hook
);
9306 /* If it has changed current-menubar from previous value,
9307 really recompute the menu-bar from the value. */
9308 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9309 call0 (Qrecompute_lucid_menubar
);
9311 safe_run_hooks (Qmenu_bar_update_hook
);
9316 XSETFRAME (Vmenu_updating_frame
, f
);
9317 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9319 /* Redisplay the menu bar in case we changed it. */
9320 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9321 || defined (USE_GTK)
9322 if (FRAME_WINDOW_P (f
))
9325 /* All frames on Mac OS share the same menubar. So only
9326 the selected frame should be allowed to set it. */
9327 if (f
== SELECTED_FRAME ())
9329 set_frame_menubar (f
, 0, 0);
9332 /* On a terminal screen, the menu bar is an ordinary screen
9333 line, and this makes it get updated. */
9334 w
->update_mode_line
= Qt
;
9335 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9336 /* In the non-toolkit version, the menu bar is an ordinary screen
9337 line, and this makes it get updated. */
9338 w
->update_mode_line
= Qt
;
9339 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9341 unbind_to (count
, Qnil
);
9342 set_buffer_internal_1 (prev
);
9351 /***********************************************************************
9353 ***********************************************************************/
9355 #ifdef HAVE_WINDOW_SYSTEM
9358 Nominal cursor position -- where to draw output.
9359 HPOS and VPOS are window relative glyph matrix coordinates.
9360 X and Y are window relative pixel coordinates. */
9362 struct cursor_pos output_cursor
;
9366 Set the global variable output_cursor to CURSOR. All cursor
9367 positions are relative to updated_window. */
9370 set_output_cursor (cursor
)
9371 struct cursor_pos
*cursor
;
9373 output_cursor
.hpos
= cursor
->hpos
;
9374 output_cursor
.vpos
= cursor
->vpos
;
9375 output_cursor
.x
= cursor
->x
;
9376 output_cursor
.y
= cursor
->y
;
9381 Set a nominal cursor position.
9383 HPOS and VPOS are column/row positions in a window glyph matrix. X
9384 and Y are window text area relative pixel positions.
9386 If this is done during an update, updated_window will contain the
9387 window that is being updated and the position is the future output
9388 cursor position for that window. If updated_window is null, use
9389 selected_window and display the cursor at the given position. */
9392 x_cursor_to (vpos
, hpos
, y
, x
)
9393 int vpos
, hpos
, y
, x
;
9397 /* If updated_window is not set, work on selected_window. */
9401 w
= XWINDOW (selected_window
);
9403 /* Set the output cursor. */
9404 output_cursor
.hpos
= hpos
;
9405 output_cursor
.vpos
= vpos
;
9406 output_cursor
.x
= x
;
9407 output_cursor
.y
= y
;
9409 /* If not called as part of an update, really display the cursor.
9410 This will also set the cursor position of W. */
9411 if (updated_window
== NULL
)
9414 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9415 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
9416 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
9421 #endif /* HAVE_WINDOW_SYSTEM */
9424 /***********************************************************************
9426 ***********************************************************************/
9428 #ifdef HAVE_WINDOW_SYSTEM
9430 /* Where the mouse was last time we reported a mouse event. */
9432 FRAME_PTR last_mouse_frame
;
9434 /* Tool-bar item index of the item on which a mouse button was pressed
9437 int last_tool_bar_item
;
9440 /* Update the tool-bar item list for frame F. This has to be done
9441 before we start to fill in any display lines. Called from
9442 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9443 and restore it here. */
9446 update_tool_bar (f
, save_match_data
)
9448 int save_match_data
;
9450 #if defined (USE_GTK) || USE_MAC_TOOLBAR
9451 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9453 int do_update
= WINDOWP (f
->tool_bar_window
)
9454 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9462 window
= FRAME_SELECTED_WINDOW (f
);
9463 w
= XWINDOW (window
);
9465 /* If the user has switched buffers or windows, we need to
9466 recompute to reflect the new bindings. But we'll
9467 recompute when update_mode_lines is set too; that means
9468 that people can use force-mode-line-update to request
9469 that the menu bar be recomputed. The adverse effect on
9470 the rest of the redisplay algorithm is about the same as
9471 windows_or_buffers_changed anyway. */
9472 if (windows_or_buffers_changed
9473 || !NILP (w
->update_mode_line
)
9474 || update_mode_lines
9475 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9476 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9477 != !NILP (w
->last_had_star
))
9478 || ((!NILP (Vtransient_mark_mode
)
9479 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9480 != !NILP (w
->region_showing
)))
9482 struct buffer
*prev
= current_buffer
;
9483 int count
= SPECPDL_INDEX ();
9484 Lisp_Object new_tool_bar
;
9486 struct gcpro gcpro1
;
9488 /* Set current_buffer to the buffer of the selected
9489 window of the frame, so that we get the right local
9491 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9493 /* Save match data, if we must. */
9494 if (save_match_data
)
9495 record_unwind_save_match_data ();
9497 /* Make sure that we don't accidentally use bogus keymaps. */
9498 if (NILP (Voverriding_local_map_menu_flag
))
9500 specbind (Qoverriding_terminal_local_map
, Qnil
);
9501 specbind (Qoverriding_local_map
, Qnil
);
9504 GCPRO1 (new_tool_bar
);
9506 /* Build desired tool-bar items from keymaps. */
9507 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9510 /* Redisplay the tool-bar if we changed it. */
9511 if (new_n_tool_bar
!= f
->n_tool_bar_items
9512 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9514 /* Redisplay that happens asynchronously due to an expose event
9515 may access f->tool_bar_items. Make sure we update both
9516 variables within BLOCK_INPUT so no such event interrupts. */
9518 f
->tool_bar_items
= new_tool_bar
;
9519 f
->n_tool_bar_items
= new_n_tool_bar
;
9520 w
->update_mode_line
= Qt
;
9526 unbind_to (count
, Qnil
);
9527 set_buffer_internal_1 (prev
);
9533 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9534 F's desired tool-bar contents. F->tool_bar_items must have
9535 been set up previously by calling prepare_menu_bars. */
9538 build_desired_tool_bar_string (f
)
9541 int i
, size
, size_needed
;
9542 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9543 Lisp_Object image
, plist
, props
;
9545 image
= plist
= props
= Qnil
;
9546 GCPRO3 (image
, plist
, props
);
9548 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9549 Otherwise, make a new string. */
9551 /* The size of the string we might be able to reuse. */
9552 size
= (STRINGP (f
->desired_tool_bar_string
)
9553 ? SCHARS (f
->desired_tool_bar_string
)
9556 /* We need one space in the string for each image. */
9557 size_needed
= f
->n_tool_bar_items
;
9559 /* Reuse f->desired_tool_bar_string, if possible. */
9560 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9561 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9565 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9566 Fremove_text_properties (make_number (0), make_number (size
),
9567 props
, f
->desired_tool_bar_string
);
9570 /* Put a `display' property on the string for the images to display,
9571 put a `menu_item' property on tool-bar items with a value that
9572 is the index of the item in F's tool-bar item vector. */
9573 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9575 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9577 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9578 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9579 int hmargin
, vmargin
, relief
, idx
, end
;
9580 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9582 /* If image is a vector, choose the image according to the
9584 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9585 if (VECTORP (image
))
9589 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9590 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9593 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9594 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9596 xassert (ASIZE (image
) >= idx
);
9597 image
= AREF (image
, idx
);
9602 /* Ignore invalid image specifications. */
9603 if (!valid_image_p (image
))
9606 /* Display the tool-bar button pressed, or depressed. */
9607 plist
= Fcopy_sequence (XCDR (image
));
9609 /* Compute margin and relief to draw. */
9610 relief
= (tool_bar_button_relief
>= 0
9611 ? tool_bar_button_relief
9612 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9613 hmargin
= vmargin
= relief
;
9615 if (INTEGERP (Vtool_bar_button_margin
)
9616 && XINT (Vtool_bar_button_margin
) > 0)
9618 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9619 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9621 else if (CONSP (Vtool_bar_button_margin
))
9623 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9624 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9625 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9627 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9628 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9629 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9632 if (auto_raise_tool_bar_buttons_p
)
9634 /* Add a `:relief' property to the image spec if the item is
9638 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9645 /* If image is selected, display it pressed, i.e. with a
9646 negative relief. If it's not selected, display it with a
9648 plist
= Fplist_put (plist
, QCrelief
,
9650 ? make_number (-relief
)
9651 : make_number (relief
)));
9656 /* Put a margin around the image. */
9657 if (hmargin
|| vmargin
)
9659 if (hmargin
== vmargin
)
9660 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9662 plist
= Fplist_put (plist
, QCmargin
,
9663 Fcons (make_number (hmargin
),
9664 make_number (vmargin
)));
9667 /* If button is not enabled, and we don't have special images
9668 for the disabled state, make the image appear disabled by
9669 applying an appropriate algorithm to it. */
9670 if (!enabled_p
&& idx
< 0)
9671 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9673 /* Put a `display' text property on the string for the image to
9674 display. Put a `menu-item' property on the string that gives
9675 the start of this item's properties in the tool-bar items
9677 image
= Fcons (Qimage
, plist
);
9678 props
= list4 (Qdisplay
, image
,
9679 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9681 /* Let the last image hide all remaining spaces in the tool bar
9682 string. The string can be longer than needed when we reuse a
9684 if (i
+ 1 == f
->n_tool_bar_items
)
9685 end
= SCHARS (f
->desired_tool_bar_string
);
9688 Fadd_text_properties (make_number (i
), make_number (end
),
9689 props
, f
->desired_tool_bar_string
);
9697 /* Display one line of the tool-bar of frame IT->f.
9699 HEIGHT specifies the desired height of the tool-bar line.
9700 If the actual height of the glyph row is less than HEIGHT, the
9701 row's height is increased to HEIGHT, and the icons are centered
9702 vertically in the new height.
9704 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
9705 count a final empty row in case the tool-bar width exactly matches
9710 display_tool_bar_line (it
, height
)
9714 struct glyph_row
*row
= it
->glyph_row
;
9715 int max_x
= it
->last_visible_x
;
9718 prepare_desired_row (row
);
9719 row
->y
= it
->current_y
;
9721 /* Note that this isn't made use of if the face hasn't a box,
9722 so there's no need to check the face here. */
9723 it
->start_of_box_run_p
= 1;
9725 while (it
->current_x
< max_x
)
9727 int x
, n_glyphs_before
, i
, nglyphs
;
9728 struct it it_before
;
9730 /* Get the next display element. */
9731 if (!get_next_display_element (it
))
9733 /* Don't count empty row if we are counting needed tool-bar lines. */
9734 if (height
< 0 && !it
->hpos
)
9739 /* Produce glyphs. */
9740 n_glyphs_before
= row
->used
[TEXT_AREA
];
9743 PRODUCE_GLYPHS (it
);
9745 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
9747 x
= it_before
.current_x
;
9750 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9752 if (x
+ glyph
->pixel_width
> max_x
)
9754 /* Glyph doesn't fit on line. Backtrack. */
9755 row
->used
[TEXT_AREA
] = n_glyphs_before
;
9757 /* If this is the only glyph on this line, it will never fit on the
9758 toolbar, so skip it. But ensure there is at least one glyph,
9759 so we don't accidentally disable the tool-bar. */
9760 if (n_glyphs_before
== 0
9761 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
9767 x
+= glyph
->pixel_width
;
9771 /* Stop at line ends. */
9772 if (ITERATOR_AT_END_OF_LINE_P (it
))
9775 set_iterator_to_next (it
, 1);
9780 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9782 /* Use default face for the border below the tool bar.
9784 FIXME: When auto-resize-tool-bars is grow-only, there is
9785 no additional border below the possibly empty tool-bar lines.
9786 So to make the extra empty lines look "normal", we have to
9787 use the tool-bar face for the border too. */
9788 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
9789 it
->face_id
= DEFAULT_FACE_ID
;
9791 extend_face_to_end_of_line (it
);
9792 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9793 last
->right_box_line_p
= 1;
9794 if (last
== row
->glyphs
[TEXT_AREA
])
9795 last
->left_box_line_p
= 1;
9797 /* Make line the desired height and center it vertically. */
9798 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
9800 /* Don't add more than one line height. */
9801 height
%= FRAME_LINE_HEIGHT (it
->f
);
9802 it
->max_ascent
+= height
/ 2;
9803 it
->max_descent
+= (height
+ 1) / 2;
9806 compute_line_metrics (it
);
9808 /* If line is empty, make it occupy the rest of the tool-bar. */
9809 if (!row
->displays_text_p
)
9811 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9812 row
->visible_height
= row
->height
;
9813 row
->ascent
= row
->phys_ascent
= 0;
9814 row
->extra_line_spacing
= 0;
9817 row
->full_width_p
= 1;
9818 row
->continued_p
= 0;
9819 row
->truncated_on_left_p
= 0;
9820 row
->truncated_on_right_p
= 0;
9822 it
->current_x
= it
->hpos
= 0;
9823 it
->current_y
+= row
->height
;
9829 /* Max tool-bar height. */
9831 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
9832 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
9834 /* Value is the number of screen lines needed to make all tool-bar
9835 items of frame F visible. The number of actual rows needed is
9836 returned in *N_ROWS if non-NULL. */
9839 tool_bar_lines_needed (f
, n_rows
)
9843 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9845 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
9846 the desired matrix, so use (unused) mode-line row as temporary row to
9847 avoid destroying the first tool-bar row. */
9848 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
9850 /* Initialize an iterator for iteration over
9851 F->desired_tool_bar_string in the tool-bar window of frame F. */
9852 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
9853 it
.first_visible_x
= 0;
9854 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9855 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9857 while (!ITERATOR_AT_END_P (&it
))
9859 clear_glyph_row (temp_row
);
9860 it
.glyph_row
= temp_row
;
9861 display_tool_bar_line (&it
, -1);
9863 clear_glyph_row (temp_row
);
9865 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
9867 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
9869 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9873 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9875 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9884 frame
= selected_frame
;
9886 CHECK_FRAME (frame
);
9889 if (WINDOWP (f
->tool_bar_window
)
9890 || (w
= XWINDOW (f
->tool_bar_window
),
9891 WINDOW_TOTAL_LINES (w
) > 0))
9893 update_tool_bar (f
, 1);
9894 if (f
->n_tool_bar_items
)
9896 build_desired_tool_bar_string (f
);
9897 nlines
= tool_bar_lines_needed (f
, NULL
);
9901 return make_number (nlines
);
9905 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9906 height should be changed. */
9909 redisplay_tool_bar (f
)
9914 struct glyph_row
*row
;
9916 #if defined (USE_GTK) || USE_MAC_TOOLBAR
9917 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9918 update_frame_tool_bar (f
);
9922 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9923 do anything. This means you must start with tool-bar-lines
9924 non-zero to get the auto-sizing effect. Or in other words, you
9925 can turn off tool-bars by specifying tool-bar-lines zero. */
9926 if (!WINDOWP (f
->tool_bar_window
)
9927 || (w
= XWINDOW (f
->tool_bar_window
),
9928 WINDOW_TOTAL_LINES (w
) == 0))
9931 /* Set up an iterator for the tool-bar window. */
9932 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9933 it
.first_visible_x
= 0;
9934 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9937 /* Build a string that represents the contents of the tool-bar. */
9938 build_desired_tool_bar_string (f
);
9939 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9941 if (f
->n_tool_bar_rows
== 0)
9945 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
9946 nlines
!= WINDOW_TOTAL_LINES (w
)))
9948 extern Lisp_Object Qtool_bar_lines
;
9950 int old_height
= WINDOW_TOTAL_LINES (w
);
9952 XSETFRAME (frame
, f
);
9953 Fmodify_frame_parameters (frame
,
9954 Fcons (Fcons (Qtool_bar_lines
,
9955 make_number (nlines
)),
9957 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9959 clear_glyph_matrix (w
->desired_matrix
);
9960 fonts_changed_p
= 1;
9966 /* Display as many lines as needed to display all tool-bar items. */
9968 if (f
->n_tool_bar_rows
> 0)
9970 int border
, rows
, height
, extra
;
9972 if (INTEGERP (Vtool_bar_border
))
9973 border
= XINT (Vtool_bar_border
);
9974 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
9975 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
9976 else if (EQ (Vtool_bar_border
, Qborder_width
))
9977 border
= f
->border_width
;
9983 rows
= f
->n_tool_bar_rows
;
9984 height
= max (1, (it
.last_visible_y
- border
) / rows
);
9985 extra
= it
.last_visible_y
- border
- height
* rows
;
9987 while (it
.current_y
< it
.last_visible_y
)
9990 if (extra
> 0 && rows
-- > 0)
9992 h
= (extra
+ rows
- 1) / rows
;
9995 display_tool_bar_line (&it
, height
+ h
);
10000 while (it
.current_y
< it
.last_visible_y
)
10001 display_tool_bar_line (&it
, 0);
10004 /* It doesn't make much sense to try scrolling in the tool-bar
10005 window, so don't do it. */
10006 w
->desired_matrix
->no_scrolling_p
= 1;
10007 w
->must_be_updated_p
= 1;
10009 if (!NILP (Vauto_resize_tool_bars
))
10011 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10012 int change_height_p
= 0;
10014 /* If we couldn't display everything, change the tool-bar's
10015 height if there is room for more. */
10016 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10017 && it
.current_y
< max_tool_bar_height
)
10018 change_height_p
= 1;
10020 row
= it
.glyph_row
- 1;
10022 /* If there are blank lines at the end, except for a partially
10023 visible blank line at the end that is smaller than
10024 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10025 if (!row
->displays_text_p
10026 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10027 change_height_p
= 1;
10029 /* If row displays tool-bar items, but is partially visible,
10030 change the tool-bar's height. */
10031 if (row
->displays_text_p
10032 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10033 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10034 change_height_p
= 1;
10036 /* Resize windows as needed by changing the `tool-bar-lines'
10037 frame parameter. */
10038 if (change_height_p
)
10040 extern Lisp_Object Qtool_bar_lines
;
10042 int old_height
= WINDOW_TOTAL_LINES (w
);
10044 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10046 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10047 && !f
->minimize_tool_bar_window_p
)
10048 ? (nlines
> old_height
)
10049 : (nlines
!= old_height
));
10050 f
->minimize_tool_bar_window_p
= 0;
10052 if (change_height_p
)
10054 XSETFRAME (frame
, f
);
10055 Fmodify_frame_parameters (frame
,
10056 Fcons (Fcons (Qtool_bar_lines
,
10057 make_number (nlines
)),
10059 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10061 clear_glyph_matrix (w
->desired_matrix
);
10062 f
->n_tool_bar_rows
= nrows
;
10063 fonts_changed_p
= 1;
10070 f
->minimize_tool_bar_window_p
= 0;
10075 /* Get information about the tool-bar item which is displayed in GLYPH
10076 on frame F. Return in *PROP_IDX the index where tool-bar item
10077 properties start in F->tool_bar_items. Value is zero if
10078 GLYPH doesn't display a tool-bar item. */
10081 tool_bar_item_info (f
, glyph
, prop_idx
)
10083 struct glyph
*glyph
;
10090 /* This function can be called asynchronously, which means we must
10091 exclude any possibility that Fget_text_property signals an
10093 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10094 charpos
= max (0, charpos
);
10096 /* Get the text property `menu-item' at pos. The value of that
10097 property is the start index of this item's properties in
10098 F->tool_bar_items. */
10099 prop
= Fget_text_property (make_number (charpos
),
10100 Qmenu_item
, f
->current_tool_bar_string
);
10101 if (INTEGERP (prop
))
10103 *prop_idx
= XINT (prop
);
10113 /* Get information about the tool-bar item at position X/Y on frame F.
10114 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10115 the current matrix of the tool-bar window of F, or NULL if not
10116 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10117 item in F->tool_bar_items. Value is
10119 -1 if X/Y is not on a tool-bar item
10120 0 if X/Y is on the same item that was highlighted before.
10124 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10127 struct glyph
**glyph
;
10128 int *hpos
, *vpos
, *prop_idx
;
10130 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10131 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10134 /* Find the glyph under X/Y. */
10135 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10136 if (*glyph
== NULL
)
10139 /* Get the start of this tool-bar item's properties in
10140 f->tool_bar_items. */
10141 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10144 /* Is mouse on the highlighted item? */
10145 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10146 && *vpos
>= dpyinfo
->mouse_face_beg_row
10147 && *vpos
<= dpyinfo
->mouse_face_end_row
10148 && (*vpos
> dpyinfo
->mouse_face_beg_row
10149 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10150 && (*vpos
< dpyinfo
->mouse_face_end_row
10151 || *hpos
< dpyinfo
->mouse_face_end_col
10152 || dpyinfo
->mouse_face_past_end
))
10160 Handle mouse button event on the tool-bar of frame F, at
10161 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10162 0 for button release. MODIFIERS is event modifiers for button
10166 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10169 unsigned int modifiers
;
10171 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10172 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10173 int hpos
, vpos
, prop_idx
;
10174 struct glyph
*glyph
;
10175 Lisp_Object enabled_p
;
10177 /* If not on the highlighted tool-bar item, return. */
10178 frame_to_window_pixel_xy (w
, &x
, &y
);
10179 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10182 /* If item is disabled, do nothing. */
10183 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10184 if (NILP (enabled_p
))
10189 /* Show item in pressed state. */
10190 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10191 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10192 last_tool_bar_item
= prop_idx
;
10196 Lisp_Object key
, frame
;
10197 struct input_event event
;
10198 EVENT_INIT (event
);
10200 /* Show item in released state. */
10201 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10202 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10204 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10206 XSETFRAME (frame
, f
);
10207 event
.kind
= TOOL_BAR_EVENT
;
10208 event
.frame_or_window
= frame
;
10210 kbd_buffer_store_event (&event
);
10212 event
.kind
= TOOL_BAR_EVENT
;
10213 event
.frame_or_window
= frame
;
10215 event
.modifiers
= modifiers
;
10216 kbd_buffer_store_event (&event
);
10217 last_tool_bar_item
= -1;
10222 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10223 tool-bar window-relative coordinates X/Y. Called from
10224 note_mouse_highlight. */
10227 note_tool_bar_highlight (f
, x
, y
)
10231 Lisp_Object window
= f
->tool_bar_window
;
10232 struct window
*w
= XWINDOW (window
);
10233 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10235 struct glyph
*glyph
;
10236 struct glyph_row
*row
;
10238 Lisp_Object enabled_p
;
10240 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10241 int mouse_down_p
, rc
;
10243 /* Function note_mouse_highlight is called with negative x(y
10244 values when mouse moves outside of the frame. */
10245 if (x
<= 0 || y
<= 0)
10247 clear_mouse_face (dpyinfo
);
10251 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10254 /* Not on tool-bar item. */
10255 clear_mouse_face (dpyinfo
);
10259 /* On same tool-bar item as before. */
10260 goto set_help_echo
;
10262 clear_mouse_face (dpyinfo
);
10264 /* Mouse is down, but on different tool-bar item? */
10265 mouse_down_p
= (dpyinfo
->grabbed
10266 && f
== last_mouse_frame
10267 && FRAME_LIVE_P (f
));
10269 && last_tool_bar_item
!= prop_idx
)
10272 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10273 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10275 /* If tool-bar item is not enabled, don't highlight it. */
10276 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10277 if (!NILP (enabled_p
))
10279 /* Compute the x-position of the glyph. In front and past the
10280 image is a space. We include this in the highlighted area. */
10281 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10282 for (i
= x
= 0; i
< hpos
; ++i
)
10283 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10285 /* Record this as the current active region. */
10286 dpyinfo
->mouse_face_beg_col
= hpos
;
10287 dpyinfo
->mouse_face_beg_row
= vpos
;
10288 dpyinfo
->mouse_face_beg_x
= x
;
10289 dpyinfo
->mouse_face_beg_y
= row
->y
;
10290 dpyinfo
->mouse_face_past_end
= 0;
10292 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10293 dpyinfo
->mouse_face_end_row
= vpos
;
10294 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10295 dpyinfo
->mouse_face_end_y
= row
->y
;
10296 dpyinfo
->mouse_face_window
= window
;
10297 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10299 /* Display it as active. */
10300 show_mouse_face (dpyinfo
, draw
);
10301 dpyinfo
->mouse_face_image_state
= draw
;
10306 /* Set help_echo_string to a help string to display for this tool-bar item.
10307 XTread_socket does the rest. */
10308 help_echo_object
= help_echo_window
= Qnil
;
10309 help_echo_pos
= -1;
10310 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10311 if (NILP (help_echo_string
))
10312 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10315 #endif /* HAVE_WINDOW_SYSTEM */
10319 /************************************************************************
10320 Horizontal scrolling
10321 ************************************************************************/
10323 static int hscroll_window_tree
P_ ((Lisp_Object
));
10324 static int hscroll_windows
P_ ((Lisp_Object
));
10326 /* For all leaf windows in the window tree rooted at WINDOW, set their
10327 hscroll value so that PT is (i) visible in the window, and (ii) so
10328 that it is not within a certain margin at the window's left and
10329 right border. Value is non-zero if any window's hscroll has been
10333 hscroll_window_tree (window
)
10334 Lisp_Object window
;
10336 int hscrolled_p
= 0;
10337 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10338 int hscroll_step_abs
= 0;
10339 double hscroll_step_rel
= 0;
10341 if (hscroll_relative_p
)
10343 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10344 if (hscroll_step_rel
< 0)
10346 hscroll_relative_p
= 0;
10347 hscroll_step_abs
= 0;
10350 else if (INTEGERP (Vhscroll_step
))
10352 hscroll_step_abs
= XINT (Vhscroll_step
);
10353 if (hscroll_step_abs
< 0)
10354 hscroll_step_abs
= 0;
10357 hscroll_step_abs
= 0;
10359 while (WINDOWP (window
))
10361 struct window
*w
= XWINDOW (window
);
10363 if (WINDOWP (w
->hchild
))
10364 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10365 else if (WINDOWP (w
->vchild
))
10366 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10367 else if (w
->cursor
.vpos
>= 0)
10370 int text_area_width
;
10371 struct glyph_row
*current_cursor_row
10372 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10373 struct glyph_row
*desired_cursor_row
10374 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10375 struct glyph_row
*cursor_row
10376 = (desired_cursor_row
->enabled_p
10377 ? desired_cursor_row
10378 : current_cursor_row
);
10380 text_area_width
= window_box_width (w
, TEXT_AREA
);
10382 /* Scroll when cursor is inside this scroll margin. */
10383 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10385 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
10386 && ((XFASTINT (w
->hscroll
)
10387 && w
->cursor
.x
<= h_margin
)
10388 || (cursor_row
->enabled_p
10389 && cursor_row
->truncated_on_right_p
10390 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
10394 struct buffer
*saved_current_buffer
;
10398 /* Find point in a display of infinite width. */
10399 saved_current_buffer
= current_buffer
;
10400 current_buffer
= XBUFFER (w
->buffer
);
10402 if (w
== XWINDOW (selected_window
))
10403 pt
= BUF_PT (current_buffer
);
10406 pt
= marker_position (w
->pointm
);
10407 pt
= max (BEGV
, pt
);
10411 /* Move iterator to pt starting at cursor_row->start in
10412 a line with infinite width. */
10413 init_to_row_start (&it
, w
, cursor_row
);
10414 it
.last_visible_x
= INFINITY
;
10415 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10416 current_buffer
= saved_current_buffer
;
10418 /* Position cursor in window. */
10419 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10420 hscroll
= max (0, (it
.current_x
10421 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10422 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10423 : (text_area_width
/ 2))))
10424 / FRAME_COLUMN_WIDTH (it
.f
);
10425 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10427 if (hscroll_relative_p
)
10428 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10431 wanted_x
= text_area_width
10432 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10435 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10439 if (hscroll_relative_p
)
10440 wanted_x
= text_area_width
* hscroll_step_rel
10443 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10446 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10448 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10450 /* Don't call Fset_window_hscroll if value hasn't
10451 changed because it will prevent redisplay
10453 if (XFASTINT (w
->hscroll
) != hscroll
)
10455 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10456 w
->hscroll
= make_number (hscroll
);
10465 /* Value is non-zero if hscroll of any leaf window has been changed. */
10466 return hscrolled_p
;
10470 /* Set hscroll so that cursor is visible and not inside horizontal
10471 scroll margins for all windows in the tree rooted at WINDOW. See
10472 also hscroll_window_tree above. Value is non-zero if any window's
10473 hscroll has been changed. If it has, desired matrices on the frame
10474 of WINDOW are cleared. */
10477 hscroll_windows (window
)
10478 Lisp_Object window
;
10480 int hscrolled_p
= hscroll_window_tree (window
);
10482 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10483 return hscrolled_p
;
10488 /************************************************************************
10490 ************************************************************************/
10492 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10493 to a non-zero value. This is sometimes handy to have in a debugger
10498 /* First and last unchanged row for try_window_id. */
10500 int debug_first_unchanged_at_end_vpos
;
10501 int debug_last_unchanged_at_beg_vpos
;
10503 /* Delta vpos and y. */
10505 int debug_dvpos
, debug_dy
;
10507 /* Delta in characters and bytes for try_window_id. */
10509 int debug_delta
, debug_delta_bytes
;
10511 /* Values of window_end_pos and window_end_vpos at the end of
10514 EMACS_INT debug_end_pos
, debug_end_vpos
;
10516 /* Append a string to W->desired_matrix->method. FMT is a printf
10517 format string. A1...A9 are a supplement for a variable-length
10518 argument list. If trace_redisplay_p is non-zero also printf the
10519 resulting string to stderr. */
10522 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10525 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10528 char *method
= w
->desired_matrix
->method
;
10529 int len
= strlen (method
);
10530 int size
= sizeof w
->desired_matrix
->method
;
10531 int remaining
= size
- len
- 1;
10533 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10534 if (len
&& remaining
)
10537 --remaining
, ++len
;
10540 strncpy (method
+ len
, buffer
, remaining
);
10542 if (trace_redisplay_p
)
10543 fprintf (stderr
, "%p (%s): %s\n",
10545 ((BUFFERP (w
->buffer
)
10546 && STRINGP (XBUFFER (w
->buffer
)->name
))
10547 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10552 #endif /* GLYPH_DEBUG */
10555 /* Value is non-zero if all changes in window W, which displays
10556 current_buffer, are in the text between START and END. START is a
10557 buffer position, END is given as a distance from Z. Used in
10558 redisplay_internal for display optimization. */
10561 text_outside_line_unchanged_p (w
, start
, end
)
10565 int unchanged_p
= 1;
10567 /* If text or overlays have changed, see where. */
10568 if (XFASTINT (w
->last_modified
) < MODIFF
10569 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10571 /* Gap in the line? */
10572 if (GPT
< start
|| Z
- GPT
< end
)
10575 /* Changes start in front of the line, or end after it? */
10577 && (BEG_UNCHANGED
< start
- 1
10578 || END_UNCHANGED
< end
))
10581 /* If selective display, can't optimize if changes start at the
10582 beginning of the line. */
10584 && INTEGERP (current_buffer
->selective_display
)
10585 && XINT (current_buffer
->selective_display
) > 0
10586 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10589 /* If there are overlays at the start or end of the line, these
10590 may have overlay strings with newlines in them. A change at
10591 START, for instance, may actually concern the display of such
10592 overlay strings as well, and they are displayed on different
10593 lines. So, quickly rule out this case. (For the future, it
10594 might be desirable to implement something more telling than
10595 just BEG/END_UNCHANGED.) */
10598 if (BEG
+ BEG_UNCHANGED
== start
10599 && overlay_touches_p (start
))
10601 if (END_UNCHANGED
== end
10602 && overlay_touches_p (Z
- end
))
10607 return unchanged_p
;
10611 /* Do a frame update, taking possible shortcuts into account. This is
10612 the main external entry point for redisplay.
10614 If the last redisplay displayed an echo area message and that message
10615 is no longer requested, we clear the echo area or bring back the
10616 mini-buffer if that is in use. */
10621 redisplay_internal (0);
10626 overlay_arrow_string_or_property (var
)
10631 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10634 return Voverlay_arrow_string
;
10637 /* Return 1 if there are any overlay-arrows in current_buffer. */
10639 overlay_arrow_in_current_buffer_p ()
10643 for (vlist
= Voverlay_arrow_variable_list
;
10645 vlist
= XCDR (vlist
))
10647 Lisp_Object var
= XCAR (vlist
);
10650 if (!SYMBOLP (var
))
10652 val
= find_symbol_value (var
);
10654 && current_buffer
== XMARKER (val
)->buffer
)
10661 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
10665 overlay_arrows_changed_p ()
10669 for (vlist
= Voverlay_arrow_variable_list
;
10671 vlist
= XCDR (vlist
))
10673 Lisp_Object var
= XCAR (vlist
);
10674 Lisp_Object val
, pstr
;
10676 if (!SYMBOLP (var
))
10678 val
= find_symbol_value (var
);
10679 if (!MARKERP (val
))
10681 if (! EQ (COERCE_MARKER (val
),
10682 Fget (var
, Qlast_arrow_position
))
10683 || ! (pstr
= overlay_arrow_string_or_property (var
),
10684 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
10690 /* Mark overlay arrows to be updated on next redisplay. */
10693 update_overlay_arrows (up_to_date
)
10698 for (vlist
= Voverlay_arrow_variable_list
;
10700 vlist
= XCDR (vlist
))
10702 Lisp_Object var
= XCAR (vlist
);
10704 if (!SYMBOLP (var
))
10707 if (up_to_date
> 0)
10709 Lisp_Object val
= find_symbol_value (var
);
10710 Fput (var
, Qlast_arrow_position
,
10711 COERCE_MARKER (val
));
10712 Fput (var
, Qlast_arrow_string
,
10713 overlay_arrow_string_or_property (var
));
10715 else if (up_to_date
< 0
10716 || !NILP (Fget (var
, Qlast_arrow_position
)))
10718 Fput (var
, Qlast_arrow_position
, Qt
);
10719 Fput (var
, Qlast_arrow_string
, Qt
);
10725 /* Return overlay arrow string to display at row.
10726 Return integer (bitmap number) for arrow bitmap in left fringe.
10727 Return nil if no overlay arrow. */
10730 overlay_arrow_at_row (it
, row
)
10732 struct glyph_row
*row
;
10736 for (vlist
= Voverlay_arrow_variable_list
;
10738 vlist
= XCDR (vlist
))
10740 Lisp_Object var
= XCAR (vlist
);
10743 if (!SYMBOLP (var
))
10746 val
= find_symbol_value (var
);
10749 && current_buffer
== XMARKER (val
)->buffer
10750 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10752 if (FRAME_WINDOW_P (it
->f
)
10753 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10755 #ifdef HAVE_WINDOW_SYSTEM
10756 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10759 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10760 return make_number (fringe_bitmap
);
10763 return make_number (-1); /* Use default arrow bitmap */
10765 return overlay_arrow_string_or_property (var
);
10772 /* Return 1 if point moved out of or into a composition. Otherwise
10773 return 0. PREV_BUF and PREV_PT are the last point buffer and
10774 position. BUF and PT are the current point buffer and position. */
10777 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10778 struct buffer
*prev_buf
, *buf
;
10783 Lisp_Object buffer
;
10785 XSETBUFFER (buffer
, buf
);
10786 /* Check a composition at the last point if point moved within the
10788 if (prev_buf
== buf
)
10791 /* Point didn't move. */
10794 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10795 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10796 && COMPOSITION_VALID_P (start
, end
, prop
)
10797 && start
< prev_pt
&& end
> prev_pt
)
10798 /* The last point was within the composition. Return 1 iff
10799 point moved out of the composition. */
10800 return (pt
<= start
|| pt
>= end
);
10803 /* Check a composition at the current point. */
10804 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10805 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10806 && COMPOSITION_VALID_P (start
, end
, prop
)
10807 && start
< pt
&& end
> pt
);
10811 /* Reconsider the setting of B->clip_changed which is displayed
10815 reconsider_clip_changes (w
, b
)
10819 if (b
->clip_changed
10820 && !NILP (w
->window_end_valid
)
10821 && w
->current_matrix
->buffer
== b
10822 && w
->current_matrix
->zv
== BUF_ZV (b
)
10823 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10824 b
->clip_changed
= 0;
10826 /* If display wasn't paused, and W is not a tool bar window, see if
10827 point has been moved into or out of a composition. In that case,
10828 we set b->clip_changed to 1 to force updating the screen. If
10829 b->clip_changed has already been set to 1, we can skip this
10831 if (!b
->clip_changed
10832 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10836 if (w
== XWINDOW (selected_window
))
10837 pt
= BUF_PT (current_buffer
);
10839 pt
= marker_position (w
->pointm
);
10841 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10842 || pt
!= XINT (w
->last_point
))
10843 && check_point_in_composition (w
->current_matrix
->buffer
,
10844 XINT (w
->last_point
),
10845 XBUFFER (w
->buffer
), pt
))
10846 b
->clip_changed
= 1;
10851 /* Select FRAME to forward the values of frame-local variables into C
10852 variables so that the redisplay routines can access those values
10856 select_frame_for_redisplay (frame
)
10859 Lisp_Object tail
, sym
, val
;
10860 Lisp_Object old
= selected_frame
;
10862 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
10864 selected_frame
= frame
;
10866 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10867 if (CONSP (XCAR (tail
))
10868 && (sym
= XCAR (XCAR (tail
)),
10870 && (sym
= indirect_variable (sym
),
10871 val
= SYMBOL_VALUE (sym
),
10872 (BUFFER_LOCAL_VALUEP (val
)))
10873 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10874 /* Use find_symbol_value rather than Fsymbol_value
10875 to avoid an error if it is void. */
10876 find_symbol_value (sym
);
10878 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10879 if (CONSP (XCAR (tail
))
10880 && (sym
= XCAR (XCAR (tail
)),
10882 && (sym
= indirect_variable (sym
),
10883 val
= SYMBOL_VALUE (sym
),
10884 (BUFFER_LOCAL_VALUEP (val
)))
10885 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10886 find_symbol_value (sym
);
10890 #define STOP_POLLING \
10891 do { if (! polling_stopped_here) stop_polling (); \
10892 polling_stopped_here = 1; } while (0)
10894 #define RESUME_POLLING \
10895 do { if (polling_stopped_here) start_polling (); \
10896 polling_stopped_here = 0; } while (0)
10899 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10900 response to any user action; therefore, we should preserve the echo
10901 area. (Actually, our caller does that job.) Perhaps in the future
10902 avoid recentering windows if it is not necessary; currently that
10903 causes some problems. */
10906 redisplay_internal (preserve_echo_area
)
10907 int preserve_echo_area
;
10909 struct window
*w
= XWINDOW (selected_window
);
10912 int must_finish
= 0;
10913 struct text_pos tlbufpos
, tlendpos
;
10914 int number_of_visible_frames
;
10917 int polling_stopped_here
= 0;
10918 Lisp_Object old_frame
= selected_frame
;
10920 /* Non-zero means redisplay has to consider all windows on all
10921 frames. Zero means, only selected_window is considered. */
10922 int consider_all_windows_p
;
10924 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10926 /* No redisplay if running in batch mode or frame is not yet fully
10927 initialized, or redisplay is explicitly turned off by setting
10928 Vinhibit_redisplay. */
10930 || !NILP (Vinhibit_redisplay
))
10933 /* Don't examine these until after testing Vinhibit_redisplay.
10934 When Emacs is shutting down, perhaps because its connection to
10935 X has dropped, we should not look at them at all. */
10936 f
= XFRAME (w
->frame
);
10937 sf
= SELECTED_FRAME ();
10939 if (!f
->glyphs_initialized_p
)
10942 /* The flag redisplay_performed_directly_p is set by
10943 direct_output_for_insert when it already did the whole screen
10944 update necessary. */
10945 if (redisplay_performed_directly_p
)
10947 redisplay_performed_directly_p
= 0;
10948 if (!hscroll_windows (selected_window
))
10952 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (MAC_OS)
10953 if (popup_activated ())
10957 /* I don't think this happens but let's be paranoid. */
10958 if (redisplaying_p
)
10961 /* Record a function that resets redisplaying_p to its old value
10962 when we leave this function. */
10963 count
= SPECPDL_INDEX ();
10964 record_unwind_protect (unwind_redisplay
,
10965 Fcons (make_number (redisplaying_p
), selected_frame
));
10967 specbind (Qinhibit_free_realized_faces
, Qnil
);
10970 Lisp_Object tail
, frame
;
10972 FOR_EACH_FRAME (tail
, frame
)
10974 struct frame
*f
= XFRAME (frame
);
10975 f
->already_hscrolled_p
= 0;
10980 if (!EQ (old_frame
, selected_frame
)
10981 && FRAME_LIVE_P (XFRAME (old_frame
)))
10982 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
10983 selected_frame and selected_window to be temporarily out-of-sync so
10984 when we come back here via `goto retry', we need to resync because we
10985 may need to run Elisp code (via prepare_menu_bars). */
10986 select_frame_for_redisplay (old_frame
);
10989 reconsider_clip_changes (w
, current_buffer
);
10990 last_escape_glyph_frame
= NULL
;
10991 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
10993 /* If new fonts have been loaded that make a glyph matrix adjustment
10994 necessary, do it. */
10995 if (fonts_changed_p
)
10997 adjust_glyphs (NULL
);
10998 ++windows_or_buffers_changed
;
10999 fonts_changed_p
= 0;
11002 /* If face_change_count is non-zero, init_iterator will free all
11003 realized faces, which includes the faces referenced from current
11004 matrices. So, we can't reuse current matrices in this case. */
11005 if (face_change_count
)
11006 ++windows_or_buffers_changed
;
11008 if (FRAME_TERMCAP_P (sf
)
11009 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11011 /* Since frames on a single ASCII terminal share the same
11012 display area, displaying a different frame means redisplay
11013 the whole thing. */
11014 windows_or_buffers_changed
++;
11015 SET_FRAME_GARBAGED (sf
);
11016 FRAME_TTY (sf
)->previous_frame
= sf
;
11019 /* Set the visible flags for all frames. Do this before checking
11020 for resized or garbaged frames; they want to know if their frames
11021 are visible. See the comment in frame.h for
11022 FRAME_SAMPLE_VISIBILITY. */
11024 Lisp_Object tail
, frame
;
11026 number_of_visible_frames
= 0;
11028 FOR_EACH_FRAME (tail
, frame
)
11030 struct frame
*f
= XFRAME (frame
);
11032 FRAME_SAMPLE_VISIBILITY (f
);
11033 if (FRAME_VISIBLE_P (f
))
11034 ++number_of_visible_frames
;
11035 clear_desired_matrices (f
);
11040 /* Notice any pending interrupt request to change frame size. */
11041 do_pending_window_change (1);
11043 /* Clear frames marked as garbaged. */
11044 if (frame_garbaged
)
11045 clear_garbaged_frames ();
11047 /* Build menubar and tool-bar items. */
11048 if (NILP (Vmemory_full
))
11049 prepare_menu_bars ();
11051 if (windows_or_buffers_changed
)
11052 update_mode_lines
++;
11054 /* Detect case that we need to write or remove a star in the mode line. */
11055 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11057 w
->update_mode_line
= Qt
;
11058 if (buffer_shared
> 1)
11059 update_mode_lines
++;
11062 /* Avoid invocation of point motion hooks by `current_column' below. */
11063 count1
= SPECPDL_INDEX ();
11064 specbind (Qinhibit_point_motion_hooks
, Qt
);
11066 /* If %c is in the mode line, update it if needed. */
11067 if (!NILP (w
->column_number_displayed
)
11068 /* This alternative quickly identifies a common case
11069 where no change is needed. */
11070 && !(PT
== XFASTINT (w
->last_point
)
11071 && XFASTINT (w
->last_modified
) >= MODIFF
11072 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11073 && (XFASTINT (w
->column_number_displayed
)
11074 != (int) current_column ())) /* iftc */
11075 w
->update_mode_line
= Qt
;
11077 unbind_to (count1
, Qnil
);
11079 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11081 /* The variable buffer_shared is set in redisplay_window and
11082 indicates that we redisplay a buffer in different windows. See
11084 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11085 || cursor_type_changed
);
11087 /* If specs for an arrow have changed, do thorough redisplay
11088 to ensure we remove any arrow that should no longer exist. */
11089 if (overlay_arrows_changed_p ())
11090 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11092 /* Normally the message* functions will have already displayed and
11093 updated the echo area, but the frame may have been trashed, or
11094 the update may have been preempted, so display the echo area
11095 again here. Checking message_cleared_p captures the case that
11096 the echo area should be cleared. */
11097 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11098 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11099 || (message_cleared_p
11100 && minibuf_level
== 0
11101 /* If the mini-window is currently selected, this means the
11102 echo-area doesn't show through. */
11103 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11105 int window_height_changed_p
= echo_area_display (0);
11108 /* If we don't display the current message, don't clear the
11109 message_cleared_p flag, because, if we did, we wouldn't clear
11110 the echo area in the next redisplay which doesn't preserve
11112 if (!display_last_displayed_message_p
)
11113 message_cleared_p
= 0;
11115 if (fonts_changed_p
)
11117 else if (window_height_changed_p
)
11119 consider_all_windows_p
= 1;
11120 ++update_mode_lines
;
11121 ++windows_or_buffers_changed
;
11123 /* If window configuration was changed, frames may have been
11124 marked garbaged. Clear them or we will experience
11125 surprises wrt scrolling. */
11126 if (frame_garbaged
)
11127 clear_garbaged_frames ();
11130 else if (EQ (selected_window
, minibuf_window
)
11131 && (current_buffer
->clip_changed
11132 || XFASTINT (w
->last_modified
) < MODIFF
11133 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11134 && resize_mini_window (w
, 0))
11136 /* Resized active mini-window to fit the size of what it is
11137 showing if its contents might have changed. */
11139 consider_all_windows_p
= 1;
11140 ++windows_or_buffers_changed
;
11141 ++update_mode_lines
;
11143 /* If window configuration was changed, frames may have been
11144 marked garbaged. Clear them or we will experience
11145 surprises wrt scrolling. */
11146 if (frame_garbaged
)
11147 clear_garbaged_frames ();
11151 /* If showing the region, and mark has changed, we must redisplay
11152 the whole window. The assignment to this_line_start_pos prevents
11153 the optimization directly below this if-statement. */
11154 if (((!NILP (Vtransient_mark_mode
)
11155 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11156 != !NILP (w
->region_showing
))
11157 || (!NILP (w
->region_showing
)
11158 && !EQ (w
->region_showing
,
11159 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11160 CHARPOS (this_line_start_pos
) = 0;
11162 /* Optimize the case that only the line containing the cursor in the
11163 selected window has changed. Variables starting with this_ are
11164 set in display_line and record information about the line
11165 containing the cursor. */
11166 tlbufpos
= this_line_start_pos
;
11167 tlendpos
= this_line_end_pos
;
11168 if (!consider_all_windows_p
11169 && CHARPOS (tlbufpos
) > 0
11170 && NILP (w
->update_mode_line
)
11171 && !current_buffer
->clip_changed
11172 && !current_buffer
->prevent_redisplay_optimizations_p
11173 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11174 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11175 /* Make sure recorded data applies to current buffer, etc. */
11176 && this_line_buffer
== current_buffer
11177 && current_buffer
== XBUFFER (w
->buffer
)
11178 && NILP (w
->force_start
)
11179 && NILP (w
->optional_new_start
)
11180 /* Point must be on the line that we have info recorded about. */
11181 && PT
>= CHARPOS (tlbufpos
)
11182 && PT
<= Z
- CHARPOS (tlendpos
)
11183 /* All text outside that line, including its final newline,
11184 must be unchanged */
11185 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11186 CHARPOS (tlendpos
)))
11188 if (CHARPOS (tlbufpos
) > BEGV
11189 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11190 && (CHARPOS (tlbufpos
) == ZV
11191 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11192 /* Former continuation line has disappeared by becoming empty */
11194 else if (XFASTINT (w
->last_modified
) < MODIFF
11195 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11196 || MINI_WINDOW_P (w
))
11198 /* We have to handle the case of continuation around a
11199 wide-column character (See the comment in indent.c around
11202 For instance, in the following case:
11204 -------- Insert --------
11205 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11206 J_I_ ==> J_I_ `^^' are cursors.
11210 As we have to redraw the line above, we should goto cancel. */
11213 int line_height_before
= this_line_pixel_height
;
11215 /* Note that start_display will handle the case that the
11216 line starting at tlbufpos is a continuation lines. */
11217 start_display (&it
, w
, tlbufpos
);
11219 /* Implementation note: It this still necessary? */
11220 if (it
.current_x
!= this_line_start_x
)
11223 TRACE ((stderr
, "trying display optimization 1\n"));
11224 w
->cursor
.vpos
= -1;
11225 overlay_arrow_seen
= 0;
11226 it
.vpos
= this_line_vpos
;
11227 it
.current_y
= this_line_y
;
11228 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11229 display_line (&it
);
11231 /* If line contains point, is not continued,
11232 and ends at same distance from eob as before, we win */
11233 if (w
->cursor
.vpos
>= 0
11234 /* Line is not continued, otherwise this_line_start_pos
11235 would have been set to 0 in display_line. */
11236 && CHARPOS (this_line_start_pos
)
11237 /* Line ends as before. */
11238 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11239 /* Line has same height as before. Otherwise other lines
11240 would have to be shifted up or down. */
11241 && this_line_pixel_height
== line_height_before
)
11243 /* If this is not the window's last line, we must adjust
11244 the charstarts of the lines below. */
11245 if (it
.current_y
< it
.last_visible_y
)
11247 struct glyph_row
*row
11248 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11249 int delta
, delta_bytes
;
11251 if (Z
- CHARPOS (tlendpos
) == ZV
)
11253 /* This line ends at end of (accessible part of)
11254 buffer. There is no newline to count. */
11256 - CHARPOS (tlendpos
)
11257 - MATRIX_ROW_START_CHARPOS (row
));
11258 delta_bytes
= (Z_BYTE
11259 - BYTEPOS (tlendpos
)
11260 - MATRIX_ROW_START_BYTEPOS (row
));
11264 /* This line ends in a newline. Must take
11265 account of the newline and the rest of the
11266 text that follows. */
11268 - CHARPOS (tlendpos
)
11269 - MATRIX_ROW_START_CHARPOS (row
));
11270 delta_bytes
= (Z_BYTE
11271 - BYTEPOS (tlendpos
)
11272 - MATRIX_ROW_START_BYTEPOS (row
));
11275 increment_matrix_positions (w
->current_matrix
,
11276 this_line_vpos
+ 1,
11277 w
->current_matrix
->nrows
,
11278 delta
, delta_bytes
);
11281 /* If this row displays text now but previously didn't,
11282 or vice versa, w->window_end_vpos may have to be
11284 if ((it
.glyph_row
- 1)->displays_text_p
)
11286 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11287 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11289 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11290 && this_line_vpos
> 0)
11291 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11292 w
->window_end_valid
= Qnil
;
11294 /* Update hint: No need to try to scroll in update_window. */
11295 w
->desired_matrix
->no_scrolling_p
= 1;
11298 *w
->desired_matrix
->method
= 0;
11299 debug_method_add (w
, "optimization 1");
11301 #ifdef HAVE_WINDOW_SYSTEM
11302 update_window_fringes (w
, 0);
11309 else if (/* Cursor position hasn't changed. */
11310 PT
== XFASTINT (w
->last_point
)
11311 /* Make sure the cursor was last displayed
11312 in this window. Otherwise we have to reposition it. */
11313 && 0 <= w
->cursor
.vpos
11314 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11318 do_pending_window_change (1);
11320 /* We used to always goto end_of_redisplay here, but this
11321 isn't enough if we have a blinking cursor. */
11322 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11323 goto end_of_redisplay
;
11327 /* If highlighting the region, or if the cursor is in the echo area,
11328 then we can't just move the cursor. */
11329 else if (! (!NILP (Vtransient_mark_mode
)
11330 && !NILP (current_buffer
->mark_active
))
11331 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11332 || highlight_nonselected_windows
)
11333 && NILP (w
->region_showing
)
11334 && NILP (Vshow_trailing_whitespace
)
11335 && !cursor_in_echo_area
)
11338 struct glyph_row
*row
;
11340 /* Skip from tlbufpos to PT and see where it is. Note that
11341 PT may be in invisible text. If so, we will end at the
11342 next visible position. */
11343 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11344 NULL
, DEFAULT_FACE_ID
);
11345 it
.current_x
= this_line_start_x
;
11346 it
.current_y
= this_line_y
;
11347 it
.vpos
= this_line_vpos
;
11349 /* The call to move_it_to stops in front of PT, but
11350 moves over before-strings. */
11351 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11353 if (it
.vpos
== this_line_vpos
11354 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11357 xassert (this_line_vpos
== it
.vpos
);
11358 xassert (this_line_y
== it
.current_y
);
11359 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11361 *w
->desired_matrix
->method
= 0;
11362 debug_method_add (w
, "optimization 3");
11371 /* Text changed drastically or point moved off of line. */
11372 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11375 CHARPOS (this_line_start_pos
) = 0;
11376 consider_all_windows_p
|= buffer_shared
> 1;
11377 ++clear_face_cache_count
;
11378 #ifdef HAVE_WINDOW_SYSTEM
11379 ++clear_image_cache_count
;
11382 /* Build desired matrices, and update the display. If
11383 consider_all_windows_p is non-zero, do it for all windows on all
11384 frames. Otherwise do it for selected_window, only. */
11386 if (consider_all_windows_p
)
11388 Lisp_Object tail
, frame
;
11390 FOR_EACH_FRAME (tail
, frame
)
11391 XFRAME (frame
)->updated_p
= 0;
11393 /* Recompute # windows showing selected buffer. This will be
11394 incremented each time such a window is displayed. */
11397 FOR_EACH_FRAME (tail
, frame
)
11399 struct frame
*f
= XFRAME (frame
);
11401 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
11403 if (! EQ (frame
, selected_frame
))
11404 /* Select the frame, for the sake of frame-local
11406 select_frame_for_redisplay (frame
);
11408 /* Mark all the scroll bars to be removed; we'll redeem
11409 the ones we want when we redisplay their windows. */
11410 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
11411 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
11413 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11414 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11416 /* Any scroll bars which redisplay_windows should have
11417 nuked should now go away. */
11418 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
11419 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
11421 /* If fonts changed, display again. */
11422 /* ??? rms: I suspect it is a mistake to jump all the way
11423 back to retry here. It should just retry this frame. */
11424 if (fonts_changed_p
)
11427 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11429 /* See if we have to hscroll. */
11430 if (!f
->already_hscrolled_p
)
11432 f
->already_hscrolled_p
= 1;
11433 if (hscroll_windows (f
->root_window
))
11437 /* Prevent various kinds of signals during display
11438 update. stdio is not robust about handling
11439 signals, which can cause an apparent I/O
11441 if (interrupt_input
)
11442 unrequest_sigio ();
11445 /* Update the display. */
11446 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11447 pause
|= update_frame (f
, 0, 0);
11448 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
11460 /* Do the mark_window_display_accurate after all windows have
11461 been redisplayed because this call resets flags in buffers
11462 which are needed for proper redisplay. */
11463 FOR_EACH_FRAME (tail
, frame
)
11465 struct frame
*f
= XFRAME (frame
);
11468 mark_window_display_accurate (f
->root_window
, 1);
11469 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
11470 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
11475 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11477 Lisp_Object mini_window
;
11478 struct frame
*mini_frame
;
11480 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11481 /* Use list_of_error, not Qerror, so that
11482 we catch only errors and don't run the debugger. */
11483 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11485 redisplay_window_error
);
11487 /* Compare desired and current matrices, perform output. */
11490 /* If fonts changed, display again. */
11491 if (fonts_changed_p
)
11494 /* Prevent various kinds of signals during display update.
11495 stdio is not robust about handling signals,
11496 which can cause an apparent I/O error. */
11497 if (interrupt_input
)
11498 unrequest_sigio ();
11501 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11503 if (hscroll_windows (selected_window
))
11506 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11507 pause
= update_frame (sf
, 0, 0);
11510 /* We may have called echo_area_display at the top of this
11511 function. If the echo area is on another frame, that may
11512 have put text on a frame other than the selected one, so the
11513 above call to update_frame would not have caught it. Catch
11515 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11516 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11518 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11520 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11521 pause
|= update_frame (mini_frame
, 0, 0);
11522 if (!pause
&& hscroll_windows (mini_window
))
11527 /* If display was paused because of pending input, make sure we do a
11528 thorough update the next time. */
11531 /* Prevent the optimization at the beginning of
11532 redisplay_internal that tries a single-line update of the
11533 line containing the cursor in the selected window. */
11534 CHARPOS (this_line_start_pos
) = 0;
11536 /* Let the overlay arrow be updated the next time. */
11537 update_overlay_arrows (0);
11539 /* If we pause after scrolling, some rows in the current
11540 matrices of some windows are not valid. */
11541 if (!WINDOW_FULL_WIDTH_P (w
)
11542 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11543 update_mode_lines
= 1;
11547 if (!consider_all_windows_p
)
11549 /* This has already been done above if
11550 consider_all_windows_p is set. */
11551 mark_window_display_accurate_1 (w
, 1);
11553 /* Say overlay arrows are up to date. */
11554 update_overlay_arrows (1);
11556 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
11557 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
11560 update_mode_lines
= 0;
11561 windows_or_buffers_changed
= 0;
11562 cursor_type_changed
= 0;
11565 /* Start SIGIO interrupts coming again. Having them off during the
11566 code above makes it less likely one will discard output, but not
11567 impossible, since there might be stuff in the system buffer here.
11568 But it is much hairier to try to do anything about that. */
11569 if (interrupt_input
)
11573 /* If a frame has become visible which was not before, redisplay
11574 again, so that we display it. Expose events for such a frame
11575 (which it gets when becoming visible) don't call the parts of
11576 redisplay constructing glyphs, so simply exposing a frame won't
11577 display anything in this case. So, we have to display these
11578 frames here explicitly. */
11581 Lisp_Object tail
, frame
;
11584 FOR_EACH_FRAME (tail
, frame
)
11586 int this_is_visible
= 0;
11588 if (XFRAME (frame
)->visible
)
11589 this_is_visible
= 1;
11590 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11591 if (XFRAME (frame
)->visible
)
11592 this_is_visible
= 1;
11594 if (this_is_visible
)
11598 if (new_count
!= number_of_visible_frames
)
11599 windows_or_buffers_changed
++;
11602 /* Change frame size now if a change is pending. */
11603 do_pending_window_change (1);
11605 /* If we just did a pending size change, or have additional
11606 visible frames, redisplay again. */
11607 if (windows_or_buffers_changed
&& !pause
)
11610 /* Clear the face cache eventually. */
11611 if (consider_all_windows_p
)
11613 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11615 clear_face_cache (0);
11616 clear_face_cache_count
= 0;
11618 #ifdef HAVE_WINDOW_SYSTEM
11619 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11621 Lisp_Object tail
, frame
;
11622 FOR_EACH_FRAME (tail
, frame
)
11624 struct frame
*f
= XFRAME (frame
);
11625 if (FRAME_WINDOW_P (f
))
11626 clear_image_cache (f
, 0);
11628 clear_image_cache_count
= 0;
11630 #endif /* HAVE_WINDOW_SYSTEM */
11634 unbind_to (count
, Qnil
);
11639 /* Redisplay, but leave alone any recent echo area message unless
11640 another message has been requested in its place.
11642 This is useful in situations where you need to redisplay but no
11643 user action has occurred, making it inappropriate for the message
11644 area to be cleared. See tracking_off and
11645 wait_reading_process_output for examples of these situations.
11647 FROM_WHERE is an integer saying from where this function was
11648 called. This is useful for debugging. */
11651 redisplay_preserve_echo_area (from_where
)
11654 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
11656 if (!NILP (echo_area_buffer
[1]))
11658 /* We have a previously displayed message, but no current
11659 message. Redisplay the previous message. */
11660 display_last_displayed_message_p
= 1;
11661 redisplay_internal (1);
11662 display_last_displayed_message_p
= 0;
11665 redisplay_internal (1);
11667 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
11668 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11669 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
11673 /* Function registered with record_unwind_protect in
11674 redisplay_internal. Reset redisplaying_p to the value it had
11675 before redisplay_internal was called, and clear
11676 prevent_freeing_realized_faces_p. It also selects the previously
11677 selected frame, unless it has been deleted (by an X connection
11678 failure during redisplay, for example). */
11681 unwind_redisplay (val
)
11684 Lisp_Object old_redisplaying_p
, old_frame
;
11686 old_redisplaying_p
= XCAR (val
);
11687 redisplaying_p
= XFASTINT (old_redisplaying_p
);
11688 old_frame
= XCDR (val
);
11689 if (! EQ (old_frame
, selected_frame
)
11690 && FRAME_LIVE_P (XFRAME (old_frame
)))
11691 select_frame_for_redisplay (old_frame
);
11696 /* Mark the display of window W as accurate or inaccurate. If
11697 ACCURATE_P is non-zero mark display of W as accurate. If
11698 ACCURATE_P is zero, arrange for W to be redisplayed the next time
11699 redisplay_internal is called. */
11702 mark_window_display_accurate_1 (w
, accurate_p
)
11706 if (BUFFERP (w
->buffer
))
11708 struct buffer
*b
= XBUFFER (w
->buffer
);
11711 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
11712 w
->last_overlay_modified
11713 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
11715 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
11719 b
->clip_changed
= 0;
11720 b
->prevent_redisplay_optimizations_p
= 0;
11722 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
11723 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
11724 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
11725 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
11727 w
->current_matrix
->buffer
= b
;
11728 w
->current_matrix
->begv
= BUF_BEGV (b
);
11729 w
->current_matrix
->zv
= BUF_ZV (b
);
11731 w
->last_cursor
= w
->cursor
;
11732 w
->last_cursor_off_p
= w
->cursor_off_p
;
11734 if (w
== XWINDOW (selected_window
))
11735 w
->last_point
= make_number (BUF_PT (b
));
11737 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
11743 w
->window_end_valid
= w
->buffer
;
11744 #if 0 /* This is incorrect with variable-height lines. */
11745 xassert (XINT (w
->window_end_vpos
)
11746 < (WINDOW_TOTAL_LINES (w
)
11747 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
11749 w
->update_mode_line
= Qnil
;
11754 /* Mark the display of windows in the window tree rooted at WINDOW as
11755 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
11756 windows as accurate. If ACCURATE_P is zero, arrange for windows to
11757 be redisplayed the next time redisplay_internal is called. */
11760 mark_window_display_accurate (window
, accurate_p
)
11761 Lisp_Object window
;
11766 for (; !NILP (window
); window
= w
->next
)
11768 w
= XWINDOW (window
);
11769 mark_window_display_accurate_1 (w
, accurate_p
);
11771 if (!NILP (w
->vchild
))
11772 mark_window_display_accurate (w
->vchild
, accurate_p
);
11773 if (!NILP (w
->hchild
))
11774 mark_window_display_accurate (w
->hchild
, accurate_p
);
11779 update_overlay_arrows (1);
11783 /* Force a thorough redisplay the next time by setting
11784 last_arrow_position and last_arrow_string to t, which is
11785 unequal to any useful value of Voverlay_arrow_... */
11786 update_overlay_arrows (-1);
11791 /* Return value in display table DP (Lisp_Char_Table *) for character
11792 C. Since a display table doesn't have any parent, we don't have to
11793 follow parent. Do not call this function directly but use the
11794 macro DISP_CHAR_VECTOR. */
11797 disp_char_vector (dp
, c
)
11798 struct Lisp_Char_Table
*dp
;
11804 if (SINGLE_BYTE_CHAR_P (c
))
11805 return (dp
->contents
[c
]);
11807 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
11810 else if (code
[2] < 32)
11813 /* Here, the possible range of code[0] (== charset ID) is
11814 128..max_charset. Since the top level char table contains data
11815 for multibyte characters after 256th element, we must increment
11816 code[0] by 128 to get a correct index. */
11818 code
[3] = -1; /* anchor */
11820 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
11822 val
= dp
->contents
[code
[i
]];
11823 if (!SUB_CHAR_TABLE_P (val
))
11824 return (NILP (val
) ? dp
->defalt
: val
);
11827 /* Here, val is a sub char table. We return the default value of
11829 return (dp
->defalt
);
11834 /***********************************************************************
11836 ***********************************************************************/
11838 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11841 redisplay_windows (window
)
11842 Lisp_Object window
;
11844 while (!NILP (window
))
11846 struct window
*w
= XWINDOW (window
);
11848 if (!NILP (w
->hchild
))
11849 redisplay_windows (w
->hchild
);
11850 else if (!NILP (w
->vchild
))
11851 redisplay_windows (w
->vchild
);
11854 displayed_buffer
= XBUFFER (w
->buffer
);
11855 /* Use list_of_error, not Qerror, so that
11856 we catch only errors and don't run the debugger. */
11857 internal_condition_case_1 (redisplay_window_0
, window
,
11859 redisplay_window_error
);
11867 redisplay_window_error ()
11869 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11874 redisplay_window_0 (window
)
11875 Lisp_Object window
;
11877 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11878 redisplay_window (window
, 0);
11883 redisplay_window_1 (window
)
11884 Lisp_Object window
;
11886 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11887 redisplay_window (window
, 1);
11892 /* Increment GLYPH until it reaches END or CONDITION fails while
11893 adding (GLYPH)->pixel_width to X. */
11895 #define SKIP_GLYPHS(glyph, end, x, condition) \
11898 (x) += (glyph)->pixel_width; \
11901 while ((glyph) < (end) && (condition))
11904 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11905 DELTA is the number of bytes by which positions recorded in ROW
11906 differ from current buffer positions.
11908 Return 0 if cursor is not on this row. 1 otherwise. */
11911 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11913 struct glyph_row
*row
;
11914 struct glyph_matrix
*matrix
;
11915 int delta
, delta_bytes
, dy
, dvpos
;
11917 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11918 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11919 struct glyph
*cursor
= NULL
;
11920 /* The first glyph that starts a sequence of glyphs from string. */
11921 struct glyph
*string_start
;
11922 /* The X coordinate of string_start. */
11923 int string_start_x
;
11924 /* The last known character position. */
11925 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11926 /* The last known character position before string_start. */
11927 int string_before_pos
;
11930 int cursor_from_overlay_pos
= 0;
11931 int pt_old
= PT
- delta
;
11933 /* Skip over glyphs not having an object at the start of the row.
11934 These are special glyphs like truncation marks on terminal
11936 if (row
->displays_text_p
)
11938 && INTEGERP (glyph
->object
)
11939 && glyph
->charpos
< 0)
11941 x
+= glyph
->pixel_width
;
11945 string_start
= NULL
;
11947 && !INTEGERP (glyph
->object
)
11948 && (!BUFFERP (glyph
->object
)
11949 || (last_pos
= glyph
->charpos
) < pt_old
))
11951 if (! STRINGP (glyph
->object
))
11953 string_start
= NULL
;
11954 x
+= glyph
->pixel_width
;
11956 if (cursor_from_overlay_pos
11957 && last_pos
>= cursor_from_overlay_pos
)
11959 cursor_from_overlay_pos
= 0;
11965 if (string_start
== NULL
)
11967 string_before_pos
= last_pos
;
11968 string_start
= glyph
;
11969 string_start_x
= x
;
11971 /* Skip all glyphs from string. */
11976 if ((cursor
== NULL
|| glyph
> cursor
)
11977 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
11978 Qcursor
, (glyph
)->object
),
11980 && (pos
= string_buffer_position (w
, glyph
->object
,
11981 string_before_pos
),
11982 (pos
== 0 /* From overlay */
11983 || pos
== pt_old
)))
11985 /* Estimate overlay buffer position from the buffer
11986 positions of the glyphs before and after the overlay.
11987 Add 1 to last_pos so that if point corresponds to the
11988 glyph right after the overlay, we still use a 'cursor'
11989 property found in that overlay. */
11990 cursor_from_overlay_pos
= (pos
? 0 : last_pos
11991 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
11995 x
+= glyph
->pixel_width
;
11998 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
12002 if (cursor
!= NULL
)
12007 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
12009 /* Scan back over the ellipsis glyphs, decrementing positions. */
12010 while (glyph
> row
->glyphs
[TEXT_AREA
]
12011 && (glyph
- 1)->charpos
== last_pos
)
12012 glyph
--, x
-= glyph
->pixel_width
;
12013 /* That loop always goes one position too far,
12014 including the glyph before the ellipsis.
12015 So scan forward over that one. */
12016 x
+= glyph
->pixel_width
;
12019 else if (string_start
12020 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
12022 /* We may have skipped over point because the previous glyphs
12023 are from string. As there's no easy way to know the
12024 character position of the current glyph, find the correct
12025 glyph on point by scanning from string_start again. */
12027 Lisp_Object string
;
12028 struct glyph
*stop
= glyph
;
12031 limit
= make_number (pt_old
+ 1);
12032 glyph
= string_start
;
12033 x
= string_start_x
;
12034 string
= glyph
->object
;
12035 pos
= string_buffer_position (w
, string
, string_before_pos
);
12036 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
12037 because we always put cursor after overlay strings. */
12038 while (pos
== 0 && glyph
< stop
)
12040 string
= glyph
->object
;
12041 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12043 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
12046 while (glyph
< stop
)
12048 pos
= XINT (Fnext_single_char_property_change
12049 (make_number (pos
), Qdisplay
, Qnil
, limit
));
12052 /* Skip glyphs from the same string. */
12053 string
= glyph
->object
;
12054 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12055 /* Skip glyphs from an overlay. */
12056 while (glyph
< stop
12057 && ! string_buffer_position (w
, glyph
->object
, pos
))
12059 string
= glyph
->object
;
12060 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12064 /* If we reached the end of the line, and end was from a string,
12065 cursor is not on this line. */
12066 if (glyph
== end
&& row
->continued_p
)
12070 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12072 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12073 w
->cursor
.y
= row
->y
+ dy
;
12075 if (w
== XWINDOW (selected_window
))
12077 if (!row
->continued_p
12078 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12081 this_line_buffer
= XBUFFER (w
->buffer
);
12083 CHARPOS (this_line_start_pos
)
12084 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12085 BYTEPOS (this_line_start_pos
)
12086 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12088 CHARPOS (this_line_end_pos
)
12089 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12090 BYTEPOS (this_line_end_pos
)
12091 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12093 this_line_y
= w
->cursor
.y
;
12094 this_line_pixel_height
= row
->height
;
12095 this_line_vpos
= w
->cursor
.vpos
;
12096 this_line_start_x
= row
->x
;
12099 CHARPOS (this_line_start_pos
) = 0;
12106 /* Run window scroll functions, if any, for WINDOW with new window
12107 start STARTP. Sets the window start of WINDOW to that position.
12109 We assume that the window's buffer is really current. */
12111 static INLINE
struct text_pos
12112 run_window_scroll_functions (window
, startp
)
12113 Lisp_Object window
;
12114 struct text_pos startp
;
12116 struct window
*w
= XWINDOW (window
);
12117 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12119 if (current_buffer
!= XBUFFER (w
->buffer
))
12122 if (!NILP (Vwindow_scroll_functions
))
12124 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12125 make_number (CHARPOS (startp
)));
12126 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12127 /* In case the hook functions switch buffers. */
12128 if (current_buffer
!= XBUFFER (w
->buffer
))
12129 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12136 /* Make sure the line containing the cursor is fully visible.
12137 A value of 1 means there is nothing to be done.
12138 (Either the line is fully visible, or it cannot be made so,
12139 or we cannot tell.)
12141 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12142 is higher than window.
12144 A value of 0 means the caller should do scrolling
12145 as if point had gone off the screen. */
12148 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12151 int current_matrix_p
;
12153 struct glyph_matrix
*matrix
;
12154 struct glyph_row
*row
;
12157 if (!make_cursor_line_fully_visible_p
)
12160 /* It's not always possible to find the cursor, e.g, when a window
12161 is full of overlay strings. Don't do anything in that case. */
12162 if (w
->cursor
.vpos
< 0)
12165 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12166 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12168 /* If the cursor row is not partially visible, there's nothing to do. */
12169 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12172 /* If the row the cursor is in is taller than the window's height,
12173 it's not clear what to do, so do nothing. */
12174 window_height
= window_box_height (w
);
12175 if (row
->height
>= window_height
)
12177 if (!force_p
|| MINI_WINDOW_P (w
)
12178 || w
->vscroll
|| w
->cursor
.vpos
== 0)
12184 /* This code used to try to scroll the window just enough to make
12185 the line visible. It returned 0 to say that the caller should
12186 allocate larger glyph matrices. */
12188 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
12190 int dy
= row
->height
- row
->visible_height
;
12193 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12195 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
12197 int dy
= - (row
->height
- row
->visible_height
);
12200 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12203 /* When we change the cursor y-position of the selected window,
12204 change this_line_y as well so that the display optimization for
12205 the cursor line of the selected window in redisplay_internal uses
12206 the correct y-position. */
12207 if (w
== XWINDOW (selected_window
))
12208 this_line_y
= w
->cursor
.y
;
12210 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
12211 redisplay with larger matrices. */
12212 if (matrix
->nrows
< required_matrix_height (w
))
12214 fonts_changed_p
= 1;
12223 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
12224 non-zero means only WINDOW is redisplayed in redisplay_internal.
12225 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
12226 in redisplay_window to bring a partially visible line into view in
12227 the case that only the cursor has moved.
12229 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
12230 last screen line's vertical height extends past the end of the screen.
12234 1 if scrolling succeeded
12236 0 if scrolling didn't find point.
12238 -1 if new fonts have been loaded so that we must interrupt
12239 redisplay, adjust glyph matrices, and try again. */
12245 SCROLLING_NEED_LARGER_MATRICES
12249 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
12250 scroll_step
, temp_scroll_step
, last_line_misfit
)
12251 Lisp_Object window
;
12252 int just_this_one_p
;
12253 EMACS_INT scroll_conservatively
, scroll_step
;
12254 int temp_scroll_step
;
12255 int last_line_misfit
;
12257 struct window
*w
= XWINDOW (window
);
12258 struct frame
*f
= XFRAME (w
->frame
);
12259 struct text_pos scroll_margin_pos
;
12260 struct text_pos pos
;
12261 struct text_pos startp
;
12263 Lisp_Object window_end
;
12264 int this_scroll_margin
;
12268 int amount_to_scroll
= 0;
12269 Lisp_Object aggressive
;
12271 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
12274 debug_method_add (w
, "try_scrolling");
12277 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12279 /* Compute scroll margin height in pixels. We scroll when point is
12280 within this distance from the top or bottom of the window. */
12281 if (scroll_margin
> 0)
12283 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12284 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12287 this_scroll_margin
= 0;
12289 /* Force scroll_conservatively to have a reasonable value so it doesn't
12290 cause an overflow while computing how much to scroll. */
12291 if (scroll_conservatively
)
12292 scroll_conservatively
= min (scroll_conservatively
,
12293 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
12295 /* Compute how much we should try to scroll maximally to bring point
12297 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
12298 scroll_max
= max (scroll_step
,
12299 max (scroll_conservatively
, temp_scroll_step
));
12300 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
12301 || NUMBERP (current_buffer
->scroll_up_aggressively
))
12302 /* We're trying to scroll because of aggressive scrolling
12303 but no scroll_step is set. Choose an arbitrary one. Maybe
12304 there should be a variable for this. */
12308 scroll_max
*= FRAME_LINE_HEIGHT (f
);
12310 /* Decide whether we have to scroll down. Start at the window end
12311 and move this_scroll_margin up to find the position of the scroll
12313 window_end
= Fwindow_end (window
, Qt
);
12317 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
12318 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
12320 if (this_scroll_margin
|| extra_scroll_margin_lines
)
12322 start_display (&it
, w
, scroll_margin_pos
);
12323 if (this_scroll_margin
)
12324 move_it_vertically_backward (&it
, this_scroll_margin
);
12325 if (extra_scroll_margin_lines
)
12326 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
12327 scroll_margin_pos
= it
.current
.pos
;
12330 if (PT
>= CHARPOS (scroll_margin_pos
))
12334 /* Point is in the scroll margin at the bottom of the window, or
12335 below. Compute a new window start that makes point visible. */
12337 /* Compute the distance from the scroll margin to PT.
12338 Give up if the distance is greater than scroll_max. */
12339 start_display (&it
, w
, scroll_margin_pos
);
12341 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12342 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12344 /* To make point visible, we have to move the window start
12345 down so that the line the cursor is in is visible, which
12346 means we have to add in the height of the cursor line. */
12347 dy
= line_bottom_y (&it
) - y0
;
12349 if (dy
> scroll_max
)
12350 return SCROLLING_FAILED
;
12352 /* Move the window start down. If scrolling conservatively,
12353 move it just enough down to make point visible. If
12354 scroll_step is set, move it down by scroll_step. */
12355 start_display (&it
, w
, startp
);
12357 if (scroll_conservatively
)
12358 /* Set AMOUNT_TO_SCROLL to at least one line,
12359 and at most scroll_conservatively lines. */
12361 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12362 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12363 else if (scroll_step
|| temp_scroll_step
)
12364 amount_to_scroll
= scroll_max
;
12367 aggressive
= current_buffer
->scroll_up_aggressively
;
12368 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12369 if (NUMBERP (aggressive
))
12371 double float_amount
= XFLOATINT (aggressive
) * height
;
12372 amount_to_scroll
= float_amount
;
12373 if (amount_to_scroll
== 0 && float_amount
> 0)
12374 amount_to_scroll
= 1;
12378 if (amount_to_scroll
<= 0)
12379 return SCROLLING_FAILED
;
12381 /* If moving by amount_to_scroll leaves STARTP unchanged,
12382 move it down one screen line. */
12384 move_it_vertically (&it
, amount_to_scroll
);
12385 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12386 move_it_by_lines (&it
, 1, 1);
12387 startp
= it
.current
.pos
;
12391 /* See if point is inside the scroll margin at the top of the
12393 scroll_margin_pos
= startp
;
12394 if (this_scroll_margin
)
12396 start_display (&it
, w
, startp
);
12397 move_it_vertically (&it
, this_scroll_margin
);
12398 scroll_margin_pos
= it
.current
.pos
;
12401 if (PT
< CHARPOS (scroll_margin_pos
))
12403 /* Point is in the scroll margin at the top of the window or
12404 above what is displayed in the window. */
12407 /* Compute the vertical distance from PT to the scroll
12408 margin position. Give up if distance is greater than
12410 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12411 start_display (&it
, w
, pos
);
12413 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12414 it
.last_visible_y
, -1,
12415 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12416 dy
= it
.current_y
- y0
;
12417 if (dy
> scroll_max
)
12418 return SCROLLING_FAILED
;
12420 /* Compute new window start. */
12421 start_display (&it
, w
, startp
);
12423 if (scroll_conservatively
)
12425 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12426 else if (scroll_step
|| temp_scroll_step
)
12427 amount_to_scroll
= scroll_max
;
12430 aggressive
= current_buffer
->scroll_down_aggressively
;
12431 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12432 if (NUMBERP (aggressive
))
12434 double float_amount
= XFLOATINT (aggressive
) * height
;
12435 amount_to_scroll
= float_amount
;
12436 if (amount_to_scroll
== 0 && float_amount
> 0)
12437 amount_to_scroll
= 1;
12441 if (amount_to_scroll
<= 0)
12442 return SCROLLING_FAILED
;
12444 move_it_vertically_backward (&it
, amount_to_scroll
);
12445 startp
= it
.current
.pos
;
12449 /* Run window scroll functions. */
12450 startp
= run_window_scroll_functions (window
, startp
);
12452 /* Display the window. Give up if new fonts are loaded, or if point
12454 if (!try_window (window
, startp
, 0))
12455 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12456 else if (w
->cursor
.vpos
< 0)
12458 clear_glyph_matrix (w
->desired_matrix
);
12459 rc
= SCROLLING_FAILED
;
12463 /* Maybe forget recorded base line for line number display. */
12464 if (!just_this_one_p
12465 || current_buffer
->clip_changed
12466 || BEG_UNCHANGED
< CHARPOS (startp
))
12467 w
->base_line_number
= Qnil
;
12469 /* If cursor ends up on a partially visible line,
12470 treat that as being off the bottom of the screen. */
12471 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12473 clear_glyph_matrix (w
->desired_matrix
);
12474 ++extra_scroll_margin_lines
;
12477 rc
= SCROLLING_SUCCESS
;
12484 /* Compute a suitable window start for window W if display of W starts
12485 on a continuation line. Value is non-zero if a new window start
12488 The new window start will be computed, based on W's width, starting
12489 from the start of the continued line. It is the start of the
12490 screen line with the minimum distance from the old start W->start. */
12493 compute_window_start_on_continuation_line (w
)
12496 struct text_pos pos
, start_pos
;
12497 int window_start_changed_p
= 0;
12499 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12501 /* If window start is on a continuation line... Window start may be
12502 < BEGV in case there's invisible text at the start of the
12503 buffer (M-x rmail, for example). */
12504 if (CHARPOS (start_pos
) > BEGV
12505 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12508 struct glyph_row
*row
;
12510 /* Handle the case that the window start is out of range. */
12511 if (CHARPOS (start_pos
) < BEGV
)
12512 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12513 else if (CHARPOS (start_pos
) > ZV
)
12514 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12516 /* Find the start of the continued line. This should be fast
12517 because scan_buffer is fast (newline cache). */
12518 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12519 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12520 row
, DEFAULT_FACE_ID
);
12521 reseat_at_previous_visible_line_start (&it
);
12523 /* If the line start is "too far" away from the window start,
12524 say it takes too much time to compute a new window start. */
12525 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12526 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12528 int min_distance
, distance
;
12530 /* Move forward by display lines to find the new window
12531 start. If window width was enlarged, the new start can
12532 be expected to be > the old start. If window width was
12533 decreased, the new window start will be < the old start.
12534 So, we're looking for the display line start with the
12535 minimum distance from the old window start. */
12536 pos
= it
.current
.pos
;
12537 min_distance
= INFINITY
;
12538 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12539 distance
< min_distance
)
12541 min_distance
= distance
;
12542 pos
= it
.current
.pos
;
12543 move_it_by_lines (&it
, 1, 0);
12546 /* Set the window start there. */
12547 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12548 window_start_changed_p
= 1;
12552 return window_start_changed_p
;
12556 /* Try cursor movement in case text has not changed in window WINDOW,
12557 with window start STARTP. Value is
12559 CURSOR_MOVEMENT_SUCCESS if successful
12561 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12563 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12564 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12565 we want to scroll as if scroll-step were set to 1. See the code.
12567 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12568 which case we have to abort this redisplay, and adjust matrices
12573 CURSOR_MOVEMENT_SUCCESS
,
12574 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12575 CURSOR_MOVEMENT_MUST_SCROLL
,
12576 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12580 try_cursor_movement (window
, startp
, scroll_step
)
12581 Lisp_Object window
;
12582 struct text_pos startp
;
12585 struct window
*w
= XWINDOW (window
);
12586 struct frame
*f
= XFRAME (w
->frame
);
12587 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12590 if (inhibit_try_cursor_movement
)
12594 /* Handle case where text has not changed, only point, and it has
12595 not moved off the frame. */
12596 if (/* Point may be in this window. */
12597 PT
>= CHARPOS (startp
)
12598 /* Selective display hasn't changed. */
12599 && !current_buffer
->clip_changed
12600 /* Function force-mode-line-update is used to force a thorough
12601 redisplay. It sets either windows_or_buffers_changed or
12602 update_mode_lines. So don't take a shortcut here for these
12604 && !update_mode_lines
12605 && !windows_or_buffers_changed
12606 && !cursor_type_changed
12607 /* Can't use this case if highlighting a region. When a
12608 region exists, cursor movement has to do more than just
12610 && !(!NILP (Vtransient_mark_mode
)
12611 && !NILP (current_buffer
->mark_active
))
12612 && NILP (w
->region_showing
)
12613 && NILP (Vshow_trailing_whitespace
)
12614 /* Right after splitting windows, last_point may be nil. */
12615 && INTEGERP (w
->last_point
)
12616 /* This code is not used for mini-buffer for the sake of the case
12617 of redisplaying to replace an echo area message; since in
12618 that case the mini-buffer contents per se are usually
12619 unchanged. This code is of no real use in the mini-buffer
12620 since the handling of this_line_start_pos, etc., in redisplay
12621 handles the same cases. */
12622 && !EQ (window
, minibuf_window
)
12623 /* When splitting windows or for new windows, it happens that
12624 redisplay is called with a nil window_end_vpos or one being
12625 larger than the window. This should really be fixed in
12626 window.c. I don't have this on my list, now, so we do
12627 approximately the same as the old redisplay code. --gerd. */
12628 && INTEGERP (w
->window_end_vpos
)
12629 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12630 && (FRAME_WINDOW_P (f
)
12631 || !overlay_arrow_in_current_buffer_p ()))
12633 int this_scroll_margin
, top_scroll_margin
;
12634 struct glyph_row
*row
= NULL
;
12637 debug_method_add (w
, "cursor movement");
12640 /* Scroll if point within this distance from the top or bottom
12641 of the window. This is a pixel value. */
12642 this_scroll_margin
= max (0, scroll_margin
);
12643 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12644 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12646 top_scroll_margin
= this_scroll_margin
;
12647 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12648 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12650 /* Start with the row the cursor was displayed during the last
12651 not paused redisplay. Give up if that row is not valid. */
12652 if (w
->last_cursor
.vpos
< 0
12653 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12654 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12657 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12658 if (row
->mode_line_p
)
12660 if (!row
->enabled_p
)
12661 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12664 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12667 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12669 if (PT
> XFASTINT (w
->last_point
))
12671 /* Point has moved forward. */
12672 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12673 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12675 xassert (row
->enabled_p
);
12679 /* The end position of a row equals the start position
12680 of the next row. If PT is there, we would rather
12681 display it in the next line. */
12682 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12683 && MATRIX_ROW_END_CHARPOS (row
) == PT
12684 && !cursor_row_p (w
, row
))
12687 /* If within the scroll margin, scroll. Note that
12688 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
12689 the next line would be drawn, and that
12690 this_scroll_margin can be zero. */
12691 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
12692 || PT
> MATRIX_ROW_END_CHARPOS (row
)
12693 /* Line is completely visible last line in window
12694 and PT is to be set in the next line. */
12695 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
12696 && PT
== MATRIX_ROW_END_CHARPOS (row
)
12697 && !row
->ends_at_zv_p
12698 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12701 else if (PT
< XFASTINT (w
->last_point
))
12703 /* Cursor has to be moved backward. Note that PT >=
12704 CHARPOS (startp) because of the outer if-statement. */
12705 while (!row
->mode_line_p
12706 && (MATRIX_ROW_START_CHARPOS (row
) > PT
12707 || (MATRIX_ROW_START_CHARPOS (row
) == PT
12708 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
12709 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
12710 row
> w
->current_matrix
->rows
12711 && (row
-1)->ends_in_newline_from_string_p
))))
12712 && (row
->y
> top_scroll_margin
12713 || CHARPOS (startp
) == BEGV
))
12715 xassert (row
->enabled_p
);
12719 /* Consider the following case: Window starts at BEGV,
12720 there is invisible, intangible text at BEGV, so that
12721 display starts at some point START > BEGV. It can
12722 happen that we are called with PT somewhere between
12723 BEGV and START. Try to handle that case. */
12724 if (row
< w
->current_matrix
->rows
12725 || row
->mode_line_p
)
12727 row
= w
->current_matrix
->rows
;
12728 if (row
->mode_line_p
)
12732 /* Due to newlines in overlay strings, we may have to
12733 skip forward over overlay strings. */
12734 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12735 && MATRIX_ROW_END_CHARPOS (row
) == PT
12736 && !cursor_row_p (w
, row
))
12739 /* If within the scroll margin, scroll. */
12740 if (row
->y
< top_scroll_margin
12741 && CHARPOS (startp
) != BEGV
)
12746 /* Cursor did not move. So don't scroll even if cursor line
12747 is partially visible, as it was so before. */
12748 rc
= CURSOR_MOVEMENT_SUCCESS
;
12751 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
12752 || PT
> MATRIX_ROW_END_CHARPOS (row
))
12754 /* if PT is not in the glyph row, give up. */
12755 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12757 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
12758 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
12759 && make_cursor_line_fully_visible_p
)
12761 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
12762 && !row
->ends_at_zv_p
12763 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12764 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12765 else if (row
->height
> window_box_height (w
))
12767 /* If we end up in a partially visible line, let's
12768 make it fully visible, except when it's taller
12769 than the window, in which case we can't do much
12772 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12776 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12777 if (!cursor_row_fully_visible_p (w
, 0, 1))
12778 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12780 rc
= CURSOR_MOVEMENT_SUCCESS
;
12784 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12789 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
12791 rc
= CURSOR_MOVEMENT_SUCCESS
;
12796 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12797 && MATRIX_ROW_START_CHARPOS (row
) == PT
12798 && cursor_row_p (w
, row
));
12807 set_vertical_scroll_bar (w
)
12810 int start
, end
, whole
;
12812 /* Calculate the start and end positions for the current window.
12813 At some point, it would be nice to choose between scrollbars
12814 which reflect the whole buffer size, with special markers
12815 indicating narrowing, and scrollbars which reflect only the
12818 Note that mini-buffers sometimes aren't displaying any text. */
12819 if (!MINI_WINDOW_P (w
)
12820 || (w
== XWINDOW (minibuf_window
)
12821 && NILP (echo_area_buffer
[0])))
12823 struct buffer
*buf
= XBUFFER (w
->buffer
);
12824 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12825 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12826 /* I don't think this is guaranteed to be right. For the
12827 moment, we'll pretend it is. */
12828 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12832 if (whole
< (end
- start
))
12833 whole
= end
- start
;
12836 start
= end
= whole
= 0;
12838 /* Indicate what this scroll bar ought to be displaying now. */
12839 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
12840 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
12841 (w
, end
- start
, whole
, start
);
12845 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
12846 selected_window is redisplayed.
12848 We can return without actually redisplaying the window if
12849 fonts_changed_p is nonzero. In that case, redisplay_internal will
12853 redisplay_window (window
, just_this_one_p
)
12854 Lisp_Object window
;
12855 int just_this_one_p
;
12857 struct window
*w
= XWINDOW (window
);
12858 struct frame
*f
= XFRAME (w
->frame
);
12859 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12860 struct buffer
*old
= current_buffer
;
12861 struct text_pos lpoint
, opoint
, startp
;
12862 int update_mode_line
;
12865 /* Record it now because it's overwritten. */
12866 int current_matrix_up_to_date_p
= 0;
12867 int used_current_matrix_p
= 0;
12868 /* This is less strict than current_matrix_up_to_date_p.
12869 It indictes that the buffer contents and narrowing are unchanged. */
12870 int buffer_unchanged_p
= 0;
12871 int temp_scroll_step
= 0;
12872 int count
= SPECPDL_INDEX ();
12874 int centering_position
= -1;
12875 int last_line_misfit
= 0;
12876 int beg_unchanged
, end_unchanged
;
12878 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12881 /* W must be a leaf window here. */
12882 xassert (!NILP (w
->buffer
));
12884 *w
->desired_matrix
->method
= 0;
12887 specbind (Qinhibit_point_motion_hooks
, Qt
);
12889 reconsider_clip_changes (w
, buffer
);
12891 /* Has the mode line to be updated? */
12892 update_mode_line
= (!NILP (w
->update_mode_line
)
12893 || update_mode_lines
12894 || buffer
->clip_changed
12895 || buffer
->prevent_redisplay_optimizations_p
);
12897 if (MINI_WINDOW_P (w
))
12899 if (w
== XWINDOW (echo_area_window
)
12900 && !NILP (echo_area_buffer
[0]))
12902 if (update_mode_line
)
12903 /* We may have to update a tty frame's menu bar or a
12904 tool-bar. Example `M-x C-h C-h C-g'. */
12905 goto finish_menu_bars
;
12907 /* We've already displayed the echo area glyphs in this window. */
12908 goto finish_scroll_bars
;
12910 else if ((w
!= XWINDOW (minibuf_window
)
12911 || minibuf_level
== 0)
12912 /* When buffer is nonempty, redisplay window normally. */
12913 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12914 /* Quail displays non-mini buffers in minibuffer window.
12915 In that case, redisplay the window normally. */
12916 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12918 /* W is a mini-buffer window, but it's not active, so clear
12920 int yb
= window_text_bottom_y (w
);
12921 struct glyph_row
*row
;
12924 for (y
= 0, row
= w
->desired_matrix
->rows
;
12926 y
+= row
->height
, ++row
)
12927 blank_row (w
, row
, y
);
12928 goto finish_scroll_bars
;
12931 clear_glyph_matrix (w
->desired_matrix
);
12934 /* Otherwise set up data on this window; select its buffer and point
12936 /* Really select the buffer, for the sake of buffer-local
12938 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12939 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12941 beg_unchanged
= BEG_UNCHANGED
;
12942 end_unchanged
= END_UNCHANGED
;
12944 current_matrix_up_to_date_p
12945 = (!NILP (w
->window_end_valid
)
12946 && !current_buffer
->clip_changed
12947 && !current_buffer
->prevent_redisplay_optimizations_p
12948 && XFASTINT (w
->last_modified
) >= MODIFF
12949 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12952 = (!NILP (w
->window_end_valid
)
12953 && !current_buffer
->clip_changed
12954 && XFASTINT (w
->last_modified
) >= MODIFF
12955 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12957 /* When windows_or_buffers_changed is non-zero, we can't rely on
12958 the window end being valid, so set it to nil there. */
12959 if (windows_or_buffers_changed
)
12961 /* If window starts on a continuation line, maybe adjust the
12962 window start in case the window's width changed. */
12963 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12964 compute_window_start_on_continuation_line (w
);
12966 w
->window_end_valid
= Qnil
;
12969 /* Some sanity checks. */
12970 CHECK_WINDOW_END (w
);
12971 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12973 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12976 /* If %c is in mode line, update it if needed. */
12977 if (!NILP (w
->column_number_displayed
)
12978 /* This alternative quickly identifies a common case
12979 where no change is needed. */
12980 && !(PT
== XFASTINT (w
->last_point
)
12981 && XFASTINT (w
->last_modified
) >= MODIFF
12982 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12983 && (XFASTINT (w
->column_number_displayed
)
12984 != (int) current_column ())) /* iftc */
12985 update_mode_line
= 1;
12987 /* Count number of windows showing the selected buffer. An indirect
12988 buffer counts as its base buffer. */
12989 if (!just_this_one_p
)
12991 struct buffer
*current_base
, *window_base
;
12992 current_base
= current_buffer
;
12993 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12994 if (current_base
->base_buffer
)
12995 current_base
= current_base
->base_buffer
;
12996 if (window_base
->base_buffer
)
12997 window_base
= window_base
->base_buffer
;
12998 if (current_base
== window_base
)
13002 /* Point refers normally to the selected window. For any other
13003 window, set up appropriate value. */
13004 if (!EQ (window
, selected_window
))
13006 int new_pt
= XMARKER (w
->pointm
)->charpos
;
13007 int new_pt_byte
= marker_byte_position (w
->pointm
);
13011 new_pt_byte
= BEGV_BYTE
;
13012 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13014 else if (new_pt
> (ZV
- 1))
13017 new_pt_byte
= ZV_BYTE
;
13018 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13021 /* We don't use SET_PT so that the point-motion hooks don't run. */
13022 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
13025 /* If any of the character widths specified in the display table
13026 have changed, invalidate the width run cache. It's true that
13027 this may be a bit late to catch such changes, but the rest of
13028 redisplay goes (non-fatally) haywire when the display table is
13029 changed, so why should we worry about doing any better? */
13030 if (current_buffer
->width_run_cache
)
13032 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
13034 if (! disptab_matches_widthtab (disptab
,
13035 XVECTOR (current_buffer
->width_table
)))
13037 invalidate_region_cache (current_buffer
,
13038 current_buffer
->width_run_cache
,
13040 recompute_width_table (current_buffer
, disptab
);
13044 /* If window-start is screwed up, choose a new one. */
13045 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
13048 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13050 /* If someone specified a new starting point but did not insist,
13051 check whether it can be used. */
13052 if (!NILP (w
->optional_new_start
)
13053 && CHARPOS (startp
) >= BEGV
13054 && CHARPOS (startp
) <= ZV
)
13056 w
->optional_new_start
= Qnil
;
13057 start_display (&it
, w
, startp
);
13058 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
13059 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13060 if (IT_CHARPOS (it
) == PT
)
13061 w
->force_start
= Qt
;
13062 /* IT may overshoot PT if text at PT is invisible. */
13063 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
13064 w
->force_start
= Qt
;
13069 /* Handle case where place to start displaying has been specified,
13070 unless the specified location is outside the accessible range. */
13071 if (!NILP (w
->force_start
)
13072 || w
->frozen_window_start_p
)
13074 /* We set this later on if we have to adjust point. */
13078 w
->force_start
= Qnil
;
13080 w
->window_end_valid
= Qnil
;
13082 /* Forget any recorded base line for line number display. */
13083 if (!buffer_unchanged_p
)
13084 w
->base_line_number
= Qnil
;
13086 /* Redisplay the mode line. Select the buffer properly for that.
13087 Also, run the hook window-scroll-functions
13088 because we have scrolled. */
13089 /* Note, we do this after clearing force_start because
13090 if there's an error, it is better to forget about force_start
13091 than to get into an infinite loop calling the hook functions
13092 and having them get more errors. */
13093 if (!update_mode_line
13094 || ! NILP (Vwindow_scroll_functions
))
13096 update_mode_line
= 1;
13097 w
->update_mode_line
= Qt
;
13098 startp
= run_window_scroll_functions (window
, startp
);
13101 w
->last_modified
= make_number (0);
13102 w
->last_overlay_modified
= make_number (0);
13103 if (CHARPOS (startp
) < BEGV
)
13104 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
13105 else if (CHARPOS (startp
) > ZV
)
13106 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
13108 /* Redisplay, then check if cursor has been set during the
13109 redisplay. Give up if new fonts were loaded. */
13110 val
= try_window (window
, startp
, 1);
13113 w
->force_start
= Qt
;
13114 clear_glyph_matrix (w
->desired_matrix
);
13115 goto need_larger_matrices
;
13117 /* Point was outside the scroll margins. */
13119 new_vpos
= window_box_height (w
) / 2;
13121 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
13123 /* If point does not appear, try to move point so it does
13124 appear. The desired matrix has been built above, so we
13125 can use it here. */
13126 new_vpos
= window_box_height (w
) / 2;
13129 if (!cursor_row_fully_visible_p (w
, 0, 0))
13131 /* Point does appear, but on a line partly visible at end of window.
13132 Move it back to a fully-visible line. */
13133 new_vpos
= window_box_height (w
);
13136 /* If we need to move point for either of the above reasons,
13137 now actually do it. */
13140 struct glyph_row
*row
;
13142 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13143 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13146 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13147 MATRIX_ROW_START_BYTEPOS (row
));
13149 if (w
!= XWINDOW (selected_window
))
13150 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13151 else if (current_buffer
== old
)
13152 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13154 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13156 /* If we are highlighting the region, then we just changed
13157 the region, so redisplay to show it. */
13158 if (!NILP (Vtransient_mark_mode
)
13159 && !NILP (current_buffer
->mark_active
))
13161 clear_glyph_matrix (w
->desired_matrix
);
13162 if (!try_window (window
, startp
, 0))
13163 goto need_larger_matrices
;
13168 debug_method_add (w
, "forced window start");
13173 /* Handle case where text has not changed, only point, and it has
13174 not moved off the frame, and we are not retrying after hscroll.
13175 (current_matrix_up_to_date_p is nonzero when retrying.) */
13176 if (current_matrix_up_to_date_p
13177 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13178 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13182 case CURSOR_MOVEMENT_SUCCESS
:
13183 used_current_matrix_p
= 1;
13186 #if 0 /* try_cursor_movement never returns this value. */
13187 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
13188 goto need_larger_matrices
;
13191 case CURSOR_MOVEMENT_MUST_SCROLL
:
13192 goto try_to_scroll
;
13198 /* If current starting point was originally the beginning of a line
13199 but no longer is, find a new starting point. */
13200 else if (!NILP (w
->start_at_line_beg
)
13201 && !(CHARPOS (startp
) <= BEGV
13202 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13205 debug_method_add (w
, "recenter 1");
13210 /* Try scrolling with try_window_id. Value is > 0 if update has
13211 been done, it is -1 if we know that the same window start will
13212 not work. It is 0 if unsuccessful for some other reason. */
13213 else if ((tem
= try_window_id (w
)) != 0)
13216 debug_method_add (w
, "try_window_id %d", tem
);
13219 if (fonts_changed_p
)
13220 goto need_larger_matrices
;
13224 /* Otherwise try_window_id has returned -1 which means that we
13225 don't want the alternative below this comment to execute. */
13227 else if (CHARPOS (startp
) >= BEGV
13228 && CHARPOS (startp
) <= ZV
13229 && PT
>= CHARPOS (startp
)
13230 && (CHARPOS (startp
) < ZV
13231 /* Avoid starting at end of buffer. */
13232 || CHARPOS (startp
) == BEGV
13233 || (XFASTINT (w
->last_modified
) >= MODIFF
13234 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
13237 /* If first window line is a continuation line, and window start
13238 is inside the modified region, but the first change is before
13239 current window start, we must select a new window start.
13241 However, if this is the result of a down-mouse event (e.g. by
13242 extending the mouse-drag-overlay), we don't want to select a
13243 new window start, since that would change the position under
13244 the mouse, resulting in an unwanted mouse-movement rather
13245 than a simple mouse-click. */
13246 if (NILP (w
->start_at_line_beg
)
13247 && NILP (do_mouse_tracking
)
13248 && CHARPOS (startp
) > BEGV
13249 && CHARPOS (startp
) > BEG
+ beg_unchanged
13250 && CHARPOS (startp
) <= Z
- end_unchanged
)
13252 w
->force_start
= Qt
;
13253 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13254 compute_window_start_on_continuation_line (w
);
13255 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13260 debug_method_add (w
, "same window start");
13263 /* Try to redisplay starting at same place as before.
13264 If point has not moved off frame, accept the results. */
13265 if (!current_matrix_up_to_date_p
13266 /* Don't use try_window_reusing_current_matrix in this case
13267 because a window scroll function can have changed the
13269 || !NILP (Vwindow_scroll_functions
)
13270 || MINI_WINDOW_P (w
)
13271 || !(used_current_matrix_p
13272 = try_window_reusing_current_matrix (w
)))
13274 IF_DEBUG (debug_method_add (w
, "1"));
13275 if (try_window (window
, startp
, 1) < 0)
13276 /* -1 means we need to scroll.
13277 0 means we need new matrices, but fonts_changed_p
13278 is set in that case, so we will detect it below. */
13279 goto try_to_scroll
;
13282 if (fonts_changed_p
)
13283 goto need_larger_matrices
;
13285 if (w
->cursor
.vpos
>= 0)
13287 if (!just_this_one_p
13288 || current_buffer
->clip_changed
13289 || BEG_UNCHANGED
< CHARPOS (startp
))
13290 /* Forget any recorded base line for line number display. */
13291 w
->base_line_number
= Qnil
;
13293 if (!cursor_row_fully_visible_p (w
, 1, 0))
13295 clear_glyph_matrix (w
->desired_matrix
);
13296 last_line_misfit
= 1;
13298 /* Drop through and scroll. */
13303 clear_glyph_matrix (w
->desired_matrix
);
13308 w
->last_modified
= make_number (0);
13309 w
->last_overlay_modified
= make_number (0);
13311 /* Redisplay the mode line. Select the buffer properly for that. */
13312 if (!update_mode_line
)
13314 update_mode_line
= 1;
13315 w
->update_mode_line
= Qt
;
13318 /* Try to scroll by specified few lines. */
13319 if ((scroll_conservatively
13321 || temp_scroll_step
13322 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13323 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13324 && !current_buffer
->clip_changed
13325 && CHARPOS (startp
) >= BEGV
13326 && CHARPOS (startp
) <= ZV
)
13328 /* The function returns -1 if new fonts were loaded, 1 if
13329 successful, 0 if not successful. */
13330 int rc
= try_scrolling (window
, just_this_one_p
,
13331 scroll_conservatively
,
13333 temp_scroll_step
, last_line_misfit
);
13336 case SCROLLING_SUCCESS
:
13339 case SCROLLING_NEED_LARGER_MATRICES
:
13340 goto need_larger_matrices
;
13342 case SCROLLING_FAILED
:
13350 /* Finally, just choose place to start which centers point */
13353 if (centering_position
< 0)
13354 centering_position
= window_box_height (w
) / 2;
13357 debug_method_add (w
, "recenter");
13360 /* w->vscroll = 0; */
13362 /* Forget any previously recorded base line for line number display. */
13363 if (!buffer_unchanged_p
)
13364 w
->base_line_number
= Qnil
;
13366 /* Move backward half the height of the window. */
13367 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13368 it
.current_y
= it
.last_visible_y
;
13369 move_it_vertically_backward (&it
, centering_position
);
13370 xassert (IT_CHARPOS (it
) >= BEGV
);
13372 /* The function move_it_vertically_backward may move over more
13373 than the specified y-distance. If it->w is small, e.g. a
13374 mini-buffer window, we may end up in front of the window's
13375 display area. Start displaying at the start of the line
13376 containing PT in this case. */
13377 if (it
.current_y
<= 0)
13379 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13380 move_it_vertically_backward (&it
, 0);
13382 /* I think this assert is bogus if buffer contains
13383 invisible text or images. KFS. */
13384 xassert (IT_CHARPOS (it
) <= PT
);
13389 it
.current_x
= it
.hpos
= 0;
13391 /* Set startp here explicitly in case that helps avoid an infinite loop
13392 in case the window-scroll-functions functions get errors. */
13393 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13395 /* Run scroll hooks. */
13396 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13398 /* Redisplay the window. */
13399 if (!current_matrix_up_to_date_p
13400 || windows_or_buffers_changed
13401 || cursor_type_changed
13402 /* Don't use try_window_reusing_current_matrix in this case
13403 because it can have changed the buffer. */
13404 || !NILP (Vwindow_scroll_functions
)
13405 || !just_this_one_p
13406 || MINI_WINDOW_P (w
)
13407 || !(used_current_matrix_p
13408 = try_window_reusing_current_matrix (w
)))
13409 try_window (window
, startp
, 0);
13411 /* If new fonts have been loaded (due to fontsets), give up. We
13412 have to start a new redisplay since we need to re-adjust glyph
13414 if (fonts_changed_p
)
13415 goto need_larger_matrices
;
13417 /* If cursor did not appear assume that the middle of the window is
13418 in the first line of the window. Do it again with the next line.
13419 (Imagine a window of height 100, displaying two lines of height
13420 60. Moving back 50 from it->last_visible_y will end in the first
13422 if (w
->cursor
.vpos
< 0)
13424 if (!NILP (w
->window_end_valid
)
13425 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13427 clear_glyph_matrix (w
->desired_matrix
);
13428 move_it_by_lines (&it
, 1, 0);
13429 try_window (window
, it
.current
.pos
, 0);
13431 else if (PT
< IT_CHARPOS (it
))
13433 clear_glyph_matrix (w
->desired_matrix
);
13434 move_it_by_lines (&it
, -1, 0);
13435 try_window (window
, it
.current
.pos
, 0);
13439 /* Not much we can do about it. */
13443 /* Consider the following case: Window starts at BEGV, there is
13444 invisible, intangible text at BEGV, so that display starts at
13445 some point START > BEGV. It can happen that we are called with
13446 PT somewhere between BEGV and START. Try to handle that case. */
13447 if (w
->cursor
.vpos
< 0)
13449 struct glyph_row
*row
= w
->current_matrix
->rows
;
13450 if (row
->mode_line_p
)
13452 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13455 if (!cursor_row_fully_visible_p (w
, 0, 0))
13457 /* If vscroll is enabled, disable it and try again. */
13461 clear_glyph_matrix (w
->desired_matrix
);
13465 /* If centering point failed to make the whole line visible,
13466 put point at the top instead. That has to make the whole line
13467 visible, if it can be done. */
13468 if (centering_position
== 0)
13471 clear_glyph_matrix (w
->desired_matrix
);
13472 centering_position
= 0;
13478 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13479 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13480 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13483 /* Display the mode line, if we must. */
13484 if ((update_mode_line
13485 /* If window not full width, must redo its mode line
13486 if (a) the window to its side is being redone and
13487 (b) we do a frame-based redisplay. This is a consequence
13488 of how inverted lines are drawn in frame-based redisplay. */
13489 || (!just_this_one_p
13490 && !FRAME_WINDOW_P (f
)
13491 && !WINDOW_FULL_WIDTH_P (w
))
13492 /* Line number to display. */
13493 || INTEGERP (w
->base_line_pos
)
13494 /* Column number is displayed and different from the one displayed. */
13495 || (!NILP (w
->column_number_displayed
)
13496 && (XFASTINT (w
->column_number_displayed
)
13497 != (int) current_column ()))) /* iftc */
13498 /* This means that the window has a mode line. */
13499 && (WINDOW_WANTS_MODELINE_P (w
)
13500 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13502 display_mode_lines (w
);
13504 /* If mode line height has changed, arrange for a thorough
13505 immediate redisplay using the correct mode line height. */
13506 if (WINDOW_WANTS_MODELINE_P (w
)
13507 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13509 fonts_changed_p
= 1;
13510 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13511 = DESIRED_MODE_LINE_HEIGHT (w
);
13514 /* If top line height has changed, arrange for a thorough
13515 immediate redisplay using the correct mode line height. */
13516 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13517 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13519 fonts_changed_p
= 1;
13520 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13521 = DESIRED_HEADER_LINE_HEIGHT (w
);
13524 if (fonts_changed_p
)
13525 goto need_larger_matrices
;
13528 if (!line_number_displayed
13529 && !BUFFERP (w
->base_line_pos
))
13531 w
->base_line_pos
= Qnil
;
13532 w
->base_line_number
= Qnil
;
13537 /* When we reach a frame's selected window, redo the frame's menu bar. */
13538 if (update_mode_line
13539 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13541 int redisplay_menu_p
= 0;
13542 int redisplay_tool_bar_p
= 0;
13544 if (FRAME_WINDOW_P (f
))
13546 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
13547 || defined (USE_GTK)
13548 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13550 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13554 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13556 if (redisplay_menu_p
)
13557 display_menu_bar (w
);
13559 #ifdef HAVE_WINDOW_SYSTEM
13560 if (FRAME_WINDOW_P (f
))
13562 #if defined (USE_GTK) || USE_MAC_TOOLBAR
13563 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13565 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13566 && (FRAME_TOOL_BAR_LINES (f
) > 0
13567 || !NILP (Vauto_resize_tool_bars
));
13570 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
13572 extern int ignore_mouse_drag_p
;
13573 ignore_mouse_drag_p
= 1;
13579 #ifdef HAVE_WINDOW_SYSTEM
13580 if (FRAME_WINDOW_P (f
)
13581 && update_window_fringes (w
, (just_this_one_p
13582 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13583 || w
->pseudo_window_p
)))
13587 if (draw_window_fringes (w
, 1))
13588 x_draw_vertical_border (w
);
13592 #endif /* HAVE_WINDOW_SYSTEM */
13594 /* We go to this label, with fonts_changed_p nonzero,
13595 if it is necessary to try again using larger glyph matrices.
13596 We have to redeem the scroll bar even in this case,
13597 because the loop in redisplay_internal expects that. */
13598 need_larger_matrices
:
13600 finish_scroll_bars
:
13602 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13604 /* Set the thumb's position and size. */
13605 set_vertical_scroll_bar (w
);
13607 /* Note that we actually used the scroll bar attached to this
13608 window, so it shouldn't be deleted at the end of redisplay. */
13609 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
13610 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
13613 /* Restore current_buffer and value of point in it. */
13614 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13615 set_buffer_internal_1 (old
);
13616 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
13617 shorter. This can be caused by log truncation in *Messages*. */
13618 if (CHARPOS (lpoint
) <= ZV
)
13619 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13621 unbind_to (count
, Qnil
);
13625 /* Build the complete desired matrix of WINDOW with a window start
13626 buffer position POS.
13628 Value is 1 if successful. It is zero if fonts were loaded during
13629 redisplay which makes re-adjusting glyph matrices necessary, and -1
13630 if point would appear in the scroll margins.
13631 (We check that only if CHECK_MARGINS is nonzero. */
13634 try_window (window
, pos
, check_margins
)
13635 Lisp_Object window
;
13636 struct text_pos pos
;
13639 struct window
*w
= XWINDOW (window
);
13641 struct glyph_row
*last_text_row
= NULL
;
13642 struct frame
*f
= XFRAME (w
->frame
);
13644 /* Make POS the new window start. */
13645 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13647 /* Mark cursor position as unknown. No overlay arrow seen. */
13648 w
->cursor
.vpos
= -1;
13649 overlay_arrow_seen
= 0;
13651 /* Initialize iterator and info to start at POS. */
13652 start_display (&it
, w
, pos
);
13654 /* Display all lines of W. */
13655 while (it
.current_y
< it
.last_visible_y
)
13657 if (display_line (&it
))
13658 last_text_row
= it
.glyph_row
- 1;
13659 if (fonts_changed_p
)
13663 /* Don't let the cursor end in the scroll margins. */
13665 && !MINI_WINDOW_P (w
))
13667 int this_scroll_margin
;
13669 this_scroll_margin
= max (0, scroll_margin
);
13670 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13671 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13673 if ((w
->cursor
.y
>= 0 /* not vscrolled */
13674 && w
->cursor
.y
< this_scroll_margin
13675 && CHARPOS (pos
) > BEGV
13676 && IT_CHARPOS (it
) < ZV
)
13677 /* rms: considering make_cursor_line_fully_visible_p here
13678 seems to give wrong results. We don't want to recenter
13679 when the last line is partly visible, we want to allow
13680 that case to be handled in the usual way. */
13681 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
13683 w
->cursor
.vpos
= -1;
13684 clear_glyph_matrix (w
->desired_matrix
);
13689 /* If bottom moved off end of frame, change mode line percentage. */
13690 if (XFASTINT (w
->window_end_pos
) <= 0
13691 && Z
!= IT_CHARPOS (it
))
13692 w
->update_mode_line
= Qt
;
13694 /* Set window_end_pos to the offset of the last character displayed
13695 on the window from the end of current_buffer. Set
13696 window_end_vpos to its row number. */
13699 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
13700 w
->window_end_bytepos
13701 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13703 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13705 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13706 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
13707 ->displays_text_p
);
13711 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13712 w
->window_end_pos
= make_number (Z
- ZV
);
13713 w
->window_end_vpos
= make_number (0);
13716 /* But that is not valid info until redisplay finishes. */
13717 w
->window_end_valid
= Qnil
;
13723 /************************************************************************
13724 Window redisplay reusing current matrix when buffer has not changed
13725 ************************************************************************/
13727 /* Try redisplay of window W showing an unchanged buffer with a
13728 different window start than the last time it was displayed by
13729 reusing its current matrix. Value is non-zero if successful.
13730 W->start is the new window start. */
13733 try_window_reusing_current_matrix (w
)
13736 struct frame
*f
= XFRAME (w
->frame
);
13737 struct glyph_row
*row
, *bottom_row
;
13740 struct text_pos start
, new_start
;
13741 int nrows_scrolled
, i
;
13742 struct glyph_row
*last_text_row
;
13743 struct glyph_row
*last_reused_text_row
;
13744 struct glyph_row
*start_row
;
13745 int start_vpos
, min_y
, max_y
;
13748 if (inhibit_try_window_reusing
)
13752 if (/* This function doesn't handle terminal frames. */
13753 !FRAME_WINDOW_P (f
)
13754 /* Don't try to reuse the display if windows have been split
13756 || windows_or_buffers_changed
13757 || cursor_type_changed
)
13760 /* Can't do this if region may have changed. */
13761 if ((!NILP (Vtransient_mark_mode
)
13762 && !NILP (current_buffer
->mark_active
))
13763 || !NILP (w
->region_showing
)
13764 || !NILP (Vshow_trailing_whitespace
))
13767 /* If top-line visibility has changed, give up. */
13768 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13769 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
13772 /* Give up if old or new display is scrolled vertically. We could
13773 make this function handle this, but right now it doesn't. */
13774 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13775 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
13778 /* The variable new_start now holds the new window start. The old
13779 start `start' can be determined from the current matrix. */
13780 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
13781 start
= start_row
->start
.pos
;
13782 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13784 /* Clear the desired matrix for the display below. */
13785 clear_glyph_matrix (w
->desired_matrix
);
13787 if (CHARPOS (new_start
) <= CHARPOS (start
))
13791 /* Don't use this method if the display starts with an ellipsis
13792 displayed for invisible text. It's not easy to handle that case
13793 below, and it's certainly not worth the effort since this is
13794 not a frequent case. */
13795 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
13798 IF_DEBUG (debug_method_add (w
, "twu1"));
13800 /* Display up to a row that can be reused. The variable
13801 last_text_row is set to the last row displayed that displays
13802 text. Note that it.vpos == 0 if or if not there is a
13803 header-line; it's not the same as the MATRIX_ROW_VPOS! */
13804 start_display (&it
, w
, new_start
);
13805 first_row_y
= it
.current_y
;
13806 w
->cursor
.vpos
= -1;
13807 last_text_row
= last_reused_text_row
= NULL
;
13809 while (it
.current_y
< it
.last_visible_y
13810 && !fonts_changed_p
)
13812 /* If we have reached into the characters in the START row,
13813 that means the line boundaries have changed. So we
13814 can't start copying with the row START. Maybe it will
13815 work to start copying with the following row. */
13816 while (IT_CHARPOS (it
) > CHARPOS (start
))
13818 /* Advance to the next row as the "start". */
13820 start
= start_row
->start
.pos
;
13821 /* If there are no more rows to try, or just one, give up. */
13822 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
13823 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
13824 || CHARPOS (start
) == ZV
)
13826 clear_glyph_matrix (w
->desired_matrix
);
13830 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13832 /* If we have reached alignment,
13833 we can copy the rest of the rows. */
13834 if (IT_CHARPOS (it
) == CHARPOS (start
))
13837 if (display_line (&it
))
13838 last_text_row
= it
.glyph_row
- 1;
13841 /* A value of current_y < last_visible_y means that we stopped
13842 at the previous window start, which in turn means that we
13843 have at least one reusable row. */
13844 if (it
.current_y
< it
.last_visible_y
)
13846 /* IT.vpos always starts from 0; it counts text lines. */
13847 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
13849 /* Find PT if not already found in the lines displayed. */
13850 if (w
->cursor
.vpos
< 0)
13852 int dy
= it
.current_y
- start_row
->y
;
13854 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13855 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
13857 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
13858 dy
, nrows_scrolled
);
13861 clear_glyph_matrix (w
->desired_matrix
);
13866 /* Scroll the display. Do it before the current matrix is
13867 changed. The problem here is that update has not yet
13868 run, i.e. part of the current matrix is not up to date.
13869 scroll_run_hook will clear the cursor, and use the
13870 current matrix to get the height of the row the cursor is
13872 run
.current_y
= start_row
->y
;
13873 run
.desired_y
= it
.current_y
;
13874 run
.height
= it
.last_visible_y
- it
.current_y
;
13876 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
13879 FRAME_RIF (f
)->update_window_begin_hook (w
);
13880 FRAME_RIF (f
)->clear_window_mouse_face (w
);
13881 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
13882 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
13886 /* Shift current matrix down by nrows_scrolled lines. */
13887 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13888 rotate_matrix (w
->current_matrix
,
13890 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13893 /* Disable lines that must be updated. */
13894 for (i
= 0; i
< nrows_scrolled
; ++i
)
13895 (start_row
+ i
)->enabled_p
= 0;
13897 /* Re-compute Y positions. */
13898 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13899 max_y
= it
.last_visible_y
;
13900 for (row
= start_row
+ nrows_scrolled
;
13904 row
->y
= it
.current_y
;
13905 row
->visible_height
= row
->height
;
13907 if (row
->y
< min_y
)
13908 row
->visible_height
-= min_y
- row
->y
;
13909 if (row
->y
+ row
->height
> max_y
)
13910 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13911 row
->redraw_fringe_bitmaps_p
= 1;
13913 it
.current_y
+= row
->height
;
13915 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13916 last_reused_text_row
= row
;
13917 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13921 /* Disable lines in the current matrix which are now
13922 below the window. */
13923 for (++row
; row
< bottom_row
; ++row
)
13924 row
->enabled_p
= row
->mode_line_p
= 0;
13927 /* Update window_end_pos etc.; last_reused_text_row is the last
13928 reused row from the current matrix containing text, if any.
13929 The value of last_text_row is the last displayed line
13930 containing text. */
13931 if (last_reused_text_row
)
13933 w
->window_end_bytepos
13934 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13936 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13938 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13939 w
->current_matrix
));
13941 else if (last_text_row
)
13943 w
->window_end_bytepos
13944 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13946 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13948 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13952 /* This window must be completely empty. */
13953 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13954 w
->window_end_pos
= make_number (Z
- ZV
);
13955 w
->window_end_vpos
= make_number (0);
13957 w
->window_end_valid
= Qnil
;
13959 /* Update hint: don't try scrolling again in update_window. */
13960 w
->desired_matrix
->no_scrolling_p
= 1;
13963 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13967 else if (CHARPOS (new_start
) > CHARPOS (start
))
13969 struct glyph_row
*pt_row
, *row
;
13970 struct glyph_row
*first_reusable_row
;
13971 struct glyph_row
*first_row_to_display
;
13973 int yb
= window_text_bottom_y (w
);
13975 /* Find the row starting at new_start, if there is one. Don't
13976 reuse a partially visible line at the end. */
13977 first_reusable_row
= start_row
;
13978 while (first_reusable_row
->enabled_p
13979 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13980 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13981 < CHARPOS (new_start
)))
13982 ++first_reusable_row
;
13984 /* Give up if there is no row to reuse. */
13985 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13986 || !first_reusable_row
->enabled_p
13987 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13988 != CHARPOS (new_start
)))
13991 /* We can reuse fully visible rows beginning with
13992 first_reusable_row to the end of the window. Set
13993 first_row_to_display to the first row that cannot be reused.
13994 Set pt_row to the row containing point, if there is any. */
13996 for (first_row_to_display
= first_reusable_row
;
13997 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13998 ++first_row_to_display
)
14000 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
14001 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
14002 pt_row
= first_row_to_display
;
14005 /* Start displaying at the start of first_row_to_display. */
14006 xassert (first_row_to_display
->y
< yb
);
14007 init_to_row_start (&it
, w
, first_row_to_display
);
14009 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
14011 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
14013 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
14014 + WINDOW_HEADER_LINE_HEIGHT (w
));
14016 /* Display lines beginning with first_row_to_display in the
14017 desired matrix. Set last_text_row to the last row displayed
14018 that displays text. */
14019 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
14020 if (pt_row
== NULL
)
14021 w
->cursor
.vpos
= -1;
14022 last_text_row
= NULL
;
14023 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
14024 if (display_line (&it
))
14025 last_text_row
= it
.glyph_row
- 1;
14027 /* Give up If point isn't in a row displayed or reused. */
14028 if (w
->cursor
.vpos
< 0)
14030 clear_glyph_matrix (w
->desired_matrix
);
14034 /* If point is in a reused row, adjust y and vpos of the cursor
14038 w
->cursor
.vpos
-= nrows_scrolled
;
14039 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
14042 /* Scroll the display. */
14043 run
.current_y
= first_reusable_row
->y
;
14044 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14045 run
.height
= it
.last_visible_y
- run
.current_y
;
14046 dy
= run
.current_y
- run
.desired_y
;
14051 FRAME_RIF (f
)->update_window_begin_hook (w
);
14052 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14053 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14054 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14058 /* Adjust Y positions of reused rows. */
14059 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14060 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14061 max_y
= it
.last_visible_y
;
14062 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
14065 row
->visible_height
= row
->height
;
14066 if (row
->y
< min_y
)
14067 row
->visible_height
-= min_y
- row
->y
;
14068 if (row
->y
+ row
->height
> max_y
)
14069 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14070 row
->redraw_fringe_bitmaps_p
= 1;
14073 /* Scroll the current matrix. */
14074 xassert (nrows_scrolled
> 0);
14075 rotate_matrix (w
->current_matrix
,
14077 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14080 /* Disable rows not reused. */
14081 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
14082 row
->enabled_p
= 0;
14084 /* Point may have moved to a different line, so we cannot assume that
14085 the previous cursor position is valid; locate the correct row. */
14088 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
14089 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
14093 w
->cursor
.y
= row
->y
;
14095 if (row
< bottom_row
)
14097 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14098 while (glyph
->charpos
< PT
)
14101 w
->cursor
.x
+= glyph
->pixel_width
;
14107 /* Adjust window end. A null value of last_text_row means that
14108 the window end is in reused rows which in turn means that
14109 only its vpos can have changed. */
14112 w
->window_end_bytepos
14113 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14115 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14117 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14122 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
14125 w
->window_end_valid
= Qnil
;
14126 w
->desired_matrix
->no_scrolling_p
= 1;
14129 debug_method_add (w
, "try_window_reusing_current_matrix 2");
14139 /************************************************************************
14140 Window redisplay reusing current matrix when buffer has changed
14141 ************************************************************************/
14143 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
14144 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
14146 static struct glyph_row
*
14147 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
14148 struct glyph_row
*));
14151 /* Return the last row in MATRIX displaying text. If row START is
14152 non-null, start searching with that row. IT gives the dimensions
14153 of the display. Value is null if matrix is empty; otherwise it is
14154 a pointer to the row found. */
14156 static struct glyph_row
*
14157 find_last_row_displaying_text (matrix
, it
, start
)
14158 struct glyph_matrix
*matrix
;
14160 struct glyph_row
*start
;
14162 struct glyph_row
*row
, *row_found
;
14164 /* Set row_found to the last row in IT->w's current matrix
14165 displaying text. The loop looks funny but think of partially
14168 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14169 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14171 xassert (row
->enabled_p
);
14173 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
14182 /* Return the last row in the current matrix of W that is not affected
14183 by changes at the start of current_buffer that occurred since W's
14184 current matrix was built. Value is null if no such row exists.
14186 BEG_UNCHANGED us the number of characters unchanged at the start of
14187 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
14188 first changed character in current_buffer. Characters at positions <
14189 BEG + BEG_UNCHANGED are at the same buffer positions as they were
14190 when the current matrix was built. */
14192 static struct glyph_row
*
14193 find_last_unchanged_at_beg_row (w
)
14196 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
14197 struct glyph_row
*row
;
14198 struct glyph_row
*row_found
= NULL
;
14199 int yb
= window_text_bottom_y (w
);
14201 /* Find the last row displaying unchanged text. */
14202 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14203 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14204 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
14206 if (/* If row ends before first_changed_pos, it is unchanged,
14207 except in some case. */
14208 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
14209 /* When row ends in ZV and we write at ZV it is not
14211 && !row
->ends_at_zv_p
14212 /* When first_changed_pos is the end of a continued line,
14213 row is not unchanged because it may be no longer
14215 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
14216 && (row
->continued_p
14217 || row
->exact_window_width_line_p
)))
14220 /* Stop if last visible row. */
14221 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
14231 /* Find the first glyph row in the current matrix of W that is not
14232 affected by changes at the end of current_buffer since the
14233 time W's current matrix was built.
14235 Return in *DELTA the number of chars by which buffer positions in
14236 unchanged text at the end of current_buffer must be adjusted.
14238 Return in *DELTA_BYTES the corresponding number of bytes.
14240 Value is null if no such row exists, i.e. all rows are affected by
14243 static struct glyph_row
*
14244 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
14246 int *delta
, *delta_bytes
;
14248 struct glyph_row
*row
;
14249 struct glyph_row
*row_found
= NULL
;
14251 *delta
= *delta_bytes
= 0;
14253 /* Display must not have been paused, otherwise the current matrix
14254 is not up to date. */
14255 if (NILP (w
->window_end_valid
))
14258 /* A value of window_end_pos >= END_UNCHANGED means that the window
14259 end is in the range of changed text. If so, there is no
14260 unchanged row at the end of W's current matrix. */
14261 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
14264 /* Set row to the last row in W's current matrix displaying text. */
14265 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14267 /* If matrix is entirely empty, no unchanged row exists. */
14268 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14270 /* The value of row is the last glyph row in the matrix having a
14271 meaningful buffer position in it. The end position of row
14272 corresponds to window_end_pos. This allows us to translate
14273 buffer positions in the current matrix to current buffer
14274 positions for characters not in changed text. */
14275 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14276 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14277 int last_unchanged_pos
, last_unchanged_pos_old
;
14278 struct glyph_row
*first_text_row
14279 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14281 *delta
= Z
- Z_old
;
14282 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14284 /* Set last_unchanged_pos to the buffer position of the last
14285 character in the buffer that has not been changed. Z is the
14286 index + 1 of the last character in current_buffer, i.e. by
14287 subtracting END_UNCHANGED we get the index of the last
14288 unchanged character, and we have to add BEG to get its buffer
14290 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
14291 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
14293 /* Search backward from ROW for a row displaying a line that
14294 starts at a minimum position >= last_unchanged_pos_old. */
14295 for (; row
> first_text_row
; --row
)
14297 /* This used to abort, but it can happen.
14298 It is ok to just stop the search instead here. KFS. */
14299 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14302 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
14307 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
14314 /* Make sure that glyph rows in the current matrix of window W
14315 reference the same glyph memory as corresponding rows in the
14316 frame's frame matrix. This function is called after scrolling W's
14317 current matrix on a terminal frame in try_window_id and
14318 try_window_reusing_current_matrix. */
14321 sync_frame_with_window_matrix_rows (w
)
14324 struct frame
*f
= XFRAME (w
->frame
);
14325 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
14327 /* Preconditions: W must be a leaf window and full-width. Its frame
14328 must have a frame matrix. */
14329 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
14330 xassert (WINDOW_FULL_WIDTH_P (w
));
14331 xassert (!FRAME_WINDOW_P (f
));
14333 /* If W is a full-width window, glyph pointers in W's current matrix
14334 have, by definition, to be the same as glyph pointers in the
14335 corresponding frame matrix. Note that frame matrices have no
14336 marginal areas (see build_frame_matrix). */
14337 window_row
= w
->current_matrix
->rows
;
14338 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14339 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14340 while (window_row
< window_row_end
)
14342 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14343 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14345 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14346 frame_row
->glyphs
[TEXT_AREA
] = start
;
14347 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14348 frame_row
->glyphs
[LAST_AREA
] = end
;
14350 /* Disable frame rows whose corresponding window rows have
14351 been disabled in try_window_id. */
14352 if (!window_row
->enabled_p
)
14353 frame_row
->enabled_p
= 0;
14355 ++window_row
, ++frame_row
;
14360 /* Find the glyph row in window W containing CHARPOS. Consider all
14361 rows between START and END (not inclusive). END null means search
14362 all rows to the end of the display area of W. Value is the row
14363 containing CHARPOS or null. */
14366 row_containing_pos (w
, charpos
, start
, end
, dy
)
14369 struct glyph_row
*start
, *end
;
14372 struct glyph_row
*row
= start
;
14375 /* If we happen to start on a header-line, skip that. */
14376 if (row
->mode_line_p
)
14379 if ((end
&& row
>= end
) || !row
->enabled_p
)
14382 last_y
= window_text_bottom_y (w
) - dy
;
14386 /* Give up if we have gone too far. */
14387 if (end
&& row
>= end
)
14389 /* This formerly returned if they were equal.
14390 I think that both quantities are of a "last plus one" type;
14391 if so, when they are equal, the row is within the screen. -- rms. */
14392 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14395 /* If it is in this row, return this row. */
14396 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14397 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14398 /* The end position of a row equals the start
14399 position of the next row. If CHARPOS is there, we
14400 would rather display it in the next line, except
14401 when this line ends in ZV. */
14402 && !row
->ends_at_zv_p
14403 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14404 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14411 /* Try to redisplay window W by reusing its existing display. W's
14412 current matrix must be up to date when this function is called,
14413 i.e. window_end_valid must not be nil.
14417 1 if display has been updated
14418 0 if otherwise unsuccessful
14419 -1 if redisplay with same window start is known not to succeed
14421 The following steps are performed:
14423 1. Find the last row in the current matrix of W that is not
14424 affected by changes at the start of current_buffer. If no such row
14427 2. Find the first row in W's current matrix that is not affected by
14428 changes at the end of current_buffer. Maybe there is no such row.
14430 3. Display lines beginning with the row + 1 found in step 1 to the
14431 row found in step 2 or, if step 2 didn't find a row, to the end of
14434 4. If cursor is not known to appear on the window, give up.
14436 5. If display stopped at the row found in step 2, scroll the
14437 display and current matrix as needed.
14439 6. Maybe display some lines at the end of W, if we must. This can
14440 happen under various circumstances, like a partially visible line
14441 becoming fully visible, or because newly displayed lines are displayed
14442 in smaller font sizes.
14444 7. Update W's window end information. */
14450 struct frame
*f
= XFRAME (w
->frame
);
14451 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14452 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14453 struct glyph_row
*last_unchanged_at_beg_row
;
14454 struct glyph_row
*first_unchanged_at_end_row
;
14455 struct glyph_row
*row
;
14456 struct glyph_row
*bottom_row
;
14459 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14460 struct text_pos start_pos
;
14462 int first_unchanged_at_end_vpos
= 0;
14463 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14464 struct text_pos start
;
14465 int first_changed_charpos
, last_changed_charpos
;
14468 if (inhibit_try_window_id
)
14472 /* This is handy for debugging. */
14474 #define GIVE_UP(X) \
14476 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14480 #define GIVE_UP(X) return 0
14483 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14485 /* Don't use this for mini-windows because these can show
14486 messages and mini-buffers, and we don't handle that here. */
14487 if (MINI_WINDOW_P (w
))
14490 /* This flag is used to prevent redisplay optimizations. */
14491 if (windows_or_buffers_changed
|| cursor_type_changed
)
14494 /* Verify that narrowing has not changed.
14495 Also verify that we were not told to prevent redisplay optimizations.
14496 It would be nice to further
14497 reduce the number of cases where this prevents try_window_id. */
14498 if (current_buffer
->clip_changed
14499 || current_buffer
->prevent_redisplay_optimizations_p
)
14502 /* Window must either use window-based redisplay or be full width. */
14503 if (!FRAME_WINDOW_P (f
)
14504 && (!FRAME_LINE_INS_DEL_OK (f
)
14505 || !WINDOW_FULL_WIDTH_P (w
)))
14508 /* Give up if point is not known NOT to appear in W. */
14509 if (PT
< CHARPOS (start
))
14512 /* Another way to prevent redisplay optimizations. */
14513 if (XFASTINT (w
->last_modified
) == 0)
14516 /* Verify that window is not hscrolled. */
14517 if (XFASTINT (w
->hscroll
) != 0)
14520 /* Verify that display wasn't paused. */
14521 if (NILP (w
->window_end_valid
))
14524 /* Can't use this if highlighting a region because a cursor movement
14525 will do more than just set the cursor. */
14526 if (!NILP (Vtransient_mark_mode
)
14527 && !NILP (current_buffer
->mark_active
))
14530 /* Likewise if highlighting trailing whitespace. */
14531 if (!NILP (Vshow_trailing_whitespace
))
14534 /* Likewise if showing a region. */
14535 if (!NILP (w
->region_showing
))
14538 /* Can use this if overlay arrow position and or string have changed. */
14539 if (overlay_arrows_changed_p ())
14543 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14544 only if buffer has really changed. The reason is that the gap is
14545 initially at Z for freshly visited files. The code below would
14546 set end_unchanged to 0 in that case. */
14547 if (MODIFF
> SAVE_MODIFF
14548 /* This seems to happen sometimes after saving a buffer. */
14549 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14551 if (GPT
- BEG
< BEG_UNCHANGED
)
14552 BEG_UNCHANGED
= GPT
- BEG
;
14553 if (Z
- GPT
< END_UNCHANGED
)
14554 END_UNCHANGED
= Z
- GPT
;
14557 /* The position of the first and last character that has been changed. */
14558 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14559 last_changed_charpos
= Z
- END_UNCHANGED
;
14561 /* If window starts after a line end, and the last change is in
14562 front of that newline, then changes don't affect the display.
14563 This case happens with stealth-fontification. Note that although
14564 the display is unchanged, glyph positions in the matrix have to
14565 be adjusted, of course. */
14566 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14567 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14568 && ((last_changed_charpos
< CHARPOS (start
)
14569 && CHARPOS (start
) == BEGV
)
14570 || (last_changed_charpos
< CHARPOS (start
) - 1
14571 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14573 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14574 struct glyph_row
*r0
;
14576 /* Compute how many chars/bytes have been added to or removed
14577 from the buffer. */
14578 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14579 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14581 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14583 /* Give up if PT is not in the window. Note that it already has
14584 been checked at the start of try_window_id that PT is not in
14585 front of the window start. */
14586 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14589 /* If window start is unchanged, we can reuse the whole matrix
14590 as is, after adjusting glyph positions. No need to compute
14591 the window end again, since its offset from Z hasn't changed. */
14592 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14593 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14594 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14595 /* PT must not be in a partially visible line. */
14596 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14597 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14599 /* Adjust positions in the glyph matrix. */
14600 if (delta
|| delta_bytes
)
14602 struct glyph_row
*r1
14603 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14604 increment_matrix_positions (w
->current_matrix
,
14605 MATRIX_ROW_VPOS (r0
, current_matrix
),
14606 MATRIX_ROW_VPOS (r1
, current_matrix
),
14607 delta
, delta_bytes
);
14610 /* Set the cursor. */
14611 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14613 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14620 /* Handle the case that changes are all below what is displayed in
14621 the window, and that PT is in the window. This shortcut cannot
14622 be taken if ZV is visible in the window, and text has been added
14623 there that is visible in the window. */
14624 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14625 /* ZV is not visible in the window, or there are no
14626 changes at ZV, actually. */
14627 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14628 || first_changed_charpos
== last_changed_charpos
))
14630 struct glyph_row
*r0
;
14632 /* Give up if PT is not in the window. Note that it already has
14633 been checked at the start of try_window_id that PT is not in
14634 front of the window start. */
14635 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14638 /* If window start is unchanged, we can reuse the whole matrix
14639 as is, without changing glyph positions since no text has
14640 been added/removed in front of the window end. */
14641 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14642 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14643 /* PT must not be in a partially visible line. */
14644 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14645 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14647 /* We have to compute the window end anew since text
14648 can have been added/removed after it. */
14650 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14651 w
->window_end_bytepos
14652 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14654 /* Set the cursor. */
14655 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14657 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14664 /* Give up if window start is in the changed area.
14666 The condition used to read
14668 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
14670 but why that was tested escapes me at the moment. */
14671 if (CHARPOS (start
) >= first_changed_charpos
14672 && CHARPOS (start
) <= last_changed_charpos
)
14675 /* Check that window start agrees with the start of the first glyph
14676 row in its current matrix. Check this after we know the window
14677 start is not in changed text, otherwise positions would not be
14679 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14680 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
14683 /* Give up if the window ends in strings. Overlay strings
14684 at the end are difficult to handle, so don't try. */
14685 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
14686 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
14689 /* Compute the position at which we have to start displaying new
14690 lines. Some of the lines at the top of the window might be
14691 reusable because they are not displaying changed text. Find the
14692 last row in W's current matrix not affected by changes at the
14693 start of current_buffer. Value is null if changes start in the
14694 first line of window. */
14695 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
14696 if (last_unchanged_at_beg_row
)
14698 /* Avoid starting to display in the moddle of a character, a TAB
14699 for instance. This is easier than to set up the iterator
14700 exactly, and it's not a frequent case, so the additional
14701 effort wouldn't really pay off. */
14702 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
14703 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
14704 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
14705 --last_unchanged_at_beg_row
;
14707 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
14710 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
14712 start_pos
= it
.current
.pos
;
14714 /* Start displaying new lines in the desired matrix at the same
14715 vpos we would use in the current matrix, i.e. below
14716 last_unchanged_at_beg_row. */
14717 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
14719 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14720 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
14722 xassert (it
.hpos
== 0 && it
.current_x
== 0);
14726 /* There are no reusable lines at the start of the window.
14727 Start displaying in the first text line. */
14728 start_display (&it
, w
, start
);
14729 it
.vpos
= it
.first_vpos
;
14730 start_pos
= it
.current
.pos
;
14733 /* Find the first row that is not affected by changes at the end of
14734 the buffer. Value will be null if there is no unchanged row, in
14735 which case we must redisplay to the end of the window. delta
14736 will be set to the value by which buffer positions beginning with
14737 first_unchanged_at_end_row have to be adjusted due to text
14739 first_unchanged_at_end_row
14740 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
14741 IF_DEBUG (debug_delta
= delta
);
14742 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
14744 /* Set stop_pos to the buffer position up to which we will have to
14745 display new lines. If first_unchanged_at_end_row != NULL, this
14746 is the buffer position of the start of the line displayed in that
14747 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
14748 that we don't stop at a buffer position. */
14750 if (first_unchanged_at_end_row
)
14752 xassert (last_unchanged_at_beg_row
== NULL
14753 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
14755 /* If this is a continuation line, move forward to the next one
14756 that isn't. Changes in lines above affect this line.
14757 Caution: this may move first_unchanged_at_end_row to a row
14758 not displaying text. */
14759 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
14760 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14761 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14762 < it
.last_visible_y
))
14763 ++first_unchanged_at_end_row
;
14765 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14766 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14767 >= it
.last_visible_y
))
14768 first_unchanged_at_end_row
= NULL
;
14771 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
14773 first_unchanged_at_end_vpos
14774 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
14775 xassert (stop_pos
>= Z
- END_UNCHANGED
);
14778 else if (last_unchanged_at_beg_row
== NULL
)
14784 /* Either there is no unchanged row at the end, or the one we have
14785 now displays text. This is a necessary condition for the window
14786 end pos calculation at the end of this function. */
14787 xassert (first_unchanged_at_end_row
== NULL
14788 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
14790 debug_last_unchanged_at_beg_vpos
14791 = (last_unchanged_at_beg_row
14792 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
14794 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
14796 #endif /* GLYPH_DEBUG != 0 */
14799 /* Display new lines. Set last_text_row to the last new line
14800 displayed which has text on it, i.e. might end up as being the
14801 line where the window_end_vpos is. */
14802 w
->cursor
.vpos
= -1;
14803 last_text_row
= NULL
;
14804 overlay_arrow_seen
= 0;
14805 while (it
.current_y
< it
.last_visible_y
14806 && !fonts_changed_p
14807 && (first_unchanged_at_end_row
== NULL
14808 || IT_CHARPOS (it
) < stop_pos
))
14810 if (display_line (&it
))
14811 last_text_row
= it
.glyph_row
- 1;
14814 if (fonts_changed_p
)
14818 /* Compute differences in buffer positions, y-positions etc. for
14819 lines reused at the bottom of the window. Compute what we can
14821 if (first_unchanged_at_end_row
14822 /* No lines reused because we displayed everything up to the
14823 bottom of the window. */
14824 && it
.current_y
< it
.last_visible_y
)
14827 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
14829 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
14830 run
.current_y
= first_unchanged_at_end_row
->y
;
14831 run
.desired_y
= run
.current_y
+ dy
;
14832 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
14836 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
14837 first_unchanged_at_end_row
= NULL
;
14839 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
14842 /* Find the cursor if not already found. We have to decide whether
14843 PT will appear on this window (it sometimes doesn't, but this is
14844 not a very frequent case.) This decision has to be made before
14845 the current matrix is altered. A value of cursor.vpos < 0 means
14846 that PT is either in one of the lines beginning at
14847 first_unchanged_at_end_row or below the window. Don't care for
14848 lines that might be displayed later at the window end; as
14849 mentioned, this is not a frequent case. */
14850 if (w
->cursor
.vpos
< 0)
14852 /* Cursor in unchanged rows at the top? */
14853 if (PT
< CHARPOS (start_pos
)
14854 && last_unchanged_at_beg_row
)
14856 row
= row_containing_pos (w
, PT
,
14857 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
14858 last_unchanged_at_beg_row
+ 1, 0);
14860 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14863 /* Start from first_unchanged_at_end_row looking for PT. */
14864 else if (first_unchanged_at_end_row
)
14866 row
= row_containing_pos (w
, PT
- delta
,
14867 first_unchanged_at_end_row
, NULL
, 0);
14869 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
14870 delta_bytes
, dy
, dvpos
);
14873 /* Give up if cursor was not found. */
14874 if (w
->cursor
.vpos
< 0)
14876 clear_glyph_matrix (w
->desired_matrix
);
14881 /* Don't let the cursor end in the scroll margins. */
14883 int this_scroll_margin
, cursor_height
;
14885 this_scroll_margin
= max (0, scroll_margin
);
14886 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14887 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14888 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
14890 if ((w
->cursor
.y
< this_scroll_margin
14891 && CHARPOS (start
) > BEGV
)
14892 /* Old redisplay didn't take scroll margin into account at the bottom,
14893 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14894 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14895 ? cursor_height
+ this_scroll_margin
14896 : 1)) > it
.last_visible_y
)
14898 w
->cursor
.vpos
= -1;
14899 clear_glyph_matrix (w
->desired_matrix
);
14904 /* Scroll the display. Do it before changing the current matrix so
14905 that xterm.c doesn't get confused about where the cursor glyph is
14907 if (dy
&& run
.height
)
14911 if (FRAME_WINDOW_P (f
))
14913 FRAME_RIF (f
)->update_window_begin_hook (w
);
14914 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14915 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14916 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14920 /* Terminal frame. In this case, dvpos gives the number of
14921 lines to scroll by; dvpos < 0 means scroll up. */
14922 int first_unchanged_at_end_vpos
14923 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14924 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14925 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14926 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14927 + window_internal_height (w
));
14929 /* Perform the operation on the screen. */
14932 /* Scroll last_unchanged_at_beg_row to the end of the
14933 window down dvpos lines. */
14934 set_terminal_window (f
, end
);
14936 /* On dumb terminals delete dvpos lines at the end
14937 before inserting dvpos empty lines. */
14938 if (!FRAME_SCROLL_REGION_OK (f
))
14939 ins_del_lines (f
, end
- dvpos
, -dvpos
);
14941 /* Insert dvpos empty lines in front of
14942 last_unchanged_at_beg_row. */
14943 ins_del_lines (f
, from
, dvpos
);
14945 else if (dvpos
< 0)
14947 /* Scroll up last_unchanged_at_beg_vpos to the end of
14948 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14949 set_terminal_window (f
, end
);
14951 /* Delete dvpos lines in front of
14952 last_unchanged_at_beg_vpos. ins_del_lines will set
14953 the cursor to the given vpos and emit |dvpos| delete
14955 ins_del_lines (f
, from
+ dvpos
, dvpos
);
14957 /* On a dumb terminal insert dvpos empty lines at the
14959 if (!FRAME_SCROLL_REGION_OK (f
))
14960 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
14963 set_terminal_window (f
, 0);
14969 /* Shift reused rows of the current matrix to the right position.
14970 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14972 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14973 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14976 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14977 bottom_vpos
, dvpos
);
14978 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14981 else if (dvpos
> 0)
14983 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14984 bottom_vpos
, dvpos
);
14985 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14986 first_unchanged_at_end_vpos
+ dvpos
, 0);
14989 /* For frame-based redisplay, make sure that current frame and window
14990 matrix are in sync with respect to glyph memory. */
14991 if (!FRAME_WINDOW_P (f
))
14992 sync_frame_with_window_matrix_rows (w
);
14994 /* Adjust buffer positions in reused rows. */
14995 if (delta
|| delta_bytes
)
14996 increment_matrix_positions (current_matrix
,
14997 first_unchanged_at_end_vpos
+ dvpos
,
14998 bottom_vpos
, delta
, delta_bytes
);
15000 /* Adjust Y positions. */
15002 shift_glyph_matrix (w
, current_matrix
,
15003 first_unchanged_at_end_vpos
+ dvpos
,
15006 if (first_unchanged_at_end_row
)
15008 first_unchanged_at_end_row
+= dvpos
;
15009 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
15010 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
15011 first_unchanged_at_end_row
= NULL
;
15014 /* If scrolling up, there may be some lines to display at the end of
15016 last_text_row_at_end
= NULL
;
15019 /* Scrolling up can leave for example a partially visible line
15020 at the end of the window to be redisplayed. */
15021 /* Set last_row to the glyph row in the current matrix where the
15022 window end line is found. It has been moved up or down in
15023 the matrix by dvpos. */
15024 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
15025 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
15027 /* If last_row is the window end line, it should display text. */
15028 xassert (last_row
->displays_text_p
);
15030 /* If window end line was partially visible before, begin
15031 displaying at that line. Otherwise begin displaying with the
15032 line following it. */
15033 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
15035 init_to_row_start (&it
, w
, last_row
);
15036 it
.vpos
= last_vpos
;
15037 it
.current_y
= last_row
->y
;
15041 init_to_row_end (&it
, w
, last_row
);
15042 it
.vpos
= 1 + last_vpos
;
15043 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
15047 /* We may start in a continuation line. If so, we have to
15048 get the right continuation_lines_width and current_x. */
15049 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
15050 it
.hpos
= it
.current_x
= 0;
15052 /* Display the rest of the lines at the window end. */
15053 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15054 while (it
.current_y
< it
.last_visible_y
15055 && !fonts_changed_p
)
15057 /* Is it always sure that the display agrees with lines in
15058 the current matrix? I don't think so, so we mark rows
15059 displayed invalid in the current matrix by setting their
15060 enabled_p flag to zero. */
15061 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
15062 if (display_line (&it
))
15063 last_text_row_at_end
= it
.glyph_row
- 1;
15067 /* Update window_end_pos and window_end_vpos. */
15068 if (first_unchanged_at_end_row
15069 && !last_text_row_at_end
)
15071 /* Window end line if one of the preserved rows from the current
15072 matrix. Set row to the last row displaying text in current
15073 matrix starting at first_unchanged_at_end_row, after
15075 xassert (first_unchanged_at_end_row
->displays_text_p
);
15076 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
15077 first_unchanged_at_end_row
);
15078 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
15080 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15081 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15083 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
15084 xassert (w
->window_end_bytepos
>= 0);
15085 IF_DEBUG (debug_method_add (w
, "A"));
15087 else if (last_text_row_at_end
)
15090 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
15091 w
->window_end_bytepos
15092 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
15094 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
15095 xassert (w
->window_end_bytepos
>= 0);
15096 IF_DEBUG (debug_method_add (w
, "B"));
15098 else if (last_text_row
)
15100 /* We have displayed either to the end of the window or at the
15101 end of the window, i.e. the last row with text is to be found
15102 in the desired matrix. */
15104 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15105 w
->window_end_bytepos
15106 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15108 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
15109 xassert (w
->window_end_bytepos
>= 0);
15111 else if (first_unchanged_at_end_row
== NULL
15112 && last_text_row
== NULL
15113 && last_text_row_at_end
== NULL
)
15115 /* Displayed to end of window, but no line containing text was
15116 displayed. Lines were deleted at the end of the window. */
15117 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
15118 int vpos
= XFASTINT (w
->window_end_vpos
);
15119 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
15120 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
15123 row
== NULL
&& vpos
>= first_vpos
;
15124 --vpos
, --current_row
, --desired_row
)
15126 if (desired_row
->enabled_p
)
15128 if (desired_row
->displays_text_p
)
15131 else if (current_row
->displays_text_p
)
15135 xassert (row
!= NULL
);
15136 w
->window_end_vpos
= make_number (vpos
+ 1);
15137 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15138 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15139 xassert (w
->window_end_bytepos
>= 0);
15140 IF_DEBUG (debug_method_add (w
, "C"));
15145 #if 0 /* This leads to problems, for instance when the cursor is
15146 at ZV, and the cursor line displays no text. */
15147 /* Disable rows below what's displayed in the window. This makes
15148 debugging easier. */
15149 enable_glyph_matrix_rows (current_matrix
,
15150 XFASTINT (w
->window_end_vpos
) + 1,
15154 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
15155 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
15157 /* Record that display has not been completed. */
15158 w
->window_end_valid
= Qnil
;
15159 w
->desired_matrix
->no_scrolling_p
= 1;
15167 /***********************************************************************
15168 More debugging support
15169 ***********************************************************************/
15173 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
15174 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
15175 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
15178 /* Dump the contents of glyph matrix MATRIX on stderr.
15180 GLYPHS 0 means don't show glyph contents.
15181 GLYPHS 1 means show glyphs in short form
15182 GLYPHS > 1 means show glyphs in long form. */
15185 dump_glyph_matrix (matrix
, glyphs
)
15186 struct glyph_matrix
*matrix
;
15190 for (i
= 0; i
< matrix
->nrows
; ++i
)
15191 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
15195 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
15196 the glyph row and area where the glyph comes from. */
15199 dump_glyph (row
, glyph
, area
)
15200 struct glyph_row
*row
;
15201 struct glyph
*glyph
;
15204 if (glyph
->type
== CHAR_GLYPH
)
15207 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15208 glyph
- row
->glyphs
[TEXT_AREA
],
15211 (BUFFERP (glyph
->object
)
15213 : (STRINGP (glyph
->object
)
15216 glyph
->pixel_width
,
15218 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
15222 glyph
->left_box_line_p
,
15223 glyph
->right_box_line_p
);
15225 else if (glyph
->type
== STRETCH_GLYPH
)
15228 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15229 glyph
- row
->glyphs
[TEXT_AREA
],
15232 (BUFFERP (glyph
->object
)
15234 : (STRINGP (glyph
->object
)
15237 glyph
->pixel_width
,
15241 glyph
->left_box_line_p
,
15242 glyph
->right_box_line_p
);
15244 else if (glyph
->type
== IMAGE_GLYPH
)
15247 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15248 glyph
- row
->glyphs
[TEXT_AREA
],
15251 (BUFFERP (glyph
->object
)
15253 : (STRINGP (glyph
->object
)
15256 glyph
->pixel_width
,
15260 glyph
->left_box_line_p
,
15261 glyph
->right_box_line_p
);
15263 else if (glyph
->type
== COMPOSITE_GLYPH
)
15266 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15267 glyph
- row
->glyphs
[TEXT_AREA
],
15270 (BUFFERP (glyph
->object
)
15272 : (STRINGP (glyph
->object
)
15275 glyph
->pixel_width
,
15279 glyph
->left_box_line_p
,
15280 glyph
->right_box_line_p
);
15285 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
15286 GLYPHS 0 means don't show glyph contents.
15287 GLYPHS 1 means show glyphs in short form
15288 GLYPHS > 1 means show glyphs in long form. */
15291 dump_glyph_row (row
, vpos
, glyphs
)
15292 struct glyph_row
*row
;
15297 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
15298 fprintf (stderr
, "======================================================================\n");
15300 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
15301 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
15303 MATRIX_ROW_START_CHARPOS (row
),
15304 MATRIX_ROW_END_CHARPOS (row
),
15305 row
->used
[TEXT_AREA
],
15306 row
->contains_overlapping_glyphs_p
,
15308 row
->truncated_on_left_p
,
15309 row
->truncated_on_right_p
,
15311 MATRIX_ROW_CONTINUATION_LINE_P (row
),
15312 row
->displays_text_p
,
15315 row
->ends_in_middle_of_char_p
,
15316 row
->starts_in_middle_of_char_p
,
15322 row
->visible_height
,
15325 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
15326 row
->end
.overlay_string_index
,
15327 row
->continuation_lines_width
);
15328 fprintf (stderr
, "%9d %5d\n",
15329 CHARPOS (row
->start
.string_pos
),
15330 CHARPOS (row
->end
.string_pos
));
15331 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
15332 row
->end
.dpvec_index
);
15339 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15341 struct glyph
*glyph
= row
->glyphs
[area
];
15342 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
15344 /* Glyph for a line end in text. */
15345 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
15348 if (glyph
< glyph_end
)
15349 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15351 for (; glyph
< glyph_end
; ++glyph
)
15352 dump_glyph (row
, glyph
, area
);
15355 else if (glyphs
== 1)
15359 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15361 char *s
= (char *) alloca (row
->used
[area
] + 1);
15364 for (i
= 0; i
< row
->used
[area
]; ++i
)
15366 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15367 if (glyph
->type
== CHAR_GLYPH
15368 && glyph
->u
.ch
< 0x80
15369 && glyph
->u
.ch
>= ' ')
15370 s
[i
] = glyph
->u
.ch
;
15376 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15382 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15383 Sdump_glyph_matrix
, 0, 1, "p",
15384 doc
: /* Dump the current matrix of the selected window to stderr.
15385 Shows contents of glyph row structures. With non-nil
15386 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15387 glyphs in short form, otherwise show glyphs in long form. */)
15389 Lisp_Object glyphs
;
15391 struct window
*w
= XWINDOW (selected_window
);
15392 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15394 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15395 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15396 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15397 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15398 fprintf (stderr
, "=============================================\n");
15399 dump_glyph_matrix (w
->current_matrix
,
15400 NILP (glyphs
) ? 0 : XINT (glyphs
));
15405 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15406 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15409 struct frame
*f
= XFRAME (selected_frame
);
15410 dump_glyph_matrix (f
->current_matrix
, 1);
15415 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15416 doc
: /* Dump glyph row ROW to stderr.
15417 GLYPH 0 means don't dump glyphs.
15418 GLYPH 1 means dump glyphs in short form.
15419 GLYPH > 1 or omitted means dump glyphs in long form. */)
15421 Lisp_Object row
, glyphs
;
15423 struct glyph_matrix
*matrix
;
15426 CHECK_NUMBER (row
);
15427 matrix
= XWINDOW (selected_window
)->current_matrix
;
15429 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15430 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15432 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15437 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15438 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15439 GLYPH 0 means don't dump glyphs.
15440 GLYPH 1 means dump glyphs in short form.
15441 GLYPH > 1 or omitted means dump glyphs in long form. */)
15443 Lisp_Object row
, glyphs
;
15445 struct frame
*sf
= SELECTED_FRAME ();
15446 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15449 CHECK_NUMBER (row
);
15451 if (vpos
>= 0 && vpos
< m
->nrows
)
15452 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15453 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15458 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15459 doc
: /* Toggle tracing of redisplay.
15460 With ARG, turn tracing on if and only if ARG is positive. */)
15465 trace_redisplay_p
= !trace_redisplay_p
;
15468 arg
= Fprefix_numeric_value (arg
);
15469 trace_redisplay_p
= XINT (arg
) > 0;
15476 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15477 doc
: /* Like `format', but print result to stderr.
15478 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15483 Lisp_Object s
= Fformat (nargs
, args
);
15484 fprintf (stderr
, "%s", SDATA (s
));
15488 #endif /* GLYPH_DEBUG */
15492 /***********************************************************************
15493 Building Desired Matrix Rows
15494 ***********************************************************************/
15496 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15497 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15499 static struct glyph_row
*
15500 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15502 Lisp_Object overlay_arrow_string
;
15504 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15505 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15506 struct buffer
*old
= current_buffer
;
15507 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15508 int arrow_len
= SCHARS (overlay_arrow_string
);
15509 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15510 const unsigned char *p
;
15513 int n_glyphs_before
;
15515 set_buffer_temp (buffer
);
15516 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15517 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15518 SET_TEXT_POS (it
.position
, 0, 0);
15520 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15522 while (p
< arrow_end
)
15524 Lisp_Object face
, ilisp
;
15526 /* Get the next character. */
15528 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15530 it
.c
= *p
, it
.len
= 1;
15533 /* Get its face. */
15534 ilisp
= make_number (p
- arrow_string
);
15535 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15536 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15538 /* Compute its width, get its glyphs. */
15539 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15540 SET_TEXT_POS (it
.position
, -1, -1);
15541 PRODUCE_GLYPHS (&it
);
15543 /* If this character doesn't fit any more in the line, we have
15544 to remove some glyphs. */
15545 if (it
.current_x
> it
.last_visible_x
)
15547 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15552 set_buffer_temp (old
);
15553 return it
.glyph_row
;
15557 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15558 glyphs are only inserted for terminal frames since we can't really
15559 win with truncation glyphs when partially visible glyphs are
15560 involved. Which glyphs to insert is determined by
15561 produce_special_glyphs. */
15564 insert_left_trunc_glyphs (it
)
15567 struct it truncate_it
;
15568 struct glyph
*from
, *end
, *to
, *toend
;
15570 xassert (!FRAME_WINDOW_P (it
->f
));
15572 /* Get the truncation glyphs. */
15574 truncate_it
.current_x
= 0;
15575 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15576 truncate_it
.glyph_row
= &scratch_glyph_row
;
15577 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15578 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15579 truncate_it
.object
= make_number (0);
15580 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15582 /* Overwrite glyphs from IT with truncation glyphs. */
15583 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15584 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15585 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15586 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15591 /* There may be padding glyphs left over. Overwrite them too. */
15592 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15594 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15600 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15604 /* Compute the pixel height and width of IT->glyph_row.
15606 Most of the time, ascent and height of a display line will be equal
15607 to the max_ascent and max_height values of the display iterator
15608 structure. This is not the case if
15610 1. We hit ZV without displaying anything. In this case, max_ascent
15611 and max_height will be zero.
15613 2. We have some glyphs that don't contribute to the line height.
15614 (The glyph row flag contributes_to_line_height_p is for future
15615 pixmap extensions).
15617 The first case is easily covered by using default values because in
15618 these cases, the line height does not really matter, except that it
15619 must not be zero. */
15622 compute_line_metrics (it
)
15625 struct glyph_row
*row
= it
->glyph_row
;
15628 if (FRAME_WINDOW_P (it
->f
))
15630 int i
, min_y
, max_y
;
15632 /* The line may consist of one space only, that was added to
15633 place the cursor on it. If so, the row's height hasn't been
15635 if (row
->height
== 0)
15637 if (it
->max_ascent
+ it
->max_descent
== 0)
15638 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15639 row
->ascent
= it
->max_ascent
;
15640 row
->height
= it
->max_ascent
+ it
->max_descent
;
15641 row
->phys_ascent
= it
->max_phys_ascent
;
15642 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15643 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15646 /* Compute the width of this line. */
15647 row
->pixel_width
= row
->x
;
15648 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15649 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15651 xassert (row
->pixel_width
>= 0);
15652 xassert (row
->ascent
>= 0 && row
->height
> 0);
15654 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15655 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15657 /* If first line's physical ascent is larger than its logical
15658 ascent, use the physical ascent, and make the row taller.
15659 This makes accented characters fully visible. */
15660 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
15661 && row
->phys_ascent
> row
->ascent
)
15663 row
->height
+= row
->phys_ascent
- row
->ascent
;
15664 row
->ascent
= row
->phys_ascent
;
15667 /* Compute how much of the line is visible. */
15668 row
->visible_height
= row
->height
;
15670 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
15671 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
15673 if (row
->y
< min_y
)
15674 row
->visible_height
-= min_y
- row
->y
;
15675 if (row
->y
+ row
->height
> max_y
)
15676 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15680 row
->pixel_width
= row
->used
[TEXT_AREA
];
15681 if (row
->continued_p
)
15682 row
->pixel_width
-= it
->continuation_pixel_width
;
15683 else if (row
->truncated_on_right_p
)
15684 row
->pixel_width
-= it
->truncation_pixel_width
;
15685 row
->ascent
= row
->phys_ascent
= 0;
15686 row
->height
= row
->phys_height
= row
->visible_height
= 1;
15687 row
->extra_line_spacing
= 0;
15690 /* Compute a hash code for this row. */
15692 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15693 for (i
= 0; i
< row
->used
[area
]; ++i
)
15694 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
15695 + row
->glyphs
[area
][i
].u
.val
15696 + row
->glyphs
[area
][i
].face_id
15697 + row
->glyphs
[area
][i
].padding_p
15698 + (row
->glyphs
[area
][i
].type
<< 2));
15700 it
->max_ascent
= it
->max_descent
= 0;
15701 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
15705 /* Append one space to the glyph row of iterator IT if doing a
15706 window-based redisplay. The space has the same face as
15707 IT->face_id. Value is non-zero if a space was added.
15709 This function is called to make sure that there is always one glyph
15710 at the end of a glyph row that the cursor can be set on under
15711 window-systems. (If there weren't such a glyph we would not know
15712 how wide and tall a box cursor should be displayed).
15714 At the same time this space let's a nicely handle clearing to the
15715 end of the line if the row ends in italic text. */
15718 append_space_for_newline (it
, default_face_p
)
15720 int default_face_p
;
15722 if (FRAME_WINDOW_P (it
->f
))
15724 int n
= it
->glyph_row
->used
[TEXT_AREA
];
15726 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
15727 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
15729 /* Save some values that must not be changed.
15730 Must save IT->c and IT->len because otherwise
15731 ITERATOR_AT_END_P wouldn't work anymore after
15732 append_space_for_newline has been called. */
15733 enum display_element_type saved_what
= it
->what
;
15734 int saved_c
= it
->c
, saved_len
= it
->len
;
15735 int saved_x
= it
->current_x
;
15736 int saved_face_id
= it
->face_id
;
15737 struct text_pos saved_pos
;
15738 Lisp_Object saved_object
;
15741 saved_object
= it
->object
;
15742 saved_pos
= it
->position
;
15744 it
->what
= IT_CHARACTER
;
15745 bzero (&it
->position
, sizeof it
->position
);
15746 it
->object
= make_number (0);
15750 if (default_face_p
)
15751 it
->face_id
= DEFAULT_FACE_ID
;
15752 else if (it
->face_before_selective_p
)
15753 it
->face_id
= it
->saved_face_id
;
15754 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15755 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
15757 PRODUCE_GLYPHS (it
);
15759 it
->override_ascent
= -1;
15760 it
->constrain_row_ascent_descent_p
= 0;
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
;
15766 it
->len
= saved_len
;
15776 /* Extend the face of the last glyph in the text area of IT->glyph_row
15777 to the end of the display line. Called from display_line.
15778 If the glyph row is empty, add a space glyph to it so that we
15779 know the face to draw. Set the glyph row flag fill_line_p. */
15782 extend_face_to_end_of_line (it
)
15786 struct frame
*f
= it
->f
;
15788 /* If line is already filled, do nothing. */
15789 if (it
->current_x
>= it
->last_visible_x
)
15792 /* Face extension extends the background and box of IT->face_id
15793 to the end of the line. If the background equals the background
15794 of the frame, we don't have to do anything. */
15795 if (it
->face_before_selective_p
)
15796 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
15798 face
= FACE_FROM_ID (f
, it
->face_id
);
15800 if (FRAME_WINDOW_P (f
)
15801 && it
->glyph_row
->displays_text_p
15802 && face
->box
== FACE_NO_BOX
15803 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
15807 /* Set the glyph row flag indicating that the face of the last glyph
15808 in the text area has to be drawn to the end of the text area. */
15809 it
->glyph_row
->fill_line_p
= 1;
15811 /* If current character of IT is not ASCII, make sure we have the
15812 ASCII face. This will be automatically undone the next time
15813 get_next_display_element returns a multibyte character. Note
15814 that the character will always be single byte in unibyte text. */
15815 if (!SINGLE_BYTE_CHAR_P (it
->c
))
15817 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
15820 if (FRAME_WINDOW_P (f
))
15822 /* If the row is empty, add a space with the current face of IT,
15823 so that we know which face to draw. */
15824 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
15826 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
15827 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
15828 it
->glyph_row
->used
[TEXT_AREA
] = 1;
15833 /* Save some values that must not be changed. */
15834 int saved_x
= it
->current_x
;
15835 struct text_pos saved_pos
;
15836 Lisp_Object saved_object
;
15837 enum display_element_type saved_what
= it
->what
;
15838 int saved_face_id
= it
->face_id
;
15840 saved_object
= it
->object
;
15841 saved_pos
= it
->position
;
15843 it
->what
= IT_CHARACTER
;
15844 bzero (&it
->position
, sizeof it
->position
);
15845 it
->object
= make_number (0);
15848 it
->face_id
= face
->id
;
15850 PRODUCE_GLYPHS (it
);
15852 while (it
->current_x
<= it
->last_visible_x
)
15853 PRODUCE_GLYPHS (it
);
15855 /* Don't count these blanks really. It would let us insert a left
15856 truncation glyph below and make us set the cursor on them, maybe. */
15857 it
->current_x
= saved_x
;
15858 it
->object
= saved_object
;
15859 it
->position
= saved_pos
;
15860 it
->what
= saved_what
;
15861 it
->face_id
= saved_face_id
;
15866 /* Value is non-zero if text starting at CHARPOS in current_buffer is
15867 trailing whitespace. */
15870 trailing_whitespace_p (charpos
)
15873 int bytepos
= CHAR_TO_BYTE (charpos
);
15876 while (bytepos
< ZV_BYTE
15877 && (c
= FETCH_CHAR (bytepos
),
15878 c
== ' ' || c
== '\t'))
15881 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
15883 if (bytepos
!= PT_BYTE
)
15890 /* Highlight trailing whitespace, if any, in ROW. */
15893 highlight_trailing_whitespace (f
, row
)
15895 struct glyph_row
*row
;
15897 int used
= row
->used
[TEXT_AREA
];
15901 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
15902 struct glyph
*glyph
= start
+ used
- 1;
15904 /* Skip over glyphs inserted to display the cursor at the
15905 end of a line, for extending the face of the last glyph
15906 to the end of the line on terminals, and for truncation
15907 and continuation glyphs. */
15908 while (glyph
>= start
15909 && glyph
->type
== CHAR_GLYPH
15910 && INTEGERP (glyph
->object
))
15913 /* If last glyph is a space or stretch, and it's trailing
15914 whitespace, set the face of all trailing whitespace glyphs in
15915 IT->glyph_row to `trailing-whitespace'. */
15917 && BUFFERP (glyph
->object
)
15918 && (glyph
->type
== STRETCH_GLYPH
15919 || (glyph
->type
== CHAR_GLYPH
15920 && glyph
->u
.ch
== ' '))
15921 && trailing_whitespace_p (glyph
->charpos
))
15923 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
15927 while (glyph
>= start
15928 && BUFFERP (glyph
->object
)
15929 && (glyph
->type
== STRETCH_GLYPH
15930 || (glyph
->type
== CHAR_GLYPH
15931 && glyph
->u
.ch
== ' ')))
15932 (glyph
--)->face_id
= face_id
;
15938 /* Value is non-zero if glyph row ROW in window W should be
15939 used to hold the cursor. */
15942 cursor_row_p (w
, row
)
15944 struct glyph_row
*row
;
15946 int cursor_row_p
= 1;
15948 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15950 /* Suppose the row ends on a string.
15951 Unless the row is continued, that means it ends on a newline
15952 in the string. If it's anything other than a display string
15953 (e.g. a before-string from an overlay), we don't want the
15954 cursor there. (This heuristic seems to give the optimal
15955 behavior for the various types of multi-line strings.) */
15956 if (CHARPOS (row
->end
.string_pos
) >= 0)
15958 if (row
->continued_p
)
15962 /* Check for `display' property. */
15963 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
15964 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
15965 struct glyph
*glyph
;
15968 for (glyph
= end
; glyph
>= beg
; --glyph
)
15969 if (STRINGP (glyph
->object
))
15972 = Fget_char_property (make_number (PT
),
15976 && display_prop_string_p (prop
, glyph
->object
));
15981 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15983 /* If the row ends in middle of a real character,
15984 and the line is continued, we want the cursor here.
15985 That's because MATRIX_ROW_END_CHARPOS would equal
15986 PT if PT is before the character. */
15987 if (!row
->ends_in_ellipsis_p
)
15988 cursor_row_p
= row
->continued_p
;
15990 /* If the row ends in an ellipsis, then
15991 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15992 We want that position to be displayed after the ellipsis. */
15995 /* If the row ends at ZV, display the cursor at the end of that
15996 row instead of at the start of the row below. */
15997 else if (row
->ends_at_zv_p
)
16003 return cursor_row_p
;
16007 /* Construct the glyph row IT->glyph_row in the desired matrix of
16008 IT->w from text at the current position of IT. See dispextern.h
16009 for an overview of struct it. Value is non-zero if
16010 IT->glyph_row displays text, as opposed to a line displaying ZV
16017 struct glyph_row
*row
= it
->glyph_row
;
16018 Lisp_Object overlay_arrow_string
;
16020 /* We always start displaying at hpos zero even if hscrolled. */
16021 xassert (it
->hpos
== 0 && it
->current_x
== 0);
16023 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
16024 >= it
->w
->desired_matrix
->nrows
)
16026 it
->w
->nrows_scale_factor
++;
16027 fonts_changed_p
= 1;
16031 /* Is IT->w showing the region? */
16032 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
16034 /* Clear the result glyph row and enable it. */
16035 prepare_desired_row (row
);
16037 row
->y
= it
->current_y
;
16038 row
->start
= it
->start
;
16039 row
->continuation_lines_width
= it
->continuation_lines_width
;
16040 row
->displays_text_p
= 1;
16041 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
16042 it
->starts_in_middle_of_char_p
= 0;
16044 /* Arrange the overlays nicely for our purposes. Usually, we call
16045 display_line on only one line at a time, in which case this
16046 can't really hurt too much, or we call it on lines which appear
16047 one after another in the buffer, in which case all calls to
16048 recenter_overlay_lists but the first will be pretty cheap. */
16049 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
16051 /* Move over display elements that are not visible because we are
16052 hscrolled. This may stop at an x-position < IT->first_visible_x
16053 if the first glyph is partially visible or if we hit a line end. */
16054 if (it
->current_x
< it
->first_visible_x
)
16056 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
16057 MOVE_TO_POS
| MOVE_TO_X
);
16060 /* Get the initial row height. This is either the height of the
16061 text hscrolled, if there is any, or zero. */
16062 row
->ascent
= it
->max_ascent
;
16063 row
->height
= it
->max_ascent
+ it
->max_descent
;
16064 row
->phys_ascent
= it
->max_phys_ascent
;
16065 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16066 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16068 /* Loop generating characters. The loop is left with IT on the next
16069 character to display. */
16072 int n_glyphs_before
, hpos_before
, x_before
;
16074 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
16076 /* Retrieve the next thing to display. Value is zero if end of
16078 if (!get_next_display_element (it
))
16080 /* Maybe add a space at the end of this line that is used to
16081 display the cursor there under X. Set the charpos of the
16082 first glyph of blank lines not corresponding to any text
16084 #ifdef HAVE_WINDOW_SYSTEM
16085 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16086 row
->exact_window_width_line_p
= 1;
16088 #endif /* HAVE_WINDOW_SYSTEM */
16089 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
16090 || row
->used
[TEXT_AREA
] == 0)
16092 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
16093 row
->displays_text_p
= 0;
16095 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
16096 && (!MINI_WINDOW_P (it
->w
)
16097 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
16098 row
->indicate_empty_line_p
= 1;
16101 it
->continuation_lines_width
= 0;
16102 row
->ends_at_zv_p
= 1;
16106 /* Now, get the metrics of what we want to display. This also
16107 generates glyphs in `row' (which is IT->glyph_row). */
16108 n_glyphs_before
= row
->used
[TEXT_AREA
];
16111 /* Remember the line height so far in case the next element doesn't
16112 fit on the line. */
16113 if (!it
->truncate_lines_p
)
16115 ascent
= it
->max_ascent
;
16116 descent
= it
->max_descent
;
16117 phys_ascent
= it
->max_phys_ascent
;
16118 phys_descent
= it
->max_phys_descent
;
16121 PRODUCE_GLYPHS (it
);
16123 /* If this display element was in marginal areas, continue with
16125 if (it
->area
!= TEXT_AREA
)
16127 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16128 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16129 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16130 row
->phys_height
= max (row
->phys_height
,
16131 it
->max_phys_ascent
+ it
->max_phys_descent
);
16132 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16133 it
->max_extra_line_spacing
);
16134 set_iterator_to_next (it
, 1);
16138 /* Does the display element fit on the line? If we truncate
16139 lines, we should draw past the right edge of the window. If
16140 we don't truncate, we want to stop so that we can display the
16141 continuation glyph before the right margin. If lines are
16142 continued, there are two possible strategies for characters
16143 resulting in more than 1 glyph (e.g. tabs): Display as many
16144 glyphs as possible in this line and leave the rest for the
16145 continuation line, or display the whole element in the next
16146 line. Original redisplay did the former, so we do it also. */
16147 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
16148 hpos_before
= it
->hpos
;
16151 if (/* Not a newline. */
16153 /* Glyphs produced fit entirely in the line. */
16154 && it
->current_x
< it
->last_visible_x
)
16156 it
->hpos
+= nglyphs
;
16157 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16158 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16159 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16160 row
->phys_height
= max (row
->phys_height
,
16161 it
->max_phys_ascent
+ it
->max_phys_descent
);
16162 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16163 it
->max_extra_line_spacing
);
16164 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
16165 row
->x
= x
- it
->first_visible_x
;
16170 struct glyph
*glyph
;
16172 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
16174 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16175 new_x
= x
+ glyph
->pixel_width
;
16177 if (/* Lines are continued. */
16178 !it
->truncate_lines_p
16179 && (/* Glyph doesn't fit on the line. */
16180 new_x
> it
->last_visible_x
16181 /* Or it fits exactly on a window system frame. */
16182 || (new_x
== it
->last_visible_x
16183 && FRAME_WINDOW_P (it
->f
))))
16185 /* End of a continued line. */
16188 || (new_x
== it
->last_visible_x
16189 && FRAME_WINDOW_P (it
->f
)))
16191 /* Current glyph is the only one on the line or
16192 fits exactly on the line. We must continue
16193 the line because we can't draw the cursor
16194 after the glyph. */
16195 row
->continued_p
= 1;
16196 it
->current_x
= new_x
;
16197 it
->continuation_lines_width
+= new_x
;
16199 if (i
== nglyphs
- 1)
16201 set_iterator_to_next (it
, 1);
16202 #ifdef HAVE_WINDOW_SYSTEM
16203 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16205 if (!get_next_display_element (it
))
16207 row
->exact_window_width_line_p
= 1;
16208 it
->continuation_lines_width
= 0;
16209 row
->continued_p
= 0;
16210 row
->ends_at_zv_p
= 1;
16212 else if (ITERATOR_AT_END_OF_LINE_P (it
))
16214 row
->continued_p
= 0;
16215 row
->exact_window_width_line_p
= 1;
16218 #endif /* HAVE_WINDOW_SYSTEM */
16221 else if (CHAR_GLYPH_PADDING_P (*glyph
)
16222 && !FRAME_WINDOW_P (it
->f
))
16224 /* A padding glyph that doesn't fit on this line.
16225 This means the whole character doesn't fit
16227 row
->used
[TEXT_AREA
] = n_glyphs_before
;
16229 /* Fill the rest of the row with continuation
16230 glyphs like in 20.x. */
16231 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
16232 < row
->glyphs
[1 + TEXT_AREA
])
16233 produce_special_glyphs (it
, IT_CONTINUATION
);
16235 row
->continued_p
= 1;
16236 it
->current_x
= x_before
;
16237 it
->continuation_lines_width
+= x_before
;
16239 /* Restore the height to what it was before the
16240 element not fitting on the line. */
16241 it
->max_ascent
= ascent
;
16242 it
->max_descent
= descent
;
16243 it
->max_phys_ascent
= phys_ascent
;
16244 it
->max_phys_descent
= phys_descent
;
16246 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
16248 /* A TAB that extends past the right edge of the
16249 window. This produces a single glyph on
16250 window system frames. We leave the glyph in
16251 this row and let it fill the row, but don't
16252 consume the TAB. */
16253 it
->continuation_lines_width
+= it
->last_visible_x
;
16254 row
->ends_in_middle_of_char_p
= 1;
16255 row
->continued_p
= 1;
16256 glyph
->pixel_width
= it
->last_visible_x
- x
;
16257 it
->starts_in_middle_of_char_p
= 1;
16261 /* Something other than a TAB that draws past
16262 the right edge of the window. Restore
16263 positions to values before the element. */
16264 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16266 /* Display continuation glyphs. */
16267 if (!FRAME_WINDOW_P (it
->f
))
16268 produce_special_glyphs (it
, IT_CONTINUATION
);
16269 row
->continued_p
= 1;
16271 it
->current_x
= x_before
;
16272 it
->continuation_lines_width
+= x
;
16273 extend_face_to_end_of_line (it
);
16275 if (nglyphs
> 1 && i
> 0)
16277 row
->ends_in_middle_of_char_p
= 1;
16278 it
->starts_in_middle_of_char_p
= 1;
16281 /* Restore the height to what it was before the
16282 element not fitting on the line. */
16283 it
->max_ascent
= ascent
;
16284 it
->max_descent
= descent
;
16285 it
->max_phys_ascent
= phys_ascent
;
16286 it
->max_phys_descent
= phys_descent
;
16291 else if (new_x
> it
->first_visible_x
)
16293 /* Increment number of glyphs actually displayed. */
16296 if (x
< it
->first_visible_x
)
16297 /* Glyph is partially visible, i.e. row starts at
16298 negative X position. */
16299 row
->x
= x
- it
->first_visible_x
;
16303 /* Glyph is completely off the left margin of the
16304 window. This should not happen because of the
16305 move_it_in_display_line at the start of this
16306 function, unless the text display area of the
16307 window is empty. */
16308 xassert (it
->first_visible_x
<= it
->last_visible_x
);
16312 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16313 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16314 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16315 row
->phys_height
= max (row
->phys_height
,
16316 it
->max_phys_ascent
+ it
->max_phys_descent
);
16317 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16318 it
->max_extra_line_spacing
);
16320 /* End of this display line if row is continued. */
16321 if (row
->continued_p
|| row
->ends_at_zv_p
)
16326 /* Is this a line end? If yes, we're also done, after making
16327 sure that a non-default face is extended up to the right
16328 margin of the window. */
16329 if (ITERATOR_AT_END_OF_LINE_P (it
))
16331 int used_before
= row
->used
[TEXT_AREA
];
16333 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
16335 #ifdef HAVE_WINDOW_SYSTEM
16336 /* Add a space at the end of the line that is used to
16337 display the cursor there. */
16338 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16339 append_space_for_newline (it
, 0);
16340 #endif /* HAVE_WINDOW_SYSTEM */
16342 /* Extend the face to the end of the line. */
16343 extend_face_to_end_of_line (it
);
16345 /* Make sure we have the position. */
16346 if (used_before
== 0)
16347 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
16349 /* Consume the line end. This skips over invisible lines. */
16350 set_iterator_to_next (it
, 1);
16351 it
->continuation_lines_width
= 0;
16355 /* Proceed with next display element. Note that this skips
16356 over lines invisible because of selective display. */
16357 set_iterator_to_next (it
, 1);
16359 /* If we truncate lines, we are done when the last displayed
16360 glyphs reach past the right margin of the window. */
16361 if (it
->truncate_lines_p
16362 && (FRAME_WINDOW_P (it
->f
)
16363 ? (it
->current_x
>= it
->last_visible_x
)
16364 : (it
->current_x
> it
->last_visible_x
)))
16366 /* Maybe add truncation glyphs. */
16367 if (!FRAME_WINDOW_P (it
->f
))
16371 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16372 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16375 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16377 row
->used
[TEXT_AREA
] = i
;
16378 produce_special_glyphs (it
, IT_TRUNCATION
);
16381 #ifdef HAVE_WINDOW_SYSTEM
16384 /* Don't truncate if we can overflow newline into fringe. */
16385 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16387 if (!get_next_display_element (it
))
16389 it
->continuation_lines_width
= 0;
16390 row
->ends_at_zv_p
= 1;
16391 row
->exact_window_width_line_p
= 1;
16394 if (ITERATOR_AT_END_OF_LINE_P (it
))
16396 row
->exact_window_width_line_p
= 1;
16397 goto at_end_of_line
;
16401 #endif /* HAVE_WINDOW_SYSTEM */
16403 row
->truncated_on_right_p
= 1;
16404 it
->continuation_lines_width
= 0;
16405 reseat_at_next_visible_line_start (it
, 0);
16406 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16407 it
->hpos
= hpos_before
;
16408 it
->current_x
= x_before
;
16413 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16414 at the left window margin. */
16415 if (it
->first_visible_x
16416 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16418 if (!FRAME_WINDOW_P (it
->f
))
16419 insert_left_trunc_glyphs (it
);
16420 row
->truncated_on_left_p
= 1;
16423 /* If the start of this line is the overlay arrow-position, then
16424 mark this glyph row as the one containing the overlay arrow.
16425 This is clearly a mess with variable size fonts. It would be
16426 better to let it be displayed like cursors under X. */
16427 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16428 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16429 !NILP (overlay_arrow_string
)))
16431 /* Overlay arrow in window redisplay is a fringe bitmap. */
16432 if (STRINGP (overlay_arrow_string
))
16434 struct glyph_row
*arrow_row
16435 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
16436 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
16437 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
16438 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
16439 struct glyph
*p2
, *end
;
16441 /* Copy the arrow glyphs. */
16442 while (glyph
< arrow_end
)
16445 /* Throw away padding glyphs. */
16447 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16448 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
16454 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
16459 xassert (INTEGERP (overlay_arrow_string
));
16460 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
16462 overlay_arrow_seen
= 1;
16465 /* Compute pixel dimensions of this line. */
16466 compute_line_metrics (it
);
16468 /* Remember the position at which this line ends. */
16469 row
->end
= it
->current
;
16471 /* Record whether this row ends inside an ellipsis. */
16472 row
->ends_in_ellipsis_p
16473 = (it
->method
== GET_FROM_DISPLAY_VECTOR
16474 && it
->ellipsis_p
);
16476 /* Save fringe bitmaps in this row. */
16477 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
16478 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
16479 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
16480 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
16482 it
->left_user_fringe_bitmap
= 0;
16483 it
->left_user_fringe_face_id
= 0;
16484 it
->right_user_fringe_bitmap
= 0;
16485 it
->right_user_fringe_face_id
= 0;
16487 /* Maybe set the cursor. */
16488 if (it
->w
->cursor
.vpos
< 0
16489 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
16490 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
16491 && cursor_row_p (it
->w
, row
))
16492 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
16494 /* Highlight trailing whitespace. */
16495 if (!NILP (Vshow_trailing_whitespace
))
16496 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
16498 /* Prepare for the next line. This line starts horizontally at (X
16499 HPOS) = (0 0). Vertical positions are incremented. As a
16500 convenience for the caller, IT->glyph_row is set to the next
16502 it
->current_x
= it
->hpos
= 0;
16503 it
->current_y
+= row
->height
;
16506 it
->start
= it
->current
;
16507 return row
->displays_text_p
;
16512 /***********************************************************************
16514 ***********************************************************************/
16516 /* Redisplay the menu bar in the frame for window W.
16518 The menu bar of X frames that don't have X toolkit support is
16519 displayed in a special window W->frame->menu_bar_window.
16521 The menu bar of terminal frames is treated specially as far as
16522 glyph matrices are concerned. Menu bar lines are not part of
16523 windows, so the update is done directly on the frame matrix rows
16524 for the menu bar. */
16527 display_menu_bar (w
)
16530 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16535 /* Don't do all this for graphical frames. */
16537 if (FRAME_W32_P (f
))
16540 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
16545 if (FRAME_MAC_P (f
))
16549 #ifdef USE_X_TOOLKIT
16550 xassert (!FRAME_WINDOW_P (f
));
16551 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
16552 it
.first_visible_x
= 0;
16553 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16554 #else /* not USE_X_TOOLKIT */
16555 if (FRAME_WINDOW_P (f
))
16557 /* Menu bar lines are displayed in the desired matrix of the
16558 dummy window menu_bar_window. */
16559 struct window
*menu_w
;
16560 xassert (WINDOWP (f
->menu_bar_window
));
16561 menu_w
= XWINDOW (f
->menu_bar_window
);
16562 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
16564 it
.first_visible_x
= 0;
16565 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16569 /* This is a TTY frame, i.e. character hpos/vpos are used as
16571 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
16573 it
.first_visible_x
= 0;
16574 it
.last_visible_x
= FRAME_COLS (f
);
16576 #endif /* not USE_X_TOOLKIT */
16578 if (! mode_line_inverse_video
)
16579 /* Force the menu-bar to be displayed in the default face. */
16580 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16582 /* Clear all rows of the menu bar. */
16583 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
16585 struct glyph_row
*row
= it
.glyph_row
+ i
;
16586 clear_glyph_row (row
);
16587 row
->enabled_p
= 1;
16588 row
->full_width_p
= 1;
16591 /* Display all items of the menu bar. */
16592 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
16593 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
16595 Lisp_Object string
;
16597 /* Stop at nil string. */
16598 string
= AREF (items
, i
+ 1);
16602 /* Remember where item was displayed. */
16603 AREF (items
, i
+ 3) = make_number (it
.hpos
);
16605 /* Display the item, pad with one space. */
16606 if (it
.current_x
< it
.last_visible_x
)
16607 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
16608 SCHARS (string
) + 1, 0, 0, -1);
16611 /* Fill out the line with spaces. */
16612 if (it
.current_x
< it
.last_visible_x
)
16613 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
16615 /* Compute the total height of the lines. */
16616 compute_line_metrics (&it
);
16621 /***********************************************************************
16623 ***********************************************************************/
16625 /* Redisplay mode lines in the window tree whose root is WINDOW. If
16626 FORCE is non-zero, redisplay mode lines unconditionally.
16627 Otherwise, redisplay only mode lines that are garbaged. Value is
16628 the number of windows whose mode lines were redisplayed. */
16631 redisplay_mode_lines (window
, force
)
16632 Lisp_Object window
;
16637 while (!NILP (window
))
16639 struct window
*w
= XWINDOW (window
);
16641 if (WINDOWP (w
->hchild
))
16642 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
16643 else if (WINDOWP (w
->vchild
))
16644 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
16646 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
16647 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
16649 struct text_pos lpoint
;
16650 struct buffer
*old
= current_buffer
;
16652 /* Set the window's buffer for the mode line display. */
16653 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16654 set_buffer_internal_1 (XBUFFER (w
->buffer
));
16656 /* Point refers normally to the selected window. For any
16657 other window, set up appropriate value. */
16658 if (!EQ (window
, selected_window
))
16660 struct text_pos pt
;
16662 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
16663 if (CHARPOS (pt
) < BEGV
)
16664 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16665 else if (CHARPOS (pt
) > (ZV
- 1))
16666 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
16668 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
16671 /* Display mode lines. */
16672 clear_glyph_matrix (w
->desired_matrix
);
16673 if (display_mode_lines (w
))
16676 w
->must_be_updated_p
= 1;
16679 /* Restore old settings. */
16680 set_buffer_internal_1 (old
);
16681 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16691 /* Display the mode and/or top line of window W. Value is the number
16692 of mode lines displayed. */
16695 display_mode_lines (w
)
16698 Lisp_Object old_selected_window
, old_selected_frame
;
16701 old_selected_frame
= selected_frame
;
16702 selected_frame
= w
->frame
;
16703 old_selected_window
= selected_window
;
16704 XSETWINDOW (selected_window
, w
);
16706 /* These will be set while the mode line specs are processed. */
16707 line_number_displayed
= 0;
16708 w
->column_number_displayed
= Qnil
;
16710 if (WINDOW_WANTS_MODELINE_P (w
))
16712 struct window
*sel_w
= XWINDOW (old_selected_window
);
16714 /* Select mode line face based on the real selected window. */
16715 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
16716 current_buffer
->mode_line_format
);
16720 if (WINDOW_WANTS_HEADER_LINE_P (w
))
16722 display_mode_line (w
, HEADER_LINE_FACE_ID
,
16723 current_buffer
->header_line_format
);
16727 selected_frame
= old_selected_frame
;
16728 selected_window
= old_selected_window
;
16733 /* Display mode or top line of window W. FACE_ID specifies which line
16734 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
16735 FORMAT is the mode line format to display. Value is the pixel
16736 height of the mode line displayed. */
16739 display_mode_line (w
, face_id
, format
)
16741 enum face_id face_id
;
16742 Lisp_Object format
;
16746 int count
= SPECPDL_INDEX ();
16748 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16749 /* Don't extend on a previously drawn mode-line.
16750 This may happen if called from pos_visible_p. */
16751 it
.glyph_row
->enabled_p
= 0;
16752 prepare_desired_row (it
.glyph_row
);
16754 it
.glyph_row
->mode_line_p
= 1;
16756 if (! mode_line_inverse_video
)
16757 /* Force the mode-line to be displayed in the default face. */
16758 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16760 record_unwind_protect (unwind_format_mode_line
,
16761 format_mode_line_unwind_data (NULL
, 0));
16763 mode_line_target
= MODE_LINE_DISPLAY
;
16765 /* Temporarily make frame's keyboard the current kboard so that
16766 kboard-local variables in the mode_line_format will get the right
16768 push_kboard (FRAME_KBOARD (it
.f
));
16769 record_unwind_save_match_data ();
16770 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16773 unbind_to (count
, Qnil
);
16775 /* Fill up with spaces. */
16776 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
16778 compute_line_metrics (&it
);
16779 it
.glyph_row
->full_width_p
= 1;
16780 it
.glyph_row
->continued_p
= 0;
16781 it
.glyph_row
->truncated_on_left_p
= 0;
16782 it
.glyph_row
->truncated_on_right_p
= 0;
16784 /* Make a 3D mode-line have a shadow at its right end. */
16785 face
= FACE_FROM_ID (it
.f
, face_id
);
16786 extend_face_to_end_of_line (&it
);
16787 if (face
->box
!= FACE_NO_BOX
)
16789 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
16790 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
16791 last
->right_box_line_p
= 1;
16794 return it
.glyph_row
->height
;
16797 /* Move element ELT in LIST to the front of LIST.
16798 Return the updated list. */
16801 move_elt_to_front (elt
, list
)
16802 Lisp_Object elt
, list
;
16804 register Lisp_Object tail
, prev
;
16805 register Lisp_Object tem
;
16809 while (CONSP (tail
))
16815 /* Splice out the link TAIL. */
16817 list
= XCDR (tail
);
16819 Fsetcdr (prev
, XCDR (tail
));
16821 /* Now make it the first. */
16822 Fsetcdr (tail
, list
);
16827 tail
= XCDR (tail
);
16831 /* Not found--return unchanged LIST. */
16835 /* Contribute ELT to the mode line for window IT->w. How it
16836 translates into text depends on its data type.
16838 IT describes the display environment in which we display, as usual.
16840 DEPTH is the depth in recursion. It is used to prevent
16841 infinite recursion here.
16843 FIELD_WIDTH is the number of characters the display of ELT should
16844 occupy in the mode line, and PRECISION is the maximum number of
16845 characters to display from ELT's representation. See
16846 display_string for details.
16848 Returns the hpos of the end of the text generated by ELT.
16850 PROPS is a property list to add to any string we encounter.
16852 If RISKY is nonzero, remove (disregard) any properties in any string
16853 we encounter, and ignore :eval and :propertize.
16855 The global variable `mode_line_target' determines whether the
16856 output is passed to `store_mode_line_noprop',
16857 `store_mode_line_string', or `display_string'. */
16860 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
16863 int field_width
, precision
;
16864 Lisp_Object elt
, props
;
16867 int n
= 0, field
, prec
;
16872 elt
= build_string ("*too-deep*");
16876 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
16880 /* A string: output it and check for %-constructs within it. */
16884 if (SCHARS (elt
) > 0
16885 && (!NILP (props
) || risky
))
16887 Lisp_Object oprops
, aelt
;
16888 oprops
= Ftext_properties_at (make_number (0), elt
);
16890 /* If the starting string's properties are not what
16891 we want, translate the string. Also, if the string
16892 is risky, do that anyway. */
16894 if (NILP (Fequal (props
, oprops
)) || risky
)
16896 /* If the starting string has properties,
16897 merge the specified ones onto the existing ones. */
16898 if (! NILP (oprops
) && !risky
)
16902 oprops
= Fcopy_sequence (oprops
);
16904 while (CONSP (tem
))
16906 oprops
= Fplist_put (oprops
, XCAR (tem
),
16907 XCAR (XCDR (tem
)));
16908 tem
= XCDR (XCDR (tem
));
16913 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
16914 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
16916 /* AELT is what we want. Move it to the front
16917 without consing. */
16919 mode_line_proptrans_alist
16920 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
16926 /* If AELT has the wrong props, it is useless.
16927 so get rid of it. */
16929 mode_line_proptrans_alist
16930 = Fdelq (aelt
, mode_line_proptrans_alist
);
16932 elt
= Fcopy_sequence (elt
);
16933 Fset_text_properties (make_number (0), Flength (elt
),
16935 /* Add this item to mode_line_proptrans_alist. */
16936 mode_line_proptrans_alist
16937 = Fcons (Fcons (elt
, props
),
16938 mode_line_proptrans_alist
);
16939 /* Truncate mode_line_proptrans_alist
16940 to at most 50 elements. */
16941 tem
= Fnthcdr (make_number (50),
16942 mode_line_proptrans_alist
);
16944 XSETCDR (tem
, Qnil
);
16953 prec
= precision
- n
;
16954 switch (mode_line_target
)
16956 case MODE_LINE_NOPROP
:
16957 case MODE_LINE_TITLE
:
16958 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
16960 case MODE_LINE_STRING
:
16961 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
16963 case MODE_LINE_DISPLAY
:
16964 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
16965 0, prec
, 0, STRING_MULTIBYTE (elt
));
16972 /* Handle the non-literal case. */
16974 while ((precision
<= 0 || n
< precision
)
16975 && SREF (elt
, offset
) != 0
16976 && (mode_line_target
!= MODE_LINE_DISPLAY
16977 || it
->current_x
< it
->last_visible_x
))
16979 int last_offset
= offset
;
16981 /* Advance to end of string or next format specifier. */
16982 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
16985 if (offset
- 1 != last_offset
)
16987 int nchars
, nbytes
;
16989 /* Output to end of string or up to '%'. Field width
16990 is length of string. Don't output more than
16991 PRECISION allows us. */
16994 prec
= c_string_width (SDATA (elt
) + last_offset
,
16995 offset
- last_offset
, precision
- n
,
16998 switch (mode_line_target
)
17000 case MODE_LINE_NOPROP
:
17001 case MODE_LINE_TITLE
:
17002 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
17004 case MODE_LINE_STRING
:
17006 int bytepos
= last_offset
;
17007 int charpos
= string_byte_to_char (elt
, bytepos
);
17008 int endpos
= (precision
<= 0
17009 ? string_byte_to_char (elt
, offset
)
17010 : charpos
+ nchars
);
17012 n
+= store_mode_line_string (NULL
,
17013 Fsubstring (elt
, make_number (charpos
),
17014 make_number (endpos
)),
17018 case MODE_LINE_DISPLAY
:
17020 int bytepos
= last_offset
;
17021 int charpos
= string_byte_to_char (elt
, bytepos
);
17023 if (precision
<= 0)
17024 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
17025 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
17027 STRING_MULTIBYTE (elt
));
17032 else /* c == '%' */
17034 int percent_position
= offset
;
17036 /* Get the specified minimum width. Zero means
17039 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
17040 field
= field
* 10 + c
- '0';
17042 /* Don't pad beyond the total padding allowed. */
17043 if (field_width
- n
> 0 && field
> field_width
- n
)
17044 field
= field_width
- n
;
17046 /* Note that either PRECISION <= 0 or N < PRECISION. */
17047 prec
= precision
- n
;
17050 n
+= display_mode_element (it
, depth
, field
, prec
,
17051 Vglobal_mode_string
, props
,
17056 int bytepos
, charpos
;
17057 unsigned char *spec
;
17059 bytepos
= percent_position
;
17060 charpos
= (STRING_MULTIBYTE (elt
)
17061 ? string_byte_to_char (elt
, bytepos
)
17065 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
17067 switch (mode_line_target
)
17069 case MODE_LINE_NOPROP
:
17070 case MODE_LINE_TITLE
:
17071 n
+= store_mode_line_noprop (spec
, field
, prec
);
17073 case MODE_LINE_STRING
:
17075 int len
= strlen (spec
);
17076 Lisp_Object tem
= make_string (spec
, len
);
17077 props
= Ftext_properties_at (make_number (charpos
), elt
);
17078 /* Should only keep face property in props */
17079 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
17082 case MODE_LINE_DISPLAY
:
17084 int nglyphs_before
, nwritten
;
17086 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17087 nwritten
= display_string (spec
, Qnil
, elt
,
17092 /* Assign to the glyphs written above the
17093 string where the `%x' came from, position
17097 struct glyph
*glyph
17098 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
17102 for (i
= 0; i
< nwritten
; ++i
)
17104 glyph
[i
].object
= elt
;
17105 glyph
[i
].charpos
= charpos
;
17122 /* A symbol: process the value of the symbol recursively
17123 as if it appeared here directly. Avoid error if symbol void.
17124 Special case: if value of symbol is a string, output the string
17127 register Lisp_Object tem
;
17129 /* If the variable is not marked as risky to set
17130 then its contents are risky to use. */
17131 if (NILP (Fget (elt
, Qrisky_local_variable
)))
17134 tem
= Fboundp (elt
);
17137 tem
= Fsymbol_value (elt
);
17138 /* If value is a string, output that string literally:
17139 don't check for % within it. */
17143 if (!EQ (tem
, elt
))
17145 /* Give up right away for nil or t. */
17155 register Lisp_Object car
, tem
;
17157 /* A cons cell: five distinct cases.
17158 If first element is :eval or :propertize, do something special.
17159 If first element is a string or a cons, process all the elements
17160 and effectively concatenate them.
17161 If first element is a negative number, truncate displaying cdr to
17162 at most that many characters. If positive, pad (with spaces)
17163 to at least that many characters.
17164 If first element is a symbol, process the cadr or caddr recursively
17165 according to whether the symbol's value is non-nil or nil. */
17167 if (EQ (car
, QCeval
))
17169 /* An element of the form (:eval FORM) means evaluate FORM
17170 and use the result as mode line elements. */
17175 if (CONSP (XCDR (elt
)))
17178 spec
= safe_eval (XCAR (XCDR (elt
)));
17179 n
+= display_mode_element (it
, depth
, field_width
- n
,
17180 precision
- n
, spec
, props
,
17184 else if (EQ (car
, QCpropertize
))
17186 /* An element of the form (:propertize ELT PROPS...)
17187 means display ELT but applying properties PROPS. */
17192 if (CONSP (XCDR (elt
)))
17193 n
+= display_mode_element (it
, depth
, field_width
- n
,
17194 precision
- n
, XCAR (XCDR (elt
)),
17195 XCDR (XCDR (elt
)), risky
);
17197 else if (SYMBOLP (car
))
17199 tem
= Fboundp (car
);
17203 /* elt is now the cdr, and we know it is a cons cell.
17204 Use its car if CAR has a non-nil value. */
17207 tem
= Fsymbol_value (car
);
17214 /* Symbol's value is nil (or symbol is unbound)
17215 Get the cddr of the original list
17216 and if possible find the caddr and use that. */
17220 else if (!CONSP (elt
))
17225 else if (INTEGERP (car
))
17227 register int lim
= XINT (car
);
17231 /* Negative int means reduce maximum width. */
17232 if (precision
<= 0)
17235 precision
= min (precision
, -lim
);
17239 /* Padding specified. Don't let it be more than
17240 current maximum. */
17242 lim
= min (precision
, lim
);
17244 /* If that's more padding than already wanted, queue it.
17245 But don't reduce padding already specified even if
17246 that is beyond the current truncation point. */
17247 field_width
= max (lim
, field_width
);
17251 else if (STRINGP (car
) || CONSP (car
))
17253 register int limit
= 50;
17254 /* Limit is to protect against circular lists. */
17257 && (precision
<= 0 || n
< precision
))
17259 n
+= display_mode_element (it
, depth
,
17260 /* Do padding only after the last
17261 element in the list. */
17262 (! CONSP (XCDR (elt
))
17265 precision
- n
, XCAR (elt
),
17275 elt
= build_string ("*invalid*");
17279 /* Pad to FIELD_WIDTH. */
17280 if (field_width
> 0 && n
< field_width
)
17282 switch (mode_line_target
)
17284 case MODE_LINE_NOPROP
:
17285 case MODE_LINE_TITLE
:
17286 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
17288 case MODE_LINE_STRING
:
17289 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
17291 case MODE_LINE_DISPLAY
:
17292 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
17301 /* Store a mode-line string element in mode_line_string_list.
17303 If STRING is non-null, display that C string. Otherwise, the Lisp
17304 string LISP_STRING is displayed.
17306 FIELD_WIDTH is the minimum number of output glyphs to produce.
17307 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17308 with spaces. FIELD_WIDTH <= 0 means don't pad.
17310 PRECISION is the maximum number of characters to output from
17311 STRING. PRECISION <= 0 means don't truncate the string.
17313 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
17314 properties to the string.
17316 PROPS are the properties to add to the string.
17317 The mode_line_string_face face property is always added to the string.
17321 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
17323 Lisp_Object lisp_string
;
17332 if (string
!= NULL
)
17334 len
= strlen (string
);
17335 if (precision
> 0 && len
> precision
)
17337 lisp_string
= make_string (string
, len
);
17339 props
= mode_line_string_face_prop
;
17340 else if (!NILP (mode_line_string_face
))
17342 Lisp_Object face
= Fplist_get (props
, Qface
);
17343 props
= Fcopy_sequence (props
);
17345 face
= mode_line_string_face
;
17347 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17348 props
= Fplist_put (props
, Qface
, face
);
17350 Fadd_text_properties (make_number (0), make_number (len
),
17351 props
, lisp_string
);
17355 len
= XFASTINT (Flength (lisp_string
));
17356 if (precision
> 0 && len
> precision
)
17359 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
17362 if (!NILP (mode_line_string_face
))
17366 props
= Ftext_properties_at (make_number (0), lisp_string
);
17367 face
= Fplist_get (props
, Qface
);
17369 face
= mode_line_string_face
;
17371 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17372 props
= Fcons (Qface
, Fcons (face
, Qnil
));
17374 lisp_string
= Fcopy_sequence (lisp_string
);
17377 Fadd_text_properties (make_number (0), make_number (len
),
17378 props
, lisp_string
);
17383 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17387 if (field_width
> len
)
17389 field_width
-= len
;
17390 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17392 Fadd_text_properties (make_number (0), make_number (field_width
),
17393 props
, lisp_string
);
17394 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17402 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17404 doc
: /* Format a string out of a mode line format specification.
17405 First arg FORMAT specifies the mode line format (see `mode-line-format'
17406 for details) to use.
17408 Optional second arg FACE specifies the face property to put
17409 on all characters for which no face is specified.
17410 The value t means whatever face the window's mode line currently uses
17411 \(either `mode-line' or `mode-line-inactive', depending).
17412 A value of nil means the default is no face property.
17413 If FACE is an integer, the value string has no text properties.
17415 Optional third and fourth args WINDOW and BUFFER specify the window
17416 and buffer to use as the context for the formatting (defaults
17417 are the selected window and the window's buffer). */)
17418 (format
, face
, window
, buffer
)
17419 Lisp_Object format
, face
, window
, buffer
;
17424 struct buffer
*old_buffer
= NULL
;
17426 int no_props
= INTEGERP (face
);
17427 int count
= SPECPDL_INDEX ();
17429 int string_start
= 0;
17432 window
= selected_window
;
17433 CHECK_WINDOW (window
);
17434 w
= XWINDOW (window
);
17437 buffer
= w
->buffer
;
17438 CHECK_BUFFER (buffer
);
17440 /* Make formatting the modeline a non-op when noninteractive, otherwise
17441 there will be problems later caused by a partially initialized frame. */
17442 if (NILP (format
) || noninteractive
)
17443 return empty_unibyte_string
;
17451 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
17452 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
17456 face_id
= DEFAULT_FACE_ID
;
17458 if (XBUFFER (buffer
) != current_buffer
)
17459 old_buffer
= current_buffer
;
17461 /* Save things including mode_line_proptrans_alist,
17462 and set that to nil so that we don't alter the outer value. */
17463 record_unwind_protect (unwind_format_mode_line
,
17464 format_mode_line_unwind_data (old_buffer
, 1));
17465 mode_line_proptrans_alist
= Qnil
;
17468 set_buffer_internal_1 (XBUFFER (buffer
));
17470 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17474 mode_line_target
= MODE_LINE_NOPROP
;
17475 mode_line_string_face_prop
= Qnil
;
17476 mode_line_string_list
= Qnil
;
17477 string_start
= MODE_LINE_NOPROP_LEN (0);
17481 mode_line_target
= MODE_LINE_STRING
;
17482 mode_line_string_list
= Qnil
;
17483 mode_line_string_face
= face
;
17484 mode_line_string_face_prop
17485 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
17488 push_kboard (FRAME_KBOARD (it
.f
));
17489 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17494 len
= MODE_LINE_NOPROP_LEN (string_start
);
17495 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
17499 mode_line_string_list
= Fnreverse (mode_line_string_list
);
17500 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
17501 empty_unibyte_string
);
17504 unbind_to (count
, Qnil
);
17508 /* Write a null-terminated, right justified decimal representation of
17509 the positive integer D to BUF using a minimal field width WIDTH. */
17512 pint2str (buf
, width
, d
)
17513 register char *buf
;
17514 register int width
;
17517 register char *p
= buf
;
17525 *p
++ = d
% 10 + '0';
17530 for (width
-= (int) (p
- buf
); width
> 0; --width
)
17541 /* Write a null-terminated, right justified decimal and "human
17542 readable" representation of the nonnegative integer D to BUF using
17543 a minimal field width WIDTH. D should be smaller than 999.5e24. */
17545 static const char power_letter
[] =
17559 pint2hrstr (buf
, width
, d
)
17564 /* We aim to represent the nonnegative integer D as
17565 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
17568 /* -1 means: do not use TENTHS. */
17572 /* Length of QUOTIENT.TENTHS as a string. */
17578 if (1000 <= quotient
)
17580 /* Scale to the appropriate EXPONENT. */
17583 remainder
= quotient
% 1000;
17587 while (1000 <= quotient
);
17589 /* Round to nearest and decide whether to use TENTHS or not. */
17592 tenths
= remainder
/ 100;
17593 if (50 <= remainder
% 100)
17600 if (quotient
== 10)
17608 if (500 <= remainder
)
17610 if (quotient
< 999)
17621 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
17622 if (tenths
== -1 && quotient
<= 99)
17629 p
= psuffix
= buf
+ max (width
, length
);
17631 /* Print EXPONENT. */
17633 *psuffix
++ = power_letter
[exponent
];
17636 /* Print TENTHS. */
17639 *--p
= '0' + tenths
;
17643 /* Print QUOTIENT. */
17646 int digit
= quotient
% 10;
17647 *--p
= '0' + digit
;
17649 while ((quotient
/= 10) != 0);
17651 /* Print leading spaces. */
17656 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
17657 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
17658 type of CODING_SYSTEM. Return updated pointer into BUF. */
17660 static unsigned char invalid_eol_type
[] = "(*invalid*)";
17663 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
17664 Lisp_Object coding_system
;
17665 register char *buf
;
17669 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
17670 const unsigned char *eol_str
;
17672 /* The EOL conversion we are using. */
17673 Lisp_Object eoltype
;
17675 val
= Fget (coding_system
, Qcoding_system
);
17678 if (!VECTORP (val
)) /* Not yet decided. */
17683 eoltype
= eol_mnemonic_undecided
;
17684 /* Don't mention EOL conversion if it isn't decided. */
17688 Lisp_Object eolvalue
;
17690 eolvalue
= Fget (coding_system
, Qeol_type
);
17693 *buf
++ = XFASTINT (AREF (val
, 1));
17697 /* The EOL conversion that is normal on this system. */
17699 if (NILP (eolvalue
)) /* Not yet decided. */
17700 eoltype
= eol_mnemonic_undecided
;
17701 else if (VECTORP (eolvalue
)) /* Not yet decided. */
17702 eoltype
= eol_mnemonic_undecided
;
17703 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
17704 eoltype
= (XFASTINT (eolvalue
) == 0
17705 ? eol_mnemonic_unix
17706 : (XFASTINT (eolvalue
) == 1
17707 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
17713 /* Mention the EOL conversion if it is not the usual one. */
17714 if (STRINGP (eoltype
))
17716 eol_str
= SDATA (eoltype
);
17717 eol_str_len
= SBYTES (eoltype
);
17719 else if (INTEGERP (eoltype
)
17720 && CHAR_VALID_P (XINT (eoltype
), 0))
17722 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
17723 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
17728 eol_str
= invalid_eol_type
;
17729 eol_str_len
= sizeof (invalid_eol_type
) - 1;
17731 bcopy (eol_str
, buf
, eol_str_len
);
17732 buf
+= eol_str_len
;
17738 /* Return a string for the output of a mode line %-spec for window W,
17739 generated by character C. PRECISION >= 0 means don't return a
17740 string longer than that value. FIELD_WIDTH > 0 means pad the
17741 string returned with spaces to that value. Return 1 in *MULTIBYTE
17742 if the result is multibyte text.
17744 Note we operate on the current buffer for most purposes,
17745 the exception being w->base_line_pos. */
17747 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
17750 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
17753 int field_width
, precision
;
17757 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17758 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
17759 struct buffer
*b
= current_buffer
;
17767 if (!NILP (b
->read_only
))
17769 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17774 /* This differs from %* only for a modified read-only buffer. */
17775 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17777 if (!NILP (b
->read_only
))
17782 /* This differs from %* in ignoring read-only-ness. */
17783 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17795 if (command_loop_level
> 5)
17797 p
= decode_mode_spec_buf
;
17798 for (i
= 0; i
< command_loop_level
; i
++)
17801 return decode_mode_spec_buf
;
17809 if (command_loop_level
> 5)
17811 p
= decode_mode_spec_buf
;
17812 for (i
= 0; i
< command_loop_level
; i
++)
17815 return decode_mode_spec_buf
;
17822 /* Let lots_of_dashes be a string of infinite length. */
17823 if (mode_line_target
== MODE_LINE_NOPROP
||
17824 mode_line_target
== MODE_LINE_STRING
)
17826 if (field_width
<= 0
17827 || field_width
> sizeof (lots_of_dashes
))
17829 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
17830 decode_mode_spec_buf
[i
] = '-';
17831 decode_mode_spec_buf
[i
] = '\0';
17832 return decode_mode_spec_buf
;
17835 return lots_of_dashes
;
17843 /* %c and %l are ignored in `frame-title-format'.
17844 (In redisplay_internal, the frame title is drawn _before_ the
17845 windows are updated, so the stuff which depends on actual
17846 window contents (such as %l) may fail to render properly, or
17847 even crash emacs.) */
17848 if (mode_line_target
== MODE_LINE_TITLE
)
17852 int col
= (int) current_column (); /* iftc */
17853 w
->column_number_displayed
= make_number (col
);
17854 pint2str (decode_mode_spec_buf
, field_width
, col
);
17855 return decode_mode_spec_buf
;
17859 #ifndef SYSTEM_MALLOC
17861 if (NILP (Vmemory_full
))
17864 return "!MEM FULL! ";
17871 /* %F displays the frame name. */
17872 if (!NILP (f
->title
))
17873 return (char *) SDATA (f
->title
);
17874 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
17875 return (char *) SDATA (f
->name
);
17884 int size
= ZV
- BEGV
;
17885 pint2str (decode_mode_spec_buf
, field_width
, size
);
17886 return decode_mode_spec_buf
;
17891 int size
= ZV
- BEGV
;
17892 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
17893 return decode_mode_spec_buf
;
17898 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
17899 int topline
, nlines
, junk
, height
;
17901 /* %c and %l are ignored in `frame-title-format'. */
17902 if (mode_line_target
== MODE_LINE_TITLE
)
17905 startpos
= XMARKER (w
->start
)->charpos
;
17906 startpos_byte
= marker_byte_position (w
->start
);
17907 height
= WINDOW_TOTAL_LINES (w
);
17909 /* If we decided that this buffer isn't suitable for line numbers,
17910 don't forget that too fast. */
17911 if (EQ (w
->base_line_pos
, w
->buffer
))
17913 /* But do forget it, if the window shows a different buffer now. */
17914 else if (BUFFERP (w
->base_line_pos
))
17915 w
->base_line_pos
= Qnil
;
17917 /* If the buffer is very big, don't waste time. */
17918 if (INTEGERP (Vline_number_display_limit
)
17919 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
17921 w
->base_line_pos
= Qnil
;
17922 w
->base_line_number
= Qnil
;
17926 if (!NILP (w
->base_line_number
)
17927 && !NILP (w
->base_line_pos
)
17928 && XFASTINT (w
->base_line_pos
) <= startpos
)
17930 line
= XFASTINT (w
->base_line_number
);
17931 linepos
= XFASTINT (w
->base_line_pos
);
17932 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
17937 linepos
= BUF_BEGV (b
);
17938 linepos_byte
= BUF_BEGV_BYTE (b
);
17941 /* Count lines from base line to window start position. */
17942 nlines
= display_count_lines (linepos
, linepos_byte
,
17946 topline
= nlines
+ line
;
17948 /* Determine a new base line, if the old one is too close
17949 or too far away, or if we did not have one.
17950 "Too close" means it's plausible a scroll-down would
17951 go back past it. */
17952 if (startpos
== BUF_BEGV (b
))
17954 w
->base_line_number
= make_number (topline
);
17955 w
->base_line_pos
= make_number (BUF_BEGV (b
));
17957 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
17958 || linepos
== BUF_BEGV (b
))
17960 int limit
= BUF_BEGV (b
);
17961 int limit_byte
= BUF_BEGV_BYTE (b
);
17963 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
17965 if (startpos
- distance
> limit
)
17967 limit
= startpos
- distance
;
17968 limit_byte
= CHAR_TO_BYTE (limit
);
17971 nlines
= display_count_lines (startpos
, startpos_byte
,
17973 - (height
* 2 + 30),
17975 /* If we couldn't find the lines we wanted within
17976 line_number_display_limit_width chars per line,
17977 give up on line numbers for this window. */
17978 if (position
== limit_byte
&& limit
== startpos
- distance
)
17980 w
->base_line_pos
= w
->buffer
;
17981 w
->base_line_number
= Qnil
;
17985 w
->base_line_number
= make_number (topline
- nlines
);
17986 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
17989 /* Now count lines from the start pos to point. */
17990 nlines
= display_count_lines (startpos
, startpos_byte
,
17991 PT_BYTE
, PT
, &junk
);
17993 /* Record that we did display the line number. */
17994 line_number_displayed
= 1;
17996 /* Make the string to show. */
17997 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
17998 return decode_mode_spec_buf
;
18001 char* p
= decode_mode_spec_buf
;
18002 int pad
= field_width
- 2;
18008 return decode_mode_spec_buf
;
18014 obj
= b
->mode_name
;
18018 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
18024 int pos
= marker_position (w
->start
);
18025 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18027 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
18029 if (pos
<= BUF_BEGV (b
))
18034 else if (pos
<= BUF_BEGV (b
))
18038 if (total
> 1000000)
18039 /* Do it differently for a large value, to avoid overflow. */
18040 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18042 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18043 /* We can't normally display a 3-digit number,
18044 so get us a 2-digit number that is close. */
18047 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18048 return decode_mode_spec_buf
;
18052 /* Display percentage of size above the bottom of the screen. */
18055 int toppos
= marker_position (w
->start
);
18056 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
18057 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18059 if (botpos
>= BUF_ZV (b
))
18061 if (toppos
<= BUF_BEGV (b
))
18068 if (total
> 1000000)
18069 /* Do it differently for a large value, to avoid overflow. */
18070 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18072 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18073 /* We can't normally display a 3-digit number,
18074 so get us a 2-digit number that is close. */
18077 if (toppos
<= BUF_BEGV (b
))
18078 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
18080 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18081 return decode_mode_spec_buf
;
18086 /* status of process */
18087 obj
= Fget_buffer_process (Fcurrent_buffer ());
18089 return "no process";
18090 #ifdef subprocesses
18091 obj
= Fsymbol_name (Fprocess_status (obj
));
18098 val
= call1 (intern ("file-remote-p"), current_buffer
->directory
);
18105 case 't': /* indicate TEXT or BINARY */
18106 #ifdef MODE_LINE_BINARY_TEXT
18107 return MODE_LINE_BINARY_TEXT (b
);
18113 /* coding-system (not including end-of-line format) */
18115 /* coding-system (including end-of-line type) */
18117 int eol_flag
= (c
== 'Z');
18118 char *p
= decode_mode_spec_buf
;
18120 if (! FRAME_WINDOW_P (f
))
18122 /* No need to mention EOL here--the terminal never needs
18123 to do EOL conversion. */
18124 p
= decode_mode_spec_coding (FRAME_KEYBOARD_CODING (f
)->symbol
, p
, 0);
18125 p
= decode_mode_spec_coding (FRAME_TERMINAL_CODING (f
)->symbol
, p
, 0);
18127 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
18130 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
18131 #ifdef subprocesses
18132 obj
= Fget_buffer_process (Fcurrent_buffer ());
18133 if (PROCESSP (obj
))
18135 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
18137 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
18140 #endif /* subprocesses */
18143 return decode_mode_spec_buf
;
18149 *multibyte
= STRING_MULTIBYTE (obj
);
18150 return (char *) SDATA (obj
);
18157 /* Count up to COUNT lines starting from START / START_BYTE.
18158 But don't go beyond LIMIT_BYTE.
18159 Return the number of lines thus found (always nonnegative).
18161 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
18164 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
18165 int start
, start_byte
, limit_byte
, count
;
18168 register unsigned char *cursor
;
18169 unsigned char *base
;
18171 register int ceiling
;
18172 register unsigned char *ceiling_addr
;
18173 int orig_count
= count
;
18175 /* If we are not in selective display mode,
18176 check only for newlines. */
18177 int selective_display
= (!NILP (current_buffer
->selective_display
)
18178 && !INTEGERP (current_buffer
->selective_display
));
18182 while (start_byte
< limit_byte
)
18184 ceiling
= BUFFER_CEILING_OF (start_byte
);
18185 ceiling
= min (limit_byte
- 1, ceiling
);
18186 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
18187 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
18190 if (selective_display
)
18191 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
18194 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
18197 if (cursor
!= ceiling_addr
)
18201 start_byte
+= cursor
- base
+ 1;
18202 *byte_pos_ptr
= start_byte
;
18206 if (++cursor
== ceiling_addr
)
18212 start_byte
+= cursor
- base
;
18217 while (start_byte
> limit_byte
)
18219 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
18220 ceiling
= max (limit_byte
, ceiling
);
18221 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
18222 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
18225 if (selective_display
)
18226 while (--cursor
!= ceiling_addr
18227 && *cursor
!= '\n' && *cursor
!= 015)
18230 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
18233 if (cursor
!= ceiling_addr
)
18237 start_byte
+= cursor
- base
+ 1;
18238 *byte_pos_ptr
= start_byte
;
18239 /* When scanning backwards, we should
18240 not count the newline posterior to which we stop. */
18241 return - orig_count
- 1;
18247 /* Here we add 1 to compensate for the last decrement
18248 of CURSOR, which took it past the valid range. */
18249 start_byte
+= cursor
- base
+ 1;
18253 *byte_pos_ptr
= limit_byte
;
18256 return - orig_count
+ count
;
18257 return orig_count
- count
;
18263 /***********************************************************************
18265 ***********************************************************************/
18267 /* Display a NUL-terminated string, starting with index START.
18269 If STRING is non-null, display that C string. Otherwise, the Lisp
18270 string LISP_STRING is displayed.
18272 If FACE_STRING is not nil, FACE_STRING_POS is a position in
18273 FACE_STRING. Display STRING or LISP_STRING with the face at
18274 FACE_STRING_POS in FACE_STRING:
18276 Display the string in the environment given by IT, but use the
18277 standard display table, temporarily.
18279 FIELD_WIDTH is the minimum number of output glyphs to produce.
18280 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18281 with spaces. If STRING has more characters, more than FIELD_WIDTH
18282 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
18284 PRECISION is the maximum number of characters to output from
18285 STRING. PRECISION < 0 means don't truncate the string.
18287 This is roughly equivalent to printf format specifiers:
18289 FIELD_WIDTH PRECISION PRINTF
18290 ----------------------------------------
18296 MULTIBYTE zero means do not display multibyte chars, > 0 means do
18297 display them, and < 0 means obey the current buffer's value of
18298 enable_multibyte_characters.
18300 Value is the number of columns displayed. */
18303 display_string (string
, lisp_string
, face_string
, face_string_pos
,
18304 start
, it
, field_width
, precision
, max_x
, multibyte
)
18305 unsigned char *string
;
18306 Lisp_Object lisp_string
;
18307 Lisp_Object face_string
;
18308 int face_string_pos
;
18311 int field_width
, precision
, max_x
;
18314 int hpos_at_start
= it
->hpos
;
18315 int saved_face_id
= it
->face_id
;
18316 struct glyph_row
*row
= it
->glyph_row
;
18318 /* Initialize the iterator IT for iteration over STRING beginning
18319 with index START. */
18320 reseat_to_string (it
, string
, lisp_string
, start
,
18321 precision
, field_width
, multibyte
);
18323 /* If displaying STRING, set up the face of the iterator
18324 from LISP_STRING, if that's given. */
18325 if (STRINGP (face_string
))
18331 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
18332 0, it
->region_beg_charpos
,
18333 it
->region_end_charpos
,
18334 &endptr
, it
->base_face_id
, 0);
18335 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18336 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
18339 /* Set max_x to the maximum allowed X position. Don't let it go
18340 beyond the right edge of the window. */
18342 max_x
= it
->last_visible_x
;
18344 max_x
= min (max_x
, it
->last_visible_x
);
18346 /* Skip over display elements that are not visible. because IT->w is
18348 if (it
->current_x
< it
->first_visible_x
)
18349 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
18350 MOVE_TO_POS
| MOVE_TO_X
);
18352 row
->ascent
= it
->max_ascent
;
18353 row
->height
= it
->max_ascent
+ it
->max_descent
;
18354 row
->phys_ascent
= it
->max_phys_ascent
;
18355 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18356 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18358 /* This condition is for the case that we are called with current_x
18359 past last_visible_x. */
18360 while (it
->current_x
< max_x
)
18362 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
18364 /* Get the next display element. */
18365 if (!get_next_display_element (it
))
18368 /* Produce glyphs. */
18369 x_before
= it
->current_x
;
18370 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18371 PRODUCE_GLYPHS (it
);
18373 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
18376 while (i
< nglyphs
)
18378 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18380 if (!it
->truncate_lines_p
18381 && x
+ glyph
->pixel_width
> max_x
)
18383 /* End of continued line or max_x reached. */
18384 if (CHAR_GLYPH_PADDING_P (*glyph
))
18386 /* A wide character is unbreakable. */
18387 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18388 it
->current_x
= x_before
;
18392 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18397 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
18399 /* Glyph is at least partially visible. */
18401 if (x
< it
->first_visible_x
)
18402 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18406 /* Glyph is off the left margin of the display area.
18407 Should not happen. */
18411 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18412 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18413 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18414 row
->phys_height
= max (row
->phys_height
,
18415 it
->max_phys_ascent
+ it
->max_phys_descent
);
18416 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18417 it
->max_extra_line_spacing
);
18418 x
+= glyph
->pixel_width
;
18422 /* Stop if max_x reached. */
18426 /* Stop at line ends. */
18427 if (ITERATOR_AT_END_OF_LINE_P (it
))
18429 it
->continuation_lines_width
= 0;
18433 set_iterator_to_next (it
, 1);
18435 /* Stop if truncating at the right edge. */
18436 if (it
->truncate_lines_p
18437 && it
->current_x
>= it
->last_visible_x
)
18439 /* Add truncation mark, but don't do it if the line is
18440 truncated at a padding space. */
18441 if (IT_CHARPOS (*it
) < it
->string_nchars
)
18443 if (!FRAME_WINDOW_P (it
->f
))
18447 if (it
->current_x
> it
->last_visible_x
)
18449 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18450 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18452 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18454 row
->used
[TEXT_AREA
] = i
;
18455 produce_special_glyphs (it
, IT_TRUNCATION
);
18458 produce_special_glyphs (it
, IT_TRUNCATION
);
18460 it
->glyph_row
->truncated_on_right_p
= 1;
18466 /* Maybe insert a truncation at the left. */
18467 if (it
->first_visible_x
18468 && IT_CHARPOS (*it
) > 0)
18470 if (!FRAME_WINDOW_P (it
->f
))
18471 insert_left_trunc_glyphs (it
);
18472 it
->glyph_row
->truncated_on_left_p
= 1;
18475 it
->face_id
= saved_face_id
;
18477 /* Value is number of columns displayed. */
18478 return it
->hpos
- hpos_at_start
;
18483 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
18484 appears as an element of LIST or as the car of an element of LIST.
18485 If PROPVAL is a list, compare each element against LIST in that
18486 way, and return 1/2 if any element of PROPVAL is found in LIST.
18487 Otherwise return 0. This function cannot quit.
18488 The return value is 2 if the text is invisible but with an ellipsis
18489 and 1 if it's invisible and without an ellipsis. */
18492 invisible_p (propval
, list
)
18493 register Lisp_Object propval
;
18496 register Lisp_Object tail
, proptail
;
18498 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18500 register Lisp_Object tem
;
18502 if (EQ (propval
, tem
))
18504 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
18505 return NILP (XCDR (tem
)) ? 1 : 2;
18508 if (CONSP (propval
))
18510 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
18512 Lisp_Object propelt
;
18513 propelt
= XCAR (proptail
);
18514 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18516 register Lisp_Object tem
;
18518 if (EQ (propelt
, tem
))
18520 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
18521 return NILP (XCDR (tem
)) ? 1 : 2;
18529 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
18530 doc
: /* Non-nil if the property makes the text invisible.
18531 POS-OR-PROP can be a marker or number, in which case it is taken to be
18532 a position in the current buffer and the value of the `invisible' property
18533 is checked; or it can be some other value, which is then presumed to be the
18534 value of the `invisible' property of the text of interest.
18535 The non-nil value returned can be t for truly invisible text or something
18536 else if the text is replaced by an ellipsis. */)
18538 Lisp_Object pos_or_prop
;
18541 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
18542 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
18544 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
18545 return (invis
== 0 ? Qnil
18547 : make_number (invis
));
18550 /* Calculate a width or height in pixels from a specification using
18551 the following elements:
18554 NUM - a (fractional) multiple of the default font width/height
18555 (NUM) - specifies exactly NUM pixels
18556 UNIT - a fixed number of pixels, see below.
18557 ELEMENT - size of a display element in pixels, see below.
18558 (NUM . SPEC) - equals NUM * SPEC
18559 (+ SPEC SPEC ...) - add pixel values
18560 (- SPEC SPEC ...) - subtract pixel values
18561 (- SPEC) - negate pixel value
18564 INT or FLOAT - a number constant
18565 SYMBOL - use symbol's (buffer local) variable binding.
18568 in - pixels per inch *)
18569 mm - pixels per 1/1000 meter *)
18570 cm - pixels per 1/100 meter *)
18571 width - width of current font in pixels.
18572 height - height of current font in pixels.
18574 *) using the ratio(s) defined in display-pixels-per-inch.
18578 left-fringe - left fringe width in pixels
18579 right-fringe - right fringe width in pixels
18581 left-margin - left margin width in pixels
18582 right-margin - right margin width in pixels
18584 scroll-bar - scroll-bar area width in pixels
18588 Pixels corresponding to 5 inches:
18591 Total width of non-text areas on left side of window (if scroll-bar is on left):
18592 '(space :width (+ left-fringe left-margin scroll-bar))
18594 Align to first text column (in header line):
18595 '(space :align-to 0)
18597 Align to middle of text area minus half the width of variable `my-image'
18598 containing a loaded image:
18599 '(space :align-to (0.5 . (- text my-image)))
18601 Width of left margin minus width of 1 character in the default font:
18602 '(space :width (- left-margin 1))
18604 Width of left margin minus width of 2 characters in the current font:
18605 '(space :width (- left-margin (2 . width)))
18607 Center 1 character over left-margin (in header line):
18608 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
18610 Different ways to express width of left fringe plus left margin minus one pixel:
18611 '(space :width (- (+ left-fringe left-margin) (1)))
18612 '(space :width (+ left-fringe left-margin (- (1))))
18613 '(space :width (+ left-fringe left-margin (-1)))
18617 #define NUMVAL(X) \
18618 ((INTEGERP (X) || FLOATP (X)) \
18623 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
18628 int width_p
, *align_to
;
18632 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
18633 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
18636 return OK_PIXELS (0);
18638 xassert (FRAME_LIVE_P (it
->f
));
18640 if (SYMBOLP (prop
))
18642 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18644 char *unit
= SDATA (SYMBOL_NAME (prop
));
18646 if (unit
[0] == 'i' && unit
[1] == 'n')
18648 else if (unit
[0] == 'm' && unit
[1] == 'm')
18650 else if (unit
[0] == 'c' && unit
[1] == 'm')
18657 #ifdef HAVE_WINDOW_SYSTEM
18658 if (FRAME_WINDOW_P (it
->f
)
18660 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
18661 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
18663 return OK_PIXELS (ppi
/ pixels
);
18666 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18667 || (CONSP (Vdisplay_pixels_per_inch
)
18669 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18670 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18672 return OK_PIXELS (ppi
/ pixels
);
18678 #ifdef HAVE_WINDOW_SYSTEM
18679 if (EQ (prop
, Qheight
))
18680 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
18681 if (EQ (prop
, Qwidth
))
18682 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
18684 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
18685 return OK_PIXELS (1);
18688 if (EQ (prop
, Qtext
))
18689 return OK_PIXELS (width_p
18690 ? window_box_width (it
->w
, TEXT_AREA
)
18691 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
18693 if (align_to
&& *align_to
< 0)
18696 if (EQ (prop
, Qleft
))
18697 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
18698 if (EQ (prop
, Qright
))
18699 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
18700 if (EQ (prop
, Qcenter
))
18701 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
18702 + window_box_width (it
->w
, TEXT_AREA
) / 2);
18703 if (EQ (prop
, Qleft_fringe
))
18704 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18705 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
18706 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
18707 if (EQ (prop
, Qright_fringe
))
18708 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18709 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18710 : window_box_right_offset (it
->w
, TEXT_AREA
));
18711 if (EQ (prop
, Qleft_margin
))
18712 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
18713 if (EQ (prop
, Qright_margin
))
18714 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
18715 if (EQ (prop
, Qscroll_bar
))
18716 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18718 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18719 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18720 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18725 if (EQ (prop
, Qleft_fringe
))
18726 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18727 if (EQ (prop
, Qright_fringe
))
18728 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18729 if (EQ (prop
, Qleft_margin
))
18730 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18731 if (EQ (prop
, Qright_margin
))
18732 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18733 if (EQ (prop
, Qscroll_bar
))
18734 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18737 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18740 if (INTEGERP (prop
) || FLOATP (prop
))
18742 int base_unit
= (width_p
18743 ? FRAME_COLUMN_WIDTH (it
->f
)
18744 : FRAME_LINE_HEIGHT (it
->f
));
18745 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18750 Lisp_Object car
= XCAR (prop
);
18751 Lisp_Object cdr
= XCDR (prop
);
18755 #ifdef HAVE_WINDOW_SYSTEM
18756 if (FRAME_WINDOW_P (it
->f
)
18757 && valid_image_p (prop
))
18759 int id
= lookup_image (it
->f
, prop
);
18760 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
18762 return OK_PIXELS (width_p
? img
->width
: img
->height
);
18765 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18771 while (CONSP (cdr
))
18773 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
18774 font
, width_p
, align_to
))
18777 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18782 if (EQ (car
, Qminus
))
18784 return OK_PIXELS (pixels
);
18787 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18790 if (INTEGERP (car
) || FLOATP (car
))
18793 pixels
= XFLOATINT (car
);
18795 return OK_PIXELS (pixels
);
18796 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
18797 font
, width_p
, align_to
))
18798 return OK_PIXELS (pixels
* fact
);
18809 /***********************************************************************
18811 ***********************************************************************/
18813 #ifdef HAVE_WINDOW_SYSTEM
18818 dump_glyph_string (s
)
18819 struct glyph_string
*s
;
18821 fprintf (stderr
, "glyph string\n");
18822 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
18823 s
->x
, s
->y
, s
->width
, s
->height
);
18824 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
18825 fprintf (stderr
, " hl = %d\n", s
->hl
);
18826 fprintf (stderr
, " left overhang = %d, right = %d\n",
18827 s
->left_overhang
, s
->right_overhang
);
18828 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
18829 fprintf (stderr
, " extends to end of line = %d\n",
18830 s
->extends_to_end_of_line_p
);
18831 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
18832 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
18835 #endif /* GLYPH_DEBUG */
18837 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
18838 of XChar2b structures for S; it can't be allocated in
18839 init_glyph_string because it must be allocated via `alloca'. W
18840 is the window on which S is drawn. ROW and AREA are the glyph row
18841 and area within the row from which S is constructed. START is the
18842 index of the first glyph structure covered by S. HL is a
18843 face-override for drawing S. */
18846 #define OPTIONAL_HDC(hdc) hdc,
18847 #define DECLARE_HDC(hdc) HDC hdc;
18848 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
18849 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
18852 #ifndef OPTIONAL_HDC
18853 #define OPTIONAL_HDC(hdc)
18854 #define DECLARE_HDC(hdc)
18855 #define ALLOCATE_HDC(hdc, f)
18856 #define RELEASE_HDC(hdc, f)
18860 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
18861 struct glyph_string
*s
;
18865 struct glyph_row
*row
;
18866 enum glyph_row_area area
;
18868 enum draw_glyphs_face hl
;
18870 bzero (s
, sizeof *s
);
18872 s
->f
= XFRAME (w
->frame
);
18876 s
->display
= FRAME_X_DISPLAY (s
->f
);
18877 s
->window
= FRAME_X_WINDOW (s
->f
);
18878 s
->char2b
= char2b
;
18882 s
->first_glyph
= row
->glyphs
[area
] + start
;
18883 s
->height
= row
->height
;
18884 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
18886 /* Display the internal border below the tool-bar window. */
18887 if (WINDOWP (s
->f
->tool_bar_window
)
18888 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
18889 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
18891 s
->ybase
= s
->y
+ row
->ascent
;
18895 /* Append the list of glyph strings with head H and tail T to the list
18896 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
18899 append_glyph_string_lists (head
, tail
, h
, t
)
18900 struct glyph_string
**head
, **tail
;
18901 struct glyph_string
*h
, *t
;
18915 /* Prepend the list of glyph strings with head H and tail T to the
18916 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
18920 prepend_glyph_string_lists (head
, tail
, h
, t
)
18921 struct glyph_string
**head
, **tail
;
18922 struct glyph_string
*h
, *t
;
18936 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
18937 Set *HEAD and *TAIL to the resulting list. */
18940 append_glyph_string (head
, tail
, s
)
18941 struct glyph_string
**head
, **tail
;
18942 struct glyph_string
*s
;
18944 s
->next
= s
->prev
= NULL
;
18945 append_glyph_string_lists (head
, tail
, s
, s
);
18949 /* Get face and two-byte form of character glyph GLYPH on frame F.
18950 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
18951 a pointer to a realized face that is ready for display. */
18953 static INLINE
struct face
*
18954 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
18956 struct glyph
*glyph
;
18962 xassert (glyph
->type
== CHAR_GLYPH
);
18963 face
= FACE_FROM_ID (f
, glyph
->face_id
);
18968 if (!glyph
->multibyte_p
)
18970 /* Unibyte case. We don't have to encode, but we have to make
18971 sure to use a face suitable for unibyte. */
18972 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18974 else if (glyph
->u
.ch
< 128)
18976 /* Case of ASCII in a face known to fit ASCII. */
18977 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18981 int c1
, c2
, charset
;
18983 /* Split characters into bytes. If c2 is -1 afterwards, C is
18984 really a one-byte character so that byte1 is zero. */
18985 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
18987 STORE_XCHAR2B (char2b
, c1
, c2
);
18989 STORE_XCHAR2B (char2b
, 0, c1
);
18991 /* Maybe encode the character in *CHAR2B. */
18992 if (charset
!= CHARSET_ASCII
)
18994 struct font_info
*font_info
18995 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18998 = FRAME_RIF (f
)->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
19002 /* Make sure X resources of the face are allocated. */
19003 xassert (face
!= NULL
);
19004 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19009 /* Fill glyph string S with composition components specified by S->cmp.
19011 FACES is an array of faces for all components of this composition.
19012 S->gidx is the index of the first component for S.
19014 OVERLAPS non-zero means S should draw the foreground only, and use
19015 its physical height for clipping. See also draw_glyphs.
19017 Value is the index of a component not in S. */
19020 fill_composite_glyph_string (s
, faces
, overlaps
)
19021 struct glyph_string
*s
;
19022 struct face
**faces
;
19029 s
->for_overlaps
= overlaps
;
19031 s
->face
= faces
[s
->gidx
];
19032 s
->font
= s
->face
->font
;
19033 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
19035 /* For all glyphs of this composition, starting at the offset
19036 S->gidx, until we reach the end of the definition or encounter a
19037 glyph that requires the different face, add it to S. */
19039 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
19042 /* All glyph strings for the same composition has the same width,
19043 i.e. the width set for the first component of the composition. */
19045 s
->width
= s
->first_glyph
->pixel_width
;
19047 /* If the specified font could not be loaded, use the frame's
19048 default font, but record the fact that we couldn't load it in
19049 the glyph string so that we can draw rectangles for the
19050 characters of the glyph string. */
19051 if (s
->font
== NULL
)
19053 s
->font_not_found_p
= 1;
19054 s
->font
= FRAME_FONT (s
->f
);
19057 /* Adjust base line for subscript/superscript text. */
19058 s
->ybase
+= s
->first_glyph
->voffset
;
19060 xassert (s
->face
&& s
->face
->gc
);
19062 /* This glyph string must always be drawn with 16-bit functions. */
19065 return s
->gidx
+ s
->nchars
;
19069 /* Fill glyph string S from a sequence of character glyphs.
19071 FACE_ID is the face id of the string. START is the index of the
19072 first glyph to consider, END is the index of the last + 1.
19073 OVERLAPS non-zero means S should draw the foreground only, and use
19074 its physical height for clipping. See also draw_glyphs.
19076 Value is the index of the first glyph not in S. */
19079 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
19080 struct glyph_string
*s
;
19082 int start
, end
, overlaps
;
19084 struct glyph
*glyph
, *last
;
19086 int glyph_not_available_p
;
19088 xassert (s
->f
== XFRAME (s
->w
->frame
));
19089 xassert (s
->nchars
== 0);
19090 xassert (start
>= 0 && end
> start
);
19092 s
->for_overlaps
= overlaps
,
19093 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19094 last
= s
->row
->glyphs
[s
->area
] + end
;
19095 voffset
= glyph
->voffset
;
19097 glyph_not_available_p
= glyph
->glyph_not_available_p
;
19099 while (glyph
< last
19100 && glyph
->type
== CHAR_GLYPH
19101 && glyph
->voffset
== voffset
19102 /* Same face id implies same font, nowadays. */
19103 && glyph
->face_id
== face_id
19104 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
19108 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
19109 s
->char2b
+ s
->nchars
,
19111 s
->two_byte_p
= two_byte_p
;
19113 xassert (s
->nchars
<= end
- start
);
19114 s
->width
+= glyph
->pixel_width
;
19118 s
->font
= s
->face
->font
;
19119 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
19121 /* If the specified font could not be loaded, use the frame's font,
19122 but record the fact that we couldn't load it in
19123 S->font_not_found_p so that we can draw rectangles for the
19124 characters of the glyph string. */
19125 if (s
->font
== NULL
|| glyph_not_available_p
)
19127 s
->font_not_found_p
= 1;
19128 s
->font
= FRAME_FONT (s
->f
);
19131 /* Adjust base line for subscript/superscript text. */
19132 s
->ybase
+= voffset
;
19134 xassert (s
->face
&& s
->face
->gc
);
19135 return glyph
- s
->row
->glyphs
[s
->area
];
19139 /* Fill glyph string S from image glyph S->first_glyph. */
19142 fill_image_glyph_string (s
)
19143 struct glyph_string
*s
;
19145 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
19146 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
19148 s
->slice
= s
->first_glyph
->slice
;
19149 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
19150 s
->font
= s
->face
->font
;
19151 s
->width
= s
->first_glyph
->pixel_width
;
19153 /* Adjust base line for subscript/superscript text. */
19154 s
->ybase
+= s
->first_glyph
->voffset
;
19158 /* Fill glyph string S from a sequence of stretch glyphs.
19160 ROW is the glyph row in which the glyphs are found, AREA is the
19161 area within the row. START is the index of the first glyph to
19162 consider, END is the index of the last + 1.
19164 Value is the index of the first glyph not in S. */
19167 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
19168 struct glyph_string
*s
;
19169 struct glyph_row
*row
;
19170 enum glyph_row_area area
;
19173 struct glyph
*glyph
, *last
;
19174 int voffset
, face_id
;
19176 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
19178 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19179 last
= s
->row
->glyphs
[s
->area
] + end
;
19180 face_id
= glyph
->face_id
;
19181 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19182 s
->font
= s
->face
->font
;
19183 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
19184 s
->width
= glyph
->pixel_width
;
19186 voffset
= glyph
->voffset
;
19190 && glyph
->type
== STRETCH_GLYPH
19191 && glyph
->voffset
== voffset
19192 && glyph
->face_id
== face_id
);
19194 s
->width
+= glyph
->pixel_width
;
19196 /* Adjust base line for subscript/superscript text. */
19197 s
->ybase
+= voffset
;
19199 /* The case that face->gc == 0 is handled when drawing the glyph
19200 string by calling PREPARE_FACE_FOR_DISPLAY. */
19202 return glyph
- s
->row
->glyphs
[s
->area
];
19207 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
19208 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
19209 assumed to be zero. */
19212 x_get_glyph_overhangs (glyph
, f
, left
, right
)
19213 struct glyph
*glyph
;
19217 *left
= *right
= 0;
19219 if (glyph
->type
== CHAR_GLYPH
)
19223 struct font_info
*font_info
;
19227 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
19229 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
19230 if (font
/* ++KFS: Should this be font_info ? */
19231 && (pcm
= FRAME_RIF (f
)->per_char_metric (font
, &char2b
, glyph
->font_type
)))
19233 if (pcm
->rbearing
> pcm
->width
)
19234 *right
= pcm
->rbearing
- pcm
->width
;
19235 if (pcm
->lbearing
< 0)
19236 *left
= -pcm
->lbearing
;
19242 /* Return the index of the first glyph preceding glyph string S that
19243 is overwritten by S because of S's left overhang. Value is -1
19244 if no glyphs are overwritten. */
19247 left_overwritten (s
)
19248 struct glyph_string
*s
;
19252 if (s
->left_overhang
)
19255 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19256 int first
= s
->first_glyph
- glyphs
;
19258 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
19259 x
-= glyphs
[i
].pixel_width
;
19270 /* Return the index of the first glyph preceding glyph string S that
19271 is overwriting S because of its right overhang. Value is -1 if no
19272 glyph in front of S overwrites S. */
19275 left_overwriting (s
)
19276 struct glyph_string
*s
;
19279 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19280 int first
= s
->first_glyph
- glyphs
;
19284 for (i
= first
- 1; i
>= 0; --i
)
19287 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19290 x
-= glyphs
[i
].pixel_width
;
19297 /* Return the index of the last glyph following glyph string S that is
19298 not overwritten by S because of S's right overhang. Value is -1 if
19299 no such glyph is found. */
19302 right_overwritten (s
)
19303 struct glyph_string
*s
;
19307 if (s
->right_overhang
)
19310 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19311 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19312 int end
= s
->row
->used
[s
->area
];
19314 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
19315 x
+= glyphs
[i
].pixel_width
;
19324 /* Return the index of the last glyph following glyph string S that
19325 overwrites S because of its left overhang. Value is negative
19326 if no such glyph is found. */
19329 right_overwriting (s
)
19330 struct glyph_string
*s
;
19333 int end
= s
->row
->used
[s
->area
];
19334 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19335 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19339 for (i
= first
; i
< end
; ++i
)
19342 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19345 x
+= glyphs
[i
].pixel_width
;
19352 /* Get face and two-byte form of character C in face FACE_ID on frame
19353 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19354 means we want to display multibyte text. DISPLAY_P non-zero means
19355 make sure that X resources for the face returned are allocated.
19356 Value is a pointer to a realized face that is ready for display if
19357 DISPLAY_P is non-zero. */
19359 static INLINE
struct face
*
19360 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
19364 int multibyte_p
, display_p
;
19366 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19370 /* Unibyte case. We don't have to encode, but we have to make
19371 sure to use a face suitable for unibyte. */
19372 STORE_XCHAR2B (char2b
, 0, c
);
19373 face_id
= FACE_FOR_CHAR (f
, face
, c
);
19374 face
= FACE_FROM_ID (f
, face_id
);
19378 /* Case of ASCII in a face known to fit ASCII. */
19379 STORE_XCHAR2B (char2b
, 0, c
);
19383 int c1
, c2
, charset
;
19385 /* Split characters into bytes. If c2 is -1 afterwards, C is
19386 really a one-byte character so that byte1 is zero. */
19387 SPLIT_CHAR (c
, charset
, c1
, c2
);
19389 STORE_XCHAR2B (char2b
, c1
, c2
);
19391 STORE_XCHAR2B (char2b
, 0, c1
);
19393 /* Maybe encode the character in *CHAR2B. */
19394 if (face
->font
!= NULL
)
19396 struct font_info
*font_info
19397 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
19399 FRAME_RIF (f
)->encode_char (c
, char2b
, font_info
, 0);
19403 /* Make sure X resources of the face are allocated. */
19404 #ifdef HAVE_X_WINDOWS
19408 xassert (face
!= NULL
);
19409 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19416 /* Set background width of glyph string S. START is the index of the
19417 first glyph following S. LAST_X is the right-most x-position + 1
19418 in the drawing area. */
19421 set_glyph_string_background_width (s
, start
, last_x
)
19422 struct glyph_string
*s
;
19426 /* If the face of this glyph string has to be drawn to the end of
19427 the drawing area, set S->extends_to_end_of_line_p. */
19429 if (start
== s
->row
->used
[s
->area
]
19430 && s
->area
== TEXT_AREA
19431 && ((s
->row
->fill_line_p
19432 && (s
->hl
== DRAW_NORMAL_TEXT
19433 || s
->hl
== DRAW_IMAGE_RAISED
19434 || s
->hl
== DRAW_IMAGE_SUNKEN
))
19435 || s
->hl
== DRAW_MOUSE_FACE
))
19436 s
->extends_to_end_of_line_p
= 1;
19438 /* If S extends its face to the end of the line, set its
19439 background_width to the distance to the right edge of the drawing
19441 if (s
->extends_to_end_of_line_p
)
19442 s
->background_width
= last_x
- s
->x
+ 1;
19444 s
->background_width
= s
->width
;
19448 /* Compute overhangs and x-positions for glyph string S and its
19449 predecessors, or successors. X is the starting x-position for S.
19450 BACKWARD_P non-zero means process predecessors. */
19453 compute_overhangs_and_x (s
, x
, backward_p
)
19454 struct glyph_string
*s
;
19462 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
19463 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
19473 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
19474 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
19484 /* The following macros are only called from draw_glyphs below.
19485 They reference the following parameters of that function directly:
19486 `w', `row', `area', and `overlap_p'
19487 as well as the following local variables:
19488 `s', `f', and `hdc' (in W32) */
19491 /* On W32, silently add local `hdc' variable to argument list of
19492 init_glyph_string. */
19493 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19494 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
19496 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19497 init_glyph_string (s, char2b, w, row, area, start, hl)
19500 /* Add a glyph string for a stretch glyph to the list of strings
19501 between HEAD and TAIL. START is the index of the stretch glyph in
19502 row area AREA of glyph row ROW. END is the index of the last glyph
19503 in that glyph row area. X is the current output position assigned
19504 to the new glyph string constructed. HL overrides that face of the
19505 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19506 is the right-most x-position of the drawing area. */
19508 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
19509 and below -- keep them on one line. */
19510 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19513 s = (struct glyph_string *) alloca (sizeof *s); \
19514 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19515 START = fill_stretch_glyph_string (s, row, area, START, END); \
19516 append_glyph_string (&HEAD, &TAIL, s); \
19522 /* Add a glyph string for an image glyph to the list of strings
19523 between HEAD and TAIL. START is the index of the image glyph in
19524 row area AREA of glyph row ROW. END is the index of the last glyph
19525 in that glyph row area. X is the current output position assigned
19526 to the new glyph string constructed. HL overrides that face of the
19527 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19528 is the right-most x-position of the drawing area. */
19530 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19533 s = (struct glyph_string *) alloca (sizeof *s); \
19534 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19535 fill_image_glyph_string (s); \
19536 append_glyph_string (&HEAD, &TAIL, s); \
19543 /* Add a glyph string for a sequence of character glyphs to the list
19544 of strings between HEAD and TAIL. START is the index of the first
19545 glyph in row area AREA of glyph row ROW that is part of the new
19546 glyph string. END is the index of the last glyph in that glyph row
19547 area. X is the current output position assigned to the new glyph
19548 string constructed. HL overrides that face of the glyph; e.g. it
19549 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
19550 right-most x-position of the drawing area. */
19552 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19558 c = (row)->glyphs[area][START].u.ch; \
19559 face_id = (row)->glyphs[area][START].face_id; \
19561 s = (struct glyph_string *) alloca (sizeof *s); \
19562 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
19563 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
19564 append_glyph_string (&HEAD, &TAIL, s); \
19566 START = fill_glyph_string (s, face_id, START, END, overlaps); \
19571 /* Add a glyph string for a composite sequence to the list of strings
19572 between HEAD and TAIL. START is the index of the first glyph in
19573 row area AREA of glyph row ROW that is part of the new glyph
19574 string. END is the index of the last glyph in that glyph row area.
19575 X is the current output position assigned to the new glyph string
19576 constructed. HL overrides that face of the glyph; e.g. it is
19577 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
19578 x-position of the drawing area. */
19580 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19582 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
19583 int face_id = (row)->glyphs[area][START].face_id; \
19584 struct face *base_face = FACE_FROM_ID (f, face_id); \
19585 struct composition *cmp = composition_table[cmp_id]; \
19586 int glyph_len = cmp->glyph_len; \
19588 struct face **faces; \
19589 struct glyph_string *first_s = NULL; \
19592 base_face = base_face->ascii_face; \
19593 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
19594 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
19595 /* At first, fill in `char2b' and `faces'. */ \
19596 for (n = 0; n < glyph_len; n++) \
19598 int c = COMPOSITION_GLYPH (cmp, n); \
19599 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
19600 faces[n] = FACE_FROM_ID (f, this_face_id); \
19601 get_char_face_and_encoding (f, c, this_face_id, \
19602 char2b + n, 1, 1); \
19605 /* Make glyph_strings for each glyph sequence that is drawable by \
19606 the same face, and append them to HEAD/TAIL. */ \
19607 for (n = 0; n < cmp->glyph_len;) \
19609 s = (struct glyph_string *) alloca (sizeof *s); \
19610 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
19611 append_glyph_string (&(HEAD), &(TAIL), s); \
19619 n = fill_composite_glyph_string (s, faces, overlaps); \
19627 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
19628 of AREA of glyph row ROW on window W between indices START and END.
19629 HL overrides the face for drawing glyph strings, e.g. it is
19630 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
19631 x-positions of the drawing area.
19633 This is an ugly monster macro construct because we must use alloca
19634 to allocate glyph strings (because draw_glyphs can be called
19635 asynchronously). */
19637 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19640 HEAD = TAIL = NULL; \
19641 while (START < END) \
19643 struct glyph *first_glyph = (row)->glyphs[area] + START; \
19644 switch (first_glyph->type) \
19647 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
19651 case COMPOSITE_GLYPH: \
19652 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
19656 case STRETCH_GLYPH: \
19657 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
19661 case IMAGE_GLYPH: \
19662 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
19670 set_glyph_string_background_width (s, START, LAST_X); \
19677 /* Draw glyphs between START and END in AREA of ROW on window W,
19678 starting at x-position X. X is relative to AREA in W. HL is a
19679 face-override with the following meaning:
19681 DRAW_NORMAL_TEXT draw normally
19682 DRAW_CURSOR draw in cursor face
19683 DRAW_MOUSE_FACE draw in mouse face.
19684 DRAW_INVERSE_VIDEO draw in mode line face
19685 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
19686 DRAW_IMAGE_RAISED draw an image with a raised relief around it
19688 If OVERLAPS is non-zero, draw only the foreground of characters and
19689 clip to the physical height of ROW. Non-zero value also defines
19690 the overlapping part to be drawn:
19692 OVERLAPS_PRED overlap with preceding rows
19693 OVERLAPS_SUCC overlap with succeeding rows
19694 OVERLAPS_BOTH overlap with both preceding/succeeding rows
19695 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
19697 Value is the x-position reached, relative to AREA of W. */
19700 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
19703 struct glyph_row
*row
;
19704 enum glyph_row_area area
;
19706 enum draw_glyphs_face hl
;
19709 struct glyph_string
*head
, *tail
;
19710 struct glyph_string
*s
;
19711 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
19712 int last_x
, area_width
;
19715 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19718 ALLOCATE_HDC (hdc
, f
);
19720 /* Let's rather be paranoid than getting a SEGV. */
19721 end
= min (end
, row
->used
[area
]);
19722 start
= max (0, start
);
19723 start
= min (end
, start
);
19725 /* Translate X to frame coordinates. Set last_x to the right
19726 end of the drawing area. */
19727 if (row
->full_width_p
)
19729 /* X is relative to the left edge of W, without scroll bars
19731 x
+= WINDOW_LEFT_EDGE_X (w
);
19732 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
19736 int area_left
= window_box_left (w
, area
);
19738 area_width
= window_box_width (w
, area
);
19739 last_x
= area_left
+ area_width
;
19742 /* Build a doubly-linked list of glyph_string structures between
19743 head and tail from what we have to draw. Note that the macro
19744 BUILD_GLYPH_STRINGS will modify its start parameter. That's
19745 the reason we use a separate variable `i'. */
19747 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
19749 x_reached
= tail
->x
+ tail
->background_width
;
19753 /* If there are any glyphs with lbearing < 0 or rbearing > width in
19754 the row, redraw some glyphs in front or following the glyph
19755 strings built above. */
19756 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
19759 struct glyph_string
*h
, *t
;
19761 /* Compute overhangs for all glyph strings. */
19762 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
19763 for (s
= head
; s
; s
= s
->next
)
19764 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
19766 /* Prepend glyph strings for glyphs in front of the first glyph
19767 string that are overwritten because of the first glyph
19768 string's left overhang. The background of all strings
19769 prepended must be drawn because the first glyph string
19771 i
= left_overwritten (head
);
19775 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
19776 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19778 compute_overhangs_and_x (t
, head
->x
, 1);
19779 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19783 /* Prepend glyph strings for glyphs in front of the first glyph
19784 string that overwrite that glyph string because of their
19785 right overhang. For these strings, only the foreground must
19786 be drawn, because it draws over the glyph string at `head'.
19787 The background must not be drawn because this would overwrite
19788 right overhangs of preceding glyphs for which no glyph
19790 i
= left_overwriting (head
);
19794 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
19795 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19796 for (s
= h
; s
; s
= s
->next
)
19797 s
->background_filled_p
= 1;
19798 compute_overhangs_and_x (t
, head
->x
, 1);
19799 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19802 /* Append glyphs strings for glyphs following the last glyph
19803 string tail that are overwritten by tail. The background of
19804 these strings has to be drawn because tail's foreground draws
19806 i
= right_overwritten (tail
);
19809 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19810 DRAW_NORMAL_TEXT
, x
, last_x
);
19811 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19812 append_glyph_string_lists (&head
, &tail
, h
, t
);
19816 /* Append glyph strings for glyphs following the last glyph
19817 string tail that overwrite tail. The foreground of such
19818 glyphs has to be drawn because it writes into the background
19819 of tail. The background must not be drawn because it could
19820 paint over the foreground of following glyphs. */
19821 i
= right_overwriting (tail
);
19825 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19826 DRAW_NORMAL_TEXT
, x
, last_x
);
19827 for (s
= h
; s
; s
= s
->next
)
19828 s
->background_filled_p
= 1;
19829 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19830 append_glyph_string_lists (&head
, &tail
, h
, t
);
19832 if (clip_head
|| clip_tail
)
19833 for (s
= head
; s
; s
= s
->next
)
19835 s
->clip_head
= clip_head
;
19836 s
->clip_tail
= clip_tail
;
19840 /* Draw all strings. */
19841 for (s
= head
; s
; s
= s
->next
)
19842 FRAME_RIF (f
)->draw_glyph_string (s
);
19844 if (area
== TEXT_AREA
19845 && !row
->full_width_p
19846 /* When drawing overlapping rows, only the glyph strings'
19847 foreground is drawn, which doesn't erase a cursor
19851 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
19852 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
19853 : (tail
? tail
->x
+ tail
->background_width
: x
));
19855 int text_left
= window_box_left (w
, TEXT_AREA
);
19859 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
19860 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
19863 /* Value is the x-position up to which drawn, relative to AREA of W.
19864 This doesn't include parts drawn because of overhangs. */
19865 if (row
->full_width_p
)
19866 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
19868 x_reached
-= window_box_left (w
, area
);
19870 RELEASE_HDC (hdc
, f
);
19875 /* Expand row matrix if too narrow. Don't expand if area
19878 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
19880 if (!fonts_changed_p \
19881 && (it->glyph_row->glyphs[area] \
19882 < it->glyph_row->glyphs[area + 1])) \
19884 it->w->ncols_scale_factor++; \
19885 fonts_changed_p = 1; \
19889 /* Store one glyph for IT->char_to_display in IT->glyph_row.
19890 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19896 struct glyph
*glyph
;
19897 enum glyph_row_area area
= it
->area
;
19899 xassert (it
->glyph_row
);
19900 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
19902 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19903 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19905 glyph
->charpos
= CHARPOS (it
->position
);
19906 glyph
->object
= it
->object
;
19907 glyph
->pixel_width
= it
->pixel_width
;
19908 glyph
->ascent
= it
->ascent
;
19909 glyph
->descent
= it
->descent
;
19910 glyph
->voffset
= it
->voffset
;
19911 glyph
->type
= CHAR_GLYPH
;
19912 glyph
->multibyte_p
= it
->multibyte_p
;
19913 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19914 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19915 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19916 || it
->phys_descent
> it
->descent
);
19917 glyph
->padding_p
= 0;
19918 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
19919 glyph
->face_id
= it
->face_id
;
19920 glyph
->u
.ch
= it
->char_to_display
;
19921 glyph
->slice
= null_glyph_slice
;
19922 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19923 ++it
->glyph_row
->used
[area
];
19926 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19929 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
19930 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19933 append_composite_glyph (it
)
19936 struct glyph
*glyph
;
19937 enum glyph_row_area area
= it
->area
;
19939 xassert (it
->glyph_row
);
19941 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19942 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19944 glyph
->charpos
= CHARPOS (it
->position
);
19945 glyph
->object
= it
->object
;
19946 glyph
->pixel_width
= it
->pixel_width
;
19947 glyph
->ascent
= it
->ascent
;
19948 glyph
->descent
= it
->descent
;
19949 glyph
->voffset
= it
->voffset
;
19950 glyph
->type
= COMPOSITE_GLYPH
;
19951 glyph
->multibyte_p
= it
->multibyte_p
;
19952 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19953 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19954 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19955 || it
->phys_descent
> it
->descent
);
19956 glyph
->padding_p
= 0;
19957 glyph
->glyph_not_available_p
= 0;
19958 glyph
->face_id
= it
->face_id
;
19959 glyph
->u
.cmp_id
= it
->cmp_id
;
19960 glyph
->slice
= null_glyph_slice
;
19961 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19962 ++it
->glyph_row
->used
[area
];
19965 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19969 /* Change IT->ascent and IT->height according to the setting of
19973 take_vertical_position_into_account (it
)
19978 if (it
->voffset
< 0)
19979 /* Increase the ascent so that we can display the text higher
19981 it
->ascent
-= it
->voffset
;
19983 /* Increase the descent so that we can display the text lower
19985 it
->descent
+= it
->voffset
;
19990 /* Produce glyphs/get display metrics for the image IT is loaded with.
19991 See the description of struct display_iterator in dispextern.h for
19992 an overview of struct display_iterator. */
19995 produce_image_glyph (it
)
20000 int glyph_ascent
, crop
;
20001 struct glyph_slice slice
;
20003 xassert (it
->what
== IT_IMAGE
);
20005 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20007 /* Make sure X resources of the face is loaded. */
20008 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20010 if (it
->image_id
< 0)
20012 /* Fringe bitmap. */
20013 it
->ascent
= it
->phys_ascent
= 0;
20014 it
->descent
= it
->phys_descent
= 0;
20015 it
->pixel_width
= 0;
20020 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
20022 /* Make sure X resources of the image is loaded. */
20023 prepare_image_for_display (it
->f
, img
);
20025 slice
.x
= slice
.y
= 0;
20026 slice
.width
= img
->width
;
20027 slice
.height
= img
->height
;
20029 if (INTEGERP (it
->slice
.x
))
20030 slice
.x
= XINT (it
->slice
.x
);
20031 else if (FLOATP (it
->slice
.x
))
20032 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
20034 if (INTEGERP (it
->slice
.y
))
20035 slice
.y
= XINT (it
->slice
.y
);
20036 else if (FLOATP (it
->slice
.y
))
20037 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
20039 if (INTEGERP (it
->slice
.width
))
20040 slice
.width
= XINT (it
->slice
.width
);
20041 else if (FLOATP (it
->slice
.width
))
20042 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
20044 if (INTEGERP (it
->slice
.height
))
20045 slice
.height
= XINT (it
->slice
.height
);
20046 else if (FLOATP (it
->slice
.height
))
20047 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
20049 if (slice
.x
>= img
->width
)
20050 slice
.x
= img
->width
;
20051 if (slice
.y
>= img
->height
)
20052 slice
.y
= img
->height
;
20053 if (slice
.x
+ slice
.width
>= img
->width
)
20054 slice
.width
= img
->width
- slice
.x
;
20055 if (slice
.y
+ slice
.height
> img
->height
)
20056 slice
.height
= img
->height
- slice
.y
;
20058 if (slice
.width
== 0 || slice
.height
== 0)
20061 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
20063 it
->descent
= slice
.height
- glyph_ascent
;
20065 it
->descent
+= img
->vmargin
;
20066 if (slice
.y
+ slice
.height
== img
->height
)
20067 it
->descent
+= img
->vmargin
;
20068 it
->phys_descent
= it
->descent
;
20070 it
->pixel_width
= slice
.width
;
20072 it
->pixel_width
+= img
->hmargin
;
20073 if (slice
.x
+ slice
.width
== img
->width
)
20074 it
->pixel_width
+= img
->hmargin
;
20076 /* It's quite possible for images to have an ascent greater than
20077 their height, so don't get confused in that case. */
20078 if (it
->descent
< 0)
20081 #if 0 /* this breaks image tiling */
20082 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
20083 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
20084 if (face_ascent
> it
->ascent
)
20085 it
->ascent
= it
->phys_ascent
= face_ascent
;
20090 if (face
->box
!= FACE_NO_BOX
)
20092 if (face
->box_line_width
> 0)
20095 it
->ascent
+= face
->box_line_width
;
20096 if (slice
.y
+ slice
.height
== img
->height
)
20097 it
->descent
+= face
->box_line_width
;
20100 if (it
->start_of_box_run_p
&& slice
.x
== 0)
20101 it
->pixel_width
+= eabs (face
->box_line_width
);
20102 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
20103 it
->pixel_width
+= eabs (face
->box_line_width
);
20106 take_vertical_position_into_account (it
);
20108 /* Automatically crop wide image glyphs at right edge so we can
20109 draw the cursor on same display row. */
20110 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
20111 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
20113 it
->pixel_width
-= crop
;
20114 slice
.width
-= crop
;
20119 struct glyph
*glyph
;
20120 enum glyph_row_area area
= it
->area
;
20122 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20123 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20125 glyph
->charpos
= CHARPOS (it
->position
);
20126 glyph
->object
= it
->object
;
20127 glyph
->pixel_width
= it
->pixel_width
;
20128 glyph
->ascent
= glyph_ascent
;
20129 glyph
->descent
= it
->descent
;
20130 glyph
->voffset
= it
->voffset
;
20131 glyph
->type
= IMAGE_GLYPH
;
20132 glyph
->multibyte_p
= it
->multibyte_p
;
20133 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20134 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20135 glyph
->overlaps_vertically_p
= 0;
20136 glyph
->padding_p
= 0;
20137 glyph
->glyph_not_available_p
= 0;
20138 glyph
->face_id
= it
->face_id
;
20139 glyph
->u
.img_id
= img
->id
;
20140 glyph
->slice
= slice
;
20141 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20142 ++it
->glyph_row
->used
[area
];
20145 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20150 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
20151 of the glyph, WIDTH and HEIGHT are the width and height of the
20152 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
20155 append_stretch_glyph (it
, object
, width
, height
, ascent
)
20157 Lisp_Object object
;
20161 struct glyph
*glyph
;
20162 enum glyph_row_area area
= it
->area
;
20164 xassert (ascent
>= 0 && ascent
<= height
);
20166 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20167 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20169 glyph
->charpos
= CHARPOS (it
->position
);
20170 glyph
->object
= object
;
20171 glyph
->pixel_width
= width
;
20172 glyph
->ascent
= ascent
;
20173 glyph
->descent
= height
- ascent
;
20174 glyph
->voffset
= it
->voffset
;
20175 glyph
->type
= STRETCH_GLYPH
;
20176 glyph
->multibyte_p
= it
->multibyte_p
;
20177 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20178 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20179 glyph
->overlaps_vertically_p
= 0;
20180 glyph
->padding_p
= 0;
20181 glyph
->glyph_not_available_p
= 0;
20182 glyph
->face_id
= it
->face_id
;
20183 glyph
->u
.stretch
.ascent
= ascent
;
20184 glyph
->u
.stretch
.height
= height
;
20185 glyph
->slice
= null_glyph_slice
;
20186 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20187 ++it
->glyph_row
->used
[area
];
20190 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20194 /* Produce a stretch glyph for iterator IT. IT->object is the value
20195 of the glyph property displayed. The value must be a list
20196 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
20199 1. `:width WIDTH' specifies that the space should be WIDTH *
20200 canonical char width wide. WIDTH may be an integer or floating
20203 2. `:relative-width FACTOR' specifies that the width of the stretch
20204 should be computed from the width of the first character having the
20205 `glyph' property, and should be FACTOR times that width.
20207 3. `:align-to HPOS' specifies that the space should be wide enough
20208 to reach HPOS, a value in canonical character units.
20210 Exactly one of the above pairs must be present.
20212 4. `:height HEIGHT' specifies that the height of the stretch produced
20213 should be HEIGHT, measured in canonical character units.
20215 5. `:relative-height FACTOR' specifies that the height of the
20216 stretch should be FACTOR times the height of the characters having
20217 the glyph property.
20219 Either none or exactly one of 4 or 5 must be present.
20221 6. `:ascent ASCENT' specifies that ASCENT percent of the height
20222 of the stretch should be used for the ascent of the stretch.
20223 ASCENT must be in the range 0 <= ASCENT <= 100. */
20226 produce_stretch_glyph (it
)
20229 /* (space :width WIDTH :height HEIGHT ...) */
20230 Lisp_Object prop
, plist
;
20231 int width
= 0, height
= 0, align_to
= -1;
20232 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
20235 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20236 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
20238 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20240 /* List should start with `space'. */
20241 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
20242 plist
= XCDR (it
->object
);
20244 /* Compute the width of the stretch. */
20245 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
20246 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
20248 /* Absolute width `:width WIDTH' specified and valid. */
20249 zero_width_ok_p
= 1;
20252 else if (prop
= Fplist_get (plist
, QCrelative_width
),
20255 /* Relative width `:relative-width FACTOR' specified and valid.
20256 Compute the width of the characters having the `glyph'
20259 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
20262 if (it
->multibyte_p
)
20264 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
20265 - IT_BYTEPOS (*it
));
20266 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
20269 it2
.c
= *p
, it2
.len
= 1;
20271 it2
.glyph_row
= NULL
;
20272 it2
.what
= IT_CHARACTER
;
20273 x_produce_glyphs (&it2
);
20274 width
= NUMVAL (prop
) * it2
.pixel_width
;
20276 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
20277 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
20279 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
20280 align_to
= (align_to
< 0
20282 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
20283 else if (align_to
< 0)
20284 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
20285 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
20286 zero_width_ok_p
= 1;
20289 /* Nothing specified -> width defaults to canonical char width. */
20290 width
= FRAME_COLUMN_WIDTH (it
->f
);
20292 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
20295 /* Compute height. */
20296 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
20297 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20300 zero_height_ok_p
= 1;
20302 else if (prop
= Fplist_get (plist
, QCrelative_height
),
20304 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
20306 height
= FONT_HEIGHT (font
);
20308 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
20311 /* Compute percentage of height used for ascent. If
20312 `:ascent ASCENT' is present and valid, use that. Otherwise,
20313 derive the ascent from the font in use. */
20314 if (prop
= Fplist_get (plist
, QCascent
),
20315 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
20316 ascent
= height
* NUMVAL (prop
) / 100.0;
20317 else if (!NILP (prop
)
20318 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20319 ascent
= min (max (0, (int)tem
), height
);
20321 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
20323 if (width
> 0 && !it
->truncate_lines_p
20324 && it
->current_x
+ width
> it
->last_visible_x
)
20325 width
= it
->last_visible_x
- it
->current_x
- 1;
20327 if (width
> 0 && height
> 0 && it
->glyph_row
)
20329 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
20330 if (!STRINGP (object
))
20331 object
= it
->w
->buffer
;
20332 append_stretch_glyph (it
, object
, width
, height
, ascent
);
20335 it
->pixel_width
= width
;
20336 it
->ascent
= it
->phys_ascent
= ascent
;
20337 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
20338 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
20340 take_vertical_position_into_account (it
);
20343 /* Get line-height and line-spacing property at point.
20344 If line-height has format (HEIGHT TOTAL), return TOTAL
20345 in TOTAL_HEIGHT. */
20348 get_line_height_property (it
, prop
)
20352 Lisp_Object position
;
20354 if (STRINGP (it
->object
))
20355 position
= make_number (IT_STRING_CHARPOS (*it
));
20356 else if (BUFFERP (it
->object
))
20357 position
= make_number (IT_CHARPOS (*it
));
20361 return Fget_char_property (position
, prop
, it
->object
);
20364 /* Calculate line-height and line-spacing properties.
20365 An integer value specifies explicit pixel value.
20366 A float value specifies relative value to current face height.
20367 A cons (float . face-name) specifies relative value to
20368 height of specified face font.
20370 Returns height in pixels, or nil. */
20374 calc_line_height_property (it
, val
, font
, boff
, override
)
20378 int boff
, override
;
20380 Lisp_Object face_name
= Qnil
;
20381 int ascent
, descent
, height
;
20383 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
20388 face_name
= XCAR (val
);
20390 if (!NUMBERP (val
))
20391 val
= make_number (1);
20392 if (NILP (face_name
))
20394 height
= it
->ascent
+ it
->descent
;
20399 if (NILP (face_name
))
20401 font
= FRAME_FONT (it
->f
);
20402 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20404 else if (EQ (face_name
, Qt
))
20412 struct font_info
*font_info
;
20414 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
20416 return make_number (-1);
20418 face
= FACE_FROM_ID (it
->f
, face_id
);
20421 return make_number (-1);
20423 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20424 boff
= font_info
->baseline_offset
;
20425 if (font_info
->vertical_centering
)
20426 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20429 ascent
= FONT_BASE (font
) + boff
;
20430 descent
= FONT_DESCENT (font
) - boff
;
20434 it
->override_ascent
= ascent
;
20435 it
->override_descent
= descent
;
20436 it
->override_boff
= boff
;
20439 height
= ascent
+ descent
;
20443 height
= (int)(XFLOAT_DATA (val
) * height
);
20444 else if (INTEGERP (val
))
20445 height
*= XINT (val
);
20447 return make_number (height
);
20452 Produce glyphs/get display metrics for the display element IT is
20453 loaded with. See the description of struct it in dispextern.h
20454 for an overview of struct it. */
20457 x_produce_glyphs (it
)
20460 int extra_line_spacing
= it
->extra_line_spacing
;
20462 it
->glyph_not_available_p
= 0;
20464 if (it
->what
== IT_CHARACTER
)
20468 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20470 int font_not_found_p
;
20471 struct font_info
*font_info
;
20472 int boff
; /* baseline offset */
20473 /* We may change it->multibyte_p upon unibyte<->multibyte
20474 conversion. So, save the current value now and restore it
20477 Note: It seems that we don't have to record multibyte_p in
20478 struct glyph because the character code itself tells if or
20479 not the character is multibyte. Thus, in the future, we must
20480 consider eliminating the field `multibyte_p' in the struct
20482 int saved_multibyte_p
= it
->multibyte_p
;
20484 /* Maybe translate single-byte characters to multibyte, or the
20486 it
->char_to_display
= it
->c
;
20487 if (!ASCII_BYTE_P (it
->c
))
20489 if (unibyte_display_via_language_environment
20490 && SINGLE_BYTE_CHAR_P (it
->c
)
20492 || !NILP (Vnonascii_translation_table
)))
20494 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20495 it
->multibyte_p
= 1;
20496 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20497 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20499 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
20500 && !it
->multibyte_p
)
20502 it
->multibyte_p
= 1;
20503 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20504 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20508 /* Get font to use. Encode IT->char_to_display. */
20509 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20510 &char2b
, it
->multibyte_p
, 0);
20513 /* When no suitable font found, use the default font. */
20514 font_not_found_p
= font
== NULL
;
20515 if (font_not_found_p
)
20517 font
= FRAME_FONT (it
->f
);
20518 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20523 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20524 boff
= font_info
->baseline_offset
;
20525 if (font_info
->vertical_centering
)
20526 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20529 if (it
->char_to_display
>= ' '
20530 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
20532 /* Either unibyte or ASCII. */
20537 pcm
= FRAME_RIF (it
->f
)->per_char_metric
20538 (font
, &char2b
, FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
20540 if (it
->override_ascent
>= 0)
20542 it
->ascent
= it
->override_ascent
;
20543 it
->descent
= it
->override_descent
;
20544 boff
= it
->override_boff
;
20548 it
->ascent
= FONT_BASE (font
) + boff
;
20549 it
->descent
= FONT_DESCENT (font
) - boff
;
20554 it
->phys_ascent
= pcm
->ascent
+ boff
;
20555 it
->phys_descent
= pcm
->descent
- boff
;
20556 it
->pixel_width
= pcm
->width
;
20560 it
->glyph_not_available_p
= 1;
20561 it
->phys_ascent
= it
->ascent
;
20562 it
->phys_descent
= it
->descent
;
20563 it
->pixel_width
= FONT_WIDTH (font
);
20566 if (it
->constrain_row_ascent_descent_p
)
20568 if (it
->descent
> it
->max_descent
)
20570 it
->ascent
+= it
->descent
- it
->max_descent
;
20571 it
->descent
= it
->max_descent
;
20573 if (it
->ascent
> it
->max_ascent
)
20575 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20576 it
->ascent
= it
->max_ascent
;
20578 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20579 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20580 extra_line_spacing
= 0;
20583 /* If this is a space inside a region of text with
20584 `space-width' property, change its width. */
20585 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
20587 it
->pixel_width
*= XFLOATINT (it
->space_width
);
20589 /* If face has a box, add the box thickness to the character
20590 height. If character has a box line to the left and/or
20591 right, add the box line width to the character's width. */
20592 if (face
->box
!= FACE_NO_BOX
)
20594 int thick
= face
->box_line_width
;
20598 it
->ascent
+= thick
;
20599 it
->descent
+= thick
;
20604 if (it
->start_of_box_run_p
)
20605 it
->pixel_width
+= thick
;
20606 if (it
->end_of_box_run_p
)
20607 it
->pixel_width
+= thick
;
20610 /* If face has an overline, add the height of the overline
20611 (1 pixel) and a 1 pixel margin to the character height. */
20612 if (face
->overline_p
)
20613 it
->ascent
+= overline_margin
;
20615 if (it
->constrain_row_ascent_descent_p
)
20617 if (it
->ascent
> it
->max_ascent
)
20618 it
->ascent
= it
->max_ascent
;
20619 if (it
->descent
> it
->max_descent
)
20620 it
->descent
= it
->max_descent
;
20623 take_vertical_position_into_account (it
);
20625 /* If we have to actually produce glyphs, do it. */
20630 /* Translate a space with a `space-width' property
20631 into a stretch glyph. */
20632 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
20633 / FONT_HEIGHT (font
));
20634 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20635 it
->ascent
+ it
->descent
, ascent
);
20640 /* If characters with lbearing or rbearing are displayed
20641 in this line, record that fact in a flag of the
20642 glyph row. This is used to optimize X output code. */
20643 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
20644 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20647 else if (it
->char_to_display
== '\n')
20649 /* A newline has no width but we need the height of the line.
20650 But if previous part of the line set a height, don't
20651 increase that height */
20653 Lisp_Object height
;
20654 Lisp_Object total_height
= Qnil
;
20656 it
->override_ascent
= -1;
20657 it
->pixel_width
= 0;
20660 height
= get_line_height_property(it
, Qline_height
);
20661 /* Split (line-height total-height) list */
20663 && CONSP (XCDR (height
))
20664 && NILP (XCDR (XCDR (height
))))
20666 total_height
= XCAR (XCDR (height
));
20667 height
= XCAR (height
);
20669 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
20671 if (it
->override_ascent
>= 0)
20673 it
->ascent
= it
->override_ascent
;
20674 it
->descent
= it
->override_descent
;
20675 boff
= it
->override_boff
;
20679 it
->ascent
= FONT_BASE (font
) + boff
;
20680 it
->descent
= FONT_DESCENT (font
) - boff
;
20683 if (EQ (height
, Qt
))
20685 if (it
->descent
> it
->max_descent
)
20687 it
->ascent
+= it
->descent
- it
->max_descent
;
20688 it
->descent
= it
->max_descent
;
20690 if (it
->ascent
> it
->max_ascent
)
20692 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20693 it
->ascent
= it
->max_ascent
;
20695 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20696 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20697 it
->constrain_row_ascent_descent_p
= 1;
20698 extra_line_spacing
= 0;
20702 Lisp_Object spacing
;
20704 it
->phys_ascent
= it
->ascent
;
20705 it
->phys_descent
= it
->descent
;
20707 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
20708 && face
->box
!= FACE_NO_BOX
20709 && face
->box_line_width
> 0)
20711 it
->ascent
+= face
->box_line_width
;
20712 it
->descent
+= face
->box_line_width
;
20715 && XINT (height
) > it
->ascent
+ it
->descent
)
20716 it
->ascent
= XINT (height
) - it
->descent
;
20718 if (!NILP (total_height
))
20719 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
20722 spacing
= get_line_height_property(it
, Qline_spacing
);
20723 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
20725 if (INTEGERP (spacing
))
20727 extra_line_spacing
= XINT (spacing
);
20728 if (!NILP (total_height
))
20729 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
20733 else if (it
->char_to_display
== '\t')
20735 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
20736 int x
= it
->current_x
+ it
->continuation_lines_width
;
20737 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
20739 /* If the distance from the current position to the next tab
20740 stop is less than a space character width, use the
20741 tab stop after that. */
20742 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
20743 next_tab_x
+= tab_width
;
20745 it
->pixel_width
= next_tab_x
- x
;
20747 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
20748 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20752 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20753 it
->ascent
+ it
->descent
, it
->ascent
);
20758 /* A multi-byte character. Assume that the display width of the
20759 character is the width of the character multiplied by the
20760 width of the font. */
20762 /* If we found a font, this font should give us the right
20763 metrics. If we didn't find a font, use the frame's
20764 default font and calculate the width of the character
20765 from the charset width; this is what old redisplay code
20768 pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
20769 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
20771 if (font_not_found_p
|| !pcm
)
20773 int charset
= CHAR_CHARSET (it
->char_to_display
);
20775 it
->glyph_not_available_p
= 1;
20776 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
20777 * CHARSET_WIDTH (charset
));
20778 it
->phys_ascent
= FONT_BASE (font
) + boff
;
20779 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20783 it
->pixel_width
= pcm
->width
;
20784 it
->phys_ascent
= pcm
->ascent
+ boff
;
20785 it
->phys_descent
= pcm
->descent
- boff
;
20787 && (pcm
->lbearing
< 0
20788 || pcm
->rbearing
> pcm
->width
))
20789 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20792 it
->ascent
= FONT_BASE (font
) + boff
;
20793 it
->descent
= FONT_DESCENT (font
) - boff
;
20794 if (face
->box
!= FACE_NO_BOX
)
20796 int thick
= face
->box_line_width
;
20800 it
->ascent
+= thick
;
20801 it
->descent
+= thick
;
20806 if (it
->start_of_box_run_p
)
20807 it
->pixel_width
+= thick
;
20808 if (it
->end_of_box_run_p
)
20809 it
->pixel_width
+= thick
;
20812 /* If face has an overline, add the height of the overline
20813 (1 pixel) and a 1 pixel margin to the character height. */
20814 if (face
->overline_p
)
20815 it
->ascent
+= overline_margin
;
20817 take_vertical_position_into_account (it
);
20822 it
->multibyte_p
= saved_multibyte_p
;
20824 else if (it
->what
== IT_COMPOSITION
)
20826 /* Note: A composition is represented as one glyph in the
20827 glyph matrix. There are no padding glyphs. */
20830 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20832 int font_not_found_p
;
20833 struct font_info
*font_info
;
20834 int boff
; /* baseline offset */
20835 struct composition
*cmp
= composition_table
[it
->cmp_id
];
20837 /* Maybe translate single-byte characters to multibyte. */
20838 it
->char_to_display
= it
->c
;
20839 if (unibyte_display_via_language_environment
20840 && SINGLE_BYTE_CHAR_P (it
->c
)
20843 && !NILP (Vnonascii_translation_table
))))
20845 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20848 /* Get face and font to use. Encode IT->char_to_display. */
20849 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20850 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20851 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20852 &char2b
, it
->multibyte_p
, 0);
20855 /* When no suitable font found, use the default font. */
20856 font_not_found_p
= font
== NULL
;
20857 if (font_not_found_p
)
20859 font
= FRAME_FONT (it
->f
);
20860 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20865 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20866 boff
= font_info
->baseline_offset
;
20867 if (font_info
->vertical_centering
)
20868 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20871 /* There are no padding glyphs, so there is only one glyph to
20872 produce for the composition. Important is that pixel_width,
20873 ascent and descent are the values of what is drawn by
20874 draw_glyphs (i.e. the values of the overall glyphs composed). */
20877 /* If we have not yet calculated pixel size data of glyphs of
20878 the composition for the current face font, calculate them
20879 now. Theoretically, we have to check all fonts for the
20880 glyphs, but that requires much time and memory space. So,
20881 here we check only the font of the first glyph. This leads
20882 to incorrect display very rarely, and C-l (recenter) can
20883 correct the display anyway. */
20884 if (cmp
->font
!= (void *) font
)
20886 /* Ascent and descent of the font of the first character of
20887 this composition (adjusted by baseline offset). Ascent
20888 and descent of overall glyphs should not be less than
20889 them respectively. */
20890 int font_ascent
= FONT_BASE (font
) + boff
;
20891 int font_descent
= FONT_DESCENT (font
) - boff
;
20892 /* Bounding box of the overall glyphs. */
20893 int leftmost
, rightmost
, lowest
, highest
;
20894 int i
, width
, ascent
, descent
;
20896 cmp
->font
= (void *) font
;
20898 /* Initialize the bounding box. */
20900 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
20901 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
20903 width
= pcm
->width
;
20904 ascent
= pcm
->ascent
;
20905 descent
= pcm
->descent
;
20909 width
= FONT_WIDTH (font
);
20910 ascent
= FONT_BASE (font
);
20911 descent
= FONT_DESCENT (font
);
20915 lowest
= - descent
+ boff
;
20916 highest
= ascent
+ boff
;
20920 && font_info
->default_ascent
20921 && CHAR_TABLE_P (Vuse_default_ascent
)
20922 && !NILP (Faref (Vuse_default_ascent
,
20923 make_number (it
->char_to_display
))))
20924 highest
= font_info
->default_ascent
+ boff
;
20926 /* Draw the first glyph at the normal position. It may be
20927 shifted to right later if some other glyphs are drawn at
20929 cmp
->offsets
[0] = 0;
20930 cmp
->offsets
[1] = boff
;
20932 /* Set cmp->offsets for the remaining glyphs. */
20933 for (i
= 1; i
< cmp
->glyph_len
; i
++)
20935 int left
, right
, btm
, top
;
20936 int ch
= COMPOSITION_GLYPH (cmp
, i
);
20937 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
20939 face
= FACE_FROM_ID (it
->f
, face_id
);
20940 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
20941 &char2b
, it
->multibyte_p
, 0);
20945 font
= FRAME_FONT (it
->f
);
20946 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20952 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20953 boff
= font_info
->baseline_offset
;
20954 if (font_info
->vertical_centering
)
20955 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20959 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
20960 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
20962 width
= pcm
->width
;
20963 ascent
= pcm
->ascent
;
20964 descent
= pcm
->descent
;
20968 width
= FONT_WIDTH (font
);
20973 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
20975 /* Relative composition with or without
20976 alternate chars. */
20977 left
= (leftmost
+ rightmost
- width
) / 2;
20978 btm
= - descent
+ boff
;
20979 if (font_info
&& font_info
->relative_compose
20980 && (! CHAR_TABLE_P (Vignore_relative_composition
)
20981 || NILP (Faref (Vignore_relative_composition
,
20982 make_number (ch
)))))
20985 if (- descent
>= font_info
->relative_compose
)
20986 /* One extra pixel between two glyphs. */
20988 else if (ascent
<= 0)
20989 /* One extra pixel between two glyphs. */
20990 btm
= lowest
- 1 - ascent
- descent
;
20995 /* A composition rule is specified by an integer
20996 value that encodes global and new reference
20997 points (GREF and NREF). GREF and NREF are
20998 specified by numbers as below:
21000 0---1---2 -- ascent
21004 9--10--11 -- center
21006 ---3---4---5--- baseline
21008 6---7---8 -- descent
21010 int rule
= COMPOSITION_RULE (cmp
, i
);
21011 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
21013 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
21014 grefx
= gref
% 3, nrefx
= nref
% 3;
21015 grefy
= gref
/ 3, nrefy
= nref
/ 3;
21018 + grefx
* (rightmost
- leftmost
) / 2
21019 - nrefx
* width
/ 2);
21020 btm
= ((grefy
== 0 ? highest
21022 : grefy
== 2 ? lowest
21023 : (highest
+ lowest
) / 2)
21024 - (nrefy
== 0 ? ascent
+ descent
21025 : nrefy
== 1 ? descent
- boff
21027 : (ascent
+ descent
) / 2));
21030 cmp
->offsets
[i
* 2] = left
;
21031 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
21033 /* Update the bounding box of the overall glyphs. */
21034 right
= left
+ width
;
21035 top
= btm
+ descent
+ ascent
;
21036 if (left
< leftmost
)
21038 if (right
> rightmost
)
21046 /* If there are glyphs whose x-offsets are negative,
21047 shift all glyphs to the right and make all x-offsets
21051 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21052 cmp
->offsets
[i
* 2] -= leftmost
;
21053 rightmost
-= leftmost
;
21056 cmp
->pixel_width
= rightmost
;
21057 cmp
->ascent
= highest
;
21058 cmp
->descent
= - lowest
;
21059 if (cmp
->ascent
< font_ascent
)
21060 cmp
->ascent
= font_ascent
;
21061 if (cmp
->descent
< font_descent
)
21062 cmp
->descent
= font_descent
;
21065 it
->pixel_width
= cmp
->pixel_width
;
21066 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
21067 it
->descent
= it
->phys_descent
= cmp
->descent
;
21069 if (face
->box
!= FACE_NO_BOX
)
21071 int thick
= face
->box_line_width
;
21075 it
->ascent
+= thick
;
21076 it
->descent
+= thick
;
21081 if (it
->start_of_box_run_p
)
21082 it
->pixel_width
+= thick
;
21083 if (it
->end_of_box_run_p
)
21084 it
->pixel_width
+= thick
;
21087 /* If face has an overline, add the height of the overline
21088 (1 pixel) and a 1 pixel margin to the character height. */
21089 if (face
->overline_p
)
21090 it
->ascent
+= overline_margin
;
21092 take_vertical_position_into_account (it
);
21095 append_composite_glyph (it
);
21097 else if (it
->what
== IT_IMAGE
)
21098 produce_image_glyph (it
);
21099 else if (it
->what
== IT_STRETCH
)
21100 produce_stretch_glyph (it
);
21102 /* Accumulate dimensions. Note: can't assume that it->descent > 0
21103 because this isn't true for images with `:ascent 100'. */
21104 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
21105 if (it
->area
== TEXT_AREA
)
21106 it
->current_x
+= it
->pixel_width
;
21108 if (extra_line_spacing
> 0)
21110 it
->descent
+= extra_line_spacing
;
21111 if (extra_line_spacing
> it
->max_extra_line_spacing
)
21112 it
->max_extra_line_spacing
= extra_line_spacing
;
21115 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
21116 it
->max_descent
= max (it
->max_descent
, it
->descent
);
21117 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
21118 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
21122 Output LEN glyphs starting at START at the nominal cursor position.
21123 Advance the nominal cursor over the text. The global variable
21124 updated_window contains the window being updated, updated_row is
21125 the glyph row being updated, and updated_area is the area of that
21126 row being updated. */
21129 x_write_glyphs (start
, len
)
21130 struct glyph
*start
;
21135 xassert (updated_window
&& updated_row
);
21138 /* Write glyphs. */
21140 hpos
= start
- updated_row
->glyphs
[updated_area
];
21141 x
= draw_glyphs (updated_window
, output_cursor
.x
,
21142 updated_row
, updated_area
,
21144 DRAW_NORMAL_TEXT
, 0);
21146 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
21147 if (updated_area
== TEXT_AREA
21148 && updated_window
->phys_cursor_on_p
21149 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
21150 && updated_window
->phys_cursor
.hpos
>= hpos
21151 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
21152 updated_window
->phys_cursor_on_p
= 0;
21156 /* Advance the output cursor. */
21157 output_cursor
.hpos
+= len
;
21158 output_cursor
.x
= x
;
21163 Insert LEN glyphs from START at the nominal cursor position. */
21166 x_insert_glyphs (start
, len
)
21167 struct glyph
*start
;
21172 int line_height
, shift_by_width
, shifted_region_width
;
21173 struct glyph_row
*row
;
21174 struct glyph
*glyph
;
21175 int frame_x
, frame_y
, hpos
;
21177 xassert (updated_window
&& updated_row
);
21179 w
= updated_window
;
21180 f
= XFRAME (WINDOW_FRAME (w
));
21182 /* Get the height of the line we are in. */
21184 line_height
= row
->height
;
21186 /* Get the width of the glyphs to insert. */
21187 shift_by_width
= 0;
21188 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
21189 shift_by_width
+= glyph
->pixel_width
;
21191 /* Get the width of the region to shift right. */
21192 shifted_region_width
= (window_box_width (w
, updated_area
)
21197 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
21198 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
21200 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
21201 line_height
, shift_by_width
);
21203 /* Write the glyphs. */
21204 hpos
= start
- row
->glyphs
[updated_area
];
21205 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
21207 DRAW_NORMAL_TEXT
, 0);
21209 /* Advance the output cursor. */
21210 output_cursor
.hpos
+= len
;
21211 output_cursor
.x
+= shift_by_width
;
21217 Erase the current text line from the nominal cursor position
21218 (inclusive) to pixel column TO_X (exclusive). The idea is that
21219 everything from TO_X onward is already erased.
21221 TO_X is a pixel position relative to updated_area of
21222 updated_window. TO_X == -1 means clear to the end of this area. */
21225 x_clear_end_of_line (to_x
)
21229 struct window
*w
= updated_window
;
21230 int max_x
, min_y
, max_y
;
21231 int from_x
, from_y
, to_y
;
21233 xassert (updated_window
&& updated_row
);
21234 f
= XFRAME (w
->frame
);
21236 if (updated_row
->full_width_p
)
21237 max_x
= WINDOW_TOTAL_WIDTH (w
);
21239 max_x
= window_box_width (w
, updated_area
);
21240 max_y
= window_text_bottom_y (w
);
21242 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
21243 of window. For TO_X > 0, truncate to end of drawing area. */
21249 to_x
= min (to_x
, max_x
);
21251 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
21253 /* Notice if the cursor will be cleared by this operation. */
21254 if (!updated_row
->full_width_p
)
21255 notice_overwritten_cursor (w
, updated_area
,
21256 output_cursor
.x
, -1,
21258 MATRIX_ROW_BOTTOM_Y (updated_row
));
21260 from_x
= output_cursor
.x
;
21262 /* Translate to frame coordinates. */
21263 if (updated_row
->full_width_p
)
21265 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
21266 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
21270 int area_left
= window_box_left (w
, updated_area
);
21271 from_x
+= area_left
;
21275 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
21276 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
21277 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
21279 /* Prevent inadvertently clearing to end of the X window. */
21280 if (to_x
> from_x
&& to_y
> from_y
)
21283 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
21284 to_x
- from_x
, to_y
- from_y
);
21289 #endif /* HAVE_WINDOW_SYSTEM */
21293 /***********************************************************************
21295 ***********************************************************************/
21297 /* Value is the internal representation of the specified cursor type
21298 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
21299 of the bar cursor. */
21301 static enum text_cursor_kinds
21302 get_specified_cursor_type (arg
, width
)
21306 enum text_cursor_kinds type
;
21311 if (EQ (arg
, Qbox
))
21312 return FILLED_BOX_CURSOR
;
21314 if (EQ (arg
, Qhollow
))
21315 return HOLLOW_BOX_CURSOR
;
21317 if (EQ (arg
, Qbar
))
21324 && EQ (XCAR (arg
), Qbar
)
21325 && INTEGERP (XCDR (arg
))
21326 && XINT (XCDR (arg
)) >= 0)
21328 *width
= XINT (XCDR (arg
));
21332 if (EQ (arg
, Qhbar
))
21335 return HBAR_CURSOR
;
21339 && EQ (XCAR (arg
), Qhbar
)
21340 && INTEGERP (XCDR (arg
))
21341 && XINT (XCDR (arg
)) >= 0)
21343 *width
= XINT (XCDR (arg
));
21344 return HBAR_CURSOR
;
21347 /* Treat anything unknown as "hollow box cursor".
21348 It was bad to signal an error; people have trouble fixing
21349 .Xdefaults with Emacs, when it has something bad in it. */
21350 type
= HOLLOW_BOX_CURSOR
;
21355 /* Set the default cursor types for specified frame. */
21357 set_frame_cursor_types (f
, arg
)
21364 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
21365 FRAME_CURSOR_WIDTH (f
) = width
;
21367 /* By default, set up the blink-off state depending on the on-state. */
21369 tem
= Fassoc (arg
, Vblink_cursor_alist
);
21372 FRAME_BLINK_OFF_CURSOR (f
)
21373 = get_specified_cursor_type (XCDR (tem
), &width
);
21374 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
21377 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
21381 /* Return the cursor we want to be displayed in window W. Return
21382 width of bar/hbar cursor through WIDTH arg. Return with
21383 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
21384 (i.e. if the `system caret' should track this cursor).
21386 In a mini-buffer window, we want the cursor only to appear if we
21387 are reading input from this window. For the selected window, we
21388 want the cursor type given by the frame parameter or buffer local
21389 setting of cursor-type. If explicitly marked off, draw no cursor.
21390 In all other cases, we want a hollow box cursor. */
21392 static enum text_cursor_kinds
21393 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
21395 struct glyph
*glyph
;
21397 int *active_cursor
;
21399 struct frame
*f
= XFRAME (w
->frame
);
21400 struct buffer
*b
= XBUFFER (w
->buffer
);
21401 int cursor_type
= DEFAULT_CURSOR
;
21402 Lisp_Object alt_cursor
;
21403 int non_selected
= 0;
21405 *active_cursor
= 1;
21408 if (cursor_in_echo_area
21409 && FRAME_HAS_MINIBUF_P (f
)
21410 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
21412 if (w
== XWINDOW (echo_area_window
))
21414 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
21416 *width
= FRAME_CURSOR_WIDTH (f
);
21417 return FRAME_DESIRED_CURSOR (f
);
21420 return get_specified_cursor_type (b
->cursor_type
, width
);
21423 *active_cursor
= 0;
21427 /* Detect a nonselected window or nonselected frame. */
21428 else if (w
!= XWINDOW (f
->selected_window
)
21429 #ifdef HAVE_WINDOW_SYSTEM
21430 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
21434 *active_cursor
= 0;
21436 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
21442 /* Never display a cursor in a window in which cursor-type is nil. */
21443 if (NILP (b
->cursor_type
))
21446 /* Get the normal cursor type for this window. */
21447 if (EQ (b
->cursor_type
, Qt
))
21449 cursor_type
= FRAME_DESIRED_CURSOR (f
);
21450 *width
= FRAME_CURSOR_WIDTH (f
);
21453 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
21455 /* Use cursor-in-non-selected-windows instead
21456 for non-selected window or frame. */
21459 alt_cursor
= b
->cursor_in_non_selected_windows
;
21460 if (!EQ (Qt
, alt_cursor
))
21461 return get_specified_cursor_type (alt_cursor
, width
);
21462 /* t means modify the normal cursor type. */
21463 if (cursor_type
== FILLED_BOX_CURSOR
)
21464 cursor_type
= HOLLOW_BOX_CURSOR
;
21465 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
21467 return cursor_type
;
21470 /* Use normal cursor if not blinked off. */
21471 if (!w
->cursor_off_p
)
21473 #ifdef HAVE_WINDOW_SYSTEM
21474 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21476 if (cursor_type
== FILLED_BOX_CURSOR
)
21478 /* Using a block cursor on large images can be very annoying.
21479 So use a hollow cursor for "large" images.
21480 If image is not transparent (no mask), also use hollow cursor. */
21481 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21482 if (img
!= NULL
&& IMAGEP (img
->spec
))
21484 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
21485 where N = size of default frame font size.
21486 This should cover most of the "tiny" icons people may use. */
21488 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
21489 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
21490 cursor_type
= HOLLOW_BOX_CURSOR
;
21493 else if (cursor_type
!= NO_CURSOR
)
21495 /* Display current only supports BOX and HOLLOW cursors for images.
21496 So for now, unconditionally use a HOLLOW cursor when cursor is
21497 not a solid box cursor. */
21498 cursor_type
= HOLLOW_BOX_CURSOR
;
21502 return cursor_type
;
21505 /* Cursor is blinked off, so determine how to "toggle" it. */
21507 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
21508 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
21509 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
21511 /* Then see if frame has specified a specific blink off cursor type. */
21512 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
21514 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
21515 return FRAME_BLINK_OFF_CURSOR (f
);
21519 /* Some people liked having a permanently visible blinking cursor,
21520 while others had very strong opinions against it. So it was
21521 decided to remove it. KFS 2003-09-03 */
21523 /* Finally perform built-in cursor blinking:
21524 filled box <-> hollow box
21525 wide [h]bar <-> narrow [h]bar
21526 narrow [h]bar <-> no cursor
21527 other type <-> no cursor */
21529 if (cursor_type
== FILLED_BOX_CURSOR
)
21530 return HOLLOW_BOX_CURSOR
;
21532 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
21535 return cursor_type
;
21543 #ifdef HAVE_WINDOW_SYSTEM
21545 /* Notice when the text cursor of window W has been completely
21546 overwritten by a drawing operation that outputs glyphs in AREA
21547 starting at X0 and ending at X1 in the line starting at Y0 and
21548 ending at Y1. X coordinates are area-relative. X1 < 0 means all
21549 the rest of the line after X0 has been written. Y coordinates
21550 are window-relative. */
21553 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
21555 enum glyph_row_area area
;
21556 int x0
, y0
, x1
, y1
;
21558 int cx0
, cx1
, cy0
, cy1
;
21559 struct glyph_row
*row
;
21561 if (!w
->phys_cursor_on_p
)
21563 if (area
!= TEXT_AREA
)
21566 if (w
->phys_cursor
.vpos
< 0
21567 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
21568 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
21569 !(row
->enabled_p
&& row
->displays_text_p
)))
21572 if (row
->cursor_in_fringe_p
)
21574 row
->cursor_in_fringe_p
= 0;
21575 draw_fringe_bitmap (w
, row
, 0);
21576 w
->phys_cursor_on_p
= 0;
21580 cx0
= w
->phys_cursor
.x
;
21581 cx1
= cx0
+ w
->phys_cursor_width
;
21582 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
21585 /* The cursor image will be completely removed from the
21586 screen if the output area intersects the cursor area in
21587 y-direction. When we draw in [y0 y1[, and some part of
21588 the cursor is at y < y0, that part must have been drawn
21589 before. When scrolling, the cursor is erased before
21590 actually scrolling, so we don't come here. When not
21591 scrolling, the rows above the old cursor row must have
21592 changed, and in this case these rows must have written
21593 over the cursor image.
21595 Likewise if part of the cursor is below y1, with the
21596 exception of the cursor being in the first blank row at
21597 the buffer and window end because update_text_area
21598 doesn't draw that row. (Except when it does, but
21599 that's handled in update_text_area.) */
21601 cy0
= w
->phys_cursor
.y
;
21602 cy1
= cy0
+ w
->phys_cursor_height
;
21603 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
21606 w
->phys_cursor_on_p
= 0;
21609 #endif /* HAVE_WINDOW_SYSTEM */
21612 /************************************************************************
21614 ************************************************************************/
21616 #ifdef HAVE_WINDOW_SYSTEM
21619 Fix the display of area AREA of overlapping row ROW in window W
21620 with respect to the overlapping part OVERLAPS. */
21623 x_fix_overlapping_area (w
, row
, area
, overlaps
)
21625 struct glyph_row
*row
;
21626 enum glyph_row_area area
;
21634 for (i
= 0; i
< row
->used
[area
];)
21636 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
21638 int start
= i
, start_x
= x
;
21642 x
+= row
->glyphs
[area
][i
].pixel_width
;
21645 while (i
< row
->used
[area
]
21646 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
21648 draw_glyphs (w
, start_x
, row
, area
,
21650 DRAW_NORMAL_TEXT
, overlaps
);
21654 x
+= row
->glyphs
[area
][i
].pixel_width
;
21664 Draw the cursor glyph of window W in glyph row ROW. See the
21665 comment of draw_glyphs for the meaning of HL. */
21668 draw_phys_cursor_glyph (w
, row
, hl
)
21670 struct glyph_row
*row
;
21671 enum draw_glyphs_face hl
;
21673 /* If cursor hpos is out of bounds, don't draw garbage. This can
21674 happen in mini-buffer windows when switching between echo area
21675 glyphs and mini-buffer. */
21676 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
21678 int on_p
= w
->phys_cursor_on_p
;
21680 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
21681 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
21683 w
->phys_cursor_on_p
= on_p
;
21685 if (hl
== DRAW_CURSOR
)
21686 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21687 /* When we erase the cursor, and ROW is overlapped by other
21688 rows, make sure that these overlapping parts of other rows
21690 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
21692 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21694 if (row
> w
->current_matrix
->rows
21695 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
21696 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
21697 OVERLAPS_ERASED_CURSOR
);
21699 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
21700 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
21701 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
21702 OVERLAPS_ERASED_CURSOR
);
21709 Erase the image of a cursor of window W from the screen. */
21712 erase_phys_cursor (w
)
21715 struct frame
*f
= XFRAME (w
->frame
);
21716 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21717 int hpos
= w
->phys_cursor
.hpos
;
21718 int vpos
= w
->phys_cursor
.vpos
;
21719 int mouse_face_here_p
= 0;
21720 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
21721 struct glyph_row
*cursor_row
;
21722 struct glyph
*cursor_glyph
;
21723 enum draw_glyphs_face hl
;
21725 /* No cursor displayed or row invalidated => nothing to do on the
21727 if (w
->phys_cursor_type
== NO_CURSOR
)
21728 goto mark_cursor_off
;
21730 /* VPOS >= active_glyphs->nrows means that window has been resized.
21731 Don't bother to erase the cursor. */
21732 if (vpos
>= active_glyphs
->nrows
)
21733 goto mark_cursor_off
;
21735 /* If row containing cursor is marked invalid, there is nothing we
21737 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
21738 if (!cursor_row
->enabled_p
)
21739 goto mark_cursor_off
;
21741 /* If line spacing is > 0, old cursor may only be partially visible in
21742 window after split-window. So adjust visible height. */
21743 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
21744 window_text_bottom_y (w
) - cursor_row
->y
);
21746 /* If row is completely invisible, don't attempt to delete a cursor which
21747 isn't there. This can happen if cursor is at top of a window, and
21748 we switch to a buffer with a header line in that window. */
21749 if (cursor_row
->visible_height
<= 0)
21750 goto mark_cursor_off
;
21752 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
21753 if (cursor_row
->cursor_in_fringe_p
)
21755 cursor_row
->cursor_in_fringe_p
= 0;
21756 draw_fringe_bitmap (w
, cursor_row
, 0);
21757 goto mark_cursor_off
;
21760 /* This can happen when the new row is shorter than the old one.
21761 In this case, either draw_glyphs or clear_end_of_line
21762 should have cleared the cursor. Note that we wouldn't be
21763 able to erase the cursor in this case because we don't have a
21764 cursor glyph at hand. */
21765 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
21766 goto mark_cursor_off
;
21768 /* If the cursor is in the mouse face area, redisplay that when
21769 we clear the cursor. */
21770 if (! NILP (dpyinfo
->mouse_face_window
)
21771 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
21772 && (vpos
> dpyinfo
->mouse_face_beg_row
21773 || (vpos
== dpyinfo
->mouse_face_beg_row
21774 && hpos
>= dpyinfo
->mouse_face_beg_col
))
21775 && (vpos
< dpyinfo
->mouse_face_end_row
21776 || (vpos
== dpyinfo
->mouse_face_end_row
21777 && hpos
< dpyinfo
->mouse_face_end_col
))
21778 /* Don't redraw the cursor's spot in mouse face if it is at the
21779 end of a line (on a newline). The cursor appears there, but
21780 mouse highlighting does not. */
21781 && cursor_row
->used
[TEXT_AREA
] > hpos
)
21782 mouse_face_here_p
= 1;
21784 /* Maybe clear the display under the cursor. */
21785 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
21788 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
21791 cursor_glyph
= get_phys_cursor_glyph (w
);
21792 if (cursor_glyph
== NULL
)
21793 goto mark_cursor_off
;
21795 width
= cursor_glyph
->pixel_width
;
21796 left_x
= window_box_left_offset (w
, TEXT_AREA
);
21797 x
= w
->phys_cursor
.x
;
21799 width
-= left_x
- x
;
21800 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
21801 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
21802 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
21805 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
21808 /* Erase the cursor by redrawing the character underneath it. */
21809 if (mouse_face_here_p
)
21810 hl
= DRAW_MOUSE_FACE
;
21812 hl
= DRAW_NORMAL_TEXT
;
21813 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
21816 w
->phys_cursor_on_p
= 0;
21817 w
->phys_cursor_type
= NO_CURSOR
;
21822 Display or clear cursor of window W. If ON is zero, clear the
21823 cursor. If it is non-zero, display the cursor. If ON is nonzero,
21824 where to put the cursor is specified by HPOS, VPOS, X and Y. */
21827 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
21829 int on
, hpos
, vpos
, x
, y
;
21831 struct frame
*f
= XFRAME (w
->frame
);
21832 int new_cursor_type
;
21833 int new_cursor_width
;
21835 struct glyph_row
*glyph_row
;
21836 struct glyph
*glyph
;
21838 /* This is pointless on invisible frames, and dangerous on garbaged
21839 windows and frames; in the latter case, the frame or window may
21840 be in the midst of changing its size, and x and y may be off the
21842 if (! FRAME_VISIBLE_P (f
)
21843 || FRAME_GARBAGED_P (f
)
21844 || vpos
>= w
->current_matrix
->nrows
21845 || hpos
>= w
->current_matrix
->matrix_w
)
21848 /* If cursor is off and we want it off, return quickly. */
21849 if (!on
&& !w
->phys_cursor_on_p
)
21852 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
21853 /* If cursor row is not enabled, we don't really know where to
21854 display the cursor. */
21855 if (!glyph_row
->enabled_p
)
21857 w
->phys_cursor_on_p
= 0;
21862 if (!glyph_row
->exact_window_width_line_p
21863 || hpos
< glyph_row
->used
[TEXT_AREA
])
21864 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
21866 xassert (interrupt_input_blocked
);
21868 /* Set new_cursor_type to the cursor we want to be displayed. */
21869 new_cursor_type
= get_window_cursor_type (w
, glyph
,
21870 &new_cursor_width
, &active_cursor
);
21872 /* If cursor is currently being shown and we don't want it to be or
21873 it is in the wrong place, or the cursor type is not what we want,
21875 if (w
->phys_cursor_on_p
21877 || w
->phys_cursor
.x
!= x
21878 || w
->phys_cursor
.y
!= y
21879 || new_cursor_type
!= w
->phys_cursor_type
21880 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
21881 && new_cursor_width
!= w
->phys_cursor_width
)))
21882 erase_phys_cursor (w
);
21884 /* Don't check phys_cursor_on_p here because that flag is only set
21885 to zero in some cases where we know that the cursor has been
21886 completely erased, to avoid the extra work of erasing the cursor
21887 twice. In other words, phys_cursor_on_p can be 1 and the cursor
21888 still not be visible, or it has only been partly erased. */
21891 w
->phys_cursor_ascent
= glyph_row
->ascent
;
21892 w
->phys_cursor_height
= glyph_row
->height
;
21894 /* Set phys_cursor_.* before x_draw_.* is called because some
21895 of them may need the information. */
21896 w
->phys_cursor
.x
= x
;
21897 w
->phys_cursor
.y
= glyph_row
->y
;
21898 w
->phys_cursor
.hpos
= hpos
;
21899 w
->phys_cursor
.vpos
= vpos
;
21902 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
21903 new_cursor_type
, new_cursor_width
,
21904 on
, active_cursor
);
21908 /* Switch the display of W's cursor on or off, according to the value
21912 update_window_cursor (w
, on
)
21916 /* Don't update cursor in windows whose frame is in the process
21917 of being deleted. */
21918 if (w
->current_matrix
)
21921 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21922 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21928 /* Call update_window_cursor with parameter ON_P on all leaf windows
21929 in the window tree rooted at W. */
21932 update_cursor_in_window_tree (w
, on_p
)
21938 if (!NILP (w
->hchild
))
21939 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
21940 else if (!NILP (w
->vchild
))
21941 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
21943 update_window_cursor (w
, on_p
);
21945 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
21951 Display the cursor on window W, or clear it, according to ON_P.
21952 Don't change the cursor's position. */
21955 x_update_cursor (f
, on_p
)
21959 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
21964 Clear the cursor of window W to background color, and mark the
21965 cursor as not shown. This is used when the text where the cursor
21966 is is about to be rewritten. */
21972 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
21973 update_window_cursor (w
, 0);
21978 Display the active region described by mouse_face_* according to DRAW. */
21981 show_mouse_face (dpyinfo
, draw
)
21982 Display_Info
*dpyinfo
;
21983 enum draw_glyphs_face draw
;
21985 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
21986 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21988 if (/* If window is in the process of being destroyed, don't bother
21990 w
->current_matrix
!= NULL
21991 /* Don't update mouse highlight if hidden */
21992 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
21993 /* Recognize when we are called to operate on rows that don't exist
21994 anymore. This can happen when a window is split. */
21995 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
21997 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
21998 struct glyph_row
*row
, *first
, *last
;
22000 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
22001 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
22003 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
22005 int start_hpos
, end_hpos
, start_x
;
22007 /* For all but the first row, the highlight starts at column 0. */
22010 start_hpos
= dpyinfo
->mouse_face_beg_col
;
22011 start_x
= dpyinfo
->mouse_face_beg_x
;
22020 end_hpos
= dpyinfo
->mouse_face_end_col
;
22023 end_hpos
= row
->used
[TEXT_AREA
];
22024 if (draw
== DRAW_NORMAL_TEXT
)
22025 row
->fill_line_p
= 1; /* Clear to end of line */
22028 if (end_hpos
> start_hpos
)
22030 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
22031 start_hpos
, end_hpos
,
22035 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
22039 /* When we've written over the cursor, arrange for it to
22040 be displayed again. */
22041 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
22044 display_and_set_cursor (w
, 1,
22045 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22046 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22051 /* Change the mouse cursor. */
22052 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
22053 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
22054 else if (draw
== DRAW_MOUSE_FACE
)
22055 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
22057 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
22061 Clear out the mouse-highlighted active region.
22062 Redraw it un-highlighted first. Value is non-zero if mouse
22063 face was actually drawn unhighlighted. */
22066 clear_mouse_face (dpyinfo
)
22067 Display_Info
*dpyinfo
;
22071 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
22073 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
22077 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22078 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22079 dpyinfo
->mouse_face_window
= Qnil
;
22080 dpyinfo
->mouse_face_overlay
= Qnil
;
22086 Non-zero if physical cursor of window W is within mouse face. */
22089 cursor_in_mouse_face_p (w
)
22092 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22093 int in_mouse_face
= 0;
22095 if (WINDOWP (dpyinfo
->mouse_face_window
)
22096 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
22098 int hpos
= w
->phys_cursor
.hpos
;
22099 int vpos
= w
->phys_cursor
.vpos
;
22101 if (vpos
>= dpyinfo
->mouse_face_beg_row
22102 && vpos
<= dpyinfo
->mouse_face_end_row
22103 && (vpos
> dpyinfo
->mouse_face_beg_row
22104 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22105 && (vpos
< dpyinfo
->mouse_face_end_row
22106 || hpos
< dpyinfo
->mouse_face_end_col
22107 || dpyinfo
->mouse_face_past_end
))
22111 return in_mouse_face
;
22117 /* Find the glyph matrix position of buffer position CHARPOS in window
22118 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
22119 current glyphs must be up to date. If CHARPOS is above window
22120 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
22121 of last line in W. In the row containing CHARPOS, stop before glyphs
22122 having STOP as object. */
22124 #if 1 /* This is a version of fast_find_position that's more correct
22125 in the presence of hscrolling, for example. I didn't install
22126 it right away because the problem fixed is minor, it failed
22127 in 20.x as well, and I think it's too risky to install
22128 so near the release of 21.1. 2001-09-25 gerd. */
22131 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
22134 int *hpos
, *vpos
, *x
, *y
;
22137 struct glyph_row
*row
, *first
;
22138 struct glyph
*glyph
, *end
;
22141 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22142 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
22147 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
22151 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
22154 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22158 /* If whole rows or last part of a row came from a display overlay,
22159 row_containing_pos will skip over such rows because their end pos
22160 equals the start pos of the overlay or interval.
22162 Move back if we have a STOP object and previous row's
22163 end glyph came from STOP. */
22166 struct glyph_row
*prev
;
22167 while ((prev
= row
- 1, prev
>= first
)
22168 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
22169 && prev
->used
[TEXT_AREA
] > 0)
22171 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
22172 glyph
= beg
+ prev
->used
[TEXT_AREA
];
22173 while (--glyph
>= beg
22174 && INTEGERP (glyph
->object
));
22176 || !EQ (stop
, glyph
->object
))
22184 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22186 glyph
= row
->glyphs
[TEXT_AREA
];
22187 end
= glyph
+ row
->used
[TEXT_AREA
];
22189 /* Skip over glyphs not having an object at the start of the row.
22190 These are special glyphs like truncation marks on terminal
22192 if (row
->displays_text_p
)
22194 && INTEGERP (glyph
->object
)
22195 && !EQ (stop
, glyph
->object
)
22196 && glyph
->charpos
< 0)
22198 *x
+= glyph
->pixel_width
;
22203 && !INTEGERP (glyph
->object
)
22204 && !EQ (stop
, glyph
->object
)
22205 && (!BUFFERP (glyph
->object
)
22206 || glyph
->charpos
< charpos
))
22208 *x
+= glyph
->pixel_width
;
22212 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
22219 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
22222 int *hpos
, *vpos
, *x
, *y
;
22227 int maybe_next_line_p
= 0;
22228 int line_start_position
;
22229 int yb
= window_text_bottom_y (w
);
22230 struct glyph_row
*row
, *best_row
;
22231 int row_vpos
, best_row_vpos
;
22234 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22235 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22237 while (row
->y
< yb
)
22239 if (row
->used
[TEXT_AREA
])
22240 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
22242 line_start_position
= 0;
22244 if (line_start_position
> pos
)
22246 /* If the position sought is the end of the buffer,
22247 don't include the blank lines at the bottom of the window. */
22248 else if (line_start_position
== pos
22249 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
22251 maybe_next_line_p
= 1;
22254 else if (line_start_position
> 0)
22257 best_row_vpos
= row_vpos
;
22260 if (row
->y
+ row
->height
>= yb
)
22267 /* Find the right column within BEST_ROW. */
22269 current_x
= best_row
->x
;
22270 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
22272 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
22273 int charpos
= glyph
->charpos
;
22275 if (BUFFERP (glyph
->object
))
22277 if (charpos
== pos
)
22280 *vpos
= best_row_vpos
;
22285 else if (charpos
> pos
)
22288 else if (EQ (glyph
->object
, stop
))
22293 current_x
+= glyph
->pixel_width
;
22296 /* If we're looking for the end of the buffer,
22297 and we didn't find it in the line we scanned,
22298 use the start of the following line. */
22299 if (maybe_next_line_p
)
22304 current_x
= best_row
->x
;
22307 *vpos
= best_row_vpos
;
22308 *hpos
= lastcol
+ 1;
22317 /* Find the position of the glyph for position POS in OBJECT in
22318 window W's current matrix, and return in *X, *Y the pixel
22319 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
22321 RIGHT_P non-zero means return the position of the right edge of the
22322 glyph, RIGHT_P zero means return the left edge position.
22324 If no glyph for POS exists in the matrix, return the position of
22325 the glyph with the next smaller position that is in the matrix, if
22326 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
22327 exists in the matrix, return the position of the glyph with the
22328 next larger position in OBJECT.
22330 Value is non-zero if a glyph was found. */
22333 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
22336 Lisp_Object object
;
22337 int *hpos
, *vpos
, *x
, *y
;
22340 int yb
= window_text_bottom_y (w
);
22341 struct glyph_row
*r
;
22342 struct glyph
*best_glyph
= NULL
;
22343 struct glyph_row
*best_row
= NULL
;
22346 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22347 r
->enabled_p
&& r
->y
< yb
;
22350 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
22351 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
22354 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
22355 if (EQ (g
->object
, object
))
22357 if (g
->charpos
== pos
)
22364 else if (best_glyph
== NULL
22365 || ((eabs (g
->charpos
- pos
)
22366 < eabs (best_glyph
->charpos
- pos
))
22369 : g
->charpos
> pos
)))
22383 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
22387 *x
+= best_glyph
->pixel_width
;
22392 *vpos
= best_row
- w
->current_matrix
->rows
;
22395 return best_glyph
!= NULL
;
22399 /* See if position X, Y is within a hot-spot of an image. */
22402 on_hot_spot_p (hot_spot
, x
, y
)
22403 Lisp_Object hot_spot
;
22406 if (!CONSP (hot_spot
))
22409 if (EQ (XCAR (hot_spot
), Qrect
))
22411 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
22412 Lisp_Object rect
= XCDR (hot_spot
);
22416 if (!CONSP (XCAR (rect
)))
22418 if (!CONSP (XCDR (rect
)))
22420 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
22422 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
22424 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
22426 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
22430 else if (EQ (XCAR (hot_spot
), Qcircle
))
22432 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
22433 Lisp_Object circ
= XCDR (hot_spot
);
22434 Lisp_Object lr
, lx0
, ly0
;
22436 && CONSP (XCAR (circ
))
22437 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
22438 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
22439 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
22441 double r
= XFLOATINT (lr
);
22442 double dx
= XINT (lx0
) - x
;
22443 double dy
= XINT (ly0
) - y
;
22444 return (dx
* dx
+ dy
* dy
<= r
* r
);
22447 else if (EQ (XCAR (hot_spot
), Qpoly
))
22449 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
22450 if (VECTORP (XCDR (hot_spot
)))
22452 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
22453 Lisp_Object
*poly
= v
->contents
;
22457 Lisp_Object lx
, ly
;
22460 /* Need an even number of coordinates, and at least 3 edges. */
22461 if (n
< 6 || n
& 1)
22464 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
22465 If count is odd, we are inside polygon. Pixels on edges
22466 may or may not be included depending on actual geometry of the
22468 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
22469 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
22471 x0
= XINT (lx
), y0
= XINT (ly
);
22472 for (i
= 0; i
< n
; i
+= 2)
22474 int x1
= x0
, y1
= y0
;
22475 if ((lx
= poly
[i
], !INTEGERP (lx
))
22476 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
22478 x0
= XINT (lx
), y0
= XINT (ly
);
22480 /* Does this segment cross the X line? */
22488 if (y
> y0
&& y
> y1
)
22490 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
22500 find_hot_spot (map
, x
, y
)
22504 while (CONSP (map
))
22506 if (CONSP (XCAR (map
))
22507 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
22515 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
22517 doc
: /* Lookup in image map MAP coordinates X and Y.
22518 An image map is an alist where each element has the format (AREA ID PLIST).
22519 An AREA is specified as either a rectangle, a circle, or a polygon:
22520 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
22521 pixel coordinates of the upper left and bottom right corners.
22522 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
22523 and the radius of the circle; r may be a float or integer.
22524 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
22525 vector describes one corner in the polygon.
22526 Returns the alist element for the first matching AREA in MAP. */)
22537 return find_hot_spot (map
, XINT (x
), XINT (y
));
22541 /* Display frame CURSOR, optionally using shape defined by POINTER. */
22543 define_frame_cursor1 (f
, cursor
, pointer
)
22546 Lisp_Object pointer
;
22548 /* Do not change cursor shape while dragging mouse. */
22549 if (!NILP (do_mouse_tracking
))
22552 if (!NILP (pointer
))
22554 if (EQ (pointer
, Qarrow
))
22555 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22556 else if (EQ (pointer
, Qhand
))
22557 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
22558 else if (EQ (pointer
, Qtext
))
22559 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22560 else if (EQ (pointer
, intern ("hdrag")))
22561 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22562 #ifdef HAVE_X_WINDOWS
22563 else if (EQ (pointer
, intern ("vdrag")))
22564 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
22566 else if (EQ (pointer
, intern ("hourglass")))
22567 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
22568 else if (EQ (pointer
, Qmodeline
))
22569 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
22571 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22574 if (cursor
!= No_Cursor
)
22575 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
22578 /* Take proper action when mouse has moved to the mode or header line
22579 or marginal area AREA of window W, x-position X and y-position Y.
22580 X is relative to the start of the text display area of W, so the
22581 width of bitmap areas and scroll bars must be subtracted to get a
22582 position relative to the start of the mode line. */
22585 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
22586 Lisp_Object window
;
22588 enum window_part area
;
22590 struct window
*w
= XWINDOW (window
);
22591 struct frame
*f
= XFRAME (w
->frame
);
22592 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22593 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22594 Lisp_Object pointer
= Qnil
;
22595 int charpos
, dx
, dy
, width
, height
;
22596 Lisp_Object string
, object
= Qnil
;
22597 Lisp_Object pos
, help
;
22599 Lisp_Object mouse_face
;
22600 int original_x_pixel
= x
;
22601 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
22602 struct glyph_row
*row
;
22604 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
22609 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
22610 &object
, &dx
, &dy
, &width
, &height
);
22612 row
= (area
== ON_MODE_LINE
22613 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
22614 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
22617 if (row
->mode_line_p
&& row
->enabled_p
)
22619 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
22620 end
= glyph
+ row
->used
[TEXT_AREA
];
22622 for (x0
= original_x_pixel
;
22623 glyph
< end
&& x0
>= glyph
->pixel_width
;
22625 x0
-= glyph
->pixel_width
;
22633 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
22634 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
22635 &object
, &dx
, &dy
, &width
, &height
);
22640 if (IMAGEP (object
))
22642 Lisp_Object image_map
, hotspot
;
22643 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
22645 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
22647 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22649 Lisp_Object area_id
, plist
;
22651 area_id
= XCAR (hotspot
);
22652 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22653 If so, we could look for mouse-enter, mouse-leave
22654 properties in PLIST (and do something...). */
22655 hotspot
= XCDR (hotspot
);
22656 if (CONSP (hotspot
)
22657 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22659 pointer
= Fplist_get (plist
, Qpointer
);
22660 if (NILP (pointer
))
22662 help
= Fplist_get (plist
, Qhelp_echo
);
22665 help_echo_string
= help
;
22666 /* Is this correct? ++kfs */
22667 XSETWINDOW (help_echo_window
, w
);
22668 help_echo_object
= w
->buffer
;
22669 help_echo_pos
= charpos
;
22673 if (NILP (pointer
))
22674 pointer
= Fplist_get (XCDR (object
), QCpointer
);
22677 if (STRINGP (string
))
22679 pos
= make_number (charpos
);
22680 /* If we're on a string with `help-echo' text property, arrange
22681 for the help to be displayed. This is done by setting the
22682 global variable help_echo_string to the help string. */
22685 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
22688 help_echo_string
= help
;
22689 XSETWINDOW (help_echo_window
, w
);
22690 help_echo_object
= string
;
22691 help_echo_pos
= charpos
;
22695 if (NILP (pointer
))
22696 pointer
= Fget_text_property (pos
, Qpointer
, string
);
22698 /* Change the mouse pointer according to what is under X/Y. */
22699 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
22702 map
= Fget_text_property (pos
, Qlocal_map
, string
);
22703 if (!KEYMAPP (map
))
22704 map
= Fget_text_property (pos
, Qkeymap
, string
);
22705 if (!KEYMAPP (map
))
22706 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
22709 /* Change the mouse face according to what is under X/Y. */
22710 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
22711 if (!NILP (mouse_face
)
22712 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22717 struct glyph
* tmp_glyph
;
22721 int total_pixel_width
;
22726 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
22727 Qmouse_face
, string
, Qnil
);
22729 b
= make_number (0);
22731 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
22733 e
= make_number (SCHARS (string
));
22735 /* Calculate the position(glyph position: GPOS) of GLYPH in
22736 displayed string. GPOS is different from CHARPOS.
22738 CHARPOS is the position of glyph in internal string
22739 object. A mode line string format has structures which
22740 is converted to a flatten by emacs lisp interpreter.
22741 The internal string is an element of the structures.
22742 The displayed string is the flatten string. */
22744 if (glyph
> row_start_glyph
)
22746 tmp_glyph
= glyph
- 1;
22747 while (tmp_glyph
>= row_start_glyph
22748 && tmp_glyph
->charpos
>= XINT (b
)
22749 && EQ (tmp_glyph
->object
, glyph
->object
))
22756 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
22757 displayed string holding GLYPH.
22759 GSEQ_LENGTH is different from SCHARS (STRING).
22760 SCHARS (STRING) returns the length of the internal string. */
22761 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
22762 tmp_glyph
->charpos
< XINT (e
);
22763 tmp_glyph
++, gseq_length
++)
22765 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22769 total_pixel_width
= 0;
22770 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
22771 total_pixel_width
+= tmp_glyph
->pixel_width
;
22773 /* Pre calculation of re-rendering position */
22775 hpos
= (area
== ON_MODE_LINE
22776 ? (w
->current_matrix
)->nrows
- 1
22779 /* If the re-rendering position is included in the last
22780 re-rendering area, we should do nothing. */
22781 if ( EQ (window
, dpyinfo
->mouse_face_window
)
22782 && dpyinfo
->mouse_face_beg_col
<= vpos
22783 && vpos
< dpyinfo
->mouse_face_end_col
22784 && dpyinfo
->mouse_face_beg_row
== hpos
)
22787 if (clear_mouse_face (dpyinfo
))
22788 cursor
= No_Cursor
;
22790 dpyinfo
->mouse_face_beg_col
= vpos
;
22791 dpyinfo
->mouse_face_beg_row
= hpos
;
22793 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
22794 dpyinfo
->mouse_face_beg_y
= 0;
22796 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
22797 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
22799 dpyinfo
->mouse_face_end_x
= 0;
22800 dpyinfo
->mouse_face_end_y
= 0;
22802 dpyinfo
->mouse_face_past_end
= 0;
22803 dpyinfo
->mouse_face_window
= window
;
22805 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
22808 glyph
->face_id
, 1);
22809 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22811 if (NILP (pointer
))
22814 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22815 clear_mouse_face (dpyinfo
);
22817 define_frame_cursor1 (f
, cursor
, pointer
);
22822 Take proper action when the mouse has moved to position X, Y on
22823 frame F as regards highlighting characters that have mouse-face
22824 properties. Also de-highlighting chars where the mouse was before.
22825 X and Y can be negative or out of range. */
22828 note_mouse_highlight (f
, x
, y
)
22832 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22833 enum window_part part
;
22834 Lisp_Object window
;
22836 Cursor cursor
= No_Cursor
;
22837 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
22840 /* When a menu is active, don't highlight because this looks odd. */
22841 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (MAC_OS)
22842 if (popup_activated ())
22846 if (NILP (Vmouse_highlight
)
22847 || !f
->glyphs_initialized_p
)
22850 dpyinfo
->mouse_face_mouse_x
= x
;
22851 dpyinfo
->mouse_face_mouse_y
= y
;
22852 dpyinfo
->mouse_face_mouse_frame
= f
;
22854 if (dpyinfo
->mouse_face_defer
)
22857 if (gc_in_progress
)
22859 dpyinfo
->mouse_face_deferred_gc
= 1;
22863 /* Which window is that in? */
22864 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
22866 /* If we were displaying active text in another window, clear that.
22867 Also clear if we move out of text area in same window. */
22868 if (! EQ (window
, dpyinfo
->mouse_face_window
)
22869 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
22870 && !NILP (dpyinfo
->mouse_face_window
)))
22871 clear_mouse_face (dpyinfo
);
22873 /* Not on a window -> return. */
22874 if (!WINDOWP (window
))
22877 /* Reset help_echo_string. It will get recomputed below. */
22878 help_echo_string
= Qnil
;
22880 /* Convert to window-relative pixel coordinates. */
22881 w
= XWINDOW (window
);
22882 frame_to_window_pixel_xy (w
, &x
, &y
);
22884 /* Handle tool-bar window differently since it doesn't display a
22886 if (EQ (window
, f
->tool_bar_window
))
22888 note_tool_bar_highlight (f
, x
, y
);
22892 /* Mouse is on the mode, header line or margin? */
22893 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
22894 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
22896 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
22900 if (part
== ON_VERTICAL_BORDER
)
22902 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22903 help_echo_string
= build_string ("drag-mouse-1: resize");
22905 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
22906 || part
== ON_SCROLL_BAR
)
22907 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22909 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22911 /* Are we in a window whose display is up to date?
22912 And verify the buffer's text has not changed. */
22913 b
= XBUFFER (w
->buffer
);
22914 if (part
== ON_TEXT
22915 && EQ (w
->window_end_valid
, w
->buffer
)
22916 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
22917 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
22919 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
22920 struct glyph
*glyph
;
22921 Lisp_Object object
;
22922 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
22923 Lisp_Object
*overlay_vec
= NULL
;
22925 struct buffer
*obuf
;
22926 int obegv
, ozv
, same_region
;
22928 /* Find the glyph under X/Y. */
22929 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
22931 /* Look for :pointer property on image. */
22932 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22934 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22935 if (img
!= NULL
&& IMAGEP (img
->spec
))
22937 Lisp_Object image_map
, hotspot
;
22938 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
22940 && (hotspot
= find_hot_spot (image_map
,
22941 glyph
->slice
.x
+ dx
,
22942 glyph
->slice
.y
+ dy
),
22944 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22946 Lisp_Object area_id
, plist
;
22948 area_id
= XCAR (hotspot
);
22949 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22950 If so, we could look for mouse-enter, mouse-leave
22951 properties in PLIST (and do something...). */
22952 hotspot
= XCDR (hotspot
);
22953 if (CONSP (hotspot
)
22954 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22956 pointer
= Fplist_get (plist
, Qpointer
);
22957 if (NILP (pointer
))
22959 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
22960 if (!NILP (help_echo_string
))
22962 help_echo_window
= window
;
22963 help_echo_object
= glyph
->object
;
22964 help_echo_pos
= glyph
->charpos
;
22968 if (NILP (pointer
))
22969 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
22973 /* Clear mouse face if X/Y not over text. */
22975 || area
!= TEXT_AREA
22976 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
22978 if (clear_mouse_face (dpyinfo
))
22979 cursor
= No_Cursor
;
22980 if (NILP (pointer
))
22982 if (area
!= TEXT_AREA
)
22983 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22985 pointer
= Vvoid_text_area_pointer
;
22990 pos
= glyph
->charpos
;
22991 object
= glyph
->object
;
22992 if (!STRINGP (object
) && !BUFFERP (object
))
22995 /* If we get an out-of-range value, return now; avoid an error. */
22996 if (BUFFERP (object
) && pos
> BUF_Z (b
))
22999 /* Make the window's buffer temporarily current for
23000 overlays_at and compute_char_face. */
23001 obuf
= current_buffer
;
23002 current_buffer
= b
;
23008 /* Is this char mouse-active or does it have help-echo? */
23009 position
= make_number (pos
);
23011 if (BUFFERP (object
))
23013 /* Put all the overlays we want in a vector in overlay_vec. */
23014 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
23015 /* Sort overlays into increasing priority order. */
23016 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
23021 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
23022 && vpos
>= dpyinfo
->mouse_face_beg_row
23023 && vpos
<= dpyinfo
->mouse_face_end_row
23024 && (vpos
> dpyinfo
->mouse_face_beg_row
23025 || hpos
>= dpyinfo
->mouse_face_beg_col
)
23026 && (vpos
< dpyinfo
->mouse_face_end_row
23027 || hpos
< dpyinfo
->mouse_face_end_col
23028 || dpyinfo
->mouse_face_past_end
));
23031 cursor
= No_Cursor
;
23033 /* Check mouse-face highlighting. */
23035 /* If there exists an overlay with mouse-face overlapping
23036 the one we are currently highlighting, we have to
23037 check if we enter the overlapping overlay, and then
23038 highlight only that. */
23039 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
23040 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
23042 /* Find the highest priority overlay that has a mouse-face
23045 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
23047 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
23048 if (!NILP (mouse_face
))
23049 overlay
= overlay_vec
[i
];
23052 /* If we're actually highlighting the same overlay as
23053 before, there's no need to do that again. */
23054 if (!NILP (overlay
)
23055 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
23056 goto check_help_echo
;
23058 dpyinfo
->mouse_face_overlay
= overlay
;
23060 /* Clear the display of the old active region, if any. */
23061 if (clear_mouse_face (dpyinfo
))
23062 cursor
= No_Cursor
;
23064 /* If no overlay applies, get a text property. */
23065 if (NILP (overlay
))
23066 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
23068 /* Handle the overlay case. */
23069 if (!NILP (overlay
))
23071 /* Find the range of text around this char that
23072 should be active. */
23073 Lisp_Object before
, after
;
23076 before
= Foverlay_start (overlay
);
23077 after
= Foverlay_end (overlay
);
23078 /* Record this as the current active region. */
23079 fast_find_position (w
, XFASTINT (before
),
23080 &dpyinfo
->mouse_face_beg_col
,
23081 &dpyinfo
->mouse_face_beg_row
,
23082 &dpyinfo
->mouse_face_beg_x
,
23083 &dpyinfo
->mouse_face_beg_y
, Qnil
);
23085 dpyinfo
->mouse_face_past_end
23086 = !fast_find_position (w
, XFASTINT (after
),
23087 &dpyinfo
->mouse_face_end_col
,
23088 &dpyinfo
->mouse_face_end_row
,
23089 &dpyinfo
->mouse_face_end_x
,
23090 &dpyinfo
->mouse_face_end_y
, Qnil
);
23091 dpyinfo
->mouse_face_window
= window
;
23093 dpyinfo
->mouse_face_face_id
23094 = face_at_buffer_position (w
, pos
, 0, 0,
23096 !dpyinfo
->mouse_face_hidden
);
23098 /* Display it as active. */
23099 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23100 cursor
= No_Cursor
;
23102 /* Handle the text property case. */
23103 else if (!NILP (mouse_face
) && BUFFERP (object
))
23105 /* Find the range of text around this char that
23106 should be active. */
23107 Lisp_Object before
, after
, beginning
, end
;
23110 beginning
= Fmarker_position (w
->start
);
23111 end
= make_number (BUF_Z (XBUFFER (object
))
23112 - XFASTINT (w
->window_end_pos
));
23114 = Fprevious_single_property_change (make_number (pos
+ 1),
23116 object
, beginning
);
23118 = Fnext_single_property_change (position
, Qmouse_face
,
23121 /* Record this as the current active region. */
23122 fast_find_position (w
, XFASTINT (before
),
23123 &dpyinfo
->mouse_face_beg_col
,
23124 &dpyinfo
->mouse_face_beg_row
,
23125 &dpyinfo
->mouse_face_beg_x
,
23126 &dpyinfo
->mouse_face_beg_y
, Qnil
);
23127 dpyinfo
->mouse_face_past_end
23128 = !fast_find_position (w
, XFASTINT (after
),
23129 &dpyinfo
->mouse_face_end_col
,
23130 &dpyinfo
->mouse_face_end_row
,
23131 &dpyinfo
->mouse_face_end_x
,
23132 &dpyinfo
->mouse_face_end_y
, Qnil
);
23133 dpyinfo
->mouse_face_window
= window
;
23135 if (BUFFERP (object
))
23136 dpyinfo
->mouse_face_face_id
23137 = face_at_buffer_position (w
, pos
, 0, 0,
23139 !dpyinfo
->mouse_face_hidden
);
23141 /* Display it as active. */
23142 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23143 cursor
= No_Cursor
;
23145 else if (!NILP (mouse_face
) && STRINGP (object
))
23150 b
= Fprevious_single_property_change (make_number (pos
+ 1),
23153 e
= Fnext_single_property_change (position
, Qmouse_face
,
23156 b
= make_number (0);
23158 e
= make_number (SCHARS (object
) - 1);
23160 fast_find_string_pos (w
, XINT (b
), object
,
23161 &dpyinfo
->mouse_face_beg_col
,
23162 &dpyinfo
->mouse_face_beg_row
,
23163 &dpyinfo
->mouse_face_beg_x
,
23164 &dpyinfo
->mouse_face_beg_y
, 0);
23165 fast_find_string_pos (w
, XINT (e
), object
,
23166 &dpyinfo
->mouse_face_end_col
,
23167 &dpyinfo
->mouse_face_end_row
,
23168 &dpyinfo
->mouse_face_end_x
,
23169 &dpyinfo
->mouse_face_end_y
, 1);
23170 dpyinfo
->mouse_face_past_end
= 0;
23171 dpyinfo
->mouse_face_window
= window
;
23172 dpyinfo
->mouse_face_face_id
23173 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
23174 glyph
->face_id
, 1);
23175 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23176 cursor
= No_Cursor
;
23178 else if (STRINGP (object
) && NILP (mouse_face
))
23180 /* A string which doesn't have mouse-face, but
23181 the text ``under'' it might have. */
23182 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
23183 int start
= MATRIX_ROW_START_CHARPOS (r
);
23185 pos
= string_buffer_position (w
, object
, start
);
23187 mouse_face
= get_char_property_and_overlay (make_number (pos
),
23191 if (!NILP (mouse_face
) && !NILP (overlay
))
23193 Lisp_Object before
= Foverlay_start (overlay
);
23194 Lisp_Object after
= Foverlay_end (overlay
);
23197 /* Note that we might not be able to find position
23198 BEFORE in the glyph matrix if the overlay is
23199 entirely covered by a `display' property. In
23200 this case, we overshoot. So let's stop in
23201 the glyph matrix before glyphs for OBJECT. */
23202 fast_find_position (w
, XFASTINT (before
),
23203 &dpyinfo
->mouse_face_beg_col
,
23204 &dpyinfo
->mouse_face_beg_row
,
23205 &dpyinfo
->mouse_face_beg_x
,
23206 &dpyinfo
->mouse_face_beg_y
,
23209 dpyinfo
->mouse_face_past_end
23210 = !fast_find_position (w
, XFASTINT (after
),
23211 &dpyinfo
->mouse_face_end_col
,
23212 &dpyinfo
->mouse_face_end_row
,
23213 &dpyinfo
->mouse_face_end_x
,
23214 &dpyinfo
->mouse_face_end_y
,
23216 dpyinfo
->mouse_face_window
= window
;
23217 dpyinfo
->mouse_face_face_id
23218 = face_at_buffer_position (w
, pos
, 0, 0,
23220 !dpyinfo
->mouse_face_hidden
);
23222 /* Display it as active. */
23223 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23224 cursor
= No_Cursor
;
23231 /* Look for a `help-echo' property. */
23232 if (NILP (help_echo_string
)) {
23233 Lisp_Object help
, overlay
;
23235 /* Check overlays first. */
23236 help
= overlay
= Qnil
;
23237 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
23239 overlay
= overlay_vec
[i
];
23240 help
= Foverlay_get (overlay
, Qhelp_echo
);
23245 help_echo_string
= help
;
23246 help_echo_window
= window
;
23247 help_echo_object
= overlay
;
23248 help_echo_pos
= pos
;
23252 Lisp_Object object
= glyph
->object
;
23253 int charpos
= glyph
->charpos
;
23255 /* Try text properties. */
23256 if (STRINGP (object
)
23258 && charpos
< SCHARS (object
))
23260 help
= Fget_text_property (make_number (charpos
),
23261 Qhelp_echo
, object
);
23264 /* If the string itself doesn't specify a help-echo,
23265 see if the buffer text ``under'' it does. */
23266 struct glyph_row
*r
23267 = MATRIX_ROW (w
->current_matrix
, vpos
);
23268 int start
= MATRIX_ROW_START_CHARPOS (r
);
23269 int pos
= string_buffer_position (w
, object
, start
);
23272 help
= Fget_char_property (make_number (pos
),
23273 Qhelp_echo
, w
->buffer
);
23277 object
= w
->buffer
;
23282 else if (BUFFERP (object
)
23285 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
23290 help_echo_string
= help
;
23291 help_echo_window
= window
;
23292 help_echo_object
= object
;
23293 help_echo_pos
= charpos
;
23298 /* Look for a `pointer' property. */
23299 if (NILP (pointer
))
23301 /* Check overlays first. */
23302 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
23303 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
23305 if (NILP (pointer
))
23307 Lisp_Object object
= glyph
->object
;
23308 int charpos
= glyph
->charpos
;
23310 /* Try text properties. */
23311 if (STRINGP (object
)
23313 && charpos
< SCHARS (object
))
23315 pointer
= Fget_text_property (make_number (charpos
),
23317 if (NILP (pointer
))
23319 /* If the string itself doesn't specify a pointer,
23320 see if the buffer text ``under'' it does. */
23321 struct glyph_row
*r
23322 = MATRIX_ROW (w
->current_matrix
, vpos
);
23323 int start
= MATRIX_ROW_START_CHARPOS (r
);
23324 int pos
= string_buffer_position (w
, object
, start
);
23326 pointer
= Fget_char_property (make_number (pos
),
23327 Qpointer
, w
->buffer
);
23330 else if (BUFFERP (object
)
23333 pointer
= Fget_text_property (make_number (charpos
),
23340 current_buffer
= obuf
;
23345 define_frame_cursor1 (f
, cursor
, pointer
);
23350 Clear any mouse-face on window W. This function is part of the
23351 redisplay interface, and is called from try_window_id and similar
23352 functions to ensure the mouse-highlight is off. */
23355 x_clear_window_mouse_face (w
)
23358 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23359 Lisp_Object window
;
23362 XSETWINDOW (window
, w
);
23363 if (EQ (window
, dpyinfo
->mouse_face_window
))
23364 clear_mouse_face (dpyinfo
);
23370 Just discard the mouse face information for frame F, if any.
23371 This is used when the size of F is changed. */
23374 cancel_mouse_face (f
)
23377 Lisp_Object window
;
23378 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23380 window
= dpyinfo
->mouse_face_window
;
23381 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
23383 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
23384 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
23385 dpyinfo
->mouse_face_window
= Qnil
;
23390 #endif /* HAVE_WINDOW_SYSTEM */
23393 /***********************************************************************
23395 ***********************************************************************/
23397 #ifdef HAVE_WINDOW_SYSTEM
23399 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
23400 which intersects rectangle R. R is in window-relative coordinates. */
23403 expose_area (w
, row
, r
, area
)
23405 struct glyph_row
*row
;
23407 enum glyph_row_area area
;
23409 struct glyph
*first
= row
->glyphs
[area
];
23410 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
23411 struct glyph
*last
;
23412 int first_x
, start_x
, x
;
23414 if (area
== TEXT_AREA
&& row
->fill_line_p
)
23415 /* If row extends face to end of line write the whole line. */
23416 draw_glyphs (w
, 0, row
, area
,
23417 0, row
->used
[area
],
23418 DRAW_NORMAL_TEXT
, 0);
23421 /* Set START_X to the window-relative start position for drawing glyphs of
23422 AREA. The first glyph of the text area can be partially visible.
23423 The first glyphs of other areas cannot. */
23424 start_x
= window_box_left_offset (w
, area
);
23426 if (area
== TEXT_AREA
)
23429 /* Find the first glyph that must be redrawn. */
23431 && x
+ first
->pixel_width
< r
->x
)
23433 x
+= first
->pixel_width
;
23437 /* Find the last one. */
23441 && x
< r
->x
+ r
->width
)
23443 x
+= last
->pixel_width
;
23449 draw_glyphs (w
, first_x
- start_x
, row
, area
,
23450 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
23451 DRAW_NORMAL_TEXT
, 0);
23456 /* Redraw the parts of the glyph row ROW on window W intersecting
23457 rectangle R. R is in window-relative coordinates. Value is
23458 non-zero if mouse-face was overwritten. */
23461 expose_line (w
, row
, r
)
23463 struct glyph_row
*row
;
23466 xassert (row
->enabled_p
);
23468 if (row
->mode_line_p
|| w
->pseudo_window_p
)
23469 draw_glyphs (w
, 0, row
, TEXT_AREA
,
23470 0, row
->used
[TEXT_AREA
],
23471 DRAW_NORMAL_TEXT
, 0);
23474 if (row
->used
[LEFT_MARGIN_AREA
])
23475 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
23476 if (row
->used
[TEXT_AREA
])
23477 expose_area (w
, row
, r
, TEXT_AREA
);
23478 if (row
->used
[RIGHT_MARGIN_AREA
])
23479 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
23480 draw_row_fringe_bitmaps (w
, row
);
23483 return row
->mouse_face_p
;
23487 /* Redraw those parts of glyphs rows during expose event handling that
23488 overlap other rows. Redrawing of an exposed line writes over parts
23489 of lines overlapping that exposed line; this function fixes that.
23491 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
23492 row in W's current matrix that is exposed and overlaps other rows.
23493 LAST_OVERLAPPING_ROW is the last such row. */
23496 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
23498 struct glyph_row
*first_overlapping_row
;
23499 struct glyph_row
*last_overlapping_row
;
23501 struct glyph_row
*row
;
23503 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
23504 if (row
->overlapping_p
)
23506 xassert (row
->enabled_p
&& !row
->mode_line_p
);
23508 if (row
->used
[LEFT_MARGIN_AREA
])
23509 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
23511 if (row
->used
[TEXT_AREA
])
23512 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
23514 if (row
->used
[RIGHT_MARGIN_AREA
])
23515 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
23520 /* Return non-zero if W's cursor intersects rectangle R. */
23523 phys_cursor_in_rect_p (w
, r
)
23527 XRectangle cr
, result
;
23528 struct glyph
*cursor_glyph
;
23529 struct glyph_row
*row
;
23531 if (w
->phys_cursor
.vpos
>= 0
23532 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
23533 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
23535 && row
->cursor_in_fringe_p
)
23537 /* Cursor is in the fringe. */
23538 cr
.x
= window_box_right_offset (w
,
23539 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
23540 ? RIGHT_MARGIN_AREA
23543 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
23544 cr
.height
= row
->height
;
23545 return x_intersect_rectangles (&cr
, r
, &result
);
23548 cursor_glyph
= get_phys_cursor_glyph (w
);
23551 /* r is relative to W's box, but w->phys_cursor.x is relative
23552 to left edge of W's TEXT area. Adjust it. */
23553 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
23554 cr
.y
= w
->phys_cursor
.y
;
23555 cr
.width
= cursor_glyph
->pixel_width
;
23556 cr
.height
= w
->phys_cursor_height
;
23557 /* ++KFS: W32 version used W32-specific IntersectRect here, but
23558 I assume the effect is the same -- and this is portable. */
23559 return x_intersect_rectangles (&cr
, r
, &result
);
23561 /* If we don't understand the format, pretend we're not in the hot-spot. */
23567 Draw a vertical window border to the right of window W if W doesn't
23568 have vertical scroll bars. */
23571 x_draw_vertical_border (w
)
23574 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23576 /* We could do better, if we knew what type of scroll-bar the adjacent
23577 windows (on either side) have... But we don't :-(
23578 However, I think this works ok. ++KFS 2003-04-25 */
23580 /* Redraw borders between horizontally adjacent windows. Don't
23581 do it for frames with vertical scroll bars because either the
23582 right scroll bar of a window, or the left scroll bar of its
23583 neighbor will suffice as a border. */
23584 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
23587 if (!WINDOW_RIGHTMOST_P (w
)
23588 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
23590 int x0
, x1
, y0
, y1
;
23592 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23595 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23598 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
23600 else if (!WINDOW_LEFTMOST_P (w
)
23601 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
23603 int x0
, x1
, y0
, y1
;
23605 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23608 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23611 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
23616 /* Redraw the part of window W intersection rectangle FR. Pixel
23617 coordinates in FR are frame-relative. Call this function with
23618 input blocked. Value is non-zero if the exposure overwrites
23622 expose_window (w
, fr
)
23626 struct frame
*f
= XFRAME (w
->frame
);
23628 int mouse_face_overwritten_p
= 0;
23630 /* If window is not yet fully initialized, do nothing. This can
23631 happen when toolkit scroll bars are used and a window is split.
23632 Reconfiguring the scroll bar will generate an expose for a newly
23634 if (w
->current_matrix
== NULL
)
23637 /* When we're currently updating the window, display and current
23638 matrix usually don't agree. Arrange for a thorough display
23640 if (w
== updated_window
)
23642 SET_FRAME_GARBAGED (f
);
23646 /* Frame-relative pixel rectangle of W. */
23647 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
23648 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
23649 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
23650 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
23652 if (x_intersect_rectangles (fr
, &wr
, &r
))
23654 int yb
= window_text_bottom_y (w
);
23655 struct glyph_row
*row
;
23656 int cursor_cleared_p
;
23657 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
23659 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
23660 r
.x
, r
.y
, r
.width
, r
.height
));
23662 /* Convert to window coordinates. */
23663 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
23664 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
23666 /* Turn off the cursor. */
23667 if (!w
->pseudo_window_p
23668 && phys_cursor_in_rect_p (w
, &r
))
23670 x_clear_cursor (w
);
23671 cursor_cleared_p
= 1;
23674 cursor_cleared_p
= 0;
23676 /* Update lines intersecting rectangle R. */
23677 first_overlapping_row
= last_overlapping_row
= NULL
;
23678 for (row
= w
->current_matrix
->rows
;
23683 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
23685 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
23686 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
23687 || (r
.y
>= y0
&& r
.y
< y1
)
23688 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
23690 /* A header line may be overlapping, but there is no need
23691 to fix overlapping areas for them. KFS 2005-02-12 */
23692 if (row
->overlapping_p
&& !row
->mode_line_p
)
23694 if (first_overlapping_row
== NULL
)
23695 first_overlapping_row
= row
;
23696 last_overlapping_row
= row
;
23699 if (expose_line (w
, row
, &r
))
23700 mouse_face_overwritten_p
= 1;
23707 /* Display the mode line if there is one. */
23708 if (WINDOW_WANTS_MODELINE_P (w
)
23709 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
23711 && row
->y
< r
.y
+ r
.height
)
23713 if (expose_line (w
, row
, &r
))
23714 mouse_face_overwritten_p
= 1;
23717 if (!w
->pseudo_window_p
)
23719 /* Fix the display of overlapping rows. */
23720 if (first_overlapping_row
)
23721 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
23723 /* Draw border between windows. */
23724 x_draw_vertical_border (w
);
23726 /* Turn the cursor on again. */
23727 if (cursor_cleared_p
)
23728 update_window_cursor (w
, 1);
23732 return mouse_face_overwritten_p
;
23737 /* Redraw (parts) of all windows in the window tree rooted at W that
23738 intersect R. R contains frame pixel coordinates. Value is
23739 non-zero if the exposure overwrites mouse-face. */
23742 expose_window_tree (w
, r
)
23746 struct frame
*f
= XFRAME (w
->frame
);
23747 int mouse_face_overwritten_p
= 0;
23749 while (w
&& !FRAME_GARBAGED_P (f
))
23751 if (!NILP (w
->hchild
))
23752 mouse_face_overwritten_p
23753 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
23754 else if (!NILP (w
->vchild
))
23755 mouse_face_overwritten_p
23756 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
23758 mouse_face_overwritten_p
|= expose_window (w
, r
);
23760 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
23763 return mouse_face_overwritten_p
;
23768 Redisplay an exposed area of frame F. X and Y are the upper-left
23769 corner of the exposed rectangle. W and H are width and height of
23770 the exposed area. All are pixel values. W or H zero means redraw
23771 the entire frame. */
23774 expose_frame (f
, x
, y
, w
, h
)
23779 int mouse_face_overwritten_p
= 0;
23781 TRACE ((stderr
, "expose_frame "));
23783 /* No need to redraw if frame will be redrawn soon. */
23784 if (FRAME_GARBAGED_P (f
))
23786 TRACE ((stderr
, " garbaged\n"));
23790 /* If basic faces haven't been realized yet, there is no point in
23791 trying to redraw anything. This can happen when we get an expose
23792 event while Emacs is starting, e.g. by moving another window. */
23793 if (FRAME_FACE_CACHE (f
) == NULL
23794 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
23796 TRACE ((stderr
, " no faces\n"));
23800 if (w
== 0 || h
== 0)
23803 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
23804 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
23814 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
23815 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
23817 if (WINDOWP (f
->tool_bar_window
))
23818 mouse_face_overwritten_p
23819 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
23821 #ifdef HAVE_X_WINDOWS
23823 #ifndef USE_X_TOOLKIT
23824 if (WINDOWP (f
->menu_bar_window
))
23825 mouse_face_overwritten_p
23826 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
23827 #endif /* not USE_X_TOOLKIT */
23831 /* Some window managers support a focus-follows-mouse style with
23832 delayed raising of frames. Imagine a partially obscured frame,
23833 and moving the mouse into partially obscured mouse-face on that
23834 frame. The visible part of the mouse-face will be highlighted,
23835 then the WM raises the obscured frame. With at least one WM, KDE
23836 2.1, Emacs is not getting any event for the raising of the frame
23837 (even tried with SubstructureRedirectMask), only Expose events.
23838 These expose events will draw text normally, i.e. not
23839 highlighted. Which means we must redo the highlight here.
23840 Subsume it under ``we love X''. --gerd 2001-08-15 */
23841 /* Included in Windows version because Windows most likely does not
23842 do the right thing if any third party tool offers
23843 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
23844 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
23846 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23847 if (f
== dpyinfo
->mouse_face_mouse_frame
)
23849 int x
= dpyinfo
->mouse_face_mouse_x
;
23850 int y
= dpyinfo
->mouse_face_mouse_y
;
23851 clear_mouse_face (dpyinfo
);
23852 note_mouse_highlight (f
, x
, y
);
23859 Determine the intersection of two rectangles R1 and R2. Return
23860 the intersection in *RESULT. Value is non-zero if RESULT is not
23864 x_intersect_rectangles (r1
, r2
, result
)
23865 XRectangle
*r1
, *r2
, *result
;
23867 XRectangle
*left
, *right
;
23868 XRectangle
*upper
, *lower
;
23869 int intersection_p
= 0;
23871 /* Rearrange so that R1 is the left-most rectangle. */
23873 left
= r1
, right
= r2
;
23875 left
= r2
, right
= r1
;
23877 /* X0 of the intersection is right.x0, if this is inside R1,
23878 otherwise there is no intersection. */
23879 if (right
->x
<= left
->x
+ left
->width
)
23881 result
->x
= right
->x
;
23883 /* The right end of the intersection is the minimum of the
23884 the right ends of left and right. */
23885 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
23888 /* Same game for Y. */
23890 upper
= r1
, lower
= r2
;
23892 upper
= r2
, lower
= r1
;
23894 /* The upper end of the intersection is lower.y0, if this is inside
23895 of upper. Otherwise, there is no intersection. */
23896 if (lower
->y
<= upper
->y
+ upper
->height
)
23898 result
->y
= lower
->y
;
23900 /* The lower end of the intersection is the minimum of the lower
23901 ends of upper and lower. */
23902 result
->height
= (min (lower
->y
+ lower
->height
,
23903 upper
->y
+ upper
->height
)
23905 intersection_p
= 1;
23909 return intersection_p
;
23912 #endif /* HAVE_WINDOW_SYSTEM */
23915 /***********************************************************************
23917 ***********************************************************************/
23922 Vwith_echo_area_save_vector
= Qnil
;
23923 staticpro (&Vwith_echo_area_save_vector
);
23925 Vmessage_stack
= Qnil
;
23926 staticpro (&Vmessage_stack
);
23928 Qinhibit_redisplay
= intern ("inhibit-redisplay");
23929 staticpro (&Qinhibit_redisplay
);
23931 message_dolog_marker1
= Fmake_marker ();
23932 staticpro (&message_dolog_marker1
);
23933 message_dolog_marker2
= Fmake_marker ();
23934 staticpro (&message_dolog_marker2
);
23935 message_dolog_marker3
= Fmake_marker ();
23936 staticpro (&message_dolog_marker3
);
23939 defsubr (&Sdump_frame_glyph_matrix
);
23940 defsubr (&Sdump_glyph_matrix
);
23941 defsubr (&Sdump_glyph_row
);
23942 defsubr (&Sdump_tool_bar_row
);
23943 defsubr (&Strace_redisplay
);
23944 defsubr (&Strace_to_stderr
);
23946 #ifdef HAVE_WINDOW_SYSTEM
23947 defsubr (&Stool_bar_lines_needed
);
23948 defsubr (&Slookup_image_map
);
23950 defsubr (&Sformat_mode_line
);
23951 defsubr (&Sinvisible_p
);
23953 staticpro (&Qmenu_bar_update_hook
);
23954 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
23956 staticpro (&Qoverriding_terminal_local_map
);
23957 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
23959 staticpro (&Qoverriding_local_map
);
23960 Qoverriding_local_map
= intern ("overriding-local-map");
23962 staticpro (&Qwindow_scroll_functions
);
23963 Qwindow_scroll_functions
= intern ("window-scroll-functions");
23965 staticpro (&Qredisplay_end_trigger_functions
);
23966 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
23968 staticpro (&Qinhibit_point_motion_hooks
);
23969 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
23971 QCdata
= intern (":data");
23972 staticpro (&QCdata
);
23973 Qdisplay
= intern ("display");
23974 staticpro (&Qdisplay
);
23975 Qspace_width
= intern ("space-width");
23976 staticpro (&Qspace_width
);
23977 Qraise
= intern ("raise");
23978 staticpro (&Qraise
);
23979 Qslice
= intern ("slice");
23980 staticpro (&Qslice
);
23981 Qspace
= intern ("space");
23982 staticpro (&Qspace
);
23983 Qmargin
= intern ("margin");
23984 staticpro (&Qmargin
);
23985 Qpointer
= intern ("pointer");
23986 staticpro (&Qpointer
);
23987 Qleft_margin
= intern ("left-margin");
23988 staticpro (&Qleft_margin
);
23989 Qright_margin
= intern ("right-margin");
23990 staticpro (&Qright_margin
);
23991 Qcenter
= intern ("center");
23992 staticpro (&Qcenter
);
23993 Qline_height
= intern ("line-height");
23994 staticpro (&Qline_height
);
23995 QCalign_to
= intern (":align-to");
23996 staticpro (&QCalign_to
);
23997 QCrelative_width
= intern (":relative-width");
23998 staticpro (&QCrelative_width
);
23999 QCrelative_height
= intern (":relative-height");
24000 staticpro (&QCrelative_height
);
24001 QCeval
= intern (":eval");
24002 staticpro (&QCeval
);
24003 QCpropertize
= intern (":propertize");
24004 staticpro (&QCpropertize
);
24005 QCfile
= intern (":file");
24006 staticpro (&QCfile
);
24007 Qfontified
= intern ("fontified");
24008 staticpro (&Qfontified
);
24009 Qfontification_functions
= intern ("fontification-functions");
24010 staticpro (&Qfontification_functions
);
24011 Qtrailing_whitespace
= intern ("trailing-whitespace");
24012 staticpro (&Qtrailing_whitespace
);
24013 Qescape_glyph
= intern ("escape-glyph");
24014 staticpro (&Qescape_glyph
);
24015 Qnobreak_space
= intern ("nobreak-space");
24016 staticpro (&Qnobreak_space
);
24017 Qimage
= intern ("image");
24018 staticpro (&Qimage
);
24019 QCmap
= intern (":map");
24020 staticpro (&QCmap
);
24021 QCpointer
= intern (":pointer");
24022 staticpro (&QCpointer
);
24023 Qrect
= intern ("rect");
24024 staticpro (&Qrect
);
24025 Qcircle
= intern ("circle");
24026 staticpro (&Qcircle
);
24027 Qpoly
= intern ("poly");
24028 staticpro (&Qpoly
);
24029 Qmessage_truncate_lines
= intern ("message-truncate-lines");
24030 staticpro (&Qmessage_truncate_lines
);
24031 Qgrow_only
= intern ("grow-only");
24032 staticpro (&Qgrow_only
);
24033 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
24034 staticpro (&Qinhibit_menubar_update
);
24035 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
24036 staticpro (&Qinhibit_eval_during_redisplay
);
24037 Qposition
= intern ("position");
24038 staticpro (&Qposition
);
24039 Qbuffer_position
= intern ("buffer-position");
24040 staticpro (&Qbuffer_position
);
24041 Qobject
= intern ("object");
24042 staticpro (&Qobject
);
24043 Qbar
= intern ("bar");
24045 Qhbar
= intern ("hbar");
24046 staticpro (&Qhbar
);
24047 Qbox
= intern ("box");
24049 Qhollow
= intern ("hollow");
24050 staticpro (&Qhollow
);
24051 Qhand
= intern ("hand");
24052 staticpro (&Qhand
);
24053 Qarrow
= intern ("arrow");
24054 staticpro (&Qarrow
);
24055 Qtext
= intern ("text");
24056 staticpro (&Qtext
);
24057 Qrisky_local_variable
= intern ("risky-local-variable");
24058 staticpro (&Qrisky_local_variable
);
24059 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
24060 staticpro (&Qinhibit_free_realized_faces
);
24062 list_of_error
= Fcons (Fcons (intern ("error"),
24063 Fcons (intern ("void-variable"), Qnil
)),
24065 staticpro (&list_of_error
);
24067 Qlast_arrow_position
= intern ("last-arrow-position");
24068 staticpro (&Qlast_arrow_position
);
24069 Qlast_arrow_string
= intern ("last-arrow-string");
24070 staticpro (&Qlast_arrow_string
);
24072 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
24073 staticpro (&Qoverlay_arrow_string
);
24074 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
24075 staticpro (&Qoverlay_arrow_bitmap
);
24077 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
24078 staticpro (&echo_buffer
[0]);
24079 staticpro (&echo_buffer
[1]);
24081 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
24082 staticpro (&echo_area_buffer
[0]);
24083 staticpro (&echo_area_buffer
[1]);
24085 Vmessages_buffer_name
= build_string ("*Messages*");
24086 staticpro (&Vmessages_buffer_name
);
24088 mode_line_proptrans_alist
= Qnil
;
24089 staticpro (&mode_line_proptrans_alist
);
24090 mode_line_string_list
= Qnil
;
24091 staticpro (&mode_line_string_list
);
24092 mode_line_string_face
= Qnil
;
24093 staticpro (&mode_line_string_face
);
24094 mode_line_string_face_prop
= Qnil
;
24095 staticpro (&mode_line_string_face_prop
);
24096 Vmode_line_unwind_vector
= Qnil
;
24097 staticpro (&Vmode_line_unwind_vector
);
24099 help_echo_string
= Qnil
;
24100 staticpro (&help_echo_string
);
24101 help_echo_object
= Qnil
;
24102 staticpro (&help_echo_object
);
24103 help_echo_window
= Qnil
;
24104 staticpro (&help_echo_window
);
24105 previous_help_echo_string
= Qnil
;
24106 staticpro (&previous_help_echo_string
);
24107 help_echo_pos
= -1;
24109 #ifdef HAVE_WINDOW_SYSTEM
24110 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
24111 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
24112 For example, if a block cursor is over a tab, it will be drawn as
24113 wide as that tab on the display. */);
24114 x_stretch_cursor_p
= 0;
24117 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
24118 doc
: /* *Non-nil means highlight trailing whitespace.
24119 The face used for trailing whitespace is `trailing-whitespace'. */);
24120 Vshow_trailing_whitespace
= Qnil
;
24122 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
24123 doc
: /* *Control highlighting of nobreak space and soft hyphen.
24124 A value of t means highlight the character itself (for nobreak space,
24125 use face `nobreak-space').
24126 A value of nil means no highlighting.
24127 Other values mean display the escape glyph followed by an ordinary
24128 space or ordinary hyphen. */);
24129 Vnobreak_char_display
= Qt
;
24131 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
24132 doc
: /* *The pointer shape to show in void text areas.
24133 A value of nil means to show the text pointer. Other options are `arrow',
24134 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
24135 Vvoid_text_area_pointer
= Qarrow
;
24137 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
24138 doc
: /* Non-nil means don't actually do any redisplay.
24139 This is used for internal purposes. */);
24140 Vinhibit_redisplay
= Qnil
;
24142 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
24143 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
24144 Vglobal_mode_string
= Qnil
;
24146 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
24147 doc
: /* Marker for where to display an arrow on top of the buffer text.
24148 This must be the beginning of a line in order to work.
24149 See also `overlay-arrow-string'. */);
24150 Voverlay_arrow_position
= Qnil
;
24152 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
24153 doc
: /* String to display as an arrow in non-window frames.
24154 See also `overlay-arrow-position'. */);
24155 Voverlay_arrow_string
= build_string ("=>");
24157 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
24158 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
24159 The symbols on this list are examined during redisplay to determine
24160 where to display overlay arrows. */);
24161 Voverlay_arrow_variable_list
24162 = Fcons (intern ("overlay-arrow-position"), Qnil
);
24164 DEFVAR_INT ("scroll-step", &scroll_step
,
24165 doc
: /* *The number of lines to try scrolling a window by when point moves out.
24166 If that fails to bring point back on frame, point is centered instead.
24167 If this is zero, point is always centered after it moves off frame.
24168 If you want scrolling to always be a line at a time, you should set
24169 `scroll-conservatively' to a large value rather than set this to 1. */);
24171 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
24172 doc
: /* *Scroll up to this many lines, to bring point back on screen.
24173 If point moves off-screen, redisplay will scroll by up to
24174 `scroll-conservatively' lines in order to bring point just barely
24175 onto the screen again. If that cannot be done, then redisplay
24176 recenters point as usual.
24178 A value of zero means always recenter point if it moves off screen. */);
24179 scroll_conservatively
= 0;
24181 DEFVAR_INT ("scroll-margin", &scroll_margin
,
24182 doc
: /* *Number of lines of margin at the top and bottom of a window.
24183 Recenter the window whenever point gets within this many lines
24184 of the top or bottom of the window. */);
24187 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
24188 doc
: /* Pixels per inch value for non-window system displays.
24189 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
24190 Vdisplay_pixels_per_inch
= make_float (72.0);
24193 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
24196 DEFVAR_BOOL ("truncate-partial-width-windows",
24197 &truncate_partial_width_windows
,
24198 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
24199 truncate_partial_width_windows
= 1;
24201 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
24202 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
24203 Any other value means to use the appropriate face, `mode-line',
24204 `header-line', or `menu' respectively. */);
24205 mode_line_inverse_video
= 1;
24207 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
24208 doc
: /* *Maximum buffer size for which line number should be displayed.
24209 If the buffer is bigger than this, the line number does not appear
24210 in the mode line. A value of nil means no limit. */);
24211 Vline_number_display_limit
= Qnil
;
24213 DEFVAR_INT ("line-number-display-limit-width",
24214 &line_number_display_limit_width
,
24215 doc
: /* *Maximum line width (in characters) for line number display.
24216 If the average length of the lines near point is bigger than this, then the
24217 line number may be omitted from the mode line. */);
24218 line_number_display_limit_width
= 200;
24220 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
24221 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
24222 highlight_nonselected_windows
= 0;
24224 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
24225 doc
: /* Non-nil if more than one frame is visible on this display.
24226 Minibuffer-only frames don't count, but iconified frames do.
24227 This variable is not guaranteed to be accurate except while processing
24228 `frame-title-format' and `icon-title-format'. */);
24230 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
24231 doc
: /* Template for displaying the title bar of visible frames.
24232 \(Assuming the window manager supports this feature.)
24234 This variable has the same structure as `mode-line-format', except that
24235 the %c and %l constructs are ignored. It is used only on frames for
24236 which no explicit name has been set \(see `modify-frame-parameters'). */);
24238 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
24239 doc
: /* Template for displaying the title bar of an iconified frame.
24240 \(Assuming the window manager supports this feature.)
24241 This variable has the same structure as `mode-line-format' (which see),
24242 and is used only on frames for which no explicit name has been set
24243 \(see `modify-frame-parameters'). */);
24245 = Vframe_title_format
24246 = Fcons (intern ("multiple-frames"),
24247 Fcons (build_string ("%b"),
24248 Fcons (Fcons (empty_unibyte_string
,
24249 Fcons (intern ("invocation-name"),
24250 Fcons (build_string ("@"),
24251 Fcons (intern ("system-name"),
24255 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
24256 doc
: /* Maximum number of lines to keep in the message log buffer.
24257 If nil, disable message logging. If t, log messages but don't truncate
24258 the buffer when it becomes large. */);
24259 Vmessage_log_max
= make_number (100);
24261 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
24262 doc
: /* Functions called before redisplay, if window sizes have changed.
24263 The value should be a list of functions that take one argument.
24264 Just before redisplay, for each frame, if any of its windows have changed
24265 size since the last redisplay, or have been split or deleted,
24266 all the functions in the list are called, with the frame as argument. */);
24267 Vwindow_size_change_functions
= Qnil
;
24269 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
24270 doc
: /* List of functions to call before redisplaying a window with scrolling.
24271 Each function is called with two arguments, the window
24272 and its new display-start position. Note that the value of `window-end'
24273 is not valid when these functions are called. */);
24274 Vwindow_scroll_functions
= Qnil
;
24276 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
24277 doc
: /* Functions called when redisplay of a window reaches the end trigger.
24278 Each function is called with two arguments, the window and the end trigger value.
24279 See `set-window-redisplay-end-trigger'. */);
24280 Vredisplay_end_trigger_functions
= Qnil
;
24282 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
24283 doc
: /* *Non-nil means autoselect window with mouse pointer.
24284 If nil, do not autoselect windows.
24285 A positive number means delay autoselection by that many seconds: a
24286 window is autoselected only after the mouse has remained in that
24287 window for the duration of the delay.
24288 A negative number has a similar effect, but causes windows to be
24289 autoselected only after the mouse has stopped moving. \(Because of
24290 the way Emacs compares mouse events, you will occasionally wait twice
24291 that time before the window gets selected.\)
24292 Any other value means to autoselect window instantaneously when the
24293 mouse pointer enters it.
24295 Autoselection selects the minibuffer only if it is active, and never
24296 unselects the minibuffer if it is active.
24298 When customizing this variable make sure that the actual value of
24299 `focus-follows-mouse' matches the behavior of your window manager. */);
24300 Vmouse_autoselect_window
= Qnil
;
24302 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
24303 doc
: /* *Non-nil means automatically resize tool-bars.
24304 This dynamically changes the tool-bar's height to the minimum height
24305 that is needed to make all tool-bar items visible.
24306 If value is `grow-only', the tool-bar's height is only increased
24307 automatically; to decrease the tool-bar height, use \\[recenter]. */);
24308 Vauto_resize_tool_bars
= Qt
;
24310 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
24311 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
24312 auto_raise_tool_bar_buttons_p
= 1;
24314 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
24315 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
24316 make_cursor_line_fully_visible_p
= 1;
24318 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
24319 doc
: /* *Border below tool-bar in pixels.
24320 If an integer, use it as the height of the border.
24321 If it is one of `internal-border-width' or `border-width', use the
24322 value of the corresponding frame parameter.
24323 Otherwise, no border is added below the tool-bar. */);
24324 Vtool_bar_border
= Qinternal_border_width
;
24326 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
24327 doc
: /* *Margin around tool-bar buttons in pixels.
24328 If an integer, use that for both horizontal and vertical margins.
24329 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
24330 HORZ specifying the horizontal margin, and VERT specifying the
24331 vertical margin. */);
24332 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
24334 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
24335 doc
: /* *Relief thickness of tool-bar buttons. */);
24336 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
24338 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
24339 doc
: /* List of functions to call to fontify regions of text.
24340 Each function is called with one argument POS. Functions must
24341 fontify a region starting at POS in the current buffer, and give
24342 fontified regions the property `fontified'. */);
24343 Vfontification_functions
= Qnil
;
24344 Fmake_variable_buffer_local (Qfontification_functions
);
24346 DEFVAR_BOOL ("unibyte-display-via-language-environment",
24347 &unibyte_display_via_language_environment
,
24348 doc
: /* *Non-nil means display unibyte text according to language environment.
24349 Specifically this means that unibyte non-ASCII characters
24350 are displayed by converting them to the equivalent multibyte characters
24351 according to the current language environment. As a result, they are
24352 displayed according to the current fontset. */);
24353 unibyte_display_via_language_environment
= 0;
24355 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
24356 doc
: /* *Maximum height for resizing mini-windows.
24357 If a float, it specifies a fraction of the mini-window frame's height.
24358 If an integer, it specifies a number of lines. */);
24359 Vmax_mini_window_height
= make_float (0.25);
24361 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
24362 doc
: /* *How to resize mini-windows.
24363 A value of nil means don't automatically resize mini-windows.
24364 A value of t means resize them to fit the text displayed in them.
24365 A value of `grow-only', the default, means let mini-windows grow
24366 only, until their display becomes empty, at which point the windows
24367 go back to their normal size. */);
24368 Vresize_mini_windows
= Qgrow_only
;
24370 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
24371 doc
: /* Alist specifying how to blink the cursor off.
24372 Each element has the form (ON-STATE . OFF-STATE). Whenever the
24373 `cursor-type' frame-parameter or variable equals ON-STATE,
24374 comparing using `equal', Emacs uses OFF-STATE to specify
24375 how to blink it off. ON-STATE and OFF-STATE are values for
24376 the `cursor-type' frame parameter.
24378 If a frame's ON-STATE has no entry in this list,
24379 the frame's other specifications determine how to blink the cursor off. */);
24380 Vblink_cursor_alist
= Qnil
;
24382 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
24383 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
24384 automatic_hscrolling_p
= 1;
24385 Qauto_hscroll_mode
= intern ("auto-hscroll-mode");
24386 staticpro (&Qauto_hscroll_mode
);
24388 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
24389 doc
: /* *How many columns away from the window edge point is allowed to get
24390 before automatic hscrolling will horizontally scroll the window. */);
24391 hscroll_margin
= 5;
24393 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
24394 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
24395 When point is less than `hscroll-margin' columns from the window
24396 edge, automatic hscrolling will scroll the window by the amount of columns
24397 determined by this variable. If its value is a positive integer, scroll that
24398 many columns. If it's a positive floating-point number, it specifies the
24399 fraction of the window's width to scroll. If it's nil or zero, point will be
24400 centered horizontally after the scroll. Any other value, including negative
24401 numbers, are treated as if the value were zero.
24403 Automatic hscrolling always moves point outside the scroll margin, so if
24404 point was more than scroll step columns inside the margin, the window will
24405 scroll more than the value given by the scroll step.
24407 Note that the lower bound for automatic hscrolling specified by `scroll-left'
24408 and `scroll-right' overrides this variable's effect. */);
24409 Vhscroll_step
= make_number (0);
24411 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
24412 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
24413 Bind this around calls to `message' to let it take effect. */);
24414 message_truncate_lines
= 0;
24416 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
24417 doc
: /* Normal hook run to update the menu bar definitions.
24418 Redisplay runs this hook before it redisplays the menu bar.
24419 This is used to update submenus such as Buffers,
24420 whose contents depend on various data. */);
24421 Vmenu_bar_update_hook
= Qnil
;
24423 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
24424 doc
: /* Frame for which we are updating a menu.
24425 The enable predicate for a menu binding should check this variable. */);
24426 Vmenu_updating_frame
= Qnil
;
24428 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
24429 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
24430 inhibit_menubar_update
= 0;
24432 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
24433 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
24434 inhibit_eval_during_redisplay
= 0;
24436 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
24437 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
24438 inhibit_free_realized_faces
= 0;
24441 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
24442 doc
: /* Inhibit try_window_id display optimization. */);
24443 inhibit_try_window_id
= 0;
24445 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
24446 doc
: /* Inhibit try_window_reusing display optimization. */);
24447 inhibit_try_window_reusing
= 0;
24449 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
24450 doc
: /* Inhibit try_cursor_movement display optimization. */);
24451 inhibit_try_cursor_movement
= 0;
24452 #endif /* GLYPH_DEBUG */
24454 DEFVAR_INT ("overline-margin", &overline_margin
,
24455 doc
: /* *Space between overline and text, in pixels.
24456 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
24457 margin to the caracter height. */);
24458 overline_margin
= 2;
24462 /* Initialize this module when Emacs starts. */
24467 Lisp_Object root_window
;
24468 struct window
*mini_w
;
24470 current_header_line_height
= current_mode_line_height
= -1;
24472 CHARPOS (this_line_start_pos
) = 0;
24474 mini_w
= XWINDOW (minibuf_window
);
24475 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
24477 if (!noninteractive
)
24479 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
24482 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
24483 set_window_height (root_window
,
24484 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
24486 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
24487 set_window_height (minibuf_window
, 1, 0);
24489 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
24490 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
24492 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
24493 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
24494 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
24496 /* The default ellipsis glyphs `...'. */
24497 for (i
= 0; i
< 3; ++i
)
24498 default_invis_vector
[i
] = make_number ('.');
24502 /* Allocate the buffer for frame titles.
24503 Also used for `format-mode-line'. */
24505 mode_line_noprop_buf
= (char *) xmalloc (size
);
24506 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
24507 mode_line_noprop_ptr
= mode_line_noprop_buf
;
24508 mode_line_target
= MODE_LINE_DISPLAY
;
24511 help_echo_showing_p
= 0;
24515 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
24516 (do not change this comment) */