1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
3 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
25 Emacs separates the task of updating the display from code
26 modifying global state, e.g. buffer text. This way functions
27 operating on buffers don't also have to be concerned with updating
30 Updating the display is triggered by the Lisp interpreter when it
31 decides it's time to do it. This is done either automatically for
32 you as part of the interpreter's command loop or as the result of
33 calling Lisp functions like `sit-for'. The C function `redisplay'
34 in xdisp.c is the only entry into the inner redisplay code. (Or,
35 let's say almost---see the description of direct update
38 The following diagram shows how redisplay code is invoked. As you
39 can see, Lisp calls redisplay and vice versa. Under window systems
40 like X, some portions of the redisplay code are also called
41 asynchronously during mouse movement or expose events. It is very
42 important that these code parts do NOT use the C library (malloc,
43 free) because many C libraries under Unix are not reentrant. They
44 may also NOT call functions of the Lisp interpreter which could
45 change the interpreter's state. If you don't follow these rules,
46 you will encounter bugs which are very hard to explain.
48 (Direct functions, see below)
49 direct_output_for_insert,
50 direct_forward_char (dispnew.c)
51 +---------------------------------+
54 +--------------+ redisplay +----------------+
55 | Lisp machine |---------------->| Redisplay code |<--+
56 +--------------+ (xdisp.c) +----------------+ |
58 +----------------------------------+ |
59 Don't use this path when called |
62 expose_window (asynchronous) |
64 X expose events -----+
66 What does redisplay do? Obviously, it has to figure out somehow what
67 has been changed since the last time the display has been updated,
68 and to make these changes visible. Preferably it would do that in
69 a moderately intelligent way, i.e. fast.
71 Changes in buffer text can be deduced from window and buffer
72 structures, and from some global variables like `beg_unchanged' and
73 `end_unchanged'. The contents of the display are additionally
74 recorded in a `glyph matrix', a two-dimensional matrix of glyph
75 structures. Each row in such a matrix corresponds to a line on the
76 display, and each glyph in a row corresponds to a column displaying
77 a character, an image, or what else. This matrix is called the
78 `current glyph matrix' or `current matrix' in redisplay
81 For buffer parts that have been changed since the last update, a
82 second glyph matrix is constructed, the so called `desired glyph
83 matrix' or short `desired matrix'. Current and desired matrix are
84 then compared to find a cheap way to update the display, e.g. by
85 reusing part of the display by scrolling lines.
90 You will find a lot of redisplay optimizations when you start
91 looking at the innards of redisplay. The overall goal of all these
92 optimizations is to make redisplay fast because it is done
95 Two optimizations are not found in xdisp.c. These are the direct
96 operations mentioned above. As the name suggests they follow a
97 different principle than the rest of redisplay. Instead of
98 building a desired matrix and then comparing it with the current
99 display, they perform their actions directly on the display and on
102 One direct operation updates the display after one character has
103 been entered. The other one moves the cursor by one position
104 forward or backward. You find these functions under the names
105 `direct_output_for_insert' and `direct_output_forward_char' in
111 Desired matrices are always built per Emacs window. The function
112 `display_line' is the central function to look at if you are
113 interested. It constructs one row in a desired matrix given an
114 iterator structure containing both a buffer position and a
115 description of the environment in which the text is to be
116 displayed. But this is too early, read on.
118 Characters and pixmaps displayed for a range of buffer text depend
119 on various settings of buffers and windows, on overlays and text
120 properties, on display tables, on selective display. The good news
121 is that all this hairy stuff is hidden behind a small set of
122 interface functions taking an iterator structure (struct it)
125 Iteration over things to be displayed is then simple. It is
126 started by initializing an iterator with a call to init_iterator.
127 Calls to get_next_display_element fill the iterator structure with
128 relevant information about the next thing to display. Calls to
129 set_iterator_to_next move the iterator to the next thing.
131 Besides this, an iterator also contains information about the
132 display environment in which glyphs for display elements are to be
133 produced. It has fields for the width and height of the display,
134 the information whether long lines are truncated or continued, a
135 current X and Y position, and lots of other stuff you can better
138 Glyphs in a desired matrix are normally constructed in a loop
139 calling get_next_display_element and then produce_glyphs. The call
140 to produce_glyphs will fill the iterator structure with pixel
141 information about the element being displayed and at the same time
142 produce glyphs for it. If the display element fits on the line
143 being displayed, set_iterator_to_next is called next, otherwise the
144 glyphs produced are discarded.
149 That just couldn't be all, could it? What about terminal types not
150 supporting operations on sub-windows of the screen? To update the
151 display on such a terminal, window-based glyph matrices are not
152 well suited. To be able to reuse part of the display (scrolling
153 lines up and down), we must instead have a view of the whole
154 screen. This is what `frame matrices' are for. They are a trick.
156 Frames on terminals like above have a glyph pool. Windows on such
157 a frame sub-allocate their glyph memory from their frame's glyph
158 pool. The frame itself is given its own glyph matrices. By
159 coincidence---or maybe something else---rows in window glyph
160 matrices are slices of corresponding rows in frame matrices. Thus
161 writing to window matrices implicitly updates a frame matrix which
162 provides us with the view of the whole screen that we originally
163 wanted to have without having to move many bytes around. To be
164 honest, there is a little bit more done, but not much more. If you
165 plan to extend that code, take a look at dispnew.c. The function
166 build_frame_matrix is a good starting point. */
172 #include "keyboard.h"
175 #include "termchar.h"
176 #include "dispextern.h"
178 #include "character.h"
181 #include "commands.h"
185 #include "termhooks.h"
186 #include "intervals.h"
189 #include "region-cache.h"
191 #include "blockinput.h"
193 #ifdef HAVE_X_WINDOWS
205 #ifndef FRAME_X_OUTPUT
206 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
209 #define INFINITY 10000000
211 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
213 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
214 extern int pending_menu_activation
;
217 extern int interrupt_input
;
218 extern int command_loop_level
;
220 extern Lisp_Object do_mouse_tracking
;
222 extern int minibuffer_auto_raise
;
223 extern Lisp_Object Vminibuffer_list
;
225 extern Lisp_Object Qface
;
226 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
228 extern Lisp_Object Voverriding_local_map
;
229 extern Lisp_Object Voverriding_local_map_menu_flag
;
230 extern Lisp_Object Qmenu_item
;
231 extern Lisp_Object Qwhen
;
232 extern Lisp_Object Qhelp_echo
;
234 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
235 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
236 Lisp_Object Qwindow_text_change_functions
, Vwindow_text_change_functions
;
237 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
238 Lisp_Object Qinhibit_point_motion_hooks
;
239 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
240 Lisp_Object Qfontified
;
241 Lisp_Object Qgrow_only
;
242 Lisp_Object Qinhibit_eval_during_redisplay
;
243 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
246 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
249 Lisp_Object Qarrow
, Qhand
, Qtext
;
251 Lisp_Object Qrisky_local_variable
;
253 /* Holds the list (error). */
254 Lisp_Object list_of_error
;
256 /* Functions called to fontify regions of text. */
258 Lisp_Object Vfontification_functions
;
259 Lisp_Object Qfontification_functions
;
261 /* Non-nil means automatically select any window when the mouse
262 cursor moves into it. */
263 Lisp_Object Vmouse_autoselect_window
;
265 /* Non-zero means draw tool bar buttons raised when the mouse moves
268 int auto_raise_tool_bar_buttons_p
;
270 /* Non-zero means to reposition window if cursor line is only partially visible. */
272 int make_cursor_line_fully_visible_p
;
274 /* Margin below tool bar in pixels. 0 or nil means no margin.
275 If value is `internal-border-width' or `border-width',
276 the corresponding frame parameter is used. */
278 Lisp_Object Vtool_bar_border
;
280 /* Margin around tool bar buttons in pixels. */
282 Lisp_Object Vtool_bar_button_margin
;
284 /* Thickness of shadow to draw around tool bar buttons. */
286 EMACS_INT tool_bar_button_relief
;
288 /* Non-nil means automatically resize tool-bars so that all tool-bar
289 items are visible, and no blank lines remain.
291 If value is `grow-only', only make tool-bar bigger. */
293 Lisp_Object Vauto_resize_tool_bars
;
295 /* Non-zero means draw block and hollow cursor as wide as the glyph
296 under it. For example, if a block cursor is over a tab, it will be
297 drawn as wide as that tab on the display. */
299 int x_stretch_cursor_p
;
301 /* Non-nil means don't actually do any redisplay. */
303 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
305 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
307 int inhibit_eval_during_redisplay
;
309 /* Names of text properties relevant for redisplay. */
311 Lisp_Object Qdisplay
;
312 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
314 /* Symbols used in text property values. */
316 Lisp_Object Vdisplay_pixels_per_inch
;
317 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
318 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
321 Lisp_Object Qmargin
, Qpointer
;
322 Lisp_Object Qline_height
;
323 extern Lisp_Object Qheight
;
324 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
325 extern Lisp_Object Qscroll_bar
;
326 extern Lisp_Object Qcursor
;
328 /* Non-nil means highlight trailing whitespace. */
330 Lisp_Object Vshow_trailing_whitespace
;
332 /* Non-nil means escape non-break space and hyphens. */
334 Lisp_Object Vnobreak_char_display
;
336 #ifdef HAVE_WINDOW_SYSTEM
337 extern Lisp_Object Voverflow_newline_into_fringe
;
339 /* Test if overflow newline into fringe. Called with iterator IT
340 at or past right window margin, and with IT->current_x set. */
342 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
343 (!NILP (Voverflow_newline_into_fringe) \
344 && FRAME_WINDOW_P (it->f) \
345 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
346 && it->current_x == it->last_visible_x)
348 #endif /* HAVE_WINDOW_SYSTEM */
350 /* Non-nil means show the text cursor in void text areas
351 i.e. in blank areas after eol and eob. This used to be
352 the default in 21.3. */
354 Lisp_Object Vvoid_text_area_pointer
;
356 /* Name of the face used to highlight trailing whitespace. */
358 Lisp_Object Qtrailing_whitespace
;
360 /* Name and number of the face used to highlight escape glyphs. */
362 Lisp_Object Qescape_glyph
;
364 /* Name and number of the face used to highlight non-breaking spaces. */
366 Lisp_Object Qnobreak_space
;
368 /* The symbol `image' which is the car of the lists used to represent
373 /* The image map types. */
374 Lisp_Object QCmap
, QCpointer
;
375 Lisp_Object Qrect
, Qcircle
, Qpoly
;
377 /* Non-zero means print newline to stdout before next mini-buffer
380 int noninteractive_need_newline
;
382 /* Non-zero means print newline to message log before next message. */
384 static int message_log_need_newline
;
386 /* Three markers that message_dolog uses.
387 It could allocate them itself, but that causes trouble
388 in handling memory-full errors. */
389 static Lisp_Object message_dolog_marker1
;
390 static Lisp_Object message_dolog_marker2
;
391 static Lisp_Object message_dolog_marker3
;
393 /* The buffer position of the first character appearing entirely or
394 partially on the line of the selected window which contains the
395 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
396 redisplay optimization in redisplay_internal. */
398 static struct text_pos this_line_start_pos
;
400 /* Number of characters past the end of the line above, including the
401 terminating newline. */
403 static struct text_pos this_line_end_pos
;
405 /* The vertical positions and the height of this line. */
407 static int this_line_vpos
;
408 static int this_line_y
;
409 static int this_line_pixel_height
;
411 /* X position at which this display line starts. Usually zero;
412 negative if first character is partially visible. */
414 static int this_line_start_x
;
416 /* Buffer that this_line_.* variables are referring to. */
418 static struct buffer
*this_line_buffer
;
420 /* Nonzero means truncate lines in all windows less wide than the
423 int truncate_partial_width_windows
;
425 /* A flag to control how to display unibyte 8-bit character. */
427 int unibyte_display_via_language_environment
;
429 /* Nonzero means we have more than one non-mini-buffer-only frame.
430 Not guaranteed to be accurate except while parsing
431 frame-title-format. */
435 Lisp_Object Vglobal_mode_string
;
438 /* List of variables (symbols) which hold markers for overlay arrows.
439 The symbols on this list are examined during redisplay to determine
440 where to display overlay arrows. */
442 Lisp_Object Voverlay_arrow_variable_list
;
444 /* Marker for where to display an arrow on top of the buffer text. */
446 Lisp_Object Voverlay_arrow_position
;
448 /* String to display for the arrow. Only used on terminal frames. */
450 Lisp_Object Voverlay_arrow_string
;
452 /* Values of those variables at last redisplay are stored as
453 properties on `overlay-arrow-position' symbol. However, if
454 Voverlay_arrow_position is a marker, last-arrow-position is its
455 numerical position. */
457 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
459 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
460 properties on a symbol in overlay-arrow-variable-list. */
462 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
464 /* Like mode-line-format, but for the title bar on a visible frame. */
466 Lisp_Object Vframe_title_format
;
468 /* Like mode-line-format, but for the title bar on an iconified frame. */
470 Lisp_Object Vicon_title_format
;
472 /* List of functions to call when a window's size changes. These
473 functions get one arg, a frame on which one or more windows' sizes
476 static Lisp_Object Vwindow_size_change_functions
;
478 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
480 /* Nonzero if an overlay arrow has been displayed in this window. */
482 static int overlay_arrow_seen
;
484 /* Nonzero means highlight the region even in nonselected windows. */
486 int highlight_nonselected_windows
;
488 /* If cursor motion alone moves point off frame, try scrolling this
489 many lines up or down if that will bring it back. */
491 static EMACS_INT scroll_step
;
493 /* Nonzero means scroll just far enough to bring point back on the
494 screen, when appropriate. */
496 static EMACS_INT scroll_conservatively
;
498 /* Recenter the window whenever point gets within this many lines of
499 the top or bottom of the window. This value is translated into a
500 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
501 that there is really a fixed pixel height scroll margin. */
503 EMACS_INT scroll_margin
;
505 /* Number of windows showing the buffer of the selected window (or
506 another buffer with the same base buffer). keyboard.c refers to
511 /* Vector containing glyphs for an ellipsis `...'. */
513 static Lisp_Object default_invis_vector
[3];
515 /* Zero means display the mode-line/header-line/menu-bar in the default face
516 (this slightly odd definition is for compatibility with previous versions
517 of emacs), non-zero means display them using their respective faces.
519 This variable is deprecated. */
521 int mode_line_inverse_video
;
523 /* Prompt to display in front of the mini-buffer contents. */
525 Lisp_Object minibuf_prompt
;
527 /* Width of current mini-buffer prompt. Only set after display_line
528 of the line that contains the prompt. */
530 int minibuf_prompt_width
;
532 /* This is the window where the echo area message was displayed. It
533 is always a mini-buffer window, but it may not be the same window
534 currently active as a mini-buffer. */
536 Lisp_Object echo_area_window
;
538 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
539 pushes the current message and the value of
540 message_enable_multibyte on the stack, the function restore_message
541 pops the stack and displays MESSAGE again. */
543 Lisp_Object Vmessage_stack
;
545 /* Nonzero means multibyte characters were enabled when the echo area
546 message was specified. */
548 int message_enable_multibyte
;
550 /* Nonzero if we should redraw the mode lines on the next redisplay. */
552 int update_mode_lines
;
554 /* Nonzero if window sizes or contents have changed since last
555 redisplay that finished. */
557 int windows_or_buffers_changed
;
559 /* Nonzero means a frame's cursor type has been changed. */
561 int cursor_type_changed
;
563 /* Nonzero after display_mode_line if %l was used and it displayed a
566 int line_number_displayed
;
568 /* Maximum buffer size for which to display line numbers. */
570 Lisp_Object Vline_number_display_limit
;
572 /* Line width to consider when repositioning for line number display. */
574 static EMACS_INT line_number_display_limit_width
;
576 /* Number of lines to keep in the message log buffer. t means
577 infinite. nil means don't log at all. */
579 Lisp_Object Vmessage_log_max
;
581 /* The name of the *Messages* buffer, a string. */
583 static Lisp_Object Vmessages_buffer_name
;
585 /* Current, index 0, and last displayed echo area message. Either
586 buffers from echo_buffers, or nil to indicate no message. */
588 Lisp_Object echo_area_buffer
[2];
590 /* The buffers referenced from echo_area_buffer. */
592 static Lisp_Object echo_buffer
[2];
594 /* A vector saved used in with_area_buffer to reduce consing. */
596 static Lisp_Object Vwith_echo_area_save_vector
;
598 /* Non-zero means display_echo_area should display the last echo area
599 message again. Set by redisplay_preserve_echo_area. */
601 static int display_last_displayed_message_p
;
603 /* Nonzero if echo area is being used by print; zero if being used by
606 int message_buf_print
;
608 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
610 Lisp_Object Qinhibit_menubar_update
;
611 int inhibit_menubar_update
;
613 /* When evaluating expressions from menu bar items (enable conditions,
614 for instance), this is the frame they are being processed for. */
616 Lisp_Object Vmenu_updating_frame
;
618 /* Maximum height for resizing mini-windows. Either a float
619 specifying a fraction of the available height, or an integer
620 specifying a number of lines. */
622 Lisp_Object Vmax_mini_window_height
;
624 /* Non-zero means messages should be displayed with truncated
625 lines instead of being continued. */
627 int message_truncate_lines
;
628 Lisp_Object Qmessage_truncate_lines
;
630 /* Set to 1 in clear_message to make redisplay_internal aware
631 of an emptied echo area. */
633 static int message_cleared_p
;
635 /* How to blink the default frame cursor off. */
636 Lisp_Object Vblink_cursor_alist
;
638 /* A scratch glyph row with contents used for generating truncation
639 glyphs. Also used in direct_output_for_insert. */
641 #define MAX_SCRATCH_GLYPHS 100
642 struct glyph_row scratch_glyph_row
;
643 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
645 /* Ascent and height of the last line processed by move_it_to. */
647 static int last_max_ascent
, last_height
;
649 /* Non-zero if there's a help-echo in the echo area. */
651 int help_echo_showing_p
;
653 /* If >= 0, computed, exact values of mode-line and header-line height
654 to use in the macros CURRENT_MODE_LINE_HEIGHT and
655 CURRENT_HEADER_LINE_HEIGHT. */
657 int current_mode_line_height
, current_header_line_height
;
659 /* The maximum distance to look ahead for text properties. Values
660 that are too small let us call compute_char_face and similar
661 functions too often which is expensive. Values that are too large
662 let us call compute_char_face and alike too often because we
663 might not be interested in text properties that far away. */
665 #define TEXT_PROP_DISTANCE_LIMIT 100
669 /* Variables to turn off display optimizations from Lisp. */
671 int inhibit_try_window_id
, inhibit_try_window_reusing
;
672 int inhibit_try_cursor_movement
;
674 /* Non-zero means print traces of redisplay if compiled with
677 int trace_redisplay_p
;
679 #endif /* GLYPH_DEBUG */
681 #ifdef DEBUG_TRACE_MOVE
682 /* Non-zero means trace with TRACE_MOVE to stderr. */
685 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
687 #define TRACE_MOVE(x) (void) 0
690 /* Non-zero means automatically scroll windows horizontally to make
693 int automatic_hscrolling_p
;
694 Lisp_Object Qauto_hscroll_mode
;
696 /* How close to the margin can point get before the window is scrolled
698 EMACS_INT hscroll_margin
;
700 /* How much to scroll horizontally when point is inside the above margin. */
701 Lisp_Object Vhscroll_step
;
703 /* The variable `resize-mini-windows'. If nil, don't resize
704 mini-windows. If t, always resize them to fit the text they
705 display. If `grow-only', let mini-windows grow only until they
708 Lisp_Object Vresize_mini_windows
;
710 /* Buffer being redisplayed -- for redisplay_window_error. */
712 struct buffer
*displayed_buffer
;
714 /* Space between overline and text. */
716 EMACS_INT overline_margin
;
718 /* Value returned from text property handlers (see below). */
723 HANDLED_RECOMPUTE_PROPS
,
724 HANDLED_OVERLAY_STRING_CONSUMED
,
728 /* A description of text properties that redisplay is interested
733 /* The name of the property. */
736 /* A unique index for the property. */
739 /* A handler function called to set up iterator IT from the property
740 at IT's current position. Value is used to steer handle_stop. */
741 enum prop_handled (*handler
) P_ ((struct it
*it
));
744 static enum prop_handled handle_face_prop
P_ ((struct it
*));
745 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
746 static enum prop_handled handle_display_prop
P_ ((struct it
*));
747 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
748 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
749 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
750 static enum prop_handled handle_auto_composed_prop
P_ ((struct it
*));
752 /* Properties handled by iterators. */
754 static struct props it_props
[] =
756 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
757 /* Handle `face' before `display' because some sub-properties of
758 `display' need to know the face. */
759 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
760 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
761 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
762 {&Qauto_composed
, AUTO_COMPOSED_PROP_IDX
, handle_auto_composed_prop
},
763 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
767 /* Value is the position described by X. If X is a marker, value is
768 the marker_position of X. Otherwise, value is X. */
770 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
772 /* Enumeration returned by some move_it_.* functions internally. */
776 /* Not used. Undefined value. */
779 /* Move ended at the requested buffer position or ZV. */
780 MOVE_POS_MATCH_OR_ZV
,
782 /* Move ended at the requested X pixel position. */
785 /* Move within a line ended at the end of a line that must be
789 /* Move within a line ended at the end of a line that would
790 be displayed truncated. */
793 /* Move within a line ended at a line end. */
797 /* This counter is used to clear the face cache every once in a while
798 in redisplay_internal. It is incremented for each redisplay.
799 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
802 #define CLEAR_FACE_CACHE_COUNT 500
803 static int clear_face_cache_count
;
805 /* Similarly for the image cache. */
807 #ifdef HAVE_WINDOW_SYSTEM
808 #define CLEAR_IMAGE_CACHE_COUNT 101
809 static int clear_image_cache_count
;
812 /* Non-zero while redisplay_internal is in progress. */
816 /* Non-zero means don't free realized faces. Bound while freeing
817 realized faces is dangerous because glyph matrices might still
820 int inhibit_free_realized_faces
;
821 Lisp_Object Qinhibit_free_realized_faces
;
823 /* If a string, XTread_socket generates an event to display that string.
824 (The display is done in read_char.) */
826 Lisp_Object help_echo_string
;
827 Lisp_Object help_echo_window
;
828 Lisp_Object help_echo_object
;
831 /* Temporary variable for XTread_socket. */
833 Lisp_Object previous_help_echo_string
;
835 /* Null glyph slice */
837 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
840 /* Function prototypes. */
842 static void setup_for_ellipsis
P_ ((struct it
*, int));
843 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
844 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
845 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
846 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
847 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
848 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
851 static int invisible_text_between_p
P_ ((struct it
*, int, int));
854 static void pint2str
P_ ((char *, int, int));
855 static void pint2hrstr
P_ ((char *, int, int));
856 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
858 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
859 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
860 static void store_mode_line_noprop_char
P_ ((char));
861 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
862 static void x_consider_frame_title
P_ ((Lisp_Object
));
863 static void handle_stop
P_ ((struct it
*));
864 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
865 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
866 static void ensure_echo_area_buffers
P_ ((void));
867 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
868 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
869 static int with_echo_area_buffer
P_ ((struct window
*, int,
870 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
871 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
872 static void clear_garbaged_frames
P_ ((void));
873 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
874 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
875 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
876 static int display_echo_area
P_ ((struct window
*));
877 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
878 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
879 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
880 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
881 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
883 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
884 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
885 static void insert_left_trunc_glyphs
P_ ((struct it
*));
886 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
888 static void extend_face_to_end_of_line
P_ ((struct it
*));
889 static int append_space_for_newline
P_ ((struct it
*, int));
890 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
891 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
892 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
893 static int trailing_whitespace_p
P_ ((int));
894 static int message_log_check_duplicate
P_ ((int, int, int, int));
895 static void push_it
P_ ((struct it
*));
896 static void pop_it
P_ ((struct it
*));
897 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
898 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
899 static void redisplay_internal
P_ ((int));
900 static int echo_area_display
P_ ((int));
901 static void redisplay_windows
P_ ((Lisp_Object
));
902 static void redisplay_window
P_ ((Lisp_Object
, int));
903 static Lisp_Object
redisplay_window_error ();
904 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
905 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
906 static int update_menu_bar
P_ ((struct frame
*, int, int));
907 static int try_window_reusing_current_matrix
P_ ((struct window
*));
908 static int try_window_id
P_ ((struct window
*));
909 static int display_line
P_ ((struct it
*));
910 static int display_mode_lines
P_ ((struct window
*));
911 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
912 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
913 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
914 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
915 static void display_menu_bar
P_ ((struct window
*));
916 static int display_count_lines
P_ ((int, int, int, int, int *));
917 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
918 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int));
919 static void compute_line_metrics
P_ ((struct it
*));
920 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
921 static int get_overlay_strings
P_ ((struct it
*, int));
922 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
923 static void next_overlay_string
P_ ((struct it
*));
924 static void reseat
P_ ((struct it
*, struct text_pos
, int));
925 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
926 static void back_to_previous_visible_line_start
P_ ((struct it
*));
927 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
928 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
929 static int next_element_from_ellipsis
P_ ((struct it
*));
930 static int next_element_from_display_vector
P_ ((struct it
*));
931 static int next_element_from_string
P_ ((struct it
*));
932 static int next_element_from_c_string
P_ ((struct it
*));
933 static int next_element_from_buffer
P_ ((struct it
*));
934 static int next_element_from_composition
P_ ((struct it
*));
935 static int next_element_from_image
P_ ((struct it
*));
936 static int next_element_from_stretch
P_ ((struct it
*));
937 static void load_overlay_strings
P_ ((struct it
*, int));
938 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
939 struct display_pos
*));
940 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
941 Lisp_Object
, int, int, int, int));
942 static enum move_it_result
943 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
944 enum move_operation_enum
);
945 void move_it_vertically_backward
P_ ((struct it
*, int));
946 static void init_to_row_start
P_ ((struct it
*, struct window
*,
947 struct glyph_row
*));
948 static int init_to_row_end
P_ ((struct it
*, struct window
*,
949 struct glyph_row
*));
950 static void back_to_previous_line_start
P_ ((struct it
*));
951 static int forward_to_next_line_start
P_ ((struct it
*, int *));
952 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
954 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
955 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
956 static int number_of_chars
P_ ((unsigned char *, int));
957 static void compute_stop_pos
P_ ((struct it
*));
958 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
960 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
961 static EMACS_INT next_overlay_change
P_ ((EMACS_INT
));
962 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
963 Lisp_Object
, Lisp_Object
,
964 struct text_pos
*, int));
965 static int underlying_face_id
P_ ((struct it
*));
966 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
969 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
970 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
972 #ifdef HAVE_WINDOW_SYSTEM
974 static void update_tool_bar
P_ ((struct frame
*, int));
975 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
976 static int redisplay_tool_bar
P_ ((struct frame
*));
977 static void display_tool_bar_line
P_ ((struct it
*, int));
978 static void notice_overwritten_cursor
P_ ((struct window
*,
980 int, int, int, int));
984 #endif /* HAVE_WINDOW_SYSTEM */
987 /***********************************************************************
988 Window display dimensions
989 ***********************************************************************/
991 /* Return the bottom boundary y-position for text lines in window W.
992 This is the first y position at which a line cannot start.
993 It is relative to the top of the window.
995 This is the height of W minus the height of a mode line, if any. */
998 window_text_bottom_y (w
)
1001 int height
= WINDOW_TOTAL_HEIGHT (w
);
1003 if (WINDOW_WANTS_MODELINE_P (w
))
1004 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1008 /* Return the pixel width of display area AREA of window W. AREA < 0
1009 means return the total width of W, not including fringes to
1010 the left and right of the window. */
1013 window_box_width (w
, area
)
1017 int cols
= XFASTINT (w
->total_cols
);
1020 if (!w
->pseudo_window_p
)
1022 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1024 if (area
== TEXT_AREA
)
1026 if (INTEGERP (w
->left_margin_cols
))
1027 cols
-= XFASTINT (w
->left_margin_cols
);
1028 if (INTEGERP (w
->right_margin_cols
))
1029 cols
-= XFASTINT (w
->right_margin_cols
);
1030 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1032 else if (area
== LEFT_MARGIN_AREA
)
1034 cols
= (INTEGERP (w
->left_margin_cols
)
1035 ? XFASTINT (w
->left_margin_cols
) : 0);
1038 else if (area
== RIGHT_MARGIN_AREA
)
1040 cols
= (INTEGERP (w
->right_margin_cols
)
1041 ? XFASTINT (w
->right_margin_cols
) : 0);
1046 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1050 /* Return the pixel height of the display area of window W, not
1051 including mode lines of W, if any. */
1054 window_box_height (w
)
1057 struct frame
*f
= XFRAME (w
->frame
);
1058 int height
= WINDOW_TOTAL_HEIGHT (w
);
1060 xassert (height
>= 0);
1062 /* Note: the code below that determines the mode-line/header-line
1063 height is essentially the same as that contained in the macro
1064 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1065 the appropriate glyph row has its `mode_line_p' flag set,
1066 and if it doesn't, uses estimate_mode_line_height instead. */
1068 if (WINDOW_WANTS_MODELINE_P (w
))
1070 struct glyph_row
*ml_row
1071 = (w
->current_matrix
&& w
->current_matrix
->rows
1072 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1074 if (ml_row
&& ml_row
->mode_line_p
)
1075 height
-= ml_row
->height
;
1077 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1080 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1082 struct glyph_row
*hl_row
1083 = (w
->current_matrix
&& w
->current_matrix
->rows
1084 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1086 if (hl_row
&& hl_row
->mode_line_p
)
1087 height
-= hl_row
->height
;
1089 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1092 /* With a very small font and a mode-line that's taller than
1093 default, we might end up with a negative height. */
1094 return max (0, height
);
1097 /* Return the window-relative coordinate of the left edge of display
1098 area AREA of window W. AREA < 0 means return the left edge of the
1099 whole window, to the right of the left fringe of W. */
1102 window_box_left_offset (w
, area
)
1108 if (w
->pseudo_window_p
)
1111 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1113 if (area
== TEXT_AREA
)
1114 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1115 + window_box_width (w
, LEFT_MARGIN_AREA
));
1116 else if (area
== RIGHT_MARGIN_AREA
)
1117 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1118 + window_box_width (w
, LEFT_MARGIN_AREA
)
1119 + window_box_width (w
, TEXT_AREA
)
1120 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1122 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1123 else if (area
== LEFT_MARGIN_AREA
1124 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1125 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1131 /* Return the window-relative coordinate of the right edge of display
1132 area AREA of window W. AREA < 0 means return the left edge of the
1133 whole window, to the left of the right fringe of W. */
1136 window_box_right_offset (w
, area
)
1140 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1143 /* Return the frame-relative coordinate of the left edge of display
1144 area AREA of window W. AREA < 0 means return the left edge of the
1145 whole window, to the right of the left fringe of W. */
1148 window_box_left (w
, area
)
1152 struct frame
*f
= XFRAME (w
->frame
);
1155 if (w
->pseudo_window_p
)
1156 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1158 x
= (WINDOW_LEFT_EDGE_X (w
)
1159 + window_box_left_offset (w
, area
));
1165 /* Return the frame-relative coordinate of the right edge of display
1166 area AREA of window W. AREA < 0 means return the left edge of the
1167 whole window, to the left of the right fringe of W. */
1170 window_box_right (w
, area
)
1174 return window_box_left (w
, area
) + window_box_width (w
, area
);
1177 /* Get the bounding box of the display area AREA of window W, without
1178 mode lines, in frame-relative coordinates. AREA < 0 means the
1179 whole window, not including the left and right fringes of
1180 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1181 coordinates of the upper-left corner of the box. Return in
1182 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1185 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1188 int *box_x
, *box_y
, *box_width
, *box_height
;
1191 *box_width
= window_box_width (w
, area
);
1193 *box_height
= window_box_height (w
);
1195 *box_x
= window_box_left (w
, area
);
1198 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1199 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1200 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1205 /* Get the bounding box of the display area AREA of window W, without
1206 mode lines. AREA < 0 means the whole window, not including the
1207 left and right fringe of the window. Return in *TOP_LEFT_X
1208 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1209 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1210 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1214 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1215 bottom_right_x
, bottom_right_y
)
1218 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1220 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1222 *bottom_right_x
+= *top_left_x
;
1223 *bottom_right_y
+= *top_left_y
;
1228 /***********************************************************************
1230 ***********************************************************************/
1232 /* Return the bottom y-position of the line the iterator IT is in.
1233 This can modify IT's settings. */
1239 int line_height
= it
->max_ascent
+ it
->max_descent
;
1240 int line_top_y
= it
->current_y
;
1242 if (line_height
== 0)
1245 line_height
= last_height
;
1246 else if (IT_CHARPOS (*it
) < ZV
)
1248 move_it_by_lines (it
, 1, 1);
1249 line_height
= (it
->max_ascent
|| it
->max_descent
1250 ? it
->max_ascent
+ it
->max_descent
1255 struct glyph_row
*row
= it
->glyph_row
;
1257 /* Use the default character height. */
1258 it
->glyph_row
= NULL
;
1259 it
->what
= IT_CHARACTER
;
1262 PRODUCE_GLYPHS (it
);
1263 line_height
= it
->ascent
+ it
->descent
;
1264 it
->glyph_row
= row
;
1268 return line_top_y
+ line_height
;
1272 /* Return 1 if position CHARPOS is visible in window W.
1273 CHARPOS < 0 means return info about WINDOW_END position.
1274 If visible, set *X and *Y to pixel coordinates of top left corner.
1275 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1276 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1279 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1281 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1284 struct text_pos top
;
1286 struct buffer
*old_buffer
= NULL
;
1291 if (XBUFFER (w
->buffer
) != current_buffer
)
1293 old_buffer
= current_buffer
;
1294 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1297 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1299 /* Compute exact mode line heights. */
1300 if (WINDOW_WANTS_MODELINE_P (w
))
1301 current_mode_line_height
1302 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1303 current_buffer
->mode_line_format
);
1305 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1306 current_header_line_height
1307 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1308 current_buffer
->header_line_format
);
1310 start_display (&it
, w
, top
);
1311 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1312 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1314 /* Note that we may overshoot because of invisible text. */
1315 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1317 int top_x
= it
.current_x
;
1318 int top_y
= it
.current_y
;
1319 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1320 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1322 if (top_y
< window_top_y
)
1323 visible_p
= bottom_y
> window_top_y
;
1324 else if (top_y
< it
.last_visible_y
)
1328 if (it
.method
== GET_FROM_BUFFER
)
1330 Lisp_Object window
, prop
;
1332 XSETWINDOW (window
, w
);
1333 prop
= Fget_char_property (make_number (it
.position
.charpos
),
1334 Qinvisible
, window
);
1336 /* If charpos coincides with invisible text covered with an
1337 ellipsis, use the first glyph of the ellipsis to compute
1338 the pixel positions. */
1339 if (TEXT_PROP_MEANS_INVISIBLE (prop
) == 2)
1341 struct glyph_row
*row
= it
.glyph_row
;
1342 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1343 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
1346 for (; glyph
< end
&& glyph
->charpos
< charpos
; glyph
++)
1347 x
+= glyph
->pixel_width
;
1354 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1355 *rtop
= max (0, window_top_y
- top_y
);
1356 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1357 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1358 - max (top_y
, window_top_y
)));
1367 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1368 move_it_by_lines (&it
, 1, 0);
1369 if (charpos
< IT_CHARPOS (it
)
1370 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1373 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1375 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1376 *rtop
= max (0, -it2
.current_y
);
1377 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1378 - it
.last_visible_y
));
1379 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1381 - max (it2
.current_y
,
1382 WINDOW_HEADER_LINE_HEIGHT (w
))));
1388 set_buffer_internal_1 (old_buffer
);
1390 current_header_line_height
= current_mode_line_height
= -1;
1392 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1393 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1396 /* Debugging code. */
1398 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1399 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1401 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1408 /* Return the next character from STR which is MAXLEN bytes long.
1409 Return in *LEN the length of the character. This is like
1410 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1411 we find one, we return a `?', but with the length of the invalid
1415 string_char_and_length (str
, maxlen
, len
)
1416 const unsigned char *str
;
1421 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1422 if (!CHAR_VALID_P (c
, 1))
1423 /* We may not change the length here because other places in Emacs
1424 don't use this function, i.e. they silently accept invalid
1433 /* Given a position POS containing a valid character and byte position
1434 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1436 static struct text_pos
1437 string_pos_nchars_ahead (pos
, string
, nchars
)
1438 struct text_pos pos
;
1442 xassert (STRINGP (string
) && nchars
>= 0);
1444 if (STRING_MULTIBYTE (string
))
1446 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1447 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1452 string_char_and_length (p
, rest
, &len
);
1453 p
+= len
, rest
-= len
;
1454 xassert (rest
>= 0);
1456 BYTEPOS (pos
) += len
;
1460 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1466 /* Value is the text position, i.e. character and byte position,
1467 for character position CHARPOS in STRING. */
1469 static INLINE
struct text_pos
1470 string_pos (charpos
, string
)
1474 struct text_pos pos
;
1475 xassert (STRINGP (string
));
1476 xassert (charpos
>= 0);
1477 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1482 /* Value is a text position, i.e. character and byte position, for
1483 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1484 means recognize multibyte characters. */
1486 static struct text_pos
1487 c_string_pos (charpos
, s
, multibyte_p
)
1492 struct text_pos pos
;
1494 xassert (s
!= NULL
);
1495 xassert (charpos
>= 0);
1499 int rest
= strlen (s
), len
;
1501 SET_TEXT_POS (pos
, 0, 0);
1504 string_char_and_length (s
, rest
, &len
);
1505 s
+= len
, rest
-= len
;
1506 xassert (rest
>= 0);
1508 BYTEPOS (pos
) += len
;
1512 SET_TEXT_POS (pos
, charpos
, charpos
);
1518 /* Value is the number of characters in C string S. MULTIBYTE_P
1519 non-zero means recognize multibyte characters. */
1522 number_of_chars (s
, multibyte_p
)
1530 int rest
= strlen (s
), len
;
1531 unsigned char *p
= (unsigned char *) s
;
1533 for (nchars
= 0; rest
> 0; ++nchars
)
1535 string_char_and_length (p
, rest
, &len
);
1536 rest
-= len
, p
+= len
;
1540 nchars
= strlen (s
);
1546 /* Compute byte position NEWPOS->bytepos corresponding to
1547 NEWPOS->charpos. POS is a known position in string STRING.
1548 NEWPOS->charpos must be >= POS.charpos. */
1551 compute_string_pos (newpos
, pos
, string
)
1552 struct text_pos
*newpos
, pos
;
1555 xassert (STRINGP (string
));
1556 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1558 if (STRING_MULTIBYTE (string
))
1559 *newpos
= string_pos_nchars_ahead (pos
, string
,
1560 CHARPOS (*newpos
) - CHARPOS (pos
));
1562 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1566 Return an estimation of the pixel height of mode or top lines on
1567 frame F. FACE_ID specifies what line's height to estimate. */
1570 estimate_mode_line_height (f
, face_id
)
1572 enum face_id face_id
;
1574 #ifdef HAVE_WINDOW_SYSTEM
1575 if (FRAME_WINDOW_P (f
))
1577 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1579 /* This function is called so early when Emacs starts that the face
1580 cache and mode line face are not yet initialized. */
1581 if (FRAME_FACE_CACHE (f
))
1583 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1587 height
= FONT_HEIGHT (face
->font
);
1588 if (face
->box_line_width
> 0)
1589 height
+= 2 * face
->box_line_width
;
1600 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1601 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1602 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1603 not force the value into range. */
1606 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1608 register int pix_x
, pix_y
;
1610 NativeRectangle
*bounds
;
1614 #ifdef HAVE_WINDOW_SYSTEM
1615 if (FRAME_WINDOW_P (f
))
1617 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1618 even for negative values. */
1620 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1622 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1624 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1625 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1628 STORE_NATIVE_RECT (*bounds
,
1629 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1630 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1631 FRAME_COLUMN_WIDTH (f
) - 1,
1632 FRAME_LINE_HEIGHT (f
) - 1);
1638 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1639 pix_x
= FRAME_TOTAL_COLS (f
);
1643 else if (pix_y
> FRAME_LINES (f
))
1644 pix_y
= FRAME_LINES (f
);
1654 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1655 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1656 can't tell the positions because W's display is not up to date,
1660 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1663 int *frame_x
, *frame_y
;
1665 #ifdef HAVE_WINDOW_SYSTEM
1666 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1670 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1671 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1673 if (display_completed
)
1675 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1676 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1677 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1683 hpos
+= glyph
->pixel_width
;
1687 /* If first glyph is partially visible, its first visible position is still 0. */
1699 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1700 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1711 #ifdef HAVE_WINDOW_SYSTEM
1713 /* Find the glyph under window-relative coordinates X/Y in window W.
1714 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1715 strings. Return in *HPOS and *VPOS the row and column number of
1716 the glyph found. Return in *AREA the glyph area containing X.
1717 Value is a pointer to the glyph found or null if X/Y is not on
1718 text, or we can't tell because W's current matrix is not up to
1725 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1728 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1730 struct glyph
*glyph
, *end
;
1731 struct glyph_row
*row
= NULL
;
1734 /* Find row containing Y. Give up if some row is not enabled. */
1735 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1737 row
= MATRIX_ROW (w
->current_matrix
, i
);
1738 if (!row
->enabled_p
)
1740 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1747 /* Give up if Y is not in the window. */
1748 if (i
== w
->current_matrix
->nrows
)
1751 /* Get the glyph area containing X. */
1752 if (w
->pseudo_window_p
)
1759 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1761 *area
= LEFT_MARGIN_AREA
;
1762 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1764 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1767 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1771 *area
= RIGHT_MARGIN_AREA
;
1772 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1776 /* Find glyph containing X. */
1777 glyph
= row
->glyphs
[*area
];
1778 end
= glyph
+ row
->used
[*area
];
1780 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1782 x
-= glyph
->pixel_width
;
1792 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1795 *hpos
= glyph
- row
->glyphs
[*area
];
1801 Convert frame-relative x/y to coordinates relative to window W.
1802 Takes pseudo-windows into account. */
1805 frame_to_window_pixel_xy (w
, x
, y
)
1809 if (w
->pseudo_window_p
)
1811 /* A pseudo-window is always full-width, and starts at the
1812 left edge of the frame, plus a frame border. */
1813 struct frame
*f
= XFRAME (w
->frame
);
1814 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1815 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1819 *x
-= WINDOW_LEFT_EDGE_X (w
);
1820 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1825 Return in RECTS[] at most N clipping rectangles for glyph string S.
1826 Return the number of stored rectangles. */
1829 get_glyph_string_clip_rects (s
, rects
, n
)
1830 struct glyph_string
*s
;
1831 NativeRectangle
*rects
;
1839 if (s
->row
->full_width_p
)
1841 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1842 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1843 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1845 /* Unless displaying a mode or menu bar line, which are always
1846 fully visible, clip to the visible part of the row. */
1847 if (s
->w
->pseudo_window_p
)
1848 r
.height
= s
->row
->visible_height
;
1850 r
.height
= s
->height
;
1854 /* This is a text line that may be partially visible. */
1855 r
.x
= window_box_left (s
->w
, s
->area
);
1856 r
.width
= window_box_width (s
->w
, s
->area
);
1857 r
.height
= s
->row
->visible_height
;
1861 if (r
.x
< s
->clip_head
->x
)
1863 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1864 r
.width
-= s
->clip_head
->x
- r
.x
;
1867 r
.x
= s
->clip_head
->x
;
1870 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1872 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1873 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1878 /* If S draws overlapping rows, it's sufficient to use the top and
1879 bottom of the window for clipping because this glyph string
1880 intentionally draws over other lines. */
1881 if (s
->for_overlaps
)
1883 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1884 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1886 /* Alas, the above simple strategy does not work for the
1887 environments with anti-aliased text: if the same text is
1888 drawn onto the same place multiple times, it gets thicker.
1889 If the overlap we are processing is for the erased cursor, we
1890 take the intersection with the rectagle of the cursor. */
1891 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1893 XRectangle rc
, r_save
= r
;
1895 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1896 rc
.y
= s
->w
->phys_cursor
.y
;
1897 rc
.width
= s
->w
->phys_cursor_width
;
1898 rc
.height
= s
->w
->phys_cursor_height
;
1900 x_intersect_rectangles (&r_save
, &rc
, &r
);
1905 /* Don't use S->y for clipping because it doesn't take partially
1906 visible lines into account. For example, it can be negative for
1907 partially visible lines at the top of a window. */
1908 if (!s
->row
->full_width_p
1909 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1910 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1912 r
.y
= max (0, s
->row
->y
);
1914 /* If drawing a tool-bar window, draw it over the internal border
1915 at the top of the window. */
1916 if (WINDOWP (s
->f
->tool_bar_window
)
1917 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1918 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1921 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1923 /* If drawing the cursor, don't let glyph draw outside its
1924 advertised boundaries. Cleartype does this under some circumstances. */
1925 if (s
->hl
== DRAW_CURSOR
)
1927 struct glyph
*glyph
= s
->first_glyph
;
1932 r
.width
-= s
->x
- r
.x
;
1935 r
.width
= min (r
.width
, glyph
->pixel_width
);
1937 /* If r.y is below window bottom, ensure that we still see a cursor. */
1938 height
= min (glyph
->ascent
+ glyph
->descent
,
1939 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1940 max_y
= window_text_bottom_y (s
->w
) - height
;
1941 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1942 if (s
->ybase
- glyph
->ascent
> max_y
)
1949 /* Don't draw cursor glyph taller than our actual glyph. */
1950 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1951 if (height
< r
.height
)
1953 max_y
= r
.y
+ r
.height
;
1954 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1955 r
.height
= min (max_y
- r
.y
, height
);
1962 XRectangle r_save
= r
;
1964 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
1968 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1969 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1971 #ifdef CONVERT_FROM_XRECT
1972 CONVERT_FROM_XRECT (r
, *rects
);
1980 /* If we are processing overlapping and allowed to return
1981 multiple clipping rectangles, we exclude the row of the glyph
1982 string from the clipping rectangle. This is to avoid drawing
1983 the same text on the environment with anti-aliasing. */
1984 #ifdef CONVERT_FROM_XRECT
1987 XRectangle
*rs
= rects
;
1989 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
1991 if (s
->for_overlaps
& OVERLAPS_PRED
)
1994 if (r
.y
+ r
.height
> row_y
)
1997 rs
[i
].height
= row_y
- r
.y
;
2003 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2006 if (r
.y
< row_y
+ s
->row
->visible_height
)
2008 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2010 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2011 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2020 #ifdef CONVERT_FROM_XRECT
2021 for (i
= 0; i
< n
; i
++)
2022 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2029 Return in *NR the clipping rectangle for glyph string S. */
2032 get_glyph_string_clip_rect (s
, nr
)
2033 struct glyph_string
*s
;
2034 NativeRectangle
*nr
;
2036 get_glyph_string_clip_rects (s
, nr
, 1);
2041 Return the position and height of the phys cursor in window W.
2042 Set w->phys_cursor_width to width of phys cursor.
2046 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2048 struct glyph_row
*row
;
2049 struct glyph
*glyph
;
2050 int *xp
, *yp
, *heightp
;
2052 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2053 int x
, y
, wd
, h
, h0
, y0
;
2055 /* Compute the width of the rectangle to draw. If on a stretch
2056 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2057 rectangle as wide as the glyph, but use a canonical character
2059 wd
= glyph
->pixel_width
- 1;
2064 x
= w
->phys_cursor
.x
;
2071 if (glyph
->type
== STRETCH_GLYPH
2072 && !x_stretch_cursor_p
)
2073 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2074 w
->phys_cursor_width
= wd
;
2076 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2078 /* If y is below window bottom, ensure that we still see a cursor. */
2079 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2081 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2082 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2084 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2087 h
= max (h
- (y0
- y
) + 1, h0
);
2092 y0
= window_text_bottom_y (w
) - h0
;
2100 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2101 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2106 * Remember which glyph the mouse is over.
2110 remember_mouse_glyph (f
, gx
, gy
, rect
)
2113 NativeRectangle
*rect
;
2117 struct glyph_row
*r
, *gr
, *end_row
;
2118 enum window_part part
;
2119 enum glyph_row_area area
;
2120 int x
, y
, width
, height
;
2122 /* Try to determine frame pixel position and size of the glyph under
2123 frame pixel coordinates X/Y on frame F. */
2125 if (!f
->glyphs_initialized_p
2126 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2129 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2130 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2134 w
= XWINDOW (window
);
2135 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2136 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2138 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2139 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2141 if (w
->pseudo_window_p
)
2144 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2150 case ON_LEFT_MARGIN
:
2151 area
= LEFT_MARGIN_AREA
;
2154 case ON_RIGHT_MARGIN
:
2155 area
= RIGHT_MARGIN_AREA
;
2158 case ON_HEADER_LINE
:
2160 gr
= (part
== ON_HEADER_LINE
2161 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2162 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2165 goto text_glyph_row_found
;
2172 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2173 if (r
->y
+ r
->height
> y
)
2179 text_glyph_row_found
:
2182 struct glyph
*g
= gr
->glyphs
[area
];
2183 struct glyph
*end
= g
+ gr
->used
[area
];
2185 height
= gr
->height
;
2186 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2187 if (gx
+ g
->pixel_width
> x
)
2192 if (g
->type
== IMAGE_GLYPH
)
2194 /* Don't remember when mouse is over image, as
2195 image may have hot-spots. */
2196 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2199 width
= g
->pixel_width
;
2203 /* Use nominal char spacing at end of line. */
2205 gx
+= (x
/ width
) * width
;
2208 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2209 gx
+= window_box_left_offset (w
, area
);
2213 /* Use nominal line height at end of window. */
2214 gx
= (x
/ width
) * width
;
2216 gy
+= (y
/ height
) * height
;
2220 case ON_LEFT_FRINGE
:
2221 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2222 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2223 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2224 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2227 case ON_RIGHT_FRINGE
:
2228 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2229 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2230 : window_box_right_offset (w
, TEXT_AREA
));
2231 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2235 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2237 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2238 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2239 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2241 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2245 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2246 if (r
->y
+ r
->height
> y
)
2253 height
= gr
->height
;
2256 /* Use nominal line height at end of window. */
2258 gy
+= (y
/ height
) * height
;
2265 /* If there is no glyph under the mouse, then we divide the screen
2266 into a grid of the smallest glyph in the frame, and use that
2269 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2270 round down even for negative values. */
2276 gx
= (gx
/ width
) * width
;
2277 gy
= (gy
/ height
) * height
;
2282 gx
+= WINDOW_LEFT_EDGE_X (w
);
2283 gy
+= WINDOW_TOP_EDGE_Y (w
);
2286 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2288 /* Visible feedback for debugging. */
2291 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2292 f
->output_data
.x
->normal_gc
,
2293 gx
, gy
, width
, height
);
2299 #endif /* HAVE_WINDOW_SYSTEM */
2302 /***********************************************************************
2303 Lisp form evaluation
2304 ***********************************************************************/
2306 /* Error handler for safe_eval and safe_call. */
2309 safe_eval_handler (arg
)
2312 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2317 /* Evaluate SEXPR and return the result, or nil if something went
2318 wrong. Prevent redisplay during the evaluation. */
2320 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2321 Return the result, or nil if something went wrong. Prevent
2322 redisplay during the evaluation. */
2325 safe_call (nargs
, args
)
2331 if (inhibit_eval_during_redisplay
)
2335 int count
= SPECPDL_INDEX ();
2336 struct gcpro gcpro1
;
2339 gcpro1
.nvars
= nargs
;
2340 specbind (Qinhibit_redisplay
, Qt
);
2341 /* Use Qt to ensure debugger does not run,
2342 so there is no possibility of wanting to redisplay. */
2343 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2346 val
= unbind_to (count
, val
);
2353 /* Call function FN with one argument ARG.
2354 Return the result, or nil if something went wrong. */
2357 safe_call1 (fn
, arg
)
2358 Lisp_Object fn
, arg
;
2360 Lisp_Object args
[2];
2363 return safe_call (2, args
);
2366 static Lisp_Object Qeval
;
2369 safe_eval (Lisp_Object sexpr
)
2371 return safe_call1 (Qeval
, sexpr
);
2374 /* Call function FN with one argument ARG.
2375 Return the result, or nil if something went wrong. */
2378 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2380 Lisp_Object args
[3];
2384 return safe_call (3, args
);
2389 /***********************************************************************
2391 ***********************************************************************/
2395 /* Define CHECK_IT to perform sanity checks on iterators.
2396 This is for debugging. It is too slow to do unconditionally. */
2402 if (it
->method
== GET_FROM_STRING
)
2404 xassert (STRINGP (it
->string
));
2405 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2409 xassert (IT_STRING_CHARPOS (*it
) < 0);
2410 if (it
->method
== GET_FROM_BUFFER
)
2412 /* Check that character and byte positions agree. */
2413 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2418 xassert (it
->current
.dpvec_index
>= 0);
2420 xassert (it
->current
.dpvec_index
< 0);
2423 #define CHECK_IT(IT) check_it ((IT))
2427 #define CHECK_IT(IT) (void) 0
2434 /* Check that the window end of window W is what we expect it
2435 to be---the last row in the current matrix displaying text. */
2438 check_window_end (w
)
2441 if (!MINI_WINDOW_P (w
)
2442 && !NILP (w
->window_end_valid
))
2444 struct glyph_row
*row
;
2445 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2446 XFASTINT (w
->window_end_vpos
)),
2448 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2449 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2453 #define CHECK_WINDOW_END(W) check_window_end ((W))
2455 #else /* not GLYPH_DEBUG */
2457 #define CHECK_WINDOW_END(W) (void) 0
2459 #endif /* not GLYPH_DEBUG */
2463 /***********************************************************************
2464 Iterator initialization
2465 ***********************************************************************/
2467 /* Initialize IT for displaying current_buffer in window W, starting
2468 at character position CHARPOS. CHARPOS < 0 means that no buffer
2469 position is specified which is useful when the iterator is assigned
2470 a position later. BYTEPOS is the byte position corresponding to
2471 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2473 If ROW is not null, calls to produce_glyphs with IT as parameter
2474 will produce glyphs in that row.
2476 BASE_FACE_ID is the id of a base face to use. It must be one of
2477 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2478 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2479 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2481 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2482 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2483 will be initialized to use the corresponding mode line glyph row of
2484 the desired matrix of W. */
2487 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2490 int charpos
, bytepos
;
2491 struct glyph_row
*row
;
2492 enum face_id base_face_id
;
2494 int highlight_region_p
;
2495 enum face_id remapped_base_face_id
= base_face_id
;
2497 /* Some precondition checks. */
2498 xassert (w
!= NULL
&& it
!= NULL
);
2499 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2502 /* If face attributes have been changed since the last redisplay,
2503 free realized faces now because they depend on face definitions
2504 that might have changed. Don't free faces while there might be
2505 desired matrices pending which reference these faces. */
2506 if (face_change_count
&& !inhibit_free_realized_faces
)
2508 face_change_count
= 0;
2509 free_all_realized_faces (Qnil
);
2512 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2513 if (! NILP (Vface_remapping_alist
))
2514 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2516 /* Use one of the mode line rows of W's desired matrix if
2520 if (base_face_id
== MODE_LINE_FACE_ID
2521 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2522 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2523 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2524 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2528 bzero (it
, sizeof *it
);
2529 it
->current
.overlay_string_index
= -1;
2530 it
->current
.dpvec_index
= -1;
2531 it
->base_face_id
= remapped_base_face_id
;
2533 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2535 /* The window in which we iterate over current_buffer: */
2536 XSETWINDOW (it
->window
, w
);
2538 it
->f
= XFRAME (w
->frame
);
2540 /* Extra space between lines (on window systems only). */
2541 if (base_face_id
== DEFAULT_FACE_ID
2542 && FRAME_WINDOW_P (it
->f
))
2544 if (NATNUMP (current_buffer
->extra_line_spacing
))
2545 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2546 else if (FLOATP (current_buffer
->extra_line_spacing
))
2547 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2548 * FRAME_LINE_HEIGHT (it
->f
));
2549 else if (it
->f
->extra_line_spacing
> 0)
2550 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2551 it
->max_extra_line_spacing
= 0;
2554 /* If realized faces have been removed, e.g. because of face
2555 attribute changes of named faces, recompute them. When running
2556 in batch mode, the face cache of the initial frame is null. If
2557 we happen to get called, make a dummy face cache. */
2558 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2559 init_frame_faces (it
->f
);
2560 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2561 recompute_basic_faces (it
->f
);
2563 /* Current value of the `slice', `space-width', and 'height' properties. */
2564 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2565 it
->space_width
= Qnil
;
2566 it
->font_height
= Qnil
;
2567 it
->override_ascent
= -1;
2569 /* Are control characters displayed as `^C'? */
2570 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2572 /* -1 means everything between a CR and the following line end
2573 is invisible. >0 means lines indented more than this value are
2575 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2576 ? XFASTINT (current_buffer
->selective_display
)
2577 : (!NILP (current_buffer
->selective_display
)
2579 it
->selective_display_ellipsis_p
2580 = !NILP (current_buffer
->selective_display_ellipses
);
2582 /* Display table to use. */
2583 it
->dp
= window_display_table (w
);
2585 /* Are multibyte characters enabled in current_buffer? */
2586 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2588 /* Non-zero if we should highlight the region. */
2590 = (!NILP (Vtransient_mark_mode
)
2591 && !NILP (current_buffer
->mark_active
)
2592 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2594 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2595 start and end of a visible region in window IT->w. Set both to
2596 -1 to indicate no region. */
2597 if (highlight_region_p
2598 /* Maybe highlight only in selected window. */
2599 && (/* Either show region everywhere. */
2600 highlight_nonselected_windows
2601 /* Or show region in the selected window. */
2602 || w
== XWINDOW (selected_window
)
2603 /* Or show the region if we are in the mini-buffer and W is
2604 the window the mini-buffer refers to. */
2605 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2606 && WINDOWP (minibuf_selected_window
)
2607 && w
== XWINDOW (minibuf_selected_window
))))
2609 int charpos
= marker_position (current_buffer
->mark
);
2610 it
->region_beg_charpos
= min (PT
, charpos
);
2611 it
->region_end_charpos
= max (PT
, charpos
);
2614 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2616 /* Get the position at which the redisplay_end_trigger hook should
2617 be run, if it is to be run at all. */
2618 if (MARKERP (w
->redisplay_end_trigger
)
2619 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2620 it
->redisplay_end_trigger_charpos
2621 = marker_position (w
->redisplay_end_trigger
);
2622 else if (INTEGERP (w
->redisplay_end_trigger
))
2623 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2625 /* Correct bogus values of tab_width. */
2626 it
->tab_width
= XINT (current_buffer
->tab_width
);
2627 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2630 /* Are lines in the display truncated? */
2631 it
->truncate_lines_p
2632 = (base_face_id
!= DEFAULT_FACE_ID
2633 || XINT (it
->w
->hscroll
)
2634 || (truncate_partial_width_windows
2635 && !WINDOW_FULL_WIDTH_P (it
->w
))
2636 || !NILP (current_buffer
->truncate_lines
));
2638 /* Get dimensions of truncation and continuation glyphs. These are
2639 displayed as fringe bitmaps under X, so we don't need them for such
2641 if (!FRAME_WINDOW_P (it
->f
))
2643 if (it
->truncate_lines_p
)
2645 /* We will need the truncation glyph. */
2646 xassert (it
->glyph_row
== NULL
);
2647 produce_special_glyphs (it
, IT_TRUNCATION
);
2648 it
->truncation_pixel_width
= it
->pixel_width
;
2652 /* We will need the continuation glyph. */
2653 xassert (it
->glyph_row
== NULL
);
2654 produce_special_glyphs (it
, IT_CONTINUATION
);
2655 it
->continuation_pixel_width
= it
->pixel_width
;
2658 /* Reset these values to zero because the produce_special_glyphs
2659 above has changed them. */
2660 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2661 it
->phys_ascent
= it
->phys_descent
= 0;
2664 /* Set this after getting the dimensions of truncation and
2665 continuation glyphs, so that we don't produce glyphs when calling
2666 produce_special_glyphs, above. */
2667 it
->glyph_row
= row
;
2668 it
->area
= TEXT_AREA
;
2670 /* Get the dimensions of the display area. The display area
2671 consists of the visible window area plus a horizontally scrolled
2672 part to the left of the window. All x-values are relative to the
2673 start of this total display area. */
2674 if (base_face_id
!= DEFAULT_FACE_ID
)
2676 /* Mode lines, menu bar in terminal frames. */
2677 it
->first_visible_x
= 0;
2678 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2683 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2684 it
->last_visible_x
= (it
->first_visible_x
2685 + window_box_width (w
, TEXT_AREA
));
2687 /* If we truncate lines, leave room for the truncator glyph(s) at
2688 the right margin. Otherwise, leave room for the continuation
2689 glyph(s). Truncation and continuation glyphs are not inserted
2690 for window-based redisplay. */
2691 if (!FRAME_WINDOW_P (it
->f
))
2693 if (it
->truncate_lines_p
)
2694 it
->last_visible_x
-= it
->truncation_pixel_width
;
2696 it
->last_visible_x
-= it
->continuation_pixel_width
;
2699 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2700 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2703 /* Leave room for a border glyph. */
2704 if (!FRAME_WINDOW_P (it
->f
)
2705 && !WINDOW_RIGHTMOST_P (it
->w
))
2706 it
->last_visible_x
-= 1;
2708 it
->last_visible_y
= window_text_bottom_y (w
);
2710 /* For mode lines and alike, arrange for the first glyph having a
2711 left box line if the face specifies a box. */
2712 if (base_face_id
!= DEFAULT_FACE_ID
)
2716 it
->face_id
= remapped_base_face_id
;
2718 /* If we have a boxed mode line, make the first character appear
2719 with a left box line. */
2720 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2721 if (face
->box
!= FACE_NO_BOX
)
2722 it
->start_of_box_run_p
= 1;
2725 /* If a buffer position was specified, set the iterator there,
2726 getting overlays and face properties from that position. */
2727 if (charpos
>= BUF_BEG (current_buffer
))
2729 it
->end_charpos
= ZV
;
2731 IT_CHARPOS (*it
) = charpos
;
2733 /* Compute byte position if not specified. */
2734 if (bytepos
< charpos
)
2735 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2737 IT_BYTEPOS (*it
) = bytepos
;
2739 it
->start
= it
->current
;
2741 /* Compute faces etc. */
2742 reseat (it
, it
->current
.pos
, 1);
2749 /* Initialize IT for the display of window W with window start POS. */
2752 start_display (it
, w
, pos
)
2755 struct text_pos pos
;
2757 struct glyph_row
*row
;
2758 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2760 row
= w
->desired_matrix
->rows
+ first_vpos
;
2761 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2762 it
->first_vpos
= first_vpos
;
2764 /* Don't reseat to previous visible line start if current start
2765 position is in a string or image. */
2766 if (it
->method
== GET_FROM_BUFFER
&& !it
->truncate_lines_p
)
2768 int start_at_line_beg_p
;
2769 int first_y
= it
->current_y
;
2771 /* If window start is not at a line start, skip forward to POS to
2772 get the correct continuation lines width. */
2773 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2774 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2775 if (!start_at_line_beg_p
)
2779 reseat_at_previous_visible_line_start (it
);
2780 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2782 new_x
= it
->current_x
+ it
->pixel_width
;
2784 /* If lines are continued, this line may end in the middle
2785 of a multi-glyph character (e.g. a control character
2786 displayed as \003, or in the middle of an overlay
2787 string). In this case move_it_to above will not have
2788 taken us to the start of the continuation line but to the
2789 end of the continued line. */
2790 if (it
->current_x
> 0
2791 && !it
->truncate_lines_p
/* Lines are continued. */
2792 && (/* And glyph doesn't fit on the line. */
2793 new_x
> it
->last_visible_x
2794 /* Or it fits exactly and we're on a window
2796 || (new_x
== it
->last_visible_x
2797 && FRAME_WINDOW_P (it
->f
))))
2799 if (it
->current
.dpvec_index
>= 0
2800 || it
->current
.overlay_string_index
>= 0)
2802 set_iterator_to_next (it
, 1);
2803 move_it_in_display_line_to (it
, -1, -1, 0);
2806 it
->continuation_lines_width
+= it
->current_x
;
2809 /* We're starting a new display line, not affected by the
2810 height of the continued line, so clear the appropriate
2811 fields in the iterator structure. */
2812 it
->max_ascent
= it
->max_descent
= 0;
2813 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2815 it
->current_y
= first_y
;
2817 it
->current_x
= it
->hpos
= 0;
2821 #if 0 /* Don't assert the following because start_display is sometimes
2822 called intentionally with a window start that is not at a
2823 line start. Please leave this code in as a comment. */
2825 /* Window start should be on a line start, now. */
2826 xassert (it
->continuation_lines_width
2827 || IT_CHARPOS (it
) == BEGV
2828 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2833 /* Return 1 if POS is a position in ellipses displayed for invisible
2834 text. W is the window we display, for text property lookup. */
2837 in_ellipses_for_invisible_text_p (pos
, w
)
2838 struct display_pos
*pos
;
2841 Lisp_Object prop
, window
;
2843 int charpos
= CHARPOS (pos
->pos
);
2845 /* If POS specifies a position in a display vector, this might
2846 be for an ellipsis displayed for invisible text. We won't
2847 get the iterator set up for delivering that ellipsis unless
2848 we make sure that it gets aware of the invisible text. */
2849 if (pos
->dpvec_index
>= 0
2850 && pos
->overlay_string_index
< 0
2851 && CHARPOS (pos
->string_pos
) < 0
2853 && (XSETWINDOW (window
, w
),
2854 prop
= Fget_char_property (make_number (charpos
),
2855 Qinvisible
, window
),
2856 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2858 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2860 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2867 /* Initialize IT for stepping through current_buffer in window W,
2868 starting at position POS that includes overlay string and display
2869 vector/ control character translation position information. Value
2870 is zero if there are overlay strings with newlines at POS. */
2873 init_from_display_pos (it
, w
, pos
)
2876 struct display_pos
*pos
;
2878 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2879 int i
, overlay_strings_with_newlines
= 0;
2881 /* If POS specifies a position in a display vector, this might
2882 be for an ellipsis displayed for invisible text. We won't
2883 get the iterator set up for delivering that ellipsis unless
2884 we make sure that it gets aware of the invisible text. */
2885 if (in_ellipses_for_invisible_text_p (pos
, w
))
2891 /* Keep in mind: the call to reseat in init_iterator skips invisible
2892 text, so we might end up at a position different from POS. This
2893 is only a problem when POS is a row start after a newline and an
2894 overlay starts there with an after-string, and the overlay has an
2895 invisible property. Since we don't skip invisible text in
2896 display_line and elsewhere immediately after consuming the
2897 newline before the row start, such a POS will not be in a string,
2898 but the call to init_iterator below will move us to the
2900 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2902 /* This only scans the current chunk -- it should scan all chunks.
2903 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2904 to 16 in 22.1 to make this a lesser problem. */
2905 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2907 const char *s
= SDATA (it
->overlay_strings
[i
]);
2908 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2910 while (s
< e
&& *s
!= '\n')
2915 overlay_strings_with_newlines
= 1;
2920 /* If position is within an overlay string, set up IT to the right
2922 if (pos
->overlay_string_index
>= 0)
2926 /* If the first overlay string happens to have a `display'
2927 property for an image, the iterator will be set up for that
2928 image, and we have to undo that setup first before we can
2929 correct the overlay string index. */
2930 if (it
->method
== GET_FROM_IMAGE
)
2933 /* We already have the first chunk of overlay strings in
2934 IT->overlay_strings. Load more until the one for
2935 pos->overlay_string_index is in IT->overlay_strings. */
2936 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2938 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2939 it
->current
.overlay_string_index
= 0;
2942 load_overlay_strings (it
, 0);
2943 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2947 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2948 relative_index
= (it
->current
.overlay_string_index
2949 % OVERLAY_STRING_CHUNK_SIZE
);
2950 it
->string
= it
->overlay_strings
[relative_index
];
2951 xassert (STRINGP (it
->string
));
2952 it
->current
.string_pos
= pos
->string_pos
;
2953 it
->method
= GET_FROM_STRING
;
2956 #if 0 /* This is bogus because POS not having an overlay string
2957 position does not mean it's after the string. Example: A
2958 line starting with a before-string and initialization of IT
2959 to the previous row's end position. */
2960 else if (it
->current
.overlay_string_index
>= 0)
2962 /* If POS says we're already after an overlay string ending at
2963 POS, make sure to pop the iterator because it will be in
2964 front of that overlay string. When POS is ZV, we've thereby
2965 also ``processed'' overlay strings at ZV. */
2968 xassert (it
->current
.overlay_string_index
== -1);
2969 xassert (it
->method
== GET_FROM_BUFFER
);
2970 if (CHARPOS (pos
->pos
) == ZV
)
2971 it
->overlay_strings_at_end_processed_p
= 1;
2975 if (CHARPOS (pos
->string_pos
) >= 0)
2977 /* Recorded position is not in an overlay string, but in another
2978 string. This can only be a string from a `display' property.
2979 IT should already be filled with that string. */
2980 it
->current
.string_pos
= pos
->string_pos
;
2981 xassert (STRINGP (it
->string
));
2984 /* Restore position in display vector translations, control
2985 character translations or ellipses. */
2986 if (pos
->dpvec_index
>= 0)
2988 if (it
->dpvec
== NULL
)
2989 get_next_display_element (it
);
2990 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2991 it
->current
.dpvec_index
= pos
->dpvec_index
;
2995 return !overlay_strings_with_newlines
;
2999 /* Initialize IT for stepping through current_buffer in window W
3000 starting at ROW->start. */
3003 init_to_row_start (it
, w
, row
)
3006 struct glyph_row
*row
;
3008 init_from_display_pos (it
, w
, &row
->start
);
3009 it
->start
= row
->start
;
3010 it
->continuation_lines_width
= row
->continuation_lines_width
;
3015 /* Initialize IT for stepping through current_buffer in window W
3016 starting in the line following ROW, i.e. starting at ROW->end.
3017 Value is zero if there are overlay strings with newlines at ROW's
3021 init_to_row_end (it
, w
, row
)
3024 struct glyph_row
*row
;
3028 if (init_from_display_pos (it
, w
, &row
->end
))
3030 if (row
->continued_p
)
3031 it
->continuation_lines_width
3032 = row
->continuation_lines_width
+ row
->pixel_width
;
3043 /***********************************************************************
3045 ***********************************************************************/
3047 /* Called when IT reaches IT->stop_charpos. Handle text property and
3048 overlay changes. Set IT->stop_charpos to the next position where
3055 enum prop_handled handled
;
3056 int handle_overlay_change_p
;
3060 it
->current
.dpvec_index
= -1;
3061 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3062 it
->ignore_overlay_strings_at_pos_p
= 0;
3064 /* Use face of preceding text for ellipsis (if invisible) */
3065 if (it
->selective_display_ellipsis_p
)
3066 it
->saved_face_id
= it
->face_id
;
3070 handled
= HANDLED_NORMALLY
;
3072 /* Call text property handlers. */
3073 for (p
= it_props
; p
->handler
; ++p
)
3075 handled
= p
->handler (it
);
3077 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3079 else if (handled
== HANDLED_RETURN
)
3081 /* We still want to show before and after strings from
3082 overlays even if the actual buffer text is replaced. */
3083 if (!handle_overlay_change_p
|| it
->sp
> 1)
3085 if (!get_overlay_strings_1 (it
, 0, 0))
3087 it
->ignore_overlay_strings_at_pos_p
= 1;
3088 it
->string_from_display_prop_p
= 0;
3089 handle_overlay_change_p
= 0;
3090 handled
= HANDLED_RECOMPUTE_PROPS
;
3093 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3094 handle_overlay_change_p
= 0;
3097 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3099 /* Don't check for overlay strings below when set to deliver
3100 characters from a display vector. */
3101 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3102 handle_overlay_change_p
= 0;
3104 /* Handle overlay changes.
3105 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3106 if it finds overlays. */
3107 if (handle_overlay_change_p
)
3108 handled
= handle_overlay_change (it
);
3111 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3113 /* Determine where to stop next. */
3114 if (handled
== HANDLED_NORMALLY
)
3115 compute_stop_pos (it
);
3119 /* Compute IT->stop_charpos from text property and overlay change
3120 information for IT's current position. */
3123 compute_stop_pos (it
)
3126 register INTERVAL iv
, next_iv
;
3127 Lisp_Object object
, limit
, position
;
3129 /* If nowhere else, stop at the end. */
3130 it
->stop_charpos
= it
->end_charpos
;
3132 if (STRINGP (it
->string
))
3134 /* Strings are usually short, so don't limit the search for
3136 object
= it
->string
;
3138 position
= make_number (IT_STRING_CHARPOS (*it
));
3144 /* If next overlay change is in front of the current stop pos
3145 (which is IT->end_charpos), stop there. Note: value of
3146 next_overlay_change is point-max if no overlay change
3148 charpos
= next_overlay_change (IT_CHARPOS (*it
));
3149 if (charpos
< it
->stop_charpos
)
3150 it
->stop_charpos
= charpos
;
3152 /* If showing the region, we have to stop at the region
3153 start or end because the face might change there. */
3154 if (it
->region_beg_charpos
> 0)
3156 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3157 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3158 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3159 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3162 /* Set up variables for computing the stop position from text
3163 property changes. */
3164 XSETBUFFER (object
, current_buffer
);
3165 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3166 position
= make_number (IT_CHARPOS (*it
));
3170 /* Get the interval containing IT's position. Value is a null
3171 interval if there isn't such an interval. */
3172 iv
= validate_interval_range (object
, &position
, &position
, 0);
3173 if (!NULL_INTERVAL_P (iv
))
3175 Lisp_Object values_here
[LAST_PROP_IDX
];
3178 /* Get properties here. */
3179 for (p
= it_props
; p
->handler
; ++p
)
3180 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3182 /* Look for an interval following iv that has different
3184 for (next_iv
= next_interval (iv
);
3185 (!NULL_INTERVAL_P (next_iv
)
3187 || XFASTINT (limit
) > next_iv
->position
));
3188 next_iv
= next_interval (next_iv
))
3190 for (p
= it_props
; p
->handler
; ++p
)
3192 Lisp_Object new_value
;
3194 new_value
= textget (next_iv
->plist
, *p
->name
);
3195 if (!EQ (values_here
[p
->idx
], new_value
))
3203 if (!NULL_INTERVAL_P (next_iv
))
3205 if (INTEGERP (limit
)
3206 && next_iv
->position
>= XFASTINT (limit
))
3207 /* No text property change up to limit. */
3208 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3210 /* Text properties change in next_iv. */
3211 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3215 xassert (STRINGP (it
->string
)
3216 || (it
->stop_charpos
>= BEGV
3217 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3221 /* Return the position of the next overlay change after POS in
3222 current_buffer. Value is point-max if no overlay change
3223 follows. This is like `next-overlay-change' but doesn't use
3227 next_overlay_change (pos
)
3232 Lisp_Object
*overlays
;
3235 /* Get all overlays at the given position. */
3236 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3238 /* If any of these overlays ends before endpos,
3239 use its ending point instead. */
3240 for (i
= 0; i
< noverlays
; ++i
)
3245 oend
= OVERLAY_END (overlays
[i
]);
3246 oendpos
= OVERLAY_POSITION (oend
);
3247 endpos
= min (endpos
, oendpos
);
3255 /***********************************************************************
3257 ***********************************************************************/
3259 /* Handle changes in the `fontified' property of the current buffer by
3260 calling hook functions from Qfontification_functions to fontify
3263 static enum prop_handled
3264 handle_fontified_prop (it
)
3267 Lisp_Object prop
, pos
;
3268 enum prop_handled handled
= HANDLED_NORMALLY
;
3270 if (!NILP (Vmemory_full
))
3273 /* Get the value of the `fontified' property at IT's current buffer
3274 position. (The `fontified' property doesn't have a special
3275 meaning in strings.) If the value is nil, call functions from
3276 Qfontification_functions. */
3277 if (!STRINGP (it
->string
)
3279 && !NILP (Vfontification_functions
)
3280 && !NILP (Vrun_hooks
)
3281 && (pos
= make_number (IT_CHARPOS (*it
)),
3282 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3283 /* Ignore the special cased nil value always present at EOB since
3284 no amount of fontifying will be able to change it. */
3285 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3287 int count
= SPECPDL_INDEX ();
3290 val
= Vfontification_functions
;
3291 specbind (Qfontification_functions
, Qnil
);
3293 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3294 safe_call1 (val
, pos
);
3297 Lisp_Object globals
, fn
;
3298 struct gcpro gcpro1
, gcpro2
;
3301 GCPRO2 (val
, globals
);
3303 for (; CONSP (val
); val
= XCDR (val
))
3309 /* A value of t indicates this hook has a local
3310 binding; it means to run the global binding too.
3311 In a global value, t should not occur. If it
3312 does, we must ignore it to avoid an endless
3314 for (globals
= Fdefault_value (Qfontification_functions
);
3316 globals
= XCDR (globals
))
3318 fn
= XCAR (globals
);
3320 safe_call1 (fn
, pos
);
3324 safe_call1 (fn
, pos
);
3330 unbind_to (count
, Qnil
);
3332 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3333 something. This avoids an endless loop if they failed to
3334 fontify the text for which reason ever. */
3335 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3336 handled
= HANDLED_RECOMPUTE_PROPS
;
3344 /***********************************************************************
3346 ***********************************************************************/
3348 /* Set up iterator IT from face properties at its current position.
3349 Called from handle_stop. */
3351 static enum prop_handled
3352 handle_face_prop (it
)
3356 EMACS_INT next_stop
;
3358 if (!STRINGP (it
->string
))
3361 = face_at_buffer_position (it
->w
,
3363 it
->region_beg_charpos
,
3364 it
->region_end_charpos
,
3367 + TEXT_PROP_DISTANCE_LIMIT
),
3370 /* Is this a start of a run of characters with box face?
3371 Caveat: this can be called for a freshly initialized
3372 iterator; face_id is -1 in this case. We know that the new
3373 face will not change until limit, i.e. if the new face has a
3374 box, all characters up to limit will have one. But, as
3375 usual, we don't know whether limit is really the end. */
3376 if (new_face_id
!= it
->face_id
)
3378 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3380 /* If new face has a box but old face has not, this is
3381 the start of a run of characters with box, i.e. it has
3382 a shadow on the left side. The value of face_id of the
3383 iterator will be -1 if this is the initial call that gets
3384 the face. In this case, we have to look in front of IT's
3385 position and see whether there is a face != new_face_id. */
3386 it
->start_of_box_run_p
3387 = (new_face
->box
!= FACE_NO_BOX
3388 && (it
->face_id
>= 0
3389 || IT_CHARPOS (*it
) == BEG
3390 || new_face_id
!= face_before_it_pos (it
)));
3391 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3396 int base_face_id
, bufpos
;
3398 Lisp_Object from_overlay
3399 = (it
->current
.overlay_string_index
>= 0
3400 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3403 /* See if we got to this string directly or indirectly from
3404 an overlay property. That includes the before-string or
3405 after-string of an overlay, strings in display properties
3406 provided by an overlay, their text properties, etc.
3408 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3409 if (! NILP (from_overlay
))
3410 for (i
= it
->sp
- 1; i
>= 0; i
--)
3412 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3414 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3415 else if (! NILP (it
->stack
[i
].from_overlay
))
3416 from_overlay
= it
->stack
[i
].from_overlay
;
3418 if (!NILP (from_overlay
))
3422 if (! NILP (from_overlay
))
3424 bufpos
= IT_CHARPOS (*it
);
3425 /* For a string from an overlay, the base face depends
3426 only on text properties and ignores overlays. */
3428 = face_for_overlay_string (it
->w
,
3430 it
->region_beg_charpos
,
3431 it
->region_end_charpos
,
3434 + TEXT_PROP_DISTANCE_LIMIT
),
3442 /* For strings from a `display' property, use the face at
3443 IT's current buffer position as the base face to merge
3444 with, so that overlay strings appear in the same face as
3445 surrounding text, unless they specify their own
3447 base_face_id
= underlying_face_id (it
);
3450 new_face_id
= face_at_string_position (it
->w
,
3452 IT_STRING_CHARPOS (*it
),
3454 it
->region_beg_charpos
,
3455 it
->region_end_charpos
,
3459 #if 0 /* This shouldn't be neccessary. Let's check it. */
3460 /* If IT is used to display a mode line we would really like to
3461 use the mode line face instead of the frame's default face. */
3462 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3463 && new_face_id
== DEFAULT_FACE_ID
)
3464 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3467 /* Is this a start of a run of characters with box? Caveat:
3468 this can be called for a freshly allocated iterator; face_id
3469 is -1 is this case. We know that the new face will not
3470 change until the next check pos, i.e. if the new face has a
3471 box, all characters up to that position will have a
3472 box. But, as usual, we don't know whether that position
3473 is really the end. */
3474 if (new_face_id
!= it
->face_id
)
3476 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3477 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3479 /* If new face has a box but old face hasn't, this is the
3480 start of a run of characters with box, i.e. it has a
3481 shadow on the left side. */
3482 it
->start_of_box_run_p
3483 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3484 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3488 it
->face_id
= new_face_id
;
3489 return HANDLED_NORMALLY
;
3493 /* Return the ID of the face ``underlying'' IT's current position,
3494 which is in a string. If the iterator is associated with a
3495 buffer, return the face at IT's current buffer position.
3496 Otherwise, use the iterator's base_face_id. */
3499 underlying_face_id (it
)
3502 int face_id
= it
->base_face_id
, i
;
3504 xassert (STRINGP (it
->string
));
3506 for (i
= it
->sp
- 1; i
>= 0; --i
)
3507 if (NILP (it
->stack
[i
].string
))
3508 face_id
= it
->stack
[i
].face_id
;
3514 /* Compute the face one character before or after the current position
3515 of IT. BEFORE_P non-zero means get the face in front of IT's
3516 position. Value is the id of the face. */
3519 face_before_or_after_it_pos (it
, before_p
)
3524 EMACS_INT next_check_charpos
;
3525 struct text_pos pos
;
3527 xassert (it
->s
== NULL
);
3529 if (STRINGP (it
->string
))
3531 int bufpos
, base_face_id
;
3533 /* No face change past the end of the string (for the case
3534 we are padding with spaces). No face change before the
3536 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3537 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3540 /* Set pos to the position before or after IT's current position. */
3542 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3544 /* For composition, we must check the character after the
3546 pos
= (it
->what
== IT_COMPOSITION
3547 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3548 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3550 if (it
->current
.overlay_string_index
>= 0)
3551 bufpos
= IT_CHARPOS (*it
);
3555 base_face_id
= underlying_face_id (it
);
3557 /* Get the face for ASCII, or unibyte. */
3558 face_id
= face_at_string_position (it
->w
,
3562 it
->region_beg_charpos
,
3563 it
->region_end_charpos
,
3564 &next_check_charpos
,
3567 /* Correct the face for charsets different from ASCII. Do it
3568 for the multibyte case only. The face returned above is
3569 suitable for unibyte text if IT->string is unibyte. */
3570 if (STRING_MULTIBYTE (it
->string
))
3572 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3573 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3575 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3577 c
= string_char_and_length (p
, rest
, &len
);
3578 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3583 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3584 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3587 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3588 pos
= it
->current
.pos
;
3591 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3594 if (it
->what
== IT_COMPOSITION
)
3595 /* For composition, we must check the position after the
3597 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3599 INC_TEXT_POS (pos
, it
->multibyte_p
);
3602 /* Determine face for CHARSET_ASCII, or unibyte. */
3603 face_id
= face_at_buffer_position (it
->w
,
3605 it
->region_beg_charpos
,
3606 it
->region_end_charpos
,
3607 &next_check_charpos
,
3610 /* Correct the face for charsets different from ASCII. Do it
3611 for the multibyte case only. The face returned above is
3612 suitable for unibyte text if current_buffer is unibyte. */
3613 if (it
->multibyte_p
)
3615 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3616 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3617 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3626 /***********************************************************************
3628 ***********************************************************************/
3630 /* Set up iterator IT from invisible properties at its current
3631 position. Called from handle_stop. */
3633 static enum prop_handled
3634 handle_invisible_prop (it
)
3637 enum prop_handled handled
= HANDLED_NORMALLY
;
3639 if (STRINGP (it
->string
))
3641 extern Lisp_Object Qinvisible
;
3642 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3644 /* Get the value of the invisible text property at the
3645 current position. Value will be nil if there is no such
3647 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3648 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3651 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3653 handled
= HANDLED_RECOMPUTE_PROPS
;
3655 /* Get the position at which the next change of the
3656 invisible text property can be found in IT->string.
3657 Value will be nil if the property value is the same for
3658 all the rest of IT->string. */
3659 XSETINT (limit
, SCHARS (it
->string
));
3660 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3663 /* Text at current position is invisible. The next
3664 change in the property is at position end_charpos.
3665 Move IT's current position to that position. */
3666 if (INTEGERP (end_charpos
)
3667 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3669 struct text_pos old
;
3670 old
= it
->current
.string_pos
;
3671 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3672 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3676 /* The rest of the string is invisible. If this is an
3677 overlay string, proceed with the next overlay string
3678 or whatever comes and return a character from there. */
3679 if (it
->current
.overlay_string_index
>= 0)
3681 next_overlay_string (it
);
3682 /* Don't check for overlay strings when we just
3683 finished processing them. */
3684 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3688 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3689 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3697 EMACS_INT newpos
, next_stop
, start_charpos
;
3698 Lisp_Object pos
, prop
, overlay
;
3700 /* First of all, is there invisible text at this position? */
3701 start_charpos
= IT_CHARPOS (*it
);
3702 pos
= make_number (IT_CHARPOS (*it
));
3703 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3705 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3707 /* If we are on invisible text, skip over it. */
3708 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3710 /* Record whether we have to display an ellipsis for the
3712 int display_ellipsis_p
= invis_p
== 2;
3714 handled
= HANDLED_RECOMPUTE_PROPS
;
3716 /* Loop skipping over invisible text. The loop is left at
3717 ZV or with IT on the first char being visible again. */
3720 /* Try to skip some invisible text. Return value is the
3721 position reached which can be equal to IT's position
3722 if there is nothing invisible here. This skips both
3723 over invisible text properties and overlays with
3724 invisible property. */
3725 newpos
= skip_invisible (IT_CHARPOS (*it
),
3726 &next_stop
, ZV
, it
->window
);
3728 /* If we skipped nothing at all we weren't at invisible
3729 text in the first place. If everything to the end of
3730 the buffer was skipped, end the loop. */
3731 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3735 /* We skipped some characters but not necessarily
3736 all there are. Check if we ended up on visible
3737 text. Fget_char_property returns the property of
3738 the char before the given position, i.e. if we
3739 get invis_p = 0, this means that the char at
3740 newpos is visible. */
3741 pos
= make_number (newpos
);
3742 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3743 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3746 /* If we ended up on invisible text, proceed to
3747 skip starting with next_stop. */
3749 IT_CHARPOS (*it
) = next_stop
;
3751 /* If there are adjacent invisible texts, don't lose the
3752 second one's ellipsis. */
3754 display_ellipsis_p
= 1;
3758 /* The position newpos is now either ZV or on visible text. */
3759 IT_CHARPOS (*it
) = newpos
;
3760 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3762 /* If there are before-strings at the start of invisible
3763 text, and the text is invisible because of a text
3764 property, arrange to show before-strings because 20.x did
3765 it that way. (If the text is invisible because of an
3766 overlay property instead of a text property, this is
3767 already handled in the overlay code.) */
3769 && get_overlay_strings (it
, start_charpos
))
3771 handled
= HANDLED_RECOMPUTE_PROPS
;
3772 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3774 else if (display_ellipsis_p
)
3776 /* Make sure that the glyphs of the ellipsis will get
3777 correct `charpos' values. If we would not update
3778 it->position here, the glyphs would belong to the
3779 last visible character _before_ the invisible
3780 text, which confuses `set_cursor_from_row'.
3782 We use the last invisible position instead of the
3783 first because this way the cursor is always drawn on
3784 the first "." of the ellipsis, whenever PT is inside
3785 the invisible text. Otherwise the cursor would be
3786 placed _after_ the ellipsis when the point is after the
3787 first invisible character. */
3788 if (!STRINGP (it
->object
))
3790 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3791 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3793 setup_for_ellipsis (it
, 0);
3794 /* Let the ellipsis display before
3795 considering any properties of the following char.
3796 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3797 handled
= HANDLED_RETURN
;
3806 /* Make iterator IT return `...' next.
3807 Replaces LEN characters from buffer. */
3810 setup_for_ellipsis (it
, len
)
3814 /* Use the display table definition for `...'. Invalid glyphs
3815 will be handled by the method returning elements from dpvec. */
3816 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3818 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3819 it
->dpvec
= v
->contents
;
3820 it
->dpend
= v
->contents
+ v
->size
;
3824 /* Default `...'. */
3825 it
->dpvec
= default_invis_vector
;
3826 it
->dpend
= default_invis_vector
+ 3;
3829 it
->dpvec_char_len
= len
;
3830 it
->current
.dpvec_index
= 0;
3831 it
->dpvec_face_id
= -1;
3833 /* Remember the current face id in case glyphs specify faces.
3834 IT's face is restored in set_iterator_to_next.
3835 saved_face_id was set to preceding char's face in handle_stop. */
3836 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3837 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3839 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3845 /***********************************************************************
3847 ***********************************************************************/
3849 /* Set up iterator IT from `display' property at its current position.
3850 Called from handle_stop.
3851 We return HANDLED_RETURN if some part of the display property
3852 overrides the display of the buffer text itself.
3853 Otherwise we return HANDLED_NORMALLY. */
3855 static enum prop_handled
3856 handle_display_prop (it
)
3859 Lisp_Object prop
, object
, overlay
;
3860 struct text_pos
*position
;
3861 /* Nonzero if some property replaces the display of the text itself. */
3862 int display_replaced_p
= 0;
3864 if (STRINGP (it
->string
))
3866 object
= it
->string
;
3867 position
= &it
->current
.string_pos
;
3871 XSETWINDOW (object
, it
->w
);
3872 position
= &it
->current
.pos
;
3875 /* Reset those iterator values set from display property values. */
3876 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3877 it
->space_width
= Qnil
;
3878 it
->font_height
= Qnil
;
3881 /* We don't support recursive `display' properties, i.e. string
3882 values that have a string `display' property, that have a string
3883 `display' property etc. */
3884 if (!it
->string_from_display_prop_p
)
3885 it
->area
= TEXT_AREA
;
3887 prop
= get_char_property_and_overlay (make_number (position
->charpos
),
3888 Qdisplay
, object
, &overlay
);
3890 return HANDLED_NORMALLY
;
3891 /* Now OVERLAY is the overlay that gave us this property, or nil
3892 if it was a text property. */
3894 if (!STRINGP (it
->string
))
3895 object
= it
->w
->buffer
;
3898 /* Simple properties. */
3899 && !EQ (XCAR (prop
), Qimage
)
3900 && !EQ (XCAR (prop
), Qspace
)
3901 && !EQ (XCAR (prop
), Qwhen
)
3902 && !EQ (XCAR (prop
), Qslice
)
3903 && !EQ (XCAR (prop
), Qspace_width
)
3904 && !EQ (XCAR (prop
), Qheight
)
3905 && !EQ (XCAR (prop
), Qraise
)
3906 /* Marginal area specifications. */
3907 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3908 && !EQ (XCAR (prop
), Qleft_fringe
)
3909 && !EQ (XCAR (prop
), Qright_fringe
)
3910 && !NILP (XCAR (prop
)))
3912 for (; CONSP (prop
); prop
= XCDR (prop
))
3914 if (handle_single_display_spec (it
, XCAR (prop
), object
, overlay
,
3915 position
, display_replaced_p
))
3917 display_replaced_p
= 1;
3918 /* If some text in a string is replaced, `position' no
3919 longer points to the position of `object'. */
3920 if (STRINGP (object
))
3925 else if (VECTORP (prop
))
3928 for (i
= 0; i
< ASIZE (prop
); ++i
)
3929 if (handle_single_display_spec (it
, AREF (prop
, i
), object
, overlay
,
3930 position
, display_replaced_p
))
3932 display_replaced_p
= 1;
3933 /* If some text in a string is replaced, `position' no
3934 longer points to the position of `object'. */
3935 if (STRINGP (object
))
3941 int ret
= handle_single_display_spec (it
, prop
, object
, overlay
,
3943 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3944 return HANDLED_RECOMPUTE_PROPS
;
3946 display_replaced_p
= 1;
3949 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3953 /* Value is the position of the end of the `display' property starting
3954 at START_POS in OBJECT. */
3956 static struct text_pos
3957 display_prop_end (it
, object
, start_pos
)
3960 struct text_pos start_pos
;
3963 struct text_pos end_pos
;
3965 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3966 Qdisplay
, object
, Qnil
);
3967 CHARPOS (end_pos
) = XFASTINT (end
);
3968 if (STRINGP (object
))
3969 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3971 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3977 /* Set up IT from a single `display' specification PROP. OBJECT
3978 is the object in which the `display' property was found. *POSITION
3979 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3980 means that we previously saw a display specification which already
3981 replaced text display with something else, for example an image;
3982 we ignore such properties after the first one has been processed.
3984 OVERLAY is the overlay this `display' property came from,
3985 or nil if it was a text property.
3987 If PROP is a `space' or `image' specification, and in some other
3988 cases too, set *POSITION to the position where the `display'
3991 Value is non-zero if something was found which replaces the display
3992 of buffer or string text. Specifically, the value is -1 if that
3993 "something" is "nothing". */
3996 handle_single_display_spec (it
, spec
, object
, overlay
, position
,
3997 display_replaced_before_p
)
4001 Lisp_Object overlay
;
4002 struct text_pos
*position
;
4003 int display_replaced_before_p
;
4006 Lisp_Object location
, value
;
4007 struct text_pos start_pos
, save_pos
;
4010 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4011 If the result is non-nil, use VALUE instead of SPEC. */
4013 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4022 if (!NILP (form
) && !EQ (form
, Qt
))
4024 int count
= SPECPDL_INDEX ();
4025 struct gcpro gcpro1
;
4027 /* Bind `object' to the object having the `display' property, a
4028 buffer or string. Bind `position' to the position in the
4029 object where the property was found, and `buffer-position'
4030 to the current position in the buffer. */
4031 specbind (Qobject
, object
);
4032 specbind (Qposition
, make_number (CHARPOS (*position
)));
4033 specbind (Qbuffer_position
,
4034 make_number (STRINGP (object
)
4035 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
4037 form
= safe_eval (form
);
4039 unbind_to (count
, Qnil
);
4045 /* Handle `(height HEIGHT)' specifications. */
4047 && EQ (XCAR (spec
), Qheight
)
4048 && CONSP (XCDR (spec
)))
4050 if (!FRAME_WINDOW_P (it
->f
))
4053 it
->font_height
= XCAR (XCDR (spec
));
4054 if (!NILP (it
->font_height
))
4056 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4057 int new_height
= -1;
4059 if (CONSP (it
->font_height
)
4060 && (EQ (XCAR (it
->font_height
), Qplus
)
4061 || EQ (XCAR (it
->font_height
), Qminus
))
4062 && CONSP (XCDR (it
->font_height
))
4063 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4065 /* `(+ N)' or `(- N)' where N is an integer. */
4066 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4067 if (EQ (XCAR (it
->font_height
), Qplus
))
4069 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4071 else if (FUNCTIONP (it
->font_height
))
4073 /* Call function with current height as argument.
4074 Value is the new height. */
4076 height
= safe_call1 (it
->font_height
,
4077 face
->lface
[LFACE_HEIGHT_INDEX
]);
4078 if (NUMBERP (height
))
4079 new_height
= XFLOATINT (height
);
4081 else if (NUMBERP (it
->font_height
))
4083 /* Value is a multiple of the canonical char height. */
4086 face
= FACE_FROM_ID (it
->f
,
4087 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4088 new_height
= (XFLOATINT (it
->font_height
)
4089 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4093 /* Evaluate IT->font_height with `height' bound to the
4094 current specified height to get the new height. */
4095 int count
= SPECPDL_INDEX ();
4097 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4098 value
= safe_eval (it
->font_height
);
4099 unbind_to (count
, Qnil
);
4101 if (NUMBERP (value
))
4102 new_height
= XFLOATINT (value
);
4106 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4112 /* Handle `(space-width WIDTH)'. */
4114 && EQ (XCAR (spec
), Qspace_width
)
4115 && CONSP (XCDR (spec
)))
4117 if (!FRAME_WINDOW_P (it
->f
))
4120 value
= XCAR (XCDR (spec
));
4121 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4122 it
->space_width
= value
;
4127 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4129 && EQ (XCAR (spec
), Qslice
))
4133 if (!FRAME_WINDOW_P (it
->f
))
4136 if (tem
= XCDR (spec
), CONSP (tem
))
4138 it
->slice
.x
= XCAR (tem
);
4139 if (tem
= XCDR (tem
), CONSP (tem
))
4141 it
->slice
.y
= XCAR (tem
);
4142 if (tem
= XCDR (tem
), CONSP (tem
))
4144 it
->slice
.width
= XCAR (tem
);
4145 if (tem
= XCDR (tem
), CONSP (tem
))
4146 it
->slice
.height
= XCAR (tem
);
4154 /* Handle `(raise FACTOR)'. */
4156 && EQ (XCAR (spec
), Qraise
)
4157 && CONSP (XCDR (spec
)))
4159 if (!FRAME_WINDOW_P (it
->f
))
4162 #ifdef HAVE_WINDOW_SYSTEM
4163 value
= XCAR (XCDR (spec
));
4164 if (NUMBERP (value
))
4166 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4167 it
->voffset
= - (XFLOATINT (value
)
4168 * (FONT_HEIGHT (face
->font
)));
4170 #endif /* HAVE_WINDOW_SYSTEM */
4175 /* Don't handle the other kinds of display specifications
4176 inside a string that we got from a `display' property. */
4177 if (it
->string_from_display_prop_p
)
4180 /* Characters having this form of property are not displayed, so
4181 we have to find the end of the property. */
4182 start_pos
= *position
;
4183 *position
= display_prop_end (it
, object
, start_pos
);
4186 /* Stop the scan at that end position--we assume that all
4187 text properties change there. */
4188 it
->stop_charpos
= position
->charpos
;
4190 /* Handle `(left-fringe BITMAP [FACE])'
4191 and `(right-fringe BITMAP [FACE])'. */
4193 && (EQ (XCAR (spec
), Qleft_fringe
)
4194 || EQ (XCAR (spec
), Qright_fringe
))
4195 && CONSP (XCDR (spec
)))
4197 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
4200 if (!FRAME_WINDOW_P (it
->f
))
4201 /* If we return here, POSITION has been advanced
4202 across the text with this property. */
4205 #ifdef HAVE_WINDOW_SYSTEM
4206 value
= XCAR (XCDR (spec
));
4207 if (!SYMBOLP (value
)
4208 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4209 /* If we return here, POSITION has been advanced
4210 across the text with this property. */
4213 if (CONSP (XCDR (XCDR (spec
))))
4215 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4216 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4222 /* Save current settings of IT so that we can restore them
4223 when we are finished with the glyph property value. */
4225 save_pos
= it
->position
;
4226 it
->position
= *position
;
4228 it
->position
= save_pos
;
4230 it
->area
= TEXT_AREA
;
4231 it
->what
= IT_IMAGE
;
4232 it
->image_id
= -1; /* no image */
4233 it
->position
= start_pos
;
4234 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4235 it
->method
= GET_FROM_IMAGE
;
4236 it
->from_overlay
= Qnil
;
4237 it
->face_id
= face_id
;
4239 /* Say that we haven't consumed the characters with
4240 `display' property yet. The call to pop_it in
4241 set_iterator_to_next will clean this up. */
4242 *position
= start_pos
;
4244 if (EQ (XCAR (spec
), Qleft_fringe
))
4246 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4247 it
->left_user_fringe_face_id
= face_id
;
4251 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4252 it
->right_user_fringe_face_id
= face_id
;
4254 #endif /* HAVE_WINDOW_SYSTEM */
4258 /* Prepare to handle `((margin left-margin) ...)',
4259 `((margin right-margin) ...)' and `((margin nil) ...)'
4260 prefixes for display specifications. */
4261 location
= Qunbound
;
4262 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4266 value
= XCDR (spec
);
4268 value
= XCAR (value
);
4271 if (EQ (XCAR (tem
), Qmargin
)
4272 && (tem
= XCDR (tem
),
4273 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4275 || EQ (tem
, Qleft_margin
)
4276 || EQ (tem
, Qright_margin
))))
4280 if (EQ (location
, Qunbound
))
4286 /* After this point, VALUE is the property after any
4287 margin prefix has been stripped. It must be a string,
4288 an image specification, or `(space ...)'.
4290 LOCATION specifies where to display: `left-margin',
4291 `right-margin' or nil. */
4293 valid_p
= (STRINGP (value
)
4294 #ifdef HAVE_WINDOW_SYSTEM
4295 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4296 #endif /* not HAVE_WINDOW_SYSTEM */
4297 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4299 if (valid_p
&& !display_replaced_before_p
)
4301 /* Save current settings of IT so that we can restore them
4302 when we are finished with the glyph property value. */
4303 save_pos
= it
->position
;
4304 it
->position
= *position
;
4306 it
->position
= save_pos
;
4307 it
->from_overlay
= overlay
;
4309 if (NILP (location
))
4310 it
->area
= TEXT_AREA
;
4311 else if (EQ (location
, Qleft_margin
))
4312 it
->area
= LEFT_MARGIN_AREA
;
4314 it
->area
= RIGHT_MARGIN_AREA
;
4316 if (STRINGP (value
))
4318 if (SCHARS (value
) == 0)
4321 return -1; /* Replaced by "", i.e. nothing. */
4324 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4325 it
->current
.overlay_string_index
= -1;
4326 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4327 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4328 it
->method
= GET_FROM_STRING
;
4329 it
->stop_charpos
= 0;
4330 it
->string_from_display_prop_p
= 1;
4331 /* Say that we haven't consumed the characters with
4332 `display' property yet. The call to pop_it in
4333 set_iterator_to_next will clean this up. */
4334 if (BUFFERP (object
))
4335 *position
= start_pos
;
4337 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4339 it
->method
= GET_FROM_STRETCH
;
4341 *position
= it
->position
= start_pos
;
4343 #ifdef HAVE_WINDOW_SYSTEM
4346 it
->what
= IT_IMAGE
;
4347 it
->image_id
= lookup_image (it
->f
, value
);
4348 it
->position
= start_pos
;
4349 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4350 it
->method
= GET_FROM_IMAGE
;
4352 /* Say that we haven't consumed the characters with
4353 `display' property yet. The call to pop_it in
4354 set_iterator_to_next will clean this up. */
4355 *position
= start_pos
;
4357 #endif /* HAVE_WINDOW_SYSTEM */
4362 /* Invalid property or property not supported. Restore
4363 POSITION to what it was before. */
4364 *position
= start_pos
;
4369 /* Check if SPEC is a display sub-property value whose text should be
4370 treated as intangible. */
4373 single_display_spec_intangible_p (prop
)
4376 /* Skip over `when FORM'. */
4377 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4391 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4392 we don't need to treat text as intangible. */
4393 if (EQ (XCAR (prop
), Qmargin
))
4401 || EQ (XCAR (prop
), Qleft_margin
)
4402 || EQ (XCAR (prop
), Qright_margin
))
4406 return (CONSP (prop
)
4407 && (EQ (XCAR (prop
), Qimage
)
4408 || EQ (XCAR (prop
), Qspace
)));
4412 /* Check if PROP is a display property value whose text should be
4413 treated as intangible. */
4416 display_prop_intangible_p (prop
)
4420 && CONSP (XCAR (prop
))
4421 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4423 /* A list of sub-properties. */
4424 while (CONSP (prop
))
4426 if (single_display_spec_intangible_p (XCAR (prop
)))
4431 else if (VECTORP (prop
))
4433 /* A vector of sub-properties. */
4435 for (i
= 0; i
< ASIZE (prop
); ++i
)
4436 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4440 return single_display_spec_intangible_p (prop
);
4446 /* Return 1 if PROP is a display sub-property value containing STRING. */
4449 single_display_spec_string_p (prop
, string
)
4450 Lisp_Object prop
, string
;
4452 if (EQ (string
, prop
))
4455 /* Skip over `when FORM'. */
4456 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4465 /* Skip over `margin LOCATION'. */
4466 if (EQ (XCAR (prop
), Qmargin
))
4477 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4481 /* Return 1 if STRING appears in the `display' property PROP. */
4484 display_prop_string_p (prop
, string
)
4485 Lisp_Object prop
, string
;
4488 && CONSP (XCAR (prop
))
4489 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4491 /* A list of sub-properties. */
4492 while (CONSP (prop
))
4494 if (single_display_spec_string_p (XCAR (prop
), string
))
4499 else if (VECTORP (prop
))
4501 /* A vector of sub-properties. */
4503 for (i
= 0; i
< ASIZE (prop
); ++i
)
4504 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4508 return single_display_spec_string_p (prop
, string
);
4514 /* Determine from which buffer position in W's buffer STRING comes
4515 from. AROUND_CHARPOS is an approximate position where it could
4516 be from. Value is the buffer position or 0 if it couldn't be
4519 W's buffer must be current.
4521 This function is necessary because we don't record buffer positions
4522 in glyphs generated from strings (to keep struct glyph small).
4523 This function may only use code that doesn't eval because it is
4524 called asynchronously from note_mouse_highlight. */
4527 string_buffer_position (w
, string
, around_charpos
)
4532 Lisp_Object limit
, prop
, pos
;
4533 const int MAX_DISTANCE
= 1000;
4536 pos
= make_number (around_charpos
);
4537 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4538 while (!found
&& !EQ (pos
, limit
))
4540 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4541 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4544 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4549 pos
= make_number (around_charpos
);
4550 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4551 while (!found
&& !EQ (pos
, limit
))
4553 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4554 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4557 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4562 return found
? XINT (pos
) : 0;
4567 /***********************************************************************
4568 `composition' property
4569 ***********************************************************************/
4571 static enum prop_handled
4572 handle_auto_composed_prop (it
)
4575 enum prop_handled handled
= HANDLED_NORMALLY
;
4577 if (FRAME_WINDOW_P (it
->f
) && FUNCTIONP (Vauto_composition_function
))
4579 Lisp_Object val
= Qnil
;
4580 EMACS_INT pos
, limit
= -1;
4582 if (STRINGP (it
->string
))
4583 pos
= IT_STRING_CHARPOS (*it
);
4585 pos
= IT_CHARPOS (*it
);
4587 val
= Fget_text_property (make_number (pos
), Qauto_composed
, it
->string
);
4590 Lisp_Object cmp_prop
;
4591 EMACS_INT cmp_start
, cmp_end
;
4593 if (get_property_and_range (pos
, Qcomposition
, &cmp_prop
,
4594 &cmp_start
, &cmp_end
, it
->string
)
4596 && COMPOSITION_METHOD (cmp_prop
) == COMPOSITION_WITH_GLYPH_STRING
)
4598 Lisp_Object gstring
= COMPOSITION_COMPONENTS (cmp_prop
);
4599 Lisp_Object font_object
= LGSTRING_FONT (gstring
);
4601 if (! EQ (font_object
,
4602 font_at (-1, pos
, FACE_FROM_ID (it
->f
, it
->face_id
),
4603 it
->w
, it
->string
)))
4604 /* We must re-compute the composition for the
4613 /* As Fnext_single_char_property_change is very slow, we
4614 limit the search to the current line. */
4615 if (STRINGP (it
->string
))
4616 limit
= SCHARS (it
->string
);
4618 limit
= find_next_newline_no_quit (pos
, 1);
4619 end
= Fnext_single_char_property_change (make_number (pos
),
4622 make_number (limit
));
4624 if (XINT (end
) < limit
)
4625 /* The current point is auto-composed, but there exist
4626 characters not yet composed beyond the
4627 auto-composed region. There's a possiblity that
4628 the last characters in the region may be newly
4633 if (NILP (val
) && ! STRINGP (it
->string
))
4636 limit
= (STRINGP (it
->string
) ? SCHARS (it
->string
)
4637 : find_next_newline_no_quit (pos
, 1));
4640 int count
= SPECPDL_INDEX ();
4641 Lisp_Object args
[5];
4643 limit
= font_range (pos
, limit
, FACE_FROM_ID (it
->f
, it
->face_id
),
4645 args
[0] = Vauto_composition_function
;
4646 specbind (Qauto_composition_function
, Qnil
);
4647 args
[1] = make_number (pos
);
4648 args
[2] = make_number (limit
);
4649 args
[3] = it
->window
;
4650 args
[4] = it
->string
;
4651 safe_call (5, args
);
4652 unbind_to (count
, Qnil
);
4660 /* Set up iterator IT from `composition' property at its current
4661 position. Called from handle_stop. */
4663 static enum prop_handled
4664 handle_composition_prop (it
)
4667 Lisp_Object prop
, string
;
4668 EMACS_INT pos
, pos_byte
, start
, end
;
4669 enum prop_handled handled
= HANDLED_NORMALLY
;
4671 if (STRINGP (it
->string
))
4675 pos
= IT_STRING_CHARPOS (*it
);
4676 pos_byte
= IT_STRING_BYTEPOS (*it
);
4677 string
= it
->string
;
4678 s
= SDATA (string
) + pos_byte
;
4679 it
->c
= STRING_CHAR (s
, 0);
4683 pos
= IT_CHARPOS (*it
);
4684 pos_byte
= IT_BYTEPOS (*it
);
4686 it
->c
= FETCH_CHAR (pos_byte
);
4689 /* If there's a valid composition and point is not inside of the
4690 composition (in the case that the composition is from the current
4691 buffer), draw a glyph composed from the composition components. */
4692 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4693 && COMPOSITION_VALID_P (start
, end
, prop
)
4694 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4700 if (STRINGP (it
->string
))
4701 pos_byte
= string_char_to_byte (it
->string
, start
);
4703 pos_byte
= CHAR_TO_BYTE (start
);
4705 id
= get_composition_id (start
, pos_byte
, end
- start
, prop
, string
);
4709 struct composition
*cmp
= composition_table
[id
];
4711 if (cmp
->glyph_len
== 0)
4714 if (STRINGP (it
->string
))
4716 IT_STRING_CHARPOS (*it
) = end
;
4717 IT_STRING_BYTEPOS (*it
) = string_char_to_byte (it
->string
,
4722 IT_CHARPOS (*it
) = end
;
4723 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (end
);
4725 return HANDLED_RECOMPUTE_PROPS
;
4728 it
->stop_charpos
= end
;
4731 it
->method
= GET_FROM_COMPOSITION
;
4733 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4734 /* For a terminal, draw only the first (non-TAB) character
4735 of the components. */
4736 if (composition_table
[id
]->method
== COMPOSITION_WITH_GLYPH_STRING
)
4738 /* FIXME: This doesn't do anything!?! */
4739 Lisp_Object lgstring
= AREF (XHASH_TABLE (composition_hash_table
)
4741 cmp
->hash_index
* 2);
4747 for (i
= 0; i
< cmp
->glyph_len
; i
++)
4748 if ((it
->c
= COMPOSITION_GLYPH (composition_table
[id
], i
))
4754 it
->len
= (STRINGP (it
->string
)
4755 ? string_char_to_byte (it
->string
, end
)
4756 : CHAR_TO_BYTE (end
)) - pos_byte
;
4757 handled
= HANDLED_RETURN
;
4766 /***********************************************************************
4768 ***********************************************************************/
4770 /* The following structure is used to record overlay strings for
4771 later sorting in load_overlay_strings. */
4773 struct overlay_entry
4775 Lisp_Object overlay
;
4782 /* Set up iterator IT from overlay strings at its current position.
4783 Called from handle_stop. */
4785 static enum prop_handled
4786 handle_overlay_change (it
)
4789 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4790 return HANDLED_RECOMPUTE_PROPS
;
4792 return HANDLED_NORMALLY
;
4796 /* Set up the next overlay string for delivery by IT, if there is an
4797 overlay string to deliver. Called by set_iterator_to_next when the
4798 end of the current overlay string is reached. If there are more
4799 overlay strings to display, IT->string and
4800 IT->current.overlay_string_index are set appropriately here.
4801 Otherwise IT->string is set to nil. */
4804 next_overlay_string (it
)
4807 ++it
->current
.overlay_string_index
;
4808 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4810 /* No more overlay strings. Restore IT's settings to what
4811 they were before overlay strings were processed, and
4812 continue to deliver from current_buffer. */
4813 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4817 || it
->method
== GET_FROM_COMPOSITION
4818 || (NILP (it
->string
)
4819 && it
->method
== GET_FROM_BUFFER
4820 && it
->stop_charpos
>= BEGV
4821 && it
->stop_charpos
<= it
->end_charpos
));
4822 it
->current
.overlay_string_index
= -1;
4823 it
->n_overlay_strings
= 0;
4825 /* If we're at the end of the buffer, record that we have
4826 processed the overlay strings there already, so that
4827 next_element_from_buffer doesn't try it again. */
4828 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4829 it
->overlay_strings_at_end_processed_p
= 1;
4831 /* If we have to display `...' for invisible text, set
4832 the iterator up for that. */
4833 if (display_ellipsis_p
)
4834 setup_for_ellipsis (it
, 0);
4838 /* There are more overlay strings to process. If
4839 IT->current.overlay_string_index has advanced to a position
4840 where we must load IT->overlay_strings with more strings, do
4842 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4844 if (it
->current
.overlay_string_index
&& i
== 0)
4845 load_overlay_strings (it
, 0);
4847 /* Initialize IT to deliver display elements from the overlay
4849 it
->string
= it
->overlay_strings
[i
];
4850 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4851 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4852 it
->method
= GET_FROM_STRING
;
4853 it
->stop_charpos
= 0;
4860 /* Compare two overlay_entry structures E1 and E2. Used as a
4861 comparison function for qsort in load_overlay_strings. Overlay
4862 strings for the same position are sorted so that
4864 1. All after-strings come in front of before-strings, except
4865 when they come from the same overlay.
4867 2. Within after-strings, strings are sorted so that overlay strings
4868 from overlays with higher priorities come first.
4870 2. Within before-strings, strings are sorted so that overlay
4871 strings from overlays with higher priorities come last.
4873 Value is analogous to strcmp. */
4877 compare_overlay_entries (e1
, e2
)
4880 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4881 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4884 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4886 /* Let after-strings appear in front of before-strings if
4887 they come from different overlays. */
4888 if (EQ (entry1
->overlay
, entry2
->overlay
))
4889 result
= entry1
->after_string_p
? 1 : -1;
4891 result
= entry1
->after_string_p
? -1 : 1;
4893 else if (entry1
->after_string_p
)
4894 /* After-strings sorted in order of decreasing priority. */
4895 result
= entry2
->priority
- entry1
->priority
;
4897 /* Before-strings sorted in order of increasing priority. */
4898 result
= entry1
->priority
- entry2
->priority
;
4904 /* Load the vector IT->overlay_strings with overlay strings from IT's
4905 current buffer position, or from CHARPOS if that is > 0. Set
4906 IT->n_overlays to the total number of overlay strings found.
4908 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4909 a time. On entry into load_overlay_strings,
4910 IT->current.overlay_string_index gives the number of overlay
4911 strings that have already been loaded by previous calls to this
4914 IT->add_overlay_start contains an additional overlay start
4915 position to consider for taking overlay strings from, if non-zero.
4916 This position comes into play when the overlay has an `invisible'
4917 property, and both before and after-strings. When we've skipped to
4918 the end of the overlay, because of its `invisible' property, we
4919 nevertheless want its before-string to appear.
4920 IT->add_overlay_start will contain the overlay start position
4923 Overlay strings are sorted so that after-string strings come in
4924 front of before-string strings. Within before and after-strings,
4925 strings are sorted by overlay priority. See also function
4926 compare_overlay_entries. */
4929 load_overlay_strings (it
, charpos
)
4933 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4934 Lisp_Object overlay
, window
, str
, invisible
;
4935 struct Lisp_Overlay
*ov
;
4938 int n
= 0, i
, j
, invis_p
;
4939 struct overlay_entry
*entries
4940 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4943 charpos
= IT_CHARPOS (*it
);
4945 /* Append the overlay string STRING of overlay OVERLAY to vector
4946 `entries' which has size `size' and currently contains `n'
4947 elements. AFTER_P non-zero means STRING is an after-string of
4949 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4952 Lisp_Object priority; \
4956 int new_size = 2 * size; \
4957 struct overlay_entry *old = entries; \
4959 (struct overlay_entry *) alloca (new_size \
4960 * sizeof *entries); \
4961 bcopy (old, entries, size * sizeof *entries); \
4965 entries[n].string = (STRING); \
4966 entries[n].overlay = (OVERLAY); \
4967 priority = Foverlay_get ((OVERLAY), Qpriority); \
4968 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4969 entries[n].after_string_p = (AFTER_P); \
4974 /* Process overlay before the overlay center. */
4975 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4977 XSETMISC (overlay
, ov
);
4978 xassert (OVERLAYP (overlay
));
4979 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4980 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4985 /* Skip this overlay if it doesn't start or end at IT's current
4987 if (end
!= charpos
&& start
!= charpos
)
4990 /* Skip this overlay if it doesn't apply to IT->w. */
4991 window
= Foverlay_get (overlay
, Qwindow
);
4992 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4995 /* If the text ``under'' the overlay is invisible, both before-
4996 and after-strings from this overlay are visible; start and
4997 end position are indistinguishable. */
4998 invisible
= Foverlay_get (overlay
, Qinvisible
);
4999 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5001 /* If overlay has a non-empty before-string, record it. */
5002 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5003 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5005 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5007 /* If overlay has a non-empty after-string, record it. */
5008 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5009 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5011 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5014 /* Process overlays after the overlay center. */
5015 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5017 XSETMISC (overlay
, ov
);
5018 xassert (OVERLAYP (overlay
));
5019 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5020 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5022 if (start
> charpos
)
5025 /* Skip this overlay if it doesn't start or end at IT's current
5027 if (end
!= charpos
&& start
!= charpos
)
5030 /* Skip this overlay if it doesn't apply to IT->w. */
5031 window
= Foverlay_get (overlay
, Qwindow
);
5032 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5035 /* If the text ``under'' the overlay is invisible, it has a zero
5036 dimension, and both before- and after-strings apply. */
5037 invisible
= Foverlay_get (overlay
, Qinvisible
);
5038 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5040 /* If overlay has a non-empty before-string, record it. */
5041 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5042 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5044 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5046 /* If overlay has a non-empty after-string, record it. */
5047 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5048 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5050 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5053 #undef RECORD_OVERLAY_STRING
5057 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5059 /* Record the total number of strings to process. */
5060 it
->n_overlay_strings
= n
;
5062 /* IT->current.overlay_string_index is the number of overlay strings
5063 that have already been consumed by IT. Copy some of the
5064 remaining overlay strings to IT->overlay_strings. */
5066 j
= it
->current
.overlay_string_index
;
5067 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5069 it
->overlay_strings
[i
] = entries
[j
].string
;
5070 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5077 /* Get the first chunk of overlay strings at IT's current buffer
5078 position, or at CHARPOS if that is > 0. Value is non-zero if at
5079 least one overlay string was found. */
5082 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
5087 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5088 process. This fills IT->overlay_strings with strings, and sets
5089 IT->n_overlay_strings to the total number of strings to process.
5090 IT->pos.overlay_string_index has to be set temporarily to zero
5091 because load_overlay_strings needs this; it must be set to -1
5092 when no overlay strings are found because a zero value would
5093 indicate a position in the first overlay string. */
5094 it
->current
.overlay_string_index
= 0;
5095 load_overlay_strings (it
, charpos
);
5097 /* If we found overlay strings, set up IT to deliver display
5098 elements from the first one. Otherwise set up IT to deliver
5099 from current_buffer. */
5100 if (it
->n_overlay_strings
)
5102 /* Make sure we know settings in current_buffer, so that we can
5103 restore meaningful values when we're done with the overlay
5106 compute_stop_pos (it
);
5107 xassert (it
->face_id
>= 0);
5109 /* Save IT's settings. They are restored after all overlay
5110 strings have been processed. */
5111 xassert (!compute_stop_p
|| it
->sp
== 0);
5114 /* Set up IT to deliver display elements from the first overlay
5116 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5117 it
->string
= it
->overlay_strings
[0];
5118 it
->from_overlay
= Qnil
;
5119 it
->stop_charpos
= 0;
5120 xassert (STRINGP (it
->string
));
5121 it
->end_charpos
= SCHARS (it
->string
);
5122 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5123 it
->method
= GET_FROM_STRING
;
5127 it
->current
.overlay_string_index
= -1;
5132 get_overlay_strings (it
, charpos
)
5137 it
->method
= GET_FROM_BUFFER
;
5139 (void) get_overlay_strings_1 (it
, charpos
, 1);
5143 /* Value is non-zero if we found at least one overlay string. */
5144 return STRINGP (it
->string
);
5149 /***********************************************************************
5150 Saving and restoring state
5151 ***********************************************************************/
5153 /* Save current settings of IT on IT->stack. Called, for example,
5154 before setting up IT for an overlay string, to be able to restore
5155 IT's settings to what they were after the overlay string has been
5162 struct iterator_stack_entry
*p
;
5164 xassert (it
->sp
< IT_STACK_SIZE
);
5165 p
= it
->stack
+ it
->sp
;
5167 p
->stop_charpos
= it
->stop_charpos
;
5168 xassert (it
->face_id
>= 0);
5169 p
->face_id
= it
->face_id
;
5170 p
->string
= it
->string
;
5171 p
->method
= it
->method
;
5172 p
->from_overlay
= it
->from_overlay
;
5175 case GET_FROM_IMAGE
:
5176 p
->u
.image
.object
= it
->object
;
5177 p
->u
.image
.image_id
= it
->image_id
;
5178 p
->u
.image
.slice
= it
->slice
;
5180 case GET_FROM_COMPOSITION
:
5181 p
->u
.comp
.object
= it
->object
;
5182 p
->u
.comp
.c
= it
->c
;
5183 p
->u
.comp
.len
= it
->len
;
5184 p
->u
.comp
.cmp_id
= it
->cmp_id
;
5185 p
->u
.comp
.cmp_len
= it
->cmp_len
;
5187 case GET_FROM_STRETCH
:
5188 p
->u
.stretch
.object
= it
->object
;
5191 p
->position
= it
->position
;
5192 p
->current
= it
->current
;
5193 p
->end_charpos
= it
->end_charpos
;
5194 p
->string_nchars
= it
->string_nchars
;
5196 p
->multibyte_p
= it
->multibyte_p
;
5197 p
->space_width
= it
->space_width
;
5198 p
->font_height
= it
->font_height
;
5199 p
->voffset
= it
->voffset
;
5200 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5201 p
->display_ellipsis_p
= 0;
5206 /* Restore IT's settings from IT->stack. Called, for example, when no
5207 more overlay strings must be processed, and we return to delivering
5208 display elements from a buffer, or when the end of a string from a
5209 `display' property is reached and we return to delivering display
5210 elements from an overlay string, or from a buffer. */
5216 struct iterator_stack_entry
*p
;
5218 xassert (it
->sp
> 0);
5220 p
= it
->stack
+ it
->sp
;
5221 it
->stop_charpos
= p
->stop_charpos
;
5222 it
->face_id
= p
->face_id
;
5223 it
->current
= p
->current
;
5224 it
->position
= p
->position
;
5225 it
->string
= p
->string
;
5226 it
->from_overlay
= p
->from_overlay
;
5227 if (NILP (it
->string
))
5228 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5229 it
->method
= p
->method
;
5232 case GET_FROM_IMAGE
:
5233 it
->image_id
= p
->u
.image
.image_id
;
5234 it
->object
= p
->u
.image
.object
;
5235 it
->slice
= p
->u
.image
.slice
;
5237 case GET_FROM_COMPOSITION
:
5238 it
->object
= p
->u
.comp
.object
;
5239 it
->c
= p
->u
.comp
.c
;
5240 it
->len
= p
->u
.comp
.len
;
5241 it
->cmp_id
= p
->u
.comp
.cmp_id
;
5242 it
->cmp_len
= p
->u
.comp
.cmp_len
;
5244 case GET_FROM_STRETCH
:
5245 it
->object
= p
->u
.comp
.object
;
5247 case GET_FROM_BUFFER
:
5248 it
->object
= it
->w
->buffer
;
5250 case GET_FROM_STRING
:
5251 it
->object
= it
->string
;
5254 it
->end_charpos
= p
->end_charpos
;
5255 it
->string_nchars
= p
->string_nchars
;
5257 it
->multibyte_p
= p
->multibyte_p
;
5258 it
->space_width
= p
->space_width
;
5259 it
->font_height
= p
->font_height
;
5260 it
->voffset
= p
->voffset
;
5261 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5266 /***********************************************************************
5268 ***********************************************************************/
5270 /* Set IT's current position to the previous line start. */
5273 back_to_previous_line_start (it
)
5276 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5277 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5281 /* Move IT to the next line start.
5283 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5284 we skipped over part of the text (as opposed to moving the iterator
5285 continuously over the text). Otherwise, don't change the value
5288 Newlines may come from buffer text, overlay strings, or strings
5289 displayed via the `display' property. That's the reason we can't
5290 simply use find_next_newline_no_quit.
5292 Note that this function may not skip over invisible text that is so
5293 because of text properties and immediately follows a newline. If
5294 it would, function reseat_at_next_visible_line_start, when called
5295 from set_iterator_to_next, would effectively make invisible
5296 characters following a newline part of the wrong glyph row, which
5297 leads to wrong cursor motion. */
5300 forward_to_next_line_start (it
, skipped_p
)
5304 int old_selective
, newline_found_p
, n
;
5305 const int MAX_NEWLINE_DISTANCE
= 500;
5307 /* If already on a newline, just consume it to avoid unintended
5308 skipping over invisible text below. */
5309 if (it
->what
== IT_CHARACTER
5311 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5313 set_iterator_to_next (it
, 0);
5318 /* Don't handle selective display in the following. It's (a)
5319 unnecessary because it's done by the caller, and (b) leads to an
5320 infinite recursion because next_element_from_ellipsis indirectly
5321 calls this function. */
5322 old_selective
= it
->selective
;
5325 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5326 from buffer text. */
5327 for (n
= newline_found_p
= 0;
5328 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5329 n
+= STRINGP (it
->string
) ? 0 : 1)
5331 if (!get_next_display_element (it
))
5333 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5334 set_iterator_to_next (it
, 0);
5337 /* If we didn't find a newline near enough, see if we can use a
5339 if (!newline_found_p
)
5341 int start
= IT_CHARPOS (*it
);
5342 int limit
= find_next_newline_no_quit (start
, 1);
5345 xassert (!STRINGP (it
->string
));
5347 /* If there isn't any `display' property in sight, and no
5348 overlays, we can just use the position of the newline in
5350 if (it
->stop_charpos
>= limit
5351 || ((pos
= Fnext_single_property_change (make_number (start
),
5353 Qnil
, make_number (limit
)),
5355 && next_overlay_change (start
) == ZV
))
5357 IT_CHARPOS (*it
) = limit
;
5358 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5359 *skipped_p
= newline_found_p
= 1;
5363 while (get_next_display_element (it
)
5364 && !newline_found_p
)
5366 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5367 set_iterator_to_next (it
, 0);
5372 it
->selective
= old_selective
;
5373 return newline_found_p
;
5377 /* Set IT's current position to the previous visible line start. Skip
5378 invisible text that is so either due to text properties or due to
5379 selective display. Caution: this does not change IT->current_x and
5383 back_to_previous_visible_line_start (it
)
5386 while (IT_CHARPOS (*it
) > BEGV
)
5388 back_to_previous_line_start (it
);
5390 if (IT_CHARPOS (*it
) <= BEGV
)
5393 /* If selective > 0, then lines indented more than that values
5395 if (it
->selective
> 0
5396 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5397 (double) it
->selective
)) /* iftc */
5400 /* Check the newline before point for invisibility. */
5403 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5404 Qinvisible
, it
->window
);
5405 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5409 if (IT_CHARPOS (*it
) <= BEGV
)
5416 Lisp_Object val
, overlay
;
5418 /* If newline is part of a composition, continue from start of composition */
5419 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5420 && beg
< IT_CHARPOS (*it
))
5423 /* If newline is replaced by a display property, find start of overlay
5424 or interval and continue search from that point. */
5426 pos
= --IT_CHARPOS (it2
);
5429 if (handle_display_prop (&it2
) == HANDLED_RETURN
5430 && !NILP (val
= get_char_property_and_overlay
5431 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5432 && (OVERLAYP (overlay
)
5433 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5434 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5437 /* Newline is not replaced by anything -- so we are done. */
5443 IT_CHARPOS (*it
) = beg
;
5444 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5448 it
->continuation_lines_width
= 0;
5450 xassert (IT_CHARPOS (*it
) >= BEGV
);
5451 xassert (IT_CHARPOS (*it
) == BEGV
5452 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5457 /* Reseat iterator IT at the previous visible line start. Skip
5458 invisible text that is so either due to text properties or due to
5459 selective display. At the end, update IT's overlay information,
5460 face information etc. */
5463 reseat_at_previous_visible_line_start (it
)
5466 back_to_previous_visible_line_start (it
);
5467 reseat (it
, it
->current
.pos
, 1);
5472 /* Reseat iterator IT on the next visible line start in the current
5473 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5474 preceding the line start. Skip over invisible text that is so
5475 because of selective display. Compute faces, overlays etc at the
5476 new position. Note that this function does not skip over text that
5477 is invisible because of text properties. */
5480 reseat_at_next_visible_line_start (it
, on_newline_p
)
5484 int newline_found_p
, skipped_p
= 0;
5486 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5488 /* Skip over lines that are invisible because they are indented
5489 more than the value of IT->selective. */
5490 if (it
->selective
> 0)
5491 while (IT_CHARPOS (*it
) < ZV
5492 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5493 (double) it
->selective
)) /* iftc */
5495 xassert (IT_BYTEPOS (*it
) == BEGV
5496 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5497 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5500 /* Position on the newline if that's what's requested. */
5501 if (on_newline_p
&& newline_found_p
)
5503 if (STRINGP (it
->string
))
5505 if (IT_STRING_CHARPOS (*it
) > 0)
5507 --IT_STRING_CHARPOS (*it
);
5508 --IT_STRING_BYTEPOS (*it
);
5511 else if (IT_CHARPOS (*it
) > BEGV
)
5515 reseat (it
, it
->current
.pos
, 0);
5519 reseat (it
, it
->current
.pos
, 0);
5526 /***********************************************************************
5527 Changing an iterator's position
5528 ***********************************************************************/
5530 /* Change IT's current position to POS in current_buffer. If FORCE_P
5531 is non-zero, always check for text properties at the new position.
5532 Otherwise, text properties are only looked up if POS >=
5533 IT->check_charpos of a property. */
5536 reseat (it
, pos
, force_p
)
5538 struct text_pos pos
;
5541 int original_pos
= IT_CHARPOS (*it
);
5543 reseat_1 (it
, pos
, 0);
5545 /* Determine where to check text properties. Avoid doing it
5546 where possible because text property lookup is very expensive. */
5548 || CHARPOS (pos
) > it
->stop_charpos
5549 || CHARPOS (pos
) < original_pos
)
5556 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5557 IT->stop_pos to POS, also. */
5560 reseat_1 (it
, pos
, set_stop_p
)
5562 struct text_pos pos
;
5565 /* Don't call this function when scanning a C string. */
5566 xassert (it
->s
== NULL
);
5568 /* POS must be a reasonable value. */
5569 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5571 it
->current
.pos
= it
->position
= pos
;
5572 it
->end_charpos
= ZV
;
5574 it
->current
.dpvec_index
= -1;
5575 it
->current
.overlay_string_index
= -1;
5576 IT_STRING_CHARPOS (*it
) = -1;
5577 IT_STRING_BYTEPOS (*it
) = -1;
5579 it
->method
= GET_FROM_BUFFER
;
5580 it
->object
= it
->w
->buffer
;
5581 it
->area
= TEXT_AREA
;
5582 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5584 it
->string_from_display_prop_p
= 0;
5585 it
->face_before_selective_p
= 0;
5588 it
->stop_charpos
= CHARPOS (pos
);
5592 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5593 If S is non-null, it is a C string to iterate over. Otherwise,
5594 STRING gives a Lisp string to iterate over.
5596 If PRECISION > 0, don't return more then PRECISION number of
5597 characters from the string.
5599 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5600 characters have been returned. FIELD_WIDTH < 0 means an infinite
5603 MULTIBYTE = 0 means disable processing of multibyte characters,
5604 MULTIBYTE > 0 means enable it,
5605 MULTIBYTE < 0 means use IT->multibyte_p.
5607 IT must be initialized via a prior call to init_iterator before
5608 calling this function. */
5611 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5616 int precision
, field_width
, multibyte
;
5618 /* No region in strings. */
5619 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5621 /* No text property checks performed by default, but see below. */
5622 it
->stop_charpos
= -1;
5624 /* Set iterator position and end position. */
5625 bzero (&it
->current
, sizeof it
->current
);
5626 it
->current
.overlay_string_index
= -1;
5627 it
->current
.dpvec_index
= -1;
5628 xassert (charpos
>= 0);
5630 /* If STRING is specified, use its multibyteness, otherwise use the
5631 setting of MULTIBYTE, if specified. */
5633 it
->multibyte_p
= multibyte
> 0;
5637 xassert (STRINGP (string
));
5638 it
->string
= string
;
5640 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5641 it
->method
= GET_FROM_STRING
;
5642 it
->current
.string_pos
= string_pos (charpos
, string
);
5649 /* Note that we use IT->current.pos, not it->current.string_pos,
5650 for displaying C strings. */
5651 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5652 if (it
->multibyte_p
)
5654 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5655 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5659 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5660 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5663 it
->method
= GET_FROM_C_STRING
;
5666 /* PRECISION > 0 means don't return more than PRECISION characters
5668 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5669 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5671 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5672 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5673 FIELD_WIDTH < 0 means infinite field width. This is useful for
5674 padding with `-' at the end of a mode line. */
5675 if (field_width
< 0)
5676 field_width
= INFINITY
;
5677 if (field_width
> it
->end_charpos
- charpos
)
5678 it
->end_charpos
= charpos
+ field_width
;
5680 /* Use the standard display table for displaying strings. */
5681 if (DISP_TABLE_P (Vstandard_display_table
))
5682 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5684 it
->stop_charpos
= charpos
;
5690 /***********************************************************************
5692 ***********************************************************************/
5694 /* Map enum it_method value to corresponding next_element_from_* function. */
5696 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5698 next_element_from_buffer
,
5699 next_element_from_display_vector
,
5700 next_element_from_composition
,
5701 next_element_from_string
,
5702 next_element_from_c_string
,
5703 next_element_from_image
,
5704 next_element_from_stretch
5707 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5709 /* Load IT's display element fields with information about the next
5710 display element from the current position of IT. Value is zero if
5711 end of buffer (or C string) is reached. */
5713 static struct frame
*last_escape_glyph_frame
= NULL
;
5714 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5715 static int last_escape_glyph_merged_face_id
= 0;
5718 get_next_display_element (it
)
5721 /* Non-zero means that we found a display element. Zero means that
5722 we hit the end of what we iterate over. Performance note: the
5723 function pointer `method' used here turns out to be faster than
5724 using a sequence of if-statements. */
5728 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5730 if (it
->what
== IT_CHARACTER
)
5732 /* Map via display table or translate control characters.
5733 IT->c, IT->len etc. have been set to the next character by
5734 the function call above. If we have a display table, and it
5735 contains an entry for IT->c, translate it. Don't do this if
5736 IT->c itself comes from a display table, otherwise we could
5737 end up in an infinite recursion. (An alternative could be to
5738 count the recursion depth of this function and signal an
5739 error when a certain maximum depth is reached.) Is it worth
5741 if (success_p
&& it
->dpvec
== NULL
)
5746 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5749 struct Lisp_Vector
*v
= XVECTOR (dv
);
5751 /* Return the first character from the display table
5752 entry, if not empty. If empty, don't display the
5753 current character. */
5756 it
->dpvec_char_len
= it
->len
;
5757 it
->dpvec
= v
->contents
;
5758 it
->dpend
= v
->contents
+ v
->size
;
5759 it
->current
.dpvec_index
= 0;
5760 it
->dpvec_face_id
= -1;
5761 it
->saved_face_id
= it
->face_id
;
5762 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5767 set_iterator_to_next (it
, 0);
5772 /* Translate control characters into `\003' or `^C' form.
5773 Control characters coming from a display table entry are
5774 currently not translated because we use IT->dpvec to hold
5775 the translation. This could easily be changed but I
5776 don't believe that it is worth doing.
5778 If it->multibyte_p is nonzero, non-printable non-ASCII
5779 characters are also translated to octal form.
5781 If it->multibyte_p is zero, eight-bit characters that
5782 don't have corresponding multibyte char code are also
5783 translated to octal form. */
5784 else if ((it
->c
< ' '
5785 ? (it
->area
!= TEXT_AREA
5786 /* In mode line, treat \n, \t like other crl chars. */
5788 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5789 || (it
->c
!= '\n' && it
->c
!= '\t'))
5791 ? (!CHAR_PRINTABLE_P (it
->c
)
5792 || (!NILP (Vnobreak_char_display
)
5793 && (it
->c
== 0xA0 /* NO-BREAK SPACE */
5794 || it
->c
== 0xAD /* SOFT HYPHEN */)))
5796 && (! unibyte_display_via_language_environment
5797 || (UNIBYTE_CHAR_HAS_MULTIBYTE_P (it
->c
)))))))
5799 /* IT->c is a control character which must be displayed
5800 either as '\003' or as `^C' where the '\\' and '^'
5801 can be defined in the display table. Fill
5802 IT->ctl_chars with glyphs for what we have to
5803 display. Then, set IT->dpvec to these glyphs. */
5806 int face_id
, lface_id
= 0 ;
5809 /* Handle control characters with ^. */
5811 if (it
->c
< 128 && it
->ctl_arrow_p
)
5815 g
= '^'; /* default glyph for Control */
5816 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5818 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5819 && GLYPH_CODE_CHAR_VALID_P (gc
))
5821 g
= GLYPH_CODE_CHAR (gc
);
5822 lface_id
= GLYPH_CODE_FACE (gc
);
5826 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5828 else if (it
->f
== last_escape_glyph_frame
5829 && it
->face_id
== last_escape_glyph_face_id
)
5831 face_id
= last_escape_glyph_merged_face_id
;
5835 /* Merge the escape-glyph face into the current face. */
5836 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5838 last_escape_glyph_frame
= it
->f
;
5839 last_escape_glyph_face_id
= it
->face_id
;
5840 last_escape_glyph_merged_face_id
= face_id
;
5843 XSETINT (it
->ctl_chars
[0], g
);
5844 XSETINT (it
->ctl_chars
[1], it
->c
^ 0100);
5846 goto display_control
;
5849 /* Handle non-break space in the mode where it only gets
5852 if (EQ (Vnobreak_char_display
, Qt
)
5855 /* Merge the no-break-space face into the current face. */
5856 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5860 XSETINT (it
->ctl_chars
[0], ' ');
5862 goto display_control
;
5865 /* Handle sequences that start with the "escape glyph". */
5867 /* the default escape glyph is \. */
5868 escape_glyph
= '\\';
5871 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5872 && GLYPH_CODE_CHAR_VALID_P (gc
))
5874 escape_glyph
= GLYPH_CODE_CHAR (gc
);
5875 lface_id
= GLYPH_CODE_FACE (gc
);
5879 /* The display table specified a face.
5880 Merge it into face_id and also into escape_glyph. */
5881 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5884 else if (it
->f
== last_escape_glyph_frame
5885 && it
->face_id
== last_escape_glyph_face_id
)
5887 face_id
= last_escape_glyph_merged_face_id
;
5891 /* Merge the escape-glyph face into the current face. */
5892 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5894 last_escape_glyph_frame
= it
->f
;
5895 last_escape_glyph_face_id
= it
->face_id
;
5896 last_escape_glyph_merged_face_id
= face_id
;
5899 /* Handle soft hyphens in the mode where they only get
5902 if (EQ (Vnobreak_char_display
, Qt
)
5906 XSETINT (it
->ctl_chars
[0], '-');
5908 goto display_control
;
5911 /* Handle non-break space and soft hyphen
5912 with the escape glyph. */
5914 if (it
->c
== 0xA0 || it
->c
== 0xAD)
5916 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5917 it
->c
= (it
->c
== 0xA0 ? ' ' : '-');
5918 XSETINT (it
->ctl_chars
[1], it
->c
);
5920 goto display_control
;
5924 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5928 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5929 if (CHAR_BYTE8_P (it
->c
))
5931 str
[0] = CHAR_TO_BYTE8 (it
->c
);
5934 else if (it
->c
< 256)
5941 /* It's an invalid character, which shouldn't
5942 happen actually, but due to bugs it may
5943 happen. Let's print the char as is, there's
5944 not much meaningful we can do with it. */
5946 str
[1] = it
->c
>> 8;
5947 str
[2] = it
->c
>> 16;
5948 str
[3] = it
->c
>> 24;
5952 for (i
= 0; i
< len
; i
++)
5955 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5956 /* Insert three more glyphs into IT->ctl_chars for
5957 the octal display of the character. */
5958 g
= ((str
[i
] >> 6) & 7) + '0';
5959 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5960 g
= ((str
[i
] >> 3) & 7) + '0';
5961 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5962 g
= (str
[i
] & 7) + '0';
5963 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5969 /* Set up IT->dpvec and return first character from it. */
5970 it
->dpvec_char_len
= it
->len
;
5971 it
->dpvec
= it
->ctl_chars
;
5972 it
->dpend
= it
->dpvec
+ ctl_len
;
5973 it
->current
.dpvec_index
= 0;
5974 it
->dpvec_face_id
= face_id
;
5975 it
->saved_face_id
= it
->face_id
;
5976 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5983 /* Adjust face id for a multibyte character. There are no multibyte
5984 character in unibyte text. */
5985 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
5988 && FRAME_WINDOW_P (it
->f
))
5990 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5991 int pos
= (it
->s
? -1
5992 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
5993 : IT_CHARPOS (*it
));
5995 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
, pos
, it
->string
);
5998 /* Is this character the last one of a run of characters with
5999 box? If yes, set IT->end_of_box_run_p to 1. */
6006 it
->end_of_box_run_p
6007 = ((face_id
= face_after_it_pos (it
),
6008 face_id
!= it
->face_id
)
6009 && (face
= FACE_FROM_ID (it
->f
, face_id
),
6010 face
->box
== FACE_NO_BOX
));
6013 /* Value is 0 if end of buffer or string reached. */
6018 /* Move IT to the next display element.
6020 RESEAT_P non-zero means if called on a newline in buffer text,
6021 skip to the next visible line start.
6023 Functions get_next_display_element and set_iterator_to_next are
6024 separate because I find this arrangement easier to handle than a
6025 get_next_display_element function that also increments IT's
6026 position. The way it is we can first look at an iterator's current
6027 display element, decide whether it fits on a line, and if it does,
6028 increment the iterator position. The other way around we probably
6029 would either need a flag indicating whether the iterator has to be
6030 incremented the next time, or we would have to implement a
6031 decrement position function which would not be easy to write. */
6034 set_iterator_to_next (it
, reseat_p
)
6038 /* Reset flags indicating start and end of a sequence of characters
6039 with box. Reset them at the start of this function because
6040 moving the iterator to a new position might set them. */
6041 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6045 case GET_FROM_BUFFER
:
6046 /* The current display element of IT is a character from
6047 current_buffer. Advance in the buffer, and maybe skip over
6048 invisible lines that are so because of selective display. */
6049 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6050 reseat_at_next_visible_line_start (it
, 0);
6053 xassert (it
->len
!= 0);
6054 IT_BYTEPOS (*it
) += it
->len
;
6055 IT_CHARPOS (*it
) += 1;
6056 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6060 case GET_FROM_COMPOSITION
:
6061 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
6062 xassert (it
->sp
> 0);
6064 if (it
->method
== GET_FROM_STRING
)
6066 IT_STRING_BYTEPOS (*it
) += it
->len
;
6067 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
6068 goto consider_string_end
;
6070 else if (it
->method
== GET_FROM_BUFFER
)
6072 IT_BYTEPOS (*it
) += it
->len
;
6073 IT_CHARPOS (*it
) += it
->cmp_len
;
6077 case GET_FROM_C_STRING
:
6078 /* Current display element of IT is from a C string. */
6079 IT_BYTEPOS (*it
) += it
->len
;
6080 IT_CHARPOS (*it
) += 1;
6083 case GET_FROM_DISPLAY_VECTOR
:
6084 /* Current display element of IT is from a display table entry.
6085 Advance in the display table definition. Reset it to null if
6086 end reached, and continue with characters from buffers/
6088 ++it
->current
.dpvec_index
;
6090 /* Restore face of the iterator to what they were before the
6091 display vector entry (these entries may contain faces). */
6092 it
->face_id
= it
->saved_face_id
;
6094 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6096 int recheck_faces
= it
->ellipsis_p
;
6099 it
->method
= GET_FROM_C_STRING
;
6100 else if (STRINGP (it
->string
))
6101 it
->method
= GET_FROM_STRING
;
6104 it
->method
= GET_FROM_BUFFER
;
6105 it
->object
= it
->w
->buffer
;
6109 it
->current
.dpvec_index
= -1;
6111 /* Skip over characters which were displayed via IT->dpvec. */
6112 if (it
->dpvec_char_len
< 0)
6113 reseat_at_next_visible_line_start (it
, 1);
6114 else if (it
->dpvec_char_len
> 0)
6116 if (it
->method
== GET_FROM_STRING
6117 && it
->n_overlay_strings
> 0)
6118 it
->ignore_overlay_strings_at_pos_p
= 1;
6119 it
->len
= it
->dpvec_char_len
;
6120 set_iterator_to_next (it
, reseat_p
);
6123 /* Maybe recheck faces after display vector */
6125 it
->stop_charpos
= IT_CHARPOS (*it
);
6129 case GET_FROM_STRING
:
6130 /* Current display element is a character from a Lisp string. */
6131 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6132 IT_STRING_BYTEPOS (*it
) += it
->len
;
6133 IT_STRING_CHARPOS (*it
) += 1;
6135 consider_string_end
:
6137 if (it
->current
.overlay_string_index
>= 0)
6139 /* IT->string is an overlay string. Advance to the
6140 next, if there is one. */
6141 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6142 next_overlay_string (it
);
6146 /* IT->string is not an overlay string. If we reached
6147 its end, and there is something on IT->stack, proceed
6148 with what is on the stack. This can be either another
6149 string, this time an overlay string, or a buffer. */
6150 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6154 if (it
->method
== GET_FROM_STRING
)
6155 goto consider_string_end
;
6160 case GET_FROM_IMAGE
:
6161 case GET_FROM_STRETCH
:
6162 /* The position etc with which we have to proceed are on
6163 the stack. The position may be at the end of a string,
6164 if the `display' property takes up the whole string. */
6165 xassert (it
->sp
> 0);
6167 if (it
->method
== GET_FROM_STRING
)
6168 goto consider_string_end
;
6172 /* There are no other methods defined, so this should be a bug. */
6176 xassert (it
->method
!= GET_FROM_STRING
6177 || (STRINGP (it
->string
)
6178 && IT_STRING_CHARPOS (*it
) >= 0));
6181 /* Load IT's display element fields with information about the next
6182 display element which comes from a display table entry or from the
6183 result of translating a control character to one of the forms `^C'
6186 IT->dpvec holds the glyphs to return as characters.
6187 IT->saved_face_id holds the face id before the display vector--
6188 it is restored into IT->face_idin set_iterator_to_next. */
6191 next_element_from_display_vector (it
)
6197 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6199 it
->face_id
= it
->saved_face_id
;
6201 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6202 That seemed totally bogus - so I changed it... */
6204 if ((gc
= it
->dpvec
[it
->current
.dpvec_index
], GLYPH_CODE_P (gc
))
6205 && GLYPH_CODE_CHAR_VALID_P (gc
))
6207 it
->c
= GLYPH_CODE_CHAR (gc
);
6208 it
->len
= CHAR_BYTES (it
->c
);
6210 /* The entry may contain a face id to use. Such a face id is
6211 the id of a Lisp face, not a realized face. A face id of
6212 zero means no face is specified. */
6213 if (it
->dpvec_face_id
>= 0)
6214 it
->face_id
= it
->dpvec_face_id
;
6217 int lface_id
= GLYPH_CODE_FACE (gc
);
6219 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6224 /* Display table entry is invalid. Return a space. */
6225 it
->c
= ' ', it
->len
= 1;
6227 /* Don't change position and object of the iterator here. They are
6228 still the values of the character that had this display table
6229 entry or was translated, and that's what we want. */
6230 it
->what
= IT_CHARACTER
;
6235 /* Load IT with the next display element from Lisp string IT->string.
6236 IT->current.string_pos is the current position within the string.
6237 If IT->current.overlay_string_index >= 0, the Lisp string is an
6241 next_element_from_string (it
)
6244 struct text_pos position
;
6246 xassert (STRINGP (it
->string
));
6247 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6248 position
= it
->current
.string_pos
;
6250 /* Time to check for invisible text? */
6251 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6252 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6256 /* Since a handler may have changed IT->method, we must
6258 return GET_NEXT_DISPLAY_ELEMENT (it
);
6261 if (it
->current
.overlay_string_index
>= 0)
6263 /* Get the next character from an overlay string. In overlay
6264 strings, There is no field width or padding with spaces to
6266 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6271 else if (STRING_MULTIBYTE (it
->string
))
6273 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6274 const unsigned char *s
= (SDATA (it
->string
)
6275 + IT_STRING_BYTEPOS (*it
));
6276 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
6280 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6286 /* Get the next character from a Lisp string that is not an
6287 overlay string. Such strings come from the mode line, for
6288 example. We may have to pad with spaces, or truncate the
6289 string. See also next_element_from_c_string. */
6290 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6295 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6297 /* Pad with spaces. */
6298 it
->c
= ' ', it
->len
= 1;
6299 CHARPOS (position
) = BYTEPOS (position
) = -1;
6301 else if (STRING_MULTIBYTE (it
->string
))
6303 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6304 const unsigned char *s
= (SDATA (it
->string
)
6305 + IT_STRING_BYTEPOS (*it
));
6306 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
6310 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6315 /* Record what we have and where it came from. */
6316 it
->what
= IT_CHARACTER
;
6317 it
->object
= it
->string
;
6318 it
->position
= position
;
6323 /* Load IT with next display element from C string IT->s.
6324 IT->string_nchars is the maximum number of characters to return
6325 from the string. IT->end_charpos may be greater than
6326 IT->string_nchars when this function is called, in which case we
6327 may have to return padding spaces. Value is zero if end of string
6328 reached, including padding spaces. */
6331 next_element_from_c_string (it
)
6337 it
->what
= IT_CHARACTER
;
6338 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6341 /* IT's position can be greater IT->string_nchars in case a field
6342 width or precision has been specified when the iterator was
6344 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6346 /* End of the game. */
6350 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6352 /* Pad with spaces. */
6353 it
->c
= ' ', it
->len
= 1;
6354 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6356 else if (it
->multibyte_p
)
6358 /* Implementation note: The calls to strlen apparently aren't a
6359 performance problem because there is no noticeable performance
6360 difference between Emacs running in unibyte or multibyte mode. */
6361 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6362 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
6366 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6372 /* Set up IT to return characters from an ellipsis, if appropriate.
6373 The definition of the ellipsis glyphs may come from a display table
6374 entry. This function Fills IT with the first glyph from the
6375 ellipsis if an ellipsis is to be displayed. */
6378 next_element_from_ellipsis (it
)
6381 if (it
->selective_display_ellipsis_p
)
6382 setup_for_ellipsis (it
, it
->len
);
6385 /* The face at the current position may be different from the
6386 face we find after the invisible text. Remember what it
6387 was in IT->saved_face_id, and signal that it's there by
6388 setting face_before_selective_p. */
6389 it
->saved_face_id
= it
->face_id
;
6390 it
->method
= GET_FROM_BUFFER
;
6391 it
->object
= it
->w
->buffer
;
6392 reseat_at_next_visible_line_start (it
, 1);
6393 it
->face_before_selective_p
= 1;
6396 return GET_NEXT_DISPLAY_ELEMENT (it
);
6400 /* Deliver an image display element. The iterator IT is already
6401 filled with image information (done in handle_display_prop). Value
6406 next_element_from_image (it
)
6409 it
->what
= IT_IMAGE
;
6414 /* Fill iterator IT with next display element from a stretch glyph
6415 property. IT->object is the value of the text property. Value is
6419 next_element_from_stretch (it
)
6422 it
->what
= IT_STRETCH
;
6427 /* Load IT with the next display element from current_buffer. Value
6428 is zero if end of buffer reached. IT->stop_charpos is the next
6429 position at which to stop and check for text properties or buffer
6433 next_element_from_buffer (it
)
6438 /* Check this assumption, otherwise, we would never enter the
6439 if-statement, below. */
6440 xassert (IT_CHARPOS (*it
) >= BEGV
6441 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
6443 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6445 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6447 int overlay_strings_follow_p
;
6449 /* End of the game, except when overlay strings follow that
6450 haven't been returned yet. */
6451 if (it
->overlay_strings_at_end_processed_p
)
6452 overlay_strings_follow_p
= 0;
6455 it
->overlay_strings_at_end_processed_p
= 1;
6456 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6459 if (overlay_strings_follow_p
)
6460 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6464 it
->position
= it
->current
.pos
;
6471 return GET_NEXT_DISPLAY_ELEMENT (it
);
6476 /* No face changes, overlays etc. in sight, so just return a
6477 character from current_buffer. */
6480 /* Maybe run the redisplay end trigger hook. Performance note:
6481 This doesn't seem to cost measurable time. */
6482 if (it
->redisplay_end_trigger_charpos
6484 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6485 run_redisplay_end_trigger_hook (it
);
6487 /* Get the next character, maybe multibyte. */
6488 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6489 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6491 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
6492 - IT_BYTEPOS (*it
));
6493 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
6496 it
->c
= *p
, it
->len
= 1;
6498 /* Record what we have and where it came from. */
6499 it
->what
= IT_CHARACTER
;
6500 it
->object
= it
->w
->buffer
;
6501 it
->position
= it
->current
.pos
;
6503 /* Normally we return the character found above, except when we
6504 really want to return an ellipsis for selective display. */
6509 /* A value of selective > 0 means hide lines indented more
6510 than that number of columns. */
6511 if (it
->selective
> 0
6512 && IT_CHARPOS (*it
) + 1 < ZV
6513 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6514 IT_BYTEPOS (*it
) + 1,
6515 (double) it
->selective
)) /* iftc */
6517 success_p
= next_element_from_ellipsis (it
);
6518 it
->dpvec_char_len
= -1;
6521 else if (it
->c
== '\r' && it
->selective
== -1)
6523 /* A value of selective == -1 means that everything from the
6524 CR to the end of the line is invisible, with maybe an
6525 ellipsis displayed for it. */
6526 success_p
= next_element_from_ellipsis (it
);
6527 it
->dpvec_char_len
= -1;
6532 /* Value is zero if end of buffer reached. */
6533 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6538 /* Run the redisplay end trigger hook for IT. */
6541 run_redisplay_end_trigger_hook (it
)
6544 Lisp_Object args
[3];
6546 /* IT->glyph_row should be non-null, i.e. we should be actually
6547 displaying something, or otherwise we should not run the hook. */
6548 xassert (it
->glyph_row
);
6550 /* Set up hook arguments. */
6551 args
[0] = Qredisplay_end_trigger_functions
;
6552 args
[1] = it
->window
;
6553 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6554 it
->redisplay_end_trigger_charpos
= 0;
6556 /* Since we are *trying* to run these functions, don't try to run
6557 them again, even if they get an error. */
6558 it
->w
->redisplay_end_trigger
= Qnil
;
6559 Frun_hook_with_args (3, args
);
6561 /* Notice if it changed the face of the character we are on. */
6562 handle_face_prop (it
);
6566 /* Deliver a composition display element. The iterator IT is already
6567 filled with composition information (done in
6568 handle_composition_prop). Value is always 1. */
6571 next_element_from_composition (it
)
6574 it
->what
= IT_COMPOSITION
;
6575 it
->position
= (STRINGP (it
->string
)
6576 ? it
->current
.string_pos
6578 if (STRINGP (it
->string
))
6579 it
->object
= it
->string
;
6581 it
->object
= it
->w
->buffer
;
6587 /***********************************************************************
6588 Moving an iterator without producing glyphs
6589 ***********************************************************************/
6591 /* Check if iterator is at a position corresponding to a valid buffer
6592 position after some move_it_ call. */
6594 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6595 ((it)->method == GET_FROM_STRING \
6596 ? IT_STRING_CHARPOS (*it) == 0 \
6600 /* Move iterator IT to a specified buffer or X position within one
6601 line on the display without producing glyphs.
6603 OP should be a bit mask including some or all of these bits:
6604 MOVE_TO_X: Stop on reaching x-position TO_X.
6605 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6606 Regardless of OP's value, stop in reaching the end of the display line.
6608 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6609 This means, in particular, that TO_X includes window's horizontal
6612 The return value has several possible values that
6613 say what condition caused the scan to stop:
6615 MOVE_POS_MATCH_OR_ZV
6616 - when TO_POS or ZV was reached.
6619 -when TO_X was reached before TO_POS or ZV were reached.
6622 - when we reached the end of the display area and the line must
6626 - when we reached the end of the display area and the line is
6630 - when we stopped at a line end, i.e. a newline or a CR and selective
6633 static enum move_it_result
6634 move_it_in_display_line_to (struct it
*it
,
6635 EMACS_INT to_charpos
, int to_x
,
6636 enum move_operation_enum op
)
6638 enum move_it_result result
= MOVE_UNDEFINED
;
6639 struct glyph_row
*saved_glyph_row
;
6641 /* Don't produce glyphs in produce_glyphs. */
6642 saved_glyph_row
= it
->glyph_row
;
6643 it
->glyph_row
= NULL
;
6645 #define BUFFER_POS_REACHED_P() \
6646 ((op & MOVE_TO_POS) != 0 \
6647 && BUFFERP (it->object) \
6648 && IT_CHARPOS (*it) >= to_charpos \
6649 && (it->method == GET_FROM_BUFFER \
6650 || (it->method == GET_FROM_DISPLAY_VECTOR \
6651 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6656 int x
, i
, ascent
= 0, descent
= 0;
6658 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
6659 if ((op
& MOVE_TO_POS
) != 0
6660 && BUFFERP (it
->object
)
6661 && it
->method
== GET_FROM_BUFFER
6662 && IT_CHARPOS (*it
) > to_charpos
)
6664 result
= MOVE_POS_MATCH_OR_ZV
;
6668 /* Stop when ZV reached.
6669 We used to stop here when TO_CHARPOS reached as well, but that is
6670 too soon if this glyph does not fit on this line. So we handle it
6671 explicitly below. */
6672 if (!get_next_display_element (it
)
6673 || (it
->truncate_lines_p
6674 && BUFFER_POS_REACHED_P ()))
6676 result
= MOVE_POS_MATCH_OR_ZV
;
6680 /* The call to produce_glyphs will get the metrics of the
6681 display element IT is loaded with. We record in x the
6682 x-position before this display element in case it does not
6686 /* Remember the line height so far in case the next element doesn't
6688 if (!it
->truncate_lines_p
)
6690 ascent
= it
->max_ascent
;
6691 descent
= it
->max_descent
;
6694 PRODUCE_GLYPHS (it
);
6696 if (it
->area
!= TEXT_AREA
)
6698 set_iterator_to_next (it
, 1);
6702 /* The number of glyphs we get back in IT->nglyphs will normally
6703 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6704 character on a terminal frame, or (iii) a line end. For the
6705 second case, IT->nglyphs - 1 padding glyphs will be present
6706 (on X frames, there is only one glyph produced for a
6707 composite character.
6709 The behavior implemented below means, for continuation lines,
6710 that as many spaces of a TAB as fit on the current line are
6711 displayed there. For terminal frames, as many glyphs of a
6712 multi-glyph character are displayed in the current line, too.
6713 This is what the old redisplay code did, and we keep it that
6714 way. Under X, the whole shape of a complex character must
6715 fit on the line or it will be completely displayed in the
6718 Note that both for tabs and padding glyphs, all glyphs have
6722 /* More than one glyph or glyph doesn't fit on line. All
6723 glyphs have the same width. */
6724 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6726 int x_before_this_char
= x
;
6727 int hpos_before_this_char
= it
->hpos
;
6729 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6731 new_x
= x
+ single_glyph_width
;
6733 /* We want to leave anything reaching TO_X to the caller. */
6734 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6736 if (BUFFER_POS_REACHED_P ())
6737 goto buffer_pos_reached
;
6739 result
= MOVE_X_REACHED
;
6742 else if (/* Lines are continued. */
6743 !it
->truncate_lines_p
6744 && (/* And glyph doesn't fit on the line. */
6745 new_x
> it
->last_visible_x
6746 /* Or it fits exactly and we're on a window
6748 || (new_x
== it
->last_visible_x
6749 && FRAME_WINDOW_P (it
->f
))))
6751 if (/* IT->hpos == 0 means the very first glyph
6752 doesn't fit on the line, e.g. a wide image. */
6754 || (new_x
== it
->last_visible_x
6755 && FRAME_WINDOW_P (it
->f
)))
6758 it
->current_x
= new_x
;
6760 /* The character's last glyph just barely fits
6762 if (i
== it
->nglyphs
- 1)
6764 /* If this is the destination position,
6765 return a position *before* it in this row,
6766 now that we know it fits in this row. */
6767 if (BUFFER_POS_REACHED_P ())
6769 it
->hpos
= hpos_before_this_char
;
6770 it
->current_x
= x_before_this_char
;
6771 result
= MOVE_POS_MATCH_OR_ZV
;
6775 set_iterator_to_next (it
, 1);
6776 #ifdef HAVE_WINDOW_SYSTEM
6777 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6779 if (!get_next_display_element (it
))
6781 result
= MOVE_POS_MATCH_OR_ZV
;
6784 if (BUFFER_POS_REACHED_P ())
6786 if (ITERATOR_AT_END_OF_LINE_P (it
))
6787 result
= MOVE_POS_MATCH_OR_ZV
;
6789 result
= MOVE_LINE_CONTINUED
;
6792 if (ITERATOR_AT_END_OF_LINE_P (it
))
6794 result
= MOVE_NEWLINE_OR_CR
;
6798 #endif /* HAVE_WINDOW_SYSTEM */
6804 it
->max_ascent
= ascent
;
6805 it
->max_descent
= descent
;
6808 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6810 result
= MOVE_LINE_CONTINUED
;
6813 else if (BUFFER_POS_REACHED_P ())
6814 goto buffer_pos_reached
;
6815 else if (new_x
> it
->first_visible_x
)
6817 /* Glyph is visible. Increment number of glyphs that
6818 would be displayed. */
6823 /* Glyph is completely off the left margin of the display
6824 area. Nothing to do. */
6828 if (result
!= MOVE_UNDEFINED
)
6831 else if (BUFFER_POS_REACHED_P ())
6835 it
->max_ascent
= ascent
;
6836 it
->max_descent
= descent
;
6837 result
= MOVE_POS_MATCH_OR_ZV
;
6840 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6842 /* Stop when TO_X specified and reached. This check is
6843 necessary here because of lines consisting of a line end,
6844 only. The line end will not produce any glyphs and we
6845 would never get MOVE_X_REACHED. */
6846 xassert (it
->nglyphs
== 0);
6847 result
= MOVE_X_REACHED
;
6851 /* Is this a line end? If yes, we're done. */
6852 if (ITERATOR_AT_END_OF_LINE_P (it
))
6854 result
= MOVE_NEWLINE_OR_CR
;
6858 /* The current display element has been consumed. Advance
6860 set_iterator_to_next (it
, 1);
6862 /* Stop if lines are truncated and IT's current x-position is
6863 past the right edge of the window now. */
6864 if (it
->truncate_lines_p
6865 && it
->current_x
>= it
->last_visible_x
)
6867 #ifdef HAVE_WINDOW_SYSTEM
6868 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6870 if (!get_next_display_element (it
)
6871 || BUFFER_POS_REACHED_P ())
6873 result
= MOVE_POS_MATCH_OR_ZV
;
6876 if (ITERATOR_AT_END_OF_LINE_P (it
))
6878 result
= MOVE_NEWLINE_OR_CR
;
6882 #endif /* HAVE_WINDOW_SYSTEM */
6883 result
= MOVE_LINE_TRUNCATED
;
6888 #undef BUFFER_POS_REACHED_P
6890 /* Restore the iterator settings altered at the beginning of this
6892 it
->glyph_row
= saved_glyph_row
;
6896 /* For external use. */
6898 move_it_in_display_line (struct it
*it
,
6899 EMACS_INT to_charpos
, int to_x
,
6900 enum move_operation_enum op
)
6902 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6906 /* Move IT forward until it satisfies one or more of the criteria in
6907 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6909 OP is a bit-mask that specifies where to stop, and in particular,
6910 which of those four position arguments makes a difference. See the
6911 description of enum move_operation_enum.
6913 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6914 screen line, this function will set IT to the next position >
6918 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6920 int to_charpos
, to_x
, to_y
, to_vpos
;
6923 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6929 if (op
& MOVE_TO_VPOS
)
6931 /* If no TO_CHARPOS and no TO_X specified, stop at the
6932 start of the line TO_VPOS. */
6933 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6935 if (it
->vpos
== to_vpos
)
6941 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6945 /* TO_VPOS >= 0 means stop at TO_X in the line at
6946 TO_VPOS, or at TO_POS, whichever comes first. */
6947 if (it
->vpos
== to_vpos
)
6953 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6955 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6960 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6962 /* We have reached TO_X but not in the line we want. */
6963 skip
= move_it_in_display_line_to (it
, to_charpos
,
6965 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6973 else if (op
& MOVE_TO_Y
)
6975 struct it it_backup
;
6977 /* TO_Y specified means stop at TO_X in the line containing
6978 TO_Y---or at TO_CHARPOS if this is reached first. The
6979 problem is that we can't really tell whether the line
6980 contains TO_Y before we have completely scanned it, and
6981 this may skip past TO_X. What we do is to first scan to
6984 If TO_X is not specified, use a TO_X of zero. The reason
6985 is to make the outcome of this function more predictable.
6986 If we didn't use TO_X == 0, we would stop at the end of
6987 the line which is probably not what a caller would expect
6989 skip
= move_it_in_display_line_to (it
, to_charpos
,
6993 | (op
& MOVE_TO_POS
)));
6995 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6996 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7002 /* If TO_X was reached, we would like to know whether TO_Y
7003 is in the line. This can only be said if we know the
7004 total line height which requires us to scan the rest of
7006 if (skip
== MOVE_X_REACHED
)
7008 /* Wait! We can conclude that TO_Y is in the line if
7009 the already scanned glyphs make the line tall enough
7010 because further scanning doesn't make it shorter. */
7011 line_height
= it
->max_ascent
+ it
->max_descent
;
7012 if (to_y
>= it
->current_y
7013 && to_y
< it
->current_y
+ line_height
)
7019 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7020 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7022 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7025 /* Now, decide whether TO_Y is in this line. */
7026 line_height
= it
->max_ascent
+ it
->max_descent
;
7027 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7029 if (to_y
>= it
->current_y
7030 && to_y
< it
->current_y
+ line_height
)
7032 if (skip
== MOVE_X_REACHED
)
7033 /* If TO_Y is in this line and TO_X was reached above,
7034 we scanned too far. We have to restore IT's settings
7035 to the ones before skipping. */
7039 else if (skip
== MOVE_X_REACHED
)
7042 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7049 else if (BUFFERP (it
->object
)
7050 && it
->method
== GET_FROM_BUFFER
7051 && IT_CHARPOS (*it
) >= to_charpos
)
7052 skip
= MOVE_POS_MATCH_OR_ZV
;
7054 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7058 case MOVE_POS_MATCH_OR_ZV
:
7062 case MOVE_NEWLINE_OR_CR
:
7063 set_iterator_to_next (it
, 1);
7064 it
->continuation_lines_width
= 0;
7067 case MOVE_LINE_TRUNCATED
:
7068 it
->continuation_lines_width
= 0;
7069 reseat_at_next_visible_line_start (it
, 0);
7070 if ((op
& MOVE_TO_POS
) != 0
7071 && IT_CHARPOS (*it
) > to_charpos
)
7078 case MOVE_LINE_CONTINUED
:
7079 /* For continued lines ending in a tab, some of the glyphs
7080 associated with the tab are displayed on the current
7081 line. Since it->current_x does not include these glyphs,
7082 we use it->last_visible_x instead. */
7083 it
->continuation_lines_width
+=
7084 (it
->c
== '\t') ? it
->last_visible_x
: it
->current_x
;
7091 /* Reset/increment for the next run. */
7092 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7093 it
->current_x
= it
->hpos
= 0;
7094 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7096 last_height
= it
->max_ascent
+ it
->max_descent
;
7097 last_max_ascent
= it
->max_ascent
;
7098 it
->max_ascent
= it
->max_descent
= 0;
7103 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7107 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7109 If DY > 0, move IT backward at least that many pixels. DY = 0
7110 means move IT backward to the preceding line start or BEGV. This
7111 function may move over more than DY pixels if IT->current_y - DY
7112 ends up in the middle of a line; in this case IT->current_y will be
7113 set to the top of the line moved to. */
7116 move_it_vertically_backward (it
, dy
)
7127 start_pos
= IT_CHARPOS (*it
);
7129 /* Estimate how many newlines we must move back. */
7130 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7132 /* Set the iterator's position that many lines back. */
7133 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7134 back_to_previous_visible_line_start (it
);
7136 /* Reseat the iterator here. When moving backward, we don't want
7137 reseat to skip forward over invisible text, set up the iterator
7138 to deliver from overlay strings at the new position etc. So,
7139 use reseat_1 here. */
7140 reseat_1 (it
, it
->current
.pos
, 1);
7142 /* We are now surely at a line start. */
7143 it
->current_x
= it
->hpos
= 0;
7144 it
->continuation_lines_width
= 0;
7146 /* Move forward and see what y-distance we moved. First move to the
7147 start of the next line so that we get its height. We need this
7148 height to be able to tell whether we reached the specified
7151 it2
.max_ascent
= it2
.max_descent
= 0;
7154 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7155 MOVE_TO_POS
| MOVE_TO_VPOS
);
7157 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7158 xassert (IT_CHARPOS (*it
) >= BEGV
);
7161 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7162 xassert (IT_CHARPOS (*it
) >= BEGV
);
7163 /* H is the actual vertical distance from the position in *IT
7164 and the starting position. */
7165 h
= it2
.current_y
- it
->current_y
;
7166 /* NLINES is the distance in number of lines. */
7167 nlines
= it2
.vpos
- it
->vpos
;
7169 /* Correct IT's y and vpos position
7170 so that they are relative to the starting point. */
7176 /* DY == 0 means move to the start of the screen line. The
7177 value of nlines is > 0 if continuation lines were involved. */
7179 move_it_by_lines (it
, nlines
, 1);
7181 /* I think this assert is bogus if buffer contains
7182 invisible text or images. KFS. */
7183 xassert (IT_CHARPOS (*it
) <= start_pos
);
7188 /* The y-position we try to reach, relative to *IT.
7189 Note that H has been subtracted in front of the if-statement. */
7190 int target_y
= it
->current_y
+ h
- dy
;
7191 int y0
= it3
.current_y
;
7192 int y1
= line_bottom_y (&it3
);
7193 int line_height
= y1
- y0
;
7195 /* If we did not reach target_y, try to move further backward if
7196 we can. If we moved too far backward, try to move forward. */
7197 if (target_y
< it
->current_y
7198 /* This is heuristic. In a window that's 3 lines high, with
7199 a line height of 13 pixels each, recentering with point
7200 on the bottom line will try to move -39/2 = 19 pixels
7201 backward. Try to avoid moving into the first line. */
7202 && (it
->current_y
- target_y
7203 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7204 && IT_CHARPOS (*it
) > BEGV
)
7206 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7207 target_y
- it
->current_y
));
7208 dy
= it
->current_y
- target_y
;
7209 goto move_further_back
;
7211 else if (target_y
>= it
->current_y
+ line_height
7212 && IT_CHARPOS (*it
) < ZV
)
7214 /* Should move forward by at least one line, maybe more.
7216 Note: Calling move_it_by_lines can be expensive on
7217 terminal frames, where compute_motion is used (via
7218 vmotion) to do the job, when there are very long lines
7219 and truncate-lines is nil. That's the reason for
7220 treating terminal frames specially here. */
7222 if (!FRAME_WINDOW_P (it
->f
))
7223 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7228 move_it_by_lines (it
, 1, 1);
7230 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7234 /* I think this assert is bogus if buffer contains
7235 invisible text or images. KFS. */
7236 xassert (IT_CHARPOS (*it
) >= BEGV
);
7243 /* Move IT by a specified amount of pixel lines DY. DY negative means
7244 move backwards. DY = 0 means move to start of screen line. At the
7245 end, IT will be on the start of a screen line. */
7248 move_it_vertically (it
, dy
)
7253 move_it_vertically_backward (it
, -dy
);
7256 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7257 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7258 MOVE_TO_POS
| MOVE_TO_Y
);
7259 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7261 /* If buffer ends in ZV without a newline, move to the start of
7262 the line to satisfy the post-condition. */
7263 if (IT_CHARPOS (*it
) == ZV
7265 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7266 move_it_by_lines (it
, 0, 0);
7271 /* Move iterator IT past the end of the text line it is in. */
7274 move_it_past_eol (it
)
7277 enum move_it_result rc
;
7279 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7280 if (rc
== MOVE_NEWLINE_OR_CR
)
7281 set_iterator_to_next (it
, 0);
7285 #if 0 /* Currently not used. */
7287 /* Return non-zero if some text between buffer positions START_CHARPOS
7288 and END_CHARPOS is invisible. IT->window is the window for text
7292 invisible_text_between_p (it
, start_charpos
, end_charpos
)
7294 int start_charpos
, end_charpos
;
7296 Lisp_Object prop
, limit
;
7297 int invisible_found_p
;
7299 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
7301 /* Is text at START invisible? */
7302 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
7304 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
7305 invisible_found_p
= 1;
7308 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
7310 make_number (end_charpos
));
7311 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
7314 return invisible_found_p
;
7320 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7321 negative means move up. DVPOS == 0 means move to the start of the
7322 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7323 NEED_Y_P is zero, IT->current_y will be left unchanged.
7325 Further optimization ideas: If we would know that IT->f doesn't use
7326 a face with proportional font, we could be faster for
7327 truncate-lines nil. */
7330 move_it_by_lines (it
, dvpos
, need_y_p
)
7332 int dvpos
, need_y_p
;
7334 struct position pos
;
7336 /* The commented-out optimization uses vmotion on terminals. This
7337 gives bad results, because elements like it->what, on which
7338 callers such as pos_visible_p rely, aren't updated. */
7339 /* if (!FRAME_WINDOW_P (it->f))
7341 struct text_pos textpos;
7343 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7344 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7345 reseat (it, textpos, 1);
7346 it->vpos += pos.vpos;
7347 it->current_y += pos.vpos;
7353 /* DVPOS == 0 means move to the start of the screen line. */
7354 move_it_vertically_backward (it
, 0);
7355 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7356 /* Let next call to line_bottom_y calculate real line height */
7361 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7362 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7363 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7368 int start_charpos
, i
;
7370 /* Start at the beginning of the screen line containing IT's
7371 position. This may actually move vertically backwards,
7372 in case of overlays, so adjust dvpos accordingly. */
7374 move_it_vertically_backward (it
, 0);
7377 /* Go back -DVPOS visible lines and reseat the iterator there. */
7378 start_charpos
= IT_CHARPOS (*it
);
7379 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7380 back_to_previous_visible_line_start (it
);
7381 reseat (it
, it
->current
.pos
, 1);
7383 /* Move further back if we end up in a string or an image. */
7384 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7386 /* First try to move to start of display line. */
7388 move_it_vertically_backward (it
, 0);
7390 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7392 /* If start of line is still in string or image,
7393 move further back. */
7394 back_to_previous_visible_line_start (it
);
7395 reseat (it
, it
->current
.pos
, 1);
7399 it
->current_x
= it
->hpos
= 0;
7401 /* Above call may have moved too far if continuation lines
7402 are involved. Scan forward and see if it did. */
7404 it2
.vpos
= it2
.current_y
= 0;
7405 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7406 it
->vpos
-= it2
.vpos
;
7407 it
->current_y
-= it2
.current_y
;
7408 it
->current_x
= it
->hpos
= 0;
7410 /* If we moved too far back, move IT some lines forward. */
7411 if (it2
.vpos
> -dvpos
)
7413 int delta
= it2
.vpos
+ dvpos
;
7415 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7416 /* Move back again if we got too far ahead. */
7417 if (IT_CHARPOS (*it
) >= start_charpos
)
7423 /* Return 1 if IT points into the middle of a display vector. */
7426 in_display_vector_p (it
)
7429 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7430 && it
->current
.dpvec_index
> 0
7431 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7435 /***********************************************************************
7437 ***********************************************************************/
7440 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7444 add_to_log (format
, arg1
, arg2
)
7446 Lisp_Object arg1
, arg2
;
7448 Lisp_Object args
[3];
7449 Lisp_Object msg
, fmt
;
7452 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7455 /* Do nothing if called asynchronously. Inserting text into
7456 a buffer may call after-change-functions and alike and
7457 that would means running Lisp asynchronously. */
7458 if (handling_signal
)
7462 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7464 args
[0] = fmt
= build_string (format
);
7467 msg
= Fformat (3, args
);
7469 len
= SBYTES (msg
) + 1;
7470 SAFE_ALLOCA (buffer
, char *, len
);
7471 bcopy (SDATA (msg
), buffer
, len
);
7473 message_dolog (buffer
, len
- 1, 1, 0);
7480 /* Output a newline in the *Messages* buffer if "needs" one. */
7483 message_log_maybe_newline ()
7485 if (message_log_need_newline
)
7486 message_dolog ("", 0, 1, 0);
7490 /* Add a string M of length NBYTES to the message log, optionally
7491 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7492 nonzero, means interpret the contents of M as multibyte. This
7493 function calls low-level routines in order to bypass text property
7494 hooks, etc. which might not be safe to run.
7496 This may GC (insert may run before/after change hooks),
7497 so the buffer M must NOT point to a Lisp string. */
7500 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7502 int nbytes
, nlflag
, multibyte
;
7504 if (!NILP (Vmemory_full
))
7507 if (!NILP (Vmessage_log_max
))
7509 struct buffer
*oldbuf
;
7510 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7511 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7512 int point_at_end
= 0;
7514 Lisp_Object old_deactivate_mark
, tem
;
7515 struct gcpro gcpro1
;
7517 old_deactivate_mark
= Vdeactivate_mark
;
7518 oldbuf
= current_buffer
;
7519 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7520 current_buffer
->undo_list
= Qt
;
7522 oldpoint
= message_dolog_marker1
;
7523 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7524 oldbegv
= message_dolog_marker2
;
7525 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7526 oldzv
= message_dolog_marker3
;
7527 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7528 GCPRO1 (old_deactivate_mark
);
7536 BEGV_BYTE
= BEG_BYTE
;
7539 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7541 /* Insert the string--maybe converting multibyte to single byte
7542 or vice versa, so that all the text fits the buffer. */
7544 && NILP (current_buffer
->enable_multibyte_characters
))
7546 int i
, c
, char_bytes
;
7547 unsigned char work
[1];
7549 /* Convert a multibyte string to single-byte
7550 for the *Message* buffer. */
7551 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7553 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7554 work
[0] = (ASCII_CHAR_P (c
)
7556 : multibyte_char_to_unibyte (c
, Qnil
));
7557 insert_1_both (work
, 1, 1, 1, 0, 0);
7560 else if (! multibyte
7561 && ! NILP (current_buffer
->enable_multibyte_characters
))
7563 int i
, c
, char_bytes
;
7564 unsigned char *msg
= (unsigned char *) m
;
7565 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7566 /* Convert a single-byte string to multibyte
7567 for the *Message* buffer. */
7568 for (i
= 0; i
< nbytes
; i
++)
7571 c
= unibyte_char_to_multibyte (c
);
7572 char_bytes
= CHAR_STRING (c
, str
);
7573 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7577 insert_1 (m
, nbytes
, 1, 0, 0);
7581 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7582 insert_1 ("\n", 1, 1, 0, 0);
7584 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7586 this_bol_byte
= PT_BYTE
;
7588 /* See if this line duplicates the previous one.
7589 If so, combine duplicates. */
7592 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7594 prev_bol_byte
= PT_BYTE
;
7596 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7597 this_bol
, this_bol_byte
);
7600 del_range_both (prev_bol
, prev_bol_byte
,
7601 this_bol
, this_bol_byte
, 0);
7607 /* If you change this format, don't forget to also
7608 change message_log_check_duplicate. */
7609 sprintf (dupstr
, " [%d times]", dup
);
7610 duplen
= strlen (dupstr
);
7611 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7612 insert_1 (dupstr
, duplen
, 1, 0, 1);
7617 /* If we have more than the desired maximum number of lines
7618 in the *Messages* buffer now, delete the oldest ones.
7619 This is safe because we don't have undo in this buffer. */
7621 if (NATNUMP (Vmessage_log_max
))
7623 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7624 -XFASTINT (Vmessage_log_max
) - 1, 0);
7625 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7628 BEGV
= XMARKER (oldbegv
)->charpos
;
7629 BEGV_BYTE
= marker_byte_position (oldbegv
);
7638 ZV
= XMARKER (oldzv
)->charpos
;
7639 ZV_BYTE
= marker_byte_position (oldzv
);
7643 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7645 /* We can't do Fgoto_char (oldpoint) because it will run some
7647 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7648 XMARKER (oldpoint
)->bytepos
);
7651 unchain_marker (XMARKER (oldpoint
));
7652 unchain_marker (XMARKER (oldbegv
));
7653 unchain_marker (XMARKER (oldzv
));
7655 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7656 set_buffer_internal (oldbuf
);
7658 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7659 message_log_need_newline
= !nlflag
;
7660 Vdeactivate_mark
= old_deactivate_mark
;
7665 /* We are at the end of the buffer after just having inserted a newline.
7666 (Note: We depend on the fact we won't be crossing the gap.)
7667 Check to see if the most recent message looks a lot like the previous one.
7668 Return 0 if different, 1 if the new one should just replace it, or a
7669 value N > 1 if we should also append " [N times]". */
7672 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7673 int prev_bol
, this_bol
;
7674 int prev_bol_byte
, this_bol_byte
;
7677 int len
= Z_BYTE
- 1 - this_bol_byte
;
7679 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7680 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7682 for (i
= 0; i
< len
; i
++)
7684 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7692 if (*p1
++ == ' ' && *p1
++ == '[')
7695 while (*p1
>= '0' && *p1
<= '9')
7696 n
= n
* 10 + *p1
++ - '0';
7697 if (strncmp (p1
, " times]\n", 8) == 0)
7704 /* Display an echo area message M with a specified length of NBYTES
7705 bytes. The string may include null characters. If M is 0, clear
7706 out any existing message, and let the mini-buffer text show
7709 This may GC, so the buffer M must NOT point to a Lisp string. */
7712 message2 (m
, nbytes
, multibyte
)
7717 /* First flush out any partial line written with print. */
7718 message_log_maybe_newline ();
7720 message_dolog (m
, nbytes
, 1, multibyte
);
7721 message2_nolog (m
, nbytes
, multibyte
);
7725 /* The non-logging counterpart of message2. */
7728 message2_nolog (m
, nbytes
, multibyte
)
7730 int nbytes
, multibyte
;
7732 struct frame
*sf
= SELECTED_FRAME ();
7733 message_enable_multibyte
= multibyte
;
7737 if (noninteractive_need_newline
)
7738 putc ('\n', stderr
);
7739 noninteractive_need_newline
= 0;
7741 fwrite (m
, nbytes
, 1, stderr
);
7742 if (cursor_in_echo_area
== 0)
7743 fprintf (stderr
, "\n");
7746 /* A null message buffer means that the frame hasn't really been
7747 initialized yet. Error messages get reported properly by
7748 cmd_error, so this must be just an informative message; toss it. */
7749 else if (INTERACTIVE
7750 && sf
->glyphs_initialized_p
7751 && FRAME_MESSAGE_BUF (sf
))
7753 Lisp_Object mini_window
;
7756 /* Get the frame containing the mini-buffer
7757 that the selected frame is using. */
7758 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7759 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7761 FRAME_SAMPLE_VISIBILITY (f
);
7762 if (FRAME_VISIBLE_P (sf
)
7763 && ! FRAME_VISIBLE_P (f
))
7764 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7768 set_message (m
, Qnil
, nbytes
, multibyte
);
7769 if (minibuffer_auto_raise
)
7770 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7773 clear_message (1, 1);
7775 do_pending_window_change (0);
7776 echo_area_display (1);
7777 do_pending_window_change (0);
7778 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7779 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7784 /* Display an echo area message M with a specified length of NBYTES
7785 bytes. The string may include null characters. If M is not a
7786 string, clear out any existing message, and let the mini-buffer
7789 This function cancels echoing. */
7792 message3 (m
, nbytes
, multibyte
)
7797 struct gcpro gcpro1
;
7800 clear_message (1,1);
7803 /* First flush out any partial line written with print. */
7804 message_log_maybe_newline ();
7810 SAFE_ALLOCA (buffer
, char *, nbytes
);
7811 bcopy (SDATA (m
), buffer
, nbytes
);
7812 message_dolog (buffer
, nbytes
, 1, multibyte
);
7815 message3_nolog (m
, nbytes
, multibyte
);
7821 /* The non-logging version of message3.
7822 This does not cancel echoing, because it is used for echoing.
7823 Perhaps we need to make a separate function for echoing
7824 and make this cancel echoing. */
7827 message3_nolog (m
, nbytes
, multibyte
)
7829 int nbytes
, multibyte
;
7831 struct frame
*sf
= SELECTED_FRAME ();
7832 message_enable_multibyte
= multibyte
;
7836 if (noninteractive_need_newline
)
7837 putc ('\n', stderr
);
7838 noninteractive_need_newline
= 0;
7840 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7841 if (cursor_in_echo_area
== 0)
7842 fprintf (stderr
, "\n");
7845 /* A null message buffer means that the frame hasn't really been
7846 initialized yet. Error messages get reported properly by
7847 cmd_error, so this must be just an informative message; toss it. */
7848 else if (INTERACTIVE
7849 && sf
->glyphs_initialized_p
7850 && FRAME_MESSAGE_BUF (sf
))
7852 Lisp_Object mini_window
;
7856 /* Get the frame containing the mini-buffer
7857 that the selected frame is using. */
7858 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7859 frame
= XWINDOW (mini_window
)->frame
;
7862 FRAME_SAMPLE_VISIBILITY (f
);
7863 if (FRAME_VISIBLE_P (sf
)
7864 && !FRAME_VISIBLE_P (f
))
7865 Fmake_frame_visible (frame
);
7867 if (STRINGP (m
) && SCHARS (m
) > 0)
7869 set_message (NULL
, m
, nbytes
, multibyte
);
7870 if (minibuffer_auto_raise
)
7871 Fraise_frame (frame
);
7872 /* Assume we are not echoing.
7873 (If we are, echo_now will override this.) */
7874 echo_message_buffer
= Qnil
;
7877 clear_message (1, 1);
7879 do_pending_window_change (0);
7880 echo_area_display (1);
7881 do_pending_window_change (0);
7882 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7883 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7888 /* Display a null-terminated echo area message M. If M is 0, clear
7889 out any existing message, and let the mini-buffer text show through.
7891 The buffer M must continue to exist until after the echo area gets
7892 cleared or some other message gets displayed there. Do not pass
7893 text that is stored in a Lisp string. Do not pass text in a buffer
7894 that was alloca'd. */
7900 message2 (m
, (m
? strlen (m
) : 0), 0);
7904 /* The non-logging counterpart of message1. */
7910 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7913 /* Display a message M which contains a single %s
7914 which gets replaced with STRING. */
7917 message_with_string (m
, string
, log
)
7922 CHECK_STRING (string
);
7928 if (noninteractive_need_newline
)
7929 putc ('\n', stderr
);
7930 noninteractive_need_newline
= 0;
7931 fprintf (stderr
, m
, SDATA (string
));
7932 if (cursor_in_echo_area
== 0)
7933 fprintf (stderr
, "\n");
7937 else if (INTERACTIVE
)
7939 /* The frame whose minibuffer we're going to display the message on.
7940 It may be larger than the selected frame, so we need
7941 to use its buffer, not the selected frame's buffer. */
7942 Lisp_Object mini_window
;
7943 struct frame
*f
, *sf
= SELECTED_FRAME ();
7945 /* Get the frame containing the minibuffer
7946 that the selected frame is using. */
7947 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7948 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7950 /* A null message buffer means that the frame hasn't really been
7951 initialized yet. Error messages get reported properly by
7952 cmd_error, so this must be just an informative message; toss it. */
7953 if (FRAME_MESSAGE_BUF (f
))
7955 Lisp_Object args
[2], message
;
7956 struct gcpro gcpro1
, gcpro2
;
7958 args
[0] = build_string (m
);
7959 args
[1] = message
= string
;
7960 GCPRO2 (args
[0], message
);
7963 message
= Fformat (2, args
);
7966 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7968 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7972 /* Print should start at the beginning of the message
7973 buffer next time. */
7974 message_buf_print
= 0;
7980 /* Dump an informative message to the minibuf. If M is 0, clear out
7981 any existing message, and let the mini-buffer text show through. */
7985 message (m
, a1
, a2
, a3
)
7987 EMACS_INT a1
, a2
, a3
;
7993 if (noninteractive_need_newline
)
7994 putc ('\n', stderr
);
7995 noninteractive_need_newline
= 0;
7996 fprintf (stderr
, m
, a1
, a2
, a3
);
7997 if (cursor_in_echo_area
== 0)
7998 fprintf (stderr
, "\n");
8002 else if (INTERACTIVE
)
8004 /* The frame whose mini-buffer we're going to display the message
8005 on. It may be larger than the selected frame, so we need to
8006 use its buffer, not the selected frame's buffer. */
8007 Lisp_Object mini_window
;
8008 struct frame
*f
, *sf
= SELECTED_FRAME ();
8010 /* Get the frame containing the mini-buffer
8011 that the selected frame is using. */
8012 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8013 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8015 /* A null message buffer means that the frame hasn't really been
8016 initialized yet. Error messages get reported properly by
8017 cmd_error, so this must be just an informative message; toss
8019 if (FRAME_MESSAGE_BUF (f
))
8030 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8031 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
8033 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8034 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
8036 #endif /* NO_ARG_ARRAY */
8038 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8043 /* Print should start at the beginning of the message
8044 buffer next time. */
8045 message_buf_print
= 0;
8051 /* The non-logging version of message. */
8054 message_nolog (m
, a1
, a2
, a3
)
8056 EMACS_INT a1
, a2
, a3
;
8058 Lisp_Object old_log_max
;
8059 old_log_max
= Vmessage_log_max
;
8060 Vmessage_log_max
= Qnil
;
8061 message (m
, a1
, a2
, a3
);
8062 Vmessage_log_max
= old_log_max
;
8066 /* Display the current message in the current mini-buffer. This is
8067 only called from error handlers in process.c, and is not time
8073 if (!NILP (echo_area_buffer
[0]))
8076 string
= Fcurrent_message ();
8077 message3 (string
, SBYTES (string
),
8078 !NILP (current_buffer
->enable_multibyte_characters
));
8083 /* Make sure echo area buffers in `echo_buffers' are live.
8084 If they aren't, make new ones. */
8087 ensure_echo_area_buffers ()
8091 for (i
= 0; i
< 2; ++i
)
8092 if (!BUFFERP (echo_buffer
[i
])
8093 || NILP (XBUFFER (echo_buffer
[i
])->name
))
8096 Lisp_Object old_buffer
;
8099 old_buffer
= echo_buffer
[i
];
8100 sprintf (name
, " *Echo Area %d*", i
);
8101 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8102 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
8104 for (j
= 0; j
< 2; ++j
)
8105 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8106 echo_area_buffer
[j
] = echo_buffer
[i
];
8111 /* Call FN with args A1..A4 with either the current or last displayed
8112 echo_area_buffer as current buffer.
8114 WHICH zero means use the current message buffer
8115 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8116 from echo_buffer[] and clear it.
8118 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8119 suitable buffer from echo_buffer[] and clear it.
8121 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8122 that the current message becomes the last displayed one, make
8123 choose a suitable buffer for echo_area_buffer[0], and clear it.
8125 Value is what FN returns. */
8128 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
8131 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
8137 int this_one
, the_other
, clear_buffer_p
, rc
;
8138 int count
= SPECPDL_INDEX ();
8140 /* If buffers aren't live, make new ones. */
8141 ensure_echo_area_buffers ();
8146 this_one
= 0, the_other
= 1;
8148 this_one
= 1, the_other
= 0;
8151 this_one
= 0, the_other
= 1;
8154 /* We need a fresh one in case the current echo buffer equals
8155 the one containing the last displayed echo area message. */
8156 if (!NILP (echo_area_buffer
[this_one
])
8157 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8158 echo_area_buffer
[this_one
] = Qnil
;
8161 /* Choose a suitable buffer from echo_buffer[] is we don't
8163 if (NILP (echo_area_buffer
[this_one
]))
8165 echo_area_buffer
[this_one
]
8166 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8167 ? echo_buffer
[the_other
]
8168 : echo_buffer
[this_one
]);
8172 buffer
= echo_area_buffer
[this_one
];
8174 /* Don't get confused by reusing the buffer used for echoing
8175 for a different purpose. */
8176 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8179 record_unwind_protect (unwind_with_echo_area_buffer
,
8180 with_echo_area_buffer_unwind_data (w
));
8182 /* Make the echo area buffer current. Note that for display
8183 purposes, it is not necessary that the displayed window's buffer
8184 == current_buffer, except for text property lookup. So, let's
8185 only set that buffer temporarily here without doing a full
8186 Fset_window_buffer. We must also change w->pointm, though,
8187 because otherwise an assertions in unshow_buffer fails, and Emacs
8189 set_buffer_internal_1 (XBUFFER (buffer
));
8193 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8196 current_buffer
->undo_list
= Qt
;
8197 current_buffer
->read_only
= Qnil
;
8198 specbind (Qinhibit_read_only
, Qt
);
8199 specbind (Qinhibit_modification_hooks
, Qt
);
8201 if (clear_buffer_p
&& Z
> BEG
)
8204 xassert (BEGV
>= BEG
);
8205 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8207 rc
= fn (a1
, a2
, a3
, a4
);
8209 xassert (BEGV
>= BEG
);
8210 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8212 unbind_to (count
, Qnil
);
8217 /* Save state that should be preserved around the call to the function
8218 FN called in with_echo_area_buffer. */
8221 with_echo_area_buffer_unwind_data (w
)
8225 Lisp_Object vector
, tmp
;
8227 /* Reduce consing by keeping one vector in
8228 Vwith_echo_area_save_vector. */
8229 vector
= Vwith_echo_area_save_vector
;
8230 Vwith_echo_area_save_vector
= Qnil
;
8233 vector
= Fmake_vector (make_number (7), Qnil
);
8235 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
8236 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
8237 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
8241 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
8242 ASET (vector
, i
, w
->buffer
); ++i
;
8243 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
8244 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
8249 for (; i
< end
; ++i
)
8250 ASET (vector
, i
, Qnil
);
8253 xassert (i
== ASIZE (vector
));
8258 /* Restore global state from VECTOR which was created by
8259 with_echo_area_buffer_unwind_data. */
8262 unwind_with_echo_area_buffer (vector
)
8265 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8266 Vdeactivate_mark
= AREF (vector
, 1);
8267 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8269 if (WINDOWP (AREF (vector
, 3)))
8272 Lisp_Object buffer
, charpos
, bytepos
;
8274 w
= XWINDOW (AREF (vector
, 3));
8275 buffer
= AREF (vector
, 4);
8276 charpos
= AREF (vector
, 5);
8277 bytepos
= AREF (vector
, 6);
8280 set_marker_both (w
->pointm
, buffer
,
8281 XFASTINT (charpos
), XFASTINT (bytepos
));
8284 Vwith_echo_area_save_vector
= vector
;
8289 /* Set up the echo area for use by print functions. MULTIBYTE_P
8290 non-zero means we will print multibyte. */
8293 setup_echo_area_for_printing (multibyte_p
)
8296 /* If we can't find an echo area any more, exit. */
8297 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8300 ensure_echo_area_buffers ();
8302 if (!message_buf_print
)
8304 /* A message has been output since the last time we printed.
8305 Choose a fresh echo area buffer. */
8306 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8307 echo_area_buffer
[0] = echo_buffer
[1];
8309 echo_area_buffer
[0] = echo_buffer
[0];
8311 /* Switch to that buffer and clear it. */
8312 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8313 current_buffer
->truncate_lines
= Qnil
;
8317 int count
= SPECPDL_INDEX ();
8318 specbind (Qinhibit_read_only
, Qt
);
8319 /* Note that undo recording is always disabled. */
8321 unbind_to (count
, Qnil
);
8323 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8325 /* Set up the buffer for the multibyteness we need. */
8327 != !NILP (current_buffer
->enable_multibyte_characters
))
8328 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8330 /* Raise the frame containing the echo area. */
8331 if (minibuffer_auto_raise
)
8333 struct frame
*sf
= SELECTED_FRAME ();
8334 Lisp_Object mini_window
;
8335 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8336 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8339 message_log_maybe_newline ();
8340 message_buf_print
= 1;
8344 if (NILP (echo_area_buffer
[0]))
8346 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8347 echo_area_buffer
[0] = echo_buffer
[1];
8349 echo_area_buffer
[0] = echo_buffer
[0];
8352 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8354 /* Someone switched buffers between print requests. */
8355 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8356 current_buffer
->truncate_lines
= Qnil
;
8362 /* Display an echo area message in window W. Value is non-zero if W's
8363 height is changed. If display_last_displayed_message_p is
8364 non-zero, display the message that was last displayed, otherwise
8365 display the current message. */
8368 display_echo_area (w
)
8371 int i
, no_message_p
, window_height_changed_p
, count
;
8373 /* Temporarily disable garbage collections while displaying the echo
8374 area. This is done because a GC can print a message itself.
8375 That message would modify the echo area buffer's contents while a
8376 redisplay of the buffer is going on, and seriously confuse
8378 count
= inhibit_garbage_collection ();
8380 /* If there is no message, we must call display_echo_area_1
8381 nevertheless because it resizes the window. But we will have to
8382 reset the echo_area_buffer in question to nil at the end because
8383 with_echo_area_buffer will sets it to an empty buffer. */
8384 i
= display_last_displayed_message_p
? 1 : 0;
8385 no_message_p
= NILP (echo_area_buffer
[i
]);
8387 window_height_changed_p
8388 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8389 display_echo_area_1
,
8390 (EMACS_INT
) w
, Qnil
, 0, 0);
8393 echo_area_buffer
[i
] = Qnil
;
8395 unbind_to (count
, Qnil
);
8396 return window_height_changed_p
;
8400 /* Helper for display_echo_area. Display the current buffer which
8401 contains the current echo area message in window W, a mini-window,
8402 a pointer to which is passed in A1. A2..A4 are currently not used.
8403 Change the height of W so that all of the message is displayed.
8404 Value is non-zero if height of W was changed. */
8407 display_echo_area_1 (a1
, a2
, a3
, a4
)
8412 struct window
*w
= (struct window
*) a1
;
8414 struct text_pos start
;
8415 int window_height_changed_p
= 0;
8417 /* Do this before displaying, so that we have a large enough glyph
8418 matrix for the display. If we can't get enough space for the
8419 whole text, display the last N lines. That works by setting w->start. */
8420 window_height_changed_p
= resize_mini_window (w
, 0);
8422 /* Use the starting position chosen by resize_mini_window. */
8423 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8426 clear_glyph_matrix (w
->desired_matrix
);
8427 XSETWINDOW (window
, w
);
8428 try_window (window
, start
, 0);
8430 return window_height_changed_p
;
8434 /* Resize the echo area window to exactly the size needed for the
8435 currently displayed message, if there is one. If a mini-buffer
8436 is active, don't shrink it. */
8439 resize_echo_area_exactly ()
8441 if (BUFFERP (echo_area_buffer
[0])
8442 && WINDOWP (echo_area_window
))
8444 struct window
*w
= XWINDOW (echo_area_window
);
8446 Lisp_Object resize_exactly
;
8448 if (minibuf_level
== 0)
8449 resize_exactly
= Qt
;
8451 resize_exactly
= Qnil
;
8453 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8454 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8457 ++windows_or_buffers_changed
;
8458 ++update_mode_lines
;
8459 redisplay_internal (0);
8465 /* Callback function for with_echo_area_buffer, when used from
8466 resize_echo_area_exactly. A1 contains a pointer to the window to
8467 resize, EXACTLY non-nil means resize the mini-window exactly to the
8468 size of the text displayed. A3 and A4 are not used. Value is what
8469 resize_mini_window returns. */
8472 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8474 Lisp_Object exactly
;
8477 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8481 /* Resize mini-window W to fit the size of its contents. EXACT_P
8482 means size the window exactly to the size needed. Otherwise, it's
8483 only enlarged until W's buffer is empty.
8485 Set W->start to the right place to begin display. If the whole
8486 contents fit, start at the beginning. Otherwise, start so as
8487 to make the end of the contents appear. This is particularly
8488 important for y-or-n-p, but seems desirable generally.
8490 Value is non-zero if the window height has been changed. */
8493 resize_mini_window (w
, exact_p
)
8497 struct frame
*f
= XFRAME (w
->frame
);
8498 int window_height_changed_p
= 0;
8500 xassert (MINI_WINDOW_P (w
));
8502 /* By default, start display at the beginning. */
8503 set_marker_both (w
->start
, w
->buffer
,
8504 BUF_BEGV (XBUFFER (w
->buffer
)),
8505 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8507 /* Don't resize windows while redisplaying a window; it would
8508 confuse redisplay functions when the size of the window they are
8509 displaying changes from under them. Such a resizing can happen,
8510 for instance, when which-func prints a long message while
8511 we are running fontification-functions. We're running these
8512 functions with safe_call which binds inhibit-redisplay to t. */
8513 if (!NILP (Vinhibit_redisplay
))
8516 /* Nil means don't try to resize. */
8517 if (NILP (Vresize_mini_windows
)
8518 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8521 if (!FRAME_MINIBUF_ONLY_P (f
))
8524 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8525 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8526 int height
, max_height
;
8527 int unit
= FRAME_LINE_HEIGHT (f
);
8528 struct text_pos start
;
8529 struct buffer
*old_current_buffer
= NULL
;
8531 if (current_buffer
!= XBUFFER (w
->buffer
))
8533 old_current_buffer
= current_buffer
;
8534 set_buffer_internal (XBUFFER (w
->buffer
));
8537 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8539 /* Compute the max. number of lines specified by the user. */
8540 if (FLOATP (Vmax_mini_window_height
))
8541 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8542 else if (INTEGERP (Vmax_mini_window_height
))
8543 max_height
= XINT (Vmax_mini_window_height
);
8545 max_height
= total_height
/ 4;
8547 /* Correct that max. height if it's bogus. */
8548 max_height
= max (1, max_height
);
8549 max_height
= min (total_height
, max_height
);
8551 /* Find out the height of the text in the window. */
8552 if (it
.truncate_lines_p
)
8557 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8558 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8559 height
= it
.current_y
+ last_height
;
8561 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8562 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8563 height
= (height
+ unit
- 1) / unit
;
8566 /* Compute a suitable window start. */
8567 if (height
> max_height
)
8569 height
= max_height
;
8570 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8571 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8572 start
= it
.current
.pos
;
8575 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8576 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8578 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8580 /* Let it grow only, until we display an empty message, in which
8581 case the window shrinks again. */
8582 if (height
> WINDOW_TOTAL_LINES (w
))
8584 int old_height
= WINDOW_TOTAL_LINES (w
);
8585 freeze_window_starts (f
, 1);
8586 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8587 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8589 else if (height
< WINDOW_TOTAL_LINES (w
)
8590 && (exact_p
|| BEGV
== ZV
))
8592 int old_height
= WINDOW_TOTAL_LINES (w
);
8593 freeze_window_starts (f
, 0);
8594 shrink_mini_window (w
);
8595 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8600 /* Always resize to exact size needed. */
8601 if (height
> WINDOW_TOTAL_LINES (w
))
8603 int old_height
= WINDOW_TOTAL_LINES (w
);
8604 freeze_window_starts (f
, 1);
8605 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8606 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8608 else if (height
< WINDOW_TOTAL_LINES (w
))
8610 int old_height
= WINDOW_TOTAL_LINES (w
);
8611 freeze_window_starts (f
, 0);
8612 shrink_mini_window (w
);
8616 freeze_window_starts (f
, 1);
8617 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8620 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8624 if (old_current_buffer
)
8625 set_buffer_internal (old_current_buffer
);
8628 return window_height_changed_p
;
8632 /* Value is the current message, a string, or nil if there is no
8640 if (!BUFFERP (echo_area_buffer
[0]))
8644 with_echo_area_buffer (0, 0, current_message_1
,
8645 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8647 echo_area_buffer
[0] = Qnil
;
8655 current_message_1 (a1
, a2
, a3
, a4
)
8660 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8663 *msg
= make_buffer_string (BEG
, Z
, 1);
8670 /* Push the current message on Vmessage_stack for later restauration
8671 by restore_message. Value is non-zero if the current message isn't
8672 empty. This is a relatively infrequent operation, so it's not
8673 worth optimizing. */
8679 msg
= current_message ();
8680 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8681 return STRINGP (msg
);
8685 /* Restore message display from the top of Vmessage_stack. */
8692 xassert (CONSP (Vmessage_stack
));
8693 msg
= XCAR (Vmessage_stack
);
8695 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8697 message3_nolog (msg
, 0, 0);
8701 /* Handler for record_unwind_protect calling pop_message. */
8704 pop_message_unwind (dummy
)
8711 /* Pop the top-most entry off Vmessage_stack. */
8716 xassert (CONSP (Vmessage_stack
));
8717 Vmessage_stack
= XCDR (Vmessage_stack
);
8721 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8722 exits. If the stack is not empty, we have a missing pop_message
8726 check_message_stack ()
8728 if (!NILP (Vmessage_stack
))
8733 /* Truncate to NCHARS what will be displayed in the echo area the next
8734 time we display it---but don't redisplay it now. */
8737 truncate_echo_area (nchars
)
8741 echo_area_buffer
[0] = Qnil
;
8742 /* A null message buffer means that the frame hasn't really been
8743 initialized yet. Error messages get reported properly by
8744 cmd_error, so this must be just an informative message; toss it. */
8745 else if (!noninteractive
8747 && !NILP (echo_area_buffer
[0]))
8749 struct frame
*sf
= SELECTED_FRAME ();
8750 if (FRAME_MESSAGE_BUF (sf
))
8751 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8756 /* Helper function for truncate_echo_area. Truncate the current
8757 message to at most NCHARS characters. */
8760 truncate_message_1 (nchars
, a2
, a3
, a4
)
8765 if (BEG
+ nchars
< Z
)
8766 del_range (BEG
+ nchars
, Z
);
8768 echo_area_buffer
[0] = Qnil
;
8773 /* Set the current message to a substring of S or STRING.
8775 If STRING is a Lisp string, set the message to the first NBYTES
8776 bytes from STRING. NBYTES zero means use the whole string. If
8777 STRING is multibyte, the message will be displayed multibyte.
8779 If S is not null, set the message to the first LEN bytes of S. LEN
8780 zero means use the whole string. MULTIBYTE_P non-zero means S is
8781 multibyte. Display the message multibyte in that case.
8783 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8784 to t before calling set_message_1 (which calls insert).
8788 set_message (s
, string
, nbytes
, multibyte_p
)
8791 int nbytes
, multibyte_p
;
8793 message_enable_multibyte
8794 = ((s
&& multibyte_p
)
8795 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8797 with_echo_area_buffer (0, -1, set_message_1
,
8798 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8799 message_buf_print
= 0;
8800 help_echo_showing_p
= 0;
8804 /* Helper function for set_message. Arguments have the same meaning
8805 as there, with A1 corresponding to S and A2 corresponding to STRING
8806 This function is called with the echo area buffer being
8810 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8813 EMACS_INT nbytes
, multibyte_p
;
8815 const char *s
= (const char *) a1
;
8816 Lisp_Object string
= a2
;
8818 /* Change multibyteness of the echo buffer appropriately. */
8819 if (message_enable_multibyte
8820 != !NILP (current_buffer
->enable_multibyte_characters
))
8821 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8823 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8825 /* Insert new message at BEG. */
8826 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8828 if (STRINGP (string
))
8833 nbytes
= SBYTES (string
);
8834 nchars
= string_byte_to_char (string
, nbytes
);
8836 /* This function takes care of single/multibyte conversion. We
8837 just have to ensure that the echo area buffer has the right
8838 setting of enable_multibyte_characters. */
8839 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8844 nbytes
= strlen (s
);
8846 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8848 /* Convert from multi-byte to single-byte. */
8850 unsigned char work
[1];
8852 /* Convert a multibyte string to single-byte. */
8853 for (i
= 0; i
< nbytes
; i
+= n
)
8855 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8856 work
[0] = (ASCII_CHAR_P (c
)
8858 : multibyte_char_to_unibyte (c
, Qnil
));
8859 insert_1_both (work
, 1, 1, 1, 0, 0);
8862 else if (!multibyte_p
8863 && !NILP (current_buffer
->enable_multibyte_characters
))
8865 /* Convert from single-byte to multi-byte. */
8867 const unsigned char *msg
= (const unsigned char *) s
;
8868 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8870 /* Convert a single-byte string to multibyte. */
8871 for (i
= 0; i
< nbytes
; i
++)
8874 c
= unibyte_char_to_multibyte (c
);
8875 n
= CHAR_STRING (c
, str
);
8876 insert_1_both (str
, 1, n
, 1, 0, 0);
8880 insert_1 (s
, nbytes
, 1, 0, 0);
8887 /* Clear messages. CURRENT_P non-zero means clear the current
8888 message. LAST_DISPLAYED_P non-zero means clear the message
8892 clear_message (current_p
, last_displayed_p
)
8893 int current_p
, last_displayed_p
;
8897 echo_area_buffer
[0] = Qnil
;
8898 message_cleared_p
= 1;
8901 if (last_displayed_p
)
8902 echo_area_buffer
[1] = Qnil
;
8904 message_buf_print
= 0;
8907 /* Clear garbaged frames.
8909 This function is used where the old redisplay called
8910 redraw_garbaged_frames which in turn called redraw_frame which in
8911 turn called clear_frame. The call to clear_frame was a source of
8912 flickering. I believe a clear_frame is not necessary. It should
8913 suffice in the new redisplay to invalidate all current matrices,
8914 and ensure a complete redisplay of all windows. */
8917 clear_garbaged_frames ()
8921 Lisp_Object tail
, frame
;
8922 int changed_count
= 0;
8924 FOR_EACH_FRAME (tail
, frame
)
8926 struct frame
*f
= XFRAME (frame
);
8928 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8932 Fredraw_frame (frame
);
8933 f
->force_flush_display_p
= 1;
8935 clear_current_matrices (f
);
8944 ++windows_or_buffers_changed
;
8949 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8950 is non-zero update selected_frame. Value is non-zero if the
8951 mini-windows height has been changed. */
8954 echo_area_display (update_frame_p
)
8957 Lisp_Object mini_window
;
8960 int window_height_changed_p
= 0;
8961 struct frame
*sf
= SELECTED_FRAME ();
8963 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8964 w
= XWINDOW (mini_window
);
8965 f
= XFRAME (WINDOW_FRAME (w
));
8967 /* Don't display if frame is invisible or not yet initialized. */
8968 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8971 #ifdef HAVE_WINDOW_SYSTEM
8972 /* When Emacs starts, selected_frame may be the initial terminal
8973 frame. If we let this through, a message would be displayed on
8975 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
8977 #endif /* HAVE_WINDOW_SYSTEM */
8979 /* Redraw garbaged frames. */
8981 clear_garbaged_frames ();
8983 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8985 echo_area_window
= mini_window
;
8986 window_height_changed_p
= display_echo_area (w
);
8987 w
->must_be_updated_p
= 1;
8989 /* Update the display, unless called from redisplay_internal.
8990 Also don't update the screen during redisplay itself. The
8991 update will happen at the end of redisplay, and an update
8992 here could cause confusion. */
8993 if (update_frame_p
&& !redisplaying_p
)
8997 /* If the display update has been interrupted by pending
8998 input, update mode lines in the frame. Due to the
8999 pending input, it might have been that redisplay hasn't
9000 been called, so that mode lines above the echo area are
9001 garbaged. This looks odd, so we prevent it here. */
9002 if (!display_completed
)
9003 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9005 if (window_height_changed_p
9006 /* Don't do this if Emacs is shutting down. Redisplay
9007 needs to run hooks. */
9008 && !NILP (Vrun_hooks
))
9010 /* Must update other windows. Likewise as in other
9011 cases, don't let this update be interrupted by
9013 int count
= SPECPDL_INDEX ();
9014 specbind (Qredisplay_dont_pause
, Qt
);
9015 windows_or_buffers_changed
= 1;
9016 redisplay_internal (0);
9017 unbind_to (count
, Qnil
);
9019 else if (FRAME_WINDOW_P (f
) && n
== 0)
9021 /* Window configuration is the same as before.
9022 Can do with a display update of the echo area,
9023 unless we displayed some mode lines. */
9024 update_single_window (w
, 1);
9025 FRAME_RIF (f
)->flush_display (f
);
9028 update_frame (f
, 1, 1);
9030 /* If cursor is in the echo area, make sure that the next
9031 redisplay displays the minibuffer, so that the cursor will
9032 be replaced with what the minibuffer wants. */
9033 if (cursor_in_echo_area
)
9034 ++windows_or_buffers_changed
;
9037 else if (!EQ (mini_window
, selected_window
))
9038 windows_or_buffers_changed
++;
9040 /* Last displayed message is now the current message. */
9041 echo_area_buffer
[1] = echo_area_buffer
[0];
9042 /* Inform read_char that we're not echoing. */
9043 echo_message_buffer
= Qnil
;
9045 /* Prevent redisplay optimization in redisplay_internal by resetting
9046 this_line_start_pos. This is done because the mini-buffer now
9047 displays the message instead of its buffer text. */
9048 if (EQ (mini_window
, selected_window
))
9049 CHARPOS (this_line_start_pos
) = 0;
9051 return window_height_changed_p
;
9056 /***********************************************************************
9057 Mode Lines and Frame Titles
9058 ***********************************************************************/
9060 /* A buffer for constructing non-propertized mode-line strings and
9061 frame titles in it; allocated from the heap in init_xdisp and
9062 resized as needed in store_mode_line_noprop_char. */
9064 static char *mode_line_noprop_buf
;
9066 /* The buffer's end, and a current output position in it. */
9068 static char *mode_line_noprop_buf_end
;
9069 static char *mode_line_noprop_ptr
;
9071 #define MODE_LINE_NOPROP_LEN(start) \
9072 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9075 MODE_LINE_DISPLAY
= 0,
9081 /* Alist that caches the results of :propertize.
9082 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9083 static Lisp_Object mode_line_proptrans_alist
;
9085 /* List of strings making up the mode-line. */
9086 static Lisp_Object mode_line_string_list
;
9088 /* Base face property when building propertized mode line string. */
9089 static Lisp_Object mode_line_string_face
;
9090 static Lisp_Object mode_line_string_face_prop
;
9093 /* Unwind data for mode line strings */
9095 static Lisp_Object Vmode_line_unwind_vector
;
9098 format_mode_line_unwind_data (struct buffer
*obuf
,
9102 Lisp_Object vector
, tmp
;
9104 /* Reduce consing by keeping one vector in
9105 Vwith_echo_area_save_vector. */
9106 vector
= Vmode_line_unwind_vector
;
9107 Vmode_line_unwind_vector
= Qnil
;
9110 vector
= Fmake_vector (make_number (8), Qnil
);
9112 ASET (vector
, 0, make_number (mode_line_target
));
9113 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9114 ASET (vector
, 2, mode_line_string_list
);
9115 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9116 ASET (vector
, 4, mode_line_string_face
);
9117 ASET (vector
, 5, mode_line_string_face_prop
);
9120 XSETBUFFER (tmp
, obuf
);
9123 ASET (vector
, 6, tmp
);
9124 ASET (vector
, 7, owin
);
9130 unwind_format_mode_line (vector
)
9133 mode_line_target
= XINT (AREF (vector
, 0));
9134 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9135 mode_line_string_list
= AREF (vector
, 2);
9136 if (! EQ (AREF (vector
, 3), Qt
))
9137 mode_line_proptrans_alist
= AREF (vector
, 3);
9138 mode_line_string_face
= AREF (vector
, 4);
9139 mode_line_string_face_prop
= AREF (vector
, 5);
9141 if (!NILP (AREF (vector
, 7)))
9142 /* Select window before buffer, since it may change the buffer. */
9143 Fselect_window (AREF (vector
, 7), Qt
);
9145 if (!NILP (AREF (vector
, 6)))
9147 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9148 ASET (vector
, 6, Qnil
);
9151 Vmode_line_unwind_vector
= vector
;
9156 /* Store a single character C for the frame title in mode_line_noprop_buf.
9157 Re-allocate mode_line_noprop_buf if necessary. */
9161 store_mode_line_noprop_char (char c
)
9163 store_mode_line_noprop_char (c
)
9167 /* If output position has reached the end of the allocated buffer,
9168 double the buffer's size. */
9169 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9171 int len
= MODE_LINE_NOPROP_LEN (0);
9172 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9173 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9174 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9175 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9178 *mode_line_noprop_ptr
++ = c
;
9182 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9183 mode_line_noprop_ptr. STR is the string to store. Do not copy
9184 characters that yield more columns than PRECISION; PRECISION <= 0
9185 means copy the whole string. Pad with spaces until FIELD_WIDTH
9186 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9187 pad. Called from display_mode_element when it is used to build a
9191 store_mode_line_noprop (str
, field_width
, precision
)
9192 const unsigned char *str
;
9193 int field_width
, precision
;
9198 /* Copy at most PRECISION chars from STR. */
9199 nbytes
= strlen (str
);
9200 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9202 store_mode_line_noprop_char (*str
++);
9204 /* Fill up with spaces until FIELD_WIDTH reached. */
9205 while (field_width
> 0
9208 store_mode_line_noprop_char (' ');
9215 /***********************************************************************
9217 ***********************************************************************/
9219 #ifdef HAVE_WINDOW_SYSTEM
9221 /* Set the title of FRAME, if it has changed. The title format is
9222 Vicon_title_format if FRAME is iconified, otherwise it is
9223 frame_title_format. */
9226 x_consider_frame_title (frame
)
9229 struct frame
*f
= XFRAME (frame
);
9231 if (FRAME_WINDOW_P (f
)
9232 || FRAME_MINIBUF_ONLY_P (f
)
9233 || f
->explicit_name
)
9235 /* Do we have more than one visible frame on this X display? */
9242 int count
= SPECPDL_INDEX ();
9244 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9246 Lisp_Object other_frame
= XCAR (tail
);
9247 struct frame
*tf
= XFRAME (other_frame
);
9250 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9251 && !FRAME_MINIBUF_ONLY_P (tf
)
9252 && !EQ (other_frame
, tip_frame
)
9253 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9257 /* Set global variable indicating that multiple frames exist. */
9258 multiple_frames
= CONSP (tail
);
9260 /* Switch to the buffer of selected window of the frame. Set up
9261 mode_line_target so that display_mode_element will output into
9262 mode_line_noprop_buf; then display the title. */
9263 record_unwind_protect (unwind_format_mode_line
,
9264 format_mode_line_unwind_data
9265 (current_buffer
, selected_window
, 0));
9267 Fselect_window (f
->selected_window
, Qt
);
9268 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9269 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9271 mode_line_target
= MODE_LINE_TITLE
;
9272 title_start
= MODE_LINE_NOPROP_LEN (0);
9273 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9274 NULL
, DEFAULT_FACE_ID
);
9275 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9276 len
= MODE_LINE_NOPROP_LEN (title_start
);
9277 title
= mode_line_noprop_buf
+ title_start
;
9278 unbind_to (count
, Qnil
);
9280 /* Set the title only if it's changed. This avoids consing in
9281 the common case where it hasn't. (If it turns out that we've
9282 already wasted too much time by walking through the list with
9283 display_mode_element, then we might need to optimize at a
9284 higher level than this.) */
9285 if (! STRINGP (f
->name
)
9286 || SBYTES (f
->name
) != len
9287 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9288 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9292 #endif /* not HAVE_WINDOW_SYSTEM */
9297 /***********************************************************************
9299 ***********************************************************************/
9302 /* Prepare for redisplay by updating menu-bar item lists when
9303 appropriate. This can call eval. */
9306 prepare_menu_bars ()
9309 struct gcpro gcpro1
, gcpro2
;
9311 Lisp_Object tooltip_frame
;
9313 #ifdef HAVE_WINDOW_SYSTEM
9314 tooltip_frame
= tip_frame
;
9316 tooltip_frame
= Qnil
;
9319 /* Update all frame titles based on their buffer names, etc. We do
9320 this before the menu bars so that the buffer-menu will show the
9321 up-to-date frame titles. */
9322 #ifdef HAVE_WINDOW_SYSTEM
9323 if (windows_or_buffers_changed
|| update_mode_lines
)
9325 Lisp_Object tail
, frame
;
9327 FOR_EACH_FRAME (tail
, frame
)
9330 if (!EQ (frame
, tooltip_frame
)
9331 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9332 x_consider_frame_title (frame
);
9335 #endif /* HAVE_WINDOW_SYSTEM */
9337 /* Update the menu bar item lists, if appropriate. This has to be
9338 done before any actual redisplay or generation of display lines. */
9339 all_windows
= (update_mode_lines
9340 || buffer_shared
> 1
9341 || windows_or_buffers_changed
);
9344 Lisp_Object tail
, frame
;
9345 int count
= SPECPDL_INDEX ();
9346 /* 1 means that update_menu_bar has run its hooks
9347 so any further calls to update_menu_bar shouldn't do so again. */
9348 int menu_bar_hooks_run
= 0;
9350 record_unwind_save_match_data ();
9352 FOR_EACH_FRAME (tail
, frame
)
9356 /* Ignore tooltip frame. */
9357 if (EQ (frame
, tooltip_frame
))
9360 /* If a window on this frame changed size, report that to
9361 the user and clear the size-change flag. */
9362 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9364 Lisp_Object functions
;
9366 /* Clear flag first in case we get an error below. */
9367 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9368 functions
= Vwindow_size_change_functions
;
9369 GCPRO2 (tail
, functions
);
9371 while (CONSP (functions
))
9373 call1 (XCAR (functions
), frame
);
9374 functions
= XCDR (functions
);
9380 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9381 #ifdef HAVE_WINDOW_SYSTEM
9382 update_tool_bar (f
, 0);
9384 mac_update_title_bar (f
, 0);
9390 unbind_to (count
, Qnil
);
9394 struct frame
*sf
= SELECTED_FRAME ();
9395 update_menu_bar (sf
, 1, 0);
9396 #ifdef HAVE_WINDOW_SYSTEM
9397 update_tool_bar (sf
, 1);
9399 mac_update_title_bar (sf
, 1);
9404 /* Motif needs this. See comment in xmenu.c. Turn it off when
9405 pending_menu_activation is not defined. */
9406 #ifdef USE_X_TOOLKIT
9407 pending_menu_activation
= 0;
9412 /* Update the menu bar item list for frame F. This has to be done
9413 before we start to fill in any display lines, because it can call
9416 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9418 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9419 already ran the menu bar hooks for this redisplay, so there
9420 is no need to run them again. The return value is the
9421 updated value of this flag, to pass to the next call. */
9424 update_menu_bar (f
, save_match_data
, hooks_run
)
9426 int save_match_data
;
9430 register struct window
*w
;
9432 /* If called recursively during a menu update, do nothing. This can
9433 happen when, for instance, an activate-menubar-hook causes a
9435 if (inhibit_menubar_update
)
9438 window
= FRAME_SELECTED_WINDOW (f
);
9439 w
= XWINDOW (window
);
9441 #if 0 /* The if statement below this if statement used to include the
9442 condition !NILP (w->update_mode_line), rather than using
9443 update_mode_lines directly, and this if statement may have
9444 been added to make that condition work. Now the if
9445 statement below matches its comment, this isn't needed. */
9446 if (update_mode_lines
)
9447 w
->update_mode_line
= Qt
;
9450 if (FRAME_WINDOW_P (f
)
9452 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9453 || defined (USE_GTK)
9454 FRAME_EXTERNAL_MENU_BAR (f
)
9456 FRAME_MENU_BAR_LINES (f
) > 0
9458 : FRAME_MENU_BAR_LINES (f
) > 0)
9460 /* If the user has switched buffers or windows, we need to
9461 recompute to reflect the new bindings. But we'll
9462 recompute when update_mode_lines is set too; that means
9463 that people can use force-mode-line-update to request
9464 that the menu bar be recomputed. The adverse effect on
9465 the rest of the redisplay algorithm is about the same as
9466 windows_or_buffers_changed anyway. */
9467 if (windows_or_buffers_changed
9468 /* This used to test w->update_mode_line, but we believe
9469 there is no need to recompute the menu in that case. */
9470 || update_mode_lines
9471 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9472 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9473 != !NILP (w
->last_had_star
))
9474 || ((!NILP (Vtransient_mark_mode
)
9475 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9476 != !NILP (w
->region_showing
)))
9478 struct buffer
*prev
= current_buffer
;
9479 int count
= SPECPDL_INDEX ();
9481 specbind (Qinhibit_menubar_update
, Qt
);
9483 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9484 if (save_match_data
)
9485 record_unwind_save_match_data ();
9486 if (NILP (Voverriding_local_map_menu_flag
))
9488 specbind (Qoverriding_terminal_local_map
, Qnil
);
9489 specbind (Qoverriding_local_map
, Qnil
);
9494 /* Run the Lucid hook. */
9495 safe_run_hooks (Qactivate_menubar_hook
);
9497 /* If it has changed current-menubar from previous value,
9498 really recompute the menu-bar from the value. */
9499 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9500 call0 (Qrecompute_lucid_menubar
);
9502 safe_run_hooks (Qmenu_bar_update_hook
);
9507 XSETFRAME (Vmenu_updating_frame
, f
);
9508 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9510 /* Redisplay the menu bar in case we changed it. */
9511 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9512 || defined (USE_GTK)
9513 if (FRAME_WINDOW_P (f
))
9516 /* All frames on Mac OS share the same menubar. So only
9517 the selected frame should be allowed to set it. */
9518 if (f
== SELECTED_FRAME ())
9520 set_frame_menubar (f
, 0, 0);
9523 /* On a terminal screen, the menu bar is an ordinary screen
9524 line, and this makes it get updated. */
9525 w
->update_mode_line
= Qt
;
9526 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9527 /* In the non-toolkit version, the menu bar is an ordinary screen
9528 line, and this makes it get updated. */
9529 w
->update_mode_line
= Qt
;
9530 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9532 unbind_to (count
, Qnil
);
9533 set_buffer_internal_1 (prev
);
9542 /***********************************************************************
9544 ***********************************************************************/
9546 #ifdef HAVE_WINDOW_SYSTEM
9549 Nominal cursor position -- where to draw output.
9550 HPOS and VPOS are window relative glyph matrix coordinates.
9551 X and Y are window relative pixel coordinates. */
9553 struct cursor_pos output_cursor
;
9557 Set the global variable output_cursor to CURSOR. All cursor
9558 positions are relative to updated_window. */
9561 set_output_cursor (cursor
)
9562 struct cursor_pos
*cursor
;
9564 output_cursor
.hpos
= cursor
->hpos
;
9565 output_cursor
.vpos
= cursor
->vpos
;
9566 output_cursor
.x
= cursor
->x
;
9567 output_cursor
.y
= cursor
->y
;
9572 Set a nominal cursor position.
9574 HPOS and VPOS are column/row positions in a window glyph matrix. X
9575 and Y are window text area relative pixel positions.
9577 If this is done during an update, updated_window will contain the
9578 window that is being updated and the position is the future output
9579 cursor position for that window. If updated_window is null, use
9580 selected_window and display the cursor at the given position. */
9583 x_cursor_to (vpos
, hpos
, y
, x
)
9584 int vpos
, hpos
, y
, x
;
9588 /* If updated_window is not set, work on selected_window. */
9592 w
= XWINDOW (selected_window
);
9594 /* Set the output cursor. */
9595 output_cursor
.hpos
= hpos
;
9596 output_cursor
.vpos
= vpos
;
9597 output_cursor
.x
= x
;
9598 output_cursor
.y
= y
;
9600 /* If not called as part of an update, really display the cursor.
9601 This will also set the cursor position of W. */
9602 if (updated_window
== NULL
)
9605 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9606 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
9607 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
9612 #endif /* HAVE_WINDOW_SYSTEM */
9615 /***********************************************************************
9617 ***********************************************************************/
9619 #ifdef HAVE_WINDOW_SYSTEM
9621 /* Where the mouse was last time we reported a mouse event. */
9623 FRAME_PTR last_mouse_frame
;
9625 /* Tool-bar item index of the item on which a mouse button was pressed
9628 int last_tool_bar_item
;
9631 /* Update the tool-bar item list for frame F. This has to be done
9632 before we start to fill in any display lines. Called from
9633 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9634 and restore it here. */
9637 update_tool_bar (f
, save_match_data
)
9639 int save_match_data
;
9641 #if defined (USE_GTK) || USE_MAC_TOOLBAR
9642 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9644 int do_update
= WINDOWP (f
->tool_bar_window
)
9645 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9653 window
= FRAME_SELECTED_WINDOW (f
);
9654 w
= XWINDOW (window
);
9656 /* If the user has switched buffers or windows, we need to
9657 recompute to reflect the new bindings. But we'll
9658 recompute when update_mode_lines is set too; that means
9659 that people can use force-mode-line-update to request
9660 that the menu bar be recomputed. The adverse effect on
9661 the rest of the redisplay algorithm is about the same as
9662 windows_or_buffers_changed anyway. */
9663 if (windows_or_buffers_changed
9664 || !NILP (w
->update_mode_line
)
9665 || update_mode_lines
9666 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9667 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9668 != !NILP (w
->last_had_star
))
9669 || ((!NILP (Vtransient_mark_mode
)
9670 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9671 != !NILP (w
->region_showing
)))
9673 struct buffer
*prev
= current_buffer
;
9674 int count
= SPECPDL_INDEX ();
9675 Lisp_Object new_tool_bar
;
9677 struct gcpro gcpro1
;
9679 /* Set current_buffer to the buffer of the selected
9680 window of the frame, so that we get the right local
9682 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9684 /* Save match data, if we must. */
9685 if (save_match_data
)
9686 record_unwind_save_match_data ();
9688 /* Make sure that we don't accidentally use bogus keymaps. */
9689 if (NILP (Voverriding_local_map_menu_flag
))
9691 specbind (Qoverriding_terminal_local_map
, Qnil
);
9692 specbind (Qoverriding_local_map
, Qnil
);
9695 GCPRO1 (new_tool_bar
);
9697 /* Build desired tool-bar items from keymaps. */
9698 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9701 /* Redisplay the tool-bar if we changed it. */
9702 if (new_n_tool_bar
!= f
->n_tool_bar_items
9703 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9705 /* Redisplay that happens asynchronously due to an expose event
9706 may access f->tool_bar_items. Make sure we update both
9707 variables within BLOCK_INPUT so no such event interrupts. */
9709 f
->tool_bar_items
= new_tool_bar
;
9710 f
->n_tool_bar_items
= new_n_tool_bar
;
9711 w
->update_mode_line
= Qt
;
9717 unbind_to (count
, Qnil
);
9718 set_buffer_internal_1 (prev
);
9724 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9725 F's desired tool-bar contents. F->tool_bar_items must have
9726 been set up previously by calling prepare_menu_bars. */
9729 build_desired_tool_bar_string (f
)
9732 int i
, size
, size_needed
;
9733 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9734 Lisp_Object image
, plist
, props
;
9736 image
= plist
= props
= Qnil
;
9737 GCPRO3 (image
, plist
, props
);
9739 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9740 Otherwise, make a new string. */
9742 /* The size of the string we might be able to reuse. */
9743 size
= (STRINGP (f
->desired_tool_bar_string
)
9744 ? SCHARS (f
->desired_tool_bar_string
)
9747 /* We need one space in the string for each image. */
9748 size_needed
= f
->n_tool_bar_items
;
9750 /* Reuse f->desired_tool_bar_string, if possible. */
9751 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9752 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9756 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9757 Fremove_text_properties (make_number (0), make_number (size
),
9758 props
, f
->desired_tool_bar_string
);
9761 /* Put a `display' property on the string for the images to display,
9762 put a `menu_item' property on tool-bar items with a value that
9763 is the index of the item in F's tool-bar item vector. */
9764 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9766 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9768 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9769 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9770 int hmargin
, vmargin
, relief
, idx
, end
;
9771 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9773 /* If image is a vector, choose the image according to the
9775 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9776 if (VECTORP (image
))
9780 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9781 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9784 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9785 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9787 xassert (ASIZE (image
) >= idx
);
9788 image
= AREF (image
, idx
);
9793 /* Ignore invalid image specifications. */
9794 if (!valid_image_p (image
))
9797 /* Display the tool-bar button pressed, or depressed. */
9798 plist
= Fcopy_sequence (XCDR (image
));
9800 /* Compute margin and relief to draw. */
9801 relief
= (tool_bar_button_relief
>= 0
9802 ? tool_bar_button_relief
9803 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9804 hmargin
= vmargin
= relief
;
9806 if (INTEGERP (Vtool_bar_button_margin
)
9807 && XINT (Vtool_bar_button_margin
) > 0)
9809 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9810 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9812 else if (CONSP (Vtool_bar_button_margin
))
9814 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9815 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9816 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9818 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9819 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9820 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9823 if (auto_raise_tool_bar_buttons_p
)
9825 /* Add a `:relief' property to the image spec if the item is
9829 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9836 /* If image is selected, display it pressed, i.e. with a
9837 negative relief. If it's not selected, display it with a
9839 plist
= Fplist_put (plist
, QCrelief
,
9841 ? make_number (-relief
)
9842 : make_number (relief
)));
9847 /* Put a margin around the image. */
9848 if (hmargin
|| vmargin
)
9850 if (hmargin
== vmargin
)
9851 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9853 plist
= Fplist_put (plist
, QCmargin
,
9854 Fcons (make_number (hmargin
),
9855 make_number (vmargin
)));
9858 /* If button is not enabled, and we don't have special images
9859 for the disabled state, make the image appear disabled by
9860 applying an appropriate algorithm to it. */
9861 if (!enabled_p
&& idx
< 0)
9862 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9864 /* Put a `display' text property on the string for the image to
9865 display. Put a `menu-item' property on the string that gives
9866 the start of this item's properties in the tool-bar items
9868 image
= Fcons (Qimage
, plist
);
9869 props
= list4 (Qdisplay
, image
,
9870 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9872 /* Let the last image hide all remaining spaces in the tool bar
9873 string. The string can be longer than needed when we reuse a
9875 if (i
+ 1 == f
->n_tool_bar_items
)
9876 end
= SCHARS (f
->desired_tool_bar_string
);
9879 Fadd_text_properties (make_number (i
), make_number (end
),
9880 props
, f
->desired_tool_bar_string
);
9888 /* Display one line of the tool-bar of frame IT->f.
9890 HEIGHT specifies the desired height of the tool-bar line.
9891 If the actual height of the glyph row is less than HEIGHT, the
9892 row's height is increased to HEIGHT, and the icons are centered
9893 vertically in the new height.
9895 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
9896 count a final empty row in case the tool-bar width exactly matches
9901 display_tool_bar_line (it
, height
)
9905 struct glyph_row
*row
= it
->glyph_row
;
9906 int max_x
= it
->last_visible_x
;
9909 prepare_desired_row (row
);
9910 row
->y
= it
->current_y
;
9912 /* Note that this isn't made use of if the face hasn't a box,
9913 so there's no need to check the face here. */
9914 it
->start_of_box_run_p
= 1;
9916 while (it
->current_x
< max_x
)
9918 int x
, n_glyphs_before
, i
, nglyphs
;
9919 struct it it_before
;
9921 /* Get the next display element. */
9922 if (!get_next_display_element (it
))
9924 /* Don't count empty row if we are counting needed tool-bar lines. */
9925 if (height
< 0 && !it
->hpos
)
9930 /* Produce glyphs. */
9931 n_glyphs_before
= row
->used
[TEXT_AREA
];
9934 PRODUCE_GLYPHS (it
);
9936 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
9938 x
= it_before
.current_x
;
9941 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9943 if (x
+ glyph
->pixel_width
> max_x
)
9945 /* Glyph doesn't fit on line. Backtrack. */
9946 row
->used
[TEXT_AREA
] = n_glyphs_before
;
9948 /* If this is the only glyph on this line, it will never fit on the
9949 toolbar, so skip it. But ensure there is at least one glyph,
9950 so we don't accidentally disable the tool-bar. */
9951 if (n_glyphs_before
== 0
9952 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
9958 x
+= glyph
->pixel_width
;
9962 /* Stop at line ends. */
9963 if (ITERATOR_AT_END_OF_LINE_P (it
))
9966 set_iterator_to_next (it
, 1);
9971 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9973 /* Use default face for the border below the tool bar.
9975 FIXME: When auto-resize-tool-bars is grow-only, there is
9976 no additional border below the possibly empty tool-bar lines.
9977 So to make the extra empty lines look "normal", we have to
9978 use the tool-bar face for the border too. */
9979 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
9980 it
->face_id
= DEFAULT_FACE_ID
;
9982 extend_face_to_end_of_line (it
);
9983 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9984 last
->right_box_line_p
= 1;
9985 if (last
== row
->glyphs
[TEXT_AREA
])
9986 last
->left_box_line_p
= 1;
9988 /* Make line the desired height and center it vertically. */
9989 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
9991 /* Don't add more than one line height. */
9992 height
%= FRAME_LINE_HEIGHT (it
->f
);
9993 it
->max_ascent
+= height
/ 2;
9994 it
->max_descent
+= (height
+ 1) / 2;
9997 compute_line_metrics (it
);
9999 /* If line is empty, make it occupy the rest of the tool-bar. */
10000 if (!row
->displays_text_p
)
10002 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10003 row
->visible_height
= row
->height
;
10004 row
->ascent
= row
->phys_ascent
= 0;
10005 row
->extra_line_spacing
= 0;
10008 row
->full_width_p
= 1;
10009 row
->continued_p
= 0;
10010 row
->truncated_on_left_p
= 0;
10011 row
->truncated_on_right_p
= 0;
10013 it
->current_x
= it
->hpos
= 0;
10014 it
->current_y
+= row
->height
;
10020 /* Max tool-bar height. */
10022 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10023 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10025 /* Value is the number of screen lines needed to make all tool-bar
10026 items of frame F visible. The number of actual rows needed is
10027 returned in *N_ROWS if non-NULL. */
10030 tool_bar_lines_needed (f
, n_rows
)
10034 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10036 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10037 the desired matrix, so use (unused) mode-line row as temporary row to
10038 avoid destroying the first tool-bar row. */
10039 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10041 /* Initialize an iterator for iteration over
10042 F->desired_tool_bar_string in the tool-bar window of frame F. */
10043 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10044 it
.first_visible_x
= 0;
10045 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10046 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10048 while (!ITERATOR_AT_END_P (&it
))
10050 clear_glyph_row (temp_row
);
10051 it
.glyph_row
= temp_row
;
10052 display_tool_bar_line (&it
, -1);
10054 clear_glyph_row (temp_row
);
10056 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10058 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10060 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10064 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10066 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10075 frame
= selected_frame
;
10077 CHECK_FRAME (frame
);
10078 f
= XFRAME (frame
);
10080 if (WINDOWP (f
->tool_bar_window
)
10081 || (w
= XWINDOW (f
->tool_bar_window
),
10082 WINDOW_TOTAL_LINES (w
) > 0))
10084 update_tool_bar (f
, 1);
10085 if (f
->n_tool_bar_items
)
10087 build_desired_tool_bar_string (f
);
10088 nlines
= tool_bar_lines_needed (f
, NULL
);
10092 return make_number (nlines
);
10096 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10097 height should be changed. */
10100 redisplay_tool_bar (f
)
10105 struct glyph_row
*row
;
10107 #if defined (USE_GTK) || USE_MAC_TOOLBAR
10108 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10109 update_frame_tool_bar (f
);
10113 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10114 do anything. This means you must start with tool-bar-lines
10115 non-zero to get the auto-sizing effect. Or in other words, you
10116 can turn off tool-bars by specifying tool-bar-lines zero. */
10117 if (!WINDOWP (f
->tool_bar_window
)
10118 || (w
= XWINDOW (f
->tool_bar_window
),
10119 WINDOW_TOTAL_LINES (w
) == 0))
10122 /* Set up an iterator for the tool-bar window. */
10123 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10124 it
.first_visible_x
= 0;
10125 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10126 row
= it
.glyph_row
;
10128 /* Build a string that represents the contents of the tool-bar. */
10129 build_desired_tool_bar_string (f
);
10130 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10132 if (f
->n_tool_bar_rows
== 0)
10136 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10137 nlines
!= WINDOW_TOTAL_LINES (w
)))
10139 extern Lisp_Object Qtool_bar_lines
;
10141 int old_height
= WINDOW_TOTAL_LINES (w
);
10143 XSETFRAME (frame
, f
);
10144 Fmodify_frame_parameters (frame
,
10145 Fcons (Fcons (Qtool_bar_lines
,
10146 make_number (nlines
)),
10148 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10150 clear_glyph_matrix (w
->desired_matrix
);
10151 fonts_changed_p
= 1;
10157 /* Display as many lines as needed to display all tool-bar items. */
10159 if (f
->n_tool_bar_rows
> 0)
10161 int border
, rows
, height
, extra
;
10163 if (INTEGERP (Vtool_bar_border
))
10164 border
= XINT (Vtool_bar_border
);
10165 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10166 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10167 else if (EQ (Vtool_bar_border
, Qborder_width
))
10168 border
= f
->border_width
;
10174 rows
= f
->n_tool_bar_rows
;
10175 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10176 extra
= it
.last_visible_y
- border
- height
* rows
;
10178 while (it
.current_y
< it
.last_visible_y
)
10181 if (extra
> 0 && rows
-- > 0)
10183 h
= (extra
+ rows
- 1) / rows
;
10186 display_tool_bar_line (&it
, height
+ h
);
10191 while (it
.current_y
< it
.last_visible_y
)
10192 display_tool_bar_line (&it
, 0);
10195 /* It doesn't make much sense to try scrolling in the tool-bar
10196 window, so don't do it. */
10197 w
->desired_matrix
->no_scrolling_p
= 1;
10198 w
->must_be_updated_p
= 1;
10200 if (!NILP (Vauto_resize_tool_bars
))
10202 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10203 int change_height_p
= 0;
10205 /* If we couldn't display everything, change the tool-bar's
10206 height if there is room for more. */
10207 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10208 && it
.current_y
< max_tool_bar_height
)
10209 change_height_p
= 1;
10211 row
= it
.glyph_row
- 1;
10213 /* If there are blank lines at the end, except for a partially
10214 visible blank line at the end that is smaller than
10215 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10216 if (!row
->displays_text_p
10217 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10218 change_height_p
= 1;
10220 /* If row displays tool-bar items, but is partially visible,
10221 change the tool-bar's height. */
10222 if (row
->displays_text_p
10223 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10224 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10225 change_height_p
= 1;
10227 /* Resize windows as needed by changing the `tool-bar-lines'
10228 frame parameter. */
10229 if (change_height_p
)
10231 extern Lisp_Object Qtool_bar_lines
;
10233 int old_height
= WINDOW_TOTAL_LINES (w
);
10235 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10237 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10238 && !f
->minimize_tool_bar_window_p
)
10239 ? (nlines
> old_height
)
10240 : (nlines
!= old_height
));
10241 f
->minimize_tool_bar_window_p
= 0;
10243 if (change_height_p
)
10245 XSETFRAME (frame
, f
);
10246 Fmodify_frame_parameters (frame
,
10247 Fcons (Fcons (Qtool_bar_lines
,
10248 make_number (nlines
)),
10250 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10252 clear_glyph_matrix (w
->desired_matrix
);
10253 f
->n_tool_bar_rows
= nrows
;
10254 fonts_changed_p
= 1;
10261 f
->minimize_tool_bar_window_p
= 0;
10266 /* Get information about the tool-bar item which is displayed in GLYPH
10267 on frame F. Return in *PROP_IDX the index where tool-bar item
10268 properties start in F->tool_bar_items. Value is zero if
10269 GLYPH doesn't display a tool-bar item. */
10272 tool_bar_item_info (f
, glyph
, prop_idx
)
10274 struct glyph
*glyph
;
10281 /* This function can be called asynchronously, which means we must
10282 exclude any possibility that Fget_text_property signals an
10284 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10285 charpos
= max (0, charpos
);
10287 /* Get the text property `menu-item' at pos. The value of that
10288 property is the start index of this item's properties in
10289 F->tool_bar_items. */
10290 prop
= Fget_text_property (make_number (charpos
),
10291 Qmenu_item
, f
->current_tool_bar_string
);
10292 if (INTEGERP (prop
))
10294 *prop_idx
= XINT (prop
);
10304 /* Get information about the tool-bar item at position X/Y on frame F.
10305 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10306 the current matrix of the tool-bar window of F, or NULL if not
10307 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10308 item in F->tool_bar_items. Value is
10310 -1 if X/Y is not on a tool-bar item
10311 0 if X/Y is on the same item that was highlighted before.
10315 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10318 struct glyph
**glyph
;
10319 int *hpos
, *vpos
, *prop_idx
;
10321 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10322 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10325 /* Find the glyph under X/Y. */
10326 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10327 if (*glyph
== NULL
)
10330 /* Get the start of this tool-bar item's properties in
10331 f->tool_bar_items. */
10332 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10335 /* Is mouse on the highlighted item? */
10336 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10337 && *vpos
>= dpyinfo
->mouse_face_beg_row
10338 && *vpos
<= dpyinfo
->mouse_face_end_row
10339 && (*vpos
> dpyinfo
->mouse_face_beg_row
10340 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10341 && (*vpos
< dpyinfo
->mouse_face_end_row
10342 || *hpos
< dpyinfo
->mouse_face_end_col
10343 || dpyinfo
->mouse_face_past_end
))
10351 Handle mouse button event on the tool-bar of frame F, at
10352 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10353 0 for button release. MODIFIERS is event modifiers for button
10357 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10360 unsigned int modifiers
;
10362 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10363 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10364 int hpos
, vpos
, prop_idx
;
10365 struct glyph
*glyph
;
10366 Lisp_Object enabled_p
;
10368 /* If not on the highlighted tool-bar item, return. */
10369 frame_to_window_pixel_xy (w
, &x
, &y
);
10370 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10373 /* If item is disabled, do nothing. */
10374 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10375 if (NILP (enabled_p
))
10380 /* Show item in pressed state. */
10381 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10382 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10383 last_tool_bar_item
= prop_idx
;
10387 Lisp_Object key
, frame
;
10388 struct input_event event
;
10389 EVENT_INIT (event
);
10391 /* Show item in released state. */
10392 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10393 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10395 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10397 XSETFRAME (frame
, f
);
10398 event
.kind
= TOOL_BAR_EVENT
;
10399 event
.frame_or_window
= frame
;
10401 kbd_buffer_store_event (&event
);
10403 event
.kind
= TOOL_BAR_EVENT
;
10404 event
.frame_or_window
= frame
;
10406 event
.modifiers
= modifiers
;
10407 kbd_buffer_store_event (&event
);
10408 last_tool_bar_item
= -1;
10413 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10414 tool-bar window-relative coordinates X/Y. Called from
10415 note_mouse_highlight. */
10418 note_tool_bar_highlight (f
, x
, y
)
10422 Lisp_Object window
= f
->tool_bar_window
;
10423 struct window
*w
= XWINDOW (window
);
10424 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10426 struct glyph
*glyph
;
10427 struct glyph_row
*row
;
10429 Lisp_Object enabled_p
;
10431 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10432 int mouse_down_p
, rc
;
10434 /* Function note_mouse_highlight is called with negative x(y
10435 values when mouse moves outside of the frame. */
10436 if (x
<= 0 || y
<= 0)
10438 clear_mouse_face (dpyinfo
);
10442 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10445 /* Not on tool-bar item. */
10446 clear_mouse_face (dpyinfo
);
10450 /* On same tool-bar item as before. */
10451 goto set_help_echo
;
10453 clear_mouse_face (dpyinfo
);
10455 /* Mouse is down, but on different tool-bar item? */
10456 mouse_down_p
= (dpyinfo
->grabbed
10457 && f
== last_mouse_frame
10458 && FRAME_LIVE_P (f
));
10460 && last_tool_bar_item
!= prop_idx
)
10463 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10464 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10466 /* If tool-bar item is not enabled, don't highlight it. */
10467 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10468 if (!NILP (enabled_p
))
10470 /* Compute the x-position of the glyph. In front and past the
10471 image is a space. We include this in the highlighted area. */
10472 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10473 for (i
= x
= 0; i
< hpos
; ++i
)
10474 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10476 /* Record this as the current active region. */
10477 dpyinfo
->mouse_face_beg_col
= hpos
;
10478 dpyinfo
->mouse_face_beg_row
= vpos
;
10479 dpyinfo
->mouse_face_beg_x
= x
;
10480 dpyinfo
->mouse_face_beg_y
= row
->y
;
10481 dpyinfo
->mouse_face_past_end
= 0;
10483 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10484 dpyinfo
->mouse_face_end_row
= vpos
;
10485 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10486 dpyinfo
->mouse_face_end_y
= row
->y
;
10487 dpyinfo
->mouse_face_window
= window
;
10488 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10490 /* Display it as active. */
10491 show_mouse_face (dpyinfo
, draw
);
10492 dpyinfo
->mouse_face_image_state
= draw
;
10497 /* Set help_echo_string to a help string to display for this tool-bar item.
10498 XTread_socket does the rest. */
10499 help_echo_object
= help_echo_window
= Qnil
;
10500 help_echo_pos
= -1;
10501 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10502 if (NILP (help_echo_string
))
10503 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10506 #endif /* HAVE_WINDOW_SYSTEM */
10510 /************************************************************************
10511 Horizontal scrolling
10512 ************************************************************************/
10514 static int hscroll_window_tree
P_ ((Lisp_Object
));
10515 static int hscroll_windows
P_ ((Lisp_Object
));
10517 /* For all leaf windows in the window tree rooted at WINDOW, set their
10518 hscroll value so that PT is (i) visible in the window, and (ii) so
10519 that it is not within a certain margin at the window's left and
10520 right border. Value is non-zero if any window's hscroll has been
10524 hscroll_window_tree (window
)
10525 Lisp_Object window
;
10527 int hscrolled_p
= 0;
10528 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10529 int hscroll_step_abs
= 0;
10530 double hscroll_step_rel
= 0;
10532 if (hscroll_relative_p
)
10534 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10535 if (hscroll_step_rel
< 0)
10537 hscroll_relative_p
= 0;
10538 hscroll_step_abs
= 0;
10541 else if (INTEGERP (Vhscroll_step
))
10543 hscroll_step_abs
= XINT (Vhscroll_step
);
10544 if (hscroll_step_abs
< 0)
10545 hscroll_step_abs
= 0;
10548 hscroll_step_abs
= 0;
10550 while (WINDOWP (window
))
10552 struct window
*w
= XWINDOW (window
);
10554 if (WINDOWP (w
->hchild
))
10555 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10556 else if (WINDOWP (w
->vchild
))
10557 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10558 else if (w
->cursor
.vpos
>= 0)
10561 int text_area_width
;
10562 struct glyph_row
*current_cursor_row
10563 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10564 struct glyph_row
*desired_cursor_row
10565 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10566 struct glyph_row
*cursor_row
10567 = (desired_cursor_row
->enabled_p
10568 ? desired_cursor_row
10569 : current_cursor_row
);
10571 text_area_width
= window_box_width (w
, TEXT_AREA
);
10573 /* Scroll when cursor is inside this scroll margin. */
10574 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10576 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
10577 && ((XFASTINT (w
->hscroll
)
10578 && w
->cursor
.x
<= h_margin
)
10579 || (cursor_row
->enabled_p
10580 && cursor_row
->truncated_on_right_p
10581 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
10585 struct buffer
*saved_current_buffer
;
10589 /* Find point in a display of infinite width. */
10590 saved_current_buffer
= current_buffer
;
10591 current_buffer
= XBUFFER (w
->buffer
);
10593 if (w
== XWINDOW (selected_window
))
10594 pt
= BUF_PT (current_buffer
);
10597 pt
= marker_position (w
->pointm
);
10598 pt
= max (BEGV
, pt
);
10602 /* Move iterator to pt starting at cursor_row->start in
10603 a line with infinite width. */
10604 init_to_row_start (&it
, w
, cursor_row
);
10605 it
.last_visible_x
= INFINITY
;
10606 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10607 current_buffer
= saved_current_buffer
;
10609 /* Position cursor in window. */
10610 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10611 hscroll
= max (0, (it
.current_x
10612 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10613 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10614 : (text_area_width
/ 2))))
10615 / FRAME_COLUMN_WIDTH (it
.f
);
10616 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10618 if (hscroll_relative_p
)
10619 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10622 wanted_x
= text_area_width
10623 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10626 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10630 if (hscroll_relative_p
)
10631 wanted_x
= text_area_width
* hscroll_step_rel
10634 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10637 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10639 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10641 /* Don't call Fset_window_hscroll if value hasn't
10642 changed because it will prevent redisplay
10644 if (XFASTINT (w
->hscroll
) != hscroll
)
10646 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10647 w
->hscroll
= make_number (hscroll
);
10656 /* Value is non-zero if hscroll of any leaf window has been changed. */
10657 return hscrolled_p
;
10661 /* Set hscroll so that cursor is visible and not inside horizontal
10662 scroll margins for all windows in the tree rooted at WINDOW. See
10663 also hscroll_window_tree above. Value is non-zero if any window's
10664 hscroll has been changed. If it has, desired matrices on the frame
10665 of WINDOW are cleared. */
10668 hscroll_windows (window
)
10669 Lisp_Object window
;
10671 int hscrolled_p
= hscroll_window_tree (window
);
10673 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10674 return hscrolled_p
;
10679 /************************************************************************
10681 ************************************************************************/
10683 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10684 to a non-zero value. This is sometimes handy to have in a debugger
10689 /* First and last unchanged row for try_window_id. */
10691 int debug_first_unchanged_at_end_vpos
;
10692 int debug_last_unchanged_at_beg_vpos
;
10694 /* Delta vpos and y. */
10696 int debug_dvpos
, debug_dy
;
10698 /* Delta in characters and bytes for try_window_id. */
10700 int debug_delta
, debug_delta_bytes
;
10702 /* Values of window_end_pos and window_end_vpos at the end of
10705 EMACS_INT debug_end_pos
, debug_end_vpos
;
10707 /* Append a string to W->desired_matrix->method. FMT is a printf
10708 format string. A1...A9 are a supplement for a variable-length
10709 argument list. If trace_redisplay_p is non-zero also printf the
10710 resulting string to stderr. */
10713 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10716 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10719 char *method
= w
->desired_matrix
->method
;
10720 int len
= strlen (method
);
10721 int size
= sizeof w
->desired_matrix
->method
;
10722 int remaining
= size
- len
- 1;
10724 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10725 if (len
&& remaining
)
10728 --remaining
, ++len
;
10731 strncpy (method
+ len
, buffer
, remaining
);
10733 if (trace_redisplay_p
)
10734 fprintf (stderr
, "%p (%s): %s\n",
10736 ((BUFFERP (w
->buffer
)
10737 && STRINGP (XBUFFER (w
->buffer
)->name
))
10738 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10743 #endif /* GLYPH_DEBUG */
10746 /* Value is non-zero if all changes in window W, which displays
10747 current_buffer, are in the text between START and END. START is a
10748 buffer position, END is given as a distance from Z. Used in
10749 redisplay_internal for display optimization. */
10752 text_outside_line_unchanged_p (w
, start
, end
)
10756 int unchanged_p
= 1;
10758 /* If text or overlays have changed, see where. */
10759 if (XFASTINT (w
->last_modified
) < MODIFF
10760 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10762 /* Gap in the line? */
10763 if (GPT
< start
|| Z
- GPT
< end
)
10766 /* Changes start in front of the line, or end after it? */
10768 && (BEG_UNCHANGED
< start
- 1
10769 || END_UNCHANGED
< end
))
10772 /* If selective display, can't optimize if changes start at the
10773 beginning of the line. */
10775 && INTEGERP (current_buffer
->selective_display
)
10776 && XINT (current_buffer
->selective_display
) > 0
10777 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10780 /* If there are overlays at the start or end of the line, these
10781 may have overlay strings with newlines in them. A change at
10782 START, for instance, may actually concern the display of such
10783 overlay strings as well, and they are displayed on different
10784 lines. So, quickly rule out this case. (For the future, it
10785 might be desirable to implement something more telling than
10786 just BEG/END_UNCHANGED.) */
10789 if (BEG
+ BEG_UNCHANGED
== start
10790 && overlay_touches_p (start
))
10792 if (END_UNCHANGED
== end
10793 && overlay_touches_p (Z
- end
))
10798 return unchanged_p
;
10802 /* Do a frame update, taking possible shortcuts into account. This is
10803 the main external entry point for redisplay.
10805 If the last redisplay displayed an echo area message and that message
10806 is no longer requested, we clear the echo area or bring back the
10807 mini-buffer if that is in use. */
10812 redisplay_internal (0);
10817 overlay_arrow_string_or_property (var
)
10822 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10825 return Voverlay_arrow_string
;
10828 /* Return 1 if there are any overlay-arrows in current_buffer. */
10830 overlay_arrow_in_current_buffer_p ()
10834 for (vlist
= Voverlay_arrow_variable_list
;
10836 vlist
= XCDR (vlist
))
10838 Lisp_Object var
= XCAR (vlist
);
10841 if (!SYMBOLP (var
))
10843 val
= find_symbol_value (var
);
10845 && current_buffer
== XMARKER (val
)->buffer
)
10852 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
10856 overlay_arrows_changed_p ()
10860 for (vlist
= Voverlay_arrow_variable_list
;
10862 vlist
= XCDR (vlist
))
10864 Lisp_Object var
= XCAR (vlist
);
10865 Lisp_Object val
, pstr
;
10867 if (!SYMBOLP (var
))
10869 val
= find_symbol_value (var
);
10870 if (!MARKERP (val
))
10872 if (! EQ (COERCE_MARKER (val
),
10873 Fget (var
, Qlast_arrow_position
))
10874 || ! (pstr
= overlay_arrow_string_or_property (var
),
10875 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
10881 /* Mark overlay arrows to be updated on next redisplay. */
10884 update_overlay_arrows (up_to_date
)
10889 for (vlist
= Voverlay_arrow_variable_list
;
10891 vlist
= XCDR (vlist
))
10893 Lisp_Object var
= XCAR (vlist
);
10895 if (!SYMBOLP (var
))
10898 if (up_to_date
> 0)
10900 Lisp_Object val
= find_symbol_value (var
);
10901 Fput (var
, Qlast_arrow_position
,
10902 COERCE_MARKER (val
));
10903 Fput (var
, Qlast_arrow_string
,
10904 overlay_arrow_string_or_property (var
));
10906 else if (up_to_date
< 0
10907 || !NILP (Fget (var
, Qlast_arrow_position
)))
10909 Fput (var
, Qlast_arrow_position
, Qt
);
10910 Fput (var
, Qlast_arrow_string
, Qt
);
10916 /* Return overlay arrow string to display at row.
10917 Return integer (bitmap number) for arrow bitmap in left fringe.
10918 Return nil if no overlay arrow. */
10921 overlay_arrow_at_row (it
, row
)
10923 struct glyph_row
*row
;
10927 for (vlist
= Voverlay_arrow_variable_list
;
10929 vlist
= XCDR (vlist
))
10931 Lisp_Object var
= XCAR (vlist
);
10934 if (!SYMBOLP (var
))
10937 val
= find_symbol_value (var
);
10940 && current_buffer
== XMARKER (val
)->buffer
10941 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10943 if (FRAME_WINDOW_P (it
->f
)
10944 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10946 #ifdef HAVE_WINDOW_SYSTEM
10947 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10950 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10951 return make_number (fringe_bitmap
);
10954 return make_number (-1); /* Use default arrow bitmap */
10956 return overlay_arrow_string_or_property (var
);
10963 /* Return 1 if point moved out of or into a composition. Otherwise
10964 return 0. PREV_BUF and PREV_PT are the last point buffer and
10965 position. BUF and PT are the current point buffer and position. */
10968 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10969 struct buffer
*prev_buf
, *buf
;
10972 EMACS_INT start
, end
;
10974 Lisp_Object buffer
;
10976 XSETBUFFER (buffer
, buf
);
10977 /* Check a composition at the last point if point moved within the
10979 if (prev_buf
== buf
)
10982 /* Point didn't move. */
10985 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10986 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10987 && COMPOSITION_VALID_P (start
, end
, prop
)
10988 && start
< prev_pt
&& end
> prev_pt
)
10989 /* The last point was within the composition. Return 1 iff
10990 point moved out of the composition. */
10991 return (pt
<= start
|| pt
>= end
);
10994 /* Check a composition at the current point. */
10995 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10996 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10997 && COMPOSITION_VALID_P (start
, end
, prop
)
10998 && start
< pt
&& end
> pt
);
11002 /* Reconsider the setting of B->clip_changed which is displayed
11006 reconsider_clip_changes (w
, b
)
11010 if (b
->clip_changed
11011 && !NILP (w
->window_end_valid
)
11012 && w
->current_matrix
->buffer
== b
11013 && w
->current_matrix
->zv
== BUF_ZV (b
)
11014 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11015 b
->clip_changed
= 0;
11017 /* If display wasn't paused, and W is not a tool bar window, see if
11018 point has been moved into or out of a composition. In that case,
11019 we set b->clip_changed to 1 to force updating the screen. If
11020 b->clip_changed has already been set to 1, we can skip this
11022 if (!b
->clip_changed
11023 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11027 if (w
== XWINDOW (selected_window
))
11028 pt
= BUF_PT (current_buffer
);
11030 pt
= marker_position (w
->pointm
);
11032 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11033 || pt
!= XINT (w
->last_point
))
11034 && check_point_in_composition (w
->current_matrix
->buffer
,
11035 XINT (w
->last_point
),
11036 XBUFFER (w
->buffer
), pt
))
11037 b
->clip_changed
= 1;
11042 /* Select FRAME to forward the values of frame-local variables into C
11043 variables so that the redisplay routines can access those values
11047 select_frame_for_redisplay (frame
)
11050 Lisp_Object tail
, symbol
, val
;
11051 Lisp_Object old
= selected_frame
;
11052 struct Lisp_Symbol
*sym
;
11054 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11056 selected_frame
= frame
;
11060 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11061 if (CONSP (XCAR (tail
))
11062 && (symbol
= XCAR (XCAR (tail
)),
11064 && (sym
= indirect_variable (XSYMBOL (symbol
)),
11066 (BUFFER_LOCAL_VALUEP (val
)))
11067 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
11068 /* Use find_symbol_value rather than Fsymbol_value
11069 to avoid an error if it is void. */
11070 find_symbol_value (symbol
);
11071 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11075 #define STOP_POLLING \
11076 do { if (! polling_stopped_here) stop_polling (); \
11077 polling_stopped_here = 1; } while (0)
11079 #define RESUME_POLLING \
11080 do { if (polling_stopped_here) start_polling (); \
11081 polling_stopped_here = 0; } while (0)
11084 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
11085 response to any user action; therefore, we should preserve the echo
11086 area. (Actually, our caller does that job.) Perhaps in the future
11087 avoid recentering windows if it is not necessary; currently that
11088 causes some problems. */
11091 redisplay_internal (preserve_echo_area
)
11092 int preserve_echo_area
;
11094 struct window
*w
= XWINDOW (selected_window
);
11097 int must_finish
= 0;
11098 struct text_pos tlbufpos
, tlendpos
;
11099 int number_of_visible_frames
;
11102 int polling_stopped_here
= 0;
11103 Lisp_Object old_frame
= selected_frame
;
11105 /* Non-zero means redisplay has to consider all windows on all
11106 frames. Zero means, only selected_window is considered. */
11107 int consider_all_windows_p
;
11109 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11111 /* No redisplay if running in batch mode or frame is not yet fully
11112 initialized, or redisplay is explicitly turned off by setting
11113 Vinhibit_redisplay. */
11115 || !NILP (Vinhibit_redisplay
))
11118 /* Don't examine these until after testing Vinhibit_redisplay.
11119 When Emacs is shutting down, perhaps because its connection to
11120 X has dropped, we should not look at them at all. */
11121 f
= XFRAME (w
->frame
);
11122 sf
= SELECTED_FRAME ();
11124 if (!f
->glyphs_initialized_p
)
11127 /* The flag redisplay_performed_directly_p is set by
11128 direct_output_for_insert when it already did the whole screen
11129 update necessary. */
11130 if (redisplay_performed_directly_p
)
11132 redisplay_performed_directly_p
= 0;
11133 if (!hscroll_windows (selected_window
))
11137 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (MAC_OS)
11138 if (popup_activated ())
11142 /* I don't think this happens but let's be paranoid. */
11143 if (redisplaying_p
)
11146 /* Record a function that resets redisplaying_p to its old value
11147 when we leave this function. */
11148 count
= SPECPDL_INDEX ();
11149 record_unwind_protect (unwind_redisplay
,
11150 Fcons (make_number (redisplaying_p
), selected_frame
));
11152 specbind (Qinhibit_free_realized_faces
, Qnil
);
11155 Lisp_Object tail
, frame
;
11157 FOR_EACH_FRAME (tail
, frame
)
11159 struct frame
*f
= XFRAME (frame
);
11160 f
->already_hscrolled_p
= 0;
11165 if (!EQ (old_frame
, selected_frame
)
11166 && FRAME_LIVE_P (XFRAME (old_frame
)))
11167 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11168 selected_frame and selected_window to be temporarily out-of-sync so
11169 when we come back here via `goto retry', we need to resync because we
11170 may need to run Elisp code (via prepare_menu_bars). */
11171 select_frame_for_redisplay (old_frame
);
11174 reconsider_clip_changes (w
, current_buffer
);
11175 last_escape_glyph_frame
= NULL
;
11176 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11178 /* If new fonts have been loaded that make a glyph matrix adjustment
11179 necessary, do it. */
11180 if (fonts_changed_p
)
11182 adjust_glyphs (NULL
);
11183 ++windows_or_buffers_changed
;
11184 fonts_changed_p
= 0;
11187 /* If face_change_count is non-zero, init_iterator will free all
11188 realized faces, which includes the faces referenced from current
11189 matrices. So, we can't reuse current matrices in this case. */
11190 if (face_change_count
)
11191 ++windows_or_buffers_changed
;
11193 if (FRAME_TERMCAP_P (sf
)
11194 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11196 /* Since frames on a single ASCII terminal share the same
11197 display area, displaying a different frame means redisplay
11198 the whole thing. */
11199 windows_or_buffers_changed
++;
11200 SET_FRAME_GARBAGED (sf
);
11202 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11204 FRAME_TTY (sf
)->previous_frame
= sf
;
11207 /* Set the visible flags for all frames. Do this before checking
11208 for resized or garbaged frames; they want to know if their frames
11209 are visible. See the comment in frame.h for
11210 FRAME_SAMPLE_VISIBILITY. */
11212 Lisp_Object tail
, frame
;
11214 number_of_visible_frames
= 0;
11216 FOR_EACH_FRAME (tail
, frame
)
11218 struct frame
*f
= XFRAME (frame
);
11220 FRAME_SAMPLE_VISIBILITY (f
);
11221 if (FRAME_VISIBLE_P (f
))
11222 ++number_of_visible_frames
;
11223 clear_desired_matrices (f
);
11228 /* Notice any pending interrupt request to change frame size. */
11229 do_pending_window_change (1);
11231 /* Clear frames marked as garbaged. */
11232 if (frame_garbaged
)
11233 clear_garbaged_frames ();
11235 /* Build menubar and tool-bar items. */
11236 if (NILP (Vmemory_full
))
11237 prepare_menu_bars ();
11239 if (windows_or_buffers_changed
)
11240 update_mode_lines
++;
11242 /* Detect case that we need to write or remove a star in the mode line. */
11243 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11245 w
->update_mode_line
= Qt
;
11246 if (buffer_shared
> 1)
11247 update_mode_lines
++;
11250 /* Avoid invocation of point motion hooks by `current_column' below. */
11251 count1
= SPECPDL_INDEX ();
11252 specbind (Qinhibit_point_motion_hooks
, Qt
);
11254 /* If %c is in the mode line, update it if needed. */
11255 if (!NILP (w
->column_number_displayed
)
11256 /* This alternative quickly identifies a common case
11257 where no change is needed. */
11258 && !(PT
== XFASTINT (w
->last_point
)
11259 && XFASTINT (w
->last_modified
) >= MODIFF
11260 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11261 && (XFASTINT (w
->column_number_displayed
)
11262 != (int) current_column ())) /* iftc */
11263 w
->update_mode_line
= Qt
;
11265 unbind_to (count1
, Qnil
);
11267 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11269 /* The variable buffer_shared is set in redisplay_window and
11270 indicates that we redisplay a buffer in different windows. See
11272 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11273 || cursor_type_changed
);
11275 /* If specs for an arrow have changed, do thorough redisplay
11276 to ensure we remove any arrow that should no longer exist. */
11277 if (overlay_arrows_changed_p ())
11278 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11280 /* Normally the message* functions will have already displayed and
11281 updated the echo area, but the frame may have been trashed, or
11282 the update may have been preempted, so display the echo area
11283 again here. Checking message_cleared_p captures the case that
11284 the echo area should be cleared. */
11285 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11286 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11287 || (message_cleared_p
11288 && minibuf_level
== 0
11289 /* If the mini-window is currently selected, this means the
11290 echo-area doesn't show through. */
11291 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11293 int window_height_changed_p
= echo_area_display (0);
11296 /* If we don't display the current message, don't clear the
11297 message_cleared_p flag, because, if we did, we wouldn't clear
11298 the echo area in the next redisplay which doesn't preserve
11300 if (!display_last_displayed_message_p
)
11301 message_cleared_p
= 0;
11303 if (fonts_changed_p
)
11305 else if (window_height_changed_p
)
11307 consider_all_windows_p
= 1;
11308 ++update_mode_lines
;
11309 ++windows_or_buffers_changed
;
11311 /* If window configuration was changed, frames may have been
11312 marked garbaged. Clear them or we will experience
11313 surprises wrt scrolling. */
11314 if (frame_garbaged
)
11315 clear_garbaged_frames ();
11318 else if (EQ (selected_window
, minibuf_window
)
11319 && (current_buffer
->clip_changed
11320 || XFASTINT (w
->last_modified
) < MODIFF
11321 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11322 && resize_mini_window (w
, 0))
11324 /* Resized active mini-window to fit the size of what it is
11325 showing if its contents might have changed. */
11327 consider_all_windows_p
= 1;
11328 ++windows_or_buffers_changed
;
11329 ++update_mode_lines
;
11331 /* If window configuration was changed, frames may have been
11332 marked garbaged. Clear them or we will experience
11333 surprises wrt scrolling. */
11334 if (frame_garbaged
)
11335 clear_garbaged_frames ();
11339 /* If showing the region, and mark has changed, we must redisplay
11340 the whole window. The assignment to this_line_start_pos prevents
11341 the optimization directly below this if-statement. */
11342 if (((!NILP (Vtransient_mark_mode
)
11343 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11344 != !NILP (w
->region_showing
))
11345 || (!NILP (w
->region_showing
)
11346 && !EQ (w
->region_showing
,
11347 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11348 CHARPOS (this_line_start_pos
) = 0;
11350 /* Optimize the case that only the line containing the cursor in the
11351 selected window has changed. Variables starting with this_ are
11352 set in display_line and record information about the line
11353 containing the cursor. */
11354 tlbufpos
= this_line_start_pos
;
11355 tlendpos
= this_line_end_pos
;
11356 if (!consider_all_windows_p
11357 && CHARPOS (tlbufpos
) > 0
11358 && NILP (w
->update_mode_line
)
11359 && !current_buffer
->clip_changed
11360 && !current_buffer
->prevent_redisplay_optimizations_p
11361 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11362 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11363 /* Make sure recorded data applies to current buffer, etc. */
11364 && this_line_buffer
== current_buffer
11365 && current_buffer
== XBUFFER (w
->buffer
)
11366 && NILP (w
->force_start
)
11367 && NILP (w
->optional_new_start
)
11368 /* Point must be on the line that we have info recorded about. */
11369 && PT
>= CHARPOS (tlbufpos
)
11370 && PT
<= Z
- CHARPOS (tlendpos
)
11371 /* All text outside that line, including its final newline,
11372 must be unchanged */
11373 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11374 CHARPOS (tlendpos
)))
11376 if (CHARPOS (tlbufpos
) > BEGV
11377 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11378 && (CHARPOS (tlbufpos
) == ZV
11379 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11380 /* Former continuation line has disappeared by becoming empty */
11382 else if (XFASTINT (w
->last_modified
) < MODIFF
11383 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11384 || MINI_WINDOW_P (w
))
11386 /* We have to handle the case of continuation around a
11387 wide-column character (See the comment in indent.c around
11390 For instance, in the following case:
11392 -------- Insert --------
11393 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11394 J_I_ ==> J_I_ `^^' are cursors.
11398 As we have to redraw the line above, we should goto cancel. */
11401 int line_height_before
= this_line_pixel_height
;
11403 /* Note that start_display will handle the case that the
11404 line starting at tlbufpos is a continuation lines. */
11405 start_display (&it
, w
, tlbufpos
);
11407 /* Implementation note: It this still necessary? */
11408 if (it
.current_x
!= this_line_start_x
)
11411 TRACE ((stderr
, "trying display optimization 1\n"));
11412 w
->cursor
.vpos
= -1;
11413 overlay_arrow_seen
= 0;
11414 it
.vpos
= this_line_vpos
;
11415 it
.current_y
= this_line_y
;
11416 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11417 display_line (&it
);
11419 /* If line contains point, is not continued,
11420 and ends at same distance from eob as before, we win */
11421 if (w
->cursor
.vpos
>= 0
11422 /* Line is not continued, otherwise this_line_start_pos
11423 would have been set to 0 in display_line. */
11424 && CHARPOS (this_line_start_pos
)
11425 /* Line ends as before. */
11426 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11427 /* Line has same height as before. Otherwise other lines
11428 would have to be shifted up or down. */
11429 && this_line_pixel_height
== line_height_before
)
11431 /* If this is not the window's last line, we must adjust
11432 the charstarts of the lines below. */
11433 if (it
.current_y
< it
.last_visible_y
)
11435 struct glyph_row
*row
11436 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11437 int delta
, delta_bytes
;
11439 if (Z
- CHARPOS (tlendpos
) == ZV
)
11441 /* This line ends at end of (accessible part of)
11442 buffer. There is no newline to count. */
11444 - CHARPOS (tlendpos
)
11445 - MATRIX_ROW_START_CHARPOS (row
));
11446 delta_bytes
= (Z_BYTE
11447 - BYTEPOS (tlendpos
)
11448 - MATRIX_ROW_START_BYTEPOS (row
));
11452 /* This line ends in a newline. Must take
11453 account of the newline and the rest of the
11454 text that follows. */
11456 - CHARPOS (tlendpos
)
11457 - MATRIX_ROW_START_CHARPOS (row
));
11458 delta_bytes
= (Z_BYTE
11459 - BYTEPOS (tlendpos
)
11460 - MATRIX_ROW_START_BYTEPOS (row
));
11463 increment_matrix_positions (w
->current_matrix
,
11464 this_line_vpos
+ 1,
11465 w
->current_matrix
->nrows
,
11466 delta
, delta_bytes
);
11469 /* If this row displays text now but previously didn't,
11470 or vice versa, w->window_end_vpos may have to be
11472 if ((it
.glyph_row
- 1)->displays_text_p
)
11474 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11475 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11477 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11478 && this_line_vpos
> 0)
11479 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11480 w
->window_end_valid
= Qnil
;
11482 /* Update hint: No need to try to scroll in update_window. */
11483 w
->desired_matrix
->no_scrolling_p
= 1;
11486 *w
->desired_matrix
->method
= 0;
11487 debug_method_add (w
, "optimization 1");
11489 #ifdef HAVE_WINDOW_SYSTEM
11490 update_window_fringes (w
, 0);
11497 else if (/* Cursor position hasn't changed. */
11498 PT
== XFASTINT (w
->last_point
)
11499 /* Make sure the cursor was last displayed
11500 in this window. Otherwise we have to reposition it. */
11501 && 0 <= w
->cursor
.vpos
11502 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11506 do_pending_window_change (1);
11508 /* We used to always goto end_of_redisplay here, but this
11509 isn't enough if we have a blinking cursor. */
11510 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11511 goto end_of_redisplay
;
11515 /* If highlighting the region, or if the cursor is in the echo area,
11516 then we can't just move the cursor. */
11517 else if (! (!NILP (Vtransient_mark_mode
)
11518 && !NILP (current_buffer
->mark_active
))
11519 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11520 || highlight_nonselected_windows
)
11521 && NILP (w
->region_showing
)
11522 && NILP (Vshow_trailing_whitespace
)
11523 && !cursor_in_echo_area
)
11526 struct glyph_row
*row
;
11528 /* Skip from tlbufpos to PT and see where it is. Note that
11529 PT may be in invisible text. If so, we will end at the
11530 next visible position. */
11531 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11532 NULL
, DEFAULT_FACE_ID
);
11533 it
.current_x
= this_line_start_x
;
11534 it
.current_y
= this_line_y
;
11535 it
.vpos
= this_line_vpos
;
11537 /* The call to move_it_to stops in front of PT, but
11538 moves over before-strings. */
11539 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11541 if (it
.vpos
== this_line_vpos
11542 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11545 xassert (this_line_vpos
== it
.vpos
);
11546 xassert (this_line_y
== it
.current_y
);
11547 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11549 *w
->desired_matrix
->method
= 0;
11550 debug_method_add (w
, "optimization 3");
11559 /* Text changed drastically or point moved off of line. */
11560 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11563 CHARPOS (this_line_start_pos
) = 0;
11564 consider_all_windows_p
|= buffer_shared
> 1;
11565 ++clear_face_cache_count
;
11566 #ifdef HAVE_WINDOW_SYSTEM
11567 ++clear_image_cache_count
;
11570 /* Build desired matrices, and update the display. If
11571 consider_all_windows_p is non-zero, do it for all windows on all
11572 frames. Otherwise do it for selected_window, only. */
11574 if (consider_all_windows_p
)
11576 Lisp_Object tail
, frame
;
11578 FOR_EACH_FRAME (tail
, frame
)
11579 XFRAME (frame
)->updated_p
= 0;
11581 /* Recompute # windows showing selected buffer. This will be
11582 incremented each time such a window is displayed. */
11585 FOR_EACH_FRAME (tail
, frame
)
11587 struct frame
*f
= XFRAME (frame
);
11589 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
11591 if (! EQ (frame
, selected_frame
))
11592 /* Select the frame, for the sake of frame-local
11594 select_frame_for_redisplay (frame
);
11596 /* Mark all the scroll bars to be removed; we'll redeem
11597 the ones we want when we redisplay their windows. */
11598 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
11599 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
11601 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11602 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11604 /* Any scroll bars which redisplay_windows should have
11605 nuked should now go away. */
11606 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
11607 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
11609 /* If fonts changed, display again. */
11610 /* ??? rms: I suspect it is a mistake to jump all the way
11611 back to retry here. It should just retry this frame. */
11612 if (fonts_changed_p
)
11615 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11617 /* See if we have to hscroll. */
11618 if (!f
->already_hscrolled_p
)
11620 f
->already_hscrolled_p
= 1;
11621 if (hscroll_windows (f
->root_window
))
11625 /* Prevent various kinds of signals during display
11626 update. stdio is not robust about handling
11627 signals, which can cause an apparent I/O
11629 if (interrupt_input
)
11630 unrequest_sigio ();
11633 /* Update the display. */
11634 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11635 pause
|= update_frame (f
, 0, 0);
11636 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
11646 if (!EQ (old_frame
, selected_frame
)
11647 && FRAME_LIVE_P (XFRAME (old_frame
)))
11648 /* We played a bit fast-and-loose above and allowed selected_frame
11649 and selected_window to be temporarily out-of-sync but let's make
11650 sure this stays contained. */
11651 select_frame_for_redisplay (old_frame
);
11652 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
11656 /* Do the mark_window_display_accurate after all windows have
11657 been redisplayed because this call resets flags in buffers
11658 which are needed for proper redisplay. */
11659 FOR_EACH_FRAME (tail
, frame
)
11661 struct frame
*f
= XFRAME (frame
);
11664 mark_window_display_accurate (f
->root_window
, 1);
11665 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
11666 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
11671 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11673 Lisp_Object mini_window
;
11674 struct frame
*mini_frame
;
11676 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11677 /* Use list_of_error, not Qerror, so that
11678 we catch only errors and don't run the debugger. */
11679 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11681 redisplay_window_error
);
11683 /* Compare desired and current matrices, perform output. */
11686 /* If fonts changed, display again. */
11687 if (fonts_changed_p
)
11690 /* Prevent various kinds of signals during display update.
11691 stdio is not robust about handling signals,
11692 which can cause an apparent I/O error. */
11693 if (interrupt_input
)
11694 unrequest_sigio ();
11697 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11699 if (hscroll_windows (selected_window
))
11702 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11703 pause
= update_frame (sf
, 0, 0);
11706 /* We may have called echo_area_display at the top of this
11707 function. If the echo area is on another frame, that may
11708 have put text on a frame other than the selected one, so the
11709 above call to update_frame would not have caught it. Catch
11711 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11712 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11714 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11716 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11717 pause
|= update_frame (mini_frame
, 0, 0);
11718 if (!pause
&& hscroll_windows (mini_window
))
11723 /* If display was paused because of pending input, make sure we do a
11724 thorough update the next time. */
11727 /* Prevent the optimization at the beginning of
11728 redisplay_internal that tries a single-line update of the
11729 line containing the cursor in the selected window. */
11730 CHARPOS (this_line_start_pos
) = 0;
11732 /* Let the overlay arrow be updated the next time. */
11733 update_overlay_arrows (0);
11735 /* If we pause after scrolling, some rows in the current
11736 matrices of some windows are not valid. */
11737 if (!WINDOW_FULL_WIDTH_P (w
)
11738 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11739 update_mode_lines
= 1;
11743 if (!consider_all_windows_p
)
11745 /* This has already been done above if
11746 consider_all_windows_p is set. */
11747 mark_window_display_accurate_1 (w
, 1);
11749 /* Say overlay arrows are up to date. */
11750 update_overlay_arrows (1);
11752 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
11753 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
11756 update_mode_lines
= 0;
11757 windows_or_buffers_changed
= 0;
11758 cursor_type_changed
= 0;
11761 /* Start SIGIO interrupts coming again. Having them off during the
11762 code above makes it less likely one will discard output, but not
11763 impossible, since there might be stuff in the system buffer here.
11764 But it is much hairier to try to do anything about that. */
11765 if (interrupt_input
)
11769 /* If a frame has become visible which was not before, redisplay
11770 again, so that we display it. Expose events for such a frame
11771 (which it gets when becoming visible) don't call the parts of
11772 redisplay constructing glyphs, so simply exposing a frame won't
11773 display anything in this case. So, we have to display these
11774 frames here explicitly. */
11777 Lisp_Object tail
, frame
;
11780 FOR_EACH_FRAME (tail
, frame
)
11782 int this_is_visible
= 0;
11784 if (XFRAME (frame
)->visible
)
11785 this_is_visible
= 1;
11786 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11787 if (XFRAME (frame
)->visible
)
11788 this_is_visible
= 1;
11790 if (this_is_visible
)
11794 if (new_count
!= number_of_visible_frames
)
11795 windows_or_buffers_changed
++;
11798 /* Change frame size now if a change is pending. */
11799 do_pending_window_change (1);
11801 /* If we just did a pending size change, or have additional
11802 visible frames, redisplay again. */
11803 if (windows_or_buffers_changed
&& !pause
)
11806 /* Clear the face cache eventually. */
11807 if (consider_all_windows_p
)
11809 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11811 clear_face_cache (0);
11812 clear_face_cache_count
= 0;
11814 #ifdef HAVE_WINDOW_SYSTEM
11815 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11817 clear_image_caches (Qnil
);
11818 clear_image_cache_count
= 0;
11820 #endif /* HAVE_WINDOW_SYSTEM */
11824 unbind_to (count
, Qnil
);
11829 /* Redisplay, but leave alone any recent echo area message unless
11830 another message has been requested in its place.
11832 This is useful in situations where you need to redisplay but no
11833 user action has occurred, making it inappropriate for the message
11834 area to be cleared. See tracking_off and
11835 wait_reading_process_output for examples of these situations.
11837 FROM_WHERE is an integer saying from where this function was
11838 called. This is useful for debugging. */
11841 redisplay_preserve_echo_area (from_where
)
11844 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
11846 if (!NILP (echo_area_buffer
[1]))
11848 /* We have a previously displayed message, but no current
11849 message. Redisplay the previous message. */
11850 display_last_displayed_message_p
= 1;
11851 redisplay_internal (1);
11852 display_last_displayed_message_p
= 0;
11855 redisplay_internal (1);
11857 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
11858 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11859 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
11863 /* Function registered with record_unwind_protect in
11864 redisplay_internal. Reset redisplaying_p to the value it had
11865 before redisplay_internal was called, and clear
11866 prevent_freeing_realized_faces_p. It also selects the previously
11867 selected frame, unless it has been deleted (by an X connection
11868 failure during redisplay, for example). */
11871 unwind_redisplay (val
)
11874 Lisp_Object old_redisplaying_p
, old_frame
;
11876 old_redisplaying_p
= XCAR (val
);
11877 redisplaying_p
= XFASTINT (old_redisplaying_p
);
11878 old_frame
= XCDR (val
);
11879 if (! EQ (old_frame
, selected_frame
)
11880 && FRAME_LIVE_P (XFRAME (old_frame
)))
11881 select_frame_for_redisplay (old_frame
);
11886 /* Mark the display of window W as accurate or inaccurate. If
11887 ACCURATE_P is non-zero mark display of W as accurate. If
11888 ACCURATE_P is zero, arrange for W to be redisplayed the next time
11889 redisplay_internal is called. */
11892 mark_window_display_accurate_1 (w
, accurate_p
)
11896 if (BUFFERP (w
->buffer
))
11898 struct buffer
*b
= XBUFFER (w
->buffer
);
11901 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
11902 w
->last_overlay_modified
11903 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
11905 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
11909 b
->clip_changed
= 0;
11910 b
->prevent_redisplay_optimizations_p
= 0;
11912 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
11913 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
11914 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
11915 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
11917 w
->current_matrix
->buffer
= b
;
11918 w
->current_matrix
->begv
= BUF_BEGV (b
);
11919 w
->current_matrix
->zv
= BUF_ZV (b
);
11921 w
->last_cursor
= w
->cursor
;
11922 w
->last_cursor_off_p
= w
->cursor_off_p
;
11924 if (w
== XWINDOW (selected_window
))
11925 w
->last_point
= make_number (BUF_PT (b
));
11927 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
11933 w
->window_end_valid
= w
->buffer
;
11934 #if 0 /* This is incorrect with variable-height lines. */
11935 xassert (XINT (w
->window_end_vpos
)
11936 < (WINDOW_TOTAL_LINES (w
)
11937 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
11939 w
->update_mode_line
= Qnil
;
11944 /* Mark the display of windows in the window tree rooted at WINDOW as
11945 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
11946 windows as accurate. If ACCURATE_P is zero, arrange for windows to
11947 be redisplayed the next time redisplay_internal is called. */
11950 mark_window_display_accurate (window
, accurate_p
)
11951 Lisp_Object window
;
11956 for (; !NILP (window
); window
= w
->next
)
11958 w
= XWINDOW (window
);
11959 mark_window_display_accurate_1 (w
, accurate_p
);
11961 if (!NILP (w
->vchild
))
11962 mark_window_display_accurate (w
->vchild
, accurate_p
);
11963 if (!NILP (w
->hchild
))
11964 mark_window_display_accurate (w
->hchild
, accurate_p
);
11969 update_overlay_arrows (1);
11973 /* Force a thorough redisplay the next time by setting
11974 last_arrow_position and last_arrow_string to t, which is
11975 unequal to any useful value of Voverlay_arrow_... */
11976 update_overlay_arrows (-1);
11981 /* Return value in display table DP (Lisp_Char_Table *) for character
11982 C. Since a display table doesn't have any parent, we don't have to
11983 follow parent. Do not call this function directly but use the
11984 macro DISP_CHAR_VECTOR. */
11987 disp_char_vector (dp
, c
)
11988 struct Lisp_Char_Table
*dp
;
11993 if (ASCII_CHAR_P (c
))
11996 if (SUB_CHAR_TABLE_P (val
))
11997 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12003 XSETCHAR_TABLE (table
, dp
);
12004 val
= char_table_ref (table
, c
);
12013 /***********************************************************************
12015 ***********************************************************************/
12017 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12020 redisplay_windows (window
)
12021 Lisp_Object window
;
12023 while (!NILP (window
))
12025 struct window
*w
= XWINDOW (window
);
12027 if (!NILP (w
->hchild
))
12028 redisplay_windows (w
->hchild
);
12029 else if (!NILP (w
->vchild
))
12030 redisplay_windows (w
->vchild
);
12033 displayed_buffer
= XBUFFER (w
->buffer
);
12034 /* Use list_of_error, not Qerror, so that
12035 we catch only errors and don't run the debugger. */
12036 internal_condition_case_1 (redisplay_window_0
, window
,
12038 redisplay_window_error
);
12046 redisplay_window_error ()
12048 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12053 redisplay_window_0 (window
)
12054 Lisp_Object window
;
12056 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12057 redisplay_window (window
, 0);
12062 redisplay_window_1 (window
)
12063 Lisp_Object window
;
12065 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12066 redisplay_window (window
, 1);
12071 /* Increment GLYPH until it reaches END or CONDITION fails while
12072 adding (GLYPH)->pixel_width to X. */
12074 #define SKIP_GLYPHS(glyph, end, x, condition) \
12077 (x) += (glyph)->pixel_width; \
12080 while ((glyph) < (end) && (condition))
12083 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12084 DELTA is the number of bytes by which positions recorded in ROW
12085 differ from current buffer positions.
12087 Return 0 if cursor is not on this row. 1 otherwise. */
12090 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
12092 struct glyph_row
*row
;
12093 struct glyph_matrix
*matrix
;
12094 int delta
, delta_bytes
, dy
, dvpos
;
12096 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12097 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12098 struct glyph
*cursor
= NULL
;
12099 /* The first glyph that starts a sequence of glyphs from string. */
12100 struct glyph
*string_start
;
12101 /* The X coordinate of string_start. */
12102 int string_start_x
;
12103 /* The last known character position. */
12104 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12105 /* The last known character position before string_start. */
12106 int string_before_pos
;
12109 int cursor_from_overlay_pos
= 0;
12110 int pt_old
= PT
- delta
;
12112 /* Skip over glyphs not having an object at the start of the row.
12113 These are special glyphs like truncation marks on terminal
12115 if (row
->displays_text_p
)
12117 && INTEGERP (glyph
->object
)
12118 && glyph
->charpos
< 0)
12120 x
+= glyph
->pixel_width
;
12124 string_start
= NULL
;
12126 && !INTEGERP (glyph
->object
)
12127 && (!BUFFERP (glyph
->object
)
12128 || (last_pos
= glyph
->charpos
) < pt_old
))
12130 if (! STRINGP (glyph
->object
))
12132 string_start
= NULL
;
12133 x
+= glyph
->pixel_width
;
12135 if (cursor_from_overlay_pos
12136 && last_pos
>= cursor_from_overlay_pos
)
12138 cursor_from_overlay_pos
= 0;
12144 if (string_start
== NULL
)
12146 string_before_pos
= last_pos
;
12147 string_start
= glyph
;
12148 string_start_x
= x
;
12150 /* Skip all glyphs from string. */
12155 if ((cursor
== NULL
|| glyph
> cursor
)
12156 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
12157 Qcursor
, (glyph
)->object
),
12159 && (pos
= string_buffer_position (w
, glyph
->object
,
12160 string_before_pos
),
12161 (pos
== 0 /* From overlay */
12162 || pos
== pt_old
)))
12164 /* Estimate overlay buffer position from the buffer
12165 positions of the glyphs before and after the overlay.
12166 Add 1 to last_pos so that if point corresponds to the
12167 glyph right after the overlay, we still use a 'cursor'
12168 property found in that overlay. */
12169 cursor_from_overlay_pos
= (pos
? 0 : last_pos
12170 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
12174 x
+= glyph
->pixel_width
;
12177 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
12181 if (cursor
!= NULL
)
12186 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
12188 /* Scan back over the ellipsis glyphs, decrementing positions. */
12189 while (glyph
> row
->glyphs
[TEXT_AREA
]
12190 && (glyph
- 1)->charpos
== last_pos
)
12191 glyph
--, x
-= glyph
->pixel_width
;
12192 /* That loop always goes one position too far,
12193 including the glyph before the ellipsis.
12194 So scan forward over that one. */
12195 x
+= glyph
->pixel_width
;
12198 else if (string_start
12199 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
12201 /* We may have skipped over point because the previous glyphs
12202 are from string. As there's no easy way to know the
12203 character position of the current glyph, find the correct
12204 glyph on point by scanning from string_start again. */
12206 Lisp_Object string
;
12207 struct glyph
*stop
= glyph
;
12210 limit
= make_number (pt_old
+ 1);
12211 glyph
= string_start
;
12212 x
= string_start_x
;
12213 string
= glyph
->object
;
12214 pos
= string_buffer_position (w
, string
, string_before_pos
);
12215 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
12216 because we always put cursor after overlay strings. */
12217 while (pos
== 0 && glyph
< stop
)
12219 string
= glyph
->object
;
12220 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12222 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
12225 while (glyph
< stop
)
12227 pos
= XINT (Fnext_single_char_property_change
12228 (make_number (pos
), Qdisplay
, Qnil
, limit
));
12231 /* Skip glyphs from the same string. */
12232 string
= glyph
->object
;
12233 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12234 /* Skip glyphs from an overlay. */
12235 while (glyph
< stop
12236 && ! string_buffer_position (w
, glyph
->object
, pos
))
12238 string
= glyph
->object
;
12239 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12243 /* If we reached the end of the line, and end was from a string,
12244 cursor is not on this line. */
12245 if (glyph
== end
&& row
->continued_p
)
12249 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12251 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12252 w
->cursor
.y
= row
->y
+ dy
;
12254 if (w
== XWINDOW (selected_window
))
12256 if (!row
->continued_p
12257 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12260 this_line_buffer
= XBUFFER (w
->buffer
);
12262 CHARPOS (this_line_start_pos
)
12263 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12264 BYTEPOS (this_line_start_pos
)
12265 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12267 CHARPOS (this_line_end_pos
)
12268 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12269 BYTEPOS (this_line_end_pos
)
12270 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12272 this_line_y
= w
->cursor
.y
;
12273 this_line_pixel_height
= row
->height
;
12274 this_line_vpos
= w
->cursor
.vpos
;
12275 this_line_start_x
= row
->x
;
12278 CHARPOS (this_line_start_pos
) = 0;
12285 /* Run window scroll functions, if any, for WINDOW with new window
12286 start STARTP. Sets the window start of WINDOW to that position.
12288 We assume that the window's buffer is really current. */
12290 static INLINE
struct text_pos
12291 run_window_scroll_functions (window
, startp
)
12292 Lisp_Object window
;
12293 struct text_pos startp
;
12295 struct window
*w
= XWINDOW (window
);
12296 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12298 if (current_buffer
!= XBUFFER (w
->buffer
))
12301 if (!NILP (Vwindow_scroll_functions
))
12303 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12304 make_number (CHARPOS (startp
)));
12305 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12306 /* In case the hook functions switch buffers. */
12307 if (current_buffer
!= XBUFFER (w
->buffer
))
12308 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12315 /* Make sure the line containing the cursor is fully visible.
12316 A value of 1 means there is nothing to be done.
12317 (Either the line is fully visible, or it cannot be made so,
12318 or we cannot tell.)
12320 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12321 is higher than window.
12323 A value of 0 means the caller should do scrolling
12324 as if point had gone off the screen. */
12327 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12330 int current_matrix_p
;
12332 struct glyph_matrix
*matrix
;
12333 struct glyph_row
*row
;
12336 if (!make_cursor_line_fully_visible_p
)
12339 /* It's not always possible to find the cursor, e.g, when a window
12340 is full of overlay strings. Don't do anything in that case. */
12341 if (w
->cursor
.vpos
< 0)
12344 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12345 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12347 /* If the cursor row is not partially visible, there's nothing to do. */
12348 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12351 /* If the row the cursor is in is taller than the window's height,
12352 it's not clear what to do, so do nothing. */
12353 window_height
= window_box_height (w
);
12354 if (row
->height
>= window_height
)
12356 if (!force_p
|| MINI_WINDOW_P (w
)
12357 || w
->vscroll
|| w
->cursor
.vpos
== 0)
12363 /* This code used to try to scroll the window just enough to make
12364 the line visible. It returned 0 to say that the caller should
12365 allocate larger glyph matrices. */
12367 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
12369 int dy
= row
->height
- row
->visible_height
;
12372 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12374 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
12376 int dy
= - (row
->height
- row
->visible_height
);
12379 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12382 /* When we change the cursor y-position of the selected window,
12383 change this_line_y as well so that the display optimization for
12384 the cursor line of the selected window in redisplay_internal uses
12385 the correct y-position. */
12386 if (w
== XWINDOW (selected_window
))
12387 this_line_y
= w
->cursor
.y
;
12389 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
12390 redisplay with larger matrices. */
12391 if (matrix
->nrows
< required_matrix_height (w
))
12393 fonts_changed_p
= 1;
12402 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
12403 non-zero means only WINDOW is redisplayed in redisplay_internal.
12404 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
12405 in redisplay_window to bring a partially visible line into view in
12406 the case that only the cursor has moved.
12408 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
12409 last screen line's vertical height extends past the end of the screen.
12413 1 if scrolling succeeded
12415 0 if scrolling didn't find point.
12417 -1 if new fonts have been loaded so that we must interrupt
12418 redisplay, adjust glyph matrices, and try again. */
12424 SCROLLING_NEED_LARGER_MATRICES
12428 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
12429 scroll_step
, temp_scroll_step
, last_line_misfit
)
12430 Lisp_Object window
;
12431 int just_this_one_p
;
12432 EMACS_INT scroll_conservatively
, scroll_step
;
12433 int temp_scroll_step
;
12434 int last_line_misfit
;
12436 struct window
*w
= XWINDOW (window
);
12437 struct frame
*f
= XFRAME (w
->frame
);
12438 struct text_pos scroll_margin_pos
;
12439 struct text_pos pos
;
12440 struct text_pos startp
;
12442 Lisp_Object window_end
;
12443 int this_scroll_margin
;
12447 int amount_to_scroll
= 0;
12448 Lisp_Object aggressive
;
12450 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
12453 debug_method_add (w
, "try_scrolling");
12456 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12458 /* Compute scroll margin height in pixels. We scroll when point is
12459 within this distance from the top or bottom of the window. */
12460 if (scroll_margin
> 0)
12462 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12463 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12466 this_scroll_margin
= 0;
12468 /* Force scroll_conservatively to have a reasonable value so it doesn't
12469 cause an overflow while computing how much to scroll. */
12470 if (scroll_conservatively
)
12471 scroll_conservatively
= min (scroll_conservatively
,
12472 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
12474 /* Compute how much we should try to scroll maximally to bring point
12476 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
12477 scroll_max
= max (scroll_step
,
12478 max (scroll_conservatively
, temp_scroll_step
));
12479 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
12480 || NUMBERP (current_buffer
->scroll_up_aggressively
))
12481 /* We're trying to scroll because of aggressive scrolling
12482 but no scroll_step is set. Choose an arbitrary one. Maybe
12483 there should be a variable for this. */
12487 scroll_max
*= FRAME_LINE_HEIGHT (f
);
12489 /* Decide whether we have to scroll down. Start at the window end
12490 and move this_scroll_margin up to find the position of the scroll
12492 window_end
= Fwindow_end (window
, Qt
);
12496 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
12497 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
12499 if (this_scroll_margin
|| extra_scroll_margin_lines
)
12501 start_display (&it
, w
, scroll_margin_pos
);
12502 if (this_scroll_margin
)
12503 move_it_vertically_backward (&it
, this_scroll_margin
);
12504 if (extra_scroll_margin_lines
)
12505 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
12506 scroll_margin_pos
= it
.current
.pos
;
12509 if (PT
>= CHARPOS (scroll_margin_pos
))
12513 /* Point is in the scroll margin at the bottom of the window, or
12514 below. Compute a new window start that makes point visible. */
12516 /* Compute the distance from the scroll margin to PT.
12517 Give up if the distance is greater than scroll_max. */
12518 start_display (&it
, w
, scroll_margin_pos
);
12520 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12521 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12523 /* To make point visible, we have to move the window start
12524 down so that the line the cursor is in is visible, which
12525 means we have to add in the height of the cursor line. */
12526 dy
= line_bottom_y (&it
) - y0
;
12528 if (dy
> scroll_max
)
12529 return SCROLLING_FAILED
;
12531 /* Move the window start down. If scrolling conservatively,
12532 move it just enough down to make point visible. If
12533 scroll_step is set, move it down by scroll_step. */
12534 start_display (&it
, w
, startp
);
12536 if (scroll_conservatively
)
12537 /* Set AMOUNT_TO_SCROLL to at least one line,
12538 and at most scroll_conservatively lines. */
12540 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12541 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12542 else if (scroll_step
|| temp_scroll_step
)
12543 amount_to_scroll
= scroll_max
;
12546 aggressive
= current_buffer
->scroll_up_aggressively
;
12547 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12548 if (NUMBERP (aggressive
))
12550 double float_amount
= XFLOATINT (aggressive
) * height
;
12551 amount_to_scroll
= float_amount
;
12552 if (amount_to_scroll
== 0 && float_amount
> 0)
12553 amount_to_scroll
= 1;
12557 if (amount_to_scroll
<= 0)
12558 return SCROLLING_FAILED
;
12560 /* If moving by amount_to_scroll leaves STARTP unchanged,
12561 move it down one screen line. */
12563 move_it_vertically (&it
, amount_to_scroll
);
12564 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12565 move_it_by_lines (&it
, 1, 1);
12566 startp
= it
.current
.pos
;
12570 /* See if point is inside the scroll margin at the top of the
12572 scroll_margin_pos
= startp
;
12573 if (this_scroll_margin
)
12575 start_display (&it
, w
, startp
);
12576 move_it_vertically (&it
, this_scroll_margin
);
12577 scroll_margin_pos
= it
.current
.pos
;
12580 if (PT
< CHARPOS (scroll_margin_pos
))
12582 /* Point is in the scroll margin at the top of the window or
12583 above what is displayed in the window. */
12586 /* Compute the vertical distance from PT to the scroll
12587 margin position. Give up if distance is greater than
12589 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12590 start_display (&it
, w
, pos
);
12592 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12593 it
.last_visible_y
, -1,
12594 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12595 dy
= it
.current_y
- y0
;
12596 if (dy
> scroll_max
)
12597 return SCROLLING_FAILED
;
12599 /* Compute new window start. */
12600 start_display (&it
, w
, startp
);
12602 if (scroll_conservatively
)
12604 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12605 else if (scroll_step
|| temp_scroll_step
)
12606 amount_to_scroll
= scroll_max
;
12609 aggressive
= current_buffer
->scroll_down_aggressively
;
12610 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12611 if (NUMBERP (aggressive
))
12613 double float_amount
= XFLOATINT (aggressive
) * height
;
12614 amount_to_scroll
= float_amount
;
12615 if (amount_to_scroll
== 0 && float_amount
> 0)
12616 amount_to_scroll
= 1;
12620 if (amount_to_scroll
<= 0)
12621 return SCROLLING_FAILED
;
12623 move_it_vertically_backward (&it
, amount_to_scroll
);
12624 startp
= it
.current
.pos
;
12628 /* Run window scroll functions. */
12629 startp
= run_window_scroll_functions (window
, startp
);
12631 /* Display the window. Give up if new fonts are loaded, or if point
12633 if (!try_window (window
, startp
, 0))
12634 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12635 else if (w
->cursor
.vpos
< 0)
12637 clear_glyph_matrix (w
->desired_matrix
);
12638 rc
= SCROLLING_FAILED
;
12642 /* Maybe forget recorded base line for line number display. */
12643 if (!just_this_one_p
12644 || current_buffer
->clip_changed
12645 || BEG_UNCHANGED
< CHARPOS (startp
))
12646 w
->base_line_number
= Qnil
;
12648 /* If cursor ends up on a partially visible line,
12649 treat that as being off the bottom of the screen. */
12650 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12652 clear_glyph_matrix (w
->desired_matrix
);
12653 ++extra_scroll_margin_lines
;
12656 rc
= SCROLLING_SUCCESS
;
12663 /* Compute a suitable window start for window W if display of W starts
12664 on a continuation line. Value is non-zero if a new window start
12667 The new window start will be computed, based on W's width, starting
12668 from the start of the continued line. It is the start of the
12669 screen line with the minimum distance from the old start W->start. */
12672 compute_window_start_on_continuation_line (w
)
12675 struct text_pos pos
, start_pos
;
12676 int window_start_changed_p
= 0;
12678 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12680 /* If window start is on a continuation line... Window start may be
12681 < BEGV in case there's invisible text at the start of the
12682 buffer (M-x rmail, for example). */
12683 if (CHARPOS (start_pos
) > BEGV
12684 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12687 struct glyph_row
*row
;
12689 /* Handle the case that the window start is out of range. */
12690 if (CHARPOS (start_pos
) < BEGV
)
12691 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12692 else if (CHARPOS (start_pos
) > ZV
)
12693 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12695 /* Find the start of the continued line. This should be fast
12696 because scan_buffer is fast (newline cache). */
12697 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12698 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12699 row
, DEFAULT_FACE_ID
);
12700 reseat_at_previous_visible_line_start (&it
);
12702 /* If the line start is "too far" away from the window start,
12703 say it takes too much time to compute a new window start. */
12704 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12705 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12707 int min_distance
, distance
;
12709 /* Move forward by display lines to find the new window
12710 start. If window width was enlarged, the new start can
12711 be expected to be > the old start. If window width was
12712 decreased, the new window start will be < the old start.
12713 So, we're looking for the display line start with the
12714 minimum distance from the old window start. */
12715 pos
= it
.current
.pos
;
12716 min_distance
= INFINITY
;
12717 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12718 distance
< min_distance
)
12720 min_distance
= distance
;
12721 pos
= it
.current
.pos
;
12722 move_it_by_lines (&it
, 1, 0);
12725 /* Set the window start there. */
12726 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12727 window_start_changed_p
= 1;
12731 return window_start_changed_p
;
12735 /* Try cursor movement in case text has not changed in window WINDOW,
12736 with window start STARTP. Value is
12738 CURSOR_MOVEMENT_SUCCESS if successful
12740 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12742 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12743 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12744 we want to scroll as if scroll-step were set to 1. See the code.
12746 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12747 which case we have to abort this redisplay, and adjust matrices
12752 CURSOR_MOVEMENT_SUCCESS
,
12753 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12754 CURSOR_MOVEMENT_MUST_SCROLL
,
12755 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12759 try_cursor_movement (window
, startp
, scroll_step
)
12760 Lisp_Object window
;
12761 struct text_pos startp
;
12764 struct window
*w
= XWINDOW (window
);
12765 struct frame
*f
= XFRAME (w
->frame
);
12766 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12769 if (inhibit_try_cursor_movement
)
12773 /* Handle case where text has not changed, only point, and it has
12774 not moved off the frame. */
12775 if (/* Point may be in this window. */
12776 PT
>= CHARPOS (startp
)
12777 /* Selective display hasn't changed. */
12778 && !current_buffer
->clip_changed
12779 /* Function force-mode-line-update is used to force a thorough
12780 redisplay. It sets either windows_or_buffers_changed or
12781 update_mode_lines. So don't take a shortcut here for these
12783 && !update_mode_lines
12784 && !windows_or_buffers_changed
12785 && !cursor_type_changed
12786 /* Can't use this case if highlighting a region. When a
12787 region exists, cursor movement has to do more than just
12789 && !(!NILP (Vtransient_mark_mode
)
12790 && !NILP (current_buffer
->mark_active
))
12791 && NILP (w
->region_showing
)
12792 && NILP (Vshow_trailing_whitespace
)
12793 /* Right after splitting windows, last_point may be nil. */
12794 && INTEGERP (w
->last_point
)
12795 /* This code is not used for mini-buffer for the sake of the case
12796 of redisplaying to replace an echo area message; since in
12797 that case the mini-buffer contents per se are usually
12798 unchanged. This code is of no real use in the mini-buffer
12799 since the handling of this_line_start_pos, etc., in redisplay
12800 handles the same cases. */
12801 && !EQ (window
, minibuf_window
)
12802 /* When splitting windows or for new windows, it happens that
12803 redisplay is called with a nil window_end_vpos or one being
12804 larger than the window. This should really be fixed in
12805 window.c. I don't have this on my list, now, so we do
12806 approximately the same as the old redisplay code. --gerd. */
12807 && INTEGERP (w
->window_end_vpos
)
12808 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12809 && (FRAME_WINDOW_P (f
)
12810 || !overlay_arrow_in_current_buffer_p ()))
12812 int this_scroll_margin
, top_scroll_margin
;
12813 struct glyph_row
*row
= NULL
;
12816 debug_method_add (w
, "cursor movement");
12819 /* Scroll if point within this distance from the top or bottom
12820 of the window. This is a pixel value. */
12821 this_scroll_margin
= max (0, scroll_margin
);
12822 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12823 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12825 top_scroll_margin
= this_scroll_margin
;
12826 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12827 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12829 /* Start with the row the cursor was displayed during the last
12830 not paused redisplay. Give up if that row is not valid. */
12831 if (w
->last_cursor
.vpos
< 0
12832 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12833 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12836 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12837 if (row
->mode_line_p
)
12839 if (!row
->enabled_p
)
12840 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12843 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12846 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12848 if (PT
> XFASTINT (w
->last_point
))
12850 /* Point has moved forward. */
12851 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12852 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12854 xassert (row
->enabled_p
);
12858 /* The end position of a row equals the start position
12859 of the next row. If PT is there, we would rather
12860 display it in the next line. */
12861 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12862 && MATRIX_ROW_END_CHARPOS (row
) == PT
12863 && !cursor_row_p (w
, row
))
12866 /* If within the scroll margin, scroll. Note that
12867 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
12868 the next line would be drawn, and that
12869 this_scroll_margin can be zero. */
12870 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
12871 || PT
> MATRIX_ROW_END_CHARPOS (row
)
12872 /* Line is completely visible last line in window
12873 and PT is to be set in the next line. */
12874 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
12875 && PT
== MATRIX_ROW_END_CHARPOS (row
)
12876 && !row
->ends_at_zv_p
12877 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12880 else if (PT
< XFASTINT (w
->last_point
))
12882 /* Cursor has to be moved backward. Note that PT >=
12883 CHARPOS (startp) because of the outer if-statement. */
12884 while (!row
->mode_line_p
12885 && (MATRIX_ROW_START_CHARPOS (row
) > PT
12886 || (MATRIX_ROW_START_CHARPOS (row
) == PT
12887 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
12888 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
12889 row
> w
->current_matrix
->rows
12890 && (row
-1)->ends_in_newline_from_string_p
))))
12891 && (row
->y
> top_scroll_margin
12892 || CHARPOS (startp
) == BEGV
))
12894 xassert (row
->enabled_p
);
12898 /* Consider the following case: Window starts at BEGV,
12899 there is invisible, intangible text at BEGV, so that
12900 display starts at some point START > BEGV. It can
12901 happen that we are called with PT somewhere between
12902 BEGV and START. Try to handle that case. */
12903 if (row
< w
->current_matrix
->rows
12904 || row
->mode_line_p
)
12906 row
= w
->current_matrix
->rows
;
12907 if (row
->mode_line_p
)
12911 /* Due to newlines in overlay strings, we may have to
12912 skip forward over overlay strings. */
12913 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12914 && MATRIX_ROW_END_CHARPOS (row
) == PT
12915 && !cursor_row_p (w
, row
))
12918 /* If within the scroll margin, scroll. */
12919 if (row
->y
< top_scroll_margin
12920 && CHARPOS (startp
) != BEGV
)
12925 /* Cursor did not move. So don't scroll even if cursor line
12926 is partially visible, as it was so before. */
12927 rc
= CURSOR_MOVEMENT_SUCCESS
;
12930 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
12931 || PT
> MATRIX_ROW_END_CHARPOS (row
))
12933 /* if PT is not in the glyph row, give up. */
12934 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12936 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
12937 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
12938 && make_cursor_line_fully_visible_p
)
12940 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
12941 && !row
->ends_at_zv_p
12942 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12943 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12944 else if (row
->height
> window_box_height (w
))
12946 /* If we end up in a partially visible line, let's
12947 make it fully visible, except when it's taller
12948 than the window, in which case we can't do much
12951 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12955 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12956 if (!cursor_row_fully_visible_p (w
, 0, 1))
12957 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12959 rc
= CURSOR_MOVEMENT_SUCCESS
;
12963 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12968 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
12970 rc
= CURSOR_MOVEMENT_SUCCESS
;
12975 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12976 && MATRIX_ROW_START_CHARPOS (row
) == PT
12977 && cursor_row_p (w
, row
));
12986 set_vertical_scroll_bar (w
)
12989 int start
, end
, whole
;
12991 /* Calculate the start and end positions for the current window.
12992 At some point, it would be nice to choose between scrollbars
12993 which reflect the whole buffer size, with special markers
12994 indicating narrowing, and scrollbars which reflect only the
12997 Note that mini-buffers sometimes aren't displaying any text. */
12998 if (!MINI_WINDOW_P (w
)
12999 || (w
== XWINDOW (minibuf_window
)
13000 && NILP (echo_area_buffer
[0])))
13002 struct buffer
*buf
= XBUFFER (w
->buffer
);
13003 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13004 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13005 /* I don't think this is guaranteed to be right. For the
13006 moment, we'll pretend it is. */
13007 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13011 if (whole
< (end
- start
))
13012 whole
= end
- start
;
13015 start
= end
= whole
= 0;
13017 /* Indicate what this scroll bar ought to be displaying now. */
13018 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13019 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13020 (w
, end
- start
, whole
, start
);
13024 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13025 selected_window is redisplayed.
13027 We can return without actually redisplaying the window if
13028 fonts_changed_p is nonzero. In that case, redisplay_internal will
13032 redisplay_window (window
, just_this_one_p
)
13033 Lisp_Object window
;
13034 int just_this_one_p
;
13036 struct window
*w
= XWINDOW (window
);
13037 struct frame
*f
= XFRAME (w
->frame
);
13038 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13039 struct buffer
*old
= current_buffer
;
13040 struct text_pos lpoint
, opoint
, startp
;
13041 int update_mode_line
;
13044 /* Record it now because it's overwritten. */
13045 int current_matrix_up_to_date_p
= 0;
13046 int used_current_matrix_p
= 0;
13047 /* This is less strict than current_matrix_up_to_date_p.
13048 It indictes that the buffer contents and narrowing are unchanged. */
13049 int buffer_unchanged_p
= 0;
13050 int temp_scroll_step
= 0;
13051 int count
= SPECPDL_INDEX ();
13053 int centering_position
= -1;
13054 int last_line_misfit
= 0;
13055 int beg_unchanged
, end_unchanged
;
13057 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13060 /* W must be a leaf window here. */
13061 xassert (!NILP (w
->buffer
));
13063 *w
->desired_matrix
->method
= 0;
13067 reconsider_clip_changes (w
, buffer
);
13069 /* Has the mode line to be updated? */
13070 update_mode_line
= (!NILP (w
->update_mode_line
)
13071 || update_mode_lines
13072 || buffer
->clip_changed
13073 || buffer
->prevent_redisplay_optimizations_p
);
13075 if (MINI_WINDOW_P (w
))
13077 if (w
== XWINDOW (echo_area_window
)
13078 && !NILP (echo_area_buffer
[0]))
13080 if (update_mode_line
)
13081 /* We may have to update a tty frame's menu bar or a
13082 tool-bar. Example `M-x C-h C-h C-g'. */
13083 goto finish_menu_bars
;
13085 /* We've already displayed the echo area glyphs in this window. */
13086 goto finish_scroll_bars
;
13088 else if ((w
!= XWINDOW (minibuf_window
)
13089 || minibuf_level
== 0)
13090 /* When buffer is nonempty, redisplay window normally. */
13091 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13092 /* Quail displays non-mini buffers in minibuffer window.
13093 In that case, redisplay the window normally. */
13094 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13096 /* W is a mini-buffer window, but it's not active, so clear
13098 int yb
= window_text_bottom_y (w
);
13099 struct glyph_row
*row
;
13102 for (y
= 0, row
= w
->desired_matrix
->rows
;
13104 y
+= row
->height
, ++row
)
13105 blank_row (w
, row
, y
);
13106 goto finish_scroll_bars
;
13109 clear_glyph_matrix (w
->desired_matrix
);
13112 /* Otherwise set up data on this window; select its buffer and point
13114 /* Really select the buffer, for the sake of buffer-local
13116 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13118 current_matrix_up_to_date_p
13119 = (!NILP (w
->window_end_valid
)
13120 && !current_buffer
->clip_changed
13121 && !current_buffer
->prevent_redisplay_optimizations_p
13122 && XFASTINT (w
->last_modified
) >= MODIFF
13123 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13125 /* Run the window-bottom-change-functions
13126 if it is possible that the text on the screen has changed
13127 (either due to modification of the text, or any other reason). */
13128 if (!current_matrix_up_to_date_p
13129 && !NILP (Vwindow_text_change_functions
))
13131 safe_run_hooks (Qwindow_text_change_functions
);
13135 beg_unchanged
= BEG_UNCHANGED
;
13136 end_unchanged
= END_UNCHANGED
;
13138 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13140 specbind (Qinhibit_point_motion_hooks
, Qt
);
13143 = (!NILP (w
->window_end_valid
)
13144 && !current_buffer
->clip_changed
13145 && XFASTINT (w
->last_modified
) >= MODIFF
13146 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13148 /* When windows_or_buffers_changed is non-zero, we can't rely on
13149 the window end being valid, so set it to nil there. */
13150 if (windows_or_buffers_changed
)
13152 /* If window starts on a continuation line, maybe adjust the
13153 window start in case the window's width changed. */
13154 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13155 compute_window_start_on_continuation_line (w
);
13157 w
->window_end_valid
= Qnil
;
13160 /* Some sanity checks. */
13161 CHECK_WINDOW_END (w
);
13162 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
13164 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
13167 /* If %c is in mode line, update it if needed. */
13168 if (!NILP (w
->column_number_displayed
)
13169 /* This alternative quickly identifies a common case
13170 where no change is needed. */
13171 && !(PT
== XFASTINT (w
->last_point
)
13172 && XFASTINT (w
->last_modified
) >= MODIFF
13173 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
13174 && (XFASTINT (w
->column_number_displayed
)
13175 != (int) current_column ())) /* iftc */
13176 update_mode_line
= 1;
13178 /* Count number of windows showing the selected buffer. An indirect
13179 buffer counts as its base buffer. */
13180 if (!just_this_one_p
)
13182 struct buffer
*current_base
, *window_base
;
13183 current_base
= current_buffer
;
13184 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13185 if (current_base
->base_buffer
)
13186 current_base
= current_base
->base_buffer
;
13187 if (window_base
->base_buffer
)
13188 window_base
= window_base
->base_buffer
;
13189 if (current_base
== window_base
)
13193 /* Point refers normally to the selected window. For any other
13194 window, set up appropriate value. */
13195 if (!EQ (window
, selected_window
))
13197 int new_pt
= XMARKER (w
->pointm
)->charpos
;
13198 int new_pt_byte
= marker_byte_position (w
->pointm
);
13202 new_pt_byte
= BEGV_BYTE
;
13203 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13205 else if (new_pt
> (ZV
- 1))
13208 new_pt_byte
= ZV_BYTE
;
13209 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13212 /* We don't use SET_PT so that the point-motion hooks don't run. */
13213 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
13216 /* If any of the character widths specified in the display table
13217 have changed, invalidate the width run cache. It's true that
13218 this may be a bit late to catch such changes, but the rest of
13219 redisplay goes (non-fatally) haywire when the display table is
13220 changed, so why should we worry about doing any better? */
13221 if (current_buffer
->width_run_cache
)
13223 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
13225 if (! disptab_matches_widthtab (disptab
,
13226 XVECTOR (current_buffer
->width_table
)))
13228 invalidate_region_cache (current_buffer
,
13229 current_buffer
->width_run_cache
,
13231 recompute_width_table (current_buffer
, disptab
);
13235 /* If window-start is screwed up, choose a new one. */
13236 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
13239 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13241 /* If someone specified a new starting point but did not insist,
13242 check whether it can be used. */
13243 if (!NILP (w
->optional_new_start
)
13244 && CHARPOS (startp
) >= BEGV
13245 && CHARPOS (startp
) <= ZV
)
13247 w
->optional_new_start
= Qnil
;
13248 start_display (&it
, w
, startp
);
13249 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
13250 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13251 if (IT_CHARPOS (it
) == PT
)
13252 w
->force_start
= Qt
;
13253 /* IT may overshoot PT if text at PT is invisible. */
13254 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
13255 w
->force_start
= Qt
;
13260 /* Handle case where place to start displaying has been specified,
13261 unless the specified location is outside the accessible range. */
13262 if (!NILP (w
->force_start
)
13263 || w
->frozen_window_start_p
)
13265 /* We set this later on if we have to adjust point. */
13269 w
->force_start
= Qnil
;
13271 w
->window_end_valid
= Qnil
;
13273 /* Forget any recorded base line for line number display. */
13274 if (!buffer_unchanged_p
)
13275 w
->base_line_number
= Qnil
;
13277 /* Redisplay the mode line. Select the buffer properly for that.
13278 Also, run the hook window-scroll-functions
13279 because we have scrolled. */
13280 /* Note, we do this after clearing force_start because
13281 if there's an error, it is better to forget about force_start
13282 than to get into an infinite loop calling the hook functions
13283 and having them get more errors. */
13284 if (!update_mode_line
13285 || ! NILP (Vwindow_scroll_functions
))
13287 update_mode_line
= 1;
13288 w
->update_mode_line
= Qt
;
13289 startp
= run_window_scroll_functions (window
, startp
);
13292 w
->last_modified
= make_number (0);
13293 w
->last_overlay_modified
= make_number (0);
13294 if (CHARPOS (startp
) < BEGV
)
13295 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
13296 else if (CHARPOS (startp
) > ZV
)
13297 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
13299 /* Redisplay, then check if cursor has been set during the
13300 redisplay. Give up if new fonts were loaded. */
13301 val
= try_window (window
, startp
, 1);
13304 w
->force_start
= Qt
;
13305 clear_glyph_matrix (w
->desired_matrix
);
13306 goto need_larger_matrices
;
13308 /* Point was outside the scroll margins. */
13310 new_vpos
= window_box_height (w
) / 2;
13312 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
13314 /* If point does not appear, try to move point so it does
13315 appear. The desired matrix has been built above, so we
13316 can use it here. */
13317 new_vpos
= window_box_height (w
) / 2;
13320 if (!cursor_row_fully_visible_p (w
, 0, 0))
13322 /* Point does appear, but on a line partly visible at end of window.
13323 Move it back to a fully-visible line. */
13324 new_vpos
= window_box_height (w
);
13327 /* If we need to move point for either of the above reasons,
13328 now actually do it. */
13331 struct glyph_row
*row
;
13333 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13334 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13337 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13338 MATRIX_ROW_START_BYTEPOS (row
));
13340 if (w
!= XWINDOW (selected_window
))
13341 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13342 else if (current_buffer
== old
)
13343 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13345 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13347 /* If we are highlighting the region, then we just changed
13348 the region, so redisplay to show it. */
13349 if (!NILP (Vtransient_mark_mode
)
13350 && !NILP (current_buffer
->mark_active
))
13352 clear_glyph_matrix (w
->desired_matrix
);
13353 if (!try_window (window
, startp
, 0))
13354 goto need_larger_matrices
;
13359 debug_method_add (w
, "forced window start");
13364 /* Handle case where text has not changed, only point, and it has
13365 not moved off the frame, and we are not retrying after hscroll.
13366 (current_matrix_up_to_date_p is nonzero when retrying.) */
13367 if (current_matrix_up_to_date_p
13368 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13369 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13373 case CURSOR_MOVEMENT_SUCCESS
:
13374 used_current_matrix_p
= 1;
13377 #if 0 /* try_cursor_movement never returns this value. */
13378 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
13379 goto need_larger_matrices
;
13382 case CURSOR_MOVEMENT_MUST_SCROLL
:
13383 goto try_to_scroll
;
13389 /* If current starting point was originally the beginning of a line
13390 but no longer is, find a new starting point. */
13391 else if (!NILP (w
->start_at_line_beg
)
13392 && !(CHARPOS (startp
) <= BEGV
13393 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13396 debug_method_add (w
, "recenter 1");
13401 /* Try scrolling with try_window_id. Value is > 0 if update has
13402 been done, it is -1 if we know that the same window start will
13403 not work. It is 0 if unsuccessful for some other reason. */
13404 else if ((tem
= try_window_id (w
)) != 0)
13407 debug_method_add (w
, "try_window_id %d", tem
);
13410 if (fonts_changed_p
)
13411 goto need_larger_matrices
;
13415 /* Otherwise try_window_id has returned -1 which means that we
13416 don't want the alternative below this comment to execute. */
13418 else if (CHARPOS (startp
) >= BEGV
13419 && CHARPOS (startp
) <= ZV
13420 && PT
>= CHARPOS (startp
)
13421 && (CHARPOS (startp
) < ZV
13422 /* Avoid starting at end of buffer. */
13423 || CHARPOS (startp
) == BEGV
13424 || (XFASTINT (w
->last_modified
) >= MODIFF
13425 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
13428 /* If first window line is a continuation line, and window start
13429 is inside the modified region, but the first change is before
13430 current window start, we must select a new window start.
13432 However, if this is the result of a down-mouse event (e.g. by
13433 extending the mouse-drag-overlay), we don't want to select a
13434 new window start, since that would change the position under
13435 the mouse, resulting in an unwanted mouse-movement rather
13436 than a simple mouse-click. */
13437 if (NILP (w
->start_at_line_beg
)
13438 && NILP (do_mouse_tracking
)
13439 && CHARPOS (startp
) > BEGV
13440 && CHARPOS (startp
) > BEG
+ beg_unchanged
13441 && CHARPOS (startp
) <= Z
- end_unchanged
)
13443 w
->force_start
= Qt
;
13444 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13445 compute_window_start_on_continuation_line (w
);
13446 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13451 debug_method_add (w
, "same window start");
13454 /* Try to redisplay starting at same place as before.
13455 If point has not moved off frame, accept the results. */
13456 if (!current_matrix_up_to_date_p
13457 /* Don't use try_window_reusing_current_matrix in this case
13458 because a window scroll function can have changed the
13460 || !NILP (Vwindow_scroll_functions
)
13461 || MINI_WINDOW_P (w
)
13462 || !(used_current_matrix_p
13463 = try_window_reusing_current_matrix (w
)))
13465 IF_DEBUG (debug_method_add (w
, "1"));
13466 if (try_window (window
, startp
, 1) < 0)
13467 /* -1 means we need to scroll.
13468 0 means we need new matrices, but fonts_changed_p
13469 is set in that case, so we will detect it below. */
13470 goto try_to_scroll
;
13473 if (fonts_changed_p
)
13474 goto need_larger_matrices
;
13476 if (w
->cursor
.vpos
>= 0)
13478 if (!just_this_one_p
13479 || current_buffer
->clip_changed
13480 || BEG_UNCHANGED
< CHARPOS (startp
))
13481 /* Forget any recorded base line for line number display. */
13482 w
->base_line_number
= Qnil
;
13484 if (!cursor_row_fully_visible_p (w
, 1, 0))
13486 clear_glyph_matrix (w
->desired_matrix
);
13487 last_line_misfit
= 1;
13489 /* Drop through and scroll. */
13494 clear_glyph_matrix (w
->desired_matrix
);
13499 w
->last_modified
= make_number (0);
13500 w
->last_overlay_modified
= make_number (0);
13502 /* Redisplay the mode line. Select the buffer properly for that. */
13503 if (!update_mode_line
)
13505 update_mode_line
= 1;
13506 w
->update_mode_line
= Qt
;
13509 /* Try to scroll by specified few lines. */
13510 if ((scroll_conservatively
13512 || temp_scroll_step
13513 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13514 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13515 && !current_buffer
->clip_changed
13516 && CHARPOS (startp
) >= BEGV
13517 && CHARPOS (startp
) <= ZV
)
13519 /* The function returns -1 if new fonts were loaded, 1 if
13520 successful, 0 if not successful. */
13521 int rc
= try_scrolling (window
, just_this_one_p
,
13522 scroll_conservatively
,
13524 temp_scroll_step
, last_line_misfit
);
13527 case SCROLLING_SUCCESS
:
13530 case SCROLLING_NEED_LARGER_MATRICES
:
13531 goto need_larger_matrices
;
13533 case SCROLLING_FAILED
:
13541 /* Finally, just choose place to start which centers point */
13544 if (centering_position
< 0)
13545 centering_position
= window_box_height (w
) / 2;
13548 debug_method_add (w
, "recenter");
13551 /* w->vscroll = 0; */
13553 /* Forget any previously recorded base line for line number display. */
13554 if (!buffer_unchanged_p
)
13555 w
->base_line_number
= Qnil
;
13557 /* Move backward half the height of the window. */
13558 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13559 it
.current_y
= it
.last_visible_y
;
13560 move_it_vertically_backward (&it
, centering_position
);
13561 xassert (IT_CHARPOS (it
) >= BEGV
);
13563 /* The function move_it_vertically_backward may move over more
13564 than the specified y-distance. If it->w is small, e.g. a
13565 mini-buffer window, we may end up in front of the window's
13566 display area. Start displaying at the start of the line
13567 containing PT in this case. */
13568 if (it
.current_y
<= 0)
13570 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13571 move_it_vertically_backward (&it
, 0);
13573 /* I think this assert is bogus if buffer contains
13574 invisible text or images. KFS. */
13575 xassert (IT_CHARPOS (it
) <= PT
);
13580 it
.current_x
= it
.hpos
= 0;
13582 /* Set startp here explicitly in case that helps avoid an infinite loop
13583 in case the window-scroll-functions functions get errors. */
13584 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13586 /* Run scroll hooks. */
13587 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13589 /* Redisplay the window. */
13590 if (!current_matrix_up_to_date_p
13591 || windows_or_buffers_changed
13592 || cursor_type_changed
13593 /* Don't use try_window_reusing_current_matrix in this case
13594 because it can have changed the buffer. */
13595 || !NILP (Vwindow_scroll_functions
)
13596 || !just_this_one_p
13597 || MINI_WINDOW_P (w
)
13598 || !(used_current_matrix_p
13599 = try_window_reusing_current_matrix (w
)))
13600 try_window (window
, startp
, 0);
13602 /* If new fonts have been loaded (due to fontsets), give up. We
13603 have to start a new redisplay since we need to re-adjust glyph
13605 if (fonts_changed_p
)
13606 goto need_larger_matrices
;
13608 /* If cursor did not appear assume that the middle of the window is
13609 in the first line of the window. Do it again with the next line.
13610 (Imagine a window of height 100, displaying two lines of height
13611 60. Moving back 50 from it->last_visible_y will end in the first
13613 if (w
->cursor
.vpos
< 0)
13615 if (!NILP (w
->window_end_valid
)
13616 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13618 clear_glyph_matrix (w
->desired_matrix
);
13619 move_it_by_lines (&it
, 1, 0);
13620 try_window (window
, it
.current
.pos
, 0);
13622 else if (PT
< IT_CHARPOS (it
))
13624 clear_glyph_matrix (w
->desired_matrix
);
13625 move_it_by_lines (&it
, -1, 0);
13626 try_window (window
, it
.current
.pos
, 0);
13630 /* Not much we can do about it. */
13634 /* Consider the following case: Window starts at BEGV, there is
13635 invisible, intangible text at BEGV, so that display starts at
13636 some point START > BEGV. It can happen that we are called with
13637 PT somewhere between BEGV and START. Try to handle that case. */
13638 if (w
->cursor
.vpos
< 0)
13640 struct glyph_row
*row
= w
->current_matrix
->rows
;
13641 if (row
->mode_line_p
)
13643 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13646 if (!cursor_row_fully_visible_p (w
, 0, 0))
13648 /* If vscroll is enabled, disable it and try again. */
13652 clear_glyph_matrix (w
->desired_matrix
);
13656 /* If centering point failed to make the whole line visible,
13657 put point at the top instead. That has to make the whole line
13658 visible, if it can be done. */
13659 if (centering_position
== 0)
13662 clear_glyph_matrix (w
->desired_matrix
);
13663 centering_position
= 0;
13669 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13670 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13671 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13674 /* Display the mode line, if we must. */
13675 if ((update_mode_line
13676 /* If window not full width, must redo its mode line
13677 if (a) the window to its side is being redone and
13678 (b) we do a frame-based redisplay. This is a consequence
13679 of how inverted lines are drawn in frame-based redisplay. */
13680 || (!just_this_one_p
13681 && !FRAME_WINDOW_P (f
)
13682 && !WINDOW_FULL_WIDTH_P (w
))
13683 /* Line number to display. */
13684 || INTEGERP (w
->base_line_pos
)
13685 /* Column number is displayed and different from the one displayed. */
13686 || (!NILP (w
->column_number_displayed
)
13687 && (XFASTINT (w
->column_number_displayed
)
13688 != (int) current_column ()))) /* iftc */
13689 /* This means that the window has a mode line. */
13690 && (WINDOW_WANTS_MODELINE_P (w
)
13691 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13693 display_mode_lines (w
);
13695 /* If mode line height has changed, arrange for a thorough
13696 immediate redisplay using the correct mode line height. */
13697 if (WINDOW_WANTS_MODELINE_P (w
)
13698 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13700 fonts_changed_p
= 1;
13701 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13702 = DESIRED_MODE_LINE_HEIGHT (w
);
13705 /* If top line height has changed, arrange for a thorough
13706 immediate redisplay using the correct mode line height. */
13707 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13708 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13710 fonts_changed_p
= 1;
13711 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13712 = DESIRED_HEADER_LINE_HEIGHT (w
);
13715 if (fonts_changed_p
)
13716 goto need_larger_matrices
;
13719 if (!line_number_displayed
13720 && !BUFFERP (w
->base_line_pos
))
13722 w
->base_line_pos
= Qnil
;
13723 w
->base_line_number
= Qnil
;
13728 /* When we reach a frame's selected window, redo the frame's menu bar. */
13729 if (update_mode_line
13730 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13732 int redisplay_menu_p
= 0;
13733 int redisplay_tool_bar_p
= 0;
13735 if (FRAME_WINDOW_P (f
))
13737 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
13738 || defined (USE_GTK)
13739 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13741 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13745 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13747 if (redisplay_menu_p
)
13748 display_menu_bar (w
);
13750 #ifdef HAVE_WINDOW_SYSTEM
13751 if (FRAME_WINDOW_P (f
))
13753 #if defined (USE_GTK) || USE_MAC_TOOLBAR
13754 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13756 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13757 && (FRAME_TOOL_BAR_LINES (f
) > 0
13758 || !NILP (Vauto_resize_tool_bars
));
13761 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
13763 extern int ignore_mouse_drag_p
;
13764 ignore_mouse_drag_p
= 1;
13770 #ifdef HAVE_WINDOW_SYSTEM
13771 if (FRAME_WINDOW_P (f
)
13772 && update_window_fringes (w
, (just_this_one_p
13773 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13774 || w
->pseudo_window_p
)))
13778 if (draw_window_fringes (w
, 1))
13779 x_draw_vertical_border (w
);
13783 #endif /* HAVE_WINDOW_SYSTEM */
13785 /* We go to this label, with fonts_changed_p nonzero,
13786 if it is necessary to try again using larger glyph matrices.
13787 We have to redeem the scroll bar even in this case,
13788 because the loop in redisplay_internal expects that. */
13789 need_larger_matrices
:
13791 finish_scroll_bars
:
13793 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13795 /* Set the thumb's position and size. */
13796 set_vertical_scroll_bar (w
);
13798 /* Note that we actually used the scroll bar attached to this
13799 window, so it shouldn't be deleted at the end of redisplay. */
13800 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
13801 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
13804 /* Restore current_buffer and value of point in it. */
13805 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13806 set_buffer_internal_1 (old
);
13807 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
13808 shorter. This can be caused by log truncation in *Messages*. */
13809 if (CHARPOS (lpoint
) <= ZV
)
13810 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13812 unbind_to (count
, Qnil
);
13816 /* Build the complete desired matrix of WINDOW with a window start
13817 buffer position POS.
13819 Value is 1 if successful. It is zero if fonts were loaded during
13820 redisplay which makes re-adjusting glyph matrices necessary, and -1
13821 if point would appear in the scroll margins.
13822 (We check that only if CHECK_MARGINS is nonzero. */
13825 try_window (window
, pos
, check_margins
)
13826 Lisp_Object window
;
13827 struct text_pos pos
;
13830 struct window
*w
= XWINDOW (window
);
13832 struct glyph_row
*last_text_row
= NULL
;
13833 struct frame
*f
= XFRAME (w
->frame
);
13835 /* Make POS the new window start. */
13836 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13838 /* Mark cursor position as unknown. No overlay arrow seen. */
13839 w
->cursor
.vpos
= -1;
13840 overlay_arrow_seen
= 0;
13842 /* Initialize iterator and info to start at POS. */
13843 start_display (&it
, w
, pos
);
13845 /* Display all lines of W. */
13846 while (it
.current_y
< it
.last_visible_y
)
13848 if (display_line (&it
))
13849 last_text_row
= it
.glyph_row
- 1;
13850 if (fonts_changed_p
)
13854 /* Don't let the cursor end in the scroll margins. */
13856 && !MINI_WINDOW_P (w
))
13858 int this_scroll_margin
;
13860 this_scroll_margin
= max (0, scroll_margin
);
13861 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13862 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13864 if ((w
->cursor
.y
>= 0 /* not vscrolled */
13865 && w
->cursor
.y
< this_scroll_margin
13866 && CHARPOS (pos
) > BEGV
13867 && IT_CHARPOS (it
) < ZV
)
13868 /* rms: considering make_cursor_line_fully_visible_p here
13869 seems to give wrong results. We don't want to recenter
13870 when the last line is partly visible, we want to allow
13871 that case to be handled in the usual way. */
13872 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
13874 w
->cursor
.vpos
= -1;
13875 clear_glyph_matrix (w
->desired_matrix
);
13880 /* If bottom moved off end of frame, change mode line percentage. */
13881 if (XFASTINT (w
->window_end_pos
) <= 0
13882 && Z
!= IT_CHARPOS (it
))
13883 w
->update_mode_line
= Qt
;
13885 /* Set window_end_pos to the offset of the last character displayed
13886 on the window from the end of current_buffer. Set
13887 window_end_vpos to its row number. */
13890 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
13891 w
->window_end_bytepos
13892 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13894 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13896 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13897 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
13898 ->displays_text_p
);
13902 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13903 w
->window_end_pos
= make_number (Z
- ZV
);
13904 w
->window_end_vpos
= make_number (0);
13907 /* But that is not valid info until redisplay finishes. */
13908 w
->window_end_valid
= Qnil
;
13914 /************************************************************************
13915 Window redisplay reusing current matrix when buffer has not changed
13916 ************************************************************************/
13918 /* Try redisplay of window W showing an unchanged buffer with a
13919 different window start than the last time it was displayed by
13920 reusing its current matrix. Value is non-zero if successful.
13921 W->start is the new window start. */
13924 try_window_reusing_current_matrix (w
)
13927 struct frame
*f
= XFRAME (w
->frame
);
13928 struct glyph_row
*row
, *bottom_row
;
13931 struct text_pos start
, new_start
;
13932 int nrows_scrolled
, i
;
13933 struct glyph_row
*last_text_row
;
13934 struct glyph_row
*last_reused_text_row
;
13935 struct glyph_row
*start_row
;
13936 int start_vpos
, min_y
, max_y
;
13939 if (inhibit_try_window_reusing
)
13943 if (/* This function doesn't handle terminal frames. */
13944 !FRAME_WINDOW_P (f
)
13945 /* Don't try to reuse the display if windows have been split
13947 || windows_or_buffers_changed
13948 || cursor_type_changed
)
13951 /* Can't do this if region may have changed. */
13952 if ((!NILP (Vtransient_mark_mode
)
13953 && !NILP (current_buffer
->mark_active
))
13954 || !NILP (w
->region_showing
)
13955 || !NILP (Vshow_trailing_whitespace
))
13958 /* If top-line visibility has changed, give up. */
13959 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13960 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
13963 /* Give up if old or new display is scrolled vertically. We could
13964 make this function handle this, but right now it doesn't. */
13965 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13966 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
13969 /* The variable new_start now holds the new window start. The old
13970 start `start' can be determined from the current matrix. */
13971 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
13972 start
= start_row
->start
.pos
;
13973 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13975 /* Clear the desired matrix for the display below. */
13976 clear_glyph_matrix (w
->desired_matrix
);
13978 if (CHARPOS (new_start
) <= CHARPOS (start
))
13982 /* Don't use this method if the display starts with an ellipsis
13983 displayed for invisible text. It's not easy to handle that case
13984 below, and it's certainly not worth the effort since this is
13985 not a frequent case. */
13986 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
13989 IF_DEBUG (debug_method_add (w
, "twu1"));
13991 /* Display up to a row that can be reused. The variable
13992 last_text_row is set to the last row displayed that displays
13993 text. Note that it.vpos == 0 if or if not there is a
13994 header-line; it's not the same as the MATRIX_ROW_VPOS! */
13995 start_display (&it
, w
, new_start
);
13996 first_row_y
= it
.current_y
;
13997 w
->cursor
.vpos
= -1;
13998 last_text_row
= last_reused_text_row
= NULL
;
14000 while (it
.current_y
< it
.last_visible_y
14001 && !fonts_changed_p
)
14003 /* If we have reached into the characters in the START row,
14004 that means the line boundaries have changed. So we
14005 can't start copying with the row START. Maybe it will
14006 work to start copying with the following row. */
14007 while (IT_CHARPOS (it
) > CHARPOS (start
))
14009 /* Advance to the next row as the "start". */
14011 start
= start_row
->start
.pos
;
14012 /* If there are no more rows to try, or just one, give up. */
14013 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14014 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14015 || CHARPOS (start
) == ZV
)
14017 clear_glyph_matrix (w
->desired_matrix
);
14021 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14023 /* If we have reached alignment,
14024 we can copy the rest of the rows. */
14025 if (IT_CHARPOS (it
) == CHARPOS (start
))
14028 if (display_line (&it
))
14029 last_text_row
= it
.glyph_row
- 1;
14032 /* A value of current_y < last_visible_y means that we stopped
14033 at the previous window start, which in turn means that we
14034 have at least one reusable row. */
14035 if (it
.current_y
< it
.last_visible_y
)
14037 /* IT.vpos always starts from 0; it counts text lines. */
14038 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14040 /* Find PT if not already found in the lines displayed. */
14041 if (w
->cursor
.vpos
< 0)
14043 int dy
= it
.current_y
- start_row
->y
;
14045 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14046 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14048 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14049 dy
, nrows_scrolled
);
14052 clear_glyph_matrix (w
->desired_matrix
);
14057 /* Scroll the display. Do it before the current matrix is
14058 changed. The problem here is that update has not yet
14059 run, i.e. part of the current matrix is not up to date.
14060 scroll_run_hook will clear the cursor, and use the
14061 current matrix to get the height of the row the cursor is
14063 run
.current_y
= start_row
->y
;
14064 run
.desired_y
= it
.current_y
;
14065 run
.height
= it
.last_visible_y
- it
.current_y
;
14067 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14070 FRAME_RIF (f
)->update_window_begin_hook (w
);
14071 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14072 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14073 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14077 /* Shift current matrix down by nrows_scrolled lines. */
14078 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14079 rotate_matrix (w
->current_matrix
,
14081 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14084 /* Disable lines that must be updated. */
14085 for (i
= 0; i
< nrows_scrolled
; ++i
)
14086 (start_row
+ i
)->enabled_p
= 0;
14088 /* Re-compute Y positions. */
14089 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14090 max_y
= it
.last_visible_y
;
14091 for (row
= start_row
+ nrows_scrolled
;
14095 row
->y
= it
.current_y
;
14096 row
->visible_height
= row
->height
;
14098 if (row
->y
< min_y
)
14099 row
->visible_height
-= min_y
- row
->y
;
14100 if (row
->y
+ row
->height
> max_y
)
14101 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14102 row
->redraw_fringe_bitmaps_p
= 1;
14104 it
.current_y
+= row
->height
;
14106 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14107 last_reused_text_row
= row
;
14108 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14112 /* Disable lines in the current matrix which are now
14113 below the window. */
14114 for (++row
; row
< bottom_row
; ++row
)
14115 row
->enabled_p
= row
->mode_line_p
= 0;
14118 /* Update window_end_pos etc.; last_reused_text_row is the last
14119 reused row from the current matrix containing text, if any.
14120 The value of last_text_row is the last displayed line
14121 containing text. */
14122 if (last_reused_text_row
)
14124 w
->window_end_bytepos
14125 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14127 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14129 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14130 w
->current_matrix
));
14132 else if (last_text_row
)
14134 w
->window_end_bytepos
14135 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14137 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14139 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14143 /* This window must be completely empty. */
14144 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14145 w
->window_end_pos
= make_number (Z
- ZV
);
14146 w
->window_end_vpos
= make_number (0);
14148 w
->window_end_valid
= Qnil
;
14150 /* Update hint: don't try scrolling again in update_window. */
14151 w
->desired_matrix
->no_scrolling_p
= 1;
14154 debug_method_add (w
, "try_window_reusing_current_matrix 1");
14158 else if (CHARPOS (new_start
) > CHARPOS (start
))
14160 struct glyph_row
*pt_row
, *row
;
14161 struct glyph_row
*first_reusable_row
;
14162 struct glyph_row
*first_row_to_display
;
14164 int yb
= window_text_bottom_y (w
);
14166 /* Find the row starting at new_start, if there is one. Don't
14167 reuse a partially visible line at the end. */
14168 first_reusable_row
= start_row
;
14169 while (first_reusable_row
->enabled_p
14170 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
14171 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14172 < CHARPOS (new_start
)))
14173 ++first_reusable_row
;
14175 /* Give up if there is no row to reuse. */
14176 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
14177 || !first_reusable_row
->enabled_p
14178 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14179 != CHARPOS (new_start
)))
14182 /* We can reuse fully visible rows beginning with
14183 first_reusable_row to the end of the window. Set
14184 first_row_to_display to the first row that cannot be reused.
14185 Set pt_row to the row containing point, if there is any. */
14187 for (first_row_to_display
= first_reusable_row
;
14188 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
14189 ++first_row_to_display
)
14191 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
14192 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
14193 pt_row
= first_row_to_display
;
14196 /* Start displaying at the start of first_row_to_display. */
14197 xassert (first_row_to_display
->y
< yb
);
14198 init_to_row_start (&it
, w
, first_row_to_display
);
14200 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
14202 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
14204 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
14205 + WINDOW_HEADER_LINE_HEIGHT (w
));
14207 /* Display lines beginning with first_row_to_display in the
14208 desired matrix. Set last_text_row to the last row displayed
14209 that displays text. */
14210 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
14211 if (pt_row
== NULL
)
14212 w
->cursor
.vpos
= -1;
14213 last_text_row
= NULL
;
14214 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
14215 if (display_line (&it
))
14216 last_text_row
= it
.glyph_row
- 1;
14218 /* Give up If point isn't in a row displayed or reused. */
14219 if (w
->cursor
.vpos
< 0)
14221 clear_glyph_matrix (w
->desired_matrix
);
14225 /* If point is in a reused row, adjust y and vpos of the cursor
14229 w
->cursor
.vpos
-= nrows_scrolled
;
14230 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
14233 /* Scroll the display. */
14234 run
.current_y
= first_reusable_row
->y
;
14235 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14236 run
.height
= it
.last_visible_y
- run
.current_y
;
14237 dy
= run
.current_y
- run
.desired_y
;
14242 FRAME_RIF (f
)->update_window_begin_hook (w
);
14243 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14244 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14245 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14249 /* Adjust Y positions of reused rows. */
14250 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14251 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14252 max_y
= it
.last_visible_y
;
14253 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
14256 row
->visible_height
= row
->height
;
14257 if (row
->y
< min_y
)
14258 row
->visible_height
-= min_y
- row
->y
;
14259 if (row
->y
+ row
->height
> max_y
)
14260 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14261 row
->redraw_fringe_bitmaps_p
= 1;
14264 /* Scroll the current matrix. */
14265 xassert (nrows_scrolled
> 0);
14266 rotate_matrix (w
->current_matrix
,
14268 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14271 /* Disable rows not reused. */
14272 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
14273 row
->enabled_p
= 0;
14275 /* Point may have moved to a different line, so we cannot assume that
14276 the previous cursor position is valid; locate the correct row. */
14279 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
14280 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
14284 w
->cursor
.y
= row
->y
;
14286 if (row
< bottom_row
)
14288 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14289 while (glyph
->charpos
< PT
)
14292 w
->cursor
.x
+= glyph
->pixel_width
;
14298 /* Adjust window end. A null value of last_text_row means that
14299 the window end is in reused rows which in turn means that
14300 only its vpos can have changed. */
14303 w
->window_end_bytepos
14304 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14306 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14308 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14313 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
14316 w
->window_end_valid
= Qnil
;
14317 w
->desired_matrix
->no_scrolling_p
= 1;
14320 debug_method_add (w
, "try_window_reusing_current_matrix 2");
14330 /************************************************************************
14331 Window redisplay reusing current matrix when buffer has changed
14332 ************************************************************************/
14334 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
14335 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
14337 static struct glyph_row
*
14338 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
14339 struct glyph_row
*));
14342 /* Return the last row in MATRIX displaying text. If row START is
14343 non-null, start searching with that row. IT gives the dimensions
14344 of the display. Value is null if matrix is empty; otherwise it is
14345 a pointer to the row found. */
14347 static struct glyph_row
*
14348 find_last_row_displaying_text (matrix
, it
, start
)
14349 struct glyph_matrix
*matrix
;
14351 struct glyph_row
*start
;
14353 struct glyph_row
*row
, *row_found
;
14355 /* Set row_found to the last row in IT->w's current matrix
14356 displaying text. The loop looks funny but think of partially
14359 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14360 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14362 xassert (row
->enabled_p
);
14364 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
14373 /* Return the last row in the current matrix of W that is not affected
14374 by changes at the start of current_buffer that occurred since W's
14375 current matrix was built. Value is null if no such row exists.
14377 BEG_UNCHANGED us the number of characters unchanged at the start of
14378 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
14379 first changed character in current_buffer. Characters at positions <
14380 BEG + BEG_UNCHANGED are at the same buffer positions as they were
14381 when the current matrix was built. */
14383 static struct glyph_row
*
14384 find_last_unchanged_at_beg_row (w
)
14387 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
14388 struct glyph_row
*row
;
14389 struct glyph_row
*row_found
= NULL
;
14390 int yb
= window_text_bottom_y (w
);
14392 /* Find the last row displaying unchanged text. */
14393 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14394 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14395 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
14397 if (/* If row ends before first_changed_pos, it is unchanged,
14398 except in some case. */
14399 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
14400 /* When row ends in ZV and we write at ZV it is not
14402 && !row
->ends_at_zv_p
14403 /* When first_changed_pos is the end of a continued line,
14404 row is not unchanged because it may be no longer
14406 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
14407 && (row
->continued_p
14408 || row
->exact_window_width_line_p
)))
14411 /* Stop if last visible row. */
14412 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
14422 /* Find the first glyph row in the current matrix of W that is not
14423 affected by changes at the end of current_buffer since the
14424 time W's current matrix was built.
14426 Return in *DELTA the number of chars by which buffer positions in
14427 unchanged text at the end of current_buffer must be adjusted.
14429 Return in *DELTA_BYTES the corresponding number of bytes.
14431 Value is null if no such row exists, i.e. all rows are affected by
14434 static struct glyph_row
*
14435 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
14437 int *delta
, *delta_bytes
;
14439 struct glyph_row
*row
;
14440 struct glyph_row
*row_found
= NULL
;
14442 *delta
= *delta_bytes
= 0;
14444 /* Display must not have been paused, otherwise the current matrix
14445 is not up to date. */
14446 eassert (!NILP (w
->window_end_valid
));
14448 /* A value of window_end_pos >= END_UNCHANGED means that the window
14449 end is in the range of changed text. If so, there is no
14450 unchanged row at the end of W's current matrix. */
14451 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
14454 /* Set row to the last row in W's current matrix displaying text. */
14455 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14457 /* If matrix is entirely empty, no unchanged row exists. */
14458 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14460 /* The value of row is the last glyph row in the matrix having a
14461 meaningful buffer position in it. The end position of row
14462 corresponds to window_end_pos. This allows us to translate
14463 buffer positions in the current matrix to current buffer
14464 positions for characters not in changed text. */
14465 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14466 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14467 int last_unchanged_pos
, last_unchanged_pos_old
;
14468 struct glyph_row
*first_text_row
14469 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14471 *delta
= Z
- Z_old
;
14472 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14474 /* Set last_unchanged_pos to the buffer position of the last
14475 character in the buffer that has not been changed. Z is the
14476 index + 1 of the last character in current_buffer, i.e. by
14477 subtracting END_UNCHANGED we get the index of the last
14478 unchanged character, and we have to add BEG to get its buffer
14480 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
14481 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
14483 /* Search backward from ROW for a row displaying a line that
14484 starts at a minimum position >= last_unchanged_pos_old. */
14485 for (; row
> first_text_row
; --row
)
14487 /* This used to abort, but it can happen.
14488 It is ok to just stop the search instead here. KFS. */
14489 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14492 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
14497 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
14503 /* Make sure that glyph rows in the current matrix of window W
14504 reference the same glyph memory as corresponding rows in the
14505 frame's frame matrix. This function is called after scrolling W's
14506 current matrix on a terminal frame in try_window_id and
14507 try_window_reusing_current_matrix. */
14510 sync_frame_with_window_matrix_rows (w
)
14513 struct frame
*f
= XFRAME (w
->frame
);
14514 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
14516 /* Preconditions: W must be a leaf window and full-width. Its frame
14517 must have a frame matrix. */
14518 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
14519 xassert (WINDOW_FULL_WIDTH_P (w
));
14520 xassert (!FRAME_WINDOW_P (f
));
14522 /* If W is a full-width window, glyph pointers in W's current matrix
14523 have, by definition, to be the same as glyph pointers in the
14524 corresponding frame matrix. Note that frame matrices have no
14525 marginal areas (see build_frame_matrix). */
14526 window_row
= w
->current_matrix
->rows
;
14527 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14528 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14529 while (window_row
< window_row_end
)
14531 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14532 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14534 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14535 frame_row
->glyphs
[TEXT_AREA
] = start
;
14536 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14537 frame_row
->glyphs
[LAST_AREA
] = end
;
14539 /* Disable frame rows whose corresponding window rows have
14540 been disabled in try_window_id. */
14541 if (!window_row
->enabled_p
)
14542 frame_row
->enabled_p
= 0;
14544 ++window_row
, ++frame_row
;
14549 /* Find the glyph row in window W containing CHARPOS. Consider all
14550 rows between START and END (not inclusive). END null means search
14551 all rows to the end of the display area of W. Value is the row
14552 containing CHARPOS or null. */
14555 row_containing_pos (w
, charpos
, start
, end
, dy
)
14558 struct glyph_row
*start
, *end
;
14561 struct glyph_row
*row
= start
;
14564 /* If we happen to start on a header-line, skip that. */
14565 if (row
->mode_line_p
)
14568 if ((end
&& row
>= end
) || !row
->enabled_p
)
14571 last_y
= window_text_bottom_y (w
) - dy
;
14575 /* Give up if we have gone too far. */
14576 if (end
&& row
>= end
)
14578 /* This formerly returned if they were equal.
14579 I think that both quantities are of a "last plus one" type;
14580 if so, when they are equal, the row is within the screen. -- rms. */
14581 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14584 /* If it is in this row, return this row. */
14585 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14586 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14587 /* The end position of a row equals the start
14588 position of the next row. If CHARPOS is there, we
14589 would rather display it in the next line, except
14590 when this line ends in ZV. */
14591 && !row
->ends_at_zv_p
14592 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14593 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14600 /* Try to redisplay window W by reusing its existing display. W's
14601 current matrix must be up to date when this function is called,
14602 i.e. window_end_valid must not be nil.
14606 1 if display has been updated
14607 0 if otherwise unsuccessful
14608 -1 if redisplay with same window start is known not to succeed
14610 The following steps are performed:
14612 1. Find the last row in the current matrix of W that is not
14613 affected by changes at the start of current_buffer. If no such row
14616 2. Find the first row in W's current matrix that is not affected by
14617 changes at the end of current_buffer. Maybe there is no such row.
14619 3. Display lines beginning with the row + 1 found in step 1 to the
14620 row found in step 2 or, if step 2 didn't find a row, to the end of
14623 4. If cursor is not known to appear on the window, give up.
14625 5. If display stopped at the row found in step 2, scroll the
14626 display and current matrix as needed.
14628 6. Maybe display some lines at the end of W, if we must. This can
14629 happen under various circumstances, like a partially visible line
14630 becoming fully visible, or because newly displayed lines are displayed
14631 in smaller font sizes.
14633 7. Update W's window end information. */
14639 struct frame
*f
= XFRAME (w
->frame
);
14640 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14641 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14642 struct glyph_row
*last_unchanged_at_beg_row
;
14643 struct glyph_row
*first_unchanged_at_end_row
;
14644 struct glyph_row
*row
;
14645 struct glyph_row
*bottom_row
;
14648 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14649 struct text_pos start_pos
;
14651 int first_unchanged_at_end_vpos
= 0;
14652 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14653 struct text_pos start
;
14654 int first_changed_charpos
, last_changed_charpos
;
14657 if (inhibit_try_window_id
)
14661 /* This is handy for debugging. */
14663 #define GIVE_UP(X) \
14665 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14669 #define GIVE_UP(X) return 0
14672 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14674 /* Don't use this for mini-windows because these can show
14675 messages and mini-buffers, and we don't handle that here. */
14676 if (MINI_WINDOW_P (w
))
14679 /* This flag is used to prevent redisplay optimizations. */
14680 if (windows_or_buffers_changed
|| cursor_type_changed
)
14683 /* Verify that narrowing has not changed.
14684 Also verify that we were not told to prevent redisplay optimizations.
14685 It would be nice to further
14686 reduce the number of cases where this prevents try_window_id. */
14687 if (current_buffer
->clip_changed
14688 || current_buffer
->prevent_redisplay_optimizations_p
)
14691 /* Window must either use window-based redisplay or be full width. */
14692 if (!FRAME_WINDOW_P (f
)
14693 && (!FRAME_LINE_INS_DEL_OK (f
)
14694 || !WINDOW_FULL_WIDTH_P (w
)))
14697 /* Give up if point is not known NOT to appear in W. */
14698 if (PT
< CHARPOS (start
))
14701 /* Another way to prevent redisplay optimizations. */
14702 if (XFASTINT (w
->last_modified
) == 0)
14705 /* Verify that window is not hscrolled. */
14706 if (XFASTINT (w
->hscroll
) != 0)
14709 /* Verify that display wasn't paused. */
14710 if (NILP (w
->window_end_valid
))
14713 /* Can't use this if highlighting a region because a cursor movement
14714 will do more than just set the cursor. */
14715 if (!NILP (Vtransient_mark_mode
)
14716 && !NILP (current_buffer
->mark_active
))
14719 /* Likewise if highlighting trailing whitespace. */
14720 if (!NILP (Vshow_trailing_whitespace
))
14723 /* Likewise if showing a region. */
14724 if (!NILP (w
->region_showing
))
14727 /* Can use this if overlay arrow position and or string have changed. */
14728 if (overlay_arrows_changed_p ())
14732 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14733 only if buffer has really changed. The reason is that the gap is
14734 initially at Z for freshly visited files. The code below would
14735 set end_unchanged to 0 in that case. */
14736 if (MODIFF
> SAVE_MODIFF
14737 /* This seems to happen sometimes after saving a buffer. */
14738 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14740 if (GPT
- BEG
< BEG_UNCHANGED
)
14741 BEG_UNCHANGED
= GPT
- BEG
;
14742 if (Z
- GPT
< END_UNCHANGED
)
14743 END_UNCHANGED
= Z
- GPT
;
14746 /* The position of the first and last character that has been changed. */
14747 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14748 last_changed_charpos
= Z
- END_UNCHANGED
;
14750 /* If window starts after a line end, and the last change is in
14751 front of that newline, then changes don't affect the display.
14752 This case happens with stealth-fontification. Note that although
14753 the display is unchanged, glyph positions in the matrix have to
14754 be adjusted, of course. */
14755 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14756 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14757 && ((last_changed_charpos
< CHARPOS (start
)
14758 && CHARPOS (start
) == BEGV
)
14759 || (last_changed_charpos
< CHARPOS (start
) - 1
14760 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14762 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14763 struct glyph_row
*r0
;
14765 /* Compute how many chars/bytes have been added to or removed
14766 from the buffer. */
14767 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14768 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14770 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14772 /* Give up if PT is not in the window. Note that it already has
14773 been checked at the start of try_window_id that PT is not in
14774 front of the window start. */
14775 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14778 /* If window start is unchanged, we can reuse the whole matrix
14779 as is, after adjusting glyph positions. No need to compute
14780 the window end again, since its offset from Z hasn't changed. */
14781 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14782 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14783 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14784 /* PT must not be in a partially visible line. */
14785 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14786 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14788 /* Adjust positions in the glyph matrix. */
14789 if (delta
|| delta_bytes
)
14791 struct glyph_row
*r1
14792 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14793 increment_matrix_positions (w
->current_matrix
,
14794 MATRIX_ROW_VPOS (r0
, current_matrix
),
14795 MATRIX_ROW_VPOS (r1
, current_matrix
),
14796 delta
, delta_bytes
);
14799 /* Set the cursor. */
14800 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14802 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14809 /* Handle the case that changes are all below what is displayed in
14810 the window, and that PT is in the window. This shortcut cannot
14811 be taken if ZV is visible in the window, and text has been added
14812 there that is visible in the window. */
14813 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14814 /* ZV is not visible in the window, or there are no
14815 changes at ZV, actually. */
14816 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14817 || first_changed_charpos
== last_changed_charpos
))
14819 struct glyph_row
*r0
;
14821 /* Give up if PT is not in the window. Note that it already has
14822 been checked at the start of try_window_id that PT is not in
14823 front of the window start. */
14824 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14827 /* If window start is unchanged, we can reuse the whole matrix
14828 as is, without changing glyph positions since no text has
14829 been added/removed in front of the window end. */
14830 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14831 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14832 /* PT must not be in a partially visible line. */
14833 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14834 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14836 /* We have to compute the window end anew since text
14837 can have been added/removed after it. */
14839 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14840 w
->window_end_bytepos
14841 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14843 /* Set the cursor. */
14844 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14846 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14853 /* Give up if window start is in the changed area.
14855 The condition used to read
14857 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
14859 but why that was tested escapes me at the moment. */
14860 if (CHARPOS (start
) >= first_changed_charpos
14861 && CHARPOS (start
) <= last_changed_charpos
)
14864 /* Check that window start agrees with the start of the first glyph
14865 row in its current matrix. Check this after we know the window
14866 start is not in changed text, otherwise positions would not be
14868 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14869 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
14872 /* Give up if the window ends in strings. Overlay strings
14873 at the end are difficult to handle, so don't try. */
14874 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
14875 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
14878 /* Compute the position at which we have to start displaying new
14879 lines. Some of the lines at the top of the window might be
14880 reusable because they are not displaying changed text. Find the
14881 last row in W's current matrix not affected by changes at the
14882 start of current_buffer. Value is null if changes start in the
14883 first line of window. */
14884 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
14885 if (last_unchanged_at_beg_row
)
14887 /* Avoid starting to display in the moddle of a character, a TAB
14888 for instance. This is easier than to set up the iterator
14889 exactly, and it's not a frequent case, so the additional
14890 effort wouldn't really pay off. */
14891 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
14892 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
14893 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
14894 --last_unchanged_at_beg_row
;
14896 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
14899 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
14901 start_pos
= it
.current
.pos
;
14903 /* Start displaying new lines in the desired matrix at the same
14904 vpos we would use in the current matrix, i.e. below
14905 last_unchanged_at_beg_row. */
14906 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
14908 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14909 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
14911 xassert (it
.hpos
== 0 && it
.current_x
== 0);
14915 /* There are no reusable lines at the start of the window.
14916 Start displaying in the first text line. */
14917 start_display (&it
, w
, start
);
14918 it
.vpos
= it
.first_vpos
;
14919 start_pos
= it
.current
.pos
;
14922 /* Find the first row that is not affected by changes at the end of
14923 the buffer. Value will be null if there is no unchanged row, in
14924 which case we must redisplay to the end of the window. delta
14925 will be set to the value by which buffer positions beginning with
14926 first_unchanged_at_end_row have to be adjusted due to text
14928 first_unchanged_at_end_row
14929 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
14930 IF_DEBUG (debug_delta
= delta
);
14931 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
14933 /* Set stop_pos to the buffer position up to which we will have to
14934 display new lines. If first_unchanged_at_end_row != NULL, this
14935 is the buffer position of the start of the line displayed in that
14936 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
14937 that we don't stop at a buffer position. */
14939 if (first_unchanged_at_end_row
)
14941 xassert (last_unchanged_at_beg_row
== NULL
14942 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
14944 /* If this is a continuation line, move forward to the next one
14945 that isn't. Changes in lines above affect this line.
14946 Caution: this may move first_unchanged_at_end_row to a row
14947 not displaying text. */
14948 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
14949 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14950 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14951 < it
.last_visible_y
))
14952 ++first_unchanged_at_end_row
;
14954 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14955 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14956 >= it
.last_visible_y
))
14957 first_unchanged_at_end_row
= NULL
;
14960 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
14962 first_unchanged_at_end_vpos
14963 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
14964 xassert (stop_pos
>= Z
- END_UNCHANGED
);
14967 else if (last_unchanged_at_beg_row
== NULL
)
14973 /* Either there is no unchanged row at the end, or the one we have
14974 now displays text. This is a necessary condition for the window
14975 end pos calculation at the end of this function. */
14976 xassert (first_unchanged_at_end_row
== NULL
14977 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
14979 debug_last_unchanged_at_beg_vpos
14980 = (last_unchanged_at_beg_row
14981 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
14983 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
14985 #endif /* GLYPH_DEBUG != 0 */
14988 /* Display new lines. Set last_text_row to the last new line
14989 displayed which has text on it, i.e. might end up as being the
14990 line where the window_end_vpos is. */
14991 w
->cursor
.vpos
= -1;
14992 last_text_row
= NULL
;
14993 overlay_arrow_seen
= 0;
14994 while (it
.current_y
< it
.last_visible_y
14995 && !fonts_changed_p
14996 && (first_unchanged_at_end_row
== NULL
14997 || IT_CHARPOS (it
) < stop_pos
))
14999 if (display_line (&it
))
15000 last_text_row
= it
.glyph_row
- 1;
15003 if (fonts_changed_p
)
15007 /* Compute differences in buffer positions, y-positions etc. for
15008 lines reused at the bottom of the window. Compute what we can
15010 if (first_unchanged_at_end_row
15011 /* No lines reused because we displayed everything up to the
15012 bottom of the window. */
15013 && it
.current_y
< it
.last_visible_y
)
15016 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15018 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15019 run
.current_y
= first_unchanged_at_end_row
->y
;
15020 run
.desired_y
= run
.current_y
+ dy
;
15021 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15025 delta
= delta_bytes
= dvpos
= dy
15026 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15027 first_unchanged_at_end_row
= NULL
;
15029 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15032 /* Find the cursor if not already found. We have to decide whether
15033 PT will appear on this window (it sometimes doesn't, but this is
15034 not a very frequent case.) This decision has to be made before
15035 the current matrix is altered. A value of cursor.vpos < 0 means
15036 that PT is either in one of the lines beginning at
15037 first_unchanged_at_end_row or below the window. Don't care for
15038 lines that might be displayed later at the window end; as
15039 mentioned, this is not a frequent case. */
15040 if (w
->cursor
.vpos
< 0)
15042 /* Cursor in unchanged rows at the top? */
15043 if (PT
< CHARPOS (start_pos
)
15044 && last_unchanged_at_beg_row
)
15046 row
= row_containing_pos (w
, PT
,
15047 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15048 last_unchanged_at_beg_row
+ 1, 0);
15050 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15053 /* Start from first_unchanged_at_end_row looking for PT. */
15054 else if (first_unchanged_at_end_row
)
15056 row
= row_containing_pos (w
, PT
- delta
,
15057 first_unchanged_at_end_row
, NULL
, 0);
15059 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15060 delta_bytes
, dy
, dvpos
);
15063 /* Give up if cursor was not found. */
15064 if (w
->cursor
.vpos
< 0)
15066 clear_glyph_matrix (w
->desired_matrix
);
15071 /* Don't let the cursor end in the scroll margins. */
15073 int this_scroll_margin
, cursor_height
;
15075 this_scroll_margin
= max (0, scroll_margin
);
15076 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15077 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15078 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15080 if ((w
->cursor
.y
< this_scroll_margin
15081 && CHARPOS (start
) > BEGV
)
15082 /* Old redisplay didn't take scroll margin into account at the bottom,
15083 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
15084 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
15085 ? cursor_height
+ this_scroll_margin
15086 : 1)) > it
.last_visible_y
)
15088 w
->cursor
.vpos
= -1;
15089 clear_glyph_matrix (w
->desired_matrix
);
15094 /* Scroll the display. Do it before changing the current matrix so
15095 that xterm.c doesn't get confused about where the cursor glyph is
15097 if (dy
&& run
.height
)
15101 if (FRAME_WINDOW_P (f
))
15103 FRAME_RIF (f
)->update_window_begin_hook (w
);
15104 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15105 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15106 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15110 /* Terminal frame. In this case, dvpos gives the number of
15111 lines to scroll by; dvpos < 0 means scroll up. */
15112 int first_unchanged_at_end_vpos
15113 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
15114 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
15115 int end
= (WINDOW_TOP_EDGE_LINE (w
)
15116 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
15117 + window_internal_height (w
));
15119 /* Perform the operation on the screen. */
15122 /* Scroll last_unchanged_at_beg_row to the end of the
15123 window down dvpos lines. */
15124 set_terminal_window (f
, end
);
15126 /* On dumb terminals delete dvpos lines at the end
15127 before inserting dvpos empty lines. */
15128 if (!FRAME_SCROLL_REGION_OK (f
))
15129 ins_del_lines (f
, end
- dvpos
, -dvpos
);
15131 /* Insert dvpos empty lines in front of
15132 last_unchanged_at_beg_row. */
15133 ins_del_lines (f
, from
, dvpos
);
15135 else if (dvpos
< 0)
15137 /* Scroll up last_unchanged_at_beg_vpos to the end of
15138 the window to last_unchanged_at_beg_vpos - |dvpos|. */
15139 set_terminal_window (f
, end
);
15141 /* Delete dvpos lines in front of
15142 last_unchanged_at_beg_vpos. ins_del_lines will set
15143 the cursor to the given vpos and emit |dvpos| delete
15145 ins_del_lines (f
, from
+ dvpos
, dvpos
);
15147 /* On a dumb terminal insert dvpos empty lines at the
15149 if (!FRAME_SCROLL_REGION_OK (f
))
15150 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
15153 set_terminal_window (f
, 0);
15159 /* Shift reused rows of the current matrix to the right position.
15160 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
15162 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15163 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
15166 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
15167 bottom_vpos
, dvpos
);
15168 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
15171 else if (dvpos
> 0)
15173 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
15174 bottom_vpos
, dvpos
);
15175 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
15176 first_unchanged_at_end_vpos
+ dvpos
, 0);
15179 /* For frame-based redisplay, make sure that current frame and window
15180 matrix are in sync with respect to glyph memory. */
15181 if (!FRAME_WINDOW_P (f
))
15182 sync_frame_with_window_matrix_rows (w
);
15184 /* Adjust buffer positions in reused rows. */
15185 if (delta
|| delta_bytes
)
15186 increment_matrix_positions (current_matrix
,
15187 first_unchanged_at_end_vpos
+ dvpos
,
15188 bottom_vpos
, delta
, delta_bytes
);
15190 /* Adjust Y positions. */
15192 shift_glyph_matrix (w
, current_matrix
,
15193 first_unchanged_at_end_vpos
+ dvpos
,
15196 if (first_unchanged_at_end_row
)
15198 first_unchanged_at_end_row
+= dvpos
;
15199 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
15200 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
15201 first_unchanged_at_end_row
= NULL
;
15204 /* If scrolling up, there may be some lines to display at the end of
15206 last_text_row_at_end
= NULL
;
15209 /* Scrolling up can leave for example a partially visible line
15210 at the end of the window to be redisplayed. */
15211 /* Set last_row to the glyph row in the current matrix where the
15212 window end line is found. It has been moved up or down in
15213 the matrix by dvpos. */
15214 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
15215 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
15217 /* If last_row is the window end line, it should display text. */
15218 xassert (last_row
->displays_text_p
);
15220 /* If window end line was partially visible before, begin
15221 displaying at that line. Otherwise begin displaying with the
15222 line following it. */
15223 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
15225 init_to_row_start (&it
, w
, last_row
);
15226 it
.vpos
= last_vpos
;
15227 it
.current_y
= last_row
->y
;
15231 init_to_row_end (&it
, w
, last_row
);
15232 it
.vpos
= 1 + last_vpos
;
15233 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
15237 /* We may start in a continuation line. If so, we have to
15238 get the right continuation_lines_width and current_x. */
15239 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
15240 it
.hpos
= it
.current_x
= 0;
15242 /* Display the rest of the lines at the window end. */
15243 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15244 while (it
.current_y
< it
.last_visible_y
15245 && !fonts_changed_p
)
15247 /* Is it always sure that the display agrees with lines in
15248 the current matrix? I don't think so, so we mark rows
15249 displayed invalid in the current matrix by setting their
15250 enabled_p flag to zero. */
15251 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
15252 if (display_line (&it
))
15253 last_text_row_at_end
= it
.glyph_row
- 1;
15257 /* Update window_end_pos and window_end_vpos. */
15258 if (first_unchanged_at_end_row
15259 && !last_text_row_at_end
)
15261 /* Window end line if one of the preserved rows from the current
15262 matrix. Set row to the last row displaying text in current
15263 matrix starting at first_unchanged_at_end_row, after
15265 xassert (first_unchanged_at_end_row
->displays_text_p
);
15266 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
15267 first_unchanged_at_end_row
);
15268 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
15270 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15271 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15273 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
15274 xassert (w
->window_end_bytepos
>= 0);
15275 IF_DEBUG (debug_method_add (w
, "A"));
15277 else if (last_text_row_at_end
)
15280 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
15281 w
->window_end_bytepos
15282 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
15284 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
15285 xassert (w
->window_end_bytepos
>= 0);
15286 IF_DEBUG (debug_method_add (w
, "B"));
15288 else if (last_text_row
)
15290 /* We have displayed either to the end of the window or at the
15291 end of the window, i.e. the last row with text is to be found
15292 in the desired matrix. */
15294 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15295 w
->window_end_bytepos
15296 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15298 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
15299 xassert (w
->window_end_bytepos
>= 0);
15301 else if (first_unchanged_at_end_row
== NULL
15302 && last_text_row
== NULL
15303 && last_text_row_at_end
== NULL
)
15305 /* Displayed to end of window, but no line containing text was
15306 displayed. Lines were deleted at the end of the window. */
15307 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
15308 int vpos
= XFASTINT (w
->window_end_vpos
);
15309 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
15310 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
15313 row
== NULL
&& vpos
>= first_vpos
;
15314 --vpos
, --current_row
, --desired_row
)
15316 if (desired_row
->enabled_p
)
15318 if (desired_row
->displays_text_p
)
15321 else if (current_row
->displays_text_p
)
15325 xassert (row
!= NULL
);
15326 w
->window_end_vpos
= make_number (vpos
+ 1);
15327 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15328 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15329 xassert (w
->window_end_bytepos
>= 0);
15330 IF_DEBUG (debug_method_add (w
, "C"));
15335 #if 0 /* This leads to problems, for instance when the cursor is
15336 at ZV, and the cursor line displays no text. */
15337 /* Disable rows below what's displayed in the window. This makes
15338 debugging easier. */
15339 enable_glyph_matrix_rows (current_matrix
,
15340 XFASTINT (w
->window_end_vpos
) + 1,
15344 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
15345 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
15347 /* Record that display has not been completed. */
15348 w
->window_end_valid
= Qnil
;
15349 w
->desired_matrix
->no_scrolling_p
= 1;
15357 /***********************************************************************
15358 More debugging support
15359 ***********************************************************************/
15363 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
15364 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
15365 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
15368 /* Dump the contents of glyph matrix MATRIX on stderr.
15370 GLYPHS 0 means don't show glyph contents.
15371 GLYPHS 1 means show glyphs in short form
15372 GLYPHS > 1 means show glyphs in long form. */
15375 dump_glyph_matrix (matrix
, glyphs
)
15376 struct glyph_matrix
*matrix
;
15380 for (i
= 0; i
< matrix
->nrows
; ++i
)
15381 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
15385 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
15386 the glyph row and area where the glyph comes from. */
15389 dump_glyph (row
, glyph
, area
)
15390 struct glyph_row
*row
;
15391 struct glyph
*glyph
;
15394 if (glyph
->type
== CHAR_GLYPH
)
15397 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15398 glyph
- row
->glyphs
[TEXT_AREA
],
15401 (BUFFERP (glyph
->object
)
15403 : (STRINGP (glyph
->object
)
15406 glyph
->pixel_width
,
15408 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
15412 glyph
->left_box_line_p
,
15413 glyph
->right_box_line_p
);
15415 else if (glyph
->type
== STRETCH_GLYPH
)
15418 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15419 glyph
- row
->glyphs
[TEXT_AREA
],
15422 (BUFFERP (glyph
->object
)
15424 : (STRINGP (glyph
->object
)
15427 glyph
->pixel_width
,
15431 glyph
->left_box_line_p
,
15432 glyph
->right_box_line_p
);
15434 else if (glyph
->type
== IMAGE_GLYPH
)
15437 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15438 glyph
- row
->glyphs
[TEXT_AREA
],
15441 (BUFFERP (glyph
->object
)
15443 : (STRINGP (glyph
->object
)
15446 glyph
->pixel_width
,
15450 glyph
->left_box_line_p
,
15451 glyph
->right_box_line_p
);
15453 else if (glyph
->type
== COMPOSITE_GLYPH
)
15456 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15457 glyph
- row
->glyphs
[TEXT_AREA
],
15460 (BUFFERP (glyph
->object
)
15462 : (STRINGP (glyph
->object
)
15465 glyph
->pixel_width
,
15469 glyph
->left_box_line_p
,
15470 glyph
->right_box_line_p
);
15475 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
15476 GLYPHS 0 means don't show glyph contents.
15477 GLYPHS 1 means show glyphs in short form
15478 GLYPHS > 1 means show glyphs in long form. */
15481 dump_glyph_row (row
, vpos
, glyphs
)
15482 struct glyph_row
*row
;
15487 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
15488 fprintf (stderr
, "======================================================================\n");
15490 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
15491 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
15493 MATRIX_ROW_START_CHARPOS (row
),
15494 MATRIX_ROW_END_CHARPOS (row
),
15495 row
->used
[TEXT_AREA
],
15496 row
->contains_overlapping_glyphs_p
,
15498 row
->truncated_on_left_p
,
15499 row
->truncated_on_right_p
,
15501 MATRIX_ROW_CONTINUATION_LINE_P (row
),
15502 row
->displays_text_p
,
15505 row
->ends_in_middle_of_char_p
,
15506 row
->starts_in_middle_of_char_p
,
15512 row
->visible_height
,
15515 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
15516 row
->end
.overlay_string_index
,
15517 row
->continuation_lines_width
);
15518 fprintf (stderr
, "%9d %5d\n",
15519 CHARPOS (row
->start
.string_pos
),
15520 CHARPOS (row
->end
.string_pos
));
15521 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
15522 row
->end
.dpvec_index
);
15529 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15531 struct glyph
*glyph
= row
->glyphs
[area
];
15532 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
15534 /* Glyph for a line end in text. */
15535 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
15538 if (glyph
< glyph_end
)
15539 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15541 for (; glyph
< glyph_end
; ++glyph
)
15542 dump_glyph (row
, glyph
, area
);
15545 else if (glyphs
== 1)
15549 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15551 char *s
= (char *) alloca (row
->used
[area
] + 1);
15554 for (i
= 0; i
< row
->used
[area
]; ++i
)
15556 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15557 if (glyph
->type
== CHAR_GLYPH
15558 && glyph
->u
.ch
< 0x80
15559 && glyph
->u
.ch
>= ' ')
15560 s
[i
] = glyph
->u
.ch
;
15566 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15572 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15573 Sdump_glyph_matrix
, 0, 1, "p",
15574 doc
: /* Dump the current matrix of the selected window to stderr.
15575 Shows contents of glyph row structures. With non-nil
15576 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15577 glyphs in short form, otherwise show glyphs in long form. */)
15579 Lisp_Object glyphs
;
15581 struct window
*w
= XWINDOW (selected_window
);
15582 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15584 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15585 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15586 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15587 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15588 fprintf (stderr
, "=============================================\n");
15589 dump_glyph_matrix (w
->current_matrix
,
15590 NILP (glyphs
) ? 0 : XINT (glyphs
));
15595 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15596 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15599 struct frame
*f
= XFRAME (selected_frame
);
15600 dump_glyph_matrix (f
->current_matrix
, 1);
15605 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15606 doc
: /* Dump glyph row ROW to stderr.
15607 GLYPH 0 means don't dump glyphs.
15608 GLYPH 1 means dump glyphs in short form.
15609 GLYPH > 1 or omitted means dump glyphs in long form. */)
15611 Lisp_Object row
, glyphs
;
15613 struct glyph_matrix
*matrix
;
15616 CHECK_NUMBER (row
);
15617 matrix
= XWINDOW (selected_window
)->current_matrix
;
15619 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15620 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15622 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15627 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15628 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15629 GLYPH 0 means don't dump glyphs.
15630 GLYPH 1 means dump glyphs in short form.
15631 GLYPH > 1 or omitted means dump glyphs in long form. */)
15633 Lisp_Object row
, glyphs
;
15635 struct frame
*sf
= SELECTED_FRAME ();
15636 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15639 CHECK_NUMBER (row
);
15641 if (vpos
>= 0 && vpos
< m
->nrows
)
15642 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15643 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15648 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15649 doc
: /* Toggle tracing of redisplay.
15650 With ARG, turn tracing on if and only if ARG is positive. */)
15655 trace_redisplay_p
= !trace_redisplay_p
;
15658 arg
= Fprefix_numeric_value (arg
);
15659 trace_redisplay_p
= XINT (arg
) > 0;
15666 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15667 doc
: /* Like `format', but print result to stderr.
15668 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15673 Lisp_Object s
= Fformat (nargs
, args
);
15674 fprintf (stderr
, "%s", SDATA (s
));
15678 #endif /* GLYPH_DEBUG */
15682 /***********************************************************************
15683 Building Desired Matrix Rows
15684 ***********************************************************************/
15686 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15687 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15689 static struct glyph_row
*
15690 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15692 Lisp_Object overlay_arrow_string
;
15694 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15695 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15696 struct buffer
*old
= current_buffer
;
15697 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15698 int arrow_len
= SCHARS (overlay_arrow_string
);
15699 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15700 const unsigned char *p
;
15703 int n_glyphs_before
;
15705 set_buffer_temp (buffer
);
15706 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15707 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15708 SET_TEXT_POS (it
.position
, 0, 0);
15710 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15712 while (p
< arrow_end
)
15714 Lisp_Object face
, ilisp
;
15716 /* Get the next character. */
15718 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15720 it
.c
= *p
, it
.len
= 1;
15723 /* Get its face. */
15724 ilisp
= make_number (p
- arrow_string
);
15725 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15726 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15728 /* Compute its width, get its glyphs. */
15729 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15730 SET_TEXT_POS (it
.position
, -1, -1);
15731 PRODUCE_GLYPHS (&it
);
15733 /* If this character doesn't fit any more in the line, we have
15734 to remove some glyphs. */
15735 if (it
.current_x
> it
.last_visible_x
)
15737 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15742 set_buffer_temp (old
);
15743 return it
.glyph_row
;
15747 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15748 glyphs are only inserted for terminal frames since we can't really
15749 win with truncation glyphs when partially visible glyphs are
15750 involved. Which glyphs to insert is determined by
15751 produce_special_glyphs. */
15754 insert_left_trunc_glyphs (it
)
15757 struct it truncate_it
;
15758 struct glyph
*from
, *end
, *to
, *toend
;
15760 xassert (!FRAME_WINDOW_P (it
->f
));
15762 /* Get the truncation glyphs. */
15764 truncate_it
.current_x
= 0;
15765 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15766 truncate_it
.glyph_row
= &scratch_glyph_row
;
15767 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15768 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15769 truncate_it
.object
= make_number (0);
15770 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15772 /* Overwrite glyphs from IT with truncation glyphs. */
15773 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15774 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15775 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15776 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15781 /* There may be padding glyphs left over. Overwrite them too. */
15782 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15784 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15790 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15794 /* Compute the pixel height and width of IT->glyph_row.
15796 Most of the time, ascent and height of a display line will be equal
15797 to the max_ascent and max_height values of the display iterator
15798 structure. This is not the case if
15800 1. We hit ZV without displaying anything. In this case, max_ascent
15801 and max_height will be zero.
15803 2. We have some glyphs that don't contribute to the line height.
15804 (The glyph row flag contributes_to_line_height_p is for future
15805 pixmap extensions).
15807 The first case is easily covered by using default values because in
15808 these cases, the line height does not really matter, except that it
15809 must not be zero. */
15812 compute_line_metrics (it
)
15815 struct glyph_row
*row
= it
->glyph_row
;
15818 if (FRAME_WINDOW_P (it
->f
))
15820 int i
, min_y
, max_y
;
15822 /* The line may consist of one space only, that was added to
15823 place the cursor on it. If so, the row's height hasn't been
15825 if (row
->height
== 0)
15827 if (it
->max_ascent
+ it
->max_descent
== 0)
15828 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15829 row
->ascent
= it
->max_ascent
;
15830 row
->height
= it
->max_ascent
+ it
->max_descent
;
15831 row
->phys_ascent
= it
->max_phys_ascent
;
15832 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15833 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15836 /* Compute the width of this line. */
15837 row
->pixel_width
= row
->x
;
15838 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15839 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15841 xassert (row
->pixel_width
>= 0);
15842 xassert (row
->ascent
>= 0 && row
->height
> 0);
15844 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15845 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15847 /* If first line's physical ascent is larger than its logical
15848 ascent, use the physical ascent, and make the row taller.
15849 This makes accented characters fully visible. */
15850 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
15851 && row
->phys_ascent
> row
->ascent
)
15853 row
->height
+= row
->phys_ascent
- row
->ascent
;
15854 row
->ascent
= row
->phys_ascent
;
15857 /* Compute how much of the line is visible. */
15858 row
->visible_height
= row
->height
;
15860 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
15861 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
15863 if (row
->y
< min_y
)
15864 row
->visible_height
-= min_y
- row
->y
;
15865 if (row
->y
+ row
->height
> max_y
)
15866 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15870 row
->pixel_width
= row
->used
[TEXT_AREA
];
15871 if (row
->continued_p
)
15872 row
->pixel_width
-= it
->continuation_pixel_width
;
15873 else if (row
->truncated_on_right_p
)
15874 row
->pixel_width
-= it
->truncation_pixel_width
;
15875 row
->ascent
= row
->phys_ascent
= 0;
15876 row
->height
= row
->phys_height
= row
->visible_height
= 1;
15877 row
->extra_line_spacing
= 0;
15880 /* Compute a hash code for this row. */
15882 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15883 for (i
= 0; i
< row
->used
[area
]; ++i
)
15884 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
15885 + row
->glyphs
[area
][i
].u
.val
15886 + row
->glyphs
[area
][i
].face_id
15887 + row
->glyphs
[area
][i
].padding_p
15888 + (row
->glyphs
[area
][i
].type
<< 2));
15890 it
->max_ascent
= it
->max_descent
= 0;
15891 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
15895 /* Append one space to the glyph row of iterator IT if doing a
15896 window-based redisplay. The space has the same face as
15897 IT->face_id. Value is non-zero if a space was added.
15899 This function is called to make sure that there is always one glyph
15900 at the end of a glyph row that the cursor can be set on under
15901 window-systems. (If there weren't such a glyph we would not know
15902 how wide and tall a box cursor should be displayed).
15904 At the same time this space let's a nicely handle clearing to the
15905 end of the line if the row ends in italic text. */
15908 append_space_for_newline (it
, default_face_p
)
15910 int default_face_p
;
15912 if (FRAME_WINDOW_P (it
->f
))
15914 int n
= it
->glyph_row
->used
[TEXT_AREA
];
15916 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
15917 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
15919 /* Save some values that must not be changed.
15920 Must save IT->c and IT->len because otherwise
15921 ITERATOR_AT_END_P wouldn't work anymore after
15922 append_space_for_newline has been called. */
15923 enum display_element_type saved_what
= it
->what
;
15924 int saved_c
= it
->c
, saved_len
= it
->len
;
15925 int saved_x
= it
->current_x
;
15926 int saved_face_id
= it
->face_id
;
15927 struct text_pos saved_pos
;
15928 Lisp_Object saved_object
;
15931 saved_object
= it
->object
;
15932 saved_pos
= it
->position
;
15934 it
->what
= IT_CHARACTER
;
15935 bzero (&it
->position
, sizeof it
->position
);
15936 it
->object
= make_number (0);
15940 if (default_face_p
)
15941 it
->face_id
= DEFAULT_FACE_ID
;
15942 else if (it
->face_before_selective_p
)
15943 it
->face_id
= it
->saved_face_id
;
15944 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15945 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
15947 PRODUCE_GLYPHS (it
);
15949 it
->override_ascent
= -1;
15950 it
->constrain_row_ascent_descent_p
= 0;
15951 it
->current_x
= saved_x
;
15952 it
->object
= saved_object
;
15953 it
->position
= saved_pos
;
15954 it
->what
= saved_what
;
15955 it
->face_id
= saved_face_id
;
15956 it
->len
= saved_len
;
15966 /* Extend the face of the last glyph in the text area of IT->glyph_row
15967 to the end of the display line. Called from display_line.
15968 If the glyph row is empty, add a space glyph to it so that we
15969 know the face to draw. Set the glyph row flag fill_line_p. */
15972 extend_face_to_end_of_line (it
)
15976 struct frame
*f
= it
->f
;
15978 /* If line is already filled, do nothing. */
15979 if (it
->current_x
>= it
->last_visible_x
)
15982 /* Face extension extends the background and box of IT->face_id
15983 to the end of the line. If the background equals the background
15984 of the frame, we don't have to do anything. */
15985 if (it
->face_before_selective_p
)
15986 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
15988 face
= FACE_FROM_ID (f
, it
->face_id
);
15990 if (FRAME_WINDOW_P (f
)
15991 && it
->glyph_row
->displays_text_p
15992 && face
->box
== FACE_NO_BOX
15993 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
15997 /* Set the glyph row flag indicating that the face of the last glyph
15998 in the text area has to be drawn to the end of the text area. */
15999 it
->glyph_row
->fill_line_p
= 1;
16001 /* If current character of IT is not ASCII, make sure we have the
16002 ASCII face. This will be automatically undone the next time
16003 get_next_display_element returns a multibyte character. Note
16004 that the character will always be single byte in unibyte text. */
16005 if (!ASCII_CHAR_P (it
->c
))
16007 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
16010 if (FRAME_WINDOW_P (f
))
16012 /* If the row is empty, add a space with the current face of IT,
16013 so that we know which face to draw. */
16014 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16016 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16017 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16018 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16023 /* Save some values that must not be changed. */
16024 int saved_x
= it
->current_x
;
16025 struct text_pos saved_pos
;
16026 Lisp_Object saved_object
;
16027 enum display_element_type saved_what
= it
->what
;
16028 int saved_face_id
= it
->face_id
;
16030 saved_object
= it
->object
;
16031 saved_pos
= it
->position
;
16033 it
->what
= IT_CHARACTER
;
16034 bzero (&it
->position
, sizeof it
->position
);
16035 it
->object
= make_number (0);
16038 it
->face_id
= face
->id
;
16040 PRODUCE_GLYPHS (it
);
16042 while (it
->current_x
<= it
->last_visible_x
)
16043 PRODUCE_GLYPHS (it
);
16045 /* Don't count these blanks really. It would let us insert a left
16046 truncation glyph below and make us set the cursor on them, maybe. */
16047 it
->current_x
= saved_x
;
16048 it
->object
= saved_object
;
16049 it
->position
= saved_pos
;
16050 it
->what
= saved_what
;
16051 it
->face_id
= saved_face_id
;
16056 /* Value is non-zero if text starting at CHARPOS in current_buffer is
16057 trailing whitespace. */
16060 trailing_whitespace_p (charpos
)
16063 int bytepos
= CHAR_TO_BYTE (charpos
);
16066 while (bytepos
< ZV_BYTE
16067 && (c
= FETCH_CHAR (bytepos
),
16068 c
== ' ' || c
== '\t'))
16071 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
16073 if (bytepos
!= PT_BYTE
)
16080 /* Highlight trailing whitespace, if any, in ROW. */
16083 highlight_trailing_whitespace (f
, row
)
16085 struct glyph_row
*row
;
16087 int used
= row
->used
[TEXT_AREA
];
16091 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
16092 struct glyph
*glyph
= start
+ used
- 1;
16094 /* Skip over glyphs inserted to display the cursor at the
16095 end of a line, for extending the face of the last glyph
16096 to the end of the line on terminals, and for truncation
16097 and continuation glyphs. */
16098 while (glyph
>= start
16099 && glyph
->type
== CHAR_GLYPH
16100 && INTEGERP (glyph
->object
))
16103 /* If last glyph is a space or stretch, and it's trailing
16104 whitespace, set the face of all trailing whitespace glyphs in
16105 IT->glyph_row to `trailing-whitespace'. */
16107 && BUFFERP (glyph
->object
)
16108 && (glyph
->type
== STRETCH_GLYPH
16109 || (glyph
->type
== CHAR_GLYPH
16110 && glyph
->u
.ch
== ' '))
16111 && trailing_whitespace_p (glyph
->charpos
))
16113 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
16117 while (glyph
>= start
16118 && BUFFERP (glyph
->object
)
16119 && (glyph
->type
== STRETCH_GLYPH
16120 || (glyph
->type
== CHAR_GLYPH
16121 && glyph
->u
.ch
== ' ')))
16122 (glyph
--)->face_id
= face_id
;
16128 /* Value is non-zero if glyph row ROW in window W should be
16129 used to hold the cursor. */
16132 cursor_row_p (w
, row
)
16134 struct glyph_row
*row
;
16136 int cursor_row_p
= 1;
16138 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
16140 /* Suppose the row ends on a string.
16141 Unless the row is continued, that means it ends on a newline
16142 in the string. If it's anything other than a display string
16143 (e.g. a before-string from an overlay), we don't want the
16144 cursor there. (This heuristic seems to give the optimal
16145 behavior for the various types of multi-line strings.) */
16146 if (CHARPOS (row
->end
.string_pos
) >= 0)
16148 if (row
->continued_p
)
16152 /* Check for `display' property. */
16153 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
16154 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
16155 struct glyph
*glyph
;
16158 for (glyph
= end
; glyph
>= beg
; --glyph
)
16159 if (STRINGP (glyph
->object
))
16162 = Fget_char_property (make_number (PT
),
16166 && display_prop_string_p (prop
, glyph
->object
));
16171 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
16173 /* If the row ends in middle of a real character,
16174 and the line is continued, we want the cursor here.
16175 That's because MATRIX_ROW_END_CHARPOS would equal
16176 PT if PT is before the character. */
16177 if (!row
->ends_in_ellipsis_p
)
16178 cursor_row_p
= row
->continued_p
;
16180 /* If the row ends in an ellipsis, then
16181 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
16182 We want that position to be displayed after the ellipsis. */
16185 /* If the row ends at ZV, display the cursor at the end of that
16186 row instead of at the start of the row below. */
16187 else if (row
->ends_at_zv_p
)
16193 return cursor_row_p
;
16197 /* Construct the glyph row IT->glyph_row in the desired matrix of
16198 IT->w from text at the current position of IT. See dispextern.h
16199 for an overview of struct it. Value is non-zero if
16200 IT->glyph_row displays text, as opposed to a line displaying ZV
16207 struct glyph_row
*row
= it
->glyph_row
;
16208 Lisp_Object overlay_arrow_string
;
16210 /* We always start displaying at hpos zero even if hscrolled. */
16211 xassert (it
->hpos
== 0 && it
->current_x
== 0);
16213 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
16214 >= it
->w
->desired_matrix
->nrows
)
16216 it
->w
->nrows_scale_factor
++;
16217 fonts_changed_p
= 1;
16221 /* Is IT->w showing the region? */
16222 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
16224 /* Clear the result glyph row and enable it. */
16225 prepare_desired_row (row
);
16227 row
->y
= it
->current_y
;
16228 row
->start
= it
->start
;
16229 row
->continuation_lines_width
= it
->continuation_lines_width
;
16230 row
->displays_text_p
= 1;
16231 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
16232 it
->starts_in_middle_of_char_p
= 0;
16234 /* Arrange the overlays nicely for our purposes. Usually, we call
16235 display_line on only one line at a time, in which case this
16236 can't really hurt too much, or we call it on lines which appear
16237 one after another in the buffer, in which case all calls to
16238 recenter_overlay_lists but the first will be pretty cheap. */
16239 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
16241 /* Move over display elements that are not visible because we are
16242 hscrolled. This may stop at an x-position < IT->first_visible_x
16243 if the first glyph is partially visible or if we hit a line end. */
16244 if (it
->current_x
< it
->first_visible_x
)
16246 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
16247 MOVE_TO_POS
| MOVE_TO_X
);
16250 /* Get the initial row height. This is either the height of the
16251 text hscrolled, if there is any, or zero. */
16252 row
->ascent
= it
->max_ascent
;
16253 row
->height
= it
->max_ascent
+ it
->max_descent
;
16254 row
->phys_ascent
= it
->max_phys_ascent
;
16255 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16256 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16258 /* Loop generating characters. The loop is left with IT on the next
16259 character to display. */
16262 int n_glyphs_before
, hpos_before
, x_before
;
16264 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
16266 /* Retrieve the next thing to display. Value is zero if end of
16268 if (!get_next_display_element (it
))
16270 /* Maybe add a space at the end of this line that is used to
16271 display the cursor there under X. Set the charpos of the
16272 first glyph of blank lines not corresponding to any text
16274 #ifdef HAVE_WINDOW_SYSTEM
16275 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16276 row
->exact_window_width_line_p
= 1;
16278 #endif /* HAVE_WINDOW_SYSTEM */
16279 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
16280 || row
->used
[TEXT_AREA
] == 0)
16282 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
16283 row
->displays_text_p
= 0;
16285 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
16286 && (!MINI_WINDOW_P (it
->w
)
16287 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
16288 row
->indicate_empty_line_p
= 1;
16291 it
->continuation_lines_width
= 0;
16292 row
->ends_at_zv_p
= 1;
16296 /* Now, get the metrics of what we want to display. This also
16297 generates glyphs in `row' (which is IT->glyph_row). */
16298 n_glyphs_before
= row
->used
[TEXT_AREA
];
16301 /* Remember the line height so far in case the next element doesn't
16302 fit on the line. */
16303 if (!it
->truncate_lines_p
)
16305 ascent
= it
->max_ascent
;
16306 descent
= it
->max_descent
;
16307 phys_ascent
= it
->max_phys_ascent
;
16308 phys_descent
= it
->max_phys_descent
;
16311 PRODUCE_GLYPHS (it
);
16313 /* If this display element was in marginal areas, continue with
16315 if (it
->area
!= TEXT_AREA
)
16317 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16318 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16319 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16320 row
->phys_height
= max (row
->phys_height
,
16321 it
->max_phys_ascent
+ it
->max_phys_descent
);
16322 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16323 it
->max_extra_line_spacing
);
16324 set_iterator_to_next (it
, 1);
16328 /* Does the display element fit on the line? If we truncate
16329 lines, we should draw past the right edge of the window. If
16330 we don't truncate, we want to stop so that we can display the
16331 continuation glyph before the right margin. If lines are
16332 continued, there are two possible strategies for characters
16333 resulting in more than 1 glyph (e.g. tabs): Display as many
16334 glyphs as possible in this line and leave the rest for the
16335 continuation line, or display the whole element in the next
16336 line. Original redisplay did the former, so we do it also. */
16337 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
16338 hpos_before
= it
->hpos
;
16341 if (/* Not a newline. */
16343 /* Glyphs produced fit entirely in the line. */
16344 && it
->current_x
< it
->last_visible_x
)
16346 it
->hpos
+= nglyphs
;
16347 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16348 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16349 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16350 row
->phys_height
= max (row
->phys_height
,
16351 it
->max_phys_ascent
+ it
->max_phys_descent
);
16352 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16353 it
->max_extra_line_spacing
);
16354 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
16355 row
->x
= x
- it
->first_visible_x
;
16360 struct glyph
*glyph
;
16362 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
16364 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16365 new_x
= x
+ glyph
->pixel_width
;
16367 if (/* Lines are continued. */
16368 !it
->truncate_lines_p
16369 && (/* Glyph doesn't fit on the line. */
16370 new_x
> it
->last_visible_x
16371 /* Or it fits exactly on a window system frame. */
16372 || (new_x
== it
->last_visible_x
16373 && FRAME_WINDOW_P (it
->f
))))
16375 /* End of a continued line. */
16378 || (new_x
== it
->last_visible_x
16379 && FRAME_WINDOW_P (it
->f
)))
16381 /* Current glyph is the only one on the line or
16382 fits exactly on the line. We must continue
16383 the line because we can't draw the cursor
16384 after the glyph. */
16385 row
->continued_p
= 1;
16386 it
->current_x
= new_x
;
16387 it
->continuation_lines_width
+= new_x
;
16389 if (i
== nglyphs
- 1)
16391 set_iterator_to_next (it
, 1);
16392 #ifdef HAVE_WINDOW_SYSTEM
16393 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16395 if (!get_next_display_element (it
))
16397 row
->exact_window_width_line_p
= 1;
16398 it
->continuation_lines_width
= 0;
16399 row
->continued_p
= 0;
16400 row
->ends_at_zv_p
= 1;
16402 else if (ITERATOR_AT_END_OF_LINE_P (it
))
16404 row
->continued_p
= 0;
16405 row
->exact_window_width_line_p
= 1;
16408 #endif /* HAVE_WINDOW_SYSTEM */
16411 else if (CHAR_GLYPH_PADDING_P (*glyph
)
16412 && !FRAME_WINDOW_P (it
->f
))
16414 /* A padding glyph that doesn't fit on this line.
16415 This means the whole character doesn't fit
16417 row
->used
[TEXT_AREA
] = n_glyphs_before
;
16419 /* Fill the rest of the row with continuation
16420 glyphs like in 20.x. */
16421 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
16422 < row
->glyphs
[1 + TEXT_AREA
])
16423 produce_special_glyphs (it
, IT_CONTINUATION
);
16425 row
->continued_p
= 1;
16426 it
->current_x
= x_before
;
16427 it
->continuation_lines_width
+= x_before
;
16429 /* Restore the height to what it was before the
16430 element not fitting on the line. */
16431 it
->max_ascent
= ascent
;
16432 it
->max_descent
= descent
;
16433 it
->max_phys_ascent
= phys_ascent
;
16434 it
->max_phys_descent
= phys_descent
;
16436 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
16438 /* A TAB that extends past the right edge of the
16439 window. This produces a single glyph on
16440 window system frames. We leave the glyph in
16441 this row and let it fill the row, but don't
16442 consume the TAB. */
16443 it
->continuation_lines_width
+= it
->last_visible_x
;
16444 row
->ends_in_middle_of_char_p
= 1;
16445 row
->continued_p
= 1;
16446 glyph
->pixel_width
= it
->last_visible_x
- x
;
16447 it
->starts_in_middle_of_char_p
= 1;
16451 /* Something other than a TAB that draws past
16452 the right edge of the window. Restore
16453 positions to values before the element. */
16454 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16456 /* Display continuation glyphs. */
16457 if (!FRAME_WINDOW_P (it
->f
))
16458 produce_special_glyphs (it
, IT_CONTINUATION
);
16459 row
->continued_p
= 1;
16461 it
->current_x
= x_before
;
16462 it
->continuation_lines_width
+= x
;
16463 extend_face_to_end_of_line (it
);
16465 if (nglyphs
> 1 && i
> 0)
16467 row
->ends_in_middle_of_char_p
= 1;
16468 it
->starts_in_middle_of_char_p
= 1;
16471 /* Restore the height to what it was before the
16472 element not fitting on the line. */
16473 it
->max_ascent
= ascent
;
16474 it
->max_descent
= descent
;
16475 it
->max_phys_ascent
= phys_ascent
;
16476 it
->max_phys_descent
= phys_descent
;
16481 else if (new_x
> it
->first_visible_x
)
16483 /* Increment number of glyphs actually displayed. */
16486 if (x
< it
->first_visible_x
)
16487 /* Glyph is partially visible, i.e. row starts at
16488 negative X position. */
16489 row
->x
= x
- it
->first_visible_x
;
16493 /* Glyph is completely off the left margin of the
16494 window. This should not happen because of the
16495 move_it_in_display_line at the start of this
16496 function, unless the text display area of the
16497 window is empty. */
16498 xassert (it
->first_visible_x
<= it
->last_visible_x
);
16502 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16503 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16504 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16505 row
->phys_height
= max (row
->phys_height
,
16506 it
->max_phys_ascent
+ it
->max_phys_descent
);
16507 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16508 it
->max_extra_line_spacing
);
16510 /* End of this display line if row is continued. */
16511 if (row
->continued_p
|| row
->ends_at_zv_p
)
16516 /* Is this a line end? If yes, we're also done, after making
16517 sure that a non-default face is extended up to the right
16518 margin of the window. */
16519 if (ITERATOR_AT_END_OF_LINE_P (it
))
16521 int used_before
= row
->used
[TEXT_AREA
];
16523 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
16525 #ifdef HAVE_WINDOW_SYSTEM
16526 /* Add a space at the end of the line that is used to
16527 display the cursor there. */
16528 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16529 append_space_for_newline (it
, 0);
16530 #endif /* HAVE_WINDOW_SYSTEM */
16532 /* Extend the face to the end of the line. */
16533 extend_face_to_end_of_line (it
);
16535 /* Make sure we have the position. */
16536 if (used_before
== 0)
16537 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
16539 /* Consume the line end. This skips over invisible lines. */
16540 set_iterator_to_next (it
, 1);
16541 it
->continuation_lines_width
= 0;
16545 /* Proceed with next display element. Note that this skips
16546 over lines invisible because of selective display. */
16547 set_iterator_to_next (it
, 1);
16549 /* If we truncate lines, we are done when the last displayed
16550 glyphs reach past the right margin of the window. */
16551 if (it
->truncate_lines_p
16552 && (FRAME_WINDOW_P (it
->f
)
16553 ? (it
->current_x
>= it
->last_visible_x
)
16554 : (it
->current_x
> it
->last_visible_x
)))
16556 /* Maybe add truncation glyphs. */
16557 if (!FRAME_WINDOW_P (it
->f
))
16561 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16562 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16565 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16567 row
->used
[TEXT_AREA
] = i
;
16568 produce_special_glyphs (it
, IT_TRUNCATION
);
16571 #ifdef HAVE_WINDOW_SYSTEM
16574 /* Don't truncate if we can overflow newline into fringe. */
16575 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16577 if (!get_next_display_element (it
))
16579 it
->continuation_lines_width
= 0;
16580 row
->ends_at_zv_p
= 1;
16581 row
->exact_window_width_line_p
= 1;
16584 if (ITERATOR_AT_END_OF_LINE_P (it
))
16586 row
->exact_window_width_line_p
= 1;
16587 goto at_end_of_line
;
16591 #endif /* HAVE_WINDOW_SYSTEM */
16593 row
->truncated_on_right_p
= 1;
16594 it
->continuation_lines_width
= 0;
16595 reseat_at_next_visible_line_start (it
, 0);
16596 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16597 it
->hpos
= hpos_before
;
16598 it
->current_x
= x_before
;
16603 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16604 at the left window margin. */
16605 if (it
->first_visible_x
16606 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16608 if (!FRAME_WINDOW_P (it
->f
))
16609 insert_left_trunc_glyphs (it
);
16610 row
->truncated_on_left_p
= 1;
16613 /* If the start of this line is the overlay arrow-position, then
16614 mark this glyph row as the one containing the overlay arrow.
16615 This is clearly a mess with variable size fonts. It would be
16616 better to let it be displayed like cursors under X. */
16617 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16618 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16619 !NILP (overlay_arrow_string
)))
16621 /* Overlay arrow in window redisplay is a fringe bitmap. */
16622 if (STRINGP (overlay_arrow_string
))
16624 struct glyph_row
*arrow_row
16625 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
16626 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
16627 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
16628 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
16629 struct glyph
*p2
, *end
;
16631 /* Copy the arrow glyphs. */
16632 while (glyph
< arrow_end
)
16635 /* Throw away padding glyphs. */
16637 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16638 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
16644 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
16649 xassert (INTEGERP (overlay_arrow_string
));
16650 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
16652 overlay_arrow_seen
= 1;
16655 /* Compute pixel dimensions of this line. */
16656 compute_line_metrics (it
);
16658 /* Remember the position at which this line ends. */
16659 row
->end
= it
->current
;
16661 /* Record whether this row ends inside an ellipsis. */
16662 row
->ends_in_ellipsis_p
16663 = (it
->method
== GET_FROM_DISPLAY_VECTOR
16664 && it
->ellipsis_p
);
16666 /* Save fringe bitmaps in this row. */
16667 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
16668 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
16669 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
16670 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
16672 it
->left_user_fringe_bitmap
= 0;
16673 it
->left_user_fringe_face_id
= 0;
16674 it
->right_user_fringe_bitmap
= 0;
16675 it
->right_user_fringe_face_id
= 0;
16677 /* Maybe set the cursor. */
16678 if (it
->w
->cursor
.vpos
< 0
16679 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
16680 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
16681 && cursor_row_p (it
->w
, row
))
16682 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
16684 /* Highlight trailing whitespace. */
16685 if (!NILP (Vshow_trailing_whitespace
))
16686 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
16688 /* Prepare for the next line. This line starts horizontally at (X
16689 HPOS) = (0 0). Vertical positions are incremented. As a
16690 convenience for the caller, IT->glyph_row is set to the next
16692 it
->current_x
= it
->hpos
= 0;
16693 it
->current_y
+= row
->height
;
16696 it
->start
= it
->current
;
16697 return row
->displays_text_p
;
16702 /***********************************************************************
16704 ***********************************************************************/
16706 /* Redisplay the menu bar in the frame for window W.
16708 The menu bar of X frames that don't have X toolkit support is
16709 displayed in a special window W->frame->menu_bar_window.
16711 The menu bar of terminal frames is treated specially as far as
16712 glyph matrices are concerned. Menu bar lines are not part of
16713 windows, so the update is done directly on the frame matrix rows
16714 for the menu bar. */
16717 display_menu_bar (w
)
16720 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16725 /* Don't do all this for graphical frames. */
16727 if (FRAME_W32_P (f
))
16730 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
16735 if (FRAME_MAC_P (f
))
16739 #ifdef USE_X_TOOLKIT
16740 xassert (!FRAME_WINDOW_P (f
));
16741 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
16742 it
.first_visible_x
= 0;
16743 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16744 #else /* not USE_X_TOOLKIT */
16745 if (FRAME_WINDOW_P (f
))
16747 /* Menu bar lines are displayed in the desired matrix of the
16748 dummy window menu_bar_window. */
16749 struct window
*menu_w
;
16750 xassert (WINDOWP (f
->menu_bar_window
));
16751 menu_w
= XWINDOW (f
->menu_bar_window
);
16752 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
16754 it
.first_visible_x
= 0;
16755 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16759 /* This is a TTY frame, i.e. character hpos/vpos are used as
16761 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
16763 it
.first_visible_x
= 0;
16764 it
.last_visible_x
= FRAME_COLS (f
);
16766 #endif /* not USE_X_TOOLKIT */
16768 if (! mode_line_inverse_video
)
16769 /* Force the menu-bar to be displayed in the default face. */
16770 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16772 /* Clear all rows of the menu bar. */
16773 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
16775 struct glyph_row
*row
= it
.glyph_row
+ i
;
16776 clear_glyph_row (row
);
16777 row
->enabled_p
= 1;
16778 row
->full_width_p
= 1;
16781 /* Display all items of the menu bar. */
16782 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
16783 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
16785 Lisp_Object string
;
16787 /* Stop at nil string. */
16788 string
= AREF (items
, i
+ 1);
16792 /* Remember where item was displayed. */
16793 ASET (items
, i
+ 3, make_number (it
.hpos
));
16795 /* Display the item, pad with one space. */
16796 if (it
.current_x
< it
.last_visible_x
)
16797 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
16798 SCHARS (string
) + 1, 0, 0, -1);
16801 /* Fill out the line with spaces. */
16802 if (it
.current_x
< it
.last_visible_x
)
16803 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
16805 /* Compute the total height of the lines. */
16806 compute_line_metrics (&it
);
16811 /***********************************************************************
16813 ***********************************************************************/
16815 /* Redisplay mode lines in the window tree whose root is WINDOW. If
16816 FORCE is non-zero, redisplay mode lines unconditionally.
16817 Otherwise, redisplay only mode lines that are garbaged. Value is
16818 the number of windows whose mode lines were redisplayed. */
16821 redisplay_mode_lines (window
, force
)
16822 Lisp_Object window
;
16827 while (!NILP (window
))
16829 struct window
*w
= XWINDOW (window
);
16831 if (WINDOWP (w
->hchild
))
16832 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
16833 else if (WINDOWP (w
->vchild
))
16834 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
16836 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
16837 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
16839 struct text_pos lpoint
;
16840 struct buffer
*old
= current_buffer
;
16842 /* Set the window's buffer for the mode line display. */
16843 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16844 set_buffer_internal_1 (XBUFFER (w
->buffer
));
16846 /* Point refers normally to the selected window. For any
16847 other window, set up appropriate value. */
16848 if (!EQ (window
, selected_window
))
16850 struct text_pos pt
;
16852 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
16853 if (CHARPOS (pt
) < BEGV
)
16854 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16855 else if (CHARPOS (pt
) > (ZV
- 1))
16856 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
16858 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
16861 /* Display mode lines. */
16862 clear_glyph_matrix (w
->desired_matrix
);
16863 if (display_mode_lines (w
))
16866 w
->must_be_updated_p
= 1;
16869 /* Restore old settings. */
16870 set_buffer_internal_1 (old
);
16871 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16881 /* Display the mode and/or top line of window W. Value is the number
16882 of mode lines displayed. */
16885 display_mode_lines (w
)
16888 Lisp_Object old_selected_window
, old_selected_frame
;
16891 old_selected_frame
= selected_frame
;
16892 selected_frame
= w
->frame
;
16893 old_selected_window
= selected_window
;
16894 XSETWINDOW (selected_window
, w
);
16896 /* These will be set while the mode line specs are processed. */
16897 line_number_displayed
= 0;
16898 w
->column_number_displayed
= Qnil
;
16900 if (WINDOW_WANTS_MODELINE_P (w
))
16902 struct window
*sel_w
= XWINDOW (old_selected_window
);
16904 /* Select mode line face based on the real selected window. */
16905 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
16906 current_buffer
->mode_line_format
);
16910 if (WINDOW_WANTS_HEADER_LINE_P (w
))
16912 display_mode_line (w
, HEADER_LINE_FACE_ID
,
16913 current_buffer
->header_line_format
);
16917 selected_frame
= old_selected_frame
;
16918 selected_window
= old_selected_window
;
16923 /* Display mode or top line of window W. FACE_ID specifies which line
16924 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
16925 FORMAT is the mode line format to display. Value is the pixel
16926 height of the mode line displayed. */
16929 display_mode_line (w
, face_id
, format
)
16931 enum face_id face_id
;
16932 Lisp_Object format
;
16936 int count
= SPECPDL_INDEX ();
16938 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16939 /* Don't extend on a previously drawn mode-line.
16940 This may happen if called from pos_visible_p. */
16941 it
.glyph_row
->enabled_p
= 0;
16942 prepare_desired_row (it
.glyph_row
);
16944 it
.glyph_row
->mode_line_p
= 1;
16946 if (! mode_line_inverse_video
)
16947 /* Force the mode-line to be displayed in the default face. */
16948 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16950 record_unwind_protect (unwind_format_mode_line
,
16951 format_mode_line_unwind_data (NULL
, Qnil
, 0));
16953 mode_line_target
= MODE_LINE_DISPLAY
;
16955 /* Temporarily make frame's keyboard the current kboard so that
16956 kboard-local variables in the mode_line_format will get the right
16958 push_kboard (FRAME_KBOARD (it
.f
));
16959 record_unwind_save_match_data ();
16960 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16963 unbind_to (count
, Qnil
);
16965 /* Fill up with spaces. */
16966 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
16968 compute_line_metrics (&it
);
16969 it
.glyph_row
->full_width_p
= 1;
16970 it
.glyph_row
->continued_p
= 0;
16971 it
.glyph_row
->truncated_on_left_p
= 0;
16972 it
.glyph_row
->truncated_on_right_p
= 0;
16974 /* Make a 3D mode-line have a shadow at its right end. */
16975 face
= FACE_FROM_ID (it
.f
, face_id
);
16976 extend_face_to_end_of_line (&it
);
16977 if (face
->box
!= FACE_NO_BOX
)
16979 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
16980 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
16981 last
->right_box_line_p
= 1;
16984 return it
.glyph_row
->height
;
16987 /* Move element ELT in LIST to the front of LIST.
16988 Return the updated list. */
16991 move_elt_to_front (elt
, list
)
16992 Lisp_Object elt
, list
;
16994 register Lisp_Object tail
, prev
;
16995 register Lisp_Object tem
;
16999 while (CONSP (tail
))
17005 /* Splice out the link TAIL. */
17007 list
= XCDR (tail
);
17009 Fsetcdr (prev
, XCDR (tail
));
17011 /* Now make it the first. */
17012 Fsetcdr (tail
, list
);
17017 tail
= XCDR (tail
);
17021 /* Not found--return unchanged LIST. */
17025 /* Contribute ELT to the mode line for window IT->w. How it
17026 translates into text depends on its data type.
17028 IT describes the display environment in which we display, as usual.
17030 DEPTH is the depth in recursion. It is used to prevent
17031 infinite recursion here.
17033 FIELD_WIDTH is the number of characters the display of ELT should
17034 occupy in the mode line, and PRECISION is the maximum number of
17035 characters to display from ELT's representation. See
17036 display_string for details.
17038 Returns the hpos of the end of the text generated by ELT.
17040 PROPS is a property list to add to any string we encounter.
17042 If RISKY is nonzero, remove (disregard) any properties in any string
17043 we encounter, and ignore :eval and :propertize.
17045 The global variable `mode_line_target' determines whether the
17046 output is passed to `store_mode_line_noprop',
17047 `store_mode_line_string', or `display_string'. */
17050 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
17053 int field_width
, precision
;
17054 Lisp_Object elt
, props
;
17057 int n
= 0, field
, prec
;
17062 elt
= build_string ("*too-deep*");
17066 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
17070 /* A string: output it and check for %-constructs within it. */
17074 if (SCHARS (elt
) > 0
17075 && (!NILP (props
) || risky
))
17077 Lisp_Object oprops
, aelt
;
17078 oprops
= Ftext_properties_at (make_number (0), elt
);
17080 /* If the starting string's properties are not what
17081 we want, translate the string. Also, if the string
17082 is risky, do that anyway. */
17084 if (NILP (Fequal (props
, oprops
)) || risky
)
17086 /* If the starting string has properties,
17087 merge the specified ones onto the existing ones. */
17088 if (! NILP (oprops
) && !risky
)
17092 oprops
= Fcopy_sequence (oprops
);
17094 while (CONSP (tem
))
17096 oprops
= Fplist_put (oprops
, XCAR (tem
),
17097 XCAR (XCDR (tem
)));
17098 tem
= XCDR (XCDR (tem
));
17103 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
17104 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
17106 /* AELT is what we want. Move it to the front
17107 without consing. */
17109 mode_line_proptrans_alist
17110 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
17116 /* If AELT has the wrong props, it is useless.
17117 so get rid of it. */
17119 mode_line_proptrans_alist
17120 = Fdelq (aelt
, mode_line_proptrans_alist
);
17122 elt
= Fcopy_sequence (elt
);
17123 Fset_text_properties (make_number (0), Flength (elt
),
17125 /* Add this item to mode_line_proptrans_alist. */
17126 mode_line_proptrans_alist
17127 = Fcons (Fcons (elt
, props
),
17128 mode_line_proptrans_alist
);
17129 /* Truncate mode_line_proptrans_alist
17130 to at most 50 elements. */
17131 tem
= Fnthcdr (make_number (50),
17132 mode_line_proptrans_alist
);
17134 XSETCDR (tem
, Qnil
);
17143 prec
= precision
- n
;
17144 switch (mode_line_target
)
17146 case MODE_LINE_NOPROP
:
17147 case MODE_LINE_TITLE
:
17148 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
17150 case MODE_LINE_STRING
:
17151 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
17153 case MODE_LINE_DISPLAY
:
17154 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
17155 0, prec
, 0, STRING_MULTIBYTE (elt
));
17162 /* Handle the non-literal case. */
17164 while ((precision
<= 0 || n
< precision
)
17165 && SREF (elt
, offset
) != 0
17166 && (mode_line_target
!= MODE_LINE_DISPLAY
17167 || it
->current_x
< it
->last_visible_x
))
17169 int last_offset
= offset
;
17171 /* Advance to end of string or next format specifier. */
17172 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
17175 if (offset
- 1 != last_offset
)
17177 int nchars
, nbytes
;
17179 /* Output to end of string or up to '%'. Field width
17180 is length of string. Don't output more than
17181 PRECISION allows us. */
17184 prec
= c_string_width (SDATA (elt
) + last_offset
,
17185 offset
- last_offset
, precision
- n
,
17188 switch (mode_line_target
)
17190 case MODE_LINE_NOPROP
:
17191 case MODE_LINE_TITLE
:
17192 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
17194 case MODE_LINE_STRING
:
17196 int bytepos
= last_offset
;
17197 int charpos
= string_byte_to_char (elt
, bytepos
);
17198 int endpos
= (precision
<= 0
17199 ? string_byte_to_char (elt
, offset
)
17200 : charpos
+ nchars
);
17202 n
+= store_mode_line_string (NULL
,
17203 Fsubstring (elt
, make_number (charpos
),
17204 make_number (endpos
)),
17208 case MODE_LINE_DISPLAY
:
17210 int bytepos
= last_offset
;
17211 int charpos
= string_byte_to_char (elt
, bytepos
);
17213 if (precision
<= 0)
17214 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
17215 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
17217 STRING_MULTIBYTE (elt
));
17222 else /* c == '%' */
17224 int percent_position
= offset
;
17226 /* Get the specified minimum width. Zero means
17229 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
17230 field
= field
* 10 + c
- '0';
17232 /* Don't pad beyond the total padding allowed. */
17233 if (field_width
- n
> 0 && field
> field_width
- n
)
17234 field
= field_width
- n
;
17236 /* Note that either PRECISION <= 0 or N < PRECISION. */
17237 prec
= precision
- n
;
17240 n
+= display_mode_element (it
, depth
, field
, prec
,
17241 Vglobal_mode_string
, props
,
17246 int bytepos
, charpos
;
17247 unsigned char *spec
;
17249 bytepos
= percent_position
;
17250 charpos
= (STRING_MULTIBYTE (elt
)
17251 ? string_byte_to_char (elt
, bytepos
)
17254 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
17256 switch (mode_line_target
)
17258 case MODE_LINE_NOPROP
:
17259 case MODE_LINE_TITLE
:
17260 n
+= store_mode_line_noprop (spec
, field
, prec
);
17262 case MODE_LINE_STRING
:
17264 int len
= strlen (spec
);
17265 Lisp_Object tem
= make_string (spec
, len
);
17266 props
= Ftext_properties_at (make_number (charpos
), elt
);
17267 /* Should only keep face property in props */
17268 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
17271 case MODE_LINE_DISPLAY
:
17273 int nglyphs_before
, nwritten
;
17275 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17276 nwritten
= display_string (spec
, Qnil
, elt
,
17281 /* Assign to the glyphs written above the
17282 string where the `%x' came from, position
17286 struct glyph
*glyph
17287 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
17291 for (i
= 0; i
< nwritten
; ++i
)
17293 glyph
[i
].object
= elt
;
17294 glyph
[i
].charpos
= charpos
;
17311 /* A symbol: process the value of the symbol recursively
17312 as if it appeared here directly. Avoid error if symbol void.
17313 Special case: if value of symbol is a string, output the string
17316 register Lisp_Object tem
;
17318 /* If the variable is not marked as risky to set
17319 then its contents are risky to use. */
17320 if (NILP (Fget (elt
, Qrisky_local_variable
)))
17323 tem
= Fboundp (elt
);
17326 tem
= Fsymbol_value (elt
);
17327 /* If value is a string, output that string literally:
17328 don't check for % within it. */
17332 if (!EQ (tem
, elt
))
17334 /* Give up right away for nil or t. */
17344 register Lisp_Object car
, tem
;
17346 /* A cons cell: five distinct cases.
17347 If first element is :eval or :propertize, do something special.
17348 If first element is a string or a cons, process all the elements
17349 and effectively concatenate them.
17350 If first element is a negative number, truncate displaying cdr to
17351 at most that many characters. If positive, pad (with spaces)
17352 to at least that many characters.
17353 If first element is a symbol, process the cadr or caddr recursively
17354 according to whether the symbol's value is non-nil or nil. */
17356 if (EQ (car
, QCeval
))
17358 /* An element of the form (:eval FORM) means evaluate FORM
17359 and use the result as mode line elements. */
17364 if (CONSP (XCDR (elt
)))
17367 spec
= safe_eval (XCAR (XCDR (elt
)));
17368 n
+= display_mode_element (it
, depth
, field_width
- n
,
17369 precision
- n
, spec
, props
,
17373 else if (EQ (car
, QCpropertize
))
17375 /* An element of the form (:propertize ELT PROPS...)
17376 means display ELT but applying properties PROPS. */
17381 if (CONSP (XCDR (elt
)))
17382 n
+= display_mode_element (it
, depth
, field_width
- n
,
17383 precision
- n
, XCAR (XCDR (elt
)),
17384 XCDR (XCDR (elt
)), risky
);
17386 else if (SYMBOLP (car
))
17388 tem
= Fboundp (car
);
17392 /* elt is now the cdr, and we know it is a cons cell.
17393 Use its car if CAR has a non-nil value. */
17396 tem
= Fsymbol_value (car
);
17403 /* Symbol's value is nil (or symbol is unbound)
17404 Get the cddr of the original list
17405 and if possible find the caddr and use that. */
17409 else if (!CONSP (elt
))
17414 else if (INTEGERP (car
))
17416 register int lim
= XINT (car
);
17420 /* Negative int means reduce maximum width. */
17421 if (precision
<= 0)
17424 precision
= min (precision
, -lim
);
17428 /* Padding specified. Don't let it be more than
17429 current maximum. */
17431 lim
= min (precision
, lim
);
17433 /* If that's more padding than already wanted, queue it.
17434 But don't reduce padding already specified even if
17435 that is beyond the current truncation point. */
17436 field_width
= max (lim
, field_width
);
17440 else if (STRINGP (car
) || CONSP (car
))
17442 register int limit
= 50;
17443 /* Limit is to protect against circular lists. */
17446 && (precision
<= 0 || n
< precision
))
17448 n
+= display_mode_element (it
, depth
,
17449 /* Do padding only after the last
17450 element in the list. */
17451 (! CONSP (XCDR (elt
))
17454 precision
- n
, XCAR (elt
),
17464 elt
= build_string ("*invalid*");
17468 /* Pad to FIELD_WIDTH. */
17469 if (field_width
> 0 && n
< field_width
)
17471 switch (mode_line_target
)
17473 case MODE_LINE_NOPROP
:
17474 case MODE_LINE_TITLE
:
17475 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
17477 case MODE_LINE_STRING
:
17478 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
17480 case MODE_LINE_DISPLAY
:
17481 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
17490 /* Store a mode-line string element in mode_line_string_list.
17492 If STRING is non-null, display that C string. Otherwise, the Lisp
17493 string LISP_STRING is displayed.
17495 FIELD_WIDTH is the minimum number of output glyphs to produce.
17496 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17497 with spaces. FIELD_WIDTH <= 0 means don't pad.
17499 PRECISION is the maximum number of characters to output from
17500 STRING. PRECISION <= 0 means don't truncate the string.
17502 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
17503 properties to the string.
17505 PROPS are the properties to add to the string.
17506 The mode_line_string_face face property is always added to the string.
17510 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
17512 Lisp_Object lisp_string
;
17521 if (string
!= NULL
)
17523 len
= strlen (string
);
17524 if (precision
> 0 && len
> precision
)
17526 lisp_string
= make_string (string
, len
);
17528 props
= mode_line_string_face_prop
;
17529 else if (!NILP (mode_line_string_face
))
17531 Lisp_Object face
= Fplist_get (props
, Qface
);
17532 props
= Fcopy_sequence (props
);
17534 face
= mode_line_string_face
;
17536 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17537 props
= Fplist_put (props
, Qface
, face
);
17539 Fadd_text_properties (make_number (0), make_number (len
),
17540 props
, lisp_string
);
17544 len
= XFASTINT (Flength (lisp_string
));
17545 if (precision
> 0 && len
> precision
)
17548 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
17551 if (!NILP (mode_line_string_face
))
17555 props
= Ftext_properties_at (make_number (0), lisp_string
);
17556 face
= Fplist_get (props
, Qface
);
17558 face
= mode_line_string_face
;
17560 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17561 props
= Fcons (Qface
, Fcons (face
, Qnil
));
17563 lisp_string
= Fcopy_sequence (lisp_string
);
17566 Fadd_text_properties (make_number (0), make_number (len
),
17567 props
, lisp_string
);
17572 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17576 if (field_width
> len
)
17578 field_width
-= len
;
17579 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17581 Fadd_text_properties (make_number (0), make_number (field_width
),
17582 props
, lisp_string
);
17583 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17591 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17593 doc
: /* Format a string out of a mode line format specification.
17594 First arg FORMAT specifies the mode line format (see `mode-line-format'
17595 for details) to use.
17597 Optional second arg FACE specifies the face property to put
17598 on all characters for which no face is specified.
17599 The value t means whatever face the window's mode line currently uses
17600 \(either `mode-line' or `mode-line-inactive', depending).
17601 A value of nil means the default is no face property.
17602 If FACE is an integer, the value string has no text properties.
17604 Optional third and fourth args WINDOW and BUFFER specify the window
17605 and buffer to use as the context for the formatting (defaults
17606 are the selected window and the window's buffer). */)
17607 (format
, face
, window
, buffer
)
17608 Lisp_Object format
, face
, window
, buffer
;
17613 struct buffer
*old_buffer
= NULL
;
17615 int no_props
= INTEGERP (face
);
17616 int count
= SPECPDL_INDEX ();
17618 int string_start
= 0;
17621 window
= selected_window
;
17622 CHECK_WINDOW (window
);
17623 w
= XWINDOW (window
);
17626 buffer
= w
->buffer
;
17627 CHECK_BUFFER (buffer
);
17629 /* Make formatting the modeline a non-op when noninteractive, otherwise
17630 there will be problems later caused by a partially initialized frame. */
17631 if (NILP (format
) || noninteractive
)
17632 return empty_unibyte_string
;
17640 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
17641 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
17645 face_id
= DEFAULT_FACE_ID
;
17647 if (XBUFFER (buffer
) != current_buffer
)
17648 old_buffer
= current_buffer
;
17650 /* Save things including mode_line_proptrans_alist,
17651 and set that to nil so that we don't alter the outer value. */
17652 record_unwind_protect (unwind_format_mode_line
,
17653 format_mode_line_unwind_data
17654 (old_buffer
, selected_window
, 1));
17655 mode_line_proptrans_alist
= Qnil
;
17657 Fselect_window (window
, Qt
);
17659 set_buffer_internal_1 (XBUFFER (buffer
));
17661 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17665 mode_line_target
= MODE_LINE_NOPROP
;
17666 mode_line_string_face_prop
= Qnil
;
17667 mode_line_string_list
= Qnil
;
17668 string_start
= MODE_LINE_NOPROP_LEN (0);
17672 mode_line_target
= MODE_LINE_STRING
;
17673 mode_line_string_list
= Qnil
;
17674 mode_line_string_face
= face
;
17675 mode_line_string_face_prop
17676 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
17679 push_kboard (FRAME_KBOARD (it
.f
));
17680 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17685 len
= MODE_LINE_NOPROP_LEN (string_start
);
17686 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
17690 mode_line_string_list
= Fnreverse (mode_line_string_list
);
17691 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
17692 empty_unibyte_string
);
17695 unbind_to (count
, Qnil
);
17699 /* Write a null-terminated, right justified decimal representation of
17700 the positive integer D to BUF using a minimal field width WIDTH. */
17703 pint2str (buf
, width
, d
)
17704 register char *buf
;
17705 register int width
;
17708 register char *p
= buf
;
17716 *p
++ = d
% 10 + '0';
17721 for (width
-= (int) (p
- buf
); width
> 0; --width
)
17732 /* Write a null-terminated, right justified decimal and "human
17733 readable" representation of the nonnegative integer D to BUF using
17734 a minimal field width WIDTH. D should be smaller than 999.5e24. */
17736 static const char power_letter
[] =
17750 pint2hrstr (buf
, width
, d
)
17755 /* We aim to represent the nonnegative integer D as
17756 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
17759 /* -1 means: do not use TENTHS. */
17763 /* Length of QUOTIENT.TENTHS as a string. */
17769 if (1000 <= quotient
)
17771 /* Scale to the appropriate EXPONENT. */
17774 remainder
= quotient
% 1000;
17778 while (1000 <= quotient
);
17780 /* Round to nearest and decide whether to use TENTHS or not. */
17783 tenths
= remainder
/ 100;
17784 if (50 <= remainder
% 100)
17791 if (quotient
== 10)
17799 if (500 <= remainder
)
17801 if (quotient
< 999)
17812 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
17813 if (tenths
== -1 && quotient
<= 99)
17820 p
= psuffix
= buf
+ max (width
, length
);
17822 /* Print EXPONENT. */
17824 *psuffix
++ = power_letter
[exponent
];
17827 /* Print TENTHS. */
17830 *--p
= '0' + tenths
;
17834 /* Print QUOTIENT. */
17837 int digit
= quotient
% 10;
17838 *--p
= '0' + digit
;
17840 while ((quotient
/= 10) != 0);
17842 /* Print leading spaces. */
17847 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
17848 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
17849 type of CODING_SYSTEM. Return updated pointer into BUF. */
17851 static unsigned char invalid_eol_type
[] = "(*invalid*)";
17854 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
17855 Lisp_Object coding_system
;
17856 register char *buf
;
17860 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
17861 const unsigned char *eol_str
;
17863 /* The EOL conversion we are using. */
17864 Lisp_Object eoltype
;
17866 val
= CODING_SYSTEM_SPEC (coding_system
);
17869 if (!VECTORP (val
)) /* Not yet decided. */
17874 eoltype
= eol_mnemonic_undecided
;
17875 /* Don't mention EOL conversion if it isn't decided. */
17880 Lisp_Object eolvalue
;
17882 attrs
= AREF (val
, 0);
17883 eolvalue
= AREF (val
, 2);
17886 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
17890 /* The EOL conversion that is normal on this system. */
17892 if (NILP (eolvalue
)) /* Not yet decided. */
17893 eoltype
= eol_mnemonic_undecided
;
17894 else if (VECTORP (eolvalue
)) /* Not yet decided. */
17895 eoltype
= eol_mnemonic_undecided
;
17896 else /* eolvalue is Qunix, Qdos, or Qmac. */
17897 eoltype
= (EQ (eolvalue
, Qunix
)
17898 ? eol_mnemonic_unix
17899 : (EQ (eolvalue
, Qdos
) == 1
17900 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
17906 /* Mention the EOL conversion if it is not the usual one. */
17907 if (STRINGP (eoltype
))
17909 eol_str
= SDATA (eoltype
);
17910 eol_str_len
= SBYTES (eoltype
);
17912 else if (CHARACTERP (eoltype
))
17914 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
17915 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
17920 eol_str
= invalid_eol_type
;
17921 eol_str_len
= sizeof (invalid_eol_type
) - 1;
17923 bcopy (eol_str
, buf
, eol_str_len
);
17924 buf
+= eol_str_len
;
17930 /* Return a string for the output of a mode line %-spec for window W,
17931 generated by character C. PRECISION >= 0 means don't return a
17932 string longer than that value. FIELD_WIDTH > 0 means pad the
17933 string returned with spaces to that value. Return 1 in *MULTIBYTE
17934 if the result is multibyte text.
17936 Note we operate on the current buffer for most purposes,
17937 the exception being w->base_line_pos. */
17939 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
17942 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
17945 int field_width
, precision
;
17949 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17950 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
17951 struct buffer
*b
= current_buffer
;
17959 if (!NILP (b
->read_only
))
17961 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17966 /* This differs from %* only for a modified read-only buffer. */
17967 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17969 if (!NILP (b
->read_only
))
17974 /* This differs from %* in ignoring read-only-ness. */
17975 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17987 if (command_loop_level
> 5)
17989 p
= decode_mode_spec_buf
;
17990 for (i
= 0; i
< command_loop_level
; i
++)
17993 return decode_mode_spec_buf
;
18001 if (command_loop_level
> 5)
18003 p
= decode_mode_spec_buf
;
18004 for (i
= 0; i
< command_loop_level
; i
++)
18007 return decode_mode_spec_buf
;
18014 /* Let lots_of_dashes be a string of infinite length. */
18015 if (mode_line_target
== MODE_LINE_NOPROP
||
18016 mode_line_target
== MODE_LINE_STRING
)
18018 if (field_width
<= 0
18019 || field_width
> sizeof (lots_of_dashes
))
18021 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
18022 decode_mode_spec_buf
[i
] = '-';
18023 decode_mode_spec_buf
[i
] = '\0';
18024 return decode_mode_spec_buf
;
18027 return lots_of_dashes
;
18035 /* %c and %l are ignored in `frame-title-format'.
18036 (In redisplay_internal, the frame title is drawn _before_ the
18037 windows are updated, so the stuff which depends on actual
18038 window contents (such as %l) may fail to render properly, or
18039 even crash emacs.) */
18040 if (mode_line_target
== MODE_LINE_TITLE
)
18044 int col
= (int) current_column (); /* iftc */
18045 w
->column_number_displayed
= make_number (col
);
18046 pint2str (decode_mode_spec_buf
, field_width
, col
);
18047 return decode_mode_spec_buf
;
18051 #ifndef SYSTEM_MALLOC
18053 if (NILP (Vmemory_full
))
18056 return "!MEM FULL! ";
18063 /* %F displays the frame name. */
18064 if (!NILP (f
->title
))
18065 return (char *) SDATA (f
->title
);
18066 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
18067 return (char *) SDATA (f
->name
);
18076 int size
= ZV
- BEGV
;
18077 pint2str (decode_mode_spec_buf
, field_width
, size
);
18078 return decode_mode_spec_buf
;
18083 int size
= ZV
- BEGV
;
18084 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
18085 return decode_mode_spec_buf
;
18090 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
18091 int topline
, nlines
, junk
, height
;
18093 /* %c and %l are ignored in `frame-title-format'. */
18094 if (mode_line_target
== MODE_LINE_TITLE
)
18097 startpos
= XMARKER (w
->start
)->charpos
;
18098 startpos_byte
= marker_byte_position (w
->start
);
18099 height
= WINDOW_TOTAL_LINES (w
);
18101 /* If we decided that this buffer isn't suitable for line numbers,
18102 don't forget that too fast. */
18103 if (EQ (w
->base_line_pos
, w
->buffer
))
18105 /* But do forget it, if the window shows a different buffer now. */
18106 else if (BUFFERP (w
->base_line_pos
))
18107 w
->base_line_pos
= Qnil
;
18109 /* If the buffer is very big, don't waste time. */
18110 if (INTEGERP (Vline_number_display_limit
)
18111 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
18113 w
->base_line_pos
= Qnil
;
18114 w
->base_line_number
= Qnil
;
18118 if (INTEGERP (w
->base_line_number
)
18119 && INTEGERP (w
->base_line_pos
)
18120 && XFASTINT (w
->base_line_pos
) <= startpos
)
18122 line
= XFASTINT (w
->base_line_number
);
18123 linepos
= XFASTINT (w
->base_line_pos
);
18124 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
18129 linepos
= BUF_BEGV (b
);
18130 linepos_byte
= BUF_BEGV_BYTE (b
);
18133 /* Count lines from base line to window start position. */
18134 nlines
= display_count_lines (linepos
, linepos_byte
,
18138 topline
= nlines
+ line
;
18140 /* Determine a new base line, if the old one is too close
18141 or too far away, or if we did not have one.
18142 "Too close" means it's plausible a scroll-down would
18143 go back past it. */
18144 if (startpos
== BUF_BEGV (b
))
18146 w
->base_line_number
= make_number (topline
);
18147 w
->base_line_pos
= make_number (BUF_BEGV (b
));
18149 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
18150 || linepos
== BUF_BEGV (b
))
18152 int limit
= BUF_BEGV (b
);
18153 int limit_byte
= BUF_BEGV_BYTE (b
);
18155 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
18157 if (startpos
- distance
> limit
)
18159 limit
= startpos
- distance
;
18160 limit_byte
= CHAR_TO_BYTE (limit
);
18163 nlines
= display_count_lines (startpos
, startpos_byte
,
18165 - (height
* 2 + 30),
18167 /* If we couldn't find the lines we wanted within
18168 line_number_display_limit_width chars per line,
18169 give up on line numbers for this window. */
18170 if (position
== limit_byte
&& limit
== startpos
- distance
)
18172 w
->base_line_pos
= w
->buffer
;
18173 w
->base_line_number
= Qnil
;
18177 w
->base_line_number
= make_number (topline
- nlines
);
18178 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
18181 /* Now count lines from the start pos to point. */
18182 nlines
= display_count_lines (startpos
, startpos_byte
,
18183 PT_BYTE
, PT
, &junk
);
18185 /* Record that we did display the line number. */
18186 line_number_displayed
= 1;
18188 /* Make the string to show. */
18189 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
18190 return decode_mode_spec_buf
;
18193 char* p
= decode_mode_spec_buf
;
18194 int pad
= field_width
- 2;
18200 return decode_mode_spec_buf
;
18206 obj
= b
->mode_name
;
18210 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
18216 int pos
= marker_position (w
->start
);
18217 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18219 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
18221 if (pos
<= BUF_BEGV (b
))
18226 else if (pos
<= BUF_BEGV (b
))
18230 if (total
> 1000000)
18231 /* Do it differently for a large value, to avoid overflow. */
18232 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18234 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18235 /* We can't normally display a 3-digit number,
18236 so get us a 2-digit number that is close. */
18239 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18240 return decode_mode_spec_buf
;
18244 /* Display percentage of size above the bottom of the screen. */
18247 int toppos
= marker_position (w
->start
);
18248 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
18249 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18251 if (botpos
>= BUF_ZV (b
))
18253 if (toppos
<= BUF_BEGV (b
))
18260 if (total
> 1000000)
18261 /* Do it differently for a large value, to avoid overflow. */
18262 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18264 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18265 /* We can't normally display a 3-digit number,
18266 so get us a 2-digit number that is close. */
18269 if (toppos
<= BUF_BEGV (b
))
18270 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
18272 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18273 return decode_mode_spec_buf
;
18278 /* status of process */
18279 obj
= Fget_buffer_process (Fcurrent_buffer ());
18281 return "no process";
18282 #ifdef subprocesses
18283 obj
= Fsymbol_name (Fprocess_status (obj
));
18290 val
= call1 (intern ("file-remote-p"), current_buffer
->directory
);
18297 case 't': /* indicate TEXT or BINARY */
18298 #ifdef MODE_LINE_BINARY_TEXT
18299 return MODE_LINE_BINARY_TEXT (b
);
18305 /* coding-system (not including end-of-line format) */
18307 /* coding-system (including end-of-line type) */
18309 int eol_flag
= (c
== 'Z');
18310 char *p
= decode_mode_spec_buf
;
18312 if (! FRAME_WINDOW_P (f
))
18314 /* No need to mention EOL here--the terminal never needs
18315 to do EOL conversion. */
18316 p
= decode_mode_spec_coding (CODING_ID_NAME
18317 (FRAME_KEYBOARD_CODING (f
)->id
),
18319 p
= decode_mode_spec_coding (CODING_ID_NAME
18320 (FRAME_TERMINAL_CODING (f
)->id
),
18323 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
18326 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
18327 #ifdef subprocesses
18328 obj
= Fget_buffer_process (Fcurrent_buffer ());
18329 if (PROCESSP (obj
))
18331 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
18333 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
18336 #endif /* subprocesses */
18339 return decode_mode_spec_buf
;
18345 *multibyte
= STRING_MULTIBYTE (obj
);
18346 return (char *) SDATA (obj
);
18353 /* Count up to COUNT lines starting from START / START_BYTE.
18354 But don't go beyond LIMIT_BYTE.
18355 Return the number of lines thus found (always nonnegative).
18357 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
18360 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
18361 int start
, start_byte
, limit_byte
, count
;
18364 register unsigned char *cursor
;
18365 unsigned char *base
;
18367 register int ceiling
;
18368 register unsigned char *ceiling_addr
;
18369 int orig_count
= count
;
18371 /* If we are not in selective display mode,
18372 check only for newlines. */
18373 int selective_display
= (!NILP (current_buffer
->selective_display
)
18374 && !INTEGERP (current_buffer
->selective_display
));
18378 while (start_byte
< limit_byte
)
18380 ceiling
= BUFFER_CEILING_OF (start_byte
);
18381 ceiling
= min (limit_byte
- 1, ceiling
);
18382 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
18383 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
18386 if (selective_display
)
18387 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
18390 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
18393 if (cursor
!= ceiling_addr
)
18397 start_byte
+= cursor
- base
+ 1;
18398 *byte_pos_ptr
= start_byte
;
18402 if (++cursor
== ceiling_addr
)
18408 start_byte
+= cursor
- base
;
18413 while (start_byte
> limit_byte
)
18415 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
18416 ceiling
= max (limit_byte
, ceiling
);
18417 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
18418 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
18421 if (selective_display
)
18422 while (--cursor
!= ceiling_addr
18423 && *cursor
!= '\n' && *cursor
!= 015)
18426 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
18429 if (cursor
!= ceiling_addr
)
18433 start_byte
+= cursor
- base
+ 1;
18434 *byte_pos_ptr
= start_byte
;
18435 /* When scanning backwards, we should
18436 not count the newline posterior to which we stop. */
18437 return - orig_count
- 1;
18443 /* Here we add 1 to compensate for the last decrement
18444 of CURSOR, which took it past the valid range. */
18445 start_byte
+= cursor
- base
+ 1;
18449 *byte_pos_ptr
= limit_byte
;
18452 return - orig_count
+ count
;
18453 return orig_count
- count
;
18459 /***********************************************************************
18461 ***********************************************************************/
18463 /* Display a NUL-terminated string, starting with index START.
18465 If STRING is non-null, display that C string. Otherwise, the Lisp
18466 string LISP_STRING is displayed.
18468 If FACE_STRING is not nil, FACE_STRING_POS is a position in
18469 FACE_STRING. Display STRING or LISP_STRING with the face at
18470 FACE_STRING_POS in FACE_STRING:
18472 Display the string in the environment given by IT, but use the
18473 standard display table, temporarily.
18475 FIELD_WIDTH is the minimum number of output glyphs to produce.
18476 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18477 with spaces. If STRING has more characters, more than FIELD_WIDTH
18478 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
18480 PRECISION is the maximum number of characters to output from
18481 STRING. PRECISION < 0 means don't truncate the string.
18483 This is roughly equivalent to printf format specifiers:
18485 FIELD_WIDTH PRECISION PRINTF
18486 ----------------------------------------
18492 MULTIBYTE zero means do not display multibyte chars, > 0 means do
18493 display them, and < 0 means obey the current buffer's value of
18494 enable_multibyte_characters.
18496 Value is the number of columns displayed. */
18499 display_string (string
, lisp_string
, face_string
, face_string_pos
,
18500 start
, it
, field_width
, precision
, max_x
, multibyte
)
18501 unsigned char *string
;
18502 Lisp_Object lisp_string
;
18503 Lisp_Object face_string
;
18504 EMACS_INT face_string_pos
;
18507 int field_width
, precision
, max_x
;
18510 int hpos_at_start
= it
->hpos
;
18511 int saved_face_id
= it
->face_id
;
18512 struct glyph_row
*row
= it
->glyph_row
;
18514 /* Initialize the iterator IT for iteration over STRING beginning
18515 with index START. */
18516 reseat_to_string (it
, string
, lisp_string
, start
,
18517 precision
, field_width
, multibyte
);
18519 /* If displaying STRING, set up the face of the iterator
18520 from LISP_STRING, if that's given. */
18521 if (STRINGP (face_string
))
18527 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
18528 0, it
->region_beg_charpos
,
18529 it
->region_end_charpos
,
18530 &endptr
, it
->base_face_id
, 0);
18531 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18532 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
18535 /* Set max_x to the maximum allowed X position. Don't let it go
18536 beyond the right edge of the window. */
18538 max_x
= it
->last_visible_x
;
18540 max_x
= min (max_x
, it
->last_visible_x
);
18542 /* Skip over display elements that are not visible. because IT->w is
18544 if (it
->current_x
< it
->first_visible_x
)
18545 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
18546 MOVE_TO_POS
| MOVE_TO_X
);
18548 row
->ascent
= it
->max_ascent
;
18549 row
->height
= it
->max_ascent
+ it
->max_descent
;
18550 row
->phys_ascent
= it
->max_phys_ascent
;
18551 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18552 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18554 /* This condition is for the case that we are called with current_x
18555 past last_visible_x. */
18556 while (it
->current_x
< max_x
)
18558 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
18560 /* Get the next display element. */
18561 if (!get_next_display_element (it
))
18564 /* Produce glyphs. */
18565 x_before
= it
->current_x
;
18566 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18567 PRODUCE_GLYPHS (it
);
18569 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
18572 while (i
< nglyphs
)
18574 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18576 if (!it
->truncate_lines_p
18577 && x
+ glyph
->pixel_width
> max_x
)
18579 /* End of continued line or max_x reached. */
18580 if (CHAR_GLYPH_PADDING_P (*glyph
))
18582 /* A wide character is unbreakable. */
18583 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18584 it
->current_x
= x_before
;
18588 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18593 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
18595 /* Glyph is at least partially visible. */
18597 if (x
< it
->first_visible_x
)
18598 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18602 /* Glyph is off the left margin of the display area.
18603 Should not happen. */
18607 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18608 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18609 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18610 row
->phys_height
= max (row
->phys_height
,
18611 it
->max_phys_ascent
+ it
->max_phys_descent
);
18612 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18613 it
->max_extra_line_spacing
);
18614 x
+= glyph
->pixel_width
;
18618 /* Stop if max_x reached. */
18622 /* Stop at line ends. */
18623 if (ITERATOR_AT_END_OF_LINE_P (it
))
18625 it
->continuation_lines_width
= 0;
18629 set_iterator_to_next (it
, 1);
18631 /* Stop if truncating at the right edge. */
18632 if (it
->truncate_lines_p
18633 && it
->current_x
>= it
->last_visible_x
)
18635 /* Add truncation mark, but don't do it if the line is
18636 truncated at a padding space. */
18637 if (IT_CHARPOS (*it
) < it
->string_nchars
)
18639 if (!FRAME_WINDOW_P (it
->f
))
18643 if (it
->current_x
> it
->last_visible_x
)
18645 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18646 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18648 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18650 row
->used
[TEXT_AREA
] = i
;
18651 produce_special_glyphs (it
, IT_TRUNCATION
);
18654 produce_special_glyphs (it
, IT_TRUNCATION
);
18656 it
->glyph_row
->truncated_on_right_p
= 1;
18662 /* Maybe insert a truncation at the left. */
18663 if (it
->first_visible_x
18664 && IT_CHARPOS (*it
) > 0)
18666 if (!FRAME_WINDOW_P (it
->f
))
18667 insert_left_trunc_glyphs (it
);
18668 it
->glyph_row
->truncated_on_left_p
= 1;
18671 it
->face_id
= saved_face_id
;
18673 /* Value is number of columns displayed. */
18674 return it
->hpos
- hpos_at_start
;
18679 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
18680 appears as an element of LIST or as the car of an element of LIST.
18681 If PROPVAL is a list, compare each element against LIST in that
18682 way, and return 1/2 if any element of PROPVAL is found in LIST.
18683 Otherwise return 0. This function cannot quit.
18684 The return value is 2 if the text is invisible but with an ellipsis
18685 and 1 if it's invisible and without an ellipsis. */
18688 invisible_p (propval
, list
)
18689 register Lisp_Object propval
;
18692 register Lisp_Object tail
, proptail
;
18694 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18696 register Lisp_Object tem
;
18698 if (EQ (propval
, tem
))
18700 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
18701 return NILP (XCDR (tem
)) ? 1 : 2;
18704 if (CONSP (propval
))
18706 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
18708 Lisp_Object propelt
;
18709 propelt
= XCAR (proptail
);
18710 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18712 register Lisp_Object tem
;
18714 if (EQ (propelt
, tem
))
18716 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
18717 return NILP (XCDR (tem
)) ? 1 : 2;
18725 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
18726 doc
: /* Non-nil if the property makes the text invisible.
18727 POS-OR-PROP can be a marker or number, in which case it is taken to be
18728 a position in the current buffer and the value of the `invisible' property
18729 is checked; or it can be some other value, which is then presumed to be the
18730 value of the `invisible' property of the text of interest.
18731 The non-nil value returned can be t for truly invisible text or something
18732 else if the text is replaced by an ellipsis. */)
18734 Lisp_Object pos_or_prop
;
18737 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
18738 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
18740 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
18741 return (invis
== 0 ? Qnil
18743 : make_number (invis
));
18746 /* Calculate a width or height in pixels from a specification using
18747 the following elements:
18750 NUM - a (fractional) multiple of the default font width/height
18751 (NUM) - specifies exactly NUM pixels
18752 UNIT - a fixed number of pixels, see below.
18753 ELEMENT - size of a display element in pixels, see below.
18754 (NUM . SPEC) - equals NUM * SPEC
18755 (+ SPEC SPEC ...) - add pixel values
18756 (- SPEC SPEC ...) - subtract pixel values
18757 (- SPEC) - negate pixel value
18760 INT or FLOAT - a number constant
18761 SYMBOL - use symbol's (buffer local) variable binding.
18764 in - pixels per inch *)
18765 mm - pixels per 1/1000 meter *)
18766 cm - pixels per 1/100 meter *)
18767 width - width of current font in pixels.
18768 height - height of current font in pixels.
18770 *) using the ratio(s) defined in display-pixels-per-inch.
18774 left-fringe - left fringe width in pixels
18775 right-fringe - right fringe width in pixels
18777 left-margin - left margin width in pixels
18778 right-margin - right margin width in pixels
18780 scroll-bar - scroll-bar area width in pixels
18784 Pixels corresponding to 5 inches:
18787 Total width of non-text areas on left side of window (if scroll-bar is on left):
18788 '(space :width (+ left-fringe left-margin scroll-bar))
18790 Align to first text column (in header line):
18791 '(space :align-to 0)
18793 Align to middle of text area minus half the width of variable `my-image'
18794 containing a loaded image:
18795 '(space :align-to (0.5 . (- text my-image)))
18797 Width of left margin minus width of 1 character in the default font:
18798 '(space :width (- left-margin 1))
18800 Width of left margin minus width of 2 characters in the current font:
18801 '(space :width (- left-margin (2 . width)))
18803 Center 1 character over left-margin (in header line):
18804 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
18806 Different ways to express width of left fringe plus left margin minus one pixel:
18807 '(space :width (- (+ left-fringe left-margin) (1)))
18808 '(space :width (+ left-fringe left-margin (- (1))))
18809 '(space :width (+ left-fringe left-margin (-1)))
18813 #define NUMVAL(X) \
18814 ((INTEGERP (X) || FLOATP (X)) \
18819 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
18824 int width_p
, *align_to
;
18828 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
18829 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
18832 return OK_PIXELS (0);
18834 xassert (FRAME_LIVE_P (it
->f
));
18836 if (SYMBOLP (prop
))
18838 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18840 char *unit
= SDATA (SYMBOL_NAME (prop
));
18842 if (unit
[0] == 'i' && unit
[1] == 'n')
18844 else if (unit
[0] == 'm' && unit
[1] == 'm')
18846 else if (unit
[0] == 'c' && unit
[1] == 'm')
18853 #ifdef HAVE_WINDOW_SYSTEM
18854 if (FRAME_WINDOW_P (it
->f
)
18856 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
18857 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
18859 return OK_PIXELS (ppi
/ pixels
);
18862 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18863 || (CONSP (Vdisplay_pixels_per_inch
)
18865 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18866 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18868 return OK_PIXELS (ppi
/ pixels
);
18874 #ifdef HAVE_WINDOW_SYSTEM
18875 if (EQ (prop
, Qheight
))
18876 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
18877 if (EQ (prop
, Qwidth
))
18878 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
18880 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
18881 return OK_PIXELS (1);
18884 if (EQ (prop
, Qtext
))
18885 return OK_PIXELS (width_p
18886 ? window_box_width (it
->w
, TEXT_AREA
)
18887 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
18889 if (align_to
&& *align_to
< 0)
18892 if (EQ (prop
, Qleft
))
18893 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
18894 if (EQ (prop
, Qright
))
18895 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
18896 if (EQ (prop
, Qcenter
))
18897 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
18898 + window_box_width (it
->w
, TEXT_AREA
) / 2);
18899 if (EQ (prop
, Qleft_fringe
))
18900 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18901 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
18902 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
18903 if (EQ (prop
, Qright_fringe
))
18904 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18905 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18906 : window_box_right_offset (it
->w
, TEXT_AREA
));
18907 if (EQ (prop
, Qleft_margin
))
18908 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
18909 if (EQ (prop
, Qright_margin
))
18910 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
18911 if (EQ (prop
, Qscroll_bar
))
18912 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18914 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18915 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18916 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18921 if (EQ (prop
, Qleft_fringe
))
18922 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18923 if (EQ (prop
, Qright_fringe
))
18924 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18925 if (EQ (prop
, Qleft_margin
))
18926 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18927 if (EQ (prop
, Qright_margin
))
18928 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18929 if (EQ (prop
, Qscroll_bar
))
18930 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18933 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18936 if (INTEGERP (prop
) || FLOATP (prop
))
18938 int base_unit
= (width_p
18939 ? FRAME_COLUMN_WIDTH (it
->f
)
18940 : FRAME_LINE_HEIGHT (it
->f
));
18941 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18946 Lisp_Object car
= XCAR (prop
);
18947 Lisp_Object cdr
= XCDR (prop
);
18951 #ifdef HAVE_WINDOW_SYSTEM
18952 if (FRAME_WINDOW_P (it
->f
)
18953 && valid_image_p (prop
))
18955 int id
= lookup_image (it
->f
, prop
);
18956 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
18958 return OK_PIXELS (width_p
? img
->width
: img
->height
);
18961 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18967 while (CONSP (cdr
))
18969 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
18970 font
, width_p
, align_to
))
18973 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18978 if (EQ (car
, Qminus
))
18980 return OK_PIXELS (pixels
);
18983 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18986 if (INTEGERP (car
) || FLOATP (car
))
18989 pixels
= XFLOATINT (car
);
18991 return OK_PIXELS (pixels
);
18992 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
18993 font
, width_p
, align_to
))
18994 return OK_PIXELS (pixels
* fact
);
19005 /***********************************************************************
19007 ***********************************************************************/
19009 #ifdef HAVE_WINDOW_SYSTEM
19014 dump_glyph_string (s
)
19015 struct glyph_string
*s
;
19017 fprintf (stderr
, "glyph string\n");
19018 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
19019 s
->x
, s
->y
, s
->width
, s
->height
);
19020 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
19021 fprintf (stderr
, " hl = %d\n", s
->hl
);
19022 fprintf (stderr
, " left overhang = %d, right = %d\n",
19023 s
->left_overhang
, s
->right_overhang
);
19024 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
19025 fprintf (stderr
, " extends to end of line = %d\n",
19026 s
->extends_to_end_of_line_p
);
19027 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
19028 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
19031 #endif /* GLYPH_DEBUG */
19033 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
19034 of XChar2b structures for S; it can't be allocated in
19035 init_glyph_string because it must be allocated via `alloca'. W
19036 is the window on which S is drawn. ROW and AREA are the glyph row
19037 and area within the row from which S is constructed. START is the
19038 index of the first glyph structure covered by S. HL is a
19039 face-override for drawing S. */
19042 #define OPTIONAL_HDC(hdc) hdc,
19043 #define DECLARE_HDC(hdc) HDC hdc;
19044 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
19045 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
19048 #ifndef OPTIONAL_HDC
19049 #define OPTIONAL_HDC(hdc)
19050 #define DECLARE_HDC(hdc)
19051 #define ALLOCATE_HDC(hdc, f)
19052 #define RELEASE_HDC(hdc, f)
19056 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
19057 struct glyph_string
*s
;
19061 struct glyph_row
*row
;
19062 enum glyph_row_area area
;
19064 enum draw_glyphs_face hl
;
19066 bzero (s
, sizeof *s
);
19068 s
->f
= XFRAME (w
->frame
);
19072 s
->display
= FRAME_X_DISPLAY (s
->f
);
19073 s
->window
= FRAME_X_WINDOW (s
->f
);
19074 s
->char2b
= char2b
;
19078 s
->first_glyph
= row
->glyphs
[area
] + start
;
19079 s
->height
= row
->height
;
19080 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
19082 /* Display the internal border below the tool-bar window. */
19083 if (WINDOWP (s
->f
->tool_bar_window
)
19084 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
19085 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
19087 s
->ybase
= s
->y
+ row
->ascent
;
19091 /* Append the list of glyph strings with head H and tail T to the list
19092 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
19095 append_glyph_string_lists (head
, tail
, h
, t
)
19096 struct glyph_string
**head
, **tail
;
19097 struct glyph_string
*h
, *t
;
19111 /* Prepend the list of glyph strings with head H and tail T to the
19112 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
19116 prepend_glyph_string_lists (head
, tail
, h
, t
)
19117 struct glyph_string
**head
, **tail
;
19118 struct glyph_string
*h
, *t
;
19132 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
19133 Set *HEAD and *TAIL to the resulting list. */
19136 append_glyph_string (head
, tail
, s
)
19137 struct glyph_string
**head
, **tail
;
19138 struct glyph_string
*s
;
19140 s
->next
= s
->prev
= NULL
;
19141 append_glyph_string_lists (head
, tail
, s
, s
);
19145 /* Get face and two-byte form of character C in face FACE_ID on frame
19146 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19147 means we want to display multibyte text. DISPLAY_P non-zero means
19148 make sure that X resources for the face returned are allocated.
19149 Value is a pointer to a realized face that is ready for display if
19150 DISPLAY_P is non-zero. */
19152 static INLINE
struct face
*
19153 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
19157 int multibyte_p
, display_p
;
19159 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19163 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
19165 if (code
!= FONT_INVALID_CODE
)
19166 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19168 STORE_XCHAR2B (char2b
, 0, 0);
19171 /* Make sure X resources of the face are allocated. */
19172 #ifdef HAVE_X_WINDOWS
19176 xassert (face
!= NULL
);
19177 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19184 /* Get face and two-byte form of character glyph GLYPH on frame F.
19185 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
19186 a pointer to a realized face that is ready for display. */
19188 static INLINE
struct face
*
19189 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
19191 struct glyph
*glyph
;
19197 xassert (glyph
->type
== CHAR_GLYPH
);
19198 face
= FACE_FROM_ID (f
, glyph
->face_id
);
19205 unsigned code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
19207 if (code
!= FONT_INVALID_CODE
)
19208 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19210 STORE_XCHAR2B (char2b
, 0, code
);
19213 /* Make sure X resources of the face are allocated. */
19214 xassert (face
!= NULL
);
19215 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19220 /* Fill glyph string S with composition components specified by S->cmp.
19222 BASE_FACE is the base face of the composition.
19223 S->gidx is the index of the first component for S.
19225 OVERLAPS non-zero means S should draw the foreground only, and use
19226 its physical height for clipping. See also draw_glyphs.
19228 Value is the index of a component not in S. */
19231 fill_composite_glyph_string (s
, base_face
, overlaps
)
19232 struct glyph_string
*s
;
19233 struct face
*base_face
;
19240 s
->for_overlaps
= overlaps
;
19242 if (s
->cmp
->method
== COMPOSITION_WITH_GLYPH_STRING
)
19244 Lisp_Object gstring
19245 = AREF (XHASH_TABLE (composition_hash_table
)->key_and_value
,
19246 s
->cmp
->hash_index
* 2);
19248 s
->face
= base_face
;
19249 s
->font
= base_face
->font
;
19250 for (i
= 0, s
->nchars
= 0; i
< s
->cmp
->glyph_len
; i
++, s
->nchars
++)
19252 Lisp_Object g
= LGSTRING_GLYPH (gstring
, i
);
19254 XChar2b
* store_pos
;
19257 code
= LGLYPH_CODE (g
);
19258 store_pos
= s
->char2b
+ i
;
19259 STORE_XCHAR2B (store_pos
, code
>> 8, code
& 0xFF);
19261 s
->width
= s
->cmp
->pixel_width
;
19265 /* For all glyphs of this composition, starting at the offset
19266 S->gidx, until we reach the end of the definition or encounter a
19267 glyph that requires the different face, add it to S. */
19272 for (i
= s
->gidx
; i
< s
->cmp
->glyph_len
; i
++)
19274 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
19278 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
19281 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
19282 s
->char2b
+ i
, 1, 1);
19288 s
->font
= s
->face
->font
;
19290 else if (s
->face
!= face
)
19297 /* All glyph strings for the same composition has the same width,
19298 i.e. the width set for the first component of the composition. */
19299 s
->width
= s
->first_glyph
->pixel_width
;
19302 /* If the specified font could not be loaded, use the frame's
19303 default font, but record the fact that we couldn't load it in
19304 the glyph string so that we can draw rectangles for the
19305 characters of the glyph string. */
19306 if (s
->font
== NULL
)
19308 s
->font_not_found_p
= 1;
19309 s
->font
= FRAME_FONT (s
->f
);
19312 /* Adjust base line for subscript/superscript text. */
19313 s
->ybase
+= s
->first_glyph
->voffset
;
19315 /* This glyph string must always be drawn with 16-bit functions. */
19318 return s
->gidx
+ s
->nchars
;
19322 /* Fill glyph string S from a sequence of character glyphs.
19324 FACE_ID is the face id of the string. START is the index of the
19325 first glyph to consider, END is the index of the last + 1.
19326 OVERLAPS non-zero means S should draw the foreground only, and use
19327 its physical height for clipping. See also draw_glyphs.
19329 Value is the index of the first glyph not in S. */
19332 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
19333 struct glyph_string
*s
;
19335 int start
, end
, overlaps
;
19337 struct glyph
*glyph
, *last
;
19339 int glyph_not_available_p
;
19341 xassert (s
->f
== XFRAME (s
->w
->frame
));
19342 xassert (s
->nchars
== 0);
19343 xassert (start
>= 0 && end
> start
);
19345 s
->for_overlaps
= overlaps
,
19346 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19347 last
= s
->row
->glyphs
[s
->area
] + end
;
19348 voffset
= glyph
->voffset
;
19349 s
->padding_p
= glyph
->padding_p
;
19350 glyph_not_available_p
= glyph
->glyph_not_available_p
;
19352 while (glyph
< last
19353 && glyph
->type
== CHAR_GLYPH
19354 && glyph
->voffset
== voffset
19355 /* Same face id implies same font, nowadays. */
19356 && glyph
->face_id
== face_id
19357 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
19361 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
19362 s
->char2b
+ s
->nchars
,
19364 s
->two_byte_p
= two_byte_p
;
19366 xassert (s
->nchars
<= end
- start
);
19367 s
->width
+= glyph
->pixel_width
;
19368 if (glyph
++->padding_p
!= s
->padding_p
)
19372 s
->font
= s
->face
->font
;
19374 /* If the specified font could not be loaded, use the frame's font,
19375 but record the fact that we couldn't load it in
19376 S->font_not_found_p so that we can draw rectangles for the
19377 characters of the glyph string. */
19378 if (s
->font
== NULL
|| glyph_not_available_p
)
19380 s
->font_not_found_p
= 1;
19381 s
->font
= FRAME_FONT (s
->f
);
19384 /* Adjust base line for subscript/superscript text. */
19385 s
->ybase
+= voffset
;
19387 xassert (s
->face
&& s
->face
->gc
);
19388 return glyph
- s
->row
->glyphs
[s
->area
];
19392 /* Fill glyph string S from image glyph S->first_glyph. */
19395 fill_image_glyph_string (s
)
19396 struct glyph_string
*s
;
19398 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
19399 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
19401 s
->slice
= s
->first_glyph
->slice
;
19402 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
19403 s
->font
= s
->face
->font
;
19404 s
->width
= s
->first_glyph
->pixel_width
;
19406 /* Adjust base line for subscript/superscript text. */
19407 s
->ybase
+= s
->first_glyph
->voffset
;
19411 /* Fill glyph string S from a sequence of stretch glyphs.
19413 ROW is the glyph row in which the glyphs are found, AREA is the
19414 area within the row. START is the index of the first glyph to
19415 consider, END is the index of the last + 1.
19417 Value is the index of the first glyph not in S. */
19420 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
19421 struct glyph_string
*s
;
19422 struct glyph_row
*row
;
19423 enum glyph_row_area area
;
19426 struct glyph
*glyph
, *last
;
19427 int voffset
, face_id
;
19429 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
19431 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19432 last
= s
->row
->glyphs
[s
->area
] + end
;
19433 face_id
= glyph
->face_id
;
19434 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19435 s
->font
= s
->face
->font
;
19436 s
->width
= glyph
->pixel_width
;
19438 voffset
= glyph
->voffset
;
19442 && glyph
->type
== STRETCH_GLYPH
19443 && glyph
->voffset
== voffset
19444 && glyph
->face_id
== face_id
);
19446 s
->width
+= glyph
->pixel_width
;
19448 /* Adjust base line for subscript/superscript text. */
19449 s
->ybase
+= voffset
;
19451 /* The case that face->gc == 0 is handled when drawing the glyph
19452 string by calling PREPARE_FACE_FOR_DISPLAY. */
19454 return glyph
- s
->row
->glyphs
[s
->area
];
19457 static struct font_metrics
*
19458 get_per_char_metric (f
, font
, char2b
)
19463 static struct font_metrics metrics
;
19464 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
19465 struct font
*fontp
;
19467 if (! font
|| code
== FONT_INVALID_CODE
)
19469 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
19474 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
19475 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
19476 assumed to be zero. */
19479 x_get_glyph_overhangs (glyph
, f
, left
, right
)
19480 struct glyph
*glyph
;
19484 *left
= *right
= 0;
19486 if (glyph
->type
== CHAR_GLYPH
)
19490 struct font_metrics
*pcm
;
19492 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
19493 if (face
->font
&& (pcm
= get_per_char_metric (f
, face
->font
, &char2b
)))
19495 if (pcm
->rbearing
> pcm
->width
)
19496 *right
= pcm
->rbearing
- pcm
->width
;
19497 if (pcm
->lbearing
< 0)
19498 *left
= -pcm
->lbearing
;
19501 else if (glyph
->type
== COMPOSITE_GLYPH
)
19503 struct composition
*cmp
= composition_table
[glyph
->u
.cmp_id
];
19505 *right
= cmp
->rbearing
- cmp
->pixel_width
;
19506 *left
= - cmp
->lbearing
;
19511 /* Return the index of the first glyph preceding glyph string S that
19512 is overwritten by S because of S's left overhang. Value is -1
19513 if no glyphs are overwritten. */
19516 left_overwritten (s
)
19517 struct glyph_string
*s
;
19521 if (s
->left_overhang
)
19524 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19525 int first
= s
->first_glyph
- glyphs
;
19527 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
19528 x
-= glyphs
[i
].pixel_width
;
19539 /* Return the index of the first glyph preceding glyph string S that
19540 is overwriting S because of its right overhang. Value is -1 if no
19541 glyph in front of S overwrites S. */
19544 left_overwriting (s
)
19545 struct glyph_string
*s
;
19548 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19549 int first
= s
->first_glyph
- glyphs
;
19553 for (i
= first
- 1; i
>= 0; --i
)
19556 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19559 x
-= glyphs
[i
].pixel_width
;
19566 /* Return the index of the last glyph following glyph string S that is
19567 not overwritten by S because of S's right overhang. Value is -1 if
19568 no such glyph is found. */
19571 right_overwritten (s
)
19572 struct glyph_string
*s
;
19576 if (s
->right_overhang
)
19579 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19580 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19581 int end
= s
->row
->used
[s
->area
];
19583 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
19584 x
+= glyphs
[i
].pixel_width
;
19593 /* Return the index of the last glyph following glyph string S that
19594 overwrites S because of its left overhang. Value is negative
19595 if no such glyph is found. */
19598 right_overwriting (s
)
19599 struct glyph_string
*s
;
19602 int end
= s
->row
->used
[s
->area
];
19603 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19604 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19608 for (i
= first
; i
< end
; ++i
)
19611 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19614 x
+= glyphs
[i
].pixel_width
;
19621 /* Set background width of glyph string S. START is the index of the
19622 first glyph following S. LAST_X is the right-most x-position + 1
19623 in the drawing area. */
19626 set_glyph_string_background_width (s
, start
, last_x
)
19627 struct glyph_string
*s
;
19631 /* If the face of this glyph string has to be drawn to the end of
19632 the drawing area, set S->extends_to_end_of_line_p. */
19634 if (start
== s
->row
->used
[s
->area
]
19635 && s
->area
== TEXT_AREA
19636 && ((s
->row
->fill_line_p
19637 && (s
->hl
== DRAW_NORMAL_TEXT
19638 || s
->hl
== DRAW_IMAGE_RAISED
19639 || s
->hl
== DRAW_IMAGE_SUNKEN
))
19640 || s
->hl
== DRAW_MOUSE_FACE
))
19641 s
->extends_to_end_of_line_p
= 1;
19643 /* If S extends its face to the end of the line, set its
19644 background_width to the distance to the right edge of the drawing
19646 if (s
->extends_to_end_of_line_p
)
19647 s
->background_width
= last_x
- s
->x
+ 1;
19649 s
->background_width
= s
->width
;
19653 /* Compute overhangs and x-positions for glyph string S and its
19654 predecessors, or successors. X is the starting x-position for S.
19655 BACKWARD_P non-zero means process predecessors. */
19658 compute_overhangs_and_x (s
, x
, backward_p
)
19659 struct glyph_string
*s
;
19667 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
19668 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
19678 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
19679 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
19689 /* The following macros are only called from draw_glyphs below.
19690 They reference the following parameters of that function directly:
19691 `w', `row', `area', and `overlap_p'
19692 as well as the following local variables:
19693 `s', `f', and `hdc' (in W32) */
19696 /* On W32, silently add local `hdc' variable to argument list of
19697 init_glyph_string. */
19698 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19699 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
19701 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19702 init_glyph_string (s, char2b, w, row, area, start, hl)
19705 /* Add a glyph string for a stretch glyph to the list of strings
19706 between HEAD and TAIL. START is the index of the stretch glyph in
19707 row area AREA of glyph row ROW. END is the index of the last glyph
19708 in that glyph row area. X is the current output position assigned
19709 to the new glyph string constructed. HL overrides that face of the
19710 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19711 is the right-most x-position of the drawing area. */
19713 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
19714 and below -- keep them on one line. */
19715 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19718 s = (struct glyph_string *) alloca (sizeof *s); \
19719 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19720 START = fill_stretch_glyph_string (s, row, area, START, END); \
19721 append_glyph_string (&HEAD, &TAIL, s); \
19727 /* Add a glyph string for an image glyph to the list of strings
19728 between HEAD and TAIL. START is the index of the image glyph in
19729 row area AREA of glyph row ROW. END is the index of the last glyph
19730 in that glyph row area. X is the current output position assigned
19731 to the new glyph string constructed. HL overrides that face of the
19732 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19733 is the right-most x-position of the drawing area. */
19735 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19738 s = (struct glyph_string *) alloca (sizeof *s); \
19739 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19740 fill_image_glyph_string (s); \
19741 append_glyph_string (&HEAD, &TAIL, s); \
19748 /* Add a glyph string for a sequence of character glyphs to the list
19749 of strings between HEAD and TAIL. START is the index of the first
19750 glyph in row area AREA of glyph row ROW that is part of the new
19751 glyph string. END is the index of the last glyph in that glyph row
19752 area. X is the current output position assigned to the new glyph
19753 string constructed. HL overrides that face of the glyph; e.g. it
19754 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
19755 right-most x-position of the drawing area. */
19757 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19763 face_id = (row)->glyphs[area][START].face_id; \
19765 s = (struct glyph_string *) alloca (sizeof *s); \
19766 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
19767 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
19768 append_glyph_string (&HEAD, &TAIL, s); \
19770 START = fill_glyph_string (s, face_id, START, END, overlaps); \
19775 /* Add a glyph string for a composite sequence to the list of strings
19776 between HEAD and TAIL. START is the index of the first glyph in
19777 row area AREA of glyph row ROW that is part of the new glyph
19778 string. END is the index of the last glyph in that glyph row area.
19779 X is the current output position assigned to the new glyph string
19780 constructed. HL overrides that face of the glyph; e.g. it is
19781 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
19782 x-position of the drawing area. */
19784 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19786 int face_id = (row)->glyphs[area][START].face_id; \
19787 struct face *base_face = FACE_FROM_ID (f, face_id); \
19788 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
19789 struct composition *cmp = composition_table[cmp_id]; \
19791 struct glyph_string *first_s; \
19794 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
19796 /* Make glyph_strings for each glyph sequence that is drawable by \
19797 the same face, and append them to HEAD/TAIL. */ \
19798 for (n = 0; n < cmp->glyph_len;) \
19800 s = (struct glyph_string *) alloca (sizeof *s); \
19801 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
19802 append_glyph_string (&(HEAD), &(TAIL), s); \
19808 n = fill_composite_glyph_string (s, base_face, overlaps); \
19816 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
19817 of AREA of glyph row ROW on window W between indices START and END.
19818 HL overrides the face for drawing glyph strings, e.g. it is
19819 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
19820 x-positions of the drawing area.
19822 This is an ugly monster macro construct because we must use alloca
19823 to allocate glyph strings (because draw_glyphs can be called
19824 asynchronously). */
19826 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19829 HEAD = TAIL = NULL; \
19830 while (START < END) \
19832 struct glyph *first_glyph = (row)->glyphs[area] + START; \
19833 switch (first_glyph->type) \
19836 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
19840 case COMPOSITE_GLYPH: \
19841 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
19845 case STRETCH_GLYPH: \
19846 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
19850 case IMAGE_GLYPH: \
19851 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
19861 set_glyph_string_background_width (s, START, LAST_X); \
19869 /* Draw glyphs between START and END in AREA of ROW on window W,
19870 starting at x-position X. X is relative to AREA in W. HL is a
19871 face-override with the following meaning:
19873 DRAW_NORMAL_TEXT draw normally
19874 DRAW_CURSOR draw in cursor face
19875 DRAW_MOUSE_FACE draw in mouse face.
19876 DRAW_INVERSE_VIDEO draw in mode line face
19877 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
19878 DRAW_IMAGE_RAISED draw an image with a raised relief around it
19880 If OVERLAPS is non-zero, draw only the foreground of characters and
19881 clip to the physical height of ROW. Non-zero value also defines
19882 the overlapping part to be drawn:
19884 OVERLAPS_PRED overlap with preceding rows
19885 OVERLAPS_SUCC overlap with succeeding rows
19886 OVERLAPS_BOTH overlap with both preceding/succeeding rows
19887 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
19889 Value is the x-position reached, relative to AREA of W. */
19892 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
19895 struct glyph_row
*row
;
19896 enum glyph_row_area area
;
19897 EMACS_INT start
, end
;
19898 enum draw_glyphs_face hl
;
19901 struct glyph_string
*head
, *tail
;
19902 struct glyph_string
*s
;
19903 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
19904 int i
, j
, x_reached
, last_x
, area_left
= 0;
19905 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19908 ALLOCATE_HDC (hdc
, f
);
19910 /* Let's rather be paranoid than getting a SEGV. */
19911 end
= min (end
, row
->used
[area
]);
19912 start
= max (0, start
);
19913 start
= min (end
, start
);
19915 /* Translate X to frame coordinates. Set last_x to the right
19916 end of the drawing area. */
19917 if (row
->full_width_p
)
19919 /* X is relative to the left edge of W, without scroll bars
19921 area_left
= WINDOW_LEFT_EDGE_X (w
);
19922 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
19926 area_left
= window_box_left (w
, area
);
19927 last_x
= area_left
+ window_box_width (w
, area
);
19931 /* Build a doubly-linked list of glyph_string structures between
19932 head and tail from what we have to draw. Note that the macro
19933 BUILD_GLYPH_STRINGS will modify its start parameter. That's
19934 the reason we use a separate variable `i'. */
19936 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
19938 x_reached
= tail
->x
+ tail
->background_width
;
19942 /* If there are any glyphs with lbearing < 0 or rbearing > width in
19943 the row, redraw some glyphs in front or following the glyph
19944 strings built above. */
19945 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
19947 struct glyph_string
*h
, *t
;
19948 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
19949 int mouse_beg_col
, mouse_end_col
, check_mouse_face
= 0;
19952 /* If mouse highlighting is on, we may need to draw adjacent
19953 glyphs using mouse-face highlighting. */
19954 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
19956 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
19958 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
19959 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
19961 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
19963 check_mouse_face
= 1;
19964 mouse_beg_col
= (row
== mouse_beg_row
)
19965 ? dpyinfo
->mouse_face_beg_col
: 0;
19966 mouse_end_col
= (row
== mouse_end_row
)
19967 ? dpyinfo
->mouse_face_end_col
19968 : row
->used
[TEXT_AREA
];
19972 /* Compute overhangs for all glyph strings. */
19973 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
19974 for (s
= head
; s
; s
= s
->next
)
19975 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
19977 /* Prepend glyph strings for glyphs in front of the first glyph
19978 string that are overwritten because of the first glyph
19979 string's left overhang. The background of all strings
19980 prepended must be drawn because the first glyph string
19982 i
= left_overwritten (head
);
19985 enum draw_glyphs_face overlap_hl
;
19987 /* If this row contains mouse highlighting, attempt to draw
19988 the overlapped glyphs with the correct highlight. This
19989 code fails if the overlap encompasses more than one glyph
19990 and mouse-highlight spans only some of these glyphs.
19991 However, making it work perfectly involves a lot more
19992 code, and I don't know if the pathological case occurs in
19993 practice, so we'll stick to this for now. --- cyd */
19994 if (check_mouse_face
19995 && mouse_beg_col
< start
&& mouse_end_col
> i
)
19996 overlap_hl
= DRAW_MOUSE_FACE
;
19998 overlap_hl
= DRAW_NORMAL_TEXT
;
20001 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
20002 overlap_hl
, dummy_x
, last_x
);
20003 compute_overhangs_and_x (t
, head
->x
, 1);
20004 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20008 /* Prepend glyph strings for glyphs in front of the first glyph
20009 string that overwrite that glyph string because of their
20010 right overhang. For these strings, only the foreground must
20011 be drawn, because it draws over the glyph string at `head'.
20012 The background must not be drawn because this would overwrite
20013 right overhangs of preceding glyphs for which no glyph
20015 i
= left_overwriting (head
);
20018 enum draw_glyphs_face overlap_hl
;
20020 if (check_mouse_face
20021 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20022 overlap_hl
= DRAW_MOUSE_FACE
;
20024 overlap_hl
= DRAW_NORMAL_TEXT
;
20027 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
20028 overlap_hl
, dummy_x
, last_x
);
20029 for (s
= h
; s
; s
= s
->next
)
20030 s
->background_filled_p
= 1;
20031 compute_overhangs_and_x (t
, head
->x
, 1);
20032 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20035 /* Append glyphs strings for glyphs following the last glyph
20036 string tail that are overwritten by tail. The background of
20037 these strings has to be drawn because tail's foreground draws
20039 i
= right_overwritten (tail
);
20042 enum draw_glyphs_face overlap_hl
;
20044 if (check_mouse_face
20045 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20046 overlap_hl
= DRAW_MOUSE_FACE
;
20048 overlap_hl
= DRAW_NORMAL_TEXT
;
20050 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20051 overlap_hl
, x
, last_x
);
20052 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20053 append_glyph_string_lists (&head
, &tail
, h
, t
);
20057 /* Append glyph strings for glyphs following the last glyph
20058 string tail that overwrite tail. The foreground of such
20059 glyphs has to be drawn because it writes into the background
20060 of tail. The background must not be drawn because it could
20061 paint over the foreground of following glyphs. */
20062 i
= right_overwriting (tail
);
20065 enum draw_glyphs_face overlap_hl
;
20066 if (check_mouse_face
20067 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20068 overlap_hl
= DRAW_MOUSE_FACE
;
20070 overlap_hl
= DRAW_NORMAL_TEXT
;
20073 i
++; /* We must include the Ith glyph. */
20074 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20075 overlap_hl
, x
, last_x
);
20076 for (s
= h
; s
; s
= s
->next
)
20077 s
->background_filled_p
= 1;
20078 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20079 append_glyph_string_lists (&head
, &tail
, h
, t
);
20081 if (clip_head
|| clip_tail
)
20082 for (s
= head
; s
; s
= s
->next
)
20084 s
->clip_head
= clip_head
;
20085 s
->clip_tail
= clip_tail
;
20089 /* Draw all strings. */
20090 for (s
= head
; s
; s
= s
->next
)
20091 FRAME_RIF (f
)->draw_glyph_string (s
);
20093 if (area
== TEXT_AREA
20094 && !row
->full_width_p
20095 /* When drawing overlapping rows, only the glyph strings'
20096 foreground is drawn, which doesn't erase a cursor
20100 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
20101 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
20102 : (tail
? tail
->x
+ tail
->background_width
: x
));
20106 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
20107 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
20110 /* Value is the x-position up to which drawn, relative to AREA of W.
20111 This doesn't include parts drawn because of overhangs. */
20112 if (row
->full_width_p
)
20113 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
20115 x_reached
-= area_left
;
20117 RELEASE_HDC (hdc
, f
);
20122 /* Expand row matrix if too narrow. Don't expand if area
20125 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
20127 if (!fonts_changed_p \
20128 && (it->glyph_row->glyphs[area] \
20129 < it->glyph_row->glyphs[area + 1])) \
20131 it->w->ncols_scale_factor++; \
20132 fonts_changed_p = 1; \
20136 /* Store one glyph for IT->char_to_display in IT->glyph_row.
20137 Called from x_produce_glyphs when IT->glyph_row is non-null. */
20143 struct glyph
*glyph
;
20144 enum glyph_row_area area
= it
->area
;
20146 xassert (it
->glyph_row
);
20147 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
20149 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20150 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20152 glyph
->charpos
= CHARPOS (it
->position
);
20153 glyph
->object
= it
->object
;
20154 if (it
->pixel_width
> 0)
20156 glyph
->pixel_width
= it
->pixel_width
;
20157 glyph
->padding_p
= 0;
20161 /* Assure at least 1-pixel width. Otherwise, cursor can't
20162 be displayed correctly. */
20163 glyph
->pixel_width
= 1;
20164 glyph
->padding_p
= 1;
20166 glyph
->ascent
= it
->ascent
;
20167 glyph
->descent
= it
->descent
;
20168 glyph
->voffset
= it
->voffset
;
20169 glyph
->type
= CHAR_GLYPH
;
20170 glyph
->multibyte_p
= it
->multibyte_p
;
20171 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20172 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20173 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20174 || it
->phys_descent
> it
->descent
);
20175 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
20176 glyph
->face_id
= it
->face_id
;
20177 glyph
->u
.ch
= it
->char_to_display
;
20178 glyph
->slice
= null_glyph_slice
;
20179 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20180 ++it
->glyph_row
->used
[area
];
20183 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20186 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
20187 Called from x_produce_glyphs when IT->glyph_row is non-null. */
20190 append_composite_glyph (it
)
20193 struct glyph
*glyph
;
20194 enum glyph_row_area area
= it
->area
;
20196 xassert (it
->glyph_row
);
20198 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20199 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20201 glyph
->charpos
= CHARPOS (it
->position
);
20202 glyph
->object
= it
->object
;
20203 glyph
->pixel_width
= it
->pixel_width
;
20204 glyph
->ascent
= it
->ascent
;
20205 glyph
->descent
= it
->descent
;
20206 glyph
->voffset
= it
->voffset
;
20207 glyph
->type
= COMPOSITE_GLYPH
;
20208 glyph
->multibyte_p
= it
->multibyte_p
;
20209 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20210 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20211 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20212 || it
->phys_descent
> it
->descent
);
20213 glyph
->padding_p
= 0;
20214 glyph
->glyph_not_available_p
= 0;
20215 glyph
->face_id
= it
->face_id
;
20216 glyph
->u
.cmp_id
= it
->cmp_id
;
20217 glyph
->slice
= null_glyph_slice
;
20218 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20219 ++it
->glyph_row
->used
[area
];
20222 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20226 /* Change IT->ascent and IT->height according to the setting of
20230 take_vertical_position_into_account (it
)
20235 if (it
->voffset
< 0)
20236 /* Increase the ascent so that we can display the text higher
20238 it
->ascent
-= it
->voffset
;
20240 /* Increase the descent so that we can display the text lower
20242 it
->descent
+= it
->voffset
;
20247 /* Produce glyphs/get display metrics for the image IT is loaded with.
20248 See the description of struct display_iterator in dispextern.h for
20249 an overview of struct display_iterator. */
20252 produce_image_glyph (it
)
20257 int glyph_ascent
, crop
;
20258 struct glyph_slice slice
;
20260 xassert (it
->what
== IT_IMAGE
);
20262 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20264 /* Make sure X resources of the face is loaded. */
20265 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20267 if (it
->image_id
< 0)
20269 /* Fringe bitmap. */
20270 it
->ascent
= it
->phys_ascent
= 0;
20271 it
->descent
= it
->phys_descent
= 0;
20272 it
->pixel_width
= 0;
20277 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
20279 /* Make sure X resources of the image is loaded. */
20280 prepare_image_for_display (it
->f
, img
);
20282 slice
.x
= slice
.y
= 0;
20283 slice
.width
= img
->width
;
20284 slice
.height
= img
->height
;
20286 if (INTEGERP (it
->slice
.x
))
20287 slice
.x
= XINT (it
->slice
.x
);
20288 else if (FLOATP (it
->slice
.x
))
20289 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
20291 if (INTEGERP (it
->slice
.y
))
20292 slice
.y
= XINT (it
->slice
.y
);
20293 else if (FLOATP (it
->slice
.y
))
20294 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
20296 if (INTEGERP (it
->slice
.width
))
20297 slice
.width
= XINT (it
->slice
.width
);
20298 else if (FLOATP (it
->slice
.width
))
20299 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
20301 if (INTEGERP (it
->slice
.height
))
20302 slice
.height
= XINT (it
->slice
.height
);
20303 else if (FLOATP (it
->slice
.height
))
20304 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
20306 if (slice
.x
>= img
->width
)
20307 slice
.x
= img
->width
;
20308 if (slice
.y
>= img
->height
)
20309 slice
.y
= img
->height
;
20310 if (slice
.x
+ slice
.width
>= img
->width
)
20311 slice
.width
= img
->width
- slice
.x
;
20312 if (slice
.y
+ slice
.height
> img
->height
)
20313 slice
.height
= img
->height
- slice
.y
;
20315 if (slice
.width
== 0 || slice
.height
== 0)
20318 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
20320 it
->descent
= slice
.height
- glyph_ascent
;
20322 it
->descent
+= img
->vmargin
;
20323 if (slice
.y
+ slice
.height
== img
->height
)
20324 it
->descent
+= img
->vmargin
;
20325 it
->phys_descent
= it
->descent
;
20327 it
->pixel_width
= slice
.width
;
20329 it
->pixel_width
+= img
->hmargin
;
20330 if (slice
.x
+ slice
.width
== img
->width
)
20331 it
->pixel_width
+= img
->hmargin
;
20333 /* It's quite possible for images to have an ascent greater than
20334 their height, so don't get confused in that case. */
20335 if (it
->descent
< 0)
20338 #if 0 /* this breaks image tiling */
20339 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
20340 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
20341 if (face_ascent
> it
->ascent
)
20342 it
->ascent
= it
->phys_ascent
= face_ascent
;
20347 if (face
->box
!= FACE_NO_BOX
)
20349 if (face
->box_line_width
> 0)
20352 it
->ascent
+= face
->box_line_width
;
20353 if (slice
.y
+ slice
.height
== img
->height
)
20354 it
->descent
+= face
->box_line_width
;
20357 if (it
->start_of_box_run_p
&& slice
.x
== 0)
20358 it
->pixel_width
+= eabs (face
->box_line_width
);
20359 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
20360 it
->pixel_width
+= eabs (face
->box_line_width
);
20363 take_vertical_position_into_account (it
);
20365 /* Automatically crop wide image glyphs at right edge so we can
20366 draw the cursor on same display row. */
20367 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
20368 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
20370 it
->pixel_width
-= crop
;
20371 slice
.width
-= crop
;
20376 struct glyph
*glyph
;
20377 enum glyph_row_area area
= it
->area
;
20379 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20380 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20382 glyph
->charpos
= CHARPOS (it
->position
);
20383 glyph
->object
= it
->object
;
20384 glyph
->pixel_width
= it
->pixel_width
;
20385 glyph
->ascent
= glyph_ascent
;
20386 glyph
->descent
= it
->descent
;
20387 glyph
->voffset
= it
->voffset
;
20388 glyph
->type
= IMAGE_GLYPH
;
20389 glyph
->multibyte_p
= it
->multibyte_p
;
20390 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20391 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20392 glyph
->overlaps_vertically_p
= 0;
20393 glyph
->padding_p
= 0;
20394 glyph
->glyph_not_available_p
= 0;
20395 glyph
->face_id
= it
->face_id
;
20396 glyph
->u
.img_id
= img
->id
;
20397 glyph
->slice
= slice
;
20398 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20399 ++it
->glyph_row
->used
[area
];
20402 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20407 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
20408 of the glyph, WIDTH and HEIGHT are the width and height of the
20409 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
20412 append_stretch_glyph (it
, object
, width
, height
, ascent
)
20414 Lisp_Object object
;
20418 struct glyph
*glyph
;
20419 enum glyph_row_area area
= it
->area
;
20421 xassert (ascent
>= 0 && ascent
<= height
);
20423 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20424 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20426 glyph
->charpos
= CHARPOS (it
->position
);
20427 glyph
->object
= object
;
20428 glyph
->pixel_width
= width
;
20429 glyph
->ascent
= ascent
;
20430 glyph
->descent
= height
- ascent
;
20431 glyph
->voffset
= it
->voffset
;
20432 glyph
->type
= STRETCH_GLYPH
;
20433 glyph
->multibyte_p
= it
->multibyte_p
;
20434 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20435 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20436 glyph
->overlaps_vertically_p
= 0;
20437 glyph
->padding_p
= 0;
20438 glyph
->glyph_not_available_p
= 0;
20439 glyph
->face_id
= it
->face_id
;
20440 glyph
->u
.stretch
.ascent
= ascent
;
20441 glyph
->u
.stretch
.height
= height
;
20442 glyph
->slice
= null_glyph_slice
;
20443 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20444 ++it
->glyph_row
->used
[area
];
20447 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20451 /* Produce a stretch glyph for iterator IT. IT->object is the value
20452 of the glyph property displayed. The value must be a list
20453 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
20456 1. `:width WIDTH' specifies that the space should be WIDTH *
20457 canonical char width wide. WIDTH may be an integer or floating
20460 2. `:relative-width FACTOR' specifies that the width of the stretch
20461 should be computed from the width of the first character having the
20462 `glyph' property, and should be FACTOR times that width.
20464 3. `:align-to HPOS' specifies that the space should be wide enough
20465 to reach HPOS, a value in canonical character units.
20467 Exactly one of the above pairs must be present.
20469 4. `:height HEIGHT' specifies that the height of the stretch produced
20470 should be HEIGHT, measured in canonical character units.
20472 5. `:relative-height FACTOR' specifies that the height of the
20473 stretch should be FACTOR times the height of the characters having
20474 the glyph property.
20476 Either none or exactly one of 4 or 5 must be present.
20478 6. `:ascent ASCENT' specifies that ASCENT percent of the height
20479 of the stretch should be used for the ascent of the stretch.
20480 ASCENT must be in the range 0 <= ASCENT <= 100. */
20483 produce_stretch_glyph (it
)
20486 /* (space :width WIDTH :height HEIGHT ...) */
20487 Lisp_Object prop
, plist
;
20488 int width
= 0, height
= 0, align_to
= -1;
20489 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
20492 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20493 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
20495 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20497 /* List should start with `space'. */
20498 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
20499 plist
= XCDR (it
->object
);
20501 /* Compute the width of the stretch. */
20502 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
20503 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
20505 /* Absolute width `:width WIDTH' specified and valid. */
20506 zero_width_ok_p
= 1;
20509 else if (prop
= Fplist_get (plist
, QCrelative_width
),
20512 /* Relative width `:relative-width FACTOR' specified and valid.
20513 Compute the width of the characters having the `glyph'
20516 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
20519 if (it
->multibyte_p
)
20521 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
20522 - IT_BYTEPOS (*it
));
20523 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
20526 it2
.c
= *p
, it2
.len
= 1;
20528 it2
.glyph_row
= NULL
;
20529 it2
.what
= IT_CHARACTER
;
20530 x_produce_glyphs (&it2
);
20531 width
= NUMVAL (prop
) * it2
.pixel_width
;
20533 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
20534 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
20536 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
20537 align_to
= (align_to
< 0
20539 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
20540 else if (align_to
< 0)
20541 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
20542 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
20543 zero_width_ok_p
= 1;
20546 /* Nothing specified -> width defaults to canonical char width. */
20547 width
= FRAME_COLUMN_WIDTH (it
->f
);
20549 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
20552 /* Compute height. */
20553 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
20554 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20557 zero_height_ok_p
= 1;
20559 else if (prop
= Fplist_get (plist
, QCrelative_height
),
20561 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
20563 height
= FONT_HEIGHT (font
);
20565 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
20568 /* Compute percentage of height used for ascent. If
20569 `:ascent ASCENT' is present and valid, use that. Otherwise,
20570 derive the ascent from the font in use. */
20571 if (prop
= Fplist_get (plist
, QCascent
),
20572 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
20573 ascent
= height
* NUMVAL (prop
) / 100.0;
20574 else if (!NILP (prop
)
20575 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20576 ascent
= min (max (0, (int)tem
), height
);
20578 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
20580 if (width
> 0 && !it
->truncate_lines_p
20581 && it
->current_x
+ width
> it
->last_visible_x
)
20582 width
= it
->last_visible_x
- it
->current_x
- 1;
20584 if (width
> 0 && height
> 0 && it
->glyph_row
)
20586 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
20587 if (!STRINGP (object
))
20588 object
= it
->w
->buffer
;
20589 append_stretch_glyph (it
, object
, width
, height
, ascent
);
20592 it
->pixel_width
= width
;
20593 it
->ascent
= it
->phys_ascent
= ascent
;
20594 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
20595 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
20597 take_vertical_position_into_account (it
);
20600 /* Get line-height and line-spacing property at point.
20601 If line-height has format (HEIGHT TOTAL), return TOTAL
20602 in TOTAL_HEIGHT. */
20605 get_line_height_property (it
, prop
)
20609 Lisp_Object position
;
20611 if (STRINGP (it
->object
))
20612 position
= make_number (IT_STRING_CHARPOS (*it
));
20613 else if (BUFFERP (it
->object
))
20614 position
= make_number (IT_CHARPOS (*it
));
20618 return Fget_char_property (position
, prop
, it
->object
);
20621 /* Calculate line-height and line-spacing properties.
20622 An integer value specifies explicit pixel value.
20623 A float value specifies relative value to current face height.
20624 A cons (float . face-name) specifies relative value to
20625 height of specified face font.
20627 Returns height in pixels, or nil. */
20631 calc_line_height_property (it
, val
, font
, boff
, override
)
20635 int boff
, override
;
20637 Lisp_Object face_name
= Qnil
;
20638 int ascent
, descent
, height
;
20640 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
20645 face_name
= XCAR (val
);
20647 if (!NUMBERP (val
))
20648 val
= make_number (1);
20649 if (NILP (face_name
))
20651 height
= it
->ascent
+ it
->descent
;
20656 if (NILP (face_name
))
20658 font
= FRAME_FONT (it
->f
);
20659 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20661 else if (EQ (face_name
, Qt
))
20670 face_id
= lookup_named_face (it
->f
, face_name
, 0);
20672 return make_number (-1);
20674 face
= FACE_FROM_ID (it
->f
, face_id
);
20677 return make_number (-1);
20678 boff
= font
->baseline_offset
;
20679 if (font
->vertical_centering
)
20680 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20683 ascent
= FONT_BASE (font
) + boff
;
20684 descent
= FONT_DESCENT (font
) - boff
;
20688 it
->override_ascent
= ascent
;
20689 it
->override_descent
= descent
;
20690 it
->override_boff
= boff
;
20693 height
= ascent
+ descent
;
20697 height
= (int)(XFLOAT_DATA (val
) * height
);
20698 else if (INTEGERP (val
))
20699 height
*= XINT (val
);
20701 return make_number (height
);
20706 Produce glyphs/get display metrics for the display element IT is
20707 loaded with. See the description of struct it in dispextern.h
20708 for an overview of struct it. */
20711 x_produce_glyphs (it
)
20714 int extra_line_spacing
= it
->extra_line_spacing
;
20716 it
->glyph_not_available_p
= 0;
20718 if (it
->what
== IT_CHARACTER
)
20722 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20723 struct font_metrics
*pcm
;
20724 int font_not_found_p
;
20725 int boff
; /* baseline offset */
20726 /* We may change it->multibyte_p upon unibyte<->multibyte
20727 conversion. So, save the current value now and restore it
20730 Note: It seems that we don't have to record multibyte_p in
20731 struct glyph because the character code itself tells if or
20732 not the character is multibyte. Thus, in the future, we must
20733 consider eliminating the field `multibyte_p' in the struct
20735 int saved_multibyte_p
= it
->multibyte_p
;
20737 /* Maybe translate single-byte characters to multibyte, or the
20739 it
->char_to_display
= it
->c
;
20740 if (!ASCII_BYTE_P (it
->c
)
20741 && ! it
->multibyte_p
)
20743 if (SINGLE_BYTE_CHAR_P (it
->c
)
20744 && unibyte_display_via_language_environment
)
20745 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20746 if (! SINGLE_BYTE_CHAR_P (it
->char_to_display
))
20748 it
->multibyte_p
= 1;
20749 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
,
20751 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20755 /* Get font to use. Encode IT->char_to_display. */
20756 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20757 &char2b
, it
->multibyte_p
, 0);
20760 /* When no suitable font found, use the default font. */
20761 font_not_found_p
= font
== NULL
;
20762 if (font_not_found_p
)
20764 font
= FRAME_FONT (it
->f
);
20765 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20769 boff
= font
->baseline_offset
;
20770 if (font
->vertical_centering
)
20771 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20774 if (it
->char_to_display
>= ' '
20775 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
20777 /* Either unibyte or ASCII. */
20782 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
20784 if (it
->override_ascent
>= 0)
20786 it
->ascent
= it
->override_ascent
;
20787 it
->descent
= it
->override_descent
;
20788 boff
= it
->override_boff
;
20792 it
->ascent
= FONT_BASE (font
) + boff
;
20793 it
->descent
= FONT_DESCENT (font
) - boff
;
20798 it
->phys_ascent
= pcm
->ascent
+ boff
;
20799 it
->phys_descent
= pcm
->descent
- boff
;
20800 it
->pixel_width
= pcm
->width
;
20804 it
->glyph_not_available_p
= 1;
20805 it
->phys_ascent
= it
->ascent
;
20806 it
->phys_descent
= it
->descent
;
20807 it
->pixel_width
= FONT_WIDTH (font
);
20810 if (it
->constrain_row_ascent_descent_p
)
20812 if (it
->descent
> it
->max_descent
)
20814 it
->ascent
+= it
->descent
- it
->max_descent
;
20815 it
->descent
= it
->max_descent
;
20817 if (it
->ascent
> it
->max_ascent
)
20819 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20820 it
->ascent
= it
->max_ascent
;
20822 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20823 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20824 extra_line_spacing
= 0;
20827 /* If this is a space inside a region of text with
20828 `space-width' property, change its width. */
20829 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
20831 it
->pixel_width
*= XFLOATINT (it
->space_width
);
20833 /* If face has a box, add the box thickness to the character
20834 height. If character has a box line to the left and/or
20835 right, add the box line width to the character's width. */
20836 if (face
->box
!= FACE_NO_BOX
)
20838 int thick
= face
->box_line_width
;
20842 it
->ascent
+= thick
;
20843 it
->descent
+= thick
;
20848 if (it
->start_of_box_run_p
)
20849 it
->pixel_width
+= thick
;
20850 if (it
->end_of_box_run_p
)
20851 it
->pixel_width
+= thick
;
20854 /* If face has an overline, add the height of the overline
20855 (1 pixel) and a 1 pixel margin to the character height. */
20856 if (face
->overline_p
)
20857 it
->ascent
+= overline_margin
;
20859 if (it
->constrain_row_ascent_descent_p
)
20861 if (it
->ascent
> it
->max_ascent
)
20862 it
->ascent
= it
->max_ascent
;
20863 if (it
->descent
> it
->max_descent
)
20864 it
->descent
= it
->max_descent
;
20867 take_vertical_position_into_account (it
);
20869 /* If we have to actually produce glyphs, do it. */
20874 /* Translate a space with a `space-width' property
20875 into a stretch glyph. */
20876 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
20877 / FONT_HEIGHT (font
));
20878 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20879 it
->ascent
+ it
->descent
, ascent
);
20884 /* If characters with lbearing or rbearing are displayed
20885 in this line, record that fact in a flag of the
20886 glyph row. This is used to optimize X output code. */
20887 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
20888 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20890 if (! stretched_p
&& it
->pixel_width
== 0)
20891 /* We assure that all visible glyphs have at least 1-pixel
20893 it
->pixel_width
= 1;
20895 else if (it
->char_to_display
== '\n')
20897 /* A newline has no width but we need the height of the line.
20898 But if previous part of the line set a height, don't
20899 increase that height */
20901 Lisp_Object height
;
20902 Lisp_Object total_height
= Qnil
;
20904 it
->override_ascent
= -1;
20905 it
->pixel_width
= 0;
20908 height
= get_line_height_property(it
, Qline_height
);
20909 /* Split (line-height total-height) list */
20911 && CONSP (XCDR (height
))
20912 && NILP (XCDR (XCDR (height
))))
20914 total_height
= XCAR (XCDR (height
));
20915 height
= XCAR (height
);
20917 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
20919 if (it
->override_ascent
>= 0)
20921 it
->ascent
= it
->override_ascent
;
20922 it
->descent
= it
->override_descent
;
20923 boff
= it
->override_boff
;
20927 it
->ascent
= FONT_BASE (font
) + boff
;
20928 it
->descent
= FONT_DESCENT (font
) - boff
;
20931 if (EQ (height
, Qt
))
20933 if (it
->descent
> it
->max_descent
)
20935 it
->ascent
+= it
->descent
- it
->max_descent
;
20936 it
->descent
= it
->max_descent
;
20938 if (it
->ascent
> it
->max_ascent
)
20940 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20941 it
->ascent
= it
->max_ascent
;
20943 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20944 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20945 it
->constrain_row_ascent_descent_p
= 1;
20946 extra_line_spacing
= 0;
20950 Lisp_Object spacing
;
20952 it
->phys_ascent
= it
->ascent
;
20953 it
->phys_descent
= it
->descent
;
20955 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
20956 && face
->box
!= FACE_NO_BOX
20957 && face
->box_line_width
> 0)
20959 it
->ascent
+= face
->box_line_width
;
20960 it
->descent
+= face
->box_line_width
;
20963 && XINT (height
) > it
->ascent
+ it
->descent
)
20964 it
->ascent
= XINT (height
) - it
->descent
;
20966 if (!NILP (total_height
))
20967 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
20970 spacing
= get_line_height_property(it
, Qline_spacing
);
20971 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
20973 if (INTEGERP (spacing
))
20975 extra_line_spacing
= XINT (spacing
);
20976 if (!NILP (total_height
))
20977 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
20981 else if (it
->char_to_display
== '\t')
20983 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
20984 int x
= it
->current_x
+ it
->continuation_lines_width
;
20985 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
20987 /* If the distance from the current position to the next tab
20988 stop is less than a space character width, use the
20989 tab stop after that. */
20990 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
20991 next_tab_x
+= tab_width
;
20993 it
->pixel_width
= next_tab_x
- x
;
20995 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
20996 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21000 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21001 it
->ascent
+ it
->descent
, it
->ascent
);
21006 /* A multi-byte character. Assume that the display width of the
21007 character is the width of the character multiplied by the
21008 width of the font. */
21010 /* If we found a font, this font should give us the right
21011 metrics. If we didn't find a font, use the frame's
21012 default font and calculate the width of the character by
21013 multiplying the width of font by the width of the
21016 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21018 if (font_not_found_p
|| !pcm
)
21020 int char_width
= CHAR_WIDTH (it
->char_to_display
);
21022 if (char_width
== 0)
21023 /* This is a non spacing character. But, as we are
21024 going to display an empty box, the box must occupy
21025 at least one column. */
21027 it
->glyph_not_available_p
= 1;
21028 it
->pixel_width
= FRAME_COLUMN_WIDTH (it
->f
) * char_width
;
21029 it
->phys_ascent
= FONT_BASE (font
) + boff
;
21030 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21034 it
->pixel_width
= pcm
->width
;
21035 it
->phys_ascent
= pcm
->ascent
+ boff
;
21036 it
->phys_descent
= pcm
->descent
- boff
;
21038 && (pcm
->lbearing
< 0
21039 || pcm
->rbearing
> pcm
->width
))
21040 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21043 it
->ascent
= FONT_BASE (font
) + boff
;
21044 it
->descent
= FONT_DESCENT (font
) - boff
;
21045 if (face
->box
!= FACE_NO_BOX
)
21047 int thick
= face
->box_line_width
;
21051 it
->ascent
+= thick
;
21052 it
->descent
+= thick
;
21057 if (it
->start_of_box_run_p
)
21058 it
->pixel_width
+= thick
;
21059 if (it
->end_of_box_run_p
)
21060 it
->pixel_width
+= thick
;
21063 /* If face has an overline, add the height of the overline
21064 (1 pixel) and a 1 pixel margin to the character height. */
21065 if (face
->overline_p
)
21066 it
->ascent
+= overline_margin
;
21068 take_vertical_position_into_account (it
);
21070 if (it
->ascent
< 0)
21072 if (it
->descent
< 0)
21077 if (it
->pixel_width
== 0)
21078 /* We assure that all visible glyphs have at least 1-pixel
21080 it
->pixel_width
= 1;
21082 it
->multibyte_p
= saved_multibyte_p
;
21084 else if (it
->what
== IT_COMPOSITION
)
21086 /* Note: A composition is represented as one glyph in the
21087 glyph matrix. There are no padding glyphs.
21089 Important is that pixel_width, ascent, and descent are the
21090 values of what is drawn by draw_glyphs (i.e. the values of
21091 the overall glyphs composed). */
21092 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21093 int boff
; /* baseline offset */
21094 struct composition
*cmp
= composition_table
[it
->cmp_id
];
21095 int glyph_len
= cmp
->glyph_len
;
21096 struct font
*font
= face
->font
;
21100 if (cmp
->method
== COMPOSITION_WITH_GLYPH_STRING
)
21102 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21103 font_prepare_composition (cmp
, it
->f
);
21106 /* If we have not yet calculated pixel size data of glyphs of
21107 the composition for the current face font, calculate them
21108 now. Theoretically, we have to check all fonts for the
21109 glyphs, but that requires much time and memory space. So,
21110 here we check only the font of the first glyph. This leads
21111 to incorrect display, but it's very rare, and C-l (recenter)
21112 can correct the display anyway. */
21113 if (! cmp
->font
|| cmp
->font
!= font
)
21115 /* Ascent and descent of the font of the first character
21116 of this composition (adjusted by baseline offset).
21117 Ascent and descent of overall glyphs should not be less
21118 than them respectively. */
21119 int font_ascent
, font_descent
, font_height
;
21120 /* Bounding box of the overall glyphs. */
21121 int leftmost
, rightmost
, lowest
, highest
;
21122 int lbearing
, rbearing
;
21123 int i
, width
, ascent
, descent
;
21124 int left_padded
= 0, right_padded
= 0;
21128 struct font_metrics
*pcm
;
21129 int font_not_found_p
;
21132 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
21133 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
21135 if (glyph_len
< cmp
->glyph_len
)
21137 for (i
= 0; i
< glyph_len
; i
++)
21139 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
21141 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21146 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
21147 : IT_CHARPOS (*it
));
21148 /* When no suitable font found, use the default font. */
21149 font_not_found_p
= font
== NULL
;
21150 if (font_not_found_p
)
21152 face
= face
->ascii_face
;
21155 boff
= font
->baseline_offset
;
21156 if (font
->vertical_centering
)
21157 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21158 font_ascent
= FONT_BASE (font
) + boff
;
21159 font_descent
= FONT_DESCENT (font
) - boff
;
21160 font_height
= FONT_HEIGHT (font
);
21162 cmp
->font
= (void *) font
;
21165 if (! font_not_found_p
)
21167 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
21168 &char2b
, it
->multibyte_p
, 0);
21169 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21172 /* Initialize the bounding box. */
21175 width
= pcm
->width
;
21176 ascent
= pcm
->ascent
;
21177 descent
= pcm
->descent
;
21178 lbearing
= pcm
->lbearing
;
21179 rbearing
= pcm
->rbearing
;
21183 width
= FONT_WIDTH (font
);
21184 ascent
= FONT_BASE (font
);
21185 descent
= FONT_DESCENT (font
);
21192 lowest
= - descent
+ boff
;
21193 highest
= ascent
+ boff
;
21195 if (! font_not_found_p
21196 && font
->default_ascent
21197 && CHAR_TABLE_P (Vuse_default_ascent
)
21198 && !NILP (Faref (Vuse_default_ascent
,
21199 make_number (it
->char_to_display
))))
21200 highest
= font
->default_ascent
+ boff
;
21202 /* Draw the first glyph at the normal position. It may be
21203 shifted to right later if some other glyphs are drawn
21205 cmp
->offsets
[i
* 2] = 0;
21206 cmp
->offsets
[i
* 2 + 1] = boff
;
21207 cmp
->lbearing
= lbearing
;
21208 cmp
->rbearing
= rbearing
;
21210 /* Set cmp->offsets for the remaining glyphs. */
21211 for (i
++; i
< glyph_len
; i
++)
21213 int left
, right
, btm
, top
;
21214 int ch
= COMPOSITION_GLYPH (cmp
, i
);
21216 struct face
*this_face
;
21221 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
21222 this_face
= FACE_FROM_ID (it
->f
, face_id
);
21223 font
= this_face
->font
;
21229 this_boff
= font
->baseline_offset
;
21230 if (font
->vertical_centering
)
21231 this_boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21232 get_char_face_and_encoding (it
->f
, ch
, face_id
,
21233 &char2b
, it
->multibyte_p
, 0);
21234 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21237 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21240 width
= pcm
->width
;
21241 ascent
= pcm
->ascent
;
21242 descent
= pcm
->descent
;
21243 lbearing
= pcm
->lbearing
;
21244 rbearing
= pcm
->rbearing
;
21245 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
21247 /* Relative composition with or without
21248 alternate chars. */
21249 left
= (leftmost
+ rightmost
- width
) / 2;
21250 btm
= - descent
+ boff
;
21251 if (font
->relative_compose
21252 && (! CHAR_TABLE_P (Vignore_relative_composition
)
21253 || NILP (Faref (Vignore_relative_composition
,
21254 make_number (ch
)))))
21257 if (- descent
>= font
->relative_compose
)
21258 /* One extra pixel between two glyphs. */
21260 else if (ascent
<= 0)
21261 /* One extra pixel between two glyphs. */
21262 btm
= lowest
- 1 - ascent
- descent
;
21267 /* A composition rule is specified by an integer
21268 value that encodes global and new reference
21269 points (GREF and NREF). GREF and NREF are
21270 specified by numbers as below:
21272 0---1---2 -- ascent
21276 9--10--11 -- center
21278 ---3---4---5--- baseline
21280 6---7---8 -- descent
21282 int rule
= COMPOSITION_RULE (cmp
, i
);
21283 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
21285 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
21286 grefx
= gref
% 3, nrefx
= nref
% 3;
21287 grefy
= gref
/ 3, nrefy
= nref
/ 3;
21289 xoff
= font_height
* (xoff
- 128) / 256;
21291 yoff
= font_height
* (yoff
- 128) / 256;
21294 + grefx
* (rightmost
- leftmost
) / 2
21295 - nrefx
* width
/ 2
21298 btm
= ((grefy
== 0 ? highest
21300 : grefy
== 2 ? lowest
21301 : (highest
+ lowest
) / 2)
21302 - (nrefy
== 0 ? ascent
+ descent
21303 : nrefy
== 1 ? descent
- boff
21305 : (ascent
+ descent
) / 2)
21309 cmp
->offsets
[i
* 2] = left
;
21310 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
21312 /* Update the bounding box of the overall glyphs. */
21315 right
= left
+ width
;
21316 if (left
< leftmost
)
21318 if (right
> rightmost
)
21321 top
= btm
+ descent
+ ascent
;
21327 if (cmp
->lbearing
> left
+ lbearing
)
21328 cmp
->lbearing
= left
+ lbearing
;
21329 if (cmp
->rbearing
< left
+ rbearing
)
21330 cmp
->rbearing
= left
+ rbearing
;
21334 /* If there are glyphs whose x-offsets are negative,
21335 shift all glyphs to the right and make all x-offsets
21339 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21340 cmp
->offsets
[i
* 2] -= leftmost
;
21341 rightmost
-= leftmost
;
21342 cmp
->lbearing
-= leftmost
;
21343 cmp
->rbearing
-= leftmost
;
21346 if (left_padded
&& cmp
->lbearing
< 0)
21348 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21349 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
21350 rightmost
-= cmp
->lbearing
;
21351 cmp
->rbearing
-= cmp
->lbearing
;
21354 if (right_padded
&& rightmost
< cmp
->rbearing
)
21356 rightmost
= cmp
->rbearing
;
21359 cmp
->pixel_width
= rightmost
;
21360 cmp
->ascent
= highest
;
21361 cmp
->descent
= - lowest
;
21362 if (cmp
->ascent
< font_ascent
)
21363 cmp
->ascent
= font_ascent
;
21364 if (cmp
->descent
< font_descent
)
21365 cmp
->descent
= font_descent
;
21369 && (cmp
->lbearing
< 0
21370 || cmp
->rbearing
> cmp
->pixel_width
))
21371 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21373 it
->pixel_width
= cmp
->pixel_width
;
21374 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
21375 it
->descent
= it
->phys_descent
= cmp
->descent
;
21376 if (face
->box
!= FACE_NO_BOX
)
21378 int thick
= face
->box_line_width
;
21382 it
->ascent
+= thick
;
21383 it
->descent
+= thick
;
21388 if (it
->start_of_box_run_p
)
21389 it
->pixel_width
+= thick
;
21390 if (it
->end_of_box_run_p
)
21391 it
->pixel_width
+= thick
;
21394 /* If face has an overline, add the height of the overline
21395 (1 pixel) and a 1 pixel margin to the character height. */
21396 if (face
->overline_p
)
21397 it
->ascent
+= overline_margin
;
21399 take_vertical_position_into_account (it
);
21400 if (it
->ascent
< 0)
21402 if (it
->descent
< 0)
21406 append_composite_glyph (it
);
21408 else if (it
->what
== IT_IMAGE
)
21409 produce_image_glyph (it
);
21410 else if (it
->what
== IT_STRETCH
)
21411 produce_stretch_glyph (it
);
21413 /* Accumulate dimensions. Note: can't assume that it->descent > 0
21414 because this isn't true for images with `:ascent 100'. */
21415 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
21416 if (it
->area
== TEXT_AREA
)
21417 it
->current_x
+= it
->pixel_width
;
21419 if (extra_line_spacing
> 0)
21421 it
->descent
+= extra_line_spacing
;
21422 if (extra_line_spacing
> it
->max_extra_line_spacing
)
21423 it
->max_extra_line_spacing
= extra_line_spacing
;
21426 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
21427 it
->max_descent
= max (it
->max_descent
, it
->descent
);
21428 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
21429 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
21433 Output LEN glyphs starting at START at the nominal cursor position.
21434 Advance the nominal cursor over the text. The global variable
21435 updated_window contains the window being updated, updated_row is
21436 the glyph row being updated, and updated_area is the area of that
21437 row being updated. */
21440 x_write_glyphs (start
, len
)
21441 struct glyph
*start
;
21446 xassert (updated_window
&& updated_row
);
21449 /* Write glyphs. */
21451 hpos
= start
- updated_row
->glyphs
[updated_area
];
21452 x
= draw_glyphs (updated_window
, output_cursor
.x
,
21453 updated_row
, updated_area
,
21455 DRAW_NORMAL_TEXT
, 0);
21457 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
21458 if (updated_area
== TEXT_AREA
21459 && updated_window
->phys_cursor_on_p
21460 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
21461 && updated_window
->phys_cursor
.hpos
>= hpos
21462 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
21463 updated_window
->phys_cursor_on_p
= 0;
21467 /* Advance the output cursor. */
21468 output_cursor
.hpos
+= len
;
21469 output_cursor
.x
= x
;
21474 Insert LEN glyphs from START at the nominal cursor position. */
21477 x_insert_glyphs (start
, len
)
21478 struct glyph
*start
;
21483 int line_height
, shift_by_width
, shifted_region_width
;
21484 struct glyph_row
*row
;
21485 struct glyph
*glyph
;
21486 int frame_x
, frame_y
;
21489 xassert (updated_window
&& updated_row
);
21491 w
= updated_window
;
21492 f
= XFRAME (WINDOW_FRAME (w
));
21494 /* Get the height of the line we are in. */
21496 line_height
= row
->height
;
21498 /* Get the width of the glyphs to insert. */
21499 shift_by_width
= 0;
21500 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
21501 shift_by_width
+= glyph
->pixel_width
;
21503 /* Get the width of the region to shift right. */
21504 shifted_region_width
= (window_box_width (w
, updated_area
)
21509 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
21510 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
21512 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
21513 line_height
, shift_by_width
);
21515 /* Write the glyphs. */
21516 hpos
= start
- row
->glyphs
[updated_area
];
21517 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
21519 DRAW_NORMAL_TEXT
, 0);
21521 /* Advance the output cursor. */
21522 output_cursor
.hpos
+= len
;
21523 output_cursor
.x
+= shift_by_width
;
21529 Erase the current text line from the nominal cursor position
21530 (inclusive) to pixel column TO_X (exclusive). The idea is that
21531 everything from TO_X onward is already erased.
21533 TO_X is a pixel position relative to updated_area of
21534 updated_window. TO_X == -1 means clear to the end of this area. */
21537 x_clear_end_of_line (to_x
)
21541 struct window
*w
= updated_window
;
21542 int max_x
, min_y
, max_y
;
21543 int from_x
, from_y
, to_y
;
21545 xassert (updated_window
&& updated_row
);
21546 f
= XFRAME (w
->frame
);
21548 if (updated_row
->full_width_p
)
21549 max_x
= WINDOW_TOTAL_WIDTH (w
);
21551 max_x
= window_box_width (w
, updated_area
);
21552 max_y
= window_text_bottom_y (w
);
21554 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
21555 of window. For TO_X > 0, truncate to end of drawing area. */
21561 to_x
= min (to_x
, max_x
);
21563 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
21565 /* Notice if the cursor will be cleared by this operation. */
21566 if (!updated_row
->full_width_p
)
21567 notice_overwritten_cursor (w
, updated_area
,
21568 output_cursor
.x
, -1,
21570 MATRIX_ROW_BOTTOM_Y (updated_row
));
21572 from_x
= output_cursor
.x
;
21574 /* Translate to frame coordinates. */
21575 if (updated_row
->full_width_p
)
21577 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
21578 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
21582 int area_left
= window_box_left (w
, updated_area
);
21583 from_x
+= area_left
;
21587 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
21588 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
21589 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
21591 /* Prevent inadvertently clearing to end of the X window. */
21592 if (to_x
> from_x
&& to_y
> from_y
)
21595 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
21596 to_x
- from_x
, to_y
- from_y
);
21601 #endif /* HAVE_WINDOW_SYSTEM */
21605 /***********************************************************************
21607 ***********************************************************************/
21609 /* Value is the internal representation of the specified cursor type
21610 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
21611 of the bar cursor. */
21613 static enum text_cursor_kinds
21614 get_specified_cursor_type (arg
, width
)
21618 enum text_cursor_kinds type
;
21623 if (EQ (arg
, Qbox
))
21624 return FILLED_BOX_CURSOR
;
21626 if (EQ (arg
, Qhollow
))
21627 return HOLLOW_BOX_CURSOR
;
21629 if (EQ (arg
, Qbar
))
21636 && EQ (XCAR (arg
), Qbar
)
21637 && INTEGERP (XCDR (arg
))
21638 && XINT (XCDR (arg
)) >= 0)
21640 *width
= XINT (XCDR (arg
));
21644 if (EQ (arg
, Qhbar
))
21647 return HBAR_CURSOR
;
21651 && EQ (XCAR (arg
), Qhbar
)
21652 && INTEGERP (XCDR (arg
))
21653 && XINT (XCDR (arg
)) >= 0)
21655 *width
= XINT (XCDR (arg
));
21656 return HBAR_CURSOR
;
21659 /* Treat anything unknown as "hollow box cursor".
21660 It was bad to signal an error; people have trouble fixing
21661 .Xdefaults with Emacs, when it has something bad in it. */
21662 type
= HOLLOW_BOX_CURSOR
;
21667 /* Set the default cursor types for specified frame. */
21669 set_frame_cursor_types (f
, arg
)
21676 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
21677 FRAME_CURSOR_WIDTH (f
) = width
;
21679 /* By default, set up the blink-off state depending on the on-state. */
21681 tem
= Fassoc (arg
, Vblink_cursor_alist
);
21684 FRAME_BLINK_OFF_CURSOR (f
)
21685 = get_specified_cursor_type (XCDR (tem
), &width
);
21686 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
21689 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
21693 /* Return the cursor we want to be displayed in window W. Return
21694 width of bar/hbar cursor through WIDTH arg. Return with
21695 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
21696 (i.e. if the `system caret' should track this cursor).
21698 In a mini-buffer window, we want the cursor only to appear if we
21699 are reading input from this window. For the selected window, we
21700 want the cursor type given by the frame parameter or buffer local
21701 setting of cursor-type. If explicitly marked off, draw no cursor.
21702 In all other cases, we want a hollow box cursor. */
21704 static enum text_cursor_kinds
21705 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
21707 struct glyph
*glyph
;
21709 int *active_cursor
;
21711 struct frame
*f
= XFRAME (w
->frame
);
21712 struct buffer
*b
= XBUFFER (w
->buffer
);
21713 int cursor_type
= DEFAULT_CURSOR
;
21714 Lisp_Object alt_cursor
;
21715 int non_selected
= 0;
21717 *active_cursor
= 1;
21720 if (cursor_in_echo_area
21721 && FRAME_HAS_MINIBUF_P (f
)
21722 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
21724 if (w
== XWINDOW (echo_area_window
))
21726 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
21728 *width
= FRAME_CURSOR_WIDTH (f
);
21729 return FRAME_DESIRED_CURSOR (f
);
21732 return get_specified_cursor_type (b
->cursor_type
, width
);
21735 *active_cursor
= 0;
21739 /* Detect a nonselected window or nonselected frame. */
21740 else if (w
!= XWINDOW (f
->selected_window
)
21741 #ifdef HAVE_WINDOW_SYSTEM
21742 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
21746 *active_cursor
= 0;
21748 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
21754 /* Never display a cursor in a window in which cursor-type is nil. */
21755 if (NILP (b
->cursor_type
))
21758 /* Get the normal cursor type for this window. */
21759 if (EQ (b
->cursor_type
, Qt
))
21761 cursor_type
= FRAME_DESIRED_CURSOR (f
);
21762 *width
= FRAME_CURSOR_WIDTH (f
);
21765 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
21767 /* Use cursor-in-non-selected-windows instead
21768 for non-selected window or frame. */
21771 alt_cursor
= b
->cursor_in_non_selected_windows
;
21772 if (!EQ (Qt
, alt_cursor
))
21773 return get_specified_cursor_type (alt_cursor
, width
);
21774 /* t means modify the normal cursor type. */
21775 if (cursor_type
== FILLED_BOX_CURSOR
)
21776 cursor_type
= HOLLOW_BOX_CURSOR
;
21777 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
21779 return cursor_type
;
21782 /* Use normal cursor if not blinked off. */
21783 if (!w
->cursor_off_p
)
21785 #ifdef HAVE_WINDOW_SYSTEM
21786 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21788 if (cursor_type
== FILLED_BOX_CURSOR
)
21790 /* Using a block cursor on large images can be very annoying.
21791 So use a hollow cursor for "large" images.
21792 If image is not transparent (no mask), also use hollow cursor. */
21793 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21794 if (img
!= NULL
&& IMAGEP (img
->spec
))
21796 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
21797 where N = size of default frame font size.
21798 This should cover most of the "tiny" icons people may use. */
21800 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
21801 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
21802 cursor_type
= HOLLOW_BOX_CURSOR
;
21805 else if (cursor_type
!= NO_CURSOR
)
21807 /* Display current only supports BOX and HOLLOW cursors for images.
21808 So for now, unconditionally use a HOLLOW cursor when cursor is
21809 not a solid box cursor. */
21810 cursor_type
= HOLLOW_BOX_CURSOR
;
21814 return cursor_type
;
21817 /* Cursor is blinked off, so determine how to "toggle" it. */
21819 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
21820 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
21821 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
21823 /* Then see if frame has specified a specific blink off cursor type. */
21824 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
21826 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
21827 return FRAME_BLINK_OFF_CURSOR (f
);
21831 /* Some people liked having a permanently visible blinking cursor,
21832 while others had very strong opinions against it. So it was
21833 decided to remove it. KFS 2003-09-03 */
21835 /* Finally perform built-in cursor blinking:
21836 filled box <-> hollow box
21837 wide [h]bar <-> narrow [h]bar
21838 narrow [h]bar <-> no cursor
21839 other type <-> no cursor */
21841 if (cursor_type
== FILLED_BOX_CURSOR
)
21842 return HOLLOW_BOX_CURSOR
;
21844 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
21847 return cursor_type
;
21855 #ifdef HAVE_WINDOW_SYSTEM
21857 /* Notice when the text cursor of window W has been completely
21858 overwritten by a drawing operation that outputs glyphs in AREA
21859 starting at X0 and ending at X1 in the line starting at Y0 and
21860 ending at Y1. X coordinates are area-relative. X1 < 0 means all
21861 the rest of the line after X0 has been written. Y coordinates
21862 are window-relative. */
21865 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
21867 enum glyph_row_area area
;
21868 int x0
, y0
, x1
, y1
;
21870 int cx0
, cx1
, cy0
, cy1
;
21871 struct glyph_row
*row
;
21873 if (!w
->phys_cursor_on_p
)
21875 if (area
!= TEXT_AREA
)
21878 if (w
->phys_cursor
.vpos
< 0
21879 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
21880 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
21881 !(row
->enabled_p
&& row
->displays_text_p
)))
21884 if (row
->cursor_in_fringe_p
)
21886 row
->cursor_in_fringe_p
= 0;
21887 draw_fringe_bitmap (w
, row
, 0);
21888 w
->phys_cursor_on_p
= 0;
21892 cx0
= w
->phys_cursor
.x
;
21893 cx1
= cx0
+ w
->phys_cursor_width
;
21894 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
21897 /* The cursor image will be completely removed from the
21898 screen if the output area intersects the cursor area in
21899 y-direction. When we draw in [y0 y1[, and some part of
21900 the cursor is at y < y0, that part must have been drawn
21901 before. When scrolling, the cursor is erased before
21902 actually scrolling, so we don't come here. When not
21903 scrolling, the rows above the old cursor row must have
21904 changed, and in this case these rows must have written
21905 over the cursor image.
21907 Likewise if part of the cursor is below y1, with the
21908 exception of the cursor being in the first blank row at
21909 the buffer and window end because update_text_area
21910 doesn't draw that row. (Except when it does, but
21911 that's handled in update_text_area.) */
21913 cy0
= w
->phys_cursor
.y
;
21914 cy1
= cy0
+ w
->phys_cursor_height
;
21915 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
21918 w
->phys_cursor_on_p
= 0;
21921 #endif /* HAVE_WINDOW_SYSTEM */
21924 /************************************************************************
21926 ************************************************************************/
21928 #ifdef HAVE_WINDOW_SYSTEM
21931 Fix the display of area AREA of overlapping row ROW in window W
21932 with respect to the overlapping part OVERLAPS. */
21935 x_fix_overlapping_area (w
, row
, area
, overlaps
)
21937 struct glyph_row
*row
;
21938 enum glyph_row_area area
;
21946 for (i
= 0; i
< row
->used
[area
];)
21948 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
21950 int start
= i
, start_x
= x
;
21954 x
+= row
->glyphs
[area
][i
].pixel_width
;
21957 while (i
< row
->used
[area
]
21958 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
21960 draw_glyphs (w
, start_x
, row
, area
,
21962 DRAW_NORMAL_TEXT
, overlaps
);
21966 x
+= row
->glyphs
[area
][i
].pixel_width
;
21976 Draw the cursor glyph of window W in glyph row ROW. See the
21977 comment of draw_glyphs for the meaning of HL. */
21980 draw_phys_cursor_glyph (w
, row
, hl
)
21982 struct glyph_row
*row
;
21983 enum draw_glyphs_face hl
;
21985 /* If cursor hpos is out of bounds, don't draw garbage. This can
21986 happen in mini-buffer windows when switching between echo area
21987 glyphs and mini-buffer. */
21988 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
21990 int on_p
= w
->phys_cursor_on_p
;
21992 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
21993 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
21995 w
->phys_cursor_on_p
= on_p
;
21997 if (hl
== DRAW_CURSOR
)
21998 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21999 /* When we erase the cursor, and ROW is overlapped by other
22000 rows, make sure that these overlapping parts of other rows
22002 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
22004 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22006 if (row
> w
->current_matrix
->rows
22007 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
22008 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
22009 OVERLAPS_ERASED_CURSOR
);
22011 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
22012 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
22013 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
22014 OVERLAPS_ERASED_CURSOR
);
22021 Erase the image of a cursor of window W from the screen. */
22024 erase_phys_cursor (w
)
22027 struct frame
*f
= XFRAME (w
->frame
);
22028 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22029 int hpos
= w
->phys_cursor
.hpos
;
22030 int vpos
= w
->phys_cursor
.vpos
;
22031 int mouse_face_here_p
= 0;
22032 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
22033 struct glyph_row
*cursor_row
;
22034 struct glyph
*cursor_glyph
;
22035 enum draw_glyphs_face hl
;
22037 /* No cursor displayed or row invalidated => nothing to do on the
22039 if (w
->phys_cursor_type
== NO_CURSOR
)
22040 goto mark_cursor_off
;
22042 /* VPOS >= active_glyphs->nrows means that window has been resized.
22043 Don't bother to erase the cursor. */
22044 if (vpos
>= active_glyphs
->nrows
)
22045 goto mark_cursor_off
;
22047 /* If row containing cursor is marked invalid, there is nothing we
22049 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
22050 if (!cursor_row
->enabled_p
)
22051 goto mark_cursor_off
;
22053 /* If line spacing is > 0, old cursor may only be partially visible in
22054 window after split-window. So adjust visible height. */
22055 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
22056 window_text_bottom_y (w
) - cursor_row
->y
);
22058 /* If row is completely invisible, don't attempt to delete a cursor which
22059 isn't there. This can happen if cursor is at top of a window, and
22060 we switch to a buffer with a header line in that window. */
22061 if (cursor_row
->visible_height
<= 0)
22062 goto mark_cursor_off
;
22064 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
22065 if (cursor_row
->cursor_in_fringe_p
)
22067 cursor_row
->cursor_in_fringe_p
= 0;
22068 draw_fringe_bitmap (w
, cursor_row
, 0);
22069 goto mark_cursor_off
;
22072 /* This can happen when the new row is shorter than the old one.
22073 In this case, either draw_glyphs or clear_end_of_line
22074 should have cleared the cursor. Note that we wouldn't be
22075 able to erase the cursor in this case because we don't have a
22076 cursor glyph at hand. */
22077 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
22078 goto mark_cursor_off
;
22080 /* If the cursor is in the mouse face area, redisplay that when
22081 we clear the cursor. */
22082 if (! NILP (dpyinfo
->mouse_face_window
)
22083 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
22084 && (vpos
> dpyinfo
->mouse_face_beg_row
22085 || (vpos
== dpyinfo
->mouse_face_beg_row
22086 && hpos
>= dpyinfo
->mouse_face_beg_col
))
22087 && (vpos
< dpyinfo
->mouse_face_end_row
22088 || (vpos
== dpyinfo
->mouse_face_end_row
22089 && hpos
< dpyinfo
->mouse_face_end_col
))
22090 /* Don't redraw the cursor's spot in mouse face if it is at the
22091 end of a line (on a newline). The cursor appears there, but
22092 mouse highlighting does not. */
22093 && cursor_row
->used
[TEXT_AREA
] > hpos
)
22094 mouse_face_here_p
= 1;
22096 /* Maybe clear the display under the cursor. */
22097 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
22100 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
22103 cursor_glyph
= get_phys_cursor_glyph (w
);
22104 if (cursor_glyph
== NULL
)
22105 goto mark_cursor_off
;
22107 width
= cursor_glyph
->pixel_width
;
22108 left_x
= window_box_left_offset (w
, TEXT_AREA
);
22109 x
= w
->phys_cursor
.x
;
22111 width
-= left_x
- x
;
22112 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
22113 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
22114 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
22117 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
22120 /* Erase the cursor by redrawing the character underneath it. */
22121 if (mouse_face_here_p
)
22122 hl
= DRAW_MOUSE_FACE
;
22124 hl
= DRAW_NORMAL_TEXT
;
22125 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
22128 w
->phys_cursor_on_p
= 0;
22129 w
->phys_cursor_type
= NO_CURSOR
;
22134 Display or clear cursor of window W. If ON is zero, clear the
22135 cursor. If it is non-zero, display the cursor. If ON is nonzero,
22136 where to put the cursor is specified by HPOS, VPOS, X and Y. */
22139 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
22141 int on
, hpos
, vpos
, x
, y
;
22143 struct frame
*f
= XFRAME (w
->frame
);
22144 int new_cursor_type
;
22145 int new_cursor_width
;
22147 struct glyph_row
*glyph_row
;
22148 struct glyph
*glyph
;
22150 /* This is pointless on invisible frames, and dangerous on garbaged
22151 windows and frames; in the latter case, the frame or window may
22152 be in the midst of changing its size, and x and y may be off the
22154 if (! FRAME_VISIBLE_P (f
)
22155 || FRAME_GARBAGED_P (f
)
22156 || vpos
>= w
->current_matrix
->nrows
22157 || hpos
>= w
->current_matrix
->matrix_w
)
22160 /* If cursor is off and we want it off, return quickly. */
22161 if (!on
&& !w
->phys_cursor_on_p
)
22164 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
22165 /* If cursor row is not enabled, we don't really know where to
22166 display the cursor. */
22167 if (!glyph_row
->enabled_p
)
22169 w
->phys_cursor_on_p
= 0;
22174 if (!glyph_row
->exact_window_width_line_p
22175 || hpos
< glyph_row
->used
[TEXT_AREA
])
22176 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
22178 xassert (interrupt_input_blocked
);
22180 /* Set new_cursor_type to the cursor we want to be displayed. */
22181 new_cursor_type
= get_window_cursor_type (w
, glyph
,
22182 &new_cursor_width
, &active_cursor
);
22184 /* If cursor is currently being shown and we don't want it to be or
22185 it is in the wrong place, or the cursor type is not what we want,
22187 if (w
->phys_cursor_on_p
22189 || w
->phys_cursor
.x
!= x
22190 || w
->phys_cursor
.y
!= y
22191 || new_cursor_type
!= w
->phys_cursor_type
22192 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
22193 && new_cursor_width
!= w
->phys_cursor_width
)))
22194 erase_phys_cursor (w
);
22196 /* Don't check phys_cursor_on_p here because that flag is only set
22197 to zero in some cases where we know that the cursor has been
22198 completely erased, to avoid the extra work of erasing the cursor
22199 twice. In other words, phys_cursor_on_p can be 1 and the cursor
22200 still not be visible, or it has only been partly erased. */
22203 w
->phys_cursor_ascent
= glyph_row
->ascent
;
22204 w
->phys_cursor_height
= glyph_row
->height
;
22206 /* Set phys_cursor_.* before x_draw_.* is called because some
22207 of them may need the information. */
22208 w
->phys_cursor
.x
= x
;
22209 w
->phys_cursor
.y
= glyph_row
->y
;
22210 w
->phys_cursor
.hpos
= hpos
;
22211 w
->phys_cursor
.vpos
= vpos
;
22214 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
22215 new_cursor_type
, new_cursor_width
,
22216 on
, active_cursor
);
22220 /* Switch the display of W's cursor on or off, according to the value
22224 update_window_cursor (w
, on
)
22228 /* Don't update cursor in windows whose frame is in the process
22229 of being deleted. */
22230 if (w
->current_matrix
)
22233 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22234 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22240 /* Call update_window_cursor with parameter ON_P on all leaf windows
22241 in the window tree rooted at W. */
22244 update_cursor_in_window_tree (w
, on_p
)
22250 if (!NILP (w
->hchild
))
22251 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
22252 else if (!NILP (w
->vchild
))
22253 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
22255 update_window_cursor (w
, on_p
);
22257 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
22263 Display the cursor on window W, or clear it, according to ON_P.
22264 Don't change the cursor's position. */
22267 x_update_cursor (f
, on_p
)
22271 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
22276 Clear the cursor of window W to background color, and mark the
22277 cursor as not shown. This is used when the text where the cursor
22278 is is about to be rewritten. */
22284 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
22285 update_window_cursor (w
, 0);
22290 Display the active region described by mouse_face_* according to DRAW. */
22293 show_mouse_face (dpyinfo
, draw
)
22294 Display_Info
*dpyinfo
;
22295 enum draw_glyphs_face draw
;
22297 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
22298 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22300 if (/* If window is in the process of being destroyed, don't bother
22302 w
->current_matrix
!= NULL
22303 /* Don't update mouse highlight if hidden */
22304 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
22305 /* Recognize when we are called to operate on rows that don't exist
22306 anymore. This can happen when a window is split. */
22307 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
22309 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
22310 struct glyph_row
*row
, *first
, *last
;
22312 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
22313 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
22315 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
22317 int start_hpos
, end_hpos
, start_x
;
22319 /* For all but the first row, the highlight starts at column 0. */
22322 start_hpos
= dpyinfo
->mouse_face_beg_col
;
22323 start_x
= dpyinfo
->mouse_face_beg_x
;
22332 end_hpos
= dpyinfo
->mouse_face_end_col
;
22335 end_hpos
= row
->used
[TEXT_AREA
];
22336 if (draw
== DRAW_NORMAL_TEXT
)
22337 row
->fill_line_p
= 1; /* Clear to end of line */
22340 if (end_hpos
> start_hpos
)
22342 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
22343 start_hpos
, end_hpos
,
22347 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
22351 /* When we've written over the cursor, arrange for it to
22352 be displayed again. */
22353 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
22356 display_and_set_cursor (w
, 1,
22357 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22358 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22363 /* Change the mouse cursor. */
22364 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
22365 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
22366 else if (draw
== DRAW_MOUSE_FACE
)
22367 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
22369 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
22373 Clear out the mouse-highlighted active region.
22374 Redraw it un-highlighted first. Value is non-zero if mouse
22375 face was actually drawn unhighlighted. */
22378 clear_mouse_face (dpyinfo
)
22379 Display_Info
*dpyinfo
;
22383 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
22385 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
22389 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22390 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22391 dpyinfo
->mouse_face_window
= Qnil
;
22392 dpyinfo
->mouse_face_overlay
= Qnil
;
22398 Non-zero if physical cursor of window W is within mouse face. */
22401 cursor_in_mouse_face_p (w
)
22404 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22405 int in_mouse_face
= 0;
22407 if (WINDOWP (dpyinfo
->mouse_face_window
)
22408 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
22410 int hpos
= w
->phys_cursor
.hpos
;
22411 int vpos
= w
->phys_cursor
.vpos
;
22413 if (vpos
>= dpyinfo
->mouse_face_beg_row
22414 && vpos
<= dpyinfo
->mouse_face_end_row
22415 && (vpos
> dpyinfo
->mouse_face_beg_row
22416 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22417 && (vpos
< dpyinfo
->mouse_face_end_row
22418 || hpos
< dpyinfo
->mouse_face_end_col
22419 || dpyinfo
->mouse_face_past_end
))
22423 return in_mouse_face
;
22429 /* Find the glyph matrix position of buffer position CHARPOS in window
22430 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
22431 current glyphs must be up to date. If CHARPOS is above window
22432 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
22433 of last line in W. In the row containing CHARPOS, stop before glyphs
22434 having STOP as object. */
22436 #if 1 /* This is a version of fast_find_position that's more correct
22437 in the presence of hscrolling, for example. I didn't install
22438 it right away because the problem fixed is minor, it failed
22439 in 20.x as well, and I think it's too risky to install
22440 so near the release of 21.1. 2001-09-25 gerd. */
22442 #ifndef HAVE_CARBON
22446 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
22449 int *hpos
, *vpos
, *x
, *y
;
22452 struct glyph_row
*row
, *first
;
22453 struct glyph
*glyph
, *end
;
22456 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22457 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
22462 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
22466 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
22469 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22473 /* If whole rows or last part of a row came from a display overlay,
22474 row_containing_pos will skip over such rows because their end pos
22475 equals the start pos of the overlay or interval.
22477 Move back if we have a STOP object and previous row's
22478 end glyph came from STOP. */
22481 struct glyph_row
*prev
;
22482 while ((prev
= row
- 1, prev
>= first
)
22483 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
22484 && prev
->used
[TEXT_AREA
] > 0)
22486 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
22487 glyph
= beg
+ prev
->used
[TEXT_AREA
];
22488 while (--glyph
>= beg
22489 && INTEGERP (glyph
->object
));
22491 || !EQ (stop
, glyph
->object
))
22499 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22501 glyph
= row
->glyphs
[TEXT_AREA
];
22502 end
= glyph
+ row
->used
[TEXT_AREA
];
22504 /* Skip over glyphs not having an object at the start of the row.
22505 These are special glyphs like truncation marks on terminal
22507 if (row
->displays_text_p
)
22509 && INTEGERP (glyph
->object
)
22510 && !EQ (stop
, glyph
->object
)
22511 && glyph
->charpos
< 0)
22513 *x
+= glyph
->pixel_width
;
22518 && !INTEGERP (glyph
->object
)
22519 && !EQ (stop
, glyph
->object
)
22520 && (!BUFFERP (glyph
->object
)
22521 || glyph
->charpos
< charpos
))
22523 *x
+= glyph
->pixel_width
;
22527 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
22534 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
22537 int *hpos
, *vpos
, *x
, *y
;
22542 int maybe_next_line_p
= 0;
22543 int line_start_position
;
22544 int yb
= window_text_bottom_y (w
);
22545 struct glyph_row
*row
, *best_row
;
22546 int row_vpos
, best_row_vpos
;
22549 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22550 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22552 while (row
->y
< yb
)
22554 if (row
->used
[TEXT_AREA
])
22555 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
22557 line_start_position
= 0;
22559 if (line_start_position
> pos
)
22561 /* If the position sought is the end of the buffer,
22562 don't include the blank lines at the bottom of the window. */
22563 else if (line_start_position
== pos
22564 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
22566 maybe_next_line_p
= 1;
22569 else if (line_start_position
> 0)
22572 best_row_vpos
= row_vpos
;
22575 if (row
->y
+ row
->height
>= yb
)
22582 /* Find the right column within BEST_ROW. */
22584 current_x
= best_row
->x
;
22585 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
22587 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
22588 int charpos
= glyph
->charpos
;
22590 if (BUFFERP (glyph
->object
))
22592 if (charpos
== pos
)
22595 *vpos
= best_row_vpos
;
22600 else if (charpos
> pos
)
22603 else if (EQ (glyph
->object
, stop
))
22608 current_x
+= glyph
->pixel_width
;
22611 /* If we're looking for the end of the buffer,
22612 and we didn't find it in the line we scanned,
22613 use the start of the following line. */
22614 if (maybe_next_line_p
)
22619 current_x
= best_row
->x
;
22622 *vpos
= best_row_vpos
;
22623 *hpos
= lastcol
+ 1;
22632 /* Find the position of the glyph for position POS in OBJECT in
22633 window W's current matrix, and return in *X, *Y the pixel
22634 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
22636 RIGHT_P non-zero means return the position of the right edge of the
22637 glyph, RIGHT_P zero means return the left edge position.
22639 If no glyph for POS exists in the matrix, return the position of
22640 the glyph with the next smaller position that is in the matrix, if
22641 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
22642 exists in the matrix, return the position of the glyph with the
22643 next larger position in OBJECT.
22645 Value is non-zero if a glyph was found. */
22648 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
22651 Lisp_Object object
;
22652 int *hpos
, *vpos
, *x
, *y
;
22655 int yb
= window_text_bottom_y (w
);
22656 struct glyph_row
*r
;
22657 struct glyph
*best_glyph
= NULL
;
22658 struct glyph_row
*best_row
= NULL
;
22661 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22662 r
->enabled_p
&& r
->y
< yb
;
22665 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
22666 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
22669 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
22670 if (EQ (g
->object
, object
))
22672 if (g
->charpos
== pos
)
22679 else if (best_glyph
== NULL
22680 || ((eabs (g
->charpos
- pos
)
22681 < eabs (best_glyph
->charpos
- pos
))
22684 : g
->charpos
> pos
)))
22698 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
22702 *x
+= best_glyph
->pixel_width
;
22707 *vpos
= best_row
- w
->current_matrix
->rows
;
22710 return best_glyph
!= NULL
;
22714 /* See if position X, Y is within a hot-spot of an image. */
22717 on_hot_spot_p (hot_spot
, x
, y
)
22718 Lisp_Object hot_spot
;
22721 if (!CONSP (hot_spot
))
22724 if (EQ (XCAR (hot_spot
), Qrect
))
22726 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
22727 Lisp_Object rect
= XCDR (hot_spot
);
22731 if (!CONSP (XCAR (rect
)))
22733 if (!CONSP (XCDR (rect
)))
22735 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
22737 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
22739 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
22741 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
22745 else if (EQ (XCAR (hot_spot
), Qcircle
))
22747 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
22748 Lisp_Object circ
= XCDR (hot_spot
);
22749 Lisp_Object lr
, lx0
, ly0
;
22751 && CONSP (XCAR (circ
))
22752 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
22753 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
22754 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
22756 double r
= XFLOATINT (lr
);
22757 double dx
= XINT (lx0
) - x
;
22758 double dy
= XINT (ly0
) - y
;
22759 return (dx
* dx
+ dy
* dy
<= r
* r
);
22762 else if (EQ (XCAR (hot_spot
), Qpoly
))
22764 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
22765 if (VECTORP (XCDR (hot_spot
)))
22767 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
22768 Lisp_Object
*poly
= v
->contents
;
22772 Lisp_Object lx
, ly
;
22775 /* Need an even number of coordinates, and at least 3 edges. */
22776 if (n
< 6 || n
& 1)
22779 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
22780 If count is odd, we are inside polygon. Pixels on edges
22781 may or may not be included depending on actual geometry of the
22783 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
22784 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
22786 x0
= XINT (lx
), y0
= XINT (ly
);
22787 for (i
= 0; i
< n
; i
+= 2)
22789 int x1
= x0
, y1
= y0
;
22790 if ((lx
= poly
[i
], !INTEGERP (lx
))
22791 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
22793 x0
= XINT (lx
), y0
= XINT (ly
);
22795 /* Does this segment cross the X line? */
22803 if (y
> y0
&& y
> y1
)
22805 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
22815 find_hot_spot (map
, x
, y
)
22819 while (CONSP (map
))
22821 if (CONSP (XCAR (map
))
22822 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
22830 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
22832 doc
: /* Lookup in image map MAP coordinates X and Y.
22833 An image map is an alist where each element has the format (AREA ID PLIST).
22834 An AREA is specified as either a rectangle, a circle, or a polygon:
22835 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
22836 pixel coordinates of the upper left and bottom right corners.
22837 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
22838 and the radius of the circle; r may be a float or integer.
22839 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
22840 vector describes one corner in the polygon.
22841 Returns the alist element for the first matching AREA in MAP. */)
22852 return find_hot_spot (map
, XINT (x
), XINT (y
));
22856 /* Display frame CURSOR, optionally using shape defined by POINTER. */
22858 define_frame_cursor1 (f
, cursor
, pointer
)
22861 Lisp_Object pointer
;
22863 /* Do not change cursor shape while dragging mouse. */
22864 if (!NILP (do_mouse_tracking
))
22867 if (!NILP (pointer
))
22869 if (EQ (pointer
, Qarrow
))
22870 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22871 else if (EQ (pointer
, Qhand
))
22872 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
22873 else if (EQ (pointer
, Qtext
))
22874 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22875 else if (EQ (pointer
, intern ("hdrag")))
22876 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22877 #ifdef HAVE_X_WINDOWS
22878 else if (EQ (pointer
, intern ("vdrag")))
22879 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
22881 else if (EQ (pointer
, intern ("hourglass")))
22882 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
22883 else if (EQ (pointer
, Qmodeline
))
22884 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
22886 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22889 if (cursor
!= No_Cursor
)
22890 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
22893 /* Take proper action when mouse has moved to the mode or header line
22894 or marginal area AREA of window W, x-position X and y-position Y.
22895 X is relative to the start of the text display area of W, so the
22896 width of bitmap areas and scroll bars must be subtracted to get a
22897 position relative to the start of the mode line. */
22900 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
22901 Lisp_Object window
;
22903 enum window_part area
;
22905 struct window
*w
= XWINDOW (window
);
22906 struct frame
*f
= XFRAME (w
->frame
);
22907 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22908 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22909 Lisp_Object pointer
= Qnil
;
22910 int charpos
, dx
, dy
, width
, height
;
22911 Lisp_Object string
, object
= Qnil
;
22912 Lisp_Object pos
, help
;
22914 Lisp_Object mouse_face
;
22915 int original_x_pixel
= x
;
22916 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
22917 struct glyph_row
*row
;
22919 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
22924 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
22925 &object
, &dx
, &dy
, &width
, &height
);
22927 row
= (area
== ON_MODE_LINE
22928 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
22929 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
22932 if (row
->mode_line_p
&& row
->enabled_p
)
22934 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
22935 end
= glyph
+ row
->used
[TEXT_AREA
];
22937 for (x0
= original_x_pixel
;
22938 glyph
< end
&& x0
>= glyph
->pixel_width
;
22940 x0
-= glyph
->pixel_width
;
22948 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
22949 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
22950 &object
, &dx
, &dy
, &width
, &height
);
22955 if (IMAGEP (object
))
22957 Lisp_Object image_map
, hotspot
;
22958 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
22960 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
22962 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22964 Lisp_Object area_id
, plist
;
22966 area_id
= XCAR (hotspot
);
22967 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22968 If so, we could look for mouse-enter, mouse-leave
22969 properties in PLIST (and do something...). */
22970 hotspot
= XCDR (hotspot
);
22971 if (CONSP (hotspot
)
22972 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22974 pointer
= Fplist_get (plist
, Qpointer
);
22975 if (NILP (pointer
))
22977 help
= Fplist_get (plist
, Qhelp_echo
);
22980 help_echo_string
= help
;
22981 /* Is this correct? ++kfs */
22982 XSETWINDOW (help_echo_window
, w
);
22983 help_echo_object
= w
->buffer
;
22984 help_echo_pos
= charpos
;
22988 if (NILP (pointer
))
22989 pointer
= Fplist_get (XCDR (object
), QCpointer
);
22992 if (STRINGP (string
))
22994 pos
= make_number (charpos
);
22995 /* If we're on a string with `help-echo' text property, arrange
22996 for the help to be displayed. This is done by setting the
22997 global variable help_echo_string to the help string. */
23000 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
23003 help_echo_string
= help
;
23004 XSETWINDOW (help_echo_window
, w
);
23005 help_echo_object
= string
;
23006 help_echo_pos
= charpos
;
23010 if (NILP (pointer
))
23011 pointer
= Fget_text_property (pos
, Qpointer
, string
);
23013 /* Change the mouse pointer according to what is under X/Y. */
23014 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
23017 map
= Fget_text_property (pos
, Qlocal_map
, string
);
23018 if (!KEYMAPP (map
))
23019 map
= Fget_text_property (pos
, Qkeymap
, string
);
23020 if (!KEYMAPP (map
))
23021 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
23024 /* Change the mouse face according to what is under X/Y. */
23025 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
23026 if (!NILP (mouse_face
)
23027 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23032 struct glyph
* tmp_glyph
;
23036 int total_pixel_width
;
23041 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
23042 Qmouse_face
, string
, Qnil
);
23044 b
= make_number (0);
23046 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
23048 e
= make_number (SCHARS (string
));
23050 /* Calculate the position(glyph position: GPOS) of GLYPH in
23051 displayed string. GPOS is different from CHARPOS.
23053 CHARPOS is the position of glyph in internal string
23054 object. A mode line string format has structures which
23055 is converted to a flatten by emacs lisp interpreter.
23056 The internal string is an element of the structures.
23057 The displayed string is the flatten string. */
23059 if (glyph
> row_start_glyph
)
23061 tmp_glyph
= glyph
- 1;
23062 while (tmp_glyph
>= row_start_glyph
23063 && tmp_glyph
->charpos
>= XINT (b
)
23064 && EQ (tmp_glyph
->object
, glyph
->object
))
23071 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
23072 displayed string holding GLYPH.
23074 GSEQ_LENGTH is different from SCHARS (STRING).
23075 SCHARS (STRING) returns the length of the internal string. */
23076 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
23077 tmp_glyph
->charpos
< XINT (e
);
23078 tmp_glyph
++, gseq_length
++)
23080 if (!EQ (tmp_glyph
->object
, glyph
->object
))
23084 total_pixel_width
= 0;
23085 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
23086 total_pixel_width
+= tmp_glyph
->pixel_width
;
23088 /* Pre calculation of re-rendering position */
23090 hpos
= (area
== ON_MODE_LINE
23091 ? (w
->current_matrix
)->nrows
- 1
23094 /* If the re-rendering position is included in the last
23095 re-rendering area, we should do nothing. */
23096 if ( EQ (window
, dpyinfo
->mouse_face_window
)
23097 && dpyinfo
->mouse_face_beg_col
<= vpos
23098 && vpos
< dpyinfo
->mouse_face_end_col
23099 && dpyinfo
->mouse_face_beg_row
== hpos
)
23102 if (clear_mouse_face (dpyinfo
))
23103 cursor
= No_Cursor
;
23105 dpyinfo
->mouse_face_beg_col
= vpos
;
23106 dpyinfo
->mouse_face_beg_row
= hpos
;
23108 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
23109 dpyinfo
->mouse_face_beg_y
= 0;
23111 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
23112 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
23114 dpyinfo
->mouse_face_end_x
= 0;
23115 dpyinfo
->mouse_face_end_y
= 0;
23117 dpyinfo
->mouse_face_past_end
= 0;
23118 dpyinfo
->mouse_face_window
= window
;
23120 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
23123 glyph
->face_id
, 1);
23124 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23126 if (NILP (pointer
))
23129 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23130 clear_mouse_face (dpyinfo
);
23132 define_frame_cursor1 (f
, cursor
, pointer
);
23137 Take proper action when the mouse has moved to position X, Y on
23138 frame F as regards highlighting characters that have mouse-face
23139 properties. Also de-highlighting chars where the mouse was before.
23140 X and Y can be negative or out of range. */
23143 note_mouse_highlight (f
, x
, y
)
23147 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23148 enum window_part part
;
23149 Lisp_Object window
;
23151 Cursor cursor
= No_Cursor
;
23152 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
23155 /* When a menu is active, don't highlight because this looks odd. */
23156 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (MAC_OS)
23157 if (popup_activated ())
23161 if (NILP (Vmouse_highlight
)
23162 || !f
->glyphs_initialized_p
)
23165 dpyinfo
->mouse_face_mouse_x
= x
;
23166 dpyinfo
->mouse_face_mouse_y
= y
;
23167 dpyinfo
->mouse_face_mouse_frame
= f
;
23169 if (dpyinfo
->mouse_face_defer
)
23172 if (gc_in_progress
)
23174 dpyinfo
->mouse_face_deferred_gc
= 1;
23178 /* Which window is that in? */
23179 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
23181 /* If we were displaying active text in another window, clear that.
23182 Also clear if we move out of text area in same window. */
23183 if (! EQ (window
, dpyinfo
->mouse_face_window
)
23184 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
23185 && !NILP (dpyinfo
->mouse_face_window
)))
23186 clear_mouse_face (dpyinfo
);
23188 /* Not on a window -> return. */
23189 if (!WINDOWP (window
))
23192 /* Reset help_echo_string. It will get recomputed below. */
23193 help_echo_string
= Qnil
;
23195 /* Convert to window-relative pixel coordinates. */
23196 w
= XWINDOW (window
);
23197 frame_to_window_pixel_xy (w
, &x
, &y
);
23199 /* Handle tool-bar window differently since it doesn't display a
23201 if (EQ (window
, f
->tool_bar_window
))
23203 note_tool_bar_highlight (f
, x
, y
);
23207 /* Mouse is on the mode, header line or margin? */
23208 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
23209 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
23211 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
23215 if (part
== ON_VERTICAL_BORDER
)
23217 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23218 help_echo_string
= build_string ("drag-mouse-1: resize");
23220 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
23221 || part
== ON_SCROLL_BAR
)
23222 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23224 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23226 /* Are we in a window whose display is up to date?
23227 And verify the buffer's text has not changed. */
23228 b
= XBUFFER (w
->buffer
);
23229 if (part
== ON_TEXT
23230 && EQ (w
->window_end_valid
, w
->buffer
)
23231 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
23232 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
23234 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
23235 struct glyph
*glyph
;
23236 Lisp_Object object
;
23237 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
23238 Lisp_Object
*overlay_vec
= NULL
;
23240 struct buffer
*obuf
;
23241 int obegv
, ozv
, same_region
;
23243 /* Find the glyph under X/Y. */
23244 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
23246 /* Look for :pointer property on image. */
23247 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23249 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23250 if (img
!= NULL
&& IMAGEP (img
->spec
))
23252 Lisp_Object image_map
, hotspot
;
23253 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
23255 && (hotspot
= find_hot_spot (image_map
,
23256 glyph
->slice
.x
+ dx
,
23257 glyph
->slice
.y
+ dy
),
23259 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23261 Lisp_Object area_id
, plist
;
23263 area_id
= XCAR (hotspot
);
23264 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23265 If so, we could look for mouse-enter, mouse-leave
23266 properties in PLIST (and do something...). */
23267 hotspot
= XCDR (hotspot
);
23268 if (CONSP (hotspot
)
23269 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23271 pointer
= Fplist_get (plist
, Qpointer
);
23272 if (NILP (pointer
))
23274 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
23275 if (!NILP (help_echo_string
))
23277 help_echo_window
= window
;
23278 help_echo_object
= glyph
->object
;
23279 help_echo_pos
= glyph
->charpos
;
23283 if (NILP (pointer
))
23284 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
23288 /* Clear mouse face if X/Y not over text. */
23290 || area
!= TEXT_AREA
23291 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
23293 if (clear_mouse_face (dpyinfo
))
23294 cursor
= No_Cursor
;
23295 if (NILP (pointer
))
23297 if (area
!= TEXT_AREA
)
23298 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23300 pointer
= Vvoid_text_area_pointer
;
23305 pos
= glyph
->charpos
;
23306 object
= glyph
->object
;
23307 if (!STRINGP (object
) && !BUFFERP (object
))
23310 /* If we get an out-of-range value, return now; avoid an error. */
23311 if (BUFFERP (object
) && pos
> BUF_Z (b
))
23314 /* Make the window's buffer temporarily current for
23315 overlays_at and compute_char_face. */
23316 obuf
= current_buffer
;
23317 current_buffer
= b
;
23323 /* Is this char mouse-active or does it have help-echo? */
23324 position
= make_number (pos
);
23326 if (BUFFERP (object
))
23328 /* Put all the overlays we want in a vector in overlay_vec. */
23329 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
23330 /* Sort overlays into increasing priority order. */
23331 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
23336 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
23337 && vpos
>= dpyinfo
->mouse_face_beg_row
23338 && vpos
<= dpyinfo
->mouse_face_end_row
23339 && (vpos
> dpyinfo
->mouse_face_beg_row
23340 || hpos
>= dpyinfo
->mouse_face_beg_col
)
23341 && (vpos
< dpyinfo
->mouse_face_end_row
23342 || hpos
< dpyinfo
->mouse_face_end_col
23343 || dpyinfo
->mouse_face_past_end
));
23346 cursor
= No_Cursor
;
23348 /* Check mouse-face highlighting. */
23350 /* If there exists an overlay with mouse-face overlapping
23351 the one we are currently highlighting, we have to
23352 check if we enter the overlapping overlay, and then
23353 highlight only that. */
23354 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
23355 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
23357 /* Find the highest priority overlay that has a mouse-face
23360 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
23362 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
23363 if (!NILP (mouse_face
))
23364 overlay
= overlay_vec
[i
];
23367 /* If we're actually highlighting the same overlay as
23368 before, there's no need to do that again. */
23369 if (!NILP (overlay
)
23370 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
23371 goto check_help_echo
;
23373 dpyinfo
->mouse_face_overlay
= overlay
;
23375 /* Clear the display of the old active region, if any. */
23376 if (clear_mouse_face (dpyinfo
))
23377 cursor
= No_Cursor
;
23379 /* If no overlay applies, get a text property. */
23380 if (NILP (overlay
))
23381 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
23383 /* Handle the overlay case. */
23384 if (!NILP (overlay
))
23386 /* Find the range of text around this char that
23387 should be active. */
23388 Lisp_Object before
, after
;
23391 before
= Foverlay_start (overlay
);
23392 after
= Foverlay_end (overlay
);
23393 /* Record this as the current active region. */
23394 fast_find_position (w
, XFASTINT (before
),
23395 &dpyinfo
->mouse_face_beg_col
,
23396 &dpyinfo
->mouse_face_beg_row
,
23397 &dpyinfo
->mouse_face_beg_x
,
23398 &dpyinfo
->mouse_face_beg_y
, Qnil
);
23400 dpyinfo
->mouse_face_past_end
23401 = !fast_find_position (w
, XFASTINT (after
),
23402 &dpyinfo
->mouse_face_end_col
,
23403 &dpyinfo
->mouse_face_end_row
,
23404 &dpyinfo
->mouse_face_end_x
,
23405 &dpyinfo
->mouse_face_end_y
, Qnil
);
23406 dpyinfo
->mouse_face_window
= window
;
23408 dpyinfo
->mouse_face_face_id
23409 = face_at_buffer_position (w
, pos
, 0, 0,
23411 !dpyinfo
->mouse_face_hidden
);
23413 /* Display it as active. */
23414 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23415 cursor
= No_Cursor
;
23417 /* Handle the text property case. */
23418 else if (!NILP (mouse_face
) && BUFFERP (object
))
23420 /* Find the range of text around this char that
23421 should be active. */
23422 Lisp_Object before
, after
, beginning
, end
;
23425 beginning
= Fmarker_position (w
->start
);
23426 end
= make_number (BUF_Z (XBUFFER (object
))
23427 - XFASTINT (w
->window_end_pos
));
23429 = Fprevious_single_property_change (make_number (pos
+ 1),
23431 object
, beginning
);
23433 = Fnext_single_property_change (position
, Qmouse_face
,
23436 /* Record this as the current active region. */
23437 fast_find_position (w
, XFASTINT (before
),
23438 &dpyinfo
->mouse_face_beg_col
,
23439 &dpyinfo
->mouse_face_beg_row
,
23440 &dpyinfo
->mouse_face_beg_x
,
23441 &dpyinfo
->mouse_face_beg_y
, Qnil
);
23442 dpyinfo
->mouse_face_past_end
23443 = !fast_find_position (w
, XFASTINT (after
),
23444 &dpyinfo
->mouse_face_end_col
,
23445 &dpyinfo
->mouse_face_end_row
,
23446 &dpyinfo
->mouse_face_end_x
,
23447 &dpyinfo
->mouse_face_end_y
, Qnil
);
23448 dpyinfo
->mouse_face_window
= window
;
23450 if (BUFFERP (object
))
23451 dpyinfo
->mouse_face_face_id
23452 = face_at_buffer_position (w
, pos
, 0, 0,
23454 !dpyinfo
->mouse_face_hidden
);
23456 /* Display it as active. */
23457 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23458 cursor
= No_Cursor
;
23460 else if (!NILP (mouse_face
) && STRINGP (object
))
23465 b
= Fprevious_single_property_change (make_number (pos
+ 1),
23468 e
= Fnext_single_property_change (position
, Qmouse_face
,
23471 b
= make_number (0);
23473 e
= make_number (SCHARS (object
) - 1);
23475 fast_find_string_pos (w
, XINT (b
), object
,
23476 &dpyinfo
->mouse_face_beg_col
,
23477 &dpyinfo
->mouse_face_beg_row
,
23478 &dpyinfo
->mouse_face_beg_x
,
23479 &dpyinfo
->mouse_face_beg_y
, 0);
23480 fast_find_string_pos (w
, XINT (e
), object
,
23481 &dpyinfo
->mouse_face_end_col
,
23482 &dpyinfo
->mouse_face_end_row
,
23483 &dpyinfo
->mouse_face_end_x
,
23484 &dpyinfo
->mouse_face_end_y
, 1);
23485 dpyinfo
->mouse_face_past_end
= 0;
23486 dpyinfo
->mouse_face_window
= window
;
23487 dpyinfo
->mouse_face_face_id
23488 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
23489 glyph
->face_id
, 1);
23490 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23491 cursor
= No_Cursor
;
23493 else if (STRINGP (object
) && NILP (mouse_face
))
23495 /* A string which doesn't have mouse-face, but
23496 the text ``under'' it might have. */
23497 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
23498 int start
= MATRIX_ROW_START_CHARPOS (r
);
23500 pos
= string_buffer_position (w
, object
, start
);
23502 mouse_face
= get_char_property_and_overlay (make_number (pos
),
23506 if (!NILP (mouse_face
) && !NILP (overlay
))
23508 Lisp_Object before
= Foverlay_start (overlay
);
23509 Lisp_Object after
= Foverlay_end (overlay
);
23512 /* Note that we might not be able to find position
23513 BEFORE in the glyph matrix if the overlay is
23514 entirely covered by a `display' property. In
23515 this case, we overshoot. So let's stop in
23516 the glyph matrix before glyphs for OBJECT. */
23517 fast_find_position (w
, XFASTINT (before
),
23518 &dpyinfo
->mouse_face_beg_col
,
23519 &dpyinfo
->mouse_face_beg_row
,
23520 &dpyinfo
->mouse_face_beg_x
,
23521 &dpyinfo
->mouse_face_beg_y
,
23524 dpyinfo
->mouse_face_past_end
23525 = !fast_find_position (w
, XFASTINT (after
),
23526 &dpyinfo
->mouse_face_end_col
,
23527 &dpyinfo
->mouse_face_end_row
,
23528 &dpyinfo
->mouse_face_end_x
,
23529 &dpyinfo
->mouse_face_end_y
,
23531 dpyinfo
->mouse_face_window
= window
;
23532 dpyinfo
->mouse_face_face_id
23533 = face_at_buffer_position (w
, pos
, 0, 0,
23535 !dpyinfo
->mouse_face_hidden
);
23537 /* Display it as active. */
23538 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23539 cursor
= No_Cursor
;
23546 /* Look for a `help-echo' property. */
23547 if (NILP (help_echo_string
)) {
23548 Lisp_Object help
, overlay
;
23550 /* Check overlays first. */
23551 help
= overlay
= Qnil
;
23552 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
23554 overlay
= overlay_vec
[i
];
23555 help
= Foverlay_get (overlay
, Qhelp_echo
);
23560 help_echo_string
= help
;
23561 help_echo_window
= window
;
23562 help_echo_object
= overlay
;
23563 help_echo_pos
= pos
;
23567 Lisp_Object object
= glyph
->object
;
23568 int charpos
= glyph
->charpos
;
23570 /* Try text properties. */
23571 if (STRINGP (object
)
23573 && charpos
< SCHARS (object
))
23575 help
= Fget_text_property (make_number (charpos
),
23576 Qhelp_echo
, object
);
23579 /* If the string itself doesn't specify a help-echo,
23580 see if the buffer text ``under'' it does. */
23581 struct glyph_row
*r
23582 = MATRIX_ROW (w
->current_matrix
, vpos
);
23583 int start
= MATRIX_ROW_START_CHARPOS (r
);
23584 int pos
= string_buffer_position (w
, object
, start
);
23587 help
= Fget_char_property (make_number (pos
),
23588 Qhelp_echo
, w
->buffer
);
23592 object
= w
->buffer
;
23597 else if (BUFFERP (object
)
23600 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
23605 help_echo_string
= help
;
23606 help_echo_window
= window
;
23607 help_echo_object
= object
;
23608 help_echo_pos
= charpos
;
23613 /* Look for a `pointer' property. */
23614 if (NILP (pointer
))
23616 /* Check overlays first. */
23617 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
23618 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
23620 if (NILP (pointer
))
23622 Lisp_Object object
= glyph
->object
;
23623 int charpos
= glyph
->charpos
;
23625 /* Try text properties. */
23626 if (STRINGP (object
)
23628 && charpos
< SCHARS (object
))
23630 pointer
= Fget_text_property (make_number (charpos
),
23632 if (NILP (pointer
))
23634 /* If the string itself doesn't specify a pointer,
23635 see if the buffer text ``under'' it does. */
23636 struct glyph_row
*r
23637 = MATRIX_ROW (w
->current_matrix
, vpos
);
23638 int start
= MATRIX_ROW_START_CHARPOS (r
);
23639 int pos
= string_buffer_position (w
, object
, start
);
23641 pointer
= Fget_char_property (make_number (pos
),
23642 Qpointer
, w
->buffer
);
23645 else if (BUFFERP (object
)
23648 pointer
= Fget_text_property (make_number (charpos
),
23655 current_buffer
= obuf
;
23660 define_frame_cursor1 (f
, cursor
, pointer
);
23665 Clear any mouse-face on window W. This function is part of the
23666 redisplay interface, and is called from try_window_id and similar
23667 functions to ensure the mouse-highlight is off. */
23670 x_clear_window_mouse_face (w
)
23673 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23674 Lisp_Object window
;
23677 XSETWINDOW (window
, w
);
23678 if (EQ (window
, dpyinfo
->mouse_face_window
))
23679 clear_mouse_face (dpyinfo
);
23685 Just discard the mouse face information for frame F, if any.
23686 This is used when the size of F is changed. */
23689 cancel_mouse_face (f
)
23692 Lisp_Object window
;
23693 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23695 window
= dpyinfo
->mouse_face_window
;
23696 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
23698 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
23699 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
23700 dpyinfo
->mouse_face_window
= Qnil
;
23705 #endif /* HAVE_WINDOW_SYSTEM */
23708 /***********************************************************************
23710 ***********************************************************************/
23712 #ifdef HAVE_WINDOW_SYSTEM
23714 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
23715 which intersects rectangle R. R is in window-relative coordinates. */
23718 expose_area (w
, row
, r
, area
)
23720 struct glyph_row
*row
;
23722 enum glyph_row_area area
;
23724 struct glyph
*first
= row
->glyphs
[area
];
23725 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
23726 struct glyph
*last
;
23727 int first_x
, start_x
, x
;
23729 if (area
== TEXT_AREA
&& row
->fill_line_p
)
23730 /* If row extends face to end of line write the whole line. */
23731 draw_glyphs (w
, 0, row
, area
,
23732 0, row
->used
[area
],
23733 DRAW_NORMAL_TEXT
, 0);
23736 /* Set START_X to the window-relative start position for drawing glyphs of
23737 AREA. The first glyph of the text area can be partially visible.
23738 The first glyphs of other areas cannot. */
23739 start_x
= window_box_left_offset (w
, area
);
23741 if (area
== TEXT_AREA
)
23744 /* Find the first glyph that must be redrawn. */
23746 && x
+ first
->pixel_width
< r
->x
)
23748 x
+= first
->pixel_width
;
23752 /* Find the last one. */
23756 && x
< r
->x
+ r
->width
)
23758 x
+= last
->pixel_width
;
23764 draw_glyphs (w
, first_x
- start_x
, row
, area
,
23765 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
23766 DRAW_NORMAL_TEXT
, 0);
23771 /* Redraw the parts of the glyph row ROW on window W intersecting
23772 rectangle R. R is in window-relative coordinates. Value is
23773 non-zero if mouse-face was overwritten. */
23776 expose_line (w
, row
, r
)
23778 struct glyph_row
*row
;
23781 xassert (row
->enabled_p
);
23783 if (row
->mode_line_p
|| w
->pseudo_window_p
)
23784 draw_glyphs (w
, 0, row
, TEXT_AREA
,
23785 0, row
->used
[TEXT_AREA
],
23786 DRAW_NORMAL_TEXT
, 0);
23789 if (row
->used
[LEFT_MARGIN_AREA
])
23790 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
23791 if (row
->used
[TEXT_AREA
])
23792 expose_area (w
, row
, r
, TEXT_AREA
);
23793 if (row
->used
[RIGHT_MARGIN_AREA
])
23794 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
23795 draw_row_fringe_bitmaps (w
, row
);
23798 return row
->mouse_face_p
;
23802 /* Redraw those parts of glyphs rows during expose event handling that
23803 overlap other rows. Redrawing of an exposed line writes over parts
23804 of lines overlapping that exposed line; this function fixes that.
23806 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
23807 row in W's current matrix that is exposed and overlaps other rows.
23808 LAST_OVERLAPPING_ROW is the last such row. */
23811 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
, r
)
23813 struct glyph_row
*first_overlapping_row
;
23814 struct glyph_row
*last_overlapping_row
;
23817 struct glyph_row
*row
;
23819 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
23820 if (row
->overlapping_p
)
23822 xassert (row
->enabled_p
&& !row
->mode_line_p
);
23825 if (row
->used
[LEFT_MARGIN_AREA
])
23826 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
23828 if (row
->used
[TEXT_AREA
])
23829 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
23831 if (row
->used
[RIGHT_MARGIN_AREA
])
23832 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
23838 /* Return non-zero if W's cursor intersects rectangle R. */
23841 phys_cursor_in_rect_p (w
, r
)
23845 XRectangle cr
, result
;
23846 struct glyph
*cursor_glyph
;
23847 struct glyph_row
*row
;
23849 if (w
->phys_cursor
.vpos
>= 0
23850 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
23851 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
23853 && row
->cursor_in_fringe_p
)
23855 /* Cursor is in the fringe. */
23856 cr
.x
= window_box_right_offset (w
,
23857 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
23858 ? RIGHT_MARGIN_AREA
23861 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
23862 cr
.height
= row
->height
;
23863 return x_intersect_rectangles (&cr
, r
, &result
);
23866 cursor_glyph
= get_phys_cursor_glyph (w
);
23869 /* r is relative to W's box, but w->phys_cursor.x is relative
23870 to left edge of W's TEXT area. Adjust it. */
23871 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
23872 cr
.y
= w
->phys_cursor
.y
;
23873 cr
.width
= cursor_glyph
->pixel_width
;
23874 cr
.height
= w
->phys_cursor_height
;
23875 /* ++KFS: W32 version used W32-specific IntersectRect here, but
23876 I assume the effect is the same -- and this is portable. */
23877 return x_intersect_rectangles (&cr
, r
, &result
);
23879 /* If we don't understand the format, pretend we're not in the hot-spot. */
23885 Draw a vertical window border to the right of window W if W doesn't
23886 have vertical scroll bars. */
23889 x_draw_vertical_border (w
)
23892 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23894 /* We could do better, if we knew what type of scroll-bar the adjacent
23895 windows (on either side) have... But we don't :-(
23896 However, I think this works ok. ++KFS 2003-04-25 */
23898 /* Redraw borders between horizontally adjacent windows. Don't
23899 do it for frames with vertical scroll bars because either the
23900 right scroll bar of a window, or the left scroll bar of its
23901 neighbor will suffice as a border. */
23902 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
23905 if (!WINDOW_RIGHTMOST_P (w
)
23906 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
23908 int x0
, x1
, y0
, y1
;
23910 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23913 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23916 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
23918 else if (!WINDOW_LEFTMOST_P (w
)
23919 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
23921 int x0
, x1
, y0
, y1
;
23923 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23926 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23929 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
23934 /* Redraw the part of window W intersection rectangle FR. Pixel
23935 coordinates in FR are frame-relative. Call this function with
23936 input blocked. Value is non-zero if the exposure overwrites
23940 expose_window (w
, fr
)
23944 struct frame
*f
= XFRAME (w
->frame
);
23946 int mouse_face_overwritten_p
= 0;
23948 /* If window is not yet fully initialized, do nothing. This can
23949 happen when toolkit scroll bars are used and a window is split.
23950 Reconfiguring the scroll bar will generate an expose for a newly
23952 if (w
->current_matrix
== NULL
)
23955 /* When we're currently updating the window, display and current
23956 matrix usually don't agree. Arrange for a thorough display
23958 if (w
== updated_window
)
23960 SET_FRAME_GARBAGED (f
);
23964 /* Frame-relative pixel rectangle of W. */
23965 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
23966 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
23967 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
23968 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
23970 if (x_intersect_rectangles (fr
, &wr
, &r
))
23972 int yb
= window_text_bottom_y (w
);
23973 struct glyph_row
*row
;
23974 int cursor_cleared_p
;
23975 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
23977 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
23978 r
.x
, r
.y
, r
.width
, r
.height
));
23980 /* Convert to window coordinates. */
23981 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
23982 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
23984 /* Turn off the cursor. */
23985 if (!w
->pseudo_window_p
23986 && phys_cursor_in_rect_p (w
, &r
))
23988 x_clear_cursor (w
);
23989 cursor_cleared_p
= 1;
23992 cursor_cleared_p
= 0;
23994 /* Update lines intersecting rectangle R. */
23995 first_overlapping_row
= last_overlapping_row
= NULL
;
23996 for (row
= w
->current_matrix
->rows
;
24001 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
24003 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
24004 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
24005 || (r
.y
>= y0
&& r
.y
< y1
)
24006 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
24008 /* A header line may be overlapping, but there is no need
24009 to fix overlapping areas for them. KFS 2005-02-12 */
24010 if (row
->overlapping_p
&& !row
->mode_line_p
)
24012 if (first_overlapping_row
== NULL
)
24013 first_overlapping_row
= row
;
24014 last_overlapping_row
= row
;
24018 if (expose_line (w
, row
, &r
))
24019 mouse_face_overwritten_p
= 1;
24022 else if (row
->overlapping_p
)
24024 /* We must redraw a row overlapping the exposed area. */
24026 ? y0
+ row
->phys_height
> r
.y
24027 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
24029 if (first_overlapping_row
== NULL
)
24030 first_overlapping_row
= row
;
24031 last_overlapping_row
= row
;
24039 /* Display the mode line if there is one. */
24040 if (WINDOW_WANTS_MODELINE_P (w
)
24041 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
24043 && row
->y
< r
.y
+ r
.height
)
24045 if (expose_line (w
, row
, &r
))
24046 mouse_face_overwritten_p
= 1;
24049 if (!w
->pseudo_window_p
)
24051 /* Fix the display of overlapping rows. */
24052 if (first_overlapping_row
)
24053 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
24056 /* Draw border between windows. */
24057 x_draw_vertical_border (w
);
24059 /* Turn the cursor on again. */
24060 if (cursor_cleared_p
)
24061 update_window_cursor (w
, 1);
24065 return mouse_face_overwritten_p
;
24070 /* Redraw (parts) of all windows in the window tree rooted at W that
24071 intersect R. R contains frame pixel coordinates. Value is
24072 non-zero if the exposure overwrites mouse-face. */
24075 expose_window_tree (w
, r
)
24079 struct frame
*f
= XFRAME (w
->frame
);
24080 int mouse_face_overwritten_p
= 0;
24082 while (w
&& !FRAME_GARBAGED_P (f
))
24084 if (!NILP (w
->hchild
))
24085 mouse_face_overwritten_p
24086 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
24087 else if (!NILP (w
->vchild
))
24088 mouse_face_overwritten_p
24089 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
24091 mouse_face_overwritten_p
|= expose_window (w
, r
);
24093 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
24096 return mouse_face_overwritten_p
;
24101 Redisplay an exposed area of frame F. X and Y are the upper-left
24102 corner of the exposed rectangle. W and H are width and height of
24103 the exposed area. All are pixel values. W or H zero means redraw
24104 the entire frame. */
24107 expose_frame (f
, x
, y
, w
, h
)
24112 int mouse_face_overwritten_p
= 0;
24114 TRACE ((stderr
, "expose_frame "));
24116 /* No need to redraw if frame will be redrawn soon. */
24117 if (FRAME_GARBAGED_P (f
))
24119 TRACE ((stderr
, " garbaged\n"));
24123 /* If basic faces haven't been realized yet, there is no point in
24124 trying to redraw anything. This can happen when we get an expose
24125 event while Emacs is starting, e.g. by moving another window. */
24126 if (FRAME_FACE_CACHE (f
) == NULL
24127 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
24129 TRACE ((stderr
, " no faces\n"));
24133 if (w
== 0 || h
== 0)
24136 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
24137 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
24147 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
24148 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
24150 if (WINDOWP (f
->tool_bar_window
))
24151 mouse_face_overwritten_p
24152 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
24154 #ifdef HAVE_X_WINDOWS
24156 #ifndef USE_X_TOOLKIT
24157 if (WINDOWP (f
->menu_bar_window
))
24158 mouse_face_overwritten_p
24159 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
24160 #endif /* not USE_X_TOOLKIT */
24164 /* Some window managers support a focus-follows-mouse style with
24165 delayed raising of frames. Imagine a partially obscured frame,
24166 and moving the mouse into partially obscured mouse-face on that
24167 frame. The visible part of the mouse-face will be highlighted,
24168 then the WM raises the obscured frame. With at least one WM, KDE
24169 2.1, Emacs is not getting any event for the raising of the frame
24170 (even tried with SubstructureRedirectMask), only Expose events.
24171 These expose events will draw text normally, i.e. not
24172 highlighted. Which means we must redo the highlight here.
24173 Subsume it under ``we love X''. --gerd 2001-08-15 */
24174 /* Included in Windows version because Windows most likely does not
24175 do the right thing if any third party tool offers
24176 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
24177 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
24179 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24180 if (f
== dpyinfo
->mouse_face_mouse_frame
)
24182 int x
= dpyinfo
->mouse_face_mouse_x
;
24183 int y
= dpyinfo
->mouse_face_mouse_y
;
24184 clear_mouse_face (dpyinfo
);
24185 note_mouse_highlight (f
, x
, y
);
24192 Determine the intersection of two rectangles R1 and R2. Return
24193 the intersection in *RESULT. Value is non-zero if RESULT is not
24197 x_intersect_rectangles (r1
, r2
, result
)
24198 XRectangle
*r1
, *r2
, *result
;
24200 XRectangle
*left
, *right
;
24201 XRectangle
*upper
, *lower
;
24202 int intersection_p
= 0;
24204 /* Rearrange so that R1 is the left-most rectangle. */
24206 left
= r1
, right
= r2
;
24208 left
= r2
, right
= r1
;
24210 /* X0 of the intersection is right.x0, if this is inside R1,
24211 otherwise there is no intersection. */
24212 if (right
->x
<= left
->x
+ left
->width
)
24214 result
->x
= right
->x
;
24216 /* The right end of the intersection is the minimum of the
24217 the right ends of left and right. */
24218 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
24221 /* Same game for Y. */
24223 upper
= r1
, lower
= r2
;
24225 upper
= r2
, lower
= r1
;
24227 /* The upper end of the intersection is lower.y0, if this is inside
24228 of upper. Otherwise, there is no intersection. */
24229 if (lower
->y
<= upper
->y
+ upper
->height
)
24231 result
->y
= lower
->y
;
24233 /* The lower end of the intersection is the minimum of the lower
24234 ends of upper and lower. */
24235 result
->height
= (min (lower
->y
+ lower
->height
,
24236 upper
->y
+ upper
->height
)
24238 intersection_p
= 1;
24242 return intersection_p
;
24245 #endif /* HAVE_WINDOW_SYSTEM */
24248 /***********************************************************************
24250 ***********************************************************************/
24255 Vwith_echo_area_save_vector
= Qnil
;
24256 staticpro (&Vwith_echo_area_save_vector
);
24258 Vmessage_stack
= Qnil
;
24259 staticpro (&Vmessage_stack
);
24261 Qinhibit_redisplay
= intern ("inhibit-redisplay");
24262 staticpro (&Qinhibit_redisplay
);
24264 message_dolog_marker1
= Fmake_marker ();
24265 staticpro (&message_dolog_marker1
);
24266 message_dolog_marker2
= Fmake_marker ();
24267 staticpro (&message_dolog_marker2
);
24268 message_dolog_marker3
= Fmake_marker ();
24269 staticpro (&message_dolog_marker3
);
24272 defsubr (&Sdump_frame_glyph_matrix
);
24273 defsubr (&Sdump_glyph_matrix
);
24274 defsubr (&Sdump_glyph_row
);
24275 defsubr (&Sdump_tool_bar_row
);
24276 defsubr (&Strace_redisplay
);
24277 defsubr (&Strace_to_stderr
);
24279 #ifdef HAVE_WINDOW_SYSTEM
24280 defsubr (&Stool_bar_lines_needed
);
24281 defsubr (&Slookup_image_map
);
24283 defsubr (&Sformat_mode_line
);
24284 defsubr (&Sinvisible_p
);
24286 staticpro (&Qmenu_bar_update_hook
);
24287 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
24289 staticpro (&Qoverriding_terminal_local_map
);
24290 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
24292 staticpro (&Qoverriding_local_map
);
24293 Qoverriding_local_map
= intern ("overriding-local-map");
24295 staticpro (&Qwindow_scroll_functions
);
24296 Qwindow_scroll_functions
= intern ("window-scroll-functions");
24298 staticpro (&Qwindow_text_change_functions
);
24299 Qwindow_text_change_functions
= intern ("window-text-change-functions");
24301 staticpro (&Qredisplay_end_trigger_functions
);
24302 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
24304 staticpro (&Qinhibit_point_motion_hooks
);
24305 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
24307 Qeval
= intern ("eval");
24308 staticpro (&Qeval
);
24310 QCdata
= intern (":data");
24311 staticpro (&QCdata
);
24312 Qdisplay
= intern ("display");
24313 staticpro (&Qdisplay
);
24314 Qspace_width
= intern ("space-width");
24315 staticpro (&Qspace_width
);
24316 Qraise
= intern ("raise");
24317 staticpro (&Qraise
);
24318 Qslice
= intern ("slice");
24319 staticpro (&Qslice
);
24320 Qspace
= intern ("space");
24321 staticpro (&Qspace
);
24322 Qmargin
= intern ("margin");
24323 staticpro (&Qmargin
);
24324 Qpointer
= intern ("pointer");
24325 staticpro (&Qpointer
);
24326 Qleft_margin
= intern ("left-margin");
24327 staticpro (&Qleft_margin
);
24328 Qright_margin
= intern ("right-margin");
24329 staticpro (&Qright_margin
);
24330 Qcenter
= intern ("center");
24331 staticpro (&Qcenter
);
24332 Qline_height
= intern ("line-height");
24333 staticpro (&Qline_height
);
24334 QCalign_to
= intern (":align-to");
24335 staticpro (&QCalign_to
);
24336 QCrelative_width
= intern (":relative-width");
24337 staticpro (&QCrelative_width
);
24338 QCrelative_height
= intern (":relative-height");
24339 staticpro (&QCrelative_height
);
24340 QCeval
= intern (":eval");
24341 staticpro (&QCeval
);
24342 QCpropertize
= intern (":propertize");
24343 staticpro (&QCpropertize
);
24344 QCfile
= intern (":file");
24345 staticpro (&QCfile
);
24346 Qfontified
= intern ("fontified");
24347 staticpro (&Qfontified
);
24348 Qfontification_functions
= intern ("fontification-functions");
24349 staticpro (&Qfontification_functions
);
24350 Qtrailing_whitespace
= intern ("trailing-whitespace");
24351 staticpro (&Qtrailing_whitespace
);
24352 Qescape_glyph
= intern ("escape-glyph");
24353 staticpro (&Qescape_glyph
);
24354 Qnobreak_space
= intern ("nobreak-space");
24355 staticpro (&Qnobreak_space
);
24356 Qimage
= intern ("image");
24357 staticpro (&Qimage
);
24358 QCmap
= intern (":map");
24359 staticpro (&QCmap
);
24360 QCpointer
= intern (":pointer");
24361 staticpro (&QCpointer
);
24362 Qrect
= intern ("rect");
24363 staticpro (&Qrect
);
24364 Qcircle
= intern ("circle");
24365 staticpro (&Qcircle
);
24366 Qpoly
= intern ("poly");
24367 staticpro (&Qpoly
);
24368 Qmessage_truncate_lines
= intern ("message-truncate-lines");
24369 staticpro (&Qmessage_truncate_lines
);
24370 Qgrow_only
= intern ("grow-only");
24371 staticpro (&Qgrow_only
);
24372 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
24373 staticpro (&Qinhibit_menubar_update
);
24374 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
24375 staticpro (&Qinhibit_eval_during_redisplay
);
24376 Qposition
= intern ("position");
24377 staticpro (&Qposition
);
24378 Qbuffer_position
= intern ("buffer-position");
24379 staticpro (&Qbuffer_position
);
24380 Qobject
= intern ("object");
24381 staticpro (&Qobject
);
24382 Qbar
= intern ("bar");
24384 Qhbar
= intern ("hbar");
24385 staticpro (&Qhbar
);
24386 Qbox
= intern ("box");
24388 Qhollow
= intern ("hollow");
24389 staticpro (&Qhollow
);
24390 Qhand
= intern ("hand");
24391 staticpro (&Qhand
);
24392 Qarrow
= intern ("arrow");
24393 staticpro (&Qarrow
);
24394 Qtext
= intern ("text");
24395 staticpro (&Qtext
);
24396 Qrisky_local_variable
= intern ("risky-local-variable");
24397 staticpro (&Qrisky_local_variable
);
24398 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
24399 staticpro (&Qinhibit_free_realized_faces
);
24401 list_of_error
= Fcons (Fcons (intern ("error"),
24402 Fcons (intern ("void-variable"), Qnil
)),
24404 staticpro (&list_of_error
);
24406 Qlast_arrow_position
= intern ("last-arrow-position");
24407 staticpro (&Qlast_arrow_position
);
24408 Qlast_arrow_string
= intern ("last-arrow-string");
24409 staticpro (&Qlast_arrow_string
);
24411 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
24412 staticpro (&Qoverlay_arrow_string
);
24413 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
24414 staticpro (&Qoverlay_arrow_bitmap
);
24416 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
24417 staticpro (&echo_buffer
[0]);
24418 staticpro (&echo_buffer
[1]);
24420 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
24421 staticpro (&echo_area_buffer
[0]);
24422 staticpro (&echo_area_buffer
[1]);
24424 Vmessages_buffer_name
= build_string ("*Messages*");
24425 staticpro (&Vmessages_buffer_name
);
24427 mode_line_proptrans_alist
= Qnil
;
24428 staticpro (&mode_line_proptrans_alist
);
24429 mode_line_string_list
= Qnil
;
24430 staticpro (&mode_line_string_list
);
24431 mode_line_string_face
= Qnil
;
24432 staticpro (&mode_line_string_face
);
24433 mode_line_string_face_prop
= Qnil
;
24434 staticpro (&mode_line_string_face_prop
);
24435 Vmode_line_unwind_vector
= Qnil
;
24436 staticpro (&Vmode_line_unwind_vector
);
24438 help_echo_string
= Qnil
;
24439 staticpro (&help_echo_string
);
24440 help_echo_object
= Qnil
;
24441 staticpro (&help_echo_object
);
24442 help_echo_window
= Qnil
;
24443 staticpro (&help_echo_window
);
24444 previous_help_echo_string
= Qnil
;
24445 staticpro (&previous_help_echo_string
);
24446 help_echo_pos
= -1;
24448 #ifdef HAVE_WINDOW_SYSTEM
24449 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
24450 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
24451 For example, if a block cursor is over a tab, it will be drawn as
24452 wide as that tab on the display. */);
24453 x_stretch_cursor_p
= 0;
24456 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
24457 doc
: /* *Non-nil means highlight trailing whitespace.
24458 The face used for trailing whitespace is `trailing-whitespace'. */);
24459 Vshow_trailing_whitespace
= Qnil
;
24461 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
24462 doc
: /* *Control highlighting of nobreak space and soft hyphen.
24463 A value of t means highlight the character itself (for nobreak space,
24464 use face `nobreak-space').
24465 A value of nil means no highlighting.
24466 Other values mean display the escape glyph followed by an ordinary
24467 space or ordinary hyphen. */);
24468 Vnobreak_char_display
= Qt
;
24470 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
24471 doc
: /* *The pointer shape to show in void text areas.
24472 A value of nil means to show the text pointer. Other options are `arrow',
24473 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
24474 Vvoid_text_area_pointer
= Qarrow
;
24476 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
24477 doc
: /* Non-nil means don't actually do any redisplay.
24478 This is used for internal purposes. */);
24479 Vinhibit_redisplay
= Qnil
;
24481 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
24482 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
24483 Vglobal_mode_string
= Qnil
;
24485 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
24486 doc
: /* Marker for where to display an arrow on top of the buffer text.
24487 This must be the beginning of a line in order to work.
24488 See also `overlay-arrow-string'. */);
24489 Voverlay_arrow_position
= Qnil
;
24491 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
24492 doc
: /* String to display as an arrow in non-window frames.
24493 See also `overlay-arrow-position'. */);
24494 Voverlay_arrow_string
= build_string ("=>");
24496 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
24497 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
24498 The symbols on this list are examined during redisplay to determine
24499 where to display overlay arrows. */);
24500 Voverlay_arrow_variable_list
24501 = Fcons (intern ("overlay-arrow-position"), Qnil
);
24503 DEFVAR_INT ("scroll-step", &scroll_step
,
24504 doc
: /* *The number of lines to try scrolling a window by when point moves out.
24505 If that fails to bring point back on frame, point is centered instead.
24506 If this is zero, point is always centered after it moves off frame.
24507 If you want scrolling to always be a line at a time, you should set
24508 `scroll-conservatively' to a large value rather than set this to 1. */);
24510 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
24511 doc
: /* *Scroll up to this many lines, to bring point back on screen.
24512 If point moves off-screen, redisplay will scroll by up to
24513 `scroll-conservatively' lines in order to bring point just barely
24514 onto the screen again. If that cannot be done, then redisplay
24515 recenters point as usual.
24517 A value of zero means always recenter point if it moves off screen. */);
24518 scroll_conservatively
= 0;
24520 DEFVAR_INT ("scroll-margin", &scroll_margin
,
24521 doc
: /* *Number of lines of margin at the top and bottom of a window.
24522 Recenter the window whenever point gets within this many lines
24523 of the top or bottom of the window. */);
24526 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
24527 doc
: /* Pixels per inch value for non-window system displays.
24528 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
24529 Vdisplay_pixels_per_inch
= make_float (72.0);
24532 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
24535 DEFVAR_BOOL ("truncate-partial-width-windows",
24536 &truncate_partial_width_windows
,
24537 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide.
24538 Nil means to respect the value of `truncate-lines'. */);
24539 truncate_partial_width_windows
= 1;
24541 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
24542 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
24543 Any other value means to use the appropriate face, `mode-line',
24544 `header-line', or `menu' respectively. */);
24545 mode_line_inverse_video
= 1;
24547 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
24548 doc
: /* *Maximum buffer size for which line number should be displayed.
24549 If the buffer is bigger than this, the line number does not appear
24550 in the mode line. A value of nil means no limit. */);
24551 Vline_number_display_limit
= Qnil
;
24553 DEFVAR_INT ("line-number-display-limit-width",
24554 &line_number_display_limit_width
,
24555 doc
: /* *Maximum line width (in characters) for line number display.
24556 If the average length of the lines near point is bigger than this, then the
24557 line number may be omitted from the mode line. */);
24558 line_number_display_limit_width
= 200;
24560 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
24561 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
24562 highlight_nonselected_windows
= 0;
24564 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
24565 doc
: /* Non-nil if more than one frame is visible on this display.
24566 Minibuffer-only frames don't count, but iconified frames do.
24567 This variable is not guaranteed to be accurate except while processing
24568 `frame-title-format' and `icon-title-format'. */);
24570 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
24571 doc
: /* Template for displaying the title bar of visible frames.
24572 \(Assuming the window manager supports this feature.)
24574 This variable has the same structure as `mode-line-format', except that
24575 the %c and %l constructs are ignored. It is used only on frames for
24576 which no explicit name has been set \(see `modify-frame-parameters'). */);
24578 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
24579 doc
: /* Template for displaying the title bar of an iconified frame.
24580 \(Assuming the window manager supports this feature.)
24581 This variable has the same structure as `mode-line-format' (which see),
24582 and is used only on frames for which no explicit name has been set
24583 \(see `modify-frame-parameters'). */);
24585 = Vframe_title_format
24586 = Fcons (intern ("multiple-frames"),
24587 Fcons (build_string ("%b"),
24588 Fcons (Fcons (empty_unibyte_string
,
24589 Fcons (intern ("invocation-name"),
24590 Fcons (build_string ("@"),
24591 Fcons (intern ("system-name"),
24595 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
24596 doc
: /* Maximum number of lines to keep in the message log buffer.
24597 If nil, disable message logging. If t, log messages but don't truncate
24598 the buffer when it becomes large. */);
24599 Vmessage_log_max
= make_number (100);
24601 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
24602 doc
: /* Functions called before redisplay, if window sizes have changed.
24603 The value should be a list of functions that take one argument.
24604 Just before redisplay, for each frame, if any of its windows have changed
24605 size since the last redisplay, or have been split or deleted,
24606 all the functions in the list are called, with the frame as argument. */);
24607 Vwindow_size_change_functions
= Qnil
;
24609 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
24610 doc
: /* List of functions to call before redisplaying a window with scrolling.
24611 Each function is called with two arguments, the window
24612 and its new display-start position. Note that the value of `window-end'
24613 is not valid when these functions are called. */);
24614 Vwindow_scroll_functions
= Qnil
;
24616 DEFVAR_LISP ("window-text-change-functions",
24617 &Vwindow_text_change_functions
,
24618 doc
: /* Functions to call in redisplay when text in the window might change. */);
24619 Vwindow_text_change_functions
= Qnil
;
24621 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
24622 doc
: /* Functions called when redisplay of a window reaches the end trigger.
24623 Each function is called with two arguments, the window and the end trigger value.
24624 See `set-window-redisplay-end-trigger'. */);
24625 Vredisplay_end_trigger_functions
= Qnil
;
24627 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
24628 doc
: /* *Non-nil means autoselect window with mouse pointer.
24629 If nil, do not autoselect windows.
24630 A positive number means delay autoselection by that many seconds: a
24631 window is autoselected only after the mouse has remained in that
24632 window for the duration of the delay.
24633 A negative number has a similar effect, but causes windows to be
24634 autoselected only after the mouse has stopped moving. \(Because of
24635 the way Emacs compares mouse events, you will occasionally wait twice
24636 that time before the window gets selected.\)
24637 Any other value means to autoselect window instantaneously when the
24638 mouse pointer enters it.
24640 Autoselection selects the minibuffer only if it is active, and never
24641 unselects the minibuffer if it is active.
24643 When customizing this variable make sure that the actual value of
24644 `focus-follows-mouse' matches the behavior of your window manager. */);
24645 Vmouse_autoselect_window
= Qnil
;
24647 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
24648 doc
: /* *Non-nil means automatically resize tool-bars.
24649 This dynamically changes the tool-bar's height to the minimum height
24650 that is needed to make all tool-bar items visible.
24651 If value is `grow-only', the tool-bar's height is only increased
24652 automatically; to decrease the tool-bar height, use \\[recenter]. */);
24653 Vauto_resize_tool_bars
= Qt
;
24655 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
24656 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
24657 auto_raise_tool_bar_buttons_p
= 1;
24659 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
24660 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
24661 make_cursor_line_fully_visible_p
= 1;
24663 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
24664 doc
: /* *Border below tool-bar in pixels.
24665 If an integer, use it as the height of the border.
24666 If it is one of `internal-border-width' or `border-width', use the
24667 value of the corresponding frame parameter.
24668 Otherwise, no border is added below the tool-bar. */);
24669 Vtool_bar_border
= Qinternal_border_width
;
24671 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
24672 doc
: /* *Margin around tool-bar buttons in pixels.
24673 If an integer, use that for both horizontal and vertical margins.
24674 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
24675 HORZ specifying the horizontal margin, and VERT specifying the
24676 vertical margin. */);
24677 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
24679 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
24680 doc
: /* *Relief thickness of tool-bar buttons. */);
24681 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
24683 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
24684 doc
: /* List of functions to call to fontify regions of text.
24685 Each function is called with one argument POS. Functions must
24686 fontify a region starting at POS in the current buffer, and give
24687 fontified regions the property `fontified'. */);
24688 Vfontification_functions
= Qnil
;
24689 Fmake_variable_buffer_local (Qfontification_functions
);
24691 DEFVAR_BOOL ("unibyte-display-via-language-environment",
24692 &unibyte_display_via_language_environment
,
24693 doc
: /* *Non-nil means display unibyte text according to language environment.
24694 Specifically this means that unibyte non-ASCII characters
24695 are displayed by converting them to the equivalent multibyte characters
24696 according to the current language environment. As a result, they are
24697 displayed according to the current fontset. */);
24698 unibyte_display_via_language_environment
= 0;
24700 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
24701 doc
: /* *Maximum height for resizing mini-windows.
24702 If a float, it specifies a fraction of the mini-window frame's height.
24703 If an integer, it specifies a number of lines. */);
24704 Vmax_mini_window_height
= make_float (0.25);
24706 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
24707 doc
: /* *How to resize mini-windows.
24708 A value of nil means don't automatically resize mini-windows.
24709 A value of t means resize them to fit the text displayed in them.
24710 A value of `grow-only', the default, means let mini-windows grow
24711 only, until their display becomes empty, at which point the windows
24712 go back to their normal size. */);
24713 Vresize_mini_windows
= Qgrow_only
;
24715 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
24716 doc
: /* Alist specifying how to blink the cursor off.
24717 Each element has the form (ON-STATE . OFF-STATE). Whenever the
24718 `cursor-type' frame-parameter or variable equals ON-STATE,
24719 comparing using `equal', Emacs uses OFF-STATE to specify
24720 how to blink it off. ON-STATE and OFF-STATE are values for
24721 the `cursor-type' frame parameter.
24723 If a frame's ON-STATE has no entry in this list,
24724 the frame's other specifications determine how to blink the cursor off. */);
24725 Vblink_cursor_alist
= Qnil
;
24727 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
24728 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
24729 automatic_hscrolling_p
= 1;
24730 Qauto_hscroll_mode
= intern ("auto-hscroll-mode");
24731 staticpro (&Qauto_hscroll_mode
);
24733 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
24734 doc
: /* *How many columns away from the window edge point is allowed to get
24735 before automatic hscrolling will horizontally scroll the window. */);
24736 hscroll_margin
= 5;
24738 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
24739 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
24740 When point is less than `hscroll-margin' columns from the window
24741 edge, automatic hscrolling will scroll the window by the amount of columns
24742 determined by this variable. If its value is a positive integer, scroll that
24743 many columns. If it's a positive floating-point number, it specifies the
24744 fraction of the window's width to scroll. If it's nil or zero, point will be
24745 centered horizontally after the scroll. Any other value, including negative
24746 numbers, are treated as if the value were zero.
24748 Automatic hscrolling always moves point outside the scroll margin, so if
24749 point was more than scroll step columns inside the margin, the window will
24750 scroll more than the value given by the scroll step.
24752 Note that the lower bound for automatic hscrolling specified by `scroll-left'
24753 and `scroll-right' overrides this variable's effect. */);
24754 Vhscroll_step
= make_number (0);
24756 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
24757 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
24758 Bind this around calls to `message' to let it take effect. */);
24759 message_truncate_lines
= 0;
24761 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
24762 doc
: /* Normal hook run to update the menu bar definitions.
24763 Redisplay runs this hook before it redisplays the menu bar.
24764 This is used to update submenus such as Buffers,
24765 whose contents depend on various data. */);
24766 Vmenu_bar_update_hook
= Qnil
;
24768 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
24769 doc
: /* Frame for which we are updating a menu.
24770 The enable predicate for a menu binding should check this variable. */);
24771 Vmenu_updating_frame
= Qnil
;
24773 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
24774 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
24775 inhibit_menubar_update
= 0;
24777 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
24778 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
24779 inhibit_eval_during_redisplay
= 0;
24781 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
24782 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
24783 inhibit_free_realized_faces
= 0;
24786 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
24787 doc
: /* Inhibit try_window_id display optimization. */);
24788 inhibit_try_window_id
= 0;
24790 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
24791 doc
: /* Inhibit try_window_reusing display optimization. */);
24792 inhibit_try_window_reusing
= 0;
24794 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
24795 doc
: /* Inhibit try_cursor_movement display optimization. */);
24796 inhibit_try_cursor_movement
= 0;
24797 #endif /* GLYPH_DEBUG */
24799 DEFVAR_INT ("overline-margin", &overline_margin
,
24800 doc
: /* *Space between overline and text, in pixels.
24801 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
24802 margin to the caracter height. */);
24803 overline_margin
= 2;
24807 /* Initialize this module when Emacs starts. */
24812 Lisp_Object root_window
;
24813 struct window
*mini_w
;
24815 current_header_line_height
= current_mode_line_height
= -1;
24817 CHARPOS (this_line_start_pos
) = 0;
24819 mini_w
= XWINDOW (minibuf_window
);
24820 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
24822 if (!noninteractive
)
24824 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
24827 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
24828 set_window_height (root_window
,
24829 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
24831 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
24832 set_window_height (minibuf_window
, 1, 0);
24834 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
24835 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
24837 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
24838 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
24839 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
24841 /* The default ellipsis glyphs `...'. */
24842 for (i
= 0; i
< 3; ++i
)
24843 default_invis_vector
[i
] = make_number ('.');
24847 /* Allocate the buffer for frame titles.
24848 Also used for `format-mode-line'. */
24850 mode_line_noprop_buf
= (char *) xmalloc (size
);
24851 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
24852 mode_line_noprop_ptr
= mode_line_noprop_buf
;
24853 mode_line_target
= MODE_LINE_DISPLAY
;
24856 help_echo_showing_p
= 0;
24860 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
24861 (do not change this comment) */