1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
3 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
27 Emacs separates the task of updating the display from code
28 modifying global state, e.g. buffer text. This way functions
29 operating on buffers don't also have to be concerned with updating
32 Updating the display is triggered by the Lisp interpreter when it
33 decides it's time to do it. This is done either automatically for
34 you as part of the interpreter's command loop or as the result of
35 calling Lisp functions like `sit-for'. The C function `redisplay'
36 in xdisp.c is the only entry into the inner redisplay code. (Or,
37 let's say almost---see the description of direct update
40 The following diagram shows how redisplay code is invoked. As you
41 can see, Lisp calls redisplay and vice versa. Under window systems
42 like X, some portions of the redisplay code are also called
43 asynchronously during mouse movement or expose events. It is very
44 important that these code parts do NOT use the C library (malloc,
45 free) because many C libraries under Unix are not reentrant. They
46 may also NOT call functions of the Lisp interpreter which could
47 change the interpreter's state. If you don't follow these rules,
48 you will encounter bugs which are very hard to explain.
50 (Direct functions, see below)
51 direct_output_for_insert,
52 direct_forward_char (dispnew.c)
53 +---------------------------------+
56 +--------------+ redisplay +----------------+
57 | Lisp machine |---------------->| Redisplay code |<--+
58 +--------------+ (xdisp.c) +----------------+ |
60 +----------------------------------+ |
61 Don't use this path when called |
64 expose_window (asynchronous) |
66 X expose events -----+
68 What does redisplay do? Obviously, it has to figure out somehow what
69 has been changed since the last time the display has been updated,
70 and to make these changes visible. Preferably it would do that in
71 a moderately intelligent way, i.e. fast.
73 Changes in buffer text can be deduced from window and buffer
74 structures, and from some global variables like `beg_unchanged' and
75 `end_unchanged'. The contents of the display are additionally
76 recorded in a `glyph matrix', a two-dimensional matrix of glyph
77 structures. Each row in such a matrix corresponds to a line on the
78 display, and each glyph in a row corresponds to a column displaying
79 a character, an image, or what else. This matrix is called the
80 `current glyph matrix' or `current matrix' in redisplay
83 For buffer parts that have been changed since the last update, a
84 second glyph matrix is constructed, the so called `desired glyph
85 matrix' or short `desired matrix'. Current and desired matrix are
86 then compared to find a cheap way to update the display, e.g. by
87 reusing part of the display by scrolling lines.
92 You will find a lot of redisplay optimizations when you start
93 looking at the innards of redisplay. The overall goal of all these
94 optimizations is to make redisplay fast because it is done
97 Two optimizations are not found in xdisp.c. These are the direct
98 operations mentioned above. As the name suggests they follow a
99 different principle than the rest of redisplay. Instead of
100 building a desired matrix and then comparing it with the current
101 display, they perform their actions directly on the display and on
104 One direct operation updates the display after one character has
105 been entered. The other one moves the cursor by one position
106 forward or backward. You find these functions under the names
107 `direct_output_for_insert' and `direct_output_forward_char' in
113 Desired matrices are always built per Emacs window. The function
114 `display_line' is the central function to look at if you are
115 interested. It constructs one row in a desired matrix given an
116 iterator structure containing both a buffer position and a
117 description of the environment in which the text is to be
118 displayed. But this is too early, read on.
120 Characters and pixmaps displayed for a range of buffer text depend
121 on various settings of buffers and windows, on overlays and text
122 properties, on display tables, on selective display. The good news
123 is that all this hairy stuff is hidden behind a small set of
124 interface functions taking an iterator structure (struct it)
127 Iteration over things to be displayed is then simple. It is
128 started by initializing an iterator with a call to init_iterator.
129 Calls to get_next_display_element fill the iterator structure with
130 relevant information about the next thing to display. Calls to
131 set_iterator_to_next move the iterator to the next thing.
133 Besides this, an iterator also contains information about the
134 display environment in which glyphs for display elements are to be
135 produced. It has fields for the width and height of the display,
136 the information whether long lines are truncated or continued, a
137 current X and Y position, and lots of other stuff you can better
140 Glyphs in a desired matrix are normally constructed in a loop
141 calling get_next_display_element and then produce_glyphs. The call
142 to produce_glyphs will fill the iterator structure with pixel
143 information about the element being displayed and at the same time
144 produce glyphs for it. If the display element fits on the line
145 being displayed, set_iterator_to_next is called next, otherwise the
146 glyphs produced are discarded.
151 That just couldn't be all, could it? What about terminal types not
152 supporting operations on sub-windows of the screen? To update the
153 display on such a terminal, window-based glyph matrices are not
154 well suited. To be able to reuse part of the display (scrolling
155 lines up and down), we must instead have a view of the whole
156 screen. This is what `frame matrices' are for. They are a trick.
158 Frames on terminals like above have a glyph pool. Windows on such
159 a frame sub-allocate their glyph memory from their frame's glyph
160 pool. The frame itself is given its own glyph matrices. By
161 coincidence---or maybe something else---rows in window glyph
162 matrices are slices of corresponding rows in frame matrices. Thus
163 writing to window matrices implicitly updates a frame matrix which
164 provides us with the view of the whole screen that we originally
165 wanted to have without having to move many bytes around. To be
166 honest, there is a little bit more done, but not much more. If you
167 plan to extend that code, take a look at dispnew.c. The function
168 build_frame_matrix is a good starting point. */
174 #include "keyboard.h"
177 #include "termchar.h"
178 #include "dispextern.h"
182 #include "commands.h"
186 #include "termhooks.h"
187 #include "intervals.h"
190 #include "region-cache.h"
192 #include "blockinput.h"
194 #ifdef HAVE_X_WINDOWS
204 #ifndef FRAME_X_OUTPUT
205 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
208 #define INFINITY 10000000
210 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
212 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
213 extern int pending_menu_activation
;
216 extern int interrupt_input
;
217 extern int command_loop_level
;
219 extern Lisp_Object do_mouse_tracking
;
221 extern int minibuffer_auto_raise
;
222 extern Lisp_Object Vminibuffer_list
;
224 extern Lisp_Object Qface
;
225 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
227 extern Lisp_Object Voverriding_local_map
;
228 extern Lisp_Object Voverriding_local_map_menu_flag
;
229 extern Lisp_Object Qmenu_item
;
230 extern Lisp_Object Qwhen
;
231 extern Lisp_Object Qhelp_echo
;
233 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
234 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
235 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
236 Lisp_Object Qinhibit_point_motion_hooks
;
237 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
238 Lisp_Object Qfontified
;
239 Lisp_Object Qgrow_only
;
240 Lisp_Object Qinhibit_eval_during_redisplay
;
241 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
244 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
247 Lisp_Object Qarrow
, Qhand
, Qtext
;
249 Lisp_Object Qrisky_local_variable
;
251 /* Holds the list (error). */
252 Lisp_Object list_of_error
;
254 /* Functions called to fontify regions of text. */
256 Lisp_Object Vfontification_functions
;
257 Lisp_Object Qfontification_functions
;
259 /* Non-nil means automatically select any window when the mouse
260 cursor moves into it. */
261 Lisp_Object Vmouse_autoselect_window
;
263 /* Non-zero means draw tool bar buttons raised when the mouse moves
266 int auto_raise_tool_bar_buttons_p
;
268 /* Non-zero means to reposition window if cursor line is only partially visible. */
270 int make_cursor_line_fully_visible_p
;
272 /* Margin below tool bar in pixels. 0 or nil means no margin.
273 If value is `internal-border-width' or `border-width',
274 the corresponding frame parameter is used. */
276 Lisp_Object Vtool_bar_border
;
278 /* Margin around tool bar buttons in pixels. */
280 Lisp_Object Vtool_bar_button_margin
;
282 /* Thickness of shadow to draw around tool bar buttons. */
284 EMACS_INT tool_bar_button_relief
;
286 /* Non-nil means automatically resize tool-bars so that all tool-bar
287 items are visible, and no blank lines remain.
289 If value is `grow-only', only make tool-bar bigger. */
291 Lisp_Object Vauto_resize_tool_bars
;
293 /* Non-zero means draw block and hollow cursor as wide as the glyph
294 under it. For example, if a block cursor is over a tab, it will be
295 drawn as wide as that tab on the display. */
297 int x_stretch_cursor_p
;
299 /* Non-nil means don't actually do any redisplay. */
301 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
303 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
305 int inhibit_eval_during_redisplay
;
307 /* Names of text properties relevant for redisplay. */
309 Lisp_Object Qdisplay
;
310 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
312 /* Symbols used in text property values. */
314 Lisp_Object Vdisplay_pixels_per_inch
;
315 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
316 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
319 Lisp_Object Qmargin
, Qpointer
;
320 Lisp_Object Qline_height
;
321 extern Lisp_Object Qheight
;
322 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
323 extern Lisp_Object Qscroll_bar
;
324 extern Lisp_Object Qcursor
;
326 /* Non-nil means highlight trailing whitespace. */
328 Lisp_Object Vshow_trailing_whitespace
;
330 /* Non-nil means escape non-break space and hyphens. */
332 Lisp_Object Vnobreak_char_display
;
334 #ifdef HAVE_WINDOW_SYSTEM
335 extern Lisp_Object Voverflow_newline_into_fringe
;
337 /* Test if overflow newline into fringe. Called with iterator IT
338 at or past right window margin, and with IT->current_x set. */
340 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
341 (!NILP (Voverflow_newline_into_fringe) \
342 && FRAME_WINDOW_P (it->f) \
343 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
344 && it->current_x == it->last_visible_x)
346 #endif /* HAVE_WINDOW_SYSTEM */
348 /* Non-nil means show the text cursor in void text areas
349 i.e. in blank areas after eol and eob. This used to be
350 the default in 21.3. */
352 Lisp_Object Vvoid_text_area_pointer
;
354 /* Name of the face used to highlight trailing whitespace. */
356 Lisp_Object Qtrailing_whitespace
;
358 /* Name and number of the face used to highlight escape glyphs. */
360 Lisp_Object Qescape_glyph
;
362 /* Name and number of the face used to highlight non-breaking spaces. */
364 Lisp_Object Qnobreak_space
;
366 /* The symbol `image' which is the car of the lists used to represent
371 /* The image map types. */
372 Lisp_Object QCmap
, QCpointer
;
373 Lisp_Object Qrect
, Qcircle
, Qpoly
;
375 /* Non-zero means print newline to stdout before next mini-buffer
378 int noninteractive_need_newline
;
380 /* Non-zero means print newline to message log before next message. */
382 static int message_log_need_newline
;
384 /* Three markers that message_dolog uses.
385 It could allocate them itself, but that causes trouble
386 in handling memory-full errors. */
387 static Lisp_Object message_dolog_marker1
;
388 static Lisp_Object message_dolog_marker2
;
389 static Lisp_Object message_dolog_marker3
;
391 /* The buffer position of the first character appearing entirely or
392 partially on the line of the selected window which contains the
393 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
394 redisplay optimization in redisplay_internal. */
396 static struct text_pos this_line_start_pos
;
398 /* Number of characters past the end of the line above, including the
399 terminating newline. */
401 static struct text_pos this_line_end_pos
;
403 /* The vertical positions and the height of this line. */
405 static int this_line_vpos
;
406 static int this_line_y
;
407 static int this_line_pixel_height
;
409 /* X position at which this display line starts. Usually zero;
410 negative if first character is partially visible. */
412 static int this_line_start_x
;
414 /* Buffer that this_line_.* variables are referring to. */
416 static struct buffer
*this_line_buffer
;
418 /* Nonzero means truncate lines in all windows less wide than the
421 int truncate_partial_width_windows
;
423 /* A flag to control how to display unibyte 8-bit character. */
425 int unibyte_display_via_language_environment
;
427 /* Nonzero means we have more than one non-mini-buffer-only frame.
428 Not guaranteed to be accurate except while parsing
429 frame-title-format. */
433 Lisp_Object Vglobal_mode_string
;
436 /* List of variables (symbols) which hold markers for overlay arrows.
437 The symbols on this list are examined during redisplay to determine
438 where to display overlay arrows. */
440 Lisp_Object Voverlay_arrow_variable_list
;
442 /* Marker for where to display an arrow on top of the buffer text. */
444 Lisp_Object Voverlay_arrow_position
;
446 /* String to display for the arrow. Only used on terminal frames. */
448 Lisp_Object Voverlay_arrow_string
;
450 /* Values of those variables at last redisplay are stored as
451 properties on `overlay-arrow-position' symbol. However, if
452 Voverlay_arrow_position is a marker, last-arrow-position is its
453 numerical position. */
455 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
457 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
458 properties on a symbol in overlay-arrow-variable-list. */
460 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
462 /* Like mode-line-format, but for the title bar on a visible frame. */
464 Lisp_Object Vframe_title_format
;
466 /* Like mode-line-format, but for the title bar on an iconified frame. */
468 Lisp_Object Vicon_title_format
;
470 /* List of functions to call when a window's size changes. These
471 functions get one arg, a frame on which one or more windows' sizes
474 static Lisp_Object Vwindow_size_change_functions
;
476 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
478 /* Nonzero if an overlay arrow has been displayed in this window. */
480 static int overlay_arrow_seen
;
482 /* Nonzero means highlight the region even in nonselected windows. */
484 int highlight_nonselected_windows
;
486 /* If cursor motion alone moves point off frame, try scrolling this
487 many lines up or down if that will bring it back. */
489 static EMACS_INT scroll_step
;
491 /* Nonzero means scroll just far enough to bring point back on the
492 screen, when appropriate. */
494 static EMACS_INT scroll_conservatively
;
496 /* Recenter the window whenever point gets within this many lines of
497 the top or bottom of the window. This value is translated into a
498 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
499 that there is really a fixed pixel height scroll margin. */
501 EMACS_INT scroll_margin
;
503 /* Number of windows showing the buffer of the selected window (or
504 another buffer with the same base buffer). keyboard.c refers to
509 /* Vector containing glyphs for an ellipsis `...'. */
511 static Lisp_Object default_invis_vector
[3];
513 /* Zero means display the mode-line/header-line/menu-bar in the default face
514 (this slightly odd definition is for compatibility with previous versions
515 of emacs), non-zero means display them using their respective faces.
517 This variable is deprecated. */
519 int mode_line_inverse_video
;
521 /* Prompt to display in front of the mini-buffer contents. */
523 Lisp_Object minibuf_prompt
;
525 /* Width of current mini-buffer prompt. Only set after display_line
526 of the line that contains the prompt. */
528 int minibuf_prompt_width
;
530 /* This is the window where the echo area message was displayed. It
531 is always a mini-buffer window, but it may not be the same window
532 currently active as a mini-buffer. */
534 Lisp_Object echo_area_window
;
536 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
537 pushes the current message and the value of
538 message_enable_multibyte on the stack, the function restore_message
539 pops the stack and displays MESSAGE again. */
541 Lisp_Object Vmessage_stack
;
543 /* Nonzero means multibyte characters were enabled when the echo area
544 message was specified. */
546 int message_enable_multibyte
;
548 /* Nonzero if we should redraw the mode lines on the next redisplay. */
550 int update_mode_lines
;
552 /* Nonzero if window sizes or contents have changed since last
553 redisplay that finished. */
555 int windows_or_buffers_changed
;
557 /* Nonzero means a frame's cursor type has been changed. */
559 int cursor_type_changed
;
561 /* Nonzero after display_mode_line if %l was used and it displayed a
564 int line_number_displayed
;
566 /* Maximum buffer size for which to display line numbers. */
568 Lisp_Object Vline_number_display_limit
;
570 /* Line width to consider when repositioning for line number display. */
572 static EMACS_INT line_number_display_limit_width
;
574 /* Number of lines to keep in the message log buffer. t means
575 infinite. nil means don't log at all. */
577 Lisp_Object Vmessage_log_max
;
579 /* The name of the *Messages* buffer, a string. */
581 static Lisp_Object Vmessages_buffer_name
;
583 /* 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
;
693 /* How close to the margin can point get before the window is scrolled
695 EMACS_INT hscroll_margin
;
697 /* How much to scroll horizontally when point is inside the above margin. */
698 Lisp_Object Vhscroll_step
;
700 /* The variable `resize-mini-windows'. If nil, don't resize
701 mini-windows. If t, always resize them to fit the text they
702 display. If `grow-only', let mini-windows grow only until they
705 Lisp_Object Vresize_mini_windows
;
707 /* Buffer being redisplayed -- for redisplay_window_error. */
709 struct buffer
*displayed_buffer
;
711 /* Space between overline and text. */
713 EMACS_INT overline_margin
;
715 /* Value returned from text property handlers (see below). */
720 HANDLED_RECOMPUTE_PROPS
,
721 HANDLED_OVERLAY_STRING_CONSUMED
,
725 /* A description of text properties that redisplay is interested
730 /* The name of the property. */
733 /* A unique index for the property. */
736 /* A handler function called to set up iterator IT from the property
737 at IT's current position. Value is used to steer handle_stop. */
738 enum prop_handled (*handler
) P_ ((struct it
*it
));
741 static enum prop_handled handle_face_prop
P_ ((struct it
*));
742 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
743 static enum prop_handled handle_display_prop
P_ ((struct it
*));
744 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
745 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
746 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
748 /* Properties handled by iterators. */
750 static struct props it_props
[] =
752 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
753 /* Handle `face' before `display' because some sub-properties of
754 `display' need to know the face. */
755 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
756 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
757 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
758 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
762 /* Value is the position described by X. If X is a marker, value is
763 the marker_position of X. Otherwise, value is X. */
765 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
767 /* Enumeration returned by some move_it_.* functions internally. */
771 /* Not used. Undefined value. */
774 /* Move ended at the requested buffer position or ZV. */
775 MOVE_POS_MATCH_OR_ZV
,
777 /* Move ended at the requested X pixel position. */
780 /* Move within a line ended at the end of a line that must be
784 /* Move within a line ended at the end of a line that would
785 be displayed truncated. */
788 /* Move within a line ended at a line end. */
792 /* This counter is used to clear the face cache every once in a while
793 in redisplay_internal. It is incremented for each redisplay.
794 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
797 #define CLEAR_FACE_CACHE_COUNT 500
798 static int clear_face_cache_count
;
800 /* Similarly for the image cache. */
802 #ifdef HAVE_WINDOW_SYSTEM
803 #define CLEAR_IMAGE_CACHE_COUNT 101
804 static int clear_image_cache_count
;
807 /* Non-zero while redisplay_internal is in progress. */
811 /* Non-zero means don't free realized faces. Bound while freeing
812 realized faces is dangerous because glyph matrices might still
815 int inhibit_free_realized_faces
;
816 Lisp_Object Qinhibit_free_realized_faces
;
818 /* If a string, XTread_socket generates an event to display that string.
819 (The display is done in read_char.) */
821 Lisp_Object help_echo_string
;
822 Lisp_Object help_echo_window
;
823 Lisp_Object help_echo_object
;
826 /* Temporary variable for XTread_socket. */
828 Lisp_Object previous_help_echo_string
;
830 /* Null glyph slice */
832 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
835 /* Function prototypes. */
837 static void setup_for_ellipsis
P_ ((struct it
*, int));
838 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
839 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
840 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
841 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
842 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
843 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
846 static int invisible_text_between_p
P_ ((struct it
*, int, int));
849 static void pint2str
P_ ((char *, int, int));
850 static void pint2hrstr
P_ ((char *, int, int));
851 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
853 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
854 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
855 static void store_mode_line_noprop_char
P_ ((char));
856 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
857 static void x_consider_frame_title
P_ ((Lisp_Object
));
858 static void handle_stop
P_ ((struct it
*));
859 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
860 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
861 static void ensure_echo_area_buffers
P_ ((void));
862 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
863 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
864 static int with_echo_area_buffer
P_ ((struct window
*, int,
865 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
866 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
867 static void clear_garbaged_frames
P_ ((void));
868 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
869 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
870 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
871 static int display_echo_area
P_ ((struct window
*));
872 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
873 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
874 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
875 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
876 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
878 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
879 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
880 static void insert_left_trunc_glyphs
P_ ((struct it
*));
881 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
883 static void extend_face_to_end_of_line
P_ ((struct it
*));
884 static int append_space_for_newline
P_ ((struct it
*, int));
885 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
886 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
887 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
888 static int trailing_whitespace_p
P_ ((int));
889 static int message_log_check_duplicate
P_ ((int, int, int, int));
890 static void push_it
P_ ((struct it
*));
891 static void pop_it
P_ ((struct it
*));
892 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
893 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
894 static void redisplay_internal
P_ ((int));
895 static int echo_area_display
P_ ((int));
896 static void redisplay_windows
P_ ((Lisp_Object
));
897 static void redisplay_window
P_ ((Lisp_Object
, int));
898 static Lisp_Object
redisplay_window_error ();
899 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
900 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
901 static int update_menu_bar
P_ ((struct frame
*, int, int));
902 static int try_window_reusing_current_matrix
P_ ((struct window
*));
903 static int try_window_id
P_ ((struct window
*));
904 static int display_line
P_ ((struct it
*));
905 static int display_mode_lines
P_ ((struct window
*));
906 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
907 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
908 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
909 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
910 static void display_menu_bar
P_ ((struct window
*));
911 static int display_count_lines
P_ ((int, int, int, int, int *));
912 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
913 int, int, struct it
*, int, int, int, int));
914 static void compute_line_metrics
P_ ((struct it
*));
915 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
916 static int get_overlay_strings
P_ ((struct it
*, int));
917 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
918 static void next_overlay_string
P_ ((struct it
*));
919 static void reseat
P_ ((struct it
*, struct text_pos
, int));
920 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
921 static void back_to_previous_visible_line_start
P_ ((struct it
*));
922 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
923 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
924 static int next_element_from_ellipsis
P_ ((struct it
*));
925 static int next_element_from_display_vector
P_ ((struct it
*));
926 static int next_element_from_string
P_ ((struct it
*));
927 static int next_element_from_c_string
P_ ((struct it
*));
928 static int next_element_from_buffer
P_ ((struct it
*));
929 static int next_element_from_composition
P_ ((struct it
*));
930 static int next_element_from_image
P_ ((struct it
*));
931 static int next_element_from_stretch
P_ ((struct it
*));
932 static void load_overlay_strings
P_ ((struct it
*, int));
933 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
934 struct display_pos
*));
935 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
936 Lisp_Object
, int, int, int, int));
937 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
939 void move_it_vertically_backward
P_ ((struct it
*, int));
940 static void init_to_row_start
P_ ((struct it
*, struct window
*,
941 struct glyph_row
*));
942 static int init_to_row_end
P_ ((struct it
*, struct window
*,
943 struct glyph_row
*));
944 static void back_to_previous_line_start
P_ ((struct it
*));
945 static int forward_to_next_line_start
P_ ((struct it
*, int *));
946 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
948 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
949 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
950 static int number_of_chars
P_ ((unsigned char *, int));
951 static void compute_stop_pos
P_ ((struct it
*));
952 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
954 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
955 static int next_overlay_change
P_ ((int));
956 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
957 Lisp_Object
, struct text_pos
*,
959 static int underlying_face_id
P_ ((struct it
*));
960 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
963 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
964 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
966 #ifdef HAVE_WINDOW_SYSTEM
968 static void update_tool_bar
P_ ((struct frame
*, int));
969 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
970 static int redisplay_tool_bar
P_ ((struct frame
*));
971 static void display_tool_bar_line
P_ ((struct it
*, int));
972 static void notice_overwritten_cursor
P_ ((struct window
*,
974 int, int, int, int));
978 #endif /* HAVE_WINDOW_SYSTEM */
981 /***********************************************************************
982 Window display dimensions
983 ***********************************************************************/
985 /* Return the bottom boundary y-position for text lines in window W.
986 This is the first y position at which a line cannot start.
987 It is relative to the top of the window.
989 This is the height of W minus the height of a mode line, if any. */
992 window_text_bottom_y (w
)
995 int height
= WINDOW_TOTAL_HEIGHT (w
);
997 if (WINDOW_WANTS_MODELINE_P (w
))
998 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1002 /* Return the pixel width of display area AREA of window W. AREA < 0
1003 means return the total width of W, not including fringes to
1004 the left and right of the window. */
1007 window_box_width (w
, area
)
1011 int cols
= XFASTINT (w
->total_cols
);
1014 if (!w
->pseudo_window_p
)
1016 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1018 if (area
== TEXT_AREA
)
1020 if (INTEGERP (w
->left_margin_cols
))
1021 cols
-= XFASTINT (w
->left_margin_cols
);
1022 if (INTEGERP (w
->right_margin_cols
))
1023 cols
-= XFASTINT (w
->right_margin_cols
);
1024 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1026 else if (area
== LEFT_MARGIN_AREA
)
1028 cols
= (INTEGERP (w
->left_margin_cols
)
1029 ? XFASTINT (w
->left_margin_cols
) : 0);
1032 else if (area
== RIGHT_MARGIN_AREA
)
1034 cols
= (INTEGERP (w
->right_margin_cols
)
1035 ? XFASTINT (w
->right_margin_cols
) : 0);
1040 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1044 /* Return the pixel height of the display area of window W, not
1045 including mode lines of W, if any. */
1048 window_box_height (w
)
1051 struct frame
*f
= XFRAME (w
->frame
);
1052 int height
= WINDOW_TOTAL_HEIGHT (w
);
1054 xassert (height
>= 0);
1056 /* Note: the code below that determines the mode-line/header-line
1057 height is essentially the same as that contained in the macro
1058 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1059 the appropriate glyph row has its `mode_line_p' flag set,
1060 and if it doesn't, uses estimate_mode_line_height instead. */
1062 if (WINDOW_WANTS_MODELINE_P (w
))
1064 struct glyph_row
*ml_row
1065 = (w
->current_matrix
&& w
->current_matrix
->rows
1066 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1068 if (ml_row
&& ml_row
->mode_line_p
)
1069 height
-= ml_row
->height
;
1071 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1074 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1076 struct glyph_row
*hl_row
1077 = (w
->current_matrix
&& w
->current_matrix
->rows
1078 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1080 if (hl_row
&& hl_row
->mode_line_p
)
1081 height
-= hl_row
->height
;
1083 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1086 /* With a very small font and a mode-line that's taller than
1087 default, we might end up with a negative height. */
1088 return max (0, height
);
1091 /* Return the window-relative coordinate of the left edge of display
1092 area AREA of window W. AREA < 0 means return the left edge of the
1093 whole window, to the right of the left fringe of W. */
1096 window_box_left_offset (w
, area
)
1102 if (w
->pseudo_window_p
)
1105 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1107 if (area
== TEXT_AREA
)
1108 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1109 + window_box_width (w
, LEFT_MARGIN_AREA
));
1110 else if (area
== RIGHT_MARGIN_AREA
)
1111 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1112 + window_box_width (w
, LEFT_MARGIN_AREA
)
1113 + window_box_width (w
, TEXT_AREA
)
1114 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1116 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1117 else if (area
== LEFT_MARGIN_AREA
1118 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1119 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1125 /* Return the window-relative coordinate of the right edge of display
1126 area AREA of window W. AREA < 0 means return the left edge of the
1127 whole window, to the left of the right fringe of W. */
1130 window_box_right_offset (w
, area
)
1134 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1137 /* Return the frame-relative coordinate of the left edge of display
1138 area AREA of window W. AREA < 0 means return the left edge of the
1139 whole window, to the right of the left fringe of W. */
1142 window_box_left (w
, area
)
1146 struct frame
*f
= XFRAME (w
->frame
);
1149 if (w
->pseudo_window_p
)
1150 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1152 x
= (WINDOW_LEFT_EDGE_X (w
)
1153 + window_box_left_offset (w
, area
));
1159 /* Return the frame-relative coordinate of the right edge of display
1160 area AREA of window W. AREA < 0 means return the left edge of the
1161 whole window, to the left of the right fringe of W. */
1164 window_box_right (w
, area
)
1168 return window_box_left (w
, area
) + window_box_width (w
, area
);
1171 /* Get the bounding box of the display area AREA of window W, without
1172 mode lines, in frame-relative coordinates. AREA < 0 means the
1173 whole window, not including the left and right fringes of
1174 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1175 coordinates of the upper-left corner of the box. Return in
1176 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1179 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1182 int *box_x
, *box_y
, *box_width
, *box_height
;
1185 *box_width
= window_box_width (w
, area
);
1187 *box_height
= window_box_height (w
);
1189 *box_x
= window_box_left (w
, area
);
1192 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1193 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1194 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1199 /* Get the bounding box of the display area AREA of window W, without
1200 mode lines. AREA < 0 means the whole window, not including the
1201 left and right fringe of the window. Return in *TOP_LEFT_X
1202 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1203 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1204 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1208 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1209 bottom_right_x
, bottom_right_y
)
1212 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1214 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1216 *bottom_right_x
+= *top_left_x
;
1217 *bottom_right_y
+= *top_left_y
;
1222 /***********************************************************************
1224 ***********************************************************************/
1226 /* Return the bottom y-position of the line the iterator IT is in.
1227 This can modify IT's settings. */
1233 int line_height
= it
->max_ascent
+ it
->max_descent
;
1234 int line_top_y
= it
->current_y
;
1236 if (line_height
== 0)
1239 line_height
= last_height
;
1240 else if (IT_CHARPOS (*it
) < ZV
)
1242 move_it_by_lines (it
, 1, 1);
1243 line_height
= (it
->max_ascent
|| it
->max_descent
1244 ? it
->max_ascent
+ it
->max_descent
1249 struct glyph_row
*row
= it
->glyph_row
;
1251 /* Use the default character height. */
1252 it
->glyph_row
= NULL
;
1253 it
->what
= IT_CHARACTER
;
1256 PRODUCE_GLYPHS (it
);
1257 line_height
= it
->ascent
+ it
->descent
;
1258 it
->glyph_row
= row
;
1262 return line_top_y
+ line_height
;
1266 /* Return 1 if position CHARPOS is visible in window W.
1267 CHARPOS < 0 means return info about WINDOW_END position.
1268 If visible, set *X and *Y to pixel coordinates of top left corner.
1269 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1270 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1273 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1275 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1278 struct text_pos top
;
1280 struct buffer
*old_buffer
= NULL
;
1285 if (XBUFFER (w
->buffer
) != current_buffer
)
1287 old_buffer
= current_buffer
;
1288 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1291 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1293 /* Compute exact mode line heights. */
1294 if (WINDOW_WANTS_MODELINE_P (w
))
1295 current_mode_line_height
1296 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1297 current_buffer
->mode_line_format
);
1299 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1300 current_header_line_height
1301 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1302 current_buffer
->header_line_format
);
1304 start_display (&it
, w
, top
);
1305 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1306 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1308 /* Note that we may overshoot because of invisible text. */
1309 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1311 int top_x
= it
.current_x
;
1312 int top_y
= it
.current_y
;
1313 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1314 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1316 if (top_y
< window_top_y
)
1317 visible_p
= bottom_y
> window_top_y
;
1318 else if (top_y
< it
.last_visible_y
)
1323 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1324 *rtop
= max (0, window_top_y
- top_y
);
1325 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1326 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1327 - max (top_y
, window_top_y
)));
1336 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1337 move_it_by_lines (&it
, 1, 0);
1338 if (charpos
< IT_CHARPOS (it
)
1339 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1342 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1344 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1345 *rtop
= max (0, -it2
.current_y
);
1346 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1347 - it
.last_visible_y
));
1348 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1350 - max (it2
.current_y
,
1351 WINDOW_HEADER_LINE_HEIGHT (w
))));
1357 set_buffer_internal_1 (old_buffer
);
1359 current_header_line_height
= current_mode_line_height
= -1;
1361 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1362 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1365 /* Debugging code. */
1367 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1368 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1370 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1377 /* Return the next character from STR which is MAXLEN bytes long.
1378 Return in *LEN the length of the character. This is like
1379 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1380 we find one, we return a `?', but with the length of the invalid
1384 string_char_and_length (str
, maxlen
, len
)
1385 const unsigned char *str
;
1390 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1391 if (!CHAR_VALID_P (c
, 1))
1392 /* We may not change the length here because other places in Emacs
1393 don't use this function, i.e. they silently accept invalid
1402 /* Given a position POS containing a valid character and byte position
1403 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1405 static struct text_pos
1406 string_pos_nchars_ahead (pos
, string
, nchars
)
1407 struct text_pos pos
;
1411 xassert (STRINGP (string
) && nchars
>= 0);
1413 if (STRING_MULTIBYTE (string
))
1415 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1416 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1421 string_char_and_length (p
, rest
, &len
);
1422 p
+= len
, rest
-= len
;
1423 xassert (rest
>= 0);
1425 BYTEPOS (pos
) += len
;
1429 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1435 /* Value is the text position, i.e. character and byte position,
1436 for character position CHARPOS in STRING. */
1438 static INLINE
struct text_pos
1439 string_pos (charpos
, string
)
1443 struct text_pos pos
;
1444 xassert (STRINGP (string
));
1445 xassert (charpos
>= 0);
1446 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1451 /* Value is a text position, i.e. character and byte position, for
1452 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1453 means recognize multibyte characters. */
1455 static struct text_pos
1456 c_string_pos (charpos
, s
, multibyte_p
)
1461 struct text_pos pos
;
1463 xassert (s
!= NULL
);
1464 xassert (charpos
>= 0);
1468 int rest
= strlen (s
), len
;
1470 SET_TEXT_POS (pos
, 0, 0);
1473 string_char_and_length (s
, rest
, &len
);
1474 s
+= len
, rest
-= len
;
1475 xassert (rest
>= 0);
1477 BYTEPOS (pos
) += len
;
1481 SET_TEXT_POS (pos
, charpos
, charpos
);
1487 /* Value is the number of characters in C string S. MULTIBYTE_P
1488 non-zero means recognize multibyte characters. */
1491 number_of_chars (s
, multibyte_p
)
1499 int rest
= strlen (s
), len
;
1500 unsigned char *p
= (unsigned char *) s
;
1502 for (nchars
= 0; rest
> 0; ++nchars
)
1504 string_char_and_length (p
, rest
, &len
);
1505 rest
-= len
, p
+= len
;
1509 nchars
= strlen (s
);
1515 /* Compute byte position NEWPOS->bytepos corresponding to
1516 NEWPOS->charpos. POS is a known position in string STRING.
1517 NEWPOS->charpos must be >= POS.charpos. */
1520 compute_string_pos (newpos
, pos
, string
)
1521 struct text_pos
*newpos
, pos
;
1524 xassert (STRINGP (string
));
1525 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1527 if (STRING_MULTIBYTE (string
))
1528 *newpos
= string_pos_nchars_ahead (pos
, string
,
1529 CHARPOS (*newpos
) - CHARPOS (pos
));
1531 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1535 Return an estimation of the pixel height of mode or top lines on
1536 frame F. FACE_ID specifies what line's height to estimate. */
1539 estimate_mode_line_height (f
, face_id
)
1541 enum face_id face_id
;
1543 #ifdef HAVE_WINDOW_SYSTEM
1544 if (FRAME_WINDOW_P (f
))
1546 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1548 /* This function is called so early when Emacs starts that the face
1549 cache and mode line face are not yet initialized. */
1550 if (FRAME_FACE_CACHE (f
))
1552 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1556 height
= FONT_HEIGHT (face
->font
);
1557 if (face
->box_line_width
> 0)
1558 height
+= 2 * face
->box_line_width
;
1569 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1570 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1571 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1572 not force the value into range. */
1575 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1577 register int pix_x
, pix_y
;
1579 NativeRectangle
*bounds
;
1583 #ifdef HAVE_WINDOW_SYSTEM
1584 if (FRAME_WINDOW_P (f
))
1586 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1587 even for negative values. */
1589 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1591 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1593 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1594 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1597 STORE_NATIVE_RECT (*bounds
,
1598 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1599 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1600 FRAME_COLUMN_WIDTH (f
) - 1,
1601 FRAME_LINE_HEIGHT (f
) - 1);
1607 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1608 pix_x
= FRAME_TOTAL_COLS (f
);
1612 else if (pix_y
> FRAME_LINES (f
))
1613 pix_y
= FRAME_LINES (f
);
1623 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1624 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1625 can't tell the positions because W's display is not up to date,
1629 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1632 int *frame_x
, *frame_y
;
1634 #ifdef HAVE_WINDOW_SYSTEM
1635 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1639 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1640 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1642 if (display_completed
)
1644 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1645 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1646 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1652 hpos
+= glyph
->pixel_width
;
1656 /* If first glyph is partially visible, its first visible position is still 0. */
1668 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1669 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1680 #ifdef HAVE_WINDOW_SYSTEM
1682 /* Find the glyph under window-relative coordinates X/Y in window W.
1683 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1684 strings. Return in *HPOS and *VPOS the row and column number of
1685 the glyph found. Return in *AREA the glyph area containing X.
1686 Value is a pointer to the glyph found or null if X/Y is not on
1687 text, or we can't tell because W's current matrix is not up to
1690 static struct glyph
*
1691 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1694 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1696 struct glyph
*glyph
, *end
;
1697 struct glyph_row
*row
= NULL
;
1700 /* Find row containing Y. Give up if some row is not enabled. */
1701 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1703 row
= MATRIX_ROW (w
->current_matrix
, i
);
1704 if (!row
->enabled_p
)
1706 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1713 /* Give up if Y is not in the window. */
1714 if (i
== w
->current_matrix
->nrows
)
1717 /* Get the glyph area containing X. */
1718 if (w
->pseudo_window_p
)
1725 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1727 *area
= LEFT_MARGIN_AREA
;
1728 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1730 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1733 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1737 *area
= RIGHT_MARGIN_AREA
;
1738 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1742 /* Find glyph containing X. */
1743 glyph
= row
->glyphs
[*area
];
1744 end
= glyph
+ row
->used
[*area
];
1746 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1748 x
-= glyph
->pixel_width
;
1758 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1761 *hpos
= glyph
- row
->glyphs
[*area
];
1767 Convert frame-relative x/y to coordinates relative to window W.
1768 Takes pseudo-windows into account. */
1771 frame_to_window_pixel_xy (w
, x
, y
)
1775 if (w
->pseudo_window_p
)
1777 /* A pseudo-window is always full-width, and starts at the
1778 left edge of the frame, plus a frame border. */
1779 struct frame
*f
= XFRAME (w
->frame
);
1780 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1781 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1785 *x
-= WINDOW_LEFT_EDGE_X (w
);
1786 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1791 Return in RECTS[] at most N clipping rectangles for glyph string S.
1792 Return the number of stored rectangles. */
1795 get_glyph_string_clip_rects (s
, rects
, n
)
1796 struct glyph_string
*s
;
1797 NativeRectangle
*rects
;
1805 if (s
->row
->full_width_p
)
1807 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1808 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1809 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1811 /* Unless displaying a mode or menu bar line, which are always
1812 fully visible, clip to the visible part of the row. */
1813 if (s
->w
->pseudo_window_p
)
1814 r
.height
= s
->row
->visible_height
;
1816 r
.height
= s
->height
;
1820 /* This is a text line that may be partially visible. */
1821 r
.x
= window_box_left (s
->w
, s
->area
);
1822 r
.width
= window_box_width (s
->w
, s
->area
);
1823 r
.height
= s
->row
->visible_height
;
1827 if (r
.x
< s
->clip_head
->x
)
1829 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1830 r
.width
-= s
->clip_head
->x
- r
.x
;
1833 r
.x
= s
->clip_head
->x
;
1836 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1838 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1839 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1844 /* If S draws overlapping rows, it's sufficient to use the top and
1845 bottom of the window for clipping because this glyph string
1846 intentionally draws over other lines. */
1847 if (s
->for_overlaps
)
1849 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1850 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1852 /* Alas, the above simple strategy does not work for the
1853 environments with anti-aliased text: if the same text is
1854 drawn onto the same place multiple times, it gets thicker.
1855 If the overlap we are processing is for the erased cursor, we
1856 take the intersection with the rectagle of the cursor. */
1857 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1859 XRectangle rc
, r_save
= r
;
1861 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1862 rc
.y
= s
->w
->phys_cursor
.y
;
1863 rc
.width
= s
->w
->phys_cursor_width
;
1864 rc
.height
= s
->w
->phys_cursor_height
;
1866 x_intersect_rectangles (&r_save
, &rc
, &r
);
1871 /* Don't use S->y for clipping because it doesn't take partially
1872 visible lines into account. For example, it can be negative for
1873 partially visible lines at the top of a window. */
1874 if (!s
->row
->full_width_p
1875 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1876 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1878 r
.y
= max (0, s
->row
->y
);
1880 /* If drawing a tool-bar window, draw it over the internal border
1881 at the top of the window. */
1882 if (WINDOWP (s
->f
->tool_bar_window
)
1883 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1884 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1887 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1889 /* If drawing the cursor, don't let glyph draw outside its
1890 advertised boundaries. Cleartype does this under some circumstances. */
1891 if (s
->hl
== DRAW_CURSOR
)
1893 struct glyph
*glyph
= s
->first_glyph
;
1898 r
.width
-= s
->x
- r
.x
;
1901 r
.width
= min (r
.width
, glyph
->pixel_width
);
1903 /* If r.y is below window bottom, ensure that we still see a cursor. */
1904 height
= min (glyph
->ascent
+ glyph
->descent
,
1905 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1906 max_y
= window_text_bottom_y (s
->w
) - height
;
1907 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1908 if (s
->ybase
- glyph
->ascent
> max_y
)
1915 /* Don't draw cursor glyph taller than our actual glyph. */
1916 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1917 if (height
< r
.height
)
1919 max_y
= r
.y
+ r
.height
;
1920 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1921 r
.height
= min (max_y
- r
.y
, height
);
1926 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1927 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1929 #ifdef CONVERT_FROM_XRECT
1930 CONVERT_FROM_XRECT (r
, *rects
);
1938 /* If we are processing overlapping and allowed to return
1939 multiple clipping rectangles, we exclude the row of the glyph
1940 string from the clipping rectangle. This is to avoid drawing
1941 the same text on the environment with anti-aliasing. */
1942 #ifdef CONVERT_FROM_XRECT
1945 XRectangle
*rs
= rects
;
1947 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
1949 if (s
->for_overlaps
& OVERLAPS_PRED
)
1952 if (r
.y
+ r
.height
> row_y
)
1955 rs
[i
].height
= row_y
- r
.y
;
1961 if (s
->for_overlaps
& OVERLAPS_SUCC
)
1964 if (r
.y
< row_y
+ s
->row
->visible_height
)
1966 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
1968 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
1969 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
1978 #ifdef CONVERT_FROM_XRECT
1979 for (i
= 0; i
< n
; i
++)
1980 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
1987 Return in *NR the clipping rectangle for glyph string S. */
1990 get_glyph_string_clip_rect (s
, nr
)
1991 struct glyph_string
*s
;
1992 NativeRectangle
*nr
;
1994 get_glyph_string_clip_rects (s
, nr
, 1);
1999 Return the position and height of the phys cursor in window W.
2000 Set w->phys_cursor_width to width of phys cursor.
2004 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2006 struct glyph_row
*row
;
2007 struct glyph
*glyph
;
2008 int *xp
, *yp
, *heightp
;
2010 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2011 int x
, y
, wd
, h
, h0
, y0
;
2013 /* Compute the width of the rectangle to draw. If on a stretch
2014 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2015 rectangle as wide as the glyph, but use a canonical character
2017 wd
= glyph
->pixel_width
- 1;
2022 x
= w
->phys_cursor
.x
;
2029 if (glyph
->type
== STRETCH_GLYPH
2030 && !x_stretch_cursor_p
)
2031 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2032 w
->phys_cursor_width
= wd
;
2034 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2036 /* If y is below window bottom, ensure that we still see a cursor. */
2037 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2039 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2040 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2042 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2045 h
= max (h
- (y0
- y
) + 1, h0
);
2050 y0
= window_text_bottom_y (w
) - h0
;
2058 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2059 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2064 * Remember which glyph the mouse is over.
2068 remember_mouse_glyph (f
, gx
, gy
, rect
)
2071 NativeRectangle
*rect
;
2075 struct glyph_row
*r
, *gr
, *end_row
;
2076 enum window_part part
;
2077 enum glyph_row_area area
;
2078 int x
, y
, width
, height
;
2080 /* Try to determine frame pixel position and size of the glyph under
2081 frame pixel coordinates X/Y on frame F. */
2083 if (!f
->glyphs_initialized_p
2084 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2087 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2088 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2092 w
= XWINDOW (window
);
2093 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2094 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2096 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2097 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2099 if (w
->pseudo_window_p
)
2102 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2108 case ON_LEFT_MARGIN
:
2109 area
= LEFT_MARGIN_AREA
;
2112 case ON_RIGHT_MARGIN
:
2113 area
= RIGHT_MARGIN_AREA
;
2116 case ON_HEADER_LINE
:
2118 gr
= (part
== ON_HEADER_LINE
2119 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2120 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2123 goto text_glyph_row_found
;
2130 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2131 if (r
->y
+ r
->height
> y
)
2137 text_glyph_row_found
:
2140 struct glyph
*g
= gr
->glyphs
[area
];
2141 struct glyph
*end
= g
+ gr
->used
[area
];
2143 height
= gr
->height
;
2144 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2145 if (gx
+ g
->pixel_width
> x
)
2150 if (g
->type
== IMAGE_GLYPH
)
2152 /* Don't remember when mouse is over image, as
2153 image may have hot-spots. */
2154 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2157 width
= g
->pixel_width
;
2161 /* Use nominal char spacing at end of line. */
2163 gx
+= (x
/ width
) * width
;
2166 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2167 gx
+= window_box_left_offset (w
, area
);
2171 /* Use nominal line height at end of window. */
2172 gx
= (x
/ width
) * width
;
2174 gy
+= (y
/ height
) * height
;
2178 case ON_LEFT_FRINGE
:
2179 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2180 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2181 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2182 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2185 case ON_RIGHT_FRINGE
:
2186 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2187 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2188 : window_box_right_offset (w
, TEXT_AREA
));
2189 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2193 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2195 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2196 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2197 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2199 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2203 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2204 if (r
->y
+ r
->height
> y
)
2211 height
= gr
->height
;
2214 /* Use nominal line height at end of window. */
2216 gy
+= (y
/ height
) * height
;
2223 /* If there is no glyph under the mouse, then we divide the screen
2224 into a grid of the smallest glyph in the frame, and use that
2227 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2228 round down even for negative values. */
2234 gx
= (gx
/ width
) * width
;
2235 gy
= (gy
/ height
) * height
;
2240 gx
+= WINDOW_LEFT_EDGE_X (w
);
2241 gy
+= WINDOW_TOP_EDGE_Y (w
);
2244 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2246 /* Visible feedback for debugging. */
2249 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2250 f
->output_data
.x
->normal_gc
,
2251 gx
, gy
, width
, height
);
2257 #endif /* HAVE_WINDOW_SYSTEM */
2260 /***********************************************************************
2261 Lisp form evaluation
2262 ***********************************************************************/
2264 /* Error handler for safe_eval and safe_call. */
2267 safe_eval_handler (arg
)
2270 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2275 /* Evaluate SEXPR and return the result, or nil if something went
2276 wrong. Prevent redisplay during the evaluation. */
2284 if (inhibit_eval_during_redisplay
)
2288 int count
= SPECPDL_INDEX ();
2289 struct gcpro gcpro1
;
2292 specbind (Qinhibit_redisplay
, Qt
);
2293 /* Use Qt to ensure debugger does not run,
2294 so there is no possibility of wanting to redisplay. */
2295 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
2298 val
= unbind_to (count
, val
);
2305 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2306 Return the result, or nil if something went wrong. Prevent
2307 redisplay during the evaluation. */
2310 safe_call (nargs
, args
)
2316 if (inhibit_eval_during_redisplay
)
2320 int count
= SPECPDL_INDEX ();
2321 struct gcpro gcpro1
;
2324 gcpro1
.nvars
= nargs
;
2325 specbind (Qinhibit_redisplay
, Qt
);
2326 /* Use Qt to ensure debugger does not run,
2327 so there is no possibility of wanting to redisplay. */
2328 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2331 val
= unbind_to (count
, val
);
2338 /* Call function FN with one argument ARG.
2339 Return the result, or nil if something went wrong. */
2342 safe_call1 (fn
, arg
)
2343 Lisp_Object fn
, arg
;
2345 Lisp_Object args
[2];
2348 return safe_call (2, args
);
2353 /***********************************************************************
2355 ***********************************************************************/
2359 /* Define CHECK_IT to perform sanity checks on iterators.
2360 This is for debugging. It is too slow to do unconditionally. */
2366 if (it
->method
== GET_FROM_STRING
)
2368 xassert (STRINGP (it
->string
));
2369 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2373 xassert (IT_STRING_CHARPOS (*it
) < 0);
2374 if (it
->method
== GET_FROM_BUFFER
)
2376 /* Check that character and byte positions agree. */
2377 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2382 xassert (it
->current
.dpvec_index
>= 0);
2384 xassert (it
->current
.dpvec_index
< 0);
2387 #define CHECK_IT(IT) check_it ((IT))
2391 #define CHECK_IT(IT) (void) 0
2398 /* Check that the window end of window W is what we expect it
2399 to be---the last row in the current matrix displaying text. */
2402 check_window_end (w
)
2405 if (!MINI_WINDOW_P (w
)
2406 && !NILP (w
->window_end_valid
))
2408 struct glyph_row
*row
;
2409 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2410 XFASTINT (w
->window_end_vpos
)),
2412 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2413 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2417 #define CHECK_WINDOW_END(W) check_window_end ((W))
2419 #else /* not GLYPH_DEBUG */
2421 #define CHECK_WINDOW_END(W) (void) 0
2423 #endif /* not GLYPH_DEBUG */
2427 /***********************************************************************
2428 Iterator initialization
2429 ***********************************************************************/
2431 /* Initialize IT for displaying current_buffer in window W, starting
2432 at character position CHARPOS. CHARPOS < 0 means that no buffer
2433 position is specified which is useful when the iterator is assigned
2434 a position later. BYTEPOS is the byte position corresponding to
2435 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2437 If ROW is not null, calls to produce_glyphs with IT as parameter
2438 will produce glyphs in that row.
2440 BASE_FACE_ID is the id of a base face to use. It must be one of
2441 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2442 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2443 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2445 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2446 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2447 will be initialized to use the corresponding mode line glyph row of
2448 the desired matrix of W. */
2451 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2454 int charpos
, bytepos
;
2455 struct glyph_row
*row
;
2456 enum face_id base_face_id
;
2458 int highlight_region_p
;
2460 /* Some precondition checks. */
2461 xassert (w
!= NULL
&& it
!= NULL
);
2462 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2465 /* If face attributes have been changed since the last redisplay,
2466 free realized faces now because they depend on face definitions
2467 that might have changed. Don't free faces while there might be
2468 desired matrices pending which reference these faces. */
2469 if (face_change_count
&& !inhibit_free_realized_faces
)
2471 face_change_count
= 0;
2472 free_all_realized_faces (Qnil
);
2475 /* Use one of the mode line rows of W's desired matrix if
2479 if (base_face_id
== MODE_LINE_FACE_ID
2480 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2481 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2482 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2483 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2487 bzero (it
, sizeof *it
);
2488 it
->current
.overlay_string_index
= -1;
2489 it
->current
.dpvec_index
= -1;
2490 it
->base_face_id
= base_face_id
;
2492 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2494 /* The window in which we iterate over current_buffer: */
2495 XSETWINDOW (it
->window
, w
);
2497 it
->f
= XFRAME (w
->frame
);
2499 /* Extra space between lines (on window systems only). */
2500 if (base_face_id
== DEFAULT_FACE_ID
2501 && FRAME_WINDOW_P (it
->f
))
2503 if (NATNUMP (current_buffer
->extra_line_spacing
))
2504 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2505 else if (FLOATP (current_buffer
->extra_line_spacing
))
2506 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2507 * FRAME_LINE_HEIGHT (it
->f
));
2508 else if (it
->f
->extra_line_spacing
> 0)
2509 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2510 it
->max_extra_line_spacing
= 0;
2513 /* If realized faces have been removed, e.g. because of face
2514 attribute changes of named faces, recompute them. When running
2515 in batch mode, the face cache of the initial frame is null. If
2516 we happen to get called, make a dummy face cache. */
2517 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2518 init_frame_faces (it
->f
);
2519 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2520 recompute_basic_faces (it
->f
);
2522 /* Current value of the `slice', `space-width', and 'height' properties. */
2523 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2524 it
->space_width
= Qnil
;
2525 it
->font_height
= Qnil
;
2526 it
->override_ascent
= -1;
2528 /* Are control characters displayed as `^C'? */
2529 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2531 /* -1 means everything between a CR and the following line end
2532 is invisible. >0 means lines indented more than this value are
2534 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2535 ? XFASTINT (current_buffer
->selective_display
)
2536 : (!NILP (current_buffer
->selective_display
)
2538 it
->selective_display_ellipsis_p
2539 = !NILP (current_buffer
->selective_display_ellipses
);
2541 /* Display table to use. */
2542 it
->dp
= window_display_table (w
);
2544 /* Are multibyte characters enabled in current_buffer? */
2545 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2547 /* Non-zero if we should highlight the region. */
2549 = (!NILP (Vtransient_mark_mode
)
2550 && !NILP (current_buffer
->mark_active
)
2551 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2553 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2554 start and end of a visible region in window IT->w. Set both to
2555 -1 to indicate no region. */
2556 if (highlight_region_p
2557 /* Maybe highlight only in selected window. */
2558 && (/* Either show region everywhere. */
2559 highlight_nonselected_windows
2560 /* Or show region in the selected window. */
2561 || w
== XWINDOW (selected_window
)
2562 /* Or show the region if we are in the mini-buffer and W is
2563 the window the mini-buffer refers to. */
2564 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2565 && WINDOWP (minibuf_selected_window
)
2566 && w
== XWINDOW (minibuf_selected_window
))))
2568 int charpos
= marker_position (current_buffer
->mark
);
2569 it
->region_beg_charpos
= min (PT
, charpos
);
2570 it
->region_end_charpos
= max (PT
, charpos
);
2573 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2575 /* Get the position at which the redisplay_end_trigger hook should
2576 be run, if it is to be run at all. */
2577 if (MARKERP (w
->redisplay_end_trigger
)
2578 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2579 it
->redisplay_end_trigger_charpos
2580 = marker_position (w
->redisplay_end_trigger
);
2581 else if (INTEGERP (w
->redisplay_end_trigger
))
2582 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2584 /* Correct bogus values of tab_width. */
2585 it
->tab_width
= XINT (current_buffer
->tab_width
);
2586 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2589 /* Are lines in the display truncated? */
2590 it
->truncate_lines_p
2591 = (base_face_id
!= DEFAULT_FACE_ID
2592 || XINT (it
->w
->hscroll
)
2593 || (truncate_partial_width_windows
2594 && !WINDOW_FULL_WIDTH_P (it
->w
))
2595 || !NILP (current_buffer
->truncate_lines
));
2597 /* Get dimensions of truncation and continuation glyphs. These are
2598 displayed as fringe bitmaps under X, so we don't need them for such
2600 if (!FRAME_WINDOW_P (it
->f
))
2602 if (it
->truncate_lines_p
)
2604 /* We will need the truncation glyph. */
2605 xassert (it
->glyph_row
== NULL
);
2606 produce_special_glyphs (it
, IT_TRUNCATION
);
2607 it
->truncation_pixel_width
= it
->pixel_width
;
2611 /* We will need the continuation glyph. */
2612 xassert (it
->glyph_row
== NULL
);
2613 produce_special_glyphs (it
, IT_CONTINUATION
);
2614 it
->continuation_pixel_width
= it
->pixel_width
;
2617 /* Reset these values to zero because the produce_special_glyphs
2618 above has changed them. */
2619 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2620 it
->phys_ascent
= it
->phys_descent
= 0;
2623 /* Set this after getting the dimensions of truncation and
2624 continuation glyphs, so that we don't produce glyphs when calling
2625 produce_special_glyphs, above. */
2626 it
->glyph_row
= row
;
2627 it
->area
= TEXT_AREA
;
2629 /* Get the dimensions of the display area. The display area
2630 consists of the visible window area plus a horizontally scrolled
2631 part to the left of the window. All x-values are relative to the
2632 start of this total display area. */
2633 if (base_face_id
!= DEFAULT_FACE_ID
)
2635 /* Mode lines, menu bar in terminal frames. */
2636 it
->first_visible_x
= 0;
2637 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2642 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2643 it
->last_visible_x
= (it
->first_visible_x
2644 + window_box_width (w
, TEXT_AREA
));
2646 /* If we truncate lines, leave room for the truncator glyph(s) at
2647 the right margin. Otherwise, leave room for the continuation
2648 glyph(s). Truncation and continuation glyphs are not inserted
2649 for window-based redisplay. */
2650 if (!FRAME_WINDOW_P (it
->f
))
2652 if (it
->truncate_lines_p
)
2653 it
->last_visible_x
-= it
->truncation_pixel_width
;
2655 it
->last_visible_x
-= it
->continuation_pixel_width
;
2658 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2659 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2662 /* Leave room for a border glyph. */
2663 if (!FRAME_WINDOW_P (it
->f
)
2664 && !WINDOW_RIGHTMOST_P (it
->w
))
2665 it
->last_visible_x
-= 1;
2667 it
->last_visible_y
= window_text_bottom_y (w
);
2669 /* For mode lines and alike, arrange for the first glyph having a
2670 left box line if the face specifies a box. */
2671 if (base_face_id
!= DEFAULT_FACE_ID
)
2675 it
->face_id
= base_face_id
;
2677 /* If we have a boxed mode line, make the first character appear
2678 with a left box line. */
2679 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2680 if (face
->box
!= FACE_NO_BOX
)
2681 it
->start_of_box_run_p
= 1;
2684 /* If a buffer position was specified, set the iterator there,
2685 getting overlays and face properties from that position. */
2686 if (charpos
>= BUF_BEG (current_buffer
))
2688 it
->end_charpos
= ZV
;
2690 IT_CHARPOS (*it
) = charpos
;
2692 /* Compute byte position if not specified. */
2693 if (bytepos
< charpos
)
2694 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2696 IT_BYTEPOS (*it
) = bytepos
;
2698 it
->start
= it
->current
;
2700 /* Compute faces etc. */
2701 reseat (it
, it
->current
.pos
, 1);
2708 /* Initialize IT for the display of window W with window start POS. */
2711 start_display (it
, w
, pos
)
2714 struct text_pos pos
;
2716 struct glyph_row
*row
;
2717 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2719 row
= w
->desired_matrix
->rows
+ first_vpos
;
2720 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2721 it
->first_vpos
= first_vpos
;
2723 /* Don't reseat to previous visible line start if current start
2724 position is in a string or image. */
2725 if (it
->method
== GET_FROM_BUFFER
&& !it
->truncate_lines_p
)
2727 int start_at_line_beg_p
;
2728 int first_y
= it
->current_y
;
2730 /* If window start is not at a line start, skip forward to POS to
2731 get the correct continuation lines width. */
2732 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2733 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2734 if (!start_at_line_beg_p
)
2738 reseat_at_previous_visible_line_start (it
);
2739 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2741 new_x
= it
->current_x
+ it
->pixel_width
;
2743 /* If lines are continued, this line may end in the middle
2744 of a multi-glyph character (e.g. a control character
2745 displayed as \003, or in the middle of an overlay
2746 string). In this case move_it_to above will not have
2747 taken us to the start of the continuation line but to the
2748 end of the continued line. */
2749 if (it
->current_x
> 0
2750 && !it
->truncate_lines_p
/* Lines are continued. */
2751 && (/* And glyph doesn't fit on the line. */
2752 new_x
> it
->last_visible_x
2753 /* Or it fits exactly and we're on a window
2755 || (new_x
== it
->last_visible_x
2756 && FRAME_WINDOW_P (it
->f
))))
2758 if (it
->current
.dpvec_index
>= 0
2759 || it
->current
.overlay_string_index
>= 0)
2761 set_iterator_to_next (it
, 1);
2762 move_it_in_display_line_to (it
, -1, -1, 0);
2765 it
->continuation_lines_width
+= it
->current_x
;
2768 /* We're starting a new display line, not affected by the
2769 height of the continued line, so clear the appropriate
2770 fields in the iterator structure. */
2771 it
->max_ascent
= it
->max_descent
= 0;
2772 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2774 it
->current_y
= first_y
;
2776 it
->current_x
= it
->hpos
= 0;
2780 #if 0 /* Don't assert the following because start_display is sometimes
2781 called intentionally with a window start that is not at a
2782 line start. Please leave this code in as a comment. */
2784 /* Window start should be on a line start, now. */
2785 xassert (it
->continuation_lines_width
2786 || IT_CHARPOS (it
) == BEGV
2787 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2792 /* Return 1 if POS is a position in ellipses displayed for invisible
2793 text. W is the window we display, for text property lookup. */
2796 in_ellipses_for_invisible_text_p (pos
, w
)
2797 struct display_pos
*pos
;
2800 Lisp_Object prop
, window
;
2802 int charpos
= CHARPOS (pos
->pos
);
2804 /* If POS specifies a position in a display vector, this might
2805 be for an ellipsis displayed for invisible text. We won't
2806 get the iterator set up for delivering that ellipsis unless
2807 we make sure that it gets aware of the invisible text. */
2808 if (pos
->dpvec_index
>= 0
2809 && pos
->overlay_string_index
< 0
2810 && CHARPOS (pos
->string_pos
) < 0
2812 && (XSETWINDOW (window
, w
),
2813 prop
= Fget_char_property (make_number (charpos
),
2814 Qinvisible
, window
),
2815 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2817 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2819 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2826 /* Initialize IT for stepping through current_buffer in window W,
2827 starting at position POS that includes overlay string and display
2828 vector/ control character translation position information. Value
2829 is zero if there are overlay strings with newlines at POS. */
2832 init_from_display_pos (it
, w
, pos
)
2835 struct display_pos
*pos
;
2837 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2838 int i
, overlay_strings_with_newlines
= 0;
2840 /* If POS specifies a position in a display vector, this might
2841 be for an ellipsis displayed for invisible text. We won't
2842 get the iterator set up for delivering that ellipsis unless
2843 we make sure that it gets aware of the invisible text. */
2844 if (in_ellipses_for_invisible_text_p (pos
, w
))
2850 /* Keep in mind: the call to reseat in init_iterator skips invisible
2851 text, so we might end up at a position different from POS. This
2852 is only a problem when POS is a row start after a newline and an
2853 overlay starts there with an after-string, and the overlay has an
2854 invisible property. Since we don't skip invisible text in
2855 display_line and elsewhere immediately after consuming the
2856 newline before the row start, such a POS will not be in a string,
2857 but the call to init_iterator below will move us to the
2859 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2861 /* This only scans the current chunk -- it should scan all chunks.
2862 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2863 to 16 in 22.1 to make this a lesser problem. */
2864 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2866 const char *s
= SDATA (it
->overlay_strings
[i
]);
2867 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2869 while (s
< e
&& *s
!= '\n')
2874 overlay_strings_with_newlines
= 1;
2879 /* If position is within an overlay string, set up IT to the right
2881 if (pos
->overlay_string_index
>= 0)
2885 /* If the first overlay string happens to have a `display'
2886 property for an image, the iterator will be set up for that
2887 image, and we have to undo that setup first before we can
2888 correct the overlay string index. */
2889 if (it
->method
== GET_FROM_IMAGE
)
2892 /* We already have the first chunk of overlay strings in
2893 IT->overlay_strings. Load more until the one for
2894 pos->overlay_string_index is in IT->overlay_strings. */
2895 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2897 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2898 it
->current
.overlay_string_index
= 0;
2901 load_overlay_strings (it
, 0);
2902 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2906 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2907 relative_index
= (it
->current
.overlay_string_index
2908 % OVERLAY_STRING_CHUNK_SIZE
);
2909 it
->string
= it
->overlay_strings
[relative_index
];
2910 xassert (STRINGP (it
->string
));
2911 it
->current
.string_pos
= pos
->string_pos
;
2912 it
->method
= GET_FROM_STRING
;
2915 #if 0 /* This is bogus because POS not having an overlay string
2916 position does not mean it's after the string. Example: A
2917 line starting with a before-string and initialization of IT
2918 to the previous row's end position. */
2919 else if (it
->current
.overlay_string_index
>= 0)
2921 /* If POS says we're already after an overlay string ending at
2922 POS, make sure to pop the iterator because it will be in
2923 front of that overlay string. When POS is ZV, we've thereby
2924 also ``processed'' overlay strings at ZV. */
2927 xassert (it
->current
.overlay_string_index
== -1);
2928 xassert (it
->method
== GET_FROM_BUFFER
);
2929 if (CHARPOS (pos
->pos
) == ZV
)
2930 it
->overlay_strings_at_end_processed_p
= 1;
2934 if (CHARPOS (pos
->string_pos
) >= 0)
2936 /* Recorded position is not in an overlay string, but in another
2937 string. This can only be a string from a `display' property.
2938 IT should already be filled with that string. */
2939 it
->current
.string_pos
= pos
->string_pos
;
2940 xassert (STRINGP (it
->string
));
2943 /* Restore position in display vector translations, control
2944 character translations or ellipses. */
2945 if (pos
->dpvec_index
>= 0)
2947 if (it
->dpvec
== NULL
)
2948 get_next_display_element (it
);
2949 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2950 it
->current
.dpvec_index
= pos
->dpvec_index
;
2954 return !overlay_strings_with_newlines
;
2958 /* Initialize IT for stepping through current_buffer in window W
2959 starting at ROW->start. */
2962 init_to_row_start (it
, w
, row
)
2965 struct glyph_row
*row
;
2967 init_from_display_pos (it
, w
, &row
->start
);
2968 it
->start
= row
->start
;
2969 it
->continuation_lines_width
= row
->continuation_lines_width
;
2974 /* Initialize IT for stepping through current_buffer in window W
2975 starting in the line following ROW, i.e. starting at ROW->end.
2976 Value is zero if there are overlay strings with newlines at ROW's
2980 init_to_row_end (it
, w
, row
)
2983 struct glyph_row
*row
;
2987 if (init_from_display_pos (it
, w
, &row
->end
))
2989 if (row
->continued_p
)
2990 it
->continuation_lines_width
2991 = row
->continuation_lines_width
+ row
->pixel_width
;
3002 /***********************************************************************
3004 ***********************************************************************/
3006 /* Called when IT reaches IT->stop_charpos. Handle text property and
3007 overlay changes. Set IT->stop_charpos to the next position where
3014 enum prop_handled handled
;
3015 int handle_overlay_change_p
;
3019 it
->current
.dpvec_index
= -1;
3020 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3021 it
->ignore_overlay_strings_at_pos_p
= 0;
3023 /* Use face of preceding text for ellipsis (if invisible) */
3024 if (it
->selective_display_ellipsis_p
)
3025 it
->saved_face_id
= it
->face_id
;
3029 handled
= HANDLED_NORMALLY
;
3031 /* Call text property handlers. */
3032 for (p
= it_props
; p
->handler
; ++p
)
3034 handled
= p
->handler (it
);
3036 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3038 else if (handled
== HANDLED_RETURN
)
3040 /* We still want to show before and after strings from
3041 overlays even if the actual buffer text is replaced. */
3042 if (!handle_overlay_change_p
|| it
->sp
> 1)
3044 if (!get_overlay_strings_1 (it
, 0, 0))
3046 it
->ignore_overlay_strings_at_pos_p
= 1;
3047 it
->string_from_display_prop_p
= 0;
3048 handle_overlay_change_p
= 0;
3049 handled
= HANDLED_RECOMPUTE_PROPS
;
3052 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3053 handle_overlay_change_p
= 0;
3056 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3058 /* Don't check for overlay strings below when set to deliver
3059 characters from a display vector. */
3060 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3061 handle_overlay_change_p
= 0;
3063 /* Handle overlay changes. */
3064 if (handle_overlay_change_p
)
3065 handled
= handle_overlay_change (it
);
3067 /* Determine where to stop next. */
3068 if (handled
== HANDLED_NORMALLY
)
3069 compute_stop_pos (it
);
3072 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3076 /* Compute IT->stop_charpos from text property and overlay change
3077 information for IT's current position. */
3080 compute_stop_pos (it
)
3083 register INTERVAL iv
, next_iv
;
3084 Lisp_Object object
, limit
, position
;
3086 /* If nowhere else, stop at the end. */
3087 it
->stop_charpos
= it
->end_charpos
;
3089 if (STRINGP (it
->string
))
3091 /* Strings are usually short, so don't limit the search for
3093 object
= it
->string
;
3095 position
= make_number (IT_STRING_CHARPOS (*it
));
3101 /* If next overlay change is in front of the current stop pos
3102 (which is IT->end_charpos), stop there. Note: value of
3103 next_overlay_change is point-max if no overlay change
3105 charpos
= next_overlay_change (IT_CHARPOS (*it
));
3106 if (charpos
< it
->stop_charpos
)
3107 it
->stop_charpos
= charpos
;
3109 /* If showing the region, we have to stop at the region
3110 start or end because the face might change there. */
3111 if (it
->region_beg_charpos
> 0)
3113 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3114 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3115 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3116 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3119 /* Set up variables for computing the stop position from text
3120 property changes. */
3121 XSETBUFFER (object
, current_buffer
);
3122 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3123 position
= make_number (IT_CHARPOS (*it
));
3127 /* Get the interval containing IT's position. Value is a null
3128 interval if there isn't such an interval. */
3129 iv
= validate_interval_range (object
, &position
, &position
, 0);
3130 if (!NULL_INTERVAL_P (iv
))
3132 Lisp_Object values_here
[LAST_PROP_IDX
];
3135 /* Get properties here. */
3136 for (p
= it_props
; p
->handler
; ++p
)
3137 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3139 /* Look for an interval following iv that has different
3141 for (next_iv
= next_interval (iv
);
3142 (!NULL_INTERVAL_P (next_iv
)
3144 || XFASTINT (limit
) > next_iv
->position
));
3145 next_iv
= next_interval (next_iv
))
3147 for (p
= it_props
; p
->handler
; ++p
)
3149 Lisp_Object new_value
;
3151 new_value
= textget (next_iv
->plist
, *p
->name
);
3152 if (!EQ (values_here
[p
->idx
], new_value
))
3160 if (!NULL_INTERVAL_P (next_iv
))
3162 if (INTEGERP (limit
)
3163 && next_iv
->position
>= XFASTINT (limit
))
3164 /* No text property change up to limit. */
3165 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3167 /* Text properties change in next_iv. */
3168 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3172 xassert (STRINGP (it
->string
)
3173 || (it
->stop_charpos
>= BEGV
3174 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3178 /* Return the position of the next overlay change after POS in
3179 current_buffer. Value is point-max if no overlay change
3180 follows. This is like `next-overlay-change' but doesn't use
3184 next_overlay_change (pos
)
3189 Lisp_Object
*overlays
;
3192 /* Get all overlays at the given position. */
3193 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3195 /* If any of these overlays ends before endpos,
3196 use its ending point instead. */
3197 for (i
= 0; i
< noverlays
; ++i
)
3202 oend
= OVERLAY_END (overlays
[i
]);
3203 oendpos
= OVERLAY_POSITION (oend
);
3204 endpos
= min (endpos
, oendpos
);
3212 /***********************************************************************
3214 ***********************************************************************/
3216 /* Handle changes in the `fontified' property of the current buffer by
3217 calling hook functions from Qfontification_functions to fontify
3220 static enum prop_handled
3221 handle_fontified_prop (it
)
3224 Lisp_Object prop
, pos
;
3225 enum prop_handled handled
= HANDLED_NORMALLY
;
3227 if (!NILP (Vmemory_full
))
3230 /* Get the value of the `fontified' property at IT's current buffer
3231 position. (The `fontified' property doesn't have a special
3232 meaning in strings.) If the value is nil, call functions from
3233 Qfontification_functions. */
3234 if (!STRINGP (it
->string
)
3236 && !NILP (Vfontification_functions
)
3237 && !NILP (Vrun_hooks
)
3238 && (pos
= make_number (IT_CHARPOS (*it
)),
3239 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3240 /* Ignore the special cased nil value always present at EOB since
3241 no amount of fontifying will be able to change it. */
3242 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3244 int count
= SPECPDL_INDEX ();
3247 val
= Vfontification_functions
;
3248 specbind (Qfontification_functions
, Qnil
);
3250 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3251 safe_call1 (val
, pos
);
3254 Lisp_Object globals
, fn
;
3255 struct gcpro gcpro1
, gcpro2
;
3258 GCPRO2 (val
, globals
);
3260 for (; CONSP (val
); val
= XCDR (val
))
3266 /* A value of t indicates this hook has a local
3267 binding; it means to run the global binding too.
3268 In a global value, t should not occur. If it
3269 does, we must ignore it to avoid an endless
3271 for (globals
= Fdefault_value (Qfontification_functions
);
3273 globals
= XCDR (globals
))
3275 fn
= XCAR (globals
);
3277 safe_call1 (fn
, pos
);
3281 safe_call1 (fn
, pos
);
3287 unbind_to (count
, Qnil
);
3289 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3290 something. This avoids an endless loop if they failed to
3291 fontify the text for which reason ever. */
3292 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3293 handled
= HANDLED_RECOMPUTE_PROPS
;
3301 /***********************************************************************
3303 ***********************************************************************/
3305 /* Set up iterator IT from face properties at its current position.
3306 Called from handle_stop. */
3308 static enum prop_handled
3309 handle_face_prop (it
)
3312 int new_face_id
, next_stop
;
3314 if (!STRINGP (it
->string
))
3317 = face_at_buffer_position (it
->w
,
3319 it
->region_beg_charpos
,
3320 it
->region_end_charpos
,
3323 + TEXT_PROP_DISTANCE_LIMIT
),
3326 /* Is this a start of a run of characters with box face?
3327 Caveat: this can be called for a freshly initialized
3328 iterator; face_id is -1 in this case. We know that the new
3329 face will not change until limit, i.e. if the new face has a
3330 box, all characters up to limit will have one. But, as
3331 usual, we don't know whether limit is really the end. */
3332 if (new_face_id
!= it
->face_id
)
3334 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3336 /* If new face has a box but old face has not, this is
3337 the start of a run of characters with box, i.e. it has
3338 a shadow on the left side. The value of face_id of the
3339 iterator will be -1 if this is the initial call that gets
3340 the face. In this case, we have to look in front of IT's
3341 position and see whether there is a face != new_face_id. */
3342 it
->start_of_box_run_p
3343 = (new_face
->box
!= FACE_NO_BOX
3344 && (it
->face_id
>= 0
3345 || IT_CHARPOS (*it
) == BEG
3346 || new_face_id
!= face_before_it_pos (it
)));
3347 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3352 int base_face_id
, bufpos
;
3354 if (it
->current
.overlay_string_index
>= 0)
3355 bufpos
= IT_CHARPOS (*it
);
3359 /* For strings from a buffer, i.e. overlay strings or strings
3360 from a `display' property, use the face at IT's current
3361 buffer position as the base face to merge with, so that
3362 overlay strings appear in the same face as surrounding
3363 text, unless they specify their own faces. */
3364 base_face_id
= underlying_face_id (it
);
3366 new_face_id
= face_at_string_position (it
->w
,
3368 IT_STRING_CHARPOS (*it
),
3370 it
->region_beg_charpos
,
3371 it
->region_end_charpos
,
3375 #if 0 /* This shouldn't be neccessary. Let's check it. */
3376 /* If IT is used to display a mode line we would really like to
3377 use the mode line face instead of the frame's default face. */
3378 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3379 && new_face_id
== DEFAULT_FACE_ID
)
3380 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3383 /* Is this a start of a run of characters with box? Caveat:
3384 this can be called for a freshly allocated iterator; face_id
3385 is -1 is this case. We know that the new face will not
3386 change until the next check pos, i.e. if the new face has a
3387 box, all characters up to that position will have a
3388 box. But, as usual, we don't know whether that position
3389 is really the end. */
3390 if (new_face_id
!= it
->face_id
)
3392 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3393 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3395 /* If new face has a box but old face hasn't, this is the
3396 start of a run of characters with box, i.e. it has a
3397 shadow on the left side. */
3398 it
->start_of_box_run_p
3399 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3400 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3404 it
->face_id
= new_face_id
;
3405 return HANDLED_NORMALLY
;
3409 /* Return the ID of the face ``underlying'' IT's current position,
3410 which is in a string. If the iterator is associated with a
3411 buffer, return the face at IT's current buffer position.
3412 Otherwise, use the iterator's base_face_id. */
3415 underlying_face_id (it
)
3418 int face_id
= it
->base_face_id
, i
;
3420 xassert (STRINGP (it
->string
));
3422 for (i
= it
->sp
- 1; i
>= 0; --i
)
3423 if (NILP (it
->stack
[i
].string
))
3424 face_id
= it
->stack
[i
].face_id
;
3430 /* Compute the face one character before or after the current position
3431 of IT. BEFORE_P non-zero means get the face in front of IT's
3432 position. Value is the id of the face. */
3435 face_before_or_after_it_pos (it
, before_p
)
3440 int next_check_charpos
;
3441 struct text_pos pos
;
3443 xassert (it
->s
== NULL
);
3445 if (STRINGP (it
->string
))
3447 int bufpos
, base_face_id
;
3449 /* No face change past the end of the string (for the case
3450 we are padding with spaces). No face change before the
3452 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3453 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3456 /* Set pos to the position before or after IT's current position. */
3458 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3460 /* For composition, we must check the character after the
3462 pos
= (it
->what
== IT_COMPOSITION
3463 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3464 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3466 if (it
->current
.overlay_string_index
>= 0)
3467 bufpos
= IT_CHARPOS (*it
);
3471 base_face_id
= underlying_face_id (it
);
3473 /* Get the face for ASCII, or unibyte. */
3474 face_id
= face_at_string_position (it
->w
,
3478 it
->region_beg_charpos
,
3479 it
->region_end_charpos
,
3480 &next_check_charpos
,
3483 /* Correct the face for charsets different from ASCII. Do it
3484 for the multibyte case only. The face returned above is
3485 suitable for unibyte text if IT->string is unibyte. */
3486 if (STRING_MULTIBYTE (it
->string
))
3488 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3489 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3491 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3493 c
= string_char_and_length (p
, rest
, &len
);
3494 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3499 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3500 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3503 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3504 pos
= it
->current
.pos
;
3507 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3510 if (it
->what
== IT_COMPOSITION
)
3511 /* For composition, we must check the position after the
3513 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3515 INC_TEXT_POS (pos
, it
->multibyte_p
);
3518 /* Determine face for CHARSET_ASCII, or unibyte. */
3519 face_id
= face_at_buffer_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 current_buffer is unibyte. */
3529 if (it
->multibyte_p
)
3531 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3532 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3533 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3542 /***********************************************************************
3544 ***********************************************************************/
3546 /* Set up iterator IT from invisible properties at its current
3547 position. Called from handle_stop. */
3549 static enum prop_handled
3550 handle_invisible_prop (it
)
3553 enum prop_handled handled
= HANDLED_NORMALLY
;
3555 if (STRINGP (it
->string
))
3557 extern Lisp_Object Qinvisible
;
3558 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3560 /* Get the value of the invisible text property at the
3561 current position. Value will be nil if there is no such
3563 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3564 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3567 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3569 handled
= HANDLED_RECOMPUTE_PROPS
;
3571 /* Get the position at which the next change of the
3572 invisible text property can be found in IT->string.
3573 Value will be nil if the property value is the same for
3574 all the rest of IT->string. */
3575 XSETINT (limit
, SCHARS (it
->string
));
3576 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3579 /* Text at current position is invisible. The next
3580 change in the property is at position end_charpos.
3581 Move IT's current position to that position. */
3582 if (INTEGERP (end_charpos
)
3583 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3585 struct text_pos old
;
3586 old
= it
->current
.string_pos
;
3587 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3588 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3592 /* The rest of the string is invisible. If this is an
3593 overlay string, proceed with the next overlay string
3594 or whatever comes and return a character from there. */
3595 if (it
->current
.overlay_string_index
>= 0)
3597 next_overlay_string (it
);
3598 /* Don't check for overlay strings when we just
3599 finished processing them. */
3600 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3604 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3605 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3612 int invis_p
, newpos
, next_stop
, start_charpos
;
3613 Lisp_Object pos
, prop
, overlay
;
3615 /* First of all, is there invisible text at this position? */
3616 start_charpos
= IT_CHARPOS (*it
);
3617 pos
= make_number (IT_CHARPOS (*it
));
3618 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3620 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3622 /* If we are on invisible text, skip over it. */
3623 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3625 /* Record whether we have to display an ellipsis for the
3627 int display_ellipsis_p
= invis_p
== 2;
3629 handled
= HANDLED_RECOMPUTE_PROPS
;
3631 /* Loop skipping over invisible text. The loop is left at
3632 ZV or with IT on the first char being visible again. */
3635 /* Try to skip some invisible text. Return value is the
3636 position reached which can be equal to IT's position
3637 if there is nothing invisible here. This skips both
3638 over invisible text properties and overlays with
3639 invisible property. */
3640 newpos
= skip_invisible (IT_CHARPOS (*it
),
3641 &next_stop
, ZV
, it
->window
);
3643 /* If we skipped nothing at all we weren't at invisible
3644 text in the first place. If everything to the end of
3645 the buffer was skipped, end the loop. */
3646 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3650 /* We skipped some characters but not necessarily
3651 all there are. Check if we ended up on visible
3652 text. Fget_char_property returns the property of
3653 the char before the given position, i.e. if we
3654 get invis_p = 0, this means that the char at
3655 newpos is visible. */
3656 pos
= make_number (newpos
);
3657 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3658 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3661 /* If we ended up on invisible text, proceed to
3662 skip starting with next_stop. */
3664 IT_CHARPOS (*it
) = next_stop
;
3666 /* If there are adjacent invisible texts, don't lose the
3667 second one's ellipsis. */
3669 display_ellipsis_p
= 1;
3673 /* The position newpos is now either ZV or on visible text. */
3674 IT_CHARPOS (*it
) = newpos
;
3675 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3677 /* If there are before-strings at the start of invisible
3678 text, and the text is invisible because of a text
3679 property, arrange to show before-strings because 20.x did
3680 it that way. (If the text is invisible because of an
3681 overlay property instead of a text property, this is
3682 already handled in the overlay code.) */
3684 && get_overlay_strings (it
, start_charpos
))
3686 handled
= HANDLED_RECOMPUTE_PROPS
;
3687 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3689 else if (display_ellipsis_p
)
3691 /* Make sure that the glyphs of the ellipsis will get
3692 correct `charpos' values. If we would not update
3693 it->position here, the glyphs would belong to the
3694 last visible character _before_ the invisible
3695 text, which confuses `set_cursor_from_row'.
3697 We use the last invisible position instead of the
3698 first because this way the cursor is always drawn on
3699 the first "." of the ellipsis, whenever PT is inside
3700 the invisible text. Otherwise the cursor would be
3701 placed _after_ the ellipsis when the point is after the
3702 first invisible character. */
3703 if (!STRINGP (it
->object
))
3705 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3706 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3708 setup_for_ellipsis (it
, 0);
3717 /* Make iterator IT return `...' next.
3718 Replaces LEN characters from buffer. */
3721 setup_for_ellipsis (it
, len
)
3725 /* Use the display table definition for `...'. Invalid glyphs
3726 will be handled by the method returning elements from dpvec. */
3727 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3729 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3730 it
->dpvec
= v
->contents
;
3731 it
->dpend
= v
->contents
+ v
->size
;
3735 /* Default `...'. */
3736 it
->dpvec
= default_invis_vector
;
3737 it
->dpend
= default_invis_vector
+ 3;
3740 it
->dpvec_char_len
= len
;
3741 it
->current
.dpvec_index
= 0;
3742 it
->dpvec_face_id
= -1;
3744 /* Remember the current face id in case glyphs specify faces.
3745 IT's face is restored in set_iterator_to_next.
3746 saved_face_id was set to preceding char's face in handle_stop. */
3747 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3748 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3750 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3756 /***********************************************************************
3758 ***********************************************************************/
3760 /* Set up iterator IT from `display' property at its current position.
3761 Called from handle_stop.
3762 We return HANDLED_RETURN if some part of the display property
3763 overrides the display of the buffer text itself.
3764 Otherwise we return HANDLED_NORMALLY. */
3766 static enum prop_handled
3767 handle_display_prop (it
)
3770 Lisp_Object prop
, object
;
3771 struct text_pos
*position
;
3772 /* Nonzero if some property replaces the display of the text itself. */
3773 int display_replaced_p
= 0;
3775 if (STRINGP (it
->string
))
3777 object
= it
->string
;
3778 position
= &it
->current
.string_pos
;
3782 XSETWINDOW (object
, it
->w
);
3783 position
= &it
->current
.pos
;
3786 /* Reset those iterator values set from display property values. */
3787 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3788 it
->space_width
= Qnil
;
3789 it
->font_height
= Qnil
;
3792 /* We don't support recursive `display' properties, i.e. string
3793 values that have a string `display' property, that have a string
3794 `display' property etc. */
3795 if (!it
->string_from_display_prop_p
)
3796 it
->area
= TEXT_AREA
;
3798 prop
= Fget_char_property (make_number (position
->charpos
),
3801 return HANDLED_NORMALLY
;
3803 if (!STRINGP (it
->string
))
3804 object
= it
->w
->buffer
;
3807 /* Simple properties. */
3808 && !EQ (XCAR (prop
), Qimage
)
3809 && !EQ (XCAR (prop
), Qspace
)
3810 && !EQ (XCAR (prop
), Qwhen
)
3811 && !EQ (XCAR (prop
), Qslice
)
3812 && !EQ (XCAR (prop
), Qspace_width
)
3813 && !EQ (XCAR (prop
), Qheight
)
3814 && !EQ (XCAR (prop
), Qraise
)
3815 /* Marginal area specifications. */
3816 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3817 && !EQ (XCAR (prop
), Qleft_fringe
)
3818 && !EQ (XCAR (prop
), Qright_fringe
)
3819 && !NILP (XCAR (prop
)))
3821 for (; CONSP (prop
); prop
= XCDR (prop
))
3823 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3824 position
, display_replaced_p
))
3825 display_replaced_p
= 1;
3828 else if (VECTORP (prop
))
3831 for (i
= 0; i
< ASIZE (prop
); ++i
)
3832 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3833 position
, display_replaced_p
))
3834 display_replaced_p
= 1;
3838 int ret
= handle_single_display_spec (it
, prop
, object
, position
, 0);
3839 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3840 return HANDLED_RECOMPUTE_PROPS
;
3842 display_replaced_p
= 1;
3845 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3849 /* Value is the position of the end of the `display' property starting
3850 at START_POS in OBJECT. */
3852 static struct text_pos
3853 display_prop_end (it
, object
, start_pos
)
3856 struct text_pos start_pos
;
3859 struct text_pos end_pos
;
3861 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3862 Qdisplay
, object
, Qnil
);
3863 CHARPOS (end_pos
) = XFASTINT (end
);
3864 if (STRINGP (object
))
3865 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3867 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3873 /* Set up IT from a single `display' specification PROP. OBJECT
3874 is the object in which the `display' property was found. *POSITION
3875 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3876 means that we previously saw a display specification which already
3877 replaced text display with something else, for example an image;
3878 we ignore such properties after the first one has been processed.
3880 If PROP is a `space' or `image' specification, and in some other
3881 cases too, set *POSITION to the position where the `display'
3884 Value is non-zero if something was found which replaces the display
3885 of buffer or string text. Specifically, the value is -1 if that
3886 "something" is "nothing". */
3889 handle_single_display_spec (it
, spec
, object
, position
,
3890 display_replaced_before_p
)
3894 struct text_pos
*position
;
3895 int display_replaced_before_p
;
3898 Lisp_Object location
, value
;
3899 struct text_pos start_pos
, save_pos
;
3902 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3903 If the result is non-nil, use VALUE instead of SPEC. */
3905 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3914 if (!NILP (form
) && !EQ (form
, Qt
))
3916 int count
= SPECPDL_INDEX ();
3917 struct gcpro gcpro1
;
3919 /* Bind `object' to the object having the `display' property, a
3920 buffer or string. Bind `position' to the position in the
3921 object where the property was found, and `buffer-position'
3922 to the current position in the buffer. */
3923 specbind (Qobject
, object
);
3924 specbind (Qposition
, make_number (CHARPOS (*position
)));
3925 specbind (Qbuffer_position
,
3926 make_number (STRINGP (object
)
3927 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3929 form
= safe_eval (form
);
3931 unbind_to (count
, Qnil
);
3937 /* Handle `(height HEIGHT)' specifications. */
3939 && EQ (XCAR (spec
), Qheight
)
3940 && CONSP (XCDR (spec
)))
3942 if (!FRAME_WINDOW_P (it
->f
))
3945 it
->font_height
= XCAR (XCDR (spec
));
3946 if (!NILP (it
->font_height
))
3948 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3949 int new_height
= -1;
3951 if (CONSP (it
->font_height
)
3952 && (EQ (XCAR (it
->font_height
), Qplus
)
3953 || EQ (XCAR (it
->font_height
), Qminus
))
3954 && CONSP (XCDR (it
->font_height
))
3955 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3957 /* `(+ N)' or `(- N)' where N is an integer. */
3958 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3959 if (EQ (XCAR (it
->font_height
), Qplus
))
3961 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3963 else if (FUNCTIONP (it
->font_height
))
3965 /* Call function with current height as argument.
3966 Value is the new height. */
3968 height
= safe_call1 (it
->font_height
,
3969 face
->lface
[LFACE_HEIGHT_INDEX
]);
3970 if (NUMBERP (height
))
3971 new_height
= XFLOATINT (height
);
3973 else if (NUMBERP (it
->font_height
))
3975 /* Value is a multiple of the canonical char height. */
3978 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3979 new_height
= (XFLOATINT (it
->font_height
)
3980 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3984 /* Evaluate IT->font_height with `height' bound to the
3985 current specified height to get the new height. */
3986 int count
= SPECPDL_INDEX ();
3988 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3989 value
= safe_eval (it
->font_height
);
3990 unbind_to (count
, Qnil
);
3992 if (NUMBERP (value
))
3993 new_height
= XFLOATINT (value
);
3997 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4003 /* Handle `(space_width WIDTH)'. */
4005 && EQ (XCAR (spec
), Qspace_width
)
4006 && CONSP (XCDR (spec
)))
4008 if (!FRAME_WINDOW_P (it
->f
))
4011 value
= XCAR (XCDR (spec
));
4012 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4013 it
->space_width
= value
;
4018 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4020 && EQ (XCAR (spec
), Qslice
))
4024 if (!FRAME_WINDOW_P (it
->f
))
4027 if (tem
= XCDR (spec
), CONSP (tem
))
4029 it
->slice
.x
= XCAR (tem
);
4030 if (tem
= XCDR (tem
), CONSP (tem
))
4032 it
->slice
.y
= XCAR (tem
);
4033 if (tem
= XCDR (tem
), CONSP (tem
))
4035 it
->slice
.width
= XCAR (tem
);
4036 if (tem
= XCDR (tem
), CONSP (tem
))
4037 it
->slice
.height
= XCAR (tem
);
4045 /* Handle `(raise FACTOR)'. */
4047 && EQ (XCAR (spec
), Qraise
)
4048 && CONSP (XCDR (spec
)))
4050 if (!FRAME_WINDOW_P (it
->f
))
4053 #ifdef HAVE_WINDOW_SYSTEM
4054 value
= XCAR (XCDR (spec
));
4055 if (NUMBERP (value
))
4057 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4058 it
->voffset
= - (XFLOATINT (value
)
4059 * (FONT_HEIGHT (face
->font
)));
4061 #endif /* HAVE_WINDOW_SYSTEM */
4066 /* Don't handle the other kinds of display specifications
4067 inside a string that we got from a `display' property. */
4068 if (it
->string_from_display_prop_p
)
4071 /* Characters having this form of property are not displayed, so
4072 we have to find the end of the property. */
4073 start_pos
= *position
;
4074 *position
= display_prop_end (it
, object
, start_pos
);
4077 /* Stop the scan at that end position--we assume that all
4078 text properties change there. */
4079 it
->stop_charpos
= position
->charpos
;
4081 /* Handle `(left-fringe BITMAP [FACE])'
4082 and `(right-fringe BITMAP [FACE])'. */
4084 && (EQ (XCAR (spec
), Qleft_fringe
)
4085 || EQ (XCAR (spec
), Qright_fringe
))
4086 && CONSP (XCDR (spec
)))
4088 int face_id
= DEFAULT_FACE_ID
;
4091 if (!FRAME_WINDOW_P (it
->f
))
4092 /* If we return here, POSITION has been advanced
4093 across the text with this property. */
4096 #ifdef HAVE_WINDOW_SYSTEM
4097 value
= XCAR (XCDR (spec
));
4098 if (!SYMBOLP (value
)
4099 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4100 /* If we return here, POSITION has been advanced
4101 across the text with this property. */
4104 if (CONSP (XCDR (XCDR (spec
))))
4106 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4107 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4108 'A', FRINGE_FACE_ID
, 0);
4113 /* Save current settings of IT so that we can restore them
4114 when we are finished with the glyph property value. */
4116 save_pos
= it
->position
;
4117 it
->position
= *position
;
4119 it
->position
= save_pos
;
4121 it
->area
= TEXT_AREA
;
4122 it
->what
= IT_IMAGE
;
4123 it
->image_id
= -1; /* no image */
4124 it
->position
= start_pos
;
4125 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4126 it
->method
= GET_FROM_IMAGE
;
4127 it
->face_id
= face_id
;
4129 /* Say that we haven't consumed the characters with
4130 `display' property yet. The call to pop_it in
4131 set_iterator_to_next will clean this up. */
4132 *position
= start_pos
;
4134 if (EQ (XCAR (spec
), Qleft_fringe
))
4136 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4137 it
->left_user_fringe_face_id
= face_id
;
4141 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4142 it
->right_user_fringe_face_id
= face_id
;
4144 #endif /* HAVE_WINDOW_SYSTEM */
4148 /* Prepare to handle `((margin left-margin) ...)',
4149 `((margin right-margin) ...)' and `((margin nil) ...)'
4150 prefixes for display specifications. */
4151 location
= Qunbound
;
4152 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4156 value
= XCDR (spec
);
4158 value
= XCAR (value
);
4161 if (EQ (XCAR (tem
), Qmargin
)
4162 && (tem
= XCDR (tem
),
4163 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4165 || EQ (tem
, Qleft_margin
)
4166 || EQ (tem
, Qright_margin
))))
4170 if (EQ (location
, Qunbound
))
4176 /* After this point, VALUE is the property after any
4177 margin prefix has been stripped. It must be a string,
4178 an image specification, or `(space ...)'.
4180 LOCATION specifies where to display: `left-margin',
4181 `right-margin' or nil. */
4183 valid_p
= (STRINGP (value
)
4184 #ifdef HAVE_WINDOW_SYSTEM
4185 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4186 #endif /* not HAVE_WINDOW_SYSTEM */
4187 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4189 if (valid_p
&& !display_replaced_before_p
)
4191 /* Save current settings of IT so that we can restore them
4192 when we are finished with the glyph property value. */
4193 save_pos
= it
->position
;
4194 it
->position
= *position
;
4196 it
->position
= save_pos
;
4198 if (NILP (location
))
4199 it
->area
= TEXT_AREA
;
4200 else if (EQ (location
, Qleft_margin
))
4201 it
->area
= LEFT_MARGIN_AREA
;
4203 it
->area
= RIGHT_MARGIN_AREA
;
4205 if (STRINGP (value
))
4207 if (SCHARS (value
) == 0)
4210 return -1; /* Replaced by "", i.e. nothing. */
4213 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4214 it
->current
.overlay_string_index
= -1;
4215 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4216 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4217 it
->method
= GET_FROM_STRING
;
4218 it
->stop_charpos
= 0;
4219 it
->string_from_display_prop_p
= 1;
4220 /* Say that we haven't consumed the characters with
4221 `display' property yet. The call to pop_it in
4222 set_iterator_to_next will clean this up. */
4223 *position
= start_pos
;
4225 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4227 it
->method
= GET_FROM_STRETCH
;
4229 *position
= it
->position
= start_pos
;
4231 #ifdef HAVE_WINDOW_SYSTEM
4234 it
->what
= IT_IMAGE
;
4235 it
->image_id
= lookup_image (it
->f
, value
);
4236 it
->position
= start_pos
;
4237 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4238 it
->method
= GET_FROM_IMAGE
;
4240 /* Say that we haven't consumed the characters with
4241 `display' property yet. The call to pop_it in
4242 set_iterator_to_next will clean this up. */
4243 *position
= start_pos
;
4245 #endif /* HAVE_WINDOW_SYSTEM */
4250 /* Invalid property or property not supported. Restore
4251 POSITION to what it was before. */
4252 *position
= start_pos
;
4257 /* Check if SPEC is a display sub-property value whose text should be
4258 treated as intangible. */
4261 single_display_spec_intangible_p (prop
)
4264 /* Skip over `when FORM'. */
4265 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4279 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4280 we don't need to treat text as intangible. */
4281 if (EQ (XCAR (prop
), Qmargin
))
4289 || EQ (XCAR (prop
), Qleft_margin
)
4290 || EQ (XCAR (prop
), Qright_margin
))
4294 return (CONSP (prop
)
4295 && (EQ (XCAR (prop
), Qimage
)
4296 || EQ (XCAR (prop
), Qspace
)));
4300 /* Check if PROP is a display property value whose text should be
4301 treated as intangible. */
4304 display_prop_intangible_p (prop
)
4308 && CONSP (XCAR (prop
))
4309 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4311 /* A list of sub-properties. */
4312 while (CONSP (prop
))
4314 if (single_display_spec_intangible_p (XCAR (prop
)))
4319 else if (VECTORP (prop
))
4321 /* A vector of sub-properties. */
4323 for (i
= 0; i
< ASIZE (prop
); ++i
)
4324 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4328 return single_display_spec_intangible_p (prop
);
4334 /* Return 1 if PROP is a display sub-property value containing STRING. */
4337 single_display_spec_string_p (prop
, string
)
4338 Lisp_Object prop
, string
;
4340 if (EQ (string
, prop
))
4343 /* Skip over `when FORM'. */
4344 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4353 /* Skip over `margin LOCATION'. */
4354 if (EQ (XCAR (prop
), Qmargin
))
4365 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4369 /* Return 1 if STRING appears in the `display' property PROP. */
4372 display_prop_string_p (prop
, string
)
4373 Lisp_Object prop
, string
;
4376 && CONSP (XCAR (prop
))
4377 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4379 /* A list of sub-properties. */
4380 while (CONSP (prop
))
4382 if (single_display_spec_string_p (XCAR (prop
), string
))
4387 else if (VECTORP (prop
))
4389 /* A vector of sub-properties. */
4391 for (i
= 0; i
< ASIZE (prop
); ++i
)
4392 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4396 return single_display_spec_string_p (prop
, string
);
4402 /* Determine from which buffer position in W's buffer STRING comes
4403 from. AROUND_CHARPOS is an approximate position where it could
4404 be from. Value is the buffer position or 0 if it couldn't be
4407 W's buffer must be current.
4409 This function is necessary because we don't record buffer positions
4410 in glyphs generated from strings (to keep struct glyph small).
4411 This function may only use code that doesn't eval because it is
4412 called asynchronously from note_mouse_highlight. */
4415 string_buffer_position (w
, string
, around_charpos
)
4420 Lisp_Object limit
, prop
, pos
;
4421 const int MAX_DISTANCE
= 1000;
4424 pos
= make_number (around_charpos
);
4425 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4426 while (!found
&& !EQ (pos
, limit
))
4428 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4429 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4432 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4437 pos
= make_number (around_charpos
);
4438 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4439 while (!found
&& !EQ (pos
, limit
))
4441 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4442 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4445 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4450 return found
? XINT (pos
) : 0;
4455 /***********************************************************************
4456 `composition' property
4457 ***********************************************************************/
4459 /* Set up iterator IT from `composition' property at its current
4460 position. Called from handle_stop. */
4462 static enum prop_handled
4463 handle_composition_prop (it
)
4466 Lisp_Object prop
, string
;
4467 int pos
, pos_byte
, end
;
4468 enum prop_handled handled
= HANDLED_NORMALLY
;
4470 if (STRINGP (it
->string
))
4472 pos
= IT_STRING_CHARPOS (*it
);
4473 pos_byte
= IT_STRING_BYTEPOS (*it
);
4474 string
= it
->string
;
4478 pos
= IT_CHARPOS (*it
);
4479 pos_byte
= IT_BYTEPOS (*it
);
4483 /* If there's a valid composition and point is not inside of the
4484 composition (in the case that the composition is from the current
4485 buffer), draw a glyph composed from the composition components. */
4486 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
4487 && COMPOSITION_VALID_P (pos
, end
, prop
)
4488 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
4490 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4494 struct composition
*cmp
= composition_table
[id
];
4496 if (cmp
->glyph_len
== 0)
4499 if (STRINGP (it
->string
))
4501 IT_STRING_CHARPOS (*it
) = end
;
4502 IT_STRING_BYTEPOS (*it
) = string_char_to_byte (it
->string
,
4507 IT_CHARPOS (*it
) = end
;
4508 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (end
);
4510 return HANDLED_RECOMPUTE_PROPS
;
4513 it
->stop_charpos
= end
;
4516 it
->method
= GET_FROM_COMPOSITION
;
4518 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4519 /* For a terminal, draw only the first character of the
4521 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4522 it
->len
= (STRINGP (it
->string
)
4523 ? string_char_to_byte (it
->string
, end
)
4524 : CHAR_TO_BYTE (end
)) - pos_byte
;
4525 handled
= HANDLED_RETURN
;
4534 /***********************************************************************
4536 ***********************************************************************/
4538 /* The following structure is used to record overlay strings for
4539 later sorting in load_overlay_strings. */
4541 struct overlay_entry
4543 Lisp_Object overlay
;
4550 /* Set up iterator IT from overlay strings at its current position.
4551 Called from handle_stop. */
4553 static enum prop_handled
4554 handle_overlay_change (it
)
4557 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4558 return HANDLED_RECOMPUTE_PROPS
;
4560 return HANDLED_NORMALLY
;
4564 /* Set up the next overlay string for delivery by IT, if there is an
4565 overlay string to deliver. Called by set_iterator_to_next when the
4566 end of the current overlay string is reached. If there are more
4567 overlay strings to display, IT->string and
4568 IT->current.overlay_string_index are set appropriately here.
4569 Otherwise IT->string is set to nil. */
4572 next_overlay_string (it
)
4575 ++it
->current
.overlay_string_index
;
4576 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4578 /* No more overlay strings. Restore IT's settings to what
4579 they were before overlay strings were processed, and
4580 continue to deliver from current_buffer. */
4581 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4585 || it
->method
== GET_FROM_COMPOSITION
4586 || (NILP (it
->string
)
4587 && it
->method
== GET_FROM_BUFFER
4588 && it
->stop_charpos
>= BEGV
4589 && it
->stop_charpos
<= it
->end_charpos
));
4590 it
->current
.overlay_string_index
= -1;
4591 it
->n_overlay_strings
= 0;
4593 /* If we're at the end of the buffer, record that we have
4594 processed the overlay strings there already, so that
4595 next_element_from_buffer doesn't try it again. */
4596 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4597 it
->overlay_strings_at_end_processed_p
= 1;
4599 /* If we have to display `...' for invisible text, set
4600 the iterator up for that. */
4601 if (display_ellipsis_p
)
4602 setup_for_ellipsis (it
, 0);
4606 /* There are more overlay strings to process. If
4607 IT->current.overlay_string_index has advanced to a position
4608 where we must load IT->overlay_strings with more strings, do
4610 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4612 if (it
->current
.overlay_string_index
&& i
== 0)
4613 load_overlay_strings (it
, 0);
4615 /* Initialize IT to deliver display elements from the overlay
4617 it
->string
= it
->overlay_strings
[i
];
4618 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4619 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4620 it
->method
= GET_FROM_STRING
;
4621 it
->stop_charpos
= 0;
4628 /* Compare two overlay_entry structures E1 and E2. Used as a
4629 comparison function for qsort in load_overlay_strings. Overlay
4630 strings for the same position are sorted so that
4632 1. All after-strings come in front of before-strings, except
4633 when they come from the same overlay.
4635 2. Within after-strings, strings are sorted so that overlay strings
4636 from overlays with higher priorities come first.
4638 2. Within before-strings, strings are sorted so that overlay
4639 strings from overlays with higher priorities come last.
4641 Value is analogous to strcmp. */
4645 compare_overlay_entries (e1
, e2
)
4648 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4649 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4652 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4654 /* Let after-strings appear in front of before-strings if
4655 they come from different overlays. */
4656 if (EQ (entry1
->overlay
, entry2
->overlay
))
4657 result
= entry1
->after_string_p
? 1 : -1;
4659 result
= entry1
->after_string_p
? -1 : 1;
4661 else if (entry1
->after_string_p
)
4662 /* After-strings sorted in order of decreasing priority. */
4663 result
= entry2
->priority
- entry1
->priority
;
4665 /* Before-strings sorted in order of increasing priority. */
4666 result
= entry1
->priority
- entry2
->priority
;
4672 /* Load the vector IT->overlay_strings with overlay strings from IT's
4673 current buffer position, or from CHARPOS if that is > 0. Set
4674 IT->n_overlays to the total number of overlay strings found.
4676 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4677 a time. On entry into load_overlay_strings,
4678 IT->current.overlay_string_index gives the number of overlay
4679 strings that have already been loaded by previous calls to this
4682 IT->add_overlay_start contains an additional overlay start
4683 position to consider for taking overlay strings from, if non-zero.
4684 This position comes into play when the overlay has an `invisible'
4685 property, and both before and after-strings. When we've skipped to
4686 the end of the overlay, because of its `invisible' property, we
4687 nevertheless want its before-string to appear.
4688 IT->add_overlay_start will contain the overlay start position
4691 Overlay strings are sorted so that after-string strings come in
4692 front of before-string strings. Within before and after-strings,
4693 strings are sorted by overlay priority. See also function
4694 compare_overlay_entries. */
4697 load_overlay_strings (it
, charpos
)
4701 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4702 Lisp_Object overlay
, window
, str
, invisible
;
4703 struct Lisp_Overlay
*ov
;
4706 int n
= 0, i
, j
, invis_p
;
4707 struct overlay_entry
*entries
4708 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4711 charpos
= IT_CHARPOS (*it
);
4713 /* Append the overlay string STRING of overlay OVERLAY to vector
4714 `entries' which has size `size' and currently contains `n'
4715 elements. AFTER_P non-zero means STRING is an after-string of
4717 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4720 Lisp_Object priority; \
4724 int new_size = 2 * size; \
4725 struct overlay_entry *old = entries; \
4727 (struct overlay_entry *) alloca (new_size \
4728 * sizeof *entries); \
4729 bcopy (old, entries, size * sizeof *entries); \
4733 entries[n].string = (STRING); \
4734 entries[n].overlay = (OVERLAY); \
4735 priority = Foverlay_get ((OVERLAY), Qpriority); \
4736 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4737 entries[n].after_string_p = (AFTER_P); \
4742 /* Process overlay before the overlay center. */
4743 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4745 XSETMISC (overlay
, ov
);
4746 xassert (OVERLAYP (overlay
));
4747 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4748 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4753 /* Skip this overlay if it doesn't start or end at IT's current
4755 if (end
!= charpos
&& start
!= charpos
)
4758 /* Skip this overlay if it doesn't apply to IT->w. */
4759 window
= Foverlay_get (overlay
, Qwindow
);
4760 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4763 /* If the text ``under'' the overlay is invisible, both before-
4764 and after-strings from this overlay are visible; start and
4765 end position are indistinguishable. */
4766 invisible
= Foverlay_get (overlay
, Qinvisible
);
4767 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4769 /* If overlay has a non-empty before-string, record it. */
4770 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4771 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4773 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4775 /* If overlay has a non-empty after-string, record it. */
4776 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4777 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4779 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4782 /* Process overlays after the overlay center. */
4783 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4785 XSETMISC (overlay
, ov
);
4786 xassert (OVERLAYP (overlay
));
4787 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4788 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4790 if (start
> charpos
)
4793 /* Skip this overlay if it doesn't start or end at IT's current
4795 if (end
!= charpos
&& start
!= charpos
)
4798 /* Skip this overlay if it doesn't apply to IT->w. */
4799 window
= Foverlay_get (overlay
, Qwindow
);
4800 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4803 /* If the text ``under'' the overlay is invisible, it has a zero
4804 dimension, and both before- and after-strings apply. */
4805 invisible
= Foverlay_get (overlay
, Qinvisible
);
4806 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4808 /* If overlay has a non-empty before-string, record it. */
4809 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4810 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4812 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4814 /* If overlay has a non-empty after-string, record it. */
4815 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4816 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4818 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4821 #undef RECORD_OVERLAY_STRING
4825 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4827 /* Record the total number of strings to process. */
4828 it
->n_overlay_strings
= n
;
4830 /* IT->current.overlay_string_index is the number of overlay strings
4831 that have already been consumed by IT. Copy some of the
4832 remaining overlay strings to IT->overlay_strings. */
4834 j
= it
->current
.overlay_string_index
;
4835 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4836 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4842 /* Get the first chunk of overlay strings at IT's current buffer
4843 position, or at CHARPOS if that is > 0. Value is non-zero if at
4844 least one overlay string was found. */
4847 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
4851 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4852 process. This fills IT->overlay_strings with strings, and sets
4853 IT->n_overlay_strings to the total number of strings to process.
4854 IT->pos.overlay_string_index has to be set temporarily to zero
4855 because load_overlay_strings needs this; it must be set to -1
4856 when no overlay strings are found because a zero value would
4857 indicate a position in the first overlay string. */
4858 it
->current
.overlay_string_index
= 0;
4859 load_overlay_strings (it
, charpos
);
4861 /* If we found overlay strings, set up IT to deliver display
4862 elements from the first one. Otherwise set up IT to deliver
4863 from current_buffer. */
4864 if (it
->n_overlay_strings
)
4866 /* Make sure we know settings in current_buffer, so that we can
4867 restore meaningful values when we're done with the overlay
4870 compute_stop_pos (it
);
4871 xassert (it
->face_id
>= 0);
4873 /* Save IT's settings. They are restored after all overlay
4874 strings have been processed. */
4875 xassert (!compute_stop_p
|| it
->sp
== 0);
4878 /* Set up IT to deliver display elements from the first overlay
4880 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4881 it
->string
= it
->overlay_strings
[0];
4882 it
->stop_charpos
= 0;
4883 xassert (STRINGP (it
->string
));
4884 it
->end_charpos
= SCHARS (it
->string
);
4885 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4886 it
->method
= GET_FROM_STRING
;
4890 it
->current
.overlay_string_index
= -1;
4895 get_overlay_strings (it
, charpos
)
4900 it
->method
= GET_FROM_BUFFER
;
4902 (void) get_overlay_strings_1 (it
, charpos
, 1);
4906 /* Value is non-zero if we found at least one overlay string. */
4907 return STRINGP (it
->string
);
4912 /***********************************************************************
4913 Saving and restoring state
4914 ***********************************************************************/
4916 /* Save current settings of IT on IT->stack. Called, for example,
4917 before setting up IT for an overlay string, to be able to restore
4918 IT's settings to what they were after the overlay string has been
4925 struct iterator_stack_entry
*p
;
4927 xassert (it
->sp
< IT_STACK_SIZE
);
4928 p
= it
->stack
+ it
->sp
;
4930 p
->stop_charpos
= it
->stop_charpos
;
4931 xassert (it
->face_id
>= 0);
4932 p
->face_id
= it
->face_id
;
4933 p
->string
= it
->string
;
4934 p
->method
= it
->method
;
4937 case GET_FROM_IMAGE
:
4938 p
->u
.image
.object
= it
->object
;
4939 p
->u
.image
.image_id
= it
->image_id
;
4940 p
->u
.image
.slice
= it
->slice
;
4942 case GET_FROM_COMPOSITION
:
4943 p
->u
.comp
.object
= it
->object
;
4944 p
->u
.comp
.c
= it
->c
;
4945 p
->u
.comp
.len
= it
->len
;
4946 p
->u
.comp
.cmp_id
= it
->cmp_id
;
4947 p
->u
.comp
.cmp_len
= it
->cmp_len
;
4949 case GET_FROM_STRETCH
:
4950 p
->u
.stretch
.object
= it
->object
;
4953 p
->position
= it
->position
;
4954 p
->current
= it
->current
;
4955 p
->end_charpos
= it
->end_charpos
;
4956 p
->string_nchars
= it
->string_nchars
;
4958 p
->multibyte_p
= it
->multibyte_p
;
4959 p
->space_width
= it
->space_width
;
4960 p
->font_height
= it
->font_height
;
4961 p
->voffset
= it
->voffset
;
4962 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4963 p
->display_ellipsis_p
= 0;
4968 /* Restore IT's settings from IT->stack. Called, for example, when no
4969 more overlay strings must be processed, and we return to delivering
4970 display elements from a buffer, or when the end of a string from a
4971 `display' property is reached and we return to delivering display
4972 elements from an overlay string, or from a buffer. */
4978 struct iterator_stack_entry
*p
;
4980 xassert (it
->sp
> 0);
4982 p
= it
->stack
+ it
->sp
;
4983 it
->stop_charpos
= p
->stop_charpos
;
4984 it
->face_id
= p
->face_id
;
4985 it
->current
= p
->current
;
4986 it
->position
= p
->position
;
4987 it
->string
= p
->string
;
4988 if (NILP (it
->string
))
4989 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4990 it
->method
= p
->method
;
4993 case GET_FROM_IMAGE
:
4994 it
->image_id
= p
->u
.image
.image_id
;
4995 it
->object
= p
->u
.image
.object
;
4996 it
->slice
= p
->u
.image
.slice
;
4998 case GET_FROM_COMPOSITION
:
4999 it
->object
= p
->u
.comp
.object
;
5000 it
->c
= p
->u
.comp
.c
;
5001 it
->len
= p
->u
.comp
.len
;
5002 it
->cmp_id
= p
->u
.comp
.cmp_id
;
5003 it
->cmp_len
= p
->u
.comp
.cmp_len
;
5005 case GET_FROM_STRETCH
:
5006 it
->object
= p
->u
.comp
.object
;
5008 case GET_FROM_BUFFER
:
5009 it
->object
= it
->w
->buffer
;
5011 case GET_FROM_STRING
:
5012 it
->object
= it
->string
;
5015 it
->end_charpos
= p
->end_charpos
;
5016 it
->string_nchars
= p
->string_nchars
;
5018 it
->multibyte_p
= p
->multibyte_p
;
5019 it
->space_width
= p
->space_width
;
5020 it
->font_height
= p
->font_height
;
5021 it
->voffset
= p
->voffset
;
5022 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5027 /***********************************************************************
5029 ***********************************************************************/
5031 /* Set IT's current position to the previous line start. */
5034 back_to_previous_line_start (it
)
5037 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5038 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5042 /* Move IT to the next line start.
5044 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5045 we skipped over part of the text (as opposed to moving the iterator
5046 continuously over the text). Otherwise, don't change the value
5049 Newlines may come from buffer text, overlay strings, or strings
5050 displayed via the `display' property. That's the reason we can't
5051 simply use find_next_newline_no_quit.
5053 Note that this function may not skip over invisible text that is so
5054 because of text properties and immediately follows a newline. If
5055 it would, function reseat_at_next_visible_line_start, when called
5056 from set_iterator_to_next, would effectively make invisible
5057 characters following a newline part of the wrong glyph row, which
5058 leads to wrong cursor motion. */
5061 forward_to_next_line_start (it
, skipped_p
)
5065 int old_selective
, newline_found_p
, n
;
5066 const int MAX_NEWLINE_DISTANCE
= 500;
5068 /* If already on a newline, just consume it to avoid unintended
5069 skipping over invisible text below. */
5070 if (it
->what
== IT_CHARACTER
5072 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5074 set_iterator_to_next (it
, 0);
5079 /* Don't handle selective display in the following. It's (a)
5080 unnecessary because it's done by the caller, and (b) leads to an
5081 infinite recursion because next_element_from_ellipsis indirectly
5082 calls this function. */
5083 old_selective
= it
->selective
;
5086 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5087 from buffer text. */
5088 for (n
= newline_found_p
= 0;
5089 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5090 n
+= STRINGP (it
->string
) ? 0 : 1)
5092 if (!get_next_display_element (it
))
5094 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5095 set_iterator_to_next (it
, 0);
5098 /* If we didn't find a newline near enough, see if we can use a
5100 if (!newline_found_p
)
5102 int start
= IT_CHARPOS (*it
);
5103 int limit
= find_next_newline_no_quit (start
, 1);
5106 xassert (!STRINGP (it
->string
));
5108 /* If there isn't any `display' property in sight, and no
5109 overlays, we can just use the position of the newline in
5111 if (it
->stop_charpos
>= limit
5112 || ((pos
= Fnext_single_property_change (make_number (start
),
5114 Qnil
, make_number (limit
)),
5116 && next_overlay_change (start
) == ZV
))
5118 IT_CHARPOS (*it
) = limit
;
5119 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5120 *skipped_p
= newline_found_p
= 1;
5124 while (get_next_display_element (it
)
5125 && !newline_found_p
)
5127 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5128 set_iterator_to_next (it
, 0);
5133 it
->selective
= old_selective
;
5134 return newline_found_p
;
5138 /* Set IT's current position to the previous visible line start. Skip
5139 invisible text that is so either due to text properties or due to
5140 selective display. Caution: this does not change IT->current_x and
5144 back_to_previous_visible_line_start (it
)
5147 while (IT_CHARPOS (*it
) > BEGV
)
5149 back_to_previous_line_start (it
);
5151 if (IT_CHARPOS (*it
) <= BEGV
)
5154 /* If selective > 0, then lines indented more than that values
5156 if (it
->selective
> 0
5157 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5158 (double) it
->selective
)) /* iftc */
5161 /* Check the newline before point for invisibility. */
5164 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5165 Qinvisible
, it
->window
);
5166 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5170 if (IT_CHARPOS (*it
) <= BEGV
)
5177 Lisp_Object val
, overlay
;
5179 /* If newline is part of a composition, continue from start of composition */
5180 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5181 && beg
< IT_CHARPOS (*it
))
5184 /* If newline is replaced by a display property, find start of overlay
5185 or interval and continue search from that point. */
5187 pos
= --IT_CHARPOS (it2
);
5190 if (handle_display_prop (&it2
) == HANDLED_RETURN
5191 && !NILP (val
= get_char_property_and_overlay
5192 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5193 && (OVERLAYP (overlay
)
5194 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5195 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5198 /* Newline is not replaced by anything -- so we are done. */
5204 IT_CHARPOS (*it
) = beg
;
5205 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5209 it
->continuation_lines_width
= 0;
5211 xassert (IT_CHARPOS (*it
) >= BEGV
);
5212 xassert (IT_CHARPOS (*it
) == BEGV
5213 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5218 /* Reseat iterator IT at the previous visible line start. Skip
5219 invisible text that is so either due to text properties or due to
5220 selective display. At the end, update IT's overlay information,
5221 face information etc. */
5224 reseat_at_previous_visible_line_start (it
)
5227 back_to_previous_visible_line_start (it
);
5228 reseat (it
, it
->current
.pos
, 1);
5233 /* Reseat iterator IT on the next visible line start in the current
5234 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5235 preceding the line start. Skip over invisible text that is so
5236 because of selective display. Compute faces, overlays etc at the
5237 new position. Note that this function does not skip over text that
5238 is invisible because of text properties. */
5241 reseat_at_next_visible_line_start (it
, on_newline_p
)
5245 int newline_found_p
, skipped_p
= 0;
5247 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5249 /* Skip over lines that are invisible because they are indented
5250 more than the value of IT->selective. */
5251 if (it
->selective
> 0)
5252 while (IT_CHARPOS (*it
) < ZV
5253 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5254 (double) it
->selective
)) /* iftc */
5256 xassert (IT_BYTEPOS (*it
) == BEGV
5257 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5258 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5261 /* Position on the newline if that's what's requested. */
5262 if (on_newline_p
&& newline_found_p
)
5264 if (STRINGP (it
->string
))
5266 if (IT_STRING_CHARPOS (*it
) > 0)
5268 --IT_STRING_CHARPOS (*it
);
5269 --IT_STRING_BYTEPOS (*it
);
5272 else if (IT_CHARPOS (*it
) > BEGV
)
5276 reseat (it
, it
->current
.pos
, 0);
5280 reseat (it
, it
->current
.pos
, 0);
5287 /***********************************************************************
5288 Changing an iterator's position
5289 ***********************************************************************/
5291 /* Change IT's current position to POS in current_buffer. If FORCE_P
5292 is non-zero, always check for text properties at the new position.
5293 Otherwise, text properties are only looked up if POS >=
5294 IT->check_charpos of a property. */
5297 reseat (it
, pos
, force_p
)
5299 struct text_pos pos
;
5302 int original_pos
= IT_CHARPOS (*it
);
5304 reseat_1 (it
, pos
, 0);
5306 /* Determine where to check text properties. Avoid doing it
5307 where possible because text property lookup is very expensive. */
5309 || CHARPOS (pos
) > it
->stop_charpos
5310 || CHARPOS (pos
) < original_pos
)
5317 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5318 IT->stop_pos to POS, also. */
5321 reseat_1 (it
, pos
, set_stop_p
)
5323 struct text_pos pos
;
5326 /* Don't call this function when scanning a C string. */
5327 xassert (it
->s
== NULL
);
5329 /* POS must be a reasonable value. */
5330 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5332 it
->current
.pos
= it
->position
= pos
;
5333 it
->end_charpos
= ZV
;
5335 it
->current
.dpvec_index
= -1;
5336 it
->current
.overlay_string_index
= -1;
5337 IT_STRING_CHARPOS (*it
) = -1;
5338 IT_STRING_BYTEPOS (*it
) = -1;
5340 it
->method
= GET_FROM_BUFFER
;
5341 it
->object
= it
->w
->buffer
;
5342 it
->area
= TEXT_AREA
;
5343 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5345 it
->string_from_display_prop_p
= 0;
5346 it
->face_before_selective_p
= 0;
5349 it
->stop_charpos
= CHARPOS (pos
);
5353 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5354 If S is non-null, it is a C string to iterate over. Otherwise,
5355 STRING gives a Lisp string to iterate over.
5357 If PRECISION > 0, don't return more then PRECISION number of
5358 characters from the string.
5360 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5361 characters have been returned. FIELD_WIDTH < 0 means an infinite
5364 MULTIBYTE = 0 means disable processing of multibyte characters,
5365 MULTIBYTE > 0 means enable it,
5366 MULTIBYTE < 0 means use IT->multibyte_p.
5368 IT must be initialized via a prior call to init_iterator before
5369 calling this function. */
5372 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5377 int precision
, field_width
, multibyte
;
5379 /* No region in strings. */
5380 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5382 /* No text property checks performed by default, but see below. */
5383 it
->stop_charpos
= -1;
5385 /* Set iterator position and end position. */
5386 bzero (&it
->current
, sizeof it
->current
);
5387 it
->current
.overlay_string_index
= -1;
5388 it
->current
.dpvec_index
= -1;
5389 xassert (charpos
>= 0);
5391 /* If STRING is specified, use its multibyteness, otherwise use the
5392 setting of MULTIBYTE, if specified. */
5394 it
->multibyte_p
= multibyte
> 0;
5398 xassert (STRINGP (string
));
5399 it
->string
= string
;
5401 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5402 it
->method
= GET_FROM_STRING
;
5403 it
->current
.string_pos
= string_pos (charpos
, string
);
5410 /* Note that we use IT->current.pos, not it->current.string_pos,
5411 for displaying C strings. */
5412 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5413 if (it
->multibyte_p
)
5415 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5416 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5420 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5421 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5424 it
->method
= GET_FROM_C_STRING
;
5427 /* PRECISION > 0 means don't return more than PRECISION characters
5429 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5430 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5432 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5433 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5434 FIELD_WIDTH < 0 means infinite field width. This is useful for
5435 padding with `-' at the end of a mode line. */
5436 if (field_width
< 0)
5437 field_width
= INFINITY
;
5438 if (field_width
> it
->end_charpos
- charpos
)
5439 it
->end_charpos
= charpos
+ field_width
;
5441 /* Use the standard display table for displaying strings. */
5442 if (DISP_TABLE_P (Vstandard_display_table
))
5443 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5445 it
->stop_charpos
= charpos
;
5451 /***********************************************************************
5453 ***********************************************************************/
5455 /* Map enum it_method value to corresponding next_element_from_* function. */
5457 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5459 next_element_from_buffer
,
5460 next_element_from_display_vector
,
5461 next_element_from_composition
,
5462 next_element_from_string
,
5463 next_element_from_c_string
,
5464 next_element_from_image
,
5465 next_element_from_stretch
5469 /* Load IT's display element fields with information about the next
5470 display element from the current position of IT. Value is zero if
5471 end of buffer (or C string) is reached. */
5473 static struct frame
*last_escape_glyph_frame
= NULL
;
5474 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5475 static int last_escape_glyph_merged_face_id
= 0;
5478 get_next_display_element (it
)
5481 /* Non-zero means that we found a display element. Zero means that
5482 we hit the end of what we iterate over. Performance note: the
5483 function pointer `method' used here turns out to be faster than
5484 using a sequence of if-statements. */
5488 success_p
= (*get_next_element
[it
->method
]) (it
);
5490 if (it
->what
== IT_CHARACTER
)
5492 /* Map via display table or translate control characters.
5493 IT->c, IT->len etc. have been set to the next character by
5494 the function call above. If we have a display table, and it
5495 contains an entry for IT->c, translate it. Don't do this if
5496 IT->c itself comes from a display table, otherwise we could
5497 end up in an infinite recursion. (An alternative could be to
5498 count the recursion depth of this function and signal an
5499 error when a certain maximum depth is reached.) Is it worth
5501 if (success_p
&& it
->dpvec
== NULL
)
5506 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5509 struct Lisp_Vector
*v
= XVECTOR (dv
);
5511 /* Return the first character from the display table
5512 entry, if not empty. If empty, don't display the
5513 current character. */
5516 it
->dpvec_char_len
= it
->len
;
5517 it
->dpvec
= v
->contents
;
5518 it
->dpend
= v
->contents
+ v
->size
;
5519 it
->current
.dpvec_index
= 0;
5520 it
->dpvec_face_id
= -1;
5521 it
->saved_face_id
= it
->face_id
;
5522 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5527 set_iterator_to_next (it
, 0);
5532 /* Translate control characters into `\003' or `^C' form.
5533 Control characters coming from a display table entry are
5534 currently not translated because we use IT->dpvec to hold
5535 the translation. This could easily be changed but I
5536 don't believe that it is worth doing.
5538 If it->multibyte_p is nonzero, eight-bit characters and
5539 non-printable multibyte characters are also translated to
5542 If it->multibyte_p is zero, eight-bit characters that
5543 don't have corresponding multibyte char code are also
5544 translated to octal form. */
5545 else if ((it
->c
< ' '
5546 && (it
->area
!= TEXT_AREA
5547 /* In mode line, treat \n like other crl chars. */
5549 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5550 || (it
->c
!= '\n' && it
->c
!= '\t')))
5554 || !CHAR_PRINTABLE_P (it
->c
)
5555 || (!NILP (Vnobreak_char_display
)
5556 && (it
->c
== 0x8a0 || it
->c
== 0x8ad
5557 || it
->c
== 0x920 || it
->c
== 0x92d
5558 || it
->c
== 0xe20 || it
->c
== 0xe2d
5559 || it
->c
== 0xf20 || it
->c
== 0xf2d)))
5561 && (!unibyte_display_via_language_environment
5562 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
5564 /* IT->c is a control character which must be displayed
5565 either as '\003' or as `^C' where the '\\' and '^'
5566 can be defined in the display table. Fill
5567 IT->ctl_chars with glyphs for what we have to
5568 display. Then, set IT->dpvec to these glyphs. */
5571 int face_id
, lface_id
= 0 ;
5574 /* Handle control characters with ^. */
5576 if (it
->c
< 128 && it
->ctl_arrow_p
)
5578 g
= '^'; /* default glyph for Control */
5579 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5581 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5582 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5584 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5585 lface_id
= FAST_GLYPH_FACE (g
);
5589 g
= FAST_GLYPH_CHAR (g
);
5590 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5593 else if (it
->f
== last_escape_glyph_frame
5594 && it
->face_id
== last_escape_glyph_face_id
)
5596 face_id
= last_escape_glyph_merged_face_id
;
5600 /* Merge the escape-glyph face into the current face. */
5601 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5603 last_escape_glyph_frame
= it
->f
;
5604 last_escape_glyph_face_id
= it
->face_id
;
5605 last_escape_glyph_merged_face_id
= face_id
;
5608 XSETINT (it
->ctl_chars
[0], g
);
5610 XSETINT (it
->ctl_chars
[1], g
);
5612 goto display_control
;
5615 /* Handle non-break space in the mode where it only gets
5618 if (EQ (Vnobreak_char_display
, Qt
)
5619 && (it
->c
== 0x8a0 || it
->c
== 0x920
5620 || it
->c
== 0xe20 || it
->c
== 0xf20))
5622 /* Merge the no-break-space face into the current face. */
5623 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5627 XSETINT (it
->ctl_chars
[0], g
);
5629 goto display_control
;
5632 /* Handle sequences that start with the "escape glyph". */
5634 /* the default escape glyph is \. */
5635 escape_glyph
= '\\';
5638 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5639 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5641 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5642 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5646 /* The display table specified a face.
5647 Merge it into face_id and also into escape_glyph. */
5648 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5649 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5652 else if (it
->f
== last_escape_glyph_frame
5653 && it
->face_id
== last_escape_glyph_face_id
)
5655 face_id
= last_escape_glyph_merged_face_id
;
5659 /* Merge the escape-glyph face into the current face. */
5660 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5662 last_escape_glyph_frame
= it
->f
;
5663 last_escape_glyph_face_id
= it
->face_id
;
5664 last_escape_glyph_merged_face_id
= face_id
;
5667 /* Handle soft hyphens in the mode where they only get
5670 if (EQ (Vnobreak_char_display
, Qt
)
5671 && (it
->c
== 0x8ad || it
->c
== 0x92d
5672 || it
->c
== 0xe2d || it
->c
== 0xf2d))
5675 XSETINT (it
->ctl_chars
[0], g
);
5677 goto display_control
;
5680 /* Handle non-break space and soft hyphen
5681 with the escape glyph. */
5683 if (it
->c
== 0x8a0 || it
->c
== 0x8ad
5684 || it
->c
== 0x920 || it
->c
== 0x92d
5685 || it
->c
== 0xe20 || it
->c
== 0xe2d
5686 || it
->c
== 0xf20 || it
->c
== 0xf2d)
5688 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5689 g
= it
->c
= ((it
->c
& 0xf) == 0 ? ' ' : '-');
5690 XSETINT (it
->ctl_chars
[1], g
);
5692 goto display_control
;
5696 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5700 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5701 if (SINGLE_BYTE_CHAR_P (it
->c
))
5702 str
[0] = it
->c
, len
= 1;
5705 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5708 /* It's an invalid character, which shouldn't
5709 happen actually, but due to bugs it may
5710 happen. Let's print the char as is, there's
5711 not much meaningful we can do with it. */
5713 str
[1] = it
->c
>> 8;
5714 str
[2] = it
->c
>> 16;
5715 str
[3] = it
->c
>> 24;
5720 for (i
= 0; i
< len
; i
++)
5722 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5723 /* Insert three more glyphs into IT->ctl_chars for
5724 the octal display of the character. */
5725 g
= ((str
[i
] >> 6) & 7) + '0';
5726 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5727 g
= ((str
[i
] >> 3) & 7) + '0';
5728 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5729 g
= (str
[i
] & 7) + '0';
5730 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5736 /* Set up IT->dpvec and return first character from it. */
5737 it
->dpvec_char_len
= it
->len
;
5738 it
->dpvec
= it
->ctl_chars
;
5739 it
->dpend
= it
->dpvec
+ ctl_len
;
5740 it
->current
.dpvec_index
= 0;
5741 it
->dpvec_face_id
= face_id
;
5742 it
->saved_face_id
= it
->face_id
;
5743 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5749 /* Adjust face id for a multibyte character. There are no
5750 multibyte character in unibyte text. */
5753 && FRAME_WINDOW_P (it
->f
))
5755 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5756 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5760 /* Is this character the last one of a run of characters with
5761 box? If yes, set IT->end_of_box_run_p to 1. */
5768 it
->end_of_box_run_p
5769 = ((face_id
= face_after_it_pos (it
),
5770 face_id
!= it
->face_id
)
5771 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5772 face
->box
== FACE_NO_BOX
));
5775 /* Value is 0 if end of buffer or string reached. */
5780 /* Move IT to the next display element.
5782 RESEAT_P non-zero means if called on a newline in buffer text,
5783 skip to the next visible line start.
5785 Functions get_next_display_element and set_iterator_to_next are
5786 separate because I find this arrangement easier to handle than a
5787 get_next_display_element function that also increments IT's
5788 position. The way it is we can first look at an iterator's current
5789 display element, decide whether it fits on a line, and if it does,
5790 increment the iterator position. The other way around we probably
5791 would either need a flag indicating whether the iterator has to be
5792 incremented the next time, or we would have to implement a
5793 decrement position function which would not be easy to write. */
5796 set_iterator_to_next (it
, reseat_p
)
5800 /* Reset flags indicating start and end of a sequence of characters
5801 with box. Reset them at the start of this function because
5802 moving the iterator to a new position might set them. */
5803 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5807 case GET_FROM_BUFFER
:
5808 /* The current display element of IT is a character from
5809 current_buffer. Advance in the buffer, and maybe skip over
5810 invisible lines that are so because of selective display. */
5811 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5812 reseat_at_next_visible_line_start (it
, 0);
5815 xassert (it
->len
!= 0);
5816 IT_BYTEPOS (*it
) += it
->len
;
5817 IT_CHARPOS (*it
) += 1;
5818 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5822 case GET_FROM_COMPOSITION
:
5823 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5824 xassert (it
->sp
> 0);
5826 if (it
->method
== GET_FROM_STRING
)
5828 IT_STRING_BYTEPOS (*it
) += it
->len
;
5829 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5830 goto consider_string_end
;
5832 else if (it
->method
== GET_FROM_BUFFER
)
5834 IT_BYTEPOS (*it
) += it
->len
;
5835 IT_CHARPOS (*it
) += it
->cmp_len
;
5839 case GET_FROM_C_STRING
:
5840 /* Current display element of IT is from a C string. */
5841 IT_BYTEPOS (*it
) += it
->len
;
5842 IT_CHARPOS (*it
) += 1;
5845 case GET_FROM_DISPLAY_VECTOR
:
5846 /* Current display element of IT is from a display table entry.
5847 Advance in the display table definition. Reset it to null if
5848 end reached, and continue with characters from buffers/
5850 ++it
->current
.dpvec_index
;
5852 /* Restore face of the iterator to what they were before the
5853 display vector entry (these entries may contain faces). */
5854 it
->face_id
= it
->saved_face_id
;
5856 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5858 int recheck_faces
= it
->ellipsis_p
;
5861 it
->method
= GET_FROM_C_STRING
;
5862 else if (STRINGP (it
->string
))
5863 it
->method
= GET_FROM_STRING
;
5866 it
->method
= GET_FROM_BUFFER
;
5867 it
->object
= it
->w
->buffer
;
5871 it
->current
.dpvec_index
= -1;
5873 /* Skip over characters which were displayed via IT->dpvec. */
5874 if (it
->dpvec_char_len
< 0)
5875 reseat_at_next_visible_line_start (it
, 1);
5876 else if (it
->dpvec_char_len
> 0)
5878 if (it
->method
== GET_FROM_STRING
5879 && it
->n_overlay_strings
> 0)
5880 it
->ignore_overlay_strings_at_pos_p
= 1;
5881 it
->len
= it
->dpvec_char_len
;
5882 set_iterator_to_next (it
, reseat_p
);
5885 /* Maybe recheck faces after display vector */
5887 it
->stop_charpos
= IT_CHARPOS (*it
);
5891 case GET_FROM_STRING
:
5892 /* Current display element is a character from a Lisp string. */
5893 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5894 IT_STRING_BYTEPOS (*it
) += it
->len
;
5895 IT_STRING_CHARPOS (*it
) += 1;
5897 consider_string_end
:
5899 if (it
->current
.overlay_string_index
>= 0)
5901 /* IT->string is an overlay string. Advance to the
5902 next, if there is one. */
5903 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5904 next_overlay_string (it
);
5908 /* IT->string is not an overlay string. If we reached
5909 its end, and there is something on IT->stack, proceed
5910 with what is on the stack. This can be either another
5911 string, this time an overlay string, or a buffer. */
5912 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5916 if (it
->method
== GET_FROM_STRING
)
5917 goto consider_string_end
;
5922 case GET_FROM_IMAGE
:
5923 case GET_FROM_STRETCH
:
5924 /* The position etc with which we have to proceed are on
5925 the stack. The position may be at the end of a string,
5926 if the `display' property takes up the whole string. */
5927 xassert (it
->sp
> 0);
5929 if (it
->method
== GET_FROM_STRING
)
5930 goto consider_string_end
;
5934 /* There are no other methods defined, so this should be a bug. */
5938 xassert (it
->method
!= GET_FROM_STRING
5939 || (STRINGP (it
->string
)
5940 && IT_STRING_CHARPOS (*it
) >= 0));
5943 /* Load IT's display element fields with information about the next
5944 display element which comes from a display table entry or from the
5945 result of translating a control character to one of the forms `^C'
5948 IT->dpvec holds the glyphs to return as characters.
5949 IT->saved_face_id holds the face id before the display vector--
5950 it is restored into IT->face_idin set_iterator_to_next. */
5953 next_element_from_display_vector (it
)
5957 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5959 it
->face_id
= it
->saved_face_id
;
5961 if (INTEGERP (*it
->dpvec
)
5962 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5966 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5967 it
->c
= FAST_GLYPH_CHAR (g
);
5968 it
->len
= CHAR_BYTES (it
->c
);
5970 /* The entry may contain a face id to use. Such a face id is
5971 the id of a Lisp face, not a realized face. A face id of
5972 zero means no face is specified. */
5973 if (it
->dpvec_face_id
>= 0)
5974 it
->face_id
= it
->dpvec_face_id
;
5977 int lface_id
= FAST_GLYPH_FACE (g
);
5979 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5984 /* Display table entry is invalid. Return a space. */
5985 it
->c
= ' ', it
->len
= 1;
5987 /* Don't change position and object of the iterator here. They are
5988 still the values of the character that had this display table
5989 entry or was translated, and that's what we want. */
5990 it
->what
= IT_CHARACTER
;
5995 /* Load IT with the next display element from Lisp string IT->string.
5996 IT->current.string_pos is the current position within the string.
5997 If IT->current.overlay_string_index >= 0, the Lisp string is an
6001 next_element_from_string (it
)
6004 struct text_pos position
;
6006 xassert (STRINGP (it
->string
));
6007 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6008 position
= it
->current
.string_pos
;
6010 /* Time to check for invisible text? */
6011 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6012 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6016 /* Since a handler may have changed IT->method, we must
6018 return get_next_display_element (it
);
6021 if (it
->current
.overlay_string_index
>= 0)
6023 /* Get the next character from an overlay string. In overlay
6024 strings, There is no field width or padding with spaces to
6026 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6031 else if (STRING_MULTIBYTE (it
->string
))
6033 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6034 const unsigned char *s
= (SDATA (it
->string
)
6035 + IT_STRING_BYTEPOS (*it
));
6036 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
6040 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6046 /* Get the next character from a Lisp string that is not an
6047 overlay string. Such strings come from the mode line, for
6048 example. We may have to pad with spaces, or truncate the
6049 string. See also next_element_from_c_string. */
6050 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6055 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6057 /* Pad with spaces. */
6058 it
->c
= ' ', it
->len
= 1;
6059 CHARPOS (position
) = BYTEPOS (position
) = -1;
6061 else if (STRING_MULTIBYTE (it
->string
))
6063 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6064 const unsigned char *s
= (SDATA (it
->string
)
6065 + IT_STRING_BYTEPOS (*it
));
6066 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
6070 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6075 /* Record what we have and where it came from. */
6076 it
->what
= IT_CHARACTER
;
6077 it
->object
= it
->string
;
6078 it
->position
= position
;
6083 /* Load IT with next display element from C string IT->s.
6084 IT->string_nchars is the maximum number of characters to return
6085 from the string. IT->end_charpos may be greater than
6086 IT->string_nchars when this function is called, in which case we
6087 may have to return padding spaces. Value is zero if end of string
6088 reached, including padding spaces. */
6091 next_element_from_c_string (it
)
6097 it
->what
= IT_CHARACTER
;
6098 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6101 /* IT's position can be greater IT->string_nchars in case a field
6102 width or precision has been specified when the iterator was
6104 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6106 /* End of the game. */
6110 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6112 /* Pad with spaces. */
6113 it
->c
= ' ', it
->len
= 1;
6114 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6116 else if (it
->multibyte_p
)
6118 /* Implementation note: The calls to strlen apparently aren't a
6119 performance problem because there is no noticeable performance
6120 difference between Emacs running in unibyte or multibyte mode. */
6121 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6122 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
6126 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6132 /* Set up IT to return characters from an ellipsis, if appropriate.
6133 The definition of the ellipsis glyphs may come from a display table
6134 entry. This function Fills IT with the first glyph from the
6135 ellipsis if an ellipsis is to be displayed. */
6138 next_element_from_ellipsis (it
)
6141 if (it
->selective_display_ellipsis_p
)
6142 setup_for_ellipsis (it
, it
->len
);
6145 /* The face at the current position may be different from the
6146 face we find after the invisible text. Remember what it
6147 was in IT->saved_face_id, and signal that it's there by
6148 setting face_before_selective_p. */
6149 it
->saved_face_id
= it
->face_id
;
6150 it
->method
= GET_FROM_BUFFER
;
6151 it
->object
= it
->w
->buffer
;
6152 reseat_at_next_visible_line_start (it
, 1);
6153 it
->face_before_selective_p
= 1;
6156 return get_next_display_element (it
);
6160 /* Deliver an image display element. The iterator IT is already
6161 filled with image information (done in handle_display_prop). Value
6166 next_element_from_image (it
)
6169 it
->what
= IT_IMAGE
;
6174 /* Fill iterator IT with next display element from a stretch glyph
6175 property. IT->object is the value of the text property. Value is
6179 next_element_from_stretch (it
)
6182 it
->what
= IT_STRETCH
;
6187 /* Load IT with the next display element from current_buffer. Value
6188 is zero if end of buffer reached. IT->stop_charpos is the next
6189 position at which to stop and check for text properties or buffer
6193 next_element_from_buffer (it
)
6198 /* Check this assumption, otherwise, we would never enter the
6199 if-statement, below. */
6200 xassert (IT_CHARPOS (*it
) >= BEGV
6201 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
6203 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6205 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6207 int overlay_strings_follow_p
;
6209 /* End of the game, except when overlay strings follow that
6210 haven't been returned yet. */
6211 if (it
->overlay_strings_at_end_processed_p
)
6212 overlay_strings_follow_p
= 0;
6215 it
->overlay_strings_at_end_processed_p
= 1;
6216 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6219 if (overlay_strings_follow_p
)
6220 success_p
= get_next_display_element (it
);
6224 it
->position
= it
->current
.pos
;
6231 return get_next_display_element (it
);
6236 /* No face changes, overlays etc. in sight, so just return a
6237 character from current_buffer. */
6240 /* Maybe run the redisplay end trigger hook. Performance note:
6241 This doesn't seem to cost measurable time. */
6242 if (it
->redisplay_end_trigger_charpos
6244 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6245 run_redisplay_end_trigger_hook (it
);
6247 /* Get the next character, maybe multibyte. */
6248 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6249 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6251 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
6252 - IT_BYTEPOS (*it
));
6253 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
6256 it
->c
= *p
, it
->len
= 1;
6258 /* Record what we have and where it came from. */
6259 it
->what
= IT_CHARACTER
;
6260 it
->object
= it
->w
->buffer
;
6261 it
->position
= it
->current
.pos
;
6263 /* Normally we return the character found above, except when we
6264 really want to return an ellipsis for selective display. */
6269 /* A value of selective > 0 means hide lines indented more
6270 than that number of columns. */
6271 if (it
->selective
> 0
6272 && IT_CHARPOS (*it
) + 1 < ZV
6273 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6274 IT_BYTEPOS (*it
) + 1,
6275 (double) it
->selective
)) /* iftc */
6277 success_p
= next_element_from_ellipsis (it
);
6278 it
->dpvec_char_len
= -1;
6281 else if (it
->c
== '\r' && it
->selective
== -1)
6283 /* A value of selective == -1 means that everything from the
6284 CR to the end of the line is invisible, with maybe an
6285 ellipsis displayed for it. */
6286 success_p
= next_element_from_ellipsis (it
);
6287 it
->dpvec_char_len
= -1;
6292 /* Value is zero if end of buffer reached. */
6293 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6298 /* Run the redisplay end trigger hook for IT. */
6301 run_redisplay_end_trigger_hook (it
)
6304 Lisp_Object args
[3];
6306 /* IT->glyph_row should be non-null, i.e. we should be actually
6307 displaying something, or otherwise we should not run the hook. */
6308 xassert (it
->glyph_row
);
6310 /* Set up hook arguments. */
6311 args
[0] = Qredisplay_end_trigger_functions
;
6312 args
[1] = it
->window
;
6313 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6314 it
->redisplay_end_trigger_charpos
= 0;
6316 /* Since we are *trying* to run these functions, don't try to run
6317 them again, even if they get an error. */
6318 it
->w
->redisplay_end_trigger
= Qnil
;
6319 Frun_hook_with_args (3, args
);
6321 /* Notice if it changed the face of the character we are on. */
6322 handle_face_prop (it
);
6326 /* Deliver a composition display element. The iterator IT is already
6327 filled with composition information (done in
6328 handle_composition_prop). Value is always 1. */
6331 next_element_from_composition (it
)
6334 it
->what
= IT_COMPOSITION
;
6335 it
->position
= (STRINGP (it
->string
)
6336 ? it
->current
.string_pos
6338 if (STRINGP (it
->string
))
6339 it
->object
= it
->string
;
6341 it
->object
= it
->w
->buffer
;
6347 /***********************************************************************
6348 Moving an iterator without producing glyphs
6349 ***********************************************************************/
6351 /* Check if iterator is at a position corresponding to a valid buffer
6352 position after some move_it_ call. */
6354 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6355 ((it)->method == GET_FROM_STRING \
6356 ? IT_STRING_CHARPOS (*it) == 0 \
6360 /* Move iterator IT to a specified buffer or X position within one
6361 line on the display without producing glyphs.
6363 OP should be a bit mask including some or all of these bits:
6364 MOVE_TO_X: Stop on reaching x-position TO_X.
6365 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6366 Regardless of OP's value, stop in reaching the end of the display line.
6368 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6369 This means, in particular, that TO_X includes window's horizontal
6372 The return value has several possible values that
6373 say what condition caused the scan to stop:
6375 MOVE_POS_MATCH_OR_ZV
6376 - when TO_POS or ZV was reached.
6379 -when TO_X was reached before TO_POS or ZV were reached.
6382 - when we reached the end of the display area and the line must
6386 - when we reached the end of the display area and the line is
6390 - when we stopped at a line end, i.e. a newline or a CR and selective
6393 static enum move_it_result
6394 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
6396 int to_charpos
, to_x
, op
;
6398 enum move_it_result result
= MOVE_UNDEFINED
;
6399 struct glyph_row
*saved_glyph_row
;
6401 /* Don't produce glyphs in produce_glyphs. */
6402 saved_glyph_row
= it
->glyph_row
;
6403 it
->glyph_row
= NULL
;
6405 #define BUFFER_POS_REACHED_P() \
6406 ((op & MOVE_TO_POS) != 0 \
6407 && BUFFERP (it->object) \
6408 && IT_CHARPOS (*it) >= to_charpos \
6409 && (it->method == GET_FROM_BUFFER \
6410 || (it->method == GET_FROM_DISPLAY_VECTOR \
6411 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6416 int x
, i
, ascent
= 0, descent
= 0;
6418 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
6419 if ((op
& MOVE_TO_POS
) != 0
6420 && BUFFERP (it
->object
)
6421 && it
->method
== GET_FROM_BUFFER
6422 && IT_CHARPOS (*it
) > to_charpos
)
6424 result
= MOVE_POS_MATCH_OR_ZV
;
6428 /* Stop when ZV reached.
6429 We used to stop here when TO_CHARPOS reached as well, but that is
6430 too soon if this glyph does not fit on this line. So we handle it
6431 explicitly below. */
6432 if (!get_next_display_element (it
)
6433 || (it
->truncate_lines_p
6434 && BUFFER_POS_REACHED_P ()))
6436 result
= MOVE_POS_MATCH_OR_ZV
;
6440 /* The call to produce_glyphs will get the metrics of the
6441 display element IT is loaded with. We record in x the
6442 x-position before this display element in case it does not
6446 /* Remember the line height so far in case the next element doesn't
6448 if (!it
->truncate_lines_p
)
6450 ascent
= it
->max_ascent
;
6451 descent
= it
->max_descent
;
6454 PRODUCE_GLYPHS (it
);
6456 if (it
->area
!= TEXT_AREA
)
6458 set_iterator_to_next (it
, 1);
6462 /* The number of glyphs we get back in IT->nglyphs will normally
6463 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6464 character on a terminal frame, or (iii) a line end. For the
6465 second case, IT->nglyphs - 1 padding glyphs will be present
6466 (on X frames, there is only one glyph produced for a
6467 composite character.
6469 The behavior implemented below means, for continuation lines,
6470 that as many spaces of a TAB as fit on the current line are
6471 displayed there. For terminal frames, as many glyphs of a
6472 multi-glyph character are displayed in the current line, too.
6473 This is what the old redisplay code did, and we keep it that
6474 way. Under X, the whole shape of a complex character must
6475 fit on the line or it will be completely displayed in the
6478 Note that both for tabs and padding glyphs, all glyphs have
6482 /* More than one glyph or glyph doesn't fit on line. All
6483 glyphs have the same width. */
6484 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6486 int x_before_this_char
= x
;
6487 int hpos_before_this_char
= it
->hpos
;
6489 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6491 new_x
= x
+ single_glyph_width
;
6493 /* We want to leave anything reaching TO_X to the caller. */
6494 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6496 if (BUFFER_POS_REACHED_P ())
6497 goto buffer_pos_reached
;
6499 result
= MOVE_X_REACHED
;
6502 else if (/* Lines are continued. */
6503 !it
->truncate_lines_p
6504 && (/* And glyph doesn't fit on the line. */
6505 new_x
> it
->last_visible_x
6506 /* Or it fits exactly and we're on a window
6508 || (new_x
== it
->last_visible_x
6509 && FRAME_WINDOW_P (it
->f
))))
6511 if (/* IT->hpos == 0 means the very first glyph
6512 doesn't fit on the line, e.g. a wide image. */
6514 || (new_x
== it
->last_visible_x
6515 && FRAME_WINDOW_P (it
->f
)))
6518 it
->current_x
= new_x
;
6520 /* The character's last glyph just barely fits
6522 if (i
== it
->nglyphs
- 1)
6524 /* If this is the destination position,
6525 return a position *before* it in this row,
6526 now that we know it fits in this row. */
6527 if (BUFFER_POS_REACHED_P ())
6529 it
->hpos
= hpos_before_this_char
;
6530 it
->current_x
= x_before_this_char
;
6531 result
= MOVE_POS_MATCH_OR_ZV
;
6535 set_iterator_to_next (it
, 1);
6536 #ifdef HAVE_WINDOW_SYSTEM
6537 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6539 if (!get_next_display_element (it
))
6541 result
= MOVE_POS_MATCH_OR_ZV
;
6544 if (BUFFER_POS_REACHED_P ())
6546 if (ITERATOR_AT_END_OF_LINE_P (it
))
6547 result
= MOVE_POS_MATCH_OR_ZV
;
6549 result
= MOVE_LINE_CONTINUED
;
6552 if (ITERATOR_AT_END_OF_LINE_P (it
))
6554 result
= MOVE_NEWLINE_OR_CR
;
6558 #endif /* HAVE_WINDOW_SYSTEM */
6564 it
->max_ascent
= ascent
;
6565 it
->max_descent
= descent
;
6568 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6570 result
= MOVE_LINE_CONTINUED
;
6573 else if (BUFFER_POS_REACHED_P ())
6574 goto buffer_pos_reached
;
6575 else if (new_x
> it
->first_visible_x
)
6577 /* Glyph is visible. Increment number of glyphs that
6578 would be displayed. */
6583 /* Glyph is completely off the left margin of the display
6584 area. Nothing to do. */
6588 if (result
!= MOVE_UNDEFINED
)
6591 else if (BUFFER_POS_REACHED_P ())
6595 it
->max_ascent
= ascent
;
6596 it
->max_descent
= descent
;
6597 result
= MOVE_POS_MATCH_OR_ZV
;
6600 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6602 /* Stop when TO_X specified and reached. This check is
6603 necessary here because of lines consisting of a line end,
6604 only. The line end will not produce any glyphs and we
6605 would never get MOVE_X_REACHED. */
6606 xassert (it
->nglyphs
== 0);
6607 result
= MOVE_X_REACHED
;
6611 /* Is this a line end? If yes, we're done. */
6612 if (ITERATOR_AT_END_OF_LINE_P (it
))
6614 result
= MOVE_NEWLINE_OR_CR
;
6618 /* The current display element has been consumed. Advance
6620 set_iterator_to_next (it
, 1);
6622 /* Stop if lines are truncated and IT's current x-position is
6623 past the right edge of the window now. */
6624 if (it
->truncate_lines_p
6625 && it
->current_x
>= it
->last_visible_x
)
6627 #ifdef HAVE_WINDOW_SYSTEM
6628 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6630 if (!get_next_display_element (it
)
6631 || BUFFER_POS_REACHED_P ())
6633 result
= MOVE_POS_MATCH_OR_ZV
;
6636 if (ITERATOR_AT_END_OF_LINE_P (it
))
6638 result
= MOVE_NEWLINE_OR_CR
;
6642 #endif /* HAVE_WINDOW_SYSTEM */
6643 result
= MOVE_LINE_TRUNCATED
;
6648 #undef BUFFER_POS_REACHED_P
6650 /* Restore the iterator settings altered at the beginning of this
6652 it
->glyph_row
= saved_glyph_row
;
6657 /* Move IT forward until it satisfies one or more of the criteria in
6658 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6660 OP is a bit-mask that specifies where to stop, and in particular,
6661 which of those four position arguments makes a difference. See the
6662 description of enum move_operation_enum.
6664 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6665 screen line, this function will set IT to the next position >
6669 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6671 int to_charpos
, to_x
, to_y
, to_vpos
;
6674 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6680 if (op
& MOVE_TO_VPOS
)
6682 /* If no TO_CHARPOS and no TO_X specified, stop at the
6683 start of the line TO_VPOS. */
6684 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6686 if (it
->vpos
== to_vpos
)
6692 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6696 /* TO_VPOS >= 0 means stop at TO_X in the line at
6697 TO_VPOS, or at TO_POS, whichever comes first. */
6698 if (it
->vpos
== to_vpos
)
6704 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6706 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6711 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6713 /* We have reached TO_X but not in the line we want. */
6714 skip
= move_it_in_display_line_to (it
, to_charpos
,
6716 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6724 else if (op
& MOVE_TO_Y
)
6726 struct it it_backup
;
6728 /* TO_Y specified means stop at TO_X in the line containing
6729 TO_Y---or at TO_CHARPOS if this is reached first. The
6730 problem is that we can't really tell whether the line
6731 contains TO_Y before we have completely scanned it, and
6732 this may skip past TO_X. What we do is to first scan to
6735 If TO_X is not specified, use a TO_X of zero. The reason
6736 is to make the outcome of this function more predictable.
6737 If we didn't use TO_X == 0, we would stop at the end of
6738 the line which is probably not what a caller would expect
6740 skip
= move_it_in_display_line_to (it
, to_charpos
,
6744 | (op
& MOVE_TO_POS
)));
6746 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6747 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6753 /* If TO_X was reached, we would like to know whether TO_Y
6754 is in the line. This can only be said if we know the
6755 total line height which requires us to scan the rest of
6757 if (skip
== MOVE_X_REACHED
)
6760 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6761 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6763 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6766 /* Now, decide whether TO_Y is in this line. */
6767 line_height
= it
->max_ascent
+ it
->max_descent
;
6768 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6770 if (to_y
>= it
->current_y
6771 && to_y
< it
->current_y
+ line_height
)
6773 if (skip
== MOVE_X_REACHED
)
6774 /* If TO_Y is in this line and TO_X was reached above,
6775 we scanned too far. We have to restore IT's settings
6776 to the ones before skipping. */
6780 else if (skip
== MOVE_X_REACHED
)
6783 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6790 else if (BUFFERP (it
->object
)
6791 && it
->method
== GET_FROM_BUFFER
6792 && IT_CHARPOS (*it
) >= to_charpos
)
6793 skip
= MOVE_POS_MATCH_OR_ZV
;
6795 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6799 case MOVE_POS_MATCH_OR_ZV
:
6803 case MOVE_NEWLINE_OR_CR
:
6804 set_iterator_to_next (it
, 1);
6805 it
->continuation_lines_width
= 0;
6808 case MOVE_LINE_TRUNCATED
:
6809 it
->continuation_lines_width
= 0;
6810 reseat_at_next_visible_line_start (it
, 0);
6811 if ((op
& MOVE_TO_POS
) != 0
6812 && IT_CHARPOS (*it
) > to_charpos
)
6819 case MOVE_LINE_CONTINUED
:
6820 /* For continued lines ending in a tab, some of the glyphs
6821 associated with the tab are displayed on the current
6822 line. Since it->current_x does not include these glyphs,
6823 we use it->last_visible_x instead. */
6824 it
->continuation_lines_width
+=
6825 (it
->c
== '\t') ? it
->last_visible_x
: it
->current_x
;
6832 /* Reset/increment for the next run. */
6833 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6834 it
->current_x
= it
->hpos
= 0;
6835 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6837 last_height
= it
->max_ascent
+ it
->max_descent
;
6838 last_max_ascent
= it
->max_ascent
;
6839 it
->max_ascent
= it
->max_descent
= 0;
6844 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6848 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6850 If DY > 0, move IT backward at least that many pixels. DY = 0
6851 means move IT backward to the preceding line start or BEGV. This
6852 function may move over more than DY pixels if IT->current_y - DY
6853 ends up in the middle of a line; in this case IT->current_y will be
6854 set to the top of the line moved to. */
6857 move_it_vertically_backward (it
, dy
)
6868 start_pos
= IT_CHARPOS (*it
);
6870 /* Estimate how many newlines we must move back. */
6871 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6873 /* Set the iterator's position that many lines back. */
6874 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6875 back_to_previous_visible_line_start (it
);
6877 /* Reseat the iterator here. When moving backward, we don't want
6878 reseat to skip forward over invisible text, set up the iterator
6879 to deliver from overlay strings at the new position etc. So,
6880 use reseat_1 here. */
6881 reseat_1 (it
, it
->current
.pos
, 1);
6883 /* We are now surely at a line start. */
6884 it
->current_x
= it
->hpos
= 0;
6885 it
->continuation_lines_width
= 0;
6887 /* Move forward and see what y-distance we moved. First move to the
6888 start of the next line so that we get its height. We need this
6889 height to be able to tell whether we reached the specified
6892 it2
.max_ascent
= it2
.max_descent
= 0;
6895 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6896 MOVE_TO_POS
| MOVE_TO_VPOS
);
6898 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
6899 xassert (IT_CHARPOS (*it
) >= BEGV
);
6902 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6903 xassert (IT_CHARPOS (*it
) >= BEGV
);
6904 /* H is the actual vertical distance from the position in *IT
6905 and the starting position. */
6906 h
= it2
.current_y
- it
->current_y
;
6907 /* NLINES is the distance in number of lines. */
6908 nlines
= it2
.vpos
- it
->vpos
;
6910 /* Correct IT's y and vpos position
6911 so that they are relative to the starting point. */
6917 /* DY == 0 means move to the start of the screen line. The
6918 value of nlines is > 0 if continuation lines were involved. */
6920 move_it_by_lines (it
, nlines
, 1);
6922 /* I think this assert is bogus if buffer contains
6923 invisible text or images. KFS. */
6924 xassert (IT_CHARPOS (*it
) <= start_pos
);
6929 /* The y-position we try to reach, relative to *IT.
6930 Note that H has been subtracted in front of the if-statement. */
6931 int target_y
= it
->current_y
+ h
- dy
;
6932 int y0
= it3
.current_y
;
6933 int y1
= line_bottom_y (&it3
);
6934 int line_height
= y1
- y0
;
6936 /* If we did not reach target_y, try to move further backward if
6937 we can. If we moved too far backward, try to move forward. */
6938 if (target_y
< it
->current_y
6939 /* This is heuristic. In a window that's 3 lines high, with
6940 a line height of 13 pixels each, recentering with point
6941 on the bottom line will try to move -39/2 = 19 pixels
6942 backward. Try to avoid moving into the first line. */
6943 && (it
->current_y
- target_y
6944 > min (window_box_height (it
->w
), line_height
* 2 / 3))
6945 && IT_CHARPOS (*it
) > BEGV
)
6947 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6948 target_y
- it
->current_y
));
6949 dy
= it
->current_y
- target_y
;
6950 goto move_further_back
;
6952 else if (target_y
>= it
->current_y
+ line_height
6953 && IT_CHARPOS (*it
) < ZV
)
6955 /* Should move forward by at least one line, maybe more.
6957 Note: Calling move_it_by_lines can be expensive on
6958 terminal frames, where compute_motion is used (via
6959 vmotion) to do the job, when there are very long lines
6960 and truncate-lines is nil. That's the reason for
6961 treating terminal frames specially here. */
6963 if (!FRAME_WINDOW_P (it
->f
))
6964 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6969 move_it_by_lines (it
, 1, 1);
6971 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6975 /* I think this assert is bogus if buffer contains
6976 invisible text or images. KFS. */
6977 xassert (IT_CHARPOS (*it
) >= BEGV
);
6984 /* Move IT by a specified amount of pixel lines DY. DY negative means
6985 move backwards. DY = 0 means move to start of screen line. At the
6986 end, IT will be on the start of a screen line. */
6989 move_it_vertically (it
, dy
)
6994 move_it_vertically_backward (it
, -dy
);
6997 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6998 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6999 MOVE_TO_POS
| MOVE_TO_Y
);
7000 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7002 /* If buffer ends in ZV without a newline, move to the start of
7003 the line to satisfy the post-condition. */
7004 if (IT_CHARPOS (*it
) == ZV
7006 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7007 move_it_by_lines (it
, 0, 0);
7012 /* Move iterator IT past the end of the text line it is in. */
7015 move_it_past_eol (it
)
7018 enum move_it_result rc
;
7020 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7021 if (rc
== MOVE_NEWLINE_OR_CR
)
7022 set_iterator_to_next (it
, 0);
7026 #if 0 /* Currently not used. */
7028 /* Return non-zero if some text between buffer positions START_CHARPOS
7029 and END_CHARPOS is invisible. IT->window is the window for text
7033 invisible_text_between_p (it
, start_charpos
, end_charpos
)
7035 int start_charpos
, end_charpos
;
7037 Lisp_Object prop
, limit
;
7038 int invisible_found_p
;
7040 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
7042 /* Is text at START invisible? */
7043 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
7045 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
7046 invisible_found_p
= 1;
7049 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
7051 make_number (end_charpos
));
7052 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
7055 return invisible_found_p
;
7061 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7062 negative means move up. DVPOS == 0 means move to the start of the
7063 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7064 NEED_Y_P is zero, IT->current_y will be left unchanged.
7066 Further optimization ideas: If we would know that IT->f doesn't use
7067 a face with proportional font, we could be faster for
7068 truncate-lines nil. */
7071 move_it_by_lines (it
, dvpos
, need_y_p
)
7073 int dvpos
, need_y_p
;
7075 struct position pos
;
7077 if (!FRAME_WINDOW_P (it
->f
))
7079 struct text_pos textpos
;
7081 /* We can use vmotion on frames without proportional fonts. */
7082 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
7083 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
7084 reseat (it
, textpos
, 1);
7085 it
->vpos
+= pos
.vpos
;
7086 it
->current_y
+= pos
.vpos
;
7088 else if (dvpos
== 0)
7090 /* DVPOS == 0 means move to the start of the screen line. */
7091 move_it_vertically_backward (it
, 0);
7092 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7093 /* Let next call to line_bottom_y calculate real line height */
7098 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7099 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7100 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7105 int start_charpos
, i
;
7107 /* Start at the beginning of the screen line containing IT's
7108 position. This may actually move vertically backwards,
7109 in case of overlays, so adjust dvpos accordingly. */
7111 move_it_vertically_backward (it
, 0);
7114 /* Go back -DVPOS visible lines and reseat the iterator there. */
7115 start_charpos
= IT_CHARPOS (*it
);
7116 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7117 back_to_previous_visible_line_start (it
);
7118 reseat (it
, it
->current
.pos
, 1);
7120 /* Move further back if we end up in a string or an image. */
7121 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7123 /* First try to move to start of display line. */
7125 move_it_vertically_backward (it
, 0);
7127 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7129 /* If start of line is still in string or image,
7130 move further back. */
7131 back_to_previous_visible_line_start (it
);
7132 reseat (it
, it
->current
.pos
, 1);
7136 it
->current_x
= it
->hpos
= 0;
7138 /* Above call may have moved too far if continuation lines
7139 are involved. Scan forward and see if it did. */
7141 it2
.vpos
= it2
.current_y
= 0;
7142 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7143 it
->vpos
-= it2
.vpos
;
7144 it
->current_y
-= it2
.current_y
;
7145 it
->current_x
= it
->hpos
= 0;
7147 /* If we moved too far back, move IT some lines forward. */
7148 if (it2
.vpos
> -dvpos
)
7150 int delta
= it2
.vpos
+ dvpos
;
7152 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7153 /* Move back again if we got too far ahead. */
7154 if (IT_CHARPOS (*it
) >= start_charpos
)
7160 /* Return 1 if IT points into the middle of a display vector. */
7163 in_display_vector_p (it
)
7166 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7167 && it
->current
.dpvec_index
> 0
7168 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7172 /***********************************************************************
7174 ***********************************************************************/
7177 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7181 add_to_log (format
, arg1
, arg2
)
7183 Lisp_Object arg1
, arg2
;
7185 Lisp_Object args
[3];
7186 Lisp_Object msg
, fmt
;
7189 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7192 /* Do nothing if called asynchronously. Inserting text into
7193 a buffer may call after-change-functions and alike and
7194 that would means running Lisp asynchronously. */
7195 if (handling_signal
)
7199 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7201 args
[0] = fmt
= build_string (format
);
7204 msg
= Fformat (3, args
);
7206 len
= SBYTES (msg
) + 1;
7207 SAFE_ALLOCA (buffer
, char *, len
);
7208 bcopy (SDATA (msg
), buffer
, len
);
7210 message_dolog (buffer
, len
- 1, 1, 0);
7217 /* Output a newline in the *Messages* buffer if "needs" one. */
7220 message_log_maybe_newline ()
7222 if (message_log_need_newline
)
7223 message_dolog ("", 0, 1, 0);
7227 /* Add a string M of length NBYTES to the message log, optionally
7228 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7229 nonzero, means interpret the contents of M as multibyte. This
7230 function calls low-level routines in order to bypass text property
7231 hooks, etc. which might not be safe to run.
7233 This may GC (insert may run before/after change hooks),
7234 so the buffer M must NOT point to a Lisp string. */
7237 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7239 int nbytes
, nlflag
, multibyte
;
7241 if (!NILP (Vmemory_full
))
7244 if (!NILP (Vmessage_log_max
))
7246 struct buffer
*oldbuf
;
7247 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7248 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7249 int point_at_end
= 0;
7251 Lisp_Object old_deactivate_mark
, tem
;
7252 struct gcpro gcpro1
;
7254 old_deactivate_mark
= Vdeactivate_mark
;
7255 oldbuf
= current_buffer
;
7256 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7257 current_buffer
->undo_list
= Qt
;
7259 oldpoint
= message_dolog_marker1
;
7260 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7261 oldbegv
= message_dolog_marker2
;
7262 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7263 oldzv
= message_dolog_marker3
;
7264 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7265 GCPRO1 (old_deactivate_mark
);
7273 BEGV_BYTE
= BEG_BYTE
;
7276 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7278 /* Insert the string--maybe converting multibyte to single byte
7279 or vice versa, so that all the text fits the buffer. */
7281 && NILP (current_buffer
->enable_multibyte_characters
))
7283 int i
, c
, char_bytes
;
7284 unsigned char work
[1];
7286 /* Convert a multibyte string to single-byte
7287 for the *Message* buffer. */
7288 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7290 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7291 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7293 : multibyte_char_to_unibyte (c
, Qnil
));
7294 insert_1_both (work
, 1, 1, 1, 0, 0);
7297 else if (! multibyte
7298 && ! NILP (current_buffer
->enable_multibyte_characters
))
7300 int i
, c
, char_bytes
;
7301 unsigned char *msg
= (unsigned char *) m
;
7302 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7303 /* Convert a single-byte string to multibyte
7304 for the *Message* buffer. */
7305 for (i
= 0; i
< nbytes
; i
++)
7307 c
= unibyte_char_to_multibyte (msg
[i
]);
7308 char_bytes
= CHAR_STRING (c
, str
);
7309 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7313 insert_1 (m
, nbytes
, 1, 0, 0);
7317 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7318 insert_1 ("\n", 1, 1, 0, 0);
7320 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7322 this_bol_byte
= PT_BYTE
;
7324 /* See if this line duplicates the previous one.
7325 If so, combine duplicates. */
7328 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7330 prev_bol_byte
= PT_BYTE
;
7332 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7333 this_bol
, this_bol_byte
);
7336 del_range_both (prev_bol
, prev_bol_byte
,
7337 this_bol
, this_bol_byte
, 0);
7343 /* If you change this format, don't forget to also
7344 change message_log_check_duplicate. */
7345 sprintf (dupstr
, " [%d times]", dup
);
7346 duplen
= strlen (dupstr
);
7347 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7348 insert_1 (dupstr
, duplen
, 1, 0, 1);
7353 /* If we have more than the desired maximum number of lines
7354 in the *Messages* buffer now, delete the oldest ones.
7355 This is safe because we don't have undo in this buffer. */
7357 if (NATNUMP (Vmessage_log_max
))
7359 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7360 -XFASTINT (Vmessage_log_max
) - 1, 0);
7361 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7364 BEGV
= XMARKER (oldbegv
)->charpos
;
7365 BEGV_BYTE
= marker_byte_position (oldbegv
);
7374 ZV
= XMARKER (oldzv
)->charpos
;
7375 ZV_BYTE
= marker_byte_position (oldzv
);
7379 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7381 /* We can't do Fgoto_char (oldpoint) because it will run some
7383 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7384 XMARKER (oldpoint
)->bytepos
);
7387 unchain_marker (XMARKER (oldpoint
));
7388 unchain_marker (XMARKER (oldbegv
));
7389 unchain_marker (XMARKER (oldzv
));
7391 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7392 set_buffer_internal (oldbuf
);
7394 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7395 message_log_need_newline
= !nlflag
;
7396 Vdeactivate_mark
= old_deactivate_mark
;
7401 /* We are at the end of the buffer after just having inserted a newline.
7402 (Note: We depend on the fact we won't be crossing the gap.)
7403 Check to see if the most recent message looks a lot like the previous one.
7404 Return 0 if different, 1 if the new one should just replace it, or a
7405 value N > 1 if we should also append " [N times]". */
7408 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7409 int prev_bol
, this_bol
;
7410 int prev_bol_byte
, this_bol_byte
;
7413 int len
= Z_BYTE
- 1 - this_bol_byte
;
7415 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7416 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7418 for (i
= 0; i
< len
; i
++)
7420 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7428 if (*p1
++ == ' ' && *p1
++ == '[')
7431 while (*p1
>= '0' && *p1
<= '9')
7432 n
= n
* 10 + *p1
++ - '0';
7433 if (strncmp (p1
, " times]\n", 8) == 0)
7440 /* Display an echo area message M with a specified length of NBYTES
7441 bytes. The string may include null characters. If M is 0, clear
7442 out any existing message, and let the mini-buffer text show
7445 This may GC, so the buffer M must NOT point to a Lisp string. */
7448 message2 (m
, nbytes
, multibyte
)
7453 /* First flush out any partial line written with print. */
7454 message_log_maybe_newline ();
7456 message_dolog (m
, nbytes
, 1, multibyte
);
7457 message2_nolog (m
, nbytes
, multibyte
);
7461 /* The non-logging counterpart of message2. */
7464 message2_nolog (m
, nbytes
, multibyte
)
7466 int nbytes
, multibyte
;
7468 struct frame
*sf
= SELECTED_FRAME ();
7469 message_enable_multibyte
= multibyte
;
7473 if (noninteractive_need_newline
)
7474 putc ('\n', stderr
);
7475 noninteractive_need_newline
= 0;
7477 fwrite (m
, nbytes
, 1, stderr
);
7478 if (cursor_in_echo_area
== 0)
7479 fprintf (stderr
, "\n");
7482 /* A null message buffer means that the frame hasn't really been
7483 initialized yet. Error messages get reported properly by
7484 cmd_error, so this must be just an informative message; toss it. */
7485 else if (INTERACTIVE
7486 && sf
->glyphs_initialized_p
7487 && FRAME_MESSAGE_BUF (sf
))
7489 Lisp_Object mini_window
;
7492 /* Get the frame containing the mini-buffer
7493 that the selected frame is using. */
7494 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7495 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7497 FRAME_SAMPLE_VISIBILITY (f
);
7498 if (FRAME_VISIBLE_P (sf
)
7499 && ! FRAME_VISIBLE_P (f
))
7500 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7504 set_message (m
, Qnil
, nbytes
, multibyte
);
7505 if (minibuffer_auto_raise
)
7506 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7509 clear_message (1, 1);
7511 do_pending_window_change (0);
7512 echo_area_display (1);
7513 do_pending_window_change (0);
7514 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7515 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7520 /* Display an echo area message M with a specified length of NBYTES
7521 bytes. The string may include null characters. If M is not a
7522 string, clear out any existing message, and let the mini-buffer
7525 This function cancels echoing. */
7528 message3 (m
, nbytes
, multibyte
)
7533 struct gcpro gcpro1
;
7536 clear_message (1,1);
7539 /* First flush out any partial line written with print. */
7540 message_log_maybe_newline ();
7546 SAFE_ALLOCA (buffer
, char *, nbytes
);
7547 bcopy (SDATA (m
), buffer
, nbytes
);
7548 message_dolog (buffer
, nbytes
, 1, multibyte
);
7551 message3_nolog (m
, nbytes
, multibyte
);
7557 /* The non-logging version of message3.
7558 This does not cancel echoing, because it is used for echoing.
7559 Perhaps we need to make a separate function for echoing
7560 and make this cancel echoing. */
7563 message3_nolog (m
, nbytes
, multibyte
)
7565 int nbytes
, multibyte
;
7567 struct frame
*sf
= SELECTED_FRAME ();
7568 message_enable_multibyte
= multibyte
;
7572 if (noninteractive_need_newline
)
7573 putc ('\n', stderr
);
7574 noninteractive_need_newline
= 0;
7576 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7577 if (cursor_in_echo_area
== 0)
7578 fprintf (stderr
, "\n");
7581 /* A null message buffer means that the frame hasn't really been
7582 initialized yet. Error messages get reported properly by
7583 cmd_error, so this must be just an informative message; toss it. */
7584 else if (INTERACTIVE
7585 && sf
->glyphs_initialized_p
7586 && FRAME_MESSAGE_BUF (sf
))
7588 Lisp_Object mini_window
;
7592 /* Get the frame containing the mini-buffer
7593 that the selected frame is using. */
7594 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7595 frame
= XWINDOW (mini_window
)->frame
;
7598 FRAME_SAMPLE_VISIBILITY (f
);
7599 if (FRAME_VISIBLE_P (sf
)
7600 && !FRAME_VISIBLE_P (f
))
7601 Fmake_frame_visible (frame
);
7603 if (STRINGP (m
) && SCHARS (m
) > 0)
7605 set_message (NULL
, m
, nbytes
, multibyte
);
7606 if (minibuffer_auto_raise
)
7607 Fraise_frame (frame
);
7608 /* Assume we are not echoing.
7609 (If we are, echo_now will override this.) */
7610 echo_message_buffer
= Qnil
;
7613 clear_message (1, 1);
7615 do_pending_window_change (0);
7616 echo_area_display (1);
7617 do_pending_window_change (0);
7618 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7619 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7624 /* Display a null-terminated echo area message M. If M is 0, clear
7625 out any existing message, and let the mini-buffer text show through.
7627 The buffer M must continue to exist until after the echo area gets
7628 cleared or some other message gets displayed there. Do not pass
7629 text that is stored in a Lisp string. Do not pass text in a buffer
7630 that was alloca'd. */
7636 message2 (m
, (m
? strlen (m
) : 0), 0);
7640 /* The non-logging counterpart of message1. */
7646 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7649 /* Display a message M which contains a single %s
7650 which gets replaced with STRING. */
7653 message_with_string (m
, string
, log
)
7658 CHECK_STRING (string
);
7664 if (noninteractive_need_newline
)
7665 putc ('\n', stderr
);
7666 noninteractive_need_newline
= 0;
7667 fprintf (stderr
, m
, SDATA (string
));
7668 if (cursor_in_echo_area
== 0)
7669 fprintf (stderr
, "\n");
7673 else if (INTERACTIVE
)
7675 /* The frame whose minibuffer we're going to display the message on.
7676 It may be larger than the selected frame, so we need
7677 to use its buffer, not the selected frame's buffer. */
7678 Lisp_Object mini_window
;
7679 struct frame
*f
, *sf
= SELECTED_FRAME ();
7681 /* Get the frame containing the minibuffer
7682 that the selected frame is using. */
7683 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7684 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7686 /* A null message buffer means that the frame hasn't really been
7687 initialized yet. Error messages get reported properly by
7688 cmd_error, so this must be just an informative message; toss it. */
7689 if (FRAME_MESSAGE_BUF (f
))
7691 Lisp_Object args
[2], message
;
7692 struct gcpro gcpro1
, gcpro2
;
7694 args
[0] = build_string (m
);
7695 args
[1] = message
= string
;
7696 GCPRO2 (args
[0], message
);
7699 message
= Fformat (2, args
);
7702 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7704 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7708 /* Print should start at the beginning of the message
7709 buffer next time. */
7710 message_buf_print
= 0;
7716 /* Dump an informative message to the minibuf. If M is 0, clear out
7717 any existing message, and let the mini-buffer text show through. */
7721 message (m
, a1
, a2
, a3
)
7723 EMACS_INT a1
, a2
, a3
;
7729 if (noninteractive_need_newline
)
7730 putc ('\n', stderr
);
7731 noninteractive_need_newline
= 0;
7732 fprintf (stderr
, m
, a1
, a2
, a3
);
7733 if (cursor_in_echo_area
== 0)
7734 fprintf (stderr
, "\n");
7738 else if (INTERACTIVE
)
7740 /* The frame whose mini-buffer we're going to display the message
7741 on. It may be larger than the selected frame, so we need to
7742 use its buffer, not the selected frame's buffer. */
7743 Lisp_Object mini_window
;
7744 struct frame
*f
, *sf
= SELECTED_FRAME ();
7746 /* Get the frame containing the mini-buffer
7747 that the selected frame is using. */
7748 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7749 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7751 /* A null message buffer means that the frame hasn't really been
7752 initialized yet. Error messages get reported properly by
7753 cmd_error, so this must be just an informative message; toss
7755 if (FRAME_MESSAGE_BUF (f
))
7766 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7767 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7769 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7770 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7772 #endif /* NO_ARG_ARRAY */
7774 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7779 /* Print should start at the beginning of the message
7780 buffer next time. */
7781 message_buf_print
= 0;
7787 /* The non-logging version of message. */
7790 message_nolog (m
, a1
, a2
, a3
)
7792 EMACS_INT a1
, a2
, a3
;
7794 Lisp_Object old_log_max
;
7795 old_log_max
= Vmessage_log_max
;
7796 Vmessage_log_max
= Qnil
;
7797 message (m
, a1
, a2
, a3
);
7798 Vmessage_log_max
= old_log_max
;
7802 /* Display the current message in the current mini-buffer. This is
7803 only called from error handlers in process.c, and is not time
7809 if (!NILP (echo_area_buffer
[0]))
7812 string
= Fcurrent_message ();
7813 message3 (string
, SBYTES (string
),
7814 !NILP (current_buffer
->enable_multibyte_characters
));
7819 /* Make sure echo area buffers in `echo_buffers' are live.
7820 If they aren't, make new ones. */
7823 ensure_echo_area_buffers ()
7827 for (i
= 0; i
< 2; ++i
)
7828 if (!BUFFERP (echo_buffer
[i
])
7829 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7832 Lisp_Object old_buffer
;
7835 old_buffer
= echo_buffer
[i
];
7836 sprintf (name
, " *Echo Area %d*", i
);
7837 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7838 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7840 for (j
= 0; j
< 2; ++j
)
7841 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7842 echo_area_buffer
[j
] = echo_buffer
[i
];
7847 /* Call FN with args A1..A4 with either the current or last displayed
7848 echo_area_buffer as current buffer.
7850 WHICH zero means use the current message buffer
7851 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7852 from echo_buffer[] and clear it.
7854 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7855 suitable buffer from echo_buffer[] and clear it.
7857 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
7858 that the current message becomes the last displayed one, make
7859 choose a suitable buffer for echo_area_buffer[0], and clear it.
7861 Value is what FN returns. */
7864 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7867 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7873 int this_one
, the_other
, clear_buffer_p
, rc
;
7874 int count
= SPECPDL_INDEX ();
7876 /* If buffers aren't live, make new ones. */
7877 ensure_echo_area_buffers ();
7882 this_one
= 0, the_other
= 1;
7884 this_one
= 1, the_other
= 0;
7887 this_one
= 0, the_other
= 1;
7890 /* We need a fresh one in case the current echo buffer equals
7891 the one containing the last displayed echo area message. */
7892 if (!NILP (echo_area_buffer
[this_one
])
7893 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
7894 echo_area_buffer
[this_one
] = Qnil
;
7897 /* Choose a suitable buffer from echo_buffer[] is we don't
7899 if (NILP (echo_area_buffer
[this_one
]))
7901 echo_area_buffer
[this_one
]
7902 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7903 ? echo_buffer
[the_other
]
7904 : echo_buffer
[this_one
]);
7908 buffer
= echo_area_buffer
[this_one
];
7910 /* Don't get confused by reusing the buffer used for echoing
7911 for a different purpose. */
7912 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7915 record_unwind_protect (unwind_with_echo_area_buffer
,
7916 with_echo_area_buffer_unwind_data (w
));
7918 /* Make the echo area buffer current. Note that for display
7919 purposes, it is not necessary that the displayed window's buffer
7920 == current_buffer, except for text property lookup. So, let's
7921 only set that buffer temporarily here without doing a full
7922 Fset_window_buffer. We must also change w->pointm, though,
7923 because otherwise an assertions in unshow_buffer fails, and Emacs
7925 set_buffer_internal_1 (XBUFFER (buffer
));
7929 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7932 current_buffer
->undo_list
= Qt
;
7933 current_buffer
->read_only
= Qnil
;
7934 specbind (Qinhibit_read_only
, Qt
);
7935 specbind (Qinhibit_modification_hooks
, Qt
);
7937 if (clear_buffer_p
&& Z
> BEG
)
7940 xassert (BEGV
>= BEG
);
7941 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7943 rc
= fn (a1
, a2
, a3
, a4
);
7945 xassert (BEGV
>= BEG
);
7946 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7948 unbind_to (count
, Qnil
);
7953 /* Save state that should be preserved around the call to the function
7954 FN called in with_echo_area_buffer. */
7957 with_echo_area_buffer_unwind_data (w
)
7963 /* Reduce consing by keeping one vector in
7964 Vwith_echo_area_save_vector. */
7965 vector
= Vwith_echo_area_save_vector
;
7966 Vwith_echo_area_save_vector
= Qnil
;
7969 vector
= Fmake_vector (make_number (7), Qnil
);
7971 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7972 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7973 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7977 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7978 AREF (vector
, i
) = w
->buffer
; ++i
;
7979 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7980 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7985 for (; i
< end
; ++i
)
7986 AREF (vector
, i
) = Qnil
;
7989 xassert (i
== ASIZE (vector
));
7994 /* Restore global state from VECTOR which was created by
7995 with_echo_area_buffer_unwind_data. */
7998 unwind_with_echo_area_buffer (vector
)
8001 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8002 Vdeactivate_mark
= AREF (vector
, 1);
8003 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8005 if (WINDOWP (AREF (vector
, 3)))
8008 Lisp_Object buffer
, charpos
, bytepos
;
8010 w
= XWINDOW (AREF (vector
, 3));
8011 buffer
= AREF (vector
, 4);
8012 charpos
= AREF (vector
, 5);
8013 bytepos
= AREF (vector
, 6);
8016 set_marker_both (w
->pointm
, buffer
,
8017 XFASTINT (charpos
), XFASTINT (bytepos
));
8020 Vwith_echo_area_save_vector
= vector
;
8025 /* Set up the echo area for use by print functions. MULTIBYTE_P
8026 non-zero means we will print multibyte. */
8029 setup_echo_area_for_printing (multibyte_p
)
8032 /* If we can't find an echo area any more, exit. */
8033 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8036 ensure_echo_area_buffers ();
8038 if (!message_buf_print
)
8040 /* A message has been output since the last time we printed.
8041 Choose a fresh echo area buffer. */
8042 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8043 echo_area_buffer
[0] = echo_buffer
[1];
8045 echo_area_buffer
[0] = echo_buffer
[0];
8047 /* Switch to that buffer and clear it. */
8048 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8049 current_buffer
->truncate_lines
= Qnil
;
8053 int count
= SPECPDL_INDEX ();
8054 specbind (Qinhibit_read_only
, Qt
);
8055 /* Note that undo recording is always disabled. */
8057 unbind_to (count
, Qnil
);
8059 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8061 /* Set up the buffer for the multibyteness we need. */
8063 != !NILP (current_buffer
->enable_multibyte_characters
))
8064 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8066 /* Raise the frame containing the echo area. */
8067 if (minibuffer_auto_raise
)
8069 struct frame
*sf
= SELECTED_FRAME ();
8070 Lisp_Object mini_window
;
8071 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8072 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8075 message_log_maybe_newline ();
8076 message_buf_print
= 1;
8080 if (NILP (echo_area_buffer
[0]))
8082 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8083 echo_area_buffer
[0] = echo_buffer
[1];
8085 echo_area_buffer
[0] = echo_buffer
[0];
8088 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8090 /* Someone switched buffers between print requests. */
8091 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8092 current_buffer
->truncate_lines
= Qnil
;
8098 /* Display an echo area message in window W. Value is non-zero if W's
8099 height is changed. If display_last_displayed_message_p is
8100 non-zero, display the message that was last displayed, otherwise
8101 display the current message. */
8104 display_echo_area (w
)
8107 int i
, no_message_p
, window_height_changed_p
, count
;
8109 /* Temporarily disable garbage collections while displaying the echo
8110 area. This is done because a GC can print a message itself.
8111 That message would modify the echo area buffer's contents while a
8112 redisplay of the buffer is going on, and seriously confuse
8114 count
= inhibit_garbage_collection ();
8116 /* If there is no message, we must call display_echo_area_1
8117 nevertheless because it resizes the window. But we will have to
8118 reset the echo_area_buffer in question to nil at the end because
8119 with_echo_area_buffer will sets it to an empty buffer. */
8120 i
= display_last_displayed_message_p
? 1 : 0;
8121 no_message_p
= NILP (echo_area_buffer
[i
]);
8123 window_height_changed_p
8124 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8125 display_echo_area_1
,
8126 (EMACS_INT
) w
, Qnil
, 0, 0);
8129 echo_area_buffer
[i
] = Qnil
;
8131 unbind_to (count
, Qnil
);
8132 return window_height_changed_p
;
8136 /* Helper for display_echo_area. Display the current buffer which
8137 contains the current echo area message in window W, a mini-window,
8138 a pointer to which is passed in A1. A2..A4 are currently not used.
8139 Change the height of W so that all of the message is displayed.
8140 Value is non-zero if height of W was changed. */
8143 display_echo_area_1 (a1
, a2
, a3
, a4
)
8148 struct window
*w
= (struct window
*) a1
;
8150 struct text_pos start
;
8151 int window_height_changed_p
= 0;
8153 /* Do this before displaying, so that we have a large enough glyph
8154 matrix for the display. If we can't get enough space for the
8155 whole text, display the last N lines. That works by setting w->start. */
8156 window_height_changed_p
= resize_mini_window (w
, 0);
8158 /* Use the starting position chosen by resize_mini_window. */
8159 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8162 clear_glyph_matrix (w
->desired_matrix
);
8163 XSETWINDOW (window
, w
);
8164 try_window (window
, start
, 0);
8166 return window_height_changed_p
;
8170 /* Resize the echo area window to exactly the size needed for the
8171 currently displayed message, if there is one. If a mini-buffer
8172 is active, don't shrink it. */
8175 resize_echo_area_exactly ()
8177 if (BUFFERP (echo_area_buffer
[0])
8178 && WINDOWP (echo_area_window
))
8180 struct window
*w
= XWINDOW (echo_area_window
);
8182 Lisp_Object resize_exactly
;
8184 if (minibuf_level
== 0)
8185 resize_exactly
= Qt
;
8187 resize_exactly
= Qnil
;
8189 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8190 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8193 ++windows_or_buffers_changed
;
8194 ++update_mode_lines
;
8195 redisplay_internal (0);
8201 /* Callback function for with_echo_area_buffer, when used from
8202 resize_echo_area_exactly. A1 contains a pointer to the window to
8203 resize, EXACTLY non-nil means resize the mini-window exactly to the
8204 size of the text displayed. A3 and A4 are not used. Value is what
8205 resize_mini_window returns. */
8208 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8210 Lisp_Object exactly
;
8213 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8217 /* Resize mini-window W to fit the size of its contents. EXACT:P
8218 means size the window exactly to the size needed. Otherwise, it's
8219 only enlarged until W's buffer is empty.
8221 Set W->start to the right place to begin display. If the whole
8222 contents fit, start at the beginning. Otherwise, start so as
8223 to make the end of the contents appear. This is particularly
8224 important for y-or-n-p, but seems desirable generally.
8226 Value is non-zero if the window height has been changed. */
8229 resize_mini_window (w
, exact_p
)
8233 struct frame
*f
= XFRAME (w
->frame
);
8234 int window_height_changed_p
= 0;
8236 xassert (MINI_WINDOW_P (w
));
8238 /* By default, start display at the beginning. */
8239 set_marker_both (w
->start
, w
->buffer
,
8240 BUF_BEGV (XBUFFER (w
->buffer
)),
8241 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8243 /* Don't resize windows while redisplaying a window; it would
8244 confuse redisplay functions when the size of the window they are
8245 displaying changes from under them. Such a resizing can happen,
8246 for instance, when which-func prints a long message while
8247 we are running fontification-functions. We're running these
8248 functions with safe_call which binds inhibit-redisplay to t. */
8249 if (!NILP (Vinhibit_redisplay
))
8252 /* Nil means don't try to resize. */
8253 if (NILP (Vresize_mini_windows
)
8254 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8257 if (!FRAME_MINIBUF_ONLY_P (f
))
8260 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8261 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8262 int height
, max_height
;
8263 int unit
= FRAME_LINE_HEIGHT (f
);
8264 struct text_pos start
;
8265 struct buffer
*old_current_buffer
= NULL
;
8267 if (current_buffer
!= XBUFFER (w
->buffer
))
8269 old_current_buffer
= current_buffer
;
8270 set_buffer_internal (XBUFFER (w
->buffer
));
8273 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8275 /* Compute the max. number of lines specified by the user. */
8276 if (FLOATP (Vmax_mini_window_height
))
8277 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8278 else if (INTEGERP (Vmax_mini_window_height
))
8279 max_height
= XINT (Vmax_mini_window_height
);
8281 max_height
= total_height
/ 4;
8283 /* Correct that max. height if it's bogus. */
8284 max_height
= max (1, max_height
);
8285 max_height
= min (total_height
, max_height
);
8287 /* Find out the height of the text in the window. */
8288 if (it
.truncate_lines_p
)
8293 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8294 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8295 height
= it
.current_y
+ last_height
;
8297 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8298 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8299 height
= (height
+ unit
- 1) / unit
;
8302 /* Compute a suitable window start. */
8303 if (height
> max_height
)
8305 height
= max_height
;
8306 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8307 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8308 start
= it
.current
.pos
;
8311 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8312 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8314 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8316 /* Let it grow only, until we display an empty message, in which
8317 case the window shrinks again. */
8318 if (height
> WINDOW_TOTAL_LINES (w
))
8320 int old_height
= WINDOW_TOTAL_LINES (w
);
8321 freeze_window_starts (f
, 1);
8322 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8323 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8325 else if (height
< WINDOW_TOTAL_LINES (w
)
8326 && (exact_p
|| BEGV
== ZV
))
8328 int old_height
= WINDOW_TOTAL_LINES (w
);
8329 freeze_window_starts (f
, 0);
8330 shrink_mini_window (w
);
8331 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8336 /* Always resize to exact size needed. */
8337 if (height
> WINDOW_TOTAL_LINES (w
))
8339 int old_height
= WINDOW_TOTAL_LINES (w
);
8340 freeze_window_starts (f
, 1);
8341 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8342 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8344 else if (height
< WINDOW_TOTAL_LINES (w
))
8346 int old_height
= WINDOW_TOTAL_LINES (w
);
8347 freeze_window_starts (f
, 0);
8348 shrink_mini_window (w
);
8352 freeze_window_starts (f
, 1);
8353 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8356 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8360 if (old_current_buffer
)
8361 set_buffer_internal (old_current_buffer
);
8364 return window_height_changed_p
;
8368 /* Value is the current message, a string, or nil if there is no
8376 if (NILP (echo_area_buffer
[0]))
8380 with_echo_area_buffer (0, 0, current_message_1
,
8381 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8383 echo_area_buffer
[0] = Qnil
;
8391 current_message_1 (a1
, a2
, a3
, a4
)
8396 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8399 *msg
= make_buffer_string (BEG
, Z
, 1);
8406 /* Push the current message on Vmessage_stack for later restauration
8407 by restore_message. Value is non-zero if the current message isn't
8408 empty. This is a relatively infrequent operation, so it's not
8409 worth optimizing. */
8415 msg
= current_message ();
8416 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8417 return STRINGP (msg
);
8421 /* Restore message display from the top of Vmessage_stack. */
8428 xassert (CONSP (Vmessage_stack
));
8429 msg
= XCAR (Vmessage_stack
);
8431 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8433 message3_nolog (msg
, 0, 0);
8437 /* Handler for record_unwind_protect calling pop_message. */
8440 pop_message_unwind (dummy
)
8447 /* Pop the top-most entry off Vmessage_stack. */
8452 xassert (CONSP (Vmessage_stack
));
8453 Vmessage_stack
= XCDR (Vmessage_stack
);
8457 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8458 exits. If the stack is not empty, we have a missing pop_message
8462 check_message_stack ()
8464 if (!NILP (Vmessage_stack
))
8469 /* Truncate to NCHARS what will be displayed in the echo area the next
8470 time we display it---but don't redisplay it now. */
8473 truncate_echo_area (nchars
)
8477 echo_area_buffer
[0] = Qnil
;
8478 /* A null message buffer means that the frame hasn't really been
8479 initialized yet. Error messages get reported properly by
8480 cmd_error, so this must be just an informative message; toss it. */
8481 else if (!noninteractive
8483 && !NILP (echo_area_buffer
[0]))
8485 struct frame
*sf
= SELECTED_FRAME ();
8486 if (FRAME_MESSAGE_BUF (sf
))
8487 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8492 /* Helper function for truncate_echo_area. Truncate the current
8493 message to at most NCHARS characters. */
8496 truncate_message_1 (nchars
, a2
, a3
, a4
)
8501 if (BEG
+ nchars
< Z
)
8502 del_range (BEG
+ nchars
, Z
);
8504 echo_area_buffer
[0] = Qnil
;
8509 /* Set the current message to a substring of S or STRING.
8511 If STRING is a Lisp string, set the message to the first NBYTES
8512 bytes from STRING. NBYTES zero means use the whole string. If
8513 STRING is multibyte, the message will be displayed multibyte.
8515 If S is not null, set the message to the first LEN bytes of S. LEN
8516 zero means use the whole string. MULTIBYTE_P non-zero means S is
8517 multibyte. Display the message multibyte in that case.
8519 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8520 to t before calling set_message_1 (which calls insert).
8524 set_message (s
, string
, nbytes
, multibyte_p
)
8527 int nbytes
, multibyte_p
;
8529 message_enable_multibyte
8530 = ((s
&& multibyte_p
)
8531 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8533 with_echo_area_buffer (0, -1, set_message_1
,
8534 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8535 message_buf_print
= 0;
8536 help_echo_showing_p
= 0;
8540 /* Helper function for set_message. Arguments have the same meaning
8541 as there, with A1 corresponding to S and A2 corresponding to STRING
8542 This function is called with the echo area buffer being
8546 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8549 EMACS_INT nbytes
, multibyte_p
;
8551 const char *s
= (const char *) a1
;
8552 Lisp_Object string
= a2
;
8554 /* Change multibyteness of the echo buffer appropriately. */
8555 if (message_enable_multibyte
8556 != !NILP (current_buffer
->enable_multibyte_characters
))
8557 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8559 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8561 /* Insert new message at BEG. */
8562 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8564 if (STRINGP (string
))
8569 nbytes
= SBYTES (string
);
8570 nchars
= string_byte_to_char (string
, nbytes
);
8572 /* This function takes care of single/multibyte conversion. We
8573 just have to ensure that the echo area buffer has the right
8574 setting of enable_multibyte_characters. */
8575 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8580 nbytes
= strlen (s
);
8582 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8584 /* Convert from multi-byte to single-byte. */
8586 unsigned char work
[1];
8588 /* Convert a multibyte string to single-byte. */
8589 for (i
= 0; i
< nbytes
; i
+= n
)
8591 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8592 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
8594 : multibyte_char_to_unibyte (c
, Qnil
));
8595 insert_1_both (work
, 1, 1, 1, 0, 0);
8598 else if (!multibyte_p
8599 && !NILP (current_buffer
->enable_multibyte_characters
))
8601 /* Convert from single-byte to multi-byte. */
8603 const unsigned char *msg
= (const unsigned char *) s
;
8604 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8606 /* Convert a single-byte string to multibyte. */
8607 for (i
= 0; i
< nbytes
; i
++)
8609 c
= unibyte_char_to_multibyte (msg
[i
]);
8610 n
= CHAR_STRING (c
, str
);
8611 insert_1_both (str
, 1, n
, 1, 0, 0);
8615 insert_1 (s
, nbytes
, 1, 0, 0);
8622 /* Clear messages. CURRENT_P non-zero means clear the current
8623 message. LAST_DISPLAYED_P non-zero means clear the message
8627 clear_message (current_p
, last_displayed_p
)
8628 int current_p
, last_displayed_p
;
8632 echo_area_buffer
[0] = Qnil
;
8633 message_cleared_p
= 1;
8636 if (last_displayed_p
)
8637 echo_area_buffer
[1] = Qnil
;
8639 message_buf_print
= 0;
8642 /* Clear garbaged frames.
8644 This function is used where the old redisplay called
8645 redraw_garbaged_frames which in turn called redraw_frame which in
8646 turn called clear_frame. The call to clear_frame was a source of
8647 flickering. I believe a clear_frame is not necessary. It should
8648 suffice in the new redisplay to invalidate all current matrices,
8649 and ensure a complete redisplay of all windows. */
8652 clear_garbaged_frames ()
8656 Lisp_Object tail
, frame
;
8657 int changed_count
= 0;
8659 FOR_EACH_FRAME (tail
, frame
)
8661 struct frame
*f
= XFRAME (frame
);
8663 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8667 Fredraw_frame (frame
);
8668 f
->force_flush_display_p
= 1;
8670 clear_current_matrices (f
);
8679 ++windows_or_buffers_changed
;
8684 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8685 is non-zero update selected_frame. Value is non-zero if the
8686 mini-windows height has been changed. */
8689 echo_area_display (update_frame_p
)
8692 Lisp_Object mini_window
;
8695 int window_height_changed_p
= 0;
8696 struct frame
*sf
= SELECTED_FRAME ();
8698 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8699 w
= XWINDOW (mini_window
);
8700 f
= XFRAME (WINDOW_FRAME (w
));
8702 /* Don't display if frame is invisible or not yet initialized. */
8703 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8706 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8708 #ifdef HAVE_WINDOW_SYSTEM
8709 /* When Emacs starts, selected_frame may be the initial terminal
8710 frame. If we let this through, a message would be displayed on
8712 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
8714 #endif /* HAVE_WINDOW_SYSTEM */
8717 /* Redraw garbaged frames. */
8719 clear_garbaged_frames ();
8721 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8723 echo_area_window
= mini_window
;
8724 window_height_changed_p
= display_echo_area (w
);
8725 w
->must_be_updated_p
= 1;
8727 /* Update the display, unless called from redisplay_internal.
8728 Also don't update the screen during redisplay itself. The
8729 update will happen at the end of redisplay, and an update
8730 here could cause confusion. */
8731 if (update_frame_p
&& !redisplaying_p
)
8735 /* If the display update has been interrupted by pending
8736 input, update mode lines in the frame. Due to the
8737 pending input, it might have been that redisplay hasn't
8738 been called, so that mode lines above the echo area are
8739 garbaged. This looks odd, so we prevent it here. */
8740 if (!display_completed
)
8741 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8743 if (window_height_changed_p
8744 /* Don't do this if Emacs is shutting down. Redisplay
8745 needs to run hooks. */
8746 && !NILP (Vrun_hooks
))
8748 /* Must update other windows. Likewise as in other
8749 cases, don't let this update be interrupted by
8751 int count
= SPECPDL_INDEX ();
8752 specbind (Qredisplay_dont_pause
, Qt
);
8753 windows_or_buffers_changed
= 1;
8754 redisplay_internal (0);
8755 unbind_to (count
, Qnil
);
8757 else if (FRAME_WINDOW_P (f
) && n
== 0)
8759 /* Window configuration is the same as before.
8760 Can do with a display update of the echo area,
8761 unless we displayed some mode lines. */
8762 update_single_window (w
, 1);
8763 FRAME_RIF (f
)->flush_display (f
);
8766 update_frame (f
, 1, 1);
8768 /* If cursor is in the echo area, make sure that the next
8769 redisplay displays the minibuffer, so that the cursor will
8770 be replaced with what the minibuffer wants. */
8771 if (cursor_in_echo_area
)
8772 ++windows_or_buffers_changed
;
8775 else if (!EQ (mini_window
, selected_window
))
8776 windows_or_buffers_changed
++;
8778 /* Last displayed message is now the current message. */
8779 echo_area_buffer
[1] = echo_area_buffer
[0];
8780 /* Inform read_char that we're not echoing. */
8781 echo_message_buffer
= Qnil
;
8783 /* Prevent redisplay optimization in redisplay_internal by resetting
8784 this_line_start_pos. This is done because the mini-buffer now
8785 displays the message instead of its buffer text. */
8786 if (EQ (mini_window
, selected_window
))
8787 CHARPOS (this_line_start_pos
) = 0;
8789 return window_height_changed_p
;
8794 /***********************************************************************
8795 Mode Lines and Frame Titles
8796 ***********************************************************************/
8798 /* A buffer for constructing non-propertized mode-line strings and
8799 frame titles in it; allocated from the heap in init_xdisp and
8800 resized as needed in store_mode_line_noprop_char. */
8802 static char *mode_line_noprop_buf
;
8804 /* The buffer's end, and a current output position in it. */
8806 static char *mode_line_noprop_buf_end
;
8807 static char *mode_line_noprop_ptr
;
8809 #define MODE_LINE_NOPROP_LEN(start) \
8810 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8813 MODE_LINE_DISPLAY
= 0,
8819 /* Alist that caches the results of :propertize.
8820 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8821 static Lisp_Object mode_line_proptrans_alist
;
8823 /* List of strings making up the mode-line. */
8824 static Lisp_Object mode_line_string_list
;
8826 /* Base face property when building propertized mode line string. */
8827 static Lisp_Object mode_line_string_face
;
8828 static Lisp_Object mode_line_string_face_prop
;
8831 /* Unwind data for mode line strings */
8833 static Lisp_Object Vmode_line_unwind_vector
;
8836 format_mode_line_unwind_data (obuf
, save_proptrans
)
8837 struct buffer
*obuf
;
8841 /* Reduce consing by keeping one vector in
8842 Vwith_echo_area_save_vector. */
8843 vector
= Vmode_line_unwind_vector
;
8844 Vmode_line_unwind_vector
= Qnil
;
8847 vector
= Fmake_vector (make_number (7), Qnil
);
8849 AREF (vector
, 0) = make_number (mode_line_target
);
8850 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8851 AREF (vector
, 2) = mode_line_string_list
;
8852 AREF (vector
, 3) = (save_proptrans
? mode_line_proptrans_alist
: Qt
);
8853 AREF (vector
, 4) = mode_line_string_face
;
8854 AREF (vector
, 5) = mode_line_string_face_prop
;
8857 XSETBUFFER (AREF (vector
, 6), obuf
);
8859 AREF (vector
, 6) = Qnil
;
8865 unwind_format_mode_line (vector
)
8868 mode_line_target
= XINT (AREF (vector
, 0));
8869 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8870 mode_line_string_list
= AREF (vector
, 2);
8871 if (! EQ (AREF (vector
, 3), Qt
))
8872 mode_line_proptrans_alist
= AREF (vector
, 3);
8873 mode_line_string_face
= AREF (vector
, 4);
8874 mode_line_string_face_prop
= AREF (vector
, 5);
8876 if (!NILP (AREF (vector
, 6)))
8878 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8879 AREF (vector
, 6) = Qnil
;
8882 Vmode_line_unwind_vector
= vector
;
8887 /* Store a single character C for the frame title in mode_line_noprop_buf.
8888 Re-allocate mode_line_noprop_buf if necessary. */
8892 store_mode_line_noprop_char (char c
)
8894 store_mode_line_noprop_char (c
)
8898 /* If output position has reached the end of the allocated buffer,
8899 double the buffer's size. */
8900 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8902 int len
= MODE_LINE_NOPROP_LEN (0);
8903 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8904 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8905 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8906 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8909 *mode_line_noprop_ptr
++ = c
;
8913 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8914 mode_line_noprop_ptr. STR is the string to store. Do not copy
8915 characters that yield more columns than PRECISION; PRECISION <= 0
8916 means copy the whole string. Pad with spaces until FIELD_WIDTH
8917 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8918 pad. Called from display_mode_element when it is used to build a
8922 store_mode_line_noprop (str
, field_width
, precision
)
8923 const unsigned char *str
;
8924 int field_width
, precision
;
8929 /* Copy at most PRECISION chars from STR. */
8930 nbytes
= strlen (str
);
8931 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8933 store_mode_line_noprop_char (*str
++);
8935 /* Fill up with spaces until FIELD_WIDTH reached. */
8936 while (field_width
> 0
8939 store_mode_line_noprop_char (' ');
8946 /***********************************************************************
8948 ***********************************************************************/
8950 #ifdef HAVE_WINDOW_SYSTEM
8952 /* Set the title of FRAME, if it has changed. The title format is
8953 Vicon_title_format if FRAME is iconified, otherwise it is
8954 frame_title_format. */
8957 x_consider_frame_title (frame
)
8960 struct frame
*f
= XFRAME (frame
);
8962 if (FRAME_WINDOW_P (f
)
8963 || FRAME_MINIBUF_ONLY_P (f
)
8964 || f
->explicit_name
)
8966 /* Do we have more than one visible frame on this X display? */
8973 int count
= SPECPDL_INDEX ();
8975 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8977 Lisp_Object other_frame
= XCAR (tail
);
8978 struct frame
*tf
= XFRAME (other_frame
);
8981 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8982 && !FRAME_MINIBUF_ONLY_P (tf
)
8983 && !EQ (other_frame
, tip_frame
)
8984 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8988 /* Set global variable indicating that multiple frames exist. */
8989 multiple_frames
= CONSP (tail
);
8991 /* Switch to the buffer of selected window of the frame. Set up
8992 mode_line_target so that display_mode_element will output into
8993 mode_line_noprop_buf; then display the title. */
8994 record_unwind_protect (unwind_format_mode_line
,
8995 format_mode_line_unwind_data (current_buffer
, 0));
8997 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8998 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9000 mode_line_target
= MODE_LINE_TITLE
;
9001 title_start
= MODE_LINE_NOPROP_LEN (0);
9002 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9003 NULL
, DEFAULT_FACE_ID
);
9004 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9005 len
= MODE_LINE_NOPROP_LEN (title_start
);
9006 title
= mode_line_noprop_buf
+ title_start
;
9007 unbind_to (count
, Qnil
);
9009 /* Set the title only if it's changed. This avoids consing in
9010 the common case where it hasn't. (If it turns out that we've
9011 already wasted too much time by walking through the list with
9012 display_mode_element, then we might need to optimize at a
9013 higher level than this.) */
9014 if (! STRINGP (f
->name
)
9015 || SBYTES (f
->name
) != len
9016 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9017 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9021 #endif /* not HAVE_WINDOW_SYSTEM */
9026 /***********************************************************************
9028 ***********************************************************************/
9031 /* Prepare for redisplay by updating menu-bar item lists when
9032 appropriate. This can call eval. */
9035 prepare_menu_bars ()
9038 struct gcpro gcpro1
, gcpro2
;
9040 Lisp_Object tooltip_frame
;
9042 #ifdef HAVE_WINDOW_SYSTEM
9043 tooltip_frame
= tip_frame
;
9045 tooltip_frame
= Qnil
;
9048 /* Update all frame titles based on their buffer names, etc. We do
9049 this before the menu bars so that the buffer-menu will show the
9050 up-to-date frame titles. */
9051 #ifdef HAVE_WINDOW_SYSTEM
9052 if (windows_or_buffers_changed
|| update_mode_lines
)
9054 Lisp_Object tail
, frame
;
9056 FOR_EACH_FRAME (tail
, frame
)
9059 if (!EQ (frame
, tooltip_frame
)
9060 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9061 x_consider_frame_title (frame
);
9064 #endif /* HAVE_WINDOW_SYSTEM */
9066 /* Update the menu bar item lists, if appropriate. This has to be
9067 done before any actual redisplay or generation of display lines. */
9068 all_windows
= (update_mode_lines
9069 || buffer_shared
> 1
9070 || windows_or_buffers_changed
);
9073 Lisp_Object tail
, frame
;
9074 int count
= SPECPDL_INDEX ();
9075 /* 1 means that update_menu_bar has run its hooks
9076 so any further calls to update_menu_bar shouldn't do so again. */
9077 int menu_bar_hooks_run
= 0;
9079 record_unwind_save_match_data ();
9081 FOR_EACH_FRAME (tail
, frame
)
9085 /* Ignore tooltip frame. */
9086 if (EQ (frame
, tooltip_frame
))
9089 /* If a window on this frame changed size, report that to
9090 the user and clear the size-change flag. */
9091 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9093 Lisp_Object functions
;
9095 /* Clear flag first in case we get an error below. */
9096 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9097 functions
= Vwindow_size_change_functions
;
9098 GCPRO2 (tail
, functions
);
9100 while (CONSP (functions
))
9102 call1 (XCAR (functions
), frame
);
9103 functions
= XCDR (functions
);
9109 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9110 #ifdef HAVE_WINDOW_SYSTEM
9111 update_tool_bar (f
, 0);
9113 mac_update_title_bar (f
, 0);
9119 unbind_to (count
, Qnil
);
9123 struct frame
*sf
= SELECTED_FRAME ();
9124 update_menu_bar (sf
, 1, 0);
9125 #ifdef HAVE_WINDOW_SYSTEM
9126 update_tool_bar (sf
, 1);
9128 mac_update_title_bar (sf
, 1);
9133 /* Motif needs this. See comment in xmenu.c. Turn it off when
9134 pending_menu_activation is not defined. */
9135 #ifdef USE_X_TOOLKIT
9136 pending_menu_activation
= 0;
9141 /* Update the menu bar item list for frame F. This has to be done
9142 before we start to fill in any display lines, because it can call
9145 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9147 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9148 already ran the menu bar hooks for this redisplay, so there
9149 is no need to run them again. The return value is the
9150 updated value of this flag, to pass to the next call. */
9153 update_menu_bar (f
, save_match_data
, hooks_run
)
9155 int save_match_data
;
9159 register struct window
*w
;
9161 /* If called recursively during a menu update, do nothing. This can
9162 happen when, for instance, an activate-menubar-hook causes a
9164 if (inhibit_menubar_update
)
9167 window
= FRAME_SELECTED_WINDOW (f
);
9168 w
= XWINDOW (window
);
9170 #if 0 /* The if statement below this if statement used to include the
9171 condition !NILP (w->update_mode_line), rather than using
9172 update_mode_lines directly, and this if statement may have
9173 been added to make that condition work. Now the if
9174 statement below matches its comment, this isn't needed. */
9175 if (update_mode_lines
)
9176 w
->update_mode_line
= Qt
;
9179 if (FRAME_WINDOW_P (f
)
9181 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9182 || defined (USE_GTK)
9183 FRAME_EXTERNAL_MENU_BAR (f
)
9185 FRAME_MENU_BAR_LINES (f
) > 0
9187 : FRAME_MENU_BAR_LINES (f
) > 0)
9189 /* If the user has switched buffers or windows, we need to
9190 recompute to reflect the new bindings. But we'll
9191 recompute when update_mode_lines is set too; that means
9192 that people can use force-mode-line-update to request
9193 that the menu bar be recomputed. The adverse effect on
9194 the rest of the redisplay algorithm is about the same as
9195 windows_or_buffers_changed anyway. */
9196 if (windows_or_buffers_changed
9197 /* This used to test w->update_mode_line, but we believe
9198 there is no need to recompute the menu in that case. */
9199 || update_mode_lines
9200 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9201 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9202 != !NILP (w
->last_had_star
))
9203 || ((!NILP (Vtransient_mark_mode
)
9204 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9205 != !NILP (w
->region_showing
)))
9207 struct buffer
*prev
= current_buffer
;
9208 int count
= SPECPDL_INDEX ();
9210 specbind (Qinhibit_menubar_update
, Qt
);
9212 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9213 if (save_match_data
)
9214 record_unwind_save_match_data ();
9215 if (NILP (Voverriding_local_map_menu_flag
))
9217 specbind (Qoverriding_terminal_local_map
, Qnil
);
9218 specbind (Qoverriding_local_map
, Qnil
);
9223 /* Run the Lucid hook. */
9224 safe_run_hooks (Qactivate_menubar_hook
);
9226 /* If it has changed current-menubar from previous value,
9227 really recompute the menu-bar from the value. */
9228 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9229 call0 (Qrecompute_lucid_menubar
);
9231 safe_run_hooks (Qmenu_bar_update_hook
);
9236 XSETFRAME (Vmenu_updating_frame
, f
);
9237 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9239 /* Redisplay the menu bar in case we changed it. */
9240 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9241 || defined (USE_GTK)
9242 if (FRAME_WINDOW_P (f
))
9245 /* All frames on Mac OS share the same menubar. So only
9246 the selected frame should be allowed to set it. */
9247 if (f
== SELECTED_FRAME ())
9249 set_frame_menubar (f
, 0, 0);
9252 /* On a terminal screen, the menu bar is an ordinary screen
9253 line, and this makes it get updated. */
9254 w
->update_mode_line
= Qt
;
9255 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9256 /* In the non-toolkit version, the menu bar is an ordinary screen
9257 line, and this makes it get updated. */
9258 w
->update_mode_line
= Qt
;
9259 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9261 unbind_to (count
, Qnil
);
9262 set_buffer_internal_1 (prev
);
9271 /***********************************************************************
9273 ***********************************************************************/
9275 #ifdef HAVE_WINDOW_SYSTEM
9278 Nominal cursor position -- where to draw output.
9279 HPOS and VPOS are window relative glyph matrix coordinates.
9280 X and Y are window relative pixel coordinates. */
9282 struct cursor_pos output_cursor
;
9286 Set the global variable output_cursor to CURSOR. All cursor
9287 positions are relative to updated_window. */
9290 set_output_cursor (cursor
)
9291 struct cursor_pos
*cursor
;
9293 output_cursor
.hpos
= cursor
->hpos
;
9294 output_cursor
.vpos
= cursor
->vpos
;
9295 output_cursor
.x
= cursor
->x
;
9296 output_cursor
.y
= cursor
->y
;
9301 Set a nominal cursor position.
9303 HPOS and VPOS are column/row positions in a window glyph matrix. X
9304 and Y are window text area relative pixel positions.
9306 If this is done during an update, updated_window will contain the
9307 window that is being updated and the position is the future output
9308 cursor position for that window. If updated_window is null, use
9309 selected_window and display the cursor at the given position. */
9312 x_cursor_to (vpos
, hpos
, y
, x
)
9313 int vpos
, hpos
, y
, x
;
9317 /* If updated_window is not set, work on selected_window. */
9321 w
= XWINDOW (selected_window
);
9323 /* Set the output cursor. */
9324 output_cursor
.hpos
= hpos
;
9325 output_cursor
.vpos
= vpos
;
9326 output_cursor
.x
= x
;
9327 output_cursor
.y
= y
;
9329 /* If not called as part of an update, really display the cursor.
9330 This will also set the cursor position of W. */
9331 if (updated_window
== NULL
)
9334 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9335 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
9336 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
9341 #endif /* HAVE_WINDOW_SYSTEM */
9344 /***********************************************************************
9346 ***********************************************************************/
9348 #ifdef HAVE_WINDOW_SYSTEM
9350 /* Where the mouse was last time we reported a mouse event. */
9352 FRAME_PTR last_mouse_frame
;
9354 /* Tool-bar item index of the item on which a mouse button was pressed
9357 int last_tool_bar_item
;
9360 /* Update the tool-bar item list for frame F. This has to be done
9361 before we start to fill in any display lines. Called from
9362 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9363 and restore it here. */
9366 update_tool_bar (f
, save_match_data
)
9368 int save_match_data
;
9371 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9373 int do_update
= WINDOWP (f
->tool_bar_window
)
9374 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9382 window
= FRAME_SELECTED_WINDOW (f
);
9383 w
= XWINDOW (window
);
9385 /* If the user has switched buffers or windows, we need to
9386 recompute to reflect the new bindings. But we'll
9387 recompute when update_mode_lines is set too; that means
9388 that people can use force-mode-line-update to request
9389 that the menu bar be recomputed. The adverse effect on
9390 the rest of the redisplay algorithm is about the same as
9391 windows_or_buffers_changed anyway. */
9392 if (windows_or_buffers_changed
9393 || !NILP (w
->update_mode_line
)
9394 || update_mode_lines
9395 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9396 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9397 != !NILP (w
->last_had_star
))
9398 || ((!NILP (Vtransient_mark_mode
)
9399 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9400 != !NILP (w
->region_showing
)))
9402 struct buffer
*prev
= current_buffer
;
9403 int count
= SPECPDL_INDEX ();
9404 Lisp_Object new_tool_bar
;
9406 struct gcpro gcpro1
;
9408 /* Set current_buffer to the buffer of the selected
9409 window of the frame, so that we get the right local
9411 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9413 /* Save match data, if we must. */
9414 if (save_match_data
)
9415 record_unwind_save_match_data ();
9417 /* Make sure that we don't accidentally use bogus keymaps. */
9418 if (NILP (Voverriding_local_map_menu_flag
))
9420 specbind (Qoverriding_terminal_local_map
, Qnil
);
9421 specbind (Qoverriding_local_map
, Qnil
);
9424 GCPRO1 (new_tool_bar
);
9426 /* Build desired tool-bar items from keymaps. */
9427 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9430 /* Redisplay the tool-bar if we changed it. */
9431 if (new_n_tool_bar
!= f
->n_tool_bar_items
9432 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9434 /* Redisplay that happens asynchronously due to an expose event
9435 may access f->tool_bar_items. Make sure we update both
9436 variables within BLOCK_INPUT so no such event interrupts. */
9438 f
->tool_bar_items
= new_tool_bar
;
9439 f
->n_tool_bar_items
= new_n_tool_bar
;
9440 w
->update_mode_line
= Qt
;
9446 unbind_to (count
, Qnil
);
9447 set_buffer_internal_1 (prev
);
9453 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9454 F's desired tool-bar contents. F->tool_bar_items must have
9455 been set up previously by calling prepare_menu_bars. */
9458 build_desired_tool_bar_string (f
)
9461 int i
, size
, size_needed
;
9462 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9463 Lisp_Object image
, plist
, props
;
9465 image
= plist
= props
= Qnil
;
9466 GCPRO3 (image
, plist
, props
);
9468 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9469 Otherwise, make a new string. */
9471 /* The size of the string we might be able to reuse. */
9472 size
= (STRINGP (f
->desired_tool_bar_string
)
9473 ? SCHARS (f
->desired_tool_bar_string
)
9476 /* We need one space in the string for each image. */
9477 size_needed
= f
->n_tool_bar_items
;
9479 /* Reuse f->desired_tool_bar_string, if possible. */
9480 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9481 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9485 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9486 Fremove_text_properties (make_number (0), make_number (size
),
9487 props
, f
->desired_tool_bar_string
);
9490 /* Put a `display' property on the string for the images to display,
9491 put a `menu_item' property on tool-bar items with a value that
9492 is the index of the item in F's tool-bar item vector. */
9493 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9495 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9497 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9498 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9499 int hmargin
, vmargin
, relief
, idx
, end
;
9500 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9502 /* If image is a vector, choose the image according to the
9504 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9505 if (VECTORP (image
))
9509 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9510 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9513 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9514 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9516 xassert (ASIZE (image
) >= idx
);
9517 image
= AREF (image
, idx
);
9522 /* Ignore invalid image specifications. */
9523 if (!valid_image_p (image
))
9526 /* Display the tool-bar button pressed, or depressed. */
9527 plist
= Fcopy_sequence (XCDR (image
));
9529 /* Compute margin and relief to draw. */
9530 relief
= (tool_bar_button_relief
>= 0
9531 ? tool_bar_button_relief
9532 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9533 hmargin
= vmargin
= relief
;
9535 if (INTEGERP (Vtool_bar_button_margin
)
9536 && XINT (Vtool_bar_button_margin
) > 0)
9538 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9539 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9541 else if (CONSP (Vtool_bar_button_margin
))
9543 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9544 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9545 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9547 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9548 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9549 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9552 if (auto_raise_tool_bar_buttons_p
)
9554 /* Add a `:relief' property to the image spec if the item is
9558 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9565 /* If image is selected, display it pressed, i.e. with a
9566 negative relief. If it's not selected, display it with a
9568 plist
= Fplist_put (plist
, QCrelief
,
9570 ? make_number (-relief
)
9571 : make_number (relief
)));
9576 /* Put a margin around the image. */
9577 if (hmargin
|| vmargin
)
9579 if (hmargin
== vmargin
)
9580 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9582 plist
= Fplist_put (plist
, QCmargin
,
9583 Fcons (make_number (hmargin
),
9584 make_number (vmargin
)));
9587 /* If button is not enabled, and we don't have special images
9588 for the disabled state, make the image appear disabled by
9589 applying an appropriate algorithm to it. */
9590 if (!enabled_p
&& idx
< 0)
9591 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9593 /* Put a `display' text property on the string for the image to
9594 display. Put a `menu-item' property on the string that gives
9595 the start of this item's properties in the tool-bar items
9597 image
= Fcons (Qimage
, plist
);
9598 props
= list4 (Qdisplay
, image
,
9599 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9601 /* Let the last image hide all remaining spaces in the tool bar
9602 string. The string can be longer than needed when we reuse a
9604 if (i
+ 1 == f
->n_tool_bar_items
)
9605 end
= SCHARS (f
->desired_tool_bar_string
);
9608 Fadd_text_properties (make_number (i
), make_number (end
),
9609 props
, f
->desired_tool_bar_string
);
9617 /* Display one line of the tool-bar of frame IT->f.
9619 HEIGHT specifies the desired height of the tool-bar line.
9620 If the actual height of the glyph row is less than HEIGHT, the
9621 row's height is increased to HEIGHT, and the icons are centered
9622 vertically in the new height.
9624 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
9625 count a final empty row in case the tool-bar width exactly matches
9630 display_tool_bar_line (it
, height
)
9634 struct glyph_row
*row
= it
->glyph_row
;
9635 int max_x
= it
->last_visible_x
;
9638 prepare_desired_row (row
);
9639 row
->y
= it
->current_y
;
9641 /* Note that this isn't made use of if the face hasn't a box,
9642 so there's no need to check the face here. */
9643 it
->start_of_box_run_p
= 1;
9645 while (it
->current_x
< max_x
)
9647 int x
, n_glyphs_before
, i
, nglyphs
;
9648 struct it it_before
;
9650 /* Get the next display element. */
9651 if (!get_next_display_element (it
))
9653 /* Don't count empty row if we are counting needed tool-bar lines. */
9654 if (height
< 0 && !it
->hpos
)
9659 /* Produce glyphs. */
9660 n_glyphs_before
= row
->used
[TEXT_AREA
];
9663 PRODUCE_GLYPHS (it
);
9665 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
9667 x
= it_before
.current_x
;
9670 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9672 if (x
+ glyph
->pixel_width
> max_x
)
9674 /* Glyph doesn't fit on line. Backtrack. */
9675 row
->used
[TEXT_AREA
] = n_glyphs_before
;
9677 /* If this is the only glyph on this line, it will never fit on the
9678 toolbar, so skip it. But ensure there is at least one glyph,
9679 so we don't accidentally disable the tool-bar. */
9680 if (n_glyphs_before
== 0
9681 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
9687 x
+= glyph
->pixel_width
;
9691 /* Stop at line ends. */
9692 if (ITERATOR_AT_END_OF_LINE_P (it
))
9695 set_iterator_to_next (it
, 1);
9700 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9702 /* Use default face for the border below the tool bar.
9704 FIXME: When auto-resize-tool-bars is grow-only, there is
9705 no additional border below the possibly empty tool-bar lines.
9706 So to make the extra empty lines look "normal", we have to
9707 use the tool-bar face for the border too. */
9708 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
9709 it
->face_id
= DEFAULT_FACE_ID
;
9711 extend_face_to_end_of_line (it
);
9712 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9713 last
->right_box_line_p
= 1;
9714 if (last
== row
->glyphs
[TEXT_AREA
])
9715 last
->left_box_line_p
= 1;
9717 /* Make line the desired height and center it vertically. */
9718 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
9720 /* Don't add more than one line height. */
9721 height
%= FRAME_LINE_HEIGHT (it
->f
);
9722 it
->max_ascent
+= height
/ 2;
9723 it
->max_descent
+= (height
+ 1) / 2;
9726 compute_line_metrics (it
);
9728 /* If line is empty, make it occupy the rest of the tool-bar. */
9729 if (!row
->displays_text_p
)
9731 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9732 row
->visible_height
= row
->height
;
9733 row
->ascent
= row
->phys_ascent
= 0;
9734 row
->extra_line_spacing
= 0;
9737 row
->full_width_p
= 1;
9738 row
->continued_p
= 0;
9739 row
->truncated_on_left_p
= 0;
9740 row
->truncated_on_right_p
= 0;
9742 it
->current_x
= it
->hpos
= 0;
9743 it
->current_y
+= row
->height
;
9749 /* Max tool-bar height. */
9751 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
9752 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
9754 /* Value is the number of screen lines needed to make all tool-bar
9755 items of frame F visible. The number of actual rows needed is
9756 returned in *N_ROWS if non-NULL. */
9759 tool_bar_lines_needed (f
, n_rows
)
9763 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9765 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
9766 the desired matrix, so use (unused) mode-line row as temporary row to
9767 avoid destroying the first tool-bar row. */
9768 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
9770 /* Initialize an iterator for iteration over
9771 F->desired_tool_bar_string in the tool-bar window of frame F. */
9772 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
9773 it
.first_visible_x
= 0;
9774 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9775 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9777 while (!ITERATOR_AT_END_P (&it
))
9779 clear_glyph_row (temp_row
);
9780 it
.glyph_row
= temp_row
;
9781 display_tool_bar_line (&it
, -1);
9783 clear_glyph_row (temp_row
);
9785 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
9787 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
9789 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9793 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9795 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9804 frame
= selected_frame
;
9806 CHECK_FRAME (frame
);
9809 if (WINDOWP (f
->tool_bar_window
)
9810 || (w
= XWINDOW (f
->tool_bar_window
),
9811 WINDOW_TOTAL_LINES (w
) > 0))
9813 update_tool_bar (f
, 1);
9814 if (f
->n_tool_bar_items
)
9816 build_desired_tool_bar_string (f
);
9817 nlines
= tool_bar_lines_needed (f
, NULL
);
9821 return make_number (nlines
);
9825 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9826 height should be changed. */
9829 redisplay_tool_bar (f
)
9834 struct glyph_row
*row
;
9837 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9838 update_frame_tool_bar (f
);
9842 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9843 do anything. This means you must start with tool-bar-lines
9844 non-zero to get the auto-sizing effect. Or in other words, you
9845 can turn off tool-bars by specifying tool-bar-lines zero. */
9846 if (!WINDOWP (f
->tool_bar_window
)
9847 || (w
= XWINDOW (f
->tool_bar_window
),
9848 WINDOW_TOTAL_LINES (w
) == 0))
9851 /* Set up an iterator for the tool-bar window. */
9852 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9853 it
.first_visible_x
= 0;
9854 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9857 /* Build a string that represents the contents of the tool-bar. */
9858 build_desired_tool_bar_string (f
);
9859 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9861 if (f
->n_tool_bar_rows
== 0)
9865 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
9866 nlines
!= WINDOW_TOTAL_LINES (w
)))
9868 extern Lisp_Object Qtool_bar_lines
;
9870 int old_height
= WINDOW_TOTAL_LINES (w
);
9872 XSETFRAME (frame
, f
);
9873 Fmodify_frame_parameters (frame
,
9874 Fcons (Fcons (Qtool_bar_lines
,
9875 make_number (nlines
)),
9877 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9879 clear_glyph_matrix (w
->desired_matrix
);
9880 fonts_changed_p
= 1;
9886 /* Display as many lines as needed to display all tool-bar items. */
9888 if (f
->n_tool_bar_rows
> 0)
9890 int border
, rows
, height
, extra
;
9892 if (INTEGERP (Vtool_bar_border
))
9893 border
= XINT (Vtool_bar_border
);
9894 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
9895 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
9896 else if (EQ (Vtool_bar_border
, Qborder_width
))
9897 border
= f
->border_width
;
9903 rows
= f
->n_tool_bar_rows
;
9904 height
= max (1, (it
.last_visible_y
- border
) / rows
);
9905 extra
= it
.last_visible_y
- border
- height
* rows
;
9907 while (it
.current_y
< it
.last_visible_y
)
9910 if (extra
> 0 && rows
-- > 0)
9912 h
= (extra
+ rows
- 1) / rows
;
9915 display_tool_bar_line (&it
, height
+ h
);
9920 while (it
.current_y
< it
.last_visible_y
)
9921 display_tool_bar_line (&it
, 0);
9924 /* It doesn't make much sense to try scrolling in the tool-bar
9925 window, so don't do it. */
9926 w
->desired_matrix
->no_scrolling_p
= 1;
9927 w
->must_be_updated_p
= 1;
9929 if (!NILP (Vauto_resize_tool_bars
))
9931 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
9932 int change_height_p
= 0;
9934 /* If we couldn't display everything, change the tool-bar's
9935 height if there is room for more. */
9936 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
9937 && it
.current_y
< max_tool_bar_height
)
9938 change_height_p
= 1;
9940 row
= it
.glyph_row
- 1;
9942 /* If there are blank lines at the end, except for a partially
9943 visible blank line at the end that is smaller than
9944 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9945 if (!row
->displays_text_p
9946 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9947 change_height_p
= 1;
9949 /* If row displays tool-bar items, but is partially visible,
9950 change the tool-bar's height. */
9951 if (row
->displays_text_p
9952 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
9953 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
9954 change_height_p
= 1;
9956 /* Resize windows as needed by changing the `tool-bar-lines'
9958 if (change_height_p
)
9960 extern Lisp_Object Qtool_bar_lines
;
9962 int old_height
= WINDOW_TOTAL_LINES (w
);
9964 int nlines
= tool_bar_lines_needed (f
, &nrows
);
9966 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
9967 && !f
->minimize_tool_bar_window_p
)
9968 ? (nlines
> old_height
)
9969 : (nlines
!= old_height
));
9970 f
->minimize_tool_bar_window_p
= 0;
9972 if (change_height_p
)
9974 XSETFRAME (frame
, f
);
9975 Fmodify_frame_parameters (frame
,
9976 Fcons (Fcons (Qtool_bar_lines
,
9977 make_number (nlines
)),
9979 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9981 clear_glyph_matrix (w
->desired_matrix
);
9982 f
->n_tool_bar_rows
= nrows
;
9983 fonts_changed_p
= 1;
9990 f
->minimize_tool_bar_window_p
= 0;
9995 /* Get information about the tool-bar item which is displayed in GLYPH
9996 on frame F. Return in *PROP_IDX the index where tool-bar item
9997 properties start in F->tool_bar_items. Value is zero if
9998 GLYPH doesn't display a tool-bar item. */
10001 tool_bar_item_info (f
, glyph
, prop_idx
)
10003 struct glyph
*glyph
;
10010 /* This function can be called asynchronously, which means we must
10011 exclude any possibility that Fget_text_property signals an
10013 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10014 charpos
= max (0, charpos
);
10016 /* Get the text property `menu-item' at pos. The value of that
10017 property is the start index of this item's properties in
10018 F->tool_bar_items. */
10019 prop
= Fget_text_property (make_number (charpos
),
10020 Qmenu_item
, f
->current_tool_bar_string
);
10021 if (INTEGERP (prop
))
10023 *prop_idx
= XINT (prop
);
10033 /* Get information about the tool-bar item at position X/Y on frame F.
10034 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10035 the current matrix of the tool-bar window of F, or NULL if not
10036 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10037 item in F->tool_bar_items. Value is
10039 -1 if X/Y is not on a tool-bar item
10040 0 if X/Y is on the same item that was highlighted before.
10044 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10047 struct glyph
**glyph
;
10048 int *hpos
, *vpos
, *prop_idx
;
10050 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10051 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10054 /* Find the glyph under X/Y. */
10055 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10056 if (*glyph
== NULL
)
10059 /* Get the start of this tool-bar item's properties in
10060 f->tool_bar_items. */
10061 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10064 /* Is mouse on the highlighted item? */
10065 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10066 && *vpos
>= dpyinfo
->mouse_face_beg_row
10067 && *vpos
<= dpyinfo
->mouse_face_end_row
10068 && (*vpos
> dpyinfo
->mouse_face_beg_row
10069 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10070 && (*vpos
< dpyinfo
->mouse_face_end_row
10071 || *hpos
< dpyinfo
->mouse_face_end_col
10072 || dpyinfo
->mouse_face_past_end
))
10080 Handle mouse button event on the tool-bar of frame F, at
10081 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10082 0 for button release. MODIFIERS is event modifiers for button
10086 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10089 unsigned int modifiers
;
10091 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10092 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10093 int hpos
, vpos
, prop_idx
;
10094 struct glyph
*glyph
;
10095 Lisp_Object enabled_p
;
10097 /* If not on the highlighted tool-bar item, return. */
10098 frame_to_window_pixel_xy (w
, &x
, &y
);
10099 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10102 /* If item is disabled, do nothing. */
10103 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10104 if (NILP (enabled_p
))
10109 /* Show item in pressed state. */
10110 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10111 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10112 last_tool_bar_item
= prop_idx
;
10116 Lisp_Object key
, frame
;
10117 struct input_event event
;
10118 EVENT_INIT (event
);
10120 /* Show item in released state. */
10121 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10122 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10124 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10126 XSETFRAME (frame
, f
);
10127 event
.kind
= TOOL_BAR_EVENT
;
10128 event
.frame_or_window
= frame
;
10130 kbd_buffer_store_event (&event
);
10132 event
.kind
= TOOL_BAR_EVENT
;
10133 event
.frame_or_window
= frame
;
10135 event
.modifiers
= modifiers
;
10136 kbd_buffer_store_event (&event
);
10137 last_tool_bar_item
= -1;
10142 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10143 tool-bar window-relative coordinates X/Y. Called from
10144 note_mouse_highlight. */
10147 note_tool_bar_highlight (f
, x
, y
)
10151 Lisp_Object window
= f
->tool_bar_window
;
10152 struct window
*w
= XWINDOW (window
);
10153 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10155 struct glyph
*glyph
;
10156 struct glyph_row
*row
;
10158 Lisp_Object enabled_p
;
10160 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10161 int mouse_down_p
, rc
;
10163 /* Function note_mouse_highlight is called with negative x(y
10164 values when mouse moves outside of the frame. */
10165 if (x
<= 0 || y
<= 0)
10167 clear_mouse_face (dpyinfo
);
10171 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10174 /* Not on tool-bar item. */
10175 clear_mouse_face (dpyinfo
);
10179 /* On same tool-bar item as before. */
10180 goto set_help_echo
;
10182 clear_mouse_face (dpyinfo
);
10184 /* Mouse is down, but on different tool-bar item? */
10185 mouse_down_p
= (dpyinfo
->grabbed
10186 && f
== last_mouse_frame
10187 && FRAME_LIVE_P (f
));
10189 && last_tool_bar_item
!= prop_idx
)
10192 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10193 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10195 /* If tool-bar item is not enabled, don't highlight it. */
10196 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10197 if (!NILP (enabled_p
))
10199 /* Compute the x-position of the glyph. In front and past the
10200 image is a space. We include this in the highlighted area. */
10201 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10202 for (i
= x
= 0; i
< hpos
; ++i
)
10203 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10205 /* Record this as the current active region. */
10206 dpyinfo
->mouse_face_beg_col
= hpos
;
10207 dpyinfo
->mouse_face_beg_row
= vpos
;
10208 dpyinfo
->mouse_face_beg_x
= x
;
10209 dpyinfo
->mouse_face_beg_y
= row
->y
;
10210 dpyinfo
->mouse_face_past_end
= 0;
10212 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10213 dpyinfo
->mouse_face_end_row
= vpos
;
10214 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10215 dpyinfo
->mouse_face_end_y
= row
->y
;
10216 dpyinfo
->mouse_face_window
= window
;
10217 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10219 /* Display it as active. */
10220 show_mouse_face (dpyinfo
, draw
);
10221 dpyinfo
->mouse_face_image_state
= draw
;
10226 /* Set help_echo_string to a help string to display for this tool-bar item.
10227 XTread_socket does the rest. */
10228 help_echo_object
= help_echo_window
= Qnil
;
10229 help_echo_pos
= -1;
10230 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10231 if (NILP (help_echo_string
))
10232 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10235 #endif /* HAVE_WINDOW_SYSTEM */
10239 /************************************************************************
10240 Horizontal scrolling
10241 ************************************************************************/
10243 static int hscroll_window_tree
P_ ((Lisp_Object
));
10244 static int hscroll_windows
P_ ((Lisp_Object
));
10246 /* For all leaf windows in the window tree rooted at WINDOW, set their
10247 hscroll value so that PT is (i) visible in the window, and (ii) so
10248 that it is not within a certain margin at the window's left and
10249 right border. Value is non-zero if any window's hscroll has been
10253 hscroll_window_tree (window
)
10254 Lisp_Object window
;
10256 int hscrolled_p
= 0;
10257 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10258 int hscroll_step_abs
= 0;
10259 double hscroll_step_rel
= 0;
10261 if (hscroll_relative_p
)
10263 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10264 if (hscroll_step_rel
< 0)
10266 hscroll_relative_p
= 0;
10267 hscroll_step_abs
= 0;
10270 else if (INTEGERP (Vhscroll_step
))
10272 hscroll_step_abs
= XINT (Vhscroll_step
);
10273 if (hscroll_step_abs
< 0)
10274 hscroll_step_abs
= 0;
10277 hscroll_step_abs
= 0;
10279 while (WINDOWP (window
))
10281 struct window
*w
= XWINDOW (window
);
10283 if (WINDOWP (w
->hchild
))
10284 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10285 else if (WINDOWP (w
->vchild
))
10286 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10287 else if (w
->cursor
.vpos
>= 0)
10290 int text_area_width
;
10291 struct glyph_row
*current_cursor_row
10292 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10293 struct glyph_row
*desired_cursor_row
10294 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10295 struct glyph_row
*cursor_row
10296 = (desired_cursor_row
->enabled_p
10297 ? desired_cursor_row
10298 : current_cursor_row
);
10300 text_area_width
= window_box_width (w
, TEXT_AREA
);
10302 /* Scroll when cursor is inside this scroll margin. */
10303 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10305 if ((XFASTINT (w
->hscroll
)
10306 && w
->cursor
.x
<= h_margin
)
10307 || (cursor_row
->enabled_p
10308 && cursor_row
->truncated_on_right_p
10309 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
10313 struct buffer
*saved_current_buffer
;
10317 /* Find point in a display of infinite width. */
10318 saved_current_buffer
= current_buffer
;
10319 current_buffer
= XBUFFER (w
->buffer
);
10321 if (w
== XWINDOW (selected_window
))
10322 pt
= BUF_PT (current_buffer
);
10325 pt
= marker_position (w
->pointm
);
10326 pt
= max (BEGV
, pt
);
10330 /* Move iterator to pt starting at cursor_row->start in
10331 a line with infinite width. */
10332 init_to_row_start (&it
, w
, cursor_row
);
10333 it
.last_visible_x
= INFINITY
;
10334 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10335 current_buffer
= saved_current_buffer
;
10337 /* Position cursor in window. */
10338 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10339 hscroll
= max (0, (it
.current_x
10340 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10341 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10342 : (text_area_width
/ 2))))
10343 / FRAME_COLUMN_WIDTH (it
.f
);
10344 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10346 if (hscroll_relative_p
)
10347 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10350 wanted_x
= text_area_width
10351 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10354 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10358 if (hscroll_relative_p
)
10359 wanted_x
= text_area_width
* hscroll_step_rel
10362 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10365 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10367 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10369 /* Don't call Fset_window_hscroll if value hasn't
10370 changed because it will prevent redisplay
10372 if (XFASTINT (w
->hscroll
) != hscroll
)
10374 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10375 w
->hscroll
= make_number (hscroll
);
10384 /* Value is non-zero if hscroll of any leaf window has been changed. */
10385 return hscrolled_p
;
10389 /* Set hscroll so that cursor is visible and not inside horizontal
10390 scroll margins for all windows in the tree rooted at WINDOW. See
10391 also hscroll_window_tree above. Value is non-zero if any window's
10392 hscroll has been changed. If it has, desired matrices on the frame
10393 of WINDOW are cleared. */
10396 hscroll_windows (window
)
10397 Lisp_Object window
;
10401 if (automatic_hscrolling_p
)
10403 hscrolled_p
= hscroll_window_tree (window
);
10405 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10409 return hscrolled_p
;
10414 /************************************************************************
10416 ************************************************************************/
10418 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10419 to a non-zero value. This is sometimes handy to have in a debugger
10424 /* First and last unchanged row for try_window_id. */
10426 int debug_first_unchanged_at_end_vpos
;
10427 int debug_last_unchanged_at_beg_vpos
;
10429 /* Delta vpos and y. */
10431 int debug_dvpos
, debug_dy
;
10433 /* Delta in characters and bytes for try_window_id. */
10435 int debug_delta
, debug_delta_bytes
;
10437 /* Values of window_end_pos and window_end_vpos at the end of
10440 EMACS_INT debug_end_pos
, debug_end_vpos
;
10442 /* Append a string to W->desired_matrix->method. FMT is a printf
10443 format string. A1...A9 are a supplement for a variable-length
10444 argument list. If trace_redisplay_p is non-zero also printf the
10445 resulting string to stderr. */
10448 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10451 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10454 char *method
= w
->desired_matrix
->method
;
10455 int len
= strlen (method
);
10456 int size
= sizeof w
->desired_matrix
->method
;
10457 int remaining
= size
- len
- 1;
10459 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10460 if (len
&& remaining
)
10463 --remaining
, ++len
;
10466 strncpy (method
+ len
, buffer
, remaining
);
10468 if (trace_redisplay_p
)
10469 fprintf (stderr
, "%p (%s): %s\n",
10471 ((BUFFERP (w
->buffer
)
10472 && STRINGP (XBUFFER (w
->buffer
)->name
))
10473 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10478 #endif /* GLYPH_DEBUG */
10481 /* Value is non-zero if all changes in window W, which displays
10482 current_buffer, are in the text between START and END. START is a
10483 buffer position, END is given as a distance from Z. Used in
10484 redisplay_internal for display optimization. */
10487 text_outside_line_unchanged_p (w
, start
, end
)
10491 int unchanged_p
= 1;
10493 /* If text or overlays have changed, see where. */
10494 if (XFASTINT (w
->last_modified
) < MODIFF
10495 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10497 /* Gap in the line? */
10498 if (GPT
< start
|| Z
- GPT
< end
)
10501 /* Changes start in front of the line, or end after it? */
10503 && (BEG_UNCHANGED
< start
- 1
10504 || END_UNCHANGED
< end
))
10507 /* If selective display, can't optimize if changes start at the
10508 beginning of the line. */
10510 && INTEGERP (current_buffer
->selective_display
)
10511 && XINT (current_buffer
->selective_display
) > 0
10512 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10515 /* If there are overlays at the start or end of the line, these
10516 may have overlay strings with newlines in them. A change at
10517 START, for instance, may actually concern the display of such
10518 overlay strings as well, and they are displayed on different
10519 lines. So, quickly rule out this case. (For the future, it
10520 might be desirable to implement something more telling than
10521 just BEG/END_UNCHANGED.) */
10524 if (BEG
+ BEG_UNCHANGED
== start
10525 && overlay_touches_p (start
))
10527 if (END_UNCHANGED
== end
10528 && overlay_touches_p (Z
- end
))
10533 return unchanged_p
;
10537 /* Do a frame update, taking possible shortcuts into account. This is
10538 the main external entry point for redisplay.
10540 If the last redisplay displayed an echo area message and that message
10541 is no longer requested, we clear the echo area or bring back the
10542 mini-buffer if that is in use. */
10547 redisplay_internal (0);
10552 overlay_arrow_string_or_property (var
)
10557 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10560 return Voverlay_arrow_string
;
10563 /* Return 1 if there are any overlay-arrows in current_buffer. */
10565 overlay_arrow_in_current_buffer_p ()
10569 for (vlist
= Voverlay_arrow_variable_list
;
10571 vlist
= XCDR (vlist
))
10573 Lisp_Object var
= XCAR (vlist
);
10576 if (!SYMBOLP (var
))
10578 val
= find_symbol_value (var
);
10580 && current_buffer
== XMARKER (val
)->buffer
)
10587 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
10591 overlay_arrows_changed_p ()
10595 for (vlist
= Voverlay_arrow_variable_list
;
10597 vlist
= XCDR (vlist
))
10599 Lisp_Object var
= XCAR (vlist
);
10600 Lisp_Object val
, pstr
;
10602 if (!SYMBOLP (var
))
10604 val
= find_symbol_value (var
);
10605 if (!MARKERP (val
))
10607 if (! EQ (COERCE_MARKER (val
),
10608 Fget (var
, Qlast_arrow_position
))
10609 || ! (pstr
= overlay_arrow_string_or_property (var
),
10610 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
10616 /* Mark overlay arrows to be updated on next redisplay. */
10619 update_overlay_arrows (up_to_date
)
10624 for (vlist
= Voverlay_arrow_variable_list
;
10626 vlist
= XCDR (vlist
))
10628 Lisp_Object var
= XCAR (vlist
);
10630 if (!SYMBOLP (var
))
10633 if (up_to_date
> 0)
10635 Lisp_Object val
= find_symbol_value (var
);
10636 Fput (var
, Qlast_arrow_position
,
10637 COERCE_MARKER (val
));
10638 Fput (var
, Qlast_arrow_string
,
10639 overlay_arrow_string_or_property (var
));
10641 else if (up_to_date
< 0
10642 || !NILP (Fget (var
, Qlast_arrow_position
)))
10644 Fput (var
, Qlast_arrow_position
, Qt
);
10645 Fput (var
, Qlast_arrow_string
, Qt
);
10651 /* Return overlay arrow string to display at row.
10652 Return integer (bitmap number) for arrow bitmap in left fringe.
10653 Return nil if no overlay arrow. */
10656 overlay_arrow_at_row (it
, row
)
10658 struct glyph_row
*row
;
10662 for (vlist
= Voverlay_arrow_variable_list
;
10664 vlist
= XCDR (vlist
))
10666 Lisp_Object var
= XCAR (vlist
);
10669 if (!SYMBOLP (var
))
10672 val
= find_symbol_value (var
);
10675 && current_buffer
== XMARKER (val
)->buffer
10676 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10678 if (FRAME_WINDOW_P (it
->f
)
10679 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10681 #ifdef HAVE_WINDOW_SYSTEM
10682 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10685 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10686 return make_number (fringe_bitmap
);
10689 return make_number (-1); /* Use default arrow bitmap */
10691 return overlay_arrow_string_or_property (var
);
10698 /* Return 1 if point moved out of or into a composition. Otherwise
10699 return 0. PREV_BUF and PREV_PT are the last point buffer and
10700 position. BUF and PT are the current point buffer and position. */
10703 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10704 struct buffer
*prev_buf
, *buf
;
10709 Lisp_Object buffer
;
10711 XSETBUFFER (buffer
, buf
);
10712 /* Check a composition at the last point if point moved within the
10714 if (prev_buf
== buf
)
10717 /* Point didn't move. */
10720 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10721 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10722 && COMPOSITION_VALID_P (start
, end
, prop
)
10723 && start
< prev_pt
&& end
> prev_pt
)
10724 /* The last point was within the composition. Return 1 iff
10725 point moved out of the composition. */
10726 return (pt
<= start
|| pt
>= end
);
10729 /* Check a composition at the current point. */
10730 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10731 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10732 && COMPOSITION_VALID_P (start
, end
, prop
)
10733 && start
< pt
&& end
> pt
);
10737 /* Reconsider the setting of B->clip_changed which is displayed
10741 reconsider_clip_changes (w
, b
)
10745 if (b
->clip_changed
10746 && !NILP (w
->window_end_valid
)
10747 && w
->current_matrix
->buffer
== b
10748 && w
->current_matrix
->zv
== BUF_ZV (b
)
10749 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10750 b
->clip_changed
= 0;
10752 /* If display wasn't paused, and W is not a tool bar window, see if
10753 point has been moved into or out of a composition. In that case,
10754 we set b->clip_changed to 1 to force updating the screen. If
10755 b->clip_changed has already been set to 1, we can skip this
10757 if (!b
->clip_changed
10758 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10762 if (w
== XWINDOW (selected_window
))
10763 pt
= BUF_PT (current_buffer
);
10765 pt
= marker_position (w
->pointm
);
10767 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10768 || pt
!= XINT (w
->last_point
))
10769 && check_point_in_composition (w
->current_matrix
->buffer
,
10770 XINT (w
->last_point
),
10771 XBUFFER (w
->buffer
), pt
))
10772 b
->clip_changed
= 1;
10777 /* Select FRAME to forward the values of frame-local variables into C
10778 variables so that the redisplay routines can access those values
10782 select_frame_for_redisplay (frame
)
10785 Lisp_Object tail
, sym
, val
;
10786 Lisp_Object old
= selected_frame
;
10788 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
10790 selected_frame
= frame
;
10792 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10793 if (CONSP (XCAR (tail
))
10794 && (sym
= XCAR (XCAR (tail
)),
10796 && (sym
= indirect_variable (sym
),
10797 val
= SYMBOL_VALUE (sym
),
10798 (BUFFER_LOCAL_VALUEP (val
)
10799 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10800 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10801 /* Use find_symbol_value rather than Fsymbol_value
10802 to avoid an error if it is void. */
10803 find_symbol_value (sym
);
10805 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10806 if (CONSP (XCAR (tail
))
10807 && (sym
= XCAR (XCAR (tail
)),
10809 && (sym
= indirect_variable (sym
),
10810 val
= SYMBOL_VALUE (sym
),
10811 (BUFFER_LOCAL_VALUEP (val
)
10812 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10813 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10814 find_symbol_value (sym
);
10818 #define STOP_POLLING \
10819 do { if (! polling_stopped_here) stop_polling (); \
10820 polling_stopped_here = 1; } while (0)
10822 #define RESUME_POLLING \
10823 do { if (polling_stopped_here) start_polling (); \
10824 polling_stopped_here = 0; } while (0)
10827 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10828 response to any user action; therefore, we should preserve the echo
10829 area. (Actually, our caller does that job.) Perhaps in the future
10830 avoid recentering windows if it is not necessary; currently that
10831 causes some problems. */
10834 redisplay_internal (preserve_echo_area
)
10835 int preserve_echo_area
;
10837 struct window
*w
= XWINDOW (selected_window
);
10840 int must_finish
= 0;
10841 struct text_pos tlbufpos
, tlendpos
;
10842 int number_of_visible_frames
;
10845 int polling_stopped_here
= 0;
10847 /* Non-zero means redisplay has to consider all windows on all
10848 frames. Zero means, only selected_window is considered. */
10849 int consider_all_windows_p
;
10851 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10853 /* No redisplay if running in batch mode or frame is not yet fully
10854 initialized, or redisplay is explicitly turned off by setting
10855 Vinhibit_redisplay. */
10857 || !NILP (Vinhibit_redisplay
))
10860 /* Don't examine these until after testing Vinhibit_redisplay.
10861 When Emacs is shutting down, perhaps because its connection to
10862 X has dropped, we should not look at them at all. */
10863 f
= XFRAME (w
->frame
);
10864 sf
= SELECTED_FRAME ();
10866 if (!f
->glyphs_initialized_p
)
10869 /* The flag redisplay_performed_directly_p is set by
10870 direct_output_for_insert when it already did the whole screen
10871 update necessary. */
10872 if (redisplay_performed_directly_p
)
10874 redisplay_performed_directly_p
= 0;
10875 if (!hscroll_windows (selected_window
))
10879 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (MAC_OS)
10880 if (popup_activated ())
10884 /* I don't think this happens but let's be paranoid. */
10885 if (redisplaying_p
)
10888 /* Record a function that resets redisplaying_p to its old value
10889 when we leave this function. */
10890 count
= SPECPDL_INDEX ();
10891 record_unwind_protect (unwind_redisplay
,
10892 Fcons (make_number (redisplaying_p
), selected_frame
));
10894 specbind (Qinhibit_free_realized_faces
, Qnil
);
10897 Lisp_Object tail
, frame
;
10899 FOR_EACH_FRAME (tail
, frame
)
10901 struct frame
*f
= XFRAME (frame
);
10902 f
->already_hscrolled_p
= 0;
10908 reconsider_clip_changes (w
, current_buffer
);
10909 last_escape_glyph_frame
= NULL
;
10910 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
10912 /* If new fonts have been loaded that make a glyph matrix adjustment
10913 necessary, do it. */
10914 if (fonts_changed_p
)
10916 adjust_glyphs (NULL
);
10917 ++windows_or_buffers_changed
;
10918 fonts_changed_p
= 0;
10921 /* If face_change_count is non-zero, init_iterator will free all
10922 realized faces, which includes the faces referenced from current
10923 matrices. So, we can't reuse current matrices in this case. */
10924 if (face_change_count
)
10925 ++windows_or_buffers_changed
;
10927 if (FRAME_TERMCAP_P (sf
)
10928 && FRAME_TTY (sf
)->previous_frame
!= sf
)
10930 /* Since frames on a single ASCII terminal share the same
10931 display area, displaying a different frame means redisplay
10932 the whole thing. */
10933 windows_or_buffers_changed
++;
10934 SET_FRAME_GARBAGED (sf
);
10935 FRAME_TTY (sf
)->previous_frame
= sf
;
10938 /* Set the visible flags for all frames. Do this before checking
10939 for resized or garbaged frames; they want to know if their frames
10940 are visible. See the comment in frame.h for
10941 FRAME_SAMPLE_VISIBILITY. */
10943 Lisp_Object tail
, frame
;
10945 number_of_visible_frames
= 0;
10947 FOR_EACH_FRAME (tail
, frame
)
10949 struct frame
*f
= XFRAME (frame
);
10951 FRAME_SAMPLE_VISIBILITY (f
);
10952 if (FRAME_VISIBLE_P (f
))
10953 ++number_of_visible_frames
;
10954 clear_desired_matrices (f
);
10959 /* Notice any pending interrupt request to change frame size. */
10960 do_pending_window_change (1);
10962 /* Clear frames marked as garbaged. */
10963 if (frame_garbaged
)
10964 clear_garbaged_frames ();
10966 /* Build menubar and tool-bar items. */
10967 if (NILP (Vmemory_full
))
10968 prepare_menu_bars ();
10970 if (windows_or_buffers_changed
)
10971 update_mode_lines
++;
10973 /* Detect case that we need to write or remove a star in the mode line. */
10974 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10976 w
->update_mode_line
= Qt
;
10977 if (buffer_shared
> 1)
10978 update_mode_lines
++;
10981 /* Avoid invocation of point motion hooks by `current_column' below. */
10982 count1
= SPECPDL_INDEX ();
10983 specbind (Qinhibit_point_motion_hooks
, Qt
);
10985 /* If %c is in the mode line, update it if needed. */
10986 if (!NILP (w
->column_number_displayed
)
10987 /* This alternative quickly identifies a common case
10988 where no change is needed. */
10989 && !(PT
== XFASTINT (w
->last_point
)
10990 && XFASTINT (w
->last_modified
) >= MODIFF
10991 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10992 && (XFASTINT (w
->column_number_displayed
)
10993 != (int) current_column ())) /* iftc */
10994 w
->update_mode_line
= Qt
;
10996 unbind_to (count1
, Qnil
);
10998 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11000 /* The variable buffer_shared is set in redisplay_window and
11001 indicates that we redisplay a buffer in different windows. See
11003 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11004 || cursor_type_changed
);
11006 /* If specs for an arrow have changed, do thorough redisplay
11007 to ensure we remove any arrow that should no longer exist. */
11008 if (overlay_arrows_changed_p ())
11009 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11011 /* Normally the message* functions will have already displayed and
11012 updated the echo area, but the frame may have been trashed, or
11013 the update may have been preempted, so display the echo area
11014 again here. Checking message_cleared_p captures the case that
11015 the echo area should be cleared. */
11016 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11017 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11018 || (message_cleared_p
11019 && minibuf_level
== 0
11020 /* If the mini-window is currently selected, this means the
11021 echo-area doesn't show through. */
11022 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11024 int window_height_changed_p
= echo_area_display (0);
11027 /* If we don't display the current message, don't clear the
11028 message_cleared_p flag, because, if we did, we wouldn't clear
11029 the echo area in the next redisplay which doesn't preserve
11031 if (!display_last_displayed_message_p
)
11032 message_cleared_p
= 0;
11034 if (fonts_changed_p
)
11036 else if (window_height_changed_p
)
11038 consider_all_windows_p
= 1;
11039 ++update_mode_lines
;
11040 ++windows_or_buffers_changed
;
11042 /* If window configuration was changed, frames may have been
11043 marked garbaged. Clear them or we will experience
11044 surprises wrt scrolling. */
11045 if (frame_garbaged
)
11046 clear_garbaged_frames ();
11049 else if (EQ (selected_window
, minibuf_window
)
11050 && (current_buffer
->clip_changed
11051 || XFASTINT (w
->last_modified
) < MODIFF
11052 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11053 && resize_mini_window (w
, 0))
11055 /* Resized active mini-window to fit the size of what it is
11056 showing if its contents might have changed. */
11058 consider_all_windows_p
= 1;
11059 ++windows_or_buffers_changed
;
11060 ++update_mode_lines
;
11062 /* If window configuration was changed, frames may have been
11063 marked garbaged. Clear them or we will experience
11064 surprises wrt scrolling. */
11065 if (frame_garbaged
)
11066 clear_garbaged_frames ();
11070 /* If showing the region, and mark has changed, we must redisplay
11071 the whole window. The assignment to this_line_start_pos prevents
11072 the optimization directly below this if-statement. */
11073 if (((!NILP (Vtransient_mark_mode
)
11074 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11075 != !NILP (w
->region_showing
))
11076 || (!NILP (w
->region_showing
)
11077 && !EQ (w
->region_showing
,
11078 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11079 CHARPOS (this_line_start_pos
) = 0;
11081 /* Optimize the case that only the line containing the cursor in the
11082 selected window has changed. Variables starting with this_ are
11083 set in display_line and record information about the line
11084 containing the cursor. */
11085 tlbufpos
= this_line_start_pos
;
11086 tlendpos
= this_line_end_pos
;
11087 if (!consider_all_windows_p
11088 && CHARPOS (tlbufpos
) > 0
11089 && NILP (w
->update_mode_line
)
11090 && !current_buffer
->clip_changed
11091 && !current_buffer
->prevent_redisplay_optimizations_p
11092 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11093 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11094 /* Make sure recorded data applies to current buffer, etc. */
11095 && this_line_buffer
== current_buffer
11096 && current_buffer
== XBUFFER (w
->buffer
)
11097 && NILP (w
->force_start
)
11098 && NILP (w
->optional_new_start
)
11099 /* Point must be on the line that we have info recorded about. */
11100 && PT
>= CHARPOS (tlbufpos
)
11101 && PT
<= Z
- CHARPOS (tlendpos
)
11102 /* All text outside that line, including its final newline,
11103 must be unchanged */
11104 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11105 CHARPOS (tlendpos
)))
11107 if (CHARPOS (tlbufpos
) > BEGV
11108 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11109 && (CHARPOS (tlbufpos
) == ZV
11110 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11111 /* Former continuation line has disappeared by becoming empty */
11113 else if (XFASTINT (w
->last_modified
) < MODIFF
11114 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11115 || MINI_WINDOW_P (w
))
11117 /* We have to handle the case of continuation around a
11118 wide-column character (See the comment in indent.c around
11121 For instance, in the following case:
11123 -------- Insert --------
11124 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11125 J_I_ ==> J_I_ `^^' are cursors.
11129 As we have to redraw the line above, we should goto cancel. */
11132 int line_height_before
= this_line_pixel_height
;
11134 /* Note that start_display will handle the case that the
11135 line starting at tlbufpos is a continuation lines. */
11136 start_display (&it
, w
, tlbufpos
);
11138 /* Implementation note: It this still necessary? */
11139 if (it
.current_x
!= this_line_start_x
)
11142 TRACE ((stderr
, "trying display optimization 1\n"));
11143 w
->cursor
.vpos
= -1;
11144 overlay_arrow_seen
= 0;
11145 it
.vpos
= this_line_vpos
;
11146 it
.current_y
= this_line_y
;
11147 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11148 display_line (&it
);
11150 /* If line contains point, is not continued,
11151 and ends at same distance from eob as before, we win */
11152 if (w
->cursor
.vpos
>= 0
11153 /* Line is not continued, otherwise this_line_start_pos
11154 would have been set to 0 in display_line. */
11155 && CHARPOS (this_line_start_pos
)
11156 /* Line ends as before. */
11157 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11158 /* Line has same height as before. Otherwise other lines
11159 would have to be shifted up or down. */
11160 && this_line_pixel_height
== line_height_before
)
11162 /* If this is not the window's last line, we must adjust
11163 the charstarts of the lines below. */
11164 if (it
.current_y
< it
.last_visible_y
)
11166 struct glyph_row
*row
11167 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11168 int delta
, delta_bytes
;
11170 if (Z
- CHARPOS (tlendpos
) == ZV
)
11172 /* This line ends at end of (accessible part of)
11173 buffer. There is no newline to count. */
11175 - CHARPOS (tlendpos
)
11176 - MATRIX_ROW_START_CHARPOS (row
));
11177 delta_bytes
= (Z_BYTE
11178 - BYTEPOS (tlendpos
)
11179 - MATRIX_ROW_START_BYTEPOS (row
));
11183 /* This line ends in a newline. Must take
11184 account of the newline and the rest of the
11185 text that follows. */
11187 - CHARPOS (tlendpos
)
11188 - MATRIX_ROW_START_CHARPOS (row
));
11189 delta_bytes
= (Z_BYTE
11190 - BYTEPOS (tlendpos
)
11191 - MATRIX_ROW_START_BYTEPOS (row
));
11194 increment_matrix_positions (w
->current_matrix
,
11195 this_line_vpos
+ 1,
11196 w
->current_matrix
->nrows
,
11197 delta
, delta_bytes
);
11200 /* If this row displays text now but previously didn't,
11201 or vice versa, w->window_end_vpos may have to be
11203 if ((it
.glyph_row
- 1)->displays_text_p
)
11205 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11206 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11208 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11209 && this_line_vpos
> 0)
11210 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11211 w
->window_end_valid
= Qnil
;
11213 /* Update hint: No need to try to scroll in update_window. */
11214 w
->desired_matrix
->no_scrolling_p
= 1;
11217 *w
->desired_matrix
->method
= 0;
11218 debug_method_add (w
, "optimization 1");
11220 #ifdef HAVE_WINDOW_SYSTEM
11221 update_window_fringes (w
, 0);
11228 else if (/* Cursor position hasn't changed. */
11229 PT
== XFASTINT (w
->last_point
)
11230 /* Make sure the cursor was last displayed
11231 in this window. Otherwise we have to reposition it. */
11232 && 0 <= w
->cursor
.vpos
11233 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11237 do_pending_window_change (1);
11239 /* We used to always goto end_of_redisplay here, but this
11240 isn't enough if we have a blinking cursor. */
11241 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11242 goto end_of_redisplay
;
11246 /* If highlighting the region, or if the cursor is in the echo area,
11247 then we can't just move the cursor. */
11248 else if (! (!NILP (Vtransient_mark_mode
)
11249 && !NILP (current_buffer
->mark_active
))
11250 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11251 || highlight_nonselected_windows
)
11252 && NILP (w
->region_showing
)
11253 && NILP (Vshow_trailing_whitespace
)
11254 && !cursor_in_echo_area
)
11257 struct glyph_row
*row
;
11259 /* Skip from tlbufpos to PT and see where it is. Note that
11260 PT may be in invisible text. If so, we will end at the
11261 next visible position. */
11262 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11263 NULL
, DEFAULT_FACE_ID
);
11264 it
.current_x
= this_line_start_x
;
11265 it
.current_y
= this_line_y
;
11266 it
.vpos
= this_line_vpos
;
11268 /* The call to move_it_to stops in front of PT, but
11269 moves over before-strings. */
11270 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11272 if (it
.vpos
== this_line_vpos
11273 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11276 xassert (this_line_vpos
== it
.vpos
);
11277 xassert (this_line_y
== it
.current_y
);
11278 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11280 *w
->desired_matrix
->method
= 0;
11281 debug_method_add (w
, "optimization 3");
11290 /* Text changed drastically or point moved off of line. */
11291 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11294 CHARPOS (this_line_start_pos
) = 0;
11295 consider_all_windows_p
|= buffer_shared
> 1;
11296 ++clear_face_cache_count
;
11297 #ifdef HAVE_WINDOW_SYSTEM
11298 ++clear_image_cache_count
;
11301 /* Build desired matrices, and update the display. If
11302 consider_all_windows_p is non-zero, do it for all windows on all
11303 frames. Otherwise do it for selected_window, only. */
11305 if (consider_all_windows_p
)
11307 Lisp_Object tail
, frame
;
11309 FOR_EACH_FRAME (tail
, frame
)
11310 XFRAME (frame
)->updated_p
= 0;
11312 /* Recompute # windows showing selected buffer. This will be
11313 incremented each time such a window is displayed. */
11316 FOR_EACH_FRAME (tail
, frame
)
11318 struct frame
*f
= XFRAME (frame
);
11320 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
11322 if (! EQ (frame
, selected_frame
))
11323 /* Select the frame, for the sake of frame-local
11325 select_frame_for_redisplay (frame
);
11327 /* Mark all the scroll bars to be removed; we'll redeem
11328 the ones we want when we redisplay their windows. */
11329 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
11330 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
11332 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11333 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11335 /* Any scroll bars which redisplay_windows should have
11336 nuked should now go away. */
11337 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
11338 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
11340 /* If fonts changed, display again. */
11341 /* ??? rms: I suspect it is a mistake to jump all the way
11342 back to retry here. It should just retry this frame. */
11343 if (fonts_changed_p
)
11346 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11348 /* See if we have to hscroll. */
11349 if (!f
->already_hscrolled_p
)
11351 f
->already_hscrolled_p
= 1;
11352 if (hscroll_windows (f
->root_window
))
11356 /* Prevent various kinds of signals during display
11357 update. stdio is not robust about handling
11358 signals, which can cause an apparent I/O
11360 if (interrupt_input
)
11361 unrequest_sigio ();
11364 /* Update the display. */
11365 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11366 pause
|= update_frame (f
, 0, 0);
11367 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
11379 /* Do the mark_window_display_accurate after all windows have
11380 been redisplayed because this call resets flags in buffers
11381 which are needed for proper redisplay. */
11382 FOR_EACH_FRAME (tail
, frame
)
11384 struct frame
*f
= XFRAME (frame
);
11387 mark_window_display_accurate (f
->root_window
, 1);
11388 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
11389 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
11394 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11396 Lisp_Object mini_window
;
11397 struct frame
*mini_frame
;
11399 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11400 /* Use list_of_error, not Qerror, so that
11401 we catch only errors and don't run the debugger. */
11402 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11404 redisplay_window_error
);
11406 /* Compare desired and current matrices, perform output. */
11409 /* If fonts changed, display again. */
11410 if (fonts_changed_p
)
11413 /* Prevent various kinds of signals during display update.
11414 stdio is not robust about handling signals,
11415 which can cause an apparent I/O error. */
11416 if (interrupt_input
)
11417 unrequest_sigio ();
11420 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11422 if (hscroll_windows (selected_window
))
11425 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11426 pause
= update_frame (sf
, 0, 0);
11429 /* We may have called echo_area_display at the top of this
11430 function. If the echo area is on another frame, that may
11431 have put text on a frame other than the selected one, so the
11432 above call to update_frame would not have caught it. Catch
11434 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11435 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11437 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11439 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11440 pause
|= update_frame (mini_frame
, 0, 0);
11441 if (!pause
&& hscroll_windows (mini_window
))
11446 /* If display was paused because of pending input, make sure we do a
11447 thorough update the next time. */
11450 /* Prevent the optimization at the beginning of
11451 redisplay_internal that tries a single-line update of the
11452 line containing the cursor in the selected window. */
11453 CHARPOS (this_line_start_pos
) = 0;
11455 /* Let the overlay arrow be updated the next time. */
11456 update_overlay_arrows (0);
11458 /* If we pause after scrolling, some rows in the current
11459 matrices of some windows are not valid. */
11460 if (!WINDOW_FULL_WIDTH_P (w
)
11461 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11462 update_mode_lines
= 1;
11466 if (!consider_all_windows_p
)
11468 /* This has already been done above if
11469 consider_all_windows_p is set. */
11470 mark_window_display_accurate_1 (w
, 1);
11472 /* Say overlay arrows are up to date. */
11473 update_overlay_arrows (1);
11475 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
11476 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
11479 update_mode_lines
= 0;
11480 windows_or_buffers_changed
= 0;
11481 cursor_type_changed
= 0;
11484 /* Start SIGIO interrupts coming again. Having them off during the
11485 code above makes it less likely one will discard output, but not
11486 impossible, since there might be stuff in the system buffer here.
11487 But it is much hairier to try to do anything about that. */
11488 if (interrupt_input
)
11492 /* If a frame has become visible which was not before, redisplay
11493 again, so that we display it. Expose events for such a frame
11494 (which it gets when becoming visible) don't call the parts of
11495 redisplay constructing glyphs, so simply exposing a frame won't
11496 display anything in this case. So, we have to display these
11497 frames here explicitly. */
11500 Lisp_Object tail
, frame
;
11503 FOR_EACH_FRAME (tail
, frame
)
11505 int this_is_visible
= 0;
11507 if (XFRAME (frame
)->visible
)
11508 this_is_visible
= 1;
11509 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11510 if (XFRAME (frame
)->visible
)
11511 this_is_visible
= 1;
11513 if (this_is_visible
)
11517 if (new_count
!= number_of_visible_frames
)
11518 windows_or_buffers_changed
++;
11521 /* Change frame size now if a change is pending. */
11522 do_pending_window_change (1);
11524 /* If we just did a pending size change, or have additional
11525 visible frames, redisplay again. */
11526 if (windows_or_buffers_changed
&& !pause
)
11529 /* Clear the face cache eventually. */
11530 if (consider_all_windows_p
)
11532 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11534 clear_face_cache (0);
11535 clear_face_cache_count
= 0;
11537 #ifdef HAVE_WINDOW_SYSTEM
11538 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11540 Lisp_Object tail
, frame
;
11541 FOR_EACH_FRAME (tail
, frame
)
11543 struct frame
*f
= XFRAME (frame
);
11544 if (FRAME_WINDOW_P (f
))
11545 clear_image_cache (f
, 0);
11547 clear_image_cache_count
= 0;
11549 #endif /* HAVE_WINDOW_SYSTEM */
11553 unbind_to (count
, Qnil
);
11558 /* Redisplay, but leave alone any recent echo area message unless
11559 another message has been requested in its place.
11561 This is useful in situations where you need to redisplay but no
11562 user action has occurred, making it inappropriate for the message
11563 area to be cleared. See tracking_off and
11564 wait_reading_process_output for examples of these situations.
11566 FROM_WHERE is an integer saying from where this function was
11567 called. This is useful for debugging. */
11570 redisplay_preserve_echo_area (from_where
)
11573 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
11575 if (!NILP (echo_area_buffer
[1]))
11577 /* We have a previously displayed message, but no current
11578 message. Redisplay the previous message. */
11579 display_last_displayed_message_p
= 1;
11580 redisplay_internal (1);
11581 display_last_displayed_message_p
= 0;
11584 redisplay_internal (1);
11586 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
11587 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11588 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
11592 /* Function registered with record_unwind_protect in
11593 redisplay_internal. Reset redisplaying_p to the value it had
11594 before redisplay_internal was called, and clear
11595 prevent_freeing_realized_faces_p. It also selects the previously
11596 selected frame, unless it has been deleted (by an X connection
11597 failure during redisplay, for example). */
11600 unwind_redisplay (val
)
11603 Lisp_Object old_redisplaying_p
, old_frame
;
11605 old_redisplaying_p
= XCAR (val
);
11606 redisplaying_p
= XFASTINT (old_redisplaying_p
);
11607 old_frame
= XCDR (val
);
11608 if (! EQ (old_frame
, selected_frame
)
11609 && FRAME_LIVE_P (XFRAME (old_frame
)))
11610 select_frame_for_redisplay (old_frame
);
11615 /* Mark the display of window W as accurate or inaccurate. If
11616 ACCURATE_P is non-zero mark display of W as accurate. If
11617 ACCURATE_P is zero, arrange for W to be redisplayed the next time
11618 redisplay_internal is called. */
11621 mark_window_display_accurate_1 (w
, accurate_p
)
11625 if (BUFFERP (w
->buffer
))
11627 struct buffer
*b
= XBUFFER (w
->buffer
);
11630 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
11631 w
->last_overlay_modified
11632 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
11634 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
11638 b
->clip_changed
= 0;
11639 b
->prevent_redisplay_optimizations_p
= 0;
11641 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
11642 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
11643 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
11644 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
11646 w
->current_matrix
->buffer
= b
;
11647 w
->current_matrix
->begv
= BUF_BEGV (b
);
11648 w
->current_matrix
->zv
= BUF_ZV (b
);
11650 w
->last_cursor
= w
->cursor
;
11651 w
->last_cursor_off_p
= w
->cursor_off_p
;
11653 if (w
== XWINDOW (selected_window
))
11654 w
->last_point
= make_number (BUF_PT (b
));
11656 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
11662 w
->window_end_valid
= w
->buffer
;
11663 #if 0 /* This is incorrect with variable-height lines. */
11664 xassert (XINT (w
->window_end_vpos
)
11665 < (WINDOW_TOTAL_LINES (w
)
11666 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
11668 w
->update_mode_line
= Qnil
;
11673 /* Mark the display of windows in the window tree rooted at WINDOW as
11674 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
11675 windows as accurate. If ACCURATE_P is zero, arrange for windows to
11676 be redisplayed the next time redisplay_internal is called. */
11679 mark_window_display_accurate (window
, accurate_p
)
11680 Lisp_Object window
;
11685 for (; !NILP (window
); window
= w
->next
)
11687 w
= XWINDOW (window
);
11688 mark_window_display_accurate_1 (w
, accurate_p
);
11690 if (!NILP (w
->vchild
))
11691 mark_window_display_accurate (w
->vchild
, accurate_p
);
11692 if (!NILP (w
->hchild
))
11693 mark_window_display_accurate (w
->hchild
, accurate_p
);
11698 update_overlay_arrows (1);
11702 /* Force a thorough redisplay the next time by setting
11703 last_arrow_position and last_arrow_string to t, which is
11704 unequal to any useful value of Voverlay_arrow_... */
11705 update_overlay_arrows (-1);
11710 /* Return value in display table DP (Lisp_Char_Table *) for character
11711 C. Since a display table doesn't have any parent, we don't have to
11712 follow parent. Do not call this function directly but use the
11713 macro DISP_CHAR_VECTOR. */
11716 disp_char_vector (dp
, c
)
11717 struct Lisp_Char_Table
*dp
;
11723 if (SINGLE_BYTE_CHAR_P (c
))
11724 return (dp
->contents
[c
]);
11726 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
11729 else if (code
[2] < 32)
11732 /* Here, the possible range of code[0] (== charset ID) is
11733 128..max_charset. Since the top level char table contains data
11734 for multibyte characters after 256th element, we must increment
11735 code[0] by 128 to get a correct index. */
11737 code
[3] = -1; /* anchor */
11739 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
11741 val
= dp
->contents
[code
[i
]];
11742 if (!SUB_CHAR_TABLE_P (val
))
11743 return (NILP (val
) ? dp
->defalt
: val
);
11746 /* Here, val is a sub char table. We return the default value of
11748 return (dp
->defalt
);
11753 /***********************************************************************
11755 ***********************************************************************/
11757 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11760 redisplay_windows (window
)
11761 Lisp_Object window
;
11763 while (!NILP (window
))
11765 struct window
*w
= XWINDOW (window
);
11767 if (!NILP (w
->hchild
))
11768 redisplay_windows (w
->hchild
);
11769 else if (!NILP (w
->vchild
))
11770 redisplay_windows (w
->vchild
);
11773 displayed_buffer
= XBUFFER (w
->buffer
);
11774 /* Use list_of_error, not Qerror, so that
11775 we catch only errors and don't run the debugger. */
11776 internal_condition_case_1 (redisplay_window_0
, window
,
11778 redisplay_window_error
);
11786 redisplay_window_error ()
11788 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11793 redisplay_window_0 (window
)
11794 Lisp_Object window
;
11796 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11797 redisplay_window (window
, 0);
11802 redisplay_window_1 (window
)
11803 Lisp_Object window
;
11805 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11806 redisplay_window (window
, 1);
11811 /* Increment GLYPH until it reaches END or CONDITION fails while
11812 adding (GLYPH)->pixel_width to X. */
11814 #define SKIP_GLYPHS(glyph, end, x, condition) \
11817 (x) += (glyph)->pixel_width; \
11820 while ((glyph) < (end) && (condition))
11823 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11824 DELTA is the number of bytes by which positions recorded in ROW
11825 differ from current buffer positions.
11827 Return 0 if cursor is not on this row. 1 otherwise. */
11830 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11832 struct glyph_row
*row
;
11833 struct glyph_matrix
*matrix
;
11834 int delta
, delta_bytes
, dy
, dvpos
;
11836 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11837 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11838 struct glyph
*cursor
= NULL
;
11839 /* The first glyph that starts a sequence of glyphs from string. */
11840 struct glyph
*string_start
;
11841 /* The X coordinate of string_start. */
11842 int string_start_x
;
11843 /* The last known character position. */
11844 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11845 /* The last known character position before string_start. */
11846 int string_before_pos
;
11849 int cursor_from_overlay_pos
= 0;
11850 int pt_old
= PT
- delta
;
11852 /* Skip over glyphs not having an object at the start of the row.
11853 These are special glyphs like truncation marks on terminal
11855 if (row
->displays_text_p
)
11857 && INTEGERP (glyph
->object
)
11858 && glyph
->charpos
< 0)
11860 x
+= glyph
->pixel_width
;
11864 string_start
= NULL
;
11866 && !INTEGERP (glyph
->object
)
11867 && (!BUFFERP (glyph
->object
)
11868 || (last_pos
= glyph
->charpos
) < pt_old
))
11870 if (! STRINGP (glyph
->object
))
11872 string_start
= NULL
;
11873 x
+= glyph
->pixel_width
;
11875 if (cursor_from_overlay_pos
11876 && last_pos
>= cursor_from_overlay_pos
)
11878 cursor_from_overlay_pos
= 0;
11884 if (string_start
== NULL
)
11886 string_before_pos
= last_pos
;
11887 string_start
= glyph
;
11888 string_start_x
= x
;
11890 /* Skip all glyphs from string. */
11895 if ((cursor
== NULL
|| glyph
> cursor
)
11896 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
11897 Qcursor
, (glyph
)->object
),
11899 && (pos
= string_buffer_position (w
, glyph
->object
,
11900 string_before_pos
),
11901 (pos
== 0 /* From overlay */
11902 || pos
== pt_old
)))
11904 /* Estimate overlay buffer position from the buffer
11905 positions of the glyphs before and after the overlay.
11906 Add 1 to last_pos so that if point corresponds to the
11907 glyph right after the overlay, we still use a 'cursor'
11908 property found in that overlay. */
11909 cursor_from_overlay_pos
= (pos
? 0 : last_pos
11910 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
11914 x
+= glyph
->pixel_width
;
11917 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
11921 if (cursor
!= NULL
)
11926 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
11928 /* Scan back over the ellipsis glyphs, decrementing positions. */
11929 while (glyph
> row
->glyphs
[TEXT_AREA
]
11930 && (glyph
- 1)->charpos
== last_pos
)
11931 glyph
--, x
-= glyph
->pixel_width
;
11932 /* That loop always goes one position too far,
11933 including the glyph before the ellipsis.
11934 So scan forward over that one. */
11935 x
+= glyph
->pixel_width
;
11938 else if (string_start
11939 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
11941 /* We may have skipped over point because the previous glyphs
11942 are from string. As there's no easy way to know the
11943 character position of the current glyph, find the correct
11944 glyph on point by scanning from string_start again. */
11946 Lisp_Object string
;
11947 struct glyph
*stop
= glyph
;
11950 limit
= make_number (pt_old
+ 1);
11951 glyph
= string_start
;
11952 x
= string_start_x
;
11953 string
= glyph
->object
;
11954 pos
= string_buffer_position (w
, string
, string_before_pos
);
11955 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
11956 because we always put cursor after overlay strings. */
11957 while (pos
== 0 && glyph
< stop
)
11959 string
= glyph
->object
;
11960 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
11962 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
11965 while (glyph
< stop
)
11967 pos
= XINT (Fnext_single_char_property_change
11968 (make_number (pos
), Qdisplay
, Qnil
, limit
));
11971 /* Skip glyphs from the same string. */
11972 string
= glyph
->object
;
11973 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
11974 /* Skip glyphs from an overlay. */
11975 while (glyph
< stop
11976 && ! string_buffer_position (w
, glyph
->object
, pos
))
11978 string
= glyph
->object
;
11979 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
11983 /* If we reached the end of the line, and end was from a string,
11984 cursor is not on this line. */
11985 if (glyph
== end
&& row
->continued_p
)
11989 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
11991 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
11992 w
->cursor
.y
= row
->y
+ dy
;
11994 if (w
== XWINDOW (selected_window
))
11996 if (!row
->continued_p
11997 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12000 this_line_buffer
= XBUFFER (w
->buffer
);
12002 CHARPOS (this_line_start_pos
)
12003 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12004 BYTEPOS (this_line_start_pos
)
12005 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12007 CHARPOS (this_line_end_pos
)
12008 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12009 BYTEPOS (this_line_end_pos
)
12010 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12012 this_line_y
= w
->cursor
.y
;
12013 this_line_pixel_height
= row
->height
;
12014 this_line_vpos
= w
->cursor
.vpos
;
12015 this_line_start_x
= row
->x
;
12018 CHARPOS (this_line_start_pos
) = 0;
12025 /* Run window scroll functions, if any, for WINDOW with new window
12026 start STARTP. Sets the window start of WINDOW to that position.
12028 We assume that the window's buffer is really current. */
12030 static INLINE
struct text_pos
12031 run_window_scroll_functions (window
, startp
)
12032 Lisp_Object window
;
12033 struct text_pos startp
;
12035 struct window
*w
= XWINDOW (window
);
12036 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12038 if (current_buffer
!= XBUFFER (w
->buffer
))
12041 if (!NILP (Vwindow_scroll_functions
))
12043 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12044 make_number (CHARPOS (startp
)));
12045 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12046 /* In case the hook functions switch buffers. */
12047 if (current_buffer
!= XBUFFER (w
->buffer
))
12048 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12055 /* Make sure the line containing the cursor is fully visible.
12056 A value of 1 means there is nothing to be done.
12057 (Either the line is fully visible, or it cannot be made so,
12058 or we cannot tell.)
12060 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12061 is higher than window.
12063 A value of 0 means the caller should do scrolling
12064 as if point had gone off the screen. */
12067 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12070 int current_matrix_p
;
12072 struct glyph_matrix
*matrix
;
12073 struct glyph_row
*row
;
12076 if (!make_cursor_line_fully_visible_p
)
12079 /* It's not always possible to find the cursor, e.g, when a window
12080 is full of overlay strings. Don't do anything in that case. */
12081 if (w
->cursor
.vpos
< 0)
12084 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12085 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12087 /* If the cursor row is not partially visible, there's nothing to do. */
12088 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12091 /* If the row the cursor is in is taller than the window's height,
12092 it's not clear what to do, so do nothing. */
12093 window_height
= window_box_height (w
);
12094 if (row
->height
>= window_height
)
12096 if (!force_p
|| MINI_WINDOW_P (w
)
12097 || w
->vscroll
|| w
->cursor
.vpos
== 0)
12103 /* This code used to try to scroll the window just enough to make
12104 the line visible. It returned 0 to say that the caller should
12105 allocate larger glyph matrices. */
12107 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
12109 int dy
= row
->height
- row
->visible_height
;
12112 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12114 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
12116 int dy
= - (row
->height
- row
->visible_height
);
12119 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12122 /* When we change the cursor y-position of the selected window,
12123 change this_line_y as well so that the display optimization for
12124 the cursor line of the selected window in redisplay_internal uses
12125 the correct y-position. */
12126 if (w
== XWINDOW (selected_window
))
12127 this_line_y
= w
->cursor
.y
;
12129 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
12130 redisplay with larger matrices. */
12131 if (matrix
->nrows
< required_matrix_height (w
))
12133 fonts_changed_p
= 1;
12142 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
12143 non-zero means only WINDOW is redisplayed in redisplay_internal.
12144 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
12145 in redisplay_window to bring a partially visible line into view in
12146 the case that only the cursor has moved.
12148 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
12149 last screen line's vertical height extends past the end of the screen.
12153 1 if scrolling succeeded
12155 0 if scrolling didn't find point.
12157 -1 if new fonts have been loaded so that we must interrupt
12158 redisplay, adjust glyph matrices, and try again. */
12164 SCROLLING_NEED_LARGER_MATRICES
12168 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
12169 scroll_step
, temp_scroll_step
, last_line_misfit
)
12170 Lisp_Object window
;
12171 int just_this_one_p
;
12172 EMACS_INT scroll_conservatively
, scroll_step
;
12173 int temp_scroll_step
;
12174 int last_line_misfit
;
12176 struct window
*w
= XWINDOW (window
);
12177 struct frame
*f
= XFRAME (w
->frame
);
12178 struct text_pos scroll_margin_pos
;
12179 struct text_pos pos
;
12180 struct text_pos startp
;
12182 Lisp_Object window_end
;
12183 int this_scroll_margin
;
12187 int amount_to_scroll
= 0;
12188 Lisp_Object aggressive
;
12190 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
12193 debug_method_add (w
, "try_scrolling");
12196 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12198 /* Compute scroll margin height in pixels. We scroll when point is
12199 within this distance from the top or bottom of the window. */
12200 if (scroll_margin
> 0)
12202 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12203 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12206 this_scroll_margin
= 0;
12208 /* Force scroll_conservatively to have a reasonable value so it doesn't
12209 cause an overflow while computing how much to scroll. */
12210 if (scroll_conservatively
)
12211 scroll_conservatively
= min (scroll_conservatively
,
12212 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
12214 /* Compute how much we should try to scroll maximally to bring point
12216 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
12217 scroll_max
= max (scroll_step
,
12218 max (scroll_conservatively
, temp_scroll_step
));
12219 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
12220 || NUMBERP (current_buffer
->scroll_up_aggressively
))
12221 /* We're trying to scroll because of aggressive scrolling
12222 but no scroll_step is set. Choose an arbitrary one. Maybe
12223 there should be a variable for this. */
12227 scroll_max
*= FRAME_LINE_HEIGHT (f
);
12229 /* Decide whether we have to scroll down. Start at the window end
12230 and move this_scroll_margin up to find the position of the scroll
12232 window_end
= Fwindow_end (window
, Qt
);
12236 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
12237 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
12239 if (this_scroll_margin
|| extra_scroll_margin_lines
)
12241 start_display (&it
, w
, scroll_margin_pos
);
12242 if (this_scroll_margin
)
12243 move_it_vertically_backward (&it
, this_scroll_margin
);
12244 if (extra_scroll_margin_lines
)
12245 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
12246 scroll_margin_pos
= it
.current
.pos
;
12249 if (PT
>= CHARPOS (scroll_margin_pos
))
12253 /* Point is in the scroll margin at the bottom of the window, or
12254 below. Compute a new window start that makes point visible. */
12256 /* Compute the distance from the scroll margin to PT.
12257 Give up if the distance is greater than scroll_max. */
12258 start_display (&it
, w
, scroll_margin_pos
);
12260 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12261 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12263 /* To make point visible, we have to move the window start
12264 down so that the line the cursor is in is visible, which
12265 means we have to add in the height of the cursor line. */
12266 dy
= line_bottom_y (&it
) - y0
;
12268 if (dy
> scroll_max
)
12269 return SCROLLING_FAILED
;
12271 /* Move the window start down. If scrolling conservatively,
12272 move it just enough down to make point visible. If
12273 scroll_step is set, move it down by scroll_step. */
12274 start_display (&it
, w
, startp
);
12276 if (scroll_conservatively
)
12277 /* Set AMOUNT_TO_SCROLL to at least one line,
12278 and at most scroll_conservatively lines. */
12280 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12281 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12282 else if (scroll_step
|| temp_scroll_step
)
12283 amount_to_scroll
= scroll_max
;
12286 aggressive
= current_buffer
->scroll_up_aggressively
;
12287 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12288 if (NUMBERP (aggressive
))
12290 double float_amount
= XFLOATINT (aggressive
) * height
;
12291 amount_to_scroll
= float_amount
;
12292 if (amount_to_scroll
== 0 && float_amount
> 0)
12293 amount_to_scroll
= 1;
12297 if (amount_to_scroll
<= 0)
12298 return SCROLLING_FAILED
;
12300 /* If moving by amount_to_scroll leaves STARTP unchanged,
12301 move it down one screen line. */
12303 move_it_vertically (&it
, amount_to_scroll
);
12304 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12305 move_it_by_lines (&it
, 1, 1);
12306 startp
= it
.current
.pos
;
12310 /* See if point is inside the scroll margin at the top of the
12312 scroll_margin_pos
= startp
;
12313 if (this_scroll_margin
)
12315 start_display (&it
, w
, startp
);
12316 move_it_vertically (&it
, this_scroll_margin
);
12317 scroll_margin_pos
= it
.current
.pos
;
12320 if (PT
< CHARPOS (scroll_margin_pos
))
12322 /* Point is in the scroll margin at the top of the window or
12323 above what is displayed in the window. */
12326 /* Compute the vertical distance from PT to the scroll
12327 margin position. Give up if distance is greater than
12329 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12330 start_display (&it
, w
, pos
);
12332 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12333 it
.last_visible_y
, -1,
12334 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12335 dy
= it
.current_y
- y0
;
12336 if (dy
> scroll_max
)
12337 return SCROLLING_FAILED
;
12339 /* Compute new window start. */
12340 start_display (&it
, w
, startp
);
12342 if (scroll_conservatively
)
12344 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12345 else if (scroll_step
|| temp_scroll_step
)
12346 amount_to_scroll
= scroll_max
;
12349 aggressive
= current_buffer
->scroll_down_aggressively
;
12350 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12351 if (NUMBERP (aggressive
))
12353 double float_amount
= XFLOATINT (aggressive
) * height
;
12354 amount_to_scroll
= float_amount
;
12355 if (amount_to_scroll
== 0 && float_amount
> 0)
12356 amount_to_scroll
= 1;
12360 if (amount_to_scroll
<= 0)
12361 return SCROLLING_FAILED
;
12363 move_it_vertically_backward (&it
, amount_to_scroll
);
12364 startp
= it
.current
.pos
;
12368 /* Run window scroll functions. */
12369 startp
= run_window_scroll_functions (window
, startp
);
12371 /* Display the window. Give up if new fonts are loaded, or if point
12373 if (!try_window (window
, startp
, 0))
12374 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12375 else if (w
->cursor
.vpos
< 0)
12377 clear_glyph_matrix (w
->desired_matrix
);
12378 rc
= SCROLLING_FAILED
;
12382 /* Maybe forget recorded base line for line number display. */
12383 if (!just_this_one_p
12384 || current_buffer
->clip_changed
12385 || BEG_UNCHANGED
< CHARPOS (startp
))
12386 w
->base_line_number
= Qnil
;
12388 /* If cursor ends up on a partially visible line,
12389 treat that as being off the bottom of the screen. */
12390 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12392 clear_glyph_matrix (w
->desired_matrix
);
12393 ++extra_scroll_margin_lines
;
12396 rc
= SCROLLING_SUCCESS
;
12403 /* Compute a suitable window start for window W if display of W starts
12404 on a continuation line. Value is non-zero if a new window start
12407 The new window start will be computed, based on W's width, starting
12408 from the start of the continued line. It is the start of the
12409 screen line with the minimum distance from the old start W->start. */
12412 compute_window_start_on_continuation_line (w
)
12415 struct text_pos pos
, start_pos
;
12416 int window_start_changed_p
= 0;
12418 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12420 /* If window start is on a continuation line... Window start may be
12421 < BEGV in case there's invisible text at the start of the
12422 buffer (M-x rmail, for example). */
12423 if (CHARPOS (start_pos
) > BEGV
12424 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12427 struct glyph_row
*row
;
12429 /* Handle the case that the window start is out of range. */
12430 if (CHARPOS (start_pos
) < BEGV
)
12431 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12432 else if (CHARPOS (start_pos
) > ZV
)
12433 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12435 /* Find the start of the continued line. This should be fast
12436 because scan_buffer is fast (newline cache). */
12437 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12438 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12439 row
, DEFAULT_FACE_ID
);
12440 reseat_at_previous_visible_line_start (&it
);
12442 /* If the line start is "too far" away from the window start,
12443 say it takes too much time to compute a new window start. */
12444 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12445 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12447 int min_distance
, distance
;
12449 /* Move forward by display lines to find the new window
12450 start. If window width was enlarged, the new start can
12451 be expected to be > the old start. If window width was
12452 decreased, the new window start will be < the old start.
12453 So, we're looking for the display line start with the
12454 minimum distance from the old window start. */
12455 pos
= it
.current
.pos
;
12456 min_distance
= INFINITY
;
12457 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12458 distance
< min_distance
)
12460 min_distance
= distance
;
12461 pos
= it
.current
.pos
;
12462 move_it_by_lines (&it
, 1, 0);
12465 /* Set the window start there. */
12466 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12467 window_start_changed_p
= 1;
12471 return window_start_changed_p
;
12475 /* Try cursor movement in case text has not changed in window WINDOW,
12476 with window start STARTP. Value is
12478 CURSOR_MOVEMENT_SUCCESS if successful
12480 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12482 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12483 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12484 we want to scroll as if scroll-step were set to 1. See the code.
12486 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12487 which case we have to abort this redisplay, and adjust matrices
12492 CURSOR_MOVEMENT_SUCCESS
,
12493 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12494 CURSOR_MOVEMENT_MUST_SCROLL
,
12495 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12499 try_cursor_movement (window
, startp
, scroll_step
)
12500 Lisp_Object window
;
12501 struct text_pos startp
;
12504 struct window
*w
= XWINDOW (window
);
12505 struct frame
*f
= XFRAME (w
->frame
);
12506 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12509 if (inhibit_try_cursor_movement
)
12513 /* Handle case where text has not changed, only point, and it has
12514 not moved off the frame. */
12515 if (/* Point may be in this window. */
12516 PT
>= CHARPOS (startp
)
12517 /* Selective display hasn't changed. */
12518 && !current_buffer
->clip_changed
12519 /* Function force-mode-line-update is used to force a thorough
12520 redisplay. It sets either windows_or_buffers_changed or
12521 update_mode_lines. So don't take a shortcut here for these
12523 && !update_mode_lines
12524 && !windows_or_buffers_changed
12525 && !cursor_type_changed
12526 /* Can't use this case if highlighting a region. When a
12527 region exists, cursor movement has to do more than just
12529 && !(!NILP (Vtransient_mark_mode
)
12530 && !NILP (current_buffer
->mark_active
))
12531 && NILP (w
->region_showing
)
12532 && NILP (Vshow_trailing_whitespace
)
12533 /* Right after splitting windows, last_point may be nil. */
12534 && INTEGERP (w
->last_point
)
12535 /* This code is not used for mini-buffer for the sake of the case
12536 of redisplaying to replace an echo area message; since in
12537 that case the mini-buffer contents per se are usually
12538 unchanged. This code is of no real use in the mini-buffer
12539 since the handling of this_line_start_pos, etc., in redisplay
12540 handles the same cases. */
12541 && !EQ (window
, minibuf_window
)
12542 /* When splitting windows or for new windows, it happens that
12543 redisplay is called with a nil window_end_vpos or one being
12544 larger than the window. This should really be fixed in
12545 window.c. I don't have this on my list, now, so we do
12546 approximately the same as the old redisplay code. --gerd. */
12547 && INTEGERP (w
->window_end_vpos
)
12548 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12549 && (FRAME_WINDOW_P (f
)
12550 || !overlay_arrow_in_current_buffer_p ()))
12552 int this_scroll_margin
, top_scroll_margin
;
12553 struct glyph_row
*row
= NULL
;
12556 debug_method_add (w
, "cursor movement");
12559 /* Scroll if point within this distance from the top or bottom
12560 of the window. This is a pixel value. */
12561 this_scroll_margin
= max (0, scroll_margin
);
12562 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12563 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12565 top_scroll_margin
= this_scroll_margin
;
12566 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12567 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12569 /* Start with the row the cursor was displayed during the last
12570 not paused redisplay. Give up if that row is not valid. */
12571 if (w
->last_cursor
.vpos
< 0
12572 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12573 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12576 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12577 if (row
->mode_line_p
)
12579 if (!row
->enabled_p
)
12580 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12583 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12586 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12588 if (PT
> XFASTINT (w
->last_point
))
12590 /* Point has moved forward. */
12591 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12592 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12594 xassert (row
->enabled_p
);
12598 /* The end position of a row equals the start position
12599 of the next row. If PT is there, we would rather
12600 display it in the next line. */
12601 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12602 && MATRIX_ROW_END_CHARPOS (row
) == PT
12603 && !cursor_row_p (w
, row
))
12606 /* If within the scroll margin, scroll. Note that
12607 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
12608 the next line would be drawn, and that
12609 this_scroll_margin can be zero. */
12610 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
12611 || PT
> MATRIX_ROW_END_CHARPOS (row
)
12612 /* Line is completely visible last line in window
12613 and PT is to be set in the next line. */
12614 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
12615 && PT
== MATRIX_ROW_END_CHARPOS (row
)
12616 && !row
->ends_at_zv_p
12617 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12620 else if (PT
< XFASTINT (w
->last_point
))
12622 /* Cursor has to be moved backward. Note that PT >=
12623 CHARPOS (startp) because of the outer if-statement. */
12624 while (!row
->mode_line_p
12625 && (MATRIX_ROW_START_CHARPOS (row
) > PT
12626 || (MATRIX_ROW_START_CHARPOS (row
) == PT
12627 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
12628 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
12629 row
> w
->current_matrix
->rows
12630 && (row
-1)->ends_in_newline_from_string_p
))))
12631 && (row
->y
> top_scroll_margin
12632 || CHARPOS (startp
) == BEGV
))
12634 xassert (row
->enabled_p
);
12638 /* Consider the following case: Window starts at BEGV,
12639 there is invisible, intangible text at BEGV, so that
12640 display starts at some point START > BEGV. It can
12641 happen that we are called with PT somewhere between
12642 BEGV and START. Try to handle that case. */
12643 if (row
< w
->current_matrix
->rows
12644 || row
->mode_line_p
)
12646 row
= w
->current_matrix
->rows
;
12647 if (row
->mode_line_p
)
12651 /* Due to newlines in overlay strings, we may have to
12652 skip forward over overlay strings. */
12653 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12654 && MATRIX_ROW_END_CHARPOS (row
) == PT
12655 && !cursor_row_p (w
, row
))
12658 /* If within the scroll margin, scroll. */
12659 if (row
->y
< top_scroll_margin
12660 && CHARPOS (startp
) != BEGV
)
12665 /* Cursor did not move. So don't scroll even if cursor line
12666 is partially visible, as it was so before. */
12667 rc
= CURSOR_MOVEMENT_SUCCESS
;
12670 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
12671 || PT
> MATRIX_ROW_END_CHARPOS (row
))
12673 /* if PT is not in the glyph row, give up. */
12674 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12676 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
12677 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
12678 && make_cursor_line_fully_visible_p
)
12680 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
12681 && !row
->ends_at_zv_p
12682 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12683 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12684 else if (row
->height
> window_box_height (w
))
12686 /* If we end up in a partially visible line, let's
12687 make it fully visible, except when it's taller
12688 than the window, in which case we can't do much
12691 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12695 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12696 if (!cursor_row_fully_visible_p (w
, 0, 1))
12697 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12699 rc
= CURSOR_MOVEMENT_SUCCESS
;
12703 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12708 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
12710 rc
= CURSOR_MOVEMENT_SUCCESS
;
12715 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12716 && MATRIX_ROW_START_CHARPOS (row
) == PT
12717 && cursor_row_p (w
, row
));
12726 set_vertical_scroll_bar (w
)
12729 int start
, end
, whole
;
12731 /* Calculate the start and end positions for the current window.
12732 At some point, it would be nice to choose between scrollbars
12733 which reflect the whole buffer size, with special markers
12734 indicating narrowing, and scrollbars which reflect only the
12737 Note that mini-buffers sometimes aren't displaying any text. */
12738 if (!MINI_WINDOW_P (w
)
12739 || (w
== XWINDOW (minibuf_window
)
12740 && NILP (echo_area_buffer
[0])))
12742 struct buffer
*buf
= XBUFFER (w
->buffer
);
12743 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12744 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12745 /* I don't think this is guaranteed to be right. For the
12746 moment, we'll pretend it is. */
12747 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12751 if (whole
< (end
- start
))
12752 whole
= end
- start
;
12755 start
= end
= whole
= 0;
12757 /* Indicate what this scroll bar ought to be displaying now. */
12758 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
12759 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
12760 (w
, end
- start
, whole
, start
);
12764 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
12765 selected_window is redisplayed.
12767 We can return without actually redisplaying the window if
12768 fonts_changed_p is nonzero. In that case, redisplay_internal will
12772 redisplay_window (window
, just_this_one_p
)
12773 Lisp_Object window
;
12774 int just_this_one_p
;
12776 struct window
*w
= XWINDOW (window
);
12777 struct frame
*f
= XFRAME (w
->frame
);
12778 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12779 struct buffer
*old
= current_buffer
;
12780 struct text_pos lpoint
, opoint
, startp
;
12781 int update_mode_line
;
12784 /* Record it now because it's overwritten. */
12785 int current_matrix_up_to_date_p
= 0;
12786 int used_current_matrix_p
= 0;
12787 /* This is less strict than current_matrix_up_to_date_p.
12788 It indictes that the buffer contents and narrowing are unchanged. */
12789 int buffer_unchanged_p
= 0;
12790 int temp_scroll_step
= 0;
12791 int count
= SPECPDL_INDEX ();
12793 int centering_position
= -1;
12794 int last_line_misfit
= 0;
12795 int beg_unchanged
, end_unchanged
;
12797 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12800 /* W must be a leaf window here. */
12801 xassert (!NILP (w
->buffer
));
12803 *w
->desired_matrix
->method
= 0;
12806 specbind (Qinhibit_point_motion_hooks
, Qt
);
12808 reconsider_clip_changes (w
, buffer
);
12810 /* Has the mode line to be updated? */
12811 update_mode_line
= (!NILP (w
->update_mode_line
)
12812 || update_mode_lines
12813 || buffer
->clip_changed
12814 || buffer
->prevent_redisplay_optimizations_p
);
12816 if (MINI_WINDOW_P (w
))
12818 if (w
== XWINDOW (echo_area_window
)
12819 && !NILP (echo_area_buffer
[0]))
12821 if (update_mode_line
)
12822 /* We may have to update a tty frame's menu bar or a
12823 tool-bar. Example `M-x C-h C-h C-g'. */
12824 goto finish_menu_bars
;
12826 /* We've already displayed the echo area glyphs in this window. */
12827 goto finish_scroll_bars
;
12829 else if ((w
!= XWINDOW (minibuf_window
)
12830 || minibuf_level
== 0)
12831 /* When buffer is nonempty, redisplay window normally. */
12832 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12833 /* Quail displays non-mini buffers in minibuffer window.
12834 In that case, redisplay the window normally. */
12835 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12837 /* W is a mini-buffer window, but it's not active, so clear
12839 int yb
= window_text_bottom_y (w
);
12840 struct glyph_row
*row
;
12843 for (y
= 0, row
= w
->desired_matrix
->rows
;
12845 y
+= row
->height
, ++row
)
12846 blank_row (w
, row
, y
);
12847 goto finish_scroll_bars
;
12850 clear_glyph_matrix (w
->desired_matrix
);
12853 /* Otherwise set up data on this window; select its buffer and point
12855 /* Really select the buffer, for the sake of buffer-local
12857 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12858 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12860 beg_unchanged
= BEG_UNCHANGED
;
12861 end_unchanged
= END_UNCHANGED
;
12863 current_matrix_up_to_date_p
12864 = (!NILP (w
->window_end_valid
)
12865 && !current_buffer
->clip_changed
12866 && !current_buffer
->prevent_redisplay_optimizations_p
12867 && XFASTINT (w
->last_modified
) >= MODIFF
12868 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12871 = (!NILP (w
->window_end_valid
)
12872 && !current_buffer
->clip_changed
12873 && XFASTINT (w
->last_modified
) >= MODIFF
12874 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12876 /* When windows_or_buffers_changed is non-zero, we can't rely on
12877 the window end being valid, so set it to nil there. */
12878 if (windows_or_buffers_changed
)
12880 /* If window starts on a continuation line, maybe adjust the
12881 window start in case the window's width changed. */
12882 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12883 compute_window_start_on_continuation_line (w
);
12885 w
->window_end_valid
= Qnil
;
12888 /* Some sanity checks. */
12889 CHECK_WINDOW_END (w
);
12890 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12892 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12895 /* If %c is in mode line, update it if needed. */
12896 if (!NILP (w
->column_number_displayed
)
12897 /* This alternative quickly identifies a common case
12898 where no change is needed. */
12899 && !(PT
== XFASTINT (w
->last_point
)
12900 && XFASTINT (w
->last_modified
) >= MODIFF
12901 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12902 && (XFASTINT (w
->column_number_displayed
)
12903 != (int) current_column ())) /* iftc */
12904 update_mode_line
= 1;
12906 /* Count number of windows showing the selected buffer. An indirect
12907 buffer counts as its base buffer. */
12908 if (!just_this_one_p
)
12910 struct buffer
*current_base
, *window_base
;
12911 current_base
= current_buffer
;
12912 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12913 if (current_base
->base_buffer
)
12914 current_base
= current_base
->base_buffer
;
12915 if (window_base
->base_buffer
)
12916 window_base
= window_base
->base_buffer
;
12917 if (current_base
== window_base
)
12921 /* Point refers normally to the selected window. For any other
12922 window, set up appropriate value. */
12923 if (!EQ (window
, selected_window
))
12925 int new_pt
= XMARKER (w
->pointm
)->charpos
;
12926 int new_pt_byte
= marker_byte_position (w
->pointm
);
12930 new_pt_byte
= BEGV_BYTE
;
12931 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
12933 else if (new_pt
> (ZV
- 1))
12936 new_pt_byte
= ZV_BYTE
;
12937 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
12940 /* We don't use SET_PT so that the point-motion hooks don't run. */
12941 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
12944 /* If any of the character widths specified in the display table
12945 have changed, invalidate the width run cache. It's true that
12946 this may be a bit late to catch such changes, but the rest of
12947 redisplay goes (non-fatally) haywire when the display table is
12948 changed, so why should we worry about doing any better? */
12949 if (current_buffer
->width_run_cache
)
12951 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
12953 if (! disptab_matches_widthtab (disptab
,
12954 XVECTOR (current_buffer
->width_table
)))
12956 invalidate_region_cache (current_buffer
,
12957 current_buffer
->width_run_cache
,
12959 recompute_width_table (current_buffer
, disptab
);
12963 /* If window-start is screwed up, choose a new one. */
12964 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12967 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12969 /* If someone specified a new starting point but did not insist,
12970 check whether it can be used. */
12971 if (!NILP (w
->optional_new_start
)
12972 && CHARPOS (startp
) >= BEGV
12973 && CHARPOS (startp
) <= ZV
)
12975 w
->optional_new_start
= Qnil
;
12976 start_display (&it
, w
, startp
);
12977 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12978 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12979 if (IT_CHARPOS (it
) == PT
)
12980 w
->force_start
= Qt
;
12981 /* IT may overshoot PT if text at PT is invisible. */
12982 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12983 w
->force_start
= Qt
;
12988 /* Handle case where place to start displaying has been specified,
12989 unless the specified location is outside the accessible range. */
12990 if (!NILP (w
->force_start
)
12991 || w
->frozen_window_start_p
)
12993 /* We set this later on if we have to adjust point. */
12997 w
->force_start
= Qnil
;
12999 w
->window_end_valid
= Qnil
;
13001 /* Forget any recorded base line for line number display. */
13002 if (!buffer_unchanged_p
)
13003 w
->base_line_number
= Qnil
;
13005 /* Redisplay the mode line. Select the buffer properly for that.
13006 Also, run the hook window-scroll-functions
13007 because we have scrolled. */
13008 /* Note, we do this after clearing force_start because
13009 if there's an error, it is better to forget about force_start
13010 than to get into an infinite loop calling the hook functions
13011 and having them get more errors. */
13012 if (!update_mode_line
13013 || ! NILP (Vwindow_scroll_functions
))
13015 update_mode_line
= 1;
13016 w
->update_mode_line
= Qt
;
13017 startp
= run_window_scroll_functions (window
, startp
);
13020 w
->last_modified
= make_number (0);
13021 w
->last_overlay_modified
= make_number (0);
13022 if (CHARPOS (startp
) < BEGV
)
13023 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
13024 else if (CHARPOS (startp
) > ZV
)
13025 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
13027 /* Redisplay, then check if cursor has been set during the
13028 redisplay. Give up if new fonts were loaded. */
13029 val
= try_window (window
, startp
, 1);
13032 w
->force_start
= Qt
;
13033 clear_glyph_matrix (w
->desired_matrix
);
13034 goto need_larger_matrices
;
13036 /* Point was outside the scroll margins. */
13038 new_vpos
= window_box_height (w
) / 2;
13040 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
13042 /* If point does not appear, try to move point so it does
13043 appear. The desired matrix has been built above, so we
13044 can use it here. */
13045 new_vpos
= window_box_height (w
) / 2;
13048 if (!cursor_row_fully_visible_p (w
, 0, 0))
13050 /* Point does appear, but on a line partly visible at end of window.
13051 Move it back to a fully-visible line. */
13052 new_vpos
= window_box_height (w
);
13055 /* If we need to move point for either of the above reasons,
13056 now actually do it. */
13059 struct glyph_row
*row
;
13061 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13062 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13065 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13066 MATRIX_ROW_START_BYTEPOS (row
));
13068 if (w
!= XWINDOW (selected_window
))
13069 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13070 else if (current_buffer
== old
)
13071 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13073 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13075 /* If we are highlighting the region, then we just changed
13076 the region, so redisplay to show it. */
13077 if (!NILP (Vtransient_mark_mode
)
13078 && !NILP (current_buffer
->mark_active
))
13080 clear_glyph_matrix (w
->desired_matrix
);
13081 if (!try_window (window
, startp
, 0))
13082 goto need_larger_matrices
;
13087 debug_method_add (w
, "forced window start");
13092 /* Handle case where text has not changed, only point, and it has
13093 not moved off the frame, and we are not retrying after hscroll.
13094 (current_matrix_up_to_date_p is nonzero when retrying.) */
13095 if (current_matrix_up_to_date_p
13096 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13097 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13101 case CURSOR_MOVEMENT_SUCCESS
:
13102 used_current_matrix_p
= 1;
13105 #if 0 /* try_cursor_movement never returns this value. */
13106 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
13107 goto need_larger_matrices
;
13110 case CURSOR_MOVEMENT_MUST_SCROLL
:
13111 goto try_to_scroll
;
13117 /* If current starting point was originally the beginning of a line
13118 but no longer is, find a new starting point. */
13119 else if (!NILP (w
->start_at_line_beg
)
13120 && !(CHARPOS (startp
) <= BEGV
13121 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13124 debug_method_add (w
, "recenter 1");
13129 /* Try scrolling with try_window_id. Value is > 0 if update has
13130 been done, it is -1 if we know that the same window start will
13131 not work. It is 0 if unsuccessful for some other reason. */
13132 else if ((tem
= try_window_id (w
)) != 0)
13135 debug_method_add (w
, "try_window_id %d", tem
);
13138 if (fonts_changed_p
)
13139 goto need_larger_matrices
;
13143 /* Otherwise try_window_id has returned -1 which means that we
13144 don't want the alternative below this comment to execute. */
13146 else if (CHARPOS (startp
) >= BEGV
13147 && CHARPOS (startp
) <= ZV
13148 && PT
>= CHARPOS (startp
)
13149 && (CHARPOS (startp
) < ZV
13150 /* Avoid starting at end of buffer. */
13151 || CHARPOS (startp
) == BEGV
13152 || (XFASTINT (w
->last_modified
) >= MODIFF
13153 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
13156 /* If first window line is a continuation line, and window start
13157 is inside the modified region, but the first change is before
13158 current window start, we must select a new window start.
13160 However, if this is the result of a down-mouse event (e.g. by
13161 extending the mouse-drag-overlay), we don't want to select a
13162 new window start, since that would change the position under
13163 the mouse, resulting in an unwanted mouse-movement rather
13164 than a simple mouse-click. */
13165 if (NILP (w
->start_at_line_beg
)
13166 && NILP (do_mouse_tracking
)
13167 && CHARPOS (startp
) > BEGV
13168 && CHARPOS (startp
) > BEG
+ beg_unchanged
13169 && CHARPOS (startp
) <= Z
- end_unchanged
)
13171 w
->force_start
= Qt
;
13172 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13173 compute_window_start_on_continuation_line (w
);
13174 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13179 debug_method_add (w
, "same window start");
13182 /* Try to redisplay starting at same place as before.
13183 If point has not moved off frame, accept the results. */
13184 if (!current_matrix_up_to_date_p
13185 /* Don't use try_window_reusing_current_matrix in this case
13186 because a window scroll function can have changed the
13188 || !NILP (Vwindow_scroll_functions
)
13189 || MINI_WINDOW_P (w
)
13190 || !(used_current_matrix_p
13191 = try_window_reusing_current_matrix (w
)))
13193 IF_DEBUG (debug_method_add (w
, "1"));
13194 if (try_window (window
, startp
, 1) < 0)
13195 /* -1 means we need to scroll.
13196 0 means we need new matrices, but fonts_changed_p
13197 is set in that case, so we will detect it below. */
13198 goto try_to_scroll
;
13201 if (fonts_changed_p
)
13202 goto need_larger_matrices
;
13204 if (w
->cursor
.vpos
>= 0)
13206 if (!just_this_one_p
13207 || current_buffer
->clip_changed
13208 || BEG_UNCHANGED
< CHARPOS (startp
))
13209 /* Forget any recorded base line for line number display. */
13210 w
->base_line_number
= Qnil
;
13212 if (!cursor_row_fully_visible_p (w
, 1, 0))
13214 clear_glyph_matrix (w
->desired_matrix
);
13215 last_line_misfit
= 1;
13217 /* Drop through and scroll. */
13222 clear_glyph_matrix (w
->desired_matrix
);
13227 w
->last_modified
= make_number (0);
13228 w
->last_overlay_modified
= make_number (0);
13230 /* Redisplay the mode line. Select the buffer properly for that. */
13231 if (!update_mode_line
)
13233 update_mode_line
= 1;
13234 w
->update_mode_line
= Qt
;
13237 /* Try to scroll by specified few lines. */
13238 if ((scroll_conservatively
13240 || temp_scroll_step
13241 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13242 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13243 && !current_buffer
->clip_changed
13244 && CHARPOS (startp
) >= BEGV
13245 && CHARPOS (startp
) <= ZV
)
13247 /* The function returns -1 if new fonts were loaded, 1 if
13248 successful, 0 if not successful. */
13249 int rc
= try_scrolling (window
, just_this_one_p
,
13250 scroll_conservatively
,
13252 temp_scroll_step
, last_line_misfit
);
13255 case SCROLLING_SUCCESS
:
13258 case SCROLLING_NEED_LARGER_MATRICES
:
13259 goto need_larger_matrices
;
13261 case SCROLLING_FAILED
:
13269 /* Finally, just choose place to start which centers point */
13272 if (centering_position
< 0)
13273 centering_position
= window_box_height (w
) / 2;
13276 debug_method_add (w
, "recenter");
13279 /* w->vscroll = 0; */
13281 /* Forget any previously recorded base line for line number display. */
13282 if (!buffer_unchanged_p
)
13283 w
->base_line_number
= Qnil
;
13285 /* Move backward half the height of the window. */
13286 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13287 it
.current_y
= it
.last_visible_y
;
13288 move_it_vertically_backward (&it
, centering_position
);
13289 xassert (IT_CHARPOS (it
) >= BEGV
);
13291 /* The function move_it_vertically_backward may move over more
13292 than the specified y-distance. If it->w is small, e.g. a
13293 mini-buffer window, we may end up in front of the window's
13294 display area. Start displaying at the start of the line
13295 containing PT in this case. */
13296 if (it
.current_y
<= 0)
13298 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13299 move_it_vertically_backward (&it
, 0);
13301 /* I think this assert is bogus if buffer contains
13302 invisible text or images. KFS. */
13303 xassert (IT_CHARPOS (it
) <= PT
);
13308 it
.current_x
= it
.hpos
= 0;
13310 /* Set startp here explicitly in case that helps avoid an infinite loop
13311 in case the window-scroll-functions functions get errors. */
13312 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13314 /* Run scroll hooks. */
13315 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13317 /* Redisplay the window. */
13318 if (!current_matrix_up_to_date_p
13319 || windows_or_buffers_changed
13320 || cursor_type_changed
13321 /* Don't use try_window_reusing_current_matrix in this case
13322 because it can have changed the buffer. */
13323 || !NILP (Vwindow_scroll_functions
)
13324 || !just_this_one_p
13325 || MINI_WINDOW_P (w
)
13326 || !(used_current_matrix_p
13327 = try_window_reusing_current_matrix (w
)))
13328 try_window (window
, startp
, 0);
13330 /* If new fonts have been loaded (due to fontsets), give up. We
13331 have to start a new redisplay since we need to re-adjust glyph
13333 if (fonts_changed_p
)
13334 goto need_larger_matrices
;
13336 /* If cursor did not appear assume that the middle of the window is
13337 in the first line of the window. Do it again with the next line.
13338 (Imagine a window of height 100, displaying two lines of height
13339 60. Moving back 50 from it->last_visible_y will end in the first
13341 if (w
->cursor
.vpos
< 0)
13343 if (!NILP (w
->window_end_valid
)
13344 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13346 clear_glyph_matrix (w
->desired_matrix
);
13347 move_it_by_lines (&it
, 1, 0);
13348 try_window (window
, it
.current
.pos
, 0);
13350 else if (PT
< IT_CHARPOS (it
))
13352 clear_glyph_matrix (w
->desired_matrix
);
13353 move_it_by_lines (&it
, -1, 0);
13354 try_window (window
, it
.current
.pos
, 0);
13358 /* Not much we can do about it. */
13362 /* Consider the following case: Window starts at BEGV, there is
13363 invisible, intangible text at BEGV, so that display starts at
13364 some point START > BEGV. It can happen that we are called with
13365 PT somewhere between BEGV and START. Try to handle that case. */
13366 if (w
->cursor
.vpos
< 0)
13368 struct glyph_row
*row
= w
->current_matrix
->rows
;
13369 if (row
->mode_line_p
)
13371 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13374 if (!cursor_row_fully_visible_p (w
, 0, 0))
13376 /* If vscroll is enabled, disable it and try again. */
13380 clear_glyph_matrix (w
->desired_matrix
);
13384 /* If centering point failed to make the whole line visible,
13385 put point at the top instead. That has to make the whole line
13386 visible, if it can be done. */
13387 if (centering_position
== 0)
13390 clear_glyph_matrix (w
->desired_matrix
);
13391 centering_position
= 0;
13397 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13398 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13399 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13402 /* Display the mode line, if we must. */
13403 if ((update_mode_line
13404 /* If window not full width, must redo its mode line
13405 if (a) the window to its side is being redone and
13406 (b) we do a frame-based redisplay. This is a consequence
13407 of how inverted lines are drawn in frame-based redisplay. */
13408 || (!just_this_one_p
13409 && !FRAME_WINDOW_P (f
)
13410 && !WINDOW_FULL_WIDTH_P (w
))
13411 /* Line number to display. */
13412 || INTEGERP (w
->base_line_pos
)
13413 /* Column number is displayed and different from the one displayed. */
13414 || (!NILP (w
->column_number_displayed
)
13415 && (XFASTINT (w
->column_number_displayed
)
13416 != (int) current_column ()))) /* iftc */
13417 /* This means that the window has a mode line. */
13418 && (WINDOW_WANTS_MODELINE_P (w
)
13419 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13421 display_mode_lines (w
);
13423 /* If mode line height has changed, arrange for a thorough
13424 immediate redisplay using the correct mode line height. */
13425 if (WINDOW_WANTS_MODELINE_P (w
)
13426 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13428 fonts_changed_p
= 1;
13429 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13430 = DESIRED_MODE_LINE_HEIGHT (w
);
13433 /* If top line height has changed, arrange for a thorough
13434 immediate redisplay using the correct mode line height. */
13435 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13436 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13438 fonts_changed_p
= 1;
13439 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13440 = DESIRED_HEADER_LINE_HEIGHT (w
);
13443 if (fonts_changed_p
)
13444 goto need_larger_matrices
;
13447 if (!line_number_displayed
13448 && !BUFFERP (w
->base_line_pos
))
13450 w
->base_line_pos
= Qnil
;
13451 w
->base_line_number
= Qnil
;
13456 /* When we reach a frame's selected window, redo the frame's menu bar. */
13457 if (update_mode_line
13458 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13460 int redisplay_menu_p
= 0;
13461 int redisplay_tool_bar_p
= 0;
13463 if (FRAME_WINDOW_P (f
))
13465 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
13466 || defined (USE_GTK)
13467 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13469 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13473 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13475 if (redisplay_menu_p
)
13476 display_menu_bar (w
);
13478 #ifdef HAVE_WINDOW_SYSTEM
13479 if (FRAME_WINDOW_P (f
))
13482 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13484 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13485 && (FRAME_TOOL_BAR_LINES (f
) > 0
13486 || !NILP (Vauto_resize_tool_bars
));
13489 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
13491 extern int ignore_mouse_drag_p
;
13492 ignore_mouse_drag_p
= 1;
13498 #ifdef HAVE_WINDOW_SYSTEM
13499 if (FRAME_WINDOW_P (f
)
13500 && update_window_fringes (w
, (just_this_one_p
13501 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13502 || w
->pseudo_window_p
)))
13506 if (draw_window_fringes (w
, 1))
13507 x_draw_vertical_border (w
);
13511 #endif /* HAVE_WINDOW_SYSTEM */
13513 /* We go to this label, with fonts_changed_p nonzero,
13514 if it is necessary to try again using larger glyph matrices.
13515 We have to redeem the scroll bar even in this case,
13516 because the loop in redisplay_internal expects that. */
13517 need_larger_matrices
:
13519 finish_scroll_bars
:
13521 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13523 /* Set the thumb's position and size. */
13524 set_vertical_scroll_bar (w
);
13526 /* Note that we actually used the scroll bar attached to this
13527 window, so it shouldn't be deleted at the end of redisplay. */
13528 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
13529 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
13532 /* Restore current_buffer and value of point in it. */
13533 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13534 set_buffer_internal_1 (old
);
13535 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13537 unbind_to (count
, Qnil
);
13541 /* Build the complete desired matrix of WINDOW with a window start
13542 buffer position POS.
13544 Value is 1 if successful. It is zero if fonts were loaded during
13545 redisplay which makes re-adjusting glyph matrices necessary, and -1
13546 if point would appear in the scroll margins.
13547 (We check that only if CHECK_MARGINS is nonzero. */
13550 try_window (window
, pos
, check_margins
)
13551 Lisp_Object window
;
13552 struct text_pos pos
;
13555 struct window
*w
= XWINDOW (window
);
13557 struct glyph_row
*last_text_row
= NULL
;
13558 struct frame
*f
= XFRAME (w
->frame
);
13560 /* Make POS the new window start. */
13561 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13563 /* Mark cursor position as unknown. No overlay arrow seen. */
13564 w
->cursor
.vpos
= -1;
13565 overlay_arrow_seen
= 0;
13567 /* Initialize iterator and info to start at POS. */
13568 start_display (&it
, w
, pos
);
13570 /* Display all lines of W. */
13571 while (it
.current_y
< it
.last_visible_y
)
13573 if (display_line (&it
))
13574 last_text_row
= it
.glyph_row
- 1;
13575 if (fonts_changed_p
)
13579 /* Don't let the cursor end in the scroll margins. */
13581 && !MINI_WINDOW_P (w
))
13583 int this_scroll_margin
;
13585 this_scroll_margin
= max (0, scroll_margin
);
13586 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13587 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13589 if ((w
->cursor
.y
>= 0 /* not vscrolled */
13590 && w
->cursor
.y
< this_scroll_margin
13591 && CHARPOS (pos
) > BEGV
13592 && IT_CHARPOS (it
) < ZV
)
13593 /* rms: considering make_cursor_line_fully_visible_p here
13594 seems to give wrong results. We don't want to recenter
13595 when the last line is partly visible, we want to allow
13596 that case to be handled in the usual way. */
13597 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
13599 w
->cursor
.vpos
= -1;
13600 clear_glyph_matrix (w
->desired_matrix
);
13605 /* If bottom moved off end of frame, change mode line percentage. */
13606 if (XFASTINT (w
->window_end_pos
) <= 0
13607 && Z
!= IT_CHARPOS (it
))
13608 w
->update_mode_line
= Qt
;
13610 /* Set window_end_pos to the offset of the last character displayed
13611 on the window from the end of current_buffer. Set
13612 window_end_vpos to its row number. */
13615 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
13616 w
->window_end_bytepos
13617 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13619 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13621 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13622 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
13623 ->displays_text_p
);
13627 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13628 w
->window_end_pos
= make_number (Z
- ZV
);
13629 w
->window_end_vpos
= make_number (0);
13632 /* But that is not valid info until redisplay finishes. */
13633 w
->window_end_valid
= Qnil
;
13639 /************************************************************************
13640 Window redisplay reusing current matrix when buffer has not changed
13641 ************************************************************************/
13643 /* Try redisplay of window W showing an unchanged buffer with a
13644 different window start than the last time it was displayed by
13645 reusing its current matrix. Value is non-zero if successful.
13646 W->start is the new window start. */
13649 try_window_reusing_current_matrix (w
)
13652 struct frame
*f
= XFRAME (w
->frame
);
13653 struct glyph_row
*row
, *bottom_row
;
13656 struct text_pos start
, new_start
;
13657 int nrows_scrolled
, i
;
13658 struct glyph_row
*last_text_row
;
13659 struct glyph_row
*last_reused_text_row
;
13660 struct glyph_row
*start_row
;
13661 int start_vpos
, min_y
, max_y
;
13664 if (inhibit_try_window_reusing
)
13668 if (/* This function doesn't handle terminal frames. */
13669 !FRAME_WINDOW_P (f
)
13670 /* Don't try to reuse the display if windows have been split
13672 || windows_or_buffers_changed
13673 || cursor_type_changed
)
13676 /* Can't do this if region may have changed. */
13677 if ((!NILP (Vtransient_mark_mode
)
13678 && !NILP (current_buffer
->mark_active
))
13679 || !NILP (w
->region_showing
)
13680 || !NILP (Vshow_trailing_whitespace
))
13683 /* If top-line visibility has changed, give up. */
13684 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13685 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
13688 /* Give up if old or new display is scrolled vertically. We could
13689 make this function handle this, but right now it doesn't. */
13690 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13691 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
13694 /* The variable new_start now holds the new window start. The old
13695 start `start' can be determined from the current matrix. */
13696 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
13697 start
= start_row
->start
.pos
;
13698 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13700 /* Clear the desired matrix for the display below. */
13701 clear_glyph_matrix (w
->desired_matrix
);
13703 if (CHARPOS (new_start
) <= CHARPOS (start
))
13707 /* Don't use this method if the display starts with an ellipsis
13708 displayed for invisible text. It's not easy to handle that case
13709 below, and it's certainly not worth the effort since this is
13710 not a frequent case. */
13711 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
13714 IF_DEBUG (debug_method_add (w
, "twu1"));
13716 /* Display up to a row that can be reused. The variable
13717 last_text_row is set to the last row displayed that displays
13718 text. Note that it.vpos == 0 if or if not there is a
13719 header-line; it's not the same as the MATRIX_ROW_VPOS! */
13720 start_display (&it
, w
, new_start
);
13721 first_row_y
= it
.current_y
;
13722 w
->cursor
.vpos
= -1;
13723 last_text_row
= last_reused_text_row
= NULL
;
13725 while (it
.current_y
< it
.last_visible_y
13726 && !fonts_changed_p
)
13728 /* If we have reached into the characters in the START row,
13729 that means the line boundaries have changed. So we
13730 can't start copying with the row START. Maybe it will
13731 work to start copying with the following row. */
13732 while (IT_CHARPOS (it
) > CHARPOS (start
))
13734 /* Advance to the next row as the "start". */
13736 start
= start_row
->start
.pos
;
13737 /* If there are no more rows to try, or just one, give up. */
13738 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
13739 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
13740 || CHARPOS (start
) == ZV
)
13742 clear_glyph_matrix (w
->desired_matrix
);
13746 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13748 /* If we have reached alignment,
13749 we can copy the rest of the rows. */
13750 if (IT_CHARPOS (it
) == CHARPOS (start
))
13753 if (display_line (&it
))
13754 last_text_row
= it
.glyph_row
- 1;
13757 /* A value of current_y < last_visible_y means that we stopped
13758 at the previous window start, which in turn means that we
13759 have at least one reusable row. */
13760 if (it
.current_y
< it
.last_visible_y
)
13762 /* IT.vpos always starts from 0; it counts text lines. */
13763 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
13765 /* Find PT if not already found in the lines displayed. */
13766 if (w
->cursor
.vpos
< 0)
13768 int dy
= it
.current_y
- start_row
->y
;
13770 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13771 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
13773 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
13774 dy
, nrows_scrolled
);
13777 clear_glyph_matrix (w
->desired_matrix
);
13782 /* Scroll the display. Do it before the current matrix is
13783 changed. The problem here is that update has not yet
13784 run, i.e. part of the current matrix is not up to date.
13785 scroll_run_hook will clear the cursor, and use the
13786 current matrix to get the height of the row the cursor is
13788 run
.current_y
= start_row
->y
;
13789 run
.desired_y
= it
.current_y
;
13790 run
.height
= it
.last_visible_y
- it
.current_y
;
13792 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
13795 FRAME_RIF (f
)->update_window_begin_hook (w
);
13796 FRAME_RIF (f
)->clear_window_mouse_face (w
);
13797 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
13798 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
13802 /* Shift current matrix down by nrows_scrolled lines. */
13803 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13804 rotate_matrix (w
->current_matrix
,
13806 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13809 /* Disable lines that must be updated. */
13810 for (i
= 0; i
< nrows_scrolled
; ++i
)
13811 (start_row
+ i
)->enabled_p
= 0;
13813 /* Re-compute Y positions. */
13814 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13815 max_y
= it
.last_visible_y
;
13816 for (row
= start_row
+ nrows_scrolled
;
13820 row
->y
= it
.current_y
;
13821 row
->visible_height
= row
->height
;
13823 if (row
->y
< min_y
)
13824 row
->visible_height
-= min_y
- row
->y
;
13825 if (row
->y
+ row
->height
> max_y
)
13826 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13827 row
->redraw_fringe_bitmaps_p
= 1;
13829 it
.current_y
+= row
->height
;
13831 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13832 last_reused_text_row
= row
;
13833 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13837 /* Disable lines in the current matrix which are now
13838 below the window. */
13839 for (++row
; row
< bottom_row
; ++row
)
13840 row
->enabled_p
= row
->mode_line_p
= 0;
13843 /* Update window_end_pos etc.; last_reused_text_row is the last
13844 reused row from the current matrix containing text, if any.
13845 The value of last_text_row is the last displayed line
13846 containing text. */
13847 if (last_reused_text_row
)
13849 w
->window_end_bytepos
13850 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13852 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13854 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13855 w
->current_matrix
));
13857 else if (last_text_row
)
13859 w
->window_end_bytepos
13860 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13862 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13864 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13868 /* This window must be completely empty. */
13869 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13870 w
->window_end_pos
= make_number (Z
- ZV
);
13871 w
->window_end_vpos
= make_number (0);
13873 w
->window_end_valid
= Qnil
;
13875 /* Update hint: don't try scrolling again in update_window. */
13876 w
->desired_matrix
->no_scrolling_p
= 1;
13879 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13883 else if (CHARPOS (new_start
) > CHARPOS (start
))
13885 struct glyph_row
*pt_row
, *row
;
13886 struct glyph_row
*first_reusable_row
;
13887 struct glyph_row
*first_row_to_display
;
13889 int yb
= window_text_bottom_y (w
);
13891 /* Find the row starting at new_start, if there is one. Don't
13892 reuse a partially visible line at the end. */
13893 first_reusable_row
= start_row
;
13894 while (first_reusable_row
->enabled_p
13895 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13896 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13897 < CHARPOS (new_start
)))
13898 ++first_reusable_row
;
13900 /* Give up if there is no row to reuse. */
13901 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13902 || !first_reusable_row
->enabled_p
13903 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13904 != CHARPOS (new_start
)))
13907 /* We can reuse fully visible rows beginning with
13908 first_reusable_row to the end of the window. Set
13909 first_row_to_display to the first row that cannot be reused.
13910 Set pt_row to the row containing point, if there is any. */
13912 for (first_row_to_display
= first_reusable_row
;
13913 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13914 ++first_row_to_display
)
13916 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
13917 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
13918 pt_row
= first_row_to_display
;
13921 /* Start displaying at the start of first_row_to_display. */
13922 xassert (first_row_to_display
->y
< yb
);
13923 init_to_row_start (&it
, w
, first_row_to_display
);
13925 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
13927 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
13929 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
13930 + WINDOW_HEADER_LINE_HEIGHT (w
));
13932 /* Display lines beginning with first_row_to_display in the
13933 desired matrix. Set last_text_row to the last row displayed
13934 that displays text. */
13935 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
13936 if (pt_row
== NULL
)
13937 w
->cursor
.vpos
= -1;
13938 last_text_row
= NULL
;
13939 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
13940 if (display_line (&it
))
13941 last_text_row
= it
.glyph_row
- 1;
13943 /* Give up If point isn't in a row displayed or reused. */
13944 if (w
->cursor
.vpos
< 0)
13946 clear_glyph_matrix (w
->desired_matrix
);
13950 /* If point is in a reused row, adjust y and vpos of the cursor
13954 w
->cursor
.vpos
-= nrows_scrolled
;
13955 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
13958 /* Scroll the display. */
13959 run
.current_y
= first_reusable_row
->y
;
13960 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13961 run
.height
= it
.last_visible_y
- run
.current_y
;
13962 dy
= run
.current_y
- run
.desired_y
;
13967 FRAME_RIF (f
)->update_window_begin_hook (w
);
13968 FRAME_RIF (f
)->clear_window_mouse_face (w
);
13969 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
13970 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
13974 /* Adjust Y positions of reused rows. */
13975 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13976 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13977 max_y
= it
.last_visible_y
;
13978 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
13981 row
->visible_height
= row
->height
;
13982 if (row
->y
< min_y
)
13983 row
->visible_height
-= min_y
- row
->y
;
13984 if (row
->y
+ row
->height
> max_y
)
13985 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13986 row
->redraw_fringe_bitmaps_p
= 1;
13989 /* Scroll the current matrix. */
13990 xassert (nrows_scrolled
> 0);
13991 rotate_matrix (w
->current_matrix
,
13993 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13996 /* Disable rows not reused. */
13997 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
13998 row
->enabled_p
= 0;
14000 /* Point may have moved to a different line, so we cannot assume that
14001 the previous cursor position is valid; locate the correct row. */
14004 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
14005 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
14009 w
->cursor
.y
= row
->y
;
14011 if (row
< bottom_row
)
14013 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14014 while (glyph
->charpos
< PT
)
14017 w
->cursor
.x
+= glyph
->pixel_width
;
14023 /* Adjust window end. A null value of last_text_row means that
14024 the window end is in reused rows which in turn means that
14025 only its vpos can have changed. */
14028 w
->window_end_bytepos
14029 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14031 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14033 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14038 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
14041 w
->window_end_valid
= Qnil
;
14042 w
->desired_matrix
->no_scrolling_p
= 1;
14045 debug_method_add (w
, "try_window_reusing_current_matrix 2");
14055 /************************************************************************
14056 Window redisplay reusing current matrix when buffer has changed
14057 ************************************************************************/
14059 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
14060 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
14062 static struct glyph_row
*
14063 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
14064 struct glyph_row
*));
14067 /* Return the last row in MATRIX displaying text. If row START is
14068 non-null, start searching with that row. IT gives the dimensions
14069 of the display. Value is null if matrix is empty; otherwise it is
14070 a pointer to the row found. */
14072 static struct glyph_row
*
14073 find_last_row_displaying_text (matrix
, it
, start
)
14074 struct glyph_matrix
*matrix
;
14076 struct glyph_row
*start
;
14078 struct glyph_row
*row
, *row_found
;
14080 /* Set row_found to the last row in IT->w's current matrix
14081 displaying text. The loop looks funny but think of partially
14084 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14085 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14087 xassert (row
->enabled_p
);
14089 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
14098 /* Return the last row in the current matrix of W that is not affected
14099 by changes at the start of current_buffer that occurred since W's
14100 current matrix was built. Value is null if no such row exists.
14102 BEG_UNCHANGED us the number of characters unchanged at the start of
14103 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
14104 first changed character in current_buffer. Characters at positions <
14105 BEG + BEG_UNCHANGED are at the same buffer positions as they were
14106 when the current matrix was built. */
14108 static struct glyph_row
*
14109 find_last_unchanged_at_beg_row (w
)
14112 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
14113 struct glyph_row
*row
;
14114 struct glyph_row
*row_found
= NULL
;
14115 int yb
= window_text_bottom_y (w
);
14117 /* Find the last row displaying unchanged text. */
14118 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14119 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14120 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
14122 if (/* If row ends before first_changed_pos, it is unchanged,
14123 except in some case. */
14124 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
14125 /* When row ends in ZV and we write at ZV it is not
14127 && !row
->ends_at_zv_p
14128 /* When first_changed_pos is the end of a continued line,
14129 row is not unchanged because it may be no longer
14131 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
14132 && (row
->continued_p
14133 || row
->exact_window_width_line_p
)))
14136 /* Stop if last visible row. */
14137 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
14147 /* Find the first glyph row in the current matrix of W that is not
14148 affected by changes at the end of current_buffer since the
14149 time W's current matrix was built.
14151 Return in *DELTA the number of chars by which buffer positions in
14152 unchanged text at the end of current_buffer must be adjusted.
14154 Return in *DELTA_BYTES the corresponding number of bytes.
14156 Value is null if no such row exists, i.e. all rows are affected by
14159 static struct glyph_row
*
14160 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
14162 int *delta
, *delta_bytes
;
14164 struct glyph_row
*row
;
14165 struct glyph_row
*row_found
= NULL
;
14167 *delta
= *delta_bytes
= 0;
14169 /* Display must not have been paused, otherwise the current matrix
14170 is not up to date. */
14171 if (NILP (w
->window_end_valid
))
14174 /* A value of window_end_pos >= END_UNCHANGED means that the window
14175 end is in the range of changed text. If so, there is no
14176 unchanged row at the end of W's current matrix. */
14177 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
14180 /* Set row to the last row in W's current matrix displaying text. */
14181 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14183 /* If matrix is entirely empty, no unchanged row exists. */
14184 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14186 /* The value of row is the last glyph row in the matrix having a
14187 meaningful buffer position in it. The end position of row
14188 corresponds to window_end_pos. This allows us to translate
14189 buffer positions in the current matrix to current buffer
14190 positions for characters not in changed text. */
14191 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14192 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14193 int last_unchanged_pos
, last_unchanged_pos_old
;
14194 struct glyph_row
*first_text_row
14195 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14197 *delta
= Z
- Z_old
;
14198 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14200 /* Set last_unchanged_pos to the buffer position of the last
14201 character in the buffer that has not been changed. Z is the
14202 index + 1 of the last character in current_buffer, i.e. by
14203 subtracting END_UNCHANGED we get the index of the last
14204 unchanged character, and we have to add BEG to get its buffer
14206 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
14207 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
14209 /* Search backward from ROW for a row displaying a line that
14210 starts at a minimum position >= last_unchanged_pos_old. */
14211 for (; row
> first_text_row
; --row
)
14213 /* This used to abort, but it can happen.
14214 It is ok to just stop the search instead here. KFS. */
14215 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14218 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
14223 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
14230 /* Make sure that glyph rows in the current matrix of window W
14231 reference the same glyph memory as corresponding rows in the
14232 frame's frame matrix. This function is called after scrolling W's
14233 current matrix on a terminal frame in try_window_id and
14234 try_window_reusing_current_matrix. */
14237 sync_frame_with_window_matrix_rows (w
)
14240 struct frame
*f
= XFRAME (w
->frame
);
14241 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
14243 /* Preconditions: W must be a leaf window and full-width. Its frame
14244 must have a frame matrix. */
14245 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
14246 xassert (WINDOW_FULL_WIDTH_P (w
));
14247 xassert (!FRAME_WINDOW_P (f
));
14249 /* If W is a full-width window, glyph pointers in W's current matrix
14250 have, by definition, to be the same as glyph pointers in the
14251 corresponding frame matrix. Note that frame matrices have no
14252 marginal areas (see build_frame_matrix). */
14253 window_row
= w
->current_matrix
->rows
;
14254 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14255 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14256 while (window_row
< window_row_end
)
14258 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14259 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14261 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14262 frame_row
->glyphs
[TEXT_AREA
] = start
;
14263 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14264 frame_row
->glyphs
[LAST_AREA
] = end
;
14266 /* Disable frame rows whose corresponding window rows have
14267 been disabled in try_window_id. */
14268 if (!window_row
->enabled_p
)
14269 frame_row
->enabled_p
= 0;
14271 ++window_row
, ++frame_row
;
14276 /* Find the glyph row in window W containing CHARPOS. Consider all
14277 rows between START and END (not inclusive). END null means search
14278 all rows to the end of the display area of W. Value is the row
14279 containing CHARPOS or null. */
14282 row_containing_pos (w
, charpos
, start
, end
, dy
)
14285 struct glyph_row
*start
, *end
;
14288 struct glyph_row
*row
= start
;
14291 /* If we happen to start on a header-line, skip that. */
14292 if (row
->mode_line_p
)
14295 if ((end
&& row
>= end
) || !row
->enabled_p
)
14298 last_y
= window_text_bottom_y (w
) - dy
;
14302 /* Give up if we have gone too far. */
14303 if (end
&& row
>= end
)
14305 /* This formerly returned if they were equal.
14306 I think that both quantities are of a "last plus one" type;
14307 if so, when they are equal, the row is within the screen. -- rms. */
14308 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14311 /* If it is in this row, return this row. */
14312 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14313 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14314 /* The end position of a row equals the start
14315 position of the next row. If CHARPOS is there, we
14316 would rather display it in the next line, except
14317 when this line ends in ZV. */
14318 && !row
->ends_at_zv_p
14319 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14320 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14327 /* Try to redisplay window W by reusing its existing display. W's
14328 current matrix must be up to date when this function is called,
14329 i.e. window_end_valid must not be nil.
14333 1 if display has been updated
14334 0 if otherwise unsuccessful
14335 -1 if redisplay with same window start is known not to succeed
14337 The following steps are performed:
14339 1. Find the last row in the current matrix of W that is not
14340 affected by changes at the start of current_buffer. If no such row
14343 2. Find the first row in W's current matrix that is not affected by
14344 changes at the end of current_buffer. Maybe there is no such row.
14346 3. Display lines beginning with the row + 1 found in step 1 to the
14347 row found in step 2 or, if step 2 didn't find a row, to the end of
14350 4. If cursor is not known to appear on the window, give up.
14352 5. If display stopped at the row found in step 2, scroll the
14353 display and current matrix as needed.
14355 6. Maybe display some lines at the end of W, if we must. This can
14356 happen under various circumstances, like a partially visible line
14357 becoming fully visible, or because newly displayed lines are displayed
14358 in smaller font sizes.
14360 7. Update W's window end information. */
14366 struct frame
*f
= XFRAME (w
->frame
);
14367 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14368 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14369 struct glyph_row
*last_unchanged_at_beg_row
;
14370 struct glyph_row
*first_unchanged_at_end_row
;
14371 struct glyph_row
*row
;
14372 struct glyph_row
*bottom_row
;
14375 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14376 struct text_pos start_pos
;
14378 int first_unchanged_at_end_vpos
= 0;
14379 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14380 struct text_pos start
;
14381 int first_changed_charpos
, last_changed_charpos
;
14384 if (inhibit_try_window_id
)
14388 /* This is handy for debugging. */
14390 #define GIVE_UP(X) \
14392 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14396 #define GIVE_UP(X) return 0
14399 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14401 /* Don't use this for mini-windows because these can show
14402 messages and mini-buffers, and we don't handle that here. */
14403 if (MINI_WINDOW_P (w
))
14406 /* This flag is used to prevent redisplay optimizations. */
14407 if (windows_or_buffers_changed
|| cursor_type_changed
)
14410 /* Verify that narrowing has not changed.
14411 Also verify that we were not told to prevent redisplay optimizations.
14412 It would be nice to further
14413 reduce the number of cases where this prevents try_window_id. */
14414 if (current_buffer
->clip_changed
14415 || current_buffer
->prevent_redisplay_optimizations_p
)
14418 /* Window must either use window-based redisplay or be full width. */
14419 if (!FRAME_WINDOW_P (f
)
14420 && (!FRAME_LINE_INS_DEL_OK (f
)
14421 || !WINDOW_FULL_WIDTH_P (w
)))
14424 /* Give up if point is not known NOT to appear in W. */
14425 if (PT
< CHARPOS (start
))
14428 /* Another way to prevent redisplay optimizations. */
14429 if (XFASTINT (w
->last_modified
) == 0)
14432 /* Verify that window is not hscrolled. */
14433 if (XFASTINT (w
->hscroll
) != 0)
14436 /* Verify that display wasn't paused. */
14437 if (NILP (w
->window_end_valid
))
14440 /* Can't use this if highlighting a region because a cursor movement
14441 will do more than just set the cursor. */
14442 if (!NILP (Vtransient_mark_mode
)
14443 && !NILP (current_buffer
->mark_active
))
14446 /* Likewise if highlighting trailing whitespace. */
14447 if (!NILP (Vshow_trailing_whitespace
))
14450 /* Likewise if showing a region. */
14451 if (!NILP (w
->region_showing
))
14454 /* Can use this if overlay arrow position and or string have changed. */
14455 if (overlay_arrows_changed_p ())
14459 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14460 only if buffer has really changed. The reason is that the gap is
14461 initially at Z for freshly visited files. The code below would
14462 set end_unchanged to 0 in that case. */
14463 if (MODIFF
> SAVE_MODIFF
14464 /* This seems to happen sometimes after saving a buffer. */
14465 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14467 if (GPT
- BEG
< BEG_UNCHANGED
)
14468 BEG_UNCHANGED
= GPT
- BEG
;
14469 if (Z
- GPT
< END_UNCHANGED
)
14470 END_UNCHANGED
= Z
- GPT
;
14473 /* The position of the first and last character that has been changed. */
14474 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14475 last_changed_charpos
= Z
- END_UNCHANGED
;
14477 /* If window starts after a line end, and the last change is in
14478 front of that newline, then changes don't affect the display.
14479 This case happens with stealth-fontification. Note that although
14480 the display is unchanged, glyph positions in the matrix have to
14481 be adjusted, of course. */
14482 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14483 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14484 && ((last_changed_charpos
< CHARPOS (start
)
14485 && CHARPOS (start
) == BEGV
)
14486 || (last_changed_charpos
< CHARPOS (start
) - 1
14487 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14489 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14490 struct glyph_row
*r0
;
14492 /* Compute how many chars/bytes have been added to or removed
14493 from the buffer. */
14494 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14495 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14497 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14499 /* Give up if PT is not in the window. Note that it already has
14500 been checked at the start of try_window_id that PT is not in
14501 front of the window start. */
14502 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14505 /* If window start is unchanged, we can reuse the whole matrix
14506 as is, after adjusting glyph positions. No need to compute
14507 the window end again, since its offset from Z hasn't changed. */
14508 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14509 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14510 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14511 /* PT must not be in a partially visible line. */
14512 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14513 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14515 /* Adjust positions in the glyph matrix. */
14516 if (delta
|| delta_bytes
)
14518 struct glyph_row
*r1
14519 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14520 increment_matrix_positions (w
->current_matrix
,
14521 MATRIX_ROW_VPOS (r0
, current_matrix
),
14522 MATRIX_ROW_VPOS (r1
, current_matrix
),
14523 delta
, delta_bytes
);
14526 /* Set the cursor. */
14527 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14529 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14536 /* Handle the case that changes are all below what is displayed in
14537 the window, and that PT is in the window. This shortcut cannot
14538 be taken if ZV is visible in the window, and text has been added
14539 there that is visible in the window. */
14540 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14541 /* ZV is not visible in the window, or there are no
14542 changes at ZV, actually. */
14543 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14544 || first_changed_charpos
== last_changed_charpos
))
14546 struct glyph_row
*r0
;
14548 /* Give up if PT is not in the window. Note that it already has
14549 been checked at the start of try_window_id that PT is not in
14550 front of the window start. */
14551 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14554 /* If window start is unchanged, we can reuse the whole matrix
14555 as is, without changing glyph positions since no text has
14556 been added/removed in front of the window end. */
14557 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14558 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14559 /* PT must not be in a partially visible line. */
14560 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14561 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14563 /* We have to compute the window end anew since text
14564 can have been added/removed after it. */
14566 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14567 w
->window_end_bytepos
14568 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14570 /* Set the cursor. */
14571 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14573 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14580 /* Give up if window start is in the changed area.
14582 The condition used to read
14584 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
14586 but why that was tested escapes me at the moment. */
14587 if (CHARPOS (start
) >= first_changed_charpos
14588 && CHARPOS (start
) <= last_changed_charpos
)
14591 /* Check that window start agrees with the start of the first glyph
14592 row in its current matrix. Check this after we know the window
14593 start is not in changed text, otherwise positions would not be
14595 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14596 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
14599 /* Give up if the window ends in strings. Overlay strings
14600 at the end are difficult to handle, so don't try. */
14601 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
14602 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
14605 /* Compute the position at which we have to start displaying new
14606 lines. Some of the lines at the top of the window might be
14607 reusable because they are not displaying changed text. Find the
14608 last row in W's current matrix not affected by changes at the
14609 start of current_buffer. Value is null if changes start in the
14610 first line of window. */
14611 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
14612 if (last_unchanged_at_beg_row
)
14614 /* Avoid starting to display in the moddle of a character, a TAB
14615 for instance. This is easier than to set up the iterator
14616 exactly, and it's not a frequent case, so the additional
14617 effort wouldn't really pay off. */
14618 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
14619 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
14620 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
14621 --last_unchanged_at_beg_row
;
14623 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
14626 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
14628 start_pos
= it
.current
.pos
;
14630 /* Start displaying new lines in the desired matrix at the same
14631 vpos we would use in the current matrix, i.e. below
14632 last_unchanged_at_beg_row. */
14633 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
14635 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14636 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
14638 xassert (it
.hpos
== 0 && it
.current_x
== 0);
14642 /* There are no reusable lines at the start of the window.
14643 Start displaying in the first text line. */
14644 start_display (&it
, w
, start
);
14645 it
.vpos
= it
.first_vpos
;
14646 start_pos
= it
.current
.pos
;
14649 /* Find the first row that is not affected by changes at the end of
14650 the buffer. Value will be null if there is no unchanged row, in
14651 which case we must redisplay to the end of the window. delta
14652 will be set to the value by which buffer positions beginning with
14653 first_unchanged_at_end_row have to be adjusted due to text
14655 first_unchanged_at_end_row
14656 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
14657 IF_DEBUG (debug_delta
= delta
);
14658 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
14660 /* Set stop_pos to the buffer position up to which we will have to
14661 display new lines. If first_unchanged_at_end_row != NULL, this
14662 is the buffer position of the start of the line displayed in that
14663 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
14664 that we don't stop at a buffer position. */
14666 if (first_unchanged_at_end_row
)
14668 xassert (last_unchanged_at_beg_row
== NULL
14669 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
14671 /* If this is a continuation line, move forward to the next one
14672 that isn't. Changes in lines above affect this line.
14673 Caution: this may move first_unchanged_at_end_row to a row
14674 not displaying text. */
14675 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
14676 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14677 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14678 < it
.last_visible_y
))
14679 ++first_unchanged_at_end_row
;
14681 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14682 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14683 >= it
.last_visible_y
))
14684 first_unchanged_at_end_row
= NULL
;
14687 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
14689 first_unchanged_at_end_vpos
14690 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
14691 xassert (stop_pos
>= Z
- END_UNCHANGED
);
14694 else if (last_unchanged_at_beg_row
== NULL
)
14700 /* Either there is no unchanged row at the end, or the one we have
14701 now displays text. This is a necessary condition for the window
14702 end pos calculation at the end of this function. */
14703 xassert (first_unchanged_at_end_row
== NULL
14704 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
14706 debug_last_unchanged_at_beg_vpos
14707 = (last_unchanged_at_beg_row
14708 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
14710 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
14712 #endif /* GLYPH_DEBUG != 0 */
14715 /* Display new lines. Set last_text_row to the last new line
14716 displayed which has text on it, i.e. might end up as being the
14717 line where the window_end_vpos is. */
14718 w
->cursor
.vpos
= -1;
14719 last_text_row
= NULL
;
14720 overlay_arrow_seen
= 0;
14721 while (it
.current_y
< it
.last_visible_y
14722 && !fonts_changed_p
14723 && (first_unchanged_at_end_row
== NULL
14724 || IT_CHARPOS (it
) < stop_pos
))
14726 if (display_line (&it
))
14727 last_text_row
= it
.glyph_row
- 1;
14730 if (fonts_changed_p
)
14734 /* Compute differences in buffer positions, y-positions etc. for
14735 lines reused at the bottom of the window. Compute what we can
14737 if (first_unchanged_at_end_row
14738 /* No lines reused because we displayed everything up to the
14739 bottom of the window. */
14740 && it
.current_y
< it
.last_visible_y
)
14743 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
14745 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
14746 run
.current_y
= first_unchanged_at_end_row
->y
;
14747 run
.desired_y
= run
.current_y
+ dy
;
14748 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
14752 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
14753 first_unchanged_at_end_row
= NULL
;
14755 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
14758 /* Find the cursor if not already found. We have to decide whether
14759 PT will appear on this window (it sometimes doesn't, but this is
14760 not a very frequent case.) This decision has to be made before
14761 the current matrix is altered. A value of cursor.vpos < 0 means
14762 that PT is either in one of the lines beginning at
14763 first_unchanged_at_end_row or below the window. Don't care for
14764 lines that might be displayed later at the window end; as
14765 mentioned, this is not a frequent case. */
14766 if (w
->cursor
.vpos
< 0)
14768 /* Cursor in unchanged rows at the top? */
14769 if (PT
< CHARPOS (start_pos
)
14770 && last_unchanged_at_beg_row
)
14772 row
= row_containing_pos (w
, PT
,
14773 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
14774 last_unchanged_at_beg_row
+ 1, 0);
14776 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14779 /* Start from first_unchanged_at_end_row looking for PT. */
14780 else if (first_unchanged_at_end_row
)
14782 row
= row_containing_pos (w
, PT
- delta
,
14783 first_unchanged_at_end_row
, NULL
, 0);
14785 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
14786 delta_bytes
, dy
, dvpos
);
14789 /* Give up if cursor was not found. */
14790 if (w
->cursor
.vpos
< 0)
14792 clear_glyph_matrix (w
->desired_matrix
);
14797 /* Don't let the cursor end in the scroll margins. */
14799 int this_scroll_margin
, cursor_height
;
14801 this_scroll_margin
= max (0, scroll_margin
);
14802 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14803 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14804 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
14806 if ((w
->cursor
.y
< this_scroll_margin
14807 && CHARPOS (start
) > BEGV
)
14808 /* Old redisplay didn't take scroll margin into account at the bottom,
14809 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14810 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14811 ? cursor_height
+ this_scroll_margin
14812 : 1)) > it
.last_visible_y
)
14814 w
->cursor
.vpos
= -1;
14815 clear_glyph_matrix (w
->desired_matrix
);
14820 /* Scroll the display. Do it before changing the current matrix so
14821 that xterm.c doesn't get confused about where the cursor glyph is
14823 if (dy
&& run
.height
)
14827 if (FRAME_WINDOW_P (f
))
14829 FRAME_RIF (f
)->update_window_begin_hook (w
);
14830 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14831 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14832 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14836 /* Terminal frame. In this case, dvpos gives the number of
14837 lines to scroll by; dvpos < 0 means scroll up. */
14838 int first_unchanged_at_end_vpos
14839 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14840 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14841 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14842 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14843 + window_internal_height (w
));
14845 /* Perform the operation on the screen. */
14848 /* Scroll last_unchanged_at_beg_row to the end of the
14849 window down dvpos lines. */
14850 set_terminal_window (f
, end
);
14852 /* On dumb terminals delete dvpos lines at the end
14853 before inserting dvpos empty lines. */
14854 if (!FRAME_SCROLL_REGION_OK (f
))
14855 ins_del_lines (f
, end
- dvpos
, -dvpos
);
14857 /* Insert dvpos empty lines in front of
14858 last_unchanged_at_beg_row. */
14859 ins_del_lines (f
, from
, dvpos
);
14861 else if (dvpos
< 0)
14863 /* Scroll up last_unchanged_at_beg_vpos to the end of
14864 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14865 set_terminal_window (f
, end
);
14867 /* Delete dvpos lines in front of
14868 last_unchanged_at_beg_vpos. ins_del_lines will set
14869 the cursor to the given vpos and emit |dvpos| delete
14871 ins_del_lines (f
, from
+ dvpos
, dvpos
);
14873 /* On a dumb terminal insert dvpos empty lines at the
14875 if (!FRAME_SCROLL_REGION_OK (f
))
14876 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
14879 set_terminal_window (f
, 0);
14885 /* Shift reused rows of the current matrix to the right position.
14886 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14888 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14889 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14892 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14893 bottom_vpos
, dvpos
);
14894 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14897 else if (dvpos
> 0)
14899 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14900 bottom_vpos
, dvpos
);
14901 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14902 first_unchanged_at_end_vpos
+ dvpos
, 0);
14905 /* For frame-based redisplay, make sure that current frame and window
14906 matrix are in sync with respect to glyph memory. */
14907 if (!FRAME_WINDOW_P (f
))
14908 sync_frame_with_window_matrix_rows (w
);
14910 /* Adjust buffer positions in reused rows. */
14911 if (delta
|| delta_bytes
)
14912 increment_matrix_positions (current_matrix
,
14913 first_unchanged_at_end_vpos
+ dvpos
,
14914 bottom_vpos
, delta
, delta_bytes
);
14916 /* Adjust Y positions. */
14918 shift_glyph_matrix (w
, current_matrix
,
14919 first_unchanged_at_end_vpos
+ dvpos
,
14922 if (first_unchanged_at_end_row
)
14924 first_unchanged_at_end_row
+= dvpos
;
14925 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
14926 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
14927 first_unchanged_at_end_row
= NULL
;
14930 /* If scrolling up, there may be some lines to display at the end of
14932 last_text_row_at_end
= NULL
;
14935 /* Scrolling up can leave for example a partially visible line
14936 at the end of the window to be redisplayed. */
14937 /* Set last_row to the glyph row in the current matrix where the
14938 window end line is found. It has been moved up or down in
14939 the matrix by dvpos. */
14940 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
14941 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
14943 /* If last_row is the window end line, it should display text. */
14944 xassert (last_row
->displays_text_p
);
14946 /* If window end line was partially visible before, begin
14947 displaying at that line. Otherwise begin displaying with the
14948 line following it. */
14949 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
14951 init_to_row_start (&it
, w
, last_row
);
14952 it
.vpos
= last_vpos
;
14953 it
.current_y
= last_row
->y
;
14957 init_to_row_end (&it
, w
, last_row
);
14958 it
.vpos
= 1 + last_vpos
;
14959 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
14963 /* We may start in a continuation line. If so, we have to
14964 get the right continuation_lines_width and current_x. */
14965 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
14966 it
.hpos
= it
.current_x
= 0;
14968 /* Display the rest of the lines at the window end. */
14969 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14970 while (it
.current_y
< it
.last_visible_y
14971 && !fonts_changed_p
)
14973 /* Is it always sure that the display agrees with lines in
14974 the current matrix? I don't think so, so we mark rows
14975 displayed invalid in the current matrix by setting their
14976 enabled_p flag to zero. */
14977 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
14978 if (display_line (&it
))
14979 last_text_row_at_end
= it
.glyph_row
- 1;
14983 /* Update window_end_pos and window_end_vpos. */
14984 if (first_unchanged_at_end_row
14985 && !last_text_row_at_end
)
14987 /* Window end line if one of the preserved rows from the current
14988 matrix. Set row to the last row displaying text in current
14989 matrix starting at first_unchanged_at_end_row, after
14991 xassert (first_unchanged_at_end_row
->displays_text_p
);
14992 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
14993 first_unchanged_at_end_row
);
14994 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
14996 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14997 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14999 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
15000 xassert (w
->window_end_bytepos
>= 0);
15001 IF_DEBUG (debug_method_add (w
, "A"));
15003 else if (last_text_row_at_end
)
15006 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
15007 w
->window_end_bytepos
15008 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
15010 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
15011 xassert (w
->window_end_bytepos
>= 0);
15012 IF_DEBUG (debug_method_add (w
, "B"));
15014 else if (last_text_row
)
15016 /* We have displayed either to the end of the window or at the
15017 end of the window, i.e. the last row with text is to be found
15018 in the desired matrix. */
15020 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15021 w
->window_end_bytepos
15022 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15024 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
15025 xassert (w
->window_end_bytepos
>= 0);
15027 else if (first_unchanged_at_end_row
== NULL
15028 && last_text_row
== NULL
15029 && last_text_row_at_end
== NULL
)
15031 /* Displayed to end of window, but no line containing text was
15032 displayed. Lines were deleted at the end of the window. */
15033 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
15034 int vpos
= XFASTINT (w
->window_end_vpos
);
15035 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
15036 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
15039 row
== NULL
&& vpos
>= first_vpos
;
15040 --vpos
, --current_row
, --desired_row
)
15042 if (desired_row
->enabled_p
)
15044 if (desired_row
->displays_text_p
)
15047 else if (current_row
->displays_text_p
)
15051 xassert (row
!= NULL
);
15052 w
->window_end_vpos
= make_number (vpos
+ 1);
15053 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15054 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15055 xassert (w
->window_end_bytepos
>= 0);
15056 IF_DEBUG (debug_method_add (w
, "C"));
15061 #if 0 /* This leads to problems, for instance when the cursor is
15062 at ZV, and the cursor line displays no text. */
15063 /* Disable rows below what's displayed in the window. This makes
15064 debugging easier. */
15065 enable_glyph_matrix_rows (current_matrix
,
15066 XFASTINT (w
->window_end_vpos
) + 1,
15070 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
15071 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
15073 /* Record that display has not been completed. */
15074 w
->window_end_valid
= Qnil
;
15075 w
->desired_matrix
->no_scrolling_p
= 1;
15083 /***********************************************************************
15084 More debugging support
15085 ***********************************************************************/
15089 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
15090 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
15091 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
15094 /* Dump the contents of glyph matrix MATRIX on stderr.
15096 GLYPHS 0 means don't show glyph contents.
15097 GLYPHS 1 means show glyphs in short form
15098 GLYPHS > 1 means show glyphs in long form. */
15101 dump_glyph_matrix (matrix
, glyphs
)
15102 struct glyph_matrix
*matrix
;
15106 for (i
= 0; i
< matrix
->nrows
; ++i
)
15107 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
15111 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
15112 the glyph row and area where the glyph comes from. */
15115 dump_glyph (row
, glyph
, area
)
15116 struct glyph_row
*row
;
15117 struct glyph
*glyph
;
15120 if (glyph
->type
== CHAR_GLYPH
)
15123 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15124 glyph
- row
->glyphs
[TEXT_AREA
],
15127 (BUFFERP (glyph
->object
)
15129 : (STRINGP (glyph
->object
)
15132 glyph
->pixel_width
,
15134 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
15138 glyph
->left_box_line_p
,
15139 glyph
->right_box_line_p
);
15141 else if (glyph
->type
== STRETCH_GLYPH
)
15144 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15145 glyph
- row
->glyphs
[TEXT_AREA
],
15148 (BUFFERP (glyph
->object
)
15150 : (STRINGP (glyph
->object
)
15153 glyph
->pixel_width
,
15157 glyph
->left_box_line_p
,
15158 glyph
->right_box_line_p
);
15160 else if (glyph
->type
== IMAGE_GLYPH
)
15163 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15164 glyph
- row
->glyphs
[TEXT_AREA
],
15167 (BUFFERP (glyph
->object
)
15169 : (STRINGP (glyph
->object
)
15172 glyph
->pixel_width
,
15176 glyph
->left_box_line_p
,
15177 glyph
->right_box_line_p
);
15179 else if (glyph
->type
== COMPOSITE_GLYPH
)
15182 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15183 glyph
- row
->glyphs
[TEXT_AREA
],
15186 (BUFFERP (glyph
->object
)
15188 : (STRINGP (glyph
->object
)
15191 glyph
->pixel_width
,
15195 glyph
->left_box_line_p
,
15196 glyph
->right_box_line_p
);
15201 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
15202 GLYPHS 0 means don't show glyph contents.
15203 GLYPHS 1 means show glyphs in short form
15204 GLYPHS > 1 means show glyphs in long form. */
15207 dump_glyph_row (row
, vpos
, glyphs
)
15208 struct glyph_row
*row
;
15213 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
15214 fprintf (stderr
, "======================================================================\n");
15216 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
15217 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
15219 MATRIX_ROW_START_CHARPOS (row
),
15220 MATRIX_ROW_END_CHARPOS (row
),
15221 row
->used
[TEXT_AREA
],
15222 row
->contains_overlapping_glyphs_p
,
15224 row
->truncated_on_left_p
,
15225 row
->truncated_on_right_p
,
15227 MATRIX_ROW_CONTINUATION_LINE_P (row
),
15228 row
->displays_text_p
,
15231 row
->ends_in_middle_of_char_p
,
15232 row
->starts_in_middle_of_char_p
,
15238 row
->visible_height
,
15241 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
15242 row
->end
.overlay_string_index
,
15243 row
->continuation_lines_width
);
15244 fprintf (stderr
, "%9d %5d\n",
15245 CHARPOS (row
->start
.string_pos
),
15246 CHARPOS (row
->end
.string_pos
));
15247 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
15248 row
->end
.dpvec_index
);
15255 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15257 struct glyph
*glyph
= row
->glyphs
[area
];
15258 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
15260 /* Glyph for a line end in text. */
15261 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
15264 if (glyph
< glyph_end
)
15265 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15267 for (; glyph
< glyph_end
; ++glyph
)
15268 dump_glyph (row
, glyph
, area
);
15271 else if (glyphs
== 1)
15275 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15277 char *s
= (char *) alloca (row
->used
[area
] + 1);
15280 for (i
= 0; i
< row
->used
[area
]; ++i
)
15282 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15283 if (glyph
->type
== CHAR_GLYPH
15284 && glyph
->u
.ch
< 0x80
15285 && glyph
->u
.ch
>= ' ')
15286 s
[i
] = glyph
->u
.ch
;
15292 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15298 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15299 Sdump_glyph_matrix
, 0, 1, "p",
15300 doc
: /* Dump the current matrix of the selected window to stderr.
15301 Shows contents of glyph row structures. With non-nil
15302 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15303 glyphs in short form, otherwise show glyphs in long form. */)
15305 Lisp_Object glyphs
;
15307 struct window
*w
= XWINDOW (selected_window
);
15308 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15310 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15311 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15312 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15313 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15314 fprintf (stderr
, "=============================================\n");
15315 dump_glyph_matrix (w
->current_matrix
,
15316 NILP (glyphs
) ? 0 : XINT (glyphs
));
15321 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15322 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15325 struct frame
*f
= XFRAME (selected_frame
);
15326 dump_glyph_matrix (f
->current_matrix
, 1);
15331 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15332 doc
: /* Dump glyph row ROW to stderr.
15333 GLYPH 0 means don't dump glyphs.
15334 GLYPH 1 means dump glyphs in short form.
15335 GLYPH > 1 or omitted means dump glyphs in long form. */)
15337 Lisp_Object row
, glyphs
;
15339 struct glyph_matrix
*matrix
;
15342 CHECK_NUMBER (row
);
15343 matrix
= XWINDOW (selected_window
)->current_matrix
;
15345 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15346 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15348 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15353 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15354 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15355 GLYPH 0 means don't dump glyphs.
15356 GLYPH 1 means dump glyphs in short form.
15357 GLYPH > 1 or omitted means dump glyphs in long form. */)
15359 Lisp_Object row
, glyphs
;
15361 struct frame
*sf
= SELECTED_FRAME ();
15362 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15365 CHECK_NUMBER (row
);
15367 if (vpos
>= 0 && vpos
< m
->nrows
)
15368 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15369 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15374 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15375 doc
: /* Toggle tracing of redisplay.
15376 With ARG, turn tracing on if and only if ARG is positive. */)
15381 trace_redisplay_p
= !trace_redisplay_p
;
15384 arg
= Fprefix_numeric_value (arg
);
15385 trace_redisplay_p
= XINT (arg
) > 0;
15392 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15393 doc
: /* Like `format', but print result to stderr.
15394 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15399 Lisp_Object s
= Fformat (nargs
, args
);
15400 fprintf (stderr
, "%s", SDATA (s
));
15404 #endif /* GLYPH_DEBUG */
15408 /***********************************************************************
15409 Building Desired Matrix Rows
15410 ***********************************************************************/
15412 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15413 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15415 static struct glyph_row
*
15416 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15418 Lisp_Object overlay_arrow_string
;
15420 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15421 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15422 struct buffer
*old
= current_buffer
;
15423 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15424 int arrow_len
= SCHARS (overlay_arrow_string
);
15425 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15426 const unsigned char *p
;
15429 int n_glyphs_before
;
15431 set_buffer_temp (buffer
);
15432 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15433 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15434 SET_TEXT_POS (it
.position
, 0, 0);
15436 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15438 while (p
< arrow_end
)
15440 Lisp_Object face
, ilisp
;
15442 /* Get the next character. */
15444 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15446 it
.c
= *p
, it
.len
= 1;
15449 /* Get its face. */
15450 ilisp
= make_number (p
- arrow_string
);
15451 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15452 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15454 /* Compute its width, get its glyphs. */
15455 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15456 SET_TEXT_POS (it
.position
, -1, -1);
15457 PRODUCE_GLYPHS (&it
);
15459 /* If this character doesn't fit any more in the line, we have
15460 to remove some glyphs. */
15461 if (it
.current_x
> it
.last_visible_x
)
15463 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15468 set_buffer_temp (old
);
15469 return it
.glyph_row
;
15473 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15474 glyphs are only inserted for terminal frames since we can't really
15475 win with truncation glyphs when partially visible glyphs are
15476 involved. Which glyphs to insert is determined by
15477 produce_special_glyphs. */
15480 insert_left_trunc_glyphs (it
)
15483 struct it truncate_it
;
15484 struct glyph
*from
, *end
, *to
, *toend
;
15486 xassert (!FRAME_WINDOW_P (it
->f
));
15488 /* Get the truncation glyphs. */
15490 truncate_it
.current_x
= 0;
15491 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15492 truncate_it
.glyph_row
= &scratch_glyph_row
;
15493 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15494 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15495 truncate_it
.object
= make_number (0);
15496 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15498 /* Overwrite glyphs from IT with truncation glyphs. */
15499 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15500 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15501 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15502 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15507 /* There may be padding glyphs left over. Overwrite them too. */
15508 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15510 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15516 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15520 /* Compute the pixel height and width of IT->glyph_row.
15522 Most of the time, ascent and height of a display line will be equal
15523 to the max_ascent and max_height values of the display iterator
15524 structure. This is not the case if
15526 1. We hit ZV without displaying anything. In this case, max_ascent
15527 and max_height will be zero.
15529 2. We have some glyphs that don't contribute to the line height.
15530 (The glyph row flag contributes_to_line_height_p is for future
15531 pixmap extensions).
15533 The first case is easily covered by using default values because in
15534 these cases, the line height does not really matter, except that it
15535 must not be zero. */
15538 compute_line_metrics (it
)
15541 struct glyph_row
*row
= it
->glyph_row
;
15544 if (FRAME_WINDOW_P (it
->f
))
15546 int i
, min_y
, max_y
;
15548 /* The line may consist of one space only, that was added to
15549 place the cursor on it. If so, the row's height hasn't been
15551 if (row
->height
== 0)
15553 if (it
->max_ascent
+ it
->max_descent
== 0)
15554 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15555 row
->ascent
= it
->max_ascent
;
15556 row
->height
= it
->max_ascent
+ it
->max_descent
;
15557 row
->phys_ascent
= it
->max_phys_ascent
;
15558 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15559 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15562 /* Compute the width of this line. */
15563 row
->pixel_width
= row
->x
;
15564 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15565 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15567 xassert (row
->pixel_width
>= 0);
15568 xassert (row
->ascent
>= 0 && row
->height
> 0);
15570 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15571 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15573 /* If first line's physical ascent is larger than its logical
15574 ascent, use the physical ascent, and make the row taller.
15575 This makes accented characters fully visible. */
15576 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
15577 && row
->phys_ascent
> row
->ascent
)
15579 row
->height
+= row
->phys_ascent
- row
->ascent
;
15580 row
->ascent
= row
->phys_ascent
;
15583 /* Compute how much of the line is visible. */
15584 row
->visible_height
= row
->height
;
15586 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
15587 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
15589 if (row
->y
< min_y
)
15590 row
->visible_height
-= min_y
- row
->y
;
15591 if (row
->y
+ row
->height
> max_y
)
15592 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15596 row
->pixel_width
= row
->used
[TEXT_AREA
];
15597 if (row
->continued_p
)
15598 row
->pixel_width
-= it
->continuation_pixel_width
;
15599 else if (row
->truncated_on_right_p
)
15600 row
->pixel_width
-= it
->truncation_pixel_width
;
15601 row
->ascent
= row
->phys_ascent
= 0;
15602 row
->height
= row
->phys_height
= row
->visible_height
= 1;
15603 row
->extra_line_spacing
= 0;
15606 /* Compute a hash code for this row. */
15608 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15609 for (i
= 0; i
< row
->used
[area
]; ++i
)
15610 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
15611 + row
->glyphs
[area
][i
].u
.val
15612 + row
->glyphs
[area
][i
].face_id
15613 + row
->glyphs
[area
][i
].padding_p
15614 + (row
->glyphs
[area
][i
].type
<< 2));
15616 it
->max_ascent
= it
->max_descent
= 0;
15617 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
15621 /* Append one space to the glyph row of iterator IT if doing a
15622 window-based redisplay. The space has the same face as
15623 IT->face_id. Value is non-zero if a space was added.
15625 This function is called to make sure that there is always one glyph
15626 at the end of a glyph row that the cursor can be set on under
15627 window-systems. (If there weren't such a glyph we would not know
15628 how wide and tall a box cursor should be displayed).
15630 At the same time this space let's a nicely handle clearing to the
15631 end of the line if the row ends in italic text. */
15634 append_space_for_newline (it
, default_face_p
)
15636 int default_face_p
;
15638 if (FRAME_WINDOW_P (it
->f
))
15640 int n
= it
->glyph_row
->used
[TEXT_AREA
];
15642 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
15643 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
15645 /* Save some values that must not be changed.
15646 Must save IT->c and IT->len because otherwise
15647 ITERATOR_AT_END_P wouldn't work anymore after
15648 append_space_for_newline has been called. */
15649 enum display_element_type saved_what
= it
->what
;
15650 int saved_c
= it
->c
, saved_len
= it
->len
;
15651 int saved_x
= it
->current_x
;
15652 int saved_face_id
= it
->face_id
;
15653 struct text_pos saved_pos
;
15654 Lisp_Object saved_object
;
15657 saved_object
= it
->object
;
15658 saved_pos
= it
->position
;
15660 it
->what
= IT_CHARACTER
;
15661 bzero (&it
->position
, sizeof it
->position
);
15662 it
->object
= make_number (0);
15666 if (default_face_p
)
15667 it
->face_id
= DEFAULT_FACE_ID
;
15668 else if (it
->face_before_selective_p
)
15669 it
->face_id
= it
->saved_face_id
;
15670 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15671 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
15673 PRODUCE_GLYPHS (it
);
15675 it
->override_ascent
= -1;
15676 it
->constrain_row_ascent_descent_p
= 0;
15677 it
->current_x
= saved_x
;
15678 it
->object
= saved_object
;
15679 it
->position
= saved_pos
;
15680 it
->what
= saved_what
;
15681 it
->face_id
= saved_face_id
;
15682 it
->len
= saved_len
;
15692 /* Extend the face of the last glyph in the text area of IT->glyph_row
15693 to the end of the display line. Called from display_line.
15694 If the glyph row is empty, add a space glyph to it so that we
15695 know the face to draw. Set the glyph row flag fill_line_p. */
15698 extend_face_to_end_of_line (it
)
15702 struct frame
*f
= it
->f
;
15704 /* If line is already filled, do nothing. */
15705 if (it
->current_x
>= it
->last_visible_x
)
15708 /* Face extension extends the background and box of IT->face_id
15709 to the end of the line. If the background equals the background
15710 of the frame, we don't have to do anything. */
15711 if (it
->face_before_selective_p
)
15712 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
15714 face
= FACE_FROM_ID (f
, it
->face_id
);
15716 if (FRAME_WINDOW_P (f
)
15717 && it
->glyph_row
->displays_text_p
15718 && face
->box
== FACE_NO_BOX
15719 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
15723 /* Set the glyph row flag indicating that the face of the last glyph
15724 in the text area has to be drawn to the end of the text area. */
15725 it
->glyph_row
->fill_line_p
= 1;
15727 /* If current character of IT is not ASCII, make sure we have the
15728 ASCII face. This will be automatically undone the next time
15729 get_next_display_element returns a multibyte character. Note
15730 that the character will always be single byte in unibyte text. */
15731 if (!SINGLE_BYTE_CHAR_P (it
->c
))
15733 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
15736 if (FRAME_WINDOW_P (f
))
15738 /* If the row is empty, add a space with the current face of IT,
15739 so that we know which face to draw. */
15740 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
15742 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
15743 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
15744 it
->glyph_row
->used
[TEXT_AREA
] = 1;
15749 /* Save some values that must not be changed. */
15750 int saved_x
= it
->current_x
;
15751 struct text_pos saved_pos
;
15752 Lisp_Object saved_object
;
15753 enum display_element_type saved_what
= it
->what
;
15754 int saved_face_id
= it
->face_id
;
15756 saved_object
= it
->object
;
15757 saved_pos
= it
->position
;
15759 it
->what
= IT_CHARACTER
;
15760 bzero (&it
->position
, sizeof it
->position
);
15761 it
->object
= make_number (0);
15764 it
->face_id
= face
->id
;
15766 PRODUCE_GLYPHS (it
);
15768 while (it
->current_x
<= it
->last_visible_x
)
15769 PRODUCE_GLYPHS (it
);
15771 /* Don't count these blanks really. It would let us insert a left
15772 truncation glyph below and make us set the cursor on them, maybe. */
15773 it
->current_x
= saved_x
;
15774 it
->object
= saved_object
;
15775 it
->position
= saved_pos
;
15776 it
->what
= saved_what
;
15777 it
->face_id
= saved_face_id
;
15782 /* Value is non-zero if text starting at CHARPOS in current_buffer is
15783 trailing whitespace. */
15786 trailing_whitespace_p (charpos
)
15789 int bytepos
= CHAR_TO_BYTE (charpos
);
15792 while (bytepos
< ZV_BYTE
15793 && (c
= FETCH_CHAR (bytepos
),
15794 c
== ' ' || c
== '\t'))
15797 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
15799 if (bytepos
!= PT_BYTE
)
15806 /* Highlight trailing whitespace, if any, in ROW. */
15809 highlight_trailing_whitespace (f
, row
)
15811 struct glyph_row
*row
;
15813 int used
= row
->used
[TEXT_AREA
];
15817 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
15818 struct glyph
*glyph
= start
+ used
- 1;
15820 /* Skip over glyphs inserted to display the cursor at the
15821 end of a line, for extending the face of the last glyph
15822 to the end of the line on terminals, and for truncation
15823 and continuation glyphs. */
15824 while (glyph
>= start
15825 && glyph
->type
== CHAR_GLYPH
15826 && INTEGERP (glyph
->object
))
15829 /* If last glyph is a space or stretch, and it's trailing
15830 whitespace, set the face of all trailing whitespace glyphs in
15831 IT->glyph_row to `trailing-whitespace'. */
15833 && BUFFERP (glyph
->object
)
15834 && (glyph
->type
== STRETCH_GLYPH
15835 || (glyph
->type
== CHAR_GLYPH
15836 && glyph
->u
.ch
== ' '))
15837 && trailing_whitespace_p (glyph
->charpos
))
15839 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
15843 while (glyph
>= start
15844 && BUFFERP (glyph
->object
)
15845 && (glyph
->type
== STRETCH_GLYPH
15846 || (glyph
->type
== CHAR_GLYPH
15847 && glyph
->u
.ch
== ' ')))
15848 (glyph
--)->face_id
= face_id
;
15854 /* Value is non-zero if glyph row ROW in window W should be
15855 used to hold the cursor. */
15858 cursor_row_p (w
, row
)
15860 struct glyph_row
*row
;
15862 int cursor_row_p
= 1;
15864 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15866 /* Suppose the row ends on a string.
15867 Unless the row is continued, that means it ends on a newline
15868 in the string. If it's anything other than a display string
15869 (e.g. a before-string from an overlay), we don't want the
15870 cursor there. (This heuristic seems to give the optimal
15871 behavior for the various types of multi-line strings.) */
15872 if (CHARPOS (row
->end
.string_pos
) >= 0)
15874 if (row
->continued_p
)
15878 /* Check for `display' property. */
15879 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
15880 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
15881 struct glyph
*glyph
;
15884 for (glyph
= end
; glyph
>= beg
; --glyph
)
15885 if (STRINGP (glyph
->object
))
15888 = Fget_char_property (make_number (PT
),
15892 && display_prop_string_p (prop
, glyph
->object
));
15897 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15899 /* If the row ends in middle of a real character,
15900 and the line is continued, we want the cursor here.
15901 That's because MATRIX_ROW_END_CHARPOS would equal
15902 PT if PT is before the character. */
15903 if (!row
->ends_in_ellipsis_p
)
15904 cursor_row_p
= row
->continued_p
;
15906 /* If the row ends in an ellipsis, then
15907 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15908 We want that position to be displayed after the ellipsis. */
15911 /* If the row ends at ZV, display the cursor at the end of that
15912 row instead of at the start of the row below. */
15913 else if (row
->ends_at_zv_p
)
15919 return cursor_row_p
;
15923 /* Construct the glyph row IT->glyph_row in the desired matrix of
15924 IT->w from text at the current position of IT. See dispextern.h
15925 for an overview of struct it. Value is non-zero if
15926 IT->glyph_row displays text, as opposed to a line displaying ZV
15933 struct glyph_row
*row
= it
->glyph_row
;
15934 Lisp_Object overlay_arrow_string
;
15936 /* We always start displaying at hpos zero even if hscrolled. */
15937 xassert (it
->hpos
== 0 && it
->current_x
== 0);
15939 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
15940 >= it
->w
->desired_matrix
->nrows
)
15942 it
->w
->nrows_scale_factor
++;
15943 fonts_changed_p
= 1;
15947 /* Is IT->w showing the region? */
15948 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
15950 /* Clear the result glyph row and enable it. */
15951 prepare_desired_row (row
);
15953 row
->y
= it
->current_y
;
15954 row
->start
= it
->start
;
15955 row
->continuation_lines_width
= it
->continuation_lines_width
;
15956 row
->displays_text_p
= 1;
15957 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
15958 it
->starts_in_middle_of_char_p
= 0;
15960 /* Arrange the overlays nicely for our purposes. Usually, we call
15961 display_line on only one line at a time, in which case this
15962 can't really hurt too much, or we call it on lines which appear
15963 one after another in the buffer, in which case all calls to
15964 recenter_overlay_lists but the first will be pretty cheap. */
15965 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
15967 /* Move over display elements that are not visible because we are
15968 hscrolled. This may stop at an x-position < IT->first_visible_x
15969 if the first glyph is partially visible or if we hit a line end. */
15970 if (it
->current_x
< it
->first_visible_x
)
15972 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
15973 MOVE_TO_POS
| MOVE_TO_X
);
15976 /* Get the initial row height. This is either the height of the
15977 text hscrolled, if there is any, or zero. */
15978 row
->ascent
= it
->max_ascent
;
15979 row
->height
= it
->max_ascent
+ it
->max_descent
;
15980 row
->phys_ascent
= it
->max_phys_ascent
;
15981 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15982 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15984 /* Loop generating characters. The loop is left with IT on the next
15985 character to display. */
15988 int n_glyphs_before
, hpos_before
, x_before
;
15990 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
15992 /* Retrieve the next thing to display. Value is zero if end of
15994 if (!get_next_display_element (it
))
15996 /* Maybe add a space at the end of this line that is used to
15997 display the cursor there under X. Set the charpos of the
15998 first glyph of blank lines not corresponding to any text
16000 #ifdef HAVE_WINDOW_SYSTEM
16001 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16002 row
->exact_window_width_line_p
= 1;
16004 #endif /* HAVE_WINDOW_SYSTEM */
16005 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
16006 || row
->used
[TEXT_AREA
] == 0)
16008 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
16009 row
->displays_text_p
= 0;
16011 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
16012 && (!MINI_WINDOW_P (it
->w
)
16013 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
16014 row
->indicate_empty_line_p
= 1;
16017 it
->continuation_lines_width
= 0;
16018 row
->ends_at_zv_p
= 1;
16022 /* Now, get the metrics of what we want to display. This also
16023 generates glyphs in `row' (which is IT->glyph_row). */
16024 n_glyphs_before
= row
->used
[TEXT_AREA
];
16027 /* Remember the line height so far in case the next element doesn't
16028 fit on the line. */
16029 if (!it
->truncate_lines_p
)
16031 ascent
= it
->max_ascent
;
16032 descent
= it
->max_descent
;
16033 phys_ascent
= it
->max_phys_ascent
;
16034 phys_descent
= it
->max_phys_descent
;
16037 PRODUCE_GLYPHS (it
);
16039 /* If this display element was in marginal areas, continue with
16041 if (it
->area
!= TEXT_AREA
)
16043 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16044 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16045 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16046 row
->phys_height
= max (row
->phys_height
,
16047 it
->max_phys_ascent
+ it
->max_phys_descent
);
16048 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16049 it
->max_extra_line_spacing
);
16050 set_iterator_to_next (it
, 1);
16054 /* Does the display element fit on the line? If we truncate
16055 lines, we should draw past the right edge of the window. If
16056 we don't truncate, we want to stop so that we can display the
16057 continuation glyph before the right margin. If lines are
16058 continued, there are two possible strategies for characters
16059 resulting in more than 1 glyph (e.g. tabs): Display as many
16060 glyphs as possible in this line and leave the rest for the
16061 continuation line, or display the whole element in the next
16062 line. Original redisplay did the former, so we do it also. */
16063 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
16064 hpos_before
= it
->hpos
;
16067 if (/* Not a newline. */
16069 /* Glyphs produced fit entirely in the line. */
16070 && it
->current_x
< it
->last_visible_x
)
16072 it
->hpos
+= nglyphs
;
16073 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16074 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16075 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16076 row
->phys_height
= max (row
->phys_height
,
16077 it
->max_phys_ascent
+ it
->max_phys_descent
);
16078 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16079 it
->max_extra_line_spacing
);
16080 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
16081 row
->x
= x
- it
->first_visible_x
;
16086 struct glyph
*glyph
;
16088 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
16090 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16091 new_x
= x
+ glyph
->pixel_width
;
16093 if (/* Lines are continued. */
16094 !it
->truncate_lines_p
16095 && (/* Glyph doesn't fit on the line. */
16096 new_x
> it
->last_visible_x
16097 /* Or it fits exactly on a window system frame. */
16098 || (new_x
== it
->last_visible_x
16099 && FRAME_WINDOW_P (it
->f
))))
16101 /* End of a continued line. */
16104 || (new_x
== it
->last_visible_x
16105 && FRAME_WINDOW_P (it
->f
)))
16107 /* Current glyph is the only one on the line or
16108 fits exactly on the line. We must continue
16109 the line because we can't draw the cursor
16110 after the glyph. */
16111 row
->continued_p
= 1;
16112 it
->current_x
= new_x
;
16113 it
->continuation_lines_width
+= new_x
;
16115 if (i
== nglyphs
- 1)
16117 set_iterator_to_next (it
, 1);
16118 #ifdef HAVE_WINDOW_SYSTEM
16119 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16121 if (!get_next_display_element (it
))
16123 row
->exact_window_width_line_p
= 1;
16124 it
->continuation_lines_width
= 0;
16125 row
->continued_p
= 0;
16126 row
->ends_at_zv_p
= 1;
16128 else if (ITERATOR_AT_END_OF_LINE_P (it
))
16130 row
->continued_p
= 0;
16131 row
->exact_window_width_line_p
= 1;
16134 #endif /* HAVE_WINDOW_SYSTEM */
16137 else if (CHAR_GLYPH_PADDING_P (*glyph
)
16138 && !FRAME_WINDOW_P (it
->f
))
16140 /* A padding glyph that doesn't fit on this line.
16141 This means the whole character doesn't fit
16143 row
->used
[TEXT_AREA
] = n_glyphs_before
;
16145 /* Fill the rest of the row with continuation
16146 glyphs like in 20.x. */
16147 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
16148 < row
->glyphs
[1 + TEXT_AREA
])
16149 produce_special_glyphs (it
, IT_CONTINUATION
);
16151 row
->continued_p
= 1;
16152 it
->current_x
= x_before
;
16153 it
->continuation_lines_width
+= x_before
;
16155 /* Restore the height to what it was before the
16156 element not fitting on the line. */
16157 it
->max_ascent
= ascent
;
16158 it
->max_descent
= descent
;
16159 it
->max_phys_ascent
= phys_ascent
;
16160 it
->max_phys_descent
= phys_descent
;
16162 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
16164 /* A TAB that extends past the right edge of the
16165 window. This produces a single glyph on
16166 window system frames. We leave the glyph in
16167 this row and let it fill the row, but don't
16168 consume the TAB. */
16169 it
->continuation_lines_width
+= it
->last_visible_x
;
16170 row
->ends_in_middle_of_char_p
= 1;
16171 row
->continued_p
= 1;
16172 glyph
->pixel_width
= it
->last_visible_x
- x
;
16173 it
->starts_in_middle_of_char_p
= 1;
16177 /* Something other than a TAB that draws past
16178 the right edge of the window. Restore
16179 positions to values before the element. */
16180 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16182 /* Display continuation glyphs. */
16183 if (!FRAME_WINDOW_P (it
->f
))
16184 produce_special_glyphs (it
, IT_CONTINUATION
);
16185 row
->continued_p
= 1;
16187 it
->current_x
= x_before
;
16188 it
->continuation_lines_width
+= x
;
16189 extend_face_to_end_of_line (it
);
16191 if (nglyphs
> 1 && i
> 0)
16193 row
->ends_in_middle_of_char_p
= 1;
16194 it
->starts_in_middle_of_char_p
= 1;
16197 /* Restore the height to what it was before the
16198 element not fitting on the line. */
16199 it
->max_ascent
= ascent
;
16200 it
->max_descent
= descent
;
16201 it
->max_phys_ascent
= phys_ascent
;
16202 it
->max_phys_descent
= phys_descent
;
16207 else if (new_x
> it
->first_visible_x
)
16209 /* Increment number of glyphs actually displayed. */
16212 if (x
< it
->first_visible_x
)
16213 /* Glyph is partially visible, i.e. row starts at
16214 negative X position. */
16215 row
->x
= x
- it
->first_visible_x
;
16219 /* Glyph is completely off the left margin of the
16220 window. This should not happen because of the
16221 move_it_in_display_line at the start of this
16222 function, unless the text display area of the
16223 window is empty. */
16224 xassert (it
->first_visible_x
<= it
->last_visible_x
);
16228 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16229 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16230 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16231 row
->phys_height
= max (row
->phys_height
,
16232 it
->max_phys_ascent
+ it
->max_phys_descent
);
16233 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16234 it
->max_extra_line_spacing
);
16236 /* End of this display line if row is continued. */
16237 if (row
->continued_p
|| row
->ends_at_zv_p
)
16242 /* Is this a line end? If yes, we're also done, after making
16243 sure that a non-default face is extended up to the right
16244 margin of the window. */
16245 if (ITERATOR_AT_END_OF_LINE_P (it
))
16247 int used_before
= row
->used
[TEXT_AREA
];
16249 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
16251 #ifdef HAVE_WINDOW_SYSTEM
16252 /* Add a space at the end of the line that is used to
16253 display the cursor there. */
16254 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16255 append_space_for_newline (it
, 0);
16256 #endif /* HAVE_WINDOW_SYSTEM */
16258 /* Extend the face to the end of the line. */
16259 extend_face_to_end_of_line (it
);
16261 /* Make sure we have the position. */
16262 if (used_before
== 0)
16263 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
16265 /* Consume the line end. This skips over invisible lines. */
16266 set_iterator_to_next (it
, 1);
16267 it
->continuation_lines_width
= 0;
16271 /* Proceed with next display element. Note that this skips
16272 over lines invisible because of selective display. */
16273 set_iterator_to_next (it
, 1);
16275 /* If we truncate lines, we are done when the last displayed
16276 glyphs reach past the right margin of the window. */
16277 if (it
->truncate_lines_p
16278 && (FRAME_WINDOW_P (it
->f
)
16279 ? (it
->current_x
>= it
->last_visible_x
)
16280 : (it
->current_x
> it
->last_visible_x
)))
16282 /* Maybe add truncation glyphs. */
16283 if (!FRAME_WINDOW_P (it
->f
))
16287 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16288 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16291 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16293 row
->used
[TEXT_AREA
] = i
;
16294 produce_special_glyphs (it
, IT_TRUNCATION
);
16297 #ifdef HAVE_WINDOW_SYSTEM
16300 /* Don't truncate if we can overflow newline into fringe. */
16301 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16303 if (!get_next_display_element (it
))
16305 it
->continuation_lines_width
= 0;
16306 row
->ends_at_zv_p
= 1;
16307 row
->exact_window_width_line_p
= 1;
16310 if (ITERATOR_AT_END_OF_LINE_P (it
))
16312 row
->exact_window_width_line_p
= 1;
16313 goto at_end_of_line
;
16317 #endif /* HAVE_WINDOW_SYSTEM */
16319 row
->truncated_on_right_p
= 1;
16320 it
->continuation_lines_width
= 0;
16321 reseat_at_next_visible_line_start (it
, 0);
16322 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16323 it
->hpos
= hpos_before
;
16324 it
->current_x
= x_before
;
16329 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16330 at the left window margin. */
16331 if (it
->first_visible_x
16332 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16334 if (!FRAME_WINDOW_P (it
->f
))
16335 insert_left_trunc_glyphs (it
);
16336 row
->truncated_on_left_p
= 1;
16339 /* If the start of this line is the overlay arrow-position, then
16340 mark this glyph row as the one containing the overlay arrow.
16341 This is clearly a mess with variable size fonts. It would be
16342 better to let it be displayed like cursors under X. */
16343 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16344 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16345 !NILP (overlay_arrow_string
)))
16347 /* Overlay arrow in window redisplay is a fringe bitmap. */
16348 if (STRINGP (overlay_arrow_string
))
16350 struct glyph_row
*arrow_row
16351 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
16352 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
16353 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
16354 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
16355 struct glyph
*p2
, *end
;
16357 /* Copy the arrow glyphs. */
16358 while (glyph
< arrow_end
)
16361 /* Throw away padding glyphs. */
16363 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16364 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
16370 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
16375 xassert (INTEGERP (overlay_arrow_string
));
16376 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
16378 overlay_arrow_seen
= 1;
16381 /* Compute pixel dimensions of this line. */
16382 compute_line_metrics (it
);
16384 /* Remember the position at which this line ends. */
16385 row
->end
= it
->current
;
16387 /* Record whether this row ends inside an ellipsis. */
16388 row
->ends_in_ellipsis_p
16389 = (it
->method
== GET_FROM_DISPLAY_VECTOR
16390 && it
->ellipsis_p
);
16392 /* Save fringe bitmaps in this row. */
16393 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
16394 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
16395 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
16396 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
16398 it
->left_user_fringe_bitmap
= 0;
16399 it
->left_user_fringe_face_id
= 0;
16400 it
->right_user_fringe_bitmap
= 0;
16401 it
->right_user_fringe_face_id
= 0;
16403 /* Maybe set the cursor. */
16404 if (it
->w
->cursor
.vpos
< 0
16405 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
16406 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
16407 && cursor_row_p (it
->w
, row
))
16408 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
16410 /* Highlight trailing whitespace. */
16411 if (!NILP (Vshow_trailing_whitespace
))
16412 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
16414 /* Prepare for the next line. This line starts horizontally at (X
16415 HPOS) = (0 0). Vertical positions are incremented. As a
16416 convenience for the caller, IT->glyph_row is set to the next
16418 it
->current_x
= it
->hpos
= 0;
16419 it
->current_y
+= row
->height
;
16422 it
->start
= it
->current
;
16423 return row
->displays_text_p
;
16428 /***********************************************************************
16430 ***********************************************************************/
16432 /* Redisplay the menu bar in the frame for window W.
16434 The menu bar of X frames that don't have X toolkit support is
16435 displayed in a special window W->frame->menu_bar_window.
16437 The menu bar of terminal frames is treated specially as far as
16438 glyph matrices are concerned. Menu bar lines are not part of
16439 windows, so the update is done directly on the frame matrix rows
16440 for the menu bar. */
16443 display_menu_bar (w
)
16446 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16451 /* Don't do all this for graphical frames. */
16453 if (FRAME_W32_P (f
))
16456 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
16461 if (FRAME_MAC_P (f
))
16465 #ifdef USE_X_TOOLKIT
16466 xassert (!FRAME_WINDOW_P (f
));
16467 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
16468 it
.first_visible_x
= 0;
16469 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16470 #else /* not USE_X_TOOLKIT */
16471 if (FRAME_WINDOW_P (f
))
16473 /* Menu bar lines are displayed in the desired matrix of the
16474 dummy window menu_bar_window. */
16475 struct window
*menu_w
;
16476 xassert (WINDOWP (f
->menu_bar_window
));
16477 menu_w
= XWINDOW (f
->menu_bar_window
);
16478 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
16480 it
.first_visible_x
= 0;
16481 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16485 /* This is a TTY frame, i.e. character hpos/vpos are used as
16487 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
16489 it
.first_visible_x
= 0;
16490 it
.last_visible_x
= FRAME_COLS (f
);
16492 #endif /* not USE_X_TOOLKIT */
16494 if (! mode_line_inverse_video
)
16495 /* Force the menu-bar to be displayed in the default face. */
16496 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16498 /* Clear all rows of the menu bar. */
16499 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
16501 struct glyph_row
*row
= it
.glyph_row
+ i
;
16502 clear_glyph_row (row
);
16503 row
->enabled_p
= 1;
16504 row
->full_width_p
= 1;
16507 /* Display all items of the menu bar. */
16508 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
16509 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
16511 Lisp_Object string
;
16513 /* Stop at nil string. */
16514 string
= AREF (items
, i
+ 1);
16518 /* Remember where item was displayed. */
16519 AREF (items
, i
+ 3) = make_number (it
.hpos
);
16521 /* Display the item, pad with one space. */
16522 if (it
.current_x
< it
.last_visible_x
)
16523 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
16524 SCHARS (string
) + 1, 0, 0, -1);
16527 /* Fill out the line with spaces. */
16528 if (it
.current_x
< it
.last_visible_x
)
16529 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
16531 /* Compute the total height of the lines. */
16532 compute_line_metrics (&it
);
16537 /***********************************************************************
16539 ***********************************************************************/
16541 /* Redisplay mode lines in the window tree whose root is WINDOW. If
16542 FORCE is non-zero, redisplay mode lines unconditionally.
16543 Otherwise, redisplay only mode lines that are garbaged. Value is
16544 the number of windows whose mode lines were redisplayed. */
16547 redisplay_mode_lines (window
, force
)
16548 Lisp_Object window
;
16553 while (!NILP (window
))
16555 struct window
*w
= XWINDOW (window
);
16557 if (WINDOWP (w
->hchild
))
16558 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
16559 else if (WINDOWP (w
->vchild
))
16560 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
16562 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
16563 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
16565 struct text_pos lpoint
;
16566 struct buffer
*old
= current_buffer
;
16568 /* Set the window's buffer for the mode line display. */
16569 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16570 set_buffer_internal_1 (XBUFFER (w
->buffer
));
16572 /* Point refers normally to the selected window. For any
16573 other window, set up appropriate value. */
16574 if (!EQ (window
, selected_window
))
16576 struct text_pos pt
;
16578 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
16579 if (CHARPOS (pt
) < BEGV
)
16580 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16581 else if (CHARPOS (pt
) > (ZV
- 1))
16582 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
16584 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
16587 /* Display mode lines. */
16588 clear_glyph_matrix (w
->desired_matrix
);
16589 if (display_mode_lines (w
))
16592 w
->must_be_updated_p
= 1;
16595 /* Restore old settings. */
16596 set_buffer_internal_1 (old
);
16597 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16607 /* Display the mode and/or top line of window W. Value is the number
16608 of mode lines displayed. */
16611 display_mode_lines (w
)
16614 Lisp_Object old_selected_window
, old_selected_frame
;
16617 old_selected_frame
= selected_frame
;
16618 selected_frame
= w
->frame
;
16619 old_selected_window
= selected_window
;
16620 XSETWINDOW (selected_window
, w
);
16622 /* These will be set while the mode line specs are processed. */
16623 line_number_displayed
= 0;
16624 w
->column_number_displayed
= Qnil
;
16626 if (WINDOW_WANTS_MODELINE_P (w
))
16628 struct window
*sel_w
= XWINDOW (old_selected_window
);
16630 /* Select mode line face based on the real selected window. */
16631 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
16632 current_buffer
->mode_line_format
);
16636 if (WINDOW_WANTS_HEADER_LINE_P (w
))
16638 display_mode_line (w
, HEADER_LINE_FACE_ID
,
16639 current_buffer
->header_line_format
);
16643 selected_frame
= old_selected_frame
;
16644 selected_window
= old_selected_window
;
16649 /* Display mode or top line of window W. FACE_ID specifies which line
16650 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
16651 FORMAT is the mode line format to display. Value is the pixel
16652 height of the mode line displayed. */
16655 display_mode_line (w
, face_id
, format
)
16657 enum face_id face_id
;
16658 Lisp_Object format
;
16662 int count
= SPECPDL_INDEX ();
16664 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16665 /* Don't extend on a previously drawn mode-line.
16666 This may happen if called from pos_visible_p. */
16667 it
.glyph_row
->enabled_p
= 0;
16668 prepare_desired_row (it
.glyph_row
);
16670 it
.glyph_row
->mode_line_p
= 1;
16672 if (! mode_line_inverse_video
)
16673 /* Force the mode-line to be displayed in the default face. */
16674 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16676 record_unwind_protect (unwind_format_mode_line
,
16677 format_mode_line_unwind_data (NULL
, 0));
16679 mode_line_target
= MODE_LINE_DISPLAY
;
16681 /* Temporarily make frame's keyboard the current kboard so that
16682 kboard-local variables in the mode_line_format will get the right
16684 push_kboard (FRAME_KBOARD (it
.f
));
16685 record_unwind_save_match_data ();
16686 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16689 unbind_to (count
, Qnil
);
16691 /* Fill up with spaces. */
16692 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
16694 compute_line_metrics (&it
);
16695 it
.glyph_row
->full_width_p
= 1;
16696 it
.glyph_row
->continued_p
= 0;
16697 it
.glyph_row
->truncated_on_left_p
= 0;
16698 it
.glyph_row
->truncated_on_right_p
= 0;
16700 /* Make a 3D mode-line have a shadow at its right end. */
16701 face
= FACE_FROM_ID (it
.f
, face_id
);
16702 extend_face_to_end_of_line (&it
);
16703 if (face
->box
!= FACE_NO_BOX
)
16705 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
16706 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
16707 last
->right_box_line_p
= 1;
16710 return it
.glyph_row
->height
;
16713 /* Move element ELT in LIST to the front of LIST.
16714 Return the updated list. */
16717 move_elt_to_front (elt
, list
)
16718 Lisp_Object elt
, list
;
16720 register Lisp_Object tail
, prev
;
16721 register Lisp_Object tem
;
16725 while (CONSP (tail
))
16731 /* Splice out the link TAIL. */
16733 list
= XCDR (tail
);
16735 Fsetcdr (prev
, XCDR (tail
));
16737 /* Now make it the first. */
16738 Fsetcdr (tail
, list
);
16743 tail
= XCDR (tail
);
16747 /* Not found--return unchanged LIST. */
16751 /* Contribute ELT to the mode line for window IT->w. How it
16752 translates into text depends on its data type.
16754 IT describes the display environment in which we display, as usual.
16756 DEPTH is the depth in recursion. It is used to prevent
16757 infinite recursion here.
16759 FIELD_WIDTH is the number of characters the display of ELT should
16760 occupy in the mode line, and PRECISION is the maximum number of
16761 characters to display from ELT's representation. See
16762 display_string for details.
16764 Returns the hpos of the end of the text generated by ELT.
16766 PROPS is a property list to add to any string we encounter.
16768 If RISKY is nonzero, remove (disregard) any properties in any string
16769 we encounter, and ignore :eval and :propertize.
16771 The global variable `mode_line_target' determines whether the
16772 output is passed to `store_mode_line_noprop',
16773 `store_mode_line_string', or `display_string'. */
16776 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
16779 int field_width
, precision
;
16780 Lisp_Object elt
, props
;
16783 int n
= 0, field
, prec
;
16788 elt
= build_string ("*too-deep*");
16792 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
16796 /* A string: output it and check for %-constructs within it. */
16800 if (SCHARS (elt
) > 0
16801 && (!NILP (props
) || risky
))
16803 Lisp_Object oprops
, aelt
;
16804 oprops
= Ftext_properties_at (make_number (0), elt
);
16806 /* If the starting string's properties are not what
16807 we want, translate the string. Also, if the string
16808 is risky, do that anyway. */
16810 if (NILP (Fequal (props
, oprops
)) || risky
)
16812 /* If the starting string has properties,
16813 merge the specified ones onto the existing ones. */
16814 if (! NILP (oprops
) && !risky
)
16818 oprops
= Fcopy_sequence (oprops
);
16820 while (CONSP (tem
))
16822 oprops
= Fplist_put (oprops
, XCAR (tem
),
16823 XCAR (XCDR (tem
)));
16824 tem
= XCDR (XCDR (tem
));
16829 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
16830 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
16832 /* AELT is what we want. Move it to the front
16833 without consing. */
16835 mode_line_proptrans_alist
16836 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
16842 /* If AELT has the wrong props, it is useless.
16843 so get rid of it. */
16845 mode_line_proptrans_alist
16846 = Fdelq (aelt
, mode_line_proptrans_alist
);
16848 elt
= Fcopy_sequence (elt
);
16849 Fset_text_properties (make_number (0), Flength (elt
),
16851 /* Add this item to mode_line_proptrans_alist. */
16852 mode_line_proptrans_alist
16853 = Fcons (Fcons (elt
, props
),
16854 mode_line_proptrans_alist
);
16855 /* Truncate mode_line_proptrans_alist
16856 to at most 50 elements. */
16857 tem
= Fnthcdr (make_number (50),
16858 mode_line_proptrans_alist
);
16860 XSETCDR (tem
, Qnil
);
16869 prec
= precision
- n
;
16870 switch (mode_line_target
)
16872 case MODE_LINE_NOPROP
:
16873 case MODE_LINE_TITLE
:
16874 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
16876 case MODE_LINE_STRING
:
16877 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
16879 case MODE_LINE_DISPLAY
:
16880 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
16881 0, prec
, 0, STRING_MULTIBYTE (elt
));
16888 /* Handle the non-literal case. */
16890 while ((precision
<= 0 || n
< precision
)
16891 && SREF (elt
, offset
) != 0
16892 && (mode_line_target
!= MODE_LINE_DISPLAY
16893 || it
->current_x
< it
->last_visible_x
))
16895 int last_offset
= offset
;
16897 /* Advance to end of string or next format specifier. */
16898 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
16901 if (offset
- 1 != last_offset
)
16903 int nchars
, nbytes
;
16905 /* Output to end of string or up to '%'. Field width
16906 is length of string. Don't output more than
16907 PRECISION allows us. */
16910 prec
= c_string_width (SDATA (elt
) + last_offset
,
16911 offset
- last_offset
, precision
- n
,
16914 switch (mode_line_target
)
16916 case MODE_LINE_NOPROP
:
16917 case MODE_LINE_TITLE
:
16918 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
16920 case MODE_LINE_STRING
:
16922 int bytepos
= last_offset
;
16923 int charpos
= string_byte_to_char (elt
, bytepos
);
16924 int endpos
= (precision
<= 0
16925 ? string_byte_to_char (elt
, offset
)
16926 : charpos
+ nchars
);
16928 n
+= store_mode_line_string (NULL
,
16929 Fsubstring (elt
, make_number (charpos
),
16930 make_number (endpos
)),
16934 case MODE_LINE_DISPLAY
:
16936 int bytepos
= last_offset
;
16937 int charpos
= string_byte_to_char (elt
, bytepos
);
16939 if (precision
<= 0)
16940 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
16941 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
16943 STRING_MULTIBYTE (elt
));
16948 else /* c == '%' */
16950 int percent_position
= offset
;
16952 /* Get the specified minimum width. Zero means
16955 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
16956 field
= field
* 10 + c
- '0';
16958 /* Don't pad beyond the total padding allowed. */
16959 if (field_width
- n
> 0 && field
> field_width
- n
)
16960 field
= field_width
- n
;
16962 /* Note that either PRECISION <= 0 or N < PRECISION. */
16963 prec
= precision
- n
;
16966 n
+= display_mode_element (it
, depth
, field
, prec
,
16967 Vglobal_mode_string
, props
,
16972 int bytepos
, charpos
;
16973 unsigned char *spec
;
16975 bytepos
= percent_position
;
16976 charpos
= (STRING_MULTIBYTE (elt
)
16977 ? string_byte_to_char (elt
, bytepos
)
16981 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
16983 switch (mode_line_target
)
16985 case MODE_LINE_NOPROP
:
16986 case MODE_LINE_TITLE
:
16987 n
+= store_mode_line_noprop (spec
, field
, prec
);
16989 case MODE_LINE_STRING
:
16991 int len
= strlen (spec
);
16992 Lisp_Object tem
= make_string (spec
, len
);
16993 props
= Ftext_properties_at (make_number (charpos
), elt
);
16994 /* Should only keep face property in props */
16995 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
16998 case MODE_LINE_DISPLAY
:
17000 int nglyphs_before
, nwritten
;
17002 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17003 nwritten
= display_string (spec
, Qnil
, elt
,
17008 /* Assign to the glyphs written above the
17009 string where the `%x' came from, position
17013 struct glyph
*glyph
17014 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
17018 for (i
= 0; i
< nwritten
; ++i
)
17020 glyph
[i
].object
= elt
;
17021 glyph
[i
].charpos
= charpos
;
17038 /* A symbol: process the value of the symbol recursively
17039 as if it appeared here directly. Avoid error if symbol void.
17040 Special case: if value of symbol is a string, output the string
17043 register Lisp_Object tem
;
17045 /* If the variable is not marked as risky to set
17046 then its contents are risky to use. */
17047 if (NILP (Fget (elt
, Qrisky_local_variable
)))
17050 tem
= Fboundp (elt
);
17053 tem
= Fsymbol_value (elt
);
17054 /* If value is a string, output that string literally:
17055 don't check for % within it. */
17059 if (!EQ (tem
, elt
))
17061 /* Give up right away for nil or t. */
17071 register Lisp_Object car
, tem
;
17073 /* A cons cell: five distinct cases.
17074 If first element is :eval or :propertize, do something special.
17075 If first element is a string or a cons, process all the elements
17076 and effectively concatenate them.
17077 If first element is a negative number, truncate displaying cdr to
17078 at most that many characters. If positive, pad (with spaces)
17079 to at least that many characters.
17080 If first element is a symbol, process the cadr or caddr recursively
17081 according to whether the symbol's value is non-nil or nil. */
17083 if (EQ (car
, QCeval
))
17085 /* An element of the form (:eval FORM) means evaluate FORM
17086 and use the result as mode line elements. */
17091 if (CONSP (XCDR (elt
)))
17094 spec
= safe_eval (XCAR (XCDR (elt
)));
17095 n
+= display_mode_element (it
, depth
, field_width
- n
,
17096 precision
- n
, spec
, props
,
17100 else if (EQ (car
, QCpropertize
))
17102 /* An element of the form (:propertize ELT PROPS...)
17103 means display ELT but applying properties PROPS. */
17108 if (CONSP (XCDR (elt
)))
17109 n
+= display_mode_element (it
, depth
, field_width
- n
,
17110 precision
- n
, XCAR (XCDR (elt
)),
17111 XCDR (XCDR (elt
)), risky
);
17113 else if (SYMBOLP (car
))
17115 tem
= Fboundp (car
);
17119 /* elt is now the cdr, and we know it is a cons cell.
17120 Use its car if CAR has a non-nil value. */
17123 tem
= Fsymbol_value (car
);
17130 /* Symbol's value is nil (or symbol is unbound)
17131 Get the cddr of the original list
17132 and if possible find the caddr and use that. */
17136 else if (!CONSP (elt
))
17141 else if (INTEGERP (car
))
17143 register int lim
= XINT (car
);
17147 /* Negative int means reduce maximum width. */
17148 if (precision
<= 0)
17151 precision
= min (precision
, -lim
);
17155 /* Padding specified. Don't let it be more than
17156 current maximum. */
17158 lim
= min (precision
, lim
);
17160 /* If that's more padding than already wanted, queue it.
17161 But don't reduce padding already specified even if
17162 that is beyond the current truncation point. */
17163 field_width
= max (lim
, field_width
);
17167 else if (STRINGP (car
) || CONSP (car
))
17169 register int limit
= 50;
17170 /* Limit is to protect against circular lists. */
17173 && (precision
<= 0 || n
< precision
))
17175 n
+= display_mode_element (it
, depth
,
17176 /* Do padding only after the last
17177 element in the list. */
17178 (! CONSP (XCDR (elt
))
17181 precision
- n
, XCAR (elt
),
17191 elt
= build_string ("*invalid*");
17195 /* Pad to FIELD_WIDTH. */
17196 if (field_width
> 0 && n
< field_width
)
17198 switch (mode_line_target
)
17200 case MODE_LINE_NOPROP
:
17201 case MODE_LINE_TITLE
:
17202 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
17204 case MODE_LINE_STRING
:
17205 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
17207 case MODE_LINE_DISPLAY
:
17208 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
17217 /* Store a mode-line string element in mode_line_string_list.
17219 If STRING is non-null, display that C string. Otherwise, the Lisp
17220 string LISP_STRING is displayed.
17222 FIELD_WIDTH is the minimum number of output glyphs to produce.
17223 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17224 with spaces. FIELD_WIDTH <= 0 means don't pad.
17226 PRECISION is the maximum number of characters to output from
17227 STRING. PRECISION <= 0 means don't truncate the string.
17229 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
17230 properties to the string.
17232 PROPS are the properties to add to the string.
17233 The mode_line_string_face face property is always added to the string.
17237 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
17239 Lisp_Object lisp_string
;
17248 if (string
!= NULL
)
17250 len
= strlen (string
);
17251 if (precision
> 0 && len
> precision
)
17253 lisp_string
= make_string (string
, len
);
17255 props
= mode_line_string_face_prop
;
17256 else if (!NILP (mode_line_string_face
))
17258 Lisp_Object face
= Fplist_get (props
, Qface
);
17259 props
= Fcopy_sequence (props
);
17261 face
= mode_line_string_face
;
17263 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17264 props
= Fplist_put (props
, Qface
, face
);
17266 Fadd_text_properties (make_number (0), make_number (len
),
17267 props
, lisp_string
);
17271 len
= XFASTINT (Flength (lisp_string
));
17272 if (precision
> 0 && len
> precision
)
17275 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
17278 if (!NILP (mode_line_string_face
))
17282 props
= Ftext_properties_at (make_number (0), lisp_string
);
17283 face
= Fplist_get (props
, Qface
);
17285 face
= mode_line_string_face
;
17287 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17288 props
= Fcons (Qface
, Fcons (face
, Qnil
));
17290 lisp_string
= Fcopy_sequence (lisp_string
);
17293 Fadd_text_properties (make_number (0), make_number (len
),
17294 props
, lisp_string
);
17299 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17303 if (field_width
> len
)
17305 field_width
-= len
;
17306 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17308 Fadd_text_properties (make_number (0), make_number (field_width
),
17309 props
, lisp_string
);
17310 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17318 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17320 doc
: /* Format a string out of a mode line format specification.
17321 First arg FORMAT specifies the mode line format (see `mode-line-format'
17322 for details) to use.
17324 Optional second arg FACE specifies the face property to put
17325 on all characters for which no face is specified.
17326 The value t means whatever face the window's mode line currently uses
17327 \(either `mode-line' or `mode-line-inactive', depending).
17328 A value of nil means the default is no face property.
17329 If FACE is an integer, the value string has no text properties.
17331 Optional third and fourth args WINDOW and BUFFER specify the window
17332 and buffer to use as the context for the formatting (defaults
17333 are the selected window and the window's buffer). */)
17334 (format
, face
, window
, buffer
)
17335 Lisp_Object format
, face
, window
, buffer
;
17340 struct buffer
*old_buffer
= NULL
;
17342 int no_props
= INTEGERP (face
);
17343 int count
= SPECPDL_INDEX ();
17345 int string_start
= 0;
17348 window
= selected_window
;
17349 CHECK_WINDOW (window
);
17350 w
= XWINDOW (window
);
17353 buffer
= w
->buffer
;
17354 CHECK_BUFFER (buffer
);
17357 return empty_unibyte_string
;
17365 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
17366 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
17370 face_id
= DEFAULT_FACE_ID
;
17372 if (XBUFFER (buffer
) != current_buffer
)
17373 old_buffer
= current_buffer
;
17375 /* Save things including mode_line_proptrans_alist,
17376 and set that to nil so that we don't alter the outer value. */
17377 record_unwind_protect (unwind_format_mode_line
,
17378 format_mode_line_unwind_data (old_buffer
, 1));
17379 mode_line_proptrans_alist
= Qnil
;
17382 set_buffer_internal_1 (XBUFFER (buffer
));
17384 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17388 mode_line_target
= MODE_LINE_NOPROP
;
17389 mode_line_string_face_prop
= Qnil
;
17390 mode_line_string_list
= Qnil
;
17391 string_start
= MODE_LINE_NOPROP_LEN (0);
17395 mode_line_target
= MODE_LINE_STRING
;
17396 mode_line_string_list
= Qnil
;
17397 mode_line_string_face
= face
;
17398 mode_line_string_face_prop
17399 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
17402 push_kboard (FRAME_KBOARD (it
.f
));
17403 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17408 len
= MODE_LINE_NOPROP_LEN (string_start
);
17409 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
17413 mode_line_string_list
= Fnreverse (mode_line_string_list
);
17414 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
17415 empty_unibyte_string
);
17418 unbind_to (count
, Qnil
);
17422 /* Write a null-terminated, right justified decimal representation of
17423 the positive integer D to BUF using a minimal field width WIDTH. */
17426 pint2str (buf
, width
, d
)
17427 register char *buf
;
17428 register int width
;
17431 register char *p
= buf
;
17439 *p
++ = d
% 10 + '0';
17444 for (width
-= (int) (p
- buf
); width
> 0; --width
)
17455 /* Write a null-terminated, right justified decimal and "human
17456 readable" representation of the nonnegative integer D to BUF using
17457 a minimal field width WIDTH. D should be smaller than 999.5e24. */
17459 static const char power_letter
[] =
17473 pint2hrstr (buf
, width
, d
)
17478 /* We aim to represent the nonnegative integer D as
17479 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
17482 /* -1 means: do not use TENTHS. */
17486 /* Length of QUOTIENT.TENTHS as a string. */
17492 if (1000 <= quotient
)
17494 /* Scale to the appropriate EXPONENT. */
17497 remainder
= quotient
% 1000;
17501 while (1000 <= quotient
);
17503 /* Round to nearest and decide whether to use TENTHS or not. */
17506 tenths
= remainder
/ 100;
17507 if (50 <= remainder
% 100)
17514 if (quotient
== 10)
17522 if (500 <= remainder
)
17524 if (quotient
< 999)
17535 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
17536 if (tenths
== -1 && quotient
<= 99)
17543 p
= psuffix
= buf
+ max (width
, length
);
17545 /* Print EXPONENT. */
17547 *psuffix
++ = power_letter
[exponent
];
17550 /* Print TENTHS. */
17553 *--p
= '0' + tenths
;
17557 /* Print QUOTIENT. */
17560 int digit
= quotient
% 10;
17561 *--p
= '0' + digit
;
17563 while ((quotient
/= 10) != 0);
17565 /* Print leading spaces. */
17570 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
17571 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
17572 type of CODING_SYSTEM. Return updated pointer into BUF. */
17574 static unsigned char invalid_eol_type
[] = "(*invalid*)";
17577 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
17578 Lisp_Object coding_system
;
17579 register char *buf
;
17583 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
17584 const unsigned char *eol_str
;
17586 /* The EOL conversion we are using. */
17587 Lisp_Object eoltype
;
17589 val
= Fget (coding_system
, Qcoding_system
);
17592 if (!VECTORP (val
)) /* Not yet decided. */
17597 eoltype
= eol_mnemonic_undecided
;
17598 /* Don't mention EOL conversion if it isn't decided. */
17602 Lisp_Object eolvalue
;
17604 eolvalue
= Fget (coding_system
, Qeol_type
);
17607 *buf
++ = XFASTINT (AREF (val
, 1));
17611 /* The EOL conversion that is normal on this system. */
17613 if (NILP (eolvalue
)) /* Not yet decided. */
17614 eoltype
= eol_mnemonic_undecided
;
17615 else if (VECTORP (eolvalue
)) /* Not yet decided. */
17616 eoltype
= eol_mnemonic_undecided
;
17617 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
17618 eoltype
= (XFASTINT (eolvalue
) == 0
17619 ? eol_mnemonic_unix
17620 : (XFASTINT (eolvalue
) == 1
17621 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
17627 /* Mention the EOL conversion if it is not the usual one. */
17628 if (STRINGP (eoltype
))
17630 eol_str
= SDATA (eoltype
);
17631 eol_str_len
= SBYTES (eoltype
);
17633 else if (INTEGERP (eoltype
)
17634 && CHAR_VALID_P (XINT (eoltype
), 0))
17636 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
17637 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
17642 eol_str
= invalid_eol_type
;
17643 eol_str_len
= sizeof (invalid_eol_type
) - 1;
17645 bcopy (eol_str
, buf
, eol_str_len
);
17646 buf
+= eol_str_len
;
17652 /* Return a string for the output of a mode line %-spec for window W,
17653 generated by character C. PRECISION >= 0 means don't return a
17654 string longer than that value. FIELD_WIDTH > 0 means pad the
17655 string returned with spaces to that value. Return 1 in *MULTIBYTE
17656 if the result is multibyte text.
17658 Note we operate on the current buffer for most purposes,
17659 the exception being w->base_line_pos. */
17661 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
17664 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
17667 int field_width
, precision
;
17671 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17672 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
17673 struct buffer
*b
= current_buffer
;
17681 if (!NILP (b
->read_only
))
17683 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17688 /* This differs from %* only for a modified read-only buffer. */
17689 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17691 if (!NILP (b
->read_only
))
17696 /* This differs from %* in ignoring read-only-ness. */
17697 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17709 if (command_loop_level
> 5)
17711 p
= decode_mode_spec_buf
;
17712 for (i
= 0; i
< command_loop_level
; i
++)
17715 return decode_mode_spec_buf
;
17723 if (command_loop_level
> 5)
17725 p
= decode_mode_spec_buf
;
17726 for (i
= 0; i
< command_loop_level
; i
++)
17729 return decode_mode_spec_buf
;
17736 /* Let lots_of_dashes be a string of infinite length. */
17737 if (mode_line_target
== MODE_LINE_NOPROP
||
17738 mode_line_target
== MODE_LINE_STRING
)
17740 if (field_width
<= 0
17741 || field_width
> sizeof (lots_of_dashes
))
17743 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
17744 decode_mode_spec_buf
[i
] = '-';
17745 decode_mode_spec_buf
[i
] = '\0';
17746 return decode_mode_spec_buf
;
17749 return lots_of_dashes
;
17757 /* %c and %l are ignored in `frame-title-format'.
17758 (In redisplay_internal, the frame title is drawn _before_ the
17759 windows are updated, so the stuff which depends on actual
17760 window contents (such as %l) may fail to render properly, or
17761 even crash emacs.) */
17762 if (mode_line_target
== MODE_LINE_TITLE
)
17766 int col
= (int) current_column (); /* iftc */
17767 w
->column_number_displayed
= make_number (col
);
17768 pint2str (decode_mode_spec_buf
, field_width
, col
);
17769 return decode_mode_spec_buf
;
17773 #ifndef SYSTEM_MALLOC
17775 if (NILP (Vmemory_full
))
17778 return "!MEM FULL! ";
17785 /* %F displays the frame name. */
17786 if (!NILP (f
->title
))
17787 return (char *) SDATA (f
->title
);
17788 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
17789 return (char *) SDATA (f
->name
);
17798 int size
= ZV
- BEGV
;
17799 pint2str (decode_mode_spec_buf
, field_width
, size
);
17800 return decode_mode_spec_buf
;
17805 int size
= ZV
- BEGV
;
17806 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
17807 return decode_mode_spec_buf
;
17812 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
17813 int topline
, nlines
, junk
, height
;
17815 /* %c and %l are ignored in `frame-title-format'. */
17816 if (mode_line_target
== MODE_LINE_TITLE
)
17819 startpos
= XMARKER (w
->start
)->charpos
;
17820 startpos_byte
= marker_byte_position (w
->start
);
17821 height
= WINDOW_TOTAL_LINES (w
);
17823 /* If we decided that this buffer isn't suitable for line numbers,
17824 don't forget that too fast. */
17825 if (EQ (w
->base_line_pos
, w
->buffer
))
17827 /* But do forget it, if the window shows a different buffer now. */
17828 else if (BUFFERP (w
->base_line_pos
))
17829 w
->base_line_pos
= Qnil
;
17831 /* If the buffer is very big, don't waste time. */
17832 if (INTEGERP (Vline_number_display_limit
)
17833 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
17835 w
->base_line_pos
= Qnil
;
17836 w
->base_line_number
= Qnil
;
17840 if (!NILP (w
->base_line_number
)
17841 && !NILP (w
->base_line_pos
)
17842 && XFASTINT (w
->base_line_pos
) <= startpos
)
17844 line
= XFASTINT (w
->base_line_number
);
17845 linepos
= XFASTINT (w
->base_line_pos
);
17846 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
17851 linepos
= BUF_BEGV (b
);
17852 linepos_byte
= BUF_BEGV_BYTE (b
);
17855 /* Count lines from base line to window start position. */
17856 nlines
= display_count_lines (linepos
, linepos_byte
,
17860 topline
= nlines
+ line
;
17862 /* Determine a new base line, if the old one is too close
17863 or too far away, or if we did not have one.
17864 "Too close" means it's plausible a scroll-down would
17865 go back past it. */
17866 if (startpos
== BUF_BEGV (b
))
17868 w
->base_line_number
= make_number (topline
);
17869 w
->base_line_pos
= make_number (BUF_BEGV (b
));
17871 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
17872 || linepos
== BUF_BEGV (b
))
17874 int limit
= BUF_BEGV (b
);
17875 int limit_byte
= BUF_BEGV_BYTE (b
);
17877 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
17879 if (startpos
- distance
> limit
)
17881 limit
= startpos
- distance
;
17882 limit_byte
= CHAR_TO_BYTE (limit
);
17885 nlines
= display_count_lines (startpos
, startpos_byte
,
17887 - (height
* 2 + 30),
17889 /* If we couldn't find the lines we wanted within
17890 line_number_display_limit_width chars per line,
17891 give up on line numbers for this window. */
17892 if (position
== limit_byte
&& limit
== startpos
- distance
)
17894 w
->base_line_pos
= w
->buffer
;
17895 w
->base_line_number
= Qnil
;
17899 w
->base_line_number
= make_number (topline
- nlines
);
17900 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
17903 /* Now count lines from the start pos to point. */
17904 nlines
= display_count_lines (startpos
, startpos_byte
,
17905 PT_BYTE
, PT
, &junk
);
17907 /* Record that we did display the line number. */
17908 line_number_displayed
= 1;
17910 /* Make the string to show. */
17911 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
17912 return decode_mode_spec_buf
;
17915 char* p
= decode_mode_spec_buf
;
17916 int pad
= field_width
- 2;
17922 return decode_mode_spec_buf
;
17928 obj
= b
->mode_name
;
17932 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
17938 int pos
= marker_position (w
->start
);
17939 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17941 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
17943 if (pos
<= BUF_BEGV (b
))
17948 else if (pos
<= BUF_BEGV (b
))
17952 if (total
> 1000000)
17953 /* Do it differently for a large value, to avoid overflow. */
17954 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17956 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17957 /* We can't normally display a 3-digit number,
17958 so get us a 2-digit number that is close. */
17961 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17962 return decode_mode_spec_buf
;
17966 /* Display percentage of size above the bottom of the screen. */
17969 int toppos
= marker_position (w
->start
);
17970 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
17971 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17973 if (botpos
>= BUF_ZV (b
))
17975 if (toppos
<= BUF_BEGV (b
))
17982 if (total
> 1000000)
17983 /* Do it differently for a large value, to avoid overflow. */
17984 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17986 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17987 /* We can't normally display a 3-digit number,
17988 so get us a 2-digit number that is close. */
17991 if (toppos
<= BUF_BEGV (b
))
17992 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
17994 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17995 return decode_mode_spec_buf
;
18000 /* status of process */
18001 obj
= Fget_buffer_process (Fcurrent_buffer ());
18003 return "no process";
18004 #ifdef subprocesses
18005 obj
= Fsymbol_name (Fprocess_status (obj
));
18009 case 't': /* indicate TEXT or BINARY */
18010 #ifdef MODE_LINE_BINARY_TEXT
18011 return MODE_LINE_BINARY_TEXT (b
);
18017 /* coding-system (not including end-of-line format) */
18019 /* coding-system (including end-of-line type) */
18021 int eol_flag
= (c
== 'Z');
18022 char *p
= decode_mode_spec_buf
;
18024 if (! FRAME_WINDOW_P (f
))
18026 /* No need to mention EOL here--the terminal never needs
18027 to do EOL conversion. */
18028 p
= decode_mode_spec_coding (FRAME_KEYBOARD_CODING (f
)->symbol
, p
, 0);
18029 p
= decode_mode_spec_coding (FRAME_TERMINAL_CODING (f
)->symbol
, p
, 0);
18031 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
18034 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
18035 #ifdef subprocesses
18036 obj
= Fget_buffer_process (Fcurrent_buffer ());
18037 if (PROCESSP (obj
))
18039 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
18041 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
18044 #endif /* subprocesses */
18047 return decode_mode_spec_buf
;
18053 *multibyte
= STRING_MULTIBYTE (obj
);
18054 return (char *) SDATA (obj
);
18061 /* Count up to COUNT lines starting from START / START_BYTE.
18062 But don't go beyond LIMIT_BYTE.
18063 Return the number of lines thus found (always nonnegative).
18065 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
18068 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
18069 int start
, start_byte
, limit_byte
, count
;
18072 register unsigned char *cursor
;
18073 unsigned char *base
;
18075 register int ceiling
;
18076 register unsigned char *ceiling_addr
;
18077 int orig_count
= count
;
18079 /* If we are not in selective display mode,
18080 check only for newlines. */
18081 int selective_display
= (!NILP (current_buffer
->selective_display
)
18082 && !INTEGERP (current_buffer
->selective_display
));
18086 while (start_byte
< limit_byte
)
18088 ceiling
= BUFFER_CEILING_OF (start_byte
);
18089 ceiling
= min (limit_byte
- 1, ceiling
);
18090 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
18091 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
18094 if (selective_display
)
18095 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
18098 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
18101 if (cursor
!= ceiling_addr
)
18105 start_byte
+= cursor
- base
+ 1;
18106 *byte_pos_ptr
= start_byte
;
18110 if (++cursor
== ceiling_addr
)
18116 start_byte
+= cursor
- base
;
18121 while (start_byte
> limit_byte
)
18123 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
18124 ceiling
= max (limit_byte
, ceiling
);
18125 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
18126 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
18129 if (selective_display
)
18130 while (--cursor
!= ceiling_addr
18131 && *cursor
!= '\n' && *cursor
!= 015)
18134 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
18137 if (cursor
!= ceiling_addr
)
18141 start_byte
+= cursor
- base
+ 1;
18142 *byte_pos_ptr
= start_byte
;
18143 /* When scanning backwards, we should
18144 not count the newline posterior to which we stop. */
18145 return - orig_count
- 1;
18151 /* Here we add 1 to compensate for the last decrement
18152 of CURSOR, which took it past the valid range. */
18153 start_byte
+= cursor
- base
+ 1;
18157 *byte_pos_ptr
= limit_byte
;
18160 return - orig_count
+ count
;
18161 return orig_count
- count
;
18167 /***********************************************************************
18169 ***********************************************************************/
18171 /* Display a NUL-terminated string, starting with index START.
18173 If STRING is non-null, display that C string. Otherwise, the Lisp
18174 string LISP_STRING is displayed.
18176 If FACE_STRING is not nil, FACE_STRING_POS is a position in
18177 FACE_STRING. Display STRING or LISP_STRING with the face at
18178 FACE_STRING_POS in FACE_STRING:
18180 Display the string in the environment given by IT, but use the
18181 standard display table, temporarily.
18183 FIELD_WIDTH is the minimum number of output glyphs to produce.
18184 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18185 with spaces. If STRING has more characters, more than FIELD_WIDTH
18186 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
18188 PRECISION is the maximum number of characters to output from
18189 STRING. PRECISION < 0 means don't truncate the string.
18191 This is roughly equivalent to printf format specifiers:
18193 FIELD_WIDTH PRECISION PRINTF
18194 ----------------------------------------
18200 MULTIBYTE zero means do not display multibyte chars, > 0 means do
18201 display them, and < 0 means obey the current buffer's value of
18202 enable_multibyte_characters.
18204 Value is the number of columns displayed. */
18207 display_string (string
, lisp_string
, face_string
, face_string_pos
,
18208 start
, it
, field_width
, precision
, max_x
, multibyte
)
18209 unsigned char *string
;
18210 Lisp_Object lisp_string
;
18211 Lisp_Object face_string
;
18212 int face_string_pos
;
18215 int field_width
, precision
, max_x
;
18218 int hpos_at_start
= it
->hpos
;
18219 int saved_face_id
= it
->face_id
;
18220 struct glyph_row
*row
= it
->glyph_row
;
18222 /* Initialize the iterator IT for iteration over STRING beginning
18223 with index START. */
18224 reseat_to_string (it
, string
, lisp_string
, start
,
18225 precision
, field_width
, multibyte
);
18227 /* If displaying STRING, set up the face of the iterator
18228 from LISP_STRING, if that's given. */
18229 if (STRINGP (face_string
))
18235 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
18236 0, it
->region_beg_charpos
,
18237 it
->region_end_charpos
,
18238 &endptr
, it
->base_face_id
, 0);
18239 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18240 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
18243 /* Set max_x to the maximum allowed X position. Don't let it go
18244 beyond the right edge of the window. */
18246 max_x
= it
->last_visible_x
;
18248 max_x
= min (max_x
, it
->last_visible_x
);
18250 /* Skip over display elements that are not visible. because IT->w is
18252 if (it
->current_x
< it
->first_visible_x
)
18253 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
18254 MOVE_TO_POS
| MOVE_TO_X
);
18256 row
->ascent
= it
->max_ascent
;
18257 row
->height
= it
->max_ascent
+ it
->max_descent
;
18258 row
->phys_ascent
= it
->max_phys_ascent
;
18259 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18260 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18262 /* This condition is for the case that we are called with current_x
18263 past last_visible_x. */
18264 while (it
->current_x
< max_x
)
18266 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
18268 /* Get the next display element. */
18269 if (!get_next_display_element (it
))
18272 /* Produce glyphs. */
18273 x_before
= it
->current_x
;
18274 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18275 PRODUCE_GLYPHS (it
);
18277 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
18280 while (i
< nglyphs
)
18282 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18284 if (!it
->truncate_lines_p
18285 && x
+ glyph
->pixel_width
> max_x
)
18287 /* End of continued line or max_x reached. */
18288 if (CHAR_GLYPH_PADDING_P (*glyph
))
18290 /* A wide character is unbreakable. */
18291 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18292 it
->current_x
= x_before
;
18296 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18301 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
18303 /* Glyph is at least partially visible. */
18305 if (x
< it
->first_visible_x
)
18306 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18310 /* Glyph is off the left margin of the display area.
18311 Should not happen. */
18315 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18316 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18317 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18318 row
->phys_height
= max (row
->phys_height
,
18319 it
->max_phys_ascent
+ it
->max_phys_descent
);
18320 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18321 it
->max_extra_line_spacing
);
18322 x
+= glyph
->pixel_width
;
18326 /* Stop if max_x reached. */
18330 /* Stop at line ends. */
18331 if (ITERATOR_AT_END_OF_LINE_P (it
))
18333 it
->continuation_lines_width
= 0;
18337 set_iterator_to_next (it
, 1);
18339 /* Stop if truncating at the right edge. */
18340 if (it
->truncate_lines_p
18341 && it
->current_x
>= it
->last_visible_x
)
18343 /* Add truncation mark, but don't do it if the line is
18344 truncated at a padding space. */
18345 if (IT_CHARPOS (*it
) < it
->string_nchars
)
18347 if (!FRAME_WINDOW_P (it
->f
))
18351 if (it
->current_x
> it
->last_visible_x
)
18353 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18354 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18356 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18358 row
->used
[TEXT_AREA
] = i
;
18359 produce_special_glyphs (it
, IT_TRUNCATION
);
18362 produce_special_glyphs (it
, IT_TRUNCATION
);
18364 it
->glyph_row
->truncated_on_right_p
= 1;
18370 /* Maybe insert a truncation at the left. */
18371 if (it
->first_visible_x
18372 && IT_CHARPOS (*it
) > 0)
18374 if (!FRAME_WINDOW_P (it
->f
))
18375 insert_left_trunc_glyphs (it
);
18376 it
->glyph_row
->truncated_on_left_p
= 1;
18379 it
->face_id
= saved_face_id
;
18381 /* Value is number of columns displayed. */
18382 return it
->hpos
- hpos_at_start
;
18387 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
18388 appears as an element of LIST or as the car of an element of LIST.
18389 If PROPVAL is a list, compare each element against LIST in that
18390 way, and return 1/2 if any element of PROPVAL is found in LIST.
18391 Otherwise return 0. This function cannot quit.
18392 The return value is 2 if the text is invisible but with an ellipsis
18393 and 1 if it's invisible and without an ellipsis. */
18396 invisible_p (propval
, list
)
18397 register Lisp_Object propval
;
18400 register Lisp_Object tail
, proptail
;
18402 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18404 register Lisp_Object tem
;
18406 if (EQ (propval
, tem
))
18408 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
18409 return NILP (XCDR (tem
)) ? 1 : 2;
18412 if (CONSP (propval
))
18414 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
18416 Lisp_Object propelt
;
18417 propelt
= XCAR (proptail
);
18418 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18420 register Lisp_Object tem
;
18422 if (EQ (propelt
, tem
))
18424 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
18425 return NILP (XCDR (tem
)) ? 1 : 2;
18433 /* Calculate a width or height in pixels from a specification using
18434 the following elements:
18437 NUM - a (fractional) multiple of the default font width/height
18438 (NUM) - specifies exactly NUM pixels
18439 UNIT - a fixed number of pixels, see below.
18440 ELEMENT - size of a display element in pixels, see below.
18441 (NUM . SPEC) - equals NUM * SPEC
18442 (+ SPEC SPEC ...) - add pixel values
18443 (- SPEC SPEC ...) - subtract pixel values
18444 (- SPEC) - negate pixel value
18447 INT or FLOAT - a number constant
18448 SYMBOL - use symbol's (buffer local) variable binding.
18451 in - pixels per inch *)
18452 mm - pixels per 1/1000 meter *)
18453 cm - pixels per 1/100 meter *)
18454 width - width of current font in pixels.
18455 height - height of current font in pixels.
18457 *) using the ratio(s) defined in display-pixels-per-inch.
18461 left-fringe - left fringe width in pixels
18462 right-fringe - right fringe width in pixels
18464 left-margin - left margin width in pixels
18465 right-margin - right margin width in pixels
18467 scroll-bar - scroll-bar area width in pixels
18471 Pixels corresponding to 5 inches:
18474 Total width of non-text areas on left side of window (if scroll-bar is on left):
18475 '(space :width (+ left-fringe left-margin scroll-bar))
18477 Align to first text column (in header line):
18478 '(space :align-to 0)
18480 Align to middle of text area minus half the width of variable `my-image'
18481 containing a loaded image:
18482 '(space :align-to (0.5 . (- text my-image)))
18484 Width of left margin minus width of 1 character in the default font:
18485 '(space :width (- left-margin 1))
18487 Width of left margin minus width of 2 characters in the current font:
18488 '(space :width (- left-margin (2 . width)))
18490 Center 1 character over left-margin (in header line):
18491 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
18493 Different ways to express width of left fringe plus left margin minus one pixel:
18494 '(space :width (- (+ left-fringe left-margin) (1)))
18495 '(space :width (+ left-fringe left-margin (- (1))))
18496 '(space :width (+ left-fringe left-margin (-1)))
18500 #define NUMVAL(X) \
18501 ((INTEGERP (X) || FLOATP (X)) \
18506 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
18511 int width_p
, *align_to
;
18515 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
18516 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
18519 return OK_PIXELS (0);
18521 xassert (FRAME_LIVE_P (it
->f
));
18523 if (SYMBOLP (prop
))
18525 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18527 char *unit
= SDATA (SYMBOL_NAME (prop
));
18529 if (unit
[0] == 'i' && unit
[1] == 'n')
18531 else if (unit
[0] == 'm' && unit
[1] == 'm')
18533 else if (unit
[0] == 'c' && unit
[1] == 'm')
18540 #ifdef HAVE_WINDOW_SYSTEM
18541 if (FRAME_WINDOW_P (it
->f
)
18543 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
18544 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
18546 return OK_PIXELS (ppi
/ pixels
);
18549 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18550 || (CONSP (Vdisplay_pixels_per_inch
)
18552 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18553 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18555 return OK_PIXELS (ppi
/ pixels
);
18561 #ifdef HAVE_WINDOW_SYSTEM
18562 if (EQ (prop
, Qheight
))
18563 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
18564 if (EQ (prop
, Qwidth
))
18565 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
18567 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
18568 return OK_PIXELS (1);
18571 if (EQ (prop
, Qtext
))
18572 return OK_PIXELS (width_p
18573 ? window_box_width (it
->w
, TEXT_AREA
)
18574 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
18576 if (align_to
&& *align_to
< 0)
18579 if (EQ (prop
, Qleft
))
18580 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
18581 if (EQ (prop
, Qright
))
18582 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
18583 if (EQ (prop
, Qcenter
))
18584 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
18585 + window_box_width (it
->w
, TEXT_AREA
) / 2);
18586 if (EQ (prop
, Qleft_fringe
))
18587 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18588 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
18589 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
18590 if (EQ (prop
, Qright_fringe
))
18591 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18592 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18593 : window_box_right_offset (it
->w
, TEXT_AREA
));
18594 if (EQ (prop
, Qleft_margin
))
18595 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
18596 if (EQ (prop
, Qright_margin
))
18597 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
18598 if (EQ (prop
, Qscroll_bar
))
18599 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18601 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18602 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18603 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18608 if (EQ (prop
, Qleft_fringe
))
18609 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18610 if (EQ (prop
, Qright_fringe
))
18611 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18612 if (EQ (prop
, Qleft_margin
))
18613 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18614 if (EQ (prop
, Qright_margin
))
18615 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18616 if (EQ (prop
, Qscroll_bar
))
18617 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18620 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18623 if (INTEGERP (prop
) || FLOATP (prop
))
18625 int base_unit
= (width_p
18626 ? FRAME_COLUMN_WIDTH (it
->f
)
18627 : FRAME_LINE_HEIGHT (it
->f
));
18628 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18633 Lisp_Object car
= XCAR (prop
);
18634 Lisp_Object cdr
= XCDR (prop
);
18638 #ifdef HAVE_WINDOW_SYSTEM
18639 if (FRAME_WINDOW_P (it
->f
)
18640 && valid_image_p (prop
))
18642 int id
= lookup_image (it
->f
, prop
);
18643 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
18645 return OK_PIXELS (width_p
? img
->width
: img
->height
);
18648 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18654 while (CONSP (cdr
))
18656 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
18657 font
, width_p
, align_to
))
18660 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18665 if (EQ (car
, Qminus
))
18667 return OK_PIXELS (pixels
);
18670 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18673 if (INTEGERP (car
) || FLOATP (car
))
18676 pixels
= XFLOATINT (car
);
18678 return OK_PIXELS (pixels
);
18679 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
18680 font
, width_p
, align_to
))
18681 return OK_PIXELS (pixels
* fact
);
18692 /***********************************************************************
18694 ***********************************************************************/
18696 #ifdef HAVE_WINDOW_SYSTEM
18701 dump_glyph_string (s
)
18702 struct glyph_string
*s
;
18704 fprintf (stderr
, "glyph string\n");
18705 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
18706 s
->x
, s
->y
, s
->width
, s
->height
);
18707 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
18708 fprintf (stderr
, " hl = %d\n", s
->hl
);
18709 fprintf (stderr
, " left overhang = %d, right = %d\n",
18710 s
->left_overhang
, s
->right_overhang
);
18711 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
18712 fprintf (stderr
, " extends to end of line = %d\n",
18713 s
->extends_to_end_of_line_p
);
18714 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
18715 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
18718 #endif /* GLYPH_DEBUG */
18720 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
18721 of XChar2b structures for S; it can't be allocated in
18722 init_glyph_string because it must be allocated via `alloca'. W
18723 is the window on which S is drawn. ROW and AREA are the glyph row
18724 and area within the row from which S is constructed. START is the
18725 index of the first glyph structure covered by S. HL is a
18726 face-override for drawing S. */
18729 #define OPTIONAL_HDC(hdc) hdc,
18730 #define DECLARE_HDC(hdc) HDC hdc;
18731 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
18732 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
18735 #ifndef OPTIONAL_HDC
18736 #define OPTIONAL_HDC(hdc)
18737 #define DECLARE_HDC(hdc)
18738 #define ALLOCATE_HDC(hdc, f)
18739 #define RELEASE_HDC(hdc, f)
18743 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
18744 struct glyph_string
*s
;
18748 struct glyph_row
*row
;
18749 enum glyph_row_area area
;
18751 enum draw_glyphs_face hl
;
18753 bzero (s
, sizeof *s
);
18755 s
->f
= XFRAME (w
->frame
);
18759 s
->display
= FRAME_X_DISPLAY (s
->f
);
18760 s
->window
= FRAME_X_WINDOW (s
->f
);
18761 s
->char2b
= char2b
;
18765 s
->first_glyph
= row
->glyphs
[area
] + start
;
18766 s
->height
= row
->height
;
18767 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
18769 /* Display the internal border below the tool-bar window. */
18770 if (WINDOWP (s
->f
->tool_bar_window
)
18771 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
18772 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
18774 s
->ybase
= s
->y
+ row
->ascent
;
18778 /* Append the list of glyph strings with head H and tail T to the list
18779 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
18782 append_glyph_string_lists (head
, tail
, h
, t
)
18783 struct glyph_string
**head
, **tail
;
18784 struct glyph_string
*h
, *t
;
18798 /* Prepend the list of glyph strings with head H and tail T to the
18799 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
18803 prepend_glyph_string_lists (head
, tail
, h
, t
)
18804 struct glyph_string
**head
, **tail
;
18805 struct glyph_string
*h
, *t
;
18819 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
18820 Set *HEAD and *TAIL to the resulting list. */
18823 append_glyph_string (head
, tail
, s
)
18824 struct glyph_string
**head
, **tail
;
18825 struct glyph_string
*s
;
18827 s
->next
= s
->prev
= NULL
;
18828 append_glyph_string_lists (head
, tail
, s
, s
);
18832 /* Get face and two-byte form of character glyph GLYPH on frame F.
18833 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
18834 a pointer to a realized face that is ready for display. */
18836 static INLINE
struct face
*
18837 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
18839 struct glyph
*glyph
;
18845 xassert (glyph
->type
== CHAR_GLYPH
);
18846 face
= FACE_FROM_ID (f
, glyph
->face_id
);
18851 if (!glyph
->multibyte_p
)
18853 /* Unibyte case. We don't have to encode, but we have to make
18854 sure to use a face suitable for unibyte. */
18855 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18857 else if (glyph
->u
.ch
< 128)
18859 /* Case of ASCII in a face known to fit ASCII. */
18860 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18864 int c1
, c2
, charset
;
18866 /* Split characters into bytes. If c2 is -1 afterwards, C is
18867 really a one-byte character so that byte1 is zero. */
18868 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
18870 STORE_XCHAR2B (char2b
, c1
, c2
);
18872 STORE_XCHAR2B (char2b
, 0, c1
);
18874 /* Maybe encode the character in *CHAR2B. */
18875 if (charset
!= CHARSET_ASCII
)
18877 struct font_info
*font_info
18878 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18881 = FRAME_RIF (f
)->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
18885 /* Make sure X resources of the face are allocated. */
18886 xassert (face
!= NULL
);
18887 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18892 /* Fill glyph string S with composition components specified by S->cmp.
18894 FACES is an array of faces for all components of this composition.
18895 S->gidx is the index of the first component for S.
18897 OVERLAPS non-zero means S should draw the foreground only, and use
18898 its physical height for clipping. See also draw_glyphs.
18900 Value is the index of a component not in S. */
18903 fill_composite_glyph_string (s
, faces
, overlaps
)
18904 struct glyph_string
*s
;
18905 struct face
**faces
;
18912 s
->for_overlaps
= overlaps
;
18914 s
->face
= faces
[s
->gidx
];
18915 s
->font
= s
->face
->font
;
18916 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18918 /* For all glyphs of this composition, starting at the offset
18919 S->gidx, until we reach the end of the definition or encounter a
18920 glyph that requires the different face, add it to S. */
18922 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
18925 /* All glyph strings for the same composition has the same width,
18926 i.e. the width set for the first component of the composition. */
18928 s
->width
= s
->first_glyph
->pixel_width
;
18930 /* If the specified font could not be loaded, use the frame's
18931 default font, but record the fact that we couldn't load it in
18932 the glyph string so that we can draw rectangles for the
18933 characters of the glyph string. */
18934 if (s
->font
== NULL
)
18936 s
->font_not_found_p
= 1;
18937 s
->font
= FRAME_FONT (s
->f
);
18940 /* Adjust base line for subscript/superscript text. */
18941 s
->ybase
+= s
->first_glyph
->voffset
;
18943 xassert (s
->face
&& s
->face
->gc
);
18945 /* This glyph string must always be drawn with 16-bit functions. */
18948 return s
->gidx
+ s
->nchars
;
18952 /* Fill glyph string S from a sequence of character glyphs.
18954 FACE_ID is the face id of the string. START is the index of the
18955 first glyph to consider, END is the index of the last + 1.
18956 OVERLAPS non-zero means S should draw the foreground only, and use
18957 its physical height for clipping. See also draw_glyphs.
18959 Value is the index of the first glyph not in S. */
18962 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
18963 struct glyph_string
*s
;
18965 int start
, end
, overlaps
;
18967 struct glyph
*glyph
, *last
;
18969 int glyph_not_available_p
;
18971 xassert (s
->f
== XFRAME (s
->w
->frame
));
18972 xassert (s
->nchars
== 0);
18973 xassert (start
>= 0 && end
> start
);
18975 s
->for_overlaps
= overlaps
,
18976 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18977 last
= s
->row
->glyphs
[s
->area
] + end
;
18978 voffset
= glyph
->voffset
;
18980 glyph_not_available_p
= glyph
->glyph_not_available_p
;
18982 while (glyph
< last
18983 && glyph
->type
== CHAR_GLYPH
18984 && glyph
->voffset
== voffset
18985 /* Same face id implies same font, nowadays. */
18986 && glyph
->face_id
== face_id
18987 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
18991 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
18992 s
->char2b
+ s
->nchars
,
18994 s
->two_byte_p
= two_byte_p
;
18996 xassert (s
->nchars
<= end
- start
);
18997 s
->width
+= glyph
->pixel_width
;
19001 s
->font
= s
->face
->font
;
19002 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
19004 /* If the specified font could not be loaded, use the frame's font,
19005 but record the fact that we couldn't load it in
19006 S->font_not_found_p so that we can draw rectangles for the
19007 characters of the glyph string. */
19008 if (s
->font
== NULL
|| glyph_not_available_p
)
19010 s
->font_not_found_p
= 1;
19011 s
->font
= FRAME_FONT (s
->f
);
19014 /* Adjust base line for subscript/superscript text. */
19015 s
->ybase
+= voffset
;
19017 xassert (s
->face
&& s
->face
->gc
);
19018 return glyph
- s
->row
->glyphs
[s
->area
];
19022 /* Fill glyph string S from image glyph S->first_glyph. */
19025 fill_image_glyph_string (s
)
19026 struct glyph_string
*s
;
19028 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
19029 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
19031 s
->slice
= s
->first_glyph
->slice
;
19032 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
19033 s
->font
= s
->face
->font
;
19034 s
->width
= s
->first_glyph
->pixel_width
;
19036 /* Adjust base line for subscript/superscript text. */
19037 s
->ybase
+= s
->first_glyph
->voffset
;
19041 /* Fill glyph string S from a sequence of stretch glyphs.
19043 ROW is the glyph row in which the glyphs are found, AREA is the
19044 area within the row. START is the index of the first glyph to
19045 consider, END is the index of the last + 1.
19047 Value is the index of the first glyph not in S. */
19050 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
19051 struct glyph_string
*s
;
19052 struct glyph_row
*row
;
19053 enum glyph_row_area area
;
19056 struct glyph
*glyph
, *last
;
19057 int voffset
, face_id
;
19059 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
19061 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19062 last
= s
->row
->glyphs
[s
->area
] + end
;
19063 face_id
= glyph
->face_id
;
19064 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19065 s
->font
= s
->face
->font
;
19066 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
19067 s
->width
= glyph
->pixel_width
;
19069 voffset
= glyph
->voffset
;
19073 && glyph
->type
== STRETCH_GLYPH
19074 && glyph
->voffset
== voffset
19075 && glyph
->face_id
== face_id
);
19077 s
->width
+= glyph
->pixel_width
;
19079 /* Adjust base line for subscript/superscript text. */
19080 s
->ybase
+= voffset
;
19082 /* The case that face->gc == 0 is handled when drawing the glyph
19083 string by calling PREPARE_FACE_FOR_DISPLAY. */
19085 return glyph
- s
->row
->glyphs
[s
->area
];
19090 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
19091 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
19092 assumed to be zero. */
19095 x_get_glyph_overhangs (glyph
, f
, left
, right
)
19096 struct glyph
*glyph
;
19100 *left
= *right
= 0;
19102 if (glyph
->type
== CHAR_GLYPH
)
19106 struct font_info
*font_info
;
19110 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
19112 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
19113 if (font
/* ++KFS: Should this be font_info ? */
19114 && (pcm
= FRAME_RIF (f
)->per_char_metric (font
, &char2b
, glyph
->font_type
)))
19116 if (pcm
->rbearing
> pcm
->width
)
19117 *right
= pcm
->rbearing
- pcm
->width
;
19118 if (pcm
->lbearing
< 0)
19119 *left
= -pcm
->lbearing
;
19125 /* Return the index of the first glyph preceding glyph string S that
19126 is overwritten by S because of S's left overhang. Value is -1
19127 if no glyphs are overwritten. */
19130 left_overwritten (s
)
19131 struct glyph_string
*s
;
19135 if (s
->left_overhang
)
19138 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19139 int first
= s
->first_glyph
- glyphs
;
19141 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
19142 x
-= glyphs
[i
].pixel_width
;
19153 /* Return the index of the first glyph preceding glyph string S that
19154 is overwriting S because of its right overhang. Value is -1 if no
19155 glyph in front of S overwrites S. */
19158 left_overwriting (s
)
19159 struct glyph_string
*s
;
19162 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19163 int first
= s
->first_glyph
- glyphs
;
19167 for (i
= first
- 1; i
>= 0; --i
)
19170 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19173 x
-= glyphs
[i
].pixel_width
;
19180 /* Return the index of the last glyph following glyph string S that is
19181 not overwritten by S because of S's right overhang. Value is -1 if
19182 no such glyph is found. */
19185 right_overwritten (s
)
19186 struct glyph_string
*s
;
19190 if (s
->right_overhang
)
19193 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19194 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19195 int end
= s
->row
->used
[s
->area
];
19197 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
19198 x
+= glyphs
[i
].pixel_width
;
19207 /* Return the index of the last glyph following glyph string S that
19208 overwrites S because of its left overhang. Value is negative
19209 if no such glyph is found. */
19212 right_overwriting (s
)
19213 struct glyph_string
*s
;
19216 int end
= s
->row
->used
[s
->area
];
19217 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19218 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19222 for (i
= first
; i
< end
; ++i
)
19225 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19228 x
+= glyphs
[i
].pixel_width
;
19235 /* Get face and two-byte form of character C in face FACE_ID on frame
19236 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19237 means we want to display multibyte text. DISPLAY_P non-zero means
19238 make sure that X resources for the face returned are allocated.
19239 Value is a pointer to a realized face that is ready for display if
19240 DISPLAY_P is non-zero. */
19242 static INLINE
struct face
*
19243 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
19247 int multibyte_p
, display_p
;
19249 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19253 /* Unibyte case. We don't have to encode, but we have to make
19254 sure to use a face suitable for unibyte. */
19255 STORE_XCHAR2B (char2b
, 0, c
);
19256 face_id
= FACE_FOR_CHAR (f
, face
, c
);
19257 face
= FACE_FROM_ID (f
, face_id
);
19261 /* Case of ASCII in a face known to fit ASCII. */
19262 STORE_XCHAR2B (char2b
, 0, c
);
19266 int c1
, c2
, charset
;
19268 /* Split characters into bytes. If c2 is -1 afterwards, C is
19269 really a one-byte character so that byte1 is zero. */
19270 SPLIT_CHAR (c
, charset
, c1
, c2
);
19272 STORE_XCHAR2B (char2b
, c1
, c2
);
19274 STORE_XCHAR2B (char2b
, 0, c1
);
19276 /* Maybe encode the character in *CHAR2B. */
19277 if (face
->font
!= NULL
)
19279 struct font_info
*font_info
19280 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
19282 FRAME_RIF (f
)->encode_char (c
, char2b
, font_info
, 0);
19286 /* Make sure X resources of the face are allocated. */
19287 #ifdef HAVE_X_WINDOWS
19291 xassert (face
!= NULL
);
19292 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19299 /* Set background width of glyph string S. START is the index of the
19300 first glyph following S. LAST_X is the right-most x-position + 1
19301 in the drawing area. */
19304 set_glyph_string_background_width (s
, start
, last_x
)
19305 struct glyph_string
*s
;
19309 /* If the face of this glyph string has to be drawn to the end of
19310 the drawing area, set S->extends_to_end_of_line_p. */
19312 if (start
== s
->row
->used
[s
->area
]
19313 && s
->area
== TEXT_AREA
19314 && ((s
->row
->fill_line_p
19315 && (s
->hl
== DRAW_NORMAL_TEXT
19316 || s
->hl
== DRAW_IMAGE_RAISED
19317 || s
->hl
== DRAW_IMAGE_SUNKEN
))
19318 || s
->hl
== DRAW_MOUSE_FACE
))
19319 s
->extends_to_end_of_line_p
= 1;
19321 /* If S extends its face to the end of the line, set its
19322 background_width to the distance to the right edge of the drawing
19324 if (s
->extends_to_end_of_line_p
)
19325 s
->background_width
= last_x
- s
->x
+ 1;
19327 s
->background_width
= s
->width
;
19331 /* Compute overhangs and x-positions for glyph string S and its
19332 predecessors, or successors. X is the starting x-position for S.
19333 BACKWARD_P non-zero means process predecessors. */
19336 compute_overhangs_and_x (s
, x
, backward_p
)
19337 struct glyph_string
*s
;
19345 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
19346 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
19356 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
19357 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
19367 /* The following macros are only called from draw_glyphs below.
19368 They reference the following parameters of that function directly:
19369 `w', `row', `area', and `overlap_p'
19370 as well as the following local variables:
19371 `s', `f', and `hdc' (in W32) */
19374 /* On W32, silently add local `hdc' variable to argument list of
19375 init_glyph_string. */
19376 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19377 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
19379 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19380 init_glyph_string (s, char2b, w, row, area, start, hl)
19383 /* Add a glyph string for a stretch glyph to the list of strings
19384 between HEAD and TAIL. START is the index of the stretch glyph in
19385 row area AREA of glyph row ROW. END is the index of the last glyph
19386 in that glyph row area. X is the current output position assigned
19387 to the new glyph string constructed. HL overrides that face of the
19388 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19389 is the right-most x-position of the drawing area. */
19391 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
19392 and below -- keep them on one line. */
19393 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19396 s = (struct glyph_string *) alloca (sizeof *s); \
19397 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19398 START = fill_stretch_glyph_string (s, row, area, START, END); \
19399 append_glyph_string (&HEAD, &TAIL, s); \
19405 /* Add a glyph string for an image glyph to the list of strings
19406 between HEAD and TAIL. START is the index of the image glyph in
19407 row area AREA of glyph row ROW. END is the index of the last glyph
19408 in that glyph row area. X is the current output position assigned
19409 to the new glyph string constructed. HL overrides that face of the
19410 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19411 is the right-most x-position of the drawing area. */
19413 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19416 s = (struct glyph_string *) alloca (sizeof *s); \
19417 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19418 fill_image_glyph_string (s); \
19419 append_glyph_string (&HEAD, &TAIL, s); \
19426 /* Add a glyph string for a sequence of character glyphs to the list
19427 of strings between HEAD and TAIL. START is the index of the first
19428 glyph in row area AREA of glyph row ROW that is part of the new
19429 glyph string. END is the index of the last glyph in that glyph row
19430 area. X is the current output position assigned to the new glyph
19431 string constructed. HL overrides that face of the glyph; e.g. it
19432 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
19433 right-most x-position of the drawing area. */
19435 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19441 c = (row)->glyphs[area][START].u.ch; \
19442 face_id = (row)->glyphs[area][START].face_id; \
19444 s = (struct glyph_string *) alloca (sizeof *s); \
19445 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
19446 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
19447 append_glyph_string (&HEAD, &TAIL, s); \
19449 START = fill_glyph_string (s, face_id, START, END, overlaps); \
19454 /* Add a glyph string for a composite sequence to the list of strings
19455 between HEAD and TAIL. START is the index of the first glyph in
19456 row area AREA of glyph row ROW that is part of the new glyph
19457 string. END is the index of the last glyph in that glyph row area.
19458 X is the current output position assigned to the new glyph string
19459 constructed. HL overrides that face of the glyph; e.g. it is
19460 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
19461 x-position of the drawing area. */
19463 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19465 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
19466 int face_id = (row)->glyphs[area][START].face_id; \
19467 struct face *base_face = FACE_FROM_ID (f, face_id); \
19468 struct composition *cmp = composition_table[cmp_id]; \
19469 int glyph_len = cmp->glyph_len; \
19471 struct face **faces; \
19472 struct glyph_string *first_s = NULL; \
19475 base_face = base_face->ascii_face; \
19476 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
19477 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
19478 /* At first, fill in `char2b' and `faces'. */ \
19479 for (n = 0; n < glyph_len; n++) \
19481 int c = COMPOSITION_GLYPH (cmp, n); \
19482 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
19483 faces[n] = FACE_FROM_ID (f, this_face_id); \
19484 get_char_face_and_encoding (f, c, this_face_id, \
19485 char2b + n, 1, 1); \
19488 /* Make glyph_strings for each glyph sequence that is drawable by \
19489 the same face, and append them to HEAD/TAIL. */ \
19490 for (n = 0; n < cmp->glyph_len;) \
19492 s = (struct glyph_string *) alloca (sizeof *s); \
19493 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
19494 append_glyph_string (&(HEAD), &(TAIL), s); \
19502 n = fill_composite_glyph_string (s, faces, overlaps); \
19510 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
19511 of AREA of glyph row ROW on window W between indices START and END.
19512 HL overrides the face for drawing glyph strings, e.g. it is
19513 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
19514 x-positions of the drawing area.
19516 This is an ugly monster macro construct because we must use alloca
19517 to allocate glyph strings (because draw_glyphs can be called
19518 asynchronously). */
19520 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19523 HEAD = TAIL = NULL; \
19524 while (START < END) \
19526 struct glyph *first_glyph = (row)->glyphs[area] + START; \
19527 switch (first_glyph->type) \
19530 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
19534 case COMPOSITE_GLYPH: \
19535 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
19539 case STRETCH_GLYPH: \
19540 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
19544 case IMAGE_GLYPH: \
19545 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
19553 set_glyph_string_background_width (s, START, LAST_X); \
19560 /* Draw glyphs between START and END in AREA of ROW on window W,
19561 starting at x-position X. X is relative to AREA in W. HL is a
19562 face-override with the following meaning:
19564 DRAW_NORMAL_TEXT draw normally
19565 DRAW_CURSOR draw in cursor face
19566 DRAW_MOUSE_FACE draw in mouse face.
19567 DRAW_INVERSE_VIDEO draw in mode line face
19568 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
19569 DRAW_IMAGE_RAISED draw an image with a raised relief around it
19571 If OVERLAPS is non-zero, draw only the foreground of characters and
19572 clip to the physical height of ROW. Non-zero value also defines
19573 the overlapping part to be drawn:
19575 OVERLAPS_PRED overlap with preceding rows
19576 OVERLAPS_SUCC overlap with succeeding rows
19577 OVERLAPS_BOTH overlap with both preceding/succeeding rows
19578 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
19580 Value is the x-position reached, relative to AREA of W. */
19583 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
19586 struct glyph_row
*row
;
19587 enum glyph_row_area area
;
19589 enum draw_glyphs_face hl
;
19592 struct glyph_string
*head
, *tail
;
19593 struct glyph_string
*s
;
19594 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
19595 int last_x
, area_width
;
19598 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19601 ALLOCATE_HDC (hdc
, f
);
19603 /* Let's rather be paranoid than getting a SEGV. */
19604 end
= min (end
, row
->used
[area
]);
19605 start
= max (0, start
);
19606 start
= min (end
, start
);
19608 /* Translate X to frame coordinates. Set last_x to the right
19609 end of the drawing area. */
19610 if (row
->full_width_p
)
19612 /* X is relative to the left edge of W, without scroll bars
19614 x
+= WINDOW_LEFT_EDGE_X (w
);
19615 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
19619 int area_left
= window_box_left (w
, area
);
19621 area_width
= window_box_width (w
, area
);
19622 last_x
= area_left
+ area_width
;
19625 /* Build a doubly-linked list of glyph_string structures between
19626 head and tail from what we have to draw. Note that the macro
19627 BUILD_GLYPH_STRINGS will modify its start parameter. That's
19628 the reason we use a separate variable `i'. */
19630 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
19632 x_reached
= tail
->x
+ tail
->background_width
;
19636 /* If there are any glyphs with lbearing < 0 or rbearing > width in
19637 the row, redraw some glyphs in front or following the glyph
19638 strings built above. */
19639 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
19642 struct glyph_string
*h
, *t
;
19644 /* Compute overhangs for all glyph strings. */
19645 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
19646 for (s
= head
; s
; s
= s
->next
)
19647 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
19649 /* Prepend glyph strings for glyphs in front of the first glyph
19650 string that are overwritten because of the first glyph
19651 string's left overhang. The background of all strings
19652 prepended must be drawn because the first glyph string
19654 i
= left_overwritten (head
);
19658 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
19659 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19661 compute_overhangs_and_x (t
, head
->x
, 1);
19662 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19666 /* Prepend glyph strings for glyphs in front of the first glyph
19667 string that overwrite that glyph string because of their
19668 right overhang. For these strings, only the foreground must
19669 be drawn, because it draws over the glyph string at `head'.
19670 The background must not be drawn because this would overwrite
19671 right overhangs of preceding glyphs for which no glyph
19673 i
= left_overwriting (head
);
19677 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
19678 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19679 for (s
= h
; s
; s
= s
->next
)
19680 s
->background_filled_p
= 1;
19681 compute_overhangs_and_x (t
, head
->x
, 1);
19682 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19685 /* Append glyphs strings for glyphs following the last glyph
19686 string tail that are overwritten by tail. The background of
19687 these strings has to be drawn because tail's foreground draws
19689 i
= right_overwritten (tail
);
19692 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19693 DRAW_NORMAL_TEXT
, x
, last_x
);
19694 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19695 append_glyph_string_lists (&head
, &tail
, h
, t
);
19699 /* Append glyph strings for glyphs following the last glyph
19700 string tail that overwrite tail. The foreground of such
19701 glyphs has to be drawn because it writes into the background
19702 of tail. The background must not be drawn because it could
19703 paint over the foreground of following glyphs. */
19704 i
= right_overwriting (tail
);
19708 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19709 DRAW_NORMAL_TEXT
, x
, last_x
);
19710 for (s
= h
; s
; s
= s
->next
)
19711 s
->background_filled_p
= 1;
19712 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19713 append_glyph_string_lists (&head
, &tail
, h
, t
);
19715 if (clip_head
|| clip_tail
)
19716 for (s
= head
; s
; s
= s
->next
)
19718 s
->clip_head
= clip_head
;
19719 s
->clip_tail
= clip_tail
;
19723 /* Draw all strings. */
19724 for (s
= head
; s
; s
= s
->next
)
19725 FRAME_RIF (f
)->draw_glyph_string (s
);
19727 if (area
== TEXT_AREA
19728 && !row
->full_width_p
19729 /* When drawing overlapping rows, only the glyph strings'
19730 foreground is drawn, which doesn't erase a cursor
19734 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
19735 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
19736 : (tail
? tail
->x
+ tail
->background_width
: x
));
19738 int text_left
= window_box_left (w
, TEXT_AREA
);
19742 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
19743 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
19746 /* Value is the x-position up to which drawn, relative to AREA of W.
19747 This doesn't include parts drawn because of overhangs. */
19748 if (row
->full_width_p
)
19749 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
19751 x_reached
-= window_box_left (w
, area
);
19753 RELEASE_HDC (hdc
, f
);
19758 /* Expand row matrix if too narrow. Don't expand if area
19761 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
19763 if (!fonts_changed_p \
19764 && (it->glyph_row->glyphs[area] \
19765 < it->glyph_row->glyphs[area + 1])) \
19767 it->w->ncols_scale_factor++; \
19768 fonts_changed_p = 1; \
19772 /* Store one glyph for IT->char_to_display in IT->glyph_row.
19773 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19779 struct glyph
*glyph
;
19780 enum glyph_row_area area
= it
->area
;
19782 xassert (it
->glyph_row
);
19783 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
19785 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19786 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19788 glyph
->charpos
= CHARPOS (it
->position
);
19789 glyph
->object
= it
->object
;
19790 glyph
->pixel_width
= it
->pixel_width
;
19791 glyph
->ascent
= it
->ascent
;
19792 glyph
->descent
= it
->descent
;
19793 glyph
->voffset
= it
->voffset
;
19794 glyph
->type
= CHAR_GLYPH
;
19795 glyph
->multibyte_p
= it
->multibyte_p
;
19796 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19797 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19798 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19799 || it
->phys_descent
> it
->descent
);
19800 glyph
->padding_p
= 0;
19801 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
19802 glyph
->face_id
= it
->face_id
;
19803 glyph
->u
.ch
= it
->char_to_display
;
19804 glyph
->slice
= null_glyph_slice
;
19805 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19806 ++it
->glyph_row
->used
[area
];
19809 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19812 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
19813 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19816 append_composite_glyph (it
)
19819 struct glyph
*glyph
;
19820 enum glyph_row_area area
= it
->area
;
19822 xassert (it
->glyph_row
);
19824 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19825 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19827 glyph
->charpos
= CHARPOS (it
->position
);
19828 glyph
->object
= it
->object
;
19829 glyph
->pixel_width
= it
->pixel_width
;
19830 glyph
->ascent
= it
->ascent
;
19831 glyph
->descent
= it
->descent
;
19832 glyph
->voffset
= it
->voffset
;
19833 glyph
->type
= COMPOSITE_GLYPH
;
19834 glyph
->multibyte_p
= it
->multibyte_p
;
19835 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19836 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19837 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19838 || it
->phys_descent
> it
->descent
);
19839 glyph
->padding_p
= 0;
19840 glyph
->glyph_not_available_p
= 0;
19841 glyph
->face_id
= it
->face_id
;
19842 glyph
->u
.cmp_id
= it
->cmp_id
;
19843 glyph
->slice
= null_glyph_slice
;
19844 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19845 ++it
->glyph_row
->used
[area
];
19848 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19852 /* Change IT->ascent and IT->height according to the setting of
19856 take_vertical_position_into_account (it
)
19861 if (it
->voffset
< 0)
19862 /* Increase the ascent so that we can display the text higher
19864 it
->ascent
-= it
->voffset
;
19866 /* Increase the descent so that we can display the text lower
19868 it
->descent
+= it
->voffset
;
19873 /* Produce glyphs/get display metrics for the image IT is loaded with.
19874 See the description of struct display_iterator in dispextern.h for
19875 an overview of struct display_iterator. */
19878 produce_image_glyph (it
)
19883 int glyph_ascent
, crop
;
19884 struct glyph_slice slice
;
19886 xassert (it
->what
== IT_IMAGE
);
19888 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19890 /* Make sure X resources of the face is loaded. */
19891 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19893 if (it
->image_id
< 0)
19895 /* Fringe bitmap. */
19896 it
->ascent
= it
->phys_ascent
= 0;
19897 it
->descent
= it
->phys_descent
= 0;
19898 it
->pixel_width
= 0;
19903 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
19905 /* Make sure X resources of the image is loaded. */
19906 prepare_image_for_display (it
->f
, img
);
19908 slice
.x
= slice
.y
= 0;
19909 slice
.width
= img
->width
;
19910 slice
.height
= img
->height
;
19912 if (INTEGERP (it
->slice
.x
))
19913 slice
.x
= XINT (it
->slice
.x
);
19914 else if (FLOATP (it
->slice
.x
))
19915 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
19917 if (INTEGERP (it
->slice
.y
))
19918 slice
.y
= XINT (it
->slice
.y
);
19919 else if (FLOATP (it
->slice
.y
))
19920 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
19922 if (INTEGERP (it
->slice
.width
))
19923 slice
.width
= XINT (it
->slice
.width
);
19924 else if (FLOATP (it
->slice
.width
))
19925 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
19927 if (INTEGERP (it
->slice
.height
))
19928 slice
.height
= XINT (it
->slice
.height
);
19929 else if (FLOATP (it
->slice
.height
))
19930 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
19932 if (slice
.x
>= img
->width
)
19933 slice
.x
= img
->width
;
19934 if (slice
.y
>= img
->height
)
19935 slice
.y
= img
->height
;
19936 if (slice
.x
+ slice
.width
>= img
->width
)
19937 slice
.width
= img
->width
- slice
.x
;
19938 if (slice
.y
+ slice
.height
> img
->height
)
19939 slice
.height
= img
->height
- slice
.y
;
19941 if (slice
.width
== 0 || slice
.height
== 0)
19944 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
19946 it
->descent
= slice
.height
- glyph_ascent
;
19948 it
->descent
+= img
->vmargin
;
19949 if (slice
.y
+ slice
.height
== img
->height
)
19950 it
->descent
+= img
->vmargin
;
19951 it
->phys_descent
= it
->descent
;
19953 it
->pixel_width
= slice
.width
;
19955 it
->pixel_width
+= img
->hmargin
;
19956 if (slice
.x
+ slice
.width
== img
->width
)
19957 it
->pixel_width
+= img
->hmargin
;
19959 /* It's quite possible for images to have an ascent greater than
19960 their height, so don't get confused in that case. */
19961 if (it
->descent
< 0)
19964 #if 0 /* this breaks image tiling */
19965 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
19966 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
19967 if (face_ascent
> it
->ascent
)
19968 it
->ascent
= it
->phys_ascent
= face_ascent
;
19973 if (face
->box
!= FACE_NO_BOX
)
19975 if (face
->box_line_width
> 0)
19978 it
->ascent
+= face
->box_line_width
;
19979 if (slice
.y
+ slice
.height
== img
->height
)
19980 it
->descent
+= face
->box_line_width
;
19983 if (it
->start_of_box_run_p
&& slice
.x
== 0)
19984 it
->pixel_width
+= abs (face
->box_line_width
);
19985 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
19986 it
->pixel_width
+= abs (face
->box_line_width
);
19989 take_vertical_position_into_account (it
);
19991 /* Automatically crop wide image glyphs at right edge so we can
19992 draw the cursor on same display row. */
19993 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
19994 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
19996 it
->pixel_width
-= crop
;
19997 slice
.width
-= crop
;
20002 struct glyph
*glyph
;
20003 enum glyph_row_area area
= it
->area
;
20005 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20006 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20008 glyph
->charpos
= CHARPOS (it
->position
);
20009 glyph
->object
= it
->object
;
20010 glyph
->pixel_width
= it
->pixel_width
;
20011 glyph
->ascent
= glyph_ascent
;
20012 glyph
->descent
= it
->descent
;
20013 glyph
->voffset
= it
->voffset
;
20014 glyph
->type
= IMAGE_GLYPH
;
20015 glyph
->multibyte_p
= it
->multibyte_p
;
20016 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20017 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20018 glyph
->overlaps_vertically_p
= 0;
20019 glyph
->padding_p
= 0;
20020 glyph
->glyph_not_available_p
= 0;
20021 glyph
->face_id
= it
->face_id
;
20022 glyph
->u
.img_id
= img
->id
;
20023 glyph
->slice
= slice
;
20024 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20025 ++it
->glyph_row
->used
[area
];
20028 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20033 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
20034 of the glyph, WIDTH and HEIGHT are the width and height of the
20035 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
20038 append_stretch_glyph (it
, object
, width
, height
, ascent
)
20040 Lisp_Object object
;
20044 struct glyph
*glyph
;
20045 enum glyph_row_area area
= it
->area
;
20047 xassert (ascent
>= 0 && ascent
<= height
);
20049 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20050 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20052 glyph
->charpos
= CHARPOS (it
->position
);
20053 glyph
->object
= object
;
20054 glyph
->pixel_width
= width
;
20055 glyph
->ascent
= ascent
;
20056 glyph
->descent
= height
- ascent
;
20057 glyph
->voffset
= it
->voffset
;
20058 glyph
->type
= STRETCH_GLYPH
;
20059 glyph
->multibyte_p
= it
->multibyte_p
;
20060 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20061 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20062 glyph
->overlaps_vertically_p
= 0;
20063 glyph
->padding_p
= 0;
20064 glyph
->glyph_not_available_p
= 0;
20065 glyph
->face_id
= it
->face_id
;
20066 glyph
->u
.stretch
.ascent
= ascent
;
20067 glyph
->u
.stretch
.height
= height
;
20068 glyph
->slice
= null_glyph_slice
;
20069 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20070 ++it
->glyph_row
->used
[area
];
20073 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20077 /* Produce a stretch glyph for iterator IT. IT->object is the value
20078 of the glyph property displayed. The value must be a list
20079 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
20082 1. `:width WIDTH' specifies that the space should be WIDTH *
20083 canonical char width wide. WIDTH may be an integer or floating
20086 2. `:relative-width FACTOR' specifies that the width of the stretch
20087 should be computed from the width of the first character having the
20088 `glyph' property, and should be FACTOR times that width.
20090 3. `:align-to HPOS' specifies that the space should be wide enough
20091 to reach HPOS, a value in canonical character units.
20093 Exactly one of the above pairs must be present.
20095 4. `:height HEIGHT' specifies that the height of the stretch produced
20096 should be HEIGHT, measured in canonical character units.
20098 5. `:relative-height FACTOR' specifies that the height of the
20099 stretch should be FACTOR times the height of the characters having
20100 the glyph property.
20102 Either none or exactly one of 4 or 5 must be present.
20104 6. `:ascent ASCENT' specifies that ASCENT percent of the height
20105 of the stretch should be used for the ascent of the stretch.
20106 ASCENT must be in the range 0 <= ASCENT <= 100. */
20109 produce_stretch_glyph (it
)
20112 /* (space :width WIDTH :height HEIGHT ...) */
20113 Lisp_Object prop
, plist
;
20114 int width
= 0, height
= 0, align_to
= -1;
20115 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
20118 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20119 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
20121 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20123 /* List should start with `space'. */
20124 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
20125 plist
= XCDR (it
->object
);
20127 /* Compute the width of the stretch. */
20128 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
20129 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
20131 /* Absolute width `:width WIDTH' specified and valid. */
20132 zero_width_ok_p
= 1;
20135 else if (prop
= Fplist_get (plist
, QCrelative_width
),
20138 /* Relative width `:relative-width FACTOR' specified and valid.
20139 Compute the width of the characters having the `glyph'
20142 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
20145 if (it
->multibyte_p
)
20147 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
20148 - IT_BYTEPOS (*it
));
20149 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
20152 it2
.c
= *p
, it2
.len
= 1;
20154 it2
.glyph_row
= NULL
;
20155 it2
.what
= IT_CHARACTER
;
20156 x_produce_glyphs (&it2
);
20157 width
= NUMVAL (prop
) * it2
.pixel_width
;
20159 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
20160 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
20162 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
20163 align_to
= (align_to
< 0
20165 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
20166 else if (align_to
< 0)
20167 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
20168 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
20169 zero_width_ok_p
= 1;
20172 /* Nothing specified -> width defaults to canonical char width. */
20173 width
= FRAME_COLUMN_WIDTH (it
->f
);
20175 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
20178 /* Compute height. */
20179 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
20180 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20183 zero_height_ok_p
= 1;
20185 else if (prop
= Fplist_get (plist
, QCrelative_height
),
20187 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
20189 height
= FONT_HEIGHT (font
);
20191 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
20194 /* Compute percentage of height used for ascent. If
20195 `:ascent ASCENT' is present and valid, use that. Otherwise,
20196 derive the ascent from the font in use. */
20197 if (prop
= Fplist_get (plist
, QCascent
),
20198 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
20199 ascent
= height
* NUMVAL (prop
) / 100.0;
20200 else if (!NILP (prop
)
20201 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20202 ascent
= min (max (0, (int)tem
), height
);
20204 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
20206 if (width
> 0 && !it
->truncate_lines_p
20207 && it
->current_x
+ width
> it
->last_visible_x
)
20208 width
= it
->last_visible_x
- it
->current_x
- 1;
20210 if (width
> 0 && height
> 0 && it
->glyph_row
)
20212 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
20213 if (!STRINGP (object
))
20214 object
= it
->w
->buffer
;
20215 append_stretch_glyph (it
, object
, width
, height
, ascent
);
20218 it
->pixel_width
= width
;
20219 it
->ascent
= it
->phys_ascent
= ascent
;
20220 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
20221 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
20223 take_vertical_position_into_account (it
);
20226 /* Get line-height and line-spacing property at point.
20227 If line-height has format (HEIGHT TOTAL), return TOTAL
20228 in TOTAL_HEIGHT. */
20231 get_line_height_property (it
, prop
)
20235 Lisp_Object position
;
20237 if (STRINGP (it
->object
))
20238 position
= make_number (IT_STRING_CHARPOS (*it
));
20239 else if (BUFFERP (it
->object
))
20240 position
= make_number (IT_CHARPOS (*it
));
20244 return Fget_char_property (position
, prop
, it
->object
);
20247 /* Calculate line-height and line-spacing properties.
20248 An integer value specifies explicit pixel value.
20249 A float value specifies relative value to current face height.
20250 A cons (float . face-name) specifies relative value to
20251 height of specified face font.
20253 Returns height in pixels, or nil. */
20257 calc_line_height_property (it
, val
, font
, boff
, override
)
20261 int boff
, override
;
20263 Lisp_Object face_name
= Qnil
;
20264 int ascent
, descent
, height
;
20266 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
20271 face_name
= XCAR (val
);
20273 if (!NUMBERP (val
))
20274 val
= make_number (1);
20275 if (NILP (face_name
))
20277 height
= it
->ascent
+ it
->descent
;
20282 if (NILP (face_name
))
20284 font
= FRAME_FONT (it
->f
);
20285 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20287 else if (EQ (face_name
, Qt
))
20295 struct font_info
*font_info
;
20297 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
20299 return make_number (-1);
20301 face
= FACE_FROM_ID (it
->f
, face_id
);
20304 return make_number (-1);
20306 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20307 boff
= font_info
->baseline_offset
;
20308 if (font_info
->vertical_centering
)
20309 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20312 ascent
= FONT_BASE (font
) + boff
;
20313 descent
= FONT_DESCENT (font
) - boff
;
20317 it
->override_ascent
= ascent
;
20318 it
->override_descent
= descent
;
20319 it
->override_boff
= boff
;
20322 height
= ascent
+ descent
;
20326 height
= (int)(XFLOAT_DATA (val
) * height
);
20327 else if (INTEGERP (val
))
20328 height
*= XINT (val
);
20330 return make_number (height
);
20335 Produce glyphs/get display metrics for the display element IT is
20336 loaded with. See the description of struct it in dispextern.h
20337 for an overview of struct it. */
20340 x_produce_glyphs (it
)
20343 int extra_line_spacing
= it
->extra_line_spacing
;
20345 it
->glyph_not_available_p
= 0;
20347 if (it
->what
== IT_CHARACTER
)
20351 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20353 int font_not_found_p
;
20354 struct font_info
*font_info
;
20355 int boff
; /* baseline offset */
20356 /* We may change it->multibyte_p upon unibyte<->multibyte
20357 conversion. So, save the current value now and restore it
20360 Note: It seems that we don't have to record multibyte_p in
20361 struct glyph because the character code itself tells if or
20362 not the character is multibyte. Thus, in the future, we must
20363 consider eliminating the field `multibyte_p' in the struct
20365 int saved_multibyte_p
= it
->multibyte_p
;
20367 /* Maybe translate single-byte characters to multibyte, or the
20369 it
->char_to_display
= it
->c
;
20370 if (!ASCII_BYTE_P (it
->c
))
20372 if (unibyte_display_via_language_environment
20373 && SINGLE_BYTE_CHAR_P (it
->c
)
20375 || !NILP (Vnonascii_translation_table
)))
20377 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20378 it
->multibyte_p
= 1;
20379 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20380 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20382 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
20383 && !it
->multibyte_p
)
20385 it
->multibyte_p
= 1;
20386 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20387 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20391 /* Get font to use. Encode IT->char_to_display. */
20392 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20393 &char2b
, it
->multibyte_p
, 0);
20396 /* When no suitable font found, use the default font. */
20397 font_not_found_p
= font
== NULL
;
20398 if (font_not_found_p
)
20400 font
= FRAME_FONT (it
->f
);
20401 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20406 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20407 boff
= font_info
->baseline_offset
;
20408 if (font_info
->vertical_centering
)
20409 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20412 if (it
->char_to_display
>= ' '
20413 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
20415 /* Either unibyte or ASCII. */
20420 pcm
= FRAME_RIF (it
->f
)->per_char_metric
20421 (font
, &char2b
, FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
20423 if (it
->override_ascent
>= 0)
20425 it
->ascent
= it
->override_ascent
;
20426 it
->descent
= it
->override_descent
;
20427 boff
= it
->override_boff
;
20431 it
->ascent
= FONT_BASE (font
) + boff
;
20432 it
->descent
= FONT_DESCENT (font
) - boff
;
20437 it
->phys_ascent
= pcm
->ascent
+ boff
;
20438 it
->phys_descent
= pcm
->descent
- boff
;
20439 it
->pixel_width
= pcm
->width
;
20443 it
->glyph_not_available_p
= 1;
20444 it
->phys_ascent
= it
->ascent
;
20445 it
->phys_descent
= it
->descent
;
20446 it
->pixel_width
= FONT_WIDTH (font
);
20449 if (it
->constrain_row_ascent_descent_p
)
20451 if (it
->descent
> it
->max_descent
)
20453 it
->ascent
+= it
->descent
- it
->max_descent
;
20454 it
->descent
= it
->max_descent
;
20456 if (it
->ascent
> it
->max_ascent
)
20458 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20459 it
->ascent
= it
->max_ascent
;
20461 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20462 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20463 extra_line_spacing
= 0;
20466 /* If this is a space inside a region of text with
20467 `space-width' property, change its width. */
20468 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
20470 it
->pixel_width
*= XFLOATINT (it
->space_width
);
20472 /* If face has a box, add the box thickness to the character
20473 height. If character has a box line to the left and/or
20474 right, add the box line width to the character's width. */
20475 if (face
->box
!= FACE_NO_BOX
)
20477 int thick
= face
->box_line_width
;
20481 it
->ascent
+= thick
;
20482 it
->descent
+= thick
;
20487 if (it
->start_of_box_run_p
)
20488 it
->pixel_width
+= thick
;
20489 if (it
->end_of_box_run_p
)
20490 it
->pixel_width
+= thick
;
20493 /* If face has an overline, add the height of the overline
20494 (1 pixel) and a 1 pixel margin to the character height. */
20495 if (face
->overline_p
)
20496 it
->ascent
+= overline_margin
;
20498 if (it
->constrain_row_ascent_descent_p
)
20500 if (it
->ascent
> it
->max_ascent
)
20501 it
->ascent
= it
->max_ascent
;
20502 if (it
->descent
> it
->max_descent
)
20503 it
->descent
= it
->max_descent
;
20506 take_vertical_position_into_account (it
);
20508 /* If we have to actually produce glyphs, do it. */
20513 /* Translate a space with a `space-width' property
20514 into a stretch glyph. */
20515 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
20516 / FONT_HEIGHT (font
));
20517 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20518 it
->ascent
+ it
->descent
, ascent
);
20523 /* If characters with lbearing or rbearing are displayed
20524 in this line, record that fact in a flag of the
20525 glyph row. This is used to optimize X output code. */
20526 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
20527 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20530 else if (it
->char_to_display
== '\n')
20532 /* A newline has no width but we need the height of the line.
20533 But if previous part of the line set a height, don't
20534 increase that height */
20536 Lisp_Object height
;
20537 Lisp_Object total_height
= Qnil
;
20539 it
->override_ascent
= -1;
20540 it
->pixel_width
= 0;
20543 height
= get_line_height_property(it
, Qline_height
);
20544 /* Split (line-height total-height) list */
20546 && CONSP (XCDR (height
))
20547 && NILP (XCDR (XCDR (height
))))
20549 total_height
= XCAR (XCDR (height
));
20550 height
= XCAR (height
);
20552 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
20554 if (it
->override_ascent
>= 0)
20556 it
->ascent
= it
->override_ascent
;
20557 it
->descent
= it
->override_descent
;
20558 boff
= it
->override_boff
;
20562 it
->ascent
= FONT_BASE (font
) + boff
;
20563 it
->descent
= FONT_DESCENT (font
) - boff
;
20566 if (EQ (height
, Qt
))
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 it
->constrain_row_ascent_descent_p
= 1;
20581 extra_line_spacing
= 0;
20585 Lisp_Object spacing
;
20587 it
->phys_ascent
= it
->ascent
;
20588 it
->phys_descent
= it
->descent
;
20590 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
20591 && face
->box
!= FACE_NO_BOX
20592 && face
->box_line_width
> 0)
20594 it
->ascent
+= face
->box_line_width
;
20595 it
->descent
+= face
->box_line_width
;
20598 && XINT (height
) > it
->ascent
+ it
->descent
)
20599 it
->ascent
= XINT (height
) - it
->descent
;
20601 if (!NILP (total_height
))
20602 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
20605 spacing
= get_line_height_property(it
, Qline_spacing
);
20606 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
20608 if (INTEGERP (spacing
))
20610 extra_line_spacing
= XINT (spacing
);
20611 if (!NILP (total_height
))
20612 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
20616 else if (it
->char_to_display
== '\t')
20618 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
20619 int x
= it
->current_x
+ it
->continuation_lines_width
;
20620 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
20622 /* If the distance from the current position to the next tab
20623 stop is less than a space character width, use the
20624 tab stop after that. */
20625 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
20626 next_tab_x
+= tab_width
;
20628 it
->pixel_width
= next_tab_x
- x
;
20630 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
20631 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20635 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20636 it
->ascent
+ it
->descent
, it
->ascent
);
20641 /* A multi-byte character. Assume that the display width of the
20642 character is the width of the character multiplied by the
20643 width of the font. */
20645 /* If we found a font, this font should give us the right
20646 metrics. If we didn't find a font, use the frame's
20647 default font and calculate the width of the character
20648 from the charset width; this is what old redisplay code
20651 pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
20652 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
20654 if (font_not_found_p
|| !pcm
)
20656 int charset
= CHAR_CHARSET (it
->char_to_display
);
20658 it
->glyph_not_available_p
= 1;
20659 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
20660 * CHARSET_WIDTH (charset
));
20661 it
->phys_ascent
= FONT_BASE (font
) + boff
;
20662 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20666 it
->pixel_width
= pcm
->width
;
20667 it
->phys_ascent
= pcm
->ascent
+ boff
;
20668 it
->phys_descent
= pcm
->descent
- boff
;
20670 && (pcm
->lbearing
< 0
20671 || pcm
->rbearing
> pcm
->width
))
20672 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20675 it
->ascent
= FONT_BASE (font
) + boff
;
20676 it
->descent
= FONT_DESCENT (font
) - boff
;
20677 if (face
->box
!= FACE_NO_BOX
)
20679 int thick
= face
->box_line_width
;
20683 it
->ascent
+= thick
;
20684 it
->descent
+= thick
;
20689 if (it
->start_of_box_run_p
)
20690 it
->pixel_width
+= thick
;
20691 if (it
->end_of_box_run_p
)
20692 it
->pixel_width
+= thick
;
20695 /* If face has an overline, add the height of the overline
20696 (1 pixel) and a 1 pixel margin to the character height. */
20697 if (face
->overline_p
)
20698 it
->ascent
+= overline_margin
;
20700 take_vertical_position_into_account (it
);
20705 it
->multibyte_p
= saved_multibyte_p
;
20707 else if (it
->what
== IT_COMPOSITION
)
20709 /* Note: A composition is represented as one glyph in the
20710 glyph matrix. There are no padding glyphs. */
20713 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20715 int font_not_found_p
;
20716 struct font_info
*font_info
;
20717 int boff
; /* baseline offset */
20718 struct composition
*cmp
= composition_table
[it
->cmp_id
];
20720 /* Maybe translate single-byte characters to multibyte. */
20721 it
->char_to_display
= it
->c
;
20722 if (unibyte_display_via_language_environment
20723 && SINGLE_BYTE_CHAR_P (it
->c
)
20726 && !NILP (Vnonascii_translation_table
))))
20728 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20731 /* Get face and font to use. Encode IT->char_to_display. */
20732 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20733 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20734 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20735 &char2b
, it
->multibyte_p
, 0);
20738 /* When no suitable font found, use the default font. */
20739 font_not_found_p
= font
== NULL
;
20740 if (font_not_found_p
)
20742 font
= FRAME_FONT (it
->f
);
20743 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20748 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20749 boff
= font_info
->baseline_offset
;
20750 if (font_info
->vertical_centering
)
20751 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20754 /* There are no padding glyphs, so there is only one glyph to
20755 produce for the composition. Important is that pixel_width,
20756 ascent and descent are the values of what is drawn by
20757 draw_glyphs (i.e. the values of the overall glyphs composed). */
20760 /* If we have not yet calculated pixel size data of glyphs of
20761 the composition for the current face font, calculate them
20762 now. Theoretically, we have to check all fonts for the
20763 glyphs, but that requires much time and memory space. So,
20764 here we check only the font of the first glyph. This leads
20765 to incorrect display very rarely, and C-l (recenter) can
20766 correct the display anyway. */
20767 if (cmp
->font
!= (void *) font
)
20769 /* Ascent and descent of the font of the first character of
20770 this composition (adjusted by baseline offset). Ascent
20771 and descent of overall glyphs should not be less than
20772 them respectively. */
20773 int font_ascent
= FONT_BASE (font
) + boff
;
20774 int font_descent
= FONT_DESCENT (font
) - boff
;
20775 /* Bounding box of the overall glyphs. */
20776 int leftmost
, rightmost
, lowest
, highest
;
20777 int i
, width
, ascent
, descent
;
20779 cmp
->font
= (void *) font
;
20781 /* Initialize the bounding box. */
20783 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
20784 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
20786 width
= pcm
->width
;
20787 ascent
= pcm
->ascent
;
20788 descent
= pcm
->descent
;
20792 width
= FONT_WIDTH (font
);
20793 ascent
= FONT_BASE (font
);
20794 descent
= FONT_DESCENT (font
);
20798 lowest
= - descent
+ boff
;
20799 highest
= ascent
+ boff
;
20803 && font_info
->default_ascent
20804 && CHAR_TABLE_P (Vuse_default_ascent
)
20805 && !NILP (Faref (Vuse_default_ascent
,
20806 make_number (it
->char_to_display
))))
20807 highest
= font_info
->default_ascent
+ boff
;
20809 /* Draw the first glyph at the normal position. It may be
20810 shifted to right later if some other glyphs are drawn at
20812 cmp
->offsets
[0] = 0;
20813 cmp
->offsets
[1] = boff
;
20815 /* Set cmp->offsets for the remaining glyphs. */
20816 for (i
= 1; i
< cmp
->glyph_len
; i
++)
20818 int left
, right
, btm
, top
;
20819 int ch
= COMPOSITION_GLYPH (cmp
, i
);
20820 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
20822 face
= FACE_FROM_ID (it
->f
, face_id
);
20823 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
20824 &char2b
, it
->multibyte_p
, 0);
20828 font
= FRAME_FONT (it
->f
);
20829 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20835 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20836 boff
= font_info
->baseline_offset
;
20837 if (font_info
->vertical_centering
)
20838 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20842 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
20843 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
20845 width
= pcm
->width
;
20846 ascent
= pcm
->ascent
;
20847 descent
= pcm
->descent
;
20851 width
= FONT_WIDTH (font
);
20856 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
20858 /* Relative composition with or without
20859 alternate chars. */
20860 left
= (leftmost
+ rightmost
- width
) / 2;
20861 btm
= - descent
+ boff
;
20862 if (font_info
&& font_info
->relative_compose
20863 && (! CHAR_TABLE_P (Vignore_relative_composition
)
20864 || NILP (Faref (Vignore_relative_composition
,
20865 make_number (ch
)))))
20868 if (- descent
>= font_info
->relative_compose
)
20869 /* One extra pixel between two glyphs. */
20871 else if (ascent
<= 0)
20872 /* One extra pixel between two glyphs. */
20873 btm
= lowest
- 1 - ascent
- descent
;
20878 /* A composition rule is specified by an integer
20879 value that encodes global and new reference
20880 points (GREF and NREF). GREF and NREF are
20881 specified by numbers as below:
20883 0---1---2 -- ascent
20887 9--10--11 -- center
20889 ---3---4---5--- baseline
20891 6---7---8 -- descent
20893 int rule
= COMPOSITION_RULE (cmp
, i
);
20894 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
20896 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
20897 grefx
= gref
% 3, nrefx
= nref
% 3;
20898 grefy
= gref
/ 3, nrefy
= nref
/ 3;
20901 + grefx
* (rightmost
- leftmost
) / 2
20902 - nrefx
* width
/ 2);
20903 btm
= ((grefy
== 0 ? highest
20905 : grefy
== 2 ? lowest
20906 : (highest
+ lowest
) / 2)
20907 - (nrefy
== 0 ? ascent
+ descent
20908 : nrefy
== 1 ? descent
- boff
20910 : (ascent
+ descent
) / 2));
20913 cmp
->offsets
[i
* 2] = left
;
20914 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
20916 /* Update the bounding box of the overall glyphs. */
20917 right
= left
+ width
;
20918 top
= btm
+ descent
+ ascent
;
20919 if (left
< leftmost
)
20921 if (right
> rightmost
)
20929 /* If there are glyphs whose x-offsets are negative,
20930 shift all glyphs to the right and make all x-offsets
20934 for (i
= 0; i
< cmp
->glyph_len
; i
++)
20935 cmp
->offsets
[i
* 2] -= leftmost
;
20936 rightmost
-= leftmost
;
20939 cmp
->pixel_width
= rightmost
;
20940 cmp
->ascent
= highest
;
20941 cmp
->descent
= - lowest
;
20942 if (cmp
->ascent
< font_ascent
)
20943 cmp
->ascent
= font_ascent
;
20944 if (cmp
->descent
< font_descent
)
20945 cmp
->descent
= font_descent
;
20948 it
->pixel_width
= cmp
->pixel_width
;
20949 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
20950 it
->descent
= it
->phys_descent
= cmp
->descent
;
20952 if (face
->box
!= FACE_NO_BOX
)
20954 int thick
= face
->box_line_width
;
20958 it
->ascent
+= thick
;
20959 it
->descent
+= thick
;
20964 if (it
->start_of_box_run_p
)
20965 it
->pixel_width
+= thick
;
20966 if (it
->end_of_box_run_p
)
20967 it
->pixel_width
+= thick
;
20970 /* If face has an overline, add the height of the overline
20971 (1 pixel) and a 1 pixel margin to the character height. */
20972 if (face
->overline_p
)
20973 it
->ascent
+= overline_margin
;
20975 take_vertical_position_into_account (it
);
20978 append_composite_glyph (it
);
20980 else if (it
->what
== IT_IMAGE
)
20981 produce_image_glyph (it
);
20982 else if (it
->what
== IT_STRETCH
)
20983 produce_stretch_glyph (it
);
20985 /* Accumulate dimensions. Note: can't assume that it->descent > 0
20986 because this isn't true for images with `:ascent 100'. */
20987 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
20988 if (it
->area
== TEXT_AREA
)
20989 it
->current_x
+= it
->pixel_width
;
20991 if (extra_line_spacing
> 0)
20993 it
->descent
+= extra_line_spacing
;
20994 if (extra_line_spacing
> it
->max_extra_line_spacing
)
20995 it
->max_extra_line_spacing
= extra_line_spacing
;
20998 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
20999 it
->max_descent
= max (it
->max_descent
, it
->descent
);
21000 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
21001 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
21005 Output LEN glyphs starting at START at the nominal cursor position.
21006 Advance the nominal cursor over the text. The global variable
21007 updated_window contains the window being updated, updated_row is
21008 the glyph row being updated, and updated_area is the area of that
21009 row being updated. */
21012 x_write_glyphs (start
, len
)
21013 struct glyph
*start
;
21018 xassert (updated_window
&& updated_row
);
21021 /* Write glyphs. */
21023 hpos
= start
- updated_row
->glyphs
[updated_area
];
21024 x
= draw_glyphs (updated_window
, output_cursor
.x
,
21025 updated_row
, updated_area
,
21027 DRAW_NORMAL_TEXT
, 0);
21029 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
21030 if (updated_area
== TEXT_AREA
21031 && updated_window
->phys_cursor_on_p
21032 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
21033 && updated_window
->phys_cursor
.hpos
>= hpos
21034 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
21035 updated_window
->phys_cursor_on_p
= 0;
21039 /* Advance the output cursor. */
21040 output_cursor
.hpos
+= len
;
21041 output_cursor
.x
= x
;
21046 Insert LEN glyphs from START at the nominal cursor position. */
21049 x_insert_glyphs (start
, len
)
21050 struct glyph
*start
;
21055 int line_height
, shift_by_width
, shifted_region_width
;
21056 struct glyph_row
*row
;
21057 struct glyph
*glyph
;
21058 int frame_x
, frame_y
, hpos
;
21060 xassert (updated_window
&& updated_row
);
21062 w
= updated_window
;
21063 f
= XFRAME (WINDOW_FRAME (w
));
21065 /* Get the height of the line we are in. */
21067 line_height
= row
->height
;
21069 /* Get the width of the glyphs to insert. */
21070 shift_by_width
= 0;
21071 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
21072 shift_by_width
+= glyph
->pixel_width
;
21074 /* Get the width of the region to shift right. */
21075 shifted_region_width
= (window_box_width (w
, updated_area
)
21080 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
21081 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
21083 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
21084 line_height
, shift_by_width
);
21086 /* Write the glyphs. */
21087 hpos
= start
- row
->glyphs
[updated_area
];
21088 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
21090 DRAW_NORMAL_TEXT
, 0);
21092 /* Advance the output cursor. */
21093 output_cursor
.hpos
+= len
;
21094 output_cursor
.x
+= shift_by_width
;
21100 Erase the current text line from the nominal cursor position
21101 (inclusive) to pixel column TO_X (exclusive). The idea is that
21102 everything from TO_X onward is already erased.
21104 TO_X is a pixel position relative to updated_area of
21105 updated_window. TO_X == -1 means clear to the end of this area. */
21108 x_clear_end_of_line (to_x
)
21112 struct window
*w
= updated_window
;
21113 int max_x
, min_y
, max_y
;
21114 int from_x
, from_y
, to_y
;
21116 xassert (updated_window
&& updated_row
);
21117 f
= XFRAME (w
->frame
);
21119 if (updated_row
->full_width_p
)
21120 max_x
= WINDOW_TOTAL_WIDTH (w
);
21122 max_x
= window_box_width (w
, updated_area
);
21123 max_y
= window_text_bottom_y (w
);
21125 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
21126 of window. For TO_X > 0, truncate to end of drawing area. */
21132 to_x
= min (to_x
, max_x
);
21134 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
21136 /* Notice if the cursor will be cleared by this operation. */
21137 if (!updated_row
->full_width_p
)
21138 notice_overwritten_cursor (w
, updated_area
,
21139 output_cursor
.x
, -1,
21141 MATRIX_ROW_BOTTOM_Y (updated_row
));
21143 from_x
= output_cursor
.x
;
21145 /* Translate to frame coordinates. */
21146 if (updated_row
->full_width_p
)
21148 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
21149 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
21153 int area_left
= window_box_left (w
, updated_area
);
21154 from_x
+= area_left
;
21158 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
21159 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
21160 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
21162 /* Prevent inadvertently clearing to end of the X window. */
21163 if (to_x
> from_x
&& to_y
> from_y
)
21166 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
21167 to_x
- from_x
, to_y
- from_y
);
21172 #endif /* HAVE_WINDOW_SYSTEM */
21176 /***********************************************************************
21178 ***********************************************************************/
21180 /* Value is the internal representation of the specified cursor type
21181 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
21182 of the bar cursor. */
21184 static enum text_cursor_kinds
21185 get_specified_cursor_type (arg
, width
)
21189 enum text_cursor_kinds type
;
21194 if (EQ (arg
, Qbox
))
21195 return FILLED_BOX_CURSOR
;
21197 if (EQ (arg
, Qhollow
))
21198 return HOLLOW_BOX_CURSOR
;
21200 if (EQ (arg
, Qbar
))
21207 && EQ (XCAR (arg
), Qbar
)
21208 && INTEGERP (XCDR (arg
))
21209 && XINT (XCDR (arg
)) >= 0)
21211 *width
= XINT (XCDR (arg
));
21215 if (EQ (arg
, Qhbar
))
21218 return HBAR_CURSOR
;
21222 && EQ (XCAR (arg
), Qhbar
)
21223 && INTEGERP (XCDR (arg
))
21224 && XINT (XCDR (arg
)) >= 0)
21226 *width
= XINT (XCDR (arg
));
21227 return HBAR_CURSOR
;
21230 /* Treat anything unknown as "hollow box cursor".
21231 It was bad to signal an error; people have trouble fixing
21232 .Xdefaults with Emacs, when it has something bad in it. */
21233 type
= HOLLOW_BOX_CURSOR
;
21238 /* Set the default cursor types for specified frame. */
21240 set_frame_cursor_types (f
, arg
)
21247 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
21248 FRAME_CURSOR_WIDTH (f
) = width
;
21250 /* By default, set up the blink-off state depending on the on-state. */
21252 tem
= Fassoc (arg
, Vblink_cursor_alist
);
21255 FRAME_BLINK_OFF_CURSOR (f
)
21256 = get_specified_cursor_type (XCDR (tem
), &width
);
21257 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
21260 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
21264 /* Return the cursor we want to be displayed in window W. Return
21265 width of bar/hbar cursor through WIDTH arg. Return with
21266 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
21267 (i.e. if the `system caret' should track this cursor).
21269 In a mini-buffer window, we want the cursor only to appear if we
21270 are reading input from this window. For the selected window, we
21271 want the cursor type given by the frame parameter or buffer local
21272 setting of cursor-type. If explicitly marked off, draw no cursor.
21273 In all other cases, we want a hollow box cursor. */
21275 static enum text_cursor_kinds
21276 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
21278 struct glyph
*glyph
;
21280 int *active_cursor
;
21282 struct frame
*f
= XFRAME (w
->frame
);
21283 struct buffer
*b
= XBUFFER (w
->buffer
);
21284 int cursor_type
= DEFAULT_CURSOR
;
21285 Lisp_Object alt_cursor
;
21286 int non_selected
= 0;
21288 *active_cursor
= 1;
21291 if (cursor_in_echo_area
21292 && FRAME_HAS_MINIBUF_P (f
)
21293 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
21295 if (w
== XWINDOW (echo_area_window
))
21297 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
21299 *width
= FRAME_CURSOR_WIDTH (f
);
21300 return FRAME_DESIRED_CURSOR (f
);
21303 return get_specified_cursor_type (b
->cursor_type
, width
);
21306 *active_cursor
= 0;
21310 /* Nonselected window or nonselected frame. */
21311 else if (w
!= XWINDOW (f
->selected_window
)
21312 #ifdef HAVE_WINDOW_SYSTEM
21313 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
21317 *active_cursor
= 0;
21319 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
21325 /* Never display a cursor in a window in which cursor-type is nil. */
21326 if (NILP (b
->cursor_type
))
21329 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
21332 alt_cursor
= b
->cursor_in_non_selected_windows
;
21333 return get_specified_cursor_type (alt_cursor
, width
);
21336 /* Get the normal cursor type for this window. */
21337 if (EQ (b
->cursor_type
, Qt
))
21339 cursor_type
= FRAME_DESIRED_CURSOR (f
);
21340 *width
= FRAME_CURSOR_WIDTH (f
);
21343 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
21345 /* Use normal cursor if not blinked off. */
21346 if (!w
->cursor_off_p
)
21348 #ifdef HAVE_WINDOW_SYSTEM
21349 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21351 if (cursor_type
== FILLED_BOX_CURSOR
)
21353 /* Using a block cursor on large images can be very annoying.
21354 So use a hollow cursor for "large" images.
21355 If image is not transparent (no mask), also use hollow cursor. */
21356 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21357 if (img
!= NULL
&& IMAGEP (img
->spec
))
21359 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
21360 where N = size of default frame font size.
21361 This should cover most of the "tiny" icons people may use. */
21363 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
21364 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
21365 cursor_type
= HOLLOW_BOX_CURSOR
;
21368 else if (cursor_type
!= NO_CURSOR
)
21370 /* Display current only supports BOX and HOLLOW cursors for images.
21371 So for now, unconditionally use a HOLLOW cursor when cursor is
21372 not a solid box cursor. */
21373 cursor_type
= HOLLOW_BOX_CURSOR
;
21377 return cursor_type
;
21380 /* Cursor is blinked off, so determine how to "toggle" it. */
21382 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
21383 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
21384 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
21386 /* Then see if frame has specified a specific blink off cursor type. */
21387 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
21389 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
21390 return FRAME_BLINK_OFF_CURSOR (f
);
21394 /* Some people liked having a permanently visible blinking cursor,
21395 while others had very strong opinions against it. So it was
21396 decided to remove it. KFS 2003-09-03 */
21398 /* Finally perform built-in cursor blinking:
21399 filled box <-> hollow box
21400 wide [h]bar <-> narrow [h]bar
21401 narrow [h]bar <-> no cursor
21402 other type <-> no cursor */
21404 if (cursor_type
== FILLED_BOX_CURSOR
)
21405 return HOLLOW_BOX_CURSOR
;
21407 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
21410 return cursor_type
;
21418 #ifdef HAVE_WINDOW_SYSTEM
21420 /* Notice when the text cursor of window W has been completely
21421 overwritten by a drawing operation that outputs glyphs in AREA
21422 starting at X0 and ending at X1 in the line starting at Y0 and
21423 ending at Y1. X coordinates are area-relative. X1 < 0 means all
21424 the rest of the line after X0 has been written. Y coordinates
21425 are window-relative. */
21428 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
21430 enum glyph_row_area area
;
21431 int x0
, y0
, x1
, y1
;
21433 int cx0
, cx1
, cy0
, cy1
;
21434 struct glyph_row
*row
;
21436 if (!w
->phys_cursor_on_p
)
21438 if (area
!= TEXT_AREA
)
21441 if (w
->phys_cursor
.vpos
< 0
21442 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
21443 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
21444 !(row
->enabled_p
&& row
->displays_text_p
)))
21447 if (row
->cursor_in_fringe_p
)
21449 row
->cursor_in_fringe_p
= 0;
21450 draw_fringe_bitmap (w
, row
, 0);
21451 w
->phys_cursor_on_p
= 0;
21455 cx0
= w
->phys_cursor
.x
;
21456 cx1
= cx0
+ w
->phys_cursor_width
;
21457 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
21460 /* The cursor image will be completely removed from the
21461 screen if the output area intersects the cursor area in
21462 y-direction. When we draw in [y0 y1[, and some part of
21463 the cursor is at y < y0, that part must have been drawn
21464 before. When scrolling, the cursor is erased before
21465 actually scrolling, so we don't come here. When not
21466 scrolling, the rows above the old cursor row must have
21467 changed, and in this case these rows must have written
21468 over the cursor image.
21470 Likewise if part of the cursor is below y1, with the
21471 exception of the cursor being in the first blank row at
21472 the buffer and window end because update_text_area
21473 doesn't draw that row. (Except when it does, but
21474 that's handled in update_text_area.) */
21476 cy0
= w
->phys_cursor
.y
;
21477 cy1
= cy0
+ w
->phys_cursor_height
;
21478 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
21481 w
->phys_cursor_on_p
= 0;
21484 #endif /* HAVE_WINDOW_SYSTEM */
21487 /************************************************************************
21489 ************************************************************************/
21491 #ifdef HAVE_WINDOW_SYSTEM
21494 Fix the display of area AREA of overlapping row ROW in window W
21495 with respect to the overlapping part OVERLAPS. */
21498 x_fix_overlapping_area (w
, row
, area
, overlaps
)
21500 struct glyph_row
*row
;
21501 enum glyph_row_area area
;
21509 for (i
= 0; i
< row
->used
[area
];)
21511 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
21513 int start
= i
, start_x
= x
;
21517 x
+= row
->glyphs
[area
][i
].pixel_width
;
21520 while (i
< row
->used
[area
]
21521 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
21523 draw_glyphs (w
, start_x
, row
, area
,
21525 DRAW_NORMAL_TEXT
, overlaps
);
21529 x
+= row
->glyphs
[area
][i
].pixel_width
;
21539 Draw the cursor glyph of window W in glyph row ROW. See the
21540 comment of draw_glyphs for the meaning of HL. */
21543 draw_phys_cursor_glyph (w
, row
, hl
)
21545 struct glyph_row
*row
;
21546 enum draw_glyphs_face hl
;
21548 /* If cursor hpos is out of bounds, don't draw garbage. This can
21549 happen in mini-buffer windows when switching between echo area
21550 glyphs and mini-buffer. */
21551 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
21553 int on_p
= w
->phys_cursor_on_p
;
21555 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
21556 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
21558 w
->phys_cursor_on_p
= on_p
;
21560 if (hl
== DRAW_CURSOR
)
21561 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21562 /* When we erase the cursor, and ROW is overlapped by other
21563 rows, make sure that these overlapping parts of other rows
21565 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
21567 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21569 if (row
> w
->current_matrix
->rows
21570 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
21571 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
21572 OVERLAPS_ERASED_CURSOR
);
21574 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
21575 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
21576 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
21577 OVERLAPS_ERASED_CURSOR
);
21584 Erase the image of a cursor of window W from the screen. */
21587 erase_phys_cursor (w
)
21590 struct frame
*f
= XFRAME (w
->frame
);
21591 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21592 int hpos
= w
->phys_cursor
.hpos
;
21593 int vpos
= w
->phys_cursor
.vpos
;
21594 int mouse_face_here_p
= 0;
21595 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
21596 struct glyph_row
*cursor_row
;
21597 struct glyph
*cursor_glyph
;
21598 enum draw_glyphs_face hl
;
21600 /* No cursor displayed or row invalidated => nothing to do on the
21602 if (w
->phys_cursor_type
== NO_CURSOR
)
21603 goto mark_cursor_off
;
21605 /* VPOS >= active_glyphs->nrows means that window has been resized.
21606 Don't bother to erase the cursor. */
21607 if (vpos
>= active_glyphs
->nrows
)
21608 goto mark_cursor_off
;
21610 /* If row containing cursor is marked invalid, there is nothing we
21612 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
21613 if (!cursor_row
->enabled_p
)
21614 goto mark_cursor_off
;
21616 /* If line spacing is > 0, old cursor may only be partially visible in
21617 window after split-window. So adjust visible height. */
21618 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
21619 window_text_bottom_y (w
) - cursor_row
->y
);
21621 /* If row is completely invisible, don't attempt to delete a cursor which
21622 isn't there. This can happen if cursor is at top of a window, and
21623 we switch to a buffer with a header line in that window. */
21624 if (cursor_row
->visible_height
<= 0)
21625 goto mark_cursor_off
;
21627 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
21628 if (cursor_row
->cursor_in_fringe_p
)
21630 cursor_row
->cursor_in_fringe_p
= 0;
21631 draw_fringe_bitmap (w
, cursor_row
, 0);
21632 goto mark_cursor_off
;
21635 /* This can happen when the new row is shorter than the old one.
21636 In this case, either draw_glyphs or clear_end_of_line
21637 should have cleared the cursor. Note that we wouldn't be
21638 able to erase the cursor in this case because we don't have a
21639 cursor glyph at hand. */
21640 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
21641 goto mark_cursor_off
;
21643 /* If the cursor is in the mouse face area, redisplay that when
21644 we clear the cursor. */
21645 if (! NILP (dpyinfo
->mouse_face_window
)
21646 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
21647 && (vpos
> dpyinfo
->mouse_face_beg_row
21648 || (vpos
== dpyinfo
->mouse_face_beg_row
21649 && hpos
>= dpyinfo
->mouse_face_beg_col
))
21650 && (vpos
< dpyinfo
->mouse_face_end_row
21651 || (vpos
== dpyinfo
->mouse_face_end_row
21652 && hpos
< dpyinfo
->mouse_face_end_col
))
21653 /* Don't redraw the cursor's spot in mouse face if it is at the
21654 end of a line (on a newline). The cursor appears there, but
21655 mouse highlighting does not. */
21656 && cursor_row
->used
[TEXT_AREA
] > hpos
)
21657 mouse_face_here_p
= 1;
21659 /* Maybe clear the display under the cursor. */
21660 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
21663 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
21666 cursor_glyph
= get_phys_cursor_glyph (w
);
21667 if (cursor_glyph
== NULL
)
21668 goto mark_cursor_off
;
21670 width
= cursor_glyph
->pixel_width
;
21671 left_x
= window_box_left_offset (w
, TEXT_AREA
);
21672 x
= w
->phys_cursor
.x
;
21674 width
-= left_x
- x
;
21675 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
21676 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
21677 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
21680 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
21683 /* Erase the cursor by redrawing the character underneath it. */
21684 if (mouse_face_here_p
)
21685 hl
= DRAW_MOUSE_FACE
;
21687 hl
= DRAW_NORMAL_TEXT
;
21688 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
21691 w
->phys_cursor_on_p
= 0;
21692 w
->phys_cursor_type
= NO_CURSOR
;
21697 Display or clear cursor of window W. If ON is zero, clear the
21698 cursor. If it is non-zero, display the cursor. If ON is nonzero,
21699 where to put the cursor is specified by HPOS, VPOS, X and Y. */
21702 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
21704 int on
, hpos
, vpos
, x
, y
;
21706 struct frame
*f
= XFRAME (w
->frame
);
21707 int new_cursor_type
;
21708 int new_cursor_width
;
21710 struct glyph_row
*glyph_row
;
21711 struct glyph
*glyph
;
21713 /* This is pointless on invisible frames, and dangerous on garbaged
21714 windows and frames; in the latter case, the frame or window may
21715 be in the midst of changing its size, and x and y may be off the
21717 if (! FRAME_VISIBLE_P (f
)
21718 || FRAME_GARBAGED_P (f
)
21719 || vpos
>= w
->current_matrix
->nrows
21720 || hpos
>= w
->current_matrix
->matrix_w
)
21723 /* If cursor is off and we want it off, return quickly. */
21724 if (!on
&& !w
->phys_cursor_on_p
)
21727 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
21728 /* If cursor row is not enabled, we don't really know where to
21729 display the cursor. */
21730 if (!glyph_row
->enabled_p
)
21732 w
->phys_cursor_on_p
= 0;
21737 if (!glyph_row
->exact_window_width_line_p
21738 || hpos
< glyph_row
->used
[TEXT_AREA
])
21739 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
21741 xassert (interrupt_input_blocked
);
21743 /* Set new_cursor_type to the cursor we want to be displayed. */
21744 new_cursor_type
= get_window_cursor_type (w
, glyph
,
21745 &new_cursor_width
, &active_cursor
);
21747 /* If cursor is currently being shown and we don't want it to be or
21748 it is in the wrong place, or the cursor type is not what we want,
21750 if (w
->phys_cursor_on_p
21752 || w
->phys_cursor
.x
!= x
21753 || w
->phys_cursor
.y
!= y
21754 || new_cursor_type
!= w
->phys_cursor_type
21755 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
21756 && new_cursor_width
!= w
->phys_cursor_width
)))
21757 erase_phys_cursor (w
);
21759 /* Don't check phys_cursor_on_p here because that flag is only set
21760 to zero in some cases where we know that the cursor has been
21761 completely erased, to avoid the extra work of erasing the cursor
21762 twice. In other words, phys_cursor_on_p can be 1 and the cursor
21763 still not be visible, or it has only been partly erased. */
21766 w
->phys_cursor_ascent
= glyph_row
->ascent
;
21767 w
->phys_cursor_height
= glyph_row
->height
;
21769 /* Set phys_cursor_.* before x_draw_.* is called because some
21770 of them may need the information. */
21771 w
->phys_cursor
.x
= x
;
21772 w
->phys_cursor
.y
= glyph_row
->y
;
21773 w
->phys_cursor
.hpos
= hpos
;
21774 w
->phys_cursor
.vpos
= vpos
;
21777 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
21778 new_cursor_type
, new_cursor_width
,
21779 on
, active_cursor
);
21783 /* Switch the display of W's cursor on or off, according to the value
21787 update_window_cursor (w
, on
)
21791 /* Don't update cursor in windows whose frame is in the process
21792 of being deleted. */
21793 if (w
->current_matrix
)
21796 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21797 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21803 /* Call update_window_cursor with parameter ON_P on all leaf windows
21804 in the window tree rooted at W. */
21807 update_cursor_in_window_tree (w
, on_p
)
21813 if (!NILP (w
->hchild
))
21814 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
21815 else if (!NILP (w
->vchild
))
21816 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
21818 update_window_cursor (w
, on_p
);
21820 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
21826 Display the cursor on window W, or clear it, according to ON_P.
21827 Don't change the cursor's position. */
21830 x_update_cursor (f
, on_p
)
21834 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
21839 Clear the cursor of window W to background color, and mark the
21840 cursor as not shown. This is used when the text where the cursor
21841 is is about to be rewritten. */
21847 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
21848 update_window_cursor (w
, 0);
21853 Display the active region described by mouse_face_* according to DRAW. */
21856 show_mouse_face (dpyinfo
, draw
)
21857 Display_Info
*dpyinfo
;
21858 enum draw_glyphs_face draw
;
21860 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
21861 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21863 if (/* If window is in the process of being destroyed, don't bother
21865 w
->current_matrix
!= NULL
21866 /* Don't update mouse highlight if hidden */
21867 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
21868 /* Recognize when we are called to operate on rows that don't exist
21869 anymore. This can happen when a window is split. */
21870 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
21872 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
21873 struct glyph_row
*row
, *first
, *last
;
21875 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
21876 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
21878 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
21880 int start_hpos
, end_hpos
, start_x
;
21882 /* For all but the first row, the highlight starts at column 0. */
21885 start_hpos
= dpyinfo
->mouse_face_beg_col
;
21886 start_x
= dpyinfo
->mouse_face_beg_x
;
21895 end_hpos
= dpyinfo
->mouse_face_end_col
;
21898 end_hpos
= row
->used
[TEXT_AREA
];
21899 if (draw
== DRAW_NORMAL_TEXT
)
21900 row
->fill_line_p
= 1; /* Clear to end of line */
21903 if (end_hpos
> start_hpos
)
21905 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
21906 start_hpos
, end_hpos
,
21910 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
21914 /* When we've written over the cursor, arrange for it to
21915 be displayed again. */
21916 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
21919 display_and_set_cursor (w
, 1,
21920 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21921 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21926 /* Change the mouse cursor. */
21927 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
21928 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
21929 else if (draw
== DRAW_MOUSE_FACE
)
21930 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
21932 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
21936 Clear out the mouse-highlighted active region.
21937 Redraw it un-highlighted first. Value is non-zero if mouse
21938 face was actually drawn unhighlighted. */
21941 clear_mouse_face (dpyinfo
)
21942 Display_Info
*dpyinfo
;
21946 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
21948 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
21952 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21953 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21954 dpyinfo
->mouse_face_window
= Qnil
;
21955 dpyinfo
->mouse_face_overlay
= Qnil
;
21961 Non-zero if physical cursor of window W is within mouse face. */
21964 cursor_in_mouse_face_p (w
)
21967 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21968 int in_mouse_face
= 0;
21970 if (WINDOWP (dpyinfo
->mouse_face_window
)
21971 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
21973 int hpos
= w
->phys_cursor
.hpos
;
21974 int vpos
= w
->phys_cursor
.vpos
;
21976 if (vpos
>= dpyinfo
->mouse_face_beg_row
21977 && vpos
<= dpyinfo
->mouse_face_end_row
21978 && (vpos
> dpyinfo
->mouse_face_beg_row
21979 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21980 && (vpos
< dpyinfo
->mouse_face_end_row
21981 || hpos
< dpyinfo
->mouse_face_end_col
21982 || dpyinfo
->mouse_face_past_end
))
21986 return in_mouse_face
;
21992 /* Find the glyph matrix position of buffer position CHARPOS in window
21993 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
21994 current glyphs must be up to date. If CHARPOS is above window
21995 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
21996 of last line in W. In the row containing CHARPOS, stop before glyphs
21997 having STOP as object. */
21999 #if 1 /* This is a version of fast_find_position that's more correct
22000 in the presence of hscrolling, for example. I didn't install
22001 it right away because the problem fixed is minor, it failed
22002 in 20.x as well, and I think it's too risky to install
22003 so near the release of 21.1. 2001-09-25 gerd. */
22006 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
22009 int *hpos
, *vpos
, *x
, *y
;
22012 struct glyph_row
*row
, *first
;
22013 struct glyph
*glyph
, *end
;
22016 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22017 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
22022 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
22026 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
22029 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22033 /* If whole rows or last part of a row came from a display overlay,
22034 row_containing_pos will skip over such rows because their end pos
22035 equals the start pos of the overlay or interval.
22037 Move back if we have a STOP object and previous row's
22038 end glyph came from STOP. */
22041 struct glyph_row
*prev
;
22042 while ((prev
= row
- 1, prev
>= first
)
22043 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
22044 && prev
->used
[TEXT_AREA
] > 0)
22046 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
22047 glyph
= beg
+ prev
->used
[TEXT_AREA
];
22048 while (--glyph
>= beg
22049 && INTEGERP (glyph
->object
));
22051 || !EQ (stop
, glyph
->object
))
22059 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22061 glyph
= row
->glyphs
[TEXT_AREA
];
22062 end
= glyph
+ row
->used
[TEXT_AREA
];
22064 /* Skip over glyphs not having an object at the start of the row.
22065 These are special glyphs like truncation marks on terminal
22067 if (row
->displays_text_p
)
22069 && INTEGERP (glyph
->object
)
22070 && !EQ (stop
, glyph
->object
)
22071 && glyph
->charpos
< 0)
22073 *x
+= glyph
->pixel_width
;
22078 && !INTEGERP (glyph
->object
)
22079 && !EQ (stop
, glyph
->object
)
22080 && (!BUFFERP (glyph
->object
)
22081 || glyph
->charpos
< charpos
))
22083 *x
+= glyph
->pixel_width
;
22087 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
22094 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
22097 int *hpos
, *vpos
, *x
, *y
;
22102 int maybe_next_line_p
= 0;
22103 int line_start_position
;
22104 int yb
= window_text_bottom_y (w
);
22105 struct glyph_row
*row
, *best_row
;
22106 int row_vpos
, best_row_vpos
;
22109 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22110 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22112 while (row
->y
< yb
)
22114 if (row
->used
[TEXT_AREA
])
22115 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
22117 line_start_position
= 0;
22119 if (line_start_position
> pos
)
22121 /* If the position sought is the end of the buffer,
22122 don't include the blank lines at the bottom of the window. */
22123 else if (line_start_position
== pos
22124 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
22126 maybe_next_line_p
= 1;
22129 else if (line_start_position
> 0)
22132 best_row_vpos
= row_vpos
;
22135 if (row
->y
+ row
->height
>= yb
)
22142 /* Find the right column within BEST_ROW. */
22144 current_x
= best_row
->x
;
22145 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
22147 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
22148 int charpos
= glyph
->charpos
;
22150 if (BUFFERP (glyph
->object
))
22152 if (charpos
== pos
)
22155 *vpos
= best_row_vpos
;
22160 else if (charpos
> pos
)
22163 else if (EQ (glyph
->object
, stop
))
22168 current_x
+= glyph
->pixel_width
;
22171 /* If we're looking for the end of the buffer,
22172 and we didn't find it in the line we scanned,
22173 use the start of the following line. */
22174 if (maybe_next_line_p
)
22179 current_x
= best_row
->x
;
22182 *vpos
= best_row_vpos
;
22183 *hpos
= lastcol
+ 1;
22192 /* Find the position of the glyph for position POS in OBJECT in
22193 window W's current matrix, and return in *X, *Y the pixel
22194 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
22196 RIGHT_P non-zero means return the position of the right edge of the
22197 glyph, RIGHT_P zero means return the left edge position.
22199 If no glyph for POS exists in the matrix, return the position of
22200 the glyph with the next smaller position that is in the matrix, if
22201 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
22202 exists in the matrix, return the position of the glyph with the
22203 next larger position in OBJECT.
22205 Value is non-zero if a glyph was found. */
22208 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
22211 Lisp_Object object
;
22212 int *hpos
, *vpos
, *x
, *y
;
22215 int yb
= window_text_bottom_y (w
);
22216 struct glyph_row
*r
;
22217 struct glyph
*best_glyph
= NULL
;
22218 struct glyph_row
*best_row
= NULL
;
22221 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22222 r
->enabled_p
&& r
->y
< yb
;
22225 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
22226 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
22229 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
22230 if (EQ (g
->object
, object
))
22232 if (g
->charpos
== pos
)
22239 else if (best_glyph
== NULL
22240 || ((abs (g
->charpos
- pos
)
22241 < abs (best_glyph
->charpos
- pos
))
22244 : g
->charpos
> pos
)))
22258 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
22262 *x
+= best_glyph
->pixel_width
;
22267 *vpos
= best_row
- w
->current_matrix
->rows
;
22270 return best_glyph
!= NULL
;
22274 /* See if position X, Y is within a hot-spot of an image. */
22277 on_hot_spot_p (hot_spot
, x
, y
)
22278 Lisp_Object hot_spot
;
22281 if (!CONSP (hot_spot
))
22284 if (EQ (XCAR (hot_spot
), Qrect
))
22286 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
22287 Lisp_Object rect
= XCDR (hot_spot
);
22291 if (!CONSP (XCAR (rect
)))
22293 if (!CONSP (XCDR (rect
)))
22295 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
22297 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
22299 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
22301 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
22305 else if (EQ (XCAR (hot_spot
), Qcircle
))
22307 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
22308 Lisp_Object circ
= XCDR (hot_spot
);
22309 Lisp_Object lr
, lx0
, ly0
;
22311 && CONSP (XCAR (circ
))
22312 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
22313 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
22314 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
22316 double r
= XFLOATINT (lr
);
22317 double dx
= XINT (lx0
) - x
;
22318 double dy
= XINT (ly0
) - y
;
22319 return (dx
* dx
+ dy
* dy
<= r
* r
);
22322 else if (EQ (XCAR (hot_spot
), Qpoly
))
22324 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
22325 if (VECTORP (XCDR (hot_spot
)))
22327 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
22328 Lisp_Object
*poly
= v
->contents
;
22332 Lisp_Object lx
, ly
;
22335 /* Need an even number of coordinates, and at least 3 edges. */
22336 if (n
< 6 || n
& 1)
22339 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
22340 If count is odd, we are inside polygon. Pixels on edges
22341 may or may not be included depending on actual geometry of the
22343 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
22344 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
22346 x0
= XINT (lx
), y0
= XINT (ly
);
22347 for (i
= 0; i
< n
; i
+= 2)
22349 int x1
= x0
, y1
= y0
;
22350 if ((lx
= poly
[i
], !INTEGERP (lx
))
22351 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
22353 x0
= XINT (lx
), y0
= XINT (ly
);
22355 /* Does this segment cross the X line? */
22363 if (y
> y0
&& y
> y1
)
22365 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
22375 find_hot_spot (map
, x
, y
)
22379 while (CONSP (map
))
22381 if (CONSP (XCAR (map
))
22382 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
22390 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
22392 doc
: /* Lookup in image map MAP coordinates X and Y.
22393 An image map is an alist where each element has the format (AREA ID PLIST).
22394 An AREA is specified as either a rectangle, a circle, or a polygon:
22395 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
22396 pixel coordinates of the upper left and bottom right corners.
22397 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
22398 and the radius of the circle; r may be a float or integer.
22399 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
22400 vector describes one corner in the polygon.
22401 Returns the alist element for the first matching AREA in MAP. */)
22412 return find_hot_spot (map
, XINT (x
), XINT (y
));
22416 /* Display frame CURSOR, optionally using shape defined by POINTER. */
22418 define_frame_cursor1 (f
, cursor
, pointer
)
22421 Lisp_Object pointer
;
22423 /* Do not change cursor shape while dragging mouse. */
22424 if (!NILP (do_mouse_tracking
))
22427 if (!NILP (pointer
))
22429 if (EQ (pointer
, Qarrow
))
22430 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22431 else if (EQ (pointer
, Qhand
))
22432 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
22433 else if (EQ (pointer
, Qtext
))
22434 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22435 else if (EQ (pointer
, intern ("hdrag")))
22436 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22437 #ifdef HAVE_X_WINDOWS
22438 else if (EQ (pointer
, intern ("vdrag")))
22439 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
22441 else if (EQ (pointer
, intern ("hourglass")))
22442 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
22443 else if (EQ (pointer
, Qmodeline
))
22444 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
22446 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22449 if (cursor
!= No_Cursor
)
22450 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
22453 /* Take proper action when mouse has moved to the mode or header line
22454 or marginal area AREA of window W, x-position X and y-position Y.
22455 X is relative to the start of the text display area of W, so the
22456 width of bitmap areas and scroll bars must be subtracted to get a
22457 position relative to the start of the mode line. */
22460 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
22461 Lisp_Object window
;
22463 enum window_part area
;
22465 struct window
*w
= XWINDOW (window
);
22466 struct frame
*f
= XFRAME (w
->frame
);
22467 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22468 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22469 Lisp_Object pointer
= Qnil
;
22470 int charpos
, dx
, dy
, width
, height
;
22471 Lisp_Object string
, object
= Qnil
;
22472 Lisp_Object pos
, help
;
22474 Lisp_Object mouse_face
;
22475 int original_x_pixel
= x
;
22476 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
22477 struct glyph_row
*row
;
22479 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
22484 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
22485 &object
, &dx
, &dy
, &width
, &height
);
22487 row
= (area
== ON_MODE_LINE
22488 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
22489 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
22492 if (row
->mode_line_p
&& row
->enabled_p
)
22494 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
22495 end
= glyph
+ row
->used
[TEXT_AREA
];
22497 for (x0
= original_x_pixel
;
22498 glyph
< end
&& x0
>= glyph
->pixel_width
;
22500 x0
-= glyph
->pixel_width
;
22508 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
22509 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
22510 &object
, &dx
, &dy
, &width
, &height
);
22515 if (IMAGEP (object
))
22517 Lisp_Object image_map
, hotspot
;
22518 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
22520 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
22522 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22524 Lisp_Object area_id
, plist
;
22526 area_id
= XCAR (hotspot
);
22527 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22528 If so, we could look for mouse-enter, mouse-leave
22529 properties in PLIST (and do something...). */
22530 hotspot
= XCDR (hotspot
);
22531 if (CONSP (hotspot
)
22532 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22534 pointer
= Fplist_get (plist
, Qpointer
);
22535 if (NILP (pointer
))
22537 help
= Fplist_get (plist
, Qhelp_echo
);
22540 help_echo_string
= help
;
22541 /* Is this correct? ++kfs */
22542 XSETWINDOW (help_echo_window
, w
);
22543 help_echo_object
= w
->buffer
;
22544 help_echo_pos
= charpos
;
22548 if (NILP (pointer
))
22549 pointer
= Fplist_get (XCDR (object
), QCpointer
);
22552 if (STRINGP (string
))
22554 pos
= make_number (charpos
);
22555 /* If we're on a string with `help-echo' text property, arrange
22556 for the help to be displayed. This is done by setting the
22557 global variable help_echo_string to the help string. */
22560 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
22563 help_echo_string
= help
;
22564 XSETWINDOW (help_echo_window
, w
);
22565 help_echo_object
= string
;
22566 help_echo_pos
= charpos
;
22570 if (NILP (pointer
))
22571 pointer
= Fget_text_property (pos
, Qpointer
, string
);
22573 /* Change the mouse pointer according to what is under X/Y. */
22574 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
22577 map
= Fget_text_property (pos
, Qlocal_map
, string
);
22578 if (!KEYMAPP (map
))
22579 map
= Fget_text_property (pos
, Qkeymap
, string
);
22580 if (!KEYMAPP (map
))
22581 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
22584 /* Change the mouse face according to what is under X/Y. */
22585 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
22586 if (!NILP (mouse_face
)
22587 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22592 struct glyph
* tmp_glyph
;
22596 int total_pixel_width
;
22601 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
22602 Qmouse_face
, string
, Qnil
);
22604 b
= make_number (0);
22606 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
22608 e
= make_number (SCHARS (string
));
22610 /* Calculate the position(glyph position: GPOS) of GLYPH in
22611 displayed string. GPOS is different from CHARPOS.
22613 CHARPOS is the position of glyph in internal string
22614 object. A mode line string format has structures which
22615 is converted to a flatten by emacs lisp interpreter.
22616 The internal string is an element of the structures.
22617 The displayed string is the flatten string. */
22619 if (glyph
> row_start_glyph
)
22621 tmp_glyph
= glyph
- 1;
22622 while (tmp_glyph
>= row_start_glyph
22623 && tmp_glyph
->charpos
>= XINT (b
)
22624 && EQ (tmp_glyph
->object
, glyph
->object
))
22631 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
22632 displayed string holding GLYPH.
22634 GSEQ_LENGTH is different from SCHARS (STRING).
22635 SCHARS (STRING) returns the length of the internal string. */
22636 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
22637 tmp_glyph
->charpos
< XINT (e
);
22638 tmp_glyph
++, gseq_length
++)
22640 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22644 total_pixel_width
= 0;
22645 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
22646 total_pixel_width
+= tmp_glyph
->pixel_width
;
22648 /* Pre calculation of re-rendering position */
22650 hpos
= (area
== ON_MODE_LINE
22651 ? (w
->current_matrix
)->nrows
- 1
22654 /* If the re-rendering position is included in the last
22655 re-rendering area, we should do nothing. */
22656 if ( EQ (window
, dpyinfo
->mouse_face_window
)
22657 && dpyinfo
->mouse_face_beg_col
<= vpos
22658 && vpos
< dpyinfo
->mouse_face_end_col
22659 && dpyinfo
->mouse_face_beg_row
== hpos
)
22662 if (clear_mouse_face (dpyinfo
))
22663 cursor
= No_Cursor
;
22665 dpyinfo
->mouse_face_beg_col
= vpos
;
22666 dpyinfo
->mouse_face_beg_row
= hpos
;
22668 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
22669 dpyinfo
->mouse_face_beg_y
= 0;
22671 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
22672 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
22674 dpyinfo
->mouse_face_end_x
= 0;
22675 dpyinfo
->mouse_face_end_y
= 0;
22677 dpyinfo
->mouse_face_past_end
= 0;
22678 dpyinfo
->mouse_face_window
= window
;
22680 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
22683 glyph
->face_id
, 1);
22684 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22686 if (NILP (pointer
))
22689 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22690 clear_mouse_face (dpyinfo
);
22692 define_frame_cursor1 (f
, cursor
, pointer
);
22697 Take proper action when the mouse has moved to position X, Y on
22698 frame F as regards highlighting characters that have mouse-face
22699 properties. Also de-highlighting chars where the mouse was before.
22700 X and Y can be negative or out of range. */
22703 note_mouse_highlight (f
, x
, y
)
22707 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22708 enum window_part part
;
22709 Lisp_Object window
;
22711 Cursor cursor
= No_Cursor
;
22712 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
22715 /* When a menu is active, don't highlight because this looks odd. */
22716 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (MAC_OS)
22717 if (popup_activated ())
22721 if (NILP (Vmouse_highlight
)
22722 || !f
->glyphs_initialized_p
)
22725 dpyinfo
->mouse_face_mouse_x
= x
;
22726 dpyinfo
->mouse_face_mouse_y
= y
;
22727 dpyinfo
->mouse_face_mouse_frame
= f
;
22729 if (dpyinfo
->mouse_face_defer
)
22732 if (gc_in_progress
)
22734 dpyinfo
->mouse_face_deferred_gc
= 1;
22738 /* Which window is that in? */
22739 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
22741 /* If we were displaying active text in another window, clear that.
22742 Also clear if we move out of text area in same window. */
22743 if (! EQ (window
, dpyinfo
->mouse_face_window
)
22744 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
22745 && !NILP (dpyinfo
->mouse_face_window
)))
22746 clear_mouse_face (dpyinfo
);
22748 /* Not on a window -> return. */
22749 if (!WINDOWP (window
))
22752 /* Reset help_echo_string. It will get recomputed below. */
22753 help_echo_string
= Qnil
;
22755 /* Convert to window-relative pixel coordinates. */
22756 w
= XWINDOW (window
);
22757 frame_to_window_pixel_xy (w
, &x
, &y
);
22759 /* Handle tool-bar window differently since it doesn't display a
22761 if (EQ (window
, f
->tool_bar_window
))
22763 note_tool_bar_highlight (f
, x
, y
);
22767 /* Mouse is on the mode, header line or margin? */
22768 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
22769 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
22771 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
22775 if (part
== ON_VERTICAL_BORDER
)
22777 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22778 help_echo_string
= build_string ("drag-mouse-1: resize");
22780 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
22781 || part
== ON_SCROLL_BAR
)
22782 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22784 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22786 /* Are we in a window whose display is up to date?
22787 And verify the buffer's text has not changed. */
22788 b
= XBUFFER (w
->buffer
);
22789 if (part
== ON_TEXT
22790 && EQ (w
->window_end_valid
, w
->buffer
)
22791 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
22792 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
22794 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
22795 struct glyph
*glyph
;
22796 Lisp_Object object
;
22797 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
22798 Lisp_Object
*overlay_vec
= NULL
;
22800 struct buffer
*obuf
;
22801 int obegv
, ozv
, same_region
;
22803 /* Find the glyph under X/Y. */
22804 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
22806 /* Look for :pointer property on image. */
22807 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22809 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22810 if (img
!= NULL
&& IMAGEP (img
->spec
))
22812 Lisp_Object image_map
, hotspot
;
22813 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
22815 && (hotspot
= find_hot_spot (image_map
,
22816 glyph
->slice
.x
+ dx
,
22817 glyph
->slice
.y
+ dy
),
22819 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22821 Lisp_Object area_id
, plist
;
22823 area_id
= XCAR (hotspot
);
22824 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22825 If so, we could look for mouse-enter, mouse-leave
22826 properties in PLIST (and do something...). */
22827 hotspot
= XCDR (hotspot
);
22828 if (CONSP (hotspot
)
22829 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22831 pointer
= Fplist_get (plist
, Qpointer
);
22832 if (NILP (pointer
))
22834 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
22835 if (!NILP (help_echo_string
))
22837 help_echo_window
= window
;
22838 help_echo_object
= glyph
->object
;
22839 help_echo_pos
= glyph
->charpos
;
22843 if (NILP (pointer
))
22844 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
22848 /* Clear mouse face if X/Y not over text. */
22850 || area
!= TEXT_AREA
22851 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
22853 if (clear_mouse_face (dpyinfo
))
22854 cursor
= No_Cursor
;
22855 if (NILP (pointer
))
22857 if (area
!= TEXT_AREA
)
22858 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22860 pointer
= Vvoid_text_area_pointer
;
22865 pos
= glyph
->charpos
;
22866 object
= glyph
->object
;
22867 if (!STRINGP (object
) && !BUFFERP (object
))
22870 /* If we get an out-of-range value, return now; avoid an error. */
22871 if (BUFFERP (object
) && pos
> BUF_Z (b
))
22874 /* Make the window's buffer temporarily current for
22875 overlays_at and compute_char_face. */
22876 obuf
= current_buffer
;
22877 current_buffer
= b
;
22883 /* Is this char mouse-active or does it have help-echo? */
22884 position
= make_number (pos
);
22886 if (BUFFERP (object
))
22888 /* Put all the overlays we want in a vector in overlay_vec. */
22889 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
22890 /* Sort overlays into increasing priority order. */
22891 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
22896 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
22897 && vpos
>= dpyinfo
->mouse_face_beg_row
22898 && vpos
<= dpyinfo
->mouse_face_end_row
22899 && (vpos
> dpyinfo
->mouse_face_beg_row
22900 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22901 && (vpos
< dpyinfo
->mouse_face_end_row
22902 || hpos
< dpyinfo
->mouse_face_end_col
22903 || dpyinfo
->mouse_face_past_end
));
22906 cursor
= No_Cursor
;
22908 /* Check mouse-face highlighting. */
22910 /* If there exists an overlay with mouse-face overlapping
22911 the one we are currently highlighting, we have to
22912 check if we enter the overlapping overlay, and then
22913 highlight only that. */
22914 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
22915 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
22917 /* Find the highest priority overlay that has a mouse-face
22920 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
22922 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
22923 if (!NILP (mouse_face
))
22924 overlay
= overlay_vec
[i
];
22927 /* If we're actually highlighting the same overlay as
22928 before, there's no need to do that again. */
22929 if (!NILP (overlay
)
22930 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
22931 goto check_help_echo
;
22933 dpyinfo
->mouse_face_overlay
= overlay
;
22935 /* Clear the display of the old active region, if any. */
22936 if (clear_mouse_face (dpyinfo
))
22937 cursor
= No_Cursor
;
22939 /* If no overlay applies, get a text property. */
22940 if (NILP (overlay
))
22941 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
22943 /* Handle the overlay case. */
22944 if (!NILP (overlay
))
22946 /* Find the range of text around this char that
22947 should be active. */
22948 Lisp_Object before
, after
;
22951 before
= Foverlay_start (overlay
);
22952 after
= Foverlay_end (overlay
);
22953 /* Record this as the current active region. */
22954 fast_find_position (w
, XFASTINT (before
),
22955 &dpyinfo
->mouse_face_beg_col
,
22956 &dpyinfo
->mouse_face_beg_row
,
22957 &dpyinfo
->mouse_face_beg_x
,
22958 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22960 dpyinfo
->mouse_face_past_end
22961 = !fast_find_position (w
, XFASTINT (after
),
22962 &dpyinfo
->mouse_face_end_col
,
22963 &dpyinfo
->mouse_face_end_row
,
22964 &dpyinfo
->mouse_face_end_x
,
22965 &dpyinfo
->mouse_face_end_y
, Qnil
);
22966 dpyinfo
->mouse_face_window
= window
;
22968 dpyinfo
->mouse_face_face_id
22969 = face_at_buffer_position (w
, pos
, 0, 0,
22971 !dpyinfo
->mouse_face_hidden
);
22973 /* Display it as active. */
22974 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22975 cursor
= No_Cursor
;
22977 /* Handle the text property case. */
22978 else if (!NILP (mouse_face
) && BUFFERP (object
))
22980 /* Find the range of text around this char that
22981 should be active. */
22982 Lisp_Object before
, after
, beginning
, end
;
22985 beginning
= Fmarker_position (w
->start
);
22986 end
= make_number (BUF_Z (XBUFFER (object
))
22987 - XFASTINT (w
->window_end_pos
));
22989 = Fprevious_single_property_change (make_number (pos
+ 1),
22991 object
, beginning
);
22993 = Fnext_single_property_change (position
, Qmouse_face
,
22996 /* Record this as the current active region. */
22997 fast_find_position (w
, XFASTINT (before
),
22998 &dpyinfo
->mouse_face_beg_col
,
22999 &dpyinfo
->mouse_face_beg_row
,
23000 &dpyinfo
->mouse_face_beg_x
,
23001 &dpyinfo
->mouse_face_beg_y
, Qnil
);
23002 dpyinfo
->mouse_face_past_end
23003 = !fast_find_position (w
, XFASTINT (after
),
23004 &dpyinfo
->mouse_face_end_col
,
23005 &dpyinfo
->mouse_face_end_row
,
23006 &dpyinfo
->mouse_face_end_x
,
23007 &dpyinfo
->mouse_face_end_y
, Qnil
);
23008 dpyinfo
->mouse_face_window
= window
;
23010 if (BUFFERP (object
))
23011 dpyinfo
->mouse_face_face_id
23012 = face_at_buffer_position (w
, pos
, 0, 0,
23014 !dpyinfo
->mouse_face_hidden
);
23016 /* Display it as active. */
23017 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23018 cursor
= No_Cursor
;
23020 else if (!NILP (mouse_face
) && STRINGP (object
))
23025 b
= Fprevious_single_property_change (make_number (pos
+ 1),
23028 e
= Fnext_single_property_change (position
, Qmouse_face
,
23031 b
= make_number (0);
23033 e
= make_number (SCHARS (object
) - 1);
23035 fast_find_string_pos (w
, XINT (b
), object
,
23036 &dpyinfo
->mouse_face_beg_col
,
23037 &dpyinfo
->mouse_face_beg_row
,
23038 &dpyinfo
->mouse_face_beg_x
,
23039 &dpyinfo
->mouse_face_beg_y
, 0);
23040 fast_find_string_pos (w
, XINT (e
), object
,
23041 &dpyinfo
->mouse_face_end_col
,
23042 &dpyinfo
->mouse_face_end_row
,
23043 &dpyinfo
->mouse_face_end_x
,
23044 &dpyinfo
->mouse_face_end_y
, 1);
23045 dpyinfo
->mouse_face_past_end
= 0;
23046 dpyinfo
->mouse_face_window
= window
;
23047 dpyinfo
->mouse_face_face_id
23048 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
23049 glyph
->face_id
, 1);
23050 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23051 cursor
= No_Cursor
;
23053 else if (STRINGP (object
) && NILP (mouse_face
))
23055 /* A string which doesn't have mouse-face, but
23056 the text ``under'' it might have. */
23057 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
23058 int start
= MATRIX_ROW_START_CHARPOS (r
);
23060 pos
= string_buffer_position (w
, object
, start
);
23062 mouse_face
= get_char_property_and_overlay (make_number (pos
),
23066 if (!NILP (mouse_face
) && !NILP (overlay
))
23068 Lisp_Object before
= Foverlay_start (overlay
);
23069 Lisp_Object after
= Foverlay_end (overlay
);
23072 /* Note that we might not be able to find position
23073 BEFORE in the glyph matrix if the overlay is
23074 entirely covered by a `display' property. In
23075 this case, we overshoot. So let's stop in
23076 the glyph matrix before glyphs for OBJECT. */
23077 fast_find_position (w
, XFASTINT (before
),
23078 &dpyinfo
->mouse_face_beg_col
,
23079 &dpyinfo
->mouse_face_beg_row
,
23080 &dpyinfo
->mouse_face_beg_x
,
23081 &dpyinfo
->mouse_face_beg_y
,
23084 dpyinfo
->mouse_face_past_end
23085 = !fast_find_position (w
, XFASTINT (after
),
23086 &dpyinfo
->mouse_face_end_col
,
23087 &dpyinfo
->mouse_face_end_row
,
23088 &dpyinfo
->mouse_face_end_x
,
23089 &dpyinfo
->mouse_face_end_y
,
23091 dpyinfo
->mouse_face_window
= window
;
23092 dpyinfo
->mouse_face_face_id
23093 = face_at_buffer_position (w
, pos
, 0, 0,
23095 !dpyinfo
->mouse_face_hidden
);
23097 /* Display it as active. */
23098 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23099 cursor
= No_Cursor
;
23106 /* Look for a `help-echo' property. */
23107 if (NILP (help_echo_string
)) {
23108 Lisp_Object help
, overlay
;
23110 /* Check overlays first. */
23111 help
= overlay
= Qnil
;
23112 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
23114 overlay
= overlay_vec
[i
];
23115 help
= Foverlay_get (overlay
, Qhelp_echo
);
23120 help_echo_string
= help
;
23121 help_echo_window
= window
;
23122 help_echo_object
= overlay
;
23123 help_echo_pos
= pos
;
23127 Lisp_Object object
= glyph
->object
;
23128 int charpos
= glyph
->charpos
;
23130 /* Try text properties. */
23131 if (STRINGP (object
)
23133 && charpos
< SCHARS (object
))
23135 help
= Fget_text_property (make_number (charpos
),
23136 Qhelp_echo
, object
);
23139 /* If the string itself doesn't specify a help-echo,
23140 see if the buffer text ``under'' it does. */
23141 struct glyph_row
*r
23142 = MATRIX_ROW (w
->current_matrix
, vpos
);
23143 int start
= MATRIX_ROW_START_CHARPOS (r
);
23144 int pos
= string_buffer_position (w
, object
, start
);
23147 help
= Fget_char_property (make_number (pos
),
23148 Qhelp_echo
, w
->buffer
);
23152 object
= w
->buffer
;
23157 else if (BUFFERP (object
)
23160 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
23165 help_echo_string
= help
;
23166 help_echo_window
= window
;
23167 help_echo_object
= object
;
23168 help_echo_pos
= charpos
;
23173 /* Look for a `pointer' property. */
23174 if (NILP (pointer
))
23176 /* Check overlays first. */
23177 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
23178 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
23180 if (NILP (pointer
))
23182 Lisp_Object object
= glyph
->object
;
23183 int charpos
= glyph
->charpos
;
23185 /* Try text properties. */
23186 if (STRINGP (object
)
23188 && charpos
< SCHARS (object
))
23190 pointer
= Fget_text_property (make_number (charpos
),
23192 if (NILP (pointer
))
23194 /* If the string itself doesn't specify a pointer,
23195 see if the buffer text ``under'' it does. */
23196 struct glyph_row
*r
23197 = MATRIX_ROW (w
->current_matrix
, vpos
);
23198 int start
= MATRIX_ROW_START_CHARPOS (r
);
23199 int pos
= string_buffer_position (w
, object
, start
);
23201 pointer
= Fget_char_property (make_number (pos
),
23202 Qpointer
, w
->buffer
);
23205 else if (BUFFERP (object
)
23208 pointer
= Fget_text_property (make_number (charpos
),
23215 current_buffer
= obuf
;
23220 define_frame_cursor1 (f
, cursor
, pointer
);
23225 Clear any mouse-face on window W. This function is part of the
23226 redisplay interface, and is called from try_window_id and similar
23227 functions to ensure the mouse-highlight is off. */
23230 x_clear_window_mouse_face (w
)
23233 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23234 Lisp_Object window
;
23237 XSETWINDOW (window
, w
);
23238 if (EQ (window
, dpyinfo
->mouse_face_window
))
23239 clear_mouse_face (dpyinfo
);
23245 Just discard the mouse face information for frame F, if any.
23246 This is used when the size of F is changed. */
23249 cancel_mouse_face (f
)
23252 Lisp_Object window
;
23253 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23255 window
= dpyinfo
->mouse_face_window
;
23256 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
23258 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
23259 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
23260 dpyinfo
->mouse_face_window
= Qnil
;
23265 #endif /* HAVE_WINDOW_SYSTEM */
23268 /***********************************************************************
23270 ***********************************************************************/
23272 #ifdef HAVE_WINDOW_SYSTEM
23274 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
23275 which intersects rectangle R. R is in window-relative coordinates. */
23278 expose_area (w
, row
, r
, area
)
23280 struct glyph_row
*row
;
23282 enum glyph_row_area area
;
23284 struct glyph
*first
= row
->glyphs
[area
];
23285 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
23286 struct glyph
*last
;
23287 int first_x
, start_x
, x
;
23289 if (area
== TEXT_AREA
&& row
->fill_line_p
)
23290 /* If row extends face to end of line write the whole line. */
23291 draw_glyphs (w
, 0, row
, area
,
23292 0, row
->used
[area
],
23293 DRAW_NORMAL_TEXT
, 0);
23296 /* Set START_X to the window-relative start position for drawing glyphs of
23297 AREA. The first glyph of the text area can be partially visible.
23298 The first glyphs of other areas cannot. */
23299 start_x
= window_box_left_offset (w
, area
);
23301 if (area
== TEXT_AREA
)
23304 /* Find the first glyph that must be redrawn. */
23306 && x
+ first
->pixel_width
< r
->x
)
23308 x
+= first
->pixel_width
;
23312 /* Find the last one. */
23316 && x
< r
->x
+ r
->width
)
23318 x
+= last
->pixel_width
;
23324 draw_glyphs (w
, first_x
- start_x
, row
, area
,
23325 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
23326 DRAW_NORMAL_TEXT
, 0);
23331 /* Redraw the parts of the glyph row ROW on window W intersecting
23332 rectangle R. R is in window-relative coordinates. Value is
23333 non-zero if mouse-face was overwritten. */
23336 expose_line (w
, row
, r
)
23338 struct glyph_row
*row
;
23341 xassert (row
->enabled_p
);
23343 if (row
->mode_line_p
|| w
->pseudo_window_p
)
23344 draw_glyphs (w
, 0, row
, TEXT_AREA
,
23345 0, row
->used
[TEXT_AREA
],
23346 DRAW_NORMAL_TEXT
, 0);
23349 if (row
->used
[LEFT_MARGIN_AREA
])
23350 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
23351 if (row
->used
[TEXT_AREA
])
23352 expose_area (w
, row
, r
, TEXT_AREA
);
23353 if (row
->used
[RIGHT_MARGIN_AREA
])
23354 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
23355 draw_row_fringe_bitmaps (w
, row
);
23358 return row
->mouse_face_p
;
23362 /* Redraw those parts of glyphs rows during expose event handling that
23363 overlap other rows. Redrawing of an exposed line writes over parts
23364 of lines overlapping that exposed line; this function fixes that.
23366 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
23367 row in W's current matrix that is exposed and overlaps other rows.
23368 LAST_OVERLAPPING_ROW is the last such row. */
23371 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
23373 struct glyph_row
*first_overlapping_row
;
23374 struct glyph_row
*last_overlapping_row
;
23376 struct glyph_row
*row
;
23378 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
23379 if (row
->overlapping_p
)
23381 xassert (row
->enabled_p
&& !row
->mode_line_p
);
23383 if (row
->used
[LEFT_MARGIN_AREA
])
23384 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
23386 if (row
->used
[TEXT_AREA
])
23387 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
23389 if (row
->used
[RIGHT_MARGIN_AREA
])
23390 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
23395 /* Return non-zero if W's cursor intersects rectangle R. */
23398 phys_cursor_in_rect_p (w
, r
)
23402 XRectangle cr
, result
;
23403 struct glyph
*cursor_glyph
;
23405 cursor_glyph
= get_phys_cursor_glyph (w
);
23408 /* r is relative to W's box, but w->phys_cursor.x is relative
23409 to left edge of W's TEXT area. Adjust it. */
23410 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
23411 cr
.y
= w
->phys_cursor
.y
;
23412 cr
.width
= cursor_glyph
->pixel_width
;
23413 cr
.height
= w
->phys_cursor_height
;
23414 /* ++KFS: W32 version used W32-specific IntersectRect here, but
23415 I assume the effect is the same -- and this is portable. */
23416 return x_intersect_rectangles (&cr
, r
, &result
);
23418 /* If we don't understand the format, pretend we're not in the hot-spot. */
23424 Draw a vertical window border to the right of window W if W doesn't
23425 have vertical scroll bars. */
23428 x_draw_vertical_border (w
)
23431 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23433 /* We could do better, if we knew what type of scroll-bar the adjacent
23434 windows (on either side) have... But we don't :-(
23435 However, I think this works ok. ++KFS 2003-04-25 */
23437 /* Redraw borders between horizontally adjacent windows. Don't
23438 do it for frames with vertical scroll bars because either the
23439 right scroll bar of a window, or the left scroll bar of its
23440 neighbor will suffice as a border. */
23441 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
23444 if (!WINDOW_RIGHTMOST_P (w
)
23445 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
23447 int x0
, x1
, y0
, y1
;
23449 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23452 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23455 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
23457 else if (!WINDOW_LEFTMOST_P (w
)
23458 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
23460 int x0
, x1
, y0
, y1
;
23462 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23465 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23468 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
23473 /* Redraw the part of window W intersection rectangle FR. Pixel
23474 coordinates in FR are frame-relative. Call this function with
23475 input blocked. Value is non-zero if the exposure overwrites
23479 expose_window (w
, fr
)
23483 struct frame
*f
= XFRAME (w
->frame
);
23485 int mouse_face_overwritten_p
= 0;
23487 /* If window is not yet fully initialized, do nothing. This can
23488 happen when toolkit scroll bars are used and a window is split.
23489 Reconfiguring the scroll bar will generate an expose for a newly
23491 if (w
->current_matrix
== NULL
)
23494 /* When we're currently updating the window, display and current
23495 matrix usually don't agree. Arrange for a thorough display
23497 if (w
== updated_window
)
23499 SET_FRAME_GARBAGED (f
);
23503 /* Frame-relative pixel rectangle of W. */
23504 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
23505 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
23506 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
23507 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
23509 if (x_intersect_rectangles (fr
, &wr
, &r
))
23511 int yb
= window_text_bottom_y (w
);
23512 struct glyph_row
*row
;
23513 int cursor_cleared_p
;
23514 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
23516 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
23517 r
.x
, r
.y
, r
.width
, r
.height
));
23519 /* Convert to window coordinates. */
23520 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
23521 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
23523 /* Turn off the cursor. */
23524 if (!w
->pseudo_window_p
23525 && phys_cursor_in_rect_p (w
, &r
))
23527 x_clear_cursor (w
);
23528 cursor_cleared_p
= 1;
23531 cursor_cleared_p
= 0;
23533 /* Update lines intersecting rectangle R. */
23534 first_overlapping_row
= last_overlapping_row
= NULL
;
23535 for (row
= w
->current_matrix
->rows
;
23540 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
23542 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
23543 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
23544 || (r
.y
>= y0
&& r
.y
< y1
)
23545 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
23547 /* A header line may be overlapping, but there is no need
23548 to fix overlapping areas for them. KFS 2005-02-12 */
23549 if (row
->overlapping_p
&& !row
->mode_line_p
)
23551 if (first_overlapping_row
== NULL
)
23552 first_overlapping_row
= row
;
23553 last_overlapping_row
= row
;
23556 if (expose_line (w
, row
, &r
))
23557 mouse_face_overwritten_p
= 1;
23564 /* Display the mode line if there is one. */
23565 if (WINDOW_WANTS_MODELINE_P (w
)
23566 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
23568 && row
->y
< r
.y
+ r
.height
)
23570 if (expose_line (w
, row
, &r
))
23571 mouse_face_overwritten_p
= 1;
23574 if (!w
->pseudo_window_p
)
23576 /* Fix the display of overlapping rows. */
23577 if (first_overlapping_row
)
23578 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
23580 /* Draw border between windows. */
23581 x_draw_vertical_border (w
);
23583 /* Turn the cursor on again. */
23584 if (cursor_cleared_p
)
23585 update_window_cursor (w
, 1);
23589 return mouse_face_overwritten_p
;
23594 /* Redraw (parts) of all windows in the window tree rooted at W that
23595 intersect R. R contains frame pixel coordinates. Value is
23596 non-zero if the exposure overwrites mouse-face. */
23599 expose_window_tree (w
, r
)
23603 struct frame
*f
= XFRAME (w
->frame
);
23604 int mouse_face_overwritten_p
= 0;
23606 while (w
&& !FRAME_GARBAGED_P (f
))
23608 if (!NILP (w
->hchild
))
23609 mouse_face_overwritten_p
23610 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
23611 else if (!NILP (w
->vchild
))
23612 mouse_face_overwritten_p
23613 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
23615 mouse_face_overwritten_p
|= expose_window (w
, r
);
23617 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
23620 return mouse_face_overwritten_p
;
23625 Redisplay an exposed area of frame F. X and Y are the upper-left
23626 corner of the exposed rectangle. W and H are width and height of
23627 the exposed area. All are pixel values. W or H zero means redraw
23628 the entire frame. */
23631 expose_frame (f
, x
, y
, w
, h
)
23636 int mouse_face_overwritten_p
= 0;
23638 TRACE ((stderr
, "expose_frame "));
23640 /* No need to redraw if frame will be redrawn soon. */
23641 if (FRAME_GARBAGED_P (f
))
23643 TRACE ((stderr
, " garbaged\n"));
23647 /* If basic faces haven't been realized yet, there is no point in
23648 trying to redraw anything. This can happen when we get an expose
23649 event while Emacs is starting, e.g. by moving another window. */
23650 if (FRAME_FACE_CACHE (f
) == NULL
23651 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
23653 TRACE ((stderr
, " no faces\n"));
23657 if (w
== 0 || h
== 0)
23660 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
23661 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
23671 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
23672 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
23674 if (WINDOWP (f
->tool_bar_window
))
23675 mouse_face_overwritten_p
23676 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
23678 #ifdef HAVE_X_WINDOWS
23680 #ifndef USE_X_TOOLKIT
23681 if (WINDOWP (f
->menu_bar_window
))
23682 mouse_face_overwritten_p
23683 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
23684 #endif /* not USE_X_TOOLKIT */
23688 /* Some window managers support a focus-follows-mouse style with
23689 delayed raising of frames. Imagine a partially obscured frame,
23690 and moving the mouse into partially obscured mouse-face on that
23691 frame. The visible part of the mouse-face will be highlighted,
23692 then the WM raises the obscured frame. With at least one WM, KDE
23693 2.1, Emacs is not getting any event for the raising of the frame
23694 (even tried with SubstructureRedirectMask), only Expose events.
23695 These expose events will draw text normally, i.e. not
23696 highlighted. Which means we must redo the highlight here.
23697 Subsume it under ``we love X''. --gerd 2001-08-15 */
23698 /* Included in Windows version because Windows most likely does not
23699 do the right thing if any third party tool offers
23700 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
23701 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
23703 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23704 if (f
== dpyinfo
->mouse_face_mouse_frame
)
23706 int x
= dpyinfo
->mouse_face_mouse_x
;
23707 int y
= dpyinfo
->mouse_face_mouse_y
;
23708 clear_mouse_face (dpyinfo
);
23709 note_mouse_highlight (f
, x
, y
);
23716 Determine the intersection of two rectangles R1 and R2. Return
23717 the intersection in *RESULT. Value is non-zero if RESULT is not
23721 x_intersect_rectangles (r1
, r2
, result
)
23722 XRectangle
*r1
, *r2
, *result
;
23724 XRectangle
*left
, *right
;
23725 XRectangle
*upper
, *lower
;
23726 int intersection_p
= 0;
23728 /* Rearrange so that R1 is the left-most rectangle. */
23730 left
= r1
, right
= r2
;
23732 left
= r2
, right
= r1
;
23734 /* X0 of the intersection is right.x0, if this is inside R1,
23735 otherwise there is no intersection. */
23736 if (right
->x
<= left
->x
+ left
->width
)
23738 result
->x
= right
->x
;
23740 /* The right end of the intersection is the minimum of the
23741 the right ends of left and right. */
23742 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
23745 /* Same game for Y. */
23747 upper
= r1
, lower
= r2
;
23749 upper
= r2
, lower
= r1
;
23751 /* The upper end of the intersection is lower.y0, if this is inside
23752 of upper. Otherwise, there is no intersection. */
23753 if (lower
->y
<= upper
->y
+ upper
->height
)
23755 result
->y
= lower
->y
;
23757 /* The lower end of the intersection is the minimum of the lower
23758 ends of upper and lower. */
23759 result
->height
= (min (lower
->y
+ lower
->height
,
23760 upper
->y
+ upper
->height
)
23762 intersection_p
= 1;
23766 return intersection_p
;
23769 #endif /* HAVE_WINDOW_SYSTEM */
23772 /***********************************************************************
23774 ***********************************************************************/
23779 Vwith_echo_area_save_vector
= Qnil
;
23780 staticpro (&Vwith_echo_area_save_vector
);
23782 Vmessage_stack
= Qnil
;
23783 staticpro (&Vmessage_stack
);
23785 Qinhibit_redisplay
= intern ("inhibit-redisplay");
23786 staticpro (&Qinhibit_redisplay
);
23788 message_dolog_marker1
= Fmake_marker ();
23789 staticpro (&message_dolog_marker1
);
23790 message_dolog_marker2
= Fmake_marker ();
23791 staticpro (&message_dolog_marker2
);
23792 message_dolog_marker3
= Fmake_marker ();
23793 staticpro (&message_dolog_marker3
);
23796 defsubr (&Sdump_frame_glyph_matrix
);
23797 defsubr (&Sdump_glyph_matrix
);
23798 defsubr (&Sdump_glyph_row
);
23799 defsubr (&Sdump_tool_bar_row
);
23800 defsubr (&Strace_redisplay
);
23801 defsubr (&Strace_to_stderr
);
23803 #ifdef HAVE_WINDOW_SYSTEM
23804 defsubr (&Stool_bar_lines_needed
);
23805 defsubr (&Slookup_image_map
);
23807 defsubr (&Sformat_mode_line
);
23809 staticpro (&Qmenu_bar_update_hook
);
23810 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
23812 staticpro (&Qoverriding_terminal_local_map
);
23813 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
23815 staticpro (&Qoverriding_local_map
);
23816 Qoverriding_local_map
= intern ("overriding-local-map");
23818 staticpro (&Qwindow_scroll_functions
);
23819 Qwindow_scroll_functions
= intern ("window-scroll-functions");
23821 staticpro (&Qredisplay_end_trigger_functions
);
23822 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
23824 staticpro (&Qinhibit_point_motion_hooks
);
23825 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
23827 QCdata
= intern (":data");
23828 staticpro (&QCdata
);
23829 Qdisplay
= intern ("display");
23830 staticpro (&Qdisplay
);
23831 Qspace_width
= intern ("space-width");
23832 staticpro (&Qspace_width
);
23833 Qraise
= intern ("raise");
23834 staticpro (&Qraise
);
23835 Qslice
= intern ("slice");
23836 staticpro (&Qslice
);
23837 Qspace
= intern ("space");
23838 staticpro (&Qspace
);
23839 Qmargin
= intern ("margin");
23840 staticpro (&Qmargin
);
23841 Qpointer
= intern ("pointer");
23842 staticpro (&Qpointer
);
23843 Qleft_margin
= intern ("left-margin");
23844 staticpro (&Qleft_margin
);
23845 Qright_margin
= intern ("right-margin");
23846 staticpro (&Qright_margin
);
23847 Qcenter
= intern ("center");
23848 staticpro (&Qcenter
);
23849 Qline_height
= intern ("line-height");
23850 staticpro (&Qline_height
);
23851 QCalign_to
= intern (":align-to");
23852 staticpro (&QCalign_to
);
23853 QCrelative_width
= intern (":relative-width");
23854 staticpro (&QCrelative_width
);
23855 QCrelative_height
= intern (":relative-height");
23856 staticpro (&QCrelative_height
);
23857 QCeval
= intern (":eval");
23858 staticpro (&QCeval
);
23859 QCpropertize
= intern (":propertize");
23860 staticpro (&QCpropertize
);
23861 QCfile
= intern (":file");
23862 staticpro (&QCfile
);
23863 Qfontified
= intern ("fontified");
23864 staticpro (&Qfontified
);
23865 Qfontification_functions
= intern ("fontification-functions");
23866 staticpro (&Qfontification_functions
);
23867 Qtrailing_whitespace
= intern ("trailing-whitespace");
23868 staticpro (&Qtrailing_whitespace
);
23869 Qescape_glyph
= intern ("escape-glyph");
23870 staticpro (&Qescape_glyph
);
23871 Qnobreak_space
= intern ("nobreak-space");
23872 staticpro (&Qnobreak_space
);
23873 Qimage
= intern ("image");
23874 staticpro (&Qimage
);
23875 QCmap
= intern (":map");
23876 staticpro (&QCmap
);
23877 QCpointer
= intern (":pointer");
23878 staticpro (&QCpointer
);
23879 Qrect
= intern ("rect");
23880 staticpro (&Qrect
);
23881 Qcircle
= intern ("circle");
23882 staticpro (&Qcircle
);
23883 Qpoly
= intern ("poly");
23884 staticpro (&Qpoly
);
23885 Qmessage_truncate_lines
= intern ("message-truncate-lines");
23886 staticpro (&Qmessage_truncate_lines
);
23887 Qgrow_only
= intern ("grow-only");
23888 staticpro (&Qgrow_only
);
23889 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
23890 staticpro (&Qinhibit_menubar_update
);
23891 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
23892 staticpro (&Qinhibit_eval_during_redisplay
);
23893 Qposition
= intern ("position");
23894 staticpro (&Qposition
);
23895 Qbuffer_position
= intern ("buffer-position");
23896 staticpro (&Qbuffer_position
);
23897 Qobject
= intern ("object");
23898 staticpro (&Qobject
);
23899 Qbar
= intern ("bar");
23901 Qhbar
= intern ("hbar");
23902 staticpro (&Qhbar
);
23903 Qbox
= intern ("box");
23905 Qhollow
= intern ("hollow");
23906 staticpro (&Qhollow
);
23907 Qhand
= intern ("hand");
23908 staticpro (&Qhand
);
23909 Qarrow
= intern ("arrow");
23910 staticpro (&Qarrow
);
23911 Qtext
= intern ("text");
23912 staticpro (&Qtext
);
23913 Qrisky_local_variable
= intern ("risky-local-variable");
23914 staticpro (&Qrisky_local_variable
);
23915 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
23916 staticpro (&Qinhibit_free_realized_faces
);
23918 list_of_error
= Fcons (Fcons (intern ("error"),
23919 Fcons (intern ("void-variable"), Qnil
)),
23921 staticpro (&list_of_error
);
23923 Qlast_arrow_position
= intern ("last-arrow-position");
23924 staticpro (&Qlast_arrow_position
);
23925 Qlast_arrow_string
= intern ("last-arrow-string");
23926 staticpro (&Qlast_arrow_string
);
23928 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
23929 staticpro (&Qoverlay_arrow_string
);
23930 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
23931 staticpro (&Qoverlay_arrow_bitmap
);
23933 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
23934 staticpro (&echo_buffer
[0]);
23935 staticpro (&echo_buffer
[1]);
23937 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
23938 staticpro (&echo_area_buffer
[0]);
23939 staticpro (&echo_area_buffer
[1]);
23941 Vmessages_buffer_name
= build_string ("*Messages*");
23942 staticpro (&Vmessages_buffer_name
);
23944 mode_line_proptrans_alist
= Qnil
;
23945 staticpro (&mode_line_proptrans_alist
);
23946 mode_line_string_list
= Qnil
;
23947 staticpro (&mode_line_string_list
);
23948 mode_line_string_face
= Qnil
;
23949 staticpro (&mode_line_string_face
);
23950 mode_line_string_face_prop
= Qnil
;
23951 staticpro (&mode_line_string_face_prop
);
23952 Vmode_line_unwind_vector
= Qnil
;
23953 staticpro (&Vmode_line_unwind_vector
);
23955 help_echo_string
= Qnil
;
23956 staticpro (&help_echo_string
);
23957 help_echo_object
= Qnil
;
23958 staticpro (&help_echo_object
);
23959 help_echo_window
= Qnil
;
23960 staticpro (&help_echo_window
);
23961 previous_help_echo_string
= Qnil
;
23962 staticpro (&previous_help_echo_string
);
23963 help_echo_pos
= -1;
23965 #ifdef HAVE_WINDOW_SYSTEM
23966 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
23967 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
23968 For example, if a block cursor is over a tab, it will be drawn as
23969 wide as that tab on the display. */);
23970 x_stretch_cursor_p
= 0;
23973 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
23974 doc
: /* *Non-nil means highlight trailing whitespace.
23975 The face used for trailing whitespace is `trailing-whitespace'. */);
23976 Vshow_trailing_whitespace
= Qnil
;
23978 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
23979 doc
: /* *Control highlighting of nobreak space and soft hyphen.
23980 A value of t means highlight the character itself (for nobreak space,
23981 use face `nobreak-space').
23982 A value of nil means no highlighting.
23983 Other values mean display the escape glyph followed by an ordinary
23984 space or ordinary hyphen. */);
23985 Vnobreak_char_display
= Qt
;
23987 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
23988 doc
: /* *The pointer shape to show in void text areas.
23989 A value of nil means to show the text pointer. Other options are `arrow',
23990 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
23991 Vvoid_text_area_pointer
= Qarrow
;
23993 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
23994 doc
: /* Non-nil means don't actually do any redisplay.
23995 This is used for internal purposes. */);
23996 Vinhibit_redisplay
= Qnil
;
23998 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
23999 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
24000 Vglobal_mode_string
= Qnil
;
24002 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
24003 doc
: /* Marker for where to display an arrow on top of the buffer text.
24004 This must be the beginning of a line in order to work.
24005 See also `overlay-arrow-string'. */);
24006 Voverlay_arrow_position
= Qnil
;
24008 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
24009 doc
: /* String to display as an arrow in non-window frames.
24010 See also `overlay-arrow-position'. */);
24011 Voverlay_arrow_string
= build_string ("=>");
24013 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
24014 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
24015 The symbols on this list are examined during redisplay to determine
24016 where to display overlay arrows. */);
24017 Voverlay_arrow_variable_list
24018 = Fcons (intern ("overlay-arrow-position"), Qnil
);
24020 DEFVAR_INT ("scroll-step", &scroll_step
,
24021 doc
: /* *The number of lines to try scrolling a window by when point moves out.
24022 If that fails to bring point back on frame, point is centered instead.
24023 If this is zero, point is always centered after it moves off frame.
24024 If you want scrolling to always be a line at a time, you should set
24025 `scroll-conservatively' to a large value rather than set this to 1. */);
24027 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
24028 doc
: /* *Scroll up to this many lines, to bring point back on screen.
24029 A value of zero means to scroll the text to center point vertically
24030 in the window. */);
24031 scroll_conservatively
= 0;
24033 DEFVAR_INT ("scroll-margin", &scroll_margin
,
24034 doc
: /* *Number of lines of margin at the top and bottom of a window.
24035 Recenter the window whenever point gets within this many lines
24036 of the top or bottom of the window. */);
24039 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
24040 doc
: /* Pixels per inch value for non-window system displays.
24041 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
24042 Vdisplay_pixels_per_inch
= make_float (72.0);
24045 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
24048 DEFVAR_BOOL ("truncate-partial-width-windows",
24049 &truncate_partial_width_windows
,
24050 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
24051 truncate_partial_width_windows
= 1;
24053 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
24054 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
24055 Any other value means to use the appropriate face, `mode-line',
24056 `header-line', or `menu' respectively. */);
24057 mode_line_inverse_video
= 1;
24059 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
24060 doc
: /* *Maximum buffer size for which line number should be displayed.
24061 If the buffer is bigger than this, the line number does not appear
24062 in the mode line. A value of nil means no limit. */);
24063 Vline_number_display_limit
= Qnil
;
24065 DEFVAR_INT ("line-number-display-limit-width",
24066 &line_number_display_limit_width
,
24067 doc
: /* *Maximum line width (in characters) for line number display.
24068 If the average length of the lines near point is bigger than this, then the
24069 line number may be omitted from the mode line. */);
24070 line_number_display_limit_width
= 200;
24072 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
24073 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
24074 highlight_nonselected_windows
= 0;
24076 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
24077 doc
: /* Non-nil if more than one frame is visible on this display.
24078 Minibuffer-only frames don't count, but iconified frames do.
24079 This variable is not guaranteed to be accurate except while processing
24080 `frame-title-format' and `icon-title-format'. */);
24082 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
24083 doc
: /* Template for displaying the title bar of visible frames.
24084 \(Assuming the window manager supports this feature.)
24086 This variable has the same structure as `mode-line-format', except that
24087 the %c and %l constructs are ignored. It is used only on frames for
24088 which no explicit name has been set \(see `modify-frame-parameters'). */);
24090 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
24091 doc
: /* Template for displaying the title bar of an iconified frame.
24092 \(Assuming the window manager supports this feature.)
24093 This variable has the same structure as `mode-line-format' (which see),
24094 and is used only on frames for which no explicit name has been set
24095 \(see `modify-frame-parameters'). */);
24097 = Vframe_title_format
24098 = Fcons (intern ("multiple-frames"),
24099 Fcons (build_string ("%b"),
24100 Fcons (Fcons (empty_unibyte_string
,
24101 Fcons (intern ("invocation-name"),
24102 Fcons (build_string ("@"),
24103 Fcons (intern ("system-name"),
24107 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
24108 doc
: /* Maximum number of lines to keep in the message log buffer.
24109 If nil, disable message logging. If t, log messages but don't truncate
24110 the buffer when it becomes large. */);
24111 Vmessage_log_max
= make_number (100);
24113 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
24114 doc
: /* Functions called before redisplay, if window sizes have changed.
24115 The value should be a list of functions that take one argument.
24116 Just before redisplay, for each frame, if any of its windows have changed
24117 size since the last redisplay, or have been split or deleted,
24118 all the functions in the list are called, with the frame as argument. */);
24119 Vwindow_size_change_functions
= Qnil
;
24121 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
24122 doc
: /* List of functions to call before redisplaying a window with scrolling.
24123 Each function is called with two arguments, the window
24124 and its new display-start position. Note that the value of `window-end'
24125 is not valid when these functions are called. */);
24126 Vwindow_scroll_functions
= Qnil
;
24128 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
24129 doc
: /* Functions called when redisplay of a window reaches the end trigger.
24130 Each function is called with two arguments, the window and the end trigger value.
24131 See `set-window-redisplay-end-trigger'. */);
24132 Vredisplay_end_trigger_functions
= Qnil
;
24134 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
24135 doc
: /* *Non-nil means autoselect window with mouse pointer.
24136 If nil, do not autoselect windows.
24137 A positive number means delay autoselection by that many seconds: a
24138 window is autoselected only after the mouse has remained in that
24139 window for the duration of the delay.
24140 A negative number has a similar effect, but causes windows to be
24141 autoselected only after the mouse has stopped moving. \(Because of
24142 the way Emacs compares mouse events, you will occasionally wait twice
24143 that time before the window gets selected.\)
24144 Any other value means to autoselect window instantaneously when the
24145 mouse pointer enters it.
24147 Autoselection selects the minibuffer only if it is active, and never
24148 unselects the minibuffer if it is active. */);
24149 Vmouse_autoselect_window
= Qnil
;
24151 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
24152 doc
: /* *Non-nil means automatically resize tool-bars.
24153 This dynamically changes the tool-bar's height to the minimum height
24154 that is needed to make all tool-bar items visible.
24155 If value is `grow-only', the tool-bar's height is only increased
24156 automatically; to decreace the tool-bar height, use \\[recenter]. */);
24157 Vauto_resize_tool_bars
= Qt
;
24159 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
24160 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
24161 auto_raise_tool_bar_buttons_p
= 1;
24163 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
24164 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
24165 make_cursor_line_fully_visible_p
= 1;
24167 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
24168 doc
: /* *Border below tool-bar in pixels.
24169 If an integer, use it as the height of the border.
24170 If it is one of `internal-border-width' or `border-width', use the
24171 value of the corresponding frame parameter.
24172 Otherwise, no border is added below the tool-bar. */);
24173 Vtool_bar_border
= Qinternal_border_width
;
24175 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
24176 doc
: /* *Margin around tool-bar buttons in pixels.
24177 If an integer, use that for both horizontal and vertical margins.
24178 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
24179 HORZ specifying the horizontal margin, and VERT specifying the
24180 vertical margin. */);
24181 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
24183 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
24184 doc
: /* *Relief thickness of tool-bar buttons. */);
24185 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
24187 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
24188 doc
: /* List of functions to call to fontify regions of text.
24189 Each function is called with one argument POS. Functions must
24190 fontify a region starting at POS in the current buffer, and give
24191 fontified regions the property `fontified'. */);
24192 Vfontification_functions
= Qnil
;
24193 Fmake_variable_buffer_local (Qfontification_functions
);
24195 DEFVAR_BOOL ("unibyte-display-via-language-environment",
24196 &unibyte_display_via_language_environment
,
24197 doc
: /* *Non-nil means display unibyte text according to language environment.
24198 Specifically this means that unibyte non-ASCII characters
24199 are displayed by converting them to the equivalent multibyte characters
24200 according to the current language environment. As a result, they are
24201 displayed according to the current fontset. */);
24202 unibyte_display_via_language_environment
= 0;
24204 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
24205 doc
: /* *Maximum height for resizing mini-windows.
24206 If a float, it specifies a fraction of the mini-window frame's height.
24207 If an integer, it specifies a number of lines. */);
24208 Vmax_mini_window_height
= make_float (0.25);
24210 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
24211 doc
: /* *How to resize mini-windows.
24212 A value of nil means don't automatically resize mini-windows.
24213 A value of t means resize them to fit the text displayed in them.
24214 A value of `grow-only', the default, means let mini-windows grow
24215 only, until their display becomes empty, at which point the windows
24216 go back to their normal size. */);
24217 Vresize_mini_windows
= Qgrow_only
;
24219 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
24220 doc
: /* Alist specifying how to blink the cursor off.
24221 Each element has the form (ON-STATE . OFF-STATE). Whenever the
24222 `cursor-type' frame-parameter or variable equals ON-STATE,
24223 comparing using `equal', Emacs uses OFF-STATE to specify
24224 how to blink it off. ON-STATE and OFF-STATE are values for
24225 the `cursor-type' frame parameter.
24227 If a frame's ON-STATE has no entry in this list,
24228 the frame's other specifications determine how to blink the cursor off. */);
24229 Vblink_cursor_alist
= Qnil
;
24231 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
24232 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
24233 automatic_hscrolling_p
= 1;
24235 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
24236 doc
: /* *How many columns away from the window edge point is allowed to get
24237 before automatic hscrolling will horizontally scroll the window. */);
24238 hscroll_margin
= 5;
24240 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
24241 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
24242 When point is less than `hscroll-margin' columns from the window
24243 edge, automatic hscrolling will scroll the window by the amount of columns
24244 determined by this variable. If its value is a positive integer, scroll that
24245 many columns. If it's a positive floating-point number, it specifies the
24246 fraction of the window's width to scroll. If it's nil or zero, point will be
24247 centered horizontally after the scroll. Any other value, including negative
24248 numbers, are treated as if the value were zero.
24250 Automatic hscrolling always moves point outside the scroll margin, so if
24251 point was more than scroll step columns inside the margin, the window will
24252 scroll more than the value given by the scroll step.
24254 Note that the lower bound for automatic hscrolling specified by `scroll-left'
24255 and `scroll-right' overrides this variable's effect. */);
24256 Vhscroll_step
= make_number (0);
24258 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
24259 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
24260 Bind this around calls to `message' to let it take effect. */);
24261 message_truncate_lines
= 0;
24263 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
24264 doc
: /* Normal hook run to update the menu bar definitions.
24265 Redisplay runs this hook before it redisplays the menu bar.
24266 This is used to update submenus such as Buffers,
24267 whose contents depend on various data. */);
24268 Vmenu_bar_update_hook
= Qnil
;
24270 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
24271 doc
: /* Frame for which we are updating a menu.
24272 The enable predicate for a menu binding should check this variable. */);
24273 Vmenu_updating_frame
= Qnil
;
24275 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
24276 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
24277 inhibit_menubar_update
= 0;
24279 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
24280 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
24281 inhibit_eval_during_redisplay
= 0;
24283 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
24284 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
24285 inhibit_free_realized_faces
= 0;
24288 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
24289 doc
: /* Inhibit try_window_id display optimization. */);
24290 inhibit_try_window_id
= 0;
24292 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
24293 doc
: /* Inhibit try_window_reusing display optimization. */);
24294 inhibit_try_window_reusing
= 0;
24296 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
24297 doc
: /* Inhibit try_cursor_movement display optimization. */);
24298 inhibit_try_cursor_movement
= 0;
24299 #endif /* GLYPH_DEBUG */
24301 DEFVAR_INT ("overline-margin", &overline_margin
,
24302 doc
: /* *Space between overline and text, in pixels.
24303 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
24304 margin to the caracter height. */);
24305 overline_margin
= 2;
24309 /* Initialize this module when Emacs starts. */
24314 Lisp_Object root_window
;
24315 struct window
*mini_w
;
24317 current_header_line_height
= current_mode_line_height
= -1;
24319 CHARPOS (this_line_start_pos
) = 0;
24321 mini_w
= XWINDOW (minibuf_window
);
24322 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
24324 if (!noninteractive
)
24326 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
24329 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
24330 set_window_height (root_window
,
24331 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
24333 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
24334 set_window_height (minibuf_window
, 1, 0);
24336 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
24337 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
24339 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
24340 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
24341 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
24343 /* The default ellipsis glyphs `...'. */
24344 for (i
= 0; i
< 3; ++i
)
24345 default_invis_vector
[i
] = make_number ('.');
24349 /* Allocate the buffer for frame titles.
24350 Also used for `format-mode-line'. */
24352 mode_line_noprop_buf
= (char *) xmalloc (size
);
24353 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
24354 mode_line_noprop_ptr
= mode_line_noprop_buf
;
24355 mode_line_target
= MODE_LINE_DISPLAY
;
24358 help_echo_showing_p
= 0;
24362 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
24363 (do not change this comment) */