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 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
27 Emacs separates the task of updating the display from code
28 modifying global state, e.g. buffer text. This way functions
29 operating on buffers don't also have to be concerned with updating
32 Updating the display is triggered by the Lisp interpreter when it
33 decides it's time to do it. This is done either automatically for
34 you as part of the interpreter's command loop or as the result of
35 calling Lisp functions like `sit-for'. The C function `redisplay'
36 in xdisp.c is the only entry into the inner redisplay code. (Or,
37 let's say almost---see the description of direct update
40 The following diagram shows how redisplay code is invoked. As you
41 can see, Lisp calls redisplay and vice versa. Under window systems
42 like X, some portions of the redisplay code are also called
43 asynchronously during mouse movement or expose events. It is very
44 important that these code parts do NOT use the C library (malloc,
45 free) because many C libraries under Unix are not reentrant. They
46 may also NOT call functions of the Lisp interpreter which could
47 change the interpreter's state. If you don't follow these rules,
48 you will encounter bugs which are very hard to explain.
50 (Direct functions, see below)
51 direct_output_for_insert,
52 direct_forward_char (dispnew.c)
53 +---------------------------------+
56 +--------------+ redisplay +----------------+
57 | Lisp machine |---------------->| Redisplay code |<--+
58 +--------------+ (xdisp.c) +----------------+ |
60 +----------------------------------+ |
61 Don't use this path when called |
64 expose_window (asynchronous) |
66 X expose events -----+
68 What does redisplay do? Obviously, it has to figure out somehow what
69 has been changed since the last time the display has been updated,
70 and to make these changes visible. Preferably it would do that in
71 a moderately intelligent way, i.e. fast.
73 Changes in buffer text can be deduced from window and buffer
74 structures, and from some global variables like `beg_unchanged' and
75 `end_unchanged'. The contents of the display are additionally
76 recorded in a `glyph matrix', a two-dimensional matrix of glyph
77 structures. Each row in such a matrix corresponds to a line on the
78 display, and each glyph in a row corresponds to a column displaying
79 a character, an image, or what else. This matrix is called the
80 `current glyph matrix' or `current matrix' in redisplay
83 For buffer parts that have been changed since the last update, a
84 second glyph matrix is constructed, the so called `desired glyph
85 matrix' or short `desired matrix'. Current and desired matrix are
86 then compared to find a cheap way to update the display, e.g. by
87 reusing part of the display by scrolling lines.
92 You will find a lot of redisplay optimizations when you start
93 looking at the innards of redisplay. The overall goal of all these
94 optimizations is to make redisplay fast because it is done
97 Two optimizations are not found in xdisp.c. These are the direct
98 operations mentioned above. As the name suggests they follow a
99 different principle than the rest of redisplay. Instead of
100 building a desired matrix and then comparing it with the current
101 display, they perform their actions directly on the display and on
104 One direct operation updates the display after one character has
105 been entered. The other one moves the cursor by one position
106 forward or backward. You find these functions under the names
107 `direct_output_for_insert' and `direct_output_forward_char' in
113 Desired matrices are always built per Emacs window. The function
114 `display_line' is the central function to look at if you are
115 interested. It constructs one row in a desired matrix given an
116 iterator structure containing both a buffer position and a
117 description of the environment in which the text is to be
118 displayed. But this is too early, read on.
120 Characters and pixmaps displayed for a range of buffer text depend
121 on various settings of buffers and windows, on overlays and text
122 properties, on display tables, on selective display. The good news
123 is that all this hairy stuff is hidden behind a small set of
124 interface functions taking an iterator structure (struct it)
127 Iteration over things to be displayed is then simple. It is
128 started by initializing an iterator with a call to init_iterator.
129 Calls to get_next_display_element fill the iterator structure with
130 relevant information about the next thing to display. Calls to
131 set_iterator_to_next move the iterator to the next thing.
133 Besides this, an iterator also contains information about the
134 display environment in which glyphs for display elements are to be
135 produced. It has fields for the width and height of the display,
136 the information whether long lines are truncated or continued, a
137 current X and Y position, and lots of other stuff you can better
140 Glyphs in a desired matrix are normally constructed in a loop
141 calling get_next_display_element and then produce_glyphs. The call
142 to produce_glyphs will fill the iterator structure with pixel
143 information about the element being displayed and at the same time
144 produce glyphs for it. If the display element fits on the line
145 being displayed, set_iterator_to_next is called next, otherwise the
146 glyphs produced are discarded.
151 That just couldn't be all, could it? What about terminal types not
152 supporting operations on sub-windows of the screen? To update the
153 display on such a terminal, window-based glyph matrices are not
154 well suited. To be able to reuse part of the display (scrolling
155 lines up and down), we must instead have a view of the whole
156 screen. This is what `frame matrices' are for. They are a trick.
158 Frames on terminals like above have a glyph pool. Windows on such
159 a frame sub-allocate their glyph memory from their frame's glyph
160 pool. The frame itself is given its own glyph matrices. By
161 coincidence---or maybe something else---rows in window glyph
162 matrices are slices of corresponding rows in frame matrices. Thus
163 writing to window matrices implicitly updates a frame matrix which
164 provides us with the view of the whole screen that we originally
165 wanted to have without having to move many bytes around. To be
166 honest, there is a little bit more done, but not much more. If you
167 plan to extend that code, take a look at dispnew.c. The function
168 build_frame_matrix is a good starting point. */
174 #include "keyboard.h"
177 #include "termchar.h"
178 #include "dispextern.h"
182 #include "commands.h"
186 #include "termhooks.h"
187 #include "intervals.h"
190 #include "region-cache.h"
192 #include "blockinput.h"
194 #ifdef HAVE_X_WINDOWS
204 #ifndef FRAME_X_OUTPUT
205 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
208 #define INFINITY 10000000
210 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
212 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
213 extern int pending_menu_activation
;
216 extern int interrupt_input
;
217 extern int command_loop_level
;
219 extern Lisp_Object do_mouse_tracking
;
221 extern int minibuffer_auto_raise
;
222 extern Lisp_Object Vminibuffer_list
;
224 extern Lisp_Object Qface
;
225 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
227 extern Lisp_Object Voverriding_local_map
;
228 extern Lisp_Object Voverriding_local_map_menu_flag
;
229 extern Lisp_Object Qmenu_item
;
230 extern Lisp_Object Qwhen
;
231 extern Lisp_Object Qhelp_echo
;
233 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
234 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
235 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
236 Lisp_Object Qinhibit_point_motion_hooks
;
237 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
238 Lisp_Object Qfontified
;
239 Lisp_Object Qgrow_only
;
240 Lisp_Object Qinhibit_eval_during_redisplay
;
241 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
244 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
247 Lisp_Object Qarrow
, Qhand
, Qtext
;
249 Lisp_Object Qrisky_local_variable
;
251 /* Holds the list (error). */
252 Lisp_Object list_of_error
;
254 /* Functions called to fontify regions of text. */
256 Lisp_Object Vfontification_functions
;
257 Lisp_Object Qfontification_functions
;
259 /* Non-nil means automatically select any window when the mouse
260 cursor moves into it. */
261 Lisp_Object Vmouse_autoselect_window
;
263 /* Non-zero means draw tool bar buttons raised when the mouse moves
266 int auto_raise_tool_bar_buttons_p
;
268 /* Non-zero means to reposition window if cursor line is only partially visible. */
270 int make_cursor_line_fully_visible_p
;
272 /* Margin below tool bar in pixels. 0 or nil means no margin.
273 If value is `internal-border-width' or `border-width',
274 the corresponding frame parameter is used. */
276 Lisp_Object Vtool_bar_border
;
278 /* Margin around tool bar buttons in pixels. */
280 Lisp_Object Vtool_bar_button_margin
;
282 /* Thickness of shadow to draw around tool bar buttons. */
284 EMACS_INT tool_bar_button_relief
;
286 /* Non-zero means automatically resize tool-bars so that all tool-bar
287 items are visible, and no blank lines remain. */
289 int auto_resize_tool_bars_p
;
291 /* Non-zero means draw block and hollow cursor as wide as the glyph
292 under it. For example, if a block cursor is over a tab, it will be
293 drawn as wide as that tab on the display. */
295 int x_stretch_cursor_p
;
297 /* Non-nil means don't actually do any redisplay. */
299 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
301 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
303 int inhibit_eval_during_redisplay
;
305 /* Names of text properties relevant for redisplay. */
307 Lisp_Object Qdisplay
;
308 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
310 /* Symbols used in text property values. */
312 Lisp_Object Vdisplay_pixels_per_inch
;
313 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
314 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
317 Lisp_Object Qmargin
, Qpointer
;
318 Lisp_Object Qline_height
;
319 extern Lisp_Object Qheight
;
320 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
321 extern Lisp_Object Qscroll_bar
;
322 extern Lisp_Object Qcursor
;
324 /* Non-nil means highlight trailing whitespace. */
326 Lisp_Object Vshow_trailing_whitespace
;
328 /* Non-nil means escape non-break space and hyphens. */
330 Lisp_Object Vnobreak_char_display
;
332 #ifdef HAVE_WINDOW_SYSTEM
333 extern Lisp_Object Voverflow_newline_into_fringe
;
335 /* Test if overflow newline into fringe. Called with iterator IT
336 at or past right window margin, and with IT->current_x set. */
338 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
339 (!NILP (Voverflow_newline_into_fringe) \
340 && FRAME_WINDOW_P (it->f) \
341 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
342 && it->current_x == it->last_visible_x)
344 #endif /* HAVE_WINDOW_SYSTEM */
346 /* Non-nil means show the text cursor in void text areas
347 i.e. in blank areas after eol and eob. This used to be
348 the default in 21.3. */
350 Lisp_Object Vvoid_text_area_pointer
;
352 /* Name of the face used to highlight trailing whitespace. */
354 Lisp_Object Qtrailing_whitespace
;
356 /* Name and number of the face used to highlight escape glyphs. */
358 Lisp_Object Qescape_glyph
;
360 /* Name and number of the face used to highlight non-breaking spaces. */
362 Lisp_Object Qnobreak_space
;
364 /* The symbol `image' which is the car of the lists used to represent
369 /* The image map types. */
370 Lisp_Object QCmap
, QCpointer
;
371 Lisp_Object Qrect
, Qcircle
, Qpoly
;
373 /* Non-zero means print newline to stdout before next mini-buffer
376 int noninteractive_need_newline
;
378 /* Non-zero means print newline to message log before next message. */
380 static int message_log_need_newline
;
382 /* Three markers that message_dolog uses.
383 It could allocate them itself, but that causes trouble
384 in handling memory-full errors. */
385 static Lisp_Object message_dolog_marker1
;
386 static Lisp_Object message_dolog_marker2
;
387 static Lisp_Object message_dolog_marker3
;
389 /* The buffer position of the first character appearing entirely or
390 partially on the line of the selected window which contains the
391 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
392 redisplay optimization in redisplay_internal. */
394 static struct text_pos this_line_start_pos
;
396 /* Number of characters past the end of the line above, including the
397 terminating newline. */
399 static struct text_pos this_line_end_pos
;
401 /* The vertical positions and the height of this line. */
403 static int this_line_vpos
;
404 static int this_line_y
;
405 static int this_line_pixel_height
;
407 /* X position at which this display line starts. Usually zero;
408 negative if first character is partially visible. */
410 static int this_line_start_x
;
412 /* Buffer that this_line_.* variables are referring to. */
414 static struct buffer
*this_line_buffer
;
416 /* Nonzero means truncate lines in all windows less wide than the
419 int truncate_partial_width_windows
;
421 /* A flag to control how to display unibyte 8-bit character. */
423 int unibyte_display_via_language_environment
;
425 /* Nonzero means we have more than one non-mini-buffer-only frame.
426 Not guaranteed to be accurate except while parsing
427 frame-title-format. */
431 Lisp_Object Vglobal_mode_string
;
434 /* List of variables (symbols) which hold markers for overlay arrows.
435 The symbols on this list are examined during redisplay to determine
436 where to display overlay arrows. */
438 Lisp_Object Voverlay_arrow_variable_list
;
440 /* Marker for where to display an arrow on top of the buffer text. */
442 Lisp_Object Voverlay_arrow_position
;
444 /* String to display for the arrow. Only used on terminal frames. */
446 Lisp_Object Voverlay_arrow_string
;
448 /* Values of those variables at last redisplay are stored as
449 properties on `overlay-arrow-position' symbol. However, if
450 Voverlay_arrow_position is a marker, last-arrow-position is its
451 numerical position. */
453 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
455 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
456 properties on a symbol in overlay-arrow-variable-list. */
458 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
460 /* Like mode-line-format, but for the title bar on a visible frame. */
462 Lisp_Object Vframe_title_format
;
464 /* Like mode-line-format, but for the title bar on an iconified frame. */
466 Lisp_Object Vicon_title_format
;
468 /* List of functions to call when a window's size changes. These
469 functions get one arg, a frame on which one or more windows' sizes
472 static Lisp_Object Vwindow_size_change_functions
;
474 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
476 /* Nonzero if an overlay arrow has been displayed in this window. */
478 static int overlay_arrow_seen
;
480 /* Nonzero means highlight the region even in nonselected windows. */
482 int highlight_nonselected_windows
;
484 /* If cursor motion alone moves point off frame, try scrolling this
485 many lines up or down if that will bring it back. */
487 static EMACS_INT scroll_step
;
489 /* Nonzero means scroll just far enough to bring point back on the
490 screen, when appropriate. */
492 static EMACS_INT scroll_conservatively
;
494 /* Recenter the window whenever point gets within this many lines of
495 the top or bottom of the window. This value is translated into a
496 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
497 that there is really a fixed pixel height scroll margin. */
499 EMACS_INT scroll_margin
;
501 /* Number of windows showing the buffer of the selected window (or
502 another buffer with the same base buffer). keyboard.c refers to
507 /* Vector containing glyphs for an ellipsis `...'. */
509 static Lisp_Object default_invis_vector
[3];
511 /* Zero means display the mode-line/header-line/menu-bar in the default face
512 (this slightly odd definition is for compatibility with previous versions
513 of emacs), non-zero means display them using their respective faces.
515 This variable is deprecated. */
517 int mode_line_inverse_video
;
519 /* Prompt to display in front of the mini-buffer contents. */
521 Lisp_Object minibuf_prompt
;
523 /* Width of current mini-buffer prompt. Only set after display_line
524 of the line that contains the prompt. */
526 int minibuf_prompt_width
;
528 /* This is the window where the echo area message was displayed. It
529 is always a mini-buffer window, but it may not be the same window
530 currently active as a mini-buffer. */
532 Lisp_Object echo_area_window
;
534 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
535 pushes the current message and the value of
536 message_enable_multibyte on the stack, the function restore_message
537 pops the stack and displays MESSAGE again. */
539 Lisp_Object Vmessage_stack
;
541 /* Nonzero means multibyte characters were enabled when the echo area
542 message was specified. */
544 int message_enable_multibyte
;
546 /* Nonzero if we should redraw the mode lines on the next redisplay. */
548 int update_mode_lines
;
550 /* Nonzero if window sizes or contents have changed since last
551 redisplay that finished. */
553 int windows_or_buffers_changed
;
555 /* Nonzero means a frame's cursor type has been changed. */
557 int cursor_type_changed
;
559 /* Nonzero after display_mode_line if %l was used and it displayed a
562 int line_number_displayed
;
564 /* Maximum buffer size for which to display line numbers. */
566 Lisp_Object Vline_number_display_limit
;
568 /* Line width to consider when repositioning for line number display. */
570 static EMACS_INT line_number_display_limit_width
;
572 /* Number of lines to keep in the message log buffer. t means
573 infinite. nil means don't log at all. */
575 Lisp_Object Vmessage_log_max
;
577 /* The name of the *Messages* buffer, a string. */
579 static Lisp_Object Vmessages_buffer_name
;
581 /* Index 0 is the buffer that holds the current (desired) echo area message,
582 or nil if none is desired right now.
584 Index 1 is the buffer that holds the previously displayed echo area message,
585 or nil to indicate no message. This is normally what's on the screen now.
587 These two can point to the same buffer. That happens when the last
588 message output by the user (or made by echoing) has been displayed. */
590 Lisp_Object echo_area_buffer
[2];
592 /* Permanent pointers to the two buffers that are used for echo area
593 purposes. Once the two buffers are made, and their pointers are
594 placed here, these two slots remain unchanged unless those buffers
595 need to be created afresh. */
597 static Lisp_Object echo_buffer
[2];
599 /* A vector saved used in with_area_buffer to reduce consing. */
601 static Lisp_Object Vwith_echo_area_save_vector
;
603 /* Non-zero means display_echo_area should display the last echo area
604 message again. Set by redisplay_preserve_echo_area. */
606 static int display_last_displayed_message_p
;
608 /* Nonzero if echo area is being used by print; zero if being used by
611 int message_buf_print
;
613 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
615 Lisp_Object Qinhibit_menubar_update
;
616 int inhibit_menubar_update
;
618 /* When evaluating expressions from menu bar items (enable conditions,
619 for instance), this is the frame they are being processed for. */
621 Lisp_Object Vmenu_updating_frame
;
623 /* Maximum height for resizing mini-windows. Either a float
624 specifying a fraction of the available height, or an integer
625 specifying a number of lines. */
627 Lisp_Object Vmax_mini_window_height
;
629 /* Non-zero means messages should be displayed with truncated
630 lines instead of being continued. */
632 int message_truncate_lines
;
633 Lisp_Object Qmessage_truncate_lines
;
635 /* Set to 1 in clear_message to make redisplay_internal aware
636 of an emptied echo area. */
638 static int message_cleared_p
;
640 /* How to blink the default frame cursor off. */
641 Lisp_Object Vblink_cursor_alist
;
643 /* A scratch glyph row with contents used for generating truncation
644 glyphs. Also used in direct_output_for_insert. */
646 #define MAX_SCRATCH_GLYPHS 100
647 struct glyph_row scratch_glyph_row
;
648 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
650 /* Ascent and height of the last line processed by move_it_to. */
652 static int last_max_ascent
, last_height
;
654 /* Non-zero if there's a help-echo in the echo area. */
656 int help_echo_showing_p
;
658 /* If >= 0, computed, exact values of mode-line and header-line height
659 to use in the macros CURRENT_MODE_LINE_HEIGHT and
660 CURRENT_HEADER_LINE_HEIGHT. */
662 int current_mode_line_height
, current_header_line_height
;
664 /* The maximum distance to look ahead for text properties. Values
665 that are too small let us call compute_char_face and similar
666 functions too often which is expensive. Values that are too large
667 let us call compute_char_face and alike too often because we
668 might not be interested in text properties that far away. */
670 #define TEXT_PROP_DISTANCE_LIMIT 100
674 /* Variables to turn off display optimizations from Lisp. */
676 int inhibit_try_window_id
, inhibit_try_window_reusing
;
677 int inhibit_try_cursor_movement
;
679 /* Non-zero means print traces of redisplay if compiled with
682 int trace_redisplay_p
;
684 #endif /* GLYPH_DEBUG */
686 #ifdef DEBUG_TRACE_MOVE
687 /* Non-zero means trace with TRACE_MOVE to stderr. */
690 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
692 #define TRACE_MOVE(x) (void) 0
695 /* Non-zero means automatically scroll windows horizontally to make
698 int automatic_hscrolling_p
;
700 /* How close to the margin can point get before the window is scrolled
702 EMACS_INT hscroll_margin
;
704 /* How much to scroll horizontally when point is inside the above margin. */
705 Lisp_Object Vhscroll_step
;
707 /* The variable `resize-mini-windows'. If nil, don't resize
708 mini-windows. If t, always resize them to fit the text they
709 display. If `grow-only', let mini-windows grow only until they
712 Lisp_Object Vresize_mini_windows
;
714 /* Buffer being redisplayed -- for redisplay_window_error. */
716 struct buffer
*displayed_buffer
;
718 /* Space between overline and text. */
720 EMACS_INT overline_margin
;
722 /* Value returned from text property handlers (see below). */
727 HANDLED_RECOMPUTE_PROPS
,
728 HANDLED_OVERLAY_STRING_CONSUMED
,
732 /* A description of text properties that redisplay is interested
737 /* The name of the property. */
740 /* A unique index for the property. */
743 /* A handler function called to set up iterator IT from the property
744 at IT's current position. Value is used to steer handle_stop. */
745 enum prop_handled (*handler
) P_ ((struct it
*it
));
748 static enum prop_handled handle_face_prop
P_ ((struct it
*));
749 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
750 static enum prop_handled handle_display_prop
P_ ((struct it
*));
751 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
752 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
753 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
755 /* Properties handled by iterators. */
757 static struct props it_props
[] =
759 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
760 /* Handle `face' before `display' because some sub-properties of
761 `display' need to know the face. */
762 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
763 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
764 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
765 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
769 /* Value is the position described by X. If X is a marker, value is
770 the marker_position of X. Otherwise, value is X. */
772 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
774 /* Enumeration returned by some move_it_.* functions internally. */
778 /* Not used. Undefined value. */
781 /* Move ended at the requested buffer position or ZV. */
782 MOVE_POS_MATCH_OR_ZV
,
784 /* Move ended at the requested X pixel position. */
787 /* Move within a line ended at the end of a line that must be
791 /* Move within a line ended at the end of a line that would
792 be displayed truncated. */
795 /* Move within a line ended at a line end. */
799 /* This counter is used to clear the face cache every once in a while
800 in redisplay_internal. It is incremented for each redisplay.
801 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
804 #define CLEAR_FACE_CACHE_COUNT 500
805 static int clear_face_cache_count
;
807 /* Similarly for the image cache. */
809 #ifdef HAVE_WINDOW_SYSTEM
810 #define CLEAR_IMAGE_CACHE_COUNT 101
811 static int clear_image_cache_count
;
814 /* Record the previous terminal frame we displayed. */
816 static struct frame
*previous_terminal_frame
;
818 /* Non-zero while redisplay_internal is in progress. */
822 /* Non-zero means don't free realized faces. Bound while freeing
823 realized faces is dangerous because glyph matrices might still
826 int inhibit_free_realized_faces
;
827 Lisp_Object Qinhibit_free_realized_faces
;
829 /* If a string, XTread_socket generates an event to display that string.
830 (The display is done in read_char.) */
832 Lisp_Object help_echo_string
;
833 Lisp_Object help_echo_window
;
834 Lisp_Object help_echo_object
;
837 /* Temporary variable for XTread_socket. */
839 Lisp_Object previous_help_echo_string
;
841 /* Null glyph slice */
843 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
846 /* Function prototypes. */
848 static void setup_for_ellipsis
P_ ((struct it
*, int));
849 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
850 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
851 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
852 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
853 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
854 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
857 static int invisible_text_between_p
P_ ((struct it
*, int, int));
860 static void pint2str
P_ ((char *, int, int));
861 static void pint2hrstr
P_ ((char *, int, int));
862 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
864 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
865 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
866 static void store_mode_line_noprop_char
P_ ((char));
867 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
868 static void x_consider_frame_title
P_ ((Lisp_Object
));
869 static void handle_stop
P_ ((struct it
*));
870 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
871 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
872 static void ensure_echo_area_buffers
P_ ((void));
873 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
874 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
875 static int with_echo_area_buffer
P_ ((struct window
*, int,
876 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
877 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
878 static void clear_garbaged_frames
P_ ((void));
879 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
880 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
881 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
882 static int display_echo_area
P_ ((struct window
*));
883 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
884 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
885 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
886 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
887 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
889 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
890 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
891 static void insert_left_trunc_glyphs
P_ ((struct it
*));
892 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
894 static void extend_face_to_end_of_line
P_ ((struct it
*));
895 static int append_space_for_newline
P_ ((struct it
*, int));
896 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
897 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
898 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
899 static int trailing_whitespace_p
P_ ((int));
900 static int message_log_check_duplicate
P_ ((int, int, int, int));
901 static void push_it
P_ ((struct it
*));
902 static void pop_it
P_ ((struct it
*));
903 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
904 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
905 static void redisplay_internal
P_ ((int));
906 static int echo_area_display
P_ ((int));
907 static void redisplay_windows
P_ ((Lisp_Object
));
908 static void redisplay_window
P_ ((Lisp_Object
, int));
909 static Lisp_Object
redisplay_window_error ();
910 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
911 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
912 static int update_menu_bar
P_ ((struct frame
*, int, int));
913 static int try_window_reusing_current_matrix
P_ ((struct window
*));
914 static int try_window_id
P_ ((struct window
*));
915 static int display_line
P_ ((struct it
*));
916 static int display_mode_lines
P_ ((struct window
*));
917 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
918 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
919 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
920 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
921 static void display_menu_bar
P_ ((struct window
*));
922 static int display_count_lines
P_ ((int, int, int, int, int *));
923 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
924 int, int, struct it
*, int, int, int, int));
925 static void compute_line_metrics
P_ ((struct it
*));
926 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
927 static int get_overlay_strings
P_ ((struct it
*, int));
928 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
929 static void next_overlay_string
P_ ((struct it
*));
930 static void reseat
P_ ((struct it
*, struct text_pos
, int));
931 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
932 static void back_to_previous_visible_line_start
P_ ((struct it
*));
933 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
934 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
935 static int next_element_from_ellipsis
P_ ((struct it
*));
936 static int next_element_from_display_vector
P_ ((struct it
*));
937 static int next_element_from_string
P_ ((struct it
*));
938 static int next_element_from_c_string
P_ ((struct it
*));
939 static int next_element_from_buffer
P_ ((struct it
*));
940 static int next_element_from_composition
P_ ((struct it
*));
941 static int next_element_from_image
P_ ((struct it
*));
942 static int next_element_from_stretch
P_ ((struct it
*));
943 static void load_overlay_strings
P_ ((struct it
*, int));
944 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
945 struct display_pos
*));
946 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
947 Lisp_Object
, int, int, int, int));
948 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
950 void move_it_vertically_backward
P_ ((struct it
*, int));
951 static void init_to_row_start
P_ ((struct it
*, struct window
*,
952 struct glyph_row
*));
953 static int init_to_row_end
P_ ((struct it
*, struct window
*,
954 struct glyph_row
*));
955 static void back_to_previous_line_start
P_ ((struct it
*));
956 static int forward_to_next_line_start
P_ ((struct it
*, int *));
957 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
959 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
960 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
961 static int number_of_chars
P_ ((unsigned char *, int));
962 static void compute_stop_pos
P_ ((struct it
*));
963 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
965 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
966 static int next_overlay_change
P_ ((int));
967 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
968 Lisp_Object
, struct text_pos
*,
970 static int underlying_face_id
P_ ((struct it
*));
971 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
974 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
975 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
977 #ifdef HAVE_WINDOW_SYSTEM
979 static void update_tool_bar
P_ ((struct frame
*, int));
980 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
981 static int redisplay_tool_bar
P_ ((struct frame
*));
982 static void display_tool_bar_line
P_ ((struct it
*, int));
983 static void notice_overwritten_cursor
P_ ((struct window
*,
985 int, int, int, int));
989 #endif /* HAVE_WINDOW_SYSTEM */
992 /***********************************************************************
993 Window display dimensions
994 ***********************************************************************/
996 /* Return the bottom boundary y-position for text lines in window W.
997 This is the first y position at which a line cannot start.
998 It is relative to the top of the window.
1000 This is the height of W minus the height of a mode line, if any. */
1003 window_text_bottom_y (w
)
1006 int height
= WINDOW_TOTAL_HEIGHT (w
);
1008 if (WINDOW_WANTS_MODELINE_P (w
))
1009 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1013 /* Return the pixel width of display area AREA of window W. AREA < 0
1014 means return the total width of W, not including fringes to
1015 the left and right of the window. */
1018 window_box_width (w
, area
)
1022 int cols
= XFASTINT (w
->total_cols
);
1025 if (!w
->pseudo_window_p
)
1027 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1029 if (area
== TEXT_AREA
)
1031 if (INTEGERP (w
->left_margin_cols
))
1032 cols
-= XFASTINT (w
->left_margin_cols
);
1033 if (INTEGERP (w
->right_margin_cols
))
1034 cols
-= XFASTINT (w
->right_margin_cols
);
1035 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1037 else if (area
== LEFT_MARGIN_AREA
)
1039 cols
= (INTEGERP (w
->left_margin_cols
)
1040 ? XFASTINT (w
->left_margin_cols
) : 0);
1043 else if (area
== RIGHT_MARGIN_AREA
)
1045 cols
= (INTEGERP (w
->right_margin_cols
)
1046 ? XFASTINT (w
->right_margin_cols
) : 0);
1051 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1055 /* Return the pixel height of the display area of window W, not
1056 including mode lines of W, if any. */
1059 window_box_height (w
)
1062 struct frame
*f
= XFRAME (w
->frame
);
1063 int height
= WINDOW_TOTAL_HEIGHT (w
);
1065 xassert (height
>= 0);
1067 /* Note: the code below that determines the mode-line/header-line
1068 height is essentially the same as that contained in the macro
1069 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1070 the appropriate glyph row has its `mode_line_p' flag set,
1071 and if it doesn't, uses estimate_mode_line_height instead. */
1073 if (WINDOW_WANTS_MODELINE_P (w
))
1075 struct glyph_row
*ml_row
1076 = (w
->current_matrix
&& w
->current_matrix
->rows
1077 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1079 if (ml_row
&& ml_row
->mode_line_p
)
1080 height
-= ml_row
->height
;
1082 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1085 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1087 struct glyph_row
*hl_row
1088 = (w
->current_matrix
&& w
->current_matrix
->rows
1089 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1091 if (hl_row
&& hl_row
->mode_line_p
)
1092 height
-= hl_row
->height
;
1094 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1097 /* With a very small font and a mode-line that's taller than
1098 default, we might end up with a negative height. */
1099 return max (0, height
);
1102 /* Return the window-relative coordinate of the left edge of display
1103 area AREA of window W. AREA < 0 means return the left edge of the
1104 whole window, to the right of the left fringe of W. */
1107 window_box_left_offset (w
, area
)
1113 if (w
->pseudo_window_p
)
1116 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1118 if (area
== TEXT_AREA
)
1119 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1120 + window_box_width (w
, LEFT_MARGIN_AREA
));
1121 else if (area
== RIGHT_MARGIN_AREA
)
1122 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1123 + window_box_width (w
, LEFT_MARGIN_AREA
)
1124 + window_box_width (w
, TEXT_AREA
)
1125 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1127 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1128 else if (area
== LEFT_MARGIN_AREA
1129 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1130 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1136 /* Return the window-relative coordinate of the right edge of display
1137 area AREA of window W. AREA < 0 means return the left edge of the
1138 whole window, to the left of the right fringe of W. */
1141 window_box_right_offset (w
, area
)
1145 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1148 /* Return the frame-relative coordinate of the left edge of display
1149 area AREA of window W. AREA < 0 means return the left edge of the
1150 whole window, to the right of the left fringe of W. */
1153 window_box_left (w
, area
)
1157 struct frame
*f
= XFRAME (w
->frame
);
1160 if (w
->pseudo_window_p
)
1161 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1163 x
= (WINDOW_LEFT_EDGE_X (w
)
1164 + window_box_left_offset (w
, area
));
1170 /* Return the frame-relative coordinate of the right edge of display
1171 area AREA of window W. AREA < 0 means return the left edge of the
1172 whole window, to the left of the right fringe of W. */
1175 window_box_right (w
, area
)
1179 return window_box_left (w
, area
) + window_box_width (w
, area
);
1182 /* Get the bounding box of the display area AREA of window W, without
1183 mode lines, in frame-relative coordinates. AREA < 0 means the
1184 whole window, not including the left and right fringes of
1185 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1186 coordinates of the upper-left corner of the box. Return in
1187 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1190 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1193 int *box_x
, *box_y
, *box_width
, *box_height
;
1196 *box_width
= window_box_width (w
, area
);
1198 *box_height
= window_box_height (w
);
1200 *box_x
= window_box_left (w
, area
);
1203 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1204 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1205 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1210 /* Get the bounding box of the display area AREA of window W, without
1211 mode lines. AREA < 0 means the whole window, not including the
1212 left and right fringe of the window. Return in *TOP_LEFT_X
1213 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1214 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1215 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1219 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1220 bottom_right_x
, bottom_right_y
)
1223 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1225 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1227 *bottom_right_x
+= *top_left_x
;
1228 *bottom_right_y
+= *top_left_y
;
1233 /***********************************************************************
1235 ***********************************************************************/
1237 /* Return the bottom y-position of the line the iterator IT is in.
1238 This can modify IT's settings. */
1244 int line_height
= it
->max_ascent
+ it
->max_descent
;
1245 int line_top_y
= it
->current_y
;
1247 if (line_height
== 0)
1250 line_height
= last_height
;
1251 else if (IT_CHARPOS (*it
) < ZV
)
1253 move_it_by_lines (it
, 1, 1);
1254 line_height
= (it
->max_ascent
|| it
->max_descent
1255 ? it
->max_ascent
+ it
->max_descent
1260 struct glyph_row
*row
= it
->glyph_row
;
1262 /* Use the default character height. */
1263 it
->glyph_row
= NULL
;
1264 it
->what
= IT_CHARACTER
;
1267 PRODUCE_GLYPHS (it
);
1268 line_height
= it
->ascent
+ it
->descent
;
1269 it
->glyph_row
= row
;
1273 return line_top_y
+ line_height
;
1277 /* Return 1 if position CHARPOS is visible in window W.
1278 CHARPOS < 0 means return info about WINDOW_END position.
1279 If visible, set *X and *Y to pixel coordinates of top left corner.
1280 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1281 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1284 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1286 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1289 struct text_pos top
;
1291 struct buffer
*old_buffer
= NULL
;
1296 if (XBUFFER (w
->buffer
) != current_buffer
)
1298 old_buffer
= current_buffer
;
1299 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1302 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1304 /* Compute exact mode line heights. */
1305 if (WINDOW_WANTS_MODELINE_P (w
))
1306 current_mode_line_height
1307 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1308 current_buffer
->mode_line_format
);
1310 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1311 current_header_line_height
1312 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1313 current_buffer
->header_line_format
);
1315 start_display (&it
, w
, top
);
1316 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1317 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1319 /* Note that we may overshoot because of invisible text. */
1320 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1322 int top_x
= it
.current_x
;
1323 int top_y
= it
.current_y
;
1324 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1325 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1327 if (top_y
< window_top_y
)
1328 visible_p
= bottom_y
> window_top_y
;
1329 else if (top_y
< it
.last_visible_y
)
1334 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1335 *rtop
= max (0, window_top_y
- top_y
);
1336 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1337 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1338 - max (top_y
, window_top_y
)));
1347 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1348 move_it_by_lines (&it
, 1, 0);
1349 if (charpos
< IT_CHARPOS (it
)
1350 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1353 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1355 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1356 *rtop
= max (0, -it2
.current_y
);
1357 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1358 - it
.last_visible_y
));
1359 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1361 - max (it2
.current_y
,
1362 WINDOW_HEADER_LINE_HEIGHT (w
))));
1368 set_buffer_internal_1 (old_buffer
);
1370 current_header_line_height
= current_mode_line_height
= -1;
1372 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1373 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1376 /* Debugging code. */
1378 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1379 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1381 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1388 /* Return the next character from STR which is MAXLEN bytes long.
1389 Return in *LEN the length of the character. This is like
1390 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1391 we find one, we return a `?', but with the length of the invalid
1395 string_char_and_length (str
, maxlen
, len
)
1396 const unsigned char *str
;
1401 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1402 if (!CHAR_VALID_P (c
, 1))
1403 /* We may not change the length here because other places in Emacs
1404 don't use this function, i.e. they silently accept invalid
1413 /* Given a position POS containing a valid character and byte position
1414 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1416 static struct text_pos
1417 string_pos_nchars_ahead (pos
, string
, nchars
)
1418 struct text_pos pos
;
1422 xassert (STRINGP (string
) && nchars
>= 0);
1424 if (STRING_MULTIBYTE (string
))
1426 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1427 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1432 string_char_and_length (p
, rest
, &len
);
1433 p
+= len
, rest
-= len
;
1434 xassert (rest
>= 0);
1436 BYTEPOS (pos
) += len
;
1440 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1446 /* Value is the text position, i.e. character and byte position,
1447 for character position CHARPOS in STRING. */
1449 static INLINE
struct text_pos
1450 string_pos (charpos
, string
)
1454 struct text_pos pos
;
1455 xassert (STRINGP (string
));
1456 xassert (charpos
>= 0);
1457 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1462 /* Value is a text position, i.e. character and byte position, for
1463 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1464 means recognize multibyte characters. */
1466 static struct text_pos
1467 c_string_pos (charpos
, s
, multibyte_p
)
1472 struct text_pos pos
;
1474 xassert (s
!= NULL
);
1475 xassert (charpos
>= 0);
1479 int rest
= strlen (s
), len
;
1481 SET_TEXT_POS (pos
, 0, 0);
1484 string_char_and_length (s
, rest
, &len
);
1485 s
+= len
, rest
-= len
;
1486 xassert (rest
>= 0);
1488 BYTEPOS (pos
) += len
;
1492 SET_TEXT_POS (pos
, charpos
, charpos
);
1498 /* Value is the number of characters in C string S. MULTIBYTE_P
1499 non-zero means recognize multibyte characters. */
1502 number_of_chars (s
, multibyte_p
)
1510 int rest
= strlen (s
), len
;
1511 unsigned char *p
= (unsigned char *) s
;
1513 for (nchars
= 0; rest
> 0; ++nchars
)
1515 string_char_and_length (p
, rest
, &len
);
1516 rest
-= len
, p
+= len
;
1520 nchars
= strlen (s
);
1526 /* Compute byte position NEWPOS->bytepos corresponding to
1527 NEWPOS->charpos. POS is a known position in string STRING.
1528 NEWPOS->charpos must be >= POS.charpos. */
1531 compute_string_pos (newpos
, pos
, string
)
1532 struct text_pos
*newpos
, pos
;
1535 xassert (STRINGP (string
));
1536 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1538 if (STRING_MULTIBYTE (string
))
1539 *newpos
= string_pos_nchars_ahead (pos
, string
,
1540 CHARPOS (*newpos
) - CHARPOS (pos
));
1542 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1546 Return an estimation of the pixel height of mode or top lines on
1547 frame F. FACE_ID specifies what line's height to estimate. */
1550 estimate_mode_line_height (f
, face_id
)
1552 enum face_id face_id
;
1554 #ifdef HAVE_WINDOW_SYSTEM
1555 if (FRAME_WINDOW_P (f
))
1557 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1559 /* This function is called so early when Emacs starts that the face
1560 cache and mode line face are not yet initialized. */
1561 if (FRAME_FACE_CACHE (f
))
1563 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1567 height
= FONT_HEIGHT (face
->font
);
1568 if (face
->box_line_width
> 0)
1569 height
+= 2 * face
->box_line_width
;
1580 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1581 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1582 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1583 not force the value into range. */
1586 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1588 register int pix_x
, pix_y
;
1590 NativeRectangle
*bounds
;
1594 #ifdef HAVE_WINDOW_SYSTEM
1595 if (FRAME_WINDOW_P (f
))
1597 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1598 even for negative values. */
1600 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1602 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1604 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1605 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1608 STORE_NATIVE_RECT (*bounds
,
1609 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1610 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1611 FRAME_COLUMN_WIDTH (f
) - 1,
1612 FRAME_LINE_HEIGHT (f
) - 1);
1618 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1619 pix_x
= FRAME_TOTAL_COLS (f
);
1623 else if (pix_y
> FRAME_LINES (f
))
1624 pix_y
= FRAME_LINES (f
);
1634 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1635 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1636 can't tell the positions because W's display is not up to date,
1640 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1643 int *frame_x
, *frame_y
;
1645 #ifdef HAVE_WINDOW_SYSTEM
1646 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1650 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1651 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1653 if (display_completed
)
1655 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1656 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1657 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1663 hpos
+= glyph
->pixel_width
;
1667 /* If first glyph is partially visible, its first visible position is still 0. */
1679 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1680 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1691 #ifdef HAVE_WINDOW_SYSTEM
1693 /* Find the glyph under window-relative coordinates X/Y in window W.
1694 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1695 strings. Return in *HPOS and *VPOS the row and column number of
1696 the glyph found. Return in *AREA the glyph area containing X.
1697 Value is a pointer to the glyph found or null if X/Y is not on
1698 text, or we can't tell because W's current matrix is not up to
1701 static struct glyph
*
1702 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1705 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1707 struct glyph
*glyph
, *end
;
1708 struct glyph_row
*row
= NULL
;
1711 /* Find row containing Y. Give up if some row is not enabled. */
1712 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1714 row
= MATRIX_ROW (w
->current_matrix
, i
);
1715 if (!row
->enabled_p
)
1717 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1724 /* Give up if Y is not in the window. */
1725 if (i
== w
->current_matrix
->nrows
)
1728 /* Get the glyph area containing X. */
1729 if (w
->pseudo_window_p
)
1736 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1738 *area
= LEFT_MARGIN_AREA
;
1739 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1741 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1744 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1748 *area
= RIGHT_MARGIN_AREA
;
1749 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1753 /* Find glyph containing X. */
1754 glyph
= row
->glyphs
[*area
];
1755 end
= glyph
+ row
->used
[*area
];
1757 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1759 x
-= glyph
->pixel_width
;
1769 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1772 *hpos
= glyph
- row
->glyphs
[*area
];
1778 Convert frame-relative x/y to coordinates relative to window W.
1779 Takes pseudo-windows into account. */
1782 frame_to_window_pixel_xy (w
, x
, y
)
1786 if (w
->pseudo_window_p
)
1788 /* A pseudo-window is always full-width, and starts at the
1789 left edge of the frame, plus a frame border. */
1790 struct frame
*f
= XFRAME (w
->frame
);
1791 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1792 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1796 *x
-= WINDOW_LEFT_EDGE_X (w
);
1797 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1802 Return in RECTS[] at most N clipping rectangles for glyph string S.
1803 Return the number of stored rectangles. */
1806 get_glyph_string_clip_rects (s
, rects
, n
)
1807 struct glyph_string
*s
;
1808 NativeRectangle
*rects
;
1816 if (s
->row
->full_width_p
)
1818 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1819 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1820 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1822 /* Unless displaying a mode or menu bar line, which are always
1823 fully visible, clip to the visible part of the row. */
1824 if (s
->w
->pseudo_window_p
)
1825 r
.height
= s
->row
->visible_height
;
1827 r
.height
= s
->height
;
1831 /* This is a text line that may be partially visible. */
1832 r
.x
= window_box_left (s
->w
, s
->area
);
1833 r
.width
= window_box_width (s
->w
, s
->area
);
1834 r
.height
= s
->row
->visible_height
;
1838 if (r
.x
< s
->clip_head
->x
)
1840 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1841 r
.width
-= s
->clip_head
->x
- r
.x
;
1844 r
.x
= s
->clip_head
->x
;
1847 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1849 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1850 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1855 /* If S draws overlapping rows, it's sufficient to use the top and
1856 bottom of the window for clipping because this glyph string
1857 intentionally draws over other lines. */
1858 if (s
->for_overlaps
)
1860 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1861 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1863 /* Alas, the above simple strategy does not work for the
1864 environments with anti-aliased text: if the same text is
1865 drawn onto the same place multiple times, it gets thicker.
1866 If the overlap we are processing is for the erased cursor, we
1867 take the intersection with the rectagle of the cursor. */
1868 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1870 XRectangle rc
, r_save
= r
;
1872 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1873 rc
.y
= s
->w
->phys_cursor
.y
;
1874 rc
.width
= s
->w
->phys_cursor_width
;
1875 rc
.height
= s
->w
->phys_cursor_height
;
1877 x_intersect_rectangles (&r_save
, &rc
, &r
);
1882 /* Don't use S->y for clipping because it doesn't take partially
1883 visible lines into account. For example, it can be negative for
1884 partially visible lines at the top of a window. */
1885 if (!s
->row
->full_width_p
1886 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1887 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1889 r
.y
= max (0, s
->row
->y
);
1891 /* If drawing a tool-bar window, draw it over the internal border
1892 at the top of the window. */
1893 if (WINDOWP (s
->f
->tool_bar_window
)
1894 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1895 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1898 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1900 /* If drawing the cursor, don't let glyph draw outside its
1901 advertised boundaries. Cleartype does this under some circumstances. */
1902 if (s
->hl
== DRAW_CURSOR
)
1904 struct glyph
*glyph
= s
->first_glyph
;
1909 r
.width
-= s
->x
- r
.x
;
1912 r
.width
= min (r
.width
, glyph
->pixel_width
);
1914 /* If r.y is below window bottom, ensure that we still see a cursor. */
1915 height
= min (glyph
->ascent
+ glyph
->descent
,
1916 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1917 max_y
= window_text_bottom_y (s
->w
) - height
;
1918 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1919 if (s
->ybase
- glyph
->ascent
> max_y
)
1926 /* Don't draw cursor glyph taller than our actual glyph. */
1927 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1928 if (height
< r
.height
)
1930 max_y
= r
.y
+ r
.height
;
1931 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1932 r
.height
= min (max_y
- r
.y
, height
);
1937 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1938 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1940 #ifdef CONVERT_FROM_XRECT
1941 CONVERT_FROM_XRECT (r
, *rects
);
1949 /* If we are processing overlapping and allowed to return
1950 multiple clipping rectangles, we exclude the row of the glyph
1951 string from the clipping rectangle. This is to avoid drawing
1952 the same text on the environment with anti-aliasing. */
1953 #ifdef CONVERT_FROM_XRECT
1956 XRectangle
*rs
= rects
;
1958 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
1960 if (s
->for_overlaps
& OVERLAPS_PRED
)
1963 if (r
.y
+ r
.height
> row_y
)
1966 rs
[i
].height
= row_y
- r
.y
;
1972 if (s
->for_overlaps
& OVERLAPS_SUCC
)
1975 if (r
.y
< row_y
+ s
->row
->visible_height
)
1977 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
1979 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
1980 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
1989 #ifdef CONVERT_FROM_XRECT
1990 for (i
= 0; i
< n
; i
++)
1991 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
1998 Return in *NR the clipping rectangle for glyph string S. */
2001 get_glyph_string_clip_rect (s
, nr
)
2002 struct glyph_string
*s
;
2003 NativeRectangle
*nr
;
2005 get_glyph_string_clip_rects (s
, nr
, 1);
2010 Return the position and height of the phys cursor in window W.
2011 Set w->phys_cursor_width to width of phys cursor.
2015 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2017 struct glyph_row
*row
;
2018 struct glyph
*glyph
;
2019 int *xp
, *yp
, *heightp
;
2021 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2022 int x
, y
, wd
, h
, h0
, y0
;
2024 /* Compute the width of the rectangle to draw. If on a stretch
2025 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2026 rectangle as wide as the glyph, but use a canonical character
2028 wd
= glyph
->pixel_width
- 1;
2033 x
= w
->phys_cursor
.x
;
2040 if (glyph
->type
== STRETCH_GLYPH
2041 && !x_stretch_cursor_p
)
2042 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2043 w
->phys_cursor_width
= wd
;
2045 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2047 /* If y is below window bottom, ensure that we still see a cursor. */
2048 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2050 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2051 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2053 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2056 h
= max (h
- (y0
- y
) + 1, h0
);
2061 y0
= window_text_bottom_y (w
) - h0
;
2069 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2070 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2075 * Remember which glyph the mouse is over.
2079 remember_mouse_glyph (f
, gx
, gy
, rect
)
2082 NativeRectangle
*rect
;
2084 Lisp_Object window
= Qnil
;
2086 struct glyph_row
*r
, *gr
, *end_row
;
2087 enum window_part part
;
2088 enum glyph_row_area area
;
2089 int x
, y
, width
, height
;
2091 /* Try to determine frame pixel position and size of the glyph under
2092 frame pixel coordinates X/Y on frame F. */
2094 if (f
->glyphs_initialized_p
)
2095 window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0);
2099 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2100 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2104 w
= XWINDOW (window
);
2105 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2106 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2108 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2109 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2111 if (w
->pseudo_window_p
)
2114 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2120 case ON_LEFT_MARGIN
:
2121 area
= LEFT_MARGIN_AREA
;
2124 case ON_RIGHT_MARGIN
:
2125 area
= RIGHT_MARGIN_AREA
;
2128 case ON_HEADER_LINE
:
2130 gr
= (part
== ON_HEADER_LINE
2131 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2132 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2135 goto text_glyph_row_found
;
2142 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2143 if (r
->y
+ r
->height
> y
)
2149 text_glyph_row_found
:
2152 struct glyph
*g
= gr
->glyphs
[area
];
2153 struct glyph
*end
= g
+ gr
->used
[area
];
2155 height
= gr
->height
;
2156 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2157 if (gx
+ g
->pixel_width
> x
)
2162 if (g
->type
== IMAGE_GLYPH
)
2164 /* Don't remember when mouse is over image, as
2165 image may have hot-spots. */
2166 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2169 width
= g
->pixel_width
;
2173 /* Use nominal char spacing at end of line. */
2175 gx
+= (x
/ width
) * width
;
2178 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2179 gx
+= window_box_left_offset (w
, area
);
2183 /* Use nominal line height at end of window. */
2184 gx
= (x
/ width
) * width
;
2186 gy
+= (y
/ height
) * height
;
2190 case ON_LEFT_FRINGE
:
2191 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2192 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2193 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2194 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2197 case ON_RIGHT_FRINGE
:
2198 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2199 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2200 : window_box_right_offset (w
, TEXT_AREA
));
2201 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2205 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2207 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2208 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2209 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2211 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2215 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2216 if (r
->y
+ r
->height
> y
)
2223 height
= gr
->height
;
2226 /* Use nominal line height at end of window. */
2228 gy
+= (y
/ height
) * height
;
2235 /* If there is no glyph under the mouse, then we divide the screen
2236 into a grid of the smallest glyph in the frame, and use that
2239 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2240 round down even for negative values. */
2246 gx
= (gx
/ width
) * width
;
2247 gy
= (gy
/ height
) * height
;
2252 gx
+= WINDOW_LEFT_EDGE_X (w
);
2253 gy
+= WINDOW_TOP_EDGE_Y (w
);
2256 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2258 /* Visible feedback for debugging. */
2261 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2262 f
->output_data
.x
->normal_gc
,
2263 gx
, gy
, width
, height
);
2269 #endif /* HAVE_WINDOW_SYSTEM */
2272 /***********************************************************************
2273 Lisp form evaluation
2274 ***********************************************************************/
2276 /* Error handler for safe_eval and safe_call. */
2279 safe_eval_handler (arg
)
2282 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2287 /* Evaluate SEXPR and return the result, or nil if something went
2288 wrong. Prevent redisplay during the evaluation. */
2296 if (inhibit_eval_during_redisplay
)
2300 int count
= SPECPDL_INDEX ();
2301 struct gcpro gcpro1
;
2304 specbind (Qinhibit_redisplay
, Qt
);
2305 /* Use Qt to ensure debugger does not run,
2306 so there is no possibility of wanting to redisplay. */
2307 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
2310 val
= unbind_to (count
, val
);
2317 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2318 Return the result, or nil if something went wrong. Prevent
2319 redisplay during the evaluation. */
2322 safe_call (nargs
, args
)
2328 if (inhibit_eval_during_redisplay
)
2332 int count
= SPECPDL_INDEX ();
2333 struct gcpro gcpro1
;
2336 gcpro1
.nvars
= nargs
;
2337 specbind (Qinhibit_redisplay
, Qt
);
2338 /* Use Qt to ensure debugger does not run,
2339 so there is no possibility of wanting to redisplay. */
2340 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2343 val
= unbind_to (count
, val
);
2350 /* Call function FN with one argument ARG.
2351 Return the result, or nil if something went wrong. */
2354 safe_call1 (fn
, arg
)
2355 Lisp_Object fn
, arg
;
2357 Lisp_Object args
[2];
2360 return safe_call (2, args
);
2365 /***********************************************************************
2367 ***********************************************************************/
2371 /* Define CHECK_IT to perform sanity checks on iterators.
2372 This is for debugging. It is too slow to do unconditionally. */
2378 if (it
->method
== GET_FROM_STRING
)
2380 xassert (STRINGP (it
->string
));
2381 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2385 xassert (IT_STRING_CHARPOS (*it
) < 0);
2386 if (it
->method
== GET_FROM_BUFFER
)
2388 /* Check that character and byte positions agree. */
2389 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2394 xassert (it
->current
.dpvec_index
>= 0);
2396 xassert (it
->current
.dpvec_index
< 0);
2399 #define CHECK_IT(IT) check_it ((IT))
2403 #define CHECK_IT(IT) (void) 0
2410 /* Check that the window end of window W is what we expect it
2411 to be---the last row in the current matrix displaying text. */
2414 check_window_end (w
)
2417 if (!MINI_WINDOW_P (w
)
2418 && !NILP (w
->window_end_valid
))
2420 struct glyph_row
*row
;
2421 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2422 XFASTINT (w
->window_end_vpos
)),
2424 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2425 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2429 #define CHECK_WINDOW_END(W) check_window_end ((W))
2431 #else /* not GLYPH_DEBUG */
2433 #define CHECK_WINDOW_END(W) (void) 0
2435 #endif /* not GLYPH_DEBUG */
2439 /***********************************************************************
2440 Iterator initialization
2441 ***********************************************************************/
2443 /* Initialize IT for displaying current_buffer in window W, starting
2444 at character position CHARPOS. CHARPOS < 0 means that no buffer
2445 position is specified which is useful when the iterator is assigned
2446 a position later. BYTEPOS is the byte position corresponding to
2447 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2449 If ROW is not null, calls to produce_glyphs with IT as parameter
2450 will produce glyphs in that row.
2452 BASE_FACE_ID is the id of a base face to use. It must be one of
2453 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2454 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2455 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2457 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2458 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2459 will be initialized to use the corresponding mode line glyph row of
2460 the desired matrix of W. */
2463 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2466 int charpos
, bytepos
;
2467 struct glyph_row
*row
;
2468 enum face_id base_face_id
;
2470 int highlight_region_p
;
2472 /* Some precondition checks. */
2473 xassert (w
!= NULL
&& it
!= NULL
);
2474 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2477 /* If face attributes have been changed since the last redisplay,
2478 free realized faces now because they depend on face definitions
2479 that might have changed. Don't free faces while there might be
2480 desired matrices pending which reference these faces. */
2481 if (face_change_count
&& !inhibit_free_realized_faces
)
2483 face_change_count
= 0;
2484 free_all_realized_faces (Qnil
);
2487 /* Use one of the mode line rows of W's desired matrix if
2491 if (base_face_id
== MODE_LINE_FACE_ID
2492 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2493 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2494 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2495 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2499 bzero (it
, sizeof *it
);
2500 it
->current
.overlay_string_index
= -1;
2501 it
->current
.dpvec_index
= -1;
2502 it
->base_face_id
= base_face_id
;
2504 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2506 /* The window in which we iterate over current_buffer: */
2507 XSETWINDOW (it
->window
, w
);
2509 it
->f
= XFRAME (w
->frame
);
2511 /* Extra space between lines (on window systems only). */
2512 if (base_face_id
== DEFAULT_FACE_ID
2513 && FRAME_WINDOW_P (it
->f
))
2515 if (NATNUMP (current_buffer
->extra_line_spacing
))
2516 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2517 else if (FLOATP (current_buffer
->extra_line_spacing
))
2518 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2519 * FRAME_LINE_HEIGHT (it
->f
));
2520 else if (it
->f
->extra_line_spacing
> 0)
2521 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2522 it
->max_extra_line_spacing
= 0;
2525 /* If realized faces have been removed, e.g. because of face
2526 attribute changes of named faces, recompute them. When running
2527 in batch mode, the face cache of Vterminal_frame is null. If
2528 we happen to get called, make a dummy face cache. */
2529 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2530 init_frame_faces (it
->f
);
2531 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2532 recompute_basic_faces (it
->f
);
2534 /* Current value of the `slice', `space-width', and 'height' properties. */
2535 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2536 it
->space_width
= Qnil
;
2537 it
->font_height
= Qnil
;
2538 it
->override_ascent
= -1;
2540 /* Are control characters displayed as `^C'? */
2541 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2543 /* -1 means everything between a CR and the following line end
2544 is invisible. >0 means lines indented more than this value are
2546 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2547 ? XFASTINT (current_buffer
->selective_display
)
2548 : (!NILP (current_buffer
->selective_display
)
2550 it
->selective_display_ellipsis_p
2551 = !NILP (current_buffer
->selective_display_ellipses
);
2553 /* Display table to use. */
2554 it
->dp
= window_display_table (w
);
2556 /* Are multibyte characters enabled in current_buffer? */
2557 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2559 /* Non-zero if we should highlight the region. */
2561 = (!NILP (Vtransient_mark_mode
)
2562 && !NILP (current_buffer
->mark_active
)
2563 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2565 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2566 start and end of a visible region in window IT->w. Set both to
2567 -1 to indicate no region. */
2568 if (highlight_region_p
2569 /* Maybe highlight only in selected window. */
2570 && (/* Either show region everywhere. */
2571 highlight_nonselected_windows
2572 /* Or show region in the selected window. */
2573 || w
== XWINDOW (selected_window
)
2574 /* Or show the region if we are in the mini-buffer and W is
2575 the window the mini-buffer refers to. */
2576 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2577 && WINDOWP (minibuf_selected_window
)
2578 && w
== XWINDOW (minibuf_selected_window
))))
2580 int charpos
= marker_position (current_buffer
->mark
);
2581 it
->region_beg_charpos
= min (PT
, charpos
);
2582 it
->region_end_charpos
= max (PT
, charpos
);
2585 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2587 /* Get the position at which the redisplay_end_trigger hook should
2588 be run, if it is to be run at all. */
2589 if (MARKERP (w
->redisplay_end_trigger
)
2590 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2591 it
->redisplay_end_trigger_charpos
2592 = marker_position (w
->redisplay_end_trigger
);
2593 else if (INTEGERP (w
->redisplay_end_trigger
))
2594 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2596 /* Correct bogus values of tab_width. */
2597 it
->tab_width
= XINT (current_buffer
->tab_width
);
2598 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2601 /* Are lines in the display truncated? */
2602 it
->truncate_lines_p
2603 = (base_face_id
!= DEFAULT_FACE_ID
2604 || XINT (it
->w
->hscroll
)
2605 || (truncate_partial_width_windows
2606 && !WINDOW_FULL_WIDTH_P (it
->w
))
2607 || !NILP (current_buffer
->truncate_lines
));
2609 /* Get dimensions of truncation and continuation glyphs. These are
2610 displayed as fringe bitmaps under X, so we don't need them for such
2612 if (!FRAME_WINDOW_P (it
->f
))
2614 if (it
->truncate_lines_p
)
2616 /* We will need the truncation glyph. */
2617 xassert (it
->glyph_row
== NULL
);
2618 produce_special_glyphs (it
, IT_TRUNCATION
);
2619 it
->truncation_pixel_width
= it
->pixel_width
;
2623 /* We will need the continuation glyph. */
2624 xassert (it
->glyph_row
== NULL
);
2625 produce_special_glyphs (it
, IT_CONTINUATION
);
2626 it
->continuation_pixel_width
= it
->pixel_width
;
2629 /* Reset these values to zero because the produce_special_glyphs
2630 above has changed them. */
2631 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2632 it
->phys_ascent
= it
->phys_descent
= 0;
2635 /* Set this after getting the dimensions of truncation and
2636 continuation glyphs, so that we don't produce glyphs when calling
2637 produce_special_glyphs, above. */
2638 it
->glyph_row
= row
;
2639 it
->area
= TEXT_AREA
;
2641 /* Get the dimensions of the display area. The display area
2642 consists of the visible window area plus a horizontally scrolled
2643 part to the left of the window. All x-values are relative to the
2644 start of this total display area. */
2645 if (base_face_id
!= DEFAULT_FACE_ID
)
2647 /* Mode lines, menu bar in terminal frames. */
2648 it
->first_visible_x
= 0;
2649 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2654 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2655 it
->last_visible_x
= (it
->first_visible_x
2656 + window_box_width (w
, TEXT_AREA
));
2658 /* If we truncate lines, leave room for the truncator glyph(s) at
2659 the right margin. Otherwise, leave room for the continuation
2660 glyph(s). Truncation and continuation glyphs are not inserted
2661 for window-based redisplay. */
2662 if (!FRAME_WINDOW_P (it
->f
))
2664 if (it
->truncate_lines_p
)
2665 it
->last_visible_x
-= it
->truncation_pixel_width
;
2667 it
->last_visible_x
-= it
->continuation_pixel_width
;
2670 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2671 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2674 /* Leave room for a border glyph. */
2675 if (!FRAME_WINDOW_P (it
->f
)
2676 && !WINDOW_RIGHTMOST_P (it
->w
))
2677 it
->last_visible_x
-= 1;
2679 it
->last_visible_y
= window_text_bottom_y (w
);
2681 /* For mode lines and alike, arrange for the first glyph having a
2682 left box line if the face specifies a box. */
2683 if (base_face_id
!= DEFAULT_FACE_ID
)
2687 it
->face_id
= base_face_id
;
2689 /* If we have a boxed mode line, make the first character appear
2690 with a left box line. */
2691 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2692 if (face
->box
!= FACE_NO_BOX
)
2693 it
->start_of_box_run_p
= 1;
2696 /* If a buffer position was specified, set the iterator there,
2697 getting overlays and face properties from that position. */
2698 if (charpos
>= BUF_BEG (current_buffer
))
2700 it
->end_charpos
= ZV
;
2702 IT_CHARPOS (*it
) = charpos
;
2704 /* Compute byte position if not specified. */
2705 if (bytepos
< charpos
)
2706 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2708 IT_BYTEPOS (*it
) = bytepos
;
2710 it
->start
= it
->current
;
2712 /* Compute faces etc. */
2713 reseat (it
, it
->current
.pos
, 1);
2720 /* Initialize IT for the display of window W with window start POS. */
2723 start_display (it
, w
, pos
)
2726 struct text_pos pos
;
2728 struct glyph_row
*row
;
2729 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2731 row
= w
->desired_matrix
->rows
+ first_vpos
;
2732 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2733 it
->first_vpos
= first_vpos
;
2735 /* Don't reseat to previous visible line start if current start
2736 position is in a string or image. */
2737 if (it
->method
== GET_FROM_BUFFER
&& !it
->truncate_lines_p
)
2739 int start_at_line_beg_p
;
2740 int first_y
= it
->current_y
;
2742 /* If window start is not at a line start, skip forward to POS to
2743 get the correct continuation lines width. */
2744 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2745 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2746 if (!start_at_line_beg_p
)
2750 reseat_at_previous_visible_line_start (it
);
2751 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2753 new_x
= it
->current_x
+ it
->pixel_width
;
2755 /* If lines are continued, this line may end in the middle
2756 of a multi-glyph character (e.g. a control character
2757 displayed as \003, or in the middle of an overlay
2758 string). In this case move_it_to above will not have
2759 taken us to the start of the continuation line but to the
2760 end of the continued line. */
2761 if (it
->current_x
> 0
2762 && !it
->truncate_lines_p
/* Lines are continued. */
2763 && (/* And glyph doesn't fit on the line. */
2764 new_x
> it
->last_visible_x
2765 /* Or it fits exactly and we're on a window
2767 || (new_x
== it
->last_visible_x
2768 && FRAME_WINDOW_P (it
->f
))))
2770 if (it
->current
.dpvec_index
>= 0
2771 || it
->current
.overlay_string_index
>= 0)
2773 set_iterator_to_next (it
, 1);
2774 move_it_in_display_line_to (it
, -1, -1, 0);
2777 it
->continuation_lines_width
+= it
->current_x
;
2780 /* We're starting a new display line, not affected by the
2781 height of the continued line, so clear the appropriate
2782 fields in the iterator structure. */
2783 it
->max_ascent
= it
->max_descent
= 0;
2784 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2786 it
->current_y
= first_y
;
2788 it
->current_x
= it
->hpos
= 0;
2792 #if 0 /* Don't assert the following because start_display is sometimes
2793 called intentionally with a window start that is not at a
2794 line start. Please leave this code in as a comment. */
2796 /* Window start should be on a line start, now. */
2797 xassert (it
->continuation_lines_width
2798 || IT_CHARPOS (it
) == BEGV
2799 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2804 /* Return 1 if POS is a position in ellipses displayed for invisible
2805 text. W is the window we display, for text property lookup. */
2808 in_ellipses_for_invisible_text_p (pos
, w
)
2809 struct display_pos
*pos
;
2812 Lisp_Object prop
, window
;
2814 int charpos
= CHARPOS (pos
->pos
);
2816 /* If POS specifies a position in a display vector, this might
2817 be for an ellipsis displayed for invisible text. We won't
2818 get the iterator set up for delivering that ellipsis unless
2819 we make sure that it gets aware of the invisible text. */
2820 if (pos
->dpvec_index
>= 0
2821 && pos
->overlay_string_index
< 0
2822 && CHARPOS (pos
->string_pos
) < 0
2824 && (XSETWINDOW (window
, w
),
2825 prop
= Fget_char_property (make_number (charpos
),
2826 Qinvisible
, window
),
2827 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2829 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2831 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2838 /* Initialize IT for stepping through current_buffer in window W,
2839 starting at position POS that includes overlay string and display
2840 vector/ control character translation position information. Value
2841 is zero if there are overlay strings with newlines at POS. */
2844 init_from_display_pos (it
, w
, pos
)
2847 struct display_pos
*pos
;
2849 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2850 int i
, overlay_strings_with_newlines
= 0;
2852 /* If POS specifies a position in a display vector, this might
2853 be for an ellipsis displayed for invisible text. We won't
2854 get the iterator set up for delivering that ellipsis unless
2855 we make sure that it gets aware of the invisible text. */
2856 if (in_ellipses_for_invisible_text_p (pos
, w
))
2862 /* Keep in mind: the call to reseat in init_iterator skips invisible
2863 text, so we might end up at a position different from POS. This
2864 is only a problem when POS is a row start after a newline and an
2865 overlay starts there with an after-string, and the overlay has an
2866 invisible property. Since we don't skip invisible text in
2867 display_line and elsewhere immediately after consuming the
2868 newline before the row start, such a POS will not be in a string,
2869 but the call to init_iterator below will move us to the
2871 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2873 /* This only scans the current chunk -- it should scan all chunks.
2874 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2875 to 16 in 22.1 to make this a lesser problem. */
2876 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2878 const char *s
= SDATA (it
->overlay_strings
[i
]);
2879 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2881 while (s
< e
&& *s
!= '\n')
2886 overlay_strings_with_newlines
= 1;
2891 /* If position is within an overlay string, set up IT to the right
2893 if (pos
->overlay_string_index
>= 0)
2897 /* If the first overlay string happens to have a `display'
2898 property for an image, the iterator will be set up for that
2899 image, and we have to undo that setup first before we can
2900 correct the overlay string index. */
2901 if (it
->method
== GET_FROM_IMAGE
)
2904 /* We already have the first chunk of overlay strings in
2905 IT->overlay_strings. Load more until the one for
2906 pos->overlay_string_index is in IT->overlay_strings. */
2907 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2909 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2910 it
->current
.overlay_string_index
= 0;
2913 load_overlay_strings (it
, 0);
2914 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2918 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2919 relative_index
= (it
->current
.overlay_string_index
2920 % OVERLAY_STRING_CHUNK_SIZE
);
2921 it
->string
= it
->overlay_strings
[relative_index
];
2922 xassert (STRINGP (it
->string
));
2923 it
->current
.string_pos
= pos
->string_pos
;
2924 it
->method
= GET_FROM_STRING
;
2927 #if 0 /* This is bogus because POS not having an overlay string
2928 position does not mean it's after the string. Example: A
2929 line starting with a before-string and initialization of IT
2930 to the previous row's end position. */
2931 else if (it
->current
.overlay_string_index
>= 0)
2933 /* If POS says we're already after an overlay string ending at
2934 POS, make sure to pop the iterator because it will be in
2935 front of that overlay string. When POS is ZV, we've thereby
2936 also ``processed'' overlay strings at ZV. */
2939 xassert (it
->current
.overlay_string_index
== -1);
2940 xassert (it
->method
== GET_FROM_BUFFER
);
2941 if (CHARPOS (pos
->pos
) == ZV
)
2942 it
->overlay_strings_at_end_processed_p
= 1;
2946 if (CHARPOS (pos
->string_pos
) >= 0)
2948 /* Recorded position is not in an overlay string, but in another
2949 string. This can only be a string from a `display' property.
2950 IT should already be filled with that string. */
2951 it
->current
.string_pos
= pos
->string_pos
;
2952 xassert (STRINGP (it
->string
));
2955 /* Restore position in display vector translations, control
2956 character translations or ellipses. */
2957 if (pos
->dpvec_index
>= 0)
2959 if (it
->dpvec
== NULL
)
2960 get_next_display_element (it
);
2961 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2962 it
->current
.dpvec_index
= pos
->dpvec_index
;
2966 return !overlay_strings_with_newlines
;
2970 /* Initialize IT for stepping through current_buffer in window W
2971 starting at ROW->start. */
2974 init_to_row_start (it
, w
, row
)
2977 struct glyph_row
*row
;
2979 init_from_display_pos (it
, w
, &row
->start
);
2980 it
->start
= row
->start
;
2981 it
->continuation_lines_width
= row
->continuation_lines_width
;
2986 /* Initialize IT for stepping through current_buffer in window W
2987 starting in the line following ROW, i.e. starting at ROW->end.
2988 Value is zero if there are overlay strings with newlines at ROW's
2992 init_to_row_end (it
, w
, row
)
2995 struct glyph_row
*row
;
2999 if (init_from_display_pos (it
, w
, &row
->end
))
3001 if (row
->continued_p
)
3002 it
->continuation_lines_width
3003 = row
->continuation_lines_width
+ row
->pixel_width
;
3014 /***********************************************************************
3016 ***********************************************************************/
3018 /* Called when IT reaches IT->stop_charpos. Handle text property and
3019 overlay changes. Set IT->stop_charpos to the next position where
3026 enum prop_handled handled
;
3027 int handle_overlay_change_p
;
3031 it
->current
.dpvec_index
= -1;
3032 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3033 it
->ignore_overlay_strings_at_pos_p
= 0;
3035 /* Use face of preceding text for ellipsis (if invisible) */
3036 if (it
->selective_display_ellipsis_p
)
3037 it
->saved_face_id
= it
->face_id
;
3041 handled
= HANDLED_NORMALLY
;
3043 /* Call text property handlers. */
3044 for (p
= it_props
; p
->handler
; ++p
)
3046 handled
= p
->handler (it
);
3048 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3050 else if (handled
== HANDLED_RETURN
)
3052 /* We still want to show before and after strings from
3053 overlays even if the actual buffer text is replaced. */
3054 if (!handle_overlay_change_p
|| it
->sp
> 1)
3056 if (!get_overlay_strings_1 (it
, 0, 0))
3058 it
->ignore_overlay_strings_at_pos_p
= 1;
3059 it
->string_from_display_prop_p
= 0;
3060 handle_overlay_change_p
= 0;
3061 handled
= HANDLED_RECOMPUTE_PROPS
;
3064 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3065 handle_overlay_change_p
= 0;
3068 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3070 /* Don't check for overlay strings below when set to deliver
3071 characters from a display vector. */
3072 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3073 handle_overlay_change_p
= 0;
3075 /* Handle overlay changes. */
3076 if (handle_overlay_change_p
)
3077 handled
= handle_overlay_change (it
);
3079 /* Determine where to stop next. */
3080 if (handled
== HANDLED_NORMALLY
)
3081 compute_stop_pos (it
);
3084 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3088 /* Compute IT->stop_charpos from text property and overlay change
3089 information for IT's current position. */
3092 compute_stop_pos (it
)
3095 register INTERVAL iv
, next_iv
;
3096 Lisp_Object object
, limit
, position
;
3098 /* If nowhere else, stop at the end. */
3099 it
->stop_charpos
= it
->end_charpos
;
3101 if (STRINGP (it
->string
))
3103 /* Strings are usually short, so don't limit the search for
3105 object
= it
->string
;
3107 position
= make_number (IT_STRING_CHARPOS (*it
));
3113 /* If next overlay change is in front of the current stop pos
3114 (which is IT->end_charpos), stop there. Note: value of
3115 next_overlay_change is point-max if no overlay change
3117 charpos
= next_overlay_change (IT_CHARPOS (*it
));
3118 if (charpos
< it
->stop_charpos
)
3119 it
->stop_charpos
= charpos
;
3121 /* If showing the region, we have to stop at the region
3122 start or end because the face might change there. */
3123 if (it
->region_beg_charpos
> 0)
3125 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3126 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3127 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3128 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3131 /* Set up variables for computing the stop position from text
3132 property changes. */
3133 XSETBUFFER (object
, current_buffer
);
3134 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3135 position
= make_number (IT_CHARPOS (*it
));
3139 /* Get the interval containing IT's position. Value is a null
3140 interval if there isn't such an interval. */
3141 iv
= validate_interval_range (object
, &position
, &position
, 0);
3142 if (!NULL_INTERVAL_P (iv
))
3144 Lisp_Object values_here
[LAST_PROP_IDX
];
3147 /* Get properties here. */
3148 for (p
= it_props
; p
->handler
; ++p
)
3149 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3151 /* Look for an interval following iv that has different
3153 for (next_iv
= next_interval (iv
);
3154 (!NULL_INTERVAL_P (next_iv
)
3156 || XFASTINT (limit
) > next_iv
->position
));
3157 next_iv
= next_interval (next_iv
))
3159 for (p
= it_props
; p
->handler
; ++p
)
3161 Lisp_Object new_value
;
3163 new_value
= textget (next_iv
->plist
, *p
->name
);
3164 if (!EQ (values_here
[p
->idx
], new_value
))
3172 if (!NULL_INTERVAL_P (next_iv
))
3174 if (INTEGERP (limit
)
3175 && next_iv
->position
>= XFASTINT (limit
))
3176 /* No text property change up to limit. */
3177 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3179 /* Text properties change in next_iv. */
3180 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3184 xassert (STRINGP (it
->string
)
3185 || (it
->stop_charpos
>= BEGV
3186 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3190 /* Return the position of the next overlay change after POS in
3191 current_buffer. Value is point-max if no overlay change
3192 follows. This is like `next-overlay-change' but doesn't use
3196 next_overlay_change (pos
)
3201 Lisp_Object
*overlays
;
3204 /* Get all overlays at the given position. */
3205 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3207 /* If any of these overlays ends before endpos,
3208 use its ending point instead. */
3209 for (i
= 0; i
< noverlays
; ++i
)
3214 oend
= OVERLAY_END (overlays
[i
]);
3215 oendpos
= OVERLAY_POSITION (oend
);
3216 endpos
= min (endpos
, oendpos
);
3224 /***********************************************************************
3226 ***********************************************************************/
3228 /* Handle changes in the `fontified' property of the current buffer by
3229 calling hook functions from Qfontification_functions to fontify
3232 static enum prop_handled
3233 handle_fontified_prop (it
)
3236 Lisp_Object prop
, pos
;
3237 enum prop_handled handled
= HANDLED_NORMALLY
;
3239 if (!NILP (Vmemory_full
))
3242 /* Get the value of the `fontified' property at IT's current buffer
3243 position. (The `fontified' property doesn't have a special
3244 meaning in strings.) If the value is nil, call functions from
3245 Qfontification_functions. */
3246 if (!STRINGP (it
->string
)
3248 && !NILP (Vfontification_functions
)
3249 && !NILP (Vrun_hooks
)
3250 && (pos
= make_number (IT_CHARPOS (*it
)),
3251 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3252 /* Ignore the special cased nil value always present at EOB since
3253 no amount of fontifying will be able to change it. */
3254 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3256 int count
= SPECPDL_INDEX ();
3259 val
= Vfontification_functions
;
3260 specbind (Qfontification_functions
, Qnil
);
3262 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3263 safe_call1 (val
, pos
);
3266 Lisp_Object globals
, fn
;
3267 struct gcpro gcpro1
, gcpro2
;
3270 GCPRO2 (val
, globals
);
3272 for (; CONSP (val
); val
= XCDR (val
))
3278 /* A value of t indicates this hook has a local
3279 binding; it means to run the global binding too.
3280 In a global value, t should not occur. If it
3281 does, we must ignore it to avoid an endless
3283 for (globals
= Fdefault_value (Qfontification_functions
);
3285 globals
= XCDR (globals
))
3287 fn
= XCAR (globals
);
3289 safe_call1 (fn
, pos
);
3293 safe_call1 (fn
, pos
);
3299 unbind_to (count
, Qnil
);
3301 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3302 something. This avoids an endless loop if they failed to
3303 fontify the text for which reason ever. */
3304 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3305 handled
= HANDLED_RECOMPUTE_PROPS
;
3313 /***********************************************************************
3315 ***********************************************************************/
3317 /* Set up iterator IT from face properties at its current position.
3318 Called from handle_stop. */
3320 static enum prop_handled
3321 handle_face_prop (it
)
3324 int new_face_id
, next_stop
;
3326 if (!STRINGP (it
->string
))
3329 = face_at_buffer_position (it
->w
,
3331 it
->region_beg_charpos
,
3332 it
->region_end_charpos
,
3335 + TEXT_PROP_DISTANCE_LIMIT
),
3338 /* Is this a start of a run of characters with box face?
3339 Caveat: this can be called for a freshly initialized
3340 iterator; face_id is -1 in this case. We know that the new
3341 face will not change until limit, i.e. if the new face has a
3342 box, all characters up to limit will have one. But, as
3343 usual, we don't know whether limit is really the end. */
3344 if (new_face_id
!= it
->face_id
)
3346 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3348 /* If new face has a box but old face has not, this is
3349 the start of a run of characters with box, i.e. it has
3350 a shadow on the left side. The value of face_id of the
3351 iterator will be -1 if this is the initial call that gets
3352 the face. In this case, we have to look in front of IT's
3353 position and see whether there is a face != new_face_id. */
3354 it
->start_of_box_run_p
3355 = (new_face
->box
!= FACE_NO_BOX
3356 && (it
->face_id
>= 0
3357 || IT_CHARPOS (*it
) == BEG
3358 || new_face_id
!= face_before_it_pos (it
)));
3359 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3364 int base_face_id
, bufpos
;
3366 if (it
->current
.overlay_string_index
>= 0)
3367 bufpos
= IT_CHARPOS (*it
);
3371 /* For strings from a buffer, i.e. overlay strings or strings
3372 from a `display' property, use the face at IT's current
3373 buffer position as the base face to merge with, so that
3374 overlay strings appear in the same face as surrounding
3375 text, unless they specify their own faces. */
3376 base_face_id
= underlying_face_id (it
);
3378 new_face_id
= face_at_string_position (it
->w
,
3380 IT_STRING_CHARPOS (*it
),
3382 it
->region_beg_charpos
,
3383 it
->region_end_charpos
,
3387 #if 0 /* This shouldn't be neccessary. Let's check it. */
3388 /* If IT is used to display a mode line we would really like to
3389 use the mode line face instead of the frame's default face. */
3390 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3391 && new_face_id
== DEFAULT_FACE_ID
)
3392 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3395 /* Is this a start of a run of characters with box? Caveat:
3396 this can be called for a freshly allocated iterator; face_id
3397 is -1 is this case. We know that the new face will not
3398 change until the next check pos, i.e. if the new face has a
3399 box, all characters up to that position will have a
3400 box. But, as usual, we don't know whether that position
3401 is really the end. */
3402 if (new_face_id
!= it
->face_id
)
3404 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3405 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3407 /* If new face has a box but old face hasn't, this is the
3408 start of a run of characters with box, i.e. it has a
3409 shadow on the left side. */
3410 it
->start_of_box_run_p
3411 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3412 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3416 it
->face_id
= new_face_id
;
3417 return HANDLED_NORMALLY
;
3421 /* Return the ID of the face ``underlying'' IT's current position,
3422 which is in a string. If the iterator is associated with a
3423 buffer, return the face at IT's current buffer position.
3424 Otherwise, use the iterator's base_face_id. */
3427 underlying_face_id (it
)
3430 int face_id
= it
->base_face_id
, i
;
3432 xassert (STRINGP (it
->string
));
3434 for (i
= it
->sp
- 1; i
>= 0; --i
)
3435 if (NILP (it
->stack
[i
].string
))
3436 face_id
= it
->stack
[i
].face_id
;
3442 /* Compute the face one character before or after the current position
3443 of IT. BEFORE_P non-zero means get the face in front of IT's
3444 position. Value is the id of the face. */
3447 face_before_or_after_it_pos (it
, before_p
)
3452 int next_check_charpos
;
3453 struct text_pos pos
;
3455 xassert (it
->s
== NULL
);
3457 if (STRINGP (it
->string
))
3459 int bufpos
, base_face_id
;
3461 /* No face change past the end of the string (for the case
3462 we are padding with spaces). No face change before the
3464 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3465 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3468 /* Set pos to the position before or after IT's current position. */
3470 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3472 /* For composition, we must check the character after the
3474 pos
= (it
->what
== IT_COMPOSITION
3475 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3476 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3478 if (it
->current
.overlay_string_index
>= 0)
3479 bufpos
= IT_CHARPOS (*it
);
3483 base_face_id
= underlying_face_id (it
);
3485 /* Get the face for ASCII, or unibyte. */
3486 face_id
= face_at_string_position (it
->w
,
3490 it
->region_beg_charpos
,
3491 it
->region_end_charpos
,
3492 &next_check_charpos
,
3495 /* Correct the face for charsets different from ASCII. Do it
3496 for the multibyte case only. The face returned above is
3497 suitable for unibyte text if IT->string is unibyte. */
3498 if (STRING_MULTIBYTE (it
->string
))
3500 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3501 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3503 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3505 c
= string_char_and_length (p
, rest
, &len
);
3506 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3511 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3512 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3515 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3516 pos
= it
->current
.pos
;
3519 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3522 if (it
->what
== IT_COMPOSITION
)
3523 /* For composition, we must check the position after the
3525 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3527 INC_TEXT_POS (pos
, it
->multibyte_p
);
3530 /* Determine face for CHARSET_ASCII, or unibyte. */
3531 face_id
= face_at_buffer_position (it
->w
,
3533 it
->region_beg_charpos
,
3534 it
->region_end_charpos
,
3535 &next_check_charpos
,
3538 /* Correct the face for charsets different from ASCII. Do it
3539 for the multibyte case only. The face returned above is
3540 suitable for unibyte text if current_buffer is unibyte. */
3541 if (it
->multibyte_p
)
3543 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3544 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3545 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3554 /***********************************************************************
3556 ***********************************************************************/
3558 /* Set up iterator IT from invisible properties at its current
3559 position. Called from handle_stop. */
3561 static enum prop_handled
3562 handle_invisible_prop (it
)
3565 enum prop_handled handled
= HANDLED_NORMALLY
;
3567 if (STRINGP (it
->string
))
3569 extern Lisp_Object Qinvisible
;
3570 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3572 /* Get the value of the invisible text property at the
3573 current position. Value will be nil if there is no such
3575 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3576 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3579 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3581 handled
= HANDLED_RECOMPUTE_PROPS
;
3583 /* Get the position at which the next change of the
3584 invisible text property can be found in IT->string.
3585 Value will be nil if the property value is the same for
3586 all the rest of IT->string. */
3587 XSETINT (limit
, SCHARS (it
->string
));
3588 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3591 /* Text at current position is invisible. The next
3592 change in the property is at position end_charpos.
3593 Move IT's current position to that position. */
3594 if (INTEGERP (end_charpos
)
3595 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3597 struct text_pos old
;
3598 old
= it
->current
.string_pos
;
3599 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3600 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3604 /* The rest of the string is invisible. If this is an
3605 overlay string, proceed with the next overlay string
3606 or whatever comes and return a character from there. */
3607 if (it
->current
.overlay_string_index
>= 0)
3609 next_overlay_string (it
);
3610 /* Don't check for overlay strings when we just
3611 finished processing them. */
3612 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3616 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3617 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3624 int invis_p
, newpos
, next_stop
, start_charpos
;
3625 Lisp_Object pos
, prop
, overlay
;
3627 /* First of all, is there invisible text at this position? */
3628 start_charpos
= IT_CHARPOS (*it
);
3629 pos
= make_number (IT_CHARPOS (*it
));
3630 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3632 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3634 /* If we are on invisible text, skip over it. */
3635 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3637 /* Record whether we have to display an ellipsis for the
3639 int display_ellipsis_p
= invis_p
== 2;
3641 handled
= HANDLED_RECOMPUTE_PROPS
;
3643 /* Loop skipping over invisible text. The loop is left at
3644 ZV or with IT on the first char being visible again. */
3647 /* Try to skip some invisible text. Return value is the
3648 position reached which can be equal to IT's position
3649 if there is nothing invisible here. This skips both
3650 over invisible text properties and overlays with
3651 invisible property. */
3652 newpos
= skip_invisible (IT_CHARPOS (*it
),
3653 &next_stop
, ZV
, it
->window
);
3655 /* If we skipped nothing at all we weren't at invisible
3656 text in the first place. If everything to the end of
3657 the buffer was skipped, end the loop. */
3658 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3662 /* We skipped some characters but not necessarily
3663 all there are. Check if we ended up on visible
3664 text. Fget_char_property returns the property of
3665 the char before the given position, i.e. if we
3666 get invis_p = 0, this means that the char at
3667 newpos is visible. */
3668 pos
= make_number (newpos
);
3669 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3670 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3673 /* If we ended up on invisible text, proceed to
3674 skip starting with next_stop. */
3676 IT_CHARPOS (*it
) = next_stop
;
3678 /* If there are adjacent invisible texts, don't lose the
3679 second one's ellipsis. */
3681 display_ellipsis_p
= 1;
3685 /* The position newpos is now either ZV or on visible text. */
3686 IT_CHARPOS (*it
) = newpos
;
3687 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3689 /* If there are before-strings at the start of invisible
3690 text, and the text is invisible because of a text
3691 property, arrange to show before-strings because 20.x did
3692 it that way. (If the text is invisible because of an
3693 overlay property instead of a text property, this is
3694 already handled in the overlay code.) */
3696 && get_overlay_strings (it
, start_charpos
))
3698 handled
= HANDLED_RECOMPUTE_PROPS
;
3699 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3701 else if (display_ellipsis_p
)
3703 /* Make sure that the glyphs of the ellipsis will get
3704 correct `charpos' values. If we would not update
3705 it->position here, the glyphs would belong to the
3706 last visible character _before_ the invisible
3707 text, which confuses `set_cursor_from_row'.
3709 We use the last invisible position instead of the
3710 first because this way the cursor is always drawn on
3711 the first "." of the ellipsis, whenever PT is inside
3712 the invisible text. Otherwise the cursor would be
3713 placed _after_ the ellipsis when the point is after the
3714 first invisible character. */
3715 if (!STRINGP (it
->object
))
3717 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3718 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3720 setup_for_ellipsis (it
, 0);
3729 /* Make iterator IT return `...' next.
3730 Replaces LEN characters from buffer. */
3733 setup_for_ellipsis (it
, len
)
3737 /* Use the display table definition for `...'. Invalid glyphs
3738 will be handled by the method returning elements from dpvec. */
3739 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3741 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3742 it
->dpvec
= v
->contents
;
3743 it
->dpend
= v
->contents
+ v
->size
;
3747 /* Default `...'. */
3748 it
->dpvec
= default_invis_vector
;
3749 it
->dpend
= default_invis_vector
+ 3;
3752 it
->dpvec_char_len
= len
;
3753 it
->current
.dpvec_index
= 0;
3754 it
->dpvec_face_id
= -1;
3756 /* Remember the current face id in case glyphs specify faces.
3757 IT's face is restored in set_iterator_to_next.
3758 saved_face_id was set to preceding char's face in handle_stop. */
3759 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3760 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3762 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3768 /***********************************************************************
3770 ***********************************************************************/
3772 /* Set up iterator IT from `display' property at its current position.
3773 Called from handle_stop.
3774 We return HANDLED_RETURN if some part of the display property
3775 overrides the display of the buffer text itself.
3776 Otherwise we return HANDLED_NORMALLY. */
3778 static enum prop_handled
3779 handle_display_prop (it
)
3782 Lisp_Object prop
, object
;
3783 struct text_pos
*position
;
3784 /* Nonzero if some property replaces the display of the text itself. */
3785 int display_replaced_p
= 0;
3787 if (STRINGP (it
->string
))
3789 object
= it
->string
;
3790 position
= &it
->current
.string_pos
;
3794 XSETWINDOW (object
, it
->w
);
3795 position
= &it
->current
.pos
;
3798 /* Reset those iterator values set from display property values. */
3799 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3800 it
->space_width
= Qnil
;
3801 it
->font_height
= Qnil
;
3804 /* We don't support recursive `display' properties, i.e. string
3805 values that have a string `display' property, that have a string
3806 `display' property etc. */
3807 if (!it
->string_from_display_prop_p
)
3808 it
->area
= TEXT_AREA
;
3810 prop
= Fget_char_property (make_number (position
->charpos
),
3813 return HANDLED_NORMALLY
;
3815 if (!STRINGP (it
->string
))
3816 object
= it
->w
->buffer
;
3819 /* Simple properties. */
3820 && !EQ (XCAR (prop
), Qimage
)
3821 && !EQ (XCAR (prop
), Qspace
)
3822 && !EQ (XCAR (prop
), Qwhen
)
3823 && !EQ (XCAR (prop
), Qslice
)
3824 && !EQ (XCAR (prop
), Qspace_width
)
3825 && !EQ (XCAR (prop
), Qheight
)
3826 && !EQ (XCAR (prop
), Qraise
)
3827 /* Marginal area specifications. */
3828 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3829 && !EQ (XCAR (prop
), Qleft_fringe
)
3830 && !EQ (XCAR (prop
), Qright_fringe
)
3831 && !NILP (XCAR (prop
)))
3833 for (; CONSP (prop
); prop
= XCDR (prop
))
3835 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3836 position
, display_replaced_p
))
3837 display_replaced_p
= 1;
3840 else if (VECTORP (prop
))
3843 for (i
= 0; i
< ASIZE (prop
); ++i
)
3844 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3845 position
, display_replaced_p
))
3846 display_replaced_p
= 1;
3850 int ret
= handle_single_display_spec (it
, prop
, object
, position
, 0);
3851 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3852 return HANDLED_RECOMPUTE_PROPS
;
3854 display_replaced_p
= 1;
3857 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3861 /* Value is the position of the end of the `display' property starting
3862 at START_POS in OBJECT. */
3864 static struct text_pos
3865 display_prop_end (it
, object
, start_pos
)
3868 struct text_pos start_pos
;
3871 struct text_pos end_pos
;
3873 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3874 Qdisplay
, object
, Qnil
);
3875 CHARPOS (end_pos
) = XFASTINT (end
);
3876 if (STRINGP (object
))
3877 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3879 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3885 /* Set up IT from a single `display' specification PROP. OBJECT
3886 is the object in which the `display' property was found. *POSITION
3887 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3888 means that we previously saw a display specification which already
3889 replaced text display with something else, for example an image;
3890 we ignore such properties after the first one has been processed.
3892 If PROP is a `space' or `image' specification, and in some other
3893 cases too, set *POSITION to the position where the `display'
3896 Value is non-zero if something was found which replaces the display
3897 of buffer or string text. Specifically, the value is -1 if that
3898 "something" is "nothing". */
3901 handle_single_display_spec (it
, spec
, object
, position
,
3902 display_replaced_before_p
)
3906 struct text_pos
*position
;
3907 int display_replaced_before_p
;
3910 Lisp_Object location
, value
;
3911 struct text_pos start_pos
, save_pos
;
3914 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3915 If the result is non-nil, use VALUE instead of SPEC. */
3917 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3926 if (!NILP (form
) && !EQ (form
, Qt
))
3928 int count
= SPECPDL_INDEX ();
3929 struct gcpro gcpro1
;
3931 /* Bind `object' to the object having the `display' property, a
3932 buffer or string. Bind `position' to the position in the
3933 object where the property was found, and `buffer-position'
3934 to the current position in the buffer. */
3935 specbind (Qobject
, object
);
3936 specbind (Qposition
, make_number (CHARPOS (*position
)));
3937 specbind (Qbuffer_position
,
3938 make_number (STRINGP (object
)
3939 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3941 form
= safe_eval (form
);
3943 unbind_to (count
, Qnil
);
3949 /* Handle `(height HEIGHT)' specifications. */
3951 && EQ (XCAR (spec
), Qheight
)
3952 && CONSP (XCDR (spec
)))
3954 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3957 it
->font_height
= XCAR (XCDR (spec
));
3958 if (!NILP (it
->font_height
))
3960 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3961 int new_height
= -1;
3963 if (CONSP (it
->font_height
)
3964 && (EQ (XCAR (it
->font_height
), Qplus
)
3965 || EQ (XCAR (it
->font_height
), Qminus
))
3966 && CONSP (XCDR (it
->font_height
))
3967 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3969 /* `(+ N)' or `(- N)' where N is an integer. */
3970 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3971 if (EQ (XCAR (it
->font_height
), Qplus
))
3973 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3975 else if (FUNCTIONP (it
->font_height
))
3977 /* Call function with current height as argument.
3978 Value is the new height. */
3980 height
= safe_call1 (it
->font_height
,
3981 face
->lface
[LFACE_HEIGHT_INDEX
]);
3982 if (NUMBERP (height
))
3983 new_height
= XFLOATINT (height
);
3985 else if (NUMBERP (it
->font_height
))
3987 /* Value is a multiple of the canonical char height. */
3990 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3991 new_height
= (XFLOATINT (it
->font_height
)
3992 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3996 /* Evaluate IT->font_height with `height' bound to the
3997 current specified height to get the new height. */
3998 int count
= SPECPDL_INDEX ();
4000 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4001 value
= safe_eval (it
->font_height
);
4002 unbind_to (count
, Qnil
);
4004 if (NUMBERP (value
))
4005 new_height
= XFLOATINT (value
);
4009 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4015 /* Handle `(space_width WIDTH)'. */
4017 && EQ (XCAR (spec
), Qspace_width
)
4018 && CONSP (XCDR (spec
)))
4020 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4023 value
= XCAR (XCDR (spec
));
4024 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4025 it
->space_width
= value
;
4030 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4032 && EQ (XCAR (spec
), Qslice
))
4036 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4039 if (tem
= XCDR (spec
), CONSP (tem
))
4041 it
->slice
.x
= XCAR (tem
);
4042 if (tem
= XCDR (tem
), CONSP (tem
))
4044 it
->slice
.y
= XCAR (tem
);
4045 if (tem
= XCDR (tem
), CONSP (tem
))
4047 it
->slice
.width
= XCAR (tem
);
4048 if (tem
= XCDR (tem
), CONSP (tem
))
4049 it
->slice
.height
= XCAR (tem
);
4057 /* Handle `(raise FACTOR)'. */
4059 && EQ (XCAR (spec
), Qraise
)
4060 && CONSP (XCDR (spec
)))
4062 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4065 #ifdef HAVE_WINDOW_SYSTEM
4066 value
= XCAR (XCDR (spec
));
4067 if (NUMBERP (value
))
4069 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4070 it
->voffset
= - (XFLOATINT (value
)
4071 * (FONT_HEIGHT (face
->font
)));
4073 #endif /* HAVE_WINDOW_SYSTEM */
4078 /* Don't handle the other kinds of display specifications
4079 inside a string that we got from a `display' property. */
4080 if (it
->string_from_display_prop_p
)
4083 /* Characters having this form of property are not displayed, so
4084 we have to find the end of the property. */
4085 start_pos
= *position
;
4086 *position
= display_prop_end (it
, object
, start_pos
);
4089 /* Stop the scan at that end position--we assume that all
4090 text properties change there. */
4091 it
->stop_charpos
= position
->charpos
;
4093 /* Handle `(left-fringe BITMAP [FACE])'
4094 and `(right-fringe BITMAP [FACE])'. */
4096 && (EQ (XCAR (spec
), Qleft_fringe
)
4097 || EQ (XCAR (spec
), Qright_fringe
))
4098 && CONSP (XCDR (spec
)))
4100 int face_id
= DEFAULT_FACE_ID
;
4103 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4104 /* If we return here, POSITION has been advanced
4105 across the text with this property. */
4108 #ifdef HAVE_WINDOW_SYSTEM
4109 value
= XCAR (XCDR (spec
));
4110 if (!SYMBOLP (value
)
4111 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4112 /* If we return here, POSITION has been advanced
4113 across the text with this property. */
4116 if (CONSP (XCDR (XCDR (spec
))))
4118 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4119 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4120 'A', FRINGE_FACE_ID
, 0);
4125 /* Save current settings of IT so that we can restore them
4126 when we are finished with the glyph property value. */
4128 save_pos
= it
->position
;
4129 it
->position
= *position
;
4131 it
->position
= save_pos
;
4133 it
->area
= TEXT_AREA
;
4134 it
->what
= IT_IMAGE
;
4135 it
->image_id
= -1; /* no image */
4136 it
->position
= start_pos
;
4137 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4138 it
->method
= GET_FROM_IMAGE
;
4139 it
->face_id
= face_id
;
4141 /* Say that we haven't consumed the characters with
4142 `display' property yet. The call to pop_it in
4143 set_iterator_to_next will clean this up. */
4144 *position
= start_pos
;
4146 if (EQ (XCAR (spec
), Qleft_fringe
))
4148 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4149 it
->left_user_fringe_face_id
= face_id
;
4153 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4154 it
->right_user_fringe_face_id
= face_id
;
4156 #endif /* HAVE_WINDOW_SYSTEM */
4160 /* Prepare to handle `((margin left-margin) ...)',
4161 `((margin right-margin) ...)' and `((margin nil) ...)'
4162 prefixes for display specifications. */
4163 location
= Qunbound
;
4164 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4168 value
= XCDR (spec
);
4170 value
= XCAR (value
);
4173 if (EQ (XCAR (tem
), Qmargin
)
4174 && (tem
= XCDR (tem
),
4175 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4177 || EQ (tem
, Qleft_margin
)
4178 || EQ (tem
, Qright_margin
))))
4182 if (EQ (location
, Qunbound
))
4188 /* After this point, VALUE is the property after any
4189 margin prefix has been stripped. It must be a string,
4190 an image specification, or `(space ...)'.
4192 LOCATION specifies where to display: `left-margin',
4193 `right-margin' or nil. */
4195 valid_p
= (STRINGP (value
)
4196 #ifdef HAVE_WINDOW_SYSTEM
4197 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
4198 #endif /* not HAVE_WINDOW_SYSTEM */
4199 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4201 if (valid_p
&& !display_replaced_before_p
)
4203 /* Save current settings of IT so that we can restore them
4204 when we are finished with the glyph property value. */
4205 save_pos
= it
->position
;
4206 it
->position
= *position
;
4208 it
->position
= save_pos
;
4210 if (NILP (location
))
4211 it
->area
= TEXT_AREA
;
4212 else if (EQ (location
, Qleft_margin
))
4213 it
->area
= LEFT_MARGIN_AREA
;
4215 it
->area
= RIGHT_MARGIN_AREA
;
4217 if (STRINGP (value
))
4219 if (SCHARS (value
) == 0)
4222 return -1; /* Replaced by "", i.e. nothing. */
4225 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4226 it
->current
.overlay_string_index
= -1;
4227 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4228 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4229 it
->method
= GET_FROM_STRING
;
4230 it
->stop_charpos
= 0;
4231 it
->string_from_display_prop_p
= 1;
4232 /* Say that we haven't consumed the characters with
4233 `display' property yet. The call to pop_it in
4234 set_iterator_to_next will clean this up. */
4235 *position
= start_pos
;
4237 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4239 it
->method
= GET_FROM_STRETCH
;
4241 *position
= it
->position
= start_pos
;
4243 #ifdef HAVE_WINDOW_SYSTEM
4246 it
->what
= IT_IMAGE
;
4247 it
->image_id
= lookup_image (it
->f
, value
);
4248 it
->position
= start_pos
;
4249 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4250 it
->method
= GET_FROM_IMAGE
;
4252 /* Say that we haven't consumed the characters with
4253 `display' property yet. The call to pop_it in
4254 set_iterator_to_next will clean this up. */
4255 *position
= start_pos
;
4257 #endif /* HAVE_WINDOW_SYSTEM */
4262 /* Invalid property or property not supported. Restore
4263 POSITION to what it was before. */
4264 *position
= start_pos
;
4269 /* Check if SPEC is a display specification value whose text should be
4270 treated as intangible. */
4273 single_display_spec_intangible_p (prop
)
4276 /* Skip over `when FORM'. */
4277 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4291 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4292 we don't need to treat text as intangible. */
4293 if (EQ (XCAR (prop
), Qmargin
))
4301 || EQ (XCAR (prop
), Qleft_margin
)
4302 || EQ (XCAR (prop
), Qright_margin
))
4306 return (CONSP (prop
)
4307 && (EQ (XCAR (prop
), Qimage
)
4308 || EQ (XCAR (prop
), Qspace
)));
4312 /* Check if PROP is a display property value whose text should be
4313 treated as intangible. */
4316 display_prop_intangible_p (prop
)
4320 && CONSP (XCAR (prop
))
4321 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4323 /* A list of sub-properties. */
4324 while (CONSP (prop
))
4326 if (single_display_spec_intangible_p (XCAR (prop
)))
4331 else if (VECTORP (prop
))
4333 /* A vector of sub-properties. */
4335 for (i
= 0; i
< ASIZE (prop
); ++i
)
4336 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4340 return single_display_spec_intangible_p (prop
);
4346 /* Return 1 if PROP is a display sub-property value containing STRING. */
4349 single_display_spec_string_p (prop
, string
)
4350 Lisp_Object prop
, string
;
4352 if (EQ (string
, prop
))
4355 /* Skip over `when FORM'. */
4356 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4365 /* Skip over `margin LOCATION'. */
4366 if (EQ (XCAR (prop
), Qmargin
))
4377 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4381 /* Return 1 if STRING appears in the `display' property PROP. */
4384 display_prop_string_p (prop
, string
)
4385 Lisp_Object prop
, string
;
4388 && CONSP (XCAR (prop
))
4389 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4391 /* A list of sub-properties. */
4392 while (CONSP (prop
))
4394 if (single_display_spec_string_p (XCAR (prop
), string
))
4399 else if (VECTORP (prop
))
4401 /* A vector of sub-properties. */
4403 for (i
= 0; i
< ASIZE (prop
); ++i
)
4404 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4408 return single_display_spec_string_p (prop
, string
);
4414 /* Determine from which buffer position in W's buffer STRING comes
4415 from. AROUND_CHARPOS is an approximate position where it could
4416 be from. Value is the buffer position or 0 if it couldn't be
4419 W's buffer must be current.
4421 This function is necessary because we don't record buffer positions
4422 in glyphs generated from strings (to keep struct glyph small).
4423 This function may only use code that doesn't eval because it is
4424 called asynchronously from note_mouse_highlight. */
4427 string_buffer_position (w
, string
, around_charpos
)
4432 Lisp_Object limit
, prop
, pos
;
4433 const int MAX_DISTANCE
= 1000;
4436 pos
= make_number (around_charpos
);
4437 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4438 while (!found
&& !EQ (pos
, limit
))
4440 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4441 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4444 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4449 pos
= make_number (around_charpos
);
4450 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4451 while (!found
&& !EQ (pos
, limit
))
4453 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4454 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4457 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4462 return found
? XINT (pos
) : 0;
4467 /***********************************************************************
4468 `composition' property
4469 ***********************************************************************/
4471 /* Set up iterator IT from `composition' property at its current
4472 position. Called from handle_stop. */
4474 static enum prop_handled
4475 handle_composition_prop (it
)
4478 Lisp_Object prop
, string
;
4479 int pos
, pos_byte
, end
;
4480 enum prop_handled handled
= HANDLED_NORMALLY
;
4482 if (STRINGP (it
->string
))
4484 pos
= IT_STRING_CHARPOS (*it
);
4485 pos_byte
= IT_STRING_BYTEPOS (*it
);
4486 string
= it
->string
;
4490 pos
= IT_CHARPOS (*it
);
4491 pos_byte
= IT_BYTEPOS (*it
);
4495 /* If there's a valid composition and point is not inside of the
4496 composition (in the case that the composition is from the current
4497 buffer), draw a glyph composed from the composition components. */
4498 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
4499 && COMPOSITION_VALID_P (pos
, end
, prop
)
4500 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
4502 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4506 struct composition
*cmp
= composition_table
[id
];
4508 if (cmp
->glyph_len
== 0)
4511 if (STRINGP (it
->string
))
4513 IT_STRING_CHARPOS (*it
) = end
;
4514 IT_STRING_BYTEPOS (*it
) = string_char_to_byte (it
->string
,
4519 IT_CHARPOS (*it
) = end
;
4520 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (end
);
4522 return HANDLED_RECOMPUTE_PROPS
;
4525 it
->stop_charpos
= end
;
4528 it
->method
= GET_FROM_COMPOSITION
;
4530 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4531 /* For a terminal, draw only the first character of the
4533 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4534 it
->len
= (STRINGP (it
->string
)
4535 ? string_char_to_byte (it
->string
, end
)
4536 : CHAR_TO_BYTE (end
)) - pos_byte
;
4537 handled
= HANDLED_RETURN
;
4546 /***********************************************************************
4548 ***********************************************************************/
4550 /* The following structure is used to record overlay strings for
4551 later sorting in load_overlay_strings. */
4553 struct overlay_entry
4555 Lisp_Object overlay
;
4562 /* Set up iterator IT from overlay strings at its current position.
4563 Called from handle_stop. */
4565 static enum prop_handled
4566 handle_overlay_change (it
)
4569 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4570 return HANDLED_RECOMPUTE_PROPS
;
4572 return HANDLED_NORMALLY
;
4576 /* Set up the next overlay string for delivery by IT, if there is an
4577 overlay string to deliver. Called by set_iterator_to_next when the
4578 end of the current overlay string is reached. If there are more
4579 overlay strings to display, IT->string and
4580 IT->current.overlay_string_index are set appropriately here.
4581 Otherwise IT->string is set to nil. */
4584 next_overlay_string (it
)
4587 ++it
->current
.overlay_string_index
;
4588 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4590 /* No more overlay strings. Restore IT's settings to what
4591 they were before overlay strings were processed, and
4592 continue to deliver from current_buffer. */
4593 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4597 || it
->method
== GET_FROM_COMPOSITION
4598 || (NILP (it
->string
)
4599 && it
->method
== GET_FROM_BUFFER
4600 && it
->stop_charpos
>= BEGV
4601 && it
->stop_charpos
<= it
->end_charpos
));
4602 it
->current
.overlay_string_index
= -1;
4603 it
->n_overlay_strings
= 0;
4605 /* If we're at the end of the buffer, record that we have
4606 processed the overlay strings there already, so that
4607 next_element_from_buffer doesn't try it again. */
4608 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4609 it
->overlay_strings_at_end_processed_p
= 1;
4611 /* If we have to display `...' for invisible text, set
4612 the iterator up for that. */
4613 if (display_ellipsis_p
)
4614 setup_for_ellipsis (it
, 0);
4618 /* There are more overlay strings to process. If
4619 IT->current.overlay_string_index has advanced to a position
4620 where we must load IT->overlay_strings with more strings, do
4622 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4624 if (it
->current
.overlay_string_index
&& i
== 0)
4625 load_overlay_strings (it
, 0);
4627 /* Initialize IT to deliver display elements from the overlay
4629 it
->string
= it
->overlay_strings
[i
];
4630 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4631 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4632 it
->method
= GET_FROM_STRING
;
4633 it
->stop_charpos
= 0;
4640 /* Compare two overlay_entry structures E1 and E2. Used as a
4641 comparison function for qsort in load_overlay_strings. Overlay
4642 strings for the same position are sorted so that
4644 1. All after-strings come in front of before-strings, except
4645 when they come from the same overlay.
4647 2. Within after-strings, strings are sorted so that overlay strings
4648 from overlays with higher priorities come first.
4650 2. Within before-strings, strings are sorted so that overlay
4651 strings from overlays with higher priorities come last.
4653 Value is analogous to strcmp. */
4657 compare_overlay_entries (e1
, e2
)
4660 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4661 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4664 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4666 /* Let after-strings appear in front of before-strings if
4667 they come from different overlays. */
4668 if (EQ (entry1
->overlay
, entry2
->overlay
))
4669 result
= entry1
->after_string_p
? 1 : -1;
4671 result
= entry1
->after_string_p
? -1 : 1;
4673 else if (entry1
->after_string_p
)
4674 /* After-strings sorted in order of decreasing priority. */
4675 result
= entry2
->priority
- entry1
->priority
;
4677 /* Before-strings sorted in order of increasing priority. */
4678 result
= entry1
->priority
- entry2
->priority
;
4684 /* Load the vector IT->overlay_strings with overlay strings from IT's
4685 current buffer position, or from CHARPOS if that is > 0. Set
4686 IT->n_overlays to the total number of overlay strings found.
4688 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4689 a time. On entry into load_overlay_strings,
4690 IT->current.overlay_string_index gives the number of overlay
4691 strings that have already been loaded by previous calls to this
4694 IT->add_overlay_start contains an additional overlay start
4695 position to consider for taking overlay strings from, if non-zero.
4696 This position comes into play when the overlay has an `invisible'
4697 property, and both before and after-strings. When we've skipped to
4698 the end of the overlay, because of its `invisible' property, we
4699 nevertheless want its before-string to appear.
4700 IT->add_overlay_start will contain the overlay start position
4703 Overlay strings are sorted so that after-string strings come in
4704 front of before-string strings. Within before and after-strings,
4705 strings are sorted by overlay priority. See also function
4706 compare_overlay_entries. */
4709 load_overlay_strings (it
, charpos
)
4713 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4714 Lisp_Object overlay
, window
, str
, invisible
;
4715 struct Lisp_Overlay
*ov
;
4718 int n
= 0, i
, j
, invis_p
;
4719 struct overlay_entry
*entries
4720 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4723 charpos
= IT_CHARPOS (*it
);
4725 /* Append the overlay string STRING of overlay OVERLAY to vector
4726 `entries' which has size `size' and currently contains `n'
4727 elements. AFTER_P non-zero means STRING is an after-string of
4729 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4732 Lisp_Object priority; \
4736 int new_size = 2 * size; \
4737 struct overlay_entry *old = entries; \
4739 (struct overlay_entry *) alloca (new_size \
4740 * sizeof *entries); \
4741 bcopy (old, entries, size * sizeof *entries); \
4745 entries[n].string = (STRING); \
4746 entries[n].overlay = (OVERLAY); \
4747 priority = Foverlay_get ((OVERLAY), Qpriority); \
4748 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4749 entries[n].after_string_p = (AFTER_P); \
4754 /* Process overlay before the overlay center. */
4755 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4757 XSETMISC (overlay
, ov
);
4758 xassert (OVERLAYP (overlay
));
4759 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4760 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4765 /* Skip this overlay if it doesn't start or end at IT's current
4767 if (end
!= charpos
&& start
!= charpos
)
4770 /* Skip this overlay if it doesn't apply to IT->w. */
4771 window
= Foverlay_get (overlay
, Qwindow
);
4772 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4775 /* If the text ``under'' the overlay is invisible, both before-
4776 and after-strings from this overlay are visible; start and
4777 end position are indistinguishable. */
4778 invisible
= Foverlay_get (overlay
, Qinvisible
);
4779 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4781 /* If overlay has a non-empty before-string, record it. */
4782 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4783 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4785 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4787 /* If overlay has a non-empty after-string, record it. */
4788 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4789 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4791 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4794 /* Process overlays after the overlay center. */
4795 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4797 XSETMISC (overlay
, ov
);
4798 xassert (OVERLAYP (overlay
));
4799 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4800 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4802 if (start
> charpos
)
4805 /* Skip this overlay if it doesn't start or end at IT's current
4807 if (end
!= charpos
&& start
!= charpos
)
4810 /* Skip this overlay if it doesn't apply to IT->w. */
4811 window
= Foverlay_get (overlay
, Qwindow
);
4812 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4815 /* If the text ``under'' the overlay is invisible, it has a zero
4816 dimension, and both before- and after-strings apply. */
4817 invisible
= Foverlay_get (overlay
, Qinvisible
);
4818 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4820 /* If overlay has a non-empty before-string, record it. */
4821 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4822 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4824 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4826 /* If overlay has a non-empty after-string, record it. */
4827 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4828 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4830 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4833 #undef RECORD_OVERLAY_STRING
4837 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4839 /* Record the total number of strings to process. */
4840 it
->n_overlay_strings
= n
;
4842 /* IT->current.overlay_string_index is the number of overlay strings
4843 that have already been consumed by IT. Copy some of the
4844 remaining overlay strings to IT->overlay_strings. */
4846 j
= it
->current
.overlay_string_index
;
4847 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4848 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4854 /* Get the first chunk of overlay strings at IT's current buffer
4855 position, or at CHARPOS if that is > 0. Value is non-zero if at
4856 least one overlay string was found. */
4859 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
4863 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4864 process. This fills IT->overlay_strings with strings, and sets
4865 IT->n_overlay_strings to the total number of strings to process.
4866 IT->pos.overlay_string_index has to be set temporarily to zero
4867 because load_overlay_strings needs this; it must be set to -1
4868 when no overlay strings are found because a zero value would
4869 indicate a position in the first overlay string. */
4870 it
->current
.overlay_string_index
= 0;
4871 load_overlay_strings (it
, charpos
);
4873 /* If we found overlay strings, set up IT to deliver display
4874 elements from the first one. Otherwise set up IT to deliver
4875 from current_buffer. */
4876 if (it
->n_overlay_strings
)
4878 /* Make sure we know settings in current_buffer, so that we can
4879 restore meaningful values when we're done with the overlay
4882 compute_stop_pos (it
);
4883 xassert (it
->face_id
>= 0);
4885 /* Save IT's settings. They are restored after all overlay
4886 strings have been processed. */
4887 xassert (!compute_stop_p
|| it
->sp
== 0);
4890 /* Set up IT to deliver display elements from the first overlay
4892 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4893 it
->string
= it
->overlay_strings
[0];
4894 it
->stop_charpos
= 0;
4895 xassert (STRINGP (it
->string
));
4896 it
->end_charpos
= SCHARS (it
->string
);
4897 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4898 it
->method
= GET_FROM_STRING
;
4902 it
->current
.overlay_string_index
= -1;
4907 get_overlay_strings (it
, charpos
)
4912 it
->method
= GET_FROM_BUFFER
;
4914 (void) get_overlay_strings_1 (it
, charpos
, 1);
4918 /* Value is non-zero if we found at least one overlay string. */
4919 return STRINGP (it
->string
);
4924 /***********************************************************************
4925 Saving and restoring state
4926 ***********************************************************************/
4928 /* Save current settings of IT on IT->stack. Called, for example,
4929 before setting up IT for an overlay string, to be able to restore
4930 IT's settings to what they were after the overlay string has been
4937 struct iterator_stack_entry
*p
;
4939 xassert (it
->sp
< IT_STACK_SIZE
);
4940 p
= it
->stack
+ it
->sp
;
4942 p
->stop_charpos
= it
->stop_charpos
;
4943 xassert (it
->face_id
>= 0);
4944 p
->face_id
= it
->face_id
;
4945 p
->string
= it
->string
;
4946 p
->method
= it
->method
;
4949 case GET_FROM_IMAGE
:
4950 p
->u
.image
.object
= it
->object
;
4951 p
->u
.image
.image_id
= it
->image_id
;
4952 p
->u
.image
.slice
= it
->slice
;
4954 case GET_FROM_COMPOSITION
:
4955 p
->u
.comp
.object
= it
->object
;
4956 p
->u
.comp
.c
= it
->c
;
4957 p
->u
.comp
.len
= it
->len
;
4958 p
->u
.comp
.cmp_id
= it
->cmp_id
;
4959 p
->u
.comp
.cmp_len
= it
->cmp_len
;
4961 case GET_FROM_STRETCH
:
4962 p
->u
.stretch
.object
= it
->object
;
4965 p
->position
= it
->position
;
4966 p
->current
= it
->current
;
4967 p
->end_charpos
= it
->end_charpos
;
4968 p
->string_nchars
= it
->string_nchars
;
4970 p
->multibyte_p
= it
->multibyte_p
;
4971 p
->space_width
= it
->space_width
;
4972 p
->font_height
= it
->font_height
;
4973 p
->voffset
= it
->voffset
;
4974 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4975 p
->display_ellipsis_p
= 0;
4980 /* Restore IT's settings from IT->stack. Called, for example, when no
4981 more overlay strings must be processed, and we return to delivering
4982 display elements from a buffer, or when the end of a string from a
4983 `display' property is reached and we return to delivering display
4984 elements from an overlay string, or from a buffer. */
4990 struct iterator_stack_entry
*p
;
4992 xassert (it
->sp
> 0);
4994 p
= it
->stack
+ it
->sp
;
4995 it
->stop_charpos
= p
->stop_charpos
;
4996 it
->face_id
= p
->face_id
;
4997 it
->current
= p
->current
;
4998 it
->position
= p
->position
;
4999 it
->string
= p
->string
;
5000 if (NILP (it
->string
))
5001 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5002 it
->method
= p
->method
;
5005 case GET_FROM_IMAGE
:
5006 it
->image_id
= p
->u
.image
.image_id
;
5007 it
->object
= p
->u
.image
.object
;
5008 it
->slice
= p
->u
.image
.slice
;
5010 case GET_FROM_COMPOSITION
:
5011 it
->object
= p
->u
.comp
.object
;
5012 it
->c
= p
->u
.comp
.c
;
5013 it
->len
= p
->u
.comp
.len
;
5014 it
->cmp_id
= p
->u
.comp
.cmp_id
;
5015 it
->cmp_len
= p
->u
.comp
.cmp_len
;
5017 case GET_FROM_STRETCH
:
5018 it
->object
= p
->u
.comp
.object
;
5020 case GET_FROM_BUFFER
:
5021 it
->object
= it
->w
->buffer
;
5023 case GET_FROM_STRING
:
5024 it
->object
= it
->string
;
5027 it
->end_charpos
= p
->end_charpos
;
5028 it
->string_nchars
= p
->string_nchars
;
5030 it
->multibyte_p
= p
->multibyte_p
;
5031 it
->space_width
= p
->space_width
;
5032 it
->font_height
= p
->font_height
;
5033 it
->voffset
= p
->voffset
;
5034 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5039 /***********************************************************************
5041 ***********************************************************************/
5043 /* Set IT's current position to the previous line start. */
5046 back_to_previous_line_start (it
)
5049 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5050 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5054 /* Move IT to the next line start.
5056 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5057 we skipped over part of the text (as opposed to moving the iterator
5058 continuously over the text). Otherwise, don't change the value
5061 Newlines may come from buffer text, overlay strings, or strings
5062 displayed via the `display' property. That's the reason we can't
5063 simply use find_next_newline_no_quit.
5065 Note that this function may not skip over invisible text that is so
5066 because of text properties and immediately follows a newline. If
5067 it would, function reseat_at_next_visible_line_start, when called
5068 from set_iterator_to_next, would effectively make invisible
5069 characters following a newline part of the wrong glyph row, which
5070 leads to wrong cursor motion. */
5073 forward_to_next_line_start (it
, skipped_p
)
5077 int old_selective
, newline_found_p
, n
;
5078 const int MAX_NEWLINE_DISTANCE
= 500;
5080 /* If already on a newline, just consume it to avoid unintended
5081 skipping over invisible text below. */
5082 if (it
->what
== IT_CHARACTER
5084 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5086 set_iterator_to_next (it
, 0);
5091 /* Don't handle selective display in the following. It's (a)
5092 unnecessary because it's done by the caller, and (b) leads to an
5093 infinite recursion because next_element_from_ellipsis indirectly
5094 calls this function. */
5095 old_selective
= it
->selective
;
5098 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5099 from buffer text. */
5100 for (n
= newline_found_p
= 0;
5101 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5102 n
+= STRINGP (it
->string
) ? 0 : 1)
5104 if (!get_next_display_element (it
))
5106 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5107 set_iterator_to_next (it
, 0);
5110 /* If we didn't find a newline near enough, see if we can use a
5112 if (!newline_found_p
)
5114 int start
= IT_CHARPOS (*it
);
5115 int limit
= find_next_newline_no_quit (start
, 1);
5118 xassert (!STRINGP (it
->string
));
5120 /* If there isn't any `display' property in sight, and no
5121 overlays, we can just use the position of the newline in
5123 if (it
->stop_charpos
>= limit
5124 || ((pos
= Fnext_single_property_change (make_number (start
),
5126 Qnil
, make_number (limit
)),
5128 && next_overlay_change (start
) == ZV
))
5130 IT_CHARPOS (*it
) = limit
;
5131 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5132 *skipped_p
= newline_found_p
= 1;
5136 while (get_next_display_element (it
)
5137 && !newline_found_p
)
5139 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5140 set_iterator_to_next (it
, 0);
5145 it
->selective
= old_selective
;
5146 return newline_found_p
;
5150 /* Set IT's current position to the previous visible line start. Skip
5151 invisible text that is so either due to text properties or due to
5152 selective display. Caution: this does not change IT->current_x and
5156 back_to_previous_visible_line_start (it
)
5159 while (IT_CHARPOS (*it
) > BEGV
)
5161 back_to_previous_line_start (it
);
5163 if (IT_CHARPOS (*it
) <= BEGV
)
5166 /* If selective > 0, then lines indented more than that values
5168 if (it
->selective
> 0
5169 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5170 (double) it
->selective
)) /* iftc */
5173 /* Check the newline before point for invisibility. */
5176 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5177 Qinvisible
, it
->window
);
5178 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5182 if (IT_CHARPOS (*it
) <= BEGV
)
5189 Lisp_Object val
, overlay
;
5191 /* If newline is part of a composition, continue from start of composition */
5192 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5193 && beg
< IT_CHARPOS (*it
))
5196 /* If newline is replaced by a display property, find start of overlay
5197 or interval and continue search from that point. */
5199 pos
= --IT_CHARPOS (it2
);
5202 if (handle_display_prop (&it2
) == HANDLED_RETURN
5203 && !NILP (val
= get_char_property_and_overlay
5204 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5205 && (OVERLAYP (overlay
)
5206 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5207 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5210 /* Newline is not replaced by anything -- so we are done. */
5216 IT_CHARPOS (*it
) = beg
;
5217 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5221 it
->continuation_lines_width
= 0;
5223 xassert (IT_CHARPOS (*it
) >= BEGV
);
5224 xassert (IT_CHARPOS (*it
) == BEGV
5225 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5230 /* Reseat iterator IT at the previous visible line start. Skip
5231 invisible text that is so either due to text properties or due to
5232 selective display. At the end, update IT's overlay information,
5233 face information etc. */
5236 reseat_at_previous_visible_line_start (it
)
5239 back_to_previous_visible_line_start (it
);
5240 reseat (it
, it
->current
.pos
, 1);
5245 /* Reseat iterator IT on the next visible line start in the current
5246 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5247 preceding the line start. Skip over invisible text that is so
5248 because of selective display. Compute faces, overlays etc at the
5249 new position. Note that this function does not skip over text that
5250 is invisible because of text properties. */
5253 reseat_at_next_visible_line_start (it
, on_newline_p
)
5257 int newline_found_p
, skipped_p
= 0;
5259 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5261 /* Skip over lines that are invisible because they are indented
5262 more than the value of IT->selective. */
5263 if (it
->selective
> 0)
5264 while (IT_CHARPOS (*it
) < ZV
5265 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5266 (double) it
->selective
)) /* iftc */
5268 xassert (IT_BYTEPOS (*it
) == BEGV
5269 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5270 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5273 /* Position on the newline if that's what's requested. */
5274 if (on_newline_p
&& newline_found_p
)
5276 if (STRINGP (it
->string
))
5278 if (IT_STRING_CHARPOS (*it
) > 0)
5280 --IT_STRING_CHARPOS (*it
);
5281 --IT_STRING_BYTEPOS (*it
);
5284 else if (IT_CHARPOS (*it
) > BEGV
)
5288 reseat (it
, it
->current
.pos
, 0);
5292 reseat (it
, it
->current
.pos
, 0);
5299 /***********************************************************************
5300 Changing an iterator's position
5301 ***********************************************************************/
5303 /* Change IT's current position to POS in current_buffer. If FORCE_P
5304 is non-zero, always check for text properties at the new position.
5305 Otherwise, text properties are only looked up if POS >=
5306 IT->check_charpos of a property. */
5309 reseat (it
, pos
, force_p
)
5311 struct text_pos pos
;
5314 int original_pos
= IT_CHARPOS (*it
);
5316 reseat_1 (it
, pos
, 0);
5318 /* Determine where to check text properties. Avoid doing it
5319 where possible because text property lookup is very expensive. */
5321 || CHARPOS (pos
) > it
->stop_charpos
5322 || CHARPOS (pos
) < original_pos
)
5329 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5330 IT->stop_pos to POS, also. */
5333 reseat_1 (it
, pos
, set_stop_p
)
5335 struct text_pos pos
;
5338 /* Don't call this function when scanning a C string. */
5339 xassert (it
->s
== NULL
);
5341 /* POS must be a reasonable value. */
5342 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5344 it
->current
.pos
= it
->position
= pos
;
5345 it
->end_charpos
= ZV
;
5347 it
->current
.dpvec_index
= -1;
5348 it
->current
.overlay_string_index
= -1;
5349 IT_STRING_CHARPOS (*it
) = -1;
5350 IT_STRING_BYTEPOS (*it
) = -1;
5352 it
->method
= GET_FROM_BUFFER
;
5353 it
->object
= it
->w
->buffer
;
5354 it
->area
= TEXT_AREA
;
5355 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5357 it
->string_from_display_prop_p
= 0;
5358 it
->face_before_selective_p
= 0;
5361 it
->stop_charpos
= CHARPOS (pos
);
5365 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5366 If S is non-null, it is a C string to iterate over. Otherwise,
5367 STRING gives a Lisp string to iterate over.
5369 If PRECISION > 0, don't return more then PRECISION number of
5370 characters from the string.
5372 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5373 characters have been returned. FIELD_WIDTH < 0 means an infinite
5376 MULTIBYTE = 0 means disable processing of multibyte characters,
5377 MULTIBYTE > 0 means enable it,
5378 MULTIBYTE < 0 means use IT->multibyte_p.
5380 IT must be initialized via a prior call to init_iterator before
5381 calling this function. */
5384 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5389 int precision
, field_width
, multibyte
;
5391 /* No region in strings. */
5392 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5394 /* No text property checks performed by default, but see below. */
5395 it
->stop_charpos
= -1;
5397 /* Set iterator position and end position. */
5398 bzero (&it
->current
, sizeof it
->current
);
5399 it
->current
.overlay_string_index
= -1;
5400 it
->current
.dpvec_index
= -1;
5401 xassert (charpos
>= 0);
5403 /* If STRING is specified, use its multibyteness, otherwise use the
5404 setting of MULTIBYTE, if specified. */
5406 it
->multibyte_p
= multibyte
> 0;
5410 xassert (STRINGP (string
));
5411 it
->string
= string
;
5413 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5414 it
->method
= GET_FROM_STRING
;
5415 it
->current
.string_pos
= string_pos (charpos
, string
);
5422 /* Note that we use IT->current.pos, not it->current.string_pos,
5423 for displaying C strings. */
5424 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5425 if (it
->multibyte_p
)
5427 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5428 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5432 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5433 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5436 it
->method
= GET_FROM_C_STRING
;
5439 /* PRECISION > 0 means don't return more than PRECISION characters
5441 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5442 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5444 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5445 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5446 FIELD_WIDTH < 0 means infinite field width. This is useful for
5447 padding with `-' at the end of a mode line. */
5448 if (field_width
< 0)
5449 field_width
= INFINITY
;
5450 if (field_width
> it
->end_charpos
- charpos
)
5451 it
->end_charpos
= charpos
+ field_width
;
5453 /* Use the standard display table for displaying strings. */
5454 if (DISP_TABLE_P (Vstandard_display_table
))
5455 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5457 it
->stop_charpos
= charpos
;
5463 /***********************************************************************
5465 ***********************************************************************/
5467 /* Map enum it_method value to corresponding next_element_from_* function. */
5469 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5471 next_element_from_buffer
,
5472 next_element_from_display_vector
,
5473 next_element_from_composition
,
5474 next_element_from_string
,
5475 next_element_from_c_string
,
5476 next_element_from_image
,
5477 next_element_from_stretch
5481 /* Load IT's display element fields with information about the next
5482 display element from the current position of IT. Value is zero if
5483 end of buffer (or C string) is reached. */
5485 static struct frame
*last_escape_glyph_frame
= NULL
;
5486 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5487 static int last_escape_glyph_merged_face_id
= 0;
5490 get_next_display_element (it
)
5493 /* Non-zero means that we found a display element. Zero means that
5494 we hit the end of what we iterate over. Performance note: the
5495 function pointer `method' used here turns out to be faster than
5496 using a sequence of if-statements. */
5500 success_p
= (*get_next_element
[it
->method
]) (it
);
5502 if (it
->what
== IT_CHARACTER
)
5504 /* Map via display table or translate control characters.
5505 IT->c, IT->len etc. have been set to the next character by
5506 the function call above. If we have a display table, and it
5507 contains an entry for IT->c, translate it. Don't do this if
5508 IT->c itself comes from a display table, otherwise we could
5509 end up in an infinite recursion. (An alternative could be to
5510 count the recursion depth of this function and signal an
5511 error when a certain maximum depth is reached.) Is it worth
5513 if (success_p
&& it
->dpvec
== NULL
)
5518 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5521 struct Lisp_Vector
*v
= XVECTOR (dv
);
5523 /* Return the first character from the display table
5524 entry, if not empty. If empty, don't display the
5525 current character. */
5528 it
->dpvec_char_len
= it
->len
;
5529 it
->dpvec
= v
->contents
;
5530 it
->dpend
= v
->contents
+ v
->size
;
5531 it
->current
.dpvec_index
= 0;
5532 it
->dpvec_face_id
= -1;
5533 it
->saved_face_id
= it
->face_id
;
5534 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5539 set_iterator_to_next (it
, 0);
5544 /* Translate control characters into `\003' or `^C' form.
5545 Control characters coming from a display table entry are
5546 currently not translated because we use IT->dpvec to hold
5547 the translation. This could easily be changed but I
5548 don't believe that it is worth doing.
5550 If it->multibyte_p is nonzero, eight-bit characters and
5551 non-printable multibyte characters are also translated to
5554 If it->multibyte_p is zero, eight-bit characters that
5555 don't have corresponding multibyte char code are also
5556 translated to octal form. */
5557 else if ((it
->c
< ' '
5558 && (it
->area
!= TEXT_AREA
5559 /* In mode line, treat \n like other crl chars. */
5561 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5562 || (it
->c
!= '\n' && it
->c
!= '\t')))
5566 || !CHAR_PRINTABLE_P (it
->c
)
5567 || (!NILP (Vnobreak_char_display
)
5568 && (it
->c
== 0x8a0 || it
->c
== 0x8ad
5569 || it
->c
== 0x920 || it
->c
== 0x92d
5570 || it
->c
== 0xe20 || it
->c
== 0xe2d
5571 || it
->c
== 0xf20 || it
->c
== 0xf2d)))
5573 && (!unibyte_display_via_language_environment
5574 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
5576 /* IT->c is a control character which must be displayed
5577 either as '\003' or as `^C' where the '\\' and '^'
5578 can be defined in the display table. Fill
5579 IT->ctl_chars with glyphs for what we have to
5580 display. Then, set IT->dpvec to these glyphs. */
5583 int face_id
, lface_id
= 0 ;
5586 /* Handle control characters with ^. */
5588 if (it
->c
< 128 && it
->ctl_arrow_p
)
5590 g
= '^'; /* default glyph for Control */
5591 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5593 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5594 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5596 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5597 lface_id
= FAST_GLYPH_FACE (g
);
5601 g
= FAST_GLYPH_CHAR (g
);
5602 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5605 else if (it
->f
== last_escape_glyph_frame
5606 && it
->face_id
== last_escape_glyph_face_id
)
5608 face_id
= last_escape_glyph_merged_face_id
;
5612 /* Merge the escape-glyph face into the current face. */
5613 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5615 last_escape_glyph_frame
= it
->f
;
5616 last_escape_glyph_face_id
= it
->face_id
;
5617 last_escape_glyph_merged_face_id
= face_id
;
5620 XSETINT (it
->ctl_chars
[0], g
);
5622 XSETINT (it
->ctl_chars
[1], g
);
5624 goto display_control
;
5627 /* Handle non-break space in the mode where it only gets
5630 if (EQ (Vnobreak_char_display
, Qt
)
5631 && (it
->c
== 0x8a0 || it
->c
== 0x920
5632 || it
->c
== 0xe20 || it
->c
== 0xf20))
5634 /* Merge the no-break-space face into the current face. */
5635 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5639 XSETINT (it
->ctl_chars
[0], g
);
5641 goto display_control
;
5644 /* Handle sequences that start with the "escape glyph". */
5646 /* the default escape glyph is \. */
5647 escape_glyph
= '\\';
5650 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5651 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5653 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5654 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5658 /* The display table specified a face.
5659 Merge it into face_id and also into escape_glyph. */
5660 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5661 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5664 else if (it
->f
== last_escape_glyph_frame
5665 && it
->face_id
== last_escape_glyph_face_id
)
5667 face_id
= last_escape_glyph_merged_face_id
;
5671 /* Merge the escape-glyph face into the current face. */
5672 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5674 last_escape_glyph_frame
= it
->f
;
5675 last_escape_glyph_face_id
= it
->face_id
;
5676 last_escape_glyph_merged_face_id
= face_id
;
5679 /* Handle soft hyphens in the mode where they only get
5682 if (EQ (Vnobreak_char_display
, Qt
)
5683 && (it
->c
== 0x8ad || it
->c
== 0x92d
5684 || it
->c
== 0xe2d || it
->c
== 0xf2d))
5687 XSETINT (it
->ctl_chars
[0], g
);
5689 goto display_control
;
5692 /* Handle non-break space and soft hyphen
5693 with the escape glyph. */
5695 if (it
->c
== 0x8a0 || it
->c
== 0x8ad
5696 || it
->c
== 0x920 || it
->c
== 0x92d
5697 || it
->c
== 0xe20 || it
->c
== 0xe2d
5698 || it
->c
== 0xf20 || it
->c
== 0xf2d)
5700 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5701 g
= it
->c
= ((it
->c
& 0xf) == 0 ? ' ' : '-');
5702 XSETINT (it
->ctl_chars
[1], g
);
5704 goto display_control
;
5708 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5712 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5713 if (SINGLE_BYTE_CHAR_P (it
->c
))
5714 str
[0] = it
->c
, len
= 1;
5717 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5720 /* It's an invalid character, which shouldn't
5721 happen actually, but due to bugs it may
5722 happen. Let's print the char as is, there's
5723 not much meaningful we can do with it. */
5725 str
[1] = it
->c
>> 8;
5726 str
[2] = it
->c
>> 16;
5727 str
[3] = it
->c
>> 24;
5732 for (i
= 0; i
< len
; i
++)
5734 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5735 /* Insert three more glyphs into IT->ctl_chars for
5736 the octal display of the character. */
5737 g
= ((str
[i
] >> 6) & 7) + '0';
5738 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5739 g
= ((str
[i
] >> 3) & 7) + '0';
5740 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5741 g
= (str
[i
] & 7) + '0';
5742 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5748 /* Set up IT->dpvec and return first character from it. */
5749 it
->dpvec_char_len
= it
->len
;
5750 it
->dpvec
= it
->ctl_chars
;
5751 it
->dpend
= it
->dpvec
+ ctl_len
;
5752 it
->current
.dpvec_index
= 0;
5753 it
->dpvec_face_id
= face_id
;
5754 it
->saved_face_id
= it
->face_id
;
5755 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5761 /* Adjust face id for a multibyte character. There are no
5762 multibyte character in unibyte text. */
5765 && FRAME_WINDOW_P (it
->f
))
5767 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5768 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5772 /* Is this character the last one of a run of characters with
5773 box? If yes, set IT->end_of_box_run_p to 1. */
5780 it
->end_of_box_run_p
5781 = ((face_id
= face_after_it_pos (it
),
5782 face_id
!= it
->face_id
)
5783 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5784 face
->box
== FACE_NO_BOX
));
5787 /* Value is 0 if end of buffer or string reached. */
5792 /* Move IT to the next display element.
5794 RESEAT_P non-zero means if called on a newline in buffer text,
5795 skip to the next visible line start.
5797 Functions get_next_display_element and set_iterator_to_next are
5798 separate because I find this arrangement easier to handle than a
5799 get_next_display_element function that also increments IT's
5800 position. The way it is we can first look at an iterator's current
5801 display element, decide whether it fits on a line, and if it does,
5802 increment the iterator position. The other way around we probably
5803 would either need a flag indicating whether the iterator has to be
5804 incremented the next time, or we would have to implement a
5805 decrement position function which would not be easy to write. */
5808 set_iterator_to_next (it
, reseat_p
)
5812 /* Reset flags indicating start and end of a sequence of characters
5813 with box. Reset them at the start of this function because
5814 moving the iterator to a new position might set them. */
5815 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5819 case GET_FROM_BUFFER
:
5820 /* The current display element of IT is a character from
5821 current_buffer. Advance in the buffer, and maybe skip over
5822 invisible lines that are so because of selective display. */
5823 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5824 reseat_at_next_visible_line_start (it
, 0);
5827 xassert (it
->len
!= 0);
5828 IT_BYTEPOS (*it
) += it
->len
;
5829 IT_CHARPOS (*it
) += 1;
5830 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5834 case GET_FROM_COMPOSITION
:
5835 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5836 xassert (it
->sp
> 0);
5838 if (it
->method
== GET_FROM_STRING
)
5840 IT_STRING_BYTEPOS (*it
) += it
->len
;
5841 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5842 goto consider_string_end
;
5844 else if (it
->method
== GET_FROM_BUFFER
)
5846 IT_BYTEPOS (*it
) += it
->len
;
5847 IT_CHARPOS (*it
) += it
->cmp_len
;
5851 case GET_FROM_C_STRING
:
5852 /* Current display element of IT is from a C string. */
5853 IT_BYTEPOS (*it
) += it
->len
;
5854 IT_CHARPOS (*it
) += 1;
5857 case GET_FROM_DISPLAY_VECTOR
:
5858 /* Current display element of IT is from a display table entry.
5859 Advance in the display table definition. Reset it to null if
5860 end reached, and continue with characters from buffers/
5862 ++it
->current
.dpvec_index
;
5864 /* Restore face of the iterator to what they were before the
5865 display vector entry (these entries may contain faces). */
5866 it
->face_id
= it
->saved_face_id
;
5868 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5870 int recheck_faces
= it
->ellipsis_p
;
5873 it
->method
= GET_FROM_C_STRING
;
5874 else if (STRINGP (it
->string
))
5875 it
->method
= GET_FROM_STRING
;
5878 it
->method
= GET_FROM_BUFFER
;
5879 it
->object
= it
->w
->buffer
;
5883 it
->current
.dpvec_index
= -1;
5885 /* Skip over characters which were displayed via IT->dpvec. */
5886 if (it
->dpvec_char_len
< 0)
5887 reseat_at_next_visible_line_start (it
, 1);
5888 else if (it
->dpvec_char_len
> 0)
5890 if (it
->method
== GET_FROM_STRING
5891 && it
->n_overlay_strings
> 0)
5892 it
->ignore_overlay_strings_at_pos_p
= 1;
5893 it
->len
= it
->dpvec_char_len
;
5894 set_iterator_to_next (it
, reseat_p
);
5897 /* Maybe recheck faces after display vector */
5899 it
->stop_charpos
= IT_CHARPOS (*it
);
5903 case GET_FROM_STRING
:
5904 /* Current display element is a character from a Lisp string. */
5905 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5906 IT_STRING_BYTEPOS (*it
) += it
->len
;
5907 IT_STRING_CHARPOS (*it
) += 1;
5909 consider_string_end
:
5911 if (it
->current
.overlay_string_index
>= 0)
5913 /* IT->string is an overlay string. Advance to the
5914 next, if there is one. */
5915 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5916 next_overlay_string (it
);
5920 /* IT->string is not an overlay string. If we reached
5921 its end, and there is something on IT->stack, proceed
5922 with what is on the stack. This can be either another
5923 string, this time an overlay string, or a buffer. */
5924 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5928 if (it
->method
== GET_FROM_STRING
)
5929 goto consider_string_end
;
5934 case GET_FROM_IMAGE
:
5935 case GET_FROM_STRETCH
:
5936 /* The position etc with which we have to proceed are on
5937 the stack. The position may be at the end of a string,
5938 if the `display' property takes up the whole string. */
5939 xassert (it
->sp
> 0);
5941 if (it
->method
== GET_FROM_STRING
)
5942 goto consider_string_end
;
5946 /* There are no other methods defined, so this should be a bug. */
5950 xassert (it
->method
!= GET_FROM_STRING
5951 || (STRINGP (it
->string
)
5952 && IT_STRING_CHARPOS (*it
) >= 0));
5955 /* Load IT's display element fields with information about the next
5956 display element which comes from a display table entry or from the
5957 result of translating a control character to one of the forms `^C'
5960 IT->dpvec holds the glyphs to return as characters.
5961 IT->saved_face_id holds the face id before the display vector--
5962 it is restored into IT->face_idin set_iterator_to_next. */
5965 next_element_from_display_vector (it
)
5969 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5971 it
->face_id
= it
->saved_face_id
;
5973 if (INTEGERP (*it
->dpvec
)
5974 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5978 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5979 it
->c
= FAST_GLYPH_CHAR (g
);
5980 it
->len
= CHAR_BYTES (it
->c
);
5982 /* The entry may contain a face id to use. Such a face id is
5983 the id of a Lisp face, not a realized face. A face id of
5984 zero means no face is specified. */
5985 if (it
->dpvec_face_id
>= 0)
5986 it
->face_id
= it
->dpvec_face_id
;
5989 int lface_id
= FAST_GLYPH_FACE (g
);
5991 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5996 /* Display table entry is invalid. Return a space. */
5997 it
->c
= ' ', it
->len
= 1;
5999 /* Don't change position and object of the iterator here. They are
6000 still the values of the character that had this display table
6001 entry or was translated, and that's what we want. */
6002 it
->what
= IT_CHARACTER
;
6007 /* Load IT with the next display element from Lisp string IT->string.
6008 IT->current.string_pos is the current position within the string.
6009 If IT->current.overlay_string_index >= 0, the Lisp string is an
6013 next_element_from_string (it
)
6016 struct text_pos position
;
6018 xassert (STRINGP (it
->string
));
6019 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6020 position
= it
->current
.string_pos
;
6022 /* Time to check for invisible text? */
6023 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6024 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6028 /* Since a handler may have changed IT->method, we must
6030 return get_next_display_element (it
);
6033 if (it
->current
.overlay_string_index
>= 0)
6035 /* Get the next character from an overlay string. In overlay
6036 strings, There is no field width or padding with spaces to
6038 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6043 else if (STRING_MULTIBYTE (it
->string
))
6045 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6046 const unsigned char *s
= (SDATA (it
->string
)
6047 + IT_STRING_BYTEPOS (*it
));
6048 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
6052 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6058 /* Get the next character from a Lisp string that is not an
6059 overlay string. Such strings come from the mode line, for
6060 example. We may have to pad with spaces, or truncate the
6061 string. See also next_element_from_c_string. */
6062 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6067 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6069 /* Pad with spaces. */
6070 it
->c
= ' ', it
->len
= 1;
6071 CHARPOS (position
) = BYTEPOS (position
) = -1;
6073 else if (STRING_MULTIBYTE (it
->string
))
6075 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6076 const unsigned char *s
= (SDATA (it
->string
)
6077 + IT_STRING_BYTEPOS (*it
));
6078 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
6082 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6087 /* Record what we have and where it came from. */
6088 it
->what
= IT_CHARACTER
;
6089 it
->object
= it
->string
;
6090 it
->position
= position
;
6095 /* Load IT with next display element from C string IT->s.
6096 IT->string_nchars is the maximum number of characters to return
6097 from the string. IT->end_charpos may be greater than
6098 IT->string_nchars when this function is called, in which case we
6099 may have to return padding spaces. Value is zero if end of string
6100 reached, including padding spaces. */
6103 next_element_from_c_string (it
)
6109 it
->what
= IT_CHARACTER
;
6110 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6113 /* IT's position can be greater IT->string_nchars in case a field
6114 width or precision has been specified when the iterator was
6116 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6118 /* End of the game. */
6122 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6124 /* Pad with spaces. */
6125 it
->c
= ' ', it
->len
= 1;
6126 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6128 else if (it
->multibyte_p
)
6130 /* Implementation note: The calls to strlen apparently aren't a
6131 performance problem because there is no noticeable performance
6132 difference between Emacs running in unibyte or multibyte mode. */
6133 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6134 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
6138 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6144 /* Set up IT to return characters from an ellipsis, if appropriate.
6145 The definition of the ellipsis glyphs may come from a display table
6146 entry. This function Fills IT with the first glyph from the
6147 ellipsis if an ellipsis is to be displayed. */
6150 next_element_from_ellipsis (it
)
6153 if (it
->selective_display_ellipsis_p
)
6154 setup_for_ellipsis (it
, it
->len
);
6157 /* The face at the current position may be different from the
6158 face we find after the invisible text. Remember what it
6159 was in IT->saved_face_id, and signal that it's there by
6160 setting face_before_selective_p. */
6161 it
->saved_face_id
= it
->face_id
;
6162 it
->method
= GET_FROM_BUFFER
;
6163 it
->object
= it
->w
->buffer
;
6164 reseat_at_next_visible_line_start (it
, 1);
6165 it
->face_before_selective_p
= 1;
6168 return get_next_display_element (it
);
6172 /* Deliver an image display element. The iterator IT is already
6173 filled with image information (done in handle_display_prop). Value
6178 next_element_from_image (it
)
6181 it
->what
= IT_IMAGE
;
6186 /* Fill iterator IT with next display element from a stretch glyph
6187 property. IT->object is the value of the text property. Value is
6191 next_element_from_stretch (it
)
6194 it
->what
= IT_STRETCH
;
6199 /* Load IT with the next display element from current_buffer. Value
6200 is zero if end of buffer reached. IT->stop_charpos is the next
6201 position at which to stop and check for text properties or buffer
6205 next_element_from_buffer (it
)
6210 /* Check this assumption, otherwise, we would never enter the
6211 if-statement, below. */
6212 xassert (IT_CHARPOS (*it
) >= BEGV
6213 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
6215 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6217 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6219 int overlay_strings_follow_p
;
6221 /* End of the game, except when overlay strings follow that
6222 haven't been returned yet. */
6223 if (it
->overlay_strings_at_end_processed_p
)
6224 overlay_strings_follow_p
= 0;
6227 it
->overlay_strings_at_end_processed_p
= 1;
6228 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6231 if (overlay_strings_follow_p
)
6232 success_p
= get_next_display_element (it
);
6236 it
->position
= it
->current
.pos
;
6243 return get_next_display_element (it
);
6248 /* No face changes, overlays etc. in sight, so just return a
6249 character from current_buffer. */
6252 /* Maybe run the redisplay end trigger hook. Performance note:
6253 This doesn't seem to cost measurable time. */
6254 if (it
->redisplay_end_trigger_charpos
6256 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6257 run_redisplay_end_trigger_hook (it
);
6259 /* Get the next character, maybe multibyte. */
6260 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6261 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6263 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
6264 - IT_BYTEPOS (*it
));
6265 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
6268 it
->c
= *p
, it
->len
= 1;
6270 /* Record what we have and where it came from. */
6271 it
->what
= IT_CHARACTER
;;
6272 it
->object
= it
->w
->buffer
;
6273 it
->position
= it
->current
.pos
;
6275 /* Normally we return the character found above, except when we
6276 really want to return an ellipsis for selective display. */
6281 /* A value of selective > 0 means hide lines indented more
6282 than that number of columns. */
6283 if (it
->selective
> 0
6284 && IT_CHARPOS (*it
) + 1 < ZV
6285 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6286 IT_BYTEPOS (*it
) + 1,
6287 (double) it
->selective
)) /* iftc */
6289 success_p
= next_element_from_ellipsis (it
);
6290 it
->dpvec_char_len
= -1;
6293 else if (it
->c
== '\r' && it
->selective
== -1)
6295 /* A value of selective == -1 means that everything from the
6296 CR to the end of the line is invisible, with maybe an
6297 ellipsis displayed for it. */
6298 success_p
= next_element_from_ellipsis (it
);
6299 it
->dpvec_char_len
= -1;
6304 /* Value is zero if end of buffer reached. */
6305 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6310 /* Run the redisplay end trigger hook for IT. */
6313 run_redisplay_end_trigger_hook (it
)
6316 Lisp_Object args
[3];
6318 /* IT->glyph_row should be non-null, i.e. we should be actually
6319 displaying something, or otherwise we should not run the hook. */
6320 xassert (it
->glyph_row
);
6322 /* Set up hook arguments. */
6323 args
[0] = Qredisplay_end_trigger_functions
;
6324 args
[1] = it
->window
;
6325 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6326 it
->redisplay_end_trigger_charpos
= 0;
6328 /* Since we are *trying* to run these functions, don't try to run
6329 them again, even if they get an error. */
6330 it
->w
->redisplay_end_trigger
= Qnil
;
6331 Frun_hook_with_args (3, args
);
6333 /* Notice if it changed the face of the character we are on. */
6334 handle_face_prop (it
);
6338 /* Deliver a composition display element. The iterator IT is already
6339 filled with composition information (done in
6340 handle_composition_prop). Value is always 1. */
6343 next_element_from_composition (it
)
6346 it
->what
= IT_COMPOSITION
;
6347 it
->position
= (STRINGP (it
->string
)
6348 ? it
->current
.string_pos
6350 if (STRINGP (it
->string
))
6351 it
->object
= it
->string
;
6353 it
->object
= it
->w
->buffer
;
6359 /***********************************************************************
6360 Moving an iterator without producing glyphs
6361 ***********************************************************************/
6363 /* Check if iterator is at a position corresponding to a valid buffer
6364 position after some move_it_ call. */
6366 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6367 ((it)->method == GET_FROM_STRING \
6368 ? IT_STRING_CHARPOS (*it) == 0 \
6372 /* Move iterator IT to a specified buffer or X position within one
6373 line on the display without producing glyphs.
6375 OP should be a bit mask including some or all of these bits:
6376 MOVE_TO_X: Stop on reaching x-position TO_X.
6377 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6378 Regardless of OP's value, stop in reaching the end of the display line.
6380 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6381 This means, in particular, that TO_X includes window's horizontal
6384 The return value has several possible values that
6385 say what condition caused the scan to stop:
6387 MOVE_POS_MATCH_OR_ZV
6388 - when TO_POS or ZV was reached.
6391 -when TO_X was reached before TO_POS or ZV were reached.
6394 - when we reached the end of the display area and the line must
6398 - when we reached the end of the display area and the line is
6402 - when we stopped at a line end, i.e. a newline or a CR and selective
6405 static enum move_it_result
6406 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
6408 int to_charpos
, to_x
, op
;
6410 enum move_it_result result
= MOVE_UNDEFINED
;
6411 struct glyph_row
*saved_glyph_row
;
6413 /* Don't produce glyphs in produce_glyphs. */
6414 saved_glyph_row
= it
->glyph_row
;
6415 it
->glyph_row
= NULL
;
6417 #define BUFFER_POS_REACHED_P() \
6418 ((op & MOVE_TO_POS) != 0 \
6419 && BUFFERP (it->object) \
6420 && IT_CHARPOS (*it) >= to_charpos \
6421 && (it->method == GET_FROM_BUFFER \
6422 || (it->method == GET_FROM_DISPLAY_VECTOR \
6423 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6428 int x
, i
, ascent
= 0, descent
= 0;
6430 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
6431 if ((op
& MOVE_TO_POS
) != 0
6432 && BUFFERP (it
->object
)
6433 && it
->method
== GET_FROM_BUFFER
6434 && IT_CHARPOS (*it
) > to_charpos
)
6436 result
= MOVE_POS_MATCH_OR_ZV
;
6440 /* Stop when ZV reached.
6441 We used to stop here when TO_CHARPOS reached as well, but that is
6442 too soon if this glyph does not fit on this line. So we handle it
6443 explicitly below. */
6444 if (!get_next_display_element (it
)
6445 || (it
->truncate_lines_p
6446 && BUFFER_POS_REACHED_P ()))
6448 result
= MOVE_POS_MATCH_OR_ZV
;
6452 /* The call to produce_glyphs will get the metrics of the
6453 display element IT is loaded with. We record in x the
6454 x-position before this display element in case it does not
6458 /* Remember the line height so far in case the next element doesn't
6460 if (!it
->truncate_lines_p
)
6462 ascent
= it
->max_ascent
;
6463 descent
= it
->max_descent
;
6466 PRODUCE_GLYPHS (it
);
6468 if (it
->area
!= TEXT_AREA
)
6470 set_iterator_to_next (it
, 1);
6474 /* The number of glyphs we get back in IT->nglyphs will normally
6475 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6476 character on a terminal frame, or (iii) a line end. For the
6477 second case, IT->nglyphs - 1 padding glyphs will be present
6478 (on X frames, there is only one glyph produced for a
6479 composite character.
6481 The behavior implemented below means, for continuation lines,
6482 that as many spaces of a TAB as fit on the current line are
6483 displayed there. For terminal frames, as many glyphs of a
6484 multi-glyph character are displayed in the current line, too.
6485 This is what the old redisplay code did, and we keep it that
6486 way. Under X, the whole shape of a complex character must
6487 fit on the line or it will be completely displayed in the
6490 Note that both for tabs and padding glyphs, all glyphs have
6494 /* More than one glyph or glyph doesn't fit on line. All
6495 glyphs have the same width. */
6496 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6498 int x_before_this_char
= x
;
6499 int hpos_before_this_char
= it
->hpos
;
6501 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6503 new_x
= x
+ single_glyph_width
;
6505 /* We want to leave anything reaching TO_X to the caller. */
6506 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6508 if (BUFFER_POS_REACHED_P ())
6509 goto buffer_pos_reached
;
6511 result
= MOVE_X_REACHED
;
6514 else if (/* Lines are continued. */
6515 !it
->truncate_lines_p
6516 && (/* And glyph doesn't fit on the line. */
6517 new_x
> it
->last_visible_x
6518 /* Or it fits exactly and we're on a window
6520 || (new_x
== it
->last_visible_x
6521 && FRAME_WINDOW_P (it
->f
))))
6523 if (/* IT->hpos == 0 means the very first glyph
6524 doesn't fit on the line, e.g. a wide image. */
6526 || (new_x
== it
->last_visible_x
6527 && FRAME_WINDOW_P (it
->f
)))
6530 it
->current_x
= new_x
;
6532 /* The character's last glyph just barely fits
6534 if (i
== it
->nglyphs
- 1)
6536 /* If this is the destination position,
6537 return a position *before* it in this row,
6538 now that we know it fits in this row. */
6539 if (BUFFER_POS_REACHED_P ())
6541 it
->hpos
= hpos_before_this_char
;
6542 it
->current_x
= x_before_this_char
;
6543 result
= MOVE_POS_MATCH_OR_ZV
;
6547 set_iterator_to_next (it
, 1);
6548 #ifdef HAVE_WINDOW_SYSTEM
6549 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6551 if (!get_next_display_element (it
))
6553 result
= MOVE_POS_MATCH_OR_ZV
;
6556 if (BUFFER_POS_REACHED_P ())
6558 if (ITERATOR_AT_END_OF_LINE_P (it
))
6559 result
= MOVE_POS_MATCH_OR_ZV
;
6561 result
= MOVE_LINE_CONTINUED
;
6564 if (ITERATOR_AT_END_OF_LINE_P (it
))
6566 result
= MOVE_NEWLINE_OR_CR
;
6570 #endif /* HAVE_WINDOW_SYSTEM */
6576 it
->max_ascent
= ascent
;
6577 it
->max_descent
= descent
;
6580 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6582 result
= MOVE_LINE_CONTINUED
;
6585 else if (BUFFER_POS_REACHED_P ())
6586 goto buffer_pos_reached
;
6587 else if (new_x
> it
->first_visible_x
)
6589 /* Glyph is visible. Increment number of glyphs that
6590 would be displayed. */
6595 /* Glyph is completely off the left margin of the display
6596 area. Nothing to do. */
6600 if (result
!= MOVE_UNDEFINED
)
6603 else if (BUFFER_POS_REACHED_P ())
6607 it
->max_ascent
= ascent
;
6608 it
->max_descent
= descent
;
6609 result
= MOVE_POS_MATCH_OR_ZV
;
6612 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6614 /* Stop when TO_X specified and reached. This check is
6615 necessary here because of lines consisting of a line end,
6616 only. The line end will not produce any glyphs and we
6617 would never get MOVE_X_REACHED. */
6618 xassert (it
->nglyphs
== 0);
6619 result
= MOVE_X_REACHED
;
6623 /* Is this a line end? If yes, we're done. */
6624 if (ITERATOR_AT_END_OF_LINE_P (it
))
6626 result
= MOVE_NEWLINE_OR_CR
;
6630 /* The current display element has been consumed. Advance
6632 set_iterator_to_next (it
, 1);
6634 /* Stop if lines are truncated and IT's current x-position is
6635 past the right edge of the window now. */
6636 if (it
->truncate_lines_p
6637 && it
->current_x
>= it
->last_visible_x
)
6639 #ifdef HAVE_WINDOW_SYSTEM
6640 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6642 if (!get_next_display_element (it
)
6643 || BUFFER_POS_REACHED_P ())
6645 result
= MOVE_POS_MATCH_OR_ZV
;
6648 if (ITERATOR_AT_END_OF_LINE_P (it
))
6650 result
= MOVE_NEWLINE_OR_CR
;
6654 #endif /* HAVE_WINDOW_SYSTEM */
6655 result
= MOVE_LINE_TRUNCATED
;
6660 #undef BUFFER_POS_REACHED_P
6662 /* Restore the iterator settings altered at the beginning of this
6664 it
->glyph_row
= saved_glyph_row
;
6669 /* Move IT forward until it satisfies one or more of the criteria in
6670 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6672 OP is a bit-mask that specifies where to stop, and in particular,
6673 which of those four position arguments makes a difference. See the
6674 description of enum move_operation_enum.
6676 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6677 screen line, this function will set IT to the next position >
6681 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6683 int to_charpos
, to_x
, to_y
, to_vpos
;
6686 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6692 if (op
& MOVE_TO_VPOS
)
6694 /* If no TO_CHARPOS and no TO_X specified, stop at the
6695 start of the line TO_VPOS. */
6696 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6698 if (it
->vpos
== to_vpos
)
6704 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6708 /* TO_VPOS >= 0 means stop at TO_X in the line at
6709 TO_VPOS, or at TO_POS, whichever comes first. */
6710 if (it
->vpos
== to_vpos
)
6716 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6718 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6723 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6725 /* We have reached TO_X but not in the line we want. */
6726 skip
= move_it_in_display_line_to (it
, to_charpos
,
6728 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6736 else if (op
& MOVE_TO_Y
)
6738 struct it it_backup
;
6740 /* TO_Y specified means stop at TO_X in the line containing
6741 TO_Y---or at TO_CHARPOS if this is reached first. The
6742 problem is that we can't really tell whether the line
6743 contains TO_Y before we have completely scanned it, and
6744 this may skip past TO_X. What we do is to first scan to
6747 If TO_X is not specified, use a TO_X of zero. The reason
6748 is to make the outcome of this function more predictable.
6749 If we didn't use TO_X == 0, we would stop at the end of
6750 the line which is probably not what a caller would expect
6752 skip
= move_it_in_display_line_to (it
, to_charpos
,
6756 | (op
& MOVE_TO_POS
)));
6758 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6759 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6765 /* If TO_X was reached, we would like to know whether TO_Y
6766 is in the line. This can only be said if we know the
6767 total line height which requires us to scan the rest of
6769 if (skip
== MOVE_X_REACHED
)
6772 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6773 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6775 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6778 /* Now, decide whether TO_Y is in this line. */
6779 line_height
= it
->max_ascent
+ it
->max_descent
;
6780 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6782 if (to_y
>= it
->current_y
6783 && to_y
< it
->current_y
+ line_height
)
6785 if (skip
== MOVE_X_REACHED
)
6786 /* If TO_Y is in this line and TO_X was reached above,
6787 we scanned too far. We have to restore IT's settings
6788 to the ones before skipping. */
6792 else if (skip
== MOVE_X_REACHED
)
6795 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6802 else if (BUFFERP (it
->object
)
6803 && it
->method
== GET_FROM_BUFFER
6804 && IT_CHARPOS (*it
) >= to_charpos
)
6805 skip
= MOVE_POS_MATCH_OR_ZV
;
6807 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6811 case MOVE_POS_MATCH_OR_ZV
:
6815 case MOVE_NEWLINE_OR_CR
:
6816 set_iterator_to_next (it
, 1);
6817 it
->continuation_lines_width
= 0;
6820 case MOVE_LINE_TRUNCATED
:
6821 it
->continuation_lines_width
= 0;
6822 reseat_at_next_visible_line_start (it
, 0);
6823 if ((op
& MOVE_TO_POS
) != 0
6824 && IT_CHARPOS (*it
) > to_charpos
)
6831 case MOVE_LINE_CONTINUED
:
6832 it
->continuation_lines_width
+= it
->current_x
;
6839 /* Reset/increment for the next run. */
6840 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6841 it
->current_x
= it
->hpos
= 0;
6842 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6844 last_height
= it
->max_ascent
+ it
->max_descent
;
6845 last_max_ascent
= it
->max_ascent
;
6846 it
->max_ascent
= it
->max_descent
= 0;
6851 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6855 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6857 If DY > 0, move IT backward at least that many pixels. DY = 0
6858 means move IT backward to the preceding line start or BEGV. This
6859 function may move over more than DY pixels if IT->current_y - DY
6860 ends up in the middle of a line; in this case IT->current_y will be
6861 set to the top of the line moved to. */
6864 move_it_vertically_backward (it
, dy
)
6875 start_pos
= IT_CHARPOS (*it
);
6877 /* Estimate how many newlines we must move back. */
6878 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6880 /* Set the iterator's position that many lines back. */
6881 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6882 back_to_previous_visible_line_start (it
);
6884 /* Reseat the iterator here. When moving backward, we don't want
6885 reseat to skip forward over invisible text, set up the iterator
6886 to deliver from overlay strings at the new position etc. So,
6887 use reseat_1 here. */
6888 reseat_1 (it
, it
->current
.pos
, 1);
6890 /* We are now surely at a line start. */
6891 it
->current_x
= it
->hpos
= 0;
6892 it
->continuation_lines_width
= 0;
6894 /* Move forward and see what y-distance we moved. First move to the
6895 start of the next line so that we get its height. We need this
6896 height to be able to tell whether we reached the specified
6899 it2
.max_ascent
= it2
.max_descent
= 0;
6902 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6903 MOVE_TO_POS
| MOVE_TO_VPOS
);
6905 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
6906 xassert (IT_CHARPOS (*it
) >= BEGV
);
6909 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6910 xassert (IT_CHARPOS (*it
) >= BEGV
);
6911 /* H is the actual vertical distance from the position in *IT
6912 and the starting position. */
6913 h
= it2
.current_y
- it
->current_y
;
6914 /* NLINES is the distance in number of lines. */
6915 nlines
= it2
.vpos
- it
->vpos
;
6917 /* Correct IT's y and vpos position
6918 so that they are relative to the starting point. */
6924 /* DY == 0 means move to the start of the screen line. The
6925 value of nlines is > 0 if continuation lines were involved. */
6927 move_it_by_lines (it
, nlines
, 1);
6929 /* I think this assert is bogus if buffer contains
6930 invisible text or images. KFS. */
6931 xassert (IT_CHARPOS (*it
) <= start_pos
);
6936 /* The y-position we try to reach, relative to *IT.
6937 Note that H has been subtracted in front of the if-statement. */
6938 int target_y
= it
->current_y
+ h
- dy
;
6939 int y0
= it3
.current_y
;
6940 int y1
= line_bottom_y (&it3
);
6941 int line_height
= y1
- y0
;
6943 /* If we did not reach target_y, try to move further backward if
6944 we can. If we moved too far backward, try to move forward. */
6945 if (target_y
< it
->current_y
6946 /* This is heuristic. In a window that's 3 lines high, with
6947 a line height of 13 pixels each, recentering with point
6948 on the bottom line will try to move -39/2 = 19 pixels
6949 backward. Try to avoid moving into the first line. */
6950 && (it
->current_y
- target_y
6951 > min (window_box_height (it
->w
), line_height
* 2 / 3))
6952 && IT_CHARPOS (*it
) > BEGV
)
6954 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6955 target_y
- it
->current_y
));
6956 dy
= it
->current_y
- target_y
;
6957 goto move_further_back
;
6959 else if (target_y
>= it
->current_y
+ line_height
6960 && IT_CHARPOS (*it
) < ZV
)
6962 /* Should move forward by at least one line, maybe more.
6964 Note: Calling move_it_by_lines can be expensive on
6965 terminal frames, where compute_motion is used (via
6966 vmotion) to do the job, when there are very long lines
6967 and truncate-lines is nil. That's the reason for
6968 treating terminal frames specially here. */
6970 if (!FRAME_WINDOW_P (it
->f
))
6971 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6976 move_it_by_lines (it
, 1, 1);
6978 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6982 /* I think this assert is bogus if buffer contains
6983 invisible text or images. KFS. */
6984 xassert (IT_CHARPOS (*it
) >= BEGV
);
6991 /* Move IT by a specified amount of pixel lines DY. DY negative means
6992 move backwards. DY = 0 means move to start of screen line. At the
6993 end, IT will be on the start of a screen line. */
6996 move_it_vertically (it
, dy
)
7001 move_it_vertically_backward (it
, -dy
);
7004 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7005 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7006 MOVE_TO_POS
| MOVE_TO_Y
);
7007 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7009 /* If buffer ends in ZV without a newline, move to the start of
7010 the line to satisfy the post-condition. */
7011 if (IT_CHARPOS (*it
) == ZV
7013 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7014 move_it_by_lines (it
, 0, 0);
7019 /* Move iterator IT past the end of the text line it is in. */
7022 move_it_past_eol (it
)
7025 enum move_it_result rc
;
7027 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7028 if (rc
== MOVE_NEWLINE_OR_CR
)
7029 set_iterator_to_next (it
, 0);
7033 #if 0 /* Currently not used. */
7035 /* Return non-zero if some text between buffer positions START_CHARPOS
7036 and END_CHARPOS is invisible. IT->window is the window for text
7040 invisible_text_between_p (it
, start_charpos
, end_charpos
)
7042 int start_charpos
, end_charpos
;
7044 Lisp_Object prop
, limit
;
7045 int invisible_found_p
;
7047 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
7049 /* Is text at START invisible? */
7050 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
7052 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
7053 invisible_found_p
= 1;
7056 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
7058 make_number (end_charpos
));
7059 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
7062 return invisible_found_p
;
7068 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7069 negative means move up. DVPOS == 0 means move to the start of the
7070 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7071 NEED_Y_P is zero, IT->current_y will be left unchanged.
7073 Further optimization ideas: If we would know that IT->f doesn't use
7074 a face with proportional font, we could be faster for
7075 truncate-lines nil. */
7078 move_it_by_lines (it
, dvpos
, need_y_p
)
7080 int dvpos
, need_y_p
;
7082 struct position pos
;
7084 if (!FRAME_WINDOW_P (it
->f
))
7086 struct text_pos textpos
;
7088 /* We can use vmotion on frames without proportional fonts. */
7089 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
7090 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
7091 reseat (it
, textpos
, 1);
7092 it
->vpos
+= pos
.vpos
;
7093 it
->current_y
+= pos
.vpos
;
7095 else if (dvpos
== 0)
7097 /* DVPOS == 0 means move to the start of the screen line. */
7098 move_it_vertically_backward (it
, 0);
7099 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7100 /* Let next call to line_bottom_y calculate real line height */
7105 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7106 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7107 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7112 int start_charpos
, i
;
7114 /* Start at the beginning of the screen line containing IT's
7115 position. This may actually move vertically backwards,
7116 in case of overlays, so adjust dvpos accordingly. */
7118 move_it_vertically_backward (it
, 0);
7121 /* Go back -DVPOS visible lines and reseat the iterator there. */
7122 start_charpos
= IT_CHARPOS (*it
);
7123 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7124 back_to_previous_visible_line_start (it
);
7125 reseat (it
, it
->current
.pos
, 1);
7127 /* Move further back if we end up in a string or an image. */
7128 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7130 /* First try to move to start of display line. */
7132 move_it_vertically_backward (it
, 0);
7134 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7136 /* If start of line is still in string or image,
7137 move further back. */
7138 back_to_previous_visible_line_start (it
);
7139 reseat (it
, it
->current
.pos
, 1);
7143 it
->current_x
= it
->hpos
= 0;
7145 /* Above call may have moved too far if continuation lines
7146 are involved. Scan forward and see if it did. */
7148 it2
.vpos
= it2
.current_y
= 0;
7149 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7150 it
->vpos
-= it2
.vpos
;
7151 it
->current_y
-= it2
.current_y
;
7152 it
->current_x
= it
->hpos
= 0;
7154 /* If we moved too far back, move IT some lines forward. */
7155 if (it2
.vpos
> -dvpos
)
7157 int delta
= it2
.vpos
+ dvpos
;
7159 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7160 /* Move back again if we got too far ahead. */
7161 if (IT_CHARPOS (*it
) >= start_charpos
)
7167 /* Return 1 if IT points into the middle of a display vector. */
7170 in_display_vector_p (it
)
7173 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7174 && it
->current
.dpvec_index
> 0
7175 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7179 /***********************************************************************
7181 ***********************************************************************/
7184 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7188 add_to_log (format
, arg1
, arg2
)
7190 Lisp_Object arg1
, arg2
;
7192 Lisp_Object args
[3];
7193 Lisp_Object msg
, fmt
;
7196 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7199 /* Do nothing if called asynchronously. Inserting text into
7200 a buffer may call after-change-functions and alike and
7201 that would means running Lisp asynchronously. */
7202 if (handling_signal
)
7206 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7208 args
[0] = fmt
= build_string (format
);
7211 msg
= Fformat (3, args
);
7213 len
= SBYTES (msg
) + 1;
7214 SAFE_ALLOCA (buffer
, char *, len
);
7215 bcopy (SDATA (msg
), buffer
, len
);
7217 message_dolog (buffer
, len
- 1, 1, 0);
7224 /* Output a newline in the *Messages* buffer if "needs" one. */
7227 message_log_maybe_newline ()
7229 if (message_log_need_newline
)
7230 message_dolog ("", 0, 1, 0);
7234 /* Add a string M of length NBYTES to the message log, optionally
7235 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7236 nonzero, means interpret the contents of M as multibyte. This
7237 function calls low-level routines in order to bypass text property
7238 hooks, etc. which might not be safe to run.
7240 This may GC (insert may run before/after change hooks),
7241 so the buffer M must NOT point to a Lisp string. */
7244 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7246 int nbytes
, nlflag
, multibyte
;
7248 if (!NILP (Vmemory_full
))
7251 if (!NILP (Vmessage_log_max
))
7253 struct buffer
*oldbuf
;
7254 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7255 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7256 int point_at_end
= 0;
7258 Lisp_Object old_deactivate_mark
, tem
;
7259 struct gcpro gcpro1
;
7261 old_deactivate_mark
= Vdeactivate_mark
;
7262 oldbuf
= current_buffer
;
7263 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7264 current_buffer
->undo_list
= Qt
;
7266 oldpoint
= message_dolog_marker1
;
7267 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7268 oldbegv
= message_dolog_marker2
;
7269 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7270 oldzv
= message_dolog_marker3
;
7271 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7272 GCPRO1 (old_deactivate_mark
);
7280 BEGV_BYTE
= BEG_BYTE
;
7283 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7285 /* Insert the string--maybe converting multibyte to single byte
7286 or vice versa, so that all the text fits the buffer. */
7288 && NILP (current_buffer
->enable_multibyte_characters
))
7290 int i
, c
, char_bytes
;
7291 unsigned char work
[1];
7293 /* Convert a multibyte string to single-byte
7294 for the *Message* buffer. */
7295 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7297 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7298 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7300 : multibyte_char_to_unibyte (c
, Qnil
));
7301 insert_1_both (work
, 1, 1, 1, 0, 0);
7304 else if (! multibyte
7305 && ! NILP (current_buffer
->enable_multibyte_characters
))
7307 int i
, c
, char_bytes
;
7308 unsigned char *msg
= (unsigned char *) m
;
7309 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7310 /* Convert a single-byte string to multibyte
7311 for the *Message* buffer. */
7312 for (i
= 0; i
< nbytes
; i
++)
7314 c
= unibyte_char_to_multibyte (msg
[i
]);
7315 char_bytes
= CHAR_STRING (c
, str
);
7316 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7320 insert_1 (m
, nbytes
, 1, 0, 0);
7324 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7325 insert_1 ("\n", 1, 1, 0, 0);
7327 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7329 this_bol_byte
= PT_BYTE
;
7331 /* See if this line duplicates the previous one.
7332 If so, combine duplicates. */
7335 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7337 prev_bol_byte
= PT_BYTE
;
7339 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7340 this_bol
, this_bol_byte
);
7343 del_range_both (prev_bol
, prev_bol_byte
,
7344 this_bol
, this_bol_byte
, 0);
7350 /* If you change this format, don't forget to also
7351 change message_log_check_duplicate. */
7352 sprintf (dupstr
, " [%d times]", dup
);
7353 duplen
= strlen (dupstr
);
7354 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7355 insert_1 (dupstr
, duplen
, 1, 0, 1);
7360 /* If we have more than the desired maximum number of lines
7361 in the *Messages* buffer now, delete the oldest ones.
7362 This is safe because we don't have undo in this buffer. */
7364 if (NATNUMP (Vmessage_log_max
))
7366 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7367 -XFASTINT (Vmessage_log_max
) - 1, 0);
7368 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7371 BEGV
= XMARKER (oldbegv
)->charpos
;
7372 BEGV_BYTE
= marker_byte_position (oldbegv
);
7381 ZV
= XMARKER (oldzv
)->charpos
;
7382 ZV_BYTE
= marker_byte_position (oldzv
);
7386 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7388 /* We can't do Fgoto_char (oldpoint) because it will run some
7390 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7391 XMARKER (oldpoint
)->bytepos
);
7394 unchain_marker (XMARKER (oldpoint
));
7395 unchain_marker (XMARKER (oldbegv
));
7396 unchain_marker (XMARKER (oldzv
));
7398 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7399 set_buffer_internal (oldbuf
);
7401 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7402 message_log_need_newline
= !nlflag
;
7403 Vdeactivate_mark
= old_deactivate_mark
;
7408 /* We are at the end of the buffer after just having inserted a newline.
7409 (Note: We depend on the fact we won't be crossing the gap.)
7410 Check to see if the most recent message looks a lot like the previous one.
7411 Return 0 if different, 1 if the new one should just replace it, or a
7412 value N > 1 if we should also append " [N times]". */
7415 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7416 int prev_bol
, this_bol
;
7417 int prev_bol_byte
, this_bol_byte
;
7420 int len
= Z_BYTE
- 1 - this_bol_byte
;
7422 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7423 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7425 for (i
= 0; i
< len
; i
++)
7427 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7435 if (*p1
++ == ' ' && *p1
++ == '[')
7438 while (*p1
>= '0' && *p1
<= '9')
7439 n
= n
* 10 + *p1
++ - '0';
7440 if (strncmp (p1
, " times]\n", 8) == 0)
7447 /* Display an echo area message M with a specified length of NBYTES
7448 bytes. The string may include null characters. If M is 0, clear
7449 out any existing message, and let the mini-buffer text show
7452 This may GC, so the buffer M must NOT point to a Lisp string. */
7455 message2 (m
, nbytes
, multibyte
)
7460 /* First flush out any partial line written with print. */
7461 message_log_maybe_newline ();
7463 message_dolog (m
, nbytes
, 1, multibyte
);
7464 message2_nolog (m
, nbytes
, multibyte
);
7468 /* The non-logging counterpart of message2. */
7471 message2_nolog (m
, nbytes
, multibyte
)
7473 int nbytes
, multibyte
;
7475 struct frame
*sf
= SELECTED_FRAME ();
7476 message_enable_multibyte
= multibyte
;
7480 if (noninteractive_need_newline
)
7481 putc ('\n', stderr
);
7482 noninteractive_need_newline
= 0;
7484 fwrite (m
, nbytes
, 1, stderr
);
7485 if (cursor_in_echo_area
== 0)
7486 fprintf (stderr
, "\n");
7489 /* A null message buffer means that the frame hasn't really been
7490 initialized yet. Error messages get reported properly by
7491 cmd_error, so this must be just an informative message; toss it. */
7492 else if (INTERACTIVE
7493 && sf
->glyphs_initialized_p
7494 && FRAME_MESSAGE_BUF (sf
))
7496 Lisp_Object mini_window
;
7499 /* Get the frame containing the mini-buffer
7500 that the selected frame is using. */
7501 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7502 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7504 FRAME_SAMPLE_VISIBILITY (f
);
7505 if (FRAME_VISIBLE_P (sf
)
7506 && ! FRAME_VISIBLE_P (f
))
7507 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7511 set_message (m
, Qnil
, nbytes
, multibyte
);
7512 if (minibuffer_auto_raise
)
7513 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7516 clear_message (1, 1);
7518 do_pending_window_change (0);
7519 echo_area_display (1);
7520 do_pending_window_change (0);
7521 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7522 (*frame_up_to_date_hook
) (f
);
7527 /* Display an echo area message M with a specified length of NBYTES
7528 bytes. The string may include null characters. If M is not a
7529 string, clear out any existing message, and let the mini-buffer
7532 This function cancels echoing. */
7535 message3 (m
, nbytes
, multibyte
)
7540 struct gcpro gcpro1
;
7543 clear_message (1,1);
7546 /* First flush out any partial line written with print. */
7547 message_log_maybe_newline ();
7553 SAFE_ALLOCA (buffer
, char *, nbytes
);
7554 bcopy (SDATA (m
), buffer
, nbytes
);
7555 message_dolog (buffer
, nbytes
, 1, multibyte
);
7558 message3_nolog (m
, nbytes
, multibyte
);
7564 /* The non-logging version of message3.
7565 This does not cancel echoing, because it is used for echoing.
7566 Perhaps we need to make a separate function for echoing
7567 and make this cancel echoing. */
7570 message3_nolog (m
, nbytes
, multibyte
)
7572 int nbytes
, multibyte
;
7574 struct frame
*sf
= SELECTED_FRAME ();
7575 message_enable_multibyte
= multibyte
;
7579 if (noninteractive_need_newline
)
7580 putc ('\n', stderr
);
7581 noninteractive_need_newline
= 0;
7583 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7584 if (cursor_in_echo_area
== 0)
7585 fprintf (stderr
, "\n");
7588 /* A null message buffer means that the frame hasn't really been
7589 initialized yet. Error messages get reported properly by
7590 cmd_error, so this must be just an informative message; toss it. */
7591 else if (INTERACTIVE
7592 && sf
->glyphs_initialized_p
7593 && FRAME_MESSAGE_BUF (sf
))
7595 Lisp_Object mini_window
;
7599 /* Get the frame containing the mini-buffer
7600 that the selected frame is using. */
7601 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7602 frame
= XWINDOW (mini_window
)->frame
;
7605 FRAME_SAMPLE_VISIBILITY (f
);
7606 if (FRAME_VISIBLE_P (sf
)
7607 && !FRAME_VISIBLE_P (f
))
7608 Fmake_frame_visible (frame
);
7610 if (STRINGP (m
) && SCHARS (m
) > 0)
7612 set_message (NULL
, m
, nbytes
, multibyte
);
7613 if (minibuffer_auto_raise
)
7614 Fraise_frame (frame
);
7615 /* Assume we are not echoing.
7616 (If we are, echo_now will override this.) */
7617 echo_message_buffer
= Qnil
;
7620 clear_message (1, 1);
7622 do_pending_window_change (0);
7623 echo_area_display (1);
7624 do_pending_window_change (0);
7625 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7626 (*frame_up_to_date_hook
) (f
);
7631 /* Display a null-terminated echo area message M. If M is 0, clear
7632 out any existing message, and let the mini-buffer text show through.
7634 The buffer M must continue to exist until after the echo area gets
7635 cleared or some other message gets displayed there. Do not pass
7636 text that is stored in a Lisp string. Do not pass text in a buffer
7637 that was alloca'd. */
7643 message2 (m
, (m
? strlen (m
) : 0), 0);
7647 /* The non-logging counterpart of message1. */
7653 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7656 /* Display a message M which contains a single %s
7657 which gets replaced with STRING. */
7660 message_with_string (m
, string
, log
)
7665 CHECK_STRING (string
);
7671 if (noninteractive_need_newline
)
7672 putc ('\n', stderr
);
7673 noninteractive_need_newline
= 0;
7674 fprintf (stderr
, m
, SDATA (string
));
7675 if (cursor_in_echo_area
== 0)
7676 fprintf (stderr
, "\n");
7680 else if (INTERACTIVE
)
7682 /* The frame whose minibuffer we're going to display the message on.
7683 It may be larger than the selected frame, so we need
7684 to use its buffer, not the selected frame's buffer. */
7685 Lisp_Object mini_window
;
7686 struct frame
*f
, *sf
= SELECTED_FRAME ();
7688 /* Get the frame containing the minibuffer
7689 that the selected frame is using. */
7690 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7691 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7693 /* A null message buffer means that the frame hasn't really been
7694 initialized yet. Error messages get reported properly by
7695 cmd_error, so this must be just an informative message; toss it. */
7696 if (FRAME_MESSAGE_BUF (f
))
7698 Lisp_Object args
[2], message
;
7699 struct gcpro gcpro1
, gcpro2
;
7701 args
[0] = build_string (m
);
7702 args
[1] = message
= string
;
7703 GCPRO2 (args
[0], message
);
7706 message
= Fformat (2, args
);
7709 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7711 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7715 /* Print should start at the beginning of the message
7716 buffer next time. */
7717 message_buf_print
= 0;
7723 /* Dump an informative message to the minibuf. If M is 0, clear out
7724 any existing message, and let the mini-buffer text show through. */
7728 message (m
, a1
, a2
, a3
)
7730 EMACS_INT a1
, a2
, a3
;
7736 if (noninteractive_need_newline
)
7737 putc ('\n', stderr
);
7738 noninteractive_need_newline
= 0;
7739 fprintf (stderr
, m
, a1
, a2
, a3
);
7740 if (cursor_in_echo_area
== 0)
7741 fprintf (stderr
, "\n");
7745 else if (INTERACTIVE
)
7747 /* The frame whose mini-buffer we're going to display the message
7748 on. It may be larger than the selected frame, so we need to
7749 use its buffer, not the selected frame's buffer. */
7750 Lisp_Object mini_window
;
7751 struct frame
*f
, *sf
= SELECTED_FRAME ();
7753 /* Get the frame containing the mini-buffer
7754 that the selected frame is using. */
7755 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7756 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7758 /* A null message buffer means that the frame hasn't really been
7759 initialized yet. Error messages get reported properly by
7760 cmd_error, so this must be just an informative message; toss
7762 if (FRAME_MESSAGE_BUF (f
))
7773 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7774 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7776 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7777 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7779 #endif /* NO_ARG_ARRAY */
7781 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7786 /* Print should start at the beginning of the message
7787 buffer next time. */
7788 message_buf_print
= 0;
7794 /* The non-logging version of message. */
7797 message_nolog (m
, a1
, a2
, a3
)
7799 EMACS_INT a1
, a2
, a3
;
7801 Lisp_Object old_log_max
;
7802 old_log_max
= Vmessage_log_max
;
7803 Vmessage_log_max
= Qnil
;
7804 message (m
, a1
, a2
, a3
);
7805 Vmessage_log_max
= old_log_max
;
7809 /* Display the current message in the current mini-buffer. This is
7810 only called from error handlers in process.c, and is not time
7816 if (!NILP (echo_area_buffer
[0]))
7819 string
= Fcurrent_message ();
7820 message3 (string
, SBYTES (string
),
7821 !NILP (current_buffer
->enable_multibyte_characters
));
7826 /* Make sure echo area buffers in `echo_buffers' are live.
7827 If they aren't, make new ones. */
7830 ensure_echo_area_buffers ()
7834 for (i
= 0; i
< 2; ++i
)
7835 if (!BUFFERP (echo_buffer
[i
])
7836 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7839 Lisp_Object old_buffer
;
7842 old_buffer
= echo_buffer
[i
];
7843 sprintf (name
, " *Echo Area %d*", i
);
7844 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7845 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7847 for (j
= 0; j
< 2; ++j
)
7848 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7849 echo_area_buffer
[j
] = echo_buffer
[i
];
7854 /* Call FN with args A1..A4 with either the current or last displayed
7855 echo_area_buffer as current buffer.
7857 WHICH zero means use the current message buffer
7858 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7859 from echo_buffer[] and clear it.
7861 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7862 suitable buffer from echo_buffer[] and clear it.
7864 Value is what FN returns. */
7867 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7870 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7876 int this_one
, the_other
, clear_buffer_p
, rc
;
7877 int count
= SPECPDL_INDEX ();
7879 /* If buffers aren't live, make new ones. */
7880 ensure_echo_area_buffers ();
7885 this_one
= 0, the_other
= 1;
7887 this_one
= 1, the_other
= 0;
7889 /* Choose a suitable buffer from echo_buffer[] is we don't
7891 if (NILP (echo_area_buffer
[this_one
]))
7893 echo_area_buffer
[this_one
]
7894 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7895 ? echo_buffer
[the_other
]
7896 : echo_buffer
[this_one
]);
7900 buffer
= echo_area_buffer
[this_one
];
7902 /* Don't get confused by reusing the buffer used for echoing
7903 for a different purpose. */
7904 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7907 record_unwind_protect (unwind_with_echo_area_buffer
,
7908 with_echo_area_buffer_unwind_data (w
));
7910 /* Make the echo area buffer current. Note that for display
7911 purposes, it is not necessary that the displayed window's buffer
7912 == current_buffer, except for text property lookup. So, let's
7913 only set that buffer temporarily here without doing a full
7914 Fset_window_buffer. We must also change w->pointm, though,
7915 because otherwise an assertions in unshow_buffer fails, and Emacs
7917 set_buffer_internal_1 (XBUFFER (buffer
));
7921 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7924 current_buffer
->undo_list
= Qt
;
7925 current_buffer
->read_only
= Qnil
;
7926 specbind (Qinhibit_read_only
, Qt
);
7927 specbind (Qinhibit_modification_hooks
, Qt
);
7929 if (clear_buffer_p
&& Z
> BEG
)
7932 xassert (BEGV
>= BEG
);
7933 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7935 rc
= fn (a1
, a2
, a3
, a4
);
7937 xassert (BEGV
>= BEG
);
7938 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7940 unbind_to (count
, Qnil
);
7945 /* Save state that should be preserved around the call to the function
7946 FN called in with_echo_area_buffer. */
7949 with_echo_area_buffer_unwind_data (w
)
7955 /* Reduce consing by keeping one vector in
7956 Vwith_echo_area_save_vector. */
7957 vector
= Vwith_echo_area_save_vector
;
7958 Vwith_echo_area_save_vector
= Qnil
;
7961 vector
= Fmake_vector (make_number (7), Qnil
);
7963 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7964 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7965 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7969 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7970 AREF (vector
, i
) = w
->buffer
; ++i
;
7971 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7972 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7977 for (; i
< end
; ++i
)
7978 AREF (vector
, i
) = Qnil
;
7981 xassert (i
== ASIZE (vector
));
7986 /* Restore global state from VECTOR which was created by
7987 with_echo_area_buffer_unwind_data. */
7990 unwind_with_echo_area_buffer (vector
)
7993 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7994 Vdeactivate_mark
= AREF (vector
, 1);
7995 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7997 if (WINDOWP (AREF (vector
, 3)))
8000 Lisp_Object buffer
, charpos
, bytepos
;
8002 w
= XWINDOW (AREF (vector
, 3));
8003 buffer
= AREF (vector
, 4);
8004 charpos
= AREF (vector
, 5);
8005 bytepos
= AREF (vector
, 6);
8008 set_marker_both (w
->pointm
, buffer
,
8009 XFASTINT (charpos
), XFASTINT (bytepos
));
8012 Vwith_echo_area_save_vector
= vector
;
8017 /* Set up the echo area for use by print functions. MULTIBYTE_P
8018 non-zero means we will print multibyte. */
8021 setup_echo_area_for_printing (multibyte_p
)
8024 /* If we can't find an echo area any more, exit. */
8025 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8028 ensure_echo_area_buffers ();
8030 if (!message_buf_print
)
8032 /* A message has been output since the last time we printed.
8033 Choose a fresh echo area buffer. */
8034 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8035 echo_area_buffer
[0] = echo_buffer
[1];
8037 echo_area_buffer
[0] = echo_buffer
[0];
8039 /* Switch to that buffer and clear it. */
8040 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8041 current_buffer
->truncate_lines
= Qnil
;
8045 int count
= SPECPDL_INDEX ();
8046 specbind (Qinhibit_read_only
, Qt
);
8047 /* Note that undo recording is always disabled. */
8049 unbind_to (count
, Qnil
);
8051 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8053 /* Set up the buffer for the multibyteness we need. */
8055 != !NILP (current_buffer
->enable_multibyte_characters
))
8056 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8058 /* Raise the frame containing the echo area. */
8059 if (minibuffer_auto_raise
)
8061 struct frame
*sf
= SELECTED_FRAME ();
8062 Lisp_Object mini_window
;
8063 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8064 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8067 message_log_maybe_newline ();
8068 message_buf_print
= 1;
8072 if (NILP (echo_area_buffer
[0]))
8074 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8075 echo_area_buffer
[0] = echo_buffer
[1];
8077 echo_area_buffer
[0] = echo_buffer
[0];
8080 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8082 /* Someone switched buffers between print requests. */
8083 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8084 current_buffer
->truncate_lines
= Qnil
;
8090 /* Display an echo area message in window W. Value is non-zero if W's
8091 height is changed. If display_last_displayed_message_p is
8092 non-zero, display the message that was last displayed, otherwise
8093 display the current message. */
8096 display_echo_area (w
)
8099 int i
, no_message_p
, window_height_changed_p
, count
;
8101 /* Temporarily disable garbage collections while displaying the echo
8102 area. This is done because a GC can print a message itself.
8103 That message would modify the echo area buffer's contents while a
8104 redisplay of the buffer is going on, and seriously confuse
8106 count
= inhibit_garbage_collection ();
8108 /* If there is no message, we must call display_echo_area_1
8109 nevertheless because it resizes the window. But we will have to
8110 reset the echo_area_buffer in question to nil at the end because
8111 with_echo_area_buffer will sets it to an empty buffer. */
8112 i
= display_last_displayed_message_p
? 1 : 0;
8113 no_message_p
= NILP (echo_area_buffer
[i
]);
8115 window_height_changed_p
8116 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8117 display_echo_area_1
,
8118 (EMACS_INT
) w
, Qnil
, 0, 0);
8121 echo_area_buffer
[i
] = Qnil
;
8123 unbind_to (count
, Qnil
);
8124 return window_height_changed_p
;
8128 /* Helper for display_echo_area. Display the current buffer which
8129 contains the current echo area message in window W, a mini-window,
8130 a pointer to which is passed in A1. A2..A4 are currently not used.
8131 Change the height of W so that all of the message is displayed.
8132 Value is non-zero if height of W was changed. */
8135 display_echo_area_1 (a1
, a2
, a3
, a4
)
8140 struct window
*w
= (struct window
*) a1
;
8142 struct text_pos start
;
8143 int window_height_changed_p
= 0;
8145 /* Do this before displaying, so that we have a large enough glyph
8146 matrix for the display. If we can't get enough space for the
8147 whole text, display the last N lines. That works by setting w->start. */
8148 window_height_changed_p
= resize_mini_window (w
, 0);
8150 /* Use the starting position chosen by resize_mini_window. */
8151 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8154 clear_glyph_matrix (w
->desired_matrix
);
8155 XSETWINDOW (window
, w
);
8156 try_window (window
, start
, 0);
8158 return window_height_changed_p
;
8162 /* Resize the echo area window to exactly the size needed for the
8163 currently displayed message, if there is one. If a mini-buffer
8164 is active, don't shrink it. */
8167 resize_echo_area_exactly ()
8169 if (BUFFERP (echo_area_buffer
[0])
8170 && WINDOWP (echo_area_window
))
8172 struct window
*w
= XWINDOW (echo_area_window
);
8174 Lisp_Object resize_exactly
;
8176 if (minibuf_level
== 0)
8177 resize_exactly
= Qt
;
8179 resize_exactly
= Qnil
;
8181 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8182 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8185 ++windows_or_buffers_changed
;
8186 ++update_mode_lines
;
8187 redisplay_internal (0);
8193 /* Callback function for with_echo_area_buffer, when used from
8194 resize_echo_area_exactly. A1 contains a pointer to the window to
8195 resize, EXACTLY non-nil means resize the mini-window exactly to the
8196 size of the text displayed. A3 and A4 are not used. Value is what
8197 resize_mini_window returns. */
8200 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8202 Lisp_Object exactly
;
8205 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8209 /* Resize mini-window W to fit the size of its contents. EXACT:P
8210 means size the window exactly to the size needed. Otherwise, it's
8211 only enlarged until W's buffer is empty.
8213 Set W->start to the right place to begin display. If the whole
8214 contents fit, start at the beginning. Otherwise, start so as
8215 to make the end of the contents appear. This is particularly
8216 important for y-or-n-p, but seems desirable generally.
8218 Value is non-zero if the window height has been changed. */
8221 resize_mini_window (w
, exact_p
)
8225 struct frame
*f
= XFRAME (w
->frame
);
8226 int window_height_changed_p
= 0;
8228 xassert (MINI_WINDOW_P (w
));
8230 /* By default, start display at the beginning. */
8231 set_marker_both (w
->start
, w
->buffer
,
8232 BUF_BEGV (XBUFFER (w
->buffer
)),
8233 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8235 /* Don't resize windows while redisplaying a window; it would
8236 confuse redisplay functions when the size of the window they are
8237 displaying changes from under them. Such a resizing can happen,
8238 for instance, when which-func prints a long message while
8239 we are running fontification-functions. We're running these
8240 functions with safe_call which binds inhibit-redisplay to t. */
8241 if (!NILP (Vinhibit_redisplay
))
8244 /* Nil means don't try to resize. */
8245 if (NILP (Vresize_mini_windows
)
8246 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8249 if (!FRAME_MINIBUF_ONLY_P (f
))
8252 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8253 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8254 int height
, max_height
;
8255 int unit
= FRAME_LINE_HEIGHT (f
);
8256 struct text_pos start
;
8257 struct buffer
*old_current_buffer
= NULL
;
8259 if (current_buffer
!= XBUFFER (w
->buffer
))
8261 old_current_buffer
= current_buffer
;
8262 set_buffer_internal (XBUFFER (w
->buffer
));
8265 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8267 /* Compute the max. number of lines specified by the user. */
8268 if (FLOATP (Vmax_mini_window_height
))
8269 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8270 else if (INTEGERP (Vmax_mini_window_height
))
8271 max_height
= XINT (Vmax_mini_window_height
);
8273 max_height
= total_height
/ 4;
8275 /* Correct that max. height if it's bogus. */
8276 max_height
= max (1, max_height
);
8277 max_height
= min (total_height
, max_height
);
8279 /* Find out the height of the text in the window. */
8280 if (it
.truncate_lines_p
)
8285 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8286 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8287 height
= it
.current_y
+ last_height
;
8289 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8290 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8291 height
= (height
+ unit
- 1) / unit
;
8294 /* Compute a suitable window start. */
8295 if (height
> max_height
)
8297 height
= max_height
;
8298 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8299 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8300 start
= it
.current
.pos
;
8303 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8304 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8306 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8308 /* Let it grow only, until we display an empty message, in which
8309 case the window shrinks again. */
8310 if (height
> WINDOW_TOTAL_LINES (w
))
8312 int old_height
= WINDOW_TOTAL_LINES (w
);
8313 freeze_window_starts (f
, 1);
8314 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8315 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8317 else if (height
< WINDOW_TOTAL_LINES (w
)
8318 && (exact_p
|| BEGV
== ZV
))
8320 int old_height
= WINDOW_TOTAL_LINES (w
);
8321 freeze_window_starts (f
, 0);
8322 shrink_mini_window (w
);
8323 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8328 /* Always resize to exact size needed. */
8329 if (height
> WINDOW_TOTAL_LINES (w
))
8331 int old_height
= WINDOW_TOTAL_LINES (w
);
8332 freeze_window_starts (f
, 1);
8333 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8334 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8336 else if (height
< WINDOW_TOTAL_LINES (w
))
8338 int old_height
= WINDOW_TOTAL_LINES (w
);
8339 freeze_window_starts (f
, 0);
8340 shrink_mini_window (w
);
8344 freeze_window_starts (f
, 1);
8345 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8348 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8352 if (old_current_buffer
)
8353 set_buffer_internal (old_current_buffer
);
8356 return window_height_changed_p
;
8360 /* Value is the current message, a string, or nil if there is no
8368 if (NILP (echo_area_buffer
[0]))
8372 with_echo_area_buffer (0, 0, current_message_1
,
8373 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8375 echo_area_buffer
[0] = Qnil
;
8383 current_message_1 (a1
, a2
, a3
, a4
)
8388 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8391 *msg
= make_buffer_string (BEG
, Z
, 1);
8398 /* Push the current message on Vmessage_stack for later restauration
8399 by restore_message. Value is non-zero if the current message isn't
8400 empty. This is a relatively infrequent operation, so it's not
8401 worth optimizing. */
8407 msg
= current_message ();
8408 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8409 return STRINGP (msg
);
8413 /* Restore message display from the top of Vmessage_stack. */
8420 xassert (CONSP (Vmessage_stack
));
8421 msg
= XCAR (Vmessage_stack
);
8423 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8425 message3_nolog (msg
, 0, 0);
8429 /* Handler for record_unwind_protect calling pop_message. */
8432 pop_message_unwind (dummy
)
8439 /* Pop the top-most entry off Vmessage_stack. */
8444 xassert (CONSP (Vmessage_stack
));
8445 Vmessage_stack
= XCDR (Vmessage_stack
);
8449 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8450 exits. If the stack is not empty, we have a missing pop_message
8454 check_message_stack ()
8456 if (!NILP (Vmessage_stack
))
8461 /* Truncate to NCHARS what will be displayed in the echo area the next
8462 time we display it---but don't redisplay it now. */
8465 truncate_echo_area (nchars
)
8469 echo_area_buffer
[0] = Qnil
;
8470 /* A null message buffer means that the frame hasn't really been
8471 initialized yet. Error messages get reported properly by
8472 cmd_error, so this must be just an informative message; toss it. */
8473 else if (!noninteractive
8475 && !NILP (echo_area_buffer
[0]))
8477 struct frame
*sf
= SELECTED_FRAME ();
8478 if (FRAME_MESSAGE_BUF (sf
))
8479 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8484 /* Helper function for truncate_echo_area. Truncate the current
8485 message to at most NCHARS characters. */
8488 truncate_message_1 (nchars
, a2
, a3
, a4
)
8493 if (BEG
+ nchars
< Z
)
8494 del_range (BEG
+ nchars
, Z
);
8496 echo_area_buffer
[0] = Qnil
;
8501 /* Set the current message to a substring of S or STRING.
8503 If STRING is a Lisp string, set the message to the first NBYTES
8504 bytes from STRING. NBYTES zero means use the whole string. If
8505 STRING is multibyte, the message will be displayed multibyte.
8507 If S is not null, set the message to the first LEN bytes of S. LEN
8508 zero means use the whole string. MULTIBYTE_P non-zero means S is
8509 multibyte. Display the message multibyte in that case.
8511 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8512 to t before calling set_message_1 (which calls insert).
8516 set_message (s
, string
, nbytes
, multibyte_p
)
8519 int nbytes
, multibyte_p
;
8521 message_enable_multibyte
8522 = ((s
&& multibyte_p
)
8523 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8525 with_echo_area_buffer (0, 0, set_message_1
,
8526 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8527 message_buf_print
= 0;
8528 help_echo_showing_p
= 0;
8532 /* Helper function for set_message. Arguments have the same meaning
8533 as there, with A1 corresponding to S and A2 corresponding to STRING
8534 This function is called with the echo area buffer being
8538 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8541 EMACS_INT nbytes
, multibyte_p
;
8543 const char *s
= (const char *) a1
;
8544 Lisp_Object string
= a2
;
8546 /* Change multibyteness of the echo buffer appropriately. */
8547 if (message_enable_multibyte
8548 != !NILP (current_buffer
->enable_multibyte_characters
))
8549 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8551 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8553 /* Insert new message at BEG. */
8554 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8557 if (STRINGP (string
))
8562 nbytes
= SBYTES (string
);
8563 nchars
= string_byte_to_char (string
, nbytes
);
8565 /* This function takes care of single/multibyte conversion. We
8566 just have to ensure that the echo area buffer has the right
8567 setting of enable_multibyte_characters. */
8568 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8573 nbytes
= strlen (s
);
8575 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8577 /* Convert from multi-byte to single-byte. */
8579 unsigned char work
[1];
8581 /* Convert a multibyte string to single-byte. */
8582 for (i
= 0; i
< nbytes
; i
+= n
)
8584 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8585 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
8587 : multibyte_char_to_unibyte (c
, Qnil
));
8588 insert_1_both (work
, 1, 1, 1, 0, 0);
8591 else if (!multibyte_p
8592 && !NILP (current_buffer
->enable_multibyte_characters
))
8594 /* Convert from single-byte to multi-byte. */
8596 const unsigned char *msg
= (const unsigned char *) s
;
8597 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8599 /* Convert a single-byte string to multibyte. */
8600 for (i
= 0; i
< nbytes
; i
++)
8602 c
= unibyte_char_to_multibyte (msg
[i
]);
8603 n
= CHAR_STRING (c
, str
);
8604 insert_1_both (str
, 1, n
, 1, 0, 0);
8608 insert_1 (s
, nbytes
, 1, 0, 0);
8615 /* Clear messages. CURRENT_P non-zero means clear the current
8616 message. LAST_DISPLAYED_P non-zero means clear the message
8620 clear_message (current_p
, last_displayed_p
)
8621 int current_p
, last_displayed_p
;
8625 echo_area_buffer
[0] = Qnil
;
8626 message_cleared_p
= 1;
8629 if (last_displayed_p
)
8630 echo_area_buffer
[1] = Qnil
;
8632 message_buf_print
= 0;
8635 /* Clear garbaged frames.
8637 This function is used where the old redisplay called
8638 redraw_garbaged_frames which in turn called redraw_frame which in
8639 turn called clear_frame. The call to clear_frame was a source of
8640 flickering. I believe a clear_frame is not necessary. It should
8641 suffice in the new redisplay to invalidate all current matrices,
8642 and ensure a complete redisplay of all windows. */
8645 clear_garbaged_frames ()
8649 Lisp_Object tail
, frame
;
8650 int changed_count
= 0;
8652 FOR_EACH_FRAME (tail
, frame
)
8654 struct frame
*f
= XFRAME (frame
);
8656 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8660 Fredraw_frame (frame
);
8661 f
->force_flush_display_p
= 1;
8663 clear_current_matrices (f
);
8672 ++windows_or_buffers_changed
;
8677 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8678 is non-zero update selected_frame. Value is non-zero if the
8679 mini-windows height has been changed. */
8682 echo_area_display (update_frame_p
)
8685 Lisp_Object mini_window
;
8688 int window_height_changed_p
= 0;
8689 struct frame
*sf
= SELECTED_FRAME ();
8691 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8692 w
= XWINDOW (mini_window
);
8693 f
= XFRAME (WINDOW_FRAME (w
));
8695 /* Don't display if frame is invisible or not yet initialized. */
8696 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8699 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8701 #ifdef HAVE_WINDOW_SYSTEM
8702 /* When Emacs starts, selected_frame may be a visible terminal
8703 frame, even if we run under a window system. If we let this
8704 through, a message would be displayed on the terminal. */
8705 if (EQ (selected_frame
, Vterminal_frame
)
8706 && !NILP (Vwindow_system
))
8708 #endif /* HAVE_WINDOW_SYSTEM */
8711 /* Redraw garbaged frames. */
8713 clear_garbaged_frames ();
8715 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8717 echo_area_window
= mini_window
;
8718 window_height_changed_p
= display_echo_area (w
);
8719 w
->must_be_updated_p
= 1;
8721 /* Update the display, unless called from redisplay_internal.
8722 Also don't update the screen during redisplay itself. The
8723 update will happen at the end of redisplay, and an update
8724 here could cause confusion. */
8725 if (update_frame_p
&& !redisplaying_p
)
8729 /* If the display update has been interrupted by pending
8730 input, update mode lines in the frame. Due to the
8731 pending input, it might have been that redisplay hasn't
8732 been called, so that mode lines above the echo area are
8733 garbaged. This looks odd, so we prevent it here. */
8734 if (!display_completed
)
8735 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8737 if (window_height_changed_p
8738 /* Don't do this if Emacs is shutting down. Redisplay
8739 needs to run hooks. */
8740 && !NILP (Vrun_hooks
))
8742 /* Must update other windows. Likewise as in other
8743 cases, don't let this update be interrupted by
8745 int count
= SPECPDL_INDEX ();
8746 specbind (Qredisplay_dont_pause
, Qt
);
8747 windows_or_buffers_changed
= 1;
8748 redisplay_internal (0);
8749 unbind_to (count
, Qnil
);
8751 else if (FRAME_WINDOW_P (f
) && n
== 0)
8753 /* Window configuration is the same as before.
8754 Can do with a display update of the echo area,
8755 unless we displayed some mode lines. */
8756 update_single_window (w
, 1);
8757 rif
->flush_display (f
);
8760 update_frame (f
, 1, 1);
8762 /* If cursor is in the echo area, make sure that the next
8763 redisplay displays the minibuffer, so that the cursor will
8764 be replaced with what the minibuffer wants. */
8765 if (cursor_in_echo_area
)
8766 ++windows_or_buffers_changed
;
8769 else if (!EQ (mini_window
, selected_window
))
8770 windows_or_buffers_changed
++;
8772 /* The current message is now also the last one displayed. */
8773 echo_area_buffer
[1] = echo_area_buffer
[0];
8775 /* Prevent redisplay optimization in redisplay_internal by resetting
8776 this_line_start_pos. This is done because the mini-buffer now
8777 displays the message instead of its buffer text. */
8778 if (EQ (mini_window
, selected_window
))
8779 CHARPOS (this_line_start_pos
) = 0;
8781 return window_height_changed_p
;
8786 /***********************************************************************
8787 Mode Lines and Frame Titles
8788 ***********************************************************************/
8790 /* A buffer for constructing non-propertized mode-line strings and
8791 frame titles in it; allocated from the heap in init_xdisp and
8792 resized as needed in store_mode_line_noprop_char. */
8794 static char *mode_line_noprop_buf
;
8796 /* The buffer's end, and a current output position in it. */
8798 static char *mode_line_noprop_buf_end
;
8799 static char *mode_line_noprop_ptr
;
8801 #define MODE_LINE_NOPROP_LEN(start) \
8802 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8805 MODE_LINE_DISPLAY
= 0,
8811 /* Alist that caches the results of :propertize.
8812 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8813 static Lisp_Object mode_line_proptrans_alist
;
8815 /* List of strings making up the mode-line. */
8816 static Lisp_Object mode_line_string_list
;
8818 /* Base face property when building propertized mode line string. */
8819 static Lisp_Object mode_line_string_face
;
8820 static Lisp_Object mode_line_string_face_prop
;
8823 /* Unwind data for mode line strings */
8825 static Lisp_Object Vmode_line_unwind_vector
;
8828 format_mode_line_unwind_data (obuf
, save_proptrans
)
8829 struct buffer
*obuf
;
8833 /* Reduce consing by keeping one vector in
8834 Vwith_echo_area_save_vector. */
8835 vector
= Vmode_line_unwind_vector
;
8836 Vmode_line_unwind_vector
= Qnil
;
8839 vector
= Fmake_vector (make_number (7), Qnil
);
8841 AREF (vector
, 0) = make_number (mode_line_target
);
8842 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8843 AREF (vector
, 2) = mode_line_string_list
;
8844 AREF (vector
, 3) = (save_proptrans
? mode_line_proptrans_alist
: Qt
);
8845 AREF (vector
, 4) = mode_line_string_face
;
8846 AREF (vector
, 5) = mode_line_string_face_prop
;
8849 XSETBUFFER (AREF (vector
, 6), obuf
);
8851 AREF (vector
, 6) = Qnil
;
8857 unwind_format_mode_line (vector
)
8860 mode_line_target
= XINT (AREF (vector
, 0));
8861 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8862 mode_line_string_list
= AREF (vector
, 2);
8863 if (! EQ (AREF (vector
, 3), Qt
))
8864 mode_line_proptrans_alist
= AREF (vector
, 3);
8865 mode_line_string_face
= AREF (vector
, 4);
8866 mode_line_string_face_prop
= AREF (vector
, 5);
8868 if (!NILP (AREF (vector
, 6)))
8870 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8871 AREF (vector
, 6) = Qnil
;
8874 Vmode_line_unwind_vector
= vector
;
8879 /* Store a single character C for the frame title in mode_line_noprop_buf.
8880 Re-allocate mode_line_noprop_buf if necessary. */
8884 store_mode_line_noprop_char (char c
)
8886 store_mode_line_noprop_char (c
)
8890 /* If output position has reached the end of the allocated buffer,
8891 double the buffer's size. */
8892 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8894 int len
= MODE_LINE_NOPROP_LEN (0);
8895 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8896 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8897 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8898 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8901 *mode_line_noprop_ptr
++ = c
;
8905 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8906 mode_line_noprop_ptr. STR is the string to store. Do not copy
8907 characters that yield more columns than PRECISION; PRECISION <= 0
8908 means copy the whole string. Pad with spaces until FIELD_WIDTH
8909 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8910 pad. Called from display_mode_element when it is used to build a
8914 store_mode_line_noprop (str
, field_width
, precision
)
8915 const unsigned char *str
;
8916 int field_width
, precision
;
8921 /* Copy at most PRECISION chars from STR. */
8922 nbytes
= strlen (str
);
8923 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8925 store_mode_line_noprop_char (*str
++);
8927 /* Fill up with spaces until FIELD_WIDTH reached. */
8928 while (field_width
> 0
8931 store_mode_line_noprop_char (' ');
8938 /***********************************************************************
8940 ***********************************************************************/
8942 #ifdef HAVE_WINDOW_SYSTEM
8944 /* Set the title of FRAME, if it has changed. The title format is
8945 Vicon_title_format if FRAME is iconified, otherwise it is
8946 frame_title_format. */
8949 x_consider_frame_title (frame
)
8952 struct frame
*f
= XFRAME (frame
);
8954 if (FRAME_WINDOW_P (f
)
8955 || FRAME_MINIBUF_ONLY_P (f
)
8956 || f
->explicit_name
)
8958 /* Do we have more than one visible frame on this X display? */
8965 int count
= SPECPDL_INDEX ();
8967 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8969 Lisp_Object other_frame
= XCAR (tail
);
8970 struct frame
*tf
= XFRAME (other_frame
);
8973 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8974 && !FRAME_MINIBUF_ONLY_P (tf
)
8975 && !EQ (other_frame
, tip_frame
)
8976 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8980 /* Set global variable indicating that multiple frames exist. */
8981 multiple_frames
= CONSP (tail
);
8983 /* Switch to the buffer of selected window of the frame. Set up
8984 mode_line_target so that display_mode_element will output into
8985 mode_line_noprop_buf; then display the title. */
8986 record_unwind_protect (unwind_format_mode_line
,
8987 format_mode_line_unwind_data (current_buffer
, 0));
8989 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8990 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8992 mode_line_target
= MODE_LINE_TITLE
;
8993 title_start
= MODE_LINE_NOPROP_LEN (0);
8994 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8995 NULL
, DEFAULT_FACE_ID
);
8996 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8997 len
= MODE_LINE_NOPROP_LEN (title_start
);
8998 title
= mode_line_noprop_buf
+ title_start
;
8999 unbind_to (count
, Qnil
);
9001 /* Set the title only if it's changed. This avoids consing in
9002 the common case where it hasn't. (If it turns out that we've
9003 already wasted too much time by walking through the list with
9004 display_mode_element, then we might need to optimize at a
9005 higher level than this.) */
9006 if (! STRINGP (f
->name
)
9007 || SBYTES (f
->name
) != len
9008 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9009 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9013 #endif /* not HAVE_WINDOW_SYSTEM */
9018 /***********************************************************************
9020 ***********************************************************************/
9023 /* Prepare for redisplay by updating menu-bar item lists when
9024 appropriate. This can call eval. */
9027 prepare_menu_bars ()
9030 struct gcpro gcpro1
, gcpro2
;
9032 Lisp_Object tooltip_frame
;
9034 #ifdef HAVE_WINDOW_SYSTEM
9035 tooltip_frame
= tip_frame
;
9037 tooltip_frame
= Qnil
;
9040 /* Update all frame titles based on their buffer names, etc. We do
9041 this before the menu bars so that the buffer-menu will show the
9042 up-to-date frame titles. */
9043 #ifdef HAVE_WINDOW_SYSTEM
9044 if (windows_or_buffers_changed
|| update_mode_lines
)
9046 Lisp_Object tail
, frame
;
9048 FOR_EACH_FRAME (tail
, frame
)
9051 if (!EQ (frame
, tooltip_frame
)
9052 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9053 x_consider_frame_title (frame
);
9056 #endif /* HAVE_WINDOW_SYSTEM */
9058 /* Update the menu bar item lists, if appropriate. This has to be
9059 done before any actual redisplay or generation of display lines. */
9060 all_windows
= (update_mode_lines
9061 || buffer_shared
> 1
9062 || windows_or_buffers_changed
);
9065 Lisp_Object tail
, frame
;
9066 int count
= SPECPDL_INDEX ();
9067 /* 1 means that update_menu_bar has run its hooks
9068 so any further calls to update_menu_bar shouldn't do so again. */
9069 int menu_bar_hooks_run
= 0;
9071 record_unwind_save_match_data ();
9073 FOR_EACH_FRAME (tail
, frame
)
9077 /* Ignore tooltip frame. */
9078 if (EQ (frame
, tooltip_frame
))
9081 /* If a window on this frame changed size, report that to
9082 the user and clear the size-change flag. */
9083 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9085 Lisp_Object functions
;
9087 /* Clear flag first in case we get an error below. */
9088 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9089 functions
= Vwindow_size_change_functions
;
9090 GCPRO2 (tail
, functions
);
9092 while (CONSP (functions
))
9094 call1 (XCAR (functions
), frame
);
9095 functions
= XCDR (functions
);
9101 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9102 #ifdef HAVE_WINDOW_SYSTEM
9103 update_tool_bar (f
, 0);
9105 mac_update_title_bar (f
, 0);
9111 unbind_to (count
, Qnil
);
9115 struct frame
*sf
= SELECTED_FRAME ();
9116 update_menu_bar (sf
, 1, 0);
9117 #ifdef HAVE_WINDOW_SYSTEM
9118 update_tool_bar (sf
, 1);
9120 mac_update_title_bar (sf
, 1);
9125 /* Motif needs this. See comment in xmenu.c. Turn it off when
9126 pending_menu_activation is not defined. */
9127 #ifdef USE_X_TOOLKIT
9128 pending_menu_activation
= 0;
9133 /* Update the menu bar item list for frame F. This has to be done
9134 before we start to fill in any display lines, because it can call
9137 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9139 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9140 already ran the menu bar hooks for this redisplay, so there
9141 is no need to run them again. The return value is the
9142 updated value of this flag, to pass to the next call. */
9145 update_menu_bar (f
, save_match_data
, hooks_run
)
9147 int save_match_data
;
9151 register struct window
*w
;
9153 /* If called recursively during a menu update, do nothing. This can
9154 happen when, for instance, an activate-menubar-hook causes a
9156 if (inhibit_menubar_update
)
9159 window
= FRAME_SELECTED_WINDOW (f
);
9160 w
= XWINDOW (window
);
9162 #if 0 /* The if statement below this if statement used to include the
9163 condition !NILP (w->update_mode_line), rather than using
9164 update_mode_lines directly, and this if statement may have
9165 been added to make that condition work. Now the if
9166 statement below matches its comment, this isn't needed. */
9167 if (update_mode_lines
)
9168 w
->update_mode_line
= Qt
;
9171 if (FRAME_WINDOW_P (f
)
9173 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9174 || defined (USE_GTK)
9175 FRAME_EXTERNAL_MENU_BAR (f
)
9177 FRAME_MENU_BAR_LINES (f
) > 0
9179 : FRAME_MENU_BAR_LINES (f
) > 0)
9181 /* If the user has switched buffers or windows, we need to
9182 recompute to reflect the new bindings. But we'll
9183 recompute when update_mode_lines is set too; that means
9184 that people can use force-mode-line-update to request
9185 that the menu bar be recomputed. The adverse effect on
9186 the rest of the redisplay algorithm is about the same as
9187 windows_or_buffers_changed anyway. */
9188 if (windows_or_buffers_changed
9189 /* This used to test w->update_mode_line, but we believe
9190 there is no need to recompute the menu in that case. */
9191 || update_mode_lines
9192 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9193 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9194 != !NILP (w
->last_had_star
))
9195 || ((!NILP (Vtransient_mark_mode
)
9196 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9197 != !NILP (w
->region_showing
)))
9199 struct buffer
*prev
= current_buffer
;
9200 int count
= SPECPDL_INDEX ();
9202 specbind (Qinhibit_menubar_update
, Qt
);
9204 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9205 if (save_match_data
)
9206 record_unwind_save_match_data ();
9207 if (NILP (Voverriding_local_map_menu_flag
))
9209 specbind (Qoverriding_terminal_local_map
, Qnil
);
9210 specbind (Qoverriding_local_map
, Qnil
);
9215 /* Run the Lucid hook. */
9216 safe_run_hooks (Qactivate_menubar_hook
);
9218 /* If it has changed current-menubar from previous value,
9219 really recompute the menu-bar from the value. */
9220 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9221 call0 (Qrecompute_lucid_menubar
);
9223 safe_run_hooks (Qmenu_bar_update_hook
);
9228 XSETFRAME (Vmenu_updating_frame
, f
);
9229 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9231 /* Redisplay the menu bar in case we changed it. */
9232 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9233 || defined (USE_GTK)
9234 if (FRAME_WINDOW_P (f
))
9237 /* All frames on Mac OS share the same menubar. So only
9238 the selected frame should be allowed to set it. */
9239 if (f
== SELECTED_FRAME ())
9241 set_frame_menubar (f
, 0, 0);
9244 /* On a terminal screen, the menu bar is an ordinary screen
9245 line, and this makes it get updated. */
9246 w
->update_mode_line
= Qt
;
9247 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9248 /* In the non-toolkit version, the menu bar is an ordinary screen
9249 line, and this makes it get updated. */
9250 w
->update_mode_line
= Qt
;
9251 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9253 unbind_to (count
, Qnil
);
9254 set_buffer_internal_1 (prev
);
9263 /***********************************************************************
9265 ***********************************************************************/
9267 #ifdef HAVE_WINDOW_SYSTEM
9270 Nominal cursor position -- where to draw output.
9271 HPOS and VPOS are window relative glyph matrix coordinates.
9272 X and Y are window relative pixel coordinates. */
9274 struct cursor_pos output_cursor
;
9278 Set the global variable output_cursor to CURSOR. All cursor
9279 positions are relative to updated_window. */
9282 set_output_cursor (cursor
)
9283 struct cursor_pos
*cursor
;
9285 output_cursor
.hpos
= cursor
->hpos
;
9286 output_cursor
.vpos
= cursor
->vpos
;
9287 output_cursor
.x
= cursor
->x
;
9288 output_cursor
.y
= cursor
->y
;
9293 Set a nominal cursor position.
9295 HPOS and VPOS are column/row positions in a window glyph matrix. X
9296 and Y are window text area relative pixel positions.
9298 If this is done during an update, updated_window will contain the
9299 window that is being updated and the position is the future output
9300 cursor position for that window. If updated_window is null, use
9301 selected_window and display the cursor at the given position. */
9304 x_cursor_to (vpos
, hpos
, y
, x
)
9305 int vpos
, hpos
, y
, x
;
9309 /* If updated_window is not set, work on selected_window. */
9313 w
= XWINDOW (selected_window
);
9315 /* Set the output cursor. */
9316 output_cursor
.hpos
= hpos
;
9317 output_cursor
.vpos
= vpos
;
9318 output_cursor
.x
= x
;
9319 output_cursor
.y
= y
;
9321 /* If not called as part of an update, really display the cursor.
9322 This will also set the cursor position of W. */
9323 if (updated_window
== NULL
)
9326 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9327 if (rif
->flush_display_optional
)
9328 rif
->flush_display_optional (SELECTED_FRAME ());
9333 #endif /* HAVE_WINDOW_SYSTEM */
9336 /***********************************************************************
9338 ***********************************************************************/
9340 #ifdef HAVE_WINDOW_SYSTEM
9342 /* Where the mouse was last time we reported a mouse event. */
9344 FRAME_PTR last_mouse_frame
;
9346 /* Tool-bar item index of the item on which a mouse button was pressed
9349 int last_tool_bar_item
;
9352 /* Update the tool-bar item list for frame F. This has to be done
9353 before we start to fill in any display lines. Called from
9354 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9355 and restore it here. */
9358 update_tool_bar (f
, save_match_data
)
9360 int save_match_data
;
9363 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9365 int do_update
= WINDOWP (f
->tool_bar_window
)
9366 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9374 window
= FRAME_SELECTED_WINDOW (f
);
9375 w
= XWINDOW (window
);
9377 /* If the user has switched buffers or windows, we need to
9378 recompute to reflect the new bindings. But we'll
9379 recompute when update_mode_lines is set too; that means
9380 that people can use force-mode-line-update to request
9381 that the menu bar be recomputed. The adverse effect on
9382 the rest of the redisplay algorithm is about the same as
9383 windows_or_buffers_changed anyway. */
9384 if (windows_or_buffers_changed
9385 || !NILP (w
->update_mode_line
)
9386 || update_mode_lines
9387 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9388 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9389 != !NILP (w
->last_had_star
))
9390 || ((!NILP (Vtransient_mark_mode
)
9391 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9392 != !NILP (w
->region_showing
)))
9394 struct buffer
*prev
= current_buffer
;
9395 int count
= SPECPDL_INDEX ();
9396 Lisp_Object new_tool_bar
;
9398 struct gcpro gcpro1
;
9400 /* Set current_buffer to the buffer of the selected
9401 window of the frame, so that we get the right local
9403 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9405 /* Save match data, if we must. */
9406 if (save_match_data
)
9407 record_unwind_save_match_data ();
9409 /* Make sure that we don't accidentally use bogus keymaps. */
9410 if (NILP (Voverriding_local_map_menu_flag
))
9412 specbind (Qoverriding_terminal_local_map
, Qnil
);
9413 specbind (Qoverriding_local_map
, Qnil
);
9416 GCPRO1 (new_tool_bar
);
9418 /* Build desired tool-bar items from keymaps. */
9419 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9422 /* Redisplay the tool-bar if we changed it. */
9423 if (new_n_tool_bar
!= f
->n_tool_bar_items
9424 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9426 /* Redisplay that happens asynchronously due to an expose event
9427 may access f->tool_bar_items. Make sure we update both
9428 variables within BLOCK_INPUT so no such event interrupts. */
9430 f
->tool_bar_items
= new_tool_bar
;
9431 f
->n_tool_bar_items
= new_n_tool_bar
;
9432 w
->update_mode_line
= Qt
;
9438 unbind_to (count
, Qnil
);
9439 set_buffer_internal_1 (prev
);
9445 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9446 F's desired tool-bar contents. F->tool_bar_items must have
9447 been set up previously by calling prepare_menu_bars. */
9450 build_desired_tool_bar_string (f
)
9453 int i
, size
, size_needed
;
9454 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9455 Lisp_Object image
, plist
, props
;
9457 image
= plist
= props
= Qnil
;
9458 GCPRO3 (image
, plist
, props
);
9460 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9461 Otherwise, make a new string. */
9463 /* The size of the string we might be able to reuse. */
9464 size
= (STRINGP (f
->desired_tool_bar_string
)
9465 ? SCHARS (f
->desired_tool_bar_string
)
9468 /* We need one space in the string for each image. */
9469 size_needed
= f
->n_tool_bar_items
;
9471 /* Reuse f->desired_tool_bar_string, if possible. */
9472 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9473 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9477 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9478 Fremove_text_properties (make_number (0), make_number (size
),
9479 props
, f
->desired_tool_bar_string
);
9482 /* Put a `display' property on the string for the images to display,
9483 put a `menu_item' property on tool-bar items with a value that
9484 is the index of the item in F's tool-bar item vector. */
9485 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9487 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9489 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9490 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9491 int hmargin
, vmargin
, relief
, idx
, end
;
9492 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9494 /* If image is a vector, choose the image according to the
9496 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9497 if (VECTORP (image
))
9501 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9502 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9505 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9506 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9508 xassert (ASIZE (image
) >= idx
);
9509 image
= AREF (image
, idx
);
9514 /* Ignore invalid image specifications. */
9515 if (!valid_image_p (image
))
9518 /* Display the tool-bar button pressed, or depressed. */
9519 plist
= Fcopy_sequence (XCDR (image
));
9521 /* Compute margin and relief to draw. */
9522 relief
= (tool_bar_button_relief
>= 0
9523 ? tool_bar_button_relief
9524 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9525 hmargin
= vmargin
= relief
;
9527 if (INTEGERP (Vtool_bar_button_margin
)
9528 && XINT (Vtool_bar_button_margin
) > 0)
9530 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9531 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9533 else if (CONSP (Vtool_bar_button_margin
))
9535 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9536 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9537 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9539 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9540 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9541 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9544 if (auto_raise_tool_bar_buttons_p
)
9546 /* Add a `:relief' property to the image spec if the item is
9550 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9557 /* If image is selected, display it pressed, i.e. with a
9558 negative relief. If it's not selected, display it with a
9560 plist
= Fplist_put (plist
, QCrelief
,
9562 ? make_number (-relief
)
9563 : make_number (relief
)));
9568 /* Put a margin around the image. */
9569 if (hmargin
|| vmargin
)
9571 if (hmargin
== vmargin
)
9572 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9574 plist
= Fplist_put (plist
, QCmargin
,
9575 Fcons (make_number (hmargin
),
9576 make_number (vmargin
)));
9579 /* If button is not enabled, and we don't have special images
9580 for the disabled state, make the image appear disabled by
9581 applying an appropriate algorithm to it. */
9582 if (!enabled_p
&& idx
< 0)
9583 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9585 /* Put a `display' text property on the string for the image to
9586 display. Put a `menu-item' property on the string that gives
9587 the start of this item's properties in the tool-bar items
9589 image
= Fcons (Qimage
, plist
);
9590 props
= list4 (Qdisplay
, image
,
9591 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9593 /* Let the last image hide all remaining spaces in the tool bar
9594 string. The string can be longer than needed when we reuse a
9596 if (i
+ 1 == f
->n_tool_bar_items
)
9597 end
= SCHARS (f
->desired_tool_bar_string
);
9600 Fadd_text_properties (make_number (i
), make_number (end
),
9601 props
, f
->desired_tool_bar_string
);
9609 /* Display one line of the tool-bar of frame IT->f.
9611 HEIGHT specifies the desired height of the tool-bar line.
9612 If the actual height of the glyph row is less than HEIGHT, the
9613 row's height is increased to HEIGHT, and the icons are centered
9614 vertically in the new height.
9616 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
9617 count a final empty row in case the tool-bar width exactly matches
9622 display_tool_bar_line (it
, height
)
9626 struct glyph_row
*row
= it
->glyph_row
;
9627 int max_x
= it
->last_visible_x
;
9630 prepare_desired_row (row
);
9631 row
->y
= it
->current_y
;
9633 /* Note that this isn't made use of if the face hasn't a box,
9634 so there's no need to check the face here. */
9635 it
->start_of_box_run_p
= 1;
9637 while (it
->current_x
< max_x
)
9639 int x
, n_glyphs_before
, i
, nglyphs
;
9640 struct it it_before
;
9642 /* Get the next display element. */
9643 if (!get_next_display_element (it
))
9645 /* Don't count empty row if we are counting needed tool-bar lines. */
9646 if (height
< 0 && !it
->hpos
)
9651 /* Produce glyphs. */
9652 n_glyphs_before
= row
->used
[TEXT_AREA
];
9655 PRODUCE_GLYPHS (it
);
9657 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
9659 x
= it_before
.current_x
;
9662 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9664 if (x
+ glyph
->pixel_width
> max_x
)
9666 /* Glyph doesn't fit on line. Backtrack. */
9667 row
->used
[TEXT_AREA
] = n_glyphs_before
;
9669 /* If this is the only glyph on this line, it will never fit on the
9670 toolbar, so skip it. But ensure there is at least one glyph,
9671 so we don't accidentally disable the tool-bar. */
9672 if (n_glyphs_before
== 0
9673 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
9679 x
+= glyph
->pixel_width
;
9683 /* Stop at line ends. */
9684 if (ITERATOR_AT_END_OF_LINE_P (it
))
9687 set_iterator_to_next (it
, 1);
9692 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9693 /* Use default face for the border below the tool bar. */
9694 if (!row
->displays_text_p
)
9695 it
->face_id
= DEFAULT_FACE_ID
;
9696 extend_face_to_end_of_line (it
);
9697 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9698 last
->right_box_line_p
= 1;
9699 if (last
== row
->glyphs
[TEXT_AREA
])
9700 last
->left_box_line_p
= 1;
9702 /* Make line the desired height and center it vertically. */
9703 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
9705 /* Don't add more than one line height. */
9706 height
%= FRAME_LINE_HEIGHT (it
->f
);
9707 it
->max_ascent
+= height
/ 2;
9708 it
->max_descent
+= (height
+ 1) / 2;
9711 compute_line_metrics (it
);
9713 /* If line is empty, make it occupy the rest of the tool-bar. */
9714 if (!row
->displays_text_p
)
9716 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9717 row
->ascent
= row
->phys_ascent
= 0;
9718 row
->extra_line_spacing
= 0;
9721 row
->full_width_p
= 1;
9722 row
->continued_p
= 0;
9723 row
->truncated_on_left_p
= 0;
9724 row
->truncated_on_right_p
= 0;
9726 it
->current_x
= it
->hpos
= 0;
9727 it
->current_y
+= row
->height
;
9733 /* Max tool-bar height. */
9735 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
9736 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
9738 /* Value is the number of screen lines needed to make all tool-bar
9739 items of frame F visible. The number of actual rows needed is
9740 returned in *N_ROWS if non-NULL. */
9743 tool_bar_lines_needed (f
, n_rows
)
9747 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9749 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
9750 the desired matrix, so use (unused) mode-line row as temporary row to
9751 avoid destroying the first tool-bar row. */
9752 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
9754 /* Initialize an iterator for iteration over
9755 F->desired_tool_bar_string in the tool-bar window of frame F. */
9756 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
9757 it
.first_visible_x
= 0;
9758 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9759 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9761 while (!ITERATOR_AT_END_P (&it
))
9763 clear_glyph_row (temp_row
);
9764 it
.glyph_row
= temp_row
;
9765 display_tool_bar_line (&it
, -1);
9767 clear_glyph_row (temp_row
);
9769 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
9771 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
9773 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9777 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9779 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9788 frame
= selected_frame
;
9790 CHECK_FRAME (frame
);
9793 if (WINDOWP (f
->tool_bar_window
)
9794 || (w
= XWINDOW (f
->tool_bar_window
),
9795 WINDOW_TOTAL_LINES (w
) > 0))
9797 update_tool_bar (f
, 1);
9798 if (f
->n_tool_bar_items
)
9800 build_desired_tool_bar_string (f
);
9801 nlines
= tool_bar_lines_needed (f
, NULL
);
9805 return make_number (nlines
);
9809 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9810 height should be changed. */
9813 redisplay_tool_bar (f
)
9818 struct glyph_row
*row
;
9819 int change_height_p
= 0;
9822 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9823 update_frame_tool_bar (f
);
9827 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9828 do anything. This means you must start with tool-bar-lines
9829 non-zero to get the auto-sizing effect. Or in other words, you
9830 can turn off tool-bars by specifying tool-bar-lines zero. */
9831 if (!WINDOWP (f
->tool_bar_window
)
9832 || (w
= XWINDOW (f
->tool_bar_window
),
9833 WINDOW_TOTAL_LINES (w
) == 0))
9836 /* Set up an iterator for the tool-bar window. */
9837 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9838 it
.first_visible_x
= 0;
9839 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9842 /* Build a string that represents the contents of the tool-bar. */
9843 build_desired_tool_bar_string (f
);
9844 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9846 if (f
->n_tool_bar_rows
== 0)
9850 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
9851 nlines
!= WINDOW_TOTAL_LINES (w
)))
9853 extern Lisp_Object Qtool_bar_lines
;
9855 int old_height
= WINDOW_TOTAL_LINES (w
);
9857 XSETFRAME (frame
, f
);
9858 Fmodify_frame_parameters (frame
,
9859 Fcons (Fcons (Qtool_bar_lines
,
9860 make_number (nlines
)),
9862 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9864 clear_glyph_matrix (w
->desired_matrix
);
9865 fonts_changed_p
= 1;
9871 /* Display as many lines as needed to display all tool-bar items. */
9873 if (f
->n_tool_bar_rows
> 0)
9875 int border
, rows
, height
, extra
;
9877 if (INTEGERP (Vtool_bar_border
))
9878 border
= XINT (Vtool_bar_border
);
9879 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
9880 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
9881 else if (EQ (Vtool_bar_border
, Qborder_width
))
9882 border
= f
->border_width
;
9888 rows
= f
->n_tool_bar_rows
;
9889 height
= max (1, (it
.last_visible_y
- border
) / rows
);
9890 extra
= it
.last_visible_y
- border
- height
* rows
;
9892 while (it
.current_y
< it
.last_visible_y
)
9895 if (extra
> 0 && rows
-- > 0)
9897 h
= (extra
+ rows
- 1) / rows
;
9900 display_tool_bar_line (&it
, height
+ h
);
9905 while (it
.current_y
< it
.last_visible_y
)
9906 display_tool_bar_line (&it
, 0);
9909 /* It doesn't make much sense to try scrolling in the tool-bar
9910 window, so don't do it. */
9911 w
->desired_matrix
->no_scrolling_p
= 1;
9912 w
->must_be_updated_p
= 1;
9914 if (auto_resize_tool_bars_p
)
9917 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
9919 /* If we couldn't display everything, change the tool-bar's
9920 height if there is room for more. */
9921 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
9922 && it
.current_y
< max_tool_bar_height
)
9923 change_height_p
= 1;
9925 row
= it
.glyph_row
- 1;
9927 /* If there are blank lines at the end, except for a partially
9928 visible blank line at the end that is smaller than
9929 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9930 if (!row
->displays_text_p
9931 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9932 change_height_p
= 1;
9934 /* If row displays tool-bar items, but is partially visible,
9935 change the tool-bar's height. */
9936 if (row
->displays_text_p
9937 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
9938 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
9939 change_height_p
= 1;
9941 /* Resize windows as needed by changing the `tool-bar-lines'
9944 && (nlines
= tool_bar_lines_needed (f
, &nrows
),
9945 nlines
!= WINDOW_TOTAL_LINES (w
)))
9947 extern Lisp_Object Qtool_bar_lines
;
9949 int old_height
= WINDOW_TOTAL_LINES (w
);
9951 XSETFRAME (frame
, f
);
9952 Fmodify_frame_parameters (frame
,
9953 Fcons (Fcons (Qtool_bar_lines
,
9954 make_number (nlines
)),
9956 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9958 clear_glyph_matrix (w
->desired_matrix
);
9959 f
->n_tool_bar_rows
= nrows
;
9960 fonts_changed_p
= 1;
9965 return change_height_p
;
9969 /* Get information about the tool-bar item which is displayed in GLYPH
9970 on frame F. Return in *PROP_IDX the index where tool-bar item
9971 properties start in F->tool_bar_items. Value is zero if
9972 GLYPH doesn't display a tool-bar item. */
9975 tool_bar_item_info (f
, glyph
, prop_idx
)
9977 struct glyph
*glyph
;
9984 /* This function can be called asynchronously, which means we must
9985 exclude any possibility that Fget_text_property signals an
9987 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
9988 charpos
= max (0, charpos
);
9990 /* Get the text property `menu-item' at pos. The value of that
9991 property is the start index of this item's properties in
9992 F->tool_bar_items. */
9993 prop
= Fget_text_property (make_number (charpos
),
9994 Qmenu_item
, f
->current_tool_bar_string
);
9995 if (INTEGERP (prop
))
9997 *prop_idx
= XINT (prop
);
10007 /* Get information about the tool-bar item at position X/Y on frame F.
10008 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10009 the current matrix of the tool-bar window of F, or NULL if not
10010 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10011 item in F->tool_bar_items. Value is
10013 -1 if X/Y is not on a tool-bar item
10014 0 if X/Y is on the same item that was highlighted before.
10018 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10021 struct glyph
**glyph
;
10022 int *hpos
, *vpos
, *prop_idx
;
10024 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10025 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10028 /* Find the glyph under X/Y. */
10029 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10030 if (*glyph
== NULL
)
10033 /* Get the start of this tool-bar item's properties in
10034 f->tool_bar_items. */
10035 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10038 /* Is mouse on the highlighted item? */
10039 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10040 && *vpos
>= dpyinfo
->mouse_face_beg_row
10041 && *vpos
<= dpyinfo
->mouse_face_end_row
10042 && (*vpos
> dpyinfo
->mouse_face_beg_row
10043 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10044 && (*vpos
< dpyinfo
->mouse_face_end_row
10045 || *hpos
< dpyinfo
->mouse_face_end_col
10046 || dpyinfo
->mouse_face_past_end
))
10054 Handle mouse button event on the tool-bar of frame F, at
10055 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10056 0 for button release. MODIFIERS is event modifiers for button
10060 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10063 unsigned int modifiers
;
10065 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10066 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10067 int hpos
, vpos
, prop_idx
;
10068 struct glyph
*glyph
;
10069 Lisp_Object enabled_p
;
10071 /* If not on the highlighted tool-bar item, return. */
10072 frame_to_window_pixel_xy (w
, &x
, &y
);
10073 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10076 /* If item is disabled, do nothing. */
10077 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10078 if (NILP (enabled_p
))
10083 /* Show item in pressed state. */
10084 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10085 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10086 last_tool_bar_item
= prop_idx
;
10090 Lisp_Object key
, frame
;
10091 struct input_event event
;
10092 EVENT_INIT (event
);
10094 /* Show item in released state. */
10095 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10096 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10098 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10100 XSETFRAME (frame
, f
);
10101 event
.kind
= TOOL_BAR_EVENT
;
10102 event
.frame_or_window
= frame
;
10104 kbd_buffer_store_event (&event
);
10106 event
.kind
= TOOL_BAR_EVENT
;
10107 event
.frame_or_window
= frame
;
10109 event
.modifiers
= modifiers
;
10110 kbd_buffer_store_event (&event
);
10111 last_tool_bar_item
= -1;
10116 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10117 tool-bar window-relative coordinates X/Y. Called from
10118 note_mouse_highlight. */
10121 note_tool_bar_highlight (f
, x
, y
)
10125 Lisp_Object window
= f
->tool_bar_window
;
10126 struct window
*w
= XWINDOW (window
);
10127 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10129 struct glyph
*glyph
;
10130 struct glyph_row
*row
;
10132 Lisp_Object enabled_p
;
10134 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10135 int mouse_down_p
, rc
;
10137 /* Function note_mouse_highlight is called with negative x(y
10138 values when mouse moves outside of the frame. */
10139 if (x
<= 0 || y
<= 0)
10141 clear_mouse_face (dpyinfo
);
10145 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10148 /* Not on tool-bar item. */
10149 clear_mouse_face (dpyinfo
);
10153 /* On same tool-bar item as before. */
10154 goto set_help_echo
;
10156 clear_mouse_face (dpyinfo
);
10158 /* Mouse is down, but on different tool-bar item? */
10159 mouse_down_p
= (dpyinfo
->grabbed
10160 && f
== last_mouse_frame
10161 && FRAME_LIVE_P (f
));
10163 && last_tool_bar_item
!= prop_idx
)
10166 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10167 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10169 /* If tool-bar item is not enabled, don't highlight it. */
10170 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10171 if (!NILP (enabled_p
))
10173 /* Compute the x-position of the glyph. In front and past the
10174 image is a space. We include this in the highlighted area. */
10175 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10176 for (i
= x
= 0; i
< hpos
; ++i
)
10177 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10179 /* Record this as the current active region. */
10180 dpyinfo
->mouse_face_beg_col
= hpos
;
10181 dpyinfo
->mouse_face_beg_row
= vpos
;
10182 dpyinfo
->mouse_face_beg_x
= x
;
10183 dpyinfo
->mouse_face_beg_y
= row
->y
;
10184 dpyinfo
->mouse_face_past_end
= 0;
10186 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10187 dpyinfo
->mouse_face_end_row
= vpos
;
10188 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10189 dpyinfo
->mouse_face_end_y
= row
->y
;
10190 dpyinfo
->mouse_face_window
= window
;
10191 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10193 /* Display it as active. */
10194 show_mouse_face (dpyinfo
, draw
);
10195 dpyinfo
->mouse_face_image_state
= draw
;
10200 /* Set help_echo_string to a help string to display for this tool-bar item.
10201 XTread_socket does the rest. */
10202 help_echo_object
= help_echo_window
= Qnil
;
10203 help_echo_pos
= -1;
10204 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10205 if (NILP (help_echo_string
))
10206 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10209 #endif /* HAVE_WINDOW_SYSTEM */
10213 /************************************************************************
10214 Horizontal scrolling
10215 ************************************************************************/
10217 static int hscroll_window_tree
P_ ((Lisp_Object
));
10218 static int hscroll_windows
P_ ((Lisp_Object
));
10220 /* For all leaf windows in the window tree rooted at WINDOW, set their
10221 hscroll value so that PT is (i) visible in the window, and (ii) so
10222 that it is not within a certain margin at the window's left and
10223 right border. Value is non-zero if any window's hscroll has been
10227 hscroll_window_tree (window
)
10228 Lisp_Object window
;
10230 int hscrolled_p
= 0;
10231 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10232 int hscroll_step_abs
= 0;
10233 double hscroll_step_rel
= 0;
10235 if (hscroll_relative_p
)
10237 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10238 if (hscroll_step_rel
< 0)
10240 hscroll_relative_p
= 0;
10241 hscroll_step_abs
= 0;
10244 else if (INTEGERP (Vhscroll_step
))
10246 hscroll_step_abs
= XINT (Vhscroll_step
);
10247 if (hscroll_step_abs
< 0)
10248 hscroll_step_abs
= 0;
10251 hscroll_step_abs
= 0;
10253 while (WINDOWP (window
))
10255 struct window
*w
= XWINDOW (window
);
10257 if (WINDOWP (w
->hchild
))
10258 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10259 else if (WINDOWP (w
->vchild
))
10260 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10261 else if (w
->cursor
.vpos
>= 0)
10264 int text_area_width
;
10265 struct glyph_row
*current_cursor_row
10266 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10267 struct glyph_row
*desired_cursor_row
10268 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10269 struct glyph_row
*cursor_row
10270 = (desired_cursor_row
->enabled_p
10271 ? desired_cursor_row
10272 : current_cursor_row
);
10274 text_area_width
= window_box_width (w
, TEXT_AREA
);
10276 /* Scroll when cursor is inside this scroll margin. */
10277 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10279 if ((XFASTINT (w
->hscroll
)
10280 && w
->cursor
.x
<= h_margin
)
10281 || (cursor_row
->enabled_p
10282 && cursor_row
->truncated_on_right_p
10283 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
10287 struct buffer
*saved_current_buffer
;
10291 /* Find point in a display of infinite width. */
10292 saved_current_buffer
= current_buffer
;
10293 current_buffer
= XBUFFER (w
->buffer
);
10295 if (w
== XWINDOW (selected_window
))
10296 pt
= BUF_PT (current_buffer
);
10299 pt
= marker_position (w
->pointm
);
10300 pt
= max (BEGV
, pt
);
10304 /* Move iterator to pt starting at cursor_row->start in
10305 a line with infinite width. */
10306 init_to_row_start (&it
, w
, cursor_row
);
10307 it
.last_visible_x
= INFINITY
;
10308 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10309 current_buffer
= saved_current_buffer
;
10311 /* Position cursor in window. */
10312 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10313 hscroll
= max (0, (it
.current_x
10314 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10315 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10316 : (text_area_width
/ 2))))
10317 / FRAME_COLUMN_WIDTH (it
.f
);
10318 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10320 if (hscroll_relative_p
)
10321 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10324 wanted_x
= text_area_width
10325 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10328 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10332 if (hscroll_relative_p
)
10333 wanted_x
= text_area_width
* hscroll_step_rel
10336 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10339 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10341 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10343 /* Don't call Fset_window_hscroll if value hasn't
10344 changed because it will prevent redisplay
10346 if (XFASTINT (w
->hscroll
) != hscroll
)
10348 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10349 w
->hscroll
= make_number (hscroll
);
10358 /* Value is non-zero if hscroll of any leaf window has been changed. */
10359 return hscrolled_p
;
10363 /* Set hscroll so that cursor is visible and not inside horizontal
10364 scroll margins for all windows in the tree rooted at WINDOW. See
10365 also hscroll_window_tree above. Value is non-zero if any window's
10366 hscroll has been changed. If it has, desired matrices on the frame
10367 of WINDOW are cleared. */
10370 hscroll_windows (window
)
10371 Lisp_Object window
;
10375 if (automatic_hscrolling_p
)
10377 hscrolled_p
= hscroll_window_tree (window
);
10379 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10383 return hscrolled_p
;
10388 /************************************************************************
10390 ************************************************************************/
10392 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10393 to a non-zero value. This is sometimes handy to have in a debugger
10398 /* First and last unchanged row for try_window_id. */
10400 int debug_first_unchanged_at_end_vpos
;
10401 int debug_last_unchanged_at_beg_vpos
;
10403 /* Delta vpos and y. */
10405 int debug_dvpos
, debug_dy
;
10407 /* Delta in characters and bytes for try_window_id. */
10409 int debug_delta
, debug_delta_bytes
;
10411 /* Values of window_end_pos and window_end_vpos at the end of
10414 EMACS_INT debug_end_pos
, debug_end_vpos
;
10416 /* Append a string to W->desired_matrix->method. FMT is a printf
10417 format string. A1...A9 are a supplement for a variable-length
10418 argument list. If trace_redisplay_p is non-zero also printf the
10419 resulting string to stderr. */
10422 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10425 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10428 char *method
= w
->desired_matrix
->method
;
10429 int len
= strlen (method
);
10430 int size
= sizeof w
->desired_matrix
->method
;
10431 int remaining
= size
- len
- 1;
10433 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10434 if (len
&& remaining
)
10437 --remaining
, ++len
;
10440 strncpy (method
+ len
, buffer
, remaining
);
10442 if (trace_redisplay_p
)
10443 fprintf (stderr
, "%p (%s): %s\n",
10445 ((BUFFERP (w
->buffer
)
10446 && STRINGP (XBUFFER (w
->buffer
)->name
))
10447 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10452 #endif /* GLYPH_DEBUG */
10455 /* Value is non-zero if all changes in window W, which displays
10456 current_buffer, are in the text between START and END. START is a
10457 buffer position, END is given as a distance from Z. Used in
10458 redisplay_internal for display optimization. */
10461 text_outside_line_unchanged_p (w
, start
, end
)
10465 int unchanged_p
= 1;
10467 /* If text or overlays have changed, see where. */
10468 if (XFASTINT (w
->last_modified
) < MODIFF
10469 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10471 /* Gap in the line? */
10472 if (GPT
< start
|| Z
- GPT
< end
)
10475 /* Changes start in front of the line, or end after it? */
10477 && (BEG_UNCHANGED
< start
- 1
10478 || END_UNCHANGED
< end
))
10481 /* If selective display, can't optimize if changes start at the
10482 beginning of the line. */
10484 && INTEGERP (current_buffer
->selective_display
)
10485 && XINT (current_buffer
->selective_display
) > 0
10486 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10489 /* If there are overlays at the start or end of the line, these
10490 may have overlay strings with newlines in them. A change at
10491 START, for instance, may actually concern the display of such
10492 overlay strings as well, and they are displayed on different
10493 lines. So, quickly rule out this case. (For the future, it
10494 might be desirable to implement something more telling than
10495 just BEG/END_UNCHANGED.) */
10498 if (BEG
+ BEG_UNCHANGED
== start
10499 && overlay_touches_p (start
))
10501 if (END_UNCHANGED
== end
10502 && overlay_touches_p (Z
- end
))
10507 return unchanged_p
;
10511 /* Do a frame update, taking possible shortcuts into account. This is
10512 the main external entry point for redisplay.
10514 If the last redisplay displayed an echo area message and that message
10515 is no longer requested, we clear the echo area or bring back the
10516 mini-buffer if that is in use. */
10521 redisplay_internal (0);
10526 overlay_arrow_string_or_property (var
)
10531 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10534 return Voverlay_arrow_string
;
10537 /* Return 1 if there are any overlay-arrows in current_buffer. */
10539 overlay_arrow_in_current_buffer_p ()
10543 for (vlist
= Voverlay_arrow_variable_list
;
10545 vlist
= XCDR (vlist
))
10547 Lisp_Object var
= XCAR (vlist
);
10550 if (!SYMBOLP (var
))
10552 val
= find_symbol_value (var
);
10554 && current_buffer
== XMARKER (val
)->buffer
)
10561 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
10565 overlay_arrows_changed_p ()
10569 for (vlist
= Voverlay_arrow_variable_list
;
10571 vlist
= XCDR (vlist
))
10573 Lisp_Object var
= XCAR (vlist
);
10574 Lisp_Object val
, pstr
;
10576 if (!SYMBOLP (var
))
10578 val
= find_symbol_value (var
);
10579 if (!MARKERP (val
))
10581 if (! EQ (COERCE_MARKER (val
),
10582 Fget (var
, Qlast_arrow_position
))
10583 || ! (pstr
= overlay_arrow_string_or_property (var
),
10584 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
10590 /* Mark overlay arrows to be updated on next redisplay. */
10593 update_overlay_arrows (up_to_date
)
10598 for (vlist
= Voverlay_arrow_variable_list
;
10600 vlist
= XCDR (vlist
))
10602 Lisp_Object var
= XCAR (vlist
);
10604 if (!SYMBOLP (var
))
10607 if (up_to_date
> 0)
10609 Lisp_Object val
= find_symbol_value (var
);
10610 Fput (var
, Qlast_arrow_position
,
10611 COERCE_MARKER (val
));
10612 Fput (var
, Qlast_arrow_string
,
10613 overlay_arrow_string_or_property (var
));
10615 else if (up_to_date
< 0
10616 || !NILP (Fget (var
, Qlast_arrow_position
)))
10618 Fput (var
, Qlast_arrow_position
, Qt
);
10619 Fput (var
, Qlast_arrow_string
, Qt
);
10625 /* Return overlay arrow string to display at row.
10626 Return integer (bitmap number) for arrow bitmap in left fringe.
10627 Return nil if no overlay arrow. */
10630 overlay_arrow_at_row (it
, row
)
10632 struct glyph_row
*row
;
10636 for (vlist
= Voverlay_arrow_variable_list
;
10638 vlist
= XCDR (vlist
))
10640 Lisp_Object var
= XCAR (vlist
);
10643 if (!SYMBOLP (var
))
10646 val
= find_symbol_value (var
);
10649 && current_buffer
== XMARKER (val
)->buffer
10650 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10652 if (FRAME_WINDOW_P (it
->f
)
10653 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10655 #ifdef HAVE_WINDOW_SYSTEM
10656 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10659 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10660 return make_number (fringe_bitmap
);
10663 return make_number (-1); /* Use default arrow bitmap */
10665 return overlay_arrow_string_or_property (var
);
10672 /* Return 1 if point moved out of or into a composition. Otherwise
10673 return 0. PREV_BUF and PREV_PT are the last point buffer and
10674 position. BUF and PT are the current point buffer and position. */
10677 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10678 struct buffer
*prev_buf
, *buf
;
10683 Lisp_Object buffer
;
10685 XSETBUFFER (buffer
, buf
);
10686 /* Check a composition at the last point if point moved within the
10688 if (prev_buf
== buf
)
10691 /* Point didn't move. */
10694 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10695 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10696 && COMPOSITION_VALID_P (start
, end
, prop
)
10697 && start
< prev_pt
&& end
> prev_pt
)
10698 /* The last point was within the composition. Return 1 iff
10699 point moved out of the composition. */
10700 return (pt
<= start
|| pt
>= end
);
10703 /* Check a composition at the current point. */
10704 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10705 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10706 && COMPOSITION_VALID_P (start
, end
, prop
)
10707 && start
< pt
&& end
> pt
);
10711 /* Reconsider the setting of B->clip_changed which is displayed
10715 reconsider_clip_changes (w
, b
)
10719 if (b
->clip_changed
10720 && !NILP (w
->window_end_valid
)
10721 && w
->current_matrix
->buffer
== b
10722 && w
->current_matrix
->zv
== BUF_ZV (b
)
10723 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10724 b
->clip_changed
= 0;
10726 /* If display wasn't paused, and W is not a tool bar window, see if
10727 point has been moved into or out of a composition. In that case,
10728 we set b->clip_changed to 1 to force updating the screen. If
10729 b->clip_changed has already been set to 1, we can skip this
10731 if (!b
->clip_changed
10732 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10736 if (w
== XWINDOW (selected_window
))
10737 pt
= BUF_PT (current_buffer
);
10739 pt
= marker_position (w
->pointm
);
10741 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10742 || pt
!= XINT (w
->last_point
))
10743 && check_point_in_composition (w
->current_matrix
->buffer
,
10744 XINT (w
->last_point
),
10745 XBUFFER (w
->buffer
), pt
))
10746 b
->clip_changed
= 1;
10751 /* Select FRAME to forward the values of frame-local variables into C
10752 variables so that the redisplay routines can access those values
10756 select_frame_for_redisplay (frame
)
10759 Lisp_Object tail
, sym
, val
;
10760 Lisp_Object old
= selected_frame
;
10762 selected_frame
= frame
;
10764 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10765 if (CONSP (XCAR (tail
))
10766 && (sym
= XCAR (XCAR (tail
)),
10768 && (sym
= indirect_variable (sym
),
10769 val
= SYMBOL_VALUE (sym
),
10770 (BUFFER_LOCAL_VALUEP (val
)
10771 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10772 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10773 /* Use find_symbol_value rather than Fsymbol_value
10774 to avoid an error if it is void. */
10775 find_symbol_value (sym
);
10777 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10778 if (CONSP (XCAR (tail
))
10779 && (sym
= XCAR (XCAR (tail
)),
10781 && (sym
= indirect_variable (sym
),
10782 val
= SYMBOL_VALUE (sym
),
10783 (BUFFER_LOCAL_VALUEP (val
)
10784 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10785 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10786 find_symbol_value (sym
);
10790 #define STOP_POLLING \
10791 do { if (! polling_stopped_here) stop_polling (); \
10792 polling_stopped_here = 1; } while (0)
10794 #define RESUME_POLLING \
10795 do { if (polling_stopped_here) start_polling (); \
10796 polling_stopped_here = 0; } while (0)
10799 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10800 response to any user action; therefore, we should preserve the echo
10801 area. (Actually, our caller does that job.) Perhaps in the future
10802 avoid recentering windows if it is not necessary; currently that
10803 causes some problems. */
10806 redisplay_internal (preserve_echo_area
)
10807 int preserve_echo_area
;
10809 struct window
*w
= XWINDOW (selected_window
);
10812 int must_finish
= 0;
10813 struct text_pos tlbufpos
, tlendpos
;
10814 int number_of_visible_frames
;
10817 int polling_stopped_here
= 0;
10819 /* Non-zero means redisplay has to consider all windows on all
10820 frames. Zero means, only selected_window is considered. */
10821 int consider_all_windows_p
;
10823 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10825 /* No redisplay if running in batch mode or frame is not yet fully
10826 initialized, or redisplay is explicitly turned off by setting
10827 Vinhibit_redisplay. */
10829 || !NILP (Vinhibit_redisplay
))
10832 /* Don't examine these until after testing Vinhibit_redisplay.
10833 When Emacs is shutting down, perhaps because its connection to
10834 X has dropped, we should not look at them at all. */
10835 f
= XFRAME (w
->frame
);
10836 sf
= SELECTED_FRAME ();
10838 if (!f
->glyphs_initialized_p
)
10841 /* The flag redisplay_performed_directly_p is set by
10842 direct_output_for_insert when it already did the whole screen
10843 update necessary. */
10844 if (redisplay_performed_directly_p
)
10846 redisplay_performed_directly_p
= 0;
10847 if (!hscroll_windows (selected_window
))
10851 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
10852 if (popup_activated ())
10856 /* I don't think this happens but let's be paranoid. */
10857 if (redisplaying_p
)
10860 /* Record a function that resets redisplaying_p to its old value
10861 when we leave this function. */
10862 count
= SPECPDL_INDEX ();
10863 record_unwind_protect (unwind_redisplay
,
10864 Fcons (make_number (redisplaying_p
), selected_frame
));
10866 specbind (Qinhibit_free_realized_faces
, Qnil
);
10869 Lisp_Object tail
, frame
;
10871 FOR_EACH_FRAME (tail
, frame
)
10873 struct frame
*f
= XFRAME (frame
);
10874 f
->already_hscrolled_p
= 0;
10880 reconsider_clip_changes (w
, current_buffer
);
10881 last_escape_glyph_frame
= NULL
;
10882 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
10884 /* If new fonts have been loaded that make a glyph matrix adjustment
10885 necessary, do it. */
10886 if (fonts_changed_p
)
10888 adjust_glyphs (NULL
);
10889 ++windows_or_buffers_changed
;
10890 fonts_changed_p
= 0;
10893 /* If face_change_count is non-zero, init_iterator will free all
10894 realized faces, which includes the faces referenced from current
10895 matrices. So, we can't reuse current matrices in this case. */
10896 if (face_change_count
)
10897 ++windows_or_buffers_changed
;
10899 if (! FRAME_WINDOW_P (sf
)
10900 && previous_terminal_frame
!= sf
)
10902 /* Since frames on an ASCII terminal share the same display
10903 area, displaying a different frame means redisplay the whole
10905 windows_or_buffers_changed
++;
10906 SET_FRAME_GARBAGED (sf
);
10907 XSETFRAME (Vterminal_frame
, sf
);
10909 previous_terminal_frame
= sf
;
10911 /* Set the visible flags for all frames. Do this before checking
10912 for resized or garbaged frames; they want to know if their frames
10913 are visible. See the comment in frame.h for
10914 FRAME_SAMPLE_VISIBILITY. */
10916 Lisp_Object tail
, frame
;
10918 number_of_visible_frames
= 0;
10920 FOR_EACH_FRAME (tail
, frame
)
10922 struct frame
*f
= XFRAME (frame
);
10924 FRAME_SAMPLE_VISIBILITY (f
);
10925 if (FRAME_VISIBLE_P (f
))
10926 ++number_of_visible_frames
;
10927 clear_desired_matrices (f
);
10931 /* Notice any pending interrupt request to change frame size. */
10932 do_pending_window_change (1);
10934 /* Clear frames marked as garbaged. */
10935 if (frame_garbaged
)
10936 clear_garbaged_frames ();
10938 /* Build menubar and tool-bar items. */
10939 if (NILP (Vmemory_full
))
10940 prepare_menu_bars ();
10942 if (windows_or_buffers_changed
)
10943 update_mode_lines
++;
10945 /* Detect case that we need to write or remove a star in the mode line. */
10946 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10948 w
->update_mode_line
= Qt
;
10949 if (buffer_shared
> 1)
10950 update_mode_lines
++;
10953 /* If %c is in the mode line, update it if needed. */
10954 if (!NILP (w
->column_number_displayed
)
10955 /* This alternative quickly identifies a common case
10956 where no change is needed. */
10957 && !(PT
== XFASTINT (w
->last_point
)
10958 && XFASTINT (w
->last_modified
) >= MODIFF
10959 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10960 && (XFASTINT (w
->column_number_displayed
)
10961 != (int) current_column ())) /* iftc */
10962 w
->update_mode_line
= Qt
;
10964 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10966 /* The variable buffer_shared is set in redisplay_window and
10967 indicates that we redisplay a buffer in different windows. See
10969 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
10970 || cursor_type_changed
);
10972 /* If specs for an arrow have changed, do thorough redisplay
10973 to ensure we remove any arrow that should no longer exist. */
10974 if (overlay_arrows_changed_p ())
10975 consider_all_windows_p
= windows_or_buffers_changed
= 1;
10977 /* Normally the message* functions will have already displayed and
10978 updated the echo area, but the frame may have been trashed, or
10979 the update may have been preempted, so display the echo area
10980 again here. Checking message_cleared_p captures the case that
10981 the echo area should be cleared. */
10982 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
10983 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
10984 || (message_cleared_p
10985 && minibuf_level
== 0
10986 /* If the mini-window is currently selected, this means the
10987 echo-area doesn't show through. */
10988 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
10990 int window_height_changed_p
= echo_area_display (0);
10993 /* If we don't display the current message, don't clear the
10994 message_cleared_p flag, because, if we did, we wouldn't clear
10995 the echo area in the next redisplay which doesn't preserve
10997 if (!display_last_displayed_message_p
)
10998 message_cleared_p
= 0;
11000 if (fonts_changed_p
)
11002 else if (window_height_changed_p
)
11004 consider_all_windows_p
= 1;
11005 ++update_mode_lines
;
11006 ++windows_or_buffers_changed
;
11008 /* If window configuration was changed, frames may have been
11009 marked garbaged. Clear them or we will experience
11010 surprises wrt scrolling. */
11011 if (frame_garbaged
)
11012 clear_garbaged_frames ();
11015 else if (EQ (selected_window
, minibuf_window
)
11016 && (current_buffer
->clip_changed
11017 || XFASTINT (w
->last_modified
) < MODIFF
11018 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11019 && resize_mini_window (w
, 0))
11021 /* Resized active mini-window to fit the size of what it is
11022 showing if its contents might have changed. */
11024 consider_all_windows_p
= 1;
11025 ++windows_or_buffers_changed
;
11026 ++update_mode_lines
;
11028 /* If window configuration was changed, frames may have been
11029 marked garbaged. Clear them or we will experience
11030 surprises wrt scrolling. */
11031 if (frame_garbaged
)
11032 clear_garbaged_frames ();
11036 /* If showing the region, and mark has changed, we must redisplay
11037 the whole window. The assignment to this_line_start_pos prevents
11038 the optimization directly below this if-statement. */
11039 if (((!NILP (Vtransient_mark_mode
)
11040 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11041 != !NILP (w
->region_showing
))
11042 || (!NILP (w
->region_showing
)
11043 && !EQ (w
->region_showing
,
11044 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11045 CHARPOS (this_line_start_pos
) = 0;
11047 /* Optimize the case that only the line containing the cursor in the
11048 selected window has changed. Variables starting with this_ are
11049 set in display_line and record information about the line
11050 containing the cursor. */
11051 tlbufpos
= this_line_start_pos
;
11052 tlendpos
= this_line_end_pos
;
11053 if (!consider_all_windows_p
11054 && CHARPOS (tlbufpos
) > 0
11055 && NILP (w
->update_mode_line
)
11056 && !current_buffer
->clip_changed
11057 && !current_buffer
->prevent_redisplay_optimizations_p
11058 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11059 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11060 /* Make sure recorded data applies to current buffer, etc. */
11061 && this_line_buffer
== current_buffer
11062 && current_buffer
== XBUFFER (w
->buffer
)
11063 && NILP (w
->force_start
)
11064 && NILP (w
->optional_new_start
)
11065 /* Point must be on the line that we have info recorded about. */
11066 && PT
>= CHARPOS (tlbufpos
)
11067 && PT
<= Z
- CHARPOS (tlendpos
)
11068 /* All text outside that line, including its final newline,
11069 must be unchanged */
11070 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11071 CHARPOS (tlendpos
)))
11073 if (CHARPOS (tlbufpos
) > BEGV
11074 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11075 && (CHARPOS (tlbufpos
) == ZV
11076 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11077 /* Former continuation line has disappeared by becoming empty */
11079 else if (XFASTINT (w
->last_modified
) < MODIFF
11080 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11081 || MINI_WINDOW_P (w
))
11083 /* We have to handle the case of continuation around a
11084 wide-column character (See the comment in indent.c around
11087 For instance, in the following case:
11089 -------- Insert --------
11090 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11091 J_I_ ==> J_I_ `^^' are cursors.
11095 As we have to redraw the line above, we should goto cancel. */
11098 int line_height_before
= this_line_pixel_height
;
11100 /* Note that start_display will handle the case that the
11101 line starting at tlbufpos is a continuation lines. */
11102 start_display (&it
, w
, tlbufpos
);
11104 /* Implementation note: It this still necessary? */
11105 if (it
.current_x
!= this_line_start_x
)
11108 TRACE ((stderr
, "trying display optimization 1\n"));
11109 w
->cursor
.vpos
= -1;
11110 overlay_arrow_seen
= 0;
11111 it
.vpos
= this_line_vpos
;
11112 it
.current_y
= this_line_y
;
11113 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11114 display_line (&it
);
11116 /* If line contains point, is not continued,
11117 and ends at same distance from eob as before, we win */
11118 if (w
->cursor
.vpos
>= 0
11119 /* Line is not continued, otherwise this_line_start_pos
11120 would have been set to 0 in display_line. */
11121 && CHARPOS (this_line_start_pos
)
11122 /* Line ends as before. */
11123 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11124 /* Line has same height as before. Otherwise other lines
11125 would have to be shifted up or down. */
11126 && this_line_pixel_height
== line_height_before
)
11128 /* If this is not the window's last line, we must adjust
11129 the charstarts of the lines below. */
11130 if (it
.current_y
< it
.last_visible_y
)
11132 struct glyph_row
*row
11133 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11134 int delta
, delta_bytes
;
11136 if (Z
- CHARPOS (tlendpos
) == ZV
)
11138 /* This line ends at end of (accessible part of)
11139 buffer. There is no newline to count. */
11141 - CHARPOS (tlendpos
)
11142 - MATRIX_ROW_START_CHARPOS (row
));
11143 delta_bytes
= (Z_BYTE
11144 - BYTEPOS (tlendpos
)
11145 - MATRIX_ROW_START_BYTEPOS (row
));
11149 /* This line ends in a newline. Must take
11150 account of the newline and the rest of the
11151 text that follows. */
11153 - CHARPOS (tlendpos
)
11154 - MATRIX_ROW_START_CHARPOS (row
));
11155 delta_bytes
= (Z_BYTE
11156 - BYTEPOS (tlendpos
)
11157 - MATRIX_ROW_START_BYTEPOS (row
));
11160 increment_matrix_positions (w
->current_matrix
,
11161 this_line_vpos
+ 1,
11162 w
->current_matrix
->nrows
,
11163 delta
, delta_bytes
);
11166 /* If this row displays text now but previously didn't,
11167 or vice versa, w->window_end_vpos may have to be
11169 if ((it
.glyph_row
- 1)->displays_text_p
)
11171 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11172 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11174 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11175 && this_line_vpos
> 0)
11176 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11177 w
->window_end_valid
= Qnil
;
11179 /* Update hint: No need to try to scroll in update_window. */
11180 w
->desired_matrix
->no_scrolling_p
= 1;
11183 *w
->desired_matrix
->method
= 0;
11184 debug_method_add (w
, "optimization 1");
11186 #ifdef HAVE_WINDOW_SYSTEM
11187 update_window_fringes (w
, 0);
11194 else if (/* Cursor position hasn't changed. */
11195 PT
== XFASTINT (w
->last_point
)
11196 /* Make sure the cursor was last displayed
11197 in this window. Otherwise we have to reposition it. */
11198 && 0 <= w
->cursor
.vpos
11199 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11203 do_pending_window_change (1);
11205 /* We used to always goto end_of_redisplay here, but this
11206 isn't enough if we have a blinking cursor. */
11207 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11208 goto end_of_redisplay
;
11212 /* If highlighting the region, or if the cursor is in the echo area,
11213 then we can't just move the cursor. */
11214 else if (! (!NILP (Vtransient_mark_mode
)
11215 && !NILP (current_buffer
->mark_active
))
11216 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11217 || highlight_nonselected_windows
)
11218 && NILP (w
->region_showing
)
11219 && NILP (Vshow_trailing_whitespace
)
11220 && !cursor_in_echo_area
)
11223 struct glyph_row
*row
;
11225 /* Skip from tlbufpos to PT and see where it is. Note that
11226 PT may be in invisible text. If so, we will end at the
11227 next visible position. */
11228 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11229 NULL
, DEFAULT_FACE_ID
);
11230 it
.current_x
= this_line_start_x
;
11231 it
.current_y
= this_line_y
;
11232 it
.vpos
= this_line_vpos
;
11234 /* The call to move_it_to stops in front of PT, but
11235 moves over before-strings. */
11236 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11238 if (it
.vpos
== this_line_vpos
11239 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11242 xassert (this_line_vpos
== it
.vpos
);
11243 xassert (this_line_y
== it
.current_y
);
11244 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11246 *w
->desired_matrix
->method
= 0;
11247 debug_method_add (w
, "optimization 3");
11256 /* Text changed drastically or point moved off of line. */
11257 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11260 CHARPOS (this_line_start_pos
) = 0;
11261 consider_all_windows_p
|= buffer_shared
> 1;
11262 ++clear_face_cache_count
;
11263 #ifdef HAVE_WINDOW_SYSTEM
11264 ++clear_image_cache_count
;
11267 /* Build desired matrices, and update the display. If
11268 consider_all_windows_p is non-zero, do it for all windows on all
11269 frames. Otherwise do it for selected_window, only. */
11271 if (consider_all_windows_p
)
11273 Lisp_Object tail
, frame
;
11275 FOR_EACH_FRAME (tail
, frame
)
11276 XFRAME (frame
)->updated_p
= 0;
11278 /* Recompute # windows showing selected buffer. This will be
11279 incremented each time such a window is displayed. */
11282 FOR_EACH_FRAME (tail
, frame
)
11284 struct frame
*f
= XFRAME (frame
);
11286 if (FRAME_WINDOW_P (f
) || f
== sf
)
11288 if (! EQ (frame
, selected_frame
))
11289 /* Select the frame, for the sake of frame-local
11291 select_frame_for_redisplay (frame
);
11293 /* Mark all the scroll bars to be removed; we'll redeem
11294 the ones we want when we redisplay their windows. */
11295 if (condemn_scroll_bars_hook
)
11296 condemn_scroll_bars_hook (f
);
11298 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11299 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11301 /* Any scroll bars which redisplay_windows should have
11302 nuked should now go away. */
11303 if (judge_scroll_bars_hook
)
11304 judge_scroll_bars_hook (f
);
11306 /* If fonts changed, display again. */
11307 /* ??? rms: I suspect it is a mistake to jump all the way
11308 back to retry here. It should just retry this frame. */
11309 if (fonts_changed_p
)
11312 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11314 /* See if we have to hscroll. */
11315 if (!f
->already_hscrolled_p
)
11317 f
->already_hscrolled_p
= 1;
11318 if (hscroll_windows (f
->root_window
))
11322 /* Prevent various kinds of signals during display
11323 update. stdio is not robust about handling
11324 signals, which can cause an apparent I/O
11326 if (interrupt_input
)
11327 unrequest_sigio ();
11330 /* Update the display. */
11331 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11332 pause
|= update_frame (f
, 0, 0);
11333 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
11345 /* Do the mark_window_display_accurate after all windows have
11346 been redisplayed because this call resets flags in buffers
11347 which are needed for proper redisplay. */
11348 FOR_EACH_FRAME (tail
, frame
)
11350 struct frame
*f
= XFRAME (frame
);
11353 mark_window_display_accurate (f
->root_window
, 1);
11354 if (frame_up_to_date_hook
)
11355 frame_up_to_date_hook (f
);
11360 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11362 Lisp_Object mini_window
;
11363 struct frame
*mini_frame
;
11365 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11366 /* Use list_of_error, not Qerror, so that
11367 we catch only errors and don't run the debugger. */
11368 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11370 redisplay_window_error
);
11372 /* Compare desired and current matrices, perform output. */
11375 /* If fonts changed, display again. */
11376 if (fonts_changed_p
)
11379 /* Prevent various kinds of signals during display update.
11380 stdio is not robust about handling signals,
11381 which can cause an apparent I/O error. */
11382 if (interrupt_input
)
11383 unrequest_sigio ();
11386 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11388 if (hscroll_windows (selected_window
))
11391 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11392 pause
= update_frame (sf
, 0, 0);
11395 /* We may have called echo_area_display at the top of this
11396 function. If the echo area is on another frame, that may
11397 have put text on a frame other than the selected one, so the
11398 above call to update_frame would not have caught it. Catch
11400 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11401 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11403 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11405 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11406 pause
|= update_frame (mini_frame
, 0, 0);
11407 if (!pause
&& hscroll_windows (mini_window
))
11412 /* If display was paused because of pending input, make sure we do a
11413 thorough update the next time. */
11416 /* Prevent the optimization at the beginning of
11417 redisplay_internal that tries a single-line update of the
11418 line containing the cursor in the selected window. */
11419 CHARPOS (this_line_start_pos
) = 0;
11421 /* Let the overlay arrow be updated the next time. */
11422 update_overlay_arrows (0);
11424 /* If we pause after scrolling, some rows in the current
11425 matrices of some windows are not valid. */
11426 if (!WINDOW_FULL_WIDTH_P (w
)
11427 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11428 update_mode_lines
= 1;
11432 if (!consider_all_windows_p
)
11434 /* This has already been done above if
11435 consider_all_windows_p is set. */
11436 mark_window_display_accurate_1 (w
, 1);
11438 /* Say overlay arrows are up to date. */
11439 update_overlay_arrows (1);
11441 if (frame_up_to_date_hook
!= 0)
11442 frame_up_to_date_hook (sf
);
11445 update_mode_lines
= 0;
11446 windows_or_buffers_changed
= 0;
11447 cursor_type_changed
= 0;
11450 /* Start SIGIO interrupts coming again. Having them off during the
11451 code above makes it less likely one will discard output, but not
11452 impossible, since there might be stuff in the system buffer here.
11453 But it is much hairier to try to do anything about that. */
11454 if (interrupt_input
)
11458 /* If a frame has become visible which was not before, redisplay
11459 again, so that we display it. Expose events for such a frame
11460 (which it gets when becoming visible) don't call the parts of
11461 redisplay constructing glyphs, so simply exposing a frame won't
11462 display anything in this case. So, we have to display these
11463 frames here explicitly. */
11466 Lisp_Object tail
, frame
;
11469 FOR_EACH_FRAME (tail
, frame
)
11471 int this_is_visible
= 0;
11473 if (XFRAME (frame
)->visible
)
11474 this_is_visible
= 1;
11475 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11476 if (XFRAME (frame
)->visible
)
11477 this_is_visible
= 1;
11479 if (this_is_visible
)
11483 if (new_count
!= number_of_visible_frames
)
11484 windows_or_buffers_changed
++;
11487 /* Change frame size now if a change is pending. */
11488 do_pending_window_change (1);
11490 /* If we just did a pending size change, or have additional
11491 visible frames, redisplay again. */
11492 if (windows_or_buffers_changed
&& !pause
)
11495 /* Clear the face cache eventually. */
11496 if (consider_all_windows_p
)
11498 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11500 clear_face_cache (0);
11501 clear_face_cache_count
= 0;
11503 #ifdef HAVE_WINDOW_SYSTEM
11504 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11506 Lisp_Object tail
, frame
;
11507 FOR_EACH_FRAME (tail
, frame
)
11509 struct frame
*f
= XFRAME (frame
);
11510 if (FRAME_WINDOW_P (f
))
11511 clear_image_cache (f
, 0);
11513 clear_image_cache_count
= 0;
11515 #endif /* HAVE_WINDOW_SYSTEM */
11519 unbind_to (count
, Qnil
);
11524 /* Redisplay, but leave alone any recent echo area message unless
11525 another message has been requested in its place.
11527 This is useful in situations where you need to redisplay but no
11528 user action has occurred, making it inappropriate for the message
11529 area to be cleared. See tracking_off and
11530 wait_reading_process_output for examples of these situations.
11532 FROM_WHERE is an integer saying from where this function was
11533 called. This is useful for debugging. */
11536 redisplay_preserve_echo_area (from_where
)
11539 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
11541 if (!NILP (echo_area_buffer
[1]))
11543 /* We have a previously displayed message, but no current
11544 message. Redisplay the previous message. */
11545 display_last_displayed_message_p
= 1;
11546 redisplay_internal (1);
11547 display_last_displayed_message_p
= 0;
11550 redisplay_internal (1);
11552 if (rif
!= NULL
&& rif
->flush_display_optional
)
11553 rif
->flush_display_optional (NULL
);
11557 /* Function registered with record_unwind_protect in
11558 redisplay_internal. Reset redisplaying_p to the value it had
11559 before redisplay_internal was called, and clear
11560 prevent_freeing_realized_faces_p. It also selects the previously
11564 unwind_redisplay (val
)
11567 Lisp_Object old_redisplaying_p
, old_frame
;
11569 old_redisplaying_p
= XCAR (val
);
11570 redisplaying_p
= XFASTINT (old_redisplaying_p
);
11571 old_frame
= XCDR (val
);
11572 if (! EQ (old_frame
, selected_frame
))
11573 select_frame_for_redisplay (old_frame
);
11578 /* Mark the display of window W as accurate or inaccurate. If
11579 ACCURATE_P is non-zero mark display of W as accurate. If
11580 ACCURATE_P is zero, arrange for W to be redisplayed the next time
11581 redisplay_internal is called. */
11584 mark_window_display_accurate_1 (w
, accurate_p
)
11588 if (BUFFERP (w
->buffer
))
11590 struct buffer
*b
= XBUFFER (w
->buffer
);
11593 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
11594 w
->last_overlay_modified
11595 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
11597 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
11601 b
->clip_changed
= 0;
11602 b
->prevent_redisplay_optimizations_p
= 0;
11604 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
11605 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
11606 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
11607 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
11609 w
->current_matrix
->buffer
= b
;
11610 w
->current_matrix
->begv
= BUF_BEGV (b
);
11611 w
->current_matrix
->zv
= BUF_ZV (b
);
11613 w
->last_cursor
= w
->cursor
;
11614 w
->last_cursor_off_p
= w
->cursor_off_p
;
11616 if (w
== XWINDOW (selected_window
))
11617 w
->last_point
= make_number (BUF_PT (b
));
11619 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
11625 w
->window_end_valid
= w
->buffer
;
11626 #if 0 /* This is incorrect with variable-height lines. */
11627 xassert (XINT (w
->window_end_vpos
)
11628 < (WINDOW_TOTAL_LINES (w
)
11629 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
11631 w
->update_mode_line
= Qnil
;
11636 /* Mark the display of windows in the window tree rooted at WINDOW as
11637 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
11638 windows as accurate. If ACCURATE_P is zero, arrange for windows to
11639 be redisplayed the next time redisplay_internal is called. */
11642 mark_window_display_accurate (window
, accurate_p
)
11643 Lisp_Object window
;
11648 for (; !NILP (window
); window
= w
->next
)
11650 w
= XWINDOW (window
);
11651 mark_window_display_accurate_1 (w
, accurate_p
);
11653 if (!NILP (w
->vchild
))
11654 mark_window_display_accurate (w
->vchild
, accurate_p
);
11655 if (!NILP (w
->hchild
))
11656 mark_window_display_accurate (w
->hchild
, accurate_p
);
11661 update_overlay_arrows (1);
11665 /* Force a thorough redisplay the next time by setting
11666 last_arrow_position and last_arrow_string to t, which is
11667 unequal to any useful value of Voverlay_arrow_... */
11668 update_overlay_arrows (-1);
11673 /* Return value in display table DP (Lisp_Char_Table *) for character
11674 C. Since a display table doesn't have any parent, we don't have to
11675 follow parent. Do not call this function directly but use the
11676 macro DISP_CHAR_VECTOR. */
11679 disp_char_vector (dp
, c
)
11680 struct Lisp_Char_Table
*dp
;
11686 if (SINGLE_BYTE_CHAR_P (c
))
11687 return (dp
->contents
[c
]);
11689 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
11692 else if (code
[2] < 32)
11695 /* Here, the possible range of code[0] (== charset ID) is
11696 128..max_charset. Since the top level char table contains data
11697 for multibyte characters after 256th element, we must increment
11698 code[0] by 128 to get a correct index. */
11700 code
[3] = -1; /* anchor */
11702 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
11704 val
= dp
->contents
[code
[i
]];
11705 if (!SUB_CHAR_TABLE_P (val
))
11706 return (NILP (val
) ? dp
->defalt
: val
);
11709 /* Here, val is a sub char table. We return the default value of
11711 return (dp
->defalt
);
11716 /***********************************************************************
11718 ***********************************************************************/
11720 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11723 redisplay_windows (window
)
11724 Lisp_Object window
;
11726 while (!NILP (window
))
11728 struct window
*w
= XWINDOW (window
);
11730 if (!NILP (w
->hchild
))
11731 redisplay_windows (w
->hchild
);
11732 else if (!NILP (w
->vchild
))
11733 redisplay_windows (w
->vchild
);
11736 displayed_buffer
= XBUFFER (w
->buffer
);
11737 /* Use list_of_error, not Qerror, so that
11738 we catch only errors and don't run the debugger. */
11739 internal_condition_case_1 (redisplay_window_0
, window
,
11741 redisplay_window_error
);
11749 redisplay_window_error ()
11751 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11756 redisplay_window_0 (window
)
11757 Lisp_Object window
;
11759 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11760 redisplay_window (window
, 0);
11765 redisplay_window_1 (window
)
11766 Lisp_Object window
;
11768 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11769 redisplay_window (window
, 1);
11774 /* Increment GLYPH until it reaches END or CONDITION fails while
11775 adding (GLYPH)->pixel_width to X. */
11777 #define SKIP_GLYPHS(glyph, end, x, condition) \
11780 (x) += (glyph)->pixel_width; \
11783 while ((glyph) < (end) && (condition))
11786 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11787 DELTA is the number of bytes by which positions recorded in ROW
11788 differ from current buffer positions.
11790 Return 0 if cursor is not on this row. 1 otherwise. */
11793 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11795 struct glyph_row
*row
;
11796 struct glyph_matrix
*matrix
;
11797 int delta
, delta_bytes
, dy
, dvpos
;
11799 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11800 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11801 struct glyph
*cursor
= NULL
;
11802 /* The first glyph that starts a sequence of glyphs from string. */
11803 struct glyph
*string_start
;
11804 /* The X coordinate of string_start. */
11805 int string_start_x
;
11806 /* The last known character position. */
11807 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11808 /* The last known character position before string_start. */
11809 int string_before_pos
;
11812 int cursor_from_overlay_pos
= 0;
11813 int pt_old
= PT
- delta
;
11815 /* Skip over glyphs not having an object at the start of the row.
11816 These are special glyphs like truncation marks on terminal
11818 if (row
->displays_text_p
)
11820 && INTEGERP (glyph
->object
)
11821 && glyph
->charpos
< 0)
11823 x
+= glyph
->pixel_width
;
11827 string_start
= NULL
;
11829 && !INTEGERP (glyph
->object
)
11830 && (!BUFFERP (glyph
->object
)
11831 || (last_pos
= glyph
->charpos
) < pt_old
))
11833 if (! STRINGP (glyph
->object
))
11835 string_start
= NULL
;
11836 x
+= glyph
->pixel_width
;
11838 if (cursor_from_overlay_pos
11839 && last_pos
>= cursor_from_overlay_pos
)
11841 cursor_from_overlay_pos
= 0;
11847 if (string_start
== NULL
)
11849 string_before_pos
= last_pos
;
11850 string_start
= glyph
;
11851 string_start_x
= x
;
11853 /* Skip all glyphs from string. */
11858 if ((cursor
== NULL
|| glyph
> cursor
)
11859 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
11860 Qcursor
, (glyph
)->object
),
11862 && (pos
= string_buffer_position (w
, glyph
->object
,
11863 string_before_pos
),
11864 (pos
== 0 /* From overlay */
11865 || pos
== pt_old
)))
11867 /* Estimate overlay buffer position from the buffer
11868 positions of the glyphs before and after the overlay.
11869 Add 1 to last_pos so that if point corresponds to the
11870 glyph right after the overlay, we still use a 'cursor'
11871 property found in that overlay. */
11872 cursor_from_overlay_pos
= (pos
? 0 : last_pos
11873 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
11877 x
+= glyph
->pixel_width
;
11880 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
11884 if (cursor
!= NULL
)
11889 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
11891 /* Scan back over the ellipsis glyphs, decrementing positions. */
11892 while (glyph
> row
->glyphs
[TEXT_AREA
]
11893 && (glyph
- 1)->charpos
== last_pos
)
11894 glyph
--, x
-= glyph
->pixel_width
;
11895 /* That loop always goes one position too far,
11896 including the glyph before the ellipsis.
11897 So scan forward over that one. */
11898 x
+= glyph
->pixel_width
;
11901 else if (string_start
11902 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
11904 /* We may have skipped over point because the previous glyphs
11905 are from string. As there's no easy way to know the
11906 character position of the current glyph, find the correct
11907 glyph on point by scanning from string_start again. */
11909 Lisp_Object string
;
11910 struct glyph
*stop
= glyph
;
11913 limit
= make_number (pt_old
+ 1);
11914 glyph
= string_start
;
11915 x
= string_start_x
;
11916 string
= glyph
->object
;
11917 pos
= string_buffer_position (w
, string
, string_before_pos
);
11918 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
11919 because we always put cursor after overlay strings. */
11920 while (pos
== 0 && glyph
< stop
)
11922 string
= glyph
->object
;
11923 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
11925 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
11928 while (glyph
< stop
)
11930 pos
= XINT (Fnext_single_char_property_change
11931 (make_number (pos
), Qdisplay
, Qnil
, limit
));
11934 /* Skip glyphs from the same string. */
11935 string
= glyph
->object
;
11936 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
11937 /* Skip glyphs from an overlay. */
11938 while (glyph
< stop
11939 && ! string_buffer_position (w
, glyph
->object
, pos
))
11941 string
= glyph
->object
;
11942 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
11946 /* If we reached the end of the line, and end was from a string,
11947 cursor is not on this line. */
11948 if (glyph
== end
&& row
->continued_p
)
11952 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
11954 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
11955 w
->cursor
.y
= row
->y
+ dy
;
11957 if (w
== XWINDOW (selected_window
))
11959 if (!row
->continued_p
11960 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
11963 this_line_buffer
= XBUFFER (w
->buffer
);
11965 CHARPOS (this_line_start_pos
)
11966 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
11967 BYTEPOS (this_line_start_pos
)
11968 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
11970 CHARPOS (this_line_end_pos
)
11971 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
11972 BYTEPOS (this_line_end_pos
)
11973 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
11975 this_line_y
= w
->cursor
.y
;
11976 this_line_pixel_height
= row
->height
;
11977 this_line_vpos
= w
->cursor
.vpos
;
11978 this_line_start_x
= row
->x
;
11981 CHARPOS (this_line_start_pos
) = 0;
11988 /* Run window scroll functions, if any, for WINDOW with new window
11989 start STARTP. Sets the window start of WINDOW to that position.
11991 We assume that the window's buffer is really current. */
11993 static INLINE
struct text_pos
11994 run_window_scroll_functions (window
, startp
)
11995 Lisp_Object window
;
11996 struct text_pos startp
;
11998 struct window
*w
= XWINDOW (window
);
11999 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12001 if (current_buffer
!= XBUFFER (w
->buffer
))
12004 if (!NILP (Vwindow_scroll_functions
))
12006 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12007 make_number (CHARPOS (startp
)));
12008 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12009 /* In case the hook functions switch buffers. */
12010 if (current_buffer
!= XBUFFER (w
->buffer
))
12011 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12018 /* Make sure the line containing the cursor is fully visible.
12019 A value of 1 means there is nothing to be done.
12020 (Either the line is fully visible, or it cannot be made so,
12021 or we cannot tell.)
12023 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12024 is higher than window.
12026 A value of 0 means the caller should do scrolling
12027 as if point had gone off the screen. */
12030 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12033 int current_matrix_p
;
12035 struct glyph_matrix
*matrix
;
12036 struct glyph_row
*row
;
12039 if (!make_cursor_line_fully_visible_p
)
12042 /* It's not always possible to find the cursor, e.g, when a window
12043 is full of overlay strings. Don't do anything in that case. */
12044 if (w
->cursor
.vpos
< 0)
12047 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12048 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12050 /* If the cursor row is not partially visible, there's nothing to do. */
12051 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12054 /* If the row the cursor is in is taller than the window's height,
12055 it's not clear what to do, so do nothing. */
12056 window_height
= window_box_height (w
);
12057 if (row
->height
>= window_height
)
12059 if (!force_p
|| MINI_WINDOW_P (w
)
12060 || w
->vscroll
|| w
->cursor
.vpos
== 0)
12066 /* This code used to try to scroll the window just enough to make
12067 the line visible. It returned 0 to say that the caller should
12068 allocate larger glyph matrices. */
12070 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
12072 int dy
= row
->height
- row
->visible_height
;
12075 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12077 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
12079 int dy
= - (row
->height
- row
->visible_height
);
12082 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12085 /* When we change the cursor y-position of the selected window,
12086 change this_line_y as well so that the display optimization for
12087 the cursor line of the selected window in redisplay_internal uses
12088 the correct y-position. */
12089 if (w
== XWINDOW (selected_window
))
12090 this_line_y
= w
->cursor
.y
;
12092 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
12093 redisplay with larger matrices. */
12094 if (matrix
->nrows
< required_matrix_height (w
))
12096 fonts_changed_p
= 1;
12105 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
12106 non-zero means only WINDOW is redisplayed in redisplay_internal.
12107 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
12108 in redisplay_window to bring a partially visible line into view in
12109 the case that only the cursor has moved.
12111 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
12112 last screen line's vertical height extends past the end of the screen.
12116 1 if scrolling succeeded
12118 0 if scrolling didn't find point.
12120 -1 if new fonts have been loaded so that we must interrupt
12121 redisplay, adjust glyph matrices, and try again. */
12127 SCROLLING_NEED_LARGER_MATRICES
12131 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
12132 scroll_step
, temp_scroll_step
, last_line_misfit
)
12133 Lisp_Object window
;
12134 int just_this_one_p
;
12135 EMACS_INT scroll_conservatively
, scroll_step
;
12136 int temp_scroll_step
;
12137 int last_line_misfit
;
12139 struct window
*w
= XWINDOW (window
);
12140 struct frame
*f
= XFRAME (w
->frame
);
12141 struct text_pos scroll_margin_pos
;
12142 struct text_pos pos
;
12143 struct text_pos startp
;
12145 Lisp_Object window_end
;
12146 int this_scroll_margin
;
12150 int amount_to_scroll
= 0;
12151 Lisp_Object aggressive
;
12153 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
12156 debug_method_add (w
, "try_scrolling");
12159 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12161 /* Compute scroll margin height in pixels. We scroll when point is
12162 within this distance from the top or bottom of the window. */
12163 if (scroll_margin
> 0)
12165 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12166 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12169 this_scroll_margin
= 0;
12171 /* Force scroll_conservatively to have a reasonable value so it doesn't
12172 cause an overflow while computing how much to scroll. */
12173 if (scroll_conservatively
)
12174 scroll_conservatively
= min (scroll_conservatively
,
12175 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
12177 /* Compute how much we should try to scroll maximally to bring point
12179 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
12180 scroll_max
= max (scroll_step
,
12181 max (scroll_conservatively
, temp_scroll_step
));
12182 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
12183 || NUMBERP (current_buffer
->scroll_up_aggressively
))
12184 /* We're trying to scroll because of aggressive scrolling
12185 but no scroll_step is set. Choose an arbitrary one. Maybe
12186 there should be a variable for this. */
12190 scroll_max
*= FRAME_LINE_HEIGHT (f
);
12192 /* Decide whether we have to scroll down. Start at the window end
12193 and move this_scroll_margin up to find the position of the scroll
12195 window_end
= Fwindow_end (window
, Qt
);
12199 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
12200 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
12202 if (this_scroll_margin
|| extra_scroll_margin_lines
)
12204 start_display (&it
, w
, scroll_margin_pos
);
12205 if (this_scroll_margin
)
12206 move_it_vertically_backward (&it
, this_scroll_margin
);
12207 if (extra_scroll_margin_lines
)
12208 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
12209 scroll_margin_pos
= it
.current
.pos
;
12212 if (PT
>= CHARPOS (scroll_margin_pos
))
12216 /* Point is in the scroll margin at the bottom of the window, or
12217 below. Compute a new window start that makes point visible. */
12219 /* Compute the distance from the scroll margin to PT.
12220 Give up if the distance is greater than scroll_max. */
12221 start_display (&it
, w
, scroll_margin_pos
);
12223 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12224 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12226 /* To make point visible, we have to move the window start
12227 down so that the line the cursor is in is visible, which
12228 means we have to add in the height of the cursor line. */
12229 dy
= line_bottom_y (&it
) - y0
;
12231 if (dy
> scroll_max
)
12232 return SCROLLING_FAILED
;
12234 /* Move the window start down. If scrolling conservatively,
12235 move it just enough down to make point visible. If
12236 scroll_step is set, move it down by scroll_step. */
12237 start_display (&it
, w
, startp
);
12239 if (scroll_conservatively
)
12240 /* Set AMOUNT_TO_SCROLL to at least one line,
12241 and at most scroll_conservatively lines. */
12243 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12244 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12245 else if (scroll_step
|| temp_scroll_step
)
12246 amount_to_scroll
= scroll_max
;
12249 aggressive
= current_buffer
->scroll_up_aggressively
;
12250 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12251 if (NUMBERP (aggressive
))
12253 double float_amount
= XFLOATINT (aggressive
) * height
;
12254 amount_to_scroll
= float_amount
;
12255 if (amount_to_scroll
== 0 && float_amount
> 0)
12256 amount_to_scroll
= 1;
12260 if (amount_to_scroll
<= 0)
12261 return SCROLLING_FAILED
;
12263 /* If moving by amount_to_scroll leaves STARTP unchanged,
12264 move it down one screen line. */
12266 move_it_vertically (&it
, amount_to_scroll
);
12267 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12268 move_it_by_lines (&it
, 1, 1);
12269 startp
= it
.current
.pos
;
12273 /* See if point is inside the scroll margin at the top of the
12275 scroll_margin_pos
= startp
;
12276 if (this_scroll_margin
)
12278 start_display (&it
, w
, startp
);
12279 move_it_vertically (&it
, this_scroll_margin
);
12280 scroll_margin_pos
= it
.current
.pos
;
12283 if (PT
< CHARPOS (scroll_margin_pos
))
12285 /* Point is in the scroll margin at the top of the window or
12286 above what is displayed in the window. */
12289 /* Compute the vertical distance from PT to the scroll
12290 margin position. Give up if distance is greater than
12292 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12293 start_display (&it
, w
, pos
);
12295 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12296 it
.last_visible_y
, -1,
12297 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12298 dy
= it
.current_y
- y0
;
12299 if (dy
> scroll_max
)
12300 return SCROLLING_FAILED
;
12302 /* Compute new window start. */
12303 start_display (&it
, w
, startp
);
12305 if (scroll_conservatively
)
12307 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12308 else if (scroll_step
|| temp_scroll_step
)
12309 amount_to_scroll
= scroll_max
;
12312 aggressive
= current_buffer
->scroll_down_aggressively
;
12313 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12314 if (NUMBERP (aggressive
))
12316 double float_amount
= XFLOATINT (aggressive
) * height
;
12317 amount_to_scroll
= float_amount
;
12318 if (amount_to_scroll
== 0 && float_amount
> 0)
12319 amount_to_scroll
= 1;
12323 if (amount_to_scroll
<= 0)
12324 return SCROLLING_FAILED
;
12326 move_it_vertically_backward (&it
, amount_to_scroll
);
12327 startp
= it
.current
.pos
;
12331 /* Run window scroll functions. */
12332 startp
= run_window_scroll_functions (window
, startp
);
12334 /* Display the window. Give up if new fonts are loaded, or if point
12336 if (!try_window (window
, startp
, 0))
12337 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12338 else if (w
->cursor
.vpos
< 0)
12340 clear_glyph_matrix (w
->desired_matrix
);
12341 rc
= SCROLLING_FAILED
;
12345 /* Maybe forget recorded base line for line number display. */
12346 if (!just_this_one_p
12347 || current_buffer
->clip_changed
12348 || BEG_UNCHANGED
< CHARPOS (startp
))
12349 w
->base_line_number
= Qnil
;
12351 /* If cursor ends up on a partially visible line,
12352 treat that as being off the bottom of the screen. */
12353 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12355 clear_glyph_matrix (w
->desired_matrix
);
12356 ++extra_scroll_margin_lines
;
12359 rc
= SCROLLING_SUCCESS
;
12366 /* Compute a suitable window start for window W if display of W starts
12367 on a continuation line. Value is non-zero if a new window start
12370 The new window start will be computed, based on W's width, starting
12371 from the start of the continued line. It is the start of the
12372 screen line with the minimum distance from the old start W->start. */
12375 compute_window_start_on_continuation_line (w
)
12378 struct text_pos pos
, start_pos
;
12379 int window_start_changed_p
= 0;
12381 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12383 /* If window start is on a continuation line... Window start may be
12384 < BEGV in case there's invisible text at the start of the
12385 buffer (M-x rmail, for example). */
12386 if (CHARPOS (start_pos
) > BEGV
12387 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12390 struct glyph_row
*row
;
12392 /* Handle the case that the window start is out of range. */
12393 if (CHARPOS (start_pos
) < BEGV
)
12394 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12395 else if (CHARPOS (start_pos
) > ZV
)
12396 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12398 /* Find the start of the continued line. This should be fast
12399 because scan_buffer is fast (newline cache). */
12400 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12401 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12402 row
, DEFAULT_FACE_ID
);
12403 reseat_at_previous_visible_line_start (&it
);
12405 /* If the line start is "too far" away from the window start,
12406 say it takes too much time to compute a new window start. */
12407 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12408 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12410 int min_distance
, distance
;
12412 /* Move forward by display lines to find the new window
12413 start. If window width was enlarged, the new start can
12414 be expected to be > the old start. If window width was
12415 decreased, the new window start will be < the old start.
12416 So, we're looking for the display line start with the
12417 minimum distance from the old window start. */
12418 pos
= it
.current
.pos
;
12419 min_distance
= INFINITY
;
12420 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12421 distance
< min_distance
)
12423 min_distance
= distance
;
12424 pos
= it
.current
.pos
;
12425 move_it_by_lines (&it
, 1, 0);
12428 /* Set the window start there. */
12429 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12430 window_start_changed_p
= 1;
12434 return window_start_changed_p
;
12438 /* Try cursor movement in case text has not changed in window WINDOW,
12439 with window start STARTP. Value is
12441 CURSOR_MOVEMENT_SUCCESS if successful
12443 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12445 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12446 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12447 we want to scroll as if scroll-step were set to 1. See the code.
12449 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12450 which case we have to abort this redisplay, and adjust matrices
12455 CURSOR_MOVEMENT_SUCCESS
,
12456 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12457 CURSOR_MOVEMENT_MUST_SCROLL
,
12458 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12462 try_cursor_movement (window
, startp
, scroll_step
)
12463 Lisp_Object window
;
12464 struct text_pos startp
;
12467 struct window
*w
= XWINDOW (window
);
12468 struct frame
*f
= XFRAME (w
->frame
);
12469 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12472 if (inhibit_try_cursor_movement
)
12476 /* Handle case where text has not changed, only point, and it has
12477 not moved off the frame. */
12478 if (/* Point may be in this window. */
12479 PT
>= CHARPOS (startp
)
12480 /* Selective display hasn't changed. */
12481 && !current_buffer
->clip_changed
12482 /* Function force-mode-line-update is used to force a thorough
12483 redisplay. It sets either windows_or_buffers_changed or
12484 update_mode_lines. So don't take a shortcut here for these
12486 && !update_mode_lines
12487 && !windows_or_buffers_changed
12488 && !cursor_type_changed
12489 /* Can't use this case if highlighting a region. When a
12490 region exists, cursor movement has to do more than just
12492 && !(!NILP (Vtransient_mark_mode
)
12493 && !NILP (current_buffer
->mark_active
))
12494 && NILP (w
->region_showing
)
12495 && NILP (Vshow_trailing_whitespace
)
12496 /* Right after splitting windows, last_point may be nil. */
12497 && INTEGERP (w
->last_point
)
12498 /* This code is not used for mini-buffer for the sake of the case
12499 of redisplaying to replace an echo area message; since in
12500 that case the mini-buffer contents per se are usually
12501 unchanged. This code is of no real use in the mini-buffer
12502 since the handling of this_line_start_pos, etc., in redisplay
12503 handles the same cases. */
12504 && !EQ (window
, minibuf_window
)
12505 /* When splitting windows or for new windows, it happens that
12506 redisplay is called with a nil window_end_vpos or one being
12507 larger than the window. This should really be fixed in
12508 window.c. I don't have this on my list, now, so we do
12509 approximately the same as the old redisplay code. --gerd. */
12510 && INTEGERP (w
->window_end_vpos
)
12511 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12512 && (FRAME_WINDOW_P (f
)
12513 || !overlay_arrow_in_current_buffer_p ()))
12515 int this_scroll_margin
, top_scroll_margin
;
12516 struct glyph_row
*row
= NULL
;
12519 debug_method_add (w
, "cursor movement");
12522 /* Scroll if point within this distance from the top or bottom
12523 of the window. This is a pixel value. */
12524 this_scroll_margin
= max (0, scroll_margin
);
12525 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12526 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12528 top_scroll_margin
= this_scroll_margin
;
12529 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12530 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12532 /* Start with the row the cursor was displayed during the last
12533 not paused redisplay. Give up if that row is not valid. */
12534 if (w
->last_cursor
.vpos
< 0
12535 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12536 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12539 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12540 if (row
->mode_line_p
)
12542 if (!row
->enabled_p
)
12543 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12546 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12549 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12551 if (PT
> XFASTINT (w
->last_point
))
12553 /* Point has moved forward. */
12554 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12555 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12557 xassert (row
->enabled_p
);
12561 /* The end position of a row equals the start position
12562 of the next row. If PT is there, we would rather
12563 display it in the next line. */
12564 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12565 && MATRIX_ROW_END_CHARPOS (row
) == PT
12566 && !cursor_row_p (w
, row
))
12569 /* If within the scroll margin, scroll. Note that
12570 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
12571 the next line would be drawn, and that
12572 this_scroll_margin can be zero. */
12573 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
12574 || PT
> MATRIX_ROW_END_CHARPOS (row
)
12575 /* Line is completely visible last line in window
12576 and PT is to be set in the next line. */
12577 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
12578 && PT
== MATRIX_ROW_END_CHARPOS (row
)
12579 && !row
->ends_at_zv_p
12580 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12583 else if (PT
< XFASTINT (w
->last_point
))
12585 /* Cursor has to be moved backward. Note that PT >=
12586 CHARPOS (startp) because of the outer if-statement. */
12587 while (!row
->mode_line_p
12588 && (MATRIX_ROW_START_CHARPOS (row
) > PT
12589 || (MATRIX_ROW_START_CHARPOS (row
) == PT
12590 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
12591 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
12592 row
> w
->current_matrix
->rows
12593 && (row
-1)->ends_in_newline_from_string_p
))))
12594 && (row
->y
> top_scroll_margin
12595 || CHARPOS (startp
) == BEGV
))
12597 xassert (row
->enabled_p
);
12601 /* Consider the following case: Window starts at BEGV,
12602 there is invisible, intangible text at BEGV, so that
12603 display starts at some point START > BEGV. It can
12604 happen that we are called with PT somewhere between
12605 BEGV and START. Try to handle that case. */
12606 if (row
< w
->current_matrix
->rows
12607 || row
->mode_line_p
)
12609 row
= w
->current_matrix
->rows
;
12610 if (row
->mode_line_p
)
12614 /* Due to newlines in overlay strings, we may have to
12615 skip forward over overlay strings. */
12616 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12617 && MATRIX_ROW_END_CHARPOS (row
) == PT
12618 && !cursor_row_p (w
, row
))
12621 /* If within the scroll margin, scroll. */
12622 if (row
->y
< top_scroll_margin
12623 && CHARPOS (startp
) != BEGV
)
12628 /* Cursor did not move. So don't scroll even if cursor line
12629 is partially visible, as it was so before. */
12630 rc
= CURSOR_MOVEMENT_SUCCESS
;
12633 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
12634 || PT
> MATRIX_ROW_END_CHARPOS (row
))
12636 /* if PT is not in the glyph row, give up. */
12637 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12639 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
12640 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
12641 && make_cursor_line_fully_visible_p
)
12643 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
12644 && !row
->ends_at_zv_p
12645 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12646 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12647 else if (row
->height
> window_box_height (w
))
12649 /* If we end up in a partially visible line, let's
12650 make it fully visible, except when it's taller
12651 than the window, in which case we can't do much
12654 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12658 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12659 if (!cursor_row_fully_visible_p (w
, 0, 1))
12660 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12662 rc
= CURSOR_MOVEMENT_SUCCESS
;
12666 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12671 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
12673 rc
= CURSOR_MOVEMENT_SUCCESS
;
12678 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12679 && MATRIX_ROW_START_CHARPOS (row
) == PT
12680 && cursor_row_p (w
, row
));
12689 set_vertical_scroll_bar (w
)
12692 int start
, end
, whole
;
12694 /* Calculate the start and end positions for the current window.
12695 At some point, it would be nice to choose between scrollbars
12696 which reflect the whole buffer size, with special markers
12697 indicating narrowing, and scrollbars which reflect only the
12700 Note that mini-buffers sometimes aren't displaying any text. */
12701 if (!MINI_WINDOW_P (w
)
12702 || (w
== XWINDOW (minibuf_window
)
12703 && NILP (echo_area_buffer
[0])))
12705 struct buffer
*buf
= XBUFFER (w
->buffer
);
12706 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12707 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12708 /* I don't think this is guaranteed to be right. For the
12709 moment, we'll pretend it is. */
12710 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12714 if (whole
< (end
- start
))
12715 whole
= end
- start
;
12718 start
= end
= whole
= 0;
12720 /* Indicate what this scroll bar ought to be displaying now. */
12721 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
12725 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
12726 selected_window is redisplayed.
12728 We can return without actually redisplaying the window if
12729 fonts_changed_p is nonzero. In that case, redisplay_internal will
12733 redisplay_window (window
, just_this_one_p
)
12734 Lisp_Object window
;
12735 int just_this_one_p
;
12737 struct window
*w
= XWINDOW (window
);
12738 struct frame
*f
= XFRAME (w
->frame
);
12739 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12740 struct buffer
*old
= current_buffer
;
12741 struct text_pos lpoint
, opoint
, startp
;
12742 int update_mode_line
;
12745 /* Record it now because it's overwritten. */
12746 int current_matrix_up_to_date_p
= 0;
12747 int used_current_matrix_p
= 0;
12748 /* This is less strict than current_matrix_up_to_date_p.
12749 It indictes that the buffer contents and narrowing are unchanged. */
12750 int buffer_unchanged_p
= 0;
12751 int temp_scroll_step
= 0;
12752 int count
= SPECPDL_INDEX ();
12754 int centering_position
= -1;
12755 int last_line_misfit
= 0;
12757 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12760 /* W must be a leaf window here. */
12761 xassert (!NILP (w
->buffer
));
12763 *w
->desired_matrix
->method
= 0;
12766 specbind (Qinhibit_point_motion_hooks
, Qt
);
12768 reconsider_clip_changes (w
, buffer
);
12770 /* Has the mode line to be updated? */
12771 update_mode_line
= (!NILP (w
->update_mode_line
)
12772 || update_mode_lines
12773 || buffer
->clip_changed
12774 || buffer
->prevent_redisplay_optimizations_p
);
12776 if (MINI_WINDOW_P (w
))
12778 if (w
== XWINDOW (echo_area_window
)
12779 && !NILP (echo_area_buffer
[0]))
12781 if (update_mode_line
)
12782 /* We may have to update a tty frame's menu bar or a
12783 tool-bar. Example `M-x C-h C-h C-g'. */
12784 goto finish_menu_bars
;
12786 /* We've already displayed the echo area glyphs in this window. */
12787 goto finish_scroll_bars
;
12789 else if ((w
!= XWINDOW (minibuf_window
)
12790 || minibuf_level
== 0)
12791 /* When buffer is nonempty, redisplay window normally. */
12792 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12793 /* Quail displays non-mini buffers in minibuffer window.
12794 In that case, redisplay the window normally. */
12795 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12797 /* W is a mini-buffer window, but it's not active, so clear
12799 int yb
= window_text_bottom_y (w
);
12800 struct glyph_row
*row
;
12803 for (y
= 0, row
= w
->desired_matrix
->rows
;
12805 y
+= row
->height
, ++row
)
12806 blank_row (w
, row
, y
);
12807 goto finish_scroll_bars
;
12810 clear_glyph_matrix (w
->desired_matrix
);
12813 /* Otherwise set up data on this window; select its buffer and point
12815 /* Really select the buffer, for the sake of buffer-local
12817 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12818 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12820 current_matrix_up_to_date_p
12821 = (!NILP (w
->window_end_valid
)
12822 && !current_buffer
->clip_changed
12823 && !current_buffer
->prevent_redisplay_optimizations_p
12824 && XFASTINT (w
->last_modified
) >= MODIFF
12825 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12828 = (!NILP (w
->window_end_valid
)
12829 && !current_buffer
->clip_changed
12830 && XFASTINT (w
->last_modified
) >= MODIFF
12831 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12833 /* When windows_or_buffers_changed is non-zero, we can't rely on
12834 the window end being valid, so set it to nil there. */
12835 if (windows_or_buffers_changed
)
12837 /* If window starts on a continuation line, maybe adjust the
12838 window start in case the window's width changed. */
12839 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12840 compute_window_start_on_continuation_line (w
);
12842 w
->window_end_valid
= Qnil
;
12845 /* Some sanity checks. */
12846 CHECK_WINDOW_END (w
);
12847 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12849 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12852 /* If %c is in mode line, update it if needed. */
12853 if (!NILP (w
->column_number_displayed
)
12854 /* This alternative quickly identifies a common case
12855 where no change is needed. */
12856 && !(PT
== XFASTINT (w
->last_point
)
12857 && XFASTINT (w
->last_modified
) >= MODIFF
12858 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12859 && (XFASTINT (w
->column_number_displayed
)
12860 != (int) current_column ())) /* iftc */
12861 update_mode_line
= 1;
12863 /* Count number of windows showing the selected buffer. An indirect
12864 buffer counts as its base buffer. */
12865 if (!just_this_one_p
)
12867 struct buffer
*current_base
, *window_base
;
12868 current_base
= current_buffer
;
12869 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12870 if (current_base
->base_buffer
)
12871 current_base
= current_base
->base_buffer
;
12872 if (window_base
->base_buffer
)
12873 window_base
= window_base
->base_buffer
;
12874 if (current_base
== window_base
)
12878 /* Point refers normally to the selected window. For any other
12879 window, set up appropriate value. */
12880 if (!EQ (window
, selected_window
))
12882 int new_pt
= XMARKER (w
->pointm
)->charpos
;
12883 int new_pt_byte
= marker_byte_position (w
->pointm
);
12887 new_pt_byte
= BEGV_BYTE
;
12888 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
12890 else if (new_pt
> (ZV
- 1))
12893 new_pt_byte
= ZV_BYTE
;
12894 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
12897 /* We don't use SET_PT so that the point-motion hooks don't run. */
12898 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
12901 /* If any of the character widths specified in the display table
12902 have changed, invalidate the width run cache. It's true that
12903 this may be a bit late to catch such changes, but the rest of
12904 redisplay goes (non-fatally) haywire when the display table is
12905 changed, so why should we worry about doing any better? */
12906 if (current_buffer
->width_run_cache
)
12908 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
12910 if (! disptab_matches_widthtab (disptab
,
12911 XVECTOR (current_buffer
->width_table
)))
12913 invalidate_region_cache (current_buffer
,
12914 current_buffer
->width_run_cache
,
12916 recompute_width_table (current_buffer
, disptab
);
12920 /* If window-start is screwed up, choose a new one. */
12921 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12924 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12926 /* If someone specified a new starting point but did not insist,
12927 check whether it can be used. */
12928 if (!NILP (w
->optional_new_start
)
12929 && CHARPOS (startp
) >= BEGV
12930 && CHARPOS (startp
) <= ZV
)
12932 w
->optional_new_start
= Qnil
;
12933 start_display (&it
, w
, startp
);
12934 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12935 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12936 if (IT_CHARPOS (it
) == PT
)
12937 w
->force_start
= Qt
;
12938 /* IT may overshoot PT if text at PT is invisible. */
12939 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12940 w
->force_start
= Qt
;
12943 /* Handle case where place to start displaying has been specified,
12944 unless the specified location is outside the accessible range. */
12945 if (!NILP (w
->force_start
)
12946 || w
->frozen_window_start_p
)
12948 /* We set this later on if we have to adjust point. */
12952 w
->force_start
= Qnil
;
12954 w
->window_end_valid
= Qnil
;
12956 /* Forget any recorded base line for line number display. */
12957 if (!buffer_unchanged_p
)
12958 w
->base_line_number
= Qnil
;
12960 /* Redisplay the mode line. Select the buffer properly for that.
12961 Also, run the hook window-scroll-functions
12962 because we have scrolled. */
12963 /* Note, we do this after clearing force_start because
12964 if there's an error, it is better to forget about force_start
12965 than to get into an infinite loop calling the hook functions
12966 and having them get more errors. */
12967 if (!update_mode_line
12968 || ! NILP (Vwindow_scroll_functions
))
12970 update_mode_line
= 1;
12971 w
->update_mode_line
= Qt
;
12972 startp
= run_window_scroll_functions (window
, startp
);
12975 w
->last_modified
= make_number (0);
12976 w
->last_overlay_modified
= make_number (0);
12977 if (CHARPOS (startp
) < BEGV
)
12978 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
12979 else if (CHARPOS (startp
) > ZV
)
12980 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
12982 /* Redisplay, then check if cursor has been set during the
12983 redisplay. Give up if new fonts were loaded. */
12984 val
= try_window (window
, startp
, 1);
12987 w
->force_start
= Qt
;
12988 clear_glyph_matrix (w
->desired_matrix
);
12989 goto need_larger_matrices
;
12991 /* Point was outside the scroll margins. */
12993 new_vpos
= window_box_height (w
) / 2;
12995 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
12997 /* If point does not appear, try to move point so it does
12998 appear. The desired matrix has been built above, so we
12999 can use it here. */
13000 new_vpos
= window_box_height (w
) / 2;
13003 if (!cursor_row_fully_visible_p (w
, 0, 0))
13005 /* Point does appear, but on a line partly visible at end of window.
13006 Move it back to a fully-visible line. */
13007 new_vpos
= window_box_height (w
);
13010 /* If we need to move point for either of the above reasons,
13011 now actually do it. */
13014 struct glyph_row
*row
;
13016 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13017 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13020 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13021 MATRIX_ROW_START_BYTEPOS (row
));
13023 if (w
!= XWINDOW (selected_window
))
13024 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13025 else if (current_buffer
== old
)
13026 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13028 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13030 /* If we are highlighting the region, then we just changed
13031 the region, so redisplay to show it. */
13032 if (!NILP (Vtransient_mark_mode
)
13033 && !NILP (current_buffer
->mark_active
))
13035 clear_glyph_matrix (w
->desired_matrix
);
13036 if (!try_window (window
, startp
, 0))
13037 goto need_larger_matrices
;
13042 debug_method_add (w
, "forced window start");
13047 /* Handle case where text has not changed, only point, and it has
13048 not moved off the frame, and we are not retrying after hscroll.
13049 (current_matrix_up_to_date_p is nonzero when retrying.) */
13050 if (current_matrix_up_to_date_p
13051 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13052 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13056 case CURSOR_MOVEMENT_SUCCESS
:
13057 used_current_matrix_p
= 1;
13060 #if 0 /* try_cursor_movement never returns this value. */
13061 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
13062 goto need_larger_matrices
;
13065 case CURSOR_MOVEMENT_MUST_SCROLL
:
13066 goto try_to_scroll
;
13072 /* If current starting point was originally the beginning of a line
13073 but no longer is, find a new starting point. */
13074 else if (!NILP (w
->start_at_line_beg
)
13075 && !(CHARPOS (startp
) <= BEGV
13076 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13079 debug_method_add (w
, "recenter 1");
13084 /* Try scrolling with try_window_id. Value is > 0 if update has
13085 been done, it is -1 if we know that the same window start will
13086 not work. It is 0 if unsuccessful for some other reason. */
13087 else if ((tem
= try_window_id (w
)) != 0)
13090 debug_method_add (w
, "try_window_id %d", tem
);
13093 if (fonts_changed_p
)
13094 goto need_larger_matrices
;
13098 /* Otherwise try_window_id has returned -1 which means that we
13099 don't want the alternative below this comment to execute. */
13101 else if (CHARPOS (startp
) >= BEGV
13102 && CHARPOS (startp
) <= ZV
13103 && PT
>= CHARPOS (startp
)
13104 && (CHARPOS (startp
) < ZV
13105 /* Avoid starting at end of buffer. */
13106 || CHARPOS (startp
) == BEGV
13107 || (XFASTINT (w
->last_modified
) >= MODIFF
13108 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
13111 /* If first window line is a continuation line, and window start
13112 is inside the modified region, but the first change is before
13113 current window start, we must select a new window start.*/
13114 if (NILP (w
->start_at_line_beg
)
13115 && CHARPOS (startp
) > BEGV
)
13117 /* Make sure beg_unchanged and end_unchanged are up to date.
13118 Do it only if buffer has really changed. This may or may
13119 not have been done by try_window_id (see which) already. */
13120 if (MODIFF
> SAVE_MODIFF
13121 /* This seems to happen sometimes after saving a buffer. */
13122 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
13124 if (GPT
- BEG
< BEG_UNCHANGED
)
13125 BEG_UNCHANGED
= GPT
- BEG
;
13126 if (Z
- GPT
< END_UNCHANGED
)
13127 END_UNCHANGED
= Z
- GPT
;
13130 if (CHARPOS (startp
) > BEG
+ BEG_UNCHANGED
13131 && CHARPOS (startp
) <= Z
- END_UNCHANGED
)
13133 /* There doesn't seems to be a simple way to find a new
13134 window start that is near the old window start, so
13135 we just recenter. */
13141 debug_method_add (w
, "same window start");
13144 /* Try to redisplay starting at same place as before.
13145 If point has not moved off frame, accept the results. */
13146 if (!current_matrix_up_to_date_p
13147 /* Don't use try_window_reusing_current_matrix in this case
13148 because a window scroll function can have changed the
13150 || !NILP (Vwindow_scroll_functions
)
13151 || MINI_WINDOW_P (w
)
13152 || !(used_current_matrix_p
13153 = try_window_reusing_current_matrix (w
)))
13155 IF_DEBUG (debug_method_add (w
, "1"));
13156 if (try_window (window
, startp
, 1) < 0)
13157 /* -1 means we need to scroll.
13158 0 means we need new matrices, but fonts_changed_p
13159 is set in that case, so we will detect it below. */
13160 goto try_to_scroll
;
13163 if (fonts_changed_p
)
13164 goto need_larger_matrices
;
13166 if (w
->cursor
.vpos
>= 0)
13168 if (!just_this_one_p
13169 || current_buffer
->clip_changed
13170 || BEG_UNCHANGED
< CHARPOS (startp
))
13171 /* Forget any recorded base line for line number display. */
13172 w
->base_line_number
= Qnil
;
13174 if (!cursor_row_fully_visible_p (w
, 1, 0))
13176 clear_glyph_matrix (w
->desired_matrix
);
13177 last_line_misfit
= 1;
13179 /* Drop through and scroll. */
13184 clear_glyph_matrix (w
->desired_matrix
);
13189 w
->last_modified
= make_number (0);
13190 w
->last_overlay_modified
= make_number (0);
13192 /* Redisplay the mode line. Select the buffer properly for that. */
13193 if (!update_mode_line
)
13195 update_mode_line
= 1;
13196 w
->update_mode_line
= Qt
;
13199 /* Try to scroll by specified few lines. */
13200 if ((scroll_conservatively
13202 || temp_scroll_step
13203 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13204 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13205 && !current_buffer
->clip_changed
13206 && CHARPOS (startp
) >= BEGV
13207 && CHARPOS (startp
) <= ZV
)
13209 /* The function returns -1 if new fonts were loaded, 1 if
13210 successful, 0 if not successful. */
13211 int rc
= try_scrolling (window
, just_this_one_p
,
13212 scroll_conservatively
,
13214 temp_scroll_step
, last_line_misfit
);
13217 case SCROLLING_SUCCESS
:
13220 case SCROLLING_NEED_LARGER_MATRICES
:
13221 goto need_larger_matrices
;
13223 case SCROLLING_FAILED
:
13231 /* Finally, just choose place to start which centers point */
13234 if (centering_position
< 0)
13235 centering_position
= window_box_height (w
) / 2;
13238 debug_method_add (w
, "recenter");
13241 /* w->vscroll = 0; */
13243 /* Forget any previously recorded base line for line number display. */
13244 if (!buffer_unchanged_p
)
13245 w
->base_line_number
= Qnil
;
13247 /* Move backward half the height of the window. */
13248 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13249 it
.current_y
= it
.last_visible_y
;
13250 move_it_vertically_backward (&it
, centering_position
);
13251 xassert (IT_CHARPOS (it
) >= BEGV
);
13253 /* The function move_it_vertically_backward may move over more
13254 than the specified y-distance. If it->w is small, e.g. a
13255 mini-buffer window, we may end up in front of the window's
13256 display area. Start displaying at the start of the line
13257 containing PT in this case. */
13258 if (it
.current_y
<= 0)
13260 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13261 move_it_vertically_backward (&it
, 0);
13263 /* I think this assert is bogus if buffer contains
13264 invisible text or images. KFS. */
13265 xassert (IT_CHARPOS (it
) <= PT
);
13270 it
.current_x
= it
.hpos
= 0;
13272 /* Set startp here explicitly in case that helps avoid an infinite loop
13273 in case the window-scroll-functions functions get errors. */
13274 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13276 /* Run scroll hooks. */
13277 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13279 /* Redisplay the window. */
13280 if (!current_matrix_up_to_date_p
13281 || windows_or_buffers_changed
13282 || cursor_type_changed
13283 /* Don't use try_window_reusing_current_matrix in this case
13284 because it can have changed the buffer. */
13285 || !NILP (Vwindow_scroll_functions
)
13286 || !just_this_one_p
13287 || MINI_WINDOW_P (w
)
13288 || !(used_current_matrix_p
13289 = try_window_reusing_current_matrix (w
)))
13290 try_window (window
, startp
, 0);
13292 /* If new fonts have been loaded (due to fontsets), give up. We
13293 have to start a new redisplay since we need to re-adjust glyph
13295 if (fonts_changed_p
)
13296 goto need_larger_matrices
;
13298 /* If cursor did not appear assume that the middle of the window is
13299 in the first line of the window. Do it again with the next line.
13300 (Imagine a window of height 100, displaying two lines of height
13301 60. Moving back 50 from it->last_visible_y will end in the first
13303 if (w
->cursor
.vpos
< 0)
13305 if (!NILP (w
->window_end_valid
)
13306 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13308 clear_glyph_matrix (w
->desired_matrix
);
13309 move_it_by_lines (&it
, 1, 0);
13310 try_window (window
, it
.current
.pos
, 0);
13312 else if (PT
< IT_CHARPOS (it
))
13314 clear_glyph_matrix (w
->desired_matrix
);
13315 move_it_by_lines (&it
, -1, 0);
13316 try_window (window
, it
.current
.pos
, 0);
13320 /* Not much we can do about it. */
13324 /* Consider the following case: Window starts at BEGV, there is
13325 invisible, intangible text at BEGV, so that display starts at
13326 some point START > BEGV. It can happen that we are called with
13327 PT somewhere between BEGV and START. Try to handle that case. */
13328 if (w
->cursor
.vpos
< 0)
13330 struct glyph_row
*row
= w
->current_matrix
->rows
;
13331 if (row
->mode_line_p
)
13333 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13336 if (!cursor_row_fully_visible_p (w
, 0, 0))
13338 /* If vscroll is enabled, disable it and try again. */
13342 clear_glyph_matrix (w
->desired_matrix
);
13346 /* If centering point failed to make the whole line visible,
13347 put point at the top instead. That has to make the whole line
13348 visible, if it can be done. */
13349 if (centering_position
== 0)
13352 clear_glyph_matrix (w
->desired_matrix
);
13353 centering_position
= 0;
13359 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13360 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13361 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13364 /* Display the mode line, if we must. */
13365 if ((update_mode_line
13366 /* If window not full width, must redo its mode line
13367 if (a) the window to its side is being redone and
13368 (b) we do a frame-based redisplay. This is a consequence
13369 of how inverted lines are drawn in frame-based redisplay. */
13370 || (!just_this_one_p
13371 && !FRAME_WINDOW_P (f
)
13372 && !WINDOW_FULL_WIDTH_P (w
))
13373 /* Line number to display. */
13374 || INTEGERP (w
->base_line_pos
)
13375 /* Column number is displayed and different from the one displayed. */
13376 || (!NILP (w
->column_number_displayed
)
13377 && (XFASTINT (w
->column_number_displayed
)
13378 != (int) current_column ()))) /* iftc */
13379 /* This means that the window has a mode line. */
13380 && (WINDOW_WANTS_MODELINE_P (w
)
13381 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13383 display_mode_lines (w
);
13385 /* If mode line height has changed, arrange for a thorough
13386 immediate redisplay using the correct mode line height. */
13387 if (WINDOW_WANTS_MODELINE_P (w
)
13388 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13390 fonts_changed_p
= 1;
13391 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13392 = DESIRED_MODE_LINE_HEIGHT (w
);
13395 /* If top line height has changed, arrange for a thorough
13396 immediate redisplay using the correct mode line height. */
13397 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13398 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13400 fonts_changed_p
= 1;
13401 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13402 = DESIRED_HEADER_LINE_HEIGHT (w
);
13405 if (fonts_changed_p
)
13406 goto need_larger_matrices
;
13409 if (!line_number_displayed
13410 && !BUFFERP (w
->base_line_pos
))
13412 w
->base_line_pos
= Qnil
;
13413 w
->base_line_number
= Qnil
;
13418 /* When we reach a frame's selected window, redo the frame's menu bar. */
13419 if (update_mode_line
13420 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13422 int redisplay_menu_p
= 0;
13423 int redisplay_tool_bar_p
= 0;
13425 if (FRAME_WINDOW_P (f
))
13427 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
13428 || defined (USE_GTK)
13429 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13431 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13435 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13437 if (redisplay_menu_p
)
13438 display_menu_bar (w
);
13440 #ifdef HAVE_WINDOW_SYSTEM
13442 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13444 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13445 && (FRAME_TOOL_BAR_LINES (f
) > 0
13446 || auto_resize_tool_bars_p
);
13450 if (redisplay_tool_bar_p
)
13451 redisplay_tool_bar (f
);
13455 #ifdef HAVE_WINDOW_SYSTEM
13456 if (FRAME_WINDOW_P (f
)
13457 && update_window_fringes (w
, (just_this_one_p
13458 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13459 || w
->pseudo_window_p
)))
13463 if (draw_window_fringes (w
, 1))
13464 x_draw_vertical_border (w
);
13468 #endif /* HAVE_WINDOW_SYSTEM */
13470 /* We go to this label, with fonts_changed_p nonzero,
13471 if it is necessary to try again using larger glyph matrices.
13472 We have to redeem the scroll bar even in this case,
13473 because the loop in redisplay_internal expects that. */
13474 need_larger_matrices
:
13476 finish_scroll_bars
:
13478 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13480 /* Set the thumb's position and size. */
13481 set_vertical_scroll_bar (w
);
13483 /* Note that we actually used the scroll bar attached to this
13484 window, so it shouldn't be deleted at the end of redisplay. */
13485 redeem_scroll_bar_hook (w
);
13488 /* Restore current_buffer and value of point in it. */
13489 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13490 set_buffer_internal_1 (old
);
13491 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13493 unbind_to (count
, Qnil
);
13497 /* Build the complete desired matrix of WINDOW with a window start
13498 buffer position POS.
13500 Value is 1 if successful. It is zero if fonts were loaded during
13501 redisplay which makes re-adjusting glyph matrices necessary, and -1
13502 if point would appear in the scroll margins.
13503 (We check that only if CHECK_MARGINS is nonzero. */
13506 try_window (window
, pos
, check_margins
)
13507 Lisp_Object window
;
13508 struct text_pos pos
;
13511 struct window
*w
= XWINDOW (window
);
13513 struct glyph_row
*last_text_row
= NULL
;
13515 /* Make POS the new window start. */
13516 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13518 /* Mark cursor position as unknown. No overlay arrow seen. */
13519 w
->cursor
.vpos
= -1;
13520 overlay_arrow_seen
= 0;
13522 /* Initialize iterator and info to start at POS. */
13523 start_display (&it
, w
, pos
);
13525 /* Display all lines of W. */
13526 while (it
.current_y
< it
.last_visible_y
)
13528 if (display_line (&it
))
13529 last_text_row
= it
.glyph_row
- 1;
13530 if (fonts_changed_p
)
13534 /* Don't let the cursor end in the scroll margins. */
13536 && !MINI_WINDOW_P (w
))
13538 int this_scroll_margin
;
13540 this_scroll_margin
= max (0, scroll_margin
);
13541 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13542 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13544 if ((w
->cursor
.y
>= 0 /* not vscrolled */
13545 && w
->cursor
.y
< this_scroll_margin
13546 && CHARPOS (pos
) > BEGV
13547 && IT_CHARPOS (it
) < ZV
)
13548 /* rms: considering make_cursor_line_fully_visible_p here
13549 seems to give wrong results. We don't want to recenter
13550 when the last line is partly visible, we want to allow
13551 that case to be handled in the usual way. */
13552 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
13554 w
->cursor
.vpos
= -1;
13555 clear_glyph_matrix (w
->desired_matrix
);
13560 /* If bottom moved off end of frame, change mode line percentage. */
13561 if (XFASTINT (w
->window_end_pos
) <= 0
13562 && Z
!= IT_CHARPOS (it
))
13563 w
->update_mode_line
= Qt
;
13565 /* Set window_end_pos to the offset of the last character displayed
13566 on the window from the end of current_buffer. Set
13567 window_end_vpos to its row number. */
13570 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
13571 w
->window_end_bytepos
13572 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13574 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13576 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13577 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
13578 ->displays_text_p
);
13582 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13583 w
->window_end_pos
= make_number (Z
- ZV
);
13584 w
->window_end_vpos
= make_number (0);
13587 /* But that is not valid info until redisplay finishes. */
13588 w
->window_end_valid
= Qnil
;
13594 /************************************************************************
13595 Window redisplay reusing current matrix when buffer has not changed
13596 ************************************************************************/
13598 /* Try redisplay of window W showing an unchanged buffer with a
13599 different window start than the last time it was displayed by
13600 reusing its current matrix. Value is non-zero if successful.
13601 W->start is the new window start. */
13604 try_window_reusing_current_matrix (w
)
13607 struct frame
*f
= XFRAME (w
->frame
);
13608 struct glyph_row
*row
, *bottom_row
;
13611 struct text_pos start
, new_start
;
13612 int nrows_scrolled
, i
;
13613 struct glyph_row
*last_text_row
;
13614 struct glyph_row
*last_reused_text_row
;
13615 struct glyph_row
*start_row
;
13616 int start_vpos
, min_y
, max_y
;
13619 if (inhibit_try_window_reusing
)
13623 if (/* This function doesn't handle terminal frames. */
13624 !FRAME_WINDOW_P (f
)
13625 /* Don't try to reuse the display if windows have been split
13627 || windows_or_buffers_changed
13628 || cursor_type_changed
)
13631 /* Can't do this if region may have changed. */
13632 if ((!NILP (Vtransient_mark_mode
)
13633 && !NILP (current_buffer
->mark_active
))
13634 || !NILP (w
->region_showing
)
13635 || !NILP (Vshow_trailing_whitespace
))
13638 /* If top-line visibility has changed, give up. */
13639 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13640 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
13643 /* Give up if old or new display is scrolled vertically. We could
13644 make this function handle this, but right now it doesn't. */
13645 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13646 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
13649 /* The variable new_start now holds the new window start. The old
13650 start `start' can be determined from the current matrix. */
13651 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
13652 start
= start_row
->start
.pos
;
13653 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13655 /* Clear the desired matrix for the display below. */
13656 clear_glyph_matrix (w
->desired_matrix
);
13658 if (CHARPOS (new_start
) <= CHARPOS (start
))
13662 /* Don't use this method if the display starts with an ellipsis
13663 displayed for invisible text. It's not easy to handle that case
13664 below, and it's certainly not worth the effort since this is
13665 not a frequent case. */
13666 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
13669 IF_DEBUG (debug_method_add (w
, "twu1"));
13671 /* Display up to a row that can be reused. The variable
13672 last_text_row is set to the last row displayed that displays
13673 text. Note that it.vpos == 0 if or if not there is a
13674 header-line; it's not the same as the MATRIX_ROW_VPOS! */
13675 start_display (&it
, w
, new_start
);
13676 first_row_y
= it
.current_y
;
13677 w
->cursor
.vpos
= -1;
13678 last_text_row
= last_reused_text_row
= NULL
;
13680 while (it
.current_y
< it
.last_visible_y
13681 && !fonts_changed_p
)
13683 /* If we have reached into the characters in the START row,
13684 that means the line boundaries have changed. So we
13685 can't start copying with the row START. Maybe it will
13686 work to start copying with the following row. */
13687 while (IT_CHARPOS (it
) > CHARPOS (start
))
13689 /* Advance to the next row as the "start". */
13691 start
= start_row
->start
.pos
;
13692 /* If there are no more rows to try, or just one, give up. */
13693 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
13694 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
13695 || CHARPOS (start
) == ZV
)
13697 clear_glyph_matrix (w
->desired_matrix
);
13701 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13703 /* If we have reached alignment,
13704 we can copy the rest of the rows. */
13705 if (IT_CHARPOS (it
) == CHARPOS (start
))
13708 if (display_line (&it
))
13709 last_text_row
= it
.glyph_row
- 1;
13712 /* A value of current_y < last_visible_y means that we stopped
13713 at the previous window start, which in turn means that we
13714 have at least one reusable row. */
13715 if (it
.current_y
< it
.last_visible_y
)
13717 /* IT.vpos always starts from 0; it counts text lines. */
13718 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
13720 /* Find PT if not already found in the lines displayed. */
13721 if (w
->cursor
.vpos
< 0)
13723 int dy
= it
.current_y
- start_row
->y
;
13725 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13726 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
13728 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
13729 dy
, nrows_scrolled
);
13732 clear_glyph_matrix (w
->desired_matrix
);
13737 /* Scroll the display. Do it before the current matrix is
13738 changed. The problem here is that update has not yet
13739 run, i.e. part of the current matrix is not up to date.
13740 scroll_run_hook will clear the cursor, and use the
13741 current matrix to get the height of the row the cursor is
13743 run
.current_y
= start_row
->y
;
13744 run
.desired_y
= it
.current_y
;
13745 run
.height
= it
.last_visible_y
- it
.current_y
;
13747 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
13750 rif
->update_window_begin_hook (w
);
13751 rif
->clear_window_mouse_face (w
);
13752 rif
->scroll_run_hook (w
, &run
);
13753 rif
->update_window_end_hook (w
, 0, 0);
13757 /* Shift current matrix down by nrows_scrolled lines. */
13758 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13759 rotate_matrix (w
->current_matrix
,
13761 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13764 /* Disable lines that must be updated. */
13765 for (i
= 0; i
< it
.vpos
; ++i
)
13766 (start_row
+ i
)->enabled_p
= 0;
13768 /* Re-compute Y positions. */
13769 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13770 max_y
= it
.last_visible_y
;
13771 for (row
= start_row
+ nrows_scrolled
;
13775 row
->y
= it
.current_y
;
13776 row
->visible_height
= row
->height
;
13778 if (row
->y
< min_y
)
13779 row
->visible_height
-= min_y
- row
->y
;
13780 if (row
->y
+ row
->height
> max_y
)
13781 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13782 row
->redraw_fringe_bitmaps_p
= 1;
13784 it
.current_y
+= row
->height
;
13786 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13787 last_reused_text_row
= row
;
13788 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13792 /* Disable lines in the current matrix which are now
13793 below the window. */
13794 for (++row
; row
< bottom_row
; ++row
)
13795 row
->enabled_p
= row
->mode_line_p
= 0;
13798 /* Update window_end_pos etc.; last_reused_text_row is the last
13799 reused row from the current matrix containing text, if any.
13800 The value of last_text_row is the last displayed line
13801 containing text. */
13802 if (last_reused_text_row
)
13804 w
->window_end_bytepos
13805 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13807 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13809 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13810 w
->current_matrix
));
13812 else if (last_text_row
)
13814 w
->window_end_bytepos
13815 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13817 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13819 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13823 /* This window must be completely empty. */
13824 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13825 w
->window_end_pos
= make_number (Z
- ZV
);
13826 w
->window_end_vpos
= make_number (0);
13828 w
->window_end_valid
= Qnil
;
13830 /* Update hint: don't try scrolling again in update_window. */
13831 w
->desired_matrix
->no_scrolling_p
= 1;
13834 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13838 else if (CHARPOS (new_start
) > CHARPOS (start
))
13840 struct glyph_row
*pt_row
, *row
;
13841 struct glyph_row
*first_reusable_row
;
13842 struct glyph_row
*first_row_to_display
;
13844 int yb
= window_text_bottom_y (w
);
13846 /* Find the row starting at new_start, if there is one. Don't
13847 reuse a partially visible line at the end. */
13848 first_reusable_row
= start_row
;
13849 while (first_reusable_row
->enabled_p
13850 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13851 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13852 < CHARPOS (new_start
)))
13853 ++first_reusable_row
;
13855 /* Give up if there is no row to reuse. */
13856 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13857 || !first_reusable_row
->enabled_p
13858 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13859 != CHARPOS (new_start
)))
13862 /* We can reuse fully visible rows beginning with
13863 first_reusable_row to the end of the window. Set
13864 first_row_to_display to the first row that cannot be reused.
13865 Set pt_row to the row containing point, if there is any. */
13867 for (first_row_to_display
= first_reusable_row
;
13868 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13869 ++first_row_to_display
)
13871 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
13872 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
13873 pt_row
= first_row_to_display
;
13876 /* Start displaying at the start of first_row_to_display. */
13877 xassert (first_row_to_display
->y
< yb
);
13878 init_to_row_start (&it
, w
, first_row_to_display
);
13880 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
13882 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
13884 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
13885 + WINDOW_HEADER_LINE_HEIGHT (w
));
13887 /* Display lines beginning with first_row_to_display in the
13888 desired matrix. Set last_text_row to the last row displayed
13889 that displays text. */
13890 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
13891 if (pt_row
== NULL
)
13892 w
->cursor
.vpos
= -1;
13893 last_text_row
= NULL
;
13894 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
13895 if (display_line (&it
))
13896 last_text_row
= it
.glyph_row
- 1;
13898 /* Give up If point isn't in a row displayed or reused. */
13899 if (w
->cursor
.vpos
< 0)
13901 clear_glyph_matrix (w
->desired_matrix
);
13905 /* If point is in a reused row, adjust y and vpos of the cursor
13909 w
->cursor
.vpos
-= nrows_scrolled
;
13910 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
13913 /* Scroll the display. */
13914 run
.current_y
= first_reusable_row
->y
;
13915 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13916 run
.height
= it
.last_visible_y
- run
.current_y
;
13917 dy
= run
.current_y
- run
.desired_y
;
13922 rif
->update_window_begin_hook (w
);
13923 rif
->clear_window_mouse_face (w
);
13924 rif
->scroll_run_hook (w
, &run
);
13925 rif
->update_window_end_hook (w
, 0, 0);
13929 /* Adjust Y positions of reused rows. */
13930 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13931 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13932 max_y
= it
.last_visible_y
;
13933 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
13936 row
->visible_height
= row
->height
;
13937 if (row
->y
< min_y
)
13938 row
->visible_height
-= min_y
- row
->y
;
13939 if (row
->y
+ row
->height
> max_y
)
13940 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13941 row
->redraw_fringe_bitmaps_p
= 1;
13944 /* Scroll the current matrix. */
13945 xassert (nrows_scrolled
> 0);
13946 rotate_matrix (w
->current_matrix
,
13948 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13951 /* Disable rows not reused. */
13952 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
13953 row
->enabled_p
= 0;
13955 /* Point may have moved to a different line, so we cannot assume that
13956 the previous cursor position is valid; locate the correct row. */
13959 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
13960 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
13964 w
->cursor
.y
= row
->y
;
13966 if (row
< bottom_row
)
13968 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
13969 while (glyph
->charpos
< PT
)
13972 w
->cursor
.x
+= glyph
->pixel_width
;
13978 /* Adjust window end. A null value of last_text_row means that
13979 the window end is in reused rows which in turn means that
13980 only its vpos can have changed. */
13983 w
->window_end_bytepos
13984 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13986 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13988 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13993 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
13996 w
->window_end_valid
= Qnil
;
13997 w
->desired_matrix
->no_scrolling_p
= 1;
14000 debug_method_add (w
, "try_window_reusing_current_matrix 2");
14010 /************************************************************************
14011 Window redisplay reusing current matrix when buffer has changed
14012 ************************************************************************/
14014 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
14015 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
14017 static struct glyph_row
*
14018 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
14019 struct glyph_row
*));
14022 /* Return the last row in MATRIX displaying text. If row START is
14023 non-null, start searching with that row. IT gives the dimensions
14024 of the display. Value is null if matrix is empty; otherwise it is
14025 a pointer to the row found. */
14027 static struct glyph_row
*
14028 find_last_row_displaying_text (matrix
, it
, start
)
14029 struct glyph_matrix
*matrix
;
14031 struct glyph_row
*start
;
14033 struct glyph_row
*row
, *row_found
;
14035 /* Set row_found to the last row in IT->w's current matrix
14036 displaying text. The loop looks funny but think of partially
14039 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14040 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14042 xassert (row
->enabled_p
);
14044 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
14053 /* Return the last row in the current matrix of W that is not affected
14054 by changes at the start of current_buffer that occurred since W's
14055 current matrix was built. Value is null if no such row exists.
14057 BEG_UNCHANGED us the number of characters unchanged at the start of
14058 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
14059 first changed character in current_buffer. Characters at positions <
14060 BEG + BEG_UNCHANGED are at the same buffer positions as they were
14061 when the current matrix was built. */
14063 static struct glyph_row
*
14064 find_last_unchanged_at_beg_row (w
)
14067 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
14068 struct glyph_row
*row
;
14069 struct glyph_row
*row_found
= NULL
;
14070 int yb
= window_text_bottom_y (w
);
14072 /* Find the last row displaying unchanged text. */
14073 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14074 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14075 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
14077 if (/* If row ends before first_changed_pos, it is unchanged,
14078 except in some case. */
14079 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
14080 /* When row ends in ZV and we write at ZV it is not
14082 && !row
->ends_at_zv_p
14083 /* When first_changed_pos is the end of a continued line,
14084 row is not unchanged because it may be no longer
14086 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
14087 && (row
->continued_p
14088 || row
->exact_window_width_line_p
)))
14091 /* Stop if last visible row. */
14092 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
14102 /* Find the first glyph row in the current matrix of W that is not
14103 affected by changes at the end of current_buffer since the
14104 time W's current matrix was built.
14106 Return in *DELTA the number of chars by which buffer positions in
14107 unchanged text at the end of current_buffer must be adjusted.
14109 Return in *DELTA_BYTES the corresponding number of bytes.
14111 Value is null if no such row exists, i.e. all rows are affected by
14114 static struct glyph_row
*
14115 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
14117 int *delta
, *delta_bytes
;
14119 struct glyph_row
*row
;
14120 struct glyph_row
*row_found
= NULL
;
14122 *delta
= *delta_bytes
= 0;
14124 /* Display must not have been paused, otherwise the current matrix
14125 is not up to date. */
14126 if (NILP (w
->window_end_valid
))
14129 /* A value of window_end_pos >= END_UNCHANGED means that the window
14130 end is in the range of changed text. If so, there is no
14131 unchanged row at the end of W's current matrix. */
14132 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
14135 /* Set row to the last row in W's current matrix displaying text. */
14136 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14138 /* If matrix is entirely empty, no unchanged row exists. */
14139 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14141 /* The value of row is the last glyph row in the matrix having a
14142 meaningful buffer position in it. The end position of row
14143 corresponds to window_end_pos. This allows us to translate
14144 buffer positions in the current matrix to current buffer
14145 positions for characters not in changed text. */
14146 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14147 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14148 int last_unchanged_pos
, last_unchanged_pos_old
;
14149 struct glyph_row
*first_text_row
14150 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14152 *delta
= Z
- Z_old
;
14153 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14155 /* Set last_unchanged_pos to the buffer position of the last
14156 character in the buffer that has not been changed. Z is the
14157 index + 1 of the last character in current_buffer, i.e. by
14158 subtracting END_UNCHANGED we get the index of the last
14159 unchanged character, and we have to add BEG to get its buffer
14161 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
14162 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
14164 /* Search backward from ROW for a row displaying a line that
14165 starts at a minimum position >= last_unchanged_pos_old. */
14166 for (; row
> first_text_row
; --row
)
14168 /* This used to abort, but it can happen.
14169 It is ok to just stop the search instead here. KFS. */
14170 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14173 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
14178 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
14185 /* Make sure that glyph rows in the current matrix of window W
14186 reference the same glyph memory as corresponding rows in the
14187 frame's frame matrix. This function is called after scrolling W's
14188 current matrix on a terminal frame in try_window_id and
14189 try_window_reusing_current_matrix. */
14192 sync_frame_with_window_matrix_rows (w
)
14195 struct frame
*f
= XFRAME (w
->frame
);
14196 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
14198 /* Preconditions: W must be a leaf window and full-width. Its frame
14199 must have a frame matrix. */
14200 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
14201 xassert (WINDOW_FULL_WIDTH_P (w
));
14202 xassert (!FRAME_WINDOW_P (f
));
14204 /* If W is a full-width window, glyph pointers in W's current matrix
14205 have, by definition, to be the same as glyph pointers in the
14206 corresponding frame matrix. Note that frame matrices have no
14207 marginal areas (see build_frame_matrix). */
14208 window_row
= w
->current_matrix
->rows
;
14209 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14210 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14211 while (window_row
< window_row_end
)
14213 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14214 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14216 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14217 frame_row
->glyphs
[TEXT_AREA
] = start
;
14218 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14219 frame_row
->glyphs
[LAST_AREA
] = end
;
14221 /* Disable frame rows whose corresponding window rows have
14222 been disabled in try_window_id. */
14223 if (!window_row
->enabled_p
)
14224 frame_row
->enabled_p
= 0;
14226 ++window_row
, ++frame_row
;
14231 /* Find the glyph row in window W containing CHARPOS. Consider all
14232 rows between START and END (not inclusive). END null means search
14233 all rows to the end of the display area of W. Value is the row
14234 containing CHARPOS or null. */
14237 row_containing_pos (w
, charpos
, start
, end
, dy
)
14240 struct glyph_row
*start
, *end
;
14243 struct glyph_row
*row
= start
;
14246 /* If we happen to start on a header-line, skip that. */
14247 if (row
->mode_line_p
)
14250 if ((end
&& row
>= end
) || !row
->enabled_p
)
14253 last_y
= window_text_bottom_y (w
) - dy
;
14257 /* Give up if we have gone too far. */
14258 if (end
&& row
>= end
)
14260 /* This formerly returned if they were equal.
14261 I think that both quantities are of a "last plus one" type;
14262 if so, when they are equal, the row is within the screen. -- rms. */
14263 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14266 /* If it is in this row, return this row. */
14267 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14268 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14269 /* The end position of a row equals the start
14270 position of the next row. If CHARPOS is there, we
14271 would rather display it in the next line, except
14272 when this line ends in ZV. */
14273 && !row
->ends_at_zv_p
14274 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14275 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14282 /* Try to redisplay window W by reusing its existing display. W's
14283 current matrix must be up to date when this function is called,
14284 i.e. window_end_valid must not be nil.
14288 1 if display has been updated
14289 0 if otherwise unsuccessful
14290 -1 if redisplay with same window start is known not to succeed
14292 The following steps are performed:
14294 1. Find the last row in the current matrix of W that is not
14295 affected by changes at the start of current_buffer. If no such row
14298 2. Find the first row in W's current matrix that is not affected by
14299 changes at the end of current_buffer. Maybe there is no such row.
14301 3. Display lines beginning with the row + 1 found in step 1 to the
14302 row found in step 2 or, if step 2 didn't find a row, to the end of
14305 4. If cursor is not known to appear on the window, give up.
14307 5. If display stopped at the row found in step 2, scroll the
14308 display and current matrix as needed.
14310 6. Maybe display some lines at the end of W, if we must. This can
14311 happen under various circumstances, like a partially visible line
14312 becoming fully visible, or because newly displayed lines are displayed
14313 in smaller font sizes.
14315 7. Update W's window end information. */
14321 struct frame
*f
= XFRAME (w
->frame
);
14322 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14323 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14324 struct glyph_row
*last_unchanged_at_beg_row
;
14325 struct glyph_row
*first_unchanged_at_end_row
;
14326 struct glyph_row
*row
;
14327 struct glyph_row
*bottom_row
;
14330 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14331 struct text_pos start_pos
;
14333 int first_unchanged_at_end_vpos
= 0;
14334 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14335 struct text_pos start
;
14336 int first_changed_charpos
, last_changed_charpos
;
14339 if (inhibit_try_window_id
)
14343 /* This is handy for debugging. */
14345 #define GIVE_UP(X) \
14347 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14351 #define GIVE_UP(X) return 0
14354 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14356 /* Don't use this for mini-windows because these can show
14357 messages and mini-buffers, and we don't handle that here. */
14358 if (MINI_WINDOW_P (w
))
14361 /* This flag is used to prevent redisplay optimizations. */
14362 if (windows_or_buffers_changed
|| cursor_type_changed
)
14365 /* Verify that narrowing has not changed.
14366 Also verify that we were not told to prevent redisplay optimizations.
14367 It would be nice to further
14368 reduce the number of cases where this prevents try_window_id. */
14369 if (current_buffer
->clip_changed
14370 || current_buffer
->prevent_redisplay_optimizations_p
)
14373 /* Window must either use window-based redisplay or be full width. */
14374 if (!FRAME_WINDOW_P (f
)
14375 && (!line_ins_del_ok
14376 || !WINDOW_FULL_WIDTH_P (w
)))
14379 /* Give up if point is not known NOT to appear in W. */
14380 if (PT
< CHARPOS (start
))
14383 /* Another way to prevent redisplay optimizations. */
14384 if (XFASTINT (w
->last_modified
) == 0)
14387 /* Verify that window is not hscrolled. */
14388 if (XFASTINT (w
->hscroll
) != 0)
14391 /* Verify that display wasn't paused. */
14392 if (NILP (w
->window_end_valid
))
14395 /* Can't use this if highlighting a region because a cursor movement
14396 will do more than just set the cursor. */
14397 if (!NILP (Vtransient_mark_mode
)
14398 && !NILP (current_buffer
->mark_active
))
14401 /* Likewise if highlighting trailing whitespace. */
14402 if (!NILP (Vshow_trailing_whitespace
))
14405 /* Likewise if showing a region. */
14406 if (!NILP (w
->region_showing
))
14409 /* Can use this if overlay arrow position and or string have changed. */
14410 if (overlay_arrows_changed_p ())
14414 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14415 only if buffer has really changed. The reason is that the gap is
14416 initially at Z for freshly visited files. The code below would
14417 set end_unchanged to 0 in that case. */
14418 if (MODIFF
> SAVE_MODIFF
14419 /* This seems to happen sometimes after saving a buffer. */
14420 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14422 if (GPT
- BEG
< BEG_UNCHANGED
)
14423 BEG_UNCHANGED
= GPT
- BEG
;
14424 if (Z
- GPT
< END_UNCHANGED
)
14425 END_UNCHANGED
= Z
- GPT
;
14428 /* The position of the first and last character that has been changed. */
14429 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14430 last_changed_charpos
= Z
- END_UNCHANGED
;
14432 /* If window starts after a line end, and the last change is in
14433 front of that newline, then changes don't affect the display.
14434 This case happens with stealth-fontification. Note that although
14435 the display is unchanged, glyph positions in the matrix have to
14436 be adjusted, of course. */
14437 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14438 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14439 && ((last_changed_charpos
< CHARPOS (start
)
14440 && CHARPOS (start
) == BEGV
)
14441 || (last_changed_charpos
< CHARPOS (start
) - 1
14442 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14444 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14445 struct glyph_row
*r0
;
14447 /* Compute how many chars/bytes have been added to or removed
14448 from the buffer. */
14449 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14450 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14452 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14454 /* Give up if PT is not in the window. Note that it already has
14455 been checked at the start of try_window_id that PT is not in
14456 front of the window start. */
14457 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14460 /* If window start is unchanged, we can reuse the whole matrix
14461 as is, after adjusting glyph positions. No need to compute
14462 the window end again, since its offset from Z hasn't changed. */
14463 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14464 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14465 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14466 /* PT must not be in a partially visible line. */
14467 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14468 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14470 /* Adjust positions in the glyph matrix. */
14471 if (delta
|| delta_bytes
)
14473 struct glyph_row
*r1
14474 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14475 increment_matrix_positions (w
->current_matrix
,
14476 MATRIX_ROW_VPOS (r0
, current_matrix
),
14477 MATRIX_ROW_VPOS (r1
, current_matrix
),
14478 delta
, delta_bytes
);
14481 /* Set the cursor. */
14482 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14484 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14491 /* Handle the case that changes are all below what is displayed in
14492 the window, and that PT is in the window. This shortcut cannot
14493 be taken if ZV is visible in the window, and text has been added
14494 there that is visible in the window. */
14495 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14496 /* ZV is not visible in the window, or there are no
14497 changes at ZV, actually. */
14498 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14499 || first_changed_charpos
== last_changed_charpos
))
14501 struct glyph_row
*r0
;
14503 /* Give up if PT is not in the window. Note that it already has
14504 been checked at the start of try_window_id that PT is not in
14505 front of the window start. */
14506 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14509 /* If window start is unchanged, we can reuse the whole matrix
14510 as is, without changing glyph positions since no text has
14511 been added/removed in front of the window end. */
14512 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14513 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14514 /* PT must not be in a partially visible line. */
14515 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14516 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14518 /* We have to compute the window end anew since text
14519 can have been added/removed after it. */
14521 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14522 w
->window_end_bytepos
14523 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14525 /* Set the cursor. */
14526 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14528 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14535 /* Give up if window start is in the changed area.
14537 The condition used to read
14539 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
14541 but why that was tested escapes me at the moment. */
14542 if (CHARPOS (start
) >= first_changed_charpos
14543 && CHARPOS (start
) <= last_changed_charpos
)
14546 /* Check that window start agrees with the start of the first glyph
14547 row in its current matrix. Check this after we know the window
14548 start is not in changed text, otherwise positions would not be
14550 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14551 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
14554 /* Give up if the window ends in strings. Overlay strings
14555 at the end are difficult to handle, so don't try. */
14556 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
14557 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
14560 /* Compute the position at which we have to start displaying new
14561 lines. Some of the lines at the top of the window might be
14562 reusable because they are not displaying changed text. Find the
14563 last row in W's current matrix not affected by changes at the
14564 start of current_buffer. Value is null if changes start in the
14565 first line of window. */
14566 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
14567 if (last_unchanged_at_beg_row
)
14569 /* Avoid starting to display in the moddle of a character, a TAB
14570 for instance. This is easier than to set up the iterator
14571 exactly, and it's not a frequent case, so the additional
14572 effort wouldn't really pay off. */
14573 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
14574 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
14575 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
14576 --last_unchanged_at_beg_row
;
14578 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
14581 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
14583 start_pos
= it
.current
.pos
;
14585 /* Start displaying new lines in the desired matrix at the same
14586 vpos we would use in the current matrix, i.e. below
14587 last_unchanged_at_beg_row. */
14588 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
14590 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14591 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
14593 xassert (it
.hpos
== 0 && it
.current_x
== 0);
14597 /* There are no reusable lines at the start of the window.
14598 Start displaying in the first text line. */
14599 start_display (&it
, w
, start
);
14600 it
.vpos
= it
.first_vpos
;
14601 start_pos
= it
.current
.pos
;
14604 /* Find the first row that is not affected by changes at the end of
14605 the buffer. Value will be null if there is no unchanged row, in
14606 which case we must redisplay to the end of the window. delta
14607 will be set to the value by which buffer positions beginning with
14608 first_unchanged_at_end_row have to be adjusted due to text
14610 first_unchanged_at_end_row
14611 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
14612 IF_DEBUG (debug_delta
= delta
);
14613 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
14615 /* Set stop_pos to the buffer position up to which we will have to
14616 display new lines. If first_unchanged_at_end_row != NULL, this
14617 is the buffer position of the start of the line displayed in that
14618 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
14619 that we don't stop at a buffer position. */
14621 if (first_unchanged_at_end_row
)
14623 xassert (last_unchanged_at_beg_row
== NULL
14624 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
14626 /* If this is a continuation line, move forward to the next one
14627 that isn't. Changes in lines above affect this line.
14628 Caution: this may move first_unchanged_at_end_row to a row
14629 not displaying text. */
14630 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
14631 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14632 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14633 < it
.last_visible_y
))
14634 ++first_unchanged_at_end_row
;
14636 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14637 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14638 >= it
.last_visible_y
))
14639 first_unchanged_at_end_row
= NULL
;
14642 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
14644 first_unchanged_at_end_vpos
14645 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
14646 xassert (stop_pos
>= Z
- END_UNCHANGED
);
14649 else if (last_unchanged_at_beg_row
== NULL
)
14655 /* Either there is no unchanged row at the end, or the one we have
14656 now displays text. This is a necessary condition for the window
14657 end pos calculation at the end of this function. */
14658 xassert (first_unchanged_at_end_row
== NULL
14659 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
14661 debug_last_unchanged_at_beg_vpos
14662 = (last_unchanged_at_beg_row
14663 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
14665 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
14667 #endif /* GLYPH_DEBUG != 0 */
14670 /* Display new lines. Set last_text_row to the last new line
14671 displayed which has text on it, i.e. might end up as being the
14672 line where the window_end_vpos is. */
14673 w
->cursor
.vpos
= -1;
14674 last_text_row
= NULL
;
14675 overlay_arrow_seen
= 0;
14676 while (it
.current_y
< it
.last_visible_y
14677 && !fonts_changed_p
14678 && (first_unchanged_at_end_row
== NULL
14679 || IT_CHARPOS (it
) < stop_pos
))
14681 if (display_line (&it
))
14682 last_text_row
= it
.glyph_row
- 1;
14685 if (fonts_changed_p
)
14689 /* Compute differences in buffer positions, y-positions etc. for
14690 lines reused at the bottom of the window. Compute what we can
14692 if (first_unchanged_at_end_row
14693 /* No lines reused because we displayed everything up to the
14694 bottom of the window. */
14695 && it
.current_y
< it
.last_visible_y
)
14698 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
14700 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
14701 run
.current_y
= first_unchanged_at_end_row
->y
;
14702 run
.desired_y
= run
.current_y
+ dy
;
14703 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
14707 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
14708 first_unchanged_at_end_row
= NULL
;
14710 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
14713 /* Find the cursor if not already found. We have to decide whether
14714 PT will appear on this window (it sometimes doesn't, but this is
14715 not a very frequent case.) This decision has to be made before
14716 the current matrix is altered. A value of cursor.vpos < 0 means
14717 that PT is either in one of the lines beginning at
14718 first_unchanged_at_end_row or below the window. Don't care for
14719 lines that might be displayed later at the window end; as
14720 mentioned, this is not a frequent case. */
14721 if (w
->cursor
.vpos
< 0)
14723 /* Cursor in unchanged rows at the top? */
14724 if (PT
< CHARPOS (start_pos
)
14725 && last_unchanged_at_beg_row
)
14727 row
= row_containing_pos (w
, PT
,
14728 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
14729 last_unchanged_at_beg_row
+ 1, 0);
14731 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14734 /* Start from first_unchanged_at_end_row looking for PT. */
14735 else if (first_unchanged_at_end_row
)
14737 row
= row_containing_pos (w
, PT
- delta
,
14738 first_unchanged_at_end_row
, NULL
, 0);
14740 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
14741 delta_bytes
, dy
, dvpos
);
14744 /* Give up if cursor was not found. */
14745 if (w
->cursor
.vpos
< 0)
14747 clear_glyph_matrix (w
->desired_matrix
);
14752 /* Don't let the cursor end in the scroll margins. */
14754 int this_scroll_margin
, cursor_height
;
14756 this_scroll_margin
= max (0, scroll_margin
);
14757 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14758 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14759 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
14761 if ((w
->cursor
.y
< this_scroll_margin
14762 && CHARPOS (start
) > BEGV
)
14763 /* Old redisplay didn't take scroll margin into account at the bottom,
14764 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14765 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14766 ? cursor_height
+ this_scroll_margin
14767 : 1)) > it
.last_visible_y
)
14769 w
->cursor
.vpos
= -1;
14770 clear_glyph_matrix (w
->desired_matrix
);
14775 /* Scroll the display. Do it before changing the current matrix so
14776 that xterm.c doesn't get confused about where the cursor glyph is
14778 if (dy
&& run
.height
)
14782 if (FRAME_WINDOW_P (f
))
14784 rif
->update_window_begin_hook (w
);
14785 rif
->clear_window_mouse_face (w
);
14786 rif
->scroll_run_hook (w
, &run
);
14787 rif
->update_window_end_hook (w
, 0, 0);
14791 /* Terminal frame. In this case, dvpos gives the number of
14792 lines to scroll by; dvpos < 0 means scroll up. */
14793 int first_unchanged_at_end_vpos
14794 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14795 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14796 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14797 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14798 + window_internal_height (w
));
14800 /* Perform the operation on the screen. */
14803 /* Scroll last_unchanged_at_beg_row to the end of the
14804 window down dvpos lines. */
14805 set_terminal_window (end
);
14807 /* On dumb terminals delete dvpos lines at the end
14808 before inserting dvpos empty lines. */
14809 if (!scroll_region_ok
)
14810 ins_del_lines (end
- dvpos
, -dvpos
);
14812 /* Insert dvpos empty lines in front of
14813 last_unchanged_at_beg_row. */
14814 ins_del_lines (from
, dvpos
);
14816 else if (dvpos
< 0)
14818 /* Scroll up last_unchanged_at_beg_vpos to the end of
14819 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14820 set_terminal_window (end
);
14822 /* Delete dvpos lines in front of
14823 last_unchanged_at_beg_vpos. ins_del_lines will set
14824 the cursor to the given vpos and emit |dvpos| delete
14826 ins_del_lines (from
+ dvpos
, dvpos
);
14828 /* On a dumb terminal insert dvpos empty lines at the
14830 if (!scroll_region_ok
)
14831 ins_del_lines (end
+ dvpos
, -dvpos
);
14834 set_terminal_window (0);
14840 /* Shift reused rows of the current matrix to the right position.
14841 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14843 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14844 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14847 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14848 bottom_vpos
, dvpos
);
14849 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14852 else if (dvpos
> 0)
14854 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14855 bottom_vpos
, dvpos
);
14856 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14857 first_unchanged_at_end_vpos
+ dvpos
, 0);
14860 /* For frame-based redisplay, make sure that current frame and window
14861 matrix are in sync with respect to glyph memory. */
14862 if (!FRAME_WINDOW_P (f
))
14863 sync_frame_with_window_matrix_rows (w
);
14865 /* Adjust buffer positions in reused rows. */
14867 increment_matrix_positions (current_matrix
,
14868 first_unchanged_at_end_vpos
+ dvpos
,
14869 bottom_vpos
, delta
, delta_bytes
);
14871 /* Adjust Y positions. */
14873 shift_glyph_matrix (w
, current_matrix
,
14874 first_unchanged_at_end_vpos
+ dvpos
,
14877 if (first_unchanged_at_end_row
)
14879 first_unchanged_at_end_row
+= dvpos
;
14880 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
14881 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
14882 first_unchanged_at_end_row
= NULL
;
14885 /* If scrolling up, there may be some lines to display at the end of
14887 last_text_row_at_end
= NULL
;
14890 /* Scrolling up can leave for example a partially visible line
14891 at the end of the window to be redisplayed. */
14892 /* Set last_row to the glyph row in the current matrix where the
14893 window end line is found. It has been moved up or down in
14894 the matrix by dvpos. */
14895 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
14896 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
14898 /* If last_row is the window end line, it should display text. */
14899 xassert (last_row
->displays_text_p
);
14901 /* If window end line was partially visible before, begin
14902 displaying at that line. Otherwise begin displaying with the
14903 line following it. */
14904 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
14906 init_to_row_start (&it
, w
, last_row
);
14907 it
.vpos
= last_vpos
;
14908 it
.current_y
= last_row
->y
;
14912 init_to_row_end (&it
, w
, last_row
);
14913 it
.vpos
= 1 + last_vpos
;
14914 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
14918 /* We may start in a continuation line. If so, we have to
14919 get the right continuation_lines_width and current_x. */
14920 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
14921 it
.hpos
= it
.current_x
= 0;
14923 /* Display the rest of the lines at the window end. */
14924 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14925 while (it
.current_y
< it
.last_visible_y
14926 && !fonts_changed_p
)
14928 /* Is it always sure that the display agrees with lines in
14929 the current matrix? I don't think so, so we mark rows
14930 displayed invalid in the current matrix by setting their
14931 enabled_p flag to zero. */
14932 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
14933 if (display_line (&it
))
14934 last_text_row_at_end
= it
.glyph_row
- 1;
14938 /* Update window_end_pos and window_end_vpos. */
14939 if (first_unchanged_at_end_row
14940 && !last_text_row_at_end
)
14942 /* Window end line if one of the preserved rows from the current
14943 matrix. Set row to the last row displaying text in current
14944 matrix starting at first_unchanged_at_end_row, after
14946 xassert (first_unchanged_at_end_row
->displays_text_p
);
14947 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
14948 first_unchanged_at_end_row
);
14949 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
14951 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14952 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14954 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
14955 xassert (w
->window_end_bytepos
>= 0);
14956 IF_DEBUG (debug_method_add (w
, "A"));
14958 else if (last_text_row_at_end
)
14961 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
14962 w
->window_end_bytepos
14963 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
14965 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
14966 xassert (w
->window_end_bytepos
>= 0);
14967 IF_DEBUG (debug_method_add (w
, "B"));
14969 else if (last_text_row
)
14971 /* We have displayed either to the end of the window or at the
14972 end of the window, i.e. the last row with text is to be found
14973 in the desired matrix. */
14975 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14976 w
->window_end_bytepos
14977 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14979 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
14980 xassert (w
->window_end_bytepos
>= 0);
14982 else if (first_unchanged_at_end_row
== NULL
14983 && last_text_row
== NULL
14984 && last_text_row_at_end
== NULL
)
14986 /* Displayed to end of window, but no line containing text was
14987 displayed. Lines were deleted at the end of the window. */
14988 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
14989 int vpos
= XFASTINT (w
->window_end_vpos
);
14990 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
14991 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
14994 row
== NULL
&& vpos
>= first_vpos
;
14995 --vpos
, --current_row
, --desired_row
)
14997 if (desired_row
->enabled_p
)
14999 if (desired_row
->displays_text_p
)
15002 else if (current_row
->displays_text_p
)
15006 xassert (row
!= NULL
);
15007 w
->window_end_vpos
= make_number (vpos
+ 1);
15008 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15009 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15010 xassert (w
->window_end_bytepos
>= 0);
15011 IF_DEBUG (debug_method_add (w
, "C"));
15016 #if 0 /* This leads to problems, for instance when the cursor is
15017 at ZV, and the cursor line displays no text. */
15018 /* Disable rows below what's displayed in the window. This makes
15019 debugging easier. */
15020 enable_glyph_matrix_rows (current_matrix
,
15021 XFASTINT (w
->window_end_vpos
) + 1,
15025 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
15026 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
15028 /* Record that display has not been completed. */
15029 w
->window_end_valid
= Qnil
;
15030 w
->desired_matrix
->no_scrolling_p
= 1;
15038 /***********************************************************************
15039 More debugging support
15040 ***********************************************************************/
15044 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
15045 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
15046 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
15049 /* Dump the contents of glyph matrix MATRIX on stderr.
15051 GLYPHS 0 means don't show glyph contents.
15052 GLYPHS 1 means show glyphs in short form
15053 GLYPHS > 1 means show glyphs in long form. */
15056 dump_glyph_matrix (matrix
, glyphs
)
15057 struct glyph_matrix
*matrix
;
15061 for (i
= 0; i
< matrix
->nrows
; ++i
)
15062 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
15066 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
15067 the glyph row and area where the glyph comes from. */
15070 dump_glyph (row
, glyph
, area
)
15071 struct glyph_row
*row
;
15072 struct glyph
*glyph
;
15075 if (glyph
->type
== CHAR_GLYPH
)
15078 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15079 glyph
- row
->glyphs
[TEXT_AREA
],
15082 (BUFFERP (glyph
->object
)
15084 : (STRINGP (glyph
->object
)
15087 glyph
->pixel_width
,
15089 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
15093 glyph
->left_box_line_p
,
15094 glyph
->right_box_line_p
);
15096 else if (glyph
->type
== STRETCH_GLYPH
)
15099 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15100 glyph
- row
->glyphs
[TEXT_AREA
],
15103 (BUFFERP (glyph
->object
)
15105 : (STRINGP (glyph
->object
)
15108 glyph
->pixel_width
,
15112 glyph
->left_box_line_p
,
15113 glyph
->right_box_line_p
);
15115 else if (glyph
->type
== IMAGE_GLYPH
)
15118 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15119 glyph
- row
->glyphs
[TEXT_AREA
],
15122 (BUFFERP (glyph
->object
)
15124 : (STRINGP (glyph
->object
)
15127 glyph
->pixel_width
,
15131 glyph
->left_box_line_p
,
15132 glyph
->right_box_line_p
);
15134 else if (glyph
->type
== COMPOSITE_GLYPH
)
15137 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15138 glyph
- row
->glyphs
[TEXT_AREA
],
15141 (BUFFERP (glyph
->object
)
15143 : (STRINGP (glyph
->object
)
15146 glyph
->pixel_width
,
15150 glyph
->left_box_line_p
,
15151 glyph
->right_box_line_p
);
15156 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
15157 GLYPHS 0 means don't show glyph contents.
15158 GLYPHS 1 means show glyphs in short form
15159 GLYPHS > 1 means show glyphs in long form. */
15162 dump_glyph_row (row
, vpos
, glyphs
)
15163 struct glyph_row
*row
;
15168 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
15169 fprintf (stderr
, "======================================================================\n");
15171 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
15172 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
15174 MATRIX_ROW_START_CHARPOS (row
),
15175 MATRIX_ROW_END_CHARPOS (row
),
15176 row
->used
[TEXT_AREA
],
15177 row
->contains_overlapping_glyphs_p
,
15179 row
->truncated_on_left_p
,
15180 row
->truncated_on_right_p
,
15182 MATRIX_ROW_CONTINUATION_LINE_P (row
),
15183 row
->displays_text_p
,
15186 row
->ends_in_middle_of_char_p
,
15187 row
->starts_in_middle_of_char_p
,
15193 row
->visible_height
,
15196 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
15197 row
->end
.overlay_string_index
,
15198 row
->continuation_lines_width
);
15199 fprintf (stderr
, "%9d %5d\n",
15200 CHARPOS (row
->start
.string_pos
),
15201 CHARPOS (row
->end
.string_pos
));
15202 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
15203 row
->end
.dpvec_index
);
15210 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15212 struct glyph
*glyph
= row
->glyphs
[area
];
15213 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
15215 /* Glyph for a line end in text. */
15216 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
15219 if (glyph
< glyph_end
)
15220 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15222 for (; glyph
< glyph_end
; ++glyph
)
15223 dump_glyph (row
, glyph
, area
);
15226 else if (glyphs
== 1)
15230 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15232 char *s
= (char *) alloca (row
->used
[area
] + 1);
15235 for (i
= 0; i
< row
->used
[area
]; ++i
)
15237 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15238 if (glyph
->type
== CHAR_GLYPH
15239 && glyph
->u
.ch
< 0x80
15240 && glyph
->u
.ch
>= ' ')
15241 s
[i
] = glyph
->u
.ch
;
15247 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15253 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15254 Sdump_glyph_matrix
, 0, 1, "p",
15255 doc
: /* Dump the current matrix of the selected window to stderr.
15256 Shows contents of glyph row structures. With non-nil
15257 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15258 glyphs in short form, otherwise show glyphs in long form. */)
15260 Lisp_Object glyphs
;
15262 struct window
*w
= XWINDOW (selected_window
);
15263 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15265 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15266 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15267 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15268 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15269 fprintf (stderr
, "=============================================\n");
15270 dump_glyph_matrix (w
->current_matrix
,
15271 NILP (glyphs
) ? 0 : XINT (glyphs
));
15276 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15277 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15280 struct frame
*f
= XFRAME (selected_frame
);
15281 dump_glyph_matrix (f
->current_matrix
, 1);
15286 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15287 doc
: /* Dump glyph row ROW to stderr.
15288 GLYPH 0 means don't dump glyphs.
15289 GLYPH 1 means dump glyphs in short form.
15290 GLYPH > 1 or omitted means dump glyphs in long form. */)
15292 Lisp_Object row
, glyphs
;
15294 struct glyph_matrix
*matrix
;
15297 CHECK_NUMBER (row
);
15298 matrix
= XWINDOW (selected_window
)->current_matrix
;
15300 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15301 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15303 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15308 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15309 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15310 GLYPH 0 means don't dump glyphs.
15311 GLYPH 1 means dump glyphs in short form.
15312 GLYPH > 1 or omitted means dump glyphs in long form. */)
15314 Lisp_Object row
, glyphs
;
15316 struct frame
*sf
= SELECTED_FRAME ();
15317 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15320 CHECK_NUMBER (row
);
15322 if (vpos
>= 0 && vpos
< m
->nrows
)
15323 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15324 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15329 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15330 doc
: /* Toggle tracing of redisplay.
15331 With ARG, turn tracing on if and only if ARG is positive. */)
15336 trace_redisplay_p
= !trace_redisplay_p
;
15339 arg
= Fprefix_numeric_value (arg
);
15340 trace_redisplay_p
= XINT (arg
) > 0;
15347 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15348 doc
: /* Like `format', but print result to stderr.
15349 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15354 Lisp_Object s
= Fformat (nargs
, args
);
15355 fprintf (stderr
, "%s", SDATA (s
));
15359 #endif /* GLYPH_DEBUG */
15363 /***********************************************************************
15364 Building Desired Matrix Rows
15365 ***********************************************************************/
15367 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15368 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15370 static struct glyph_row
*
15371 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15373 Lisp_Object overlay_arrow_string
;
15375 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15376 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15377 struct buffer
*old
= current_buffer
;
15378 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15379 int arrow_len
= SCHARS (overlay_arrow_string
);
15380 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15381 const unsigned char *p
;
15384 int n_glyphs_before
;
15386 set_buffer_temp (buffer
);
15387 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15388 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15389 SET_TEXT_POS (it
.position
, 0, 0);
15391 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15393 while (p
< arrow_end
)
15395 Lisp_Object face
, ilisp
;
15397 /* Get the next character. */
15399 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15401 it
.c
= *p
, it
.len
= 1;
15404 /* Get its face. */
15405 ilisp
= make_number (p
- arrow_string
);
15406 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15407 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15409 /* Compute its width, get its glyphs. */
15410 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15411 SET_TEXT_POS (it
.position
, -1, -1);
15412 PRODUCE_GLYPHS (&it
);
15414 /* If this character doesn't fit any more in the line, we have
15415 to remove some glyphs. */
15416 if (it
.current_x
> it
.last_visible_x
)
15418 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15423 set_buffer_temp (old
);
15424 return it
.glyph_row
;
15428 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15429 glyphs are only inserted for terminal frames since we can't really
15430 win with truncation glyphs when partially visible glyphs are
15431 involved. Which glyphs to insert is determined by
15432 produce_special_glyphs. */
15435 insert_left_trunc_glyphs (it
)
15438 struct it truncate_it
;
15439 struct glyph
*from
, *end
, *to
, *toend
;
15441 xassert (!FRAME_WINDOW_P (it
->f
));
15443 /* Get the truncation glyphs. */
15445 truncate_it
.current_x
= 0;
15446 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15447 truncate_it
.glyph_row
= &scratch_glyph_row
;
15448 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15449 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15450 truncate_it
.object
= make_number (0);
15451 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15453 /* Overwrite glyphs from IT with truncation glyphs. */
15454 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15455 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15456 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15457 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15462 /* There may be padding glyphs left over. Overwrite them too. */
15463 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15465 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15471 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15475 /* Compute the pixel height and width of IT->glyph_row.
15477 Most of the time, ascent and height of a display line will be equal
15478 to the max_ascent and max_height values of the display iterator
15479 structure. This is not the case if
15481 1. We hit ZV without displaying anything. In this case, max_ascent
15482 and max_height will be zero.
15484 2. We have some glyphs that don't contribute to the line height.
15485 (The glyph row flag contributes_to_line_height_p is for future
15486 pixmap extensions).
15488 The first case is easily covered by using default values because in
15489 these cases, the line height does not really matter, except that it
15490 must not be zero. */
15493 compute_line_metrics (it
)
15496 struct glyph_row
*row
= it
->glyph_row
;
15499 if (FRAME_WINDOW_P (it
->f
))
15501 int i
, min_y
, max_y
;
15503 /* The line may consist of one space only, that was added to
15504 place the cursor on it. If so, the row's height hasn't been
15506 if (row
->height
== 0)
15508 if (it
->max_ascent
+ it
->max_descent
== 0)
15509 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15510 row
->ascent
= it
->max_ascent
;
15511 row
->height
= it
->max_ascent
+ it
->max_descent
;
15512 row
->phys_ascent
= it
->max_phys_ascent
;
15513 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15514 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15517 /* Compute the width of this line. */
15518 row
->pixel_width
= row
->x
;
15519 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15520 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15522 xassert (row
->pixel_width
>= 0);
15523 xassert (row
->ascent
>= 0 && row
->height
> 0);
15525 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15526 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15528 /* If first line's physical ascent is larger than its logical
15529 ascent, use the physical ascent, and make the row taller.
15530 This makes accented characters fully visible. */
15531 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
15532 && row
->phys_ascent
> row
->ascent
)
15534 row
->height
+= row
->phys_ascent
- row
->ascent
;
15535 row
->ascent
= row
->phys_ascent
;
15538 /* Compute how much of the line is visible. */
15539 row
->visible_height
= row
->height
;
15541 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
15542 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
15544 if (row
->y
< min_y
)
15545 row
->visible_height
-= min_y
- row
->y
;
15546 if (row
->y
+ row
->height
> max_y
)
15547 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15551 row
->pixel_width
= row
->used
[TEXT_AREA
];
15552 if (row
->continued_p
)
15553 row
->pixel_width
-= it
->continuation_pixel_width
;
15554 else if (row
->truncated_on_right_p
)
15555 row
->pixel_width
-= it
->truncation_pixel_width
;
15556 row
->ascent
= row
->phys_ascent
= 0;
15557 row
->height
= row
->phys_height
= row
->visible_height
= 1;
15558 row
->extra_line_spacing
= 0;
15561 /* Compute a hash code for this row. */
15563 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15564 for (i
= 0; i
< row
->used
[area
]; ++i
)
15565 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
15566 + row
->glyphs
[area
][i
].u
.val
15567 + row
->glyphs
[area
][i
].face_id
15568 + row
->glyphs
[area
][i
].padding_p
15569 + (row
->glyphs
[area
][i
].type
<< 2));
15571 it
->max_ascent
= it
->max_descent
= 0;
15572 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
15576 /* Append one space to the glyph row of iterator IT if doing a
15577 window-based redisplay. The space has the same face as
15578 IT->face_id. Value is non-zero if a space was added.
15580 This function is called to make sure that there is always one glyph
15581 at the end of a glyph row that the cursor can be set on under
15582 window-systems. (If there weren't such a glyph we would not know
15583 how wide and tall a box cursor should be displayed).
15585 At the same time this space let's a nicely handle clearing to the
15586 end of the line if the row ends in italic text. */
15589 append_space_for_newline (it
, default_face_p
)
15591 int default_face_p
;
15593 if (FRAME_WINDOW_P (it
->f
))
15595 int n
= it
->glyph_row
->used
[TEXT_AREA
];
15597 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
15598 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
15600 /* Save some values that must not be changed.
15601 Must save IT->c and IT->len because otherwise
15602 ITERATOR_AT_END_P wouldn't work anymore after
15603 append_space_for_newline has been called. */
15604 enum display_element_type saved_what
= it
->what
;
15605 int saved_c
= it
->c
, saved_len
= it
->len
;
15606 int saved_x
= it
->current_x
;
15607 int saved_face_id
= it
->face_id
;
15608 struct text_pos saved_pos
;
15609 Lisp_Object saved_object
;
15612 saved_object
= it
->object
;
15613 saved_pos
= it
->position
;
15615 it
->what
= IT_CHARACTER
;
15616 bzero (&it
->position
, sizeof it
->position
);
15617 it
->object
= make_number (0);
15621 if (default_face_p
)
15622 it
->face_id
= DEFAULT_FACE_ID
;
15623 else if (it
->face_before_selective_p
)
15624 it
->face_id
= it
->saved_face_id
;
15625 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15626 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
15628 PRODUCE_GLYPHS (it
);
15630 it
->override_ascent
= -1;
15631 it
->constrain_row_ascent_descent_p
= 0;
15632 it
->current_x
= saved_x
;
15633 it
->object
= saved_object
;
15634 it
->position
= saved_pos
;
15635 it
->what
= saved_what
;
15636 it
->face_id
= saved_face_id
;
15637 it
->len
= saved_len
;
15647 /* Extend the face of the last glyph in the text area of IT->glyph_row
15648 to the end of the display line. Called from display_line.
15649 If the glyph row is empty, add a space glyph to it so that we
15650 know the face to draw. Set the glyph row flag fill_line_p. */
15653 extend_face_to_end_of_line (it
)
15657 struct frame
*f
= it
->f
;
15659 /* If line is already filled, do nothing. */
15660 if (it
->current_x
>= it
->last_visible_x
)
15663 /* Face extension extends the background and box of IT->face_id
15664 to the end of the line. If the background equals the background
15665 of the frame, we don't have to do anything. */
15666 if (it
->face_before_selective_p
)
15667 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
15669 face
= FACE_FROM_ID (f
, it
->face_id
);
15671 if (FRAME_WINDOW_P (f
)
15672 && it
->glyph_row
->displays_text_p
15673 && face
->box
== FACE_NO_BOX
15674 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
15678 /* Set the glyph row flag indicating that the face of the last glyph
15679 in the text area has to be drawn to the end of the text area. */
15680 it
->glyph_row
->fill_line_p
= 1;
15682 /* If current character of IT is not ASCII, make sure we have the
15683 ASCII face. This will be automatically undone the next time
15684 get_next_display_element returns a multibyte character. Note
15685 that the character will always be single byte in unibyte text. */
15686 if (!SINGLE_BYTE_CHAR_P (it
->c
))
15688 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
15691 if (FRAME_WINDOW_P (f
))
15693 /* If the row is empty, add a space with the current face of IT,
15694 so that we know which face to draw. */
15695 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
15697 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
15698 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
15699 it
->glyph_row
->used
[TEXT_AREA
] = 1;
15704 /* Save some values that must not be changed. */
15705 int saved_x
= it
->current_x
;
15706 struct text_pos saved_pos
;
15707 Lisp_Object saved_object
;
15708 enum display_element_type saved_what
= it
->what
;
15709 int saved_face_id
= it
->face_id
;
15711 saved_object
= it
->object
;
15712 saved_pos
= it
->position
;
15714 it
->what
= IT_CHARACTER
;
15715 bzero (&it
->position
, sizeof it
->position
);
15716 it
->object
= make_number (0);
15719 it
->face_id
= face
->id
;
15721 PRODUCE_GLYPHS (it
);
15723 while (it
->current_x
<= it
->last_visible_x
)
15724 PRODUCE_GLYPHS (it
);
15726 /* Don't count these blanks really. It would let us insert a left
15727 truncation glyph below and make us set the cursor on them, maybe. */
15728 it
->current_x
= saved_x
;
15729 it
->object
= saved_object
;
15730 it
->position
= saved_pos
;
15731 it
->what
= saved_what
;
15732 it
->face_id
= saved_face_id
;
15737 /* Value is non-zero if text starting at CHARPOS in current_buffer is
15738 trailing whitespace. */
15741 trailing_whitespace_p (charpos
)
15744 int bytepos
= CHAR_TO_BYTE (charpos
);
15747 while (bytepos
< ZV_BYTE
15748 && (c
= FETCH_CHAR (bytepos
),
15749 c
== ' ' || c
== '\t'))
15752 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
15754 if (bytepos
!= PT_BYTE
)
15761 /* Highlight trailing whitespace, if any, in ROW. */
15764 highlight_trailing_whitespace (f
, row
)
15766 struct glyph_row
*row
;
15768 int used
= row
->used
[TEXT_AREA
];
15772 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
15773 struct glyph
*glyph
= start
+ used
- 1;
15775 /* Skip over glyphs inserted to display the cursor at the
15776 end of a line, for extending the face of the last glyph
15777 to the end of the line on terminals, and for truncation
15778 and continuation glyphs. */
15779 while (glyph
>= start
15780 && glyph
->type
== CHAR_GLYPH
15781 && INTEGERP (glyph
->object
))
15784 /* If last glyph is a space or stretch, and it's trailing
15785 whitespace, set the face of all trailing whitespace glyphs in
15786 IT->glyph_row to `trailing-whitespace'. */
15788 && BUFFERP (glyph
->object
)
15789 && (glyph
->type
== STRETCH_GLYPH
15790 || (glyph
->type
== CHAR_GLYPH
15791 && glyph
->u
.ch
== ' '))
15792 && trailing_whitespace_p (glyph
->charpos
))
15794 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
15798 while (glyph
>= start
15799 && BUFFERP (glyph
->object
)
15800 && (glyph
->type
== STRETCH_GLYPH
15801 || (glyph
->type
== CHAR_GLYPH
15802 && glyph
->u
.ch
== ' ')))
15803 (glyph
--)->face_id
= face_id
;
15809 /* Value is non-zero if glyph row ROW in window W should be
15810 used to hold the cursor. */
15813 cursor_row_p (w
, row
)
15815 struct glyph_row
*row
;
15817 int cursor_row_p
= 1;
15819 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15821 /* If the row ends with a newline from a string, we don't want
15822 the cursor there, but we still want it at the start of the
15823 string if the string starts in this row.
15824 If the row is continued it doesn't end in a newline. */
15825 if (CHARPOS (row
->end
.string_pos
) >= 0)
15826 cursor_row_p
= (row
->continued_p
15827 || PT
>= MATRIX_ROW_START_CHARPOS (row
));
15828 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15830 /* If the row ends in middle of a real character,
15831 and the line is continued, we want the cursor here.
15832 That's because MATRIX_ROW_END_CHARPOS would equal
15833 PT if PT is before the character. */
15834 if (!row
->ends_in_ellipsis_p
)
15835 cursor_row_p
= row
->continued_p
;
15837 /* If the row ends in an ellipsis, then
15838 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15839 We want that position to be displayed after the ellipsis. */
15842 /* If the row ends at ZV, display the cursor at the end of that
15843 row instead of at the start of the row below. */
15844 else if (row
->ends_at_zv_p
)
15850 return cursor_row_p
;
15854 /* Construct the glyph row IT->glyph_row in the desired matrix of
15855 IT->w from text at the current position of IT. See dispextern.h
15856 for an overview of struct it. Value is non-zero if
15857 IT->glyph_row displays text, as opposed to a line displaying ZV
15864 struct glyph_row
*row
= it
->glyph_row
;
15865 Lisp_Object overlay_arrow_string
;
15867 /* We always start displaying at hpos zero even if hscrolled. */
15868 xassert (it
->hpos
== 0 && it
->current_x
== 0);
15870 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
15871 >= it
->w
->desired_matrix
->nrows
)
15873 it
->w
->nrows_scale_factor
++;
15874 fonts_changed_p
= 1;
15878 /* Is IT->w showing the region? */
15879 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
15881 /* Clear the result glyph row and enable it. */
15882 prepare_desired_row (row
);
15884 row
->y
= it
->current_y
;
15885 row
->start
= it
->start
;
15886 row
->continuation_lines_width
= it
->continuation_lines_width
;
15887 row
->displays_text_p
= 1;
15888 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
15889 it
->starts_in_middle_of_char_p
= 0;
15891 /* Arrange the overlays nicely for our purposes. Usually, we call
15892 display_line on only one line at a time, in which case this
15893 can't really hurt too much, or we call it on lines which appear
15894 one after another in the buffer, in which case all calls to
15895 recenter_overlay_lists but the first will be pretty cheap. */
15896 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
15898 /* Move over display elements that are not visible because we are
15899 hscrolled. This may stop at an x-position < IT->first_visible_x
15900 if the first glyph is partially visible or if we hit a line end. */
15901 if (it
->current_x
< it
->first_visible_x
)
15903 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
15904 MOVE_TO_POS
| MOVE_TO_X
);
15907 /* Get the initial row height. This is either the height of the
15908 text hscrolled, if there is any, or zero. */
15909 row
->ascent
= it
->max_ascent
;
15910 row
->height
= it
->max_ascent
+ it
->max_descent
;
15911 row
->phys_ascent
= it
->max_phys_ascent
;
15912 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15913 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15915 /* Loop generating characters. The loop is left with IT on the next
15916 character to display. */
15919 int n_glyphs_before
, hpos_before
, x_before
;
15921 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
15923 /* Retrieve the next thing to display. Value is zero if end of
15925 if (!get_next_display_element (it
))
15927 /* Maybe add a space at the end of this line that is used to
15928 display the cursor there under X. Set the charpos of the
15929 first glyph of blank lines not corresponding to any text
15931 #ifdef HAVE_WINDOW_SYSTEM
15932 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15933 row
->exact_window_width_line_p
= 1;
15935 #endif /* HAVE_WINDOW_SYSTEM */
15936 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
15937 || row
->used
[TEXT_AREA
] == 0)
15939 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
15940 row
->displays_text_p
= 0;
15942 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
15943 && (!MINI_WINDOW_P (it
->w
)
15944 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
15945 row
->indicate_empty_line_p
= 1;
15948 it
->continuation_lines_width
= 0;
15949 row
->ends_at_zv_p
= 1;
15953 /* Now, get the metrics of what we want to display. This also
15954 generates glyphs in `row' (which is IT->glyph_row). */
15955 n_glyphs_before
= row
->used
[TEXT_AREA
];
15958 /* Remember the line height so far in case the next element doesn't
15959 fit on the line. */
15960 if (!it
->truncate_lines_p
)
15962 ascent
= it
->max_ascent
;
15963 descent
= it
->max_descent
;
15964 phys_ascent
= it
->max_phys_ascent
;
15965 phys_descent
= it
->max_phys_descent
;
15968 PRODUCE_GLYPHS (it
);
15970 /* If this display element was in marginal areas, continue with
15972 if (it
->area
!= TEXT_AREA
)
15974 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15975 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15976 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15977 row
->phys_height
= max (row
->phys_height
,
15978 it
->max_phys_ascent
+ it
->max_phys_descent
);
15979 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15980 it
->max_extra_line_spacing
);
15981 set_iterator_to_next (it
, 1);
15985 /* Does the display element fit on the line? If we truncate
15986 lines, we should draw past the right edge of the window. If
15987 we don't truncate, we want to stop so that we can display the
15988 continuation glyph before the right margin. If lines are
15989 continued, there are two possible strategies for characters
15990 resulting in more than 1 glyph (e.g. tabs): Display as many
15991 glyphs as possible in this line and leave the rest for the
15992 continuation line, or display the whole element in the next
15993 line. Original redisplay did the former, so we do it also. */
15994 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
15995 hpos_before
= it
->hpos
;
15998 if (/* Not a newline. */
16000 /* Glyphs produced fit entirely in the line. */
16001 && it
->current_x
< it
->last_visible_x
)
16003 it
->hpos
+= nglyphs
;
16004 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16005 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16006 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16007 row
->phys_height
= max (row
->phys_height
,
16008 it
->max_phys_ascent
+ it
->max_phys_descent
);
16009 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16010 it
->max_extra_line_spacing
);
16011 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
16012 row
->x
= x
- it
->first_visible_x
;
16017 struct glyph
*glyph
;
16019 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
16021 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16022 new_x
= x
+ glyph
->pixel_width
;
16024 if (/* Lines are continued. */
16025 !it
->truncate_lines_p
16026 && (/* Glyph doesn't fit on the line. */
16027 new_x
> it
->last_visible_x
16028 /* Or it fits exactly on a window system frame. */
16029 || (new_x
== it
->last_visible_x
16030 && FRAME_WINDOW_P (it
->f
))))
16032 /* End of a continued line. */
16035 || (new_x
== it
->last_visible_x
16036 && FRAME_WINDOW_P (it
->f
)))
16038 /* Current glyph is the only one on the line or
16039 fits exactly on the line. We must continue
16040 the line because we can't draw the cursor
16041 after the glyph. */
16042 row
->continued_p
= 1;
16043 it
->current_x
= new_x
;
16044 it
->continuation_lines_width
+= new_x
;
16046 if (i
== nglyphs
- 1)
16048 set_iterator_to_next (it
, 1);
16049 #ifdef HAVE_WINDOW_SYSTEM
16050 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16052 if (!get_next_display_element (it
))
16054 row
->exact_window_width_line_p
= 1;
16055 it
->continuation_lines_width
= 0;
16056 row
->continued_p
= 0;
16057 row
->ends_at_zv_p
= 1;
16059 else if (ITERATOR_AT_END_OF_LINE_P (it
))
16061 row
->continued_p
= 0;
16062 row
->exact_window_width_line_p
= 1;
16065 #endif /* HAVE_WINDOW_SYSTEM */
16068 else if (CHAR_GLYPH_PADDING_P (*glyph
)
16069 && !FRAME_WINDOW_P (it
->f
))
16071 /* A padding glyph that doesn't fit on this line.
16072 This means the whole character doesn't fit
16074 row
->used
[TEXT_AREA
] = n_glyphs_before
;
16076 /* Fill the rest of the row with continuation
16077 glyphs like in 20.x. */
16078 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
16079 < row
->glyphs
[1 + TEXT_AREA
])
16080 produce_special_glyphs (it
, IT_CONTINUATION
);
16082 row
->continued_p
= 1;
16083 it
->current_x
= x_before
;
16084 it
->continuation_lines_width
+= x_before
;
16086 /* Restore the height to what it was before the
16087 element not fitting on the line. */
16088 it
->max_ascent
= ascent
;
16089 it
->max_descent
= descent
;
16090 it
->max_phys_ascent
= phys_ascent
;
16091 it
->max_phys_descent
= phys_descent
;
16093 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
16095 /* A TAB that extends past the right edge of the
16096 window. This produces a single glyph on
16097 window system frames. We leave the glyph in
16098 this row and let it fill the row, but don't
16099 consume the TAB. */
16100 it
->continuation_lines_width
+= it
->last_visible_x
;
16101 row
->ends_in_middle_of_char_p
= 1;
16102 row
->continued_p
= 1;
16103 glyph
->pixel_width
= it
->last_visible_x
- x
;
16104 it
->starts_in_middle_of_char_p
= 1;
16108 /* Something other than a TAB that draws past
16109 the right edge of the window. Restore
16110 positions to values before the element. */
16111 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16113 /* Display continuation glyphs. */
16114 if (!FRAME_WINDOW_P (it
->f
))
16115 produce_special_glyphs (it
, IT_CONTINUATION
);
16116 row
->continued_p
= 1;
16118 it
->current_x
= x_before
;
16119 it
->continuation_lines_width
+= x
;
16120 extend_face_to_end_of_line (it
);
16122 if (nglyphs
> 1 && i
> 0)
16124 row
->ends_in_middle_of_char_p
= 1;
16125 it
->starts_in_middle_of_char_p
= 1;
16128 /* Restore the height to what it was before the
16129 element not fitting on the line. */
16130 it
->max_ascent
= ascent
;
16131 it
->max_descent
= descent
;
16132 it
->max_phys_ascent
= phys_ascent
;
16133 it
->max_phys_descent
= phys_descent
;
16138 else if (new_x
> it
->first_visible_x
)
16140 /* Increment number of glyphs actually displayed. */
16143 if (x
< it
->first_visible_x
)
16144 /* Glyph is partially visible, i.e. row starts at
16145 negative X position. */
16146 row
->x
= x
- it
->first_visible_x
;
16150 /* Glyph is completely off the left margin of the
16151 window. This should not happen because of the
16152 move_it_in_display_line at the start of this
16153 function, unless the text display area of the
16154 window is empty. */
16155 xassert (it
->first_visible_x
<= it
->last_visible_x
);
16159 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16160 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16161 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16162 row
->phys_height
= max (row
->phys_height
,
16163 it
->max_phys_ascent
+ it
->max_phys_descent
);
16164 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16165 it
->max_extra_line_spacing
);
16167 /* End of this display line if row is continued. */
16168 if (row
->continued_p
|| row
->ends_at_zv_p
)
16173 /* Is this a line end? If yes, we're also done, after making
16174 sure that a non-default face is extended up to the right
16175 margin of the window. */
16176 if (ITERATOR_AT_END_OF_LINE_P (it
))
16178 int used_before
= row
->used
[TEXT_AREA
];
16180 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
16182 #ifdef HAVE_WINDOW_SYSTEM
16183 /* Add a space at the end of the line that is used to
16184 display the cursor there. */
16185 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16186 append_space_for_newline (it
, 0);
16187 #endif /* HAVE_WINDOW_SYSTEM */
16189 /* Extend the face to the end of the line. */
16190 extend_face_to_end_of_line (it
);
16192 /* Make sure we have the position. */
16193 if (used_before
== 0)
16194 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
16196 /* Consume the line end. This skips over invisible lines. */
16197 set_iterator_to_next (it
, 1);
16198 it
->continuation_lines_width
= 0;
16202 /* Proceed with next display element. Note that this skips
16203 over lines invisible because of selective display. */
16204 set_iterator_to_next (it
, 1);
16206 /* If we truncate lines, we are done when the last displayed
16207 glyphs reach past the right margin of the window. */
16208 if (it
->truncate_lines_p
16209 && (FRAME_WINDOW_P (it
->f
)
16210 ? (it
->current_x
>= it
->last_visible_x
)
16211 : (it
->current_x
> it
->last_visible_x
)))
16213 /* Maybe add truncation glyphs. */
16214 if (!FRAME_WINDOW_P (it
->f
))
16218 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16219 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16222 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16224 row
->used
[TEXT_AREA
] = i
;
16225 produce_special_glyphs (it
, IT_TRUNCATION
);
16228 #ifdef HAVE_WINDOW_SYSTEM
16231 /* Don't truncate if we can overflow newline into fringe. */
16232 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16234 if (!get_next_display_element (it
))
16236 it
->continuation_lines_width
= 0;
16237 row
->ends_at_zv_p
= 1;
16238 row
->exact_window_width_line_p
= 1;
16241 if (ITERATOR_AT_END_OF_LINE_P (it
))
16243 row
->exact_window_width_line_p
= 1;
16244 goto at_end_of_line
;
16248 #endif /* HAVE_WINDOW_SYSTEM */
16250 row
->truncated_on_right_p
= 1;
16251 it
->continuation_lines_width
= 0;
16252 reseat_at_next_visible_line_start (it
, 0);
16253 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16254 it
->hpos
= hpos_before
;
16255 it
->current_x
= x_before
;
16260 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16261 at the left window margin. */
16262 if (it
->first_visible_x
16263 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16265 if (!FRAME_WINDOW_P (it
->f
))
16266 insert_left_trunc_glyphs (it
);
16267 row
->truncated_on_left_p
= 1;
16270 /* If the start of this line is the overlay arrow-position, then
16271 mark this glyph row as the one containing the overlay arrow.
16272 This is clearly a mess with variable size fonts. It would be
16273 better to let it be displayed like cursors under X. */
16274 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16275 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16276 !NILP (overlay_arrow_string
)))
16278 /* Overlay arrow in window redisplay is a fringe bitmap. */
16279 if (STRINGP (overlay_arrow_string
))
16281 struct glyph_row
*arrow_row
16282 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
16283 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
16284 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
16285 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
16286 struct glyph
*p2
, *end
;
16288 /* Copy the arrow glyphs. */
16289 while (glyph
< arrow_end
)
16292 /* Throw away padding glyphs. */
16294 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16295 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
16301 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
16306 xassert (INTEGERP (overlay_arrow_string
));
16307 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
16309 overlay_arrow_seen
= 1;
16312 /* Compute pixel dimensions of this line. */
16313 compute_line_metrics (it
);
16315 /* Remember the position at which this line ends. */
16316 row
->end
= it
->current
;
16318 /* Record whether this row ends inside an ellipsis. */
16319 row
->ends_in_ellipsis_p
16320 = (it
->method
== GET_FROM_DISPLAY_VECTOR
16321 && it
->ellipsis_p
);
16323 /* Save fringe bitmaps in this row. */
16324 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
16325 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
16326 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
16327 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
16329 it
->left_user_fringe_bitmap
= 0;
16330 it
->left_user_fringe_face_id
= 0;
16331 it
->right_user_fringe_bitmap
= 0;
16332 it
->right_user_fringe_face_id
= 0;
16334 /* Maybe set the cursor. */
16335 if (it
->w
->cursor
.vpos
< 0
16336 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
16337 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
16338 && cursor_row_p (it
->w
, row
))
16339 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
16341 /* Highlight trailing whitespace. */
16342 if (!NILP (Vshow_trailing_whitespace
))
16343 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
16345 /* Prepare for the next line. This line starts horizontally at (X
16346 HPOS) = (0 0). Vertical positions are incremented. As a
16347 convenience for the caller, IT->glyph_row is set to the next
16349 it
->current_x
= it
->hpos
= 0;
16350 it
->current_y
+= row
->height
;
16353 it
->start
= it
->current
;
16354 return row
->displays_text_p
;
16359 /***********************************************************************
16361 ***********************************************************************/
16363 /* Redisplay the menu bar in the frame for window W.
16365 The menu bar of X frames that don't have X toolkit support is
16366 displayed in a special window W->frame->menu_bar_window.
16368 The menu bar of terminal frames is treated specially as far as
16369 glyph matrices are concerned. Menu bar lines are not part of
16370 windows, so the update is done directly on the frame matrix rows
16371 for the menu bar. */
16374 display_menu_bar (w
)
16377 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16382 /* Don't do all this for graphical frames. */
16384 if (!NILP (Vwindow_system
))
16387 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
16392 if (FRAME_MAC_P (f
))
16396 #ifdef USE_X_TOOLKIT
16397 xassert (!FRAME_WINDOW_P (f
));
16398 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
16399 it
.first_visible_x
= 0;
16400 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16401 #else /* not USE_X_TOOLKIT */
16402 if (FRAME_WINDOW_P (f
))
16404 /* Menu bar lines are displayed in the desired matrix of the
16405 dummy window menu_bar_window. */
16406 struct window
*menu_w
;
16407 xassert (WINDOWP (f
->menu_bar_window
));
16408 menu_w
= XWINDOW (f
->menu_bar_window
);
16409 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
16411 it
.first_visible_x
= 0;
16412 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16416 /* This is a TTY frame, i.e. character hpos/vpos are used as
16418 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
16420 it
.first_visible_x
= 0;
16421 it
.last_visible_x
= FRAME_COLS (f
);
16423 #endif /* not USE_X_TOOLKIT */
16425 if (! mode_line_inverse_video
)
16426 /* Force the menu-bar to be displayed in the default face. */
16427 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16429 /* Clear all rows of the menu bar. */
16430 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
16432 struct glyph_row
*row
= it
.glyph_row
+ i
;
16433 clear_glyph_row (row
);
16434 row
->enabled_p
= 1;
16435 row
->full_width_p
= 1;
16438 /* Display all items of the menu bar. */
16439 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
16440 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
16442 Lisp_Object string
;
16444 /* Stop at nil string. */
16445 string
= AREF (items
, i
+ 1);
16449 /* Remember where item was displayed. */
16450 AREF (items
, i
+ 3) = make_number (it
.hpos
);
16452 /* Display the item, pad with one space. */
16453 if (it
.current_x
< it
.last_visible_x
)
16454 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
16455 SCHARS (string
) + 1, 0, 0, -1);
16458 /* Fill out the line with spaces. */
16459 if (it
.current_x
< it
.last_visible_x
)
16460 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
16462 /* Compute the total height of the lines. */
16463 compute_line_metrics (&it
);
16468 /***********************************************************************
16470 ***********************************************************************/
16472 /* Redisplay mode lines in the window tree whose root is WINDOW. If
16473 FORCE is non-zero, redisplay mode lines unconditionally.
16474 Otherwise, redisplay only mode lines that are garbaged. Value is
16475 the number of windows whose mode lines were redisplayed. */
16478 redisplay_mode_lines (window
, force
)
16479 Lisp_Object window
;
16484 while (!NILP (window
))
16486 struct window
*w
= XWINDOW (window
);
16488 if (WINDOWP (w
->hchild
))
16489 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
16490 else if (WINDOWP (w
->vchild
))
16491 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
16493 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
16494 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
16496 struct text_pos lpoint
;
16497 struct buffer
*old
= current_buffer
;
16499 /* Set the window's buffer for the mode line display. */
16500 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16501 set_buffer_internal_1 (XBUFFER (w
->buffer
));
16503 /* Point refers normally to the selected window. For any
16504 other window, set up appropriate value. */
16505 if (!EQ (window
, selected_window
))
16507 struct text_pos pt
;
16509 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
16510 if (CHARPOS (pt
) < BEGV
)
16511 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16512 else if (CHARPOS (pt
) > (ZV
- 1))
16513 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
16515 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
16518 /* Display mode lines. */
16519 clear_glyph_matrix (w
->desired_matrix
);
16520 if (display_mode_lines (w
))
16523 w
->must_be_updated_p
= 1;
16526 /* Restore old settings. */
16527 set_buffer_internal_1 (old
);
16528 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16538 /* Display the mode and/or top line of window W. Value is the number
16539 of mode lines displayed. */
16542 display_mode_lines (w
)
16545 Lisp_Object old_selected_window
, old_selected_frame
;
16548 old_selected_frame
= selected_frame
;
16549 selected_frame
= w
->frame
;
16550 old_selected_window
= selected_window
;
16551 XSETWINDOW (selected_window
, w
);
16553 /* These will be set while the mode line specs are processed. */
16554 line_number_displayed
= 0;
16555 w
->column_number_displayed
= Qnil
;
16557 if (WINDOW_WANTS_MODELINE_P (w
))
16559 struct window
*sel_w
= XWINDOW (old_selected_window
);
16561 /* Select mode line face based on the real selected window. */
16562 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
16563 current_buffer
->mode_line_format
);
16567 if (WINDOW_WANTS_HEADER_LINE_P (w
))
16569 display_mode_line (w
, HEADER_LINE_FACE_ID
,
16570 current_buffer
->header_line_format
);
16574 selected_frame
= old_selected_frame
;
16575 selected_window
= old_selected_window
;
16580 /* Display mode or top line of window W. FACE_ID specifies which line
16581 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
16582 FORMAT is the mode line format to display. Value is the pixel
16583 height of the mode line displayed. */
16586 display_mode_line (w
, face_id
, format
)
16588 enum face_id face_id
;
16589 Lisp_Object format
;
16593 int count
= SPECPDL_INDEX ();
16595 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16596 /* Don't extend on a previously drawn mode-line.
16597 This may happen if called from pos_visible_p. */
16598 it
.glyph_row
->enabled_p
= 0;
16599 prepare_desired_row (it
.glyph_row
);
16601 it
.glyph_row
->mode_line_p
= 1;
16603 if (! mode_line_inverse_video
)
16604 /* Force the mode-line to be displayed in the default face. */
16605 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16607 record_unwind_protect (unwind_format_mode_line
,
16608 format_mode_line_unwind_data (NULL
, 0));
16610 mode_line_target
= MODE_LINE_DISPLAY
;
16612 /* Temporarily make frame's keyboard the current kboard so that
16613 kboard-local variables in the mode_line_format will get the right
16615 push_frame_kboard (it
.f
);
16616 record_unwind_save_match_data ();
16617 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16618 pop_frame_kboard ();
16620 unbind_to (count
, Qnil
);
16622 /* Fill up with spaces. */
16623 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
16625 compute_line_metrics (&it
);
16626 it
.glyph_row
->full_width_p
= 1;
16627 it
.glyph_row
->continued_p
= 0;
16628 it
.glyph_row
->truncated_on_left_p
= 0;
16629 it
.glyph_row
->truncated_on_right_p
= 0;
16631 /* Make a 3D mode-line have a shadow at its right end. */
16632 face
= FACE_FROM_ID (it
.f
, face_id
);
16633 extend_face_to_end_of_line (&it
);
16634 if (face
->box
!= FACE_NO_BOX
)
16636 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
16637 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
16638 last
->right_box_line_p
= 1;
16641 return it
.glyph_row
->height
;
16644 /* Move element ELT in LIST to the front of LIST.
16645 Return the updated list. */
16648 move_elt_to_front (elt
, list
)
16649 Lisp_Object elt
, list
;
16651 register Lisp_Object tail
, prev
;
16652 register Lisp_Object tem
;
16656 while (CONSP (tail
))
16662 /* Splice out the link TAIL. */
16664 list
= XCDR (tail
);
16666 Fsetcdr (prev
, XCDR (tail
));
16668 /* Now make it the first. */
16669 Fsetcdr (tail
, list
);
16674 tail
= XCDR (tail
);
16678 /* Not found--return unchanged LIST. */
16682 /* Contribute ELT to the mode line for window IT->w. How it
16683 translates into text depends on its data type.
16685 IT describes the display environment in which we display, as usual.
16687 DEPTH is the depth in recursion. It is used to prevent
16688 infinite recursion here.
16690 FIELD_WIDTH is the number of characters the display of ELT should
16691 occupy in the mode line, and PRECISION is the maximum number of
16692 characters to display from ELT's representation. See
16693 display_string for details.
16695 Returns the hpos of the end of the text generated by ELT.
16697 PROPS is a property list to add to any string we encounter.
16699 If RISKY is nonzero, remove (disregard) any properties in any string
16700 we encounter, and ignore :eval and :propertize.
16702 The global variable `mode_line_target' determines whether the
16703 output is passed to `store_mode_line_noprop',
16704 `store_mode_line_string', or `display_string'. */
16707 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
16710 int field_width
, precision
;
16711 Lisp_Object elt
, props
;
16714 int n
= 0, field
, prec
;
16719 elt
= build_string ("*too-deep*");
16723 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
16727 /* A string: output it and check for %-constructs within it. */
16731 if (SCHARS (elt
) > 0
16732 && (!NILP (props
) || risky
))
16734 Lisp_Object oprops
, aelt
;
16735 oprops
= Ftext_properties_at (make_number (0), elt
);
16737 /* If the starting string's properties are not what
16738 we want, translate the string. Also, if the string
16739 is risky, do that anyway. */
16741 if (NILP (Fequal (props
, oprops
)) || risky
)
16743 /* If the starting string has properties,
16744 merge the specified ones onto the existing ones. */
16745 if (! NILP (oprops
) && !risky
)
16749 oprops
= Fcopy_sequence (oprops
);
16751 while (CONSP (tem
))
16753 oprops
= Fplist_put (oprops
, XCAR (tem
),
16754 XCAR (XCDR (tem
)));
16755 tem
= XCDR (XCDR (tem
));
16760 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
16761 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
16763 /* AELT is what we want. Move it to the front
16764 without consing. */
16766 mode_line_proptrans_alist
16767 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
16773 /* If AELT has the wrong props, it is useless.
16774 so get rid of it. */
16776 mode_line_proptrans_alist
16777 = Fdelq (aelt
, mode_line_proptrans_alist
);
16779 elt
= Fcopy_sequence (elt
);
16780 Fset_text_properties (make_number (0), Flength (elt
),
16782 /* Add this item to mode_line_proptrans_alist. */
16783 mode_line_proptrans_alist
16784 = Fcons (Fcons (elt
, props
),
16785 mode_line_proptrans_alist
);
16786 /* Truncate mode_line_proptrans_alist
16787 to at most 50 elements. */
16788 tem
= Fnthcdr (make_number (50),
16789 mode_line_proptrans_alist
);
16791 XSETCDR (tem
, Qnil
);
16800 prec
= precision
- n
;
16801 switch (mode_line_target
)
16803 case MODE_LINE_NOPROP
:
16804 case MODE_LINE_TITLE
:
16805 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
16807 case MODE_LINE_STRING
:
16808 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
16810 case MODE_LINE_DISPLAY
:
16811 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
16812 0, prec
, 0, STRING_MULTIBYTE (elt
));
16819 /* Handle the non-literal case. */
16821 while ((precision
<= 0 || n
< precision
)
16822 && SREF (elt
, offset
) != 0
16823 && (mode_line_target
!= MODE_LINE_DISPLAY
16824 || it
->current_x
< it
->last_visible_x
))
16826 int last_offset
= offset
;
16828 /* Advance to end of string or next format specifier. */
16829 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
16832 if (offset
- 1 != last_offset
)
16834 int nchars
, nbytes
;
16836 /* Output to end of string or up to '%'. Field width
16837 is length of string. Don't output more than
16838 PRECISION allows us. */
16841 prec
= c_string_width (SDATA (elt
) + last_offset
,
16842 offset
- last_offset
, precision
- n
,
16845 switch (mode_line_target
)
16847 case MODE_LINE_NOPROP
:
16848 case MODE_LINE_TITLE
:
16849 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
16851 case MODE_LINE_STRING
:
16853 int bytepos
= last_offset
;
16854 int charpos
= string_byte_to_char (elt
, bytepos
);
16855 int endpos
= (precision
<= 0
16856 ? string_byte_to_char (elt
, offset
)
16857 : charpos
+ nchars
);
16859 n
+= store_mode_line_string (NULL
,
16860 Fsubstring (elt
, make_number (charpos
),
16861 make_number (endpos
)),
16865 case MODE_LINE_DISPLAY
:
16867 int bytepos
= last_offset
;
16868 int charpos
= string_byte_to_char (elt
, bytepos
);
16870 if (precision
<= 0)
16871 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
16872 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
16874 STRING_MULTIBYTE (elt
));
16879 else /* c == '%' */
16881 int percent_position
= offset
;
16883 /* Get the specified minimum width. Zero means
16886 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
16887 field
= field
* 10 + c
- '0';
16889 /* Don't pad beyond the total padding allowed. */
16890 if (field_width
- n
> 0 && field
> field_width
- n
)
16891 field
= field_width
- n
;
16893 /* Note that either PRECISION <= 0 or N < PRECISION. */
16894 prec
= precision
- n
;
16897 n
+= display_mode_element (it
, depth
, field
, prec
,
16898 Vglobal_mode_string
, props
,
16903 int bytepos
, charpos
;
16904 unsigned char *spec
;
16906 bytepos
= percent_position
;
16907 charpos
= (STRING_MULTIBYTE (elt
)
16908 ? string_byte_to_char (elt
, bytepos
)
16912 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
16914 switch (mode_line_target
)
16916 case MODE_LINE_NOPROP
:
16917 case MODE_LINE_TITLE
:
16918 n
+= store_mode_line_noprop (spec
, field
, prec
);
16920 case MODE_LINE_STRING
:
16922 int len
= strlen (spec
);
16923 Lisp_Object tem
= make_string (spec
, len
);
16924 props
= Ftext_properties_at (make_number (charpos
), elt
);
16925 /* Should only keep face property in props */
16926 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
16929 case MODE_LINE_DISPLAY
:
16931 int nglyphs_before
, nwritten
;
16933 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16934 nwritten
= display_string (spec
, Qnil
, elt
,
16939 /* Assign to the glyphs written above the
16940 string where the `%x' came from, position
16944 struct glyph
*glyph
16945 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
16949 for (i
= 0; i
< nwritten
; ++i
)
16951 glyph
[i
].object
= elt
;
16952 glyph
[i
].charpos
= charpos
;
16969 /* A symbol: process the value of the symbol recursively
16970 as if it appeared here directly. Avoid error if symbol void.
16971 Special case: if value of symbol is a string, output the string
16974 register Lisp_Object tem
;
16976 /* If the variable is not marked as risky to set
16977 then its contents are risky to use. */
16978 if (NILP (Fget (elt
, Qrisky_local_variable
)))
16981 tem
= Fboundp (elt
);
16984 tem
= Fsymbol_value (elt
);
16985 /* If value is a string, output that string literally:
16986 don't check for % within it. */
16990 if (!EQ (tem
, elt
))
16992 /* Give up right away for nil or t. */
17002 register Lisp_Object car
, tem
;
17004 /* A cons cell: five distinct cases.
17005 If first element is :eval or :propertize, do something special.
17006 If first element is a string or a cons, process all the elements
17007 and effectively concatenate them.
17008 If first element is a negative number, truncate displaying cdr to
17009 at most that many characters. If positive, pad (with spaces)
17010 to at least that many characters.
17011 If first element is a symbol, process the cadr or caddr recursively
17012 according to whether the symbol's value is non-nil or nil. */
17014 if (EQ (car
, QCeval
))
17016 /* An element of the form (:eval FORM) means evaluate FORM
17017 and use the result as mode line elements. */
17022 if (CONSP (XCDR (elt
)))
17025 spec
= safe_eval (XCAR (XCDR (elt
)));
17026 n
+= display_mode_element (it
, depth
, field_width
- n
,
17027 precision
- n
, spec
, props
,
17031 else if (EQ (car
, QCpropertize
))
17033 /* An element of the form (:propertize ELT PROPS...)
17034 means display ELT but applying properties PROPS. */
17039 if (CONSP (XCDR (elt
)))
17040 n
+= display_mode_element (it
, depth
, field_width
- n
,
17041 precision
- n
, XCAR (XCDR (elt
)),
17042 XCDR (XCDR (elt
)), risky
);
17044 else if (SYMBOLP (car
))
17046 tem
= Fboundp (car
);
17050 /* elt is now the cdr, and we know it is a cons cell.
17051 Use its car if CAR has a non-nil value. */
17054 tem
= Fsymbol_value (car
);
17061 /* Symbol's value is nil (or symbol is unbound)
17062 Get the cddr of the original list
17063 and if possible find the caddr and use that. */
17067 else if (!CONSP (elt
))
17072 else if (INTEGERP (car
))
17074 register int lim
= XINT (car
);
17078 /* Negative int means reduce maximum width. */
17079 if (precision
<= 0)
17082 precision
= min (precision
, -lim
);
17086 /* Padding specified. Don't let it be more than
17087 current maximum. */
17089 lim
= min (precision
, lim
);
17091 /* If that's more padding than already wanted, queue it.
17092 But don't reduce padding already specified even if
17093 that is beyond the current truncation point. */
17094 field_width
= max (lim
, field_width
);
17098 else if (STRINGP (car
) || CONSP (car
))
17100 register int limit
= 50;
17101 /* Limit is to protect against circular lists. */
17104 && (precision
<= 0 || n
< precision
))
17106 n
+= display_mode_element (it
, depth
,
17107 /* Do padding only after the last
17108 element in the list. */
17109 (! CONSP (XCDR (elt
))
17112 precision
- n
, XCAR (elt
),
17122 elt
= build_string ("*invalid*");
17126 /* Pad to FIELD_WIDTH. */
17127 if (field_width
> 0 && n
< field_width
)
17129 switch (mode_line_target
)
17131 case MODE_LINE_NOPROP
:
17132 case MODE_LINE_TITLE
:
17133 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
17135 case MODE_LINE_STRING
:
17136 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
17138 case MODE_LINE_DISPLAY
:
17139 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
17148 /* Store a mode-line string element in mode_line_string_list.
17150 If STRING is non-null, display that C string. Otherwise, the Lisp
17151 string LISP_STRING is displayed.
17153 FIELD_WIDTH is the minimum number of output glyphs to produce.
17154 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17155 with spaces. FIELD_WIDTH <= 0 means don't pad.
17157 PRECISION is the maximum number of characters to output from
17158 STRING. PRECISION <= 0 means don't truncate the string.
17160 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
17161 properties to the string.
17163 PROPS are the properties to add to the string.
17164 The mode_line_string_face face property is always added to the string.
17168 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
17170 Lisp_Object lisp_string
;
17179 if (string
!= NULL
)
17181 len
= strlen (string
);
17182 if (precision
> 0 && len
> precision
)
17184 lisp_string
= make_string (string
, len
);
17186 props
= mode_line_string_face_prop
;
17187 else if (!NILP (mode_line_string_face
))
17189 Lisp_Object face
= Fplist_get (props
, Qface
);
17190 props
= Fcopy_sequence (props
);
17192 face
= mode_line_string_face
;
17194 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17195 props
= Fplist_put (props
, Qface
, face
);
17197 Fadd_text_properties (make_number (0), make_number (len
),
17198 props
, lisp_string
);
17202 len
= XFASTINT (Flength (lisp_string
));
17203 if (precision
> 0 && len
> precision
)
17206 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
17209 if (!NILP (mode_line_string_face
))
17213 props
= Ftext_properties_at (make_number (0), lisp_string
);
17214 face
= Fplist_get (props
, Qface
);
17216 face
= mode_line_string_face
;
17218 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17219 props
= Fcons (Qface
, Fcons (face
, Qnil
));
17221 lisp_string
= Fcopy_sequence (lisp_string
);
17224 Fadd_text_properties (make_number (0), make_number (len
),
17225 props
, lisp_string
);
17230 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17234 if (field_width
> len
)
17236 field_width
-= len
;
17237 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17239 Fadd_text_properties (make_number (0), make_number (field_width
),
17240 props
, lisp_string
);
17241 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17249 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17251 doc
: /* Format a string out of a mode line format specification.
17252 First arg FORMAT specifies the mode line format (see `mode-line-format'
17253 for details) to use.
17255 Optional second arg FACE specifies the face property to put
17256 on all characters for which no face is specified.
17257 t means whatever face the window's mode line currently uses
17258 \(either `mode-line' or `mode-line-inactive', depending).
17259 nil means the default is no face property.
17260 If FACE is an integer, the value string has no text properties.
17262 Optional third and fourth args WINDOW and BUFFER specify the window
17263 and buffer to use as the context for the formatting (defaults
17264 are the selected window and the window's buffer). */)
17265 (format
, face
, window
, buffer
)
17266 Lisp_Object format
, face
, window
, buffer
;
17271 struct buffer
*old_buffer
= NULL
;
17273 int no_props
= INTEGERP (face
);
17274 int count
= SPECPDL_INDEX ();
17276 int string_start
= 0;
17279 window
= selected_window
;
17280 CHECK_WINDOW (window
);
17281 w
= XWINDOW (window
);
17284 buffer
= w
->buffer
;
17285 CHECK_BUFFER (buffer
);
17288 return build_string ("");
17296 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
17297 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
17301 face_id
= DEFAULT_FACE_ID
;
17303 if (XBUFFER (buffer
) != current_buffer
)
17304 old_buffer
= current_buffer
;
17306 /* Save things including mode_line_proptrans_alist,
17307 and set that to nil so that we don't alter the outer value. */
17308 record_unwind_protect (unwind_format_mode_line
,
17309 format_mode_line_unwind_data (old_buffer
, 1));
17310 mode_line_proptrans_alist
= Qnil
;
17313 set_buffer_internal_1 (XBUFFER (buffer
));
17315 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17319 mode_line_target
= MODE_LINE_NOPROP
;
17320 mode_line_string_face_prop
= Qnil
;
17321 mode_line_string_list
= Qnil
;
17322 string_start
= MODE_LINE_NOPROP_LEN (0);
17326 mode_line_target
= MODE_LINE_STRING
;
17327 mode_line_string_list
= Qnil
;
17328 mode_line_string_face
= face
;
17329 mode_line_string_face_prop
17330 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
17333 push_frame_kboard (it
.f
);
17334 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17335 pop_frame_kboard ();
17339 len
= MODE_LINE_NOPROP_LEN (string_start
);
17340 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
17344 mode_line_string_list
= Fnreverse (mode_line_string_list
);
17345 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
17346 make_string ("", 0));
17349 unbind_to (count
, Qnil
);
17353 /* Write a null-terminated, right justified decimal representation of
17354 the positive integer D to BUF using a minimal field width WIDTH. */
17357 pint2str (buf
, width
, d
)
17358 register char *buf
;
17359 register int width
;
17362 register char *p
= buf
;
17370 *p
++ = d
% 10 + '0';
17375 for (width
-= (int) (p
- buf
); width
> 0; --width
)
17386 /* Write a null-terminated, right justified decimal and "human
17387 readable" representation of the nonnegative integer D to BUF using
17388 a minimal field width WIDTH. D should be smaller than 999.5e24. */
17390 static const char power_letter
[] =
17404 pint2hrstr (buf
, width
, d
)
17409 /* We aim to represent the nonnegative integer D as
17410 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
17413 /* -1 means: do not use TENTHS. */
17417 /* Length of QUOTIENT.TENTHS as a string. */
17423 if (1000 <= quotient
)
17425 /* Scale to the appropriate EXPONENT. */
17428 remainder
= quotient
% 1000;
17432 while (1000 <= quotient
);
17434 /* Round to nearest and decide whether to use TENTHS or not. */
17437 tenths
= remainder
/ 100;
17438 if (50 <= remainder
% 100)
17445 if (quotient
== 10)
17453 if (500 <= remainder
)
17455 if (quotient
< 999)
17466 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
17467 if (tenths
== -1 && quotient
<= 99)
17474 p
= psuffix
= buf
+ max (width
, length
);
17476 /* Print EXPONENT. */
17478 *psuffix
++ = power_letter
[exponent
];
17481 /* Print TENTHS. */
17484 *--p
= '0' + tenths
;
17488 /* Print QUOTIENT. */
17491 int digit
= quotient
% 10;
17492 *--p
= '0' + digit
;
17494 while ((quotient
/= 10) != 0);
17496 /* Print leading spaces. */
17501 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
17502 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
17503 type of CODING_SYSTEM. Return updated pointer into BUF. */
17505 static unsigned char invalid_eol_type
[] = "(*invalid*)";
17508 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
17509 Lisp_Object coding_system
;
17510 register char *buf
;
17514 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
17515 const unsigned char *eol_str
;
17517 /* The EOL conversion we are using. */
17518 Lisp_Object eoltype
;
17520 val
= Fget (coding_system
, Qcoding_system
);
17523 if (!VECTORP (val
)) /* Not yet decided. */
17528 eoltype
= eol_mnemonic_undecided
;
17529 /* Don't mention EOL conversion if it isn't decided. */
17533 Lisp_Object eolvalue
;
17535 eolvalue
= Fget (coding_system
, Qeol_type
);
17538 *buf
++ = XFASTINT (AREF (val
, 1));
17542 /* The EOL conversion that is normal on this system. */
17544 if (NILP (eolvalue
)) /* Not yet decided. */
17545 eoltype
= eol_mnemonic_undecided
;
17546 else if (VECTORP (eolvalue
)) /* Not yet decided. */
17547 eoltype
= eol_mnemonic_undecided
;
17548 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
17549 eoltype
= (XFASTINT (eolvalue
) == 0
17550 ? eol_mnemonic_unix
17551 : (XFASTINT (eolvalue
) == 1
17552 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
17558 /* Mention the EOL conversion if it is not the usual one. */
17559 if (STRINGP (eoltype
))
17561 eol_str
= SDATA (eoltype
);
17562 eol_str_len
= SBYTES (eoltype
);
17564 else if (INTEGERP (eoltype
)
17565 && CHAR_VALID_P (XINT (eoltype
), 0))
17567 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
17568 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
17573 eol_str
= invalid_eol_type
;
17574 eol_str_len
= sizeof (invalid_eol_type
) - 1;
17576 bcopy (eol_str
, buf
, eol_str_len
);
17577 buf
+= eol_str_len
;
17583 /* Return a string for the output of a mode line %-spec for window W,
17584 generated by character C. PRECISION >= 0 means don't return a
17585 string longer than that value. FIELD_WIDTH > 0 means pad the
17586 string returned with spaces to that value. Return 1 in *MULTIBYTE
17587 if the result is multibyte text.
17589 Note we operate on the current buffer for most purposes,
17590 the exception being w->base_line_pos. */
17592 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
17595 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
17598 int field_width
, precision
;
17602 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17603 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
17604 struct buffer
*b
= current_buffer
;
17612 if (!NILP (b
->read_only
))
17614 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17619 /* This differs from %* only for a modified read-only buffer. */
17620 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17622 if (!NILP (b
->read_only
))
17627 /* This differs from %* in ignoring read-only-ness. */
17628 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17640 if (command_loop_level
> 5)
17642 p
= decode_mode_spec_buf
;
17643 for (i
= 0; i
< command_loop_level
; i
++)
17646 return decode_mode_spec_buf
;
17654 if (command_loop_level
> 5)
17656 p
= decode_mode_spec_buf
;
17657 for (i
= 0; i
< command_loop_level
; i
++)
17660 return decode_mode_spec_buf
;
17667 /* Let lots_of_dashes be a string of infinite length. */
17668 if (mode_line_target
== MODE_LINE_NOPROP
||
17669 mode_line_target
== MODE_LINE_STRING
)
17671 if (field_width
<= 0
17672 || field_width
> sizeof (lots_of_dashes
))
17674 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
17675 decode_mode_spec_buf
[i
] = '-';
17676 decode_mode_spec_buf
[i
] = '\0';
17677 return decode_mode_spec_buf
;
17680 return lots_of_dashes
;
17688 /* %c and %l are ignored in `frame-title-format'.
17689 (In redisplay_internal, the frame title is drawn _before_ the
17690 windows are updated, so the stuff which depends on actual
17691 window contents (such as %l) may fail to render properly, or
17692 even crash emacs.) */
17693 if (mode_line_target
== MODE_LINE_TITLE
)
17697 int col
= (int) current_column (); /* iftc */
17698 w
->column_number_displayed
= make_number (col
);
17699 pint2str (decode_mode_spec_buf
, field_width
, col
);
17700 return decode_mode_spec_buf
;
17704 #ifndef SYSTEM_MALLOC
17706 if (NILP (Vmemory_full
))
17709 return "!MEM FULL! ";
17716 /* %F displays the frame name. */
17717 if (!NILP (f
->title
))
17718 return (char *) SDATA (f
->title
);
17719 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
17720 return (char *) SDATA (f
->name
);
17729 int size
= ZV
- BEGV
;
17730 pint2str (decode_mode_spec_buf
, field_width
, size
);
17731 return decode_mode_spec_buf
;
17736 int size
= ZV
- BEGV
;
17737 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
17738 return decode_mode_spec_buf
;
17743 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
17744 int topline
, nlines
, junk
, height
;
17746 /* %c and %l are ignored in `frame-title-format'. */
17747 if (mode_line_target
== MODE_LINE_TITLE
)
17750 startpos
= XMARKER (w
->start
)->charpos
;
17751 startpos_byte
= marker_byte_position (w
->start
);
17752 height
= WINDOW_TOTAL_LINES (w
);
17754 /* If we decided that this buffer isn't suitable for line numbers,
17755 don't forget that too fast. */
17756 if (EQ (w
->base_line_pos
, w
->buffer
))
17758 /* But do forget it, if the window shows a different buffer now. */
17759 else if (BUFFERP (w
->base_line_pos
))
17760 w
->base_line_pos
= Qnil
;
17762 /* If the buffer is very big, don't waste time. */
17763 if (INTEGERP (Vline_number_display_limit
)
17764 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
17766 w
->base_line_pos
= Qnil
;
17767 w
->base_line_number
= Qnil
;
17771 if (!NILP (w
->base_line_number
)
17772 && !NILP (w
->base_line_pos
)
17773 && XFASTINT (w
->base_line_pos
) <= startpos
)
17775 line
= XFASTINT (w
->base_line_number
);
17776 linepos
= XFASTINT (w
->base_line_pos
);
17777 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
17782 linepos
= BUF_BEGV (b
);
17783 linepos_byte
= BUF_BEGV_BYTE (b
);
17786 /* Count lines from base line to window start position. */
17787 nlines
= display_count_lines (linepos
, linepos_byte
,
17791 topline
= nlines
+ line
;
17793 /* Determine a new base line, if the old one is too close
17794 or too far away, or if we did not have one.
17795 "Too close" means it's plausible a scroll-down would
17796 go back past it. */
17797 if (startpos
== BUF_BEGV (b
))
17799 w
->base_line_number
= make_number (topline
);
17800 w
->base_line_pos
= make_number (BUF_BEGV (b
));
17802 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
17803 || linepos
== BUF_BEGV (b
))
17805 int limit
= BUF_BEGV (b
);
17806 int limit_byte
= BUF_BEGV_BYTE (b
);
17808 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
17810 if (startpos
- distance
> limit
)
17812 limit
= startpos
- distance
;
17813 limit_byte
= CHAR_TO_BYTE (limit
);
17816 nlines
= display_count_lines (startpos
, startpos_byte
,
17818 - (height
* 2 + 30),
17820 /* If we couldn't find the lines we wanted within
17821 line_number_display_limit_width chars per line,
17822 give up on line numbers for this window. */
17823 if (position
== limit_byte
&& limit
== startpos
- distance
)
17825 w
->base_line_pos
= w
->buffer
;
17826 w
->base_line_number
= Qnil
;
17830 w
->base_line_number
= make_number (topline
- nlines
);
17831 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
17834 /* Now count lines from the start pos to point. */
17835 nlines
= display_count_lines (startpos
, startpos_byte
,
17836 PT_BYTE
, PT
, &junk
);
17838 /* Record that we did display the line number. */
17839 line_number_displayed
= 1;
17841 /* Make the string to show. */
17842 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
17843 return decode_mode_spec_buf
;
17846 char* p
= decode_mode_spec_buf
;
17847 int pad
= field_width
- 2;
17853 return decode_mode_spec_buf
;
17859 obj
= b
->mode_name
;
17863 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
17869 int pos
= marker_position (w
->start
);
17870 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17872 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
17874 if (pos
<= BUF_BEGV (b
))
17879 else if (pos
<= BUF_BEGV (b
))
17883 if (total
> 1000000)
17884 /* Do it differently for a large value, to avoid overflow. */
17885 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17887 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17888 /* We can't normally display a 3-digit number,
17889 so get us a 2-digit number that is close. */
17892 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17893 return decode_mode_spec_buf
;
17897 /* Display percentage of size above the bottom of the screen. */
17900 int toppos
= marker_position (w
->start
);
17901 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
17902 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17904 if (botpos
>= BUF_ZV (b
))
17906 if (toppos
<= BUF_BEGV (b
))
17913 if (total
> 1000000)
17914 /* Do it differently for a large value, to avoid overflow. */
17915 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17917 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17918 /* We can't normally display a 3-digit number,
17919 so get us a 2-digit number that is close. */
17922 if (toppos
<= BUF_BEGV (b
))
17923 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
17925 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17926 return decode_mode_spec_buf
;
17931 /* status of process */
17932 obj
= Fget_buffer_process (Fcurrent_buffer ());
17934 return "no process";
17935 #ifdef subprocesses
17936 obj
= Fsymbol_name (Fprocess_status (obj
));
17940 case 't': /* indicate TEXT or BINARY */
17941 #ifdef MODE_LINE_BINARY_TEXT
17942 return MODE_LINE_BINARY_TEXT (b
);
17948 /* coding-system (not including end-of-line format) */
17950 /* coding-system (including end-of-line type) */
17952 int eol_flag
= (c
== 'Z');
17953 char *p
= decode_mode_spec_buf
;
17955 if (! FRAME_WINDOW_P (f
))
17957 /* No need to mention EOL here--the terminal never needs
17958 to do EOL conversion. */
17959 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
17960 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
17962 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
17965 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
17966 #ifdef subprocesses
17967 obj
= Fget_buffer_process (Fcurrent_buffer ());
17968 if (PROCESSP (obj
))
17970 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
17972 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
17975 #endif /* subprocesses */
17978 return decode_mode_spec_buf
;
17984 *multibyte
= STRING_MULTIBYTE (obj
);
17985 return (char *) SDATA (obj
);
17992 /* Count up to COUNT lines starting from START / START_BYTE.
17993 But don't go beyond LIMIT_BYTE.
17994 Return the number of lines thus found (always nonnegative).
17996 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
17999 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
18000 int start
, start_byte
, limit_byte
, count
;
18003 register unsigned char *cursor
;
18004 unsigned char *base
;
18006 register int ceiling
;
18007 register unsigned char *ceiling_addr
;
18008 int orig_count
= count
;
18010 /* If we are not in selective display mode,
18011 check only for newlines. */
18012 int selective_display
= (!NILP (current_buffer
->selective_display
)
18013 && !INTEGERP (current_buffer
->selective_display
));
18017 while (start_byte
< limit_byte
)
18019 ceiling
= BUFFER_CEILING_OF (start_byte
);
18020 ceiling
= min (limit_byte
- 1, ceiling
);
18021 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
18022 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
18025 if (selective_display
)
18026 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
18029 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
18032 if (cursor
!= ceiling_addr
)
18036 start_byte
+= cursor
- base
+ 1;
18037 *byte_pos_ptr
= start_byte
;
18041 if (++cursor
== ceiling_addr
)
18047 start_byte
+= cursor
- base
;
18052 while (start_byte
> limit_byte
)
18054 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
18055 ceiling
= max (limit_byte
, ceiling
);
18056 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
18057 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
18060 if (selective_display
)
18061 while (--cursor
!= ceiling_addr
18062 && *cursor
!= '\n' && *cursor
!= 015)
18065 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
18068 if (cursor
!= ceiling_addr
)
18072 start_byte
+= cursor
- base
+ 1;
18073 *byte_pos_ptr
= start_byte
;
18074 /* When scanning backwards, we should
18075 not count the newline posterior to which we stop. */
18076 return - orig_count
- 1;
18082 /* Here we add 1 to compensate for the last decrement
18083 of CURSOR, which took it past the valid range. */
18084 start_byte
+= cursor
- base
+ 1;
18088 *byte_pos_ptr
= limit_byte
;
18091 return - orig_count
+ count
;
18092 return orig_count
- count
;
18098 /***********************************************************************
18100 ***********************************************************************/
18102 /* Display a NUL-terminated string, starting with index START.
18104 If STRING is non-null, display that C string. Otherwise, the Lisp
18105 string LISP_STRING is displayed.
18107 If FACE_STRING is not nil, FACE_STRING_POS is a position in
18108 FACE_STRING. Display STRING or LISP_STRING with the face at
18109 FACE_STRING_POS in FACE_STRING:
18111 Display the string in the environment given by IT, but use the
18112 standard display table, temporarily.
18114 FIELD_WIDTH is the minimum number of output glyphs to produce.
18115 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18116 with spaces. If STRING has more characters, more than FIELD_WIDTH
18117 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
18119 PRECISION is the maximum number of characters to output from
18120 STRING. PRECISION < 0 means don't truncate the string.
18122 This is roughly equivalent to printf format specifiers:
18124 FIELD_WIDTH PRECISION PRINTF
18125 ----------------------------------------
18131 MULTIBYTE zero means do not display multibyte chars, > 0 means do
18132 display them, and < 0 means obey the current buffer's value of
18133 enable_multibyte_characters.
18135 Value is the number of columns displayed. */
18138 display_string (string
, lisp_string
, face_string
, face_string_pos
,
18139 start
, it
, field_width
, precision
, max_x
, multibyte
)
18140 unsigned char *string
;
18141 Lisp_Object lisp_string
;
18142 Lisp_Object face_string
;
18143 int face_string_pos
;
18146 int field_width
, precision
, max_x
;
18149 int hpos_at_start
= it
->hpos
;
18150 int saved_face_id
= it
->face_id
;
18151 struct glyph_row
*row
= it
->glyph_row
;
18153 /* Initialize the iterator IT for iteration over STRING beginning
18154 with index START. */
18155 reseat_to_string (it
, string
, lisp_string
, start
,
18156 precision
, field_width
, multibyte
);
18158 /* If displaying STRING, set up the face of the iterator
18159 from LISP_STRING, if that's given. */
18160 if (STRINGP (face_string
))
18166 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
18167 0, it
->region_beg_charpos
,
18168 it
->region_end_charpos
,
18169 &endptr
, it
->base_face_id
, 0);
18170 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18171 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
18174 /* Set max_x to the maximum allowed X position. Don't let it go
18175 beyond the right edge of the window. */
18177 max_x
= it
->last_visible_x
;
18179 max_x
= min (max_x
, it
->last_visible_x
);
18181 /* Skip over display elements that are not visible. because IT->w is
18183 if (it
->current_x
< it
->first_visible_x
)
18184 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
18185 MOVE_TO_POS
| MOVE_TO_X
);
18187 row
->ascent
= it
->max_ascent
;
18188 row
->height
= it
->max_ascent
+ it
->max_descent
;
18189 row
->phys_ascent
= it
->max_phys_ascent
;
18190 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18191 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18193 /* This condition is for the case that we are called with current_x
18194 past last_visible_x. */
18195 while (it
->current_x
< max_x
)
18197 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
18199 /* Get the next display element. */
18200 if (!get_next_display_element (it
))
18203 /* Produce glyphs. */
18204 x_before
= it
->current_x
;
18205 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18206 PRODUCE_GLYPHS (it
);
18208 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
18211 while (i
< nglyphs
)
18213 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18215 if (!it
->truncate_lines_p
18216 && x
+ glyph
->pixel_width
> max_x
)
18218 /* End of continued line or max_x reached. */
18219 if (CHAR_GLYPH_PADDING_P (*glyph
))
18221 /* A wide character is unbreakable. */
18222 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18223 it
->current_x
= x_before
;
18227 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18232 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
18234 /* Glyph is at least partially visible. */
18236 if (x
< it
->first_visible_x
)
18237 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18241 /* Glyph is off the left margin of the display area.
18242 Should not happen. */
18246 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18247 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18248 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18249 row
->phys_height
= max (row
->phys_height
,
18250 it
->max_phys_ascent
+ it
->max_phys_descent
);
18251 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18252 it
->max_extra_line_spacing
);
18253 x
+= glyph
->pixel_width
;
18257 /* Stop if max_x reached. */
18261 /* Stop at line ends. */
18262 if (ITERATOR_AT_END_OF_LINE_P (it
))
18264 it
->continuation_lines_width
= 0;
18268 set_iterator_to_next (it
, 1);
18270 /* Stop if truncating at the right edge. */
18271 if (it
->truncate_lines_p
18272 && it
->current_x
>= it
->last_visible_x
)
18274 /* Add truncation mark, but don't do it if the line is
18275 truncated at a padding space. */
18276 if (IT_CHARPOS (*it
) < it
->string_nchars
)
18278 if (!FRAME_WINDOW_P (it
->f
))
18282 if (it
->current_x
> it
->last_visible_x
)
18284 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18285 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18287 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18289 row
->used
[TEXT_AREA
] = i
;
18290 produce_special_glyphs (it
, IT_TRUNCATION
);
18293 produce_special_glyphs (it
, IT_TRUNCATION
);
18295 it
->glyph_row
->truncated_on_right_p
= 1;
18301 /* Maybe insert a truncation at the left. */
18302 if (it
->first_visible_x
18303 && IT_CHARPOS (*it
) > 0)
18305 if (!FRAME_WINDOW_P (it
->f
))
18306 insert_left_trunc_glyphs (it
);
18307 it
->glyph_row
->truncated_on_left_p
= 1;
18310 it
->face_id
= saved_face_id
;
18312 /* Value is number of columns displayed. */
18313 return it
->hpos
- hpos_at_start
;
18318 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
18319 appears as an element of LIST or as the car of an element of LIST.
18320 If PROPVAL is a list, compare each element against LIST in that
18321 way, and return 1/2 if any element of PROPVAL is found in LIST.
18322 Otherwise return 0. This function cannot quit.
18323 The return value is 2 if the text is invisible but with an ellipsis
18324 and 1 if it's invisible and without an ellipsis. */
18327 invisible_p (propval
, list
)
18328 register Lisp_Object propval
;
18331 register Lisp_Object tail
, proptail
;
18333 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18335 register Lisp_Object tem
;
18337 if (EQ (propval
, tem
))
18339 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
18340 return NILP (XCDR (tem
)) ? 1 : 2;
18343 if (CONSP (propval
))
18345 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
18347 Lisp_Object propelt
;
18348 propelt
= XCAR (proptail
);
18349 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18351 register Lisp_Object tem
;
18353 if (EQ (propelt
, tem
))
18355 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
18356 return NILP (XCDR (tem
)) ? 1 : 2;
18364 /* Calculate a width or height in pixels from a specification using
18365 the following elements:
18368 NUM - a (fractional) multiple of the default font width/height
18369 (NUM) - specifies exactly NUM pixels
18370 UNIT - a fixed number of pixels, see below.
18371 ELEMENT - size of a display element in pixels, see below.
18372 (NUM . SPEC) - equals NUM * SPEC
18373 (+ SPEC SPEC ...) - add pixel values
18374 (- SPEC SPEC ...) - subtract pixel values
18375 (- SPEC) - negate pixel value
18378 INT or FLOAT - a number constant
18379 SYMBOL - use symbol's (buffer local) variable binding.
18382 in - pixels per inch *)
18383 mm - pixels per 1/1000 meter *)
18384 cm - pixels per 1/100 meter *)
18385 width - width of current font in pixels.
18386 height - height of current font in pixels.
18388 *) using the ratio(s) defined in display-pixels-per-inch.
18392 left-fringe - left fringe width in pixels
18393 right-fringe - right fringe width in pixels
18395 left-margin - left margin width in pixels
18396 right-margin - right margin width in pixels
18398 scroll-bar - scroll-bar area width in pixels
18402 Pixels corresponding to 5 inches:
18405 Total width of non-text areas on left side of window (if scroll-bar is on left):
18406 '(space :width (+ left-fringe left-margin scroll-bar))
18408 Align to first text column (in header line):
18409 '(space :align-to 0)
18411 Align to middle of text area minus half the width of variable `my-image'
18412 containing a loaded image:
18413 '(space :align-to (0.5 . (- text my-image)))
18415 Width of left margin minus width of 1 character in the default font:
18416 '(space :width (- left-margin 1))
18418 Width of left margin minus width of 2 characters in the current font:
18419 '(space :width (- left-margin (2 . width)))
18421 Center 1 character over left-margin (in header line):
18422 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
18424 Different ways to express width of left fringe plus left margin minus one pixel:
18425 '(space :width (- (+ left-fringe left-margin) (1)))
18426 '(space :width (+ left-fringe left-margin (- (1))))
18427 '(space :width (+ left-fringe left-margin (-1)))
18431 #define NUMVAL(X) \
18432 ((INTEGERP (X) || FLOATP (X)) \
18437 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
18442 int width_p
, *align_to
;
18446 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
18447 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
18450 return OK_PIXELS (0);
18452 if (SYMBOLP (prop
))
18454 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18456 char *unit
= SDATA (SYMBOL_NAME (prop
));
18458 if (unit
[0] == 'i' && unit
[1] == 'n')
18460 else if (unit
[0] == 'm' && unit
[1] == 'm')
18462 else if (unit
[0] == 'c' && unit
[1] == 'm')
18469 #ifdef HAVE_WINDOW_SYSTEM
18470 if (FRAME_WINDOW_P (it
->f
)
18472 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
18473 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
18475 return OK_PIXELS (ppi
/ pixels
);
18478 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18479 || (CONSP (Vdisplay_pixels_per_inch
)
18481 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18482 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18484 return OK_PIXELS (ppi
/ pixels
);
18490 #ifdef HAVE_WINDOW_SYSTEM
18491 if (EQ (prop
, Qheight
))
18492 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
18493 if (EQ (prop
, Qwidth
))
18494 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
18496 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
18497 return OK_PIXELS (1);
18500 if (EQ (prop
, Qtext
))
18501 return OK_PIXELS (width_p
18502 ? window_box_width (it
->w
, TEXT_AREA
)
18503 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
18505 if (align_to
&& *align_to
< 0)
18508 if (EQ (prop
, Qleft
))
18509 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
18510 if (EQ (prop
, Qright
))
18511 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
18512 if (EQ (prop
, Qcenter
))
18513 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
18514 + window_box_width (it
->w
, TEXT_AREA
) / 2);
18515 if (EQ (prop
, Qleft_fringe
))
18516 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18517 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
18518 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
18519 if (EQ (prop
, Qright_fringe
))
18520 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18521 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18522 : window_box_right_offset (it
->w
, TEXT_AREA
));
18523 if (EQ (prop
, Qleft_margin
))
18524 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
18525 if (EQ (prop
, Qright_margin
))
18526 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
18527 if (EQ (prop
, Qscroll_bar
))
18528 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18530 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18531 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18532 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18537 if (EQ (prop
, Qleft_fringe
))
18538 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18539 if (EQ (prop
, Qright_fringe
))
18540 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18541 if (EQ (prop
, Qleft_margin
))
18542 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18543 if (EQ (prop
, Qright_margin
))
18544 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18545 if (EQ (prop
, Qscroll_bar
))
18546 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18549 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18552 if (INTEGERP (prop
) || FLOATP (prop
))
18554 int base_unit
= (width_p
18555 ? FRAME_COLUMN_WIDTH (it
->f
)
18556 : FRAME_LINE_HEIGHT (it
->f
));
18557 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18562 Lisp_Object car
= XCAR (prop
);
18563 Lisp_Object cdr
= XCDR (prop
);
18567 #ifdef HAVE_WINDOW_SYSTEM
18568 if (valid_image_p (prop
))
18570 int id
= lookup_image (it
->f
, prop
);
18571 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
18573 return OK_PIXELS (width_p
? img
->width
: img
->height
);
18576 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18582 while (CONSP (cdr
))
18584 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
18585 font
, width_p
, align_to
))
18588 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18593 if (EQ (car
, Qminus
))
18595 return OK_PIXELS (pixels
);
18598 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18601 if (INTEGERP (car
) || FLOATP (car
))
18604 pixels
= XFLOATINT (car
);
18606 return OK_PIXELS (pixels
);
18607 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
18608 font
, width_p
, align_to
))
18609 return OK_PIXELS (pixels
* fact
);
18620 /***********************************************************************
18622 ***********************************************************************/
18624 #ifdef HAVE_WINDOW_SYSTEM
18629 dump_glyph_string (s
)
18630 struct glyph_string
*s
;
18632 fprintf (stderr
, "glyph string\n");
18633 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
18634 s
->x
, s
->y
, s
->width
, s
->height
);
18635 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
18636 fprintf (stderr
, " hl = %d\n", s
->hl
);
18637 fprintf (stderr
, " left overhang = %d, right = %d\n",
18638 s
->left_overhang
, s
->right_overhang
);
18639 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
18640 fprintf (stderr
, " extends to end of line = %d\n",
18641 s
->extends_to_end_of_line_p
);
18642 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
18643 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
18646 #endif /* GLYPH_DEBUG */
18648 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
18649 of XChar2b structures for S; it can't be allocated in
18650 init_glyph_string because it must be allocated via `alloca'. W
18651 is the window on which S is drawn. ROW and AREA are the glyph row
18652 and area within the row from which S is constructed. START is the
18653 index of the first glyph structure covered by S. HL is a
18654 face-override for drawing S. */
18657 #define OPTIONAL_HDC(hdc) hdc,
18658 #define DECLARE_HDC(hdc) HDC hdc;
18659 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
18660 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
18663 #ifndef OPTIONAL_HDC
18664 #define OPTIONAL_HDC(hdc)
18665 #define DECLARE_HDC(hdc)
18666 #define ALLOCATE_HDC(hdc, f)
18667 #define RELEASE_HDC(hdc, f)
18671 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
18672 struct glyph_string
*s
;
18676 struct glyph_row
*row
;
18677 enum glyph_row_area area
;
18679 enum draw_glyphs_face hl
;
18681 bzero (s
, sizeof *s
);
18683 s
->f
= XFRAME (w
->frame
);
18687 s
->display
= FRAME_X_DISPLAY (s
->f
);
18688 s
->window
= FRAME_X_WINDOW (s
->f
);
18689 s
->char2b
= char2b
;
18693 s
->first_glyph
= row
->glyphs
[area
] + start
;
18694 s
->height
= row
->height
;
18695 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
18697 /* Display the internal border below the tool-bar window. */
18698 if (WINDOWP (s
->f
->tool_bar_window
)
18699 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
18700 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
18702 s
->ybase
= s
->y
+ row
->ascent
;
18706 /* Append the list of glyph strings with head H and tail T to the list
18707 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
18710 append_glyph_string_lists (head
, tail
, h
, t
)
18711 struct glyph_string
**head
, **tail
;
18712 struct glyph_string
*h
, *t
;
18726 /* Prepend the list of glyph strings with head H and tail T to the
18727 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
18731 prepend_glyph_string_lists (head
, tail
, h
, t
)
18732 struct glyph_string
**head
, **tail
;
18733 struct glyph_string
*h
, *t
;
18747 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
18748 Set *HEAD and *TAIL to the resulting list. */
18751 append_glyph_string (head
, tail
, s
)
18752 struct glyph_string
**head
, **tail
;
18753 struct glyph_string
*s
;
18755 s
->next
= s
->prev
= NULL
;
18756 append_glyph_string_lists (head
, tail
, s
, s
);
18760 /* Get face and two-byte form of character glyph GLYPH on frame F.
18761 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
18762 a pointer to a realized face that is ready for display. */
18764 static INLINE
struct face
*
18765 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
18767 struct glyph
*glyph
;
18773 xassert (glyph
->type
== CHAR_GLYPH
);
18774 face
= FACE_FROM_ID (f
, glyph
->face_id
);
18779 if (!glyph
->multibyte_p
)
18781 /* Unibyte case. We don't have to encode, but we have to make
18782 sure to use a face suitable for unibyte. */
18783 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18785 else if (glyph
->u
.ch
< 128)
18787 /* Case of ASCII in a face known to fit ASCII. */
18788 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18792 int c1
, c2
, charset
;
18794 /* Split characters into bytes. If c2 is -1 afterwards, C is
18795 really a one-byte character so that byte1 is zero. */
18796 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
18798 STORE_XCHAR2B (char2b
, c1
, c2
);
18800 STORE_XCHAR2B (char2b
, 0, c1
);
18802 /* Maybe encode the character in *CHAR2B. */
18803 if (charset
!= CHARSET_ASCII
)
18805 struct font_info
*font_info
18806 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18809 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
18813 /* Make sure X resources of the face are allocated. */
18814 xassert (face
!= NULL
);
18815 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18820 /* Fill glyph string S with composition components specified by S->cmp.
18822 FACES is an array of faces for all components of this composition.
18823 S->gidx is the index of the first component for S.
18825 OVERLAPS non-zero means S should draw the foreground only, and use
18826 its physical height for clipping. See also draw_glyphs.
18828 Value is the index of a component not in S. */
18831 fill_composite_glyph_string (s
, faces
, overlaps
)
18832 struct glyph_string
*s
;
18833 struct face
**faces
;
18840 s
->for_overlaps
= overlaps
;
18842 s
->face
= faces
[s
->gidx
];
18843 s
->font
= s
->face
->font
;
18844 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18846 /* For all glyphs of this composition, starting at the offset
18847 S->gidx, until we reach the end of the definition or encounter a
18848 glyph that requires the different face, add it to S. */
18850 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
18853 /* All glyph strings for the same composition has the same width,
18854 i.e. the width set for the first component of the composition. */
18856 s
->width
= s
->first_glyph
->pixel_width
;
18858 /* If the specified font could not be loaded, use the frame's
18859 default font, but record the fact that we couldn't load it in
18860 the glyph string so that we can draw rectangles for the
18861 characters of the glyph string. */
18862 if (s
->font
== NULL
)
18864 s
->font_not_found_p
= 1;
18865 s
->font
= FRAME_FONT (s
->f
);
18868 /* Adjust base line for subscript/superscript text. */
18869 s
->ybase
+= s
->first_glyph
->voffset
;
18871 xassert (s
->face
&& s
->face
->gc
);
18873 /* This glyph string must always be drawn with 16-bit functions. */
18876 return s
->gidx
+ s
->nchars
;
18880 /* Fill glyph string S from a sequence of character glyphs.
18882 FACE_ID is the face id of the string. START is the index of the
18883 first glyph to consider, END is the index of the last + 1.
18884 OVERLAPS non-zero means S should draw the foreground only, and use
18885 its physical height for clipping. See also draw_glyphs.
18887 Value is the index of the first glyph not in S. */
18890 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
18891 struct glyph_string
*s
;
18893 int start
, end
, overlaps
;
18895 struct glyph
*glyph
, *last
;
18897 int glyph_not_available_p
;
18899 xassert (s
->f
== XFRAME (s
->w
->frame
));
18900 xassert (s
->nchars
== 0);
18901 xassert (start
>= 0 && end
> start
);
18903 s
->for_overlaps
= overlaps
,
18904 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18905 last
= s
->row
->glyphs
[s
->area
] + end
;
18906 voffset
= glyph
->voffset
;
18908 glyph_not_available_p
= glyph
->glyph_not_available_p
;
18910 while (glyph
< last
18911 && glyph
->type
== CHAR_GLYPH
18912 && glyph
->voffset
== voffset
18913 /* Same face id implies same font, nowadays. */
18914 && glyph
->face_id
== face_id
18915 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
18919 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
18920 s
->char2b
+ s
->nchars
,
18922 s
->two_byte_p
= two_byte_p
;
18924 xassert (s
->nchars
<= end
- start
);
18925 s
->width
+= glyph
->pixel_width
;
18929 s
->font
= s
->face
->font
;
18930 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18932 /* If the specified font could not be loaded, use the frame's font,
18933 but record the fact that we couldn't load it in
18934 S->font_not_found_p so that we can draw rectangles for the
18935 characters of the glyph string. */
18936 if (s
->font
== NULL
|| glyph_not_available_p
)
18938 s
->font_not_found_p
= 1;
18939 s
->font
= FRAME_FONT (s
->f
);
18942 /* Adjust base line for subscript/superscript text. */
18943 s
->ybase
+= voffset
;
18945 xassert (s
->face
&& s
->face
->gc
);
18946 return glyph
- s
->row
->glyphs
[s
->area
];
18950 /* Fill glyph string S from image glyph S->first_glyph. */
18953 fill_image_glyph_string (s
)
18954 struct glyph_string
*s
;
18956 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
18957 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
18959 s
->slice
= s
->first_glyph
->slice
;
18960 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
18961 s
->font
= s
->face
->font
;
18962 s
->width
= s
->first_glyph
->pixel_width
;
18964 /* Adjust base line for subscript/superscript text. */
18965 s
->ybase
+= s
->first_glyph
->voffset
;
18969 /* Fill glyph string S from a sequence of stretch glyphs.
18971 ROW is the glyph row in which the glyphs are found, AREA is the
18972 area within the row. START is the index of the first glyph to
18973 consider, END is the index of the last + 1.
18975 Value is the index of the first glyph not in S. */
18978 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
18979 struct glyph_string
*s
;
18980 struct glyph_row
*row
;
18981 enum glyph_row_area area
;
18984 struct glyph
*glyph
, *last
;
18985 int voffset
, face_id
;
18987 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
18989 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18990 last
= s
->row
->glyphs
[s
->area
] + end
;
18991 face_id
= glyph
->face_id
;
18992 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
18993 s
->font
= s
->face
->font
;
18994 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18995 s
->width
= glyph
->pixel_width
;
18997 voffset
= glyph
->voffset
;
19001 && glyph
->type
== STRETCH_GLYPH
19002 && glyph
->voffset
== voffset
19003 && glyph
->face_id
== face_id
);
19005 s
->width
+= glyph
->pixel_width
;
19007 /* Adjust base line for subscript/superscript text. */
19008 s
->ybase
+= voffset
;
19010 /* The case that face->gc == 0 is handled when drawing the glyph
19011 string by calling PREPARE_FACE_FOR_DISPLAY. */
19013 return glyph
- s
->row
->glyphs
[s
->area
];
19018 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
19019 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
19020 assumed to be zero. */
19023 x_get_glyph_overhangs (glyph
, f
, left
, right
)
19024 struct glyph
*glyph
;
19028 *left
= *right
= 0;
19030 if (glyph
->type
== CHAR_GLYPH
)
19034 struct font_info
*font_info
;
19038 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
19040 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
19041 if (font
/* ++KFS: Should this be font_info ? */
19042 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
19044 if (pcm
->rbearing
> pcm
->width
)
19045 *right
= pcm
->rbearing
- pcm
->width
;
19046 if (pcm
->lbearing
< 0)
19047 *left
= -pcm
->lbearing
;
19053 /* Return the index of the first glyph preceding glyph string S that
19054 is overwritten by S because of S's left overhang. Value is -1
19055 if no glyphs are overwritten. */
19058 left_overwritten (s
)
19059 struct glyph_string
*s
;
19063 if (s
->left_overhang
)
19066 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19067 int first
= s
->first_glyph
- glyphs
;
19069 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
19070 x
-= glyphs
[i
].pixel_width
;
19081 /* Return the index of the first glyph preceding glyph string S that
19082 is overwriting S because of its right overhang. Value is -1 if no
19083 glyph in front of S overwrites S. */
19086 left_overwriting (s
)
19087 struct glyph_string
*s
;
19090 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19091 int first
= s
->first_glyph
- glyphs
;
19095 for (i
= first
- 1; i
>= 0; --i
)
19098 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19101 x
-= glyphs
[i
].pixel_width
;
19108 /* Return the index of the last glyph following glyph string S that is
19109 not overwritten by S because of S's right overhang. Value is -1 if
19110 no such glyph is found. */
19113 right_overwritten (s
)
19114 struct glyph_string
*s
;
19118 if (s
->right_overhang
)
19121 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19122 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19123 int end
= s
->row
->used
[s
->area
];
19125 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
19126 x
+= glyphs
[i
].pixel_width
;
19135 /* Return the index of the last glyph following glyph string S that
19136 overwrites S because of its left overhang. Value is negative
19137 if no such glyph is found. */
19140 right_overwriting (s
)
19141 struct glyph_string
*s
;
19144 int end
= s
->row
->used
[s
->area
];
19145 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19146 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19150 for (i
= first
; i
< end
; ++i
)
19153 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19156 x
+= glyphs
[i
].pixel_width
;
19163 /* Get face and two-byte form of character C in face FACE_ID on frame
19164 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19165 means we want to display multibyte text. DISPLAY_P non-zero means
19166 make sure that X resources for the face returned are allocated.
19167 Value is a pointer to a realized face that is ready for display if
19168 DISPLAY_P is non-zero. */
19170 static INLINE
struct face
*
19171 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
19175 int multibyte_p
, display_p
;
19177 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19181 /* Unibyte case. We don't have to encode, but we have to make
19182 sure to use a face suitable for unibyte. */
19183 STORE_XCHAR2B (char2b
, 0, c
);
19184 face_id
= FACE_FOR_CHAR (f
, face
, c
);
19185 face
= FACE_FROM_ID (f
, face_id
);
19189 /* Case of ASCII in a face known to fit ASCII. */
19190 STORE_XCHAR2B (char2b
, 0, c
);
19194 int c1
, c2
, charset
;
19196 /* Split characters into bytes. If c2 is -1 afterwards, C is
19197 really a one-byte character so that byte1 is zero. */
19198 SPLIT_CHAR (c
, charset
, c1
, c2
);
19200 STORE_XCHAR2B (char2b
, c1
, c2
);
19202 STORE_XCHAR2B (char2b
, 0, c1
);
19204 /* Maybe encode the character in *CHAR2B. */
19205 if (face
->font
!= NULL
)
19207 struct font_info
*font_info
19208 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
19210 rif
->encode_char (c
, char2b
, font_info
, 0);
19214 /* Make sure X resources of the face are allocated. */
19215 #ifdef HAVE_X_WINDOWS
19219 xassert (face
!= NULL
);
19220 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19227 /* Set background width of glyph string S. START is the index of the
19228 first glyph following S. LAST_X is the right-most x-position + 1
19229 in the drawing area. */
19232 set_glyph_string_background_width (s
, start
, last_x
)
19233 struct glyph_string
*s
;
19237 /* If the face of this glyph string has to be drawn to the end of
19238 the drawing area, set S->extends_to_end_of_line_p. */
19240 if (start
== s
->row
->used
[s
->area
]
19241 && s
->area
== TEXT_AREA
19242 && ((s
->row
->fill_line_p
19243 && (s
->hl
== DRAW_NORMAL_TEXT
19244 || s
->hl
== DRAW_IMAGE_RAISED
19245 || s
->hl
== DRAW_IMAGE_SUNKEN
))
19246 || s
->hl
== DRAW_MOUSE_FACE
))
19247 s
->extends_to_end_of_line_p
= 1;
19249 /* If S extends its face to the end of the line, set its
19250 background_width to the distance to the right edge of the drawing
19252 if (s
->extends_to_end_of_line_p
)
19253 s
->background_width
= last_x
- s
->x
+ 1;
19255 s
->background_width
= s
->width
;
19259 /* Compute overhangs and x-positions for glyph string S and its
19260 predecessors, or successors. X is the starting x-position for S.
19261 BACKWARD_P non-zero means process predecessors. */
19264 compute_overhangs_and_x (s
, x
, backward_p
)
19265 struct glyph_string
*s
;
19273 if (rif
->compute_glyph_string_overhangs
)
19274 rif
->compute_glyph_string_overhangs (s
);
19284 if (rif
->compute_glyph_string_overhangs
)
19285 rif
->compute_glyph_string_overhangs (s
);
19295 /* The following macros are only called from draw_glyphs below.
19296 They reference the following parameters of that function directly:
19297 `w', `row', `area', and `overlap_p'
19298 as well as the following local variables:
19299 `s', `f', and `hdc' (in W32) */
19302 /* On W32, silently add local `hdc' variable to argument list of
19303 init_glyph_string. */
19304 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19305 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
19307 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19308 init_glyph_string (s, char2b, w, row, area, start, hl)
19311 /* Add a glyph string for a stretch glyph to the list of strings
19312 between HEAD and TAIL. START is the index of the stretch glyph in
19313 row area AREA of glyph row ROW. END is the index of the last glyph
19314 in that glyph row area. X is the current output position assigned
19315 to the new glyph string constructed. HL overrides that face of the
19316 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19317 is the right-most x-position of the drawing area. */
19319 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
19320 and below -- keep them on one line. */
19321 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19324 s = (struct glyph_string *) alloca (sizeof *s); \
19325 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19326 START = fill_stretch_glyph_string (s, row, area, START, END); \
19327 append_glyph_string (&HEAD, &TAIL, s); \
19333 /* Add a glyph string for an image glyph to the list of strings
19334 between HEAD and TAIL. START is the index of the image glyph in
19335 row area AREA of glyph row ROW. END is the index of the last glyph
19336 in that glyph row area. X is the current output position assigned
19337 to the new glyph string constructed. HL overrides that face of the
19338 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19339 is the right-most x-position of the drawing area. */
19341 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19344 s = (struct glyph_string *) alloca (sizeof *s); \
19345 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19346 fill_image_glyph_string (s); \
19347 append_glyph_string (&HEAD, &TAIL, s); \
19354 /* Add a glyph string for a sequence of character glyphs to the list
19355 of strings between HEAD and TAIL. START is the index of the first
19356 glyph in row area AREA of glyph row ROW that is part of the new
19357 glyph string. END is the index of the last glyph in that glyph row
19358 area. X is the current output position assigned to the new glyph
19359 string constructed. HL overrides that face of the glyph; e.g. it
19360 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
19361 right-most x-position of the drawing area. */
19363 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19369 c = (row)->glyphs[area][START].u.ch; \
19370 face_id = (row)->glyphs[area][START].face_id; \
19372 s = (struct glyph_string *) alloca (sizeof *s); \
19373 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
19374 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
19375 append_glyph_string (&HEAD, &TAIL, s); \
19377 START = fill_glyph_string (s, face_id, START, END, overlaps); \
19382 /* Add a glyph string for a composite sequence to the list of strings
19383 between HEAD and TAIL. START is the index of the first glyph in
19384 row area AREA of glyph row ROW that is part of the new glyph
19385 string. END is the index of the last glyph in that glyph row area.
19386 X is the current output position assigned to the new glyph string
19387 constructed. HL overrides that face of the glyph; e.g. it is
19388 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
19389 x-position of the drawing area. */
19391 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19393 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
19394 int face_id = (row)->glyphs[area][START].face_id; \
19395 struct face *base_face = FACE_FROM_ID (f, face_id); \
19396 struct composition *cmp = composition_table[cmp_id]; \
19397 int glyph_len = cmp->glyph_len; \
19399 struct face **faces; \
19400 struct glyph_string *first_s = NULL; \
19403 base_face = base_face->ascii_face; \
19404 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
19405 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
19406 /* At first, fill in `char2b' and `faces'. */ \
19407 for (n = 0; n < glyph_len; n++) \
19409 int c = COMPOSITION_GLYPH (cmp, n); \
19410 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
19411 faces[n] = FACE_FROM_ID (f, this_face_id); \
19412 get_char_face_and_encoding (f, c, this_face_id, \
19413 char2b + n, 1, 1); \
19416 /* Make glyph_strings for each glyph sequence that is drawable by \
19417 the same face, and append them to HEAD/TAIL. */ \
19418 for (n = 0; n < cmp->glyph_len;) \
19420 s = (struct glyph_string *) alloca (sizeof *s); \
19421 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
19422 append_glyph_string (&(HEAD), &(TAIL), s); \
19430 n = fill_composite_glyph_string (s, faces, overlaps); \
19438 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
19439 of AREA of glyph row ROW on window W between indices START and END.
19440 HL overrides the face for drawing glyph strings, e.g. it is
19441 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
19442 x-positions of the drawing area.
19444 This is an ugly monster macro construct because we must use alloca
19445 to allocate glyph strings (because draw_glyphs can be called
19446 asynchronously). */
19448 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19451 HEAD = TAIL = NULL; \
19452 while (START < END) \
19454 struct glyph *first_glyph = (row)->glyphs[area] + START; \
19455 switch (first_glyph->type) \
19458 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
19462 case COMPOSITE_GLYPH: \
19463 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
19467 case STRETCH_GLYPH: \
19468 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
19472 case IMAGE_GLYPH: \
19473 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
19481 set_glyph_string_background_width (s, START, LAST_X); \
19488 /* Draw glyphs between START and END in AREA of ROW on window W,
19489 starting at x-position X. X is relative to AREA in W. HL is a
19490 face-override with the following meaning:
19492 DRAW_NORMAL_TEXT draw normally
19493 DRAW_CURSOR draw in cursor face
19494 DRAW_MOUSE_FACE draw in mouse face.
19495 DRAW_INVERSE_VIDEO draw in mode line face
19496 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
19497 DRAW_IMAGE_RAISED draw an image with a raised relief around it
19499 If OVERLAPS is non-zero, draw only the foreground of characters and
19500 clip to the physical height of ROW. Non-zero value also defines
19501 the overlapping part to be drawn:
19503 OVERLAPS_PRED overlap with preceding rows
19504 OVERLAPS_SUCC overlap with succeeding rows
19505 OVERLAPS_BOTH overlap with both preceding/succeeding rows
19506 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
19508 Value is the x-position reached, relative to AREA of W. */
19511 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
19514 struct glyph_row
*row
;
19515 enum glyph_row_area area
;
19517 enum draw_glyphs_face hl
;
19520 struct glyph_string
*head
, *tail
;
19521 struct glyph_string
*s
;
19522 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
19523 int last_x
, area_width
;
19526 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19529 ALLOCATE_HDC (hdc
, f
);
19531 /* Let's rather be paranoid than getting a SEGV. */
19532 end
= min (end
, row
->used
[area
]);
19533 start
= max (0, start
);
19534 start
= min (end
, start
);
19536 /* Translate X to frame coordinates. Set last_x to the right
19537 end of the drawing area. */
19538 if (row
->full_width_p
)
19540 /* X is relative to the left edge of W, without scroll bars
19542 x
+= WINDOW_LEFT_EDGE_X (w
);
19543 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
19547 int area_left
= window_box_left (w
, area
);
19549 area_width
= window_box_width (w
, area
);
19550 last_x
= area_left
+ area_width
;
19553 /* Build a doubly-linked list of glyph_string structures between
19554 head and tail from what we have to draw. Note that the macro
19555 BUILD_GLYPH_STRINGS will modify its start parameter. That's
19556 the reason we use a separate variable `i'. */
19558 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
19560 x_reached
= tail
->x
+ tail
->background_width
;
19564 /* If there are any glyphs with lbearing < 0 or rbearing > width in
19565 the row, redraw some glyphs in front or following the glyph
19566 strings built above. */
19567 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
19570 struct glyph_string
*h
, *t
;
19572 /* Compute overhangs for all glyph strings. */
19573 if (rif
->compute_glyph_string_overhangs
)
19574 for (s
= head
; s
; s
= s
->next
)
19575 rif
->compute_glyph_string_overhangs (s
);
19577 /* Prepend glyph strings for glyphs in front of the first glyph
19578 string that are overwritten because of the first glyph
19579 string's left overhang. The background of all strings
19580 prepended must be drawn because the first glyph string
19582 i
= left_overwritten (head
);
19586 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
19587 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19589 compute_overhangs_and_x (t
, head
->x
, 1);
19590 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19594 /* Prepend glyph strings for glyphs in front of the first glyph
19595 string that overwrite that glyph string because of their
19596 right overhang. For these strings, only the foreground must
19597 be drawn, because it draws over the glyph string at `head'.
19598 The background must not be drawn because this would overwrite
19599 right overhangs of preceding glyphs for which no glyph
19601 i
= left_overwriting (head
);
19605 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
19606 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19607 for (s
= h
; s
; s
= s
->next
)
19608 s
->background_filled_p
= 1;
19609 compute_overhangs_and_x (t
, head
->x
, 1);
19610 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19613 /* Append glyphs strings for glyphs following the last glyph
19614 string tail that are overwritten by tail. The background of
19615 these strings has to be drawn because tail's foreground draws
19617 i
= right_overwritten (tail
);
19620 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19621 DRAW_NORMAL_TEXT
, x
, last_x
);
19622 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19623 append_glyph_string_lists (&head
, &tail
, h
, t
);
19627 /* Append glyph strings for glyphs following the last glyph
19628 string tail that overwrite tail. The foreground of such
19629 glyphs has to be drawn because it writes into the background
19630 of tail. The background must not be drawn because it could
19631 paint over the foreground of following glyphs. */
19632 i
= right_overwriting (tail
);
19636 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19637 DRAW_NORMAL_TEXT
, x
, last_x
);
19638 for (s
= h
; s
; s
= s
->next
)
19639 s
->background_filled_p
= 1;
19640 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19641 append_glyph_string_lists (&head
, &tail
, h
, t
);
19643 if (clip_head
|| clip_tail
)
19644 for (s
= head
; s
; s
= s
->next
)
19646 s
->clip_head
= clip_head
;
19647 s
->clip_tail
= clip_tail
;
19651 /* Draw all strings. */
19652 for (s
= head
; s
; s
= s
->next
)
19653 rif
->draw_glyph_string (s
);
19655 if (area
== TEXT_AREA
19656 && !row
->full_width_p
19657 /* When drawing overlapping rows, only the glyph strings'
19658 foreground is drawn, which doesn't erase a cursor
19662 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
19663 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
19664 : (tail
? tail
->x
+ tail
->background_width
: x
));
19666 int text_left
= window_box_left (w
, TEXT_AREA
);
19670 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
19671 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
19674 /* Value is the x-position up to which drawn, relative to AREA of W.
19675 This doesn't include parts drawn because of overhangs. */
19676 if (row
->full_width_p
)
19677 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
19679 x_reached
-= window_box_left (w
, area
);
19681 RELEASE_HDC (hdc
, f
);
19686 /* Expand row matrix if too narrow. Don't expand if area
19689 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
19691 if (!fonts_changed_p \
19692 && (it->glyph_row->glyphs[area] \
19693 < it->glyph_row->glyphs[area + 1])) \
19695 it->w->ncols_scale_factor++; \
19696 fonts_changed_p = 1; \
19700 /* Store one glyph for IT->char_to_display in IT->glyph_row.
19701 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19707 struct glyph
*glyph
;
19708 enum glyph_row_area area
= it
->area
;
19710 xassert (it
->glyph_row
);
19711 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
19713 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19714 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19716 glyph
->charpos
= CHARPOS (it
->position
);
19717 glyph
->object
= it
->object
;
19718 glyph
->pixel_width
= it
->pixel_width
;
19719 glyph
->ascent
= it
->ascent
;
19720 glyph
->descent
= it
->descent
;
19721 glyph
->voffset
= it
->voffset
;
19722 glyph
->type
= CHAR_GLYPH
;
19723 glyph
->multibyte_p
= it
->multibyte_p
;
19724 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19725 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19726 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19727 || it
->phys_descent
> it
->descent
);
19728 glyph
->padding_p
= 0;
19729 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
19730 glyph
->face_id
= it
->face_id
;
19731 glyph
->u
.ch
= it
->char_to_display
;
19732 glyph
->slice
= null_glyph_slice
;
19733 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19734 ++it
->glyph_row
->used
[area
];
19737 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19740 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
19741 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19744 append_composite_glyph (it
)
19747 struct glyph
*glyph
;
19748 enum glyph_row_area area
= it
->area
;
19750 xassert (it
->glyph_row
);
19752 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19753 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19755 glyph
->charpos
= CHARPOS (it
->position
);
19756 glyph
->object
= it
->object
;
19757 glyph
->pixel_width
= it
->pixel_width
;
19758 glyph
->ascent
= it
->ascent
;
19759 glyph
->descent
= it
->descent
;
19760 glyph
->voffset
= it
->voffset
;
19761 glyph
->type
= COMPOSITE_GLYPH
;
19762 glyph
->multibyte_p
= it
->multibyte_p
;
19763 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19764 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19765 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19766 || it
->phys_descent
> it
->descent
);
19767 glyph
->padding_p
= 0;
19768 glyph
->glyph_not_available_p
= 0;
19769 glyph
->face_id
= it
->face_id
;
19770 glyph
->u
.cmp_id
= it
->cmp_id
;
19771 glyph
->slice
= null_glyph_slice
;
19772 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19773 ++it
->glyph_row
->used
[area
];
19776 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19780 /* Change IT->ascent and IT->height according to the setting of
19784 take_vertical_position_into_account (it
)
19789 if (it
->voffset
< 0)
19790 /* Increase the ascent so that we can display the text higher
19792 it
->ascent
-= it
->voffset
;
19794 /* Increase the descent so that we can display the text lower
19796 it
->descent
+= it
->voffset
;
19801 /* Produce glyphs/get display metrics for the image IT is loaded with.
19802 See the description of struct display_iterator in dispextern.h for
19803 an overview of struct display_iterator. */
19806 produce_image_glyph (it
)
19811 int glyph_ascent
, crop
;
19812 struct glyph_slice slice
;
19814 xassert (it
->what
== IT_IMAGE
);
19816 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19818 /* Make sure X resources of the face is loaded. */
19819 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19821 if (it
->image_id
< 0)
19823 /* Fringe bitmap. */
19824 it
->ascent
= it
->phys_ascent
= 0;
19825 it
->descent
= it
->phys_descent
= 0;
19826 it
->pixel_width
= 0;
19831 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
19833 /* Make sure X resources of the image is loaded. */
19834 prepare_image_for_display (it
->f
, img
);
19836 slice
.x
= slice
.y
= 0;
19837 slice
.width
= img
->width
;
19838 slice
.height
= img
->height
;
19840 if (INTEGERP (it
->slice
.x
))
19841 slice
.x
= XINT (it
->slice
.x
);
19842 else if (FLOATP (it
->slice
.x
))
19843 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
19845 if (INTEGERP (it
->slice
.y
))
19846 slice
.y
= XINT (it
->slice
.y
);
19847 else if (FLOATP (it
->slice
.y
))
19848 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
19850 if (INTEGERP (it
->slice
.width
))
19851 slice
.width
= XINT (it
->slice
.width
);
19852 else if (FLOATP (it
->slice
.width
))
19853 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
19855 if (INTEGERP (it
->slice
.height
))
19856 slice
.height
= XINT (it
->slice
.height
);
19857 else if (FLOATP (it
->slice
.height
))
19858 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
19860 if (slice
.x
>= img
->width
)
19861 slice
.x
= img
->width
;
19862 if (slice
.y
>= img
->height
)
19863 slice
.y
= img
->height
;
19864 if (slice
.x
+ slice
.width
>= img
->width
)
19865 slice
.width
= img
->width
- slice
.x
;
19866 if (slice
.y
+ slice
.height
> img
->height
)
19867 slice
.height
= img
->height
- slice
.y
;
19869 if (slice
.width
== 0 || slice
.height
== 0)
19872 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
19874 it
->descent
= slice
.height
- glyph_ascent
;
19876 it
->descent
+= img
->vmargin
;
19877 if (slice
.y
+ slice
.height
== img
->height
)
19878 it
->descent
+= img
->vmargin
;
19879 it
->phys_descent
= it
->descent
;
19881 it
->pixel_width
= slice
.width
;
19883 it
->pixel_width
+= img
->hmargin
;
19884 if (slice
.x
+ slice
.width
== img
->width
)
19885 it
->pixel_width
+= img
->hmargin
;
19887 /* It's quite possible for images to have an ascent greater than
19888 their height, so don't get confused in that case. */
19889 if (it
->descent
< 0)
19892 #if 0 /* this breaks image tiling */
19893 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
19894 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
19895 if (face_ascent
> it
->ascent
)
19896 it
->ascent
= it
->phys_ascent
= face_ascent
;
19901 if (face
->box
!= FACE_NO_BOX
)
19903 if (face
->box_line_width
> 0)
19906 it
->ascent
+= face
->box_line_width
;
19907 if (slice
.y
+ slice
.height
== img
->height
)
19908 it
->descent
+= face
->box_line_width
;
19911 if (it
->start_of_box_run_p
&& slice
.x
== 0)
19912 it
->pixel_width
+= abs (face
->box_line_width
);
19913 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
19914 it
->pixel_width
+= abs (face
->box_line_width
);
19917 take_vertical_position_into_account (it
);
19919 /* Automatically crop wide image glyphs at right edge so we can
19920 draw the cursor on same display row. */
19921 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
19922 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
19924 it
->pixel_width
-= crop
;
19925 slice
.width
-= crop
;
19930 struct glyph
*glyph
;
19931 enum glyph_row_area area
= it
->area
;
19933 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19934 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19936 glyph
->charpos
= CHARPOS (it
->position
);
19937 glyph
->object
= it
->object
;
19938 glyph
->pixel_width
= it
->pixel_width
;
19939 glyph
->ascent
= glyph_ascent
;
19940 glyph
->descent
= it
->descent
;
19941 glyph
->voffset
= it
->voffset
;
19942 glyph
->type
= IMAGE_GLYPH
;
19943 glyph
->multibyte_p
= it
->multibyte_p
;
19944 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19945 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19946 glyph
->overlaps_vertically_p
= 0;
19947 glyph
->padding_p
= 0;
19948 glyph
->glyph_not_available_p
= 0;
19949 glyph
->face_id
= it
->face_id
;
19950 glyph
->u
.img_id
= img
->id
;
19951 glyph
->slice
= slice
;
19952 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19953 ++it
->glyph_row
->used
[area
];
19956 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19961 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
19962 of the glyph, WIDTH and HEIGHT are the width and height of the
19963 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
19966 append_stretch_glyph (it
, object
, width
, height
, ascent
)
19968 Lisp_Object object
;
19972 struct glyph
*glyph
;
19973 enum glyph_row_area area
= it
->area
;
19975 xassert (ascent
>= 0 && ascent
<= height
);
19977 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19978 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19980 glyph
->charpos
= CHARPOS (it
->position
);
19981 glyph
->object
= object
;
19982 glyph
->pixel_width
= width
;
19983 glyph
->ascent
= ascent
;
19984 glyph
->descent
= height
- ascent
;
19985 glyph
->voffset
= it
->voffset
;
19986 glyph
->type
= STRETCH_GLYPH
;
19987 glyph
->multibyte_p
= it
->multibyte_p
;
19988 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19989 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19990 glyph
->overlaps_vertically_p
= 0;
19991 glyph
->padding_p
= 0;
19992 glyph
->glyph_not_available_p
= 0;
19993 glyph
->face_id
= it
->face_id
;
19994 glyph
->u
.stretch
.ascent
= ascent
;
19995 glyph
->u
.stretch
.height
= height
;
19996 glyph
->slice
= null_glyph_slice
;
19997 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19998 ++it
->glyph_row
->used
[area
];
20001 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20005 /* Produce a stretch glyph for iterator IT. IT->object is the value
20006 of the glyph property displayed. The value must be a list
20007 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
20010 1. `:width WIDTH' specifies that the space should be WIDTH *
20011 canonical char width wide. WIDTH may be an integer or floating
20014 2. `:relative-width FACTOR' specifies that the width of the stretch
20015 should be computed from the width of the first character having the
20016 `glyph' property, and should be FACTOR times that width.
20018 3. `:align-to HPOS' specifies that the space should be wide enough
20019 to reach HPOS, a value in canonical character units.
20021 Exactly one of the above pairs must be present.
20023 4. `:height HEIGHT' specifies that the height of the stretch produced
20024 should be HEIGHT, measured in canonical character units.
20026 5. `:relative-height FACTOR' specifies that the height of the
20027 stretch should be FACTOR times the height of the characters having
20028 the glyph property.
20030 Either none or exactly one of 4 or 5 must be present.
20032 6. `:ascent ASCENT' specifies that ASCENT percent of the height
20033 of the stretch should be used for the ascent of the stretch.
20034 ASCENT must be in the range 0 <= ASCENT <= 100. */
20037 produce_stretch_glyph (it
)
20040 /* (space :width WIDTH :height HEIGHT ...) */
20041 Lisp_Object prop
, plist
;
20042 int width
= 0, height
= 0, align_to
= -1;
20043 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
20046 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20047 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
20049 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20051 /* List should start with `space'. */
20052 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
20053 plist
= XCDR (it
->object
);
20055 /* Compute the width of the stretch. */
20056 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
20057 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
20059 /* Absolute width `:width WIDTH' specified and valid. */
20060 zero_width_ok_p
= 1;
20063 else if (prop
= Fplist_get (plist
, QCrelative_width
),
20066 /* Relative width `:relative-width FACTOR' specified and valid.
20067 Compute the width of the characters having the `glyph'
20070 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
20073 if (it
->multibyte_p
)
20075 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
20076 - IT_BYTEPOS (*it
));
20077 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
20080 it2
.c
= *p
, it2
.len
= 1;
20082 it2
.glyph_row
= NULL
;
20083 it2
.what
= IT_CHARACTER
;
20084 x_produce_glyphs (&it2
);
20085 width
= NUMVAL (prop
) * it2
.pixel_width
;
20087 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
20088 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
20090 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
20091 align_to
= (align_to
< 0
20093 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
20094 else if (align_to
< 0)
20095 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
20096 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
20097 zero_width_ok_p
= 1;
20100 /* Nothing specified -> width defaults to canonical char width. */
20101 width
= FRAME_COLUMN_WIDTH (it
->f
);
20103 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
20106 /* Compute height. */
20107 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
20108 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20111 zero_height_ok_p
= 1;
20113 else if (prop
= Fplist_get (plist
, QCrelative_height
),
20115 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
20117 height
= FONT_HEIGHT (font
);
20119 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
20122 /* Compute percentage of height used for ascent. If
20123 `:ascent ASCENT' is present and valid, use that. Otherwise,
20124 derive the ascent from the font in use. */
20125 if (prop
= Fplist_get (plist
, QCascent
),
20126 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
20127 ascent
= height
* NUMVAL (prop
) / 100.0;
20128 else if (!NILP (prop
)
20129 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20130 ascent
= min (max (0, (int)tem
), height
);
20132 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
20134 if (width
> 0 && !it
->truncate_lines_p
20135 && it
->current_x
+ width
> it
->last_visible_x
)
20136 width
= it
->last_visible_x
- it
->current_x
- 1;
20138 if (width
> 0 && height
> 0 && it
->glyph_row
)
20140 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
20141 if (!STRINGP (object
))
20142 object
= it
->w
->buffer
;
20143 append_stretch_glyph (it
, object
, width
, height
, ascent
);
20146 it
->pixel_width
= width
;
20147 it
->ascent
= it
->phys_ascent
= ascent
;
20148 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
20149 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
20151 take_vertical_position_into_account (it
);
20154 /* Get line-height and line-spacing property at point.
20155 If line-height has format (HEIGHT TOTAL), return TOTAL
20156 in TOTAL_HEIGHT. */
20159 get_line_height_property (it
, prop
)
20163 Lisp_Object position
;
20165 if (STRINGP (it
->object
))
20166 position
= make_number (IT_STRING_CHARPOS (*it
));
20167 else if (BUFFERP (it
->object
))
20168 position
= make_number (IT_CHARPOS (*it
));
20172 return Fget_char_property (position
, prop
, it
->object
);
20175 /* Calculate line-height and line-spacing properties.
20176 An integer value specifies explicit pixel value.
20177 A float value specifies relative value to current face height.
20178 A cons (float . face-name) specifies relative value to
20179 height of specified face font.
20181 Returns height in pixels, or nil. */
20185 calc_line_height_property (it
, val
, font
, boff
, override
)
20189 int boff
, override
;
20191 Lisp_Object face_name
= Qnil
;
20192 int ascent
, descent
, height
;
20194 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
20199 face_name
= XCAR (val
);
20201 if (!NUMBERP (val
))
20202 val
= make_number (1);
20203 if (NILP (face_name
))
20205 height
= it
->ascent
+ it
->descent
;
20210 if (NILP (face_name
))
20212 font
= FRAME_FONT (it
->f
);
20213 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20215 else if (EQ (face_name
, Qt
))
20223 struct font_info
*font_info
;
20225 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
20227 return make_number (-1);
20229 face
= FACE_FROM_ID (it
->f
, face_id
);
20232 return make_number (-1);
20234 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20235 boff
= font_info
->baseline_offset
;
20236 if (font_info
->vertical_centering
)
20237 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20240 ascent
= FONT_BASE (font
) + boff
;
20241 descent
= FONT_DESCENT (font
) - boff
;
20245 it
->override_ascent
= ascent
;
20246 it
->override_descent
= descent
;
20247 it
->override_boff
= boff
;
20250 height
= ascent
+ descent
;
20254 height
= (int)(XFLOAT_DATA (val
) * height
);
20255 else if (INTEGERP (val
))
20256 height
*= XINT (val
);
20258 return make_number (height
);
20263 Produce glyphs/get display metrics for the display element IT is
20264 loaded with. See the description of struct it in dispextern.h
20265 for an overview of struct it. */
20268 x_produce_glyphs (it
)
20271 int extra_line_spacing
= it
->extra_line_spacing
;
20273 it
->glyph_not_available_p
= 0;
20275 if (it
->what
== IT_CHARACTER
)
20279 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20281 int font_not_found_p
;
20282 struct font_info
*font_info
;
20283 int boff
; /* baseline offset */
20284 /* We may change it->multibyte_p upon unibyte<->multibyte
20285 conversion. So, save the current value now and restore it
20288 Note: It seems that we don't have to record multibyte_p in
20289 struct glyph because the character code itself tells if or
20290 not the character is multibyte. Thus, in the future, we must
20291 consider eliminating the field `multibyte_p' in the struct
20293 int saved_multibyte_p
= it
->multibyte_p
;
20295 /* Maybe translate single-byte characters to multibyte, or the
20297 it
->char_to_display
= it
->c
;
20298 if (!ASCII_BYTE_P (it
->c
))
20300 if (unibyte_display_via_language_environment
20301 && SINGLE_BYTE_CHAR_P (it
->c
)
20303 || !NILP (Vnonascii_translation_table
)))
20305 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20306 it
->multibyte_p
= 1;
20307 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20308 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20310 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
20311 && !it
->multibyte_p
)
20313 it
->multibyte_p
= 1;
20314 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20315 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20319 /* Get font to use. Encode IT->char_to_display. */
20320 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20321 &char2b
, it
->multibyte_p
, 0);
20324 /* When no suitable font found, use the default font. */
20325 font_not_found_p
= font
== NULL
;
20326 if (font_not_found_p
)
20328 font
= FRAME_FONT (it
->f
);
20329 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20334 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20335 boff
= font_info
->baseline_offset
;
20336 if (font_info
->vertical_centering
)
20337 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20340 if (it
->char_to_display
>= ' '
20341 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
20343 /* Either unibyte or ASCII. */
20348 pcm
= rif
->per_char_metric (font
, &char2b
,
20349 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
20351 if (it
->override_ascent
>= 0)
20353 it
->ascent
= it
->override_ascent
;
20354 it
->descent
= it
->override_descent
;
20355 boff
= it
->override_boff
;
20359 it
->ascent
= FONT_BASE (font
) + boff
;
20360 it
->descent
= FONT_DESCENT (font
) - boff
;
20365 it
->phys_ascent
= pcm
->ascent
+ boff
;
20366 it
->phys_descent
= pcm
->descent
- boff
;
20367 it
->pixel_width
= pcm
->width
;
20371 it
->glyph_not_available_p
= 1;
20372 it
->phys_ascent
= it
->ascent
;
20373 it
->phys_descent
= it
->descent
;
20374 it
->pixel_width
= FONT_WIDTH (font
);
20377 if (it
->constrain_row_ascent_descent_p
)
20379 if (it
->descent
> it
->max_descent
)
20381 it
->ascent
+= it
->descent
- it
->max_descent
;
20382 it
->descent
= it
->max_descent
;
20384 if (it
->ascent
> it
->max_ascent
)
20386 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20387 it
->ascent
= it
->max_ascent
;
20389 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20390 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20391 extra_line_spacing
= 0;
20394 /* If this is a space inside a region of text with
20395 `space-width' property, change its width. */
20396 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
20398 it
->pixel_width
*= XFLOATINT (it
->space_width
);
20400 /* If face has a box, add the box thickness to the character
20401 height. If character has a box line to the left and/or
20402 right, add the box line width to the character's width. */
20403 if (face
->box
!= FACE_NO_BOX
)
20405 int thick
= face
->box_line_width
;
20409 it
->ascent
+= thick
;
20410 it
->descent
+= thick
;
20415 if (it
->start_of_box_run_p
)
20416 it
->pixel_width
+= thick
;
20417 if (it
->end_of_box_run_p
)
20418 it
->pixel_width
+= thick
;
20421 /* If face has an overline, add the height of the overline
20422 (1 pixel) and a 1 pixel margin to the character height. */
20423 if (face
->overline_p
)
20424 it
->ascent
+= overline_margin
;
20426 if (it
->constrain_row_ascent_descent_p
)
20428 if (it
->ascent
> it
->max_ascent
)
20429 it
->ascent
= it
->max_ascent
;
20430 if (it
->descent
> it
->max_descent
)
20431 it
->descent
= it
->max_descent
;
20434 take_vertical_position_into_account (it
);
20436 /* If we have to actually produce glyphs, do it. */
20441 /* Translate a space with a `space-width' property
20442 into a stretch glyph. */
20443 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
20444 / FONT_HEIGHT (font
));
20445 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20446 it
->ascent
+ it
->descent
, ascent
);
20451 /* If characters with lbearing or rbearing are displayed
20452 in this line, record that fact in a flag of the
20453 glyph row. This is used to optimize X output code. */
20454 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
20455 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20458 else if (it
->char_to_display
== '\n')
20460 /* A newline has no width but we need the height of the line.
20461 But if previous part of the line set a height, don't
20462 increase that height */
20464 Lisp_Object height
;
20465 Lisp_Object total_height
= Qnil
;
20467 it
->override_ascent
= -1;
20468 it
->pixel_width
= 0;
20471 height
= get_line_height_property(it
, Qline_height
);
20472 /* Split (line-height total-height) list */
20474 && CONSP (XCDR (height
))
20475 && NILP (XCDR (XCDR (height
))))
20477 total_height
= XCAR (XCDR (height
));
20478 height
= XCAR (height
);
20480 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
20482 if (it
->override_ascent
>= 0)
20484 it
->ascent
= it
->override_ascent
;
20485 it
->descent
= it
->override_descent
;
20486 boff
= it
->override_boff
;
20490 it
->ascent
= FONT_BASE (font
) + boff
;
20491 it
->descent
= FONT_DESCENT (font
) - boff
;
20494 if (EQ (height
, Qt
))
20496 if (it
->descent
> it
->max_descent
)
20498 it
->ascent
+= it
->descent
- it
->max_descent
;
20499 it
->descent
= it
->max_descent
;
20501 if (it
->ascent
> it
->max_ascent
)
20503 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20504 it
->ascent
= it
->max_ascent
;
20506 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20507 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20508 it
->constrain_row_ascent_descent_p
= 1;
20509 extra_line_spacing
= 0;
20513 Lisp_Object spacing
;
20515 it
->phys_ascent
= it
->ascent
;
20516 it
->phys_descent
= it
->descent
;
20518 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
20519 && face
->box
!= FACE_NO_BOX
20520 && face
->box_line_width
> 0)
20522 it
->ascent
+= face
->box_line_width
;
20523 it
->descent
+= face
->box_line_width
;
20526 && XINT (height
) > it
->ascent
+ it
->descent
)
20527 it
->ascent
= XINT (height
) - it
->descent
;
20529 if (!NILP (total_height
))
20530 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
20533 spacing
= get_line_height_property(it
, Qline_spacing
);
20534 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
20536 if (INTEGERP (spacing
))
20538 extra_line_spacing
= XINT (spacing
);
20539 if (!NILP (total_height
))
20540 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
20544 else if (it
->char_to_display
== '\t')
20546 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
20547 int x
= it
->current_x
+ it
->continuation_lines_width
;
20548 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
20550 /* If the distance from the current position to the next tab
20551 stop is less than a space character width, use the
20552 tab stop after that. */
20553 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
20554 next_tab_x
+= tab_width
;
20556 it
->pixel_width
= next_tab_x
- x
;
20558 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
20559 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20563 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20564 it
->ascent
+ it
->descent
, it
->ascent
);
20569 /* A multi-byte character. Assume that the display width of the
20570 character is the width of the character multiplied by the
20571 width of the font. */
20573 /* If we found a font, this font should give us the right
20574 metrics. If we didn't find a font, use the frame's
20575 default font and calculate the width of the character
20576 from the charset width; this is what old redisplay code
20579 pcm
= rif
->per_char_metric (font
, &char2b
,
20580 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
20582 if (font_not_found_p
|| !pcm
)
20584 int charset
= CHAR_CHARSET (it
->char_to_display
);
20586 it
->glyph_not_available_p
= 1;
20587 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
20588 * CHARSET_WIDTH (charset
));
20589 it
->phys_ascent
= FONT_BASE (font
) + boff
;
20590 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20594 it
->pixel_width
= pcm
->width
;
20595 it
->phys_ascent
= pcm
->ascent
+ boff
;
20596 it
->phys_descent
= pcm
->descent
- boff
;
20598 && (pcm
->lbearing
< 0
20599 || pcm
->rbearing
> pcm
->width
))
20600 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20603 it
->ascent
= FONT_BASE (font
) + boff
;
20604 it
->descent
= FONT_DESCENT (font
) - boff
;
20605 if (face
->box
!= FACE_NO_BOX
)
20607 int thick
= face
->box_line_width
;
20611 it
->ascent
+= thick
;
20612 it
->descent
+= thick
;
20617 if (it
->start_of_box_run_p
)
20618 it
->pixel_width
+= thick
;
20619 if (it
->end_of_box_run_p
)
20620 it
->pixel_width
+= thick
;
20623 /* If face has an overline, add the height of the overline
20624 (1 pixel) and a 1 pixel margin to the character height. */
20625 if (face
->overline_p
)
20626 it
->ascent
+= overline_margin
;
20628 take_vertical_position_into_account (it
);
20633 it
->multibyte_p
= saved_multibyte_p
;
20635 else if (it
->what
== IT_COMPOSITION
)
20637 /* Note: A composition is represented as one glyph in the
20638 glyph matrix. There are no padding glyphs. */
20641 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20643 int font_not_found_p
;
20644 struct font_info
*font_info
;
20645 int boff
; /* baseline offset */
20646 struct composition
*cmp
= composition_table
[it
->cmp_id
];
20648 /* Maybe translate single-byte characters to multibyte. */
20649 it
->char_to_display
= it
->c
;
20650 if (unibyte_display_via_language_environment
20651 && SINGLE_BYTE_CHAR_P (it
->c
)
20654 && !NILP (Vnonascii_translation_table
))))
20656 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20659 /* Get face and font to use. Encode IT->char_to_display. */
20660 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20661 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20662 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20663 &char2b
, it
->multibyte_p
, 0);
20666 /* When no suitable font found, use the default font. */
20667 font_not_found_p
= font
== NULL
;
20668 if (font_not_found_p
)
20670 font
= FRAME_FONT (it
->f
);
20671 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20676 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20677 boff
= font_info
->baseline_offset
;
20678 if (font_info
->vertical_centering
)
20679 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20682 /* There are no padding glyphs, so there is only one glyph to
20683 produce for the composition. Important is that pixel_width,
20684 ascent and descent are the values of what is drawn by
20685 draw_glyphs (i.e. the values of the overall glyphs composed). */
20688 /* If we have not yet calculated pixel size data of glyphs of
20689 the composition for the current face font, calculate them
20690 now. Theoretically, we have to check all fonts for the
20691 glyphs, but that requires much time and memory space. So,
20692 here we check only the font of the first glyph. This leads
20693 to incorrect display very rarely, and C-l (recenter) can
20694 correct the display anyway. */
20695 if (cmp
->font
!= (void *) font
)
20697 /* Ascent and descent of the font of the first character of
20698 this composition (adjusted by baseline offset). Ascent
20699 and descent of overall glyphs should not be less than
20700 them respectively. */
20701 int font_ascent
= FONT_BASE (font
) + boff
;
20702 int font_descent
= FONT_DESCENT (font
) - boff
;
20703 /* Bounding box of the overall glyphs. */
20704 int leftmost
, rightmost
, lowest
, highest
;
20705 int i
, width
, ascent
, descent
;
20707 cmp
->font
= (void *) font
;
20709 /* Initialize the bounding box. */
20711 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20712 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
20714 width
= pcm
->width
;
20715 ascent
= pcm
->ascent
;
20716 descent
= pcm
->descent
;
20720 width
= FONT_WIDTH (font
);
20721 ascent
= FONT_BASE (font
);
20722 descent
= FONT_DESCENT (font
);
20726 lowest
= - descent
+ boff
;
20727 highest
= ascent
+ boff
;
20731 && font_info
->default_ascent
20732 && CHAR_TABLE_P (Vuse_default_ascent
)
20733 && !NILP (Faref (Vuse_default_ascent
,
20734 make_number (it
->char_to_display
))))
20735 highest
= font_info
->default_ascent
+ boff
;
20737 /* Draw the first glyph at the normal position. It may be
20738 shifted to right later if some other glyphs are drawn at
20740 cmp
->offsets
[0] = 0;
20741 cmp
->offsets
[1] = boff
;
20743 /* Set cmp->offsets for the remaining glyphs. */
20744 for (i
= 1; i
< cmp
->glyph_len
; i
++)
20746 int left
, right
, btm
, top
;
20747 int ch
= COMPOSITION_GLYPH (cmp
, i
);
20748 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
20750 face
= FACE_FROM_ID (it
->f
, face_id
);
20751 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
20752 &char2b
, it
->multibyte_p
, 0);
20756 font
= FRAME_FONT (it
->f
);
20757 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20763 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20764 boff
= font_info
->baseline_offset
;
20765 if (font_info
->vertical_centering
)
20766 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20770 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20771 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
20773 width
= pcm
->width
;
20774 ascent
= pcm
->ascent
;
20775 descent
= pcm
->descent
;
20779 width
= FONT_WIDTH (font
);
20784 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
20786 /* Relative composition with or without
20787 alternate chars. */
20788 left
= (leftmost
+ rightmost
- width
) / 2;
20789 btm
= - descent
+ boff
;
20790 if (font_info
&& font_info
->relative_compose
20791 && (! CHAR_TABLE_P (Vignore_relative_composition
)
20792 || NILP (Faref (Vignore_relative_composition
,
20793 make_number (ch
)))))
20796 if (- descent
>= font_info
->relative_compose
)
20797 /* One extra pixel between two glyphs. */
20799 else if (ascent
<= 0)
20800 /* One extra pixel between two glyphs. */
20801 btm
= lowest
- 1 - ascent
- descent
;
20806 /* A composition rule is specified by an integer
20807 value that encodes global and new reference
20808 points (GREF and NREF). GREF and NREF are
20809 specified by numbers as below:
20811 0---1---2 -- ascent
20815 9--10--11 -- center
20817 ---3---4---5--- baseline
20819 6---7---8 -- descent
20821 int rule
= COMPOSITION_RULE (cmp
, i
);
20822 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
20824 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
20825 grefx
= gref
% 3, nrefx
= nref
% 3;
20826 grefy
= gref
/ 3, nrefy
= nref
/ 3;
20829 + grefx
* (rightmost
- leftmost
) / 2
20830 - nrefx
* width
/ 2);
20831 btm
= ((grefy
== 0 ? highest
20833 : grefy
== 2 ? lowest
20834 : (highest
+ lowest
) / 2)
20835 - (nrefy
== 0 ? ascent
+ descent
20836 : nrefy
== 1 ? descent
- boff
20838 : (ascent
+ descent
) / 2));
20841 cmp
->offsets
[i
* 2] = left
;
20842 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
20844 /* Update the bounding box of the overall glyphs. */
20845 right
= left
+ width
;
20846 top
= btm
+ descent
+ ascent
;
20847 if (left
< leftmost
)
20849 if (right
> rightmost
)
20857 /* If there are glyphs whose x-offsets are negative,
20858 shift all glyphs to the right and make all x-offsets
20862 for (i
= 0; i
< cmp
->glyph_len
; i
++)
20863 cmp
->offsets
[i
* 2] -= leftmost
;
20864 rightmost
-= leftmost
;
20867 cmp
->pixel_width
= rightmost
;
20868 cmp
->ascent
= highest
;
20869 cmp
->descent
= - lowest
;
20870 if (cmp
->ascent
< font_ascent
)
20871 cmp
->ascent
= font_ascent
;
20872 if (cmp
->descent
< font_descent
)
20873 cmp
->descent
= font_descent
;
20876 it
->pixel_width
= cmp
->pixel_width
;
20877 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
20878 it
->descent
= it
->phys_descent
= cmp
->descent
;
20880 if (face
->box
!= FACE_NO_BOX
)
20882 int thick
= face
->box_line_width
;
20886 it
->ascent
+= thick
;
20887 it
->descent
+= thick
;
20892 if (it
->start_of_box_run_p
)
20893 it
->pixel_width
+= thick
;
20894 if (it
->end_of_box_run_p
)
20895 it
->pixel_width
+= thick
;
20898 /* If face has an overline, add the height of the overline
20899 (1 pixel) and a 1 pixel margin to the character height. */
20900 if (face
->overline_p
)
20901 it
->ascent
+= overline_margin
;
20903 take_vertical_position_into_account (it
);
20906 append_composite_glyph (it
);
20908 else if (it
->what
== IT_IMAGE
)
20909 produce_image_glyph (it
);
20910 else if (it
->what
== IT_STRETCH
)
20911 produce_stretch_glyph (it
);
20913 /* Accumulate dimensions. Note: can't assume that it->descent > 0
20914 because this isn't true for images with `:ascent 100'. */
20915 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
20916 if (it
->area
== TEXT_AREA
)
20917 it
->current_x
+= it
->pixel_width
;
20919 if (extra_line_spacing
> 0)
20921 it
->descent
+= extra_line_spacing
;
20922 if (extra_line_spacing
> it
->max_extra_line_spacing
)
20923 it
->max_extra_line_spacing
= extra_line_spacing
;
20926 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
20927 it
->max_descent
= max (it
->max_descent
, it
->descent
);
20928 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
20929 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
20933 Output LEN glyphs starting at START at the nominal cursor position.
20934 Advance the nominal cursor over the text. The global variable
20935 updated_window contains the window being updated, updated_row is
20936 the glyph row being updated, and updated_area is the area of that
20937 row being updated. */
20940 x_write_glyphs (start
, len
)
20941 struct glyph
*start
;
20946 xassert (updated_window
&& updated_row
);
20949 /* Write glyphs. */
20951 hpos
= start
- updated_row
->glyphs
[updated_area
];
20952 x
= draw_glyphs (updated_window
, output_cursor
.x
,
20953 updated_row
, updated_area
,
20955 DRAW_NORMAL_TEXT
, 0);
20957 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
20958 if (updated_area
== TEXT_AREA
20959 && updated_window
->phys_cursor_on_p
20960 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
20961 && updated_window
->phys_cursor
.hpos
>= hpos
20962 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
20963 updated_window
->phys_cursor_on_p
= 0;
20967 /* Advance the output cursor. */
20968 output_cursor
.hpos
+= len
;
20969 output_cursor
.x
= x
;
20974 Insert LEN glyphs from START at the nominal cursor position. */
20977 x_insert_glyphs (start
, len
)
20978 struct glyph
*start
;
20983 int line_height
, shift_by_width
, shifted_region_width
;
20984 struct glyph_row
*row
;
20985 struct glyph
*glyph
;
20986 int frame_x
, frame_y
, hpos
;
20988 xassert (updated_window
&& updated_row
);
20990 w
= updated_window
;
20991 f
= XFRAME (WINDOW_FRAME (w
));
20993 /* Get the height of the line we are in. */
20995 line_height
= row
->height
;
20997 /* Get the width of the glyphs to insert. */
20998 shift_by_width
= 0;
20999 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
21000 shift_by_width
+= glyph
->pixel_width
;
21002 /* Get the width of the region to shift right. */
21003 shifted_region_width
= (window_box_width (w
, updated_area
)
21008 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
21009 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
21011 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
21012 line_height
, shift_by_width
);
21014 /* Write the glyphs. */
21015 hpos
= start
- row
->glyphs
[updated_area
];
21016 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
21018 DRAW_NORMAL_TEXT
, 0);
21020 /* Advance the output cursor. */
21021 output_cursor
.hpos
+= len
;
21022 output_cursor
.x
+= shift_by_width
;
21028 Erase the current text line from the nominal cursor position
21029 (inclusive) to pixel column TO_X (exclusive). The idea is that
21030 everything from TO_X onward is already erased.
21032 TO_X is a pixel position relative to updated_area of
21033 updated_window. TO_X == -1 means clear to the end of this area. */
21036 x_clear_end_of_line (to_x
)
21040 struct window
*w
= updated_window
;
21041 int max_x
, min_y
, max_y
;
21042 int from_x
, from_y
, to_y
;
21044 xassert (updated_window
&& updated_row
);
21045 f
= XFRAME (w
->frame
);
21047 if (updated_row
->full_width_p
)
21048 max_x
= WINDOW_TOTAL_WIDTH (w
);
21050 max_x
= window_box_width (w
, updated_area
);
21051 max_y
= window_text_bottom_y (w
);
21053 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
21054 of window. For TO_X > 0, truncate to end of drawing area. */
21060 to_x
= min (to_x
, max_x
);
21062 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
21064 /* Notice if the cursor will be cleared by this operation. */
21065 if (!updated_row
->full_width_p
)
21066 notice_overwritten_cursor (w
, updated_area
,
21067 output_cursor
.x
, -1,
21069 MATRIX_ROW_BOTTOM_Y (updated_row
));
21071 from_x
= output_cursor
.x
;
21073 /* Translate to frame coordinates. */
21074 if (updated_row
->full_width_p
)
21076 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
21077 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
21081 int area_left
= window_box_left (w
, updated_area
);
21082 from_x
+= area_left
;
21086 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
21087 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
21088 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
21090 /* Prevent inadvertently clearing to end of the X window. */
21091 if (to_x
> from_x
&& to_y
> from_y
)
21094 rif
->clear_frame_area (f
, from_x
, from_y
,
21095 to_x
- from_x
, to_y
- from_y
);
21100 #endif /* HAVE_WINDOW_SYSTEM */
21104 /***********************************************************************
21106 ***********************************************************************/
21108 /* Value is the internal representation of the specified cursor type
21109 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
21110 of the bar cursor. */
21112 static enum text_cursor_kinds
21113 get_specified_cursor_type (arg
, width
)
21117 enum text_cursor_kinds type
;
21122 if (EQ (arg
, Qbox
))
21123 return FILLED_BOX_CURSOR
;
21125 if (EQ (arg
, Qhollow
))
21126 return HOLLOW_BOX_CURSOR
;
21128 if (EQ (arg
, Qbar
))
21135 && EQ (XCAR (arg
), Qbar
)
21136 && INTEGERP (XCDR (arg
))
21137 && XINT (XCDR (arg
)) >= 0)
21139 *width
= XINT (XCDR (arg
));
21143 if (EQ (arg
, Qhbar
))
21146 return HBAR_CURSOR
;
21150 && EQ (XCAR (arg
), Qhbar
)
21151 && INTEGERP (XCDR (arg
))
21152 && XINT (XCDR (arg
)) >= 0)
21154 *width
= XINT (XCDR (arg
));
21155 return HBAR_CURSOR
;
21158 /* Treat anything unknown as "hollow box cursor".
21159 It was bad to signal an error; people have trouble fixing
21160 .Xdefaults with Emacs, when it has something bad in it. */
21161 type
= HOLLOW_BOX_CURSOR
;
21166 /* Set the default cursor types for specified frame. */
21168 set_frame_cursor_types (f
, arg
)
21175 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
21176 FRAME_CURSOR_WIDTH (f
) = width
;
21178 /* By default, set up the blink-off state depending on the on-state. */
21180 tem
= Fassoc (arg
, Vblink_cursor_alist
);
21183 FRAME_BLINK_OFF_CURSOR (f
)
21184 = get_specified_cursor_type (XCDR (tem
), &width
);
21185 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
21188 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
21192 /* Return the cursor we want to be displayed in window W. Return
21193 width of bar/hbar cursor through WIDTH arg. Return with
21194 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
21195 (i.e. if the `system caret' should track this cursor).
21197 In a mini-buffer window, we want the cursor only to appear if we
21198 are reading input from this window. For the selected window, we
21199 want the cursor type given by the frame parameter or buffer local
21200 setting of cursor-type. If explicitly marked off, draw no cursor.
21201 In all other cases, we want a hollow box cursor. */
21203 static enum text_cursor_kinds
21204 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
21206 struct glyph
*glyph
;
21208 int *active_cursor
;
21210 struct frame
*f
= XFRAME (w
->frame
);
21211 struct buffer
*b
= XBUFFER (w
->buffer
);
21212 int cursor_type
= DEFAULT_CURSOR
;
21213 Lisp_Object alt_cursor
;
21214 int non_selected
= 0;
21216 *active_cursor
= 1;
21219 if (cursor_in_echo_area
21220 && FRAME_HAS_MINIBUF_P (f
)
21221 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
21223 if (w
== XWINDOW (echo_area_window
))
21225 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
21227 *width
= FRAME_CURSOR_WIDTH (f
);
21228 return FRAME_DESIRED_CURSOR (f
);
21231 return get_specified_cursor_type (b
->cursor_type
, width
);
21234 *active_cursor
= 0;
21238 /* Nonselected window or nonselected frame. */
21239 else if (w
!= XWINDOW (f
->selected_window
)
21240 #ifdef HAVE_WINDOW_SYSTEM
21241 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
21245 *active_cursor
= 0;
21247 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
21253 /* Never display a cursor in a window in which cursor-type is nil. */
21254 if (NILP (b
->cursor_type
))
21257 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
21260 alt_cursor
= b
->cursor_in_non_selected_windows
;
21261 return get_specified_cursor_type (alt_cursor
, width
);
21264 /* Get the normal cursor type for this window. */
21265 if (EQ (b
->cursor_type
, Qt
))
21267 cursor_type
= FRAME_DESIRED_CURSOR (f
);
21268 *width
= FRAME_CURSOR_WIDTH (f
);
21271 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
21273 /* Use normal cursor if not blinked off. */
21274 if (!w
->cursor_off_p
)
21276 #ifdef HAVE_WINDOW_SYSTEM
21277 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21279 if (cursor_type
== FILLED_BOX_CURSOR
)
21281 /* Using a block cursor on large images can be very annoying.
21282 So use a hollow cursor for "large" images.
21283 If image is not transparent (no mask), also use hollow cursor. */
21284 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21285 if (img
!= NULL
&& IMAGEP (img
->spec
))
21287 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
21288 where N = size of default frame font size.
21289 This should cover most of the "tiny" icons people may use. */
21291 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
21292 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
21293 cursor_type
= HOLLOW_BOX_CURSOR
;
21296 else if (cursor_type
!= NO_CURSOR
)
21298 /* Display current only supports BOX and HOLLOW cursors for images.
21299 So for now, unconditionally use a HOLLOW cursor when cursor is
21300 not a solid box cursor. */
21301 cursor_type
= HOLLOW_BOX_CURSOR
;
21305 return cursor_type
;
21308 /* Cursor is blinked off, so determine how to "toggle" it. */
21310 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
21311 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
21312 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
21314 /* Then see if frame has specified a specific blink off cursor type. */
21315 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
21317 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
21318 return FRAME_BLINK_OFF_CURSOR (f
);
21322 /* Some people liked having a permanently visible blinking cursor,
21323 while others had very strong opinions against it. So it was
21324 decided to remove it. KFS 2003-09-03 */
21326 /* Finally perform built-in cursor blinking:
21327 filled box <-> hollow box
21328 wide [h]bar <-> narrow [h]bar
21329 narrow [h]bar <-> no cursor
21330 other type <-> no cursor */
21332 if (cursor_type
== FILLED_BOX_CURSOR
)
21333 return HOLLOW_BOX_CURSOR
;
21335 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
21338 return cursor_type
;
21346 #ifdef HAVE_WINDOW_SYSTEM
21348 /* Notice when the text cursor of window W has been completely
21349 overwritten by a drawing operation that outputs glyphs in AREA
21350 starting at X0 and ending at X1 in the line starting at Y0 and
21351 ending at Y1. X coordinates are area-relative. X1 < 0 means all
21352 the rest of the line after X0 has been written. Y coordinates
21353 are window-relative. */
21356 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
21358 enum glyph_row_area area
;
21359 int x0
, y0
, x1
, y1
;
21361 int cx0
, cx1
, cy0
, cy1
;
21362 struct glyph_row
*row
;
21364 if (!w
->phys_cursor_on_p
)
21366 if (area
!= TEXT_AREA
)
21369 if (w
->phys_cursor
.vpos
< 0
21370 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
21371 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
21372 !(row
->enabled_p
&& row
->displays_text_p
)))
21375 if (row
->cursor_in_fringe_p
)
21377 row
->cursor_in_fringe_p
= 0;
21378 draw_fringe_bitmap (w
, row
, 0);
21379 w
->phys_cursor_on_p
= 0;
21383 cx0
= w
->phys_cursor
.x
;
21384 cx1
= cx0
+ w
->phys_cursor_width
;
21385 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
21388 /* The cursor image will be completely removed from the
21389 screen if the output area intersects the cursor area in
21390 y-direction. When we draw in [y0 y1[, and some part of
21391 the cursor is at y < y0, that part must have been drawn
21392 before. When scrolling, the cursor is erased before
21393 actually scrolling, so we don't come here. When not
21394 scrolling, the rows above the old cursor row must have
21395 changed, and in this case these rows must have written
21396 over the cursor image.
21398 Likewise if part of the cursor is below y1, with the
21399 exception of the cursor being in the first blank row at
21400 the buffer and window end because update_text_area
21401 doesn't draw that row. (Except when it does, but
21402 that's handled in update_text_area.) */
21404 cy0
= w
->phys_cursor
.y
;
21405 cy1
= cy0
+ w
->phys_cursor_height
;
21406 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
21409 w
->phys_cursor_on_p
= 0;
21412 #endif /* HAVE_WINDOW_SYSTEM */
21415 /************************************************************************
21417 ************************************************************************/
21419 #ifdef HAVE_WINDOW_SYSTEM
21422 Fix the display of area AREA of overlapping row ROW in window W
21423 with respect to the overlapping part OVERLAPS. */
21426 x_fix_overlapping_area (w
, row
, area
, overlaps
)
21428 struct glyph_row
*row
;
21429 enum glyph_row_area area
;
21437 for (i
= 0; i
< row
->used
[area
];)
21439 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
21441 int start
= i
, start_x
= x
;
21445 x
+= row
->glyphs
[area
][i
].pixel_width
;
21448 while (i
< row
->used
[area
]
21449 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
21451 draw_glyphs (w
, start_x
, row
, area
,
21453 DRAW_NORMAL_TEXT
, overlaps
);
21457 x
+= row
->glyphs
[area
][i
].pixel_width
;
21467 Draw the cursor glyph of window W in glyph row ROW. See the
21468 comment of draw_glyphs for the meaning of HL. */
21471 draw_phys_cursor_glyph (w
, row
, hl
)
21473 struct glyph_row
*row
;
21474 enum draw_glyphs_face hl
;
21476 /* If cursor hpos is out of bounds, don't draw garbage. This can
21477 happen in mini-buffer windows when switching between echo area
21478 glyphs and mini-buffer. */
21479 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
21481 int on_p
= w
->phys_cursor_on_p
;
21483 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
21484 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
21486 w
->phys_cursor_on_p
= on_p
;
21488 if (hl
== DRAW_CURSOR
)
21489 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21490 /* When we erase the cursor, and ROW is overlapped by other
21491 rows, make sure that these overlapping parts of other rows
21493 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
21495 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21497 if (row
> w
->current_matrix
->rows
21498 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
21499 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
21500 OVERLAPS_ERASED_CURSOR
);
21502 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
21503 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
21504 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
21505 OVERLAPS_ERASED_CURSOR
);
21512 Erase the image of a cursor of window W from the screen. */
21515 erase_phys_cursor (w
)
21518 struct frame
*f
= XFRAME (w
->frame
);
21519 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21520 int hpos
= w
->phys_cursor
.hpos
;
21521 int vpos
= w
->phys_cursor
.vpos
;
21522 int mouse_face_here_p
= 0;
21523 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
21524 struct glyph_row
*cursor_row
;
21525 struct glyph
*cursor_glyph
;
21526 enum draw_glyphs_face hl
;
21528 /* No cursor displayed or row invalidated => nothing to do on the
21530 if (w
->phys_cursor_type
== NO_CURSOR
)
21531 goto mark_cursor_off
;
21533 /* VPOS >= active_glyphs->nrows means that window has been resized.
21534 Don't bother to erase the cursor. */
21535 if (vpos
>= active_glyphs
->nrows
)
21536 goto mark_cursor_off
;
21538 /* If row containing cursor is marked invalid, there is nothing we
21540 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
21541 if (!cursor_row
->enabled_p
)
21542 goto mark_cursor_off
;
21544 /* If line spacing is > 0, old cursor may only be partially visible in
21545 window after split-window. So adjust visible height. */
21546 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
21547 window_text_bottom_y (w
) - cursor_row
->y
);
21549 /* If row is completely invisible, don't attempt to delete a cursor which
21550 isn't there. This can happen if cursor is at top of a window, and
21551 we switch to a buffer with a header line in that window. */
21552 if (cursor_row
->visible_height
<= 0)
21553 goto mark_cursor_off
;
21555 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
21556 if (cursor_row
->cursor_in_fringe_p
)
21558 cursor_row
->cursor_in_fringe_p
= 0;
21559 draw_fringe_bitmap (w
, cursor_row
, 0);
21560 goto mark_cursor_off
;
21563 /* This can happen when the new row is shorter than the old one.
21564 In this case, either draw_glyphs or clear_end_of_line
21565 should have cleared the cursor. Note that we wouldn't be
21566 able to erase the cursor in this case because we don't have a
21567 cursor glyph at hand. */
21568 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
21569 goto mark_cursor_off
;
21571 /* If the cursor is in the mouse face area, redisplay that when
21572 we clear the cursor. */
21573 if (! NILP (dpyinfo
->mouse_face_window
)
21574 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
21575 && (vpos
> dpyinfo
->mouse_face_beg_row
21576 || (vpos
== dpyinfo
->mouse_face_beg_row
21577 && hpos
>= dpyinfo
->mouse_face_beg_col
))
21578 && (vpos
< dpyinfo
->mouse_face_end_row
21579 || (vpos
== dpyinfo
->mouse_face_end_row
21580 && hpos
< dpyinfo
->mouse_face_end_col
))
21581 /* Don't redraw the cursor's spot in mouse face if it is at the
21582 end of a line (on a newline). The cursor appears there, but
21583 mouse highlighting does not. */
21584 && cursor_row
->used
[TEXT_AREA
] > hpos
)
21585 mouse_face_here_p
= 1;
21587 /* Maybe clear the display under the cursor. */
21588 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
21591 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
21594 cursor_glyph
= get_phys_cursor_glyph (w
);
21595 if (cursor_glyph
== NULL
)
21596 goto mark_cursor_off
;
21598 width
= cursor_glyph
->pixel_width
;
21599 left_x
= window_box_left_offset (w
, TEXT_AREA
);
21600 x
= w
->phys_cursor
.x
;
21602 width
-= left_x
- x
;
21603 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
21604 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
21605 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
21608 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
21611 /* Erase the cursor by redrawing the character underneath it. */
21612 if (mouse_face_here_p
)
21613 hl
= DRAW_MOUSE_FACE
;
21615 hl
= DRAW_NORMAL_TEXT
;
21616 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
21619 w
->phys_cursor_on_p
= 0;
21620 w
->phys_cursor_type
= NO_CURSOR
;
21625 Display or clear cursor of window W. If ON is zero, clear the
21626 cursor. If it is non-zero, display the cursor. If ON is nonzero,
21627 where to put the cursor is specified by HPOS, VPOS, X and Y. */
21630 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
21632 int on
, hpos
, vpos
, x
, y
;
21634 struct frame
*f
= XFRAME (w
->frame
);
21635 int new_cursor_type
;
21636 int new_cursor_width
;
21638 struct glyph_row
*glyph_row
;
21639 struct glyph
*glyph
;
21641 /* This is pointless on invisible frames, and dangerous on garbaged
21642 windows and frames; in the latter case, the frame or window may
21643 be in the midst of changing its size, and x and y may be off the
21645 if (! FRAME_VISIBLE_P (f
)
21646 || FRAME_GARBAGED_P (f
)
21647 || vpos
>= w
->current_matrix
->nrows
21648 || hpos
>= w
->current_matrix
->matrix_w
)
21651 /* If cursor is off and we want it off, return quickly. */
21652 if (!on
&& !w
->phys_cursor_on_p
)
21655 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
21656 /* If cursor row is not enabled, we don't really know where to
21657 display the cursor. */
21658 if (!glyph_row
->enabled_p
)
21660 w
->phys_cursor_on_p
= 0;
21665 if (!glyph_row
->exact_window_width_line_p
21666 || hpos
< glyph_row
->used
[TEXT_AREA
])
21667 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
21669 xassert (interrupt_input_blocked
);
21671 /* Set new_cursor_type to the cursor we want to be displayed. */
21672 new_cursor_type
= get_window_cursor_type (w
, glyph
,
21673 &new_cursor_width
, &active_cursor
);
21675 /* If cursor is currently being shown and we don't want it to be or
21676 it is in the wrong place, or the cursor type is not what we want,
21678 if (w
->phys_cursor_on_p
21680 || w
->phys_cursor
.x
!= x
21681 || w
->phys_cursor
.y
!= y
21682 || new_cursor_type
!= w
->phys_cursor_type
21683 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
21684 && new_cursor_width
!= w
->phys_cursor_width
)))
21685 erase_phys_cursor (w
);
21687 /* Don't check phys_cursor_on_p here because that flag is only set
21688 to zero in some cases where we know that the cursor has been
21689 completely erased, to avoid the extra work of erasing the cursor
21690 twice. In other words, phys_cursor_on_p can be 1 and the cursor
21691 still not be visible, or it has only been partly erased. */
21694 w
->phys_cursor_ascent
= glyph_row
->ascent
;
21695 w
->phys_cursor_height
= glyph_row
->height
;
21697 /* Set phys_cursor_.* before x_draw_.* is called because some
21698 of them may need the information. */
21699 w
->phys_cursor
.x
= x
;
21700 w
->phys_cursor
.y
= glyph_row
->y
;
21701 w
->phys_cursor
.hpos
= hpos
;
21702 w
->phys_cursor
.vpos
= vpos
;
21705 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
21706 new_cursor_type
, new_cursor_width
,
21707 on
, active_cursor
);
21711 /* Switch the display of W's cursor on or off, according to the value
21715 update_window_cursor (w
, on
)
21719 /* Don't update cursor in windows whose frame is in the process
21720 of being deleted. */
21721 if (w
->current_matrix
)
21724 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21725 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21731 /* Call update_window_cursor with parameter ON_P on all leaf windows
21732 in the window tree rooted at W. */
21735 update_cursor_in_window_tree (w
, on_p
)
21741 if (!NILP (w
->hchild
))
21742 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
21743 else if (!NILP (w
->vchild
))
21744 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
21746 update_window_cursor (w
, on_p
);
21748 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
21754 Display the cursor on window W, or clear it, according to ON_P.
21755 Don't change the cursor's position. */
21758 x_update_cursor (f
, on_p
)
21762 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
21767 Clear the cursor of window W to background color, and mark the
21768 cursor as not shown. This is used when the text where the cursor
21769 is is about to be rewritten. */
21775 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
21776 update_window_cursor (w
, 0);
21781 Display the active region described by mouse_face_* according to DRAW. */
21784 show_mouse_face (dpyinfo
, draw
)
21785 Display_Info
*dpyinfo
;
21786 enum draw_glyphs_face draw
;
21788 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
21789 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21791 if (/* If window is in the process of being destroyed, don't bother
21793 w
->current_matrix
!= NULL
21794 /* Don't update mouse highlight if hidden */
21795 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
21796 /* Recognize when we are called to operate on rows that don't exist
21797 anymore. This can happen when a window is split. */
21798 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
21800 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
21801 struct glyph_row
*row
, *first
, *last
;
21803 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
21804 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
21806 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
21808 int start_hpos
, end_hpos
, start_x
;
21810 /* For all but the first row, the highlight starts at column 0. */
21813 start_hpos
= dpyinfo
->mouse_face_beg_col
;
21814 start_x
= dpyinfo
->mouse_face_beg_x
;
21823 end_hpos
= dpyinfo
->mouse_face_end_col
;
21826 end_hpos
= row
->used
[TEXT_AREA
];
21827 if (draw
== DRAW_NORMAL_TEXT
)
21828 row
->fill_line_p
= 1; /* Clear to end of line */
21831 if (end_hpos
> start_hpos
)
21833 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
21834 start_hpos
, end_hpos
,
21838 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
21842 /* When we've written over the cursor, arrange for it to
21843 be displayed again. */
21844 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
21847 display_and_set_cursor (w
, 1,
21848 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21849 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21854 /* Change the mouse cursor. */
21855 if (draw
== DRAW_NORMAL_TEXT
)
21856 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
21857 else if (draw
== DRAW_MOUSE_FACE
)
21858 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
21860 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
21864 Clear out the mouse-highlighted active region.
21865 Redraw it un-highlighted first. Value is non-zero if mouse
21866 face was actually drawn unhighlighted. */
21869 clear_mouse_face (dpyinfo
)
21870 Display_Info
*dpyinfo
;
21874 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
21876 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
21880 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21881 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21882 dpyinfo
->mouse_face_window
= Qnil
;
21883 dpyinfo
->mouse_face_overlay
= Qnil
;
21889 Non-zero if physical cursor of window W is within mouse face. */
21892 cursor_in_mouse_face_p (w
)
21895 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21896 int in_mouse_face
= 0;
21898 if (WINDOWP (dpyinfo
->mouse_face_window
)
21899 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
21901 int hpos
= w
->phys_cursor
.hpos
;
21902 int vpos
= w
->phys_cursor
.vpos
;
21904 if (vpos
>= dpyinfo
->mouse_face_beg_row
21905 && vpos
<= dpyinfo
->mouse_face_end_row
21906 && (vpos
> dpyinfo
->mouse_face_beg_row
21907 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21908 && (vpos
< dpyinfo
->mouse_face_end_row
21909 || hpos
< dpyinfo
->mouse_face_end_col
21910 || dpyinfo
->mouse_face_past_end
))
21914 return in_mouse_face
;
21920 /* Find the glyph matrix position of buffer position CHARPOS in window
21921 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
21922 current glyphs must be up to date. If CHARPOS is above window
21923 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
21924 of last line in W. In the row containing CHARPOS, stop before glyphs
21925 having STOP as object. */
21927 #if 1 /* This is a version of fast_find_position that's more correct
21928 in the presence of hscrolling, for example. I didn't install
21929 it right away because the problem fixed is minor, it failed
21930 in 20.x as well, and I think it's too risky to install
21931 so near the release of 21.1. 2001-09-25 gerd. */
21934 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
21937 int *hpos
, *vpos
, *x
, *y
;
21940 struct glyph_row
*row
, *first
;
21941 struct glyph
*glyph
, *end
;
21944 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21945 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
21950 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
21954 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
21957 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
21961 /* If whole rows or last part of a row came from a display overlay,
21962 row_containing_pos will skip over such rows because their end pos
21963 equals the start pos of the overlay or interval.
21965 Move back if we have a STOP object and previous row's
21966 end glyph came from STOP. */
21969 struct glyph_row
*prev
;
21970 while ((prev
= row
- 1, prev
>= first
)
21971 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
21972 && prev
->used
[TEXT_AREA
] > 0)
21974 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
21975 glyph
= beg
+ prev
->used
[TEXT_AREA
];
21976 while (--glyph
>= beg
21977 && INTEGERP (glyph
->object
));
21979 || !EQ (stop
, glyph
->object
))
21987 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21989 glyph
= row
->glyphs
[TEXT_AREA
];
21990 end
= glyph
+ row
->used
[TEXT_AREA
];
21992 /* Skip over glyphs not having an object at the start of the row.
21993 These are special glyphs like truncation marks on terminal
21995 if (row
->displays_text_p
)
21997 && INTEGERP (glyph
->object
)
21998 && !EQ (stop
, glyph
->object
)
21999 && glyph
->charpos
< 0)
22001 *x
+= glyph
->pixel_width
;
22006 && !INTEGERP (glyph
->object
)
22007 && !EQ (stop
, glyph
->object
)
22008 && (!BUFFERP (glyph
->object
)
22009 || glyph
->charpos
< charpos
))
22011 *x
+= glyph
->pixel_width
;
22015 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
22022 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
22025 int *hpos
, *vpos
, *x
, *y
;
22030 int maybe_next_line_p
= 0;
22031 int line_start_position
;
22032 int yb
= window_text_bottom_y (w
);
22033 struct glyph_row
*row
, *best_row
;
22034 int row_vpos
, best_row_vpos
;
22037 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22038 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22040 while (row
->y
< yb
)
22042 if (row
->used
[TEXT_AREA
])
22043 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
22045 line_start_position
= 0;
22047 if (line_start_position
> pos
)
22049 /* If the position sought is the end of the buffer,
22050 don't include the blank lines at the bottom of the window. */
22051 else if (line_start_position
== pos
22052 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
22054 maybe_next_line_p
= 1;
22057 else if (line_start_position
> 0)
22060 best_row_vpos
= row_vpos
;
22063 if (row
->y
+ row
->height
>= yb
)
22070 /* Find the right column within BEST_ROW. */
22072 current_x
= best_row
->x
;
22073 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
22075 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
22076 int charpos
= glyph
->charpos
;
22078 if (BUFFERP (glyph
->object
))
22080 if (charpos
== pos
)
22083 *vpos
= best_row_vpos
;
22088 else if (charpos
> pos
)
22091 else if (EQ (glyph
->object
, stop
))
22096 current_x
+= glyph
->pixel_width
;
22099 /* If we're looking for the end of the buffer,
22100 and we didn't find it in the line we scanned,
22101 use the start of the following line. */
22102 if (maybe_next_line_p
)
22107 current_x
= best_row
->x
;
22110 *vpos
= best_row_vpos
;
22111 *hpos
= lastcol
+ 1;
22120 /* Find the position of the glyph for position POS in OBJECT in
22121 window W's current matrix, and return in *X, *Y the pixel
22122 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
22124 RIGHT_P non-zero means return the position of the right edge of the
22125 glyph, RIGHT_P zero means return the left edge position.
22127 If no glyph for POS exists in the matrix, return the position of
22128 the glyph with the next smaller position that is in the matrix, if
22129 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
22130 exists in the matrix, return the position of the glyph with the
22131 next larger position in OBJECT.
22133 Value is non-zero if a glyph was found. */
22136 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
22139 Lisp_Object object
;
22140 int *hpos
, *vpos
, *x
, *y
;
22143 int yb
= window_text_bottom_y (w
);
22144 struct glyph_row
*r
;
22145 struct glyph
*best_glyph
= NULL
;
22146 struct glyph_row
*best_row
= NULL
;
22149 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22150 r
->enabled_p
&& r
->y
< yb
;
22153 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
22154 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
22157 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
22158 if (EQ (g
->object
, object
))
22160 if (g
->charpos
== pos
)
22167 else if (best_glyph
== NULL
22168 || ((abs (g
->charpos
- pos
)
22169 < abs (best_glyph
->charpos
- pos
))
22172 : g
->charpos
> pos
)))
22186 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
22190 *x
+= best_glyph
->pixel_width
;
22195 *vpos
= best_row
- w
->current_matrix
->rows
;
22198 return best_glyph
!= NULL
;
22202 /* See if position X, Y is within a hot-spot of an image. */
22205 on_hot_spot_p (hot_spot
, x
, y
)
22206 Lisp_Object hot_spot
;
22209 if (!CONSP (hot_spot
))
22212 if (EQ (XCAR (hot_spot
), Qrect
))
22214 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
22215 Lisp_Object rect
= XCDR (hot_spot
);
22219 if (!CONSP (XCAR (rect
)))
22221 if (!CONSP (XCDR (rect
)))
22223 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
22225 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
22227 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
22229 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
22233 else if (EQ (XCAR (hot_spot
), Qcircle
))
22235 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
22236 Lisp_Object circ
= XCDR (hot_spot
);
22237 Lisp_Object lr
, lx0
, ly0
;
22239 && CONSP (XCAR (circ
))
22240 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
22241 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
22242 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
22244 double r
= XFLOATINT (lr
);
22245 double dx
= XINT (lx0
) - x
;
22246 double dy
= XINT (ly0
) - y
;
22247 return (dx
* dx
+ dy
* dy
<= r
* r
);
22250 else if (EQ (XCAR (hot_spot
), Qpoly
))
22252 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
22253 if (VECTORP (XCDR (hot_spot
)))
22255 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
22256 Lisp_Object
*poly
= v
->contents
;
22260 Lisp_Object lx
, ly
;
22263 /* Need an even number of coordinates, and at least 3 edges. */
22264 if (n
< 6 || n
& 1)
22267 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
22268 If count is odd, we are inside polygon. Pixels on edges
22269 may or may not be included depending on actual geometry of the
22271 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
22272 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
22274 x0
= XINT (lx
), y0
= XINT (ly
);
22275 for (i
= 0; i
< n
; i
+= 2)
22277 int x1
= x0
, y1
= y0
;
22278 if ((lx
= poly
[i
], !INTEGERP (lx
))
22279 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
22281 x0
= XINT (lx
), y0
= XINT (ly
);
22283 /* Does this segment cross the X line? */
22291 if (y
> y0
&& y
> y1
)
22293 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
22299 /* If we don't understand the format, pretend we're not in the hot-spot. */
22304 find_hot_spot (map
, x
, y
)
22308 while (CONSP (map
))
22310 if (CONSP (XCAR (map
))
22311 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
22319 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
22321 doc
: /* Lookup in image map MAP coordinates X and Y.
22322 An image map is an alist where each element has the format (AREA ID PLIST).
22323 An AREA is specified as either a rectangle, a circle, or a polygon:
22324 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
22325 pixel coordinates of the upper left and bottom right corners.
22326 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
22327 and the radius of the circle; r may be a float or integer.
22328 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
22329 vector describes one corner in the polygon.
22330 Returns the alist element for the first matching AREA in MAP. */)
22341 return find_hot_spot (map
, XINT (x
), XINT (y
));
22345 /* Display frame CURSOR, optionally using shape defined by POINTER. */
22347 define_frame_cursor1 (f
, cursor
, pointer
)
22350 Lisp_Object pointer
;
22352 /* Do not change cursor shape while dragging mouse. */
22353 if (!NILP (do_mouse_tracking
))
22356 if (!NILP (pointer
))
22358 if (EQ (pointer
, Qarrow
))
22359 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22360 else if (EQ (pointer
, Qhand
))
22361 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
22362 else if (EQ (pointer
, Qtext
))
22363 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22364 else if (EQ (pointer
, intern ("hdrag")))
22365 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22366 #ifdef HAVE_X_WINDOWS
22367 else if (EQ (pointer
, intern ("vdrag")))
22368 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
22370 else if (EQ (pointer
, intern ("hourglass")))
22371 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
22372 else if (EQ (pointer
, Qmodeline
))
22373 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
22375 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22378 if (cursor
!= No_Cursor
)
22379 rif
->define_frame_cursor (f
, cursor
);
22382 /* Take proper action when mouse has moved to the mode or header line
22383 or marginal area AREA of window W, x-position X and y-position Y.
22384 X is relative to the start of the text display area of W, so the
22385 width of bitmap areas and scroll bars must be subtracted to get a
22386 position relative to the start of the mode line. */
22389 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
22390 Lisp_Object window
;
22392 enum window_part area
;
22394 struct window
*w
= XWINDOW (window
);
22395 struct frame
*f
= XFRAME (w
->frame
);
22396 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22397 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22398 Lisp_Object pointer
= Qnil
;
22399 int charpos
, dx
, dy
, width
, height
;
22400 Lisp_Object string
, object
= Qnil
;
22401 Lisp_Object pos
, help
;
22403 Lisp_Object mouse_face
;
22404 int original_x_pixel
= x
;
22405 struct glyph
* glyph
= NULL
;
22406 struct glyph_row
*row
;
22408 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
22413 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
22414 &object
, &dx
, &dy
, &width
, &height
);
22416 row
= (area
== ON_MODE_LINE
22417 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
22418 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
22421 if (row
->mode_line_p
&& row
->enabled_p
)
22423 glyph
= row
->glyphs
[TEXT_AREA
];
22424 end
= glyph
+ row
->used
[TEXT_AREA
];
22426 for (x0
= original_x_pixel
;
22427 glyph
< end
&& x0
>= glyph
->pixel_width
;
22429 x0
-= glyph
->pixel_width
;
22437 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
22438 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
22439 &object
, &dx
, &dy
, &width
, &height
);
22444 if (IMAGEP (object
))
22446 Lisp_Object image_map
, hotspot
;
22447 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
22449 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
22451 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22453 Lisp_Object area_id
, plist
;
22455 area_id
= XCAR (hotspot
);
22456 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22457 If so, we could look for mouse-enter, mouse-leave
22458 properties in PLIST (and do something...). */
22459 hotspot
= XCDR (hotspot
);
22460 if (CONSP (hotspot
)
22461 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22463 pointer
= Fplist_get (plist
, Qpointer
);
22464 if (NILP (pointer
))
22466 help
= Fplist_get (plist
, Qhelp_echo
);
22469 help_echo_string
= help
;
22470 /* Is this correct? ++kfs */
22471 XSETWINDOW (help_echo_window
, w
);
22472 help_echo_object
= w
->buffer
;
22473 help_echo_pos
= charpos
;
22477 if (NILP (pointer
))
22478 pointer
= Fplist_get (XCDR (object
), QCpointer
);
22481 if (STRINGP (string
))
22483 pos
= make_number (charpos
);
22484 /* If we're on a string with `help-echo' text property, arrange
22485 for the help to be displayed. This is done by setting the
22486 global variable help_echo_string to the help string. */
22489 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
22492 help_echo_string
= help
;
22493 XSETWINDOW (help_echo_window
, w
);
22494 help_echo_object
= string
;
22495 help_echo_pos
= charpos
;
22499 if (NILP (pointer
))
22500 pointer
= Fget_text_property (pos
, Qpointer
, string
);
22502 /* Change the mouse pointer according to what is under X/Y. */
22503 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
22506 map
= Fget_text_property (pos
, Qlocal_map
, string
);
22507 if (!KEYMAPP (map
))
22508 map
= Fget_text_property (pos
, Qkeymap
, string
);
22509 if (!KEYMAPP (map
))
22510 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
22513 /* Change the mouse face according to what is under X/Y. */
22514 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
22515 if (!NILP (mouse_face
)
22516 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22521 struct glyph
* tmp_glyph
;
22525 int total_pixel_width
;
22530 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
22531 Qmouse_face
, string
, Qnil
);
22533 b
= make_number (0);
22535 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
22537 e
= make_number (SCHARS (string
));
22539 /* Calculate the position(glyph position: GPOS) of GLYPH in
22540 displayed string. GPOS is different from CHARPOS.
22542 CHARPOS is the position of glyph in internal string
22543 object. A mode line string format has structures which
22544 is converted to a flatten by emacs lisp interpreter.
22545 The internal string is an element of the structures.
22546 The displayed string is the flatten string. */
22547 for (tmp_glyph
= glyph
- 1, gpos
= 0;
22548 tmp_glyph
->charpos
>= XINT (b
);
22549 tmp_glyph
--, gpos
++)
22551 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22555 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
22556 displayed string holding GLYPH.
22558 GSEQ_LENGTH is different from SCHARS (STRING).
22559 SCHARS (STRING) returns the length of the internal string. */
22560 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
22561 tmp_glyph
->charpos
< XINT (e
);
22562 tmp_glyph
++, gseq_length
++)
22564 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22568 total_pixel_width
= 0;
22569 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
22570 total_pixel_width
+= tmp_glyph
->pixel_width
;
22572 /* Pre calculation of re-rendering position */
22574 hpos
= (area
== ON_MODE_LINE
22575 ? (w
->current_matrix
)->nrows
- 1
22578 /* If the re-rendering position is included in the last
22579 re-rendering area, we should do nothing. */
22580 if ( EQ (window
, dpyinfo
->mouse_face_window
)
22581 && dpyinfo
->mouse_face_beg_col
<= vpos
22582 && vpos
< dpyinfo
->mouse_face_end_col
22583 && dpyinfo
->mouse_face_beg_row
== hpos
)
22586 if (clear_mouse_face (dpyinfo
))
22587 cursor
= No_Cursor
;
22589 dpyinfo
->mouse_face_beg_col
= vpos
;
22590 dpyinfo
->mouse_face_beg_row
= hpos
;
22592 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
22593 dpyinfo
->mouse_face_beg_y
= 0;
22595 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
22596 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
22598 dpyinfo
->mouse_face_end_x
= 0;
22599 dpyinfo
->mouse_face_end_y
= 0;
22601 dpyinfo
->mouse_face_past_end
= 0;
22602 dpyinfo
->mouse_face_window
= window
;
22604 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
22607 glyph
->face_id
, 1);
22608 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22610 if (NILP (pointer
))
22613 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22614 clear_mouse_face (dpyinfo
);
22616 define_frame_cursor1 (f
, cursor
, pointer
);
22621 Take proper action when the mouse has moved to position X, Y on
22622 frame F as regards highlighting characters that have mouse-face
22623 properties. Also de-highlighting chars where the mouse was before.
22624 X and Y can be negative or out of range. */
22627 note_mouse_highlight (f
, x
, y
)
22631 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22632 enum window_part part
;
22633 Lisp_Object window
;
22635 Cursor cursor
= No_Cursor
;
22636 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
22639 /* When a menu is active, don't highlight because this looks odd. */
22640 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
22641 if (popup_activated ())
22645 if (NILP (Vmouse_highlight
)
22646 || !f
->glyphs_initialized_p
)
22649 dpyinfo
->mouse_face_mouse_x
= x
;
22650 dpyinfo
->mouse_face_mouse_y
= y
;
22651 dpyinfo
->mouse_face_mouse_frame
= f
;
22653 if (dpyinfo
->mouse_face_defer
)
22656 if (gc_in_progress
)
22658 dpyinfo
->mouse_face_deferred_gc
= 1;
22662 /* Which window is that in? */
22663 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
22665 /* If we were displaying active text in another window, clear that.
22666 Also clear if we move out of text area in same window. */
22667 if (! EQ (window
, dpyinfo
->mouse_face_window
)
22668 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
22669 && !NILP (dpyinfo
->mouse_face_window
)))
22670 clear_mouse_face (dpyinfo
);
22672 /* Not on a window -> return. */
22673 if (!WINDOWP (window
))
22676 /* Reset help_echo_string. It will get recomputed below. */
22677 help_echo_string
= Qnil
;
22679 /* Convert to window-relative pixel coordinates. */
22680 w
= XWINDOW (window
);
22681 frame_to_window_pixel_xy (w
, &x
, &y
);
22683 /* Handle tool-bar window differently since it doesn't display a
22685 if (EQ (window
, f
->tool_bar_window
))
22687 note_tool_bar_highlight (f
, x
, y
);
22691 /* Mouse is on the mode, header line or margin? */
22692 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
22693 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
22695 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
22699 if (part
== ON_VERTICAL_BORDER
)
22701 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22702 help_echo_string
= build_string ("drag-mouse-1: resize");
22704 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
22705 || part
== ON_SCROLL_BAR
)
22706 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22708 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22710 /* Are we in a window whose display is up to date?
22711 And verify the buffer's text has not changed. */
22712 b
= XBUFFER (w
->buffer
);
22713 if (part
== ON_TEXT
22714 && EQ (w
->window_end_valid
, w
->buffer
)
22715 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
22716 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
22718 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
22719 struct glyph
*glyph
;
22720 Lisp_Object object
;
22721 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
22722 Lisp_Object
*overlay_vec
= NULL
;
22724 struct buffer
*obuf
;
22725 int obegv
, ozv
, same_region
;
22727 /* Find the glyph under X/Y. */
22728 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
22730 /* Look for :pointer property on image. */
22731 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22733 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22734 if (img
!= NULL
&& IMAGEP (img
->spec
))
22736 Lisp_Object image_map
, hotspot
;
22737 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
22739 && (hotspot
= find_hot_spot (image_map
,
22740 glyph
->slice
.x
+ dx
,
22741 glyph
->slice
.y
+ dy
),
22743 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22745 Lisp_Object area_id
, plist
;
22747 area_id
= XCAR (hotspot
);
22748 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22749 If so, we could look for mouse-enter, mouse-leave
22750 properties in PLIST (and do something...). */
22751 hotspot
= XCDR (hotspot
);
22752 if (CONSP (hotspot
)
22753 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22755 pointer
= Fplist_get (plist
, Qpointer
);
22756 if (NILP (pointer
))
22758 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
22759 if (!NILP (help_echo_string
))
22761 help_echo_window
= window
;
22762 help_echo_object
= glyph
->object
;
22763 help_echo_pos
= glyph
->charpos
;
22767 if (NILP (pointer
))
22768 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
22772 /* Clear mouse face if X/Y not over text. */
22774 || area
!= TEXT_AREA
22775 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
22777 if (clear_mouse_face (dpyinfo
))
22778 cursor
= No_Cursor
;
22779 if (NILP (pointer
))
22781 if (area
!= TEXT_AREA
)
22782 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22784 pointer
= Vvoid_text_area_pointer
;
22789 pos
= glyph
->charpos
;
22790 object
= glyph
->object
;
22791 if (!STRINGP (object
) && !BUFFERP (object
))
22794 /* If we get an out-of-range value, return now; avoid an error. */
22795 if (BUFFERP (object
) && pos
> BUF_Z (b
))
22798 /* Make the window's buffer temporarily current for
22799 overlays_at and compute_char_face. */
22800 obuf
= current_buffer
;
22801 current_buffer
= b
;
22807 /* Is this char mouse-active or does it have help-echo? */
22808 position
= make_number (pos
);
22810 if (BUFFERP (object
))
22812 /* Put all the overlays we want in a vector in overlay_vec. */
22813 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
22814 /* Sort overlays into increasing priority order. */
22815 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
22820 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
22821 && vpos
>= dpyinfo
->mouse_face_beg_row
22822 && vpos
<= dpyinfo
->mouse_face_end_row
22823 && (vpos
> dpyinfo
->mouse_face_beg_row
22824 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22825 && (vpos
< dpyinfo
->mouse_face_end_row
22826 || hpos
< dpyinfo
->mouse_face_end_col
22827 || dpyinfo
->mouse_face_past_end
));
22830 cursor
= No_Cursor
;
22832 /* Check mouse-face highlighting. */
22834 /* If there exists an overlay with mouse-face overlapping
22835 the one we are currently highlighting, we have to
22836 check if we enter the overlapping overlay, and then
22837 highlight only that. */
22838 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
22839 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
22841 /* Find the highest priority overlay that has a mouse-face
22844 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
22846 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
22847 if (!NILP (mouse_face
))
22848 overlay
= overlay_vec
[i
];
22851 /* If we're actually highlighting the same overlay as
22852 before, there's no need to do that again. */
22853 if (!NILP (overlay
)
22854 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
22855 goto check_help_echo
;
22857 dpyinfo
->mouse_face_overlay
= overlay
;
22859 /* Clear the display of the old active region, if any. */
22860 if (clear_mouse_face (dpyinfo
))
22861 cursor
= No_Cursor
;
22863 /* If no overlay applies, get a text property. */
22864 if (NILP (overlay
))
22865 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
22867 /* Handle the overlay case. */
22868 if (!NILP (overlay
))
22870 /* Find the range of text around this char that
22871 should be active. */
22872 Lisp_Object before
, after
;
22875 before
= Foverlay_start (overlay
);
22876 after
= Foverlay_end (overlay
);
22877 /* Record this as the current active region. */
22878 fast_find_position (w
, XFASTINT (before
),
22879 &dpyinfo
->mouse_face_beg_col
,
22880 &dpyinfo
->mouse_face_beg_row
,
22881 &dpyinfo
->mouse_face_beg_x
,
22882 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22884 dpyinfo
->mouse_face_past_end
22885 = !fast_find_position (w
, XFASTINT (after
),
22886 &dpyinfo
->mouse_face_end_col
,
22887 &dpyinfo
->mouse_face_end_row
,
22888 &dpyinfo
->mouse_face_end_x
,
22889 &dpyinfo
->mouse_face_end_y
, Qnil
);
22890 dpyinfo
->mouse_face_window
= window
;
22892 dpyinfo
->mouse_face_face_id
22893 = face_at_buffer_position (w
, pos
, 0, 0,
22895 !dpyinfo
->mouse_face_hidden
);
22897 /* Display it as active. */
22898 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22899 cursor
= No_Cursor
;
22901 /* Handle the text property case. */
22902 else if (!NILP (mouse_face
) && BUFFERP (object
))
22904 /* Find the range of text around this char that
22905 should be active. */
22906 Lisp_Object before
, after
, beginning
, end
;
22909 beginning
= Fmarker_position (w
->start
);
22910 end
= make_number (BUF_Z (XBUFFER (object
))
22911 - XFASTINT (w
->window_end_pos
));
22913 = Fprevious_single_property_change (make_number (pos
+ 1),
22915 object
, beginning
);
22917 = Fnext_single_property_change (position
, Qmouse_face
,
22920 /* Record this as the current active region. */
22921 fast_find_position (w
, XFASTINT (before
),
22922 &dpyinfo
->mouse_face_beg_col
,
22923 &dpyinfo
->mouse_face_beg_row
,
22924 &dpyinfo
->mouse_face_beg_x
,
22925 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22926 dpyinfo
->mouse_face_past_end
22927 = !fast_find_position (w
, XFASTINT (after
),
22928 &dpyinfo
->mouse_face_end_col
,
22929 &dpyinfo
->mouse_face_end_row
,
22930 &dpyinfo
->mouse_face_end_x
,
22931 &dpyinfo
->mouse_face_end_y
, Qnil
);
22932 dpyinfo
->mouse_face_window
= window
;
22934 if (BUFFERP (object
))
22935 dpyinfo
->mouse_face_face_id
22936 = face_at_buffer_position (w
, pos
, 0, 0,
22938 !dpyinfo
->mouse_face_hidden
);
22940 /* Display it as active. */
22941 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22942 cursor
= No_Cursor
;
22944 else if (!NILP (mouse_face
) && STRINGP (object
))
22949 b
= Fprevious_single_property_change (make_number (pos
+ 1),
22952 e
= Fnext_single_property_change (position
, Qmouse_face
,
22955 b
= make_number (0);
22957 e
= make_number (SCHARS (object
) - 1);
22959 fast_find_string_pos (w
, XINT (b
), object
,
22960 &dpyinfo
->mouse_face_beg_col
,
22961 &dpyinfo
->mouse_face_beg_row
,
22962 &dpyinfo
->mouse_face_beg_x
,
22963 &dpyinfo
->mouse_face_beg_y
, 0);
22964 fast_find_string_pos (w
, XINT (e
), object
,
22965 &dpyinfo
->mouse_face_end_col
,
22966 &dpyinfo
->mouse_face_end_row
,
22967 &dpyinfo
->mouse_face_end_x
,
22968 &dpyinfo
->mouse_face_end_y
, 1);
22969 dpyinfo
->mouse_face_past_end
= 0;
22970 dpyinfo
->mouse_face_window
= window
;
22971 dpyinfo
->mouse_face_face_id
22972 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
22973 glyph
->face_id
, 1);
22974 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22975 cursor
= No_Cursor
;
22977 else if (STRINGP (object
) && NILP (mouse_face
))
22979 /* A string which doesn't have mouse-face, but
22980 the text ``under'' it might have. */
22981 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
22982 int start
= MATRIX_ROW_START_CHARPOS (r
);
22984 pos
= string_buffer_position (w
, object
, start
);
22986 mouse_face
= get_char_property_and_overlay (make_number (pos
),
22990 if (!NILP (mouse_face
) && !NILP (overlay
))
22992 Lisp_Object before
= Foverlay_start (overlay
);
22993 Lisp_Object after
= Foverlay_end (overlay
);
22996 /* Note that we might not be able to find position
22997 BEFORE in the glyph matrix if the overlay is
22998 entirely covered by a `display' property. In
22999 this case, we overshoot. So let's stop in
23000 the glyph matrix before glyphs for OBJECT. */
23001 fast_find_position (w
, XFASTINT (before
),
23002 &dpyinfo
->mouse_face_beg_col
,
23003 &dpyinfo
->mouse_face_beg_row
,
23004 &dpyinfo
->mouse_face_beg_x
,
23005 &dpyinfo
->mouse_face_beg_y
,
23008 dpyinfo
->mouse_face_past_end
23009 = !fast_find_position (w
, XFASTINT (after
),
23010 &dpyinfo
->mouse_face_end_col
,
23011 &dpyinfo
->mouse_face_end_row
,
23012 &dpyinfo
->mouse_face_end_x
,
23013 &dpyinfo
->mouse_face_end_y
,
23015 dpyinfo
->mouse_face_window
= window
;
23016 dpyinfo
->mouse_face_face_id
23017 = face_at_buffer_position (w
, pos
, 0, 0,
23019 !dpyinfo
->mouse_face_hidden
);
23021 /* Display it as active. */
23022 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23023 cursor
= No_Cursor
;
23030 /* Look for a `help-echo' property. */
23031 if (NILP (help_echo_string
)) {
23032 Lisp_Object help
, overlay
;
23034 /* Check overlays first. */
23035 help
= overlay
= Qnil
;
23036 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
23038 overlay
= overlay_vec
[i
];
23039 help
= Foverlay_get (overlay
, Qhelp_echo
);
23044 help_echo_string
= help
;
23045 help_echo_window
= window
;
23046 help_echo_object
= overlay
;
23047 help_echo_pos
= pos
;
23051 Lisp_Object object
= glyph
->object
;
23052 int charpos
= glyph
->charpos
;
23054 /* Try text properties. */
23055 if (STRINGP (object
)
23057 && charpos
< SCHARS (object
))
23059 help
= Fget_text_property (make_number (charpos
),
23060 Qhelp_echo
, object
);
23063 /* If the string itself doesn't specify a help-echo,
23064 see if the buffer text ``under'' it does. */
23065 struct glyph_row
*r
23066 = MATRIX_ROW (w
->current_matrix
, vpos
);
23067 int start
= MATRIX_ROW_START_CHARPOS (r
);
23068 int pos
= string_buffer_position (w
, object
, start
);
23071 help
= Fget_char_property (make_number (pos
),
23072 Qhelp_echo
, w
->buffer
);
23076 object
= w
->buffer
;
23081 else if (BUFFERP (object
)
23084 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
23089 help_echo_string
= help
;
23090 help_echo_window
= window
;
23091 help_echo_object
= object
;
23092 help_echo_pos
= charpos
;
23097 /* Look for a `pointer' property. */
23098 if (NILP (pointer
))
23100 /* Check overlays first. */
23101 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
23102 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
23104 if (NILP (pointer
))
23106 Lisp_Object object
= glyph
->object
;
23107 int charpos
= glyph
->charpos
;
23109 /* Try text properties. */
23110 if (STRINGP (object
)
23112 && charpos
< SCHARS (object
))
23114 pointer
= Fget_text_property (make_number (charpos
),
23116 if (NILP (pointer
))
23118 /* If the string itself doesn't specify a pointer,
23119 see if the buffer text ``under'' it does. */
23120 struct glyph_row
*r
23121 = MATRIX_ROW (w
->current_matrix
, vpos
);
23122 int start
= MATRIX_ROW_START_CHARPOS (r
);
23123 int pos
= string_buffer_position (w
, object
, start
);
23125 pointer
= Fget_char_property (make_number (pos
),
23126 Qpointer
, w
->buffer
);
23129 else if (BUFFERP (object
)
23132 pointer
= Fget_text_property (make_number (charpos
),
23139 current_buffer
= obuf
;
23144 define_frame_cursor1 (f
, cursor
, pointer
);
23149 Clear any mouse-face on window W. This function is part of the
23150 redisplay interface, and is called from try_window_id and similar
23151 functions to ensure the mouse-highlight is off. */
23154 x_clear_window_mouse_face (w
)
23157 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23158 Lisp_Object window
;
23161 XSETWINDOW (window
, w
);
23162 if (EQ (window
, dpyinfo
->mouse_face_window
))
23163 clear_mouse_face (dpyinfo
);
23169 Just discard the mouse face information for frame F, if any.
23170 This is used when the size of F is changed. */
23173 cancel_mouse_face (f
)
23176 Lisp_Object window
;
23177 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23179 window
= dpyinfo
->mouse_face_window
;
23180 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
23182 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
23183 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
23184 dpyinfo
->mouse_face_window
= Qnil
;
23189 #endif /* HAVE_WINDOW_SYSTEM */
23192 /***********************************************************************
23194 ***********************************************************************/
23196 #ifdef HAVE_WINDOW_SYSTEM
23198 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
23199 which intersects rectangle R. R is in window-relative coordinates. */
23202 expose_area (w
, row
, r
, area
)
23204 struct glyph_row
*row
;
23206 enum glyph_row_area area
;
23208 struct glyph
*first
= row
->glyphs
[area
];
23209 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
23210 struct glyph
*last
;
23211 int first_x
, start_x
, x
;
23213 if (area
== TEXT_AREA
&& row
->fill_line_p
)
23214 /* If row extends face to end of line write the whole line. */
23215 draw_glyphs (w
, 0, row
, area
,
23216 0, row
->used
[area
],
23217 DRAW_NORMAL_TEXT
, 0);
23220 /* Set START_X to the window-relative start position for drawing glyphs of
23221 AREA. The first glyph of the text area can be partially visible.
23222 The first glyphs of other areas cannot. */
23223 start_x
= window_box_left_offset (w
, area
);
23225 if (area
== TEXT_AREA
)
23228 /* Find the first glyph that must be redrawn. */
23230 && x
+ first
->pixel_width
< r
->x
)
23232 x
+= first
->pixel_width
;
23236 /* Find the last one. */
23240 && x
< r
->x
+ r
->width
)
23242 x
+= last
->pixel_width
;
23248 draw_glyphs (w
, first_x
- start_x
, row
, area
,
23249 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
23250 DRAW_NORMAL_TEXT
, 0);
23255 /* Redraw the parts of the glyph row ROW on window W intersecting
23256 rectangle R. R is in window-relative coordinates. Value is
23257 non-zero if mouse-face was overwritten. */
23260 expose_line (w
, row
, r
)
23262 struct glyph_row
*row
;
23265 xassert (row
->enabled_p
);
23267 if (row
->mode_line_p
|| w
->pseudo_window_p
)
23268 draw_glyphs (w
, 0, row
, TEXT_AREA
,
23269 0, row
->used
[TEXT_AREA
],
23270 DRAW_NORMAL_TEXT
, 0);
23273 if (row
->used
[LEFT_MARGIN_AREA
])
23274 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
23275 if (row
->used
[TEXT_AREA
])
23276 expose_area (w
, row
, r
, TEXT_AREA
);
23277 if (row
->used
[RIGHT_MARGIN_AREA
])
23278 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
23279 draw_row_fringe_bitmaps (w
, row
);
23282 return row
->mouse_face_p
;
23286 /* Redraw those parts of glyphs rows during expose event handling that
23287 overlap other rows. Redrawing of an exposed line writes over parts
23288 of lines overlapping that exposed line; this function fixes that.
23290 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
23291 row in W's current matrix that is exposed and overlaps other rows.
23292 LAST_OVERLAPPING_ROW is the last such row. */
23295 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
23297 struct glyph_row
*first_overlapping_row
;
23298 struct glyph_row
*last_overlapping_row
;
23300 struct glyph_row
*row
;
23302 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
23303 if (row
->overlapping_p
)
23305 xassert (row
->enabled_p
&& !row
->mode_line_p
);
23307 if (row
->used
[LEFT_MARGIN_AREA
])
23308 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
23310 if (row
->used
[TEXT_AREA
])
23311 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
23313 if (row
->used
[RIGHT_MARGIN_AREA
])
23314 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
23319 /* Return non-zero if W's cursor intersects rectangle R. */
23322 phys_cursor_in_rect_p (w
, r
)
23326 XRectangle cr
, result
;
23327 struct glyph
*cursor_glyph
;
23329 cursor_glyph
= get_phys_cursor_glyph (w
);
23332 /* r is relative to W's box, but w->phys_cursor.x is relative
23333 to left edge of W's TEXT area. Adjust it. */
23334 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
23335 cr
.y
= w
->phys_cursor
.y
;
23336 cr
.width
= cursor_glyph
->pixel_width
;
23337 cr
.height
= w
->phys_cursor_height
;
23338 /* ++KFS: W32 version used W32-specific IntersectRect here, but
23339 I assume the effect is the same -- and this is portable. */
23340 return x_intersect_rectangles (&cr
, r
, &result
);
23348 Draw a vertical window border to the right of window W if W doesn't
23349 have vertical scroll bars. */
23352 x_draw_vertical_border (w
)
23355 /* We could do better, if we knew what type of scroll-bar the adjacent
23356 windows (on either side) have... But we don't :-(
23357 However, I think this works ok. ++KFS 2003-04-25 */
23359 /* Redraw borders between horizontally adjacent windows. Don't
23360 do it for frames with vertical scroll bars because either the
23361 right scroll bar of a window, or the left scroll bar of its
23362 neighbor will suffice as a border. */
23363 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
23366 if (!WINDOW_RIGHTMOST_P (w
)
23367 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
23369 int x0
, x1
, y0
, y1
;
23371 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23374 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23377 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
23379 else if (!WINDOW_LEFTMOST_P (w
)
23380 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
23382 int x0
, x1
, y0
, y1
;
23384 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23387 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23390 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
23395 /* Redraw the part of window W intersection rectangle FR. Pixel
23396 coordinates in FR are frame-relative. Call this function with
23397 input blocked. Value is non-zero if the exposure overwrites
23401 expose_window (w
, fr
)
23405 struct frame
*f
= XFRAME (w
->frame
);
23407 int mouse_face_overwritten_p
= 0;
23409 /* If window is not yet fully initialized, do nothing. This can
23410 happen when toolkit scroll bars are used and a window is split.
23411 Reconfiguring the scroll bar will generate an expose for a newly
23413 if (w
->current_matrix
== NULL
)
23416 /* When we're currently updating the window, display and current
23417 matrix usually don't agree. Arrange for a thorough display
23419 if (w
== updated_window
)
23421 SET_FRAME_GARBAGED (f
);
23425 /* Frame-relative pixel rectangle of W. */
23426 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
23427 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
23428 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
23429 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
23431 if (x_intersect_rectangles (fr
, &wr
, &r
))
23433 int yb
= window_text_bottom_y (w
);
23434 struct glyph_row
*row
;
23435 int cursor_cleared_p
;
23436 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
23438 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
23439 r
.x
, r
.y
, r
.width
, r
.height
));
23441 /* Convert to window coordinates. */
23442 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
23443 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
23445 /* Turn off the cursor. */
23446 if (!w
->pseudo_window_p
23447 && phys_cursor_in_rect_p (w
, &r
))
23449 x_clear_cursor (w
);
23450 cursor_cleared_p
= 1;
23453 cursor_cleared_p
= 0;
23455 /* Update lines intersecting rectangle R. */
23456 first_overlapping_row
= last_overlapping_row
= NULL
;
23457 for (row
= w
->current_matrix
->rows
;
23462 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
23464 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
23465 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
23466 || (r
.y
>= y0
&& r
.y
< y1
)
23467 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
23469 /* A header line may be overlapping, but there is no need
23470 to fix overlapping areas for them. KFS 2005-02-12 */
23471 if (row
->overlapping_p
&& !row
->mode_line_p
)
23473 if (first_overlapping_row
== NULL
)
23474 first_overlapping_row
= row
;
23475 last_overlapping_row
= row
;
23478 if (expose_line (w
, row
, &r
))
23479 mouse_face_overwritten_p
= 1;
23486 /* Display the mode line if there is one. */
23487 if (WINDOW_WANTS_MODELINE_P (w
)
23488 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
23490 && row
->y
< r
.y
+ r
.height
)
23492 if (expose_line (w
, row
, &r
))
23493 mouse_face_overwritten_p
= 1;
23496 if (!w
->pseudo_window_p
)
23498 /* Fix the display of overlapping rows. */
23499 if (first_overlapping_row
)
23500 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
23502 /* Draw border between windows. */
23503 x_draw_vertical_border (w
);
23505 /* Turn the cursor on again. */
23506 if (cursor_cleared_p
)
23507 update_window_cursor (w
, 1);
23511 return mouse_face_overwritten_p
;
23516 /* Redraw (parts) of all windows in the window tree rooted at W that
23517 intersect R. R contains frame pixel coordinates. Value is
23518 non-zero if the exposure overwrites mouse-face. */
23521 expose_window_tree (w
, r
)
23525 struct frame
*f
= XFRAME (w
->frame
);
23526 int mouse_face_overwritten_p
= 0;
23528 while (w
&& !FRAME_GARBAGED_P (f
))
23530 if (!NILP (w
->hchild
))
23531 mouse_face_overwritten_p
23532 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
23533 else if (!NILP (w
->vchild
))
23534 mouse_face_overwritten_p
23535 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
23537 mouse_face_overwritten_p
|= expose_window (w
, r
);
23539 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
23542 return mouse_face_overwritten_p
;
23547 Redisplay an exposed area of frame F. X and Y are the upper-left
23548 corner of the exposed rectangle. W and H are width and height of
23549 the exposed area. All are pixel values. W or H zero means redraw
23550 the entire frame. */
23553 expose_frame (f
, x
, y
, w
, h
)
23558 int mouse_face_overwritten_p
= 0;
23560 TRACE ((stderr
, "expose_frame "));
23562 /* No need to redraw if frame will be redrawn soon. */
23563 if (FRAME_GARBAGED_P (f
))
23565 TRACE ((stderr
, " garbaged\n"));
23569 /* If basic faces haven't been realized yet, there is no point in
23570 trying to redraw anything. This can happen when we get an expose
23571 event while Emacs is starting, e.g. by moving another window. */
23572 if (FRAME_FACE_CACHE (f
) == NULL
23573 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
23575 TRACE ((stderr
, " no faces\n"));
23579 if (w
== 0 || h
== 0)
23582 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
23583 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
23593 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
23594 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
23596 if (WINDOWP (f
->tool_bar_window
))
23597 mouse_face_overwritten_p
23598 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
23600 #ifdef HAVE_X_WINDOWS
23602 #ifndef USE_X_TOOLKIT
23603 if (WINDOWP (f
->menu_bar_window
))
23604 mouse_face_overwritten_p
23605 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
23606 #endif /* not USE_X_TOOLKIT */
23610 /* Some window managers support a focus-follows-mouse style with
23611 delayed raising of frames. Imagine a partially obscured frame,
23612 and moving the mouse into partially obscured mouse-face on that
23613 frame. The visible part of the mouse-face will be highlighted,
23614 then the WM raises the obscured frame. With at least one WM, KDE
23615 2.1, Emacs is not getting any event for the raising of the frame
23616 (even tried with SubstructureRedirectMask), only Expose events.
23617 These expose events will draw text normally, i.e. not
23618 highlighted. Which means we must redo the highlight here.
23619 Subsume it under ``we love X''. --gerd 2001-08-15 */
23620 /* Included in Windows version because Windows most likely does not
23621 do the right thing if any third party tool offers
23622 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
23623 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
23625 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23626 if (f
== dpyinfo
->mouse_face_mouse_frame
)
23628 int x
= dpyinfo
->mouse_face_mouse_x
;
23629 int y
= dpyinfo
->mouse_face_mouse_y
;
23630 clear_mouse_face (dpyinfo
);
23631 note_mouse_highlight (f
, x
, y
);
23638 Determine the intersection of two rectangles R1 and R2. Return
23639 the intersection in *RESULT. Value is non-zero if RESULT is not
23643 x_intersect_rectangles (r1
, r2
, result
)
23644 XRectangle
*r1
, *r2
, *result
;
23646 XRectangle
*left
, *right
;
23647 XRectangle
*upper
, *lower
;
23648 int intersection_p
= 0;
23650 /* Rearrange so that R1 is the left-most rectangle. */
23652 left
= r1
, right
= r2
;
23654 left
= r2
, right
= r1
;
23656 /* X0 of the intersection is right.x0, if this is inside R1,
23657 otherwise there is no intersection. */
23658 if (right
->x
<= left
->x
+ left
->width
)
23660 result
->x
= right
->x
;
23662 /* The right end of the intersection is the minimum of the
23663 the right ends of left and right. */
23664 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
23667 /* Same game for Y. */
23669 upper
= r1
, lower
= r2
;
23671 upper
= r2
, lower
= r1
;
23673 /* The upper end of the intersection is lower.y0, if this is inside
23674 of upper. Otherwise, there is no intersection. */
23675 if (lower
->y
<= upper
->y
+ upper
->height
)
23677 result
->y
= lower
->y
;
23679 /* The lower end of the intersection is the minimum of the lower
23680 ends of upper and lower. */
23681 result
->height
= (min (lower
->y
+ lower
->height
,
23682 upper
->y
+ upper
->height
)
23684 intersection_p
= 1;
23688 return intersection_p
;
23691 #endif /* HAVE_WINDOW_SYSTEM */
23694 /***********************************************************************
23696 ***********************************************************************/
23701 Vwith_echo_area_save_vector
= Qnil
;
23702 staticpro (&Vwith_echo_area_save_vector
);
23704 Vmessage_stack
= Qnil
;
23705 staticpro (&Vmessage_stack
);
23707 Qinhibit_redisplay
= intern ("inhibit-redisplay");
23708 staticpro (&Qinhibit_redisplay
);
23710 message_dolog_marker1
= Fmake_marker ();
23711 staticpro (&message_dolog_marker1
);
23712 message_dolog_marker2
= Fmake_marker ();
23713 staticpro (&message_dolog_marker2
);
23714 message_dolog_marker3
= Fmake_marker ();
23715 staticpro (&message_dolog_marker3
);
23718 defsubr (&Sdump_frame_glyph_matrix
);
23719 defsubr (&Sdump_glyph_matrix
);
23720 defsubr (&Sdump_glyph_row
);
23721 defsubr (&Sdump_tool_bar_row
);
23722 defsubr (&Strace_redisplay
);
23723 defsubr (&Strace_to_stderr
);
23725 #ifdef HAVE_WINDOW_SYSTEM
23726 defsubr (&Stool_bar_lines_needed
);
23727 defsubr (&Slookup_image_map
);
23729 defsubr (&Sformat_mode_line
);
23731 staticpro (&Qmenu_bar_update_hook
);
23732 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
23734 staticpro (&Qoverriding_terminal_local_map
);
23735 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
23737 staticpro (&Qoverriding_local_map
);
23738 Qoverriding_local_map
= intern ("overriding-local-map");
23740 staticpro (&Qwindow_scroll_functions
);
23741 Qwindow_scroll_functions
= intern ("window-scroll-functions");
23743 staticpro (&Qredisplay_end_trigger_functions
);
23744 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
23746 staticpro (&Qinhibit_point_motion_hooks
);
23747 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
23749 QCdata
= intern (":data");
23750 staticpro (&QCdata
);
23751 Qdisplay
= intern ("display");
23752 staticpro (&Qdisplay
);
23753 Qspace_width
= intern ("space-width");
23754 staticpro (&Qspace_width
);
23755 Qraise
= intern ("raise");
23756 staticpro (&Qraise
);
23757 Qslice
= intern ("slice");
23758 staticpro (&Qslice
);
23759 Qspace
= intern ("space");
23760 staticpro (&Qspace
);
23761 Qmargin
= intern ("margin");
23762 staticpro (&Qmargin
);
23763 Qpointer
= intern ("pointer");
23764 staticpro (&Qpointer
);
23765 Qleft_margin
= intern ("left-margin");
23766 staticpro (&Qleft_margin
);
23767 Qright_margin
= intern ("right-margin");
23768 staticpro (&Qright_margin
);
23769 Qcenter
= intern ("center");
23770 staticpro (&Qcenter
);
23771 Qline_height
= intern ("line-height");
23772 staticpro (&Qline_height
);
23773 QCalign_to
= intern (":align-to");
23774 staticpro (&QCalign_to
);
23775 QCrelative_width
= intern (":relative-width");
23776 staticpro (&QCrelative_width
);
23777 QCrelative_height
= intern (":relative-height");
23778 staticpro (&QCrelative_height
);
23779 QCeval
= intern (":eval");
23780 staticpro (&QCeval
);
23781 QCpropertize
= intern (":propertize");
23782 staticpro (&QCpropertize
);
23783 QCfile
= intern (":file");
23784 staticpro (&QCfile
);
23785 Qfontified
= intern ("fontified");
23786 staticpro (&Qfontified
);
23787 Qfontification_functions
= intern ("fontification-functions");
23788 staticpro (&Qfontification_functions
);
23789 Qtrailing_whitespace
= intern ("trailing-whitespace");
23790 staticpro (&Qtrailing_whitespace
);
23791 Qescape_glyph
= intern ("escape-glyph");
23792 staticpro (&Qescape_glyph
);
23793 Qnobreak_space
= intern ("nobreak-space");
23794 staticpro (&Qnobreak_space
);
23795 Qimage
= intern ("image");
23796 staticpro (&Qimage
);
23797 QCmap
= intern (":map");
23798 staticpro (&QCmap
);
23799 QCpointer
= intern (":pointer");
23800 staticpro (&QCpointer
);
23801 Qrect
= intern ("rect");
23802 staticpro (&Qrect
);
23803 Qcircle
= intern ("circle");
23804 staticpro (&Qcircle
);
23805 Qpoly
= intern ("poly");
23806 staticpro (&Qpoly
);
23807 Qmessage_truncate_lines
= intern ("message-truncate-lines");
23808 staticpro (&Qmessage_truncate_lines
);
23809 Qgrow_only
= intern ("grow-only");
23810 staticpro (&Qgrow_only
);
23811 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
23812 staticpro (&Qinhibit_menubar_update
);
23813 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
23814 staticpro (&Qinhibit_eval_during_redisplay
);
23815 Qposition
= intern ("position");
23816 staticpro (&Qposition
);
23817 Qbuffer_position
= intern ("buffer-position");
23818 staticpro (&Qbuffer_position
);
23819 Qobject
= intern ("object");
23820 staticpro (&Qobject
);
23821 Qbar
= intern ("bar");
23823 Qhbar
= intern ("hbar");
23824 staticpro (&Qhbar
);
23825 Qbox
= intern ("box");
23827 Qhollow
= intern ("hollow");
23828 staticpro (&Qhollow
);
23829 Qhand
= intern ("hand");
23830 staticpro (&Qhand
);
23831 Qarrow
= intern ("arrow");
23832 staticpro (&Qarrow
);
23833 Qtext
= intern ("text");
23834 staticpro (&Qtext
);
23835 Qrisky_local_variable
= intern ("risky-local-variable");
23836 staticpro (&Qrisky_local_variable
);
23837 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
23838 staticpro (&Qinhibit_free_realized_faces
);
23840 list_of_error
= Fcons (Fcons (intern ("error"),
23841 Fcons (intern ("void-variable"), Qnil
)),
23843 staticpro (&list_of_error
);
23845 Qlast_arrow_position
= intern ("last-arrow-position");
23846 staticpro (&Qlast_arrow_position
);
23847 Qlast_arrow_string
= intern ("last-arrow-string");
23848 staticpro (&Qlast_arrow_string
);
23850 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
23851 staticpro (&Qoverlay_arrow_string
);
23852 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
23853 staticpro (&Qoverlay_arrow_bitmap
);
23855 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
23856 staticpro (&echo_buffer
[0]);
23857 staticpro (&echo_buffer
[1]);
23859 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
23860 staticpro (&echo_area_buffer
[0]);
23861 staticpro (&echo_area_buffer
[1]);
23863 Vmessages_buffer_name
= build_string ("*Messages*");
23864 staticpro (&Vmessages_buffer_name
);
23866 mode_line_proptrans_alist
= Qnil
;
23867 staticpro (&mode_line_proptrans_alist
);
23868 mode_line_string_list
= Qnil
;
23869 staticpro (&mode_line_string_list
);
23870 mode_line_string_face
= Qnil
;
23871 staticpro (&mode_line_string_face
);
23872 mode_line_string_face_prop
= Qnil
;
23873 staticpro (&mode_line_string_face_prop
);
23874 Vmode_line_unwind_vector
= Qnil
;
23875 staticpro (&Vmode_line_unwind_vector
);
23877 help_echo_string
= Qnil
;
23878 staticpro (&help_echo_string
);
23879 help_echo_object
= Qnil
;
23880 staticpro (&help_echo_object
);
23881 help_echo_window
= Qnil
;
23882 staticpro (&help_echo_window
);
23883 previous_help_echo_string
= Qnil
;
23884 staticpro (&previous_help_echo_string
);
23885 help_echo_pos
= -1;
23887 #ifdef HAVE_WINDOW_SYSTEM
23888 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
23889 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
23890 For example, if a block cursor is over a tab, it will be drawn as
23891 wide as that tab on the display. */);
23892 x_stretch_cursor_p
= 0;
23895 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
23896 doc
: /* *Non-nil means highlight trailing whitespace.
23897 The face used for trailing whitespace is `trailing-whitespace'. */);
23898 Vshow_trailing_whitespace
= Qnil
;
23900 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
23901 doc
: /* *Control highlighting of nobreak space and soft hyphen.
23902 A value of t means highlight the character itself (for nobreak space,
23903 use face `nobreak-space').
23904 A value of nil means no highlighting.
23905 Other values mean display the escape glyph followed by an ordinary
23906 space or ordinary hyphen. */);
23907 Vnobreak_char_display
= Qt
;
23909 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
23910 doc
: /* *The pointer shape to show in void text areas.
23911 A value of nil means to show the text pointer. Other options are `arrow',
23912 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
23913 Vvoid_text_area_pointer
= Qarrow
;
23915 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
23916 doc
: /* Non-nil means don't actually do any redisplay.
23917 This is used for internal purposes. */);
23918 Vinhibit_redisplay
= Qnil
;
23920 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
23921 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
23922 Vglobal_mode_string
= Qnil
;
23924 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
23925 doc
: /* Marker for where to display an arrow on top of the buffer text.
23926 This must be the beginning of a line in order to work.
23927 See also `overlay-arrow-string'. */);
23928 Voverlay_arrow_position
= Qnil
;
23930 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
23931 doc
: /* String to display as an arrow in non-window frames.
23932 See also `overlay-arrow-position'. */);
23933 Voverlay_arrow_string
= build_string ("=>");
23935 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
23936 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
23937 The symbols on this list are examined during redisplay to determine
23938 where to display overlay arrows. */);
23939 Voverlay_arrow_variable_list
23940 = Fcons (intern ("overlay-arrow-position"), Qnil
);
23942 DEFVAR_INT ("scroll-step", &scroll_step
,
23943 doc
: /* *The number of lines to try scrolling a window by when point moves out.
23944 If that fails to bring point back on frame, point is centered instead.
23945 If this is zero, point is always centered after it moves off frame.
23946 If you want scrolling to always be a line at a time, you should set
23947 `scroll-conservatively' to a large value rather than set this to 1. */);
23949 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
23950 doc
: /* *Scroll up to this many lines, to bring point back on screen.
23951 A value of zero means to scroll the text to center point vertically
23952 in the window. */);
23953 scroll_conservatively
= 0;
23955 DEFVAR_INT ("scroll-margin", &scroll_margin
,
23956 doc
: /* *Number of lines of margin at the top and bottom of a window.
23957 Recenter the window whenever point gets within this many lines
23958 of the top or bottom of the window. */);
23961 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
23962 doc
: /* Pixels per inch value for non-window system displays.
23963 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
23964 Vdisplay_pixels_per_inch
= make_float (72.0);
23967 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
23970 DEFVAR_BOOL ("truncate-partial-width-windows",
23971 &truncate_partial_width_windows
,
23972 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
23973 truncate_partial_width_windows
= 1;
23975 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
23976 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
23977 Any other value means to use the appropriate face, `mode-line',
23978 `header-line', or `menu' respectively. */);
23979 mode_line_inverse_video
= 1;
23981 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
23982 doc
: /* *Maximum buffer size for which line number should be displayed.
23983 If the buffer is bigger than this, the line number does not appear
23984 in the mode line. A value of nil means no limit. */);
23985 Vline_number_display_limit
= Qnil
;
23987 DEFVAR_INT ("line-number-display-limit-width",
23988 &line_number_display_limit_width
,
23989 doc
: /* *Maximum line width (in characters) for line number display.
23990 If the average length of the lines near point is bigger than this, then the
23991 line number may be omitted from the mode line. */);
23992 line_number_display_limit_width
= 200;
23994 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
23995 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
23996 highlight_nonselected_windows
= 0;
23998 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
23999 doc
: /* Non-nil if more than one frame is visible on this display.
24000 Minibuffer-only frames don't count, but iconified frames do.
24001 This variable is not guaranteed to be accurate except while processing
24002 `frame-title-format' and `icon-title-format'. */);
24004 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
24005 doc
: /* Template for displaying the title bar of visible frames.
24006 \(Assuming the window manager supports this feature.)
24008 This variable has the same structure as `mode-line-format', except that
24009 the %c and %l constructs are ignored. It is used only on frames for
24010 which no explicit name has been set \(see `modify-frame-parameters'). */);
24012 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
24013 doc
: /* Template for displaying the title bar of an iconified frame.
24014 \(Assuming the window manager supports this feature.)
24015 This variable has the same structure as `mode-line-format' (which see),
24016 and is used only on frames for which no explicit name has been set
24017 \(see `modify-frame-parameters'). */);
24019 = Vframe_title_format
24020 = Fcons (intern ("multiple-frames"),
24021 Fcons (build_string ("%b"),
24022 Fcons (Fcons (empty_string
,
24023 Fcons (intern ("invocation-name"),
24024 Fcons (build_string ("@"),
24025 Fcons (intern ("system-name"),
24029 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
24030 doc
: /* Maximum number of lines to keep in the message log buffer.
24031 If nil, disable message logging. If t, log messages but don't truncate
24032 the buffer when it becomes large. */);
24033 Vmessage_log_max
= make_number (50);
24035 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
24036 doc
: /* Functions called before redisplay, if window sizes have changed.
24037 The value should be a list of functions that take one argument.
24038 Just before redisplay, for each frame, if any of its windows have changed
24039 size since the last redisplay, or have been split or deleted,
24040 all the functions in the list are called, with the frame as argument. */);
24041 Vwindow_size_change_functions
= Qnil
;
24043 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
24044 doc
: /* List of functions to call before redisplaying a window with scrolling.
24045 Each function is called with two arguments, the window
24046 and its new display-start position. Note that the value of `window-end'
24047 is not valid when these functions are called. */);
24048 Vwindow_scroll_functions
= Qnil
;
24050 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
24051 doc
: /* Functions called when redisplay of a window reaches the end trigger.
24052 Each function is called with two arguments, the window and the end trigger value.
24053 See `set-window-redisplay-end-trigger'. */);
24054 Vredisplay_end_trigger_functions
= Qnil
;
24056 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
24057 doc
: /* *Non-nil means autoselect window with mouse pointer.
24058 If nil, do not autoselect windows.
24059 A positive number means delay autoselection by that many seconds: a
24060 window is autoselected only after the mouse has remained in that
24061 window for the duration of the delay.
24062 A negative number has a similar effect, but causes windows to be
24063 autoselected only after the mouse has stopped moving. \(Because of
24064 the way Emacs compares mouse events, you will occasionally wait twice
24065 that time before the window gets selected.\)
24066 Any other value means to autoselect window instantaneously when the
24067 mouse pointer enters it.
24069 Autoselection selects the minibuffer only if it is active, and never
24070 unselects the minibuffer if it is active. */);
24071 Vmouse_autoselect_window
= Qnil
;
24073 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
24074 doc
: /* *Non-nil means automatically resize tool-bars.
24075 This increases a tool-bar's height if not all tool-bar items are visible.
24076 It decreases a tool-bar's height when it would display blank lines
24078 auto_resize_tool_bars_p
= 1;
24080 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
24081 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
24082 auto_raise_tool_bar_buttons_p
= 1;
24084 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
24085 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
24086 make_cursor_line_fully_visible_p
= 1;
24088 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
24089 doc
: /* *Border below tool-bar in pixels.
24090 If an integer, use it as the height of the border.
24091 If it is one of `internal-border-width' or `border-width', use the
24092 value of the corresponding frame parameter.
24093 Otherwise, no border is added below the tool-bar. */);
24094 Vtool_bar_border
= Qinternal_border_width
;
24096 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
24097 doc
: /* *Margin around tool-bar buttons in pixels.
24098 If an integer, use that for both horizontal and vertical margins.
24099 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
24100 HORZ specifying the horizontal margin, and VERT specifying the
24101 vertical margin. */);
24102 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
24104 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
24105 doc
: /* *Relief thickness of tool-bar buttons. */);
24106 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
24108 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
24109 doc
: /* List of functions to call to fontify regions of text.
24110 Each function is called with one argument POS. Functions must
24111 fontify a region starting at POS in the current buffer, and give
24112 fontified regions the property `fontified'. */);
24113 Vfontification_functions
= Qnil
;
24114 Fmake_variable_buffer_local (Qfontification_functions
);
24116 DEFVAR_BOOL ("unibyte-display-via-language-environment",
24117 &unibyte_display_via_language_environment
,
24118 doc
: /* *Non-nil means display unibyte text according to language environment.
24119 Specifically this means that unibyte non-ASCII characters
24120 are displayed by converting them to the equivalent multibyte characters
24121 according to the current language environment. As a result, they are
24122 displayed according to the current fontset. */);
24123 unibyte_display_via_language_environment
= 0;
24125 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
24126 doc
: /* *Maximum height for resizing mini-windows.
24127 If a float, it specifies a fraction of the mini-window frame's height.
24128 If an integer, it specifies a number of lines. */);
24129 Vmax_mini_window_height
= make_float (0.25);
24131 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
24132 doc
: /* *How to resize mini-windows.
24133 A value of nil means don't automatically resize mini-windows.
24134 A value of t means resize them to fit the text displayed in them.
24135 A value of `grow-only', the default, means let mini-windows grow
24136 only, until their display becomes empty, at which point the windows
24137 go back to their normal size. */);
24138 Vresize_mini_windows
= Qgrow_only
;
24140 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
24141 doc
: /* Alist specifying how to blink the cursor off.
24142 Each element has the form (ON-STATE . OFF-STATE). Whenever the
24143 `cursor-type' frame-parameter or variable equals ON-STATE,
24144 comparing using `equal', Emacs uses OFF-STATE to specify
24145 how to blink it off. ON-STATE and OFF-STATE are values for
24146 the `cursor-type' frame parameter.
24148 If a frame's ON-STATE has no entry in this list,
24149 the frame's other specifications determine how to blink the cursor off. */);
24150 Vblink_cursor_alist
= Qnil
;
24152 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
24153 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
24154 automatic_hscrolling_p
= 1;
24156 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
24157 doc
: /* *How many columns away from the window edge point is allowed to get
24158 before automatic hscrolling will horizontally scroll the window. */);
24159 hscroll_margin
= 5;
24161 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
24162 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
24163 When point is less than `hscroll-margin' columns from the window
24164 edge, automatic hscrolling will scroll the window by the amount of columns
24165 determined by this variable. If its value is a positive integer, scroll that
24166 many columns. If it's a positive floating-point number, it specifies the
24167 fraction of the window's width to scroll. If it's nil or zero, point will be
24168 centered horizontally after the scroll. Any other value, including negative
24169 numbers, are treated as if the value were zero.
24171 Automatic hscrolling always moves point outside the scroll margin, so if
24172 point was more than scroll step columns inside the margin, the window will
24173 scroll more than the value given by the scroll step.
24175 Note that the lower bound for automatic hscrolling specified by `scroll-left'
24176 and `scroll-right' overrides this variable's effect. */);
24177 Vhscroll_step
= make_number (0);
24179 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
24180 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
24181 Bind this around calls to `message' to let it take effect. */);
24182 message_truncate_lines
= 0;
24184 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
24185 doc
: /* Normal hook run to update the menu bar definitions.
24186 Redisplay runs this hook before it redisplays the menu bar.
24187 This is used to update submenus such as Buffers,
24188 whose contents depend on various data. */);
24189 Vmenu_bar_update_hook
= Qnil
;
24191 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
24192 doc
: /* Frame for which we are updating a menu.
24193 The enable predicate for a menu binding should check this variable. */);
24194 Vmenu_updating_frame
= Qnil
;
24196 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
24197 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
24198 inhibit_menubar_update
= 0;
24200 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
24201 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
24202 inhibit_eval_during_redisplay
= 0;
24204 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
24205 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
24206 inhibit_free_realized_faces
= 0;
24209 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
24210 doc
: /* Inhibit try_window_id display optimization. */);
24211 inhibit_try_window_id
= 0;
24213 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
24214 doc
: /* Inhibit try_window_reusing display optimization. */);
24215 inhibit_try_window_reusing
= 0;
24217 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
24218 doc
: /* Inhibit try_cursor_movement display optimization. */);
24219 inhibit_try_cursor_movement
= 0;
24220 #endif /* GLYPH_DEBUG */
24222 DEFVAR_INT ("overline-margin", &overline_margin
,
24223 doc
: /* *Space between overline and text, in pixels.
24224 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
24225 margin to the caracter height. */);
24226 overline_margin
= 2;
24230 /* Initialize this module when Emacs starts. */
24235 Lisp_Object root_window
;
24236 struct window
*mini_w
;
24238 current_header_line_height
= current_mode_line_height
= -1;
24240 CHARPOS (this_line_start_pos
) = 0;
24242 mini_w
= XWINDOW (minibuf_window
);
24243 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
24245 if (!noninteractive
)
24247 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
24250 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
24251 set_window_height (root_window
,
24252 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
24254 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
24255 set_window_height (minibuf_window
, 1, 0);
24257 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
24258 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
24260 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
24261 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
24262 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
24264 /* The default ellipsis glyphs `...'. */
24265 for (i
= 0; i
< 3; ++i
)
24266 default_invis_vector
[i
] = make_number ('.');
24270 /* Allocate the buffer for frame titles.
24271 Also used for `format-mode-line'. */
24273 mode_line_noprop_buf
= (char *) xmalloc (size
);
24274 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
24275 mode_line_noprop_ptr
= mode_line_noprop_buf
;
24276 mode_line_target
= MODE_LINE_DISPLAY
;
24279 help_echo_showing_p
= 0;
24283 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
24284 (do not change this comment) */