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 If visible, set *X and *Y to pixel coordinates of top left corner.
1279 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1280 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1283 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1285 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1288 struct text_pos top
;
1290 struct buffer
*old_buffer
= NULL
;
1295 if (XBUFFER (w
->buffer
) != current_buffer
)
1297 old_buffer
= current_buffer
;
1298 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1301 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1303 /* Compute exact mode line heights. */
1304 if (WINDOW_WANTS_MODELINE_P (w
))
1305 current_mode_line_height
1306 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1307 current_buffer
->mode_line_format
);
1309 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1310 current_header_line_height
1311 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1312 current_buffer
->header_line_format
);
1314 start_display (&it
, w
, top
);
1315 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1316 MOVE_TO_POS
| MOVE_TO_Y
);
1318 /* Note that we may overshoot because of invisible text. */
1319 if (IT_CHARPOS (it
) >= charpos
)
1321 int top_x
= it
.current_x
;
1322 int top_y
= it
.current_y
;
1323 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1324 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1326 if (top_y
< window_top_y
)
1327 visible_p
= bottom_y
> window_top_y
;
1328 else if (top_y
< it
.last_visible_y
)
1333 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1334 *rtop
= max (0, window_top_y
- top_y
);
1335 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1336 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1337 - max (top_y
, window_top_y
)));
1346 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1347 move_it_by_lines (&it
, 1, 0);
1348 if (charpos
< IT_CHARPOS (it
))
1351 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1353 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1354 *rtop
= max (0, -it2
.current_y
);
1355 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1356 - it
.last_visible_y
));
1357 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1359 - max (it2
.current_y
,
1360 WINDOW_HEADER_LINE_HEIGHT (w
))));
1366 set_buffer_internal_1 (old_buffer
);
1368 current_header_line_height
= current_mode_line_height
= -1;
1370 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1371 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1374 /* Debugging code. */
1376 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1377 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1379 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1386 /* Return the next character from STR which is MAXLEN bytes long.
1387 Return in *LEN the length of the character. This is like
1388 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1389 we find one, we return a `?', but with the length of the invalid
1393 string_char_and_length (str
, maxlen
, len
)
1394 const unsigned char *str
;
1399 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1400 if (!CHAR_VALID_P (c
, 1))
1401 /* We may not change the length here because other places in Emacs
1402 don't use this function, i.e. they silently accept invalid
1411 /* Given a position POS containing a valid character and byte position
1412 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1414 static struct text_pos
1415 string_pos_nchars_ahead (pos
, string
, nchars
)
1416 struct text_pos pos
;
1420 xassert (STRINGP (string
) && nchars
>= 0);
1422 if (STRING_MULTIBYTE (string
))
1424 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1425 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1430 string_char_and_length (p
, rest
, &len
);
1431 p
+= len
, rest
-= len
;
1432 xassert (rest
>= 0);
1434 BYTEPOS (pos
) += len
;
1438 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1444 /* Value is the text position, i.e. character and byte position,
1445 for character position CHARPOS in STRING. */
1447 static INLINE
struct text_pos
1448 string_pos (charpos
, string
)
1452 struct text_pos pos
;
1453 xassert (STRINGP (string
));
1454 xassert (charpos
>= 0);
1455 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1460 /* Value is a text position, i.e. character and byte position, for
1461 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1462 means recognize multibyte characters. */
1464 static struct text_pos
1465 c_string_pos (charpos
, s
, multibyte_p
)
1470 struct text_pos pos
;
1472 xassert (s
!= NULL
);
1473 xassert (charpos
>= 0);
1477 int rest
= strlen (s
), len
;
1479 SET_TEXT_POS (pos
, 0, 0);
1482 string_char_and_length (s
, rest
, &len
);
1483 s
+= len
, rest
-= len
;
1484 xassert (rest
>= 0);
1486 BYTEPOS (pos
) += len
;
1490 SET_TEXT_POS (pos
, charpos
, charpos
);
1496 /* Value is the number of characters in C string S. MULTIBYTE_P
1497 non-zero means recognize multibyte characters. */
1500 number_of_chars (s
, multibyte_p
)
1508 int rest
= strlen (s
), len
;
1509 unsigned char *p
= (unsigned char *) s
;
1511 for (nchars
= 0; rest
> 0; ++nchars
)
1513 string_char_and_length (p
, rest
, &len
);
1514 rest
-= len
, p
+= len
;
1518 nchars
= strlen (s
);
1524 /* Compute byte position NEWPOS->bytepos corresponding to
1525 NEWPOS->charpos. POS is a known position in string STRING.
1526 NEWPOS->charpos must be >= POS.charpos. */
1529 compute_string_pos (newpos
, pos
, string
)
1530 struct text_pos
*newpos
, pos
;
1533 xassert (STRINGP (string
));
1534 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1536 if (STRING_MULTIBYTE (string
))
1537 *newpos
= string_pos_nchars_ahead (pos
, string
,
1538 CHARPOS (*newpos
) - CHARPOS (pos
));
1540 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1544 Return an estimation of the pixel height of mode or top lines on
1545 frame F. FACE_ID specifies what line's height to estimate. */
1548 estimate_mode_line_height (f
, face_id
)
1550 enum face_id face_id
;
1552 #ifdef HAVE_WINDOW_SYSTEM
1553 if (FRAME_WINDOW_P (f
))
1555 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1557 /* This function is called so early when Emacs starts that the face
1558 cache and mode line face are not yet initialized. */
1559 if (FRAME_FACE_CACHE (f
))
1561 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1565 height
= FONT_HEIGHT (face
->font
);
1566 if (face
->box_line_width
> 0)
1567 height
+= 2 * face
->box_line_width
;
1578 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1579 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1580 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1581 not force the value into range. */
1584 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1586 register int pix_x
, pix_y
;
1588 NativeRectangle
*bounds
;
1592 #ifdef HAVE_WINDOW_SYSTEM
1593 if (FRAME_WINDOW_P (f
))
1595 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1596 even for negative values. */
1598 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1600 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1602 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1603 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1606 STORE_NATIVE_RECT (*bounds
,
1607 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1608 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1609 FRAME_COLUMN_WIDTH (f
) - 1,
1610 FRAME_LINE_HEIGHT (f
) - 1);
1616 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1617 pix_x
= FRAME_TOTAL_COLS (f
);
1621 else if (pix_y
> FRAME_LINES (f
))
1622 pix_y
= FRAME_LINES (f
);
1632 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1633 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1634 can't tell the positions because W's display is not up to date,
1638 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1641 int *frame_x
, *frame_y
;
1643 #ifdef HAVE_WINDOW_SYSTEM
1644 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1648 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1649 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1651 if (display_completed
)
1653 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1654 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1655 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1661 hpos
+= glyph
->pixel_width
;
1665 /* If first glyph is partially visible, its first visible position is still 0. */
1677 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1678 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1689 #ifdef HAVE_WINDOW_SYSTEM
1691 /* Find the glyph under window-relative coordinates X/Y in window W.
1692 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1693 strings. Return in *HPOS and *VPOS the row and column number of
1694 the glyph found. Return in *AREA the glyph area containing X.
1695 Value is a pointer to the glyph found or null if X/Y is not on
1696 text, or we can't tell because W's current matrix is not up to
1699 static struct glyph
*
1700 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1703 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1705 struct glyph
*glyph
, *end
;
1706 struct glyph_row
*row
= NULL
;
1709 /* Find row containing Y. Give up if some row is not enabled. */
1710 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1712 row
= MATRIX_ROW (w
->current_matrix
, i
);
1713 if (!row
->enabled_p
)
1715 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1722 /* Give up if Y is not in the window. */
1723 if (i
== w
->current_matrix
->nrows
)
1726 /* Get the glyph area containing X. */
1727 if (w
->pseudo_window_p
)
1734 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1736 *area
= LEFT_MARGIN_AREA
;
1737 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1739 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1742 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1746 *area
= RIGHT_MARGIN_AREA
;
1747 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1751 /* Find glyph containing X. */
1752 glyph
= row
->glyphs
[*area
];
1753 end
= glyph
+ row
->used
[*area
];
1755 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1757 x
-= glyph
->pixel_width
;
1767 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1770 *hpos
= glyph
- row
->glyphs
[*area
];
1776 Convert frame-relative x/y to coordinates relative to window W.
1777 Takes pseudo-windows into account. */
1780 frame_to_window_pixel_xy (w
, x
, y
)
1784 if (w
->pseudo_window_p
)
1786 /* A pseudo-window is always full-width, and starts at the
1787 left edge of the frame, plus a frame border. */
1788 struct frame
*f
= XFRAME (w
->frame
);
1789 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1790 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1794 *x
-= WINDOW_LEFT_EDGE_X (w
);
1795 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1800 Return in RECTS[] at most N clipping rectangles for glyph string S.
1801 Return the number of stored rectangles. */
1804 get_glyph_string_clip_rects (s
, rects
, n
)
1805 struct glyph_string
*s
;
1806 NativeRectangle
*rects
;
1814 if (s
->row
->full_width_p
)
1816 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1817 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1818 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1820 /* Unless displaying a mode or menu bar line, which are always
1821 fully visible, clip to the visible part of the row. */
1822 if (s
->w
->pseudo_window_p
)
1823 r
.height
= s
->row
->visible_height
;
1825 r
.height
= s
->height
;
1829 /* This is a text line that may be partially visible. */
1830 r
.x
= window_box_left (s
->w
, s
->area
);
1831 r
.width
= window_box_width (s
->w
, s
->area
);
1832 r
.height
= s
->row
->visible_height
;
1836 if (r
.x
< s
->clip_head
->x
)
1838 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1839 r
.width
-= s
->clip_head
->x
- r
.x
;
1842 r
.x
= s
->clip_head
->x
;
1845 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1847 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1848 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1853 /* If S draws overlapping rows, it's sufficient to use the top and
1854 bottom of the window for clipping because this glyph string
1855 intentionally draws over other lines. */
1856 if (s
->for_overlaps
)
1858 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1859 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1861 /* Alas, the above simple strategy does not work for the
1862 environments with anti-aliased text: if the same text is
1863 drawn onto the same place multiple times, it gets thicker.
1864 If the overlap we are processing is for the erased cursor, we
1865 take the intersection with the rectagle of the cursor. */
1866 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1868 XRectangle rc
, r_save
= r
;
1870 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1871 rc
.y
= s
->w
->phys_cursor
.y
;
1872 rc
.width
= s
->w
->phys_cursor_width
;
1873 rc
.height
= s
->w
->phys_cursor_height
;
1875 x_intersect_rectangles (&r_save
, &rc
, &r
);
1880 /* Don't use S->y for clipping because it doesn't take partially
1881 visible lines into account. For example, it can be negative for
1882 partially visible lines at the top of a window. */
1883 if (!s
->row
->full_width_p
1884 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1885 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1887 r
.y
= max (0, s
->row
->y
);
1889 /* If drawing a tool-bar window, draw it over the internal border
1890 at the top of the window. */
1891 if (WINDOWP (s
->f
->tool_bar_window
)
1892 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1893 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1896 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1898 /* If drawing the cursor, don't let glyph draw outside its
1899 advertised boundaries. Cleartype does this under some circumstances. */
1900 if (s
->hl
== DRAW_CURSOR
)
1902 struct glyph
*glyph
= s
->first_glyph
;
1907 r
.width
-= s
->x
- r
.x
;
1910 r
.width
= min (r
.width
, glyph
->pixel_width
);
1912 /* If r.y is below window bottom, ensure that we still see a cursor. */
1913 height
= min (glyph
->ascent
+ glyph
->descent
,
1914 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1915 max_y
= window_text_bottom_y (s
->w
) - height
;
1916 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1917 if (s
->ybase
- glyph
->ascent
> max_y
)
1924 /* Don't draw cursor glyph taller than our actual glyph. */
1925 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1926 if (height
< r
.height
)
1928 max_y
= r
.y
+ r
.height
;
1929 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1930 r
.height
= min (max_y
- r
.y
, height
);
1935 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1936 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1938 #ifdef CONVERT_FROM_XRECT
1939 CONVERT_FROM_XRECT (r
, *rects
);
1947 /* If we are processing overlapping and allowed to return
1948 multiple clipping rectangles, we exclude the row of the glyph
1949 string from the clipping rectangle. This is to avoid drawing
1950 the same text on the environment with anti-aliasing. */
1951 #ifdef CONVERT_FROM_XRECT
1954 XRectangle
*rs
= rects
;
1956 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
1958 if (s
->for_overlaps
& OVERLAPS_PRED
)
1961 if (r
.y
+ r
.height
> row_y
)
1964 rs
[i
].height
= row_y
- r
.y
;
1970 if (s
->for_overlaps
& OVERLAPS_SUCC
)
1973 if (r
.y
< row_y
+ s
->row
->visible_height
)
1975 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
1977 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
1978 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
1987 #ifdef CONVERT_FROM_XRECT
1988 for (i
= 0; i
< n
; i
++)
1989 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
1996 Return in *NR the clipping rectangle for glyph string S. */
1999 get_glyph_string_clip_rect (s
, nr
)
2000 struct glyph_string
*s
;
2001 NativeRectangle
*nr
;
2003 get_glyph_string_clip_rects (s
, nr
, 1);
2008 Return the position and height of the phys cursor in window W.
2009 Set w->phys_cursor_width to width of phys cursor.
2013 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2015 struct glyph_row
*row
;
2016 struct glyph
*glyph
;
2017 int *xp
, *yp
, *heightp
;
2019 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2020 int x
, y
, wd
, h
, h0
, y0
;
2022 /* Compute the width of the rectangle to draw. If on a stretch
2023 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2024 rectangle as wide as the glyph, but use a canonical character
2026 wd
= glyph
->pixel_width
- 1;
2031 x
= w
->phys_cursor
.x
;
2038 if (glyph
->type
== STRETCH_GLYPH
2039 && !x_stretch_cursor_p
)
2040 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2041 w
->phys_cursor_width
= wd
;
2043 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2045 /* If y is below window bottom, ensure that we still see a cursor. */
2046 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2048 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2049 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2051 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2054 h
= max (h
- (y0
- y
) + 1, h0
);
2059 y0
= window_text_bottom_y (w
) - h0
;
2067 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2068 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2073 * Remember which glyph the mouse is over.
2077 remember_mouse_glyph (f
, gx
, gy
, rect
)
2080 NativeRectangle
*rect
;
2084 struct glyph_row
*r
, *gr
, *end_row
;
2085 enum window_part part
;
2086 enum glyph_row_area area
;
2087 int x
, y
, width
, height
;
2089 /* Try to determine frame pixel position and size of the glyph under
2090 frame pixel coordinates X/Y on frame F. */
2092 window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0);
2095 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2096 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2100 w
= XWINDOW (window
);
2101 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2102 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2104 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2105 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2107 if (w
->pseudo_window_p
)
2110 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2116 case ON_LEFT_MARGIN
:
2117 area
= LEFT_MARGIN_AREA
;
2120 case ON_RIGHT_MARGIN
:
2121 area
= RIGHT_MARGIN_AREA
;
2124 case ON_HEADER_LINE
:
2126 gr
= (part
== ON_HEADER_LINE
2127 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2128 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2131 goto text_glyph_row_found
;
2138 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2139 if (r
->y
+ r
->height
> y
)
2145 text_glyph_row_found
:
2148 struct glyph
*g
= gr
->glyphs
[area
];
2149 struct glyph
*end
= g
+ gr
->used
[area
];
2151 height
= gr
->height
;
2152 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2153 if (gx
+ g
->pixel_width
> x
)
2158 if (g
->type
== IMAGE_GLYPH
)
2160 /* Don't remember when mouse is over image, as
2161 image may have hot-spots. */
2162 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2165 width
= g
->pixel_width
;
2169 /* Use nominal char spacing at end of line. */
2171 gx
+= (x
/ width
) * width
;
2174 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2175 gx
+= window_box_left_offset (w
, area
);
2179 /* Use nominal line height at end of window. */
2180 gx
= (x
/ width
) * width
;
2182 gy
+= (y
/ height
) * height
;
2186 case ON_LEFT_FRINGE
:
2187 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2188 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2189 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2190 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2193 case ON_RIGHT_FRINGE
:
2194 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2195 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2196 : window_box_right_offset (w
, TEXT_AREA
));
2197 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2201 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2203 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2204 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2205 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2207 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2211 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2212 if (r
->y
+ r
->height
> y
)
2219 height
= gr
->height
;
2222 /* Use nominal line height at end of window. */
2224 gy
+= (y
/ height
) * height
;
2231 /* If there is no glyph under the mouse, then we divide the screen
2232 into a grid of the smallest glyph in the frame, and use that
2235 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2236 round down even for negative values. */
2242 gx
= (gx
/ width
) * width
;
2243 gy
= (gy
/ height
) * height
;
2248 gx
+= WINDOW_LEFT_EDGE_X (w
);
2249 gy
+= WINDOW_TOP_EDGE_Y (w
);
2252 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2254 /* Visible feedback for debugging. */
2257 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2258 f
->output_data
.x
->normal_gc
,
2259 gx
, gy
, width
, height
);
2265 #endif /* HAVE_WINDOW_SYSTEM */
2268 /***********************************************************************
2269 Lisp form evaluation
2270 ***********************************************************************/
2272 /* Error handler for safe_eval and safe_call. */
2275 safe_eval_handler (arg
)
2278 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2283 /* Evaluate SEXPR and return the result, or nil if something went
2284 wrong. Prevent redisplay during the evaluation. */
2292 if (inhibit_eval_during_redisplay
)
2296 int count
= SPECPDL_INDEX ();
2297 struct gcpro gcpro1
;
2300 specbind (Qinhibit_redisplay
, Qt
);
2301 /* Use Qt to ensure debugger does not run,
2302 so there is no possibility of wanting to redisplay. */
2303 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
2306 val
= unbind_to (count
, val
);
2313 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2314 Return the result, or nil if something went wrong. Prevent
2315 redisplay during the evaluation. */
2318 safe_call (nargs
, args
)
2324 if (inhibit_eval_during_redisplay
)
2328 int count
= SPECPDL_INDEX ();
2329 struct gcpro gcpro1
;
2332 gcpro1
.nvars
= nargs
;
2333 specbind (Qinhibit_redisplay
, Qt
);
2334 /* Use Qt to ensure debugger does not run,
2335 so there is no possibility of wanting to redisplay. */
2336 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2339 val
= unbind_to (count
, val
);
2346 /* Call function FN with one argument ARG.
2347 Return the result, or nil if something went wrong. */
2350 safe_call1 (fn
, arg
)
2351 Lisp_Object fn
, arg
;
2353 Lisp_Object args
[2];
2356 return safe_call (2, args
);
2361 /***********************************************************************
2363 ***********************************************************************/
2367 /* Define CHECK_IT to perform sanity checks on iterators.
2368 This is for debugging. It is too slow to do unconditionally. */
2374 if (it
->method
== GET_FROM_STRING
)
2376 xassert (STRINGP (it
->string
));
2377 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2381 xassert (IT_STRING_CHARPOS (*it
) < 0);
2382 if (it
->method
== GET_FROM_BUFFER
)
2384 /* Check that character and byte positions agree. */
2385 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2390 xassert (it
->current
.dpvec_index
>= 0);
2392 xassert (it
->current
.dpvec_index
< 0);
2395 #define CHECK_IT(IT) check_it ((IT))
2399 #define CHECK_IT(IT) (void) 0
2406 /* Check that the window end of window W is what we expect it
2407 to be---the last row in the current matrix displaying text. */
2410 check_window_end (w
)
2413 if (!MINI_WINDOW_P (w
)
2414 && !NILP (w
->window_end_valid
))
2416 struct glyph_row
*row
;
2417 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2418 XFASTINT (w
->window_end_vpos
)),
2420 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2421 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2425 #define CHECK_WINDOW_END(W) check_window_end ((W))
2427 #else /* not GLYPH_DEBUG */
2429 #define CHECK_WINDOW_END(W) (void) 0
2431 #endif /* not GLYPH_DEBUG */
2435 /***********************************************************************
2436 Iterator initialization
2437 ***********************************************************************/
2439 /* Initialize IT for displaying current_buffer in window W, starting
2440 at character position CHARPOS. CHARPOS < 0 means that no buffer
2441 position is specified which is useful when the iterator is assigned
2442 a position later. BYTEPOS is the byte position corresponding to
2443 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2445 If ROW is not null, calls to produce_glyphs with IT as parameter
2446 will produce glyphs in that row.
2448 BASE_FACE_ID is the id of a base face to use. It must be one of
2449 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2450 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2451 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2453 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2454 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2455 will be initialized to use the corresponding mode line glyph row of
2456 the desired matrix of W. */
2459 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2462 int charpos
, bytepos
;
2463 struct glyph_row
*row
;
2464 enum face_id base_face_id
;
2466 int highlight_region_p
;
2468 /* Some precondition checks. */
2469 xassert (w
!= NULL
&& it
!= NULL
);
2470 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2473 /* If face attributes have been changed since the last redisplay,
2474 free realized faces now because they depend on face definitions
2475 that might have changed. Don't free faces while there might be
2476 desired matrices pending which reference these faces. */
2477 if (face_change_count
&& !inhibit_free_realized_faces
)
2479 face_change_count
= 0;
2480 free_all_realized_faces (Qnil
);
2483 /* Use one of the mode line rows of W's desired matrix if
2487 if (base_face_id
== MODE_LINE_FACE_ID
2488 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2489 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2490 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2491 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2495 bzero (it
, sizeof *it
);
2496 it
->current
.overlay_string_index
= -1;
2497 it
->current
.dpvec_index
= -1;
2498 it
->base_face_id
= base_face_id
;
2500 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2502 /* The window in which we iterate over current_buffer: */
2503 XSETWINDOW (it
->window
, w
);
2505 it
->f
= XFRAME (w
->frame
);
2507 /* Extra space between lines (on window systems only). */
2508 if (base_face_id
== DEFAULT_FACE_ID
2509 && FRAME_WINDOW_P (it
->f
))
2511 if (NATNUMP (current_buffer
->extra_line_spacing
))
2512 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2513 else if (FLOATP (current_buffer
->extra_line_spacing
))
2514 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2515 * FRAME_LINE_HEIGHT (it
->f
));
2516 else if (it
->f
->extra_line_spacing
> 0)
2517 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2518 it
->max_extra_line_spacing
= 0;
2521 /* If realized faces have been removed, e.g. because of face
2522 attribute changes of named faces, recompute them. When running
2523 in batch mode, the face cache of Vterminal_frame is null. If
2524 we happen to get called, make a dummy face cache. */
2525 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2526 init_frame_faces (it
->f
);
2527 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2528 recompute_basic_faces (it
->f
);
2530 /* Current value of the `slice', `space-width', and 'height' properties. */
2531 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2532 it
->space_width
= Qnil
;
2533 it
->font_height
= Qnil
;
2534 it
->override_ascent
= -1;
2536 /* Are control characters displayed as `^C'? */
2537 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2539 /* -1 means everything between a CR and the following line end
2540 is invisible. >0 means lines indented more than this value are
2542 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2543 ? XFASTINT (current_buffer
->selective_display
)
2544 : (!NILP (current_buffer
->selective_display
)
2546 it
->selective_display_ellipsis_p
2547 = !NILP (current_buffer
->selective_display_ellipses
);
2549 /* Display table to use. */
2550 it
->dp
= window_display_table (w
);
2552 /* Are multibyte characters enabled in current_buffer? */
2553 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2555 /* Non-zero if we should highlight the region. */
2557 = (!NILP (Vtransient_mark_mode
)
2558 && !NILP (current_buffer
->mark_active
)
2559 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2561 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2562 start and end of a visible region in window IT->w. Set both to
2563 -1 to indicate no region. */
2564 if (highlight_region_p
2565 /* Maybe highlight only in selected window. */
2566 && (/* Either show region everywhere. */
2567 highlight_nonselected_windows
2568 /* Or show region in the selected window. */
2569 || w
== XWINDOW (selected_window
)
2570 /* Or show the region if we are in the mini-buffer and W is
2571 the window the mini-buffer refers to. */
2572 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2573 && WINDOWP (minibuf_selected_window
)
2574 && w
== XWINDOW (minibuf_selected_window
))))
2576 int charpos
= marker_position (current_buffer
->mark
);
2577 it
->region_beg_charpos
= min (PT
, charpos
);
2578 it
->region_end_charpos
= max (PT
, charpos
);
2581 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2583 /* Get the position at which the redisplay_end_trigger hook should
2584 be run, if it is to be run at all. */
2585 if (MARKERP (w
->redisplay_end_trigger
)
2586 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2587 it
->redisplay_end_trigger_charpos
2588 = marker_position (w
->redisplay_end_trigger
);
2589 else if (INTEGERP (w
->redisplay_end_trigger
))
2590 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2592 /* Correct bogus values of tab_width. */
2593 it
->tab_width
= XINT (current_buffer
->tab_width
);
2594 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2597 /* Are lines in the display truncated? */
2598 it
->truncate_lines_p
2599 = (base_face_id
!= DEFAULT_FACE_ID
2600 || XINT (it
->w
->hscroll
)
2601 || (truncate_partial_width_windows
2602 && !WINDOW_FULL_WIDTH_P (it
->w
))
2603 || !NILP (current_buffer
->truncate_lines
));
2605 /* Get dimensions of truncation and continuation glyphs. These are
2606 displayed as fringe bitmaps under X, so we don't need them for such
2608 if (!FRAME_WINDOW_P (it
->f
))
2610 if (it
->truncate_lines_p
)
2612 /* We will need the truncation glyph. */
2613 xassert (it
->glyph_row
== NULL
);
2614 produce_special_glyphs (it
, IT_TRUNCATION
);
2615 it
->truncation_pixel_width
= it
->pixel_width
;
2619 /* We will need the continuation glyph. */
2620 xassert (it
->glyph_row
== NULL
);
2621 produce_special_glyphs (it
, IT_CONTINUATION
);
2622 it
->continuation_pixel_width
= it
->pixel_width
;
2625 /* Reset these values to zero because the produce_special_glyphs
2626 above has changed them. */
2627 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2628 it
->phys_ascent
= it
->phys_descent
= 0;
2631 /* Set this after getting the dimensions of truncation and
2632 continuation glyphs, so that we don't produce glyphs when calling
2633 produce_special_glyphs, above. */
2634 it
->glyph_row
= row
;
2635 it
->area
= TEXT_AREA
;
2637 /* Get the dimensions of the display area. The display area
2638 consists of the visible window area plus a horizontally scrolled
2639 part to the left of the window. All x-values are relative to the
2640 start of this total display area. */
2641 if (base_face_id
!= DEFAULT_FACE_ID
)
2643 /* Mode lines, menu bar in terminal frames. */
2644 it
->first_visible_x
= 0;
2645 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2650 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2651 it
->last_visible_x
= (it
->first_visible_x
2652 + window_box_width (w
, TEXT_AREA
));
2654 /* If we truncate lines, leave room for the truncator glyph(s) at
2655 the right margin. Otherwise, leave room for the continuation
2656 glyph(s). Truncation and continuation glyphs are not inserted
2657 for window-based redisplay. */
2658 if (!FRAME_WINDOW_P (it
->f
))
2660 if (it
->truncate_lines_p
)
2661 it
->last_visible_x
-= it
->truncation_pixel_width
;
2663 it
->last_visible_x
-= it
->continuation_pixel_width
;
2666 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2667 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2670 /* Leave room for a border glyph. */
2671 if (!FRAME_WINDOW_P (it
->f
)
2672 && !WINDOW_RIGHTMOST_P (it
->w
))
2673 it
->last_visible_x
-= 1;
2675 it
->last_visible_y
= window_text_bottom_y (w
);
2677 /* For mode lines and alike, arrange for the first glyph having a
2678 left box line if the face specifies a box. */
2679 if (base_face_id
!= DEFAULT_FACE_ID
)
2683 it
->face_id
= base_face_id
;
2685 /* If we have a boxed mode line, make the first character appear
2686 with a left box line. */
2687 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2688 if (face
->box
!= FACE_NO_BOX
)
2689 it
->start_of_box_run_p
= 1;
2692 /* If a buffer position was specified, set the iterator there,
2693 getting overlays and face properties from that position. */
2694 if (charpos
>= BUF_BEG (current_buffer
))
2696 it
->end_charpos
= ZV
;
2698 IT_CHARPOS (*it
) = charpos
;
2700 /* Compute byte position if not specified. */
2701 if (bytepos
< charpos
)
2702 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2704 IT_BYTEPOS (*it
) = bytepos
;
2706 it
->start
= it
->current
;
2708 /* Compute faces etc. */
2709 reseat (it
, it
->current
.pos
, 1);
2716 /* Initialize IT for the display of window W with window start POS. */
2719 start_display (it
, w
, pos
)
2722 struct text_pos pos
;
2724 struct glyph_row
*row
;
2725 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2727 row
= w
->desired_matrix
->rows
+ first_vpos
;
2728 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2729 it
->first_vpos
= first_vpos
;
2731 /* Don't reseat to previous visible line start if current start
2732 position is in a string or image. */
2733 if (it
->method
== GET_FROM_BUFFER
&& !it
->truncate_lines_p
)
2735 int start_at_line_beg_p
;
2736 int first_y
= it
->current_y
;
2738 /* If window start is not at a line start, skip forward to POS to
2739 get the correct continuation lines width. */
2740 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2741 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2742 if (!start_at_line_beg_p
)
2746 reseat_at_previous_visible_line_start (it
);
2747 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2749 new_x
= it
->current_x
+ it
->pixel_width
;
2751 /* If lines are continued, this line may end in the middle
2752 of a multi-glyph character (e.g. a control character
2753 displayed as \003, or in the middle of an overlay
2754 string). In this case move_it_to above will not have
2755 taken us to the start of the continuation line but to the
2756 end of the continued line. */
2757 if (it
->current_x
> 0
2758 && !it
->truncate_lines_p
/* Lines are continued. */
2759 && (/* And glyph doesn't fit on the line. */
2760 new_x
> it
->last_visible_x
2761 /* Or it fits exactly and we're on a window
2763 || (new_x
== it
->last_visible_x
2764 && FRAME_WINDOW_P (it
->f
))))
2766 if (it
->current
.dpvec_index
>= 0
2767 || it
->current
.overlay_string_index
>= 0)
2769 set_iterator_to_next (it
, 1);
2770 move_it_in_display_line_to (it
, -1, -1, 0);
2773 it
->continuation_lines_width
+= it
->current_x
;
2776 /* We're starting a new display line, not affected by the
2777 height of the continued line, so clear the appropriate
2778 fields in the iterator structure. */
2779 it
->max_ascent
= it
->max_descent
= 0;
2780 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2782 it
->current_y
= first_y
;
2784 it
->current_x
= it
->hpos
= 0;
2788 #if 0 /* Don't assert the following because start_display is sometimes
2789 called intentionally with a window start that is not at a
2790 line start. Please leave this code in as a comment. */
2792 /* Window start should be on a line start, now. */
2793 xassert (it
->continuation_lines_width
2794 || IT_CHARPOS (it
) == BEGV
2795 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2800 /* Return 1 if POS is a position in ellipses displayed for invisible
2801 text. W is the window we display, for text property lookup. */
2804 in_ellipses_for_invisible_text_p (pos
, w
)
2805 struct display_pos
*pos
;
2808 Lisp_Object prop
, window
;
2810 int charpos
= CHARPOS (pos
->pos
);
2812 /* If POS specifies a position in a display vector, this might
2813 be for an ellipsis displayed for invisible text. We won't
2814 get the iterator set up for delivering that ellipsis unless
2815 we make sure that it gets aware of the invisible text. */
2816 if (pos
->dpvec_index
>= 0
2817 && pos
->overlay_string_index
< 0
2818 && CHARPOS (pos
->string_pos
) < 0
2820 && (XSETWINDOW (window
, w
),
2821 prop
= Fget_char_property (make_number (charpos
),
2822 Qinvisible
, window
),
2823 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2825 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2827 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2834 /* Initialize IT for stepping through current_buffer in window W,
2835 starting at position POS that includes overlay string and display
2836 vector/ control character translation position information. Value
2837 is zero if there are overlay strings with newlines at POS. */
2840 init_from_display_pos (it
, w
, pos
)
2843 struct display_pos
*pos
;
2845 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2846 int i
, overlay_strings_with_newlines
= 0;
2848 /* If POS specifies a position in a display vector, this might
2849 be for an ellipsis displayed for invisible text. We won't
2850 get the iterator set up for delivering that ellipsis unless
2851 we make sure that it gets aware of the invisible text. */
2852 if (in_ellipses_for_invisible_text_p (pos
, w
))
2858 /* Keep in mind: the call to reseat in init_iterator skips invisible
2859 text, so we might end up at a position different from POS. This
2860 is only a problem when POS is a row start after a newline and an
2861 overlay starts there with an after-string, and the overlay has an
2862 invisible property. Since we don't skip invisible text in
2863 display_line and elsewhere immediately after consuming the
2864 newline before the row start, such a POS will not be in a string,
2865 but the call to init_iterator below will move us to the
2867 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2869 /* This only scans the current chunk -- it should scan all chunks.
2870 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2871 to 16 in 22.1 to make this a lesser problem. */
2872 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2874 const char *s
= SDATA (it
->overlay_strings
[i
]);
2875 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2877 while (s
< e
&& *s
!= '\n')
2882 overlay_strings_with_newlines
= 1;
2887 /* If position is within an overlay string, set up IT to the right
2889 if (pos
->overlay_string_index
>= 0)
2893 /* If the first overlay string happens to have a `display'
2894 property for an image, the iterator will be set up for that
2895 image, and we have to undo that setup first before we can
2896 correct the overlay string index. */
2897 if (it
->method
== GET_FROM_IMAGE
)
2900 /* We already have the first chunk of overlay strings in
2901 IT->overlay_strings. Load more until the one for
2902 pos->overlay_string_index is in IT->overlay_strings. */
2903 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2905 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2906 it
->current
.overlay_string_index
= 0;
2909 load_overlay_strings (it
, 0);
2910 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2914 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2915 relative_index
= (it
->current
.overlay_string_index
2916 % OVERLAY_STRING_CHUNK_SIZE
);
2917 it
->string
= it
->overlay_strings
[relative_index
];
2918 xassert (STRINGP (it
->string
));
2919 it
->current
.string_pos
= pos
->string_pos
;
2920 it
->method
= GET_FROM_STRING
;
2923 #if 0 /* This is bogus because POS not having an overlay string
2924 position does not mean it's after the string. Example: A
2925 line starting with a before-string and initialization of IT
2926 to the previous row's end position. */
2927 else if (it
->current
.overlay_string_index
>= 0)
2929 /* If POS says we're already after an overlay string ending at
2930 POS, make sure to pop the iterator because it will be in
2931 front of that overlay string. When POS is ZV, we've thereby
2932 also ``processed'' overlay strings at ZV. */
2935 xassert (it
->current
.overlay_string_index
== -1);
2936 xassert (it
->method
== GET_FROM_BUFFER
);
2937 if (CHARPOS (pos
->pos
) == ZV
)
2938 it
->overlay_strings_at_end_processed_p
= 1;
2942 if (CHARPOS (pos
->string_pos
) >= 0)
2944 /* Recorded position is not in an overlay string, but in another
2945 string. This can only be a string from a `display' property.
2946 IT should already be filled with that string. */
2947 it
->current
.string_pos
= pos
->string_pos
;
2948 xassert (STRINGP (it
->string
));
2951 /* Restore position in display vector translations, control
2952 character translations or ellipses. */
2953 if (pos
->dpvec_index
>= 0)
2955 if (it
->dpvec
== NULL
)
2956 get_next_display_element (it
);
2957 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2958 it
->current
.dpvec_index
= pos
->dpvec_index
;
2962 return !overlay_strings_with_newlines
;
2966 /* Initialize IT for stepping through current_buffer in window W
2967 starting at ROW->start. */
2970 init_to_row_start (it
, w
, row
)
2973 struct glyph_row
*row
;
2975 init_from_display_pos (it
, w
, &row
->start
);
2976 it
->start
= row
->start
;
2977 it
->continuation_lines_width
= row
->continuation_lines_width
;
2982 /* Initialize IT for stepping through current_buffer in window W
2983 starting in the line following ROW, i.e. starting at ROW->end.
2984 Value is zero if there are overlay strings with newlines at ROW's
2988 init_to_row_end (it
, w
, row
)
2991 struct glyph_row
*row
;
2995 if (init_from_display_pos (it
, w
, &row
->end
))
2997 if (row
->continued_p
)
2998 it
->continuation_lines_width
2999 = row
->continuation_lines_width
+ row
->pixel_width
;
3010 /***********************************************************************
3012 ***********************************************************************/
3014 /* Called when IT reaches IT->stop_charpos. Handle text property and
3015 overlay changes. Set IT->stop_charpos to the next position where
3022 enum prop_handled handled
;
3023 int handle_overlay_change_p
;
3027 it
->current
.dpvec_index
= -1;
3028 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3029 it
->ignore_overlay_strings_at_pos_p
= 0;
3031 /* Use face of preceding text for ellipsis (if invisible) */
3032 if (it
->selective_display_ellipsis_p
)
3033 it
->saved_face_id
= it
->face_id
;
3037 handled
= HANDLED_NORMALLY
;
3039 /* Call text property handlers. */
3040 for (p
= it_props
; p
->handler
; ++p
)
3042 handled
= p
->handler (it
);
3044 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3046 else if (handled
== HANDLED_RETURN
)
3048 /* We still want to show before and after strings from
3049 overlays even if the actual buffer text is replaced. */
3050 if (!handle_overlay_change_p
|| it
->sp
> 1)
3052 if (!get_overlay_strings_1 (it
, 0, 0))
3054 it
->ignore_overlay_strings_at_pos_p
= 1;
3055 it
->string_from_display_prop_p
= 0;
3056 handle_overlay_change_p
= 0;
3057 handled
= HANDLED_RECOMPUTE_PROPS
;
3060 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3061 handle_overlay_change_p
= 0;
3064 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3066 /* Don't check for overlay strings below when set to deliver
3067 characters from a display vector. */
3068 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3069 handle_overlay_change_p
= 0;
3071 /* Handle overlay changes. */
3072 if (handle_overlay_change_p
)
3073 handled
= handle_overlay_change (it
);
3075 /* Determine where to stop next. */
3076 if (handled
== HANDLED_NORMALLY
)
3077 compute_stop_pos (it
);
3080 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3084 /* Compute IT->stop_charpos from text property and overlay change
3085 information for IT's current position. */
3088 compute_stop_pos (it
)
3091 register INTERVAL iv
, next_iv
;
3092 Lisp_Object object
, limit
, position
;
3094 /* If nowhere else, stop at the end. */
3095 it
->stop_charpos
= it
->end_charpos
;
3097 if (STRINGP (it
->string
))
3099 /* Strings are usually short, so don't limit the search for
3101 object
= it
->string
;
3103 position
= make_number (IT_STRING_CHARPOS (*it
));
3109 /* If next overlay change is in front of the current stop pos
3110 (which is IT->end_charpos), stop there. Note: value of
3111 next_overlay_change is point-max if no overlay change
3113 charpos
= next_overlay_change (IT_CHARPOS (*it
));
3114 if (charpos
< it
->stop_charpos
)
3115 it
->stop_charpos
= charpos
;
3117 /* If showing the region, we have to stop at the region
3118 start or end because the face might change there. */
3119 if (it
->region_beg_charpos
> 0)
3121 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3122 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3123 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3124 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3127 /* Set up variables for computing the stop position from text
3128 property changes. */
3129 XSETBUFFER (object
, current_buffer
);
3130 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3131 position
= make_number (IT_CHARPOS (*it
));
3135 /* Get the interval containing IT's position. Value is a null
3136 interval if there isn't such an interval. */
3137 iv
= validate_interval_range (object
, &position
, &position
, 0);
3138 if (!NULL_INTERVAL_P (iv
))
3140 Lisp_Object values_here
[LAST_PROP_IDX
];
3143 /* Get properties here. */
3144 for (p
= it_props
; p
->handler
; ++p
)
3145 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3147 /* Look for an interval following iv that has different
3149 for (next_iv
= next_interval (iv
);
3150 (!NULL_INTERVAL_P (next_iv
)
3152 || XFASTINT (limit
) > next_iv
->position
));
3153 next_iv
= next_interval (next_iv
))
3155 for (p
= it_props
; p
->handler
; ++p
)
3157 Lisp_Object new_value
;
3159 new_value
= textget (next_iv
->plist
, *p
->name
);
3160 if (!EQ (values_here
[p
->idx
], new_value
))
3168 if (!NULL_INTERVAL_P (next_iv
))
3170 if (INTEGERP (limit
)
3171 && next_iv
->position
>= XFASTINT (limit
))
3172 /* No text property change up to limit. */
3173 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3175 /* Text properties change in next_iv. */
3176 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3180 xassert (STRINGP (it
->string
)
3181 || (it
->stop_charpos
>= BEGV
3182 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3186 /* Return the position of the next overlay change after POS in
3187 current_buffer. Value is point-max if no overlay change
3188 follows. This is like `next-overlay-change' but doesn't use
3192 next_overlay_change (pos
)
3197 Lisp_Object
*overlays
;
3200 /* Get all overlays at the given position. */
3201 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3203 /* If any of these overlays ends before endpos,
3204 use its ending point instead. */
3205 for (i
= 0; i
< noverlays
; ++i
)
3210 oend
= OVERLAY_END (overlays
[i
]);
3211 oendpos
= OVERLAY_POSITION (oend
);
3212 endpos
= min (endpos
, oendpos
);
3220 /***********************************************************************
3222 ***********************************************************************/
3224 /* Handle changes in the `fontified' property of the current buffer by
3225 calling hook functions from Qfontification_functions to fontify
3228 static enum prop_handled
3229 handle_fontified_prop (it
)
3232 Lisp_Object prop
, pos
;
3233 enum prop_handled handled
= HANDLED_NORMALLY
;
3235 if (!NILP (Vmemory_full
))
3238 /* Get the value of the `fontified' property at IT's current buffer
3239 position. (The `fontified' property doesn't have a special
3240 meaning in strings.) If the value is nil, call functions from
3241 Qfontification_functions. */
3242 if (!STRINGP (it
->string
)
3244 && !NILP (Vfontification_functions
)
3245 && !NILP (Vrun_hooks
)
3246 && (pos
= make_number (IT_CHARPOS (*it
)),
3247 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3250 int count
= SPECPDL_INDEX ();
3253 val
= Vfontification_functions
;
3254 specbind (Qfontification_functions
, Qnil
);
3256 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3257 safe_call1 (val
, pos
);
3260 Lisp_Object globals
, fn
;
3261 struct gcpro gcpro1
, gcpro2
;
3264 GCPRO2 (val
, globals
);
3266 for (; CONSP (val
); val
= XCDR (val
))
3272 /* A value of t indicates this hook has a local
3273 binding; it means to run the global binding too.
3274 In a global value, t should not occur. If it
3275 does, we must ignore it to avoid an endless
3277 for (globals
= Fdefault_value (Qfontification_functions
);
3279 globals
= XCDR (globals
))
3281 fn
= XCAR (globals
);
3283 safe_call1 (fn
, pos
);
3287 safe_call1 (fn
, pos
);
3293 unbind_to (count
, Qnil
);
3295 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3296 something. This avoids an endless loop if they failed to
3297 fontify the text for which reason ever. */
3298 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3299 handled
= HANDLED_RECOMPUTE_PROPS
;
3307 /***********************************************************************
3309 ***********************************************************************/
3311 /* Set up iterator IT from face properties at its current position.
3312 Called from handle_stop. */
3314 static enum prop_handled
3315 handle_face_prop (it
)
3318 int new_face_id
, next_stop
;
3320 if (!STRINGP (it
->string
))
3323 = face_at_buffer_position (it
->w
,
3325 it
->region_beg_charpos
,
3326 it
->region_end_charpos
,
3329 + TEXT_PROP_DISTANCE_LIMIT
),
3332 /* Is this a start of a run of characters with box face?
3333 Caveat: this can be called for a freshly initialized
3334 iterator; face_id is -1 in this case. We know that the new
3335 face will not change until limit, i.e. if the new face has a
3336 box, all characters up to limit will have one. But, as
3337 usual, we don't know whether limit is really the end. */
3338 if (new_face_id
!= it
->face_id
)
3340 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3342 /* If new face has a box but old face has not, this is
3343 the start of a run of characters with box, i.e. it has
3344 a shadow on the left side. The value of face_id of the
3345 iterator will be -1 if this is the initial call that gets
3346 the face. In this case, we have to look in front of IT's
3347 position and see whether there is a face != new_face_id. */
3348 it
->start_of_box_run_p
3349 = (new_face
->box
!= FACE_NO_BOX
3350 && (it
->face_id
>= 0
3351 || IT_CHARPOS (*it
) == BEG
3352 || new_face_id
!= face_before_it_pos (it
)));
3353 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3358 int base_face_id
, bufpos
;
3360 if (it
->current
.overlay_string_index
>= 0)
3361 bufpos
= IT_CHARPOS (*it
);
3365 /* For strings from a buffer, i.e. overlay strings or strings
3366 from a `display' property, use the face at IT's current
3367 buffer position as the base face to merge with, so that
3368 overlay strings appear in the same face as surrounding
3369 text, unless they specify their own faces. */
3370 base_face_id
= underlying_face_id (it
);
3372 new_face_id
= face_at_string_position (it
->w
,
3374 IT_STRING_CHARPOS (*it
),
3376 it
->region_beg_charpos
,
3377 it
->region_end_charpos
,
3381 #if 0 /* This shouldn't be neccessary. Let's check it. */
3382 /* If IT is used to display a mode line we would really like to
3383 use the mode line face instead of the frame's default face. */
3384 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3385 && new_face_id
== DEFAULT_FACE_ID
)
3386 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3389 /* Is this a start of a run of characters with box? Caveat:
3390 this can be called for a freshly allocated iterator; face_id
3391 is -1 is this case. We know that the new face will not
3392 change until the next check pos, i.e. if the new face has a
3393 box, all characters up to that position will have a
3394 box. But, as usual, we don't know whether that position
3395 is really the end. */
3396 if (new_face_id
!= it
->face_id
)
3398 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3399 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3401 /* If new face has a box but old face hasn't, this is the
3402 start of a run of characters with box, i.e. it has a
3403 shadow on the left side. */
3404 it
->start_of_box_run_p
3405 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3406 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3410 it
->face_id
= new_face_id
;
3411 return HANDLED_NORMALLY
;
3415 /* Return the ID of the face ``underlying'' IT's current position,
3416 which is in a string. If the iterator is associated with a
3417 buffer, return the face at IT's current buffer position.
3418 Otherwise, use the iterator's base_face_id. */
3421 underlying_face_id (it
)
3424 int face_id
= it
->base_face_id
, i
;
3426 xassert (STRINGP (it
->string
));
3428 for (i
= it
->sp
- 1; i
>= 0; --i
)
3429 if (NILP (it
->stack
[i
].string
))
3430 face_id
= it
->stack
[i
].face_id
;
3436 /* Compute the face one character before or after the current position
3437 of IT. BEFORE_P non-zero means get the face in front of IT's
3438 position. Value is the id of the face. */
3441 face_before_or_after_it_pos (it
, before_p
)
3446 int next_check_charpos
;
3447 struct text_pos pos
;
3449 xassert (it
->s
== NULL
);
3451 if (STRINGP (it
->string
))
3453 int bufpos
, base_face_id
;
3455 /* No face change past the end of the string (for the case
3456 we are padding with spaces). No face change before the
3458 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3459 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3462 /* Set pos to the position before or after IT's current position. */
3464 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3466 /* For composition, we must check the character after the
3468 pos
= (it
->what
== IT_COMPOSITION
3469 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3470 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3472 if (it
->current
.overlay_string_index
>= 0)
3473 bufpos
= IT_CHARPOS (*it
);
3477 base_face_id
= underlying_face_id (it
);
3479 /* Get the face for ASCII, or unibyte. */
3480 face_id
= face_at_string_position (it
->w
,
3484 it
->region_beg_charpos
,
3485 it
->region_end_charpos
,
3486 &next_check_charpos
,
3489 /* Correct the face for charsets different from ASCII. Do it
3490 for the multibyte case only. The face returned above is
3491 suitable for unibyte text if IT->string is unibyte. */
3492 if (STRING_MULTIBYTE (it
->string
))
3494 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3495 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3497 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3499 c
= string_char_and_length (p
, rest
, &len
);
3500 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3505 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3506 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3509 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3510 pos
= it
->current
.pos
;
3513 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3516 if (it
->what
== IT_COMPOSITION
)
3517 /* For composition, we must check the position after the
3519 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3521 INC_TEXT_POS (pos
, it
->multibyte_p
);
3524 /* Determine face for CHARSET_ASCII, or unibyte. */
3525 face_id
= face_at_buffer_position (it
->w
,
3527 it
->region_beg_charpos
,
3528 it
->region_end_charpos
,
3529 &next_check_charpos
,
3532 /* Correct the face for charsets different from ASCII. Do it
3533 for the multibyte case only. The face returned above is
3534 suitable for unibyte text if current_buffer is unibyte. */
3535 if (it
->multibyte_p
)
3537 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3538 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3539 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3548 /***********************************************************************
3550 ***********************************************************************/
3552 /* Set up iterator IT from invisible properties at its current
3553 position. Called from handle_stop. */
3555 static enum prop_handled
3556 handle_invisible_prop (it
)
3559 enum prop_handled handled
= HANDLED_NORMALLY
;
3561 if (STRINGP (it
->string
))
3563 extern Lisp_Object Qinvisible
;
3564 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3566 /* Get the value of the invisible text property at the
3567 current position. Value will be nil if there is no such
3569 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3570 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3573 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3575 handled
= HANDLED_RECOMPUTE_PROPS
;
3577 /* Get the position at which the next change of the
3578 invisible text property can be found in IT->string.
3579 Value will be nil if the property value is the same for
3580 all the rest of IT->string. */
3581 XSETINT (limit
, SCHARS (it
->string
));
3582 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3585 /* Text at current position is invisible. The next
3586 change in the property is at position end_charpos.
3587 Move IT's current position to that position. */
3588 if (INTEGERP (end_charpos
)
3589 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3591 struct text_pos old
;
3592 old
= it
->current
.string_pos
;
3593 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3594 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3598 /* The rest of the string is invisible. If this is an
3599 overlay string, proceed with the next overlay string
3600 or whatever comes and return a character from there. */
3601 if (it
->current
.overlay_string_index
>= 0)
3603 next_overlay_string (it
);
3604 /* Don't check for overlay strings when we just
3605 finished processing them. */
3606 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3610 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3611 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3618 int invis_p
, newpos
, next_stop
, start_charpos
;
3619 Lisp_Object pos
, prop
, overlay
;
3621 /* First of all, is there invisible text at this position? */
3622 start_charpos
= IT_CHARPOS (*it
);
3623 pos
= make_number (IT_CHARPOS (*it
));
3624 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3626 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3628 /* If we are on invisible text, skip over it. */
3629 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3631 /* Record whether we have to display an ellipsis for the
3633 int display_ellipsis_p
= invis_p
== 2;
3635 handled
= HANDLED_RECOMPUTE_PROPS
;
3637 /* Loop skipping over invisible text. The loop is left at
3638 ZV or with IT on the first char being visible again. */
3641 /* Try to skip some invisible text. Return value is the
3642 position reached which can be equal to IT's position
3643 if there is nothing invisible here. This skips both
3644 over invisible text properties and overlays with
3645 invisible property. */
3646 newpos
= skip_invisible (IT_CHARPOS (*it
),
3647 &next_stop
, ZV
, it
->window
);
3649 /* If we skipped nothing at all we weren't at invisible
3650 text in the first place. If everything to the end of
3651 the buffer was skipped, end the loop. */
3652 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3656 /* We skipped some characters but not necessarily
3657 all there are. Check if we ended up on visible
3658 text. Fget_char_property returns the property of
3659 the char before the given position, i.e. if we
3660 get invis_p = 0, this means that the char at
3661 newpos is visible. */
3662 pos
= make_number (newpos
);
3663 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3664 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3667 /* If we ended up on invisible text, proceed to
3668 skip starting with next_stop. */
3670 IT_CHARPOS (*it
) = next_stop
;
3672 /* If there are adjacent invisible texts, don't lose the
3673 second one's ellipsis. */
3675 display_ellipsis_p
= 1;
3679 /* The position newpos is now either ZV or on visible text. */
3680 IT_CHARPOS (*it
) = newpos
;
3681 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3683 /* If there are before-strings at the start of invisible
3684 text, and the text is invisible because of a text
3685 property, arrange to show before-strings because 20.x did
3686 it that way. (If the text is invisible because of an
3687 overlay property instead of a text property, this is
3688 already handled in the overlay code.) */
3690 && get_overlay_strings (it
, start_charpos
))
3692 handled
= HANDLED_RECOMPUTE_PROPS
;
3693 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3695 else if (display_ellipsis_p
)
3697 /* Make sure that the glyphs of the ellipsis will get
3698 correct `charpos' values. If we would not update
3699 it->position here, the glyphs would belong to the
3700 last visible character _before_ the invisible
3701 text, which confuses `set_cursor_from_row'.
3703 We use the last invisible position instead of the
3704 first because this way the cursor is always drawn on
3705 the first "." of the ellipsis, whenever PT is inside
3706 the invisible text. Otherwise the cursor would be
3707 placed _after_ the ellipsis when the point is after the
3708 first invisible character. */
3709 if (!STRINGP (it
->object
))
3711 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3712 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3714 setup_for_ellipsis (it
, 0);
3723 /* Make iterator IT return `...' next.
3724 Replaces LEN characters from buffer. */
3727 setup_for_ellipsis (it
, len
)
3731 /* Use the display table definition for `...'. Invalid glyphs
3732 will be handled by the method returning elements from dpvec. */
3733 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3735 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3736 it
->dpvec
= v
->contents
;
3737 it
->dpend
= v
->contents
+ v
->size
;
3741 /* Default `...'. */
3742 it
->dpvec
= default_invis_vector
;
3743 it
->dpend
= default_invis_vector
+ 3;
3746 it
->dpvec_char_len
= len
;
3747 it
->current
.dpvec_index
= 0;
3748 it
->dpvec_face_id
= -1;
3750 /* Remember the current face id in case glyphs specify faces.
3751 IT's face is restored in set_iterator_to_next.
3752 saved_face_id was set to preceding char's face in handle_stop. */
3753 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3754 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3756 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3762 /***********************************************************************
3764 ***********************************************************************/
3766 /* Set up iterator IT from `display' property at its current position.
3767 Called from handle_stop.
3768 We return HANDLED_RETURN if some part of the display property
3769 overrides the display of the buffer text itself.
3770 Otherwise we return HANDLED_NORMALLY. */
3772 static enum prop_handled
3773 handle_display_prop (it
)
3776 Lisp_Object prop
, object
;
3777 struct text_pos
*position
;
3778 /* Nonzero if some property replaces the display of the text itself. */
3779 int display_replaced_p
= 0;
3781 if (STRINGP (it
->string
))
3783 object
= it
->string
;
3784 position
= &it
->current
.string_pos
;
3788 XSETWINDOW (object
, it
->w
);
3789 position
= &it
->current
.pos
;
3792 /* Reset those iterator values set from display property values. */
3793 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3794 it
->space_width
= Qnil
;
3795 it
->font_height
= Qnil
;
3798 /* We don't support recursive `display' properties, i.e. string
3799 values that have a string `display' property, that have a string
3800 `display' property etc. */
3801 if (!it
->string_from_display_prop_p
)
3802 it
->area
= TEXT_AREA
;
3804 prop
= Fget_char_property (make_number (position
->charpos
),
3807 return HANDLED_NORMALLY
;
3809 if (!STRINGP (it
->string
))
3810 object
= it
->w
->buffer
;
3813 /* Simple properties. */
3814 && !EQ (XCAR (prop
), Qimage
)
3815 && !EQ (XCAR (prop
), Qspace
)
3816 && !EQ (XCAR (prop
), Qwhen
)
3817 && !EQ (XCAR (prop
), Qslice
)
3818 && !EQ (XCAR (prop
), Qspace_width
)
3819 && !EQ (XCAR (prop
), Qheight
)
3820 && !EQ (XCAR (prop
), Qraise
)
3821 /* Marginal area specifications. */
3822 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3823 && !EQ (XCAR (prop
), Qleft_fringe
)
3824 && !EQ (XCAR (prop
), Qright_fringe
)
3825 && !NILP (XCAR (prop
)))
3827 for (; CONSP (prop
); prop
= XCDR (prop
))
3829 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3830 position
, display_replaced_p
))
3831 display_replaced_p
= 1;
3834 else if (VECTORP (prop
))
3837 for (i
= 0; i
< ASIZE (prop
); ++i
)
3838 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3839 position
, display_replaced_p
))
3840 display_replaced_p
= 1;
3844 int ret
= handle_single_display_spec (it
, prop
, object
, position
, 0);
3845 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3846 return HANDLED_RECOMPUTE_PROPS
;
3848 display_replaced_p
= 1;
3851 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3855 /* Value is the position of the end of the `display' property starting
3856 at START_POS in OBJECT. */
3858 static struct text_pos
3859 display_prop_end (it
, object
, start_pos
)
3862 struct text_pos start_pos
;
3865 struct text_pos end_pos
;
3867 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3868 Qdisplay
, object
, Qnil
);
3869 CHARPOS (end_pos
) = XFASTINT (end
);
3870 if (STRINGP (object
))
3871 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3873 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3879 /* Set up IT from a single `display' specification PROP. OBJECT
3880 is the object in which the `display' property was found. *POSITION
3881 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3882 means that we previously saw a display specification which already
3883 replaced text display with something else, for example an image;
3884 we ignore such properties after the first one has been processed.
3886 If PROP is a `space' or `image' specification, and in some other
3887 cases too, set *POSITION to the position where the `display'
3890 Value is non-zero if something was found which replaces the display
3891 of buffer or string text. Specifically, the value is -1 if that
3892 "something" is "nothing". */
3895 handle_single_display_spec (it
, spec
, object
, position
,
3896 display_replaced_before_p
)
3900 struct text_pos
*position
;
3901 int display_replaced_before_p
;
3904 Lisp_Object location
, value
;
3905 struct text_pos start_pos
, save_pos
;
3908 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3909 If the result is non-nil, use VALUE instead of SPEC. */
3911 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3920 if (!NILP (form
) && !EQ (form
, Qt
))
3922 int count
= SPECPDL_INDEX ();
3923 struct gcpro gcpro1
;
3925 /* Bind `object' to the object having the `display' property, a
3926 buffer or string. Bind `position' to the position in the
3927 object where the property was found, and `buffer-position'
3928 to the current position in the buffer. */
3929 specbind (Qobject
, object
);
3930 specbind (Qposition
, make_number (CHARPOS (*position
)));
3931 specbind (Qbuffer_position
,
3932 make_number (STRINGP (object
)
3933 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3935 form
= safe_eval (form
);
3937 unbind_to (count
, Qnil
);
3943 /* Handle `(height HEIGHT)' specifications. */
3945 && EQ (XCAR (spec
), Qheight
)
3946 && CONSP (XCDR (spec
)))
3948 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3951 it
->font_height
= XCAR (XCDR (spec
));
3952 if (!NILP (it
->font_height
))
3954 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3955 int new_height
= -1;
3957 if (CONSP (it
->font_height
)
3958 && (EQ (XCAR (it
->font_height
), Qplus
)
3959 || EQ (XCAR (it
->font_height
), Qminus
))
3960 && CONSP (XCDR (it
->font_height
))
3961 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3963 /* `(+ N)' or `(- N)' where N is an integer. */
3964 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3965 if (EQ (XCAR (it
->font_height
), Qplus
))
3967 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3969 else if (FUNCTIONP (it
->font_height
))
3971 /* Call function with current height as argument.
3972 Value is the new height. */
3974 height
= safe_call1 (it
->font_height
,
3975 face
->lface
[LFACE_HEIGHT_INDEX
]);
3976 if (NUMBERP (height
))
3977 new_height
= XFLOATINT (height
);
3979 else if (NUMBERP (it
->font_height
))
3981 /* Value is a multiple of the canonical char height. */
3984 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3985 new_height
= (XFLOATINT (it
->font_height
)
3986 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3990 /* Evaluate IT->font_height with `height' bound to the
3991 current specified height to get the new height. */
3992 int count
= SPECPDL_INDEX ();
3994 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3995 value
= safe_eval (it
->font_height
);
3996 unbind_to (count
, Qnil
);
3998 if (NUMBERP (value
))
3999 new_height
= XFLOATINT (value
);
4003 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4009 /* Handle `(space_width WIDTH)'. */
4011 && EQ (XCAR (spec
), Qspace_width
)
4012 && CONSP (XCDR (spec
)))
4014 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4017 value
= XCAR (XCDR (spec
));
4018 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4019 it
->space_width
= value
;
4024 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4026 && EQ (XCAR (spec
), Qslice
))
4030 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4033 if (tem
= XCDR (spec
), CONSP (tem
))
4035 it
->slice
.x
= XCAR (tem
);
4036 if (tem
= XCDR (tem
), CONSP (tem
))
4038 it
->slice
.y
= XCAR (tem
);
4039 if (tem
= XCDR (tem
), CONSP (tem
))
4041 it
->slice
.width
= XCAR (tem
);
4042 if (tem
= XCDR (tem
), CONSP (tem
))
4043 it
->slice
.height
= XCAR (tem
);
4051 /* Handle `(raise FACTOR)'. */
4053 && EQ (XCAR (spec
), Qraise
)
4054 && CONSP (XCDR (spec
)))
4056 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4059 #ifdef HAVE_WINDOW_SYSTEM
4060 value
= XCAR (XCDR (spec
));
4061 if (NUMBERP (value
))
4063 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4064 it
->voffset
= - (XFLOATINT (value
)
4065 * (FONT_HEIGHT (face
->font
)));
4067 #endif /* HAVE_WINDOW_SYSTEM */
4072 /* Don't handle the other kinds of display specifications
4073 inside a string that we got from a `display' property. */
4074 if (it
->string_from_display_prop_p
)
4077 /* Characters having this form of property are not displayed, so
4078 we have to find the end of the property. */
4079 start_pos
= *position
;
4080 *position
= display_prop_end (it
, object
, start_pos
);
4083 /* Stop the scan at that end position--we assume that all
4084 text properties change there. */
4085 it
->stop_charpos
= position
->charpos
;
4087 /* Handle `(left-fringe BITMAP [FACE])'
4088 and `(right-fringe BITMAP [FACE])'. */
4090 && (EQ (XCAR (spec
), Qleft_fringe
)
4091 || EQ (XCAR (spec
), Qright_fringe
))
4092 && CONSP (XCDR (spec
)))
4094 int face_id
= DEFAULT_FACE_ID
;
4097 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4098 /* If we return here, POSITION has been advanced
4099 across the text with this property. */
4102 #ifdef HAVE_WINDOW_SYSTEM
4103 value
= XCAR (XCDR (spec
));
4104 if (!SYMBOLP (value
)
4105 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4106 /* If we return here, POSITION has been advanced
4107 across the text with this property. */
4110 if (CONSP (XCDR (XCDR (spec
))))
4112 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4113 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4114 'A', FRINGE_FACE_ID
, 0);
4119 /* Save current settings of IT so that we can restore them
4120 when we are finished with the glyph property value. */
4122 save_pos
= it
->position
;
4123 it
->position
= *position
;
4125 it
->position
= save_pos
;
4127 it
->area
= TEXT_AREA
;
4128 it
->what
= IT_IMAGE
;
4129 it
->image_id
= -1; /* no image */
4130 it
->position
= start_pos
;
4131 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4132 it
->method
= GET_FROM_IMAGE
;
4133 it
->face_id
= face_id
;
4135 /* Say that we haven't consumed the characters with
4136 `display' property yet. The call to pop_it in
4137 set_iterator_to_next will clean this up. */
4138 *position
= start_pos
;
4140 if (EQ (XCAR (spec
), Qleft_fringe
))
4142 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4143 it
->left_user_fringe_face_id
= face_id
;
4147 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4148 it
->right_user_fringe_face_id
= face_id
;
4150 #endif /* HAVE_WINDOW_SYSTEM */
4154 /* Prepare to handle `((margin left-margin) ...)',
4155 `((margin right-margin) ...)' and `((margin nil) ...)'
4156 prefixes for display specifications. */
4157 location
= Qunbound
;
4158 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4162 value
= XCDR (spec
);
4164 value
= XCAR (value
);
4167 if (EQ (XCAR (tem
), Qmargin
)
4168 && (tem
= XCDR (tem
),
4169 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4171 || EQ (tem
, Qleft_margin
)
4172 || EQ (tem
, Qright_margin
))))
4176 if (EQ (location
, Qunbound
))
4182 /* After this point, VALUE is the property after any
4183 margin prefix has been stripped. It must be a string,
4184 an image specification, or `(space ...)'.
4186 LOCATION specifies where to display: `left-margin',
4187 `right-margin' or nil. */
4189 valid_p
= (STRINGP (value
)
4190 #ifdef HAVE_WINDOW_SYSTEM
4191 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
4192 #endif /* not HAVE_WINDOW_SYSTEM */
4193 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4195 if (valid_p
&& !display_replaced_before_p
)
4197 /* Save current settings of IT so that we can restore them
4198 when we are finished with the glyph property value. */
4199 save_pos
= it
->position
;
4200 it
->position
= *position
;
4202 it
->position
= save_pos
;
4204 if (NILP (location
))
4205 it
->area
= TEXT_AREA
;
4206 else if (EQ (location
, Qleft_margin
))
4207 it
->area
= LEFT_MARGIN_AREA
;
4209 it
->area
= RIGHT_MARGIN_AREA
;
4211 if (STRINGP (value
))
4213 if (SCHARS (value
) == 0)
4216 return -1; /* Replaced by "", i.e. nothing. */
4219 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4220 it
->current
.overlay_string_index
= -1;
4221 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4222 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4223 it
->method
= GET_FROM_STRING
;
4224 it
->stop_charpos
= 0;
4225 it
->string_from_display_prop_p
= 1;
4226 /* Say that we haven't consumed the characters with
4227 `display' property yet. The call to pop_it in
4228 set_iterator_to_next will clean this up. */
4229 *position
= start_pos
;
4231 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4233 it
->method
= GET_FROM_STRETCH
;
4235 *position
= it
->position
= start_pos
;
4237 #ifdef HAVE_WINDOW_SYSTEM
4240 it
->what
= IT_IMAGE
;
4241 it
->image_id
= lookup_image (it
->f
, value
);
4242 it
->position
= start_pos
;
4243 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4244 it
->method
= GET_FROM_IMAGE
;
4246 /* Say that we haven't consumed the characters with
4247 `display' property yet. The call to pop_it in
4248 set_iterator_to_next will clean this up. */
4249 *position
= start_pos
;
4251 #endif /* HAVE_WINDOW_SYSTEM */
4256 /* Invalid property or property not supported. Restore
4257 POSITION to what it was before. */
4258 *position
= start_pos
;
4263 /* Check if SPEC is a display specification value whose text should be
4264 treated as intangible. */
4267 single_display_spec_intangible_p (prop
)
4270 /* Skip over `when FORM'. */
4271 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4285 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4286 we don't need to treat text as intangible. */
4287 if (EQ (XCAR (prop
), Qmargin
))
4295 || EQ (XCAR (prop
), Qleft_margin
)
4296 || EQ (XCAR (prop
), Qright_margin
))
4300 return (CONSP (prop
)
4301 && (EQ (XCAR (prop
), Qimage
)
4302 || EQ (XCAR (prop
), Qspace
)));
4306 /* Check if PROP is a display property value whose text should be
4307 treated as intangible. */
4310 display_prop_intangible_p (prop
)
4314 && CONSP (XCAR (prop
))
4315 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4317 /* A list of sub-properties. */
4318 while (CONSP (prop
))
4320 if (single_display_spec_intangible_p (XCAR (prop
)))
4325 else if (VECTORP (prop
))
4327 /* A vector of sub-properties. */
4329 for (i
= 0; i
< ASIZE (prop
); ++i
)
4330 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4334 return single_display_spec_intangible_p (prop
);
4340 /* Return 1 if PROP is a display sub-property value containing STRING. */
4343 single_display_spec_string_p (prop
, string
)
4344 Lisp_Object prop
, string
;
4346 if (EQ (string
, prop
))
4349 /* Skip over `when FORM'. */
4350 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4359 /* Skip over `margin LOCATION'. */
4360 if (EQ (XCAR (prop
), Qmargin
))
4371 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4375 /* Return 1 if STRING appears in the `display' property PROP. */
4378 display_prop_string_p (prop
, string
)
4379 Lisp_Object prop
, string
;
4382 && CONSP (XCAR (prop
))
4383 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4385 /* A list of sub-properties. */
4386 while (CONSP (prop
))
4388 if (single_display_spec_string_p (XCAR (prop
), string
))
4393 else if (VECTORP (prop
))
4395 /* A vector of sub-properties. */
4397 for (i
= 0; i
< ASIZE (prop
); ++i
)
4398 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4402 return single_display_spec_string_p (prop
, string
);
4408 /* Determine from which buffer position in W's buffer STRING comes
4409 from. AROUND_CHARPOS is an approximate position where it could
4410 be from. Value is the buffer position or 0 if it couldn't be
4413 W's buffer must be current.
4415 This function is necessary because we don't record buffer positions
4416 in glyphs generated from strings (to keep struct glyph small).
4417 This function may only use code that doesn't eval because it is
4418 called asynchronously from note_mouse_highlight. */
4421 string_buffer_position (w
, string
, around_charpos
)
4426 Lisp_Object limit
, prop
, pos
;
4427 const int MAX_DISTANCE
= 1000;
4430 pos
= make_number (around_charpos
);
4431 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4432 while (!found
&& !EQ (pos
, limit
))
4434 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4435 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4438 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4443 pos
= make_number (around_charpos
);
4444 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4445 while (!found
&& !EQ (pos
, limit
))
4447 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4448 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4451 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4456 return found
? XINT (pos
) : 0;
4461 /***********************************************************************
4462 `composition' property
4463 ***********************************************************************/
4465 /* Set up iterator IT from `composition' property at its current
4466 position. Called from handle_stop. */
4468 static enum prop_handled
4469 handle_composition_prop (it
)
4472 Lisp_Object prop
, string
;
4473 int pos
, pos_byte
, end
;
4474 enum prop_handled handled
= HANDLED_NORMALLY
;
4476 if (STRINGP (it
->string
))
4478 pos
= IT_STRING_CHARPOS (*it
);
4479 pos_byte
= IT_STRING_BYTEPOS (*it
);
4480 string
= it
->string
;
4484 pos
= IT_CHARPOS (*it
);
4485 pos_byte
= IT_BYTEPOS (*it
);
4489 /* If there's a valid composition and point is not inside of the
4490 composition (in the case that the composition is from the current
4491 buffer), draw a glyph composed from the composition components. */
4492 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
4493 && COMPOSITION_VALID_P (pos
, end
, prop
)
4494 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
4496 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4500 struct composition
*cmp
= composition_table
[id
];
4502 if (cmp
->glyph_len
== 0)
4505 if (STRINGP (it
->string
))
4507 IT_STRING_CHARPOS (*it
) = end
;
4508 IT_STRING_BYTEPOS (*it
) = string_char_to_byte (it
->string
,
4513 IT_CHARPOS (*it
) = end
;
4514 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (end
);
4516 return HANDLED_RECOMPUTE_PROPS
;
4519 it
->stop_charpos
= end
;
4522 it
->method
= GET_FROM_COMPOSITION
;
4524 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4525 /* For a terminal, draw only the first character of the
4527 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4528 it
->len
= (STRINGP (it
->string
)
4529 ? string_char_to_byte (it
->string
, end
)
4530 : CHAR_TO_BYTE (end
)) - pos_byte
;
4531 handled
= HANDLED_RETURN
;
4540 /***********************************************************************
4542 ***********************************************************************/
4544 /* The following structure is used to record overlay strings for
4545 later sorting in load_overlay_strings. */
4547 struct overlay_entry
4549 Lisp_Object overlay
;
4556 /* Set up iterator IT from overlay strings at its current position.
4557 Called from handle_stop. */
4559 static enum prop_handled
4560 handle_overlay_change (it
)
4563 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4564 return HANDLED_RECOMPUTE_PROPS
;
4566 return HANDLED_NORMALLY
;
4570 /* Set up the next overlay string for delivery by IT, if there is an
4571 overlay string to deliver. Called by set_iterator_to_next when the
4572 end of the current overlay string is reached. If there are more
4573 overlay strings to display, IT->string and
4574 IT->current.overlay_string_index are set appropriately here.
4575 Otherwise IT->string is set to nil. */
4578 next_overlay_string (it
)
4581 ++it
->current
.overlay_string_index
;
4582 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4584 /* No more overlay strings. Restore IT's settings to what
4585 they were before overlay strings were processed, and
4586 continue to deliver from current_buffer. */
4587 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4591 || it
->method
== GET_FROM_COMPOSITION
4592 || (NILP (it
->string
)
4593 && it
->method
== GET_FROM_BUFFER
4594 && it
->stop_charpos
>= BEGV
4595 && it
->stop_charpos
<= it
->end_charpos
));
4596 it
->current
.overlay_string_index
= -1;
4597 it
->n_overlay_strings
= 0;
4599 /* If we're at the end of the buffer, record that we have
4600 processed the overlay strings there already, so that
4601 next_element_from_buffer doesn't try it again. */
4602 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4603 it
->overlay_strings_at_end_processed_p
= 1;
4605 /* If we have to display `...' for invisible text, set
4606 the iterator up for that. */
4607 if (display_ellipsis_p
)
4608 setup_for_ellipsis (it
, 0);
4612 /* There are more overlay strings to process. If
4613 IT->current.overlay_string_index has advanced to a position
4614 where we must load IT->overlay_strings with more strings, do
4616 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4618 if (it
->current
.overlay_string_index
&& i
== 0)
4619 load_overlay_strings (it
, 0);
4621 /* Initialize IT to deliver display elements from the overlay
4623 it
->string
= it
->overlay_strings
[i
];
4624 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4625 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4626 it
->method
= GET_FROM_STRING
;
4627 it
->stop_charpos
= 0;
4634 /* Compare two overlay_entry structures E1 and E2. Used as a
4635 comparison function for qsort in load_overlay_strings. Overlay
4636 strings for the same position are sorted so that
4638 1. All after-strings come in front of before-strings, except
4639 when they come from the same overlay.
4641 2. Within after-strings, strings are sorted so that overlay strings
4642 from overlays with higher priorities come first.
4644 2. Within before-strings, strings are sorted so that overlay
4645 strings from overlays with higher priorities come last.
4647 Value is analogous to strcmp. */
4651 compare_overlay_entries (e1
, e2
)
4654 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4655 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4658 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4660 /* Let after-strings appear in front of before-strings if
4661 they come from different overlays. */
4662 if (EQ (entry1
->overlay
, entry2
->overlay
))
4663 result
= entry1
->after_string_p
? 1 : -1;
4665 result
= entry1
->after_string_p
? -1 : 1;
4667 else if (entry1
->after_string_p
)
4668 /* After-strings sorted in order of decreasing priority. */
4669 result
= entry2
->priority
- entry1
->priority
;
4671 /* Before-strings sorted in order of increasing priority. */
4672 result
= entry1
->priority
- entry2
->priority
;
4678 /* Load the vector IT->overlay_strings with overlay strings from IT's
4679 current buffer position, or from CHARPOS if that is > 0. Set
4680 IT->n_overlays to the total number of overlay strings found.
4682 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4683 a time. On entry into load_overlay_strings,
4684 IT->current.overlay_string_index gives the number of overlay
4685 strings that have already been loaded by previous calls to this
4688 IT->add_overlay_start contains an additional overlay start
4689 position to consider for taking overlay strings from, if non-zero.
4690 This position comes into play when the overlay has an `invisible'
4691 property, and both before and after-strings. When we've skipped to
4692 the end of the overlay, because of its `invisible' property, we
4693 nevertheless want its before-string to appear.
4694 IT->add_overlay_start will contain the overlay start position
4697 Overlay strings are sorted so that after-string strings come in
4698 front of before-string strings. Within before and after-strings,
4699 strings are sorted by overlay priority. See also function
4700 compare_overlay_entries. */
4703 load_overlay_strings (it
, charpos
)
4707 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4708 Lisp_Object overlay
, window
, str
, invisible
;
4709 struct Lisp_Overlay
*ov
;
4712 int n
= 0, i
, j
, invis_p
;
4713 struct overlay_entry
*entries
4714 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4717 charpos
= IT_CHARPOS (*it
);
4719 /* Append the overlay string STRING of overlay OVERLAY to vector
4720 `entries' which has size `size' and currently contains `n'
4721 elements. AFTER_P non-zero means STRING is an after-string of
4723 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4726 Lisp_Object priority; \
4730 int new_size = 2 * size; \
4731 struct overlay_entry *old = entries; \
4733 (struct overlay_entry *) alloca (new_size \
4734 * sizeof *entries); \
4735 bcopy (old, entries, size * sizeof *entries); \
4739 entries[n].string = (STRING); \
4740 entries[n].overlay = (OVERLAY); \
4741 priority = Foverlay_get ((OVERLAY), Qpriority); \
4742 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4743 entries[n].after_string_p = (AFTER_P); \
4748 /* Process overlay before the overlay center. */
4749 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4751 XSETMISC (overlay
, ov
);
4752 xassert (OVERLAYP (overlay
));
4753 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4754 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4759 /* Skip this overlay if it doesn't start or end at IT's current
4761 if (end
!= charpos
&& start
!= charpos
)
4764 /* Skip this overlay if it doesn't apply to IT->w. */
4765 window
= Foverlay_get (overlay
, Qwindow
);
4766 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4769 /* If the text ``under'' the overlay is invisible, both before-
4770 and after-strings from this overlay are visible; start and
4771 end position are indistinguishable. */
4772 invisible
= Foverlay_get (overlay
, Qinvisible
);
4773 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4775 /* If overlay has a non-empty before-string, record it. */
4776 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4777 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4779 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4781 /* If overlay has a non-empty after-string, record it. */
4782 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4783 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4785 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4788 /* Process overlays after the overlay center. */
4789 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4791 XSETMISC (overlay
, ov
);
4792 xassert (OVERLAYP (overlay
));
4793 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4794 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4796 if (start
> charpos
)
4799 /* Skip this overlay if it doesn't start or end at IT's current
4801 if (end
!= charpos
&& start
!= charpos
)
4804 /* Skip this overlay if it doesn't apply to IT->w. */
4805 window
= Foverlay_get (overlay
, Qwindow
);
4806 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4809 /* If the text ``under'' the overlay is invisible, it has a zero
4810 dimension, and both before- and after-strings apply. */
4811 invisible
= Foverlay_get (overlay
, Qinvisible
);
4812 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4814 /* If overlay has a non-empty before-string, record it. */
4815 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4816 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4818 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4820 /* If overlay has a non-empty after-string, record it. */
4821 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4822 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4824 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4827 #undef RECORD_OVERLAY_STRING
4831 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4833 /* Record the total number of strings to process. */
4834 it
->n_overlay_strings
= n
;
4836 /* IT->current.overlay_string_index is the number of overlay strings
4837 that have already been consumed by IT. Copy some of the
4838 remaining overlay strings to IT->overlay_strings. */
4840 j
= it
->current
.overlay_string_index
;
4841 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4842 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4848 /* Get the first chunk of overlay strings at IT's current buffer
4849 position, or at CHARPOS if that is > 0. Value is non-zero if at
4850 least one overlay string was found. */
4853 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
4857 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4858 process. This fills IT->overlay_strings with strings, and sets
4859 IT->n_overlay_strings to the total number of strings to process.
4860 IT->pos.overlay_string_index has to be set temporarily to zero
4861 because load_overlay_strings needs this; it must be set to -1
4862 when no overlay strings are found because a zero value would
4863 indicate a position in the first overlay string. */
4864 it
->current
.overlay_string_index
= 0;
4865 load_overlay_strings (it
, charpos
);
4867 /* If we found overlay strings, set up IT to deliver display
4868 elements from the first one. Otherwise set up IT to deliver
4869 from current_buffer. */
4870 if (it
->n_overlay_strings
)
4872 /* Make sure we know settings in current_buffer, so that we can
4873 restore meaningful values when we're done with the overlay
4876 compute_stop_pos (it
);
4877 xassert (it
->face_id
>= 0);
4879 /* Save IT's settings. They are restored after all overlay
4880 strings have been processed. */
4881 xassert (!compute_stop_p
|| it
->sp
== 0);
4884 /* Set up IT to deliver display elements from the first overlay
4886 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4887 it
->string
= it
->overlay_strings
[0];
4888 it
->stop_charpos
= 0;
4889 xassert (STRINGP (it
->string
));
4890 it
->end_charpos
= SCHARS (it
->string
);
4891 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4892 it
->method
= GET_FROM_STRING
;
4896 it
->current
.overlay_string_index
= -1;
4901 get_overlay_strings (it
, charpos
)
4906 it
->method
= GET_FROM_BUFFER
;
4908 (void) get_overlay_strings_1 (it
, charpos
, 1);
4912 /* Value is non-zero if we found at least one overlay string. */
4913 return STRINGP (it
->string
);
4918 /***********************************************************************
4919 Saving and restoring state
4920 ***********************************************************************/
4922 /* Save current settings of IT on IT->stack. Called, for example,
4923 before setting up IT for an overlay string, to be able to restore
4924 IT's settings to what they were after the overlay string has been
4931 struct iterator_stack_entry
*p
;
4933 xassert (it
->sp
< IT_STACK_SIZE
);
4934 p
= it
->stack
+ it
->sp
;
4936 p
->stop_charpos
= it
->stop_charpos
;
4937 xassert (it
->face_id
>= 0);
4938 p
->face_id
= it
->face_id
;
4939 p
->string
= it
->string
;
4940 p
->method
= it
->method
;
4943 case GET_FROM_IMAGE
:
4944 p
->u
.image
.object
= it
->object
;
4945 p
->u
.image
.image_id
= it
->image_id
;
4946 p
->u
.image
.slice
= it
->slice
;
4948 case GET_FROM_COMPOSITION
:
4949 p
->u
.comp
.object
= it
->object
;
4950 p
->u
.comp
.c
= it
->c
;
4951 p
->u
.comp
.len
= it
->len
;
4952 p
->u
.comp
.cmp_id
= it
->cmp_id
;
4953 p
->u
.comp
.cmp_len
= it
->cmp_len
;
4955 case GET_FROM_STRETCH
:
4956 p
->u
.stretch
.object
= it
->object
;
4959 p
->position
= it
->position
;
4960 p
->current
= it
->current
;
4961 p
->end_charpos
= it
->end_charpos
;
4962 p
->string_nchars
= it
->string_nchars
;
4964 p
->multibyte_p
= it
->multibyte_p
;
4965 p
->space_width
= it
->space_width
;
4966 p
->font_height
= it
->font_height
;
4967 p
->voffset
= it
->voffset
;
4968 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4969 p
->display_ellipsis_p
= 0;
4974 /* Restore IT's settings from IT->stack. Called, for example, when no
4975 more overlay strings must be processed, and we return to delivering
4976 display elements from a buffer, or when the end of a string from a
4977 `display' property is reached and we return to delivering display
4978 elements from an overlay string, or from a buffer. */
4984 struct iterator_stack_entry
*p
;
4986 xassert (it
->sp
> 0);
4988 p
= it
->stack
+ it
->sp
;
4989 it
->stop_charpos
= p
->stop_charpos
;
4990 it
->face_id
= p
->face_id
;
4991 it
->current
= p
->current
;
4992 it
->position
= p
->position
;
4993 it
->string
= p
->string
;
4994 if (NILP (it
->string
))
4995 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4996 it
->method
= p
->method
;
4999 case GET_FROM_IMAGE
:
5000 it
->image_id
= p
->u
.image
.image_id
;
5001 it
->object
= p
->u
.image
.object
;
5002 it
->slice
= p
->u
.image
.slice
;
5004 case GET_FROM_COMPOSITION
:
5005 it
->object
= p
->u
.comp
.object
;
5006 it
->c
= p
->u
.comp
.c
;
5007 it
->len
= p
->u
.comp
.len
;
5008 it
->cmp_id
= p
->u
.comp
.cmp_id
;
5009 it
->cmp_len
= p
->u
.comp
.cmp_len
;
5011 case GET_FROM_STRETCH
:
5012 it
->object
= p
->u
.comp
.object
;
5014 case GET_FROM_BUFFER
:
5015 it
->object
= it
->w
->buffer
;
5017 case GET_FROM_STRING
:
5018 it
->object
= it
->string
;
5021 it
->end_charpos
= p
->end_charpos
;
5022 it
->string_nchars
= p
->string_nchars
;
5024 it
->multibyte_p
= p
->multibyte_p
;
5025 it
->space_width
= p
->space_width
;
5026 it
->font_height
= p
->font_height
;
5027 it
->voffset
= p
->voffset
;
5028 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5033 /***********************************************************************
5035 ***********************************************************************/
5037 /* Set IT's current position to the previous line start. */
5040 back_to_previous_line_start (it
)
5043 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5044 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5048 /* Move IT to the next line start.
5050 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5051 we skipped over part of the text (as opposed to moving the iterator
5052 continuously over the text). Otherwise, don't change the value
5055 Newlines may come from buffer text, overlay strings, or strings
5056 displayed via the `display' property. That's the reason we can't
5057 simply use find_next_newline_no_quit.
5059 Note that this function may not skip over invisible text that is so
5060 because of text properties and immediately follows a newline. If
5061 it would, function reseat_at_next_visible_line_start, when called
5062 from set_iterator_to_next, would effectively make invisible
5063 characters following a newline part of the wrong glyph row, which
5064 leads to wrong cursor motion. */
5067 forward_to_next_line_start (it
, skipped_p
)
5071 int old_selective
, newline_found_p
, n
;
5072 const int MAX_NEWLINE_DISTANCE
= 500;
5074 /* If already on a newline, just consume it to avoid unintended
5075 skipping over invisible text below. */
5076 if (it
->what
== IT_CHARACTER
5078 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5080 set_iterator_to_next (it
, 0);
5085 /* Don't handle selective display in the following. It's (a)
5086 unnecessary because it's done by the caller, and (b) leads to an
5087 infinite recursion because next_element_from_ellipsis indirectly
5088 calls this function. */
5089 old_selective
= it
->selective
;
5092 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5093 from buffer text. */
5094 for (n
= newline_found_p
= 0;
5095 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5096 n
+= STRINGP (it
->string
) ? 0 : 1)
5098 if (!get_next_display_element (it
))
5100 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5101 set_iterator_to_next (it
, 0);
5104 /* If we didn't find a newline near enough, see if we can use a
5106 if (!newline_found_p
)
5108 int start
= IT_CHARPOS (*it
);
5109 int limit
= find_next_newline_no_quit (start
, 1);
5112 xassert (!STRINGP (it
->string
));
5114 /* If there isn't any `display' property in sight, and no
5115 overlays, we can just use the position of the newline in
5117 if (it
->stop_charpos
>= limit
5118 || ((pos
= Fnext_single_property_change (make_number (start
),
5120 Qnil
, make_number (limit
)),
5122 && next_overlay_change (start
) == ZV
))
5124 IT_CHARPOS (*it
) = limit
;
5125 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5126 *skipped_p
= newline_found_p
= 1;
5130 while (get_next_display_element (it
)
5131 && !newline_found_p
)
5133 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5134 set_iterator_to_next (it
, 0);
5139 it
->selective
= old_selective
;
5140 return newline_found_p
;
5144 /* Set IT's current position to the previous visible line start. Skip
5145 invisible text that is so either due to text properties or due to
5146 selective display. Caution: this does not change IT->current_x and
5150 back_to_previous_visible_line_start (it
)
5153 while (IT_CHARPOS (*it
) > BEGV
)
5155 back_to_previous_line_start (it
);
5157 if (IT_CHARPOS (*it
) <= BEGV
)
5160 /* If selective > 0, then lines indented more than that values
5162 if (it
->selective
> 0
5163 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5164 (double) it
->selective
)) /* iftc */
5167 /* Check the newline before point for invisibility. */
5170 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5171 Qinvisible
, it
->window
);
5172 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5176 if (IT_CHARPOS (*it
) <= BEGV
)
5183 Lisp_Object val
, overlay
;
5185 /* If newline is part of a composition, continue from start of composition */
5186 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5187 && beg
< IT_CHARPOS (*it
))
5190 /* If newline is replaced by a display property, find start of overlay
5191 or interval and continue search from that point. */
5193 pos
= --IT_CHARPOS (it2
);
5196 if (handle_display_prop (&it2
) == HANDLED_RETURN
5197 && !NILP (val
= get_char_property_and_overlay
5198 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5199 && (OVERLAYP (overlay
)
5200 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5201 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5204 /* Newline is not replaced by anything -- so we are done. */
5210 IT_CHARPOS (*it
) = beg
;
5211 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5215 it
->continuation_lines_width
= 0;
5217 xassert (IT_CHARPOS (*it
) >= BEGV
);
5218 xassert (IT_CHARPOS (*it
) == BEGV
5219 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5224 /* Reseat iterator IT at the previous visible line start. Skip
5225 invisible text that is so either due to text properties or due to
5226 selective display. At the end, update IT's overlay information,
5227 face information etc. */
5230 reseat_at_previous_visible_line_start (it
)
5233 back_to_previous_visible_line_start (it
);
5234 reseat (it
, it
->current
.pos
, 1);
5239 /* Reseat iterator IT on the next visible line start in the current
5240 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5241 preceding the line start. Skip over invisible text that is so
5242 because of selective display. Compute faces, overlays etc at the
5243 new position. Note that this function does not skip over text that
5244 is invisible because of text properties. */
5247 reseat_at_next_visible_line_start (it
, on_newline_p
)
5251 int newline_found_p
, skipped_p
= 0;
5253 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5255 /* Skip over lines that are invisible because they are indented
5256 more than the value of IT->selective. */
5257 if (it
->selective
> 0)
5258 while (IT_CHARPOS (*it
) < ZV
5259 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5260 (double) it
->selective
)) /* iftc */
5262 xassert (IT_BYTEPOS (*it
) == BEGV
5263 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5264 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5267 /* Position on the newline if that's what's requested. */
5268 if (on_newline_p
&& newline_found_p
)
5270 if (STRINGP (it
->string
))
5272 if (IT_STRING_CHARPOS (*it
) > 0)
5274 --IT_STRING_CHARPOS (*it
);
5275 --IT_STRING_BYTEPOS (*it
);
5278 else if (IT_CHARPOS (*it
) > BEGV
)
5282 reseat (it
, it
->current
.pos
, 0);
5286 reseat (it
, it
->current
.pos
, 0);
5293 /***********************************************************************
5294 Changing an iterator's position
5295 ***********************************************************************/
5297 /* Change IT's current position to POS in current_buffer. If FORCE_P
5298 is non-zero, always check for text properties at the new position.
5299 Otherwise, text properties are only looked up if POS >=
5300 IT->check_charpos of a property. */
5303 reseat (it
, pos
, force_p
)
5305 struct text_pos pos
;
5308 int original_pos
= IT_CHARPOS (*it
);
5310 reseat_1 (it
, pos
, 0);
5312 /* Determine where to check text properties. Avoid doing it
5313 where possible because text property lookup is very expensive. */
5315 || CHARPOS (pos
) > it
->stop_charpos
5316 || CHARPOS (pos
) < original_pos
)
5323 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5324 IT->stop_pos to POS, also. */
5327 reseat_1 (it
, pos
, set_stop_p
)
5329 struct text_pos pos
;
5332 /* Don't call this function when scanning a C string. */
5333 xassert (it
->s
== NULL
);
5335 /* POS must be a reasonable value. */
5336 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5338 it
->current
.pos
= it
->position
= pos
;
5339 it
->end_charpos
= ZV
;
5341 it
->current
.dpvec_index
= -1;
5342 it
->current
.overlay_string_index
= -1;
5343 IT_STRING_CHARPOS (*it
) = -1;
5344 IT_STRING_BYTEPOS (*it
) = -1;
5346 it
->method
= GET_FROM_BUFFER
;
5347 it
->object
= it
->w
->buffer
;
5348 it
->area
= TEXT_AREA
;
5349 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5351 it
->string_from_display_prop_p
= 0;
5352 it
->face_before_selective_p
= 0;
5355 it
->stop_charpos
= CHARPOS (pos
);
5359 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5360 If S is non-null, it is a C string to iterate over. Otherwise,
5361 STRING gives a Lisp string to iterate over.
5363 If PRECISION > 0, don't return more then PRECISION number of
5364 characters from the string.
5366 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5367 characters have been returned. FIELD_WIDTH < 0 means an infinite
5370 MULTIBYTE = 0 means disable processing of multibyte characters,
5371 MULTIBYTE > 0 means enable it,
5372 MULTIBYTE < 0 means use IT->multibyte_p.
5374 IT must be initialized via a prior call to init_iterator before
5375 calling this function. */
5378 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5383 int precision
, field_width
, multibyte
;
5385 /* No region in strings. */
5386 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5388 /* No text property checks performed by default, but see below. */
5389 it
->stop_charpos
= -1;
5391 /* Set iterator position and end position. */
5392 bzero (&it
->current
, sizeof it
->current
);
5393 it
->current
.overlay_string_index
= -1;
5394 it
->current
.dpvec_index
= -1;
5395 xassert (charpos
>= 0);
5397 /* If STRING is specified, use its multibyteness, otherwise use the
5398 setting of MULTIBYTE, if specified. */
5400 it
->multibyte_p
= multibyte
> 0;
5404 xassert (STRINGP (string
));
5405 it
->string
= string
;
5407 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5408 it
->method
= GET_FROM_STRING
;
5409 it
->current
.string_pos
= string_pos (charpos
, string
);
5416 /* Note that we use IT->current.pos, not it->current.string_pos,
5417 for displaying C strings. */
5418 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5419 if (it
->multibyte_p
)
5421 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5422 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5426 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5427 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5430 it
->method
= GET_FROM_C_STRING
;
5433 /* PRECISION > 0 means don't return more than PRECISION characters
5435 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5436 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5438 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5439 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5440 FIELD_WIDTH < 0 means infinite field width. This is useful for
5441 padding with `-' at the end of a mode line. */
5442 if (field_width
< 0)
5443 field_width
= INFINITY
;
5444 if (field_width
> it
->end_charpos
- charpos
)
5445 it
->end_charpos
= charpos
+ field_width
;
5447 /* Use the standard display table for displaying strings. */
5448 if (DISP_TABLE_P (Vstandard_display_table
))
5449 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5451 it
->stop_charpos
= charpos
;
5457 /***********************************************************************
5459 ***********************************************************************/
5461 /* Map enum it_method value to corresponding next_element_from_* function. */
5463 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5465 next_element_from_buffer
,
5466 next_element_from_display_vector
,
5467 next_element_from_composition
,
5468 next_element_from_string
,
5469 next_element_from_c_string
,
5470 next_element_from_image
,
5471 next_element_from_stretch
5475 /* Load IT's display element fields with information about the next
5476 display element from the current position of IT. Value is zero if
5477 end of buffer (or C string) is reached. */
5479 static struct frame
*last_escape_glyph_frame
= NULL
;
5480 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5481 static int last_escape_glyph_merged_face_id
= 0;
5484 get_next_display_element (it
)
5487 /* Non-zero means that we found a display element. Zero means that
5488 we hit the end of what we iterate over. Performance note: the
5489 function pointer `method' used here turns out to be faster than
5490 using a sequence of if-statements. */
5494 success_p
= (*get_next_element
[it
->method
]) (it
);
5496 if (it
->what
== IT_CHARACTER
)
5498 /* Map via display table or translate control characters.
5499 IT->c, IT->len etc. have been set to the next character by
5500 the function call above. If we have a display table, and it
5501 contains an entry for IT->c, translate it. Don't do this if
5502 IT->c itself comes from a display table, otherwise we could
5503 end up in an infinite recursion. (An alternative could be to
5504 count the recursion depth of this function and signal an
5505 error when a certain maximum depth is reached.) Is it worth
5507 if (success_p
&& it
->dpvec
== NULL
)
5512 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5515 struct Lisp_Vector
*v
= XVECTOR (dv
);
5517 /* Return the first character from the display table
5518 entry, if not empty. If empty, don't display the
5519 current character. */
5522 it
->dpvec_char_len
= it
->len
;
5523 it
->dpvec
= v
->contents
;
5524 it
->dpend
= v
->contents
+ v
->size
;
5525 it
->current
.dpvec_index
= 0;
5526 it
->dpvec_face_id
= -1;
5527 it
->saved_face_id
= it
->face_id
;
5528 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5533 set_iterator_to_next (it
, 0);
5538 /* Translate control characters into `\003' or `^C' form.
5539 Control characters coming from a display table entry are
5540 currently not translated because we use IT->dpvec to hold
5541 the translation. This could easily be changed but I
5542 don't believe that it is worth doing.
5544 If it->multibyte_p is nonzero, eight-bit characters and
5545 non-printable multibyte characters are also translated to
5548 If it->multibyte_p is zero, eight-bit characters that
5549 don't have corresponding multibyte char code are also
5550 translated to octal form. */
5551 else if ((it
->c
< ' '
5552 && (it
->area
!= TEXT_AREA
5553 /* In mode line, treat \n like other crl chars. */
5555 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5556 || (it
->c
!= '\n' && it
->c
!= '\t')))
5560 || !CHAR_PRINTABLE_P (it
->c
)
5561 || (!NILP (Vnobreak_char_display
)
5562 && (it
->c
== 0x8a0 || it
->c
== 0x8ad
5563 || it
->c
== 0x920 || it
->c
== 0x92d
5564 || it
->c
== 0xe20 || it
->c
== 0xe2d
5565 || it
->c
== 0xf20 || it
->c
== 0xf2d)))
5567 && (!unibyte_display_via_language_environment
5568 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
5570 /* IT->c is a control character which must be displayed
5571 either as '\003' or as `^C' where the '\\' and '^'
5572 can be defined in the display table. Fill
5573 IT->ctl_chars with glyphs for what we have to
5574 display. Then, set IT->dpvec to these glyphs. */
5577 int face_id
, lface_id
= 0 ;
5580 /* Handle control characters with ^. */
5582 if (it
->c
< 128 && it
->ctl_arrow_p
)
5584 g
= '^'; /* default glyph for Control */
5585 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5587 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5588 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5590 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5591 lface_id
= FAST_GLYPH_FACE (g
);
5595 g
= FAST_GLYPH_CHAR (g
);
5596 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5599 else if (it
->f
== last_escape_glyph_frame
5600 && it
->face_id
== last_escape_glyph_face_id
)
5602 face_id
= last_escape_glyph_merged_face_id
;
5606 /* Merge the escape-glyph face into the current face. */
5607 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5609 last_escape_glyph_frame
= it
->f
;
5610 last_escape_glyph_face_id
= it
->face_id
;
5611 last_escape_glyph_merged_face_id
= face_id
;
5614 XSETINT (it
->ctl_chars
[0], g
);
5616 XSETINT (it
->ctl_chars
[1], g
);
5618 goto display_control
;
5621 /* Handle non-break space in the mode where it only gets
5624 if (EQ (Vnobreak_char_display
, Qt
)
5625 && (it
->c
== 0x8a0 || it
->c
== 0x920
5626 || it
->c
== 0xe20 || it
->c
== 0xf20))
5628 /* Merge the no-break-space face into the current face. */
5629 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5633 XSETINT (it
->ctl_chars
[0], g
);
5635 goto display_control
;
5638 /* Handle sequences that start with the "escape glyph". */
5640 /* the default escape glyph is \. */
5641 escape_glyph
= '\\';
5644 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5645 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5647 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5648 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5652 /* The display table specified a face.
5653 Merge it into face_id and also into escape_glyph. */
5654 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5655 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5658 else if (it
->f
== last_escape_glyph_frame
5659 && it
->face_id
== last_escape_glyph_face_id
)
5661 face_id
= last_escape_glyph_merged_face_id
;
5665 /* Merge the escape-glyph face into the current face. */
5666 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5668 last_escape_glyph_frame
= it
->f
;
5669 last_escape_glyph_face_id
= it
->face_id
;
5670 last_escape_glyph_merged_face_id
= face_id
;
5673 /* Handle soft hyphens in the mode where they only get
5676 if (EQ (Vnobreak_char_display
, Qt
)
5677 && (it
->c
== 0x8ad || it
->c
== 0x92d
5678 || it
->c
== 0xe2d || it
->c
== 0xf2d))
5681 XSETINT (it
->ctl_chars
[0], g
);
5683 goto display_control
;
5686 /* Handle non-break space and soft hyphen
5687 with the escape glyph. */
5689 if (it
->c
== 0x8a0 || it
->c
== 0x8ad
5690 || it
->c
== 0x920 || it
->c
== 0x92d
5691 || it
->c
== 0xe20 || it
->c
== 0xe2d
5692 || it
->c
== 0xf20 || it
->c
== 0xf2d)
5694 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5695 g
= it
->c
= ((it
->c
& 0xf) == 0 ? ' ' : '-');
5696 XSETINT (it
->ctl_chars
[1], g
);
5698 goto display_control
;
5702 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5706 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5707 if (SINGLE_BYTE_CHAR_P (it
->c
))
5708 str
[0] = it
->c
, len
= 1;
5711 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5714 /* It's an invalid character, which shouldn't
5715 happen actually, but due to bugs it may
5716 happen. Let's print the char as is, there's
5717 not much meaningful we can do with it. */
5719 str
[1] = it
->c
>> 8;
5720 str
[2] = it
->c
>> 16;
5721 str
[3] = it
->c
>> 24;
5726 for (i
= 0; i
< len
; i
++)
5728 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5729 /* Insert three more glyphs into IT->ctl_chars for
5730 the octal display of the character. */
5731 g
= ((str
[i
] >> 6) & 7) + '0';
5732 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5733 g
= ((str
[i
] >> 3) & 7) + '0';
5734 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5735 g
= (str
[i
] & 7) + '0';
5736 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5742 /* Set up IT->dpvec and return first character from it. */
5743 it
->dpvec_char_len
= it
->len
;
5744 it
->dpvec
= it
->ctl_chars
;
5745 it
->dpend
= it
->dpvec
+ ctl_len
;
5746 it
->current
.dpvec_index
= 0;
5747 it
->dpvec_face_id
= face_id
;
5748 it
->saved_face_id
= it
->face_id
;
5749 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5755 /* Adjust face id for a multibyte character. There are no
5756 multibyte character in unibyte text. */
5759 && FRAME_WINDOW_P (it
->f
))
5761 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5762 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5766 /* Is this character the last one of a run of characters with
5767 box? If yes, set IT->end_of_box_run_p to 1. */
5774 it
->end_of_box_run_p
5775 = ((face_id
= face_after_it_pos (it
),
5776 face_id
!= it
->face_id
)
5777 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5778 face
->box
== FACE_NO_BOX
));
5781 /* Value is 0 if end of buffer or string reached. */
5786 /* Move IT to the next display element.
5788 RESEAT_P non-zero means if called on a newline in buffer text,
5789 skip to the next visible line start.
5791 Functions get_next_display_element and set_iterator_to_next are
5792 separate because I find this arrangement easier to handle than a
5793 get_next_display_element function that also increments IT's
5794 position. The way it is we can first look at an iterator's current
5795 display element, decide whether it fits on a line, and if it does,
5796 increment the iterator position. The other way around we probably
5797 would either need a flag indicating whether the iterator has to be
5798 incremented the next time, or we would have to implement a
5799 decrement position function which would not be easy to write. */
5802 set_iterator_to_next (it
, reseat_p
)
5806 /* Reset flags indicating start and end of a sequence of characters
5807 with box. Reset them at the start of this function because
5808 moving the iterator to a new position might set them. */
5809 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5813 case GET_FROM_BUFFER
:
5814 /* The current display element of IT is a character from
5815 current_buffer. Advance in the buffer, and maybe skip over
5816 invisible lines that are so because of selective display. */
5817 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5818 reseat_at_next_visible_line_start (it
, 0);
5821 xassert (it
->len
!= 0);
5822 IT_BYTEPOS (*it
) += it
->len
;
5823 IT_CHARPOS (*it
) += 1;
5824 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5828 case GET_FROM_COMPOSITION
:
5829 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5830 xassert (it
->sp
> 0);
5832 if (it
->method
== GET_FROM_STRING
)
5834 IT_STRING_BYTEPOS (*it
) += it
->len
;
5835 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5836 goto consider_string_end
;
5838 else if (it
->method
== GET_FROM_BUFFER
)
5840 IT_BYTEPOS (*it
) += it
->len
;
5841 IT_CHARPOS (*it
) += it
->cmp_len
;
5845 case GET_FROM_C_STRING
:
5846 /* Current display element of IT is from a C string. */
5847 IT_BYTEPOS (*it
) += it
->len
;
5848 IT_CHARPOS (*it
) += 1;
5851 case GET_FROM_DISPLAY_VECTOR
:
5852 /* Current display element of IT is from a display table entry.
5853 Advance in the display table definition. Reset it to null if
5854 end reached, and continue with characters from buffers/
5856 ++it
->current
.dpvec_index
;
5858 /* Restore face of the iterator to what they were before the
5859 display vector entry (these entries may contain faces). */
5860 it
->face_id
= it
->saved_face_id
;
5862 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5864 int recheck_faces
= it
->ellipsis_p
;
5867 it
->method
= GET_FROM_C_STRING
;
5868 else if (STRINGP (it
->string
))
5869 it
->method
= GET_FROM_STRING
;
5872 it
->method
= GET_FROM_BUFFER
;
5873 it
->object
= it
->w
->buffer
;
5877 it
->current
.dpvec_index
= -1;
5879 /* Skip over characters which were displayed via IT->dpvec. */
5880 if (it
->dpvec_char_len
< 0)
5881 reseat_at_next_visible_line_start (it
, 1);
5882 else if (it
->dpvec_char_len
> 0)
5884 if (it
->method
== GET_FROM_STRING
5885 && it
->n_overlay_strings
> 0)
5886 it
->ignore_overlay_strings_at_pos_p
= 1;
5887 it
->len
= it
->dpvec_char_len
;
5888 set_iterator_to_next (it
, reseat_p
);
5891 /* Maybe recheck faces after display vector */
5893 it
->stop_charpos
= IT_CHARPOS (*it
);
5897 case GET_FROM_STRING
:
5898 /* Current display element is a character from a Lisp string. */
5899 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5900 IT_STRING_BYTEPOS (*it
) += it
->len
;
5901 IT_STRING_CHARPOS (*it
) += 1;
5903 consider_string_end
:
5905 if (it
->current
.overlay_string_index
>= 0)
5907 /* IT->string is an overlay string. Advance to the
5908 next, if there is one. */
5909 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5910 next_overlay_string (it
);
5914 /* IT->string is not an overlay string. If we reached
5915 its end, and there is something on IT->stack, proceed
5916 with what is on the stack. This can be either another
5917 string, this time an overlay string, or a buffer. */
5918 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5922 if (it
->method
== GET_FROM_STRING
)
5923 goto consider_string_end
;
5928 case GET_FROM_IMAGE
:
5929 case GET_FROM_STRETCH
:
5930 /* The position etc with which we have to proceed are on
5931 the stack. The position may be at the end of a string,
5932 if the `display' property takes up the whole string. */
5933 xassert (it
->sp
> 0);
5935 if (it
->method
== GET_FROM_STRING
)
5936 goto consider_string_end
;
5940 /* There are no other methods defined, so this should be a bug. */
5944 xassert (it
->method
!= GET_FROM_STRING
5945 || (STRINGP (it
->string
)
5946 && IT_STRING_CHARPOS (*it
) >= 0));
5949 /* Load IT's display element fields with information about the next
5950 display element which comes from a display table entry or from the
5951 result of translating a control character to one of the forms `^C'
5954 IT->dpvec holds the glyphs to return as characters.
5955 IT->saved_face_id holds the face id before the display vector--
5956 it is restored into IT->face_idin set_iterator_to_next. */
5959 next_element_from_display_vector (it
)
5963 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5965 it
->face_id
= it
->saved_face_id
;
5967 if (INTEGERP (*it
->dpvec
)
5968 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5972 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5973 it
->c
= FAST_GLYPH_CHAR (g
);
5974 it
->len
= CHAR_BYTES (it
->c
);
5976 /* The entry may contain a face id to use. Such a face id is
5977 the id of a Lisp face, not a realized face. A face id of
5978 zero means no face is specified. */
5979 if (it
->dpvec_face_id
>= 0)
5980 it
->face_id
= it
->dpvec_face_id
;
5983 int lface_id
= FAST_GLYPH_FACE (g
);
5985 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5990 /* Display table entry is invalid. Return a space. */
5991 it
->c
= ' ', it
->len
= 1;
5993 /* Don't change position and object of the iterator here. They are
5994 still the values of the character that had this display table
5995 entry or was translated, and that's what we want. */
5996 it
->what
= IT_CHARACTER
;
6001 /* Load IT with the next display element from Lisp string IT->string.
6002 IT->current.string_pos is the current position within the string.
6003 If IT->current.overlay_string_index >= 0, the Lisp string is an
6007 next_element_from_string (it
)
6010 struct text_pos position
;
6012 xassert (STRINGP (it
->string
));
6013 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6014 position
= it
->current
.string_pos
;
6016 /* Time to check for invisible text? */
6017 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6018 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6022 /* Since a handler may have changed IT->method, we must
6024 return get_next_display_element (it
);
6027 if (it
->current
.overlay_string_index
>= 0)
6029 /* Get the next character from an overlay string. In overlay
6030 strings, There is no field width or padding with spaces to
6032 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6037 else if (STRING_MULTIBYTE (it
->string
))
6039 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6040 const unsigned char *s
= (SDATA (it
->string
)
6041 + IT_STRING_BYTEPOS (*it
));
6042 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
6046 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6052 /* Get the next character from a Lisp string that is not an
6053 overlay string. Such strings come from the mode line, for
6054 example. We may have to pad with spaces, or truncate the
6055 string. See also next_element_from_c_string. */
6056 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6061 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6063 /* Pad with spaces. */
6064 it
->c
= ' ', it
->len
= 1;
6065 CHARPOS (position
) = BYTEPOS (position
) = -1;
6067 else if (STRING_MULTIBYTE (it
->string
))
6069 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6070 const unsigned char *s
= (SDATA (it
->string
)
6071 + IT_STRING_BYTEPOS (*it
));
6072 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
6076 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6081 /* Record what we have and where it came from. */
6082 it
->what
= IT_CHARACTER
;
6083 it
->object
= it
->string
;
6084 it
->position
= position
;
6089 /* Load IT with next display element from C string IT->s.
6090 IT->string_nchars is the maximum number of characters to return
6091 from the string. IT->end_charpos may be greater than
6092 IT->string_nchars when this function is called, in which case we
6093 may have to return padding spaces. Value is zero if end of string
6094 reached, including padding spaces. */
6097 next_element_from_c_string (it
)
6103 it
->what
= IT_CHARACTER
;
6104 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6107 /* IT's position can be greater IT->string_nchars in case a field
6108 width or precision has been specified when the iterator was
6110 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6112 /* End of the game. */
6116 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6118 /* Pad with spaces. */
6119 it
->c
= ' ', it
->len
= 1;
6120 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6122 else if (it
->multibyte_p
)
6124 /* Implementation note: The calls to strlen apparently aren't a
6125 performance problem because there is no noticeable performance
6126 difference between Emacs running in unibyte or multibyte mode. */
6127 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6128 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
6132 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6138 /* Set up IT to return characters from an ellipsis, if appropriate.
6139 The definition of the ellipsis glyphs may come from a display table
6140 entry. This function Fills IT with the first glyph from the
6141 ellipsis if an ellipsis is to be displayed. */
6144 next_element_from_ellipsis (it
)
6147 if (it
->selective_display_ellipsis_p
)
6148 setup_for_ellipsis (it
, it
->len
);
6151 /* The face at the current position may be different from the
6152 face we find after the invisible text. Remember what it
6153 was in IT->saved_face_id, and signal that it's there by
6154 setting face_before_selective_p. */
6155 it
->saved_face_id
= it
->face_id
;
6156 it
->method
= GET_FROM_BUFFER
;
6157 it
->object
= it
->w
->buffer
;
6158 reseat_at_next_visible_line_start (it
, 1);
6159 it
->face_before_selective_p
= 1;
6162 return get_next_display_element (it
);
6166 /* Deliver an image display element. The iterator IT is already
6167 filled with image information (done in handle_display_prop). Value
6172 next_element_from_image (it
)
6175 it
->what
= IT_IMAGE
;
6180 /* Fill iterator IT with next display element from a stretch glyph
6181 property. IT->object is the value of the text property. Value is
6185 next_element_from_stretch (it
)
6188 it
->what
= IT_STRETCH
;
6193 /* Load IT with the next display element from current_buffer. Value
6194 is zero if end of buffer reached. IT->stop_charpos is the next
6195 position at which to stop and check for text properties or buffer
6199 next_element_from_buffer (it
)
6204 /* Check this assumption, otherwise, we would never enter the
6205 if-statement, below. */
6206 xassert (IT_CHARPOS (*it
) >= BEGV
6207 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
6209 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6211 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6213 int overlay_strings_follow_p
;
6215 /* End of the game, except when overlay strings follow that
6216 haven't been returned yet. */
6217 if (it
->overlay_strings_at_end_processed_p
)
6218 overlay_strings_follow_p
= 0;
6221 it
->overlay_strings_at_end_processed_p
= 1;
6222 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6225 if (overlay_strings_follow_p
)
6226 success_p
= get_next_display_element (it
);
6230 it
->position
= it
->current
.pos
;
6237 return get_next_display_element (it
);
6242 /* No face changes, overlays etc. in sight, so just return a
6243 character from current_buffer. */
6246 /* Maybe run the redisplay end trigger hook. Performance note:
6247 This doesn't seem to cost measurable time. */
6248 if (it
->redisplay_end_trigger_charpos
6250 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6251 run_redisplay_end_trigger_hook (it
);
6253 /* Get the next character, maybe multibyte. */
6254 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6255 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6257 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
6258 - IT_BYTEPOS (*it
));
6259 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
6262 it
->c
= *p
, it
->len
= 1;
6264 /* Record what we have and where it came from. */
6265 it
->what
= IT_CHARACTER
;;
6266 it
->object
= it
->w
->buffer
;
6267 it
->position
= it
->current
.pos
;
6269 /* Normally we return the character found above, except when we
6270 really want to return an ellipsis for selective display. */
6275 /* A value of selective > 0 means hide lines indented more
6276 than that number of columns. */
6277 if (it
->selective
> 0
6278 && IT_CHARPOS (*it
) + 1 < ZV
6279 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6280 IT_BYTEPOS (*it
) + 1,
6281 (double) it
->selective
)) /* iftc */
6283 success_p
= next_element_from_ellipsis (it
);
6284 it
->dpvec_char_len
= -1;
6287 else if (it
->c
== '\r' && it
->selective
== -1)
6289 /* A value of selective == -1 means that everything from the
6290 CR to the end of the line is invisible, with maybe an
6291 ellipsis displayed for it. */
6292 success_p
= next_element_from_ellipsis (it
);
6293 it
->dpvec_char_len
= -1;
6298 /* Value is zero if end of buffer reached. */
6299 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6304 /* Run the redisplay end trigger hook for IT. */
6307 run_redisplay_end_trigger_hook (it
)
6310 Lisp_Object args
[3];
6312 /* IT->glyph_row should be non-null, i.e. we should be actually
6313 displaying something, or otherwise we should not run the hook. */
6314 xassert (it
->glyph_row
);
6316 /* Set up hook arguments. */
6317 args
[0] = Qredisplay_end_trigger_functions
;
6318 args
[1] = it
->window
;
6319 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6320 it
->redisplay_end_trigger_charpos
= 0;
6322 /* Since we are *trying* to run these functions, don't try to run
6323 them again, even if they get an error. */
6324 it
->w
->redisplay_end_trigger
= Qnil
;
6325 Frun_hook_with_args (3, args
);
6327 /* Notice if it changed the face of the character we are on. */
6328 handle_face_prop (it
);
6332 /* Deliver a composition display element. The iterator IT is already
6333 filled with composition information (done in
6334 handle_composition_prop). Value is always 1. */
6337 next_element_from_composition (it
)
6340 it
->what
= IT_COMPOSITION
;
6341 it
->position
= (STRINGP (it
->string
)
6342 ? it
->current
.string_pos
6344 if (STRINGP (it
->string
))
6345 it
->object
= it
->string
;
6347 it
->object
= it
->w
->buffer
;
6353 /***********************************************************************
6354 Moving an iterator without producing glyphs
6355 ***********************************************************************/
6357 /* Check if iterator is at a position corresponding to a valid buffer
6358 position after some move_it_ call. */
6360 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6361 ((it)->method == GET_FROM_STRING \
6362 ? IT_STRING_CHARPOS (*it) == 0 \
6366 /* Move iterator IT to a specified buffer or X position within one
6367 line on the display without producing glyphs.
6369 OP should be a bit mask including some or all of these bits:
6370 MOVE_TO_X: Stop on reaching x-position TO_X.
6371 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6372 Regardless of OP's value, stop in reaching the end of the display line.
6374 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6375 This means, in particular, that TO_X includes window's horizontal
6378 The return value has several possible values that
6379 say what condition caused the scan to stop:
6381 MOVE_POS_MATCH_OR_ZV
6382 - when TO_POS or ZV was reached.
6385 -when TO_X was reached before TO_POS or ZV were reached.
6388 - when we reached the end of the display area and the line must
6392 - when we reached the end of the display area and the line is
6396 - when we stopped at a line end, i.e. a newline or a CR and selective
6399 static enum move_it_result
6400 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
6402 int to_charpos
, to_x
, op
;
6404 enum move_it_result result
= MOVE_UNDEFINED
;
6405 struct glyph_row
*saved_glyph_row
;
6407 /* Don't produce glyphs in produce_glyphs. */
6408 saved_glyph_row
= it
->glyph_row
;
6409 it
->glyph_row
= NULL
;
6411 #define BUFFER_POS_REACHED_P() \
6412 ((op & MOVE_TO_POS) != 0 \
6413 && BUFFERP (it->object) \
6414 && IT_CHARPOS (*it) >= to_charpos \
6415 && (it->method == GET_FROM_BUFFER \
6416 || (it->method == GET_FROM_DISPLAY_VECTOR \
6417 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6422 int x
, i
, ascent
= 0, descent
= 0;
6424 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
6425 if ((op
& MOVE_TO_POS
) != 0
6426 && BUFFERP (it
->object
)
6427 && it
->method
== GET_FROM_BUFFER
6428 && IT_CHARPOS (*it
) > to_charpos
)
6430 result
= MOVE_POS_MATCH_OR_ZV
;
6434 /* Stop when ZV reached.
6435 We used to stop here when TO_CHARPOS reached as well, but that is
6436 too soon if this glyph does not fit on this line. So we handle it
6437 explicitly below. */
6438 if (!get_next_display_element (it
)
6439 || (it
->truncate_lines_p
6440 && BUFFER_POS_REACHED_P ()))
6442 result
= MOVE_POS_MATCH_OR_ZV
;
6446 /* The call to produce_glyphs will get the metrics of the
6447 display element IT is loaded with. We record in x the
6448 x-position before this display element in case it does not
6452 /* Remember the line height so far in case the next element doesn't
6454 if (!it
->truncate_lines_p
)
6456 ascent
= it
->max_ascent
;
6457 descent
= it
->max_descent
;
6460 PRODUCE_GLYPHS (it
);
6462 if (it
->area
!= TEXT_AREA
)
6464 set_iterator_to_next (it
, 1);
6468 /* The number of glyphs we get back in IT->nglyphs will normally
6469 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6470 character on a terminal frame, or (iii) a line end. For the
6471 second case, IT->nglyphs - 1 padding glyphs will be present
6472 (on X frames, there is only one glyph produced for a
6473 composite character.
6475 The behavior implemented below means, for continuation lines,
6476 that as many spaces of a TAB as fit on the current line are
6477 displayed there. For terminal frames, as many glyphs of a
6478 multi-glyph character are displayed in the current line, too.
6479 This is what the old redisplay code did, and we keep it that
6480 way. Under X, the whole shape of a complex character must
6481 fit on the line or it will be completely displayed in the
6484 Note that both for tabs and padding glyphs, all glyphs have
6488 /* More than one glyph or glyph doesn't fit on line. All
6489 glyphs have the same width. */
6490 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6492 int x_before_this_char
= x
;
6493 int hpos_before_this_char
= it
->hpos
;
6495 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6497 new_x
= x
+ single_glyph_width
;
6499 /* We want to leave anything reaching TO_X to the caller. */
6500 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6502 if (BUFFER_POS_REACHED_P ())
6503 goto buffer_pos_reached
;
6505 result
= MOVE_X_REACHED
;
6508 else if (/* Lines are continued. */
6509 !it
->truncate_lines_p
6510 && (/* And glyph doesn't fit on the line. */
6511 new_x
> it
->last_visible_x
6512 /* Or it fits exactly and we're on a window
6514 || (new_x
== it
->last_visible_x
6515 && FRAME_WINDOW_P (it
->f
))))
6517 if (/* IT->hpos == 0 means the very first glyph
6518 doesn't fit on the line, e.g. a wide image. */
6520 || (new_x
== it
->last_visible_x
6521 && FRAME_WINDOW_P (it
->f
)))
6524 it
->current_x
= new_x
;
6526 /* The character's last glyph just barely fits
6528 if (i
== it
->nglyphs
- 1)
6530 /* If this is the destination position,
6531 return a position *before* it in this row,
6532 now that we know it fits in this row. */
6533 if (BUFFER_POS_REACHED_P ())
6535 it
->hpos
= hpos_before_this_char
;
6536 it
->current_x
= x_before_this_char
;
6537 result
= MOVE_POS_MATCH_OR_ZV
;
6541 set_iterator_to_next (it
, 1);
6542 #ifdef HAVE_WINDOW_SYSTEM
6543 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6545 if (!get_next_display_element (it
))
6547 result
= MOVE_POS_MATCH_OR_ZV
;
6550 if (BUFFER_POS_REACHED_P ())
6552 if (ITERATOR_AT_END_OF_LINE_P (it
))
6553 result
= MOVE_POS_MATCH_OR_ZV
;
6555 result
= MOVE_LINE_CONTINUED
;
6558 if (ITERATOR_AT_END_OF_LINE_P (it
))
6560 result
= MOVE_NEWLINE_OR_CR
;
6564 #endif /* HAVE_WINDOW_SYSTEM */
6570 it
->max_ascent
= ascent
;
6571 it
->max_descent
= descent
;
6574 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6576 result
= MOVE_LINE_CONTINUED
;
6579 else if (BUFFER_POS_REACHED_P ())
6580 goto buffer_pos_reached
;
6581 else if (new_x
> it
->first_visible_x
)
6583 /* Glyph is visible. Increment number of glyphs that
6584 would be displayed. */
6589 /* Glyph is completely off the left margin of the display
6590 area. Nothing to do. */
6594 if (result
!= MOVE_UNDEFINED
)
6597 else if (BUFFER_POS_REACHED_P ())
6601 it
->max_ascent
= ascent
;
6602 it
->max_descent
= descent
;
6603 result
= MOVE_POS_MATCH_OR_ZV
;
6606 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6608 /* Stop when TO_X specified and reached. This check is
6609 necessary here because of lines consisting of a line end,
6610 only. The line end will not produce any glyphs and we
6611 would never get MOVE_X_REACHED. */
6612 xassert (it
->nglyphs
== 0);
6613 result
= MOVE_X_REACHED
;
6617 /* Is this a line end? If yes, we're done. */
6618 if (ITERATOR_AT_END_OF_LINE_P (it
))
6620 result
= MOVE_NEWLINE_OR_CR
;
6624 /* The current display element has been consumed. Advance
6626 set_iterator_to_next (it
, 1);
6628 /* Stop if lines are truncated and IT's current x-position is
6629 past the right edge of the window now. */
6630 if (it
->truncate_lines_p
6631 && it
->current_x
>= it
->last_visible_x
)
6633 #ifdef HAVE_WINDOW_SYSTEM
6634 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6636 if (!get_next_display_element (it
)
6637 || BUFFER_POS_REACHED_P ())
6639 result
= MOVE_POS_MATCH_OR_ZV
;
6642 if (ITERATOR_AT_END_OF_LINE_P (it
))
6644 result
= MOVE_NEWLINE_OR_CR
;
6648 #endif /* HAVE_WINDOW_SYSTEM */
6649 result
= MOVE_LINE_TRUNCATED
;
6654 #undef BUFFER_POS_REACHED_P
6656 /* Restore the iterator settings altered at the beginning of this
6658 it
->glyph_row
= saved_glyph_row
;
6663 /* Move IT forward until it satisfies one or more of the criteria in
6664 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6666 OP is a bit-mask that specifies where to stop, and in particular,
6667 which of those four position arguments makes a difference. See the
6668 description of enum move_operation_enum.
6670 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6671 screen line, this function will set IT to the next position >
6675 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6677 int to_charpos
, to_x
, to_y
, to_vpos
;
6680 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6686 if (op
& MOVE_TO_VPOS
)
6688 /* If no TO_CHARPOS and no TO_X specified, stop at the
6689 start of the line TO_VPOS. */
6690 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6692 if (it
->vpos
== to_vpos
)
6698 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6702 /* TO_VPOS >= 0 means stop at TO_X in the line at
6703 TO_VPOS, or at TO_POS, whichever comes first. */
6704 if (it
->vpos
== to_vpos
)
6710 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6712 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6717 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6719 /* We have reached TO_X but not in the line we want. */
6720 skip
= move_it_in_display_line_to (it
, to_charpos
,
6722 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6730 else if (op
& MOVE_TO_Y
)
6732 struct it it_backup
;
6734 /* TO_Y specified means stop at TO_X in the line containing
6735 TO_Y---or at TO_CHARPOS if this is reached first. The
6736 problem is that we can't really tell whether the line
6737 contains TO_Y before we have completely scanned it, and
6738 this may skip past TO_X. What we do is to first scan to
6741 If TO_X is not specified, use a TO_X of zero. The reason
6742 is to make the outcome of this function more predictable.
6743 If we didn't use TO_X == 0, we would stop at the end of
6744 the line which is probably not what a caller would expect
6746 skip
= move_it_in_display_line_to (it
, to_charpos
,
6750 | (op
& MOVE_TO_POS
)));
6752 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6753 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6759 /* If TO_X was reached, we would like to know whether TO_Y
6760 is in the line. This can only be said if we know the
6761 total line height which requires us to scan the rest of
6763 if (skip
== MOVE_X_REACHED
)
6766 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6767 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6769 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6772 /* Now, decide whether TO_Y is in this line. */
6773 line_height
= it
->max_ascent
+ it
->max_descent
;
6774 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6776 if (to_y
>= it
->current_y
6777 && to_y
< it
->current_y
+ line_height
)
6779 if (skip
== MOVE_X_REACHED
)
6780 /* If TO_Y is in this line and TO_X was reached above,
6781 we scanned too far. We have to restore IT's settings
6782 to the ones before skipping. */
6786 else if (skip
== MOVE_X_REACHED
)
6789 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6796 else if (BUFFERP (it
->object
)
6797 && it
->method
== GET_FROM_BUFFER
6798 && IT_CHARPOS (*it
) >= to_charpos
)
6799 skip
= MOVE_POS_MATCH_OR_ZV
;
6801 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6805 case MOVE_POS_MATCH_OR_ZV
:
6809 case MOVE_NEWLINE_OR_CR
:
6810 set_iterator_to_next (it
, 1);
6811 it
->continuation_lines_width
= 0;
6814 case MOVE_LINE_TRUNCATED
:
6815 it
->continuation_lines_width
= 0;
6816 reseat_at_next_visible_line_start (it
, 0);
6817 if ((op
& MOVE_TO_POS
) != 0
6818 && IT_CHARPOS (*it
) > to_charpos
)
6825 case MOVE_LINE_CONTINUED
:
6826 it
->continuation_lines_width
+= it
->current_x
;
6833 /* Reset/increment for the next run. */
6834 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6835 it
->current_x
= it
->hpos
= 0;
6836 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6838 last_height
= it
->max_ascent
+ it
->max_descent
;
6839 last_max_ascent
= it
->max_ascent
;
6840 it
->max_ascent
= it
->max_descent
= 0;
6845 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6849 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6851 If DY > 0, move IT backward at least that many pixels. DY = 0
6852 means move IT backward to the preceding line start or BEGV. This
6853 function may move over more than DY pixels if IT->current_y - DY
6854 ends up in the middle of a line; in this case IT->current_y will be
6855 set to the top of the line moved to. */
6858 move_it_vertically_backward (it
, dy
)
6869 start_pos
= IT_CHARPOS (*it
);
6871 /* Estimate how many newlines we must move back. */
6872 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6874 /* Set the iterator's position that many lines back. */
6875 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6876 back_to_previous_visible_line_start (it
);
6878 /* Reseat the iterator here. When moving backward, we don't want
6879 reseat to skip forward over invisible text, set up the iterator
6880 to deliver from overlay strings at the new position etc. So,
6881 use reseat_1 here. */
6882 reseat_1 (it
, it
->current
.pos
, 1);
6884 /* We are now surely at a line start. */
6885 it
->current_x
= it
->hpos
= 0;
6886 it
->continuation_lines_width
= 0;
6888 /* Move forward and see what y-distance we moved. First move to the
6889 start of the next line so that we get its height. We need this
6890 height to be able to tell whether we reached the specified
6893 it2
.max_ascent
= it2
.max_descent
= 0;
6896 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6897 MOVE_TO_POS
| MOVE_TO_VPOS
);
6899 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
6900 xassert (IT_CHARPOS (*it
) >= BEGV
);
6903 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6904 xassert (IT_CHARPOS (*it
) >= BEGV
);
6905 /* H is the actual vertical distance from the position in *IT
6906 and the starting position. */
6907 h
= it2
.current_y
- it
->current_y
;
6908 /* NLINES is the distance in number of lines. */
6909 nlines
= it2
.vpos
- it
->vpos
;
6911 /* Correct IT's y and vpos position
6912 so that they are relative to the starting point. */
6918 /* DY == 0 means move to the start of the screen line. The
6919 value of nlines is > 0 if continuation lines were involved. */
6921 move_it_by_lines (it
, nlines
, 1);
6923 /* I think this assert is bogus if buffer contains
6924 invisible text or images. KFS. */
6925 xassert (IT_CHARPOS (*it
) <= start_pos
);
6930 /* The y-position we try to reach, relative to *IT.
6931 Note that H has been subtracted in front of the if-statement. */
6932 int target_y
= it
->current_y
+ h
- dy
;
6933 int y0
= it3
.current_y
;
6934 int y1
= line_bottom_y (&it3
);
6935 int line_height
= y1
- y0
;
6937 /* If we did not reach target_y, try to move further backward if
6938 we can. If we moved too far backward, try to move forward. */
6939 if (target_y
< it
->current_y
6940 /* This is heuristic. In a window that's 3 lines high, with
6941 a line height of 13 pixels each, recentering with point
6942 on the bottom line will try to move -39/2 = 19 pixels
6943 backward. Try to avoid moving into the first line. */
6944 && (it
->current_y
- target_y
6945 > min (window_box_height (it
->w
), line_height
* 2 / 3))
6946 && IT_CHARPOS (*it
) > BEGV
)
6948 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6949 target_y
- it
->current_y
));
6950 dy
= it
->current_y
- target_y
;
6951 goto move_further_back
;
6953 else if (target_y
>= it
->current_y
+ line_height
6954 && IT_CHARPOS (*it
) < ZV
)
6956 /* Should move forward by at least one line, maybe more.
6958 Note: Calling move_it_by_lines can be expensive on
6959 terminal frames, where compute_motion is used (via
6960 vmotion) to do the job, when there are very long lines
6961 and truncate-lines is nil. That's the reason for
6962 treating terminal frames specially here. */
6964 if (!FRAME_WINDOW_P (it
->f
))
6965 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6970 move_it_by_lines (it
, 1, 1);
6972 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6976 /* I think this assert is bogus if buffer contains
6977 invisible text or images. KFS. */
6978 xassert (IT_CHARPOS (*it
) >= BEGV
);
6985 /* Move IT by a specified amount of pixel lines DY. DY negative means
6986 move backwards. DY = 0 means move to start of screen line. At the
6987 end, IT will be on the start of a screen line. */
6990 move_it_vertically (it
, dy
)
6995 move_it_vertically_backward (it
, -dy
);
6998 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6999 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7000 MOVE_TO_POS
| MOVE_TO_Y
);
7001 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7003 /* If buffer ends in ZV without a newline, move to the start of
7004 the line to satisfy the post-condition. */
7005 if (IT_CHARPOS (*it
) == ZV
7007 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7008 move_it_by_lines (it
, 0, 0);
7013 /* Move iterator IT past the end of the text line it is in. */
7016 move_it_past_eol (it
)
7019 enum move_it_result rc
;
7021 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7022 if (rc
== MOVE_NEWLINE_OR_CR
)
7023 set_iterator_to_next (it
, 0);
7027 #if 0 /* Currently not used. */
7029 /* Return non-zero if some text between buffer positions START_CHARPOS
7030 and END_CHARPOS is invisible. IT->window is the window for text
7034 invisible_text_between_p (it
, start_charpos
, end_charpos
)
7036 int start_charpos
, end_charpos
;
7038 Lisp_Object prop
, limit
;
7039 int invisible_found_p
;
7041 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
7043 /* Is text at START invisible? */
7044 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
7046 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
7047 invisible_found_p
= 1;
7050 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
7052 make_number (end_charpos
));
7053 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
7056 return invisible_found_p
;
7062 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7063 negative means move up. DVPOS == 0 means move to the start of the
7064 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7065 NEED_Y_P is zero, IT->current_y will be left unchanged.
7067 Further optimization ideas: If we would know that IT->f doesn't use
7068 a face with proportional font, we could be faster for
7069 truncate-lines nil. */
7072 move_it_by_lines (it
, dvpos
, need_y_p
)
7074 int dvpos
, need_y_p
;
7076 struct position pos
;
7078 if (!FRAME_WINDOW_P (it
->f
))
7080 struct text_pos textpos
;
7082 /* We can use vmotion on frames without proportional fonts. */
7083 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
7084 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
7085 reseat (it
, textpos
, 1);
7086 it
->vpos
+= pos
.vpos
;
7087 it
->current_y
+= pos
.vpos
;
7089 else if (dvpos
== 0)
7091 /* DVPOS == 0 means move to the start of the screen line. */
7092 move_it_vertically_backward (it
, 0);
7093 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7094 /* Let next call to line_bottom_y calculate real line height */
7099 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7100 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7101 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7106 int start_charpos
, i
;
7108 /* Start at the beginning of the screen line containing IT's
7109 position. This may actually move vertically backwards,
7110 in case of overlays, so adjust dvpos accordingly. */
7112 move_it_vertically_backward (it
, 0);
7115 /* Go back -DVPOS visible lines and reseat the iterator there. */
7116 start_charpos
= IT_CHARPOS (*it
);
7117 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7118 back_to_previous_visible_line_start (it
);
7119 reseat (it
, it
->current
.pos
, 1);
7121 /* Move further back if we end up in a string or an image. */
7122 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7124 /* First try to move to start of display line. */
7126 move_it_vertically_backward (it
, 0);
7128 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7130 /* If start of line is still in string or image,
7131 move further back. */
7132 back_to_previous_visible_line_start (it
);
7133 reseat (it
, it
->current
.pos
, 1);
7137 it
->current_x
= it
->hpos
= 0;
7139 /* Above call may have moved too far if continuation lines
7140 are involved. Scan forward and see if it did. */
7142 it2
.vpos
= it2
.current_y
= 0;
7143 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7144 it
->vpos
-= it2
.vpos
;
7145 it
->current_y
-= it2
.current_y
;
7146 it
->current_x
= it
->hpos
= 0;
7148 /* If we moved too far back, move IT some lines forward. */
7149 if (it2
.vpos
> -dvpos
)
7151 int delta
= it2
.vpos
+ dvpos
;
7153 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7154 /* Move back again if we got too far ahead. */
7155 if (IT_CHARPOS (*it
) >= start_charpos
)
7161 /* Return 1 if IT points into the middle of a display vector. */
7164 in_display_vector_p (it
)
7167 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7168 && it
->current
.dpvec_index
> 0
7169 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7173 /***********************************************************************
7175 ***********************************************************************/
7178 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7182 add_to_log (format
, arg1
, arg2
)
7184 Lisp_Object arg1
, arg2
;
7186 Lisp_Object args
[3];
7187 Lisp_Object msg
, fmt
;
7190 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7193 /* Do nothing if called asynchronously. Inserting text into
7194 a buffer may call after-change-functions and alike and
7195 that would means running Lisp asynchronously. */
7196 if (handling_signal
)
7200 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7202 args
[0] = fmt
= build_string (format
);
7205 msg
= Fformat (3, args
);
7207 len
= SBYTES (msg
) + 1;
7208 SAFE_ALLOCA (buffer
, char *, len
);
7209 bcopy (SDATA (msg
), buffer
, len
);
7211 message_dolog (buffer
, len
- 1, 1, 0);
7218 /* Output a newline in the *Messages* buffer if "needs" one. */
7221 message_log_maybe_newline ()
7223 if (message_log_need_newline
)
7224 message_dolog ("", 0, 1, 0);
7228 /* Add a string M of length NBYTES to the message log, optionally
7229 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7230 nonzero, means interpret the contents of M as multibyte. This
7231 function calls low-level routines in order to bypass text property
7232 hooks, etc. which might not be safe to run.
7234 This may GC (insert may run before/after change hooks),
7235 so the buffer M must NOT point to a Lisp string. */
7238 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7240 int nbytes
, nlflag
, multibyte
;
7242 if (!NILP (Vmemory_full
))
7245 if (!NILP (Vmessage_log_max
))
7247 struct buffer
*oldbuf
;
7248 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7249 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7250 int point_at_end
= 0;
7252 Lisp_Object old_deactivate_mark
, tem
;
7253 struct gcpro gcpro1
;
7255 old_deactivate_mark
= Vdeactivate_mark
;
7256 oldbuf
= current_buffer
;
7257 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7258 current_buffer
->undo_list
= Qt
;
7260 oldpoint
= message_dolog_marker1
;
7261 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7262 oldbegv
= message_dolog_marker2
;
7263 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7264 oldzv
= message_dolog_marker3
;
7265 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7266 GCPRO1 (old_deactivate_mark
);
7274 BEGV_BYTE
= BEG_BYTE
;
7277 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7279 /* Insert the string--maybe converting multibyte to single byte
7280 or vice versa, so that all the text fits the buffer. */
7282 && NILP (current_buffer
->enable_multibyte_characters
))
7284 int i
, c
, char_bytes
;
7285 unsigned char work
[1];
7287 /* Convert a multibyte string to single-byte
7288 for the *Message* buffer. */
7289 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7291 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7292 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7294 : multibyte_char_to_unibyte (c
, Qnil
));
7295 insert_1_both (work
, 1, 1, 1, 0, 0);
7298 else if (! multibyte
7299 && ! NILP (current_buffer
->enable_multibyte_characters
))
7301 int i
, c
, char_bytes
;
7302 unsigned char *msg
= (unsigned char *) m
;
7303 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7304 /* Convert a single-byte string to multibyte
7305 for the *Message* buffer. */
7306 for (i
= 0; i
< nbytes
; i
++)
7308 c
= unibyte_char_to_multibyte (msg
[i
]);
7309 char_bytes
= CHAR_STRING (c
, str
);
7310 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7314 insert_1 (m
, nbytes
, 1, 0, 0);
7318 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7319 insert_1 ("\n", 1, 1, 0, 0);
7321 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7323 this_bol_byte
= PT_BYTE
;
7325 /* See if this line duplicates the previous one.
7326 If so, combine duplicates. */
7329 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7331 prev_bol_byte
= PT_BYTE
;
7333 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7334 this_bol
, this_bol_byte
);
7337 del_range_both (prev_bol
, prev_bol_byte
,
7338 this_bol
, this_bol_byte
, 0);
7344 /* If you change this format, don't forget to also
7345 change message_log_check_duplicate. */
7346 sprintf (dupstr
, " [%d times]", dup
);
7347 duplen
= strlen (dupstr
);
7348 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7349 insert_1 (dupstr
, duplen
, 1, 0, 1);
7354 /* If we have more than the desired maximum number of lines
7355 in the *Messages* buffer now, delete the oldest ones.
7356 This is safe because we don't have undo in this buffer. */
7358 if (NATNUMP (Vmessage_log_max
))
7360 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7361 -XFASTINT (Vmessage_log_max
) - 1, 0);
7362 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7365 BEGV
= XMARKER (oldbegv
)->charpos
;
7366 BEGV_BYTE
= marker_byte_position (oldbegv
);
7375 ZV
= XMARKER (oldzv
)->charpos
;
7376 ZV_BYTE
= marker_byte_position (oldzv
);
7380 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7382 /* We can't do Fgoto_char (oldpoint) because it will run some
7384 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7385 XMARKER (oldpoint
)->bytepos
);
7388 unchain_marker (XMARKER (oldpoint
));
7389 unchain_marker (XMARKER (oldbegv
));
7390 unchain_marker (XMARKER (oldzv
));
7392 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7393 set_buffer_internal (oldbuf
);
7395 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7396 message_log_need_newline
= !nlflag
;
7397 Vdeactivate_mark
= old_deactivate_mark
;
7402 /* We are at the end of the buffer after just having inserted a newline.
7403 (Note: We depend on the fact we won't be crossing the gap.)
7404 Check to see if the most recent message looks a lot like the previous one.
7405 Return 0 if different, 1 if the new one should just replace it, or a
7406 value N > 1 if we should also append " [N times]". */
7409 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7410 int prev_bol
, this_bol
;
7411 int prev_bol_byte
, this_bol_byte
;
7414 int len
= Z_BYTE
- 1 - this_bol_byte
;
7416 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7417 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7419 for (i
= 0; i
< len
; i
++)
7421 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7429 if (*p1
++ == ' ' && *p1
++ == '[')
7432 while (*p1
>= '0' && *p1
<= '9')
7433 n
= n
* 10 + *p1
++ - '0';
7434 if (strncmp (p1
, " times]\n", 8) == 0)
7441 /* Display an echo area message M with a specified length of NBYTES
7442 bytes. The string may include null characters. If M is 0, clear
7443 out any existing message, and let the mini-buffer text show
7446 This may GC, so the buffer M must NOT point to a Lisp string. */
7449 message2 (m
, nbytes
, multibyte
)
7454 /* First flush out any partial line written with print. */
7455 message_log_maybe_newline ();
7457 message_dolog (m
, nbytes
, 1, multibyte
);
7458 message2_nolog (m
, nbytes
, multibyte
);
7462 /* The non-logging counterpart of message2. */
7465 message2_nolog (m
, nbytes
, multibyte
)
7467 int nbytes
, multibyte
;
7469 struct frame
*sf
= SELECTED_FRAME ();
7470 message_enable_multibyte
= multibyte
;
7474 if (noninteractive_need_newline
)
7475 putc ('\n', stderr
);
7476 noninteractive_need_newline
= 0;
7478 fwrite (m
, nbytes
, 1, stderr
);
7479 if (cursor_in_echo_area
== 0)
7480 fprintf (stderr
, "\n");
7483 /* A null message buffer means that the frame hasn't really been
7484 initialized yet. Error messages get reported properly by
7485 cmd_error, so this must be just an informative message; toss it. */
7486 else if (INTERACTIVE
7487 && sf
->glyphs_initialized_p
7488 && FRAME_MESSAGE_BUF (sf
))
7490 Lisp_Object mini_window
;
7493 /* Get the frame containing the mini-buffer
7494 that the selected frame is using. */
7495 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7496 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7498 FRAME_SAMPLE_VISIBILITY (f
);
7499 if (FRAME_VISIBLE_P (sf
)
7500 && ! FRAME_VISIBLE_P (f
))
7501 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7505 set_message (m
, Qnil
, nbytes
, multibyte
);
7506 if (minibuffer_auto_raise
)
7507 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7510 clear_message (1, 1);
7512 do_pending_window_change (0);
7513 echo_area_display (1);
7514 do_pending_window_change (0);
7515 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7516 (*frame_up_to_date_hook
) (f
);
7521 /* Display an echo area message M with a specified length of NBYTES
7522 bytes. The string may include null characters. If M is not a
7523 string, clear out any existing message, and let the mini-buffer
7526 This function cancels echoing. */
7529 message3 (m
, nbytes
, multibyte
)
7534 struct gcpro gcpro1
;
7537 clear_message (1,1);
7540 /* First flush out any partial line written with print. */
7541 message_log_maybe_newline ();
7547 SAFE_ALLOCA (buffer
, char *, nbytes
);
7548 bcopy (SDATA (m
), buffer
, nbytes
);
7549 message_dolog (buffer
, nbytes
, 1, multibyte
);
7552 message3_nolog (m
, nbytes
, multibyte
);
7558 /* The non-logging version of message3.
7559 This does not cancel echoing, because it is used for echoing.
7560 Perhaps we need to make a separate function for echoing
7561 and make this cancel echoing. */
7564 message3_nolog (m
, nbytes
, multibyte
)
7566 int nbytes
, multibyte
;
7568 struct frame
*sf
= SELECTED_FRAME ();
7569 message_enable_multibyte
= multibyte
;
7573 if (noninteractive_need_newline
)
7574 putc ('\n', stderr
);
7575 noninteractive_need_newline
= 0;
7577 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7578 if (cursor_in_echo_area
== 0)
7579 fprintf (stderr
, "\n");
7582 /* A null message buffer means that the frame hasn't really been
7583 initialized yet. Error messages get reported properly by
7584 cmd_error, so this must be just an informative message; toss it. */
7585 else if (INTERACTIVE
7586 && sf
->glyphs_initialized_p
7587 && FRAME_MESSAGE_BUF (sf
))
7589 Lisp_Object mini_window
;
7593 /* Get the frame containing the mini-buffer
7594 that the selected frame is using. */
7595 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7596 frame
= XWINDOW (mini_window
)->frame
;
7599 FRAME_SAMPLE_VISIBILITY (f
);
7600 if (FRAME_VISIBLE_P (sf
)
7601 && !FRAME_VISIBLE_P (f
))
7602 Fmake_frame_visible (frame
);
7604 if (STRINGP (m
) && SCHARS (m
) > 0)
7606 set_message (NULL
, m
, nbytes
, multibyte
);
7607 if (minibuffer_auto_raise
)
7608 Fraise_frame (frame
);
7609 /* Assume we are not echoing.
7610 (If we are, echo_now will override this.) */
7611 echo_message_buffer
= Qnil
;
7614 clear_message (1, 1);
7616 do_pending_window_change (0);
7617 echo_area_display (1);
7618 do_pending_window_change (0);
7619 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7620 (*frame_up_to_date_hook
) (f
);
7625 /* Display a null-terminated echo area message M. If M is 0, clear
7626 out any existing message, and let the mini-buffer text show through.
7628 The buffer M must continue to exist until after the echo area gets
7629 cleared or some other message gets displayed there. Do not pass
7630 text that is stored in a Lisp string. Do not pass text in a buffer
7631 that was alloca'd. */
7637 message2 (m
, (m
? strlen (m
) : 0), 0);
7641 /* The non-logging counterpart of message1. */
7647 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7650 /* Display a message M which contains a single %s
7651 which gets replaced with STRING. */
7654 message_with_string (m
, string
, log
)
7659 CHECK_STRING (string
);
7665 if (noninteractive_need_newline
)
7666 putc ('\n', stderr
);
7667 noninteractive_need_newline
= 0;
7668 fprintf (stderr
, m
, SDATA (string
));
7669 if (cursor_in_echo_area
== 0)
7670 fprintf (stderr
, "\n");
7674 else if (INTERACTIVE
)
7676 /* The frame whose minibuffer we're going to display the message on.
7677 It may be larger than the selected frame, so we need
7678 to use its buffer, not the selected frame's buffer. */
7679 Lisp_Object mini_window
;
7680 struct frame
*f
, *sf
= SELECTED_FRAME ();
7682 /* Get the frame containing the minibuffer
7683 that the selected frame is using. */
7684 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7685 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7687 /* A null message buffer means that the frame hasn't really been
7688 initialized yet. Error messages get reported properly by
7689 cmd_error, so this must be just an informative message; toss it. */
7690 if (FRAME_MESSAGE_BUF (f
))
7692 Lisp_Object args
[2], message
;
7693 struct gcpro gcpro1
, gcpro2
;
7695 args
[0] = build_string (m
);
7696 args
[1] = message
= string
;
7697 GCPRO2 (args
[0], message
);
7700 message
= Fformat (2, args
);
7703 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7705 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7709 /* Print should start at the beginning of the message
7710 buffer next time. */
7711 message_buf_print
= 0;
7717 /* Dump an informative message to the minibuf. If M is 0, clear out
7718 any existing message, and let the mini-buffer text show through. */
7722 message (m
, a1
, a2
, a3
)
7724 EMACS_INT a1
, a2
, a3
;
7730 if (noninteractive_need_newline
)
7731 putc ('\n', stderr
);
7732 noninteractive_need_newline
= 0;
7733 fprintf (stderr
, m
, a1
, a2
, a3
);
7734 if (cursor_in_echo_area
== 0)
7735 fprintf (stderr
, "\n");
7739 else if (INTERACTIVE
)
7741 /* The frame whose mini-buffer we're going to display the message
7742 on. It may be larger than the selected frame, so we need to
7743 use its buffer, not the selected frame's buffer. */
7744 Lisp_Object mini_window
;
7745 struct frame
*f
, *sf
= SELECTED_FRAME ();
7747 /* Get the frame containing the mini-buffer
7748 that the selected frame is using. */
7749 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7750 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7752 /* A null message buffer means that the frame hasn't really been
7753 initialized yet. Error messages get reported properly by
7754 cmd_error, so this must be just an informative message; toss
7756 if (FRAME_MESSAGE_BUF (f
))
7767 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7768 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7770 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7771 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7773 #endif /* NO_ARG_ARRAY */
7775 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7780 /* Print should start at the beginning of the message
7781 buffer next time. */
7782 message_buf_print
= 0;
7788 /* The non-logging version of message. */
7791 message_nolog (m
, a1
, a2
, a3
)
7793 EMACS_INT a1
, a2
, a3
;
7795 Lisp_Object old_log_max
;
7796 old_log_max
= Vmessage_log_max
;
7797 Vmessage_log_max
= Qnil
;
7798 message (m
, a1
, a2
, a3
);
7799 Vmessage_log_max
= old_log_max
;
7803 /* Display the current message in the current mini-buffer. This is
7804 only called from error handlers in process.c, and is not time
7810 if (!NILP (echo_area_buffer
[0]))
7813 string
= Fcurrent_message ();
7814 message3 (string
, SBYTES (string
),
7815 !NILP (current_buffer
->enable_multibyte_characters
));
7820 /* Make sure echo area buffers in `echo_buffers' are live.
7821 If they aren't, make new ones. */
7824 ensure_echo_area_buffers ()
7828 for (i
= 0; i
< 2; ++i
)
7829 if (!BUFFERP (echo_buffer
[i
])
7830 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7833 Lisp_Object old_buffer
;
7836 old_buffer
= echo_buffer
[i
];
7837 sprintf (name
, " *Echo Area %d*", i
);
7838 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7839 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7841 for (j
= 0; j
< 2; ++j
)
7842 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7843 echo_area_buffer
[j
] = echo_buffer
[i
];
7848 /* Call FN with args A1..A4 with either the current or last displayed
7849 echo_area_buffer as current buffer.
7851 WHICH zero means use the current message buffer
7852 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7853 from echo_buffer[] and clear it.
7855 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7856 suitable buffer from echo_buffer[] and clear it.
7858 Value is what FN returns. */
7861 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7864 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7870 int this_one
, the_other
, clear_buffer_p
, rc
;
7871 int count
= SPECPDL_INDEX ();
7873 /* If buffers aren't live, make new ones. */
7874 ensure_echo_area_buffers ();
7879 this_one
= 0, the_other
= 1;
7881 this_one
= 1, the_other
= 0;
7883 /* Choose a suitable buffer from echo_buffer[] is we don't
7885 if (NILP (echo_area_buffer
[this_one
]))
7887 echo_area_buffer
[this_one
]
7888 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7889 ? echo_buffer
[the_other
]
7890 : echo_buffer
[this_one
]);
7894 buffer
= echo_area_buffer
[this_one
];
7896 /* Don't get confused by reusing the buffer used for echoing
7897 for a different purpose. */
7898 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7901 record_unwind_protect (unwind_with_echo_area_buffer
,
7902 with_echo_area_buffer_unwind_data (w
));
7904 /* Make the echo area buffer current. Note that for display
7905 purposes, it is not necessary that the displayed window's buffer
7906 == current_buffer, except for text property lookup. So, let's
7907 only set that buffer temporarily here without doing a full
7908 Fset_window_buffer. We must also change w->pointm, though,
7909 because otherwise an assertions in unshow_buffer fails, and Emacs
7911 set_buffer_internal_1 (XBUFFER (buffer
));
7915 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7918 current_buffer
->undo_list
= Qt
;
7919 current_buffer
->read_only
= Qnil
;
7920 specbind (Qinhibit_read_only
, Qt
);
7921 specbind (Qinhibit_modification_hooks
, Qt
);
7923 if (clear_buffer_p
&& Z
> BEG
)
7926 xassert (BEGV
>= BEG
);
7927 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7929 rc
= fn (a1
, a2
, a3
, a4
);
7931 xassert (BEGV
>= BEG
);
7932 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7934 unbind_to (count
, Qnil
);
7939 /* Save state that should be preserved around the call to the function
7940 FN called in with_echo_area_buffer. */
7943 with_echo_area_buffer_unwind_data (w
)
7949 /* Reduce consing by keeping one vector in
7950 Vwith_echo_area_save_vector. */
7951 vector
= Vwith_echo_area_save_vector
;
7952 Vwith_echo_area_save_vector
= Qnil
;
7955 vector
= Fmake_vector (make_number (7), Qnil
);
7957 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7958 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7959 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7963 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7964 AREF (vector
, i
) = w
->buffer
; ++i
;
7965 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7966 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7971 for (; i
< end
; ++i
)
7972 AREF (vector
, i
) = Qnil
;
7975 xassert (i
== ASIZE (vector
));
7980 /* Restore global state from VECTOR which was created by
7981 with_echo_area_buffer_unwind_data. */
7984 unwind_with_echo_area_buffer (vector
)
7987 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7988 Vdeactivate_mark
= AREF (vector
, 1);
7989 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7991 if (WINDOWP (AREF (vector
, 3)))
7994 Lisp_Object buffer
, charpos
, bytepos
;
7996 w
= XWINDOW (AREF (vector
, 3));
7997 buffer
= AREF (vector
, 4);
7998 charpos
= AREF (vector
, 5);
7999 bytepos
= AREF (vector
, 6);
8002 set_marker_both (w
->pointm
, buffer
,
8003 XFASTINT (charpos
), XFASTINT (bytepos
));
8006 Vwith_echo_area_save_vector
= vector
;
8011 /* Set up the echo area for use by print functions. MULTIBYTE_P
8012 non-zero means we will print multibyte. */
8015 setup_echo_area_for_printing (multibyte_p
)
8018 /* If we can't find an echo area any more, exit. */
8019 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8022 ensure_echo_area_buffers ();
8024 if (!message_buf_print
)
8026 /* A message has been output since the last time we printed.
8027 Choose a fresh echo area buffer. */
8028 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8029 echo_area_buffer
[0] = echo_buffer
[1];
8031 echo_area_buffer
[0] = echo_buffer
[0];
8033 /* Switch to that buffer and clear it. */
8034 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8035 current_buffer
->truncate_lines
= Qnil
;
8039 int count
= SPECPDL_INDEX ();
8040 specbind (Qinhibit_read_only
, Qt
);
8041 /* Note that undo recording is always disabled. */
8043 unbind_to (count
, Qnil
);
8045 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8047 /* Set up the buffer for the multibyteness we need. */
8049 != !NILP (current_buffer
->enable_multibyte_characters
))
8050 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8052 /* Raise the frame containing the echo area. */
8053 if (minibuffer_auto_raise
)
8055 struct frame
*sf
= SELECTED_FRAME ();
8056 Lisp_Object mini_window
;
8057 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8058 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8061 message_log_maybe_newline ();
8062 message_buf_print
= 1;
8066 if (NILP (echo_area_buffer
[0]))
8068 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8069 echo_area_buffer
[0] = echo_buffer
[1];
8071 echo_area_buffer
[0] = echo_buffer
[0];
8074 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8076 /* Someone switched buffers between print requests. */
8077 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8078 current_buffer
->truncate_lines
= Qnil
;
8084 /* Display an echo area message in window W. Value is non-zero if W's
8085 height is changed. If display_last_displayed_message_p is
8086 non-zero, display the message that was last displayed, otherwise
8087 display the current message. */
8090 display_echo_area (w
)
8093 int i
, no_message_p
, window_height_changed_p
, count
;
8095 /* Temporarily disable garbage collections while displaying the echo
8096 area. This is done because a GC can print a message itself.
8097 That message would modify the echo area buffer's contents while a
8098 redisplay of the buffer is going on, and seriously confuse
8100 count
= inhibit_garbage_collection ();
8102 /* If there is no message, we must call display_echo_area_1
8103 nevertheless because it resizes the window. But we will have to
8104 reset the echo_area_buffer in question to nil at the end because
8105 with_echo_area_buffer will sets it to an empty buffer. */
8106 i
= display_last_displayed_message_p
? 1 : 0;
8107 no_message_p
= NILP (echo_area_buffer
[i
]);
8109 window_height_changed_p
8110 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8111 display_echo_area_1
,
8112 (EMACS_INT
) w
, Qnil
, 0, 0);
8115 echo_area_buffer
[i
] = Qnil
;
8117 unbind_to (count
, Qnil
);
8118 return window_height_changed_p
;
8122 /* Helper for display_echo_area. Display the current buffer which
8123 contains the current echo area message in window W, a mini-window,
8124 a pointer to which is passed in A1. A2..A4 are currently not used.
8125 Change the height of W so that all of the message is displayed.
8126 Value is non-zero if height of W was changed. */
8129 display_echo_area_1 (a1
, a2
, a3
, a4
)
8134 struct window
*w
= (struct window
*) a1
;
8136 struct text_pos start
;
8137 int window_height_changed_p
= 0;
8139 /* Do this before displaying, so that we have a large enough glyph
8140 matrix for the display. If we can't get enough space for the
8141 whole text, display the last N lines. That works by setting w->start. */
8142 window_height_changed_p
= resize_mini_window (w
, 0);
8144 /* Use the starting position chosen by resize_mini_window. */
8145 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8148 clear_glyph_matrix (w
->desired_matrix
);
8149 XSETWINDOW (window
, w
);
8150 try_window (window
, start
, 0);
8152 return window_height_changed_p
;
8156 /* Resize the echo area window to exactly the size needed for the
8157 currently displayed message, if there is one. If a mini-buffer
8158 is active, don't shrink it. */
8161 resize_echo_area_exactly ()
8163 if (BUFFERP (echo_area_buffer
[0])
8164 && WINDOWP (echo_area_window
))
8166 struct window
*w
= XWINDOW (echo_area_window
);
8168 Lisp_Object resize_exactly
;
8170 if (minibuf_level
== 0)
8171 resize_exactly
= Qt
;
8173 resize_exactly
= Qnil
;
8175 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8176 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8179 ++windows_or_buffers_changed
;
8180 ++update_mode_lines
;
8181 redisplay_internal (0);
8187 /* Callback function for with_echo_area_buffer, when used from
8188 resize_echo_area_exactly. A1 contains a pointer to the window to
8189 resize, EXACTLY non-nil means resize the mini-window exactly to the
8190 size of the text displayed. A3 and A4 are not used. Value is what
8191 resize_mini_window returns. */
8194 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8196 Lisp_Object exactly
;
8199 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8203 /* Resize mini-window W to fit the size of its contents. EXACT:P
8204 means size the window exactly to the size needed. Otherwise, it's
8205 only enlarged until W's buffer is empty.
8207 Set W->start to the right place to begin display. If the whole
8208 contents fit, start at the beginning. Otherwise, start so as
8209 to make the end of the contents appear. This is particularly
8210 important for y-or-n-p, but seems desirable generally.
8212 Value is non-zero if the window height has been changed. */
8215 resize_mini_window (w
, exact_p
)
8219 struct frame
*f
= XFRAME (w
->frame
);
8220 int window_height_changed_p
= 0;
8222 xassert (MINI_WINDOW_P (w
));
8224 /* By default, start display at the beginning. */
8225 set_marker_both (w
->start
, w
->buffer
,
8226 BUF_BEGV (XBUFFER (w
->buffer
)),
8227 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8229 /* Don't resize windows while redisplaying a window; it would
8230 confuse redisplay functions when the size of the window they are
8231 displaying changes from under them. Such a resizing can happen,
8232 for instance, when which-func prints a long message while
8233 we are running fontification-functions. We're running these
8234 functions with safe_call which binds inhibit-redisplay to t. */
8235 if (!NILP (Vinhibit_redisplay
))
8238 /* Nil means don't try to resize. */
8239 if (NILP (Vresize_mini_windows
)
8240 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8243 if (!FRAME_MINIBUF_ONLY_P (f
))
8246 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8247 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8248 int height
, max_height
;
8249 int unit
= FRAME_LINE_HEIGHT (f
);
8250 struct text_pos start
;
8251 struct buffer
*old_current_buffer
= NULL
;
8253 if (current_buffer
!= XBUFFER (w
->buffer
))
8255 old_current_buffer
= current_buffer
;
8256 set_buffer_internal (XBUFFER (w
->buffer
));
8259 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8261 /* Compute the max. number of lines specified by the user. */
8262 if (FLOATP (Vmax_mini_window_height
))
8263 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8264 else if (INTEGERP (Vmax_mini_window_height
))
8265 max_height
= XINT (Vmax_mini_window_height
);
8267 max_height
= total_height
/ 4;
8269 /* Correct that max. height if it's bogus. */
8270 max_height
= max (1, max_height
);
8271 max_height
= min (total_height
, max_height
);
8273 /* Find out the height of the text in the window. */
8274 if (it
.truncate_lines_p
)
8279 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8280 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8281 height
= it
.current_y
+ last_height
;
8283 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8284 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8285 height
= (height
+ unit
- 1) / unit
;
8288 /* Compute a suitable window start. */
8289 if (height
> max_height
)
8291 height
= max_height
;
8292 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8293 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8294 start
= it
.current
.pos
;
8297 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8298 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8300 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8302 /* Let it grow only, until we display an empty message, in which
8303 case the window shrinks again. */
8304 if (height
> WINDOW_TOTAL_LINES (w
))
8306 int old_height
= WINDOW_TOTAL_LINES (w
);
8307 freeze_window_starts (f
, 1);
8308 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8309 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8311 else if (height
< WINDOW_TOTAL_LINES (w
)
8312 && (exact_p
|| BEGV
== ZV
))
8314 int old_height
= WINDOW_TOTAL_LINES (w
);
8315 freeze_window_starts (f
, 0);
8316 shrink_mini_window (w
);
8317 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8322 /* Always resize to exact size needed. */
8323 if (height
> WINDOW_TOTAL_LINES (w
))
8325 int old_height
= WINDOW_TOTAL_LINES (w
);
8326 freeze_window_starts (f
, 1);
8327 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8328 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8330 else if (height
< WINDOW_TOTAL_LINES (w
))
8332 int old_height
= WINDOW_TOTAL_LINES (w
);
8333 freeze_window_starts (f
, 0);
8334 shrink_mini_window (w
);
8338 freeze_window_starts (f
, 1);
8339 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8342 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8346 if (old_current_buffer
)
8347 set_buffer_internal (old_current_buffer
);
8350 return window_height_changed_p
;
8354 /* Value is the current message, a string, or nil if there is no
8362 if (NILP (echo_area_buffer
[0]))
8366 with_echo_area_buffer (0, 0, current_message_1
,
8367 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8369 echo_area_buffer
[0] = Qnil
;
8377 current_message_1 (a1
, a2
, a3
, a4
)
8382 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8385 *msg
= make_buffer_string (BEG
, Z
, 1);
8392 /* Push the current message on Vmessage_stack for later restauration
8393 by restore_message. Value is non-zero if the current message isn't
8394 empty. This is a relatively infrequent operation, so it's not
8395 worth optimizing. */
8401 msg
= current_message ();
8402 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8403 return STRINGP (msg
);
8407 /* Restore message display from the top of Vmessage_stack. */
8414 xassert (CONSP (Vmessage_stack
));
8415 msg
= XCAR (Vmessage_stack
);
8417 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8419 message3_nolog (msg
, 0, 0);
8423 /* Handler for record_unwind_protect calling pop_message. */
8426 pop_message_unwind (dummy
)
8433 /* Pop the top-most entry off Vmessage_stack. */
8438 xassert (CONSP (Vmessage_stack
));
8439 Vmessage_stack
= XCDR (Vmessage_stack
);
8443 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8444 exits. If the stack is not empty, we have a missing pop_message
8448 check_message_stack ()
8450 if (!NILP (Vmessage_stack
))
8455 /* Truncate to NCHARS what will be displayed in the echo area the next
8456 time we display it---but don't redisplay it now. */
8459 truncate_echo_area (nchars
)
8463 echo_area_buffer
[0] = Qnil
;
8464 /* A null message buffer means that the frame hasn't really been
8465 initialized yet. Error messages get reported properly by
8466 cmd_error, so this must be just an informative message; toss it. */
8467 else if (!noninteractive
8469 && !NILP (echo_area_buffer
[0]))
8471 struct frame
*sf
= SELECTED_FRAME ();
8472 if (FRAME_MESSAGE_BUF (sf
))
8473 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8478 /* Helper function for truncate_echo_area. Truncate the current
8479 message to at most NCHARS characters. */
8482 truncate_message_1 (nchars
, a2
, a3
, a4
)
8487 if (BEG
+ nchars
< Z
)
8488 del_range (BEG
+ nchars
, Z
);
8490 echo_area_buffer
[0] = Qnil
;
8495 /* Set the current message to a substring of S or STRING.
8497 If STRING is a Lisp string, set the message to the first NBYTES
8498 bytes from STRING. NBYTES zero means use the whole string. If
8499 STRING is multibyte, the message will be displayed multibyte.
8501 If S is not null, set the message to the first LEN bytes of S. LEN
8502 zero means use the whole string. MULTIBYTE_P non-zero means S is
8503 multibyte. Display the message multibyte in that case.
8505 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8506 to t before calling set_message_1 (which calls insert).
8510 set_message (s
, string
, nbytes
, multibyte_p
)
8513 int nbytes
, multibyte_p
;
8515 message_enable_multibyte
8516 = ((s
&& multibyte_p
)
8517 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8519 with_echo_area_buffer (0, 0, set_message_1
,
8520 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8521 message_buf_print
= 0;
8522 help_echo_showing_p
= 0;
8526 /* Helper function for set_message. Arguments have the same meaning
8527 as there, with A1 corresponding to S and A2 corresponding to STRING
8528 This function is called with the echo area buffer being
8532 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8535 EMACS_INT nbytes
, multibyte_p
;
8537 const char *s
= (const char *) a1
;
8538 Lisp_Object string
= a2
;
8540 /* Change multibyteness of the echo buffer appropriately. */
8541 if (message_enable_multibyte
8542 != !NILP (current_buffer
->enable_multibyte_characters
))
8543 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8545 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8547 /* Insert new message at BEG. */
8548 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8551 if (STRINGP (string
))
8556 nbytes
= SBYTES (string
);
8557 nchars
= string_byte_to_char (string
, nbytes
);
8559 /* This function takes care of single/multibyte conversion. We
8560 just have to ensure that the echo area buffer has the right
8561 setting of enable_multibyte_characters. */
8562 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8567 nbytes
= strlen (s
);
8569 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8571 /* Convert from multi-byte to single-byte. */
8573 unsigned char work
[1];
8575 /* Convert a multibyte string to single-byte. */
8576 for (i
= 0; i
< nbytes
; i
+= n
)
8578 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8579 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
8581 : multibyte_char_to_unibyte (c
, Qnil
));
8582 insert_1_both (work
, 1, 1, 1, 0, 0);
8585 else if (!multibyte_p
8586 && !NILP (current_buffer
->enable_multibyte_characters
))
8588 /* Convert from single-byte to multi-byte. */
8590 const unsigned char *msg
= (const unsigned char *) s
;
8591 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8593 /* Convert a single-byte string to multibyte. */
8594 for (i
= 0; i
< nbytes
; i
++)
8596 c
= unibyte_char_to_multibyte (msg
[i
]);
8597 n
= CHAR_STRING (c
, str
);
8598 insert_1_both (str
, 1, n
, 1, 0, 0);
8602 insert_1 (s
, nbytes
, 1, 0, 0);
8609 /* Clear messages. CURRENT_P non-zero means clear the current
8610 message. LAST_DISPLAYED_P non-zero means clear the message
8614 clear_message (current_p
, last_displayed_p
)
8615 int current_p
, last_displayed_p
;
8619 echo_area_buffer
[0] = Qnil
;
8620 message_cleared_p
= 1;
8623 if (last_displayed_p
)
8624 echo_area_buffer
[1] = Qnil
;
8626 message_buf_print
= 0;
8629 /* Clear garbaged frames.
8631 This function is used where the old redisplay called
8632 redraw_garbaged_frames which in turn called redraw_frame which in
8633 turn called clear_frame. The call to clear_frame was a source of
8634 flickering. I believe a clear_frame is not necessary. It should
8635 suffice in the new redisplay to invalidate all current matrices,
8636 and ensure a complete redisplay of all windows. */
8639 clear_garbaged_frames ()
8643 Lisp_Object tail
, frame
;
8644 int changed_count
= 0;
8646 FOR_EACH_FRAME (tail
, frame
)
8648 struct frame
*f
= XFRAME (frame
);
8650 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8654 Fredraw_frame (frame
);
8655 f
->force_flush_display_p
= 1;
8657 clear_current_matrices (f
);
8666 ++windows_or_buffers_changed
;
8671 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8672 is non-zero update selected_frame. Value is non-zero if the
8673 mini-windows height has been changed. */
8676 echo_area_display (update_frame_p
)
8679 Lisp_Object mini_window
;
8682 int window_height_changed_p
= 0;
8683 struct frame
*sf
= SELECTED_FRAME ();
8685 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8686 w
= XWINDOW (mini_window
);
8687 f
= XFRAME (WINDOW_FRAME (w
));
8689 /* Don't display if frame is invisible or not yet initialized. */
8690 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8693 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8695 #ifdef HAVE_WINDOW_SYSTEM
8696 /* When Emacs starts, selected_frame may be a visible terminal
8697 frame, even if we run under a window system. If we let this
8698 through, a message would be displayed on the terminal. */
8699 if (EQ (selected_frame
, Vterminal_frame
)
8700 && !NILP (Vwindow_system
))
8702 #endif /* HAVE_WINDOW_SYSTEM */
8705 /* Redraw garbaged frames. */
8707 clear_garbaged_frames ();
8709 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8711 echo_area_window
= mini_window
;
8712 window_height_changed_p
= display_echo_area (w
);
8713 w
->must_be_updated_p
= 1;
8715 /* Update the display, unless called from redisplay_internal.
8716 Also don't update the screen during redisplay itself. The
8717 update will happen at the end of redisplay, and an update
8718 here could cause confusion. */
8719 if (update_frame_p
&& !redisplaying_p
)
8723 /* If the display update has been interrupted by pending
8724 input, update mode lines in the frame. Due to the
8725 pending input, it might have been that redisplay hasn't
8726 been called, so that mode lines above the echo area are
8727 garbaged. This looks odd, so we prevent it here. */
8728 if (!display_completed
)
8729 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8731 if (window_height_changed_p
8732 /* Don't do this if Emacs is shutting down. Redisplay
8733 needs to run hooks. */
8734 && !NILP (Vrun_hooks
))
8736 /* Must update other windows. Likewise as in other
8737 cases, don't let this update be interrupted by
8739 int count
= SPECPDL_INDEX ();
8740 specbind (Qredisplay_dont_pause
, Qt
);
8741 windows_or_buffers_changed
= 1;
8742 redisplay_internal (0);
8743 unbind_to (count
, Qnil
);
8745 else if (FRAME_WINDOW_P (f
) && n
== 0)
8747 /* Window configuration is the same as before.
8748 Can do with a display update of the echo area,
8749 unless we displayed some mode lines. */
8750 update_single_window (w
, 1);
8751 rif
->flush_display (f
);
8754 update_frame (f
, 1, 1);
8756 /* If cursor is in the echo area, make sure that the next
8757 redisplay displays the minibuffer, so that the cursor will
8758 be replaced with what the minibuffer wants. */
8759 if (cursor_in_echo_area
)
8760 ++windows_or_buffers_changed
;
8763 else if (!EQ (mini_window
, selected_window
))
8764 windows_or_buffers_changed
++;
8766 /* The current message is now also the last one displayed. */
8767 echo_area_buffer
[1] = echo_area_buffer
[0];
8769 /* Prevent redisplay optimization in redisplay_internal by resetting
8770 this_line_start_pos. This is done because the mini-buffer now
8771 displays the message instead of its buffer text. */
8772 if (EQ (mini_window
, selected_window
))
8773 CHARPOS (this_line_start_pos
) = 0;
8775 return window_height_changed_p
;
8780 /***********************************************************************
8781 Mode Lines and Frame Titles
8782 ***********************************************************************/
8784 /* A buffer for constructing non-propertized mode-line strings and
8785 frame titles in it; allocated from the heap in init_xdisp and
8786 resized as needed in store_mode_line_noprop_char. */
8788 static char *mode_line_noprop_buf
;
8790 /* The buffer's end, and a current output position in it. */
8792 static char *mode_line_noprop_buf_end
;
8793 static char *mode_line_noprop_ptr
;
8795 #define MODE_LINE_NOPROP_LEN(start) \
8796 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8799 MODE_LINE_DISPLAY
= 0,
8805 /* Alist that caches the results of :propertize.
8806 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8807 static Lisp_Object mode_line_proptrans_alist
;
8809 /* List of strings making up the mode-line. */
8810 static Lisp_Object mode_line_string_list
;
8812 /* Base face property when building propertized mode line string. */
8813 static Lisp_Object mode_line_string_face
;
8814 static Lisp_Object mode_line_string_face_prop
;
8817 /* Unwind data for mode line strings */
8819 static Lisp_Object Vmode_line_unwind_vector
;
8822 format_mode_line_unwind_data (obuf
, save_proptrans
)
8823 struct buffer
*obuf
;
8827 /* Reduce consing by keeping one vector in
8828 Vwith_echo_area_save_vector. */
8829 vector
= Vmode_line_unwind_vector
;
8830 Vmode_line_unwind_vector
= Qnil
;
8833 vector
= Fmake_vector (make_number (7), Qnil
);
8835 AREF (vector
, 0) = make_number (mode_line_target
);
8836 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8837 AREF (vector
, 2) = mode_line_string_list
;
8838 AREF (vector
, 3) = (save_proptrans
? mode_line_proptrans_alist
: Qt
);
8839 AREF (vector
, 4) = mode_line_string_face
;
8840 AREF (vector
, 5) = mode_line_string_face_prop
;
8843 XSETBUFFER (AREF (vector
, 6), obuf
);
8845 AREF (vector
, 6) = Qnil
;
8851 unwind_format_mode_line (vector
)
8854 mode_line_target
= XINT (AREF (vector
, 0));
8855 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8856 mode_line_string_list
= AREF (vector
, 2);
8857 if (! EQ (AREF (vector
, 3), Qt
))
8858 mode_line_proptrans_alist
= AREF (vector
, 3);
8859 mode_line_string_face
= AREF (vector
, 4);
8860 mode_line_string_face_prop
= AREF (vector
, 5);
8862 if (!NILP (AREF (vector
, 6)))
8864 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8865 AREF (vector
, 6) = Qnil
;
8868 Vmode_line_unwind_vector
= vector
;
8873 /* Store a single character C for the frame title in mode_line_noprop_buf.
8874 Re-allocate mode_line_noprop_buf if necessary. */
8878 store_mode_line_noprop_char (char c
)
8880 store_mode_line_noprop_char (c
)
8884 /* If output position has reached the end of the allocated buffer,
8885 double the buffer's size. */
8886 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8888 int len
= MODE_LINE_NOPROP_LEN (0);
8889 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8890 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8891 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8892 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8895 *mode_line_noprop_ptr
++ = c
;
8899 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8900 mode_line_noprop_ptr. STR is the string to store. Do not copy
8901 characters that yield more columns than PRECISION; PRECISION <= 0
8902 means copy the whole string. Pad with spaces until FIELD_WIDTH
8903 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8904 pad. Called from display_mode_element when it is used to build a
8908 store_mode_line_noprop (str
, field_width
, precision
)
8909 const unsigned char *str
;
8910 int field_width
, precision
;
8915 /* Copy at most PRECISION chars from STR. */
8916 nbytes
= strlen (str
);
8917 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8919 store_mode_line_noprop_char (*str
++);
8921 /* Fill up with spaces until FIELD_WIDTH reached. */
8922 while (field_width
> 0
8925 store_mode_line_noprop_char (' ');
8932 /***********************************************************************
8934 ***********************************************************************/
8936 #ifdef HAVE_WINDOW_SYSTEM
8938 /* Set the title of FRAME, if it has changed. The title format is
8939 Vicon_title_format if FRAME is iconified, otherwise it is
8940 frame_title_format. */
8943 x_consider_frame_title (frame
)
8946 struct frame
*f
= XFRAME (frame
);
8948 if (FRAME_WINDOW_P (f
)
8949 || FRAME_MINIBUF_ONLY_P (f
)
8950 || f
->explicit_name
)
8952 /* Do we have more than one visible frame on this X display? */
8959 int count
= SPECPDL_INDEX ();
8961 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8963 Lisp_Object other_frame
= XCAR (tail
);
8964 struct frame
*tf
= XFRAME (other_frame
);
8967 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8968 && !FRAME_MINIBUF_ONLY_P (tf
)
8969 && !EQ (other_frame
, tip_frame
)
8970 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8974 /* Set global variable indicating that multiple frames exist. */
8975 multiple_frames
= CONSP (tail
);
8977 /* Switch to the buffer of selected window of the frame. Set up
8978 mode_line_target so that display_mode_element will output into
8979 mode_line_noprop_buf; then display the title. */
8980 record_unwind_protect (unwind_format_mode_line
,
8981 format_mode_line_unwind_data (current_buffer
, 0));
8983 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8984 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8986 mode_line_target
= MODE_LINE_TITLE
;
8987 title_start
= MODE_LINE_NOPROP_LEN (0);
8988 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8989 NULL
, DEFAULT_FACE_ID
);
8990 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8991 len
= MODE_LINE_NOPROP_LEN (title_start
);
8992 title
= mode_line_noprop_buf
+ title_start
;
8993 unbind_to (count
, Qnil
);
8995 /* Set the title only if it's changed. This avoids consing in
8996 the common case where it hasn't. (If it turns out that we've
8997 already wasted too much time by walking through the list with
8998 display_mode_element, then we might need to optimize at a
8999 higher level than this.) */
9000 if (! STRINGP (f
->name
)
9001 || SBYTES (f
->name
) != len
9002 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9003 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9007 #endif /* not HAVE_WINDOW_SYSTEM */
9012 /***********************************************************************
9014 ***********************************************************************/
9017 /* Prepare for redisplay by updating menu-bar item lists when
9018 appropriate. This can call eval. */
9021 prepare_menu_bars ()
9024 struct gcpro gcpro1
, gcpro2
;
9026 Lisp_Object tooltip_frame
;
9028 #ifdef HAVE_WINDOW_SYSTEM
9029 tooltip_frame
= tip_frame
;
9031 tooltip_frame
= Qnil
;
9034 /* Update all frame titles based on their buffer names, etc. We do
9035 this before the menu bars so that the buffer-menu will show the
9036 up-to-date frame titles. */
9037 #ifdef HAVE_WINDOW_SYSTEM
9038 if (windows_or_buffers_changed
|| update_mode_lines
)
9040 Lisp_Object tail
, frame
;
9042 FOR_EACH_FRAME (tail
, frame
)
9045 if (!EQ (frame
, tooltip_frame
)
9046 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9047 x_consider_frame_title (frame
);
9050 #endif /* HAVE_WINDOW_SYSTEM */
9052 /* Update the menu bar item lists, if appropriate. This has to be
9053 done before any actual redisplay or generation of display lines. */
9054 all_windows
= (update_mode_lines
9055 || buffer_shared
> 1
9056 || windows_or_buffers_changed
);
9059 Lisp_Object tail
, frame
;
9060 int count
= SPECPDL_INDEX ();
9061 /* 1 means that update_menu_bar has run its hooks
9062 so any further calls to update_menu_bar shouldn't do so again. */
9063 int menu_bar_hooks_run
= 0;
9065 record_unwind_save_match_data ();
9067 FOR_EACH_FRAME (tail
, frame
)
9071 /* Ignore tooltip frame. */
9072 if (EQ (frame
, tooltip_frame
))
9075 /* If a window on this frame changed size, report that to
9076 the user and clear the size-change flag. */
9077 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9079 Lisp_Object functions
;
9081 /* Clear flag first in case we get an error below. */
9082 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9083 functions
= Vwindow_size_change_functions
;
9084 GCPRO2 (tail
, functions
);
9086 while (CONSP (functions
))
9088 call1 (XCAR (functions
), frame
);
9089 functions
= XCDR (functions
);
9095 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9096 #ifdef HAVE_WINDOW_SYSTEM
9097 update_tool_bar (f
, 0);
9099 mac_update_title_bar (f
, 0);
9105 unbind_to (count
, Qnil
);
9109 struct frame
*sf
= SELECTED_FRAME ();
9110 update_menu_bar (sf
, 1, 0);
9111 #ifdef HAVE_WINDOW_SYSTEM
9112 update_tool_bar (sf
, 1);
9114 mac_update_title_bar (sf
, 1);
9119 /* Motif needs this. See comment in xmenu.c. Turn it off when
9120 pending_menu_activation is not defined. */
9121 #ifdef USE_X_TOOLKIT
9122 pending_menu_activation
= 0;
9127 /* Update the menu bar item list for frame F. This has to be done
9128 before we start to fill in any display lines, because it can call
9131 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9133 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9134 already ran the menu bar hooks for this redisplay, so there
9135 is no need to run them again. The return value is the
9136 updated value of this flag, to pass to the next call. */
9139 update_menu_bar (f
, save_match_data
, hooks_run
)
9141 int save_match_data
;
9145 register struct window
*w
;
9147 /* If called recursively during a menu update, do nothing. This can
9148 happen when, for instance, an activate-menubar-hook causes a
9150 if (inhibit_menubar_update
)
9153 window
= FRAME_SELECTED_WINDOW (f
);
9154 w
= XWINDOW (window
);
9156 #if 0 /* The if statement below this if statement used to include the
9157 condition !NILP (w->update_mode_line), rather than using
9158 update_mode_lines directly, and this if statement may have
9159 been added to make that condition work. Now the if
9160 statement below matches its comment, this isn't needed. */
9161 if (update_mode_lines
)
9162 w
->update_mode_line
= Qt
;
9165 if (FRAME_WINDOW_P (f
)
9167 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9168 || defined (USE_GTK)
9169 FRAME_EXTERNAL_MENU_BAR (f
)
9171 FRAME_MENU_BAR_LINES (f
) > 0
9173 : FRAME_MENU_BAR_LINES (f
) > 0)
9175 /* If the user has switched buffers or windows, we need to
9176 recompute to reflect the new bindings. But we'll
9177 recompute when update_mode_lines is set too; that means
9178 that people can use force-mode-line-update to request
9179 that the menu bar be recomputed. The adverse effect on
9180 the rest of the redisplay algorithm is about the same as
9181 windows_or_buffers_changed anyway. */
9182 if (windows_or_buffers_changed
9183 /* This used to test w->update_mode_line, but we believe
9184 there is no need to recompute the menu in that case. */
9185 || update_mode_lines
9186 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9187 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9188 != !NILP (w
->last_had_star
))
9189 || ((!NILP (Vtransient_mark_mode
)
9190 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9191 != !NILP (w
->region_showing
)))
9193 struct buffer
*prev
= current_buffer
;
9194 int count
= SPECPDL_INDEX ();
9196 specbind (Qinhibit_menubar_update
, Qt
);
9198 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9199 if (save_match_data
)
9200 record_unwind_save_match_data ();
9201 if (NILP (Voverriding_local_map_menu_flag
))
9203 specbind (Qoverriding_terminal_local_map
, Qnil
);
9204 specbind (Qoverriding_local_map
, Qnil
);
9209 /* Run the Lucid hook. */
9210 safe_run_hooks (Qactivate_menubar_hook
);
9212 /* If it has changed current-menubar from previous value,
9213 really recompute the menu-bar from the value. */
9214 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9215 call0 (Qrecompute_lucid_menubar
);
9217 safe_run_hooks (Qmenu_bar_update_hook
);
9222 XSETFRAME (Vmenu_updating_frame
, f
);
9223 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9225 /* Redisplay the menu bar in case we changed it. */
9226 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9227 || defined (USE_GTK)
9228 if (FRAME_WINDOW_P (f
))
9231 /* All frames on Mac OS share the same menubar. So only
9232 the selected frame should be allowed to set it. */
9233 if (f
== SELECTED_FRAME ())
9235 set_frame_menubar (f
, 0, 0);
9238 /* On a terminal screen, the menu bar is an ordinary screen
9239 line, and this makes it get updated. */
9240 w
->update_mode_line
= Qt
;
9241 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9242 /* In the non-toolkit version, the menu bar is an ordinary screen
9243 line, and this makes it get updated. */
9244 w
->update_mode_line
= Qt
;
9245 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9247 unbind_to (count
, Qnil
);
9248 set_buffer_internal_1 (prev
);
9257 /***********************************************************************
9259 ***********************************************************************/
9261 #ifdef HAVE_WINDOW_SYSTEM
9264 Nominal cursor position -- where to draw output.
9265 HPOS and VPOS are window relative glyph matrix coordinates.
9266 X and Y are window relative pixel coordinates. */
9268 struct cursor_pos output_cursor
;
9272 Set the global variable output_cursor to CURSOR. All cursor
9273 positions are relative to updated_window. */
9276 set_output_cursor (cursor
)
9277 struct cursor_pos
*cursor
;
9279 output_cursor
.hpos
= cursor
->hpos
;
9280 output_cursor
.vpos
= cursor
->vpos
;
9281 output_cursor
.x
= cursor
->x
;
9282 output_cursor
.y
= cursor
->y
;
9287 Set a nominal cursor position.
9289 HPOS and VPOS are column/row positions in a window glyph matrix. X
9290 and Y are window text area relative pixel positions.
9292 If this is done during an update, updated_window will contain the
9293 window that is being updated and the position is the future output
9294 cursor position for that window. If updated_window is null, use
9295 selected_window and display the cursor at the given position. */
9298 x_cursor_to (vpos
, hpos
, y
, x
)
9299 int vpos
, hpos
, y
, x
;
9303 /* If updated_window is not set, work on selected_window. */
9307 w
= XWINDOW (selected_window
);
9309 /* Set the output cursor. */
9310 output_cursor
.hpos
= hpos
;
9311 output_cursor
.vpos
= vpos
;
9312 output_cursor
.x
= x
;
9313 output_cursor
.y
= y
;
9315 /* If not called as part of an update, really display the cursor.
9316 This will also set the cursor position of W. */
9317 if (updated_window
== NULL
)
9320 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9321 if (rif
->flush_display_optional
)
9322 rif
->flush_display_optional (SELECTED_FRAME ());
9327 #endif /* HAVE_WINDOW_SYSTEM */
9330 /***********************************************************************
9332 ***********************************************************************/
9334 #ifdef HAVE_WINDOW_SYSTEM
9336 /* Where the mouse was last time we reported a mouse event. */
9338 FRAME_PTR last_mouse_frame
;
9340 /* Tool-bar item index of the item on which a mouse button was pressed
9343 int last_tool_bar_item
;
9346 /* Update the tool-bar item list for frame F. This has to be done
9347 before we start to fill in any display lines. Called from
9348 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9349 and restore it here. */
9352 update_tool_bar (f
, save_match_data
)
9354 int save_match_data
;
9357 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9359 int do_update
= WINDOWP (f
->tool_bar_window
)
9360 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9368 window
= FRAME_SELECTED_WINDOW (f
);
9369 w
= XWINDOW (window
);
9371 /* If the user has switched buffers or windows, we need to
9372 recompute to reflect the new bindings. But we'll
9373 recompute when update_mode_lines is set too; that means
9374 that people can use force-mode-line-update to request
9375 that the menu bar be recomputed. The adverse effect on
9376 the rest of the redisplay algorithm is about the same as
9377 windows_or_buffers_changed anyway. */
9378 if (windows_or_buffers_changed
9379 || !NILP (w
->update_mode_line
)
9380 || update_mode_lines
9381 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9382 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9383 != !NILP (w
->last_had_star
))
9384 || ((!NILP (Vtransient_mark_mode
)
9385 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9386 != !NILP (w
->region_showing
)))
9388 struct buffer
*prev
= current_buffer
;
9389 int count
= SPECPDL_INDEX ();
9390 Lisp_Object new_tool_bar
;
9392 struct gcpro gcpro1
;
9394 /* Set current_buffer to the buffer of the selected
9395 window of the frame, so that we get the right local
9397 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9399 /* Save match data, if we must. */
9400 if (save_match_data
)
9401 record_unwind_save_match_data ();
9403 /* Make sure that we don't accidentally use bogus keymaps. */
9404 if (NILP (Voverriding_local_map_menu_flag
))
9406 specbind (Qoverriding_terminal_local_map
, Qnil
);
9407 specbind (Qoverriding_local_map
, Qnil
);
9410 GCPRO1 (new_tool_bar
);
9412 /* Build desired tool-bar items from keymaps. */
9413 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9416 /* Redisplay the tool-bar if we changed it. */
9417 if (new_n_tool_bar
!= f
->n_tool_bar_items
9418 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9420 /* Redisplay that happens asynchronously due to an expose event
9421 may access f->tool_bar_items. Make sure we update both
9422 variables within BLOCK_INPUT so no such event interrupts. */
9424 f
->tool_bar_items
= new_tool_bar
;
9425 f
->n_tool_bar_items
= new_n_tool_bar
;
9426 w
->update_mode_line
= Qt
;
9432 unbind_to (count
, Qnil
);
9433 set_buffer_internal_1 (prev
);
9439 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9440 F's desired tool-bar contents. F->tool_bar_items must have
9441 been set up previously by calling prepare_menu_bars. */
9444 build_desired_tool_bar_string (f
)
9447 int i
, size
, size_needed
;
9448 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9449 Lisp_Object image
, plist
, props
;
9451 image
= plist
= props
= Qnil
;
9452 GCPRO3 (image
, plist
, props
);
9454 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9455 Otherwise, make a new string. */
9457 /* The size of the string we might be able to reuse. */
9458 size
= (STRINGP (f
->desired_tool_bar_string
)
9459 ? SCHARS (f
->desired_tool_bar_string
)
9462 /* We need one space in the string for each image. */
9463 size_needed
= f
->n_tool_bar_items
;
9465 /* Reuse f->desired_tool_bar_string, if possible. */
9466 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9467 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9471 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9472 Fremove_text_properties (make_number (0), make_number (size
),
9473 props
, f
->desired_tool_bar_string
);
9476 /* Put a `display' property on the string for the images to display,
9477 put a `menu_item' property on tool-bar items with a value that
9478 is the index of the item in F's tool-bar item vector. */
9479 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9481 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9483 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9484 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9485 int hmargin
, vmargin
, relief
, idx
, end
;
9486 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9488 /* If image is a vector, choose the image according to the
9490 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9491 if (VECTORP (image
))
9495 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9496 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9499 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9500 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9502 xassert (ASIZE (image
) >= idx
);
9503 image
= AREF (image
, idx
);
9508 /* Ignore invalid image specifications. */
9509 if (!valid_image_p (image
))
9512 /* Display the tool-bar button pressed, or depressed. */
9513 plist
= Fcopy_sequence (XCDR (image
));
9515 /* Compute margin and relief to draw. */
9516 relief
= (tool_bar_button_relief
>= 0
9517 ? tool_bar_button_relief
9518 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9519 hmargin
= vmargin
= relief
;
9521 if (INTEGERP (Vtool_bar_button_margin
)
9522 && XINT (Vtool_bar_button_margin
) > 0)
9524 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9525 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9527 else if (CONSP (Vtool_bar_button_margin
))
9529 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9530 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9531 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9533 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9534 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9535 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9538 if (auto_raise_tool_bar_buttons_p
)
9540 /* Add a `:relief' property to the image spec if the item is
9544 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9551 /* If image is selected, display it pressed, i.e. with a
9552 negative relief. If it's not selected, display it with a
9554 plist
= Fplist_put (plist
, QCrelief
,
9556 ? make_number (-relief
)
9557 : make_number (relief
)));
9562 /* Put a margin around the image. */
9563 if (hmargin
|| vmargin
)
9565 if (hmargin
== vmargin
)
9566 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9568 plist
= Fplist_put (plist
, QCmargin
,
9569 Fcons (make_number (hmargin
),
9570 make_number (vmargin
)));
9573 /* If button is not enabled, and we don't have special images
9574 for the disabled state, make the image appear disabled by
9575 applying an appropriate algorithm to it. */
9576 if (!enabled_p
&& idx
< 0)
9577 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9579 /* Put a `display' text property on the string for the image to
9580 display. Put a `menu-item' property on the string that gives
9581 the start of this item's properties in the tool-bar items
9583 image
= Fcons (Qimage
, plist
);
9584 props
= list4 (Qdisplay
, image
,
9585 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9587 /* Let the last image hide all remaining spaces in the tool bar
9588 string. The string can be longer than needed when we reuse a
9590 if (i
+ 1 == f
->n_tool_bar_items
)
9591 end
= SCHARS (f
->desired_tool_bar_string
);
9594 Fadd_text_properties (make_number (i
), make_number (end
),
9595 props
, f
->desired_tool_bar_string
);
9603 /* Display one line of the tool-bar of frame IT->f.
9605 HEIGHT specifies the desired height of the tool-bar line.
9606 If the actual height of the glyph row is less than HEIGHT, the
9607 row's height is increased to HEIGHT, and the icons are centered
9608 vertically in the new height.
9610 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
9611 count a final empty row in case the tool-bar width exactly matches
9616 display_tool_bar_line (it
, height
)
9620 struct glyph_row
*row
= it
->glyph_row
;
9621 int max_x
= it
->last_visible_x
;
9624 prepare_desired_row (row
);
9625 row
->y
= it
->current_y
;
9627 /* Note that this isn't made use of if the face hasn't a box,
9628 so there's no need to check the face here. */
9629 it
->start_of_box_run_p
= 1;
9631 while (it
->current_x
< max_x
)
9633 int x
, n_glyphs_before
, i
, nglyphs
;
9634 struct it it_before
;
9636 /* Get the next display element. */
9637 if (!get_next_display_element (it
))
9639 /* Don't count empty row if we are counting needed tool-bar lines. */
9640 if (height
< 0 && !it
->hpos
)
9645 /* Produce glyphs. */
9646 n_glyphs_before
= row
->used
[TEXT_AREA
];
9649 PRODUCE_GLYPHS (it
);
9651 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
9653 x
= it_before
.current_x
;
9656 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9658 if (x
+ glyph
->pixel_width
> max_x
)
9660 /* Glyph doesn't fit on line. Backtrack. */
9661 row
->used
[TEXT_AREA
] = n_glyphs_before
;
9663 /* If this is the only glyph on this line, it will never fit on the
9664 toolbar, so skip it. But ensure there is at least one glyph,
9665 so we don't accidentally disable the tool-bar. */
9666 if (n_glyphs_before
== 0
9667 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
9673 x
+= glyph
->pixel_width
;
9677 /* Stop at line ends. */
9678 if (ITERATOR_AT_END_OF_LINE_P (it
))
9681 set_iterator_to_next (it
, 1);
9686 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9687 /* Use default face for the border below the tool bar. */
9688 if (!row
->displays_text_p
)
9689 it
->face_id
= DEFAULT_FACE_ID
;
9690 extend_face_to_end_of_line (it
);
9691 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9692 last
->right_box_line_p
= 1;
9693 if (last
== row
->glyphs
[TEXT_AREA
])
9694 last
->left_box_line_p
= 1;
9696 /* Make line the desired height and center it vertically. */
9697 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
9699 /* Don't add more than one line height. */
9700 height
%= FRAME_LINE_HEIGHT (it
->f
);
9701 it
->max_ascent
+= height
/ 2;
9702 it
->max_descent
+= (height
+ 1) / 2;
9705 compute_line_metrics (it
);
9707 /* If line is empty, make it occupy the rest of the tool-bar. */
9708 if (!row
->displays_text_p
)
9710 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9711 row
->ascent
= row
->phys_ascent
= 0;
9712 row
->extra_line_spacing
= 0;
9715 row
->full_width_p
= 1;
9716 row
->continued_p
= 0;
9717 row
->truncated_on_left_p
= 0;
9718 row
->truncated_on_right_p
= 0;
9720 it
->current_x
= it
->hpos
= 0;
9721 it
->current_y
+= row
->height
;
9727 /* Max tool-bar height. */
9729 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
9730 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
9732 /* Value is the number of screen lines needed to make all tool-bar
9733 items of frame F visible. The number of actual rows needed is
9734 returned in *N_ROWS if non-NULL. */
9737 tool_bar_lines_needed (f
, n_rows
)
9741 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9743 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
9744 the desired matrix, so use (unused) mode-line row as temporary row to
9745 avoid destroying the first tool-bar row. */
9746 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
9748 /* Initialize an iterator for iteration over
9749 F->desired_tool_bar_string in the tool-bar window of frame F. */
9750 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
9751 it
.first_visible_x
= 0;
9752 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9753 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9755 while (!ITERATOR_AT_END_P (&it
))
9757 clear_glyph_row (temp_row
);
9758 it
.glyph_row
= temp_row
;
9759 display_tool_bar_line (&it
, -1);
9761 clear_glyph_row (temp_row
);
9763 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
9765 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
9767 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9771 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9773 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9782 frame
= selected_frame
;
9784 CHECK_FRAME (frame
);
9787 if (WINDOWP (f
->tool_bar_window
)
9788 || (w
= XWINDOW (f
->tool_bar_window
),
9789 WINDOW_TOTAL_LINES (w
) > 0))
9791 update_tool_bar (f
, 1);
9792 if (f
->n_tool_bar_items
)
9794 build_desired_tool_bar_string (f
);
9795 nlines
= tool_bar_lines_needed (f
, NULL
);
9799 return make_number (nlines
);
9803 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9804 height should be changed. */
9807 redisplay_tool_bar (f
)
9812 struct glyph_row
*row
;
9813 int change_height_p
= 0;
9816 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9817 update_frame_tool_bar (f
);
9821 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9822 do anything. This means you must start with tool-bar-lines
9823 non-zero to get the auto-sizing effect. Or in other words, you
9824 can turn off tool-bars by specifying tool-bar-lines zero. */
9825 if (!WINDOWP (f
->tool_bar_window
)
9826 || (w
= XWINDOW (f
->tool_bar_window
),
9827 WINDOW_TOTAL_LINES (w
) == 0))
9830 /* Set up an iterator for the tool-bar window. */
9831 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9832 it
.first_visible_x
= 0;
9833 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9836 /* Build a string that represents the contents of the tool-bar. */
9837 build_desired_tool_bar_string (f
);
9838 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9840 if (f
->n_tool_bar_rows
== 0)
9844 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
9845 nlines
!= WINDOW_TOTAL_LINES (w
)))
9847 extern Lisp_Object Qtool_bar_lines
;
9849 int old_height
= WINDOW_TOTAL_LINES (w
);
9851 XSETFRAME (frame
, f
);
9852 Fmodify_frame_parameters (frame
,
9853 Fcons (Fcons (Qtool_bar_lines
,
9854 make_number (nlines
)),
9856 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9858 clear_glyph_matrix (w
->desired_matrix
);
9859 fonts_changed_p
= 1;
9865 /* Display as many lines as needed to display all tool-bar items. */
9867 if (f
->n_tool_bar_rows
> 0)
9869 int border
, rows
, height
, extra
;
9871 if (INTEGERP (Vtool_bar_border
))
9872 border
= XINT (Vtool_bar_border
);
9873 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
9874 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
9875 else if (EQ (Vtool_bar_border
, Qborder_width
))
9876 border
= f
->border_width
;
9882 rows
= f
->n_tool_bar_rows
;
9883 height
= max (1, (it
.last_visible_y
- border
) / rows
);
9884 extra
= it
.last_visible_y
- border
- height
* rows
;
9886 while (it
.current_y
< it
.last_visible_y
)
9889 if (extra
> 0 && rows
-- > 0)
9891 h
= (extra
+ rows
- 1) / rows
;
9894 display_tool_bar_line (&it
, height
+ h
);
9899 while (it
.current_y
< it
.last_visible_y
)
9900 display_tool_bar_line (&it
, 0);
9903 /* It doesn't make much sense to try scrolling in the tool-bar
9904 window, so don't do it. */
9905 w
->desired_matrix
->no_scrolling_p
= 1;
9906 w
->must_be_updated_p
= 1;
9908 if (auto_resize_tool_bars_p
)
9911 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
9913 /* If we couldn't display everything, change the tool-bar's
9914 height if there is room for more. */
9915 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
9916 && it
.current_y
< max_tool_bar_height
)
9917 change_height_p
= 1;
9919 row
= it
.glyph_row
- 1;
9921 /* If there are blank lines at the end, except for a partially
9922 visible blank line at the end that is smaller than
9923 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9924 if (!row
->displays_text_p
9925 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9926 change_height_p
= 1;
9928 /* If row displays tool-bar items, but is partially visible,
9929 change the tool-bar's height. */
9930 if (row
->displays_text_p
9931 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
9932 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
9933 change_height_p
= 1;
9935 /* Resize windows as needed by changing the `tool-bar-lines'
9938 && (nlines
= tool_bar_lines_needed (f
, &nrows
),
9939 nlines
!= WINDOW_TOTAL_LINES (w
)))
9941 extern Lisp_Object Qtool_bar_lines
;
9943 int old_height
= WINDOW_TOTAL_LINES (w
);
9945 XSETFRAME (frame
, f
);
9946 Fmodify_frame_parameters (frame
,
9947 Fcons (Fcons (Qtool_bar_lines
,
9948 make_number (nlines
)),
9950 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9952 clear_glyph_matrix (w
->desired_matrix
);
9953 f
->n_tool_bar_rows
= nrows
;
9954 fonts_changed_p
= 1;
9959 return change_height_p
;
9963 /* Get information about the tool-bar item which is displayed in GLYPH
9964 on frame F. Return in *PROP_IDX the index where tool-bar item
9965 properties start in F->tool_bar_items. Value is zero if
9966 GLYPH doesn't display a tool-bar item. */
9969 tool_bar_item_info (f
, glyph
, prop_idx
)
9971 struct glyph
*glyph
;
9978 /* This function can be called asynchronously, which means we must
9979 exclude any possibility that Fget_text_property signals an
9981 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
9982 charpos
= max (0, charpos
);
9984 /* Get the text property `menu-item' at pos. The value of that
9985 property is the start index of this item's properties in
9986 F->tool_bar_items. */
9987 prop
= Fget_text_property (make_number (charpos
),
9988 Qmenu_item
, f
->current_tool_bar_string
);
9989 if (INTEGERP (prop
))
9991 *prop_idx
= XINT (prop
);
10001 /* Get information about the tool-bar item at position X/Y on frame F.
10002 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10003 the current matrix of the tool-bar window of F, or NULL if not
10004 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10005 item in F->tool_bar_items. Value is
10007 -1 if X/Y is not on a tool-bar item
10008 0 if X/Y is on the same item that was highlighted before.
10012 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10015 struct glyph
**glyph
;
10016 int *hpos
, *vpos
, *prop_idx
;
10018 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10019 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10022 /* Find the glyph under X/Y. */
10023 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10024 if (*glyph
== NULL
)
10027 /* Get the start of this tool-bar item's properties in
10028 f->tool_bar_items. */
10029 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10032 /* Is mouse on the highlighted item? */
10033 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10034 && *vpos
>= dpyinfo
->mouse_face_beg_row
10035 && *vpos
<= dpyinfo
->mouse_face_end_row
10036 && (*vpos
> dpyinfo
->mouse_face_beg_row
10037 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10038 && (*vpos
< dpyinfo
->mouse_face_end_row
10039 || *hpos
< dpyinfo
->mouse_face_end_col
10040 || dpyinfo
->mouse_face_past_end
))
10048 Handle mouse button event on the tool-bar of frame F, at
10049 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10050 0 for button release. MODIFIERS is event modifiers for button
10054 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10057 unsigned int modifiers
;
10059 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10060 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10061 int hpos
, vpos
, prop_idx
;
10062 struct glyph
*glyph
;
10063 Lisp_Object enabled_p
;
10065 /* If not on the highlighted tool-bar item, return. */
10066 frame_to_window_pixel_xy (w
, &x
, &y
);
10067 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10070 /* If item is disabled, do nothing. */
10071 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10072 if (NILP (enabled_p
))
10077 /* Show item in pressed state. */
10078 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10079 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10080 last_tool_bar_item
= prop_idx
;
10084 Lisp_Object key
, frame
;
10085 struct input_event event
;
10086 EVENT_INIT (event
);
10088 /* Show item in released state. */
10089 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10090 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10092 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10094 XSETFRAME (frame
, f
);
10095 event
.kind
= TOOL_BAR_EVENT
;
10096 event
.frame_or_window
= frame
;
10098 kbd_buffer_store_event (&event
);
10100 event
.kind
= TOOL_BAR_EVENT
;
10101 event
.frame_or_window
= frame
;
10103 event
.modifiers
= modifiers
;
10104 kbd_buffer_store_event (&event
);
10105 last_tool_bar_item
= -1;
10110 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10111 tool-bar window-relative coordinates X/Y. Called from
10112 note_mouse_highlight. */
10115 note_tool_bar_highlight (f
, x
, y
)
10119 Lisp_Object window
= f
->tool_bar_window
;
10120 struct window
*w
= XWINDOW (window
);
10121 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10123 struct glyph
*glyph
;
10124 struct glyph_row
*row
;
10126 Lisp_Object enabled_p
;
10128 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10129 int mouse_down_p
, rc
;
10131 /* Function note_mouse_highlight is called with negative x(y
10132 values when mouse moves outside of the frame. */
10133 if (x
<= 0 || y
<= 0)
10135 clear_mouse_face (dpyinfo
);
10139 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10142 /* Not on tool-bar item. */
10143 clear_mouse_face (dpyinfo
);
10147 /* On same tool-bar item as before. */
10148 goto set_help_echo
;
10150 clear_mouse_face (dpyinfo
);
10152 /* Mouse is down, but on different tool-bar item? */
10153 mouse_down_p
= (dpyinfo
->grabbed
10154 && f
== last_mouse_frame
10155 && FRAME_LIVE_P (f
));
10157 && last_tool_bar_item
!= prop_idx
)
10160 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10161 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10163 /* If tool-bar item is not enabled, don't highlight it. */
10164 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10165 if (!NILP (enabled_p
))
10167 /* Compute the x-position of the glyph. In front and past the
10168 image is a space. We include this in the highlighted area. */
10169 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10170 for (i
= x
= 0; i
< hpos
; ++i
)
10171 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10173 /* Record this as the current active region. */
10174 dpyinfo
->mouse_face_beg_col
= hpos
;
10175 dpyinfo
->mouse_face_beg_row
= vpos
;
10176 dpyinfo
->mouse_face_beg_x
= x
;
10177 dpyinfo
->mouse_face_beg_y
= row
->y
;
10178 dpyinfo
->mouse_face_past_end
= 0;
10180 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10181 dpyinfo
->mouse_face_end_row
= vpos
;
10182 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10183 dpyinfo
->mouse_face_end_y
= row
->y
;
10184 dpyinfo
->mouse_face_window
= window
;
10185 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10187 /* Display it as active. */
10188 show_mouse_face (dpyinfo
, draw
);
10189 dpyinfo
->mouse_face_image_state
= draw
;
10194 /* Set help_echo_string to a help string to display for this tool-bar item.
10195 XTread_socket does the rest. */
10196 help_echo_object
= help_echo_window
= Qnil
;
10197 help_echo_pos
= -1;
10198 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10199 if (NILP (help_echo_string
))
10200 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10203 #endif /* HAVE_WINDOW_SYSTEM */
10207 /************************************************************************
10208 Horizontal scrolling
10209 ************************************************************************/
10211 static int hscroll_window_tree
P_ ((Lisp_Object
));
10212 static int hscroll_windows
P_ ((Lisp_Object
));
10214 /* For all leaf windows in the window tree rooted at WINDOW, set their
10215 hscroll value so that PT is (i) visible in the window, and (ii) so
10216 that it is not within a certain margin at the window's left and
10217 right border. Value is non-zero if any window's hscroll has been
10221 hscroll_window_tree (window
)
10222 Lisp_Object window
;
10224 int hscrolled_p
= 0;
10225 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10226 int hscroll_step_abs
= 0;
10227 double hscroll_step_rel
= 0;
10229 if (hscroll_relative_p
)
10231 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10232 if (hscroll_step_rel
< 0)
10234 hscroll_relative_p
= 0;
10235 hscroll_step_abs
= 0;
10238 else if (INTEGERP (Vhscroll_step
))
10240 hscroll_step_abs
= XINT (Vhscroll_step
);
10241 if (hscroll_step_abs
< 0)
10242 hscroll_step_abs
= 0;
10245 hscroll_step_abs
= 0;
10247 while (WINDOWP (window
))
10249 struct window
*w
= XWINDOW (window
);
10251 if (WINDOWP (w
->hchild
))
10252 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10253 else if (WINDOWP (w
->vchild
))
10254 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10255 else if (w
->cursor
.vpos
>= 0)
10258 int text_area_width
;
10259 struct glyph_row
*current_cursor_row
10260 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10261 struct glyph_row
*desired_cursor_row
10262 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10263 struct glyph_row
*cursor_row
10264 = (desired_cursor_row
->enabled_p
10265 ? desired_cursor_row
10266 : current_cursor_row
);
10268 text_area_width
= window_box_width (w
, TEXT_AREA
);
10270 /* Scroll when cursor is inside this scroll margin. */
10271 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10273 if ((XFASTINT (w
->hscroll
)
10274 && w
->cursor
.x
<= h_margin
)
10275 || (cursor_row
->enabled_p
10276 && cursor_row
->truncated_on_right_p
10277 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
10281 struct buffer
*saved_current_buffer
;
10285 /* Find point in a display of infinite width. */
10286 saved_current_buffer
= current_buffer
;
10287 current_buffer
= XBUFFER (w
->buffer
);
10289 if (w
== XWINDOW (selected_window
))
10290 pt
= BUF_PT (current_buffer
);
10293 pt
= marker_position (w
->pointm
);
10294 pt
= max (BEGV
, pt
);
10298 /* Move iterator to pt starting at cursor_row->start in
10299 a line with infinite width. */
10300 init_to_row_start (&it
, w
, cursor_row
);
10301 it
.last_visible_x
= INFINITY
;
10302 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10303 current_buffer
= saved_current_buffer
;
10305 /* Position cursor in window. */
10306 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10307 hscroll
= max (0, (it
.current_x
10308 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10309 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10310 : (text_area_width
/ 2))))
10311 / FRAME_COLUMN_WIDTH (it
.f
);
10312 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10314 if (hscroll_relative_p
)
10315 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10318 wanted_x
= text_area_width
10319 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10322 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10326 if (hscroll_relative_p
)
10327 wanted_x
= text_area_width
* hscroll_step_rel
10330 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10333 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10335 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10337 /* Don't call Fset_window_hscroll if value hasn't
10338 changed because it will prevent redisplay
10340 if (XFASTINT (w
->hscroll
) != hscroll
)
10342 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10343 w
->hscroll
= make_number (hscroll
);
10352 /* Value is non-zero if hscroll of any leaf window has been changed. */
10353 return hscrolled_p
;
10357 /* Set hscroll so that cursor is visible and not inside horizontal
10358 scroll margins for all windows in the tree rooted at WINDOW. See
10359 also hscroll_window_tree above. Value is non-zero if any window's
10360 hscroll has been changed. If it has, desired matrices on the frame
10361 of WINDOW are cleared. */
10364 hscroll_windows (window
)
10365 Lisp_Object window
;
10369 if (automatic_hscrolling_p
)
10371 hscrolled_p
= hscroll_window_tree (window
);
10373 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10377 return hscrolled_p
;
10382 /************************************************************************
10384 ************************************************************************/
10386 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10387 to a non-zero value. This is sometimes handy to have in a debugger
10392 /* First and last unchanged row for try_window_id. */
10394 int debug_first_unchanged_at_end_vpos
;
10395 int debug_last_unchanged_at_beg_vpos
;
10397 /* Delta vpos and y. */
10399 int debug_dvpos
, debug_dy
;
10401 /* Delta in characters and bytes for try_window_id. */
10403 int debug_delta
, debug_delta_bytes
;
10405 /* Values of window_end_pos and window_end_vpos at the end of
10408 EMACS_INT debug_end_pos
, debug_end_vpos
;
10410 /* Append a string to W->desired_matrix->method. FMT is a printf
10411 format string. A1...A9 are a supplement for a variable-length
10412 argument list. If trace_redisplay_p is non-zero also printf the
10413 resulting string to stderr. */
10416 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10419 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10422 char *method
= w
->desired_matrix
->method
;
10423 int len
= strlen (method
);
10424 int size
= sizeof w
->desired_matrix
->method
;
10425 int remaining
= size
- len
- 1;
10427 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10428 if (len
&& remaining
)
10431 --remaining
, ++len
;
10434 strncpy (method
+ len
, buffer
, remaining
);
10436 if (trace_redisplay_p
)
10437 fprintf (stderr
, "%p (%s): %s\n",
10439 ((BUFFERP (w
->buffer
)
10440 && STRINGP (XBUFFER (w
->buffer
)->name
))
10441 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10446 #endif /* GLYPH_DEBUG */
10449 /* Value is non-zero if all changes in window W, which displays
10450 current_buffer, are in the text between START and END. START is a
10451 buffer position, END is given as a distance from Z. Used in
10452 redisplay_internal for display optimization. */
10455 text_outside_line_unchanged_p (w
, start
, end
)
10459 int unchanged_p
= 1;
10461 /* If text or overlays have changed, see where. */
10462 if (XFASTINT (w
->last_modified
) < MODIFF
10463 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10465 /* Gap in the line? */
10466 if (GPT
< start
|| Z
- GPT
< end
)
10469 /* Changes start in front of the line, or end after it? */
10471 && (BEG_UNCHANGED
< start
- 1
10472 || END_UNCHANGED
< end
))
10475 /* If selective display, can't optimize if changes start at the
10476 beginning of the line. */
10478 && INTEGERP (current_buffer
->selective_display
)
10479 && XINT (current_buffer
->selective_display
) > 0
10480 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10483 /* If there are overlays at the start or end of the line, these
10484 may have overlay strings with newlines in them. A change at
10485 START, for instance, may actually concern the display of such
10486 overlay strings as well, and they are displayed on different
10487 lines. So, quickly rule out this case. (For the future, it
10488 might be desirable to implement something more telling than
10489 just BEG/END_UNCHANGED.) */
10492 if (BEG
+ BEG_UNCHANGED
== start
10493 && overlay_touches_p (start
))
10495 if (END_UNCHANGED
== end
10496 && overlay_touches_p (Z
- end
))
10501 return unchanged_p
;
10505 /* Do a frame update, taking possible shortcuts into account. This is
10506 the main external entry point for redisplay.
10508 If the last redisplay displayed an echo area message and that message
10509 is no longer requested, we clear the echo area or bring back the
10510 mini-buffer if that is in use. */
10515 redisplay_internal (0);
10520 overlay_arrow_string_or_property (var
)
10525 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10528 return Voverlay_arrow_string
;
10531 /* Return 1 if there are any overlay-arrows in current_buffer. */
10533 overlay_arrow_in_current_buffer_p ()
10537 for (vlist
= Voverlay_arrow_variable_list
;
10539 vlist
= XCDR (vlist
))
10541 Lisp_Object var
= XCAR (vlist
);
10544 if (!SYMBOLP (var
))
10546 val
= find_symbol_value (var
);
10548 && current_buffer
== XMARKER (val
)->buffer
)
10555 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
10559 overlay_arrows_changed_p ()
10563 for (vlist
= Voverlay_arrow_variable_list
;
10565 vlist
= XCDR (vlist
))
10567 Lisp_Object var
= XCAR (vlist
);
10568 Lisp_Object val
, pstr
;
10570 if (!SYMBOLP (var
))
10572 val
= find_symbol_value (var
);
10573 if (!MARKERP (val
))
10575 if (! EQ (COERCE_MARKER (val
),
10576 Fget (var
, Qlast_arrow_position
))
10577 || ! (pstr
= overlay_arrow_string_or_property (var
),
10578 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
10584 /* Mark overlay arrows to be updated on next redisplay. */
10587 update_overlay_arrows (up_to_date
)
10592 for (vlist
= Voverlay_arrow_variable_list
;
10594 vlist
= XCDR (vlist
))
10596 Lisp_Object var
= XCAR (vlist
);
10598 if (!SYMBOLP (var
))
10601 if (up_to_date
> 0)
10603 Lisp_Object val
= find_symbol_value (var
);
10604 Fput (var
, Qlast_arrow_position
,
10605 COERCE_MARKER (val
));
10606 Fput (var
, Qlast_arrow_string
,
10607 overlay_arrow_string_or_property (var
));
10609 else if (up_to_date
< 0
10610 || !NILP (Fget (var
, Qlast_arrow_position
)))
10612 Fput (var
, Qlast_arrow_position
, Qt
);
10613 Fput (var
, Qlast_arrow_string
, Qt
);
10619 /* Return overlay arrow string to display at row.
10620 Return integer (bitmap number) for arrow bitmap in left fringe.
10621 Return nil if no overlay arrow. */
10624 overlay_arrow_at_row (it
, row
)
10626 struct glyph_row
*row
;
10630 for (vlist
= Voverlay_arrow_variable_list
;
10632 vlist
= XCDR (vlist
))
10634 Lisp_Object var
= XCAR (vlist
);
10637 if (!SYMBOLP (var
))
10640 val
= find_symbol_value (var
);
10643 && current_buffer
== XMARKER (val
)->buffer
10644 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10646 if (FRAME_WINDOW_P (it
->f
)
10647 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10649 #ifdef HAVE_WINDOW_SYSTEM
10650 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10653 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10654 return make_number (fringe_bitmap
);
10657 return make_number (-1); /* Use default arrow bitmap */
10659 return overlay_arrow_string_or_property (var
);
10666 /* Return 1 if point moved out of or into a composition. Otherwise
10667 return 0. PREV_BUF and PREV_PT are the last point buffer and
10668 position. BUF and PT are the current point buffer and position. */
10671 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10672 struct buffer
*prev_buf
, *buf
;
10677 Lisp_Object buffer
;
10679 XSETBUFFER (buffer
, buf
);
10680 /* Check a composition at the last point if point moved within the
10682 if (prev_buf
== buf
)
10685 /* Point didn't move. */
10688 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10689 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10690 && COMPOSITION_VALID_P (start
, end
, prop
)
10691 && start
< prev_pt
&& end
> prev_pt
)
10692 /* The last point was within the composition. Return 1 iff
10693 point moved out of the composition. */
10694 return (pt
<= start
|| pt
>= end
);
10697 /* Check a composition at the current point. */
10698 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10699 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10700 && COMPOSITION_VALID_P (start
, end
, prop
)
10701 && start
< pt
&& end
> pt
);
10705 /* Reconsider the setting of B->clip_changed which is displayed
10709 reconsider_clip_changes (w
, b
)
10713 if (b
->clip_changed
10714 && !NILP (w
->window_end_valid
)
10715 && w
->current_matrix
->buffer
== b
10716 && w
->current_matrix
->zv
== BUF_ZV (b
)
10717 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10718 b
->clip_changed
= 0;
10720 /* If display wasn't paused, and W is not a tool bar window, see if
10721 point has been moved into or out of a composition. In that case,
10722 we set b->clip_changed to 1 to force updating the screen. If
10723 b->clip_changed has already been set to 1, we can skip this
10725 if (!b
->clip_changed
10726 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10730 if (w
== XWINDOW (selected_window
))
10731 pt
= BUF_PT (current_buffer
);
10733 pt
= marker_position (w
->pointm
);
10735 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10736 || pt
!= XINT (w
->last_point
))
10737 && check_point_in_composition (w
->current_matrix
->buffer
,
10738 XINT (w
->last_point
),
10739 XBUFFER (w
->buffer
), pt
))
10740 b
->clip_changed
= 1;
10745 /* Select FRAME to forward the values of frame-local variables into C
10746 variables so that the redisplay routines can access those values
10750 select_frame_for_redisplay (frame
)
10753 Lisp_Object tail
, sym
, val
;
10754 Lisp_Object old
= selected_frame
;
10756 selected_frame
= frame
;
10758 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10759 if (CONSP (XCAR (tail
))
10760 && (sym
= XCAR (XCAR (tail
)),
10762 && (sym
= indirect_variable (sym
),
10763 val
= SYMBOL_VALUE (sym
),
10764 (BUFFER_LOCAL_VALUEP (val
)
10765 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10766 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10767 /* Use find_symbol_value rather than Fsymbol_value
10768 to avoid an error if it is void. */
10769 find_symbol_value (sym
);
10771 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10772 if (CONSP (XCAR (tail
))
10773 && (sym
= XCAR (XCAR (tail
)),
10775 && (sym
= indirect_variable (sym
),
10776 val
= SYMBOL_VALUE (sym
),
10777 (BUFFER_LOCAL_VALUEP (val
)
10778 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10779 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10780 find_symbol_value (sym
);
10784 #define STOP_POLLING \
10785 do { if (! polling_stopped_here) stop_polling (); \
10786 polling_stopped_here = 1; } while (0)
10788 #define RESUME_POLLING \
10789 do { if (polling_stopped_here) start_polling (); \
10790 polling_stopped_here = 0; } while (0)
10793 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10794 response to any user action; therefore, we should preserve the echo
10795 area. (Actually, our caller does that job.) Perhaps in the future
10796 avoid recentering windows if it is not necessary; currently that
10797 causes some problems. */
10800 redisplay_internal (preserve_echo_area
)
10801 int preserve_echo_area
;
10803 struct window
*w
= XWINDOW (selected_window
);
10806 int must_finish
= 0;
10807 struct text_pos tlbufpos
, tlendpos
;
10808 int number_of_visible_frames
;
10811 int polling_stopped_here
= 0;
10813 /* Non-zero means redisplay has to consider all windows on all
10814 frames. Zero means, only selected_window is considered. */
10815 int consider_all_windows_p
;
10817 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10819 /* No redisplay if running in batch mode or frame is not yet fully
10820 initialized, or redisplay is explicitly turned off by setting
10821 Vinhibit_redisplay. */
10823 || !NILP (Vinhibit_redisplay
))
10826 /* Don't examine these until after testing Vinhibit_redisplay.
10827 When Emacs is shutting down, perhaps because its connection to
10828 X has dropped, we should not look at them at all. */
10829 f
= XFRAME (w
->frame
);
10830 sf
= SELECTED_FRAME ();
10832 if (!f
->glyphs_initialized_p
)
10835 /* The flag redisplay_performed_directly_p is set by
10836 direct_output_for_insert when it already did the whole screen
10837 update necessary. */
10838 if (redisplay_performed_directly_p
)
10840 redisplay_performed_directly_p
= 0;
10841 if (!hscroll_windows (selected_window
))
10845 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
10846 if (popup_activated ())
10850 /* I don't think this happens but let's be paranoid. */
10851 if (redisplaying_p
)
10854 /* Record a function that resets redisplaying_p to its old value
10855 when we leave this function. */
10856 count
= SPECPDL_INDEX ();
10857 record_unwind_protect (unwind_redisplay
,
10858 Fcons (make_number (redisplaying_p
), selected_frame
));
10860 specbind (Qinhibit_free_realized_faces
, Qnil
);
10863 Lisp_Object tail
, frame
;
10865 FOR_EACH_FRAME (tail
, frame
)
10867 struct frame
*f
= XFRAME (frame
);
10868 f
->already_hscrolled_p
= 0;
10874 reconsider_clip_changes (w
, current_buffer
);
10875 last_escape_glyph_frame
= NULL
;
10876 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
10878 /* If new fonts have been loaded that make a glyph matrix adjustment
10879 necessary, do it. */
10880 if (fonts_changed_p
)
10882 adjust_glyphs (NULL
);
10883 ++windows_or_buffers_changed
;
10884 fonts_changed_p
= 0;
10887 /* If face_change_count is non-zero, init_iterator will free all
10888 realized faces, which includes the faces referenced from current
10889 matrices. So, we can't reuse current matrices in this case. */
10890 if (face_change_count
)
10891 ++windows_or_buffers_changed
;
10893 if (! FRAME_WINDOW_P (sf
)
10894 && previous_terminal_frame
!= sf
)
10896 /* Since frames on an ASCII terminal share the same display
10897 area, displaying a different frame means redisplay the whole
10899 windows_or_buffers_changed
++;
10900 SET_FRAME_GARBAGED (sf
);
10901 XSETFRAME (Vterminal_frame
, sf
);
10903 previous_terminal_frame
= sf
;
10905 /* Set the visible flags for all frames. Do this before checking
10906 for resized or garbaged frames; they want to know if their frames
10907 are visible. See the comment in frame.h for
10908 FRAME_SAMPLE_VISIBILITY. */
10910 Lisp_Object tail
, frame
;
10912 number_of_visible_frames
= 0;
10914 FOR_EACH_FRAME (tail
, frame
)
10916 struct frame
*f
= XFRAME (frame
);
10918 FRAME_SAMPLE_VISIBILITY (f
);
10919 if (FRAME_VISIBLE_P (f
))
10920 ++number_of_visible_frames
;
10921 clear_desired_matrices (f
);
10925 /* Notice any pending interrupt request to change frame size. */
10926 do_pending_window_change (1);
10928 /* Clear frames marked as garbaged. */
10929 if (frame_garbaged
)
10930 clear_garbaged_frames ();
10932 /* Build menubar and tool-bar items. */
10933 if (NILP (Vmemory_full
))
10934 prepare_menu_bars ();
10936 if (windows_or_buffers_changed
)
10937 update_mode_lines
++;
10939 /* Detect case that we need to write or remove a star in the mode line. */
10940 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10942 w
->update_mode_line
= Qt
;
10943 if (buffer_shared
> 1)
10944 update_mode_lines
++;
10947 /* If %c is in the mode line, update it if needed. */
10948 if (!NILP (w
->column_number_displayed
)
10949 /* This alternative quickly identifies a common case
10950 where no change is needed. */
10951 && !(PT
== XFASTINT (w
->last_point
)
10952 && XFASTINT (w
->last_modified
) >= MODIFF
10953 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10954 && (XFASTINT (w
->column_number_displayed
)
10955 != (int) current_column ())) /* iftc */
10956 w
->update_mode_line
= Qt
;
10958 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10960 /* The variable buffer_shared is set in redisplay_window and
10961 indicates that we redisplay a buffer in different windows. See
10963 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
10964 || cursor_type_changed
);
10966 /* If specs for an arrow have changed, do thorough redisplay
10967 to ensure we remove any arrow that should no longer exist. */
10968 if (overlay_arrows_changed_p ())
10969 consider_all_windows_p
= windows_or_buffers_changed
= 1;
10971 /* Normally the message* functions will have already displayed and
10972 updated the echo area, but the frame may have been trashed, or
10973 the update may have been preempted, so display the echo area
10974 again here. Checking message_cleared_p captures the case that
10975 the echo area should be cleared. */
10976 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
10977 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
10978 || (message_cleared_p
10979 && minibuf_level
== 0
10980 /* If the mini-window is currently selected, this means the
10981 echo-area doesn't show through. */
10982 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
10984 int window_height_changed_p
= echo_area_display (0);
10987 /* If we don't display the current message, don't clear the
10988 message_cleared_p flag, because, if we did, we wouldn't clear
10989 the echo area in the next redisplay which doesn't preserve
10991 if (!display_last_displayed_message_p
)
10992 message_cleared_p
= 0;
10994 if (fonts_changed_p
)
10996 else if (window_height_changed_p
)
10998 consider_all_windows_p
= 1;
10999 ++update_mode_lines
;
11000 ++windows_or_buffers_changed
;
11002 /* If window configuration was changed, frames may have been
11003 marked garbaged. Clear them or we will experience
11004 surprises wrt scrolling. */
11005 if (frame_garbaged
)
11006 clear_garbaged_frames ();
11009 else if (EQ (selected_window
, minibuf_window
)
11010 && (current_buffer
->clip_changed
11011 || XFASTINT (w
->last_modified
) < MODIFF
11012 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11013 && resize_mini_window (w
, 0))
11015 /* Resized active mini-window to fit the size of what it is
11016 showing if its contents might have changed. */
11018 consider_all_windows_p
= 1;
11019 ++windows_or_buffers_changed
;
11020 ++update_mode_lines
;
11022 /* If window configuration was changed, frames may have been
11023 marked garbaged. Clear them or we will experience
11024 surprises wrt scrolling. */
11025 if (frame_garbaged
)
11026 clear_garbaged_frames ();
11030 /* If showing the region, and mark has changed, we must redisplay
11031 the whole window. The assignment to this_line_start_pos prevents
11032 the optimization directly below this if-statement. */
11033 if (((!NILP (Vtransient_mark_mode
)
11034 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11035 != !NILP (w
->region_showing
))
11036 || (!NILP (w
->region_showing
)
11037 && !EQ (w
->region_showing
,
11038 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11039 CHARPOS (this_line_start_pos
) = 0;
11041 /* Optimize the case that only the line containing the cursor in the
11042 selected window has changed. Variables starting with this_ are
11043 set in display_line and record information about the line
11044 containing the cursor. */
11045 tlbufpos
= this_line_start_pos
;
11046 tlendpos
= this_line_end_pos
;
11047 if (!consider_all_windows_p
11048 && CHARPOS (tlbufpos
) > 0
11049 && NILP (w
->update_mode_line
)
11050 && !current_buffer
->clip_changed
11051 && !current_buffer
->prevent_redisplay_optimizations_p
11052 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11053 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11054 /* Make sure recorded data applies to current buffer, etc. */
11055 && this_line_buffer
== current_buffer
11056 && current_buffer
== XBUFFER (w
->buffer
)
11057 && NILP (w
->force_start
)
11058 && NILP (w
->optional_new_start
)
11059 /* Point must be on the line that we have info recorded about. */
11060 && PT
>= CHARPOS (tlbufpos
)
11061 && PT
<= Z
- CHARPOS (tlendpos
)
11062 /* All text outside that line, including its final newline,
11063 must be unchanged */
11064 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11065 CHARPOS (tlendpos
)))
11067 if (CHARPOS (tlbufpos
) > BEGV
11068 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11069 && (CHARPOS (tlbufpos
) == ZV
11070 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11071 /* Former continuation line has disappeared by becoming empty */
11073 else if (XFASTINT (w
->last_modified
) < MODIFF
11074 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11075 || MINI_WINDOW_P (w
))
11077 /* We have to handle the case of continuation around a
11078 wide-column character (See the comment in indent.c around
11081 For instance, in the following case:
11083 -------- Insert --------
11084 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11085 J_I_ ==> J_I_ `^^' are cursors.
11089 As we have to redraw the line above, we should goto cancel. */
11092 int line_height_before
= this_line_pixel_height
;
11094 /* Note that start_display will handle the case that the
11095 line starting at tlbufpos is a continuation lines. */
11096 start_display (&it
, w
, tlbufpos
);
11098 /* Implementation note: It this still necessary? */
11099 if (it
.current_x
!= this_line_start_x
)
11102 TRACE ((stderr
, "trying display optimization 1\n"));
11103 w
->cursor
.vpos
= -1;
11104 overlay_arrow_seen
= 0;
11105 it
.vpos
= this_line_vpos
;
11106 it
.current_y
= this_line_y
;
11107 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11108 display_line (&it
);
11110 /* If line contains point, is not continued,
11111 and ends at same distance from eob as before, we win */
11112 if (w
->cursor
.vpos
>= 0
11113 /* Line is not continued, otherwise this_line_start_pos
11114 would have been set to 0 in display_line. */
11115 && CHARPOS (this_line_start_pos
)
11116 /* Line ends as before. */
11117 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11118 /* Line has same height as before. Otherwise other lines
11119 would have to be shifted up or down. */
11120 && this_line_pixel_height
== line_height_before
)
11122 /* If this is not the window's last line, we must adjust
11123 the charstarts of the lines below. */
11124 if (it
.current_y
< it
.last_visible_y
)
11126 struct glyph_row
*row
11127 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11128 int delta
, delta_bytes
;
11130 if (Z
- CHARPOS (tlendpos
) == ZV
)
11132 /* This line ends at end of (accessible part of)
11133 buffer. There is no newline to count. */
11135 - CHARPOS (tlendpos
)
11136 - MATRIX_ROW_START_CHARPOS (row
));
11137 delta_bytes
= (Z_BYTE
11138 - BYTEPOS (tlendpos
)
11139 - MATRIX_ROW_START_BYTEPOS (row
));
11143 /* This line ends in a newline. Must take
11144 account of the newline and the rest of the
11145 text that follows. */
11147 - CHARPOS (tlendpos
)
11148 - MATRIX_ROW_START_CHARPOS (row
));
11149 delta_bytes
= (Z_BYTE
11150 - BYTEPOS (tlendpos
)
11151 - MATRIX_ROW_START_BYTEPOS (row
));
11154 increment_matrix_positions (w
->current_matrix
,
11155 this_line_vpos
+ 1,
11156 w
->current_matrix
->nrows
,
11157 delta
, delta_bytes
);
11160 /* If this row displays text now but previously didn't,
11161 or vice versa, w->window_end_vpos may have to be
11163 if ((it
.glyph_row
- 1)->displays_text_p
)
11165 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11166 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11168 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11169 && this_line_vpos
> 0)
11170 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11171 w
->window_end_valid
= Qnil
;
11173 /* Update hint: No need to try to scroll in update_window. */
11174 w
->desired_matrix
->no_scrolling_p
= 1;
11177 *w
->desired_matrix
->method
= 0;
11178 debug_method_add (w
, "optimization 1");
11180 #ifdef HAVE_WINDOW_SYSTEM
11181 update_window_fringes (w
, 0);
11188 else if (/* Cursor position hasn't changed. */
11189 PT
== XFASTINT (w
->last_point
)
11190 /* Make sure the cursor was last displayed
11191 in this window. Otherwise we have to reposition it. */
11192 && 0 <= w
->cursor
.vpos
11193 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11197 do_pending_window_change (1);
11199 /* We used to always goto end_of_redisplay here, but this
11200 isn't enough if we have a blinking cursor. */
11201 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11202 goto end_of_redisplay
;
11206 /* If highlighting the region, or if the cursor is in the echo area,
11207 then we can't just move the cursor. */
11208 else if (! (!NILP (Vtransient_mark_mode
)
11209 && !NILP (current_buffer
->mark_active
))
11210 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11211 || highlight_nonselected_windows
)
11212 && NILP (w
->region_showing
)
11213 && NILP (Vshow_trailing_whitespace
)
11214 && !cursor_in_echo_area
)
11217 struct glyph_row
*row
;
11219 /* Skip from tlbufpos to PT and see where it is. Note that
11220 PT may be in invisible text. If so, we will end at the
11221 next visible position. */
11222 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11223 NULL
, DEFAULT_FACE_ID
);
11224 it
.current_x
= this_line_start_x
;
11225 it
.current_y
= this_line_y
;
11226 it
.vpos
= this_line_vpos
;
11228 /* The call to move_it_to stops in front of PT, but
11229 moves over before-strings. */
11230 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11232 if (it
.vpos
== this_line_vpos
11233 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11236 xassert (this_line_vpos
== it
.vpos
);
11237 xassert (this_line_y
== it
.current_y
);
11238 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11240 *w
->desired_matrix
->method
= 0;
11241 debug_method_add (w
, "optimization 3");
11250 /* Text changed drastically or point moved off of line. */
11251 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11254 CHARPOS (this_line_start_pos
) = 0;
11255 consider_all_windows_p
|= buffer_shared
> 1;
11256 ++clear_face_cache_count
;
11257 #ifdef HAVE_WINDOW_SYSTEM
11258 ++clear_image_cache_count
;
11261 /* Build desired matrices, and update the display. If
11262 consider_all_windows_p is non-zero, do it for all windows on all
11263 frames. Otherwise do it for selected_window, only. */
11265 if (consider_all_windows_p
)
11267 Lisp_Object tail
, frame
;
11269 FOR_EACH_FRAME (tail
, frame
)
11270 XFRAME (frame
)->updated_p
= 0;
11272 /* Recompute # windows showing selected buffer. This will be
11273 incremented each time such a window is displayed. */
11276 FOR_EACH_FRAME (tail
, frame
)
11278 struct frame
*f
= XFRAME (frame
);
11280 if (FRAME_WINDOW_P (f
) || f
== sf
)
11282 if (! EQ (frame
, selected_frame
))
11283 /* Select the frame, for the sake of frame-local
11285 select_frame_for_redisplay (frame
);
11287 /* Mark all the scroll bars to be removed; we'll redeem
11288 the ones we want when we redisplay their windows. */
11289 if (condemn_scroll_bars_hook
)
11290 condemn_scroll_bars_hook (f
);
11292 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11293 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11295 /* Any scroll bars which redisplay_windows should have
11296 nuked should now go away. */
11297 if (judge_scroll_bars_hook
)
11298 judge_scroll_bars_hook (f
);
11300 /* If fonts changed, display again. */
11301 /* ??? rms: I suspect it is a mistake to jump all the way
11302 back to retry here. It should just retry this frame. */
11303 if (fonts_changed_p
)
11306 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11308 /* See if we have to hscroll. */
11309 if (!f
->already_hscrolled_p
)
11311 f
->already_hscrolled_p
= 1;
11312 if (hscroll_windows (f
->root_window
))
11316 /* Prevent various kinds of signals during display
11317 update. stdio is not robust about handling
11318 signals, which can cause an apparent I/O
11320 if (interrupt_input
)
11321 unrequest_sigio ();
11324 /* Update the display. */
11325 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11326 pause
|= update_frame (f
, 0, 0);
11327 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
11339 /* Do the mark_window_display_accurate after all windows have
11340 been redisplayed because this call resets flags in buffers
11341 which are needed for proper redisplay. */
11342 FOR_EACH_FRAME (tail
, frame
)
11344 struct frame
*f
= XFRAME (frame
);
11347 mark_window_display_accurate (f
->root_window
, 1);
11348 if (frame_up_to_date_hook
)
11349 frame_up_to_date_hook (f
);
11354 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11356 Lisp_Object mini_window
;
11357 struct frame
*mini_frame
;
11359 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11360 /* Use list_of_error, not Qerror, so that
11361 we catch only errors and don't run the debugger. */
11362 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11364 redisplay_window_error
);
11366 /* Compare desired and current matrices, perform output. */
11369 /* If fonts changed, display again. */
11370 if (fonts_changed_p
)
11373 /* Prevent various kinds of signals during display update.
11374 stdio is not robust about handling signals,
11375 which can cause an apparent I/O error. */
11376 if (interrupt_input
)
11377 unrequest_sigio ();
11380 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11382 if (hscroll_windows (selected_window
))
11385 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11386 pause
= update_frame (sf
, 0, 0);
11389 /* We may have called echo_area_display at the top of this
11390 function. If the echo area is on another frame, that may
11391 have put text on a frame other than the selected one, so the
11392 above call to update_frame would not have caught it. Catch
11394 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11395 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11397 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11399 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11400 pause
|= update_frame (mini_frame
, 0, 0);
11401 if (!pause
&& hscroll_windows (mini_window
))
11406 /* If display was paused because of pending input, make sure we do a
11407 thorough update the next time. */
11410 /* Prevent the optimization at the beginning of
11411 redisplay_internal that tries a single-line update of the
11412 line containing the cursor in the selected window. */
11413 CHARPOS (this_line_start_pos
) = 0;
11415 /* Let the overlay arrow be updated the next time. */
11416 update_overlay_arrows (0);
11418 /* If we pause after scrolling, some rows in the current
11419 matrices of some windows are not valid. */
11420 if (!WINDOW_FULL_WIDTH_P (w
)
11421 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11422 update_mode_lines
= 1;
11426 if (!consider_all_windows_p
)
11428 /* This has already been done above if
11429 consider_all_windows_p is set. */
11430 mark_window_display_accurate_1 (w
, 1);
11432 /* Say overlay arrows are up to date. */
11433 update_overlay_arrows (1);
11435 if (frame_up_to_date_hook
!= 0)
11436 frame_up_to_date_hook (sf
);
11439 update_mode_lines
= 0;
11440 windows_or_buffers_changed
= 0;
11441 cursor_type_changed
= 0;
11444 /* Start SIGIO interrupts coming again. Having them off during the
11445 code above makes it less likely one will discard output, but not
11446 impossible, since there might be stuff in the system buffer here.
11447 But it is much hairier to try to do anything about that. */
11448 if (interrupt_input
)
11452 /* If a frame has become visible which was not before, redisplay
11453 again, so that we display it. Expose events for such a frame
11454 (which it gets when becoming visible) don't call the parts of
11455 redisplay constructing glyphs, so simply exposing a frame won't
11456 display anything in this case. So, we have to display these
11457 frames here explicitly. */
11460 Lisp_Object tail
, frame
;
11463 FOR_EACH_FRAME (tail
, frame
)
11465 int this_is_visible
= 0;
11467 if (XFRAME (frame
)->visible
)
11468 this_is_visible
= 1;
11469 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11470 if (XFRAME (frame
)->visible
)
11471 this_is_visible
= 1;
11473 if (this_is_visible
)
11477 if (new_count
!= number_of_visible_frames
)
11478 windows_or_buffers_changed
++;
11481 /* Change frame size now if a change is pending. */
11482 do_pending_window_change (1);
11484 /* If we just did a pending size change, or have additional
11485 visible frames, redisplay again. */
11486 if (windows_or_buffers_changed
&& !pause
)
11489 /* Clear the face cache eventually. */
11490 if (consider_all_windows_p
)
11492 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11494 clear_face_cache (0);
11495 clear_face_cache_count
= 0;
11497 #ifdef HAVE_WINDOW_SYSTEM
11498 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11500 Lisp_Object tail
, frame
;
11501 FOR_EACH_FRAME (tail
, frame
)
11503 struct frame
*f
= XFRAME (frame
);
11504 if (FRAME_WINDOW_P (f
))
11505 clear_image_cache (f
, 0);
11507 clear_image_cache_count
= 0;
11509 #endif /* HAVE_WINDOW_SYSTEM */
11513 unbind_to (count
, Qnil
);
11518 /* Redisplay, but leave alone any recent echo area message unless
11519 another message has been requested in its place.
11521 This is useful in situations where you need to redisplay but no
11522 user action has occurred, making it inappropriate for the message
11523 area to be cleared. See tracking_off and
11524 wait_reading_process_output for examples of these situations.
11526 FROM_WHERE is an integer saying from where this function was
11527 called. This is useful for debugging. */
11530 redisplay_preserve_echo_area (from_where
)
11533 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
11535 if (!NILP (echo_area_buffer
[1]))
11537 /* We have a previously displayed message, but no current
11538 message. Redisplay the previous message. */
11539 display_last_displayed_message_p
= 1;
11540 redisplay_internal (1);
11541 display_last_displayed_message_p
= 0;
11544 redisplay_internal (1);
11546 if (rif
!= NULL
&& rif
->flush_display_optional
)
11547 rif
->flush_display_optional (NULL
);
11551 /* Function registered with record_unwind_protect in
11552 redisplay_internal. Reset redisplaying_p to the value it had
11553 before redisplay_internal was called, and clear
11554 prevent_freeing_realized_faces_p. It also selects the previously
11558 unwind_redisplay (val
)
11561 Lisp_Object old_redisplaying_p
, old_frame
;
11563 old_redisplaying_p
= XCAR (val
);
11564 redisplaying_p
= XFASTINT (old_redisplaying_p
);
11565 old_frame
= XCDR (val
);
11566 if (! EQ (old_frame
, selected_frame
))
11567 select_frame_for_redisplay (old_frame
);
11572 /* Mark the display of window W as accurate or inaccurate. If
11573 ACCURATE_P is non-zero mark display of W as accurate. If
11574 ACCURATE_P is zero, arrange for W to be redisplayed the next time
11575 redisplay_internal is called. */
11578 mark_window_display_accurate_1 (w
, accurate_p
)
11582 if (BUFFERP (w
->buffer
))
11584 struct buffer
*b
= XBUFFER (w
->buffer
);
11587 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
11588 w
->last_overlay_modified
11589 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
11591 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
11595 b
->clip_changed
= 0;
11596 b
->prevent_redisplay_optimizations_p
= 0;
11598 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
11599 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
11600 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
11601 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
11603 w
->current_matrix
->buffer
= b
;
11604 w
->current_matrix
->begv
= BUF_BEGV (b
);
11605 w
->current_matrix
->zv
= BUF_ZV (b
);
11607 w
->last_cursor
= w
->cursor
;
11608 w
->last_cursor_off_p
= w
->cursor_off_p
;
11610 if (w
== XWINDOW (selected_window
))
11611 w
->last_point
= make_number (BUF_PT (b
));
11613 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
11619 w
->window_end_valid
= w
->buffer
;
11620 #if 0 /* This is incorrect with variable-height lines. */
11621 xassert (XINT (w
->window_end_vpos
)
11622 < (WINDOW_TOTAL_LINES (w
)
11623 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
11625 w
->update_mode_line
= Qnil
;
11630 /* Mark the display of windows in the window tree rooted at WINDOW as
11631 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
11632 windows as accurate. If ACCURATE_P is zero, arrange for windows to
11633 be redisplayed the next time redisplay_internal is called. */
11636 mark_window_display_accurate (window
, accurate_p
)
11637 Lisp_Object window
;
11642 for (; !NILP (window
); window
= w
->next
)
11644 w
= XWINDOW (window
);
11645 mark_window_display_accurate_1 (w
, accurate_p
);
11647 if (!NILP (w
->vchild
))
11648 mark_window_display_accurate (w
->vchild
, accurate_p
);
11649 if (!NILP (w
->hchild
))
11650 mark_window_display_accurate (w
->hchild
, accurate_p
);
11655 update_overlay_arrows (1);
11659 /* Force a thorough redisplay the next time by setting
11660 last_arrow_position and last_arrow_string to t, which is
11661 unequal to any useful value of Voverlay_arrow_... */
11662 update_overlay_arrows (-1);
11667 /* Return value in display table DP (Lisp_Char_Table *) for character
11668 C. Since a display table doesn't have any parent, we don't have to
11669 follow parent. Do not call this function directly but use the
11670 macro DISP_CHAR_VECTOR. */
11673 disp_char_vector (dp
, c
)
11674 struct Lisp_Char_Table
*dp
;
11680 if (SINGLE_BYTE_CHAR_P (c
))
11681 return (dp
->contents
[c
]);
11683 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
11686 else if (code
[2] < 32)
11689 /* Here, the possible range of code[0] (== charset ID) is
11690 128..max_charset. Since the top level char table contains data
11691 for multibyte characters after 256th element, we must increment
11692 code[0] by 128 to get a correct index. */
11694 code
[3] = -1; /* anchor */
11696 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
11698 val
= dp
->contents
[code
[i
]];
11699 if (!SUB_CHAR_TABLE_P (val
))
11700 return (NILP (val
) ? dp
->defalt
: val
);
11703 /* Here, val is a sub char table. We return the default value of
11705 return (dp
->defalt
);
11710 /***********************************************************************
11712 ***********************************************************************/
11714 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11717 redisplay_windows (window
)
11718 Lisp_Object window
;
11720 while (!NILP (window
))
11722 struct window
*w
= XWINDOW (window
);
11724 if (!NILP (w
->hchild
))
11725 redisplay_windows (w
->hchild
);
11726 else if (!NILP (w
->vchild
))
11727 redisplay_windows (w
->vchild
);
11730 displayed_buffer
= XBUFFER (w
->buffer
);
11731 /* Use list_of_error, not Qerror, so that
11732 we catch only errors and don't run the debugger. */
11733 internal_condition_case_1 (redisplay_window_0
, window
,
11735 redisplay_window_error
);
11743 redisplay_window_error ()
11745 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11750 redisplay_window_0 (window
)
11751 Lisp_Object window
;
11753 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11754 redisplay_window (window
, 0);
11759 redisplay_window_1 (window
)
11760 Lisp_Object window
;
11762 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11763 redisplay_window (window
, 1);
11768 /* Increment GLYPH until it reaches END or CONDITION fails while
11769 adding (GLYPH)->pixel_width to X. */
11771 #define SKIP_GLYPHS(glyph, end, x, condition) \
11774 (x) += (glyph)->pixel_width; \
11777 while ((glyph) < (end) && (condition))
11780 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11781 DELTA is the number of bytes by which positions recorded in ROW
11782 differ from current buffer positions.
11784 Return 0 if cursor is not on this row. 1 otherwise. */
11787 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11789 struct glyph_row
*row
;
11790 struct glyph_matrix
*matrix
;
11791 int delta
, delta_bytes
, dy
, dvpos
;
11793 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11794 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11795 struct glyph
*cursor
= NULL
;
11796 /* The first glyph that starts a sequence of glyphs from string. */
11797 struct glyph
*string_start
;
11798 /* The X coordinate of string_start. */
11799 int string_start_x
;
11800 /* The last known character position. */
11801 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11802 /* The last known character position before string_start. */
11803 int string_before_pos
;
11806 int cursor_from_overlay_pos
= 0;
11807 int pt_old
= PT
- delta
;
11809 /* Skip over glyphs not having an object at the start of the row.
11810 These are special glyphs like truncation marks on terminal
11812 if (row
->displays_text_p
)
11814 && INTEGERP (glyph
->object
)
11815 && glyph
->charpos
< 0)
11817 x
+= glyph
->pixel_width
;
11821 string_start
= NULL
;
11823 && !INTEGERP (glyph
->object
)
11824 && (!BUFFERP (glyph
->object
)
11825 || (last_pos
= glyph
->charpos
) < pt_old
))
11827 if (! STRINGP (glyph
->object
))
11829 string_start
= NULL
;
11830 x
+= glyph
->pixel_width
;
11832 if (cursor_from_overlay_pos
11833 && last_pos
>= cursor_from_overlay_pos
)
11835 cursor_from_overlay_pos
= 0;
11841 if (string_start
== NULL
)
11843 string_before_pos
= last_pos
;
11844 string_start
= glyph
;
11845 string_start_x
= x
;
11847 /* Skip all glyphs from string. */
11852 if ((cursor
== NULL
|| glyph
> cursor
)
11853 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
11854 Qcursor
, (glyph
)->object
),
11856 && (pos
= string_buffer_position (w
, glyph
->object
,
11857 string_before_pos
),
11858 (pos
== 0 /* From overlay */
11859 || pos
== pt_old
)))
11861 /* Estimate overlay buffer position from the buffer
11862 positions of the glyphs before and after the overlay.
11863 Add 1 to last_pos so that if point corresponds to the
11864 glyph right after the overlay, we still use a 'cursor'
11865 property found in that overlay. */
11866 cursor_from_overlay_pos
= (pos
? 0 : last_pos
11867 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
11871 x
+= glyph
->pixel_width
;
11874 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
11878 if (cursor
!= NULL
)
11883 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
11885 /* Scan back over the ellipsis glyphs, decrementing positions. */
11886 while (glyph
> row
->glyphs
[TEXT_AREA
]
11887 && (glyph
- 1)->charpos
== last_pos
)
11888 glyph
--, x
-= glyph
->pixel_width
;
11889 /* That loop always goes one position too far,
11890 including the glyph before the ellipsis.
11891 So scan forward over that one. */
11892 x
+= glyph
->pixel_width
;
11895 else if (string_start
11896 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
11898 /* We may have skipped over point because the previous glyphs
11899 are from string. As there's no easy way to know the
11900 character position of the current glyph, find the correct
11901 glyph on point by scanning from string_start again. */
11903 Lisp_Object string
;
11904 struct glyph
*stop
= glyph
;
11907 limit
= make_number (pt_old
+ 1);
11908 glyph
= string_start
;
11909 x
= string_start_x
;
11910 string
= glyph
->object
;
11911 pos
= string_buffer_position (w
, string
, string_before_pos
);
11912 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
11913 because we always put cursor after overlay strings. */
11914 while (pos
== 0 && glyph
< stop
)
11916 string
= glyph
->object
;
11917 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
11919 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
11922 while (glyph
< stop
)
11924 pos
= XINT (Fnext_single_char_property_change
11925 (make_number (pos
), Qdisplay
, Qnil
, limit
));
11928 /* Skip glyphs from the same string. */
11929 string
= glyph
->object
;
11930 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
11931 /* Skip glyphs from an overlay. */
11932 while (glyph
< stop
11933 && ! string_buffer_position (w
, glyph
->object
, pos
))
11935 string
= glyph
->object
;
11936 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
11940 /* If we reached the end of the line, and end was from a string,
11941 cursor is not on this line. */
11942 if (glyph
== end
&& row
->continued_p
)
11946 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
11948 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
11949 w
->cursor
.y
= row
->y
+ dy
;
11951 if (w
== XWINDOW (selected_window
))
11953 if (!row
->continued_p
11954 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
11957 this_line_buffer
= XBUFFER (w
->buffer
);
11959 CHARPOS (this_line_start_pos
)
11960 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
11961 BYTEPOS (this_line_start_pos
)
11962 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
11964 CHARPOS (this_line_end_pos
)
11965 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
11966 BYTEPOS (this_line_end_pos
)
11967 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
11969 this_line_y
= w
->cursor
.y
;
11970 this_line_pixel_height
= row
->height
;
11971 this_line_vpos
= w
->cursor
.vpos
;
11972 this_line_start_x
= row
->x
;
11975 CHARPOS (this_line_start_pos
) = 0;
11982 /* Run window scroll functions, if any, for WINDOW with new window
11983 start STARTP. Sets the window start of WINDOW to that position.
11985 We assume that the window's buffer is really current. */
11987 static INLINE
struct text_pos
11988 run_window_scroll_functions (window
, startp
)
11989 Lisp_Object window
;
11990 struct text_pos startp
;
11992 struct window
*w
= XWINDOW (window
);
11993 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
11995 if (current_buffer
!= XBUFFER (w
->buffer
))
11998 if (!NILP (Vwindow_scroll_functions
))
12000 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12001 make_number (CHARPOS (startp
)));
12002 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12003 /* In case the hook functions switch buffers. */
12004 if (current_buffer
!= XBUFFER (w
->buffer
))
12005 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12012 /* Make sure the line containing the cursor is fully visible.
12013 A value of 1 means there is nothing to be done.
12014 (Either the line is fully visible, or it cannot be made so,
12015 or we cannot tell.)
12017 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12018 is higher than window.
12020 A value of 0 means the caller should do scrolling
12021 as if point had gone off the screen. */
12024 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12027 int current_matrix_p
;
12029 struct glyph_matrix
*matrix
;
12030 struct glyph_row
*row
;
12033 if (!make_cursor_line_fully_visible_p
)
12036 /* It's not always possible to find the cursor, e.g, when a window
12037 is full of overlay strings. Don't do anything in that case. */
12038 if (w
->cursor
.vpos
< 0)
12041 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12042 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12044 /* If the cursor row is not partially visible, there's nothing to do. */
12045 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12048 /* If the row the cursor is in is taller than the window's height,
12049 it's not clear what to do, so do nothing. */
12050 window_height
= window_box_height (w
);
12051 if (row
->height
>= window_height
)
12053 if (!force_p
|| MINI_WINDOW_P (w
)
12054 || w
->vscroll
|| w
->cursor
.vpos
== 0)
12060 /* This code used to try to scroll the window just enough to make
12061 the line visible. It returned 0 to say that the caller should
12062 allocate larger glyph matrices. */
12064 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
12066 int dy
= row
->height
- row
->visible_height
;
12069 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12071 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
12073 int dy
= - (row
->height
- row
->visible_height
);
12076 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12079 /* When we change the cursor y-position of the selected window,
12080 change this_line_y as well so that the display optimization for
12081 the cursor line of the selected window in redisplay_internal uses
12082 the correct y-position. */
12083 if (w
== XWINDOW (selected_window
))
12084 this_line_y
= w
->cursor
.y
;
12086 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
12087 redisplay with larger matrices. */
12088 if (matrix
->nrows
< required_matrix_height (w
))
12090 fonts_changed_p
= 1;
12099 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
12100 non-zero means only WINDOW is redisplayed in redisplay_internal.
12101 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
12102 in redisplay_window to bring a partially visible line into view in
12103 the case that only the cursor has moved.
12105 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
12106 last screen line's vertical height extends past the end of the screen.
12110 1 if scrolling succeeded
12112 0 if scrolling didn't find point.
12114 -1 if new fonts have been loaded so that we must interrupt
12115 redisplay, adjust glyph matrices, and try again. */
12121 SCROLLING_NEED_LARGER_MATRICES
12125 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
12126 scroll_step
, temp_scroll_step
, last_line_misfit
)
12127 Lisp_Object window
;
12128 int just_this_one_p
;
12129 EMACS_INT scroll_conservatively
, scroll_step
;
12130 int temp_scroll_step
;
12131 int last_line_misfit
;
12133 struct window
*w
= XWINDOW (window
);
12134 struct frame
*f
= XFRAME (w
->frame
);
12135 struct text_pos scroll_margin_pos
;
12136 struct text_pos pos
;
12137 struct text_pos startp
;
12139 Lisp_Object window_end
;
12140 int this_scroll_margin
;
12144 int amount_to_scroll
= 0;
12145 Lisp_Object aggressive
;
12147 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
12150 debug_method_add (w
, "try_scrolling");
12153 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12155 /* Compute scroll margin height in pixels. We scroll when point is
12156 within this distance from the top or bottom of the window. */
12157 if (scroll_margin
> 0)
12159 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12160 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12163 this_scroll_margin
= 0;
12165 /* Force scroll_conservatively to have a reasonable value so it doesn't
12166 cause an overflow while computing how much to scroll. */
12167 if (scroll_conservatively
)
12168 scroll_conservatively
= min (scroll_conservatively
,
12169 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
12171 /* Compute how much we should try to scroll maximally to bring point
12173 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
12174 scroll_max
= max (scroll_step
,
12175 max (scroll_conservatively
, temp_scroll_step
));
12176 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
12177 || NUMBERP (current_buffer
->scroll_up_aggressively
))
12178 /* We're trying to scroll because of aggressive scrolling
12179 but no scroll_step is set. Choose an arbitrary one. Maybe
12180 there should be a variable for this. */
12184 scroll_max
*= FRAME_LINE_HEIGHT (f
);
12186 /* Decide whether we have to scroll down. Start at the window end
12187 and move this_scroll_margin up to find the position of the scroll
12189 window_end
= Fwindow_end (window
, Qt
);
12193 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
12194 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
12196 if (this_scroll_margin
|| extra_scroll_margin_lines
)
12198 start_display (&it
, w
, scroll_margin_pos
);
12199 if (this_scroll_margin
)
12200 move_it_vertically_backward (&it
, this_scroll_margin
);
12201 if (extra_scroll_margin_lines
)
12202 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
12203 scroll_margin_pos
= it
.current
.pos
;
12206 if (PT
>= CHARPOS (scroll_margin_pos
))
12210 /* Point is in the scroll margin at the bottom of the window, or
12211 below. Compute a new window start that makes point visible. */
12213 /* Compute the distance from the scroll margin to PT.
12214 Give up if the distance is greater than scroll_max. */
12215 start_display (&it
, w
, scroll_margin_pos
);
12217 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12218 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12220 /* To make point visible, we have to move the window start
12221 down so that the line the cursor is in is visible, which
12222 means we have to add in the height of the cursor line. */
12223 dy
= line_bottom_y (&it
) - y0
;
12225 if (dy
> scroll_max
)
12226 return SCROLLING_FAILED
;
12228 /* Move the window start down. If scrolling conservatively,
12229 move it just enough down to make point visible. If
12230 scroll_step is set, move it down by scroll_step. */
12231 start_display (&it
, w
, startp
);
12233 if (scroll_conservatively
)
12234 /* Set AMOUNT_TO_SCROLL to at least one line,
12235 and at most scroll_conservatively lines. */
12237 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12238 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12239 else if (scroll_step
|| temp_scroll_step
)
12240 amount_to_scroll
= scroll_max
;
12243 aggressive
= current_buffer
->scroll_up_aggressively
;
12244 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12245 if (NUMBERP (aggressive
))
12247 double float_amount
= XFLOATINT (aggressive
) * height
;
12248 amount_to_scroll
= float_amount
;
12249 if (amount_to_scroll
== 0 && float_amount
> 0)
12250 amount_to_scroll
= 1;
12254 if (amount_to_scroll
<= 0)
12255 return SCROLLING_FAILED
;
12257 /* If moving by amount_to_scroll leaves STARTP unchanged,
12258 move it down one screen line. */
12260 move_it_vertically (&it
, amount_to_scroll
);
12261 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12262 move_it_by_lines (&it
, 1, 1);
12263 startp
= it
.current
.pos
;
12267 /* See if point is inside the scroll margin at the top of the
12269 scroll_margin_pos
= startp
;
12270 if (this_scroll_margin
)
12272 start_display (&it
, w
, startp
);
12273 move_it_vertically (&it
, this_scroll_margin
);
12274 scroll_margin_pos
= it
.current
.pos
;
12277 if (PT
< CHARPOS (scroll_margin_pos
))
12279 /* Point is in the scroll margin at the top of the window or
12280 above what is displayed in the window. */
12283 /* Compute the vertical distance from PT to the scroll
12284 margin position. Give up if distance is greater than
12286 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12287 start_display (&it
, w
, pos
);
12289 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12290 it
.last_visible_y
, -1,
12291 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12292 dy
= it
.current_y
- y0
;
12293 if (dy
> scroll_max
)
12294 return SCROLLING_FAILED
;
12296 /* Compute new window start. */
12297 start_display (&it
, w
, startp
);
12299 if (scroll_conservatively
)
12301 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12302 else if (scroll_step
|| temp_scroll_step
)
12303 amount_to_scroll
= scroll_max
;
12306 aggressive
= current_buffer
->scroll_down_aggressively
;
12307 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12308 if (NUMBERP (aggressive
))
12310 double float_amount
= XFLOATINT (aggressive
) * height
;
12311 amount_to_scroll
= float_amount
;
12312 if (amount_to_scroll
== 0 && float_amount
> 0)
12313 amount_to_scroll
= 1;
12317 if (amount_to_scroll
<= 0)
12318 return SCROLLING_FAILED
;
12320 move_it_vertically_backward (&it
, amount_to_scroll
);
12321 startp
= it
.current
.pos
;
12325 /* Run window scroll functions. */
12326 startp
= run_window_scroll_functions (window
, startp
);
12328 /* Display the window. Give up if new fonts are loaded, or if point
12330 if (!try_window (window
, startp
, 0))
12331 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12332 else if (w
->cursor
.vpos
< 0)
12334 clear_glyph_matrix (w
->desired_matrix
);
12335 rc
= SCROLLING_FAILED
;
12339 /* Maybe forget recorded base line for line number display. */
12340 if (!just_this_one_p
12341 || current_buffer
->clip_changed
12342 || BEG_UNCHANGED
< CHARPOS (startp
))
12343 w
->base_line_number
= Qnil
;
12345 /* If cursor ends up on a partially visible line,
12346 treat that as being off the bottom of the screen. */
12347 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12349 clear_glyph_matrix (w
->desired_matrix
);
12350 ++extra_scroll_margin_lines
;
12353 rc
= SCROLLING_SUCCESS
;
12360 /* Compute a suitable window start for window W if display of W starts
12361 on a continuation line. Value is non-zero if a new window start
12364 The new window start will be computed, based on W's width, starting
12365 from the start of the continued line. It is the start of the
12366 screen line with the minimum distance from the old start W->start. */
12369 compute_window_start_on_continuation_line (w
)
12372 struct text_pos pos
, start_pos
;
12373 int window_start_changed_p
= 0;
12375 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12377 /* If window start is on a continuation line... Window start may be
12378 < BEGV in case there's invisible text at the start of the
12379 buffer (M-x rmail, for example). */
12380 if (CHARPOS (start_pos
) > BEGV
12381 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12384 struct glyph_row
*row
;
12386 /* Handle the case that the window start is out of range. */
12387 if (CHARPOS (start_pos
) < BEGV
)
12388 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12389 else if (CHARPOS (start_pos
) > ZV
)
12390 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12392 /* Find the start of the continued line. This should be fast
12393 because scan_buffer is fast (newline cache). */
12394 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12395 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12396 row
, DEFAULT_FACE_ID
);
12397 reseat_at_previous_visible_line_start (&it
);
12399 /* If the line start is "too far" away from the window start,
12400 say it takes too much time to compute a new window start. */
12401 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12402 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12404 int min_distance
, distance
;
12406 /* Move forward by display lines to find the new window
12407 start. If window width was enlarged, the new start can
12408 be expected to be > the old start. If window width was
12409 decreased, the new window start will be < the old start.
12410 So, we're looking for the display line start with the
12411 minimum distance from the old window start. */
12412 pos
= it
.current
.pos
;
12413 min_distance
= INFINITY
;
12414 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12415 distance
< min_distance
)
12417 min_distance
= distance
;
12418 pos
= it
.current
.pos
;
12419 move_it_by_lines (&it
, 1, 0);
12422 /* Set the window start there. */
12423 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12424 window_start_changed_p
= 1;
12428 return window_start_changed_p
;
12432 /* Try cursor movement in case text has not changed in window WINDOW,
12433 with window start STARTP. Value is
12435 CURSOR_MOVEMENT_SUCCESS if successful
12437 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12439 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12440 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12441 we want to scroll as if scroll-step were set to 1. See the code.
12443 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12444 which case we have to abort this redisplay, and adjust matrices
12449 CURSOR_MOVEMENT_SUCCESS
,
12450 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12451 CURSOR_MOVEMENT_MUST_SCROLL
,
12452 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12456 try_cursor_movement (window
, startp
, scroll_step
)
12457 Lisp_Object window
;
12458 struct text_pos startp
;
12461 struct window
*w
= XWINDOW (window
);
12462 struct frame
*f
= XFRAME (w
->frame
);
12463 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12466 if (inhibit_try_cursor_movement
)
12470 /* Handle case where text has not changed, only point, and it has
12471 not moved off the frame. */
12472 if (/* Point may be in this window. */
12473 PT
>= CHARPOS (startp
)
12474 /* Selective display hasn't changed. */
12475 && !current_buffer
->clip_changed
12476 /* Function force-mode-line-update is used to force a thorough
12477 redisplay. It sets either windows_or_buffers_changed or
12478 update_mode_lines. So don't take a shortcut here for these
12480 && !update_mode_lines
12481 && !windows_or_buffers_changed
12482 && !cursor_type_changed
12483 /* Can't use this case if highlighting a region. When a
12484 region exists, cursor movement has to do more than just
12486 && !(!NILP (Vtransient_mark_mode
)
12487 && !NILP (current_buffer
->mark_active
))
12488 && NILP (w
->region_showing
)
12489 && NILP (Vshow_trailing_whitespace
)
12490 /* Right after splitting windows, last_point may be nil. */
12491 && INTEGERP (w
->last_point
)
12492 /* This code is not used for mini-buffer for the sake of the case
12493 of redisplaying to replace an echo area message; since in
12494 that case the mini-buffer contents per se are usually
12495 unchanged. This code is of no real use in the mini-buffer
12496 since the handling of this_line_start_pos, etc., in redisplay
12497 handles the same cases. */
12498 && !EQ (window
, minibuf_window
)
12499 /* When splitting windows or for new windows, it happens that
12500 redisplay is called with a nil window_end_vpos or one being
12501 larger than the window. This should really be fixed in
12502 window.c. I don't have this on my list, now, so we do
12503 approximately the same as the old redisplay code. --gerd. */
12504 && INTEGERP (w
->window_end_vpos
)
12505 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12506 && (FRAME_WINDOW_P (f
)
12507 || !overlay_arrow_in_current_buffer_p ()))
12509 int this_scroll_margin
, top_scroll_margin
;
12510 struct glyph_row
*row
= NULL
;
12513 debug_method_add (w
, "cursor movement");
12516 /* Scroll if point within this distance from the top or bottom
12517 of the window. This is a pixel value. */
12518 this_scroll_margin
= max (0, scroll_margin
);
12519 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12520 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12522 top_scroll_margin
= this_scroll_margin
;
12523 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12524 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12526 /* Start with the row the cursor was displayed during the last
12527 not paused redisplay. Give up if that row is not valid. */
12528 if (w
->last_cursor
.vpos
< 0
12529 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12530 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12533 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12534 if (row
->mode_line_p
)
12536 if (!row
->enabled_p
)
12537 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12540 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12543 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12545 if (PT
> XFASTINT (w
->last_point
))
12547 /* Point has moved forward. */
12548 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12549 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12551 xassert (row
->enabled_p
);
12555 /* The end position of a row equals the start position
12556 of the next row. If PT is there, we would rather
12557 display it in the next line. */
12558 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12559 && MATRIX_ROW_END_CHARPOS (row
) == PT
12560 && !cursor_row_p (w
, row
))
12563 /* If within the scroll margin, scroll. Note that
12564 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
12565 the next line would be drawn, and that
12566 this_scroll_margin can be zero. */
12567 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
12568 || PT
> MATRIX_ROW_END_CHARPOS (row
)
12569 /* Line is completely visible last line in window
12570 and PT is to be set in the next line. */
12571 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
12572 && PT
== MATRIX_ROW_END_CHARPOS (row
)
12573 && !row
->ends_at_zv_p
12574 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12577 else if (PT
< XFASTINT (w
->last_point
))
12579 /* Cursor has to be moved backward. Note that PT >=
12580 CHARPOS (startp) because of the outer if-statement. */
12581 while (!row
->mode_line_p
12582 && (MATRIX_ROW_START_CHARPOS (row
) > PT
12583 || (MATRIX_ROW_START_CHARPOS (row
) == PT
12584 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
12585 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
12586 row
> w
->current_matrix
->rows
12587 && (row
-1)->ends_in_newline_from_string_p
))))
12588 && (row
->y
> top_scroll_margin
12589 || CHARPOS (startp
) == BEGV
))
12591 xassert (row
->enabled_p
);
12595 /* Consider the following case: Window starts at BEGV,
12596 there is invisible, intangible text at BEGV, so that
12597 display starts at some point START > BEGV. It can
12598 happen that we are called with PT somewhere between
12599 BEGV and START. Try to handle that case. */
12600 if (row
< w
->current_matrix
->rows
12601 || row
->mode_line_p
)
12603 row
= w
->current_matrix
->rows
;
12604 if (row
->mode_line_p
)
12608 /* Due to newlines in overlay strings, we may have to
12609 skip forward over overlay strings. */
12610 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12611 && MATRIX_ROW_END_CHARPOS (row
) == PT
12612 && !cursor_row_p (w
, row
))
12615 /* If within the scroll margin, scroll. */
12616 if (row
->y
< top_scroll_margin
12617 && CHARPOS (startp
) != BEGV
)
12622 /* Cursor did not move. So don't scroll even if cursor line
12623 is partially visible, as it was so before. */
12624 rc
= CURSOR_MOVEMENT_SUCCESS
;
12627 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
12628 || PT
> MATRIX_ROW_END_CHARPOS (row
))
12630 /* if PT is not in the glyph row, give up. */
12631 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12633 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
12634 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
12635 && make_cursor_line_fully_visible_p
)
12637 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
12638 && !row
->ends_at_zv_p
12639 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12640 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12641 else if (row
->height
> window_box_height (w
))
12643 /* If we end up in a partially visible line, let's
12644 make it fully visible, except when it's taller
12645 than the window, in which case we can't do much
12648 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12652 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12653 if (!cursor_row_fully_visible_p (w
, 0, 1))
12654 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12656 rc
= CURSOR_MOVEMENT_SUCCESS
;
12660 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12665 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
12667 rc
= CURSOR_MOVEMENT_SUCCESS
;
12672 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12673 && MATRIX_ROW_START_CHARPOS (row
) == PT
12674 && cursor_row_p (w
, row
));
12683 set_vertical_scroll_bar (w
)
12686 int start
, end
, whole
;
12688 /* Calculate the start and end positions for the current window.
12689 At some point, it would be nice to choose between scrollbars
12690 which reflect the whole buffer size, with special markers
12691 indicating narrowing, and scrollbars which reflect only the
12694 Note that mini-buffers sometimes aren't displaying any text. */
12695 if (!MINI_WINDOW_P (w
)
12696 || (w
== XWINDOW (minibuf_window
)
12697 && NILP (echo_area_buffer
[0])))
12699 struct buffer
*buf
= XBUFFER (w
->buffer
);
12700 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12701 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12702 /* I don't think this is guaranteed to be right. For the
12703 moment, we'll pretend it is. */
12704 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12708 if (whole
< (end
- start
))
12709 whole
= end
- start
;
12712 start
= end
= whole
= 0;
12714 /* Indicate what this scroll bar ought to be displaying now. */
12715 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
12719 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
12720 selected_window is redisplayed.
12722 We can return without actually redisplaying the window if
12723 fonts_changed_p is nonzero. In that case, redisplay_internal will
12727 redisplay_window (window
, just_this_one_p
)
12728 Lisp_Object window
;
12729 int just_this_one_p
;
12731 struct window
*w
= XWINDOW (window
);
12732 struct frame
*f
= XFRAME (w
->frame
);
12733 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12734 struct buffer
*old
= current_buffer
;
12735 struct text_pos lpoint
, opoint
, startp
;
12736 int update_mode_line
;
12739 /* Record it now because it's overwritten. */
12740 int current_matrix_up_to_date_p
= 0;
12741 int used_current_matrix_p
= 0;
12742 /* This is less strict than current_matrix_up_to_date_p.
12743 It indictes that the buffer contents and narrowing are unchanged. */
12744 int buffer_unchanged_p
= 0;
12745 int temp_scroll_step
= 0;
12746 int count
= SPECPDL_INDEX ();
12748 int centering_position
= -1;
12749 int last_line_misfit
= 0;
12751 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12754 /* W must be a leaf window here. */
12755 xassert (!NILP (w
->buffer
));
12757 *w
->desired_matrix
->method
= 0;
12760 specbind (Qinhibit_point_motion_hooks
, Qt
);
12762 reconsider_clip_changes (w
, buffer
);
12764 /* Has the mode line to be updated? */
12765 update_mode_line
= (!NILP (w
->update_mode_line
)
12766 || update_mode_lines
12767 || buffer
->clip_changed
12768 || buffer
->prevent_redisplay_optimizations_p
);
12770 if (MINI_WINDOW_P (w
))
12772 if (w
== XWINDOW (echo_area_window
)
12773 && !NILP (echo_area_buffer
[0]))
12775 if (update_mode_line
)
12776 /* We may have to update a tty frame's menu bar or a
12777 tool-bar. Example `M-x C-h C-h C-g'. */
12778 goto finish_menu_bars
;
12780 /* We've already displayed the echo area glyphs in this window. */
12781 goto finish_scroll_bars
;
12783 else if ((w
!= XWINDOW (minibuf_window
)
12784 || minibuf_level
== 0)
12785 /* When buffer is nonempty, redisplay window normally. */
12786 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12787 /* Quail displays non-mini buffers in minibuffer window.
12788 In that case, redisplay the window normally. */
12789 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12791 /* W is a mini-buffer window, but it's not active, so clear
12793 int yb
= window_text_bottom_y (w
);
12794 struct glyph_row
*row
;
12797 for (y
= 0, row
= w
->desired_matrix
->rows
;
12799 y
+= row
->height
, ++row
)
12800 blank_row (w
, row
, y
);
12801 goto finish_scroll_bars
;
12804 clear_glyph_matrix (w
->desired_matrix
);
12807 /* Otherwise set up data on this window; select its buffer and point
12809 /* Really select the buffer, for the sake of buffer-local
12811 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12812 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12814 current_matrix_up_to_date_p
12815 = (!NILP (w
->window_end_valid
)
12816 && !current_buffer
->clip_changed
12817 && !current_buffer
->prevent_redisplay_optimizations_p
12818 && XFASTINT (w
->last_modified
) >= MODIFF
12819 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12822 = (!NILP (w
->window_end_valid
)
12823 && !current_buffer
->clip_changed
12824 && XFASTINT (w
->last_modified
) >= MODIFF
12825 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12827 /* When windows_or_buffers_changed is non-zero, we can't rely on
12828 the window end being valid, so set it to nil there. */
12829 if (windows_or_buffers_changed
)
12831 /* If window starts on a continuation line, maybe adjust the
12832 window start in case the window's width changed. */
12833 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12834 compute_window_start_on_continuation_line (w
);
12836 w
->window_end_valid
= Qnil
;
12839 /* Some sanity checks. */
12840 CHECK_WINDOW_END (w
);
12841 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12843 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12846 /* If %c is in mode line, update it if needed. */
12847 if (!NILP (w
->column_number_displayed
)
12848 /* This alternative quickly identifies a common case
12849 where no change is needed. */
12850 && !(PT
== XFASTINT (w
->last_point
)
12851 && XFASTINT (w
->last_modified
) >= MODIFF
12852 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12853 && (XFASTINT (w
->column_number_displayed
)
12854 != (int) current_column ())) /* iftc */
12855 update_mode_line
= 1;
12857 /* Count number of windows showing the selected buffer. An indirect
12858 buffer counts as its base buffer. */
12859 if (!just_this_one_p
)
12861 struct buffer
*current_base
, *window_base
;
12862 current_base
= current_buffer
;
12863 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12864 if (current_base
->base_buffer
)
12865 current_base
= current_base
->base_buffer
;
12866 if (window_base
->base_buffer
)
12867 window_base
= window_base
->base_buffer
;
12868 if (current_base
== window_base
)
12872 /* Point refers normally to the selected window. For any other
12873 window, set up appropriate value. */
12874 if (!EQ (window
, selected_window
))
12876 int new_pt
= XMARKER (w
->pointm
)->charpos
;
12877 int new_pt_byte
= marker_byte_position (w
->pointm
);
12881 new_pt_byte
= BEGV_BYTE
;
12882 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
12884 else if (new_pt
> (ZV
- 1))
12887 new_pt_byte
= ZV_BYTE
;
12888 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
12891 /* We don't use SET_PT so that the point-motion hooks don't run. */
12892 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
12895 /* If any of the character widths specified in the display table
12896 have changed, invalidate the width run cache. It's true that
12897 this may be a bit late to catch such changes, but the rest of
12898 redisplay goes (non-fatally) haywire when the display table is
12899 changed, so why should we worry about doing any better? */
12900 if (current_buffer
->width_run_cache
)
12902 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
12904 if (! disptab_matches_widthtab (disptab
,
12905 XVECTOR (current_buffer
->width_table
)))
12907 invalidate_region_cache (current_buffer
,
12908 current_buffer
->width_run_cache
,
12910 recompute_width_table (current_buffer
, disptab
);
12914 /* If window-start is screwed up, choose a new one. */
12915 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12918 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12920 /* If someone specified a new starting point but did not insist,
12921 check whether it can be used. */
12922 if (!NILP (w
->optional_new_start
)
12923 && CHARPOS (startp
) >= BEGV
12924 && CHARPOS (startp
) <= ZV
)
12926 w
->optional_new_start
= Qnil
;
12927 start_display (&it
, w
, startp
);
12928 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12929 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12930 if (IT_CHARPOS (it
) == PT
)
12931 w
->force_start
= Qt
;
12932 /* IT may overshoot PT if text at PT is invisible. */
12933 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12934 w
->force_start
= Qt
;
12937 /* Handle case where place to start displaying has been specified,
12938 unless the specified location is outside the accessible range. */
12939 if (!NILP (w
->force_start
)
12940 || w
->frozen_window_start_p
)
12942 /* We set this later on if we have to adjust point. */
12946 w
->force_start
= Qnil
;
12948 w
->window_end_valid
= Qnil
;
12950 /* Forget any recorded base line for line number display. */
12951 if (!buffer_unchanged_p
)
12952 w
->base_line_number
= Qnil
;
12954 /* Redisplay the mode line. Select the buffer properly for that.
12955 Also, run the hook window-scroll-functions
12956 because we have scrolled. */
12957 /* Note, we do this after clearing force_start because
12958 if there's an error, it is better to forget about force_start
12959 than to get into an infinite loop calling the hook functions
12960 and having them get more errors. */
12961 if (!update_mode_line
12962 || ! NILP (Vwindow_scroll_functions
))
12964 update_mode_line
= 1;
12965 w
->update_mode_line
= Qt
;
12966 startp
= run_window_scroll_functions (window
, startp
);
12969 w
->last_modified
= make_number (0);
12970 w
->last_overlay_modified
= make_number (0);
12971 if (CHARPOS (startp
) < BEGV
)
12972 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
12973 else if (CHARPOS (startp
) > ZV
)
12974 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
12976 /* Redisplay, then check if cursor has been set during the
12977 redisplay. Give up if new fonts were loaded. */
12978 val
= try_window (window
, startp
, 1);
12981 w
->force_start
= Qt
;
12982 clear_glyph_matrix (w
->desired_matrix
);
12983 goto need_larger_matrices
;
12985 /* Point was outside the scroll margins. */
12987 new_vpos
= window_box_height (w
) / 2;
12989 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
12991 /* If point does not appear, try to move point so it does
12992 appear. The desired matrix has been built above, so we
12993 can use it here. */
12994 new_vpos
= window_box_height (w
) / 2;
12997 if (!cursor_row_fully_visible_p (w
, 0, 0))
12999 /* Point does appear, but on a line partly visible at end of window.
13000 Move it back to a fully-visible line. */
13001 new_vpos
= window_box_height (w
);
13004 /* If we need to move point for either of the above reasons,
13005 now actually do it. */
13008 struct glyph_row
*row
;
13010 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13011 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13014 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13015 MATRIX_ROW_START_BYTEPOS (row
));
13017 if (w
!= XWINDOW (selected_window
))
13018 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13019 else if (current_buffer
== old
)
13020 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13022 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13024 /* If we are highlighting the region, then we just changed
13025 the region, so redisplay to show it. */
13026 if (!NILP (Vtransient_mark_mode
)
13027 && !NILP (current_buffer
->mark_active
))
13029 clear_glyph_matrix (w
->desired_matrix
);
13030 if (!try_window (window
, startp
, 0))
13031 goto need_larger_matrices
;
13036 debug_method_add (w
, "forced window start");
13041 /* Handle case where text has not changed, only point, and it has
13042 not moved off the frame, and we are not retrying after hscroll.
13043 (current_matrix_up_to_date_p is nonzero when retrying.) */
13044 if (current_matrix_up_to_date_p
13045 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13046 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13050 case CURSOR_MOVEMENT_SUCCESS
:
13051 used_current_matrix_p
= 1;
13054 #if 0 /* try_cursor_movement never returns this value. */
13055 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
13056 goto need_larger_matrices
;
13059 case CURSOR_MOVEMENT_MUST_SCROLL
:
13060 goto try_to_scroll
;
13066 /* If current starting point was originally the beginning of a line
13067 but no longer is, find a new starting point. */
13068 else if (!NILP (w
->start_at_line_beg
)
13069 && !(CHARPOS (startp
) <= BEGV
13070 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13073 debug_method_add (w
, "recenter 1");
13078 /* Try scrolling with try_window_id. Value is > 0 if update has
13079 been done, it is -1 if we know that the same window start will
13080 not work. It is 0 if unsuccessful for some other reason. */
13081 else if ((tem
= try_window_id (w
)) != 0)
13084 debug_method_add (w
, "try_window_id %d", tem
);
13087 if (fonts_changed_p
)
13088 goto need_larger_matrices
;
13092 /* Otherwise try_window_id has returned -1 which means that we
13093 don't want the alternative below this comment to execute. */
13095 else if (CHARPOS (startp
) >= BEGV
13096 && CHARPOS (startp
) <= ZV
13097 && PT
>= CHARPOS (startp
)
13098 && (CHARPOS (startp
) < ZV
13099 /* Avoid starting at end of buffer. */
13100 || CHARPOS (startp
) == BEGV
13101 || (XFASTINT (w
->last_modified
) >= MODIFF
13102 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
13105 /* If first window line is a continuation line, and window start
13106 is inside the modified region, but the first change is before
13107 current window start, we must select a new window start.*/
13108 if (NILP (w
->start_at_line_beg
)
13109 && CHARPOS (startp
) > BEGV
)
13111 /* Make sure beg_unchanged and end_unchanged are up to date.
13112 Do it only if buffer has really changed. This may or may
13113 not have been done by try_window_id (see which) already. */
13114 if (MODIFF
> SAVE_MODIFF
13115 /* This seems to happen sometimes after saving a buffer. */
13116 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
13118 if (GPT
- BEG
< BEG_UNCHANGED
)
13119 BEG_UNCHANGED
= GPT
- BEG
;
13120 if (Z
- GPT
< END_UNCHANGED
)
13121 END_UNCHANGED
= Z
- GPT
;
13124 if (CHARPOS (startp
) > BEG
+ BEG_UNCHANGED
13125 && CHARPOS (startp
) <= Z
- END_UNCHANGED
)
13127 /* There doesn't seems to be a simple way to find a new
13128 window start that is near the old window start, so
13129 we just recenter. */
13135 debug_method_add (w
, "same window start");
13138 /* Try to redisplay starting at same place as before.
13139 If point has not moved off frame, accept the results. */
13140 if (!current_matrix_up_to_date_p
13141 /* Don't use try_window_reusing_current_matrix in this case
13142 because a window scroll function can have changed the
13144 || !NILP (Vwindow_scroll_functions
)
13145 || MINI_WINDOW_P (w
)
13146 || !(used_current_matrix_p
13147 = try_window_reusing_current_matrix (w
)))
13149 IF_DEBUG (debug_method_add (w
, "1"));
13150 if (try_window (window
, startp
, 1) < 0)
13151 /* -1 means we need to scroll.
13152 0 means we need new matrices, but fonts_changed_p
13153 is set in that case, so we will detect it below. */
13154 goto try_to_scroll
;
13157 if (fonts_changed_p
)
13158 goto need_larger_matrices
;
13160 if (w
->cursor
.vpos
>= 0)
13162 if (!just_this_one_p
13163 || current_buffer
->clip_changed
13164 || BEG_UNCHANGED
< CHARPOS (startp
))
13165 /* Forget any recorded base line for line number display. */
13166 w
->base_line_number
= Qnil
;
13168 if (!cursor_row_fully_visible_p (w
, 1, 0))
13170 clear_glyph_matrix (w
->desired_matrix
);
13171 last_line_misfit
= 1;
13173 /* Drop through and scroll. */
13178 clear_glyph_matrix (w
->desired_matrix
);
13183 w
->last_modified
= make_number (0);
13184 w
->last_overlay_modified
= make_number (0);
13186 /* Redisplay the mode line. Select the buffer properly for that. */
13187 if (!update_mode_line
)
13189 update_mode_line
= 1;
13190 w
->update_mode_line
= Qt
;
13193 /* Try to scroll by specified few lines. */
13194 if ((scroll_conservatively
13196 || temp_scroll_step
13197 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13198 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13199 && !current_buffer
->clip_changed
13200 && CHARPOS (startp
) >= BEGV
13201 && CHARPOS (startp
) <= ZV
)
13203 /* The function returns -1 if new fonts were loaded, 1 if
13204 successful, 0 if not successful. */
13205 int rc
= try_scrolling (window
, just_this_one_p
,
13206 scroll_conservatively
,
13208 temp_scroll_step
, last_line_misfit
);
13211 case SCROLLING_SUCCESS
:
13214 case SCROLLING_NEED_LARGER_MATRICES
:
13215 goto need_larger_matrices
;
13217 case SCROLLING_FAILED
:
13225 /* Finally, just choose place to start which centers point */
13228 if (centering_position
< 0)
13229 centering_position
= window_box_height (w
) / 2;
13232 debug_method_add (w
, "recenter");
13235 /* w->vscroll = 0; */
13237 /* Forget any previously recorded base line for line number display. */
13238 if (!buffer_unchanged_p
)
13239 w
->base_line_number
= Qnil
;
13241 /* Move backward half the height of the window. */
13242 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13243 it
.current_y
= it
.last_visible_y
;
13244 move_it_vertically_backward (&it
, centering_position
);
13245 xassert (IT_CHARPOS (it
) >= BEGV
);
13247 /* The function move_it_vertically_backward may move over more
13248 than the specified y-distance. If it->w is small, e.g. a
13249 mini-buffer window, we may end up in front of the window's
13250 display area. Start displaying at the start of the line
13251 containing PT in this case. */
13252 if (it
.current_y
<= 0)
13254 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13255 move_it_vertically_backward (&it
, 0);
13257 /* I think this assert is bogus if buffer contains
13258 invisible text or images. KFS. */
13259 xassert (IT_CHARPOS (it
) <= PT
);
13264 it
.current_x
= it
.hpos
= 0;
13266 /* Set startp here explicitly in case that helps avoid an infinite loop
13267 in case the window-scroll-functions functions get errors. */
13268 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13270 /* Run scroll hooks. */
13271 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13273 /* Redisplay the window. */
13274 if (!current_matrix_up_to_date_p
13275 || windows_or_buffers_changed
13276 || cursor_type_changed
13277 /* Don't use try_window_reusing_current_matrix in this case
13278 because it can have changed the buffer. */
13279 || !NILP (Vwindow_scroll_functions
)
13280 || !just_this_one_p
13281 || MINI_WINDOW_P (w
)
13282 || !(used_current_matrix_p
13283 = try_window_reusing_current_matrix (w
)))
13284 try_window (window
, startp
, 0);
13286 /* If new fonts have been loaded (due to fontsets), give up. We
13287 have to start a new redisplay since we need to re-adjust glyph
13289 if (fonts_changed_p
)
13290 goto need_larger_matrices
;
13292 /* If cursor did not appear assume that the middle of the window is
13293 in the first line of the window. Do it again with the next line.
13294 (Imagine a window of height 100, displaying two lines of height
13295 60. Moving back 50 from it->last_visible_y will end in the first
13297 if (w
->cursor
.vpos
< 0)
13299 if (!NILP (w
->window_end_valid
)
13300 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13302 clear_glyph_matrix (w
->desired_matrix
);
13303 move_it_by_lines (&it
, 1, 0);
13304 try_window (window
, it
.current
.pos
, 0);
13306 else if (PT
< IT_CHARPOS (it
))
13308 clear_glyph_matrix (w
->desired_matrix
);
13309 move_it_by_lines (&it
, -1, 0);
13310 try_window (window
, it
.current
.pos
, 0);
13314 /* Not much we can do about it. */
13318 /* Consider the following case: Window starts at BEGV, there is
13319 invisible, intangible text at BEGV, so that display starts at
13320 some point START > BEGV. It can happen that we are called with
13321 PT somewhere between BEGV and START. Try to handle that case. */
13322 if (w
->cursor
.vpos
< 0)
13324 struct glyph_row
*row
= w
->current_matrix
->rows
;
13325 if (row
->mode_line_p
)
13327 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13330 if (!cursor_row_fully_visible_p (w
, 0, 0))
13332 /* If vscroll is enabled, disable it and try again. */
13336 clear_glyph_matrix (w
->desired_matrix
);
13340 /* If centering point failed to make the whole line visible,
13341 put point at the top instead. That has to make the whole line
13342 visible, if it can be done. */
13343 if (centering_position
== 0)
13346 clear_glyph_matrix (w
->desired_matrix
);
13347 centering_position
= 0;
13353 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13354 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13355 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13358 /* Display the mode line, if we must. */
13359 if ((update_mode_line
13360 /* If window not full width, must redo its mode line
13361 if (a) the window to its side is being redone and
13362 (b) we do a frame-based redisplay. This is a consequence
13363 of how inverted lines are drawn in frame-based redisplay. */
13364 || (!just_this_one_p
13365 && !FRAME_WINDOW_P (f
)
13366 && !WINDOW_FULL_WIDTH_P (w
))
13367 /* Line number to display. */
13368 || INTEGERP (w
->base_line_pos
)
13369 /* Column number is displayed and different from the one displayed. */
13370 || (!NILP (w
->column_number_displayed
)
13371 && (XFASTINT (w
->column_number_displayed
)
13372 != (int) current_column ()))) /* iftc */
13373 /* This means that the window has a mode line. */
13374 && (WINDOW_WANTS_MODELINE_P (w
)
13375 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13377 display_mode_lines (w
);
13379 /* If mode line height has changed, arrange for a thorough
13380 immediate redisplay using the correct mode line height. */
13381 if (WINDOW_WANTS_MODELINE_P (w
)
13382 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13384 fonts_changed_p
= 1;
13385 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13386 = DESIRED_MODE_LINE_HEIGHT (w
);
13389 /* If top line height has changed, arrange for a thorough
13390 immediate redisplay using the correct mode line height. */
13391 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13392 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13394 fonts_changed_p
= 1;
13395 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13396 = DESIRED_HEADER_LINE_HEIGHT (w
);
13399 if (fonts_changed_p
)
13400 goto need_larger_matrices
;
13403 if (!line_number_displayed
13404 && !BUFFERP (w
->base_line_pos
))
13406 w
->base_line_pos
= Qnil
;
13407 w
->base_line_number
= Qnil
;
13412 /* When we reach a frame's selected window, redo the frame's menu bar. */
13413 if (update_mode_line
13414 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13416 int redisplay_menu_p
= 0;
13417 int redisplay_tool_bar_p
= 0;
13419 if (FRAME_WINDOW_P (f
))
13421 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
13422 || defined (USE_GTK)
13423 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13425 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13429 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13431 if (redisplay_menu_p
)
13432 display_menu_bar (w
);
13434 #ifdef HAVE_WINDOW_SYSTEM
13436 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13438 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13439 && (FRAME_TOOL_BAR_LINES (f
) > 0
13440 || auto_resize_tool_bars_p
);
13444 if (redisplay_tool_bar_p
)
13445 redisplay_tool_bar (f
);
13449 #ifdef HAVE_WINDOW_SYSTEM
13450 if (FRAME_WINDOW_P (f
)
13451 && update_window_fringes (w
, (just_this_one_p
13452 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13453 || w
->pseudo_window_p
)))
13457 if (draw_window_fringes (w
, 1))
13458 x_draw_vertical_border (w
);
13462 #endif /* HAVE_WINDOW_SYSTEM */
13464 /* We go to this label, with fonts_changed_p nonzero,
13465 if it is necessary to try again using larger glyph matrices.
13466 We have to redeem the scroll bar even in this case,
13467 because the loop in redisplay_internal expects that. */
13468 need_larger_matrices
:
13470 finish_scroll_bars
:
13472 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13474 /* Set the thumb's position and size. */
13475 set_vertical_scroll_bar (w
);
13477 /* Note that we actually used the scroll bar attached to this
13478 window, so it shouldn't be deleted at the end of redisplay. */
13479 redeem_scroll_bar_hook (w
);
13482 /* Restore current_buffer and value of point in it. */
13483 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13484 set_buffer_internal_1 (old
);
13485 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13487 unbind_to (count
, Qnil
);
13491 /* Build the complete desired matrix of WINDOW with a window start
13492 buffer position POS.
13494 Value is 1 if successful. It is zero if fonts were loaded during
13495 redisplay which makes re-adjusting glyph matrices necessary, and -1
13496 if point would appear in the scroll margins.
13497 (We check that only if CHECK_MARGINS is nonzero. */
13500 try_window (window
, pos
, check_margins
)
13501 Lisp_Object window
;
13502 struct text_pos pos
;
13505 struct window
*w
= XWINDOW (window
);
13507 struct glyph_row
*last_text_row
= NULL
;
13509 /* Make POS the new window start. */
13510 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13512 /* Mark cursor position as unknown. No overlay arrow seen. */
13513 w
->cursor
.vpos
= -1;
13514 overlay_arrow_seen
= 0;
13516 /* Initialize iterator and info to start at POS. */
13517 start_display (&it
, w
, pos
);
13519 /* Display all lines of W. */
13520 while (it
.current_y
< it
.last_visible_y
)
13522 if (display_line (&it
))
13523 last_text_row
= it
.glyph_row
- 1;
13524 if (fonts_changed_p
)
13528 /* Don't let the cursor end in the scroll margins. */
13530 && !MINI_WINDOW_P (w
))
13532 int this_scroll_margin
;
13534 this_scroll_margin
= max (0, scroll_margin
);
13535 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13536 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13538 if ((w
->cursor
.y
>= 0 /* not vscrolled */
13539 && w
->cursor
.y
< this_scroll_margin
13540 && CHARPOS (pos
) > BEGV
13541 && IT_CHARPOS (it
) < ZV
)
13542 /* rms: considering make_cursor_line_fully_visible_p here
13543 seems to give wrong results. We don't want to recenter
13544 when the last line is partly visible, we want to allow
13545 that case to be handled in the usual way. */
13546 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
13548 w
->cursor
.vpos
= -1;
13549 clear_glyph_matrix (w
->desired_matrix
);
13554 /* If bottom moved off end of frame, change mode line percentage. */
13555 if (XFASTINT (w
->window_end_pos
) <= 0
13556 && Z
!= IT_CHARPOS (it
))
13557 w
->update_mode_line
= Qt
;
13559 /* Set window_end_pos to the offset of the last character displayed
13560 on the window from the end of current_buffer. Set
13561 window_end_vpos to its row number. */
13564 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
13565 w
->window_end_bytepos
13566 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13568 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13570 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13571 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
13572 ->displays_text_p
);
13576 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13577 w
->window_end_pos
= make_number (Z
- ZV
);
13578 w
->window_end_vpos
= make_number (0);
13581 /* But that is not valid info until redisplay finishes. */
13582 w
->window_end_valid
= Qnil
;
13588 /************************************************************************
13589 Window redisplay reusing current matrix when buffer has not changed
13590 ************************************************************************/
13592 /* Try redisplay of window W showing an unchanged buffer with a
13593 different window start than the last time it was displayed by
13594 reusing its current matrix. Value is non-zero if successful.
13595 W->start is the new window start. */
13598 try_window_reusing_current_matrix (w
)
13601 struct frame
*f
= XFRAME (w
->frame
);
13602 struct glyph_row
*row
, *bottom_row
;
13605 struct text_pos start
, new_start
;
13606 int nrows_scrolled
, i
;
13607 struct glyph_row
*last_text_row
;
13608 struct glyph_row
*last_reused_text_row
;
13609 struct glyph_row
*start_row
;
13610 int start_vpos
, min_y
, max_y
;
13613 if (inhibit_try_window_reusing
)
13617 if (/* This function doesn't handle terminal frames. */
13618 !FRAME_WINDOW_P (f
)
13619 /* Don't try to reuse the display if windows have been split
13621 || windows_or_buffers_changed
13622 || cursor_type_changed
)
13625 /* Can't do this if region may have changed. */
13626 if ((!NILP (Vtransient_mark_mode
)
13627 && !NILP (current_buffer
->mark_active
))
13628 || !NILP (w
->region_showing
)
13629 || !NILP (Vshow_trailing_whitespace
))
13632 /* If top-line visibility has changed, give up. */
13633 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13634 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
13637 /* Give up if old or new display is scrolled vertically. We could
13638 make this function handle this, but right now it doesn't. */
13639 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13640 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
13643 /* The variable new_start now holds the new window start. The old
13644 start `start' can be determined from the current matrix. */
13645 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
13646 start
= start_row
->start
.pos
;
13647 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13649 /* Clear the desired matrix for the display below. */
13650 clear_glyph_matrix (w
->desired_matrix
);
13652 if (CHARPOS (new_start
) <= CHARPOS (start
))
13656 /* Don't use this method if the display starts with an ellipsis
13657 displayed for invisible text. It's not easy to handle that case
13658 below, and it's certainly not worth the effort since this is
13659 not a frequent case. */
13660 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
13663 IF_DEBUG (debug_method_add (w
, "twu1"));
13665 /* Display up to a row that can be reused. The variable
13666 last_text_row is set to the last row displayed that displays
13667 text. Note that it.vpos == 0 if or if not there is a
13668 header-line; it's not the same as the MATRIX_ROW_VPOS! */
13669 start_display (&it
, w
, new_start
);
13670 first_row_y
= it
.current_y
;
13671 w
->cursor
.vpos
= -1;
13672 last_text_row
= last_reused_text_row
= NULL
;
13674 while (it
.current_y
< it
.last_visible_y
13675 && !fonts_changed_p
)
13677 /* If we have reached into the characters in the START row,
13678 that means the line boundaries have changed. So we
13679 can't start copying with the row START. Maybe it will
13680 work to start copying with the following row. */
13681 while (IT_CHARPOS (it
) > CHARPOS (start
))
13683 /* Advance to the next row as the "start". */
13685 start
= start_row
->start
.pos
;
13686 /* If there are no more rows to try, or just one, give up. */
13687 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
13688 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
13689 || CHARPOS (start
) == ZV
)
13691 clear_glyph_matrix (w
->desired_matrix
);
13695 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13697 /* If we have reached alignment,
13698 we can copy the rest of the rows. */
13699 if (IT_CHARPOS (it
) == CHARPOS (start
))
13702 if (display_line (&it
))
13703 last_text_row
= it
.glyph_row
- 1;
13706 /* A value of current_y < last_visible_y means that we stopped
13707 at the previous window start, which in turn means that we
13708 have at least one reusable row. */
13709 if (it
.current_y
< it
.last_visible_y
)
13711 /* IT.vpos always starts from 0; it counts text lines. */
13712 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
13714 /* Find PT if not already found in the lines displayed. */
13715 if (w
->cursor
.vpos
< 0)
13717 int dy
= it
.current_y
- start_row
->y
;
13719 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13720 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
13722 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
13723 dy
, nrows_scrolled
);
13726 clear_glyph_matrix (w
->desired_matrix
);
13731 /* Scroll the display. Do it before the current matrix is
13732 changed. The problem here is that update has not yet
13733 run, i.e. part of the current matrix is not up to date.
13734 scroll_run_hook will clear the cursor, and use the
13735 current matrix to get the height of the row the cursor is
13737 run
.current_y
= start_row
->y
;
13738 run
.desired_y
= it
.current_y
;
13739 run
.height
= it
.last_visible_y
- it
.current_y
;
13741 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
13744 rif
->update_window_begin_hook (w
);
13745 rif
->clear_window_mouse_face (w
);
13746 rif
->scroll_run_hook (w
, &run
);
13747 rif
->update_window_end_hook (w
, 0, 0);
13751 /* Shift current matrix down by nrows_scrolled lines. */
13752 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13753 rotate_matrix (w
->current_matrix
,
13755 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13758 /* Disable lines that must be updated. */
13759 for (i
= 0; i
< it
.vpos
; ++i
)
13760 (start_row
+ i
)->enabled_p
= 0;
13762 /* Re-compute Y positions. */
13763 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13764 max_y
= it
.last_visible_y
;
13765 for (row
= start_row
+ nrows_scrolled
;
13769 row
->y
= it
.current_y
;
13770 row
->visible_height
= row
->height
;
13772 if (row
->y
< min_y
)
13773 row
->visible_height
-= min_y
- row
->y
;
13774 if (row
->y
+ row
->height
> max_y
)
13775 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13776 row
->redraw_fringe_bitmaps_p
= 1;
13778 it
.current_y
+= row
->height
;
13780 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13781 last_reused_text_row
= row
;
13782 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13786 /* Disable lines in the current matrix which are now
13787 below the window. */
13788 for (++row
; row
< bottom_row
; ++row
)
13789 row
->enabled_p
= row
->mode_line_p
= 0;
13792 /* Update window_end_pos etc.; last_reused_text_row is the last
13793 reused row from the current matrix containing text, if any.
13794 The value of last_text_row is the last displayed line
13795 containing text. */
13796 if (last_reused_text_row
)
13798 w
->window_end_bytepos
13799 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13801 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13803 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13804 w
->current_matrix
));
13806 else if (last_text_row
)
13808 w
->window_end_bytepos
13809 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13811 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13813 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13817 /* This window must be completely empty. */
13818 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13819 w
->window_end_pos
= make_number (Z
- ZV
);
13820 w
->window_end_vpos
= make_number (0);
13822 w
->window_end_valid
= Qnil
;
13824 /* Update hint: don't try scrolling again in update_window. */
13825 w
->desired_matrix
->no_scrolling_p
= 1;
13828 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13832 else if (CHARPOS (new_start
) > CHARPOS (start
))
13834 struct glyph_row
*pt_row
, *row
;
13835 struct glyph_row
*first_reusable_row
;
13836 struct glyph_row
*first_row_to_display
;
13838 int yb
= window_text_bottom_y (w
);
13840 /* Find the row starting at new_start, if there is one. Don't
13841 reuse a partially visible line at the end. */
13842 first_reusable_row
= start_row
;
13843 while (first_reusable_row
->enabled_p
13844 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13845 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13846 < CHARPOS (new_start
)))
13847 ++first_reusable_row
;
13849 /* Give up if there is no row to reuse. */
13850 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13851 || !first_reusable_row
->enabled_p
13852 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13853 != CHARPOS (new_start
)))
13856 /* We can reuse fully visible rows beginning with
13857 first_reusable_row to the end of the window. Set
13858 first_row_to_display to the first row that cannot be reused.
13859 Set pt_row to the row containing point, if there is any. */
13861 for (first_row_to_display
= first_reusable_row
;
13862 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13863 ++first_row_to_display
)
13865 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
13866 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
13867 pt_row
= first_row_to_display
;
13870 /* Start displaying at the start of first_row_to_display. */
13871 xassert (first_row_to_display
->y
< yb
);
13872 init_to_row_start (&it
, w
, first_row_to_display
);
13874 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
13876 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
13878 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
13879 + WINDOW_HEADER_LINE_HEIGHT (w
));
13881 /* Display lines beginning with first_row_to_display in the
13882 desired matrix. Set last_text_row to the last row displayed
13883 that displays text. */
13884 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
13885 if (pt_row
== NULL
)
13886 w
->cursor
.vpos
= -1;
13887 last_text_row
= NULL
;
13888 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
13889 if (display_line (&it
))
13890 last_text_row
= it
.glyph_row
- 1;
13892 /* Give up If point isn't in a row displayed or reused. */
13893 if (w
->cursor
.vpos
< 0)
13895 clear_glyph_matrix (w
->desired_matrix
);
13899 /* If point is in a reused row, adjust y and vpos of the cursor
13903 w
->cursor
.vpos
-= nrows_scrolled
;
13904 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
13907 /* Scroll the display. */
13908 run
.current_y
= first_reusable_row
->y
;
13909 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13910 run
.height
= it
.last_visible_y
- run
.current_y
;
13911 dy
= run
.current_y
- run
.desired_y
;
13916 rif
->update_window_begin_hook (w
);
13917 rif
->clear_window_mouse_face (w
);
13918 rif
->scroll_run_hook (w
, &run
);
13919 rif
->update_window_end_hook (w
, 0, 0);
13923 /* Adjust Y positions of reused rows. */
13924 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13925 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13926 max_y
= it
.last_visible_y
;
13927 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
13930 row
->visible_height
= row
->height
;
13931 if (row
->y
< min_y
)
13932 row
->visible_height
-= min_y
- row
->y
;
13933 if (row
->y
+ row
->height
> max_y
)
13934 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13935 row
->redraw_fringe_bitmaps_p
= 1;
13938 /* Scroll the current matrix. */
13939 xassert (nrows_scrolled
> 0);
13940 rotate_matrix (w
->current_matrix
,
13942 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13945 /* Disable rows not reused. */
13946 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
13947 row
->enabled_p
= 0;
13949 /* Point may have moved to a different line, so we cannot assume that
13950 the previous cursor position is valid; locate the correct row. */
13953 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
13954 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
13958 w
->cursor
.y
= row
->y
;
13960 if (row
< bottom_row
)
13962 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
13963 while (glyph
->charpos
< PT
)
13966 w
->cursor
.x
+= glyph
->pixel_width
;
13972 /* Adjust window end. A null value of last_text_row means that
13973 the window end is in reused rows which in turn means that
13974 only its vpos can have changed. */
13977 w
->window_end_bytepos
13978 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13980 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13982 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13987 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
13990 w
->window_end_valid
= Qnil
;
13991 w
->desired_matrix
->no_scrolling_p
= 1;
13994 debug_method_add (w
, "try_window_reusing_current_matrix 2");
14004 /************************************************************************
14005 Window redisplay reusing current matrix when buffer has changed
14006 ************************************************************************/
14008 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
14009 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
14011 static struct glyph_row
*
14012 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
14013 struct glyph_row
*));
14016 /* Return the last row in MATRIX displaying text. If row START is
14017 non-null, start searching with that row. IT gives the dimensions
14018 of the display. Value is null if matrix is empty; otherwise it is
14019 a pointer to the row found. */
14021 static struct glyph_row
*
14022 find_last_row_displaying_text (matrix
, it
, start
)
14023 struct glyph_matrix
*matrix
;
14025 struct glyph_row
*start
;
14027 struct glyph_row
*row
, *row_found
;
14029 /* Set row_found to the last row in IT->w's current matrix
14030 displaying text. The loop looks funny but think of partially
14033 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14034 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14036 xassert (row
->enabled_p
);
14038 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
14047 /* Return the last row in the current matrix of W that is not affected
14048 by changes at the start of current_buffer that occurred since W's
14049 current matrix was built. Value is null if no such row exists.
14051 BEG_UNCHANGED us the number of characters unchanged at the start of
14052 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
14053 first changed character in current_buffer. Characters at positions <
14054 BEG + BEG_UNCHANGED are at the same buffer positions as they were
14055 when the current matrix was built. */
14057 static struct glyph_row
*
14058 find_last_unchanged_at_beg_row (w
)
14061 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
14062 struct glyph_row
*row
;
14063 struct glyph_row
*row_found
= NULL
;
14064 int yb
= window_text_bottom_y (w
);
14066 /* Find the last row displaying unchanged text. */
14067 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14068 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14069 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
14071 if (/* If row ends before first_changed_pos, it is unchanged,
14072 except in some case. */
14073 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
14074 /* When row ends in ZV and we write at ZV it is not
14076 && !row
->ends_at_zv_p
14077 /* When first_changed_pos is the end of a continued line,
14078 row is not unchanged because it may be no longer
14080 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
14081 && (row
->continued_p
14082 || row
->exact_window_width_line_p
)))
14085 /* Stop if last visible row. */
14086 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
14096 /* Find the first glyph row in the current matrix of W that is not
14097 affected by changes at the end of current_buffer since the
14098 time W's current matrix was built.
14100 Return in *DELTA the number of chars by which buffer positions in
14101 unchanged text at the end of current_buffer must be adjusted.
14103 Return in *DELTA_BYTES the corresponding number of bytes.
14105 Value is null if no such row exists, i.e. all rows are affected by
14108 static struct glyph_row
*
14109 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
14111 int *delta
, *delta_bytes
;
14113 struct glyph_row
*row
;
14114 struct glyph_row
*row_found
= NULL
;
14116 *delta
= *delta_bytes
= 0;
14118 /* Display must not have been paused, otherwise the current matrix
14119 is not up to date. */
14120 if (NILP (w
->window_end_valid
))
14123 /* A value of window_end_pos >= END_UNCHANGED means that the window
14124 end is in the range of changed text. If so, there is no
14125 unchanged row at the end of W's current matrix. */
14126 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
14129 /* Set row to the last row in W's current matrix displaying text. */
14130 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14132 /* If matrix is entirely empty, no unchanged row exists. */
14133 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14135 /* The value of row is the last glyph row in the matrix having a
14136 meaningful buffer position in it. The end position of row
14137 corresponds to window_end_pos. This allows us to translate
14138 buffer positions in the current matrix to current buffer
14139 positions for characters not in changed text. */
14140 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14141 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14142 int last_unchanged_pos
, last_unchanged_pos_old
;
14143 struct glyph_row
*first_text_row
14144 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14146 *delta
= Z
- Z_old
;
14147 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14149 /* Set last_unchanged_pos to the buffer position of the last
14150 character in the buffer that has not been changed. Z is the
14151 index + 1 of the last character in current_buffer, i.e. by
14152 subtracting END_UNCHANGED we get the index of the last
14153 unchanged character, and we have to add BEG to get its buffer
14155 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
14156 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
14158 /* Search backward from ROW for a row displaying a line that
14159 starts at a minimum position >= last_unchanged_pos_old. */
14160 for (; row
> first_text_row
; --row
)
14162 /* This used to abort, but it can happen.
14163 It is ok to just stop the search instead here. KFS. */
14164 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14167 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
14172 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
14179 /* Make sure that glyph rows in the current matrix of window W
14180 reference the same glyph memory as corresponding rows in the
14181 frame's frame matrix. This function is called after scrolling W's
14182 current matrix on a terminal frame in try_window_id and
14183 try_window_reusing_current_matrix. */
14186 sync_frame_with_window_matrix_rows (w
)
14189 struct frame
*f
= XFRAME (w
->frame
);
14190 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
14192 /* Preconditions: W must be a leaf window and full-width. Its frame
14193 must have a frame matrix. */
14194 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
14195 xassert (WINDOW_FULL_WIDTH_P (w
));
14196 xassert (!FRAME_WINDOW_P (f
));
14198 /* If W is a full-width window, glyph pointers in W's current matrix
14199 have, by definition, to be the same as glyph pointers in the
14200 corresponding frame matrix. Note that frame matrices have no
14201 marginal areas (see build_frame_matrix). */
14202 window_row
= w
->current_matrix
->rows
;
14203 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14204 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14205 while (window_row
< window_row_end
)
14207 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14208 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14210 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14211 frame_row
->glyphs
[TEXT_AREA
] = start
;
14212 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14213 frame_row
->glyphs
[LAST_AREA
] = end
;
14215 /* Disable frame rows whose corresponding window rows have
14216 been disabled in try_window_id. */
14217 if (!window_row
->enabled_p
)
14218 frame_row
->enabled_p
= 0;
14220 ++window_row
, ++frame_row
;
14225 /* Find the glyph row in window W containing CHARPOS. Consider all
14226 rows between START and END (not inclusive). END null means search
14227 all rows to the end of the display area of W. Value is the row
14228 containing CHARPOS or null. */
14231 row_containing_pos (w
, charpos
, start
, end
, dy
)
14234 struct glyph_row
*start
, *end
;
14237 struct glyph_row
*row
= start
;
14240 /* If we happen to start on a header-line, skip that. */
14241 if (row
->mode_line_p
)
14244 if ((end
&& row
>= end
) || !row
->enabled_p
)
14247 last_y
= window_text_bottom_y (w
) - dy
;
14251 /* Give up if we have gone too far. */
14252 if (end
&& row
>= end
)
14254 /* This formerly returned if they were equal.
14255 I think that both quantities are of a "last plus one" type;
14256 if so, when they are equal, the row is within the screen. -- rms. */
14257 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14260 /* If it is in this row, return this row. */
14261 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14262 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14263 /* The end position of a row equals the start
14264 position of the next row. If CHARPOS is there, we
14265 would rather display it in the next line, except
14266 when this line ends in ZV. */
14267 && !row
->ends_at_zv_p
14268 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14269 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14276 /* Try to redisplay window W by reusing its existing display. W's
14277 current matrix must be up to date when this function is called,
14278 i.e. window_end_valid must not be nil.
14282 1 if display has been updated
14283 0 if otherwise unsuccessful
14284 -1 if redisplay with same window start is known not to succeed
14286 The following steps are performed:
14288 1. Find the last row in the current matrix of W that is not
14289 affected by changes at the start of current_buffer. If no such row
14292 2. Find the first row in W's current matrix that is not affected by
14293 changes at the end of current_buffer. Maybe there is no such row.
14295 3. Display lines beginning with the row + 1 found in step 1 to the
14296 row found in step 2 or, if step 2 didn't find a row, to the end of
14299 4. If cursor is not known to appear on the window, give up.
14301 5. If display stopped at the row found in step 2, scroll the
14302 display and current matrix as needed.
14304 6. Maybe display some lines at the end of W, if we must. This can
14305 happen under various circumstances, like a partially visible line
14306 becoming fully visible, or because newly displayed lines are displayed
14307 in smaller font sizes.
14309 7. Update W's window end information. */
14315 struct frame
*f
= XFRAME (w
->frame
);
14316 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14317 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14318 struct glyph_row
*last_unchanged_at_beg_row
;
14319 struct glyph_row
*first_unchanged_at_end_row
;
14320 struct glyph_row
*row
;
14321 struct glyph_row
*bottom_row
;
14324 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14325 struct text_pos start_pos
;
14327 int first_unchanged_at_end_vpos
= 0;
14328 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14329 struct text_pos start
;
14330 int first_changed_charpos
, last_changed_charpos
;
14333 if (inhibit_try_window_id
)
14337 /* This is handy for debugging. */
14339 #define GIVE_UP(X) \
14341 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14345 #define GIVE_UP(X) return 0
14348 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14350 /* Don't use this for mini-windows because these can show
14351 messages and mini-buffers, and we don't handle that here. */
14352 if (MINI_WINDOW_P (w
))
14355 /* This flag is used to prevent redisplay optimizations. */
14356 if (windows_or_buffers_changed
|| cursor_type_changed
)
14359 /* Verify that narrowing has not changed.
14360 Also verify that we were not told to prevent redisplay optimizations.
14361 It would be nice to further
14362 reduce the number of cases where this prevents try_window_id. */
14363 if (current_buffer
->clip_changed
14364 || current_buffer
->prevent_redisplay_optimizations_p
)
14367 /* Window must either use window-based redisplay or be full width. */
14368 if (!FRAME_WINDOW_P (f
)
14369 && (!line_ins_del_ok
14370 || !WINDOW_FULL_WIDTH_P (w
)))
14373 /* Give up if point is not known NOT to appear in W. */
14374 if (PT
< CHARPOS (start
))
14377 /* Another way to prevent redisplay optimizations. */
14378 if (XFASTINT (w
->last_modified
) == 0)
14381 /* Verify that window is not hscrolled. */
14382 if (XFASTINT (w
->hscroll
) != 0)
14385 /* Verify that display wasn't paused. */
14386 if (NILP (w
->window_end_valid
))
14389 /* Can't use this if highlighting a region because a cursor movement
14390 will do more than just set the cursor. */
14391 if (!NILP (Vtransient_mark_mode
)
14392 && !NILP (current_buffer
->mark_active
))
14395 /* Likewise if highlighting trailing whitespace. */
14396 if (!NILP (Vshow_trailing_whitespace
))
14399 /* Likewise if showing a region. */
14400 if (!NILP (w
->region_showing
))
14403 /* Can use this if overlay arrow position and or string have changed. */
14404 if (overlay_arrows_changed_p ())
14408 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14409 only if buffer has really changed. The reason is that the gap is
14410 initially at Z for freshly visited files. The code below would
14411 set end_unchanged to 0 in that case. */
14412 if (MODIFF
> SAVE_MODIFF
14413 /* This seems to happen sometimes after saving a buffer. */
14414 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14416 if (GPT
- BEG
< BEG_UNCHANGED
)
14417 BEG_UNCHANGED
= GPT
- BEG
;
14418 if (Z
- GPT
< END_UNCHANGED
)
14419 END_UNCHANGED
= Z
- GPT
;
14422 /* The position of the first and last character that has been changed. */
14423 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14424 last_changed_charpos
= Z
- END_UNCHANGED
;
14426 /* If window starts after a line end, and the last change is in
14427 front of that newline, then changes don't affect the display.
14428 This case happens with stealth-fontification. Note that although
14429 the display is unchanged, glyph positions in the matrix have to
14430 be adjusted, of course. */
14431 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14432 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14433 && ((last_changed_charpos
< CHARPOS (start
)
14434 && CHARPOS (start
) == BEGV
)
14435 || (last_changed_charpos
< CHARPOS (start
) - 1
14436 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14438 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14439 struct glyph_row
*r0
;
14441 /* Compute how many chars/bytes have been added to or removed
14442 from the buffer. */
14443 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14444 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14446 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14448 /* Give up if PT is not in the window. Note that it already has
14449 been checked at the start of try_window_id that PT is not in
14450 front of the window start. */
14451 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14454 /* If window start is unchanged, we can reuse the whole matrix
14455 as is, after adjusting glyph positions. No need to compute
14456 the window end again, since its offset from Z hasn't changed. */
14457 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14458 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14459 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14460 /* PT must not be in a partially visible line. */
14461 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14462 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14464 /* Adjust positions in the glyph matrix. */
14465 if (delta
|| delta_bytes
)
14467 struct glyph_row
*r1
14468 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14469 increment_matrix_positions (w
->current_matrix
,
14470 MATRIX_ROW_VPOS (r0
, current_matrix
),
14471 MATRIX_ROW_VPOS (r1
, current_matrix
),
14472 delta
, delta_bytes
);
14475 /* Set the cursor. */
14476 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14478 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14485 /* Handle the case that changes are all below what is displayed in
14486 the window, and that PT is in the window. This shortcut cannot
14487 be taken if ZV is visible in the window, and text has been added
14488 there that is visible in the window. */
14489 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14490 /* ZV is not visible in the window, or there are no
14491 changes at ZV, actually. */
14492 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14493 || first_changed_charpos
== last_changed_charpos
))
14495 struct glyph_row
*r0
;
14497 /* Give up if PT is not in the window. Note that it already has
14498 been checked at the start of try_window_id that PT is not in
14499 front of the window start. */
14500 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14503 /* If window start is unchanged, we can reuse the whole matrix
14504 as is, without changing glyph positions since no text has
14505 been added/removed in front of the window end. */
14506 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14507 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14508 /* PT must not be in a partially visible line. */
14509 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14510 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14512 /* We have to compute the window end anew since text
14513 can have been added/removed after it. */
14515 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14516 w
->window_end_bytepos
14517 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14519 /* Set the cursor. */
14520 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14522 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14529 /* Give up if window start is in the changed area.
14531 The condition used to read
14533 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
14535 but why that was tested escapes me at the moment. */
14536 if (CHARPOS (start
) >= first_changed_charpos
14537 && CHARPOS (start
) <= last_changed_charpos
)
14540 /* Check that window start agrees with the start of the first glyph
14541 row in its current matrix. Check this after we know the window
14542 start is not in changed text, otherwise positions would not be
14544 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14545 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
14548 /* Give up if the window ends in strings. Overlay strings
14549 at the end are difficult to handle, so don't try. */
14550 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
14551 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
14554 /* Compute the position at which we have to start displaying new
14555 lines. Some of the lines at the top of the window might be
14556 reusable because they are not displaying changed text. Find the
14557 last row in W's current matrix not affected by changes at the
14558 start of current_buffer. Value is null if changes start in the
14559 first line of window. */
14560 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
14561 if (last_unchanged_at_beg_row
)
14563 /* Avoid starting to display in the moddle of a character, a TAB
14564 for instance. This is easier than to set up the iterator
14565 exactly, and it's not a frequent case, so the additional
14566 effort wouldn't really pay off. */
14567 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
14568 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
14569 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
14570 --last_unchanged_at_beg_row
;
14572 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
14575 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
14577 start_pos
= it
.current
.pos
;
14579 /* Start displaying new lines in the desired matrix at the same
14580 vpos we would use in the current matrix, i.e. below
14581 last_unchanged_at_beg_row. */
14582 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
14584 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14585 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
14587 xassert (it
.hpos
== 0 && it
.current_x
== 0);
14591 /* There are no reusable lines at the start of the window.
14592 Start displaying in the first text line. */
14593 start_display (&it
, w
, start
);
14594 it
.vpos
= it
.first_vpos
;
14595 start_pos
= it
.current
.pos
;
14598 /* Find the first row that is not affected by changes at the end of
14599 the buffer. Value will be null if there is no unchanged row, in
14600 which case we must redisplay to the end of the window. delta
14601 will be set to the value by which buffer positions beginning with
14602 first_unchanged_at_end_row have to be adjusted due to text
14604 first_unchanged_at_end_row
14605 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
14606 IF_DEBUG (debug_delta
= delta
);
14607 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
14609 /* Set stop_pos to the buffer position up to which we will have to
14610 display new lines. If first_unchanged_at_end_row != NULL, this
14611 is the buffer position of the start of the line displayed in that
14612 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
14613 that we don't stop at a buffer position. */
14615 if (first_unchanged_at_end_row
)
14617 xassert (last_unchanged_at_beg_row
== NULL
14618 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
14620 /* If this is a continuation line, move forward to the next one
14621 that isn't. Changes in lines above affect this line.
14622 Caution: this may move first_unchanged_at_end_row to a row
14623 not displaying text. */
14624 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
14625 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14626 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14627 < it
.last_visible_y
))
14628 ++first_unchanged_at_end_row
;
14630 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14631 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14632 >= it
.last_visible_y
))
14633 first_unchanged_at_end_row
= NULL
;
14636 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
14638 first_unchanged_at_end_vpos
14639 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
14640 xassert (stop_pos
>= Z
- END_UNCHANGED
);
14643 else if (last_unchanged_at_beg_row
== NULL
)
14649 /* Either there is no unchanged row at the end, or the one we have
14650 now displays text. This is a necessary condition for the window
14651 end pos calculation at the end of this function. */
14652 xassert (first_unchanged_at_end_row
== NULL
14653 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
14655 debug_last_unchanged_at_beg_vpos
14656 = (last_unchanged_at_beg_row
14657 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
14659 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
14661 #endif /* GLYPH_DEBUG != 0 */
14664 /* Display new lines. Set last_text_row to the last new line
14665 displayed which has text on it, i.e. might end up as being the
14666 line where the window_end_vpos is. */
14667 w
->cursor
.vpos
= -1;
14668 last_text_row
= NULL
;
14669 overlay_arrow_seen
= 0;
14670 while (it
.current_y
< it
.last_visible_y
14671 && !fonts_changed_p
14672 && (first_unchanged_at_end_row
== NULL
14673 || IT_CHARPOS (it
) < stop_pos
))
14675 if (display_line (&it
))
14676 last_text_row
= it
.glyph_row
- 1;
14679 if (fonts_changed_p
)
14683 /* Compute differences in buffer positions, y-positions etc. for
14684 lines reused at the bottom of the window. Compute what we can
14686 if (first_unchanged_at_end_row
14687 /* No lines reused because we displayed everything up to the
14688 bottom of the window. */
14689 && it
.current_y
< it
.last_visible_y
)
14692 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
14694 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
14695 run
.current_y
= first_unchanged_at_end_row
->y
;
14696 run
.desired_y
= run
.current_y
+ dy
;
14697 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
14701 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
14702 first_unchanged_at_end_row
= NULL
;
14704 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
14707 /* Find the cursor if not already found. We have to decide whether
14708 PT will appear on this window (it sometimes doesn't, but this is
14709 not a very frequent case.) This decision has to be made before
14710 the current matrix is altered. A value of cursor.vpos < 0 means
14711 that PT is either in one of the lines beginning at
14712 first_unchanged_at_end_row or below the window. Don't care for
14713 lines that might be displayed later at the window end; as
14714 mentioned, this is not a frequent case. */
14715 if (w
->cursor
.vpos
< 0)
14717 /* Cursor in unchanged rows at the top? */
14718 if (PT
< CHARPOS (start_pos
)
14719 && last_unchanged_at_beg_row
)
14721 row
= row_containing_pos (w
, PT
,
14722 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
14723 last_unchanged_at_beg_row
+ 1, 0);
14725 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14728 /* Start from first_unchanged_at_end_row looking for PT. */
14729 else if (first_unchanged_at_end_row
)
14731 row
= row_containing_pos (w
, PT
- delta
,
14732 first_unchanged_at_end_row
, NULL
, 0);
14734 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
14735 delta_bytes
, dy
, dvpos
);
14738 /* Give up if cursor was not found. */
14739 if (w
->cursor
.vpos
< 0)
14741 clear_glyph_matrix (w
->desired_matrix
);
14746 /* Don't let the cursor end in the scroll margins. */
14748 int this_scroll_margin
, cursor_height
;
14750 this_scroll_margin
= max (0, scroll_margin
);
14751 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14752 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14753 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
14755 if ((w
->cursor
.y
< this_scroll_margin
14756 && CHARPOS (start
) > BEGV
)
14757 /* Old redisplay didn't take scroll margin into account at the bottom,
14758 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14759 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14760 ? cursor_height
+ this_scroll_margin
14761 : 1)) > it
.last_visible_y
)
14763 w
->cursor
.vpos
= -1;
14764 clear_glyph_matrix (w
->desired_matrix
);
14769 /* Scroll the display. Do it before changing the current matrix so
14770 that xterm.c doesn't get confused about where the cursor glyph is
14772 if (dy
&& run
.height
)
14776 if (FRAME_WINDOW_P (f
))
14778 rif
->update_window_begin_hook (w
);
14779 rif
->clear_window_mouse_face (w
);
14780 rif
->scroll_run_hook (w
, &run
);
14781 rif
->update_window_end_hook (w
, 0, 0);
14785 /* Terminal frame. In this case, dvpos gives the number of
14786 lines to scroll by; dvpos < 0 means scroll up. */
14787 int first_unchanged_at_end_vpos
14788 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14789 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14790 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14791 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14792 + window_internal_height (w
));
14794 /* Perform the operation on the screen. */
14797 /* Scroll last_unchanged_at_beg_row to the end of the
14798 window down dvpos lines. */
14799 set_terminal_window (end
);
14801 /* On dumb terminals delete dvpos lines at the end
14802 before inserting dvpos empty lines. */
14803 if (!scroll_region_ok
)
14804 ins_del_lines (end
- dvpos
, -dvpos
);
14806 /* Insert dvpos empty lines in front of
14807 last_unchanged_at_beg_row. */
14808 ins_del_lines (from
, dvpos
);
14810 else if (dvpos
< 0)
14812 /* Scroll up last_unchanged_at_beg_vpos to the end of
14813 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14814 set_terminal_window (end
);
14816 /* Delete dvpos lines in front of
14817 last_unchanged_at_beg_vpos. ins_del_lines will set
14818 the cursor to the given vpos and emit |dvpos| delete
14820 ins_del_lines (from
+ dvpos
, dvpos
);
14822 /* On a dumb terminal insert dvpos empty lines at the
14824 if (!scroll_region_ok
)
14825 ins_del_lines (end
+ dvpos
, -dvpos
);
14828 set_terminal_window (0);
14834 /* Shift reused rows of the current matrix to the right position.
14835 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14837 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14838 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14841 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14842 bottom_vpos
, dvpos
);
14843 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14846 else if (dvpos
> 0)
14848 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14849 bottom_vpos
, dvpos
);
14850 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14851 first_unchanged_at_end_vpos
+ dvpos
, 0);
14854 /* For frame-based redisplay, make sure that current frame and window
14855 matrix are in sync with respect to glyph memory. */
14856 if (!FRAME_WINDOW_P (f
))
14857 sync_frame_with_window_matrix_rows (w
);
14859 /* Adjust buffer positions in reused rows. */
14861 increment_matrix_positions (current_matrix
,
14862 first_unchanged_at_end_vpos
+ dvpos
,
14863 bottom_vpos
, delta
, delta_bytes
);
14865 /* Adjust Y positions. */
14867 shift_glyph_matrix (w
, current_matrix
,
14868 first_unchanged_at_end_vpos
+ dvpos
,
14871 if (first_unchanged_at_end_row
)
14873 first_unchanged_at_end_row
+= dvpos
;
14874 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
14875 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
14876 first_unchanged_at_end_row
= NULL
;
14879 /* If scrolling up, there may be some lines to display at the end of
14881 last_text_row_at_end
= NULL
;
14884 /* Scrolling up can leave for example a partially visible line
14885 at the end of the window to be redisplayed. */
14886 /* Set last_row to the glyph row in the current matrix where the
14887 window end line is found. It has been moved up or down in
14888 the matrix by dvpos. */
14889 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
14890 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
14892 /* If last_row is the window end line, it should display text. */
14893 xassert (last_row
->displays_text_p
);
14895 /* If window end line was partially visible before, begin
14896 displaying at that line. Otherwise begin displaying with the
14897 line following it. */
14898 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
14900 init_to_row_start (&it
, w
, last_row
);
14901 it
.vpos
= last_vpos
;
14902 it
.current_y
= last_row
->y
;
14906 init_to_row_end (&it
, w
, last_row
);
14907 it
.vpos
= 1 + last_vpos
;
14908 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
14912 /* We may start in a continuation line. If so, we have to
14913 get the right continuation_lines_width and current_x. */
14914 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
14915 it
.hpos
= it
.current_x
= 0;
14917 /* Display the rest of the lines at the window end. */
14918 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14919 while (it
.current_y
< it
.last_visible_y
14920 && !fonts_changed_p
)
14922 /* Is it always sure that the display agrees with lines in
14923 the current matrix? I don't think so, so we mark rows
14924 displayed invalid in the current matrix by setting their
14925 enabled_p flag to zero. */
14926 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
14927 if (display_line (&it
))
14928 last_text_row_at_end
= it
.glyph_row
- 1;
14932 /* Update window_end_pos and window_end_vpos. */
14933 if (first_unchanged_at_end_row
14934 && !last_text_row_at_end
)
14936 /* Window end line if one of the preserved rows from the current
14937 matrix. Set row to the last row displaying text in current
14938 matrix starting at first_unchanged_at_end_row, after
14940 xassert (first_unchanged_at_end_row
->displays_text_p
);
14941 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
14942 first_unchanged_at_end_row
);
14943 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
14945 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14946 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14948 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
14949 xassert (w
->window_end_bytepos
>= 0);
14950 IF_DEBUG (debug_method_add (w
, "A"));
14952 else if (last_text_row_at_end
)
14955 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
14956 w
->window_end_bytepos
14957 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
14959 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
14960 xassert (w
->window_end_bytepos
>= 0);
14961 IF_DEBUG (debug_method_add (w
, "B"));
14963 else if (last_text_row
)
14965 /* We have displayed either to the end of the window or at the
14966 end of the window, i.e. the last row with text is to be found
14967 in the desired matrix. */
14969 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14970 w
->window_end_bytepos
14971 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14973 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
14974 xassert (w
->window_end_bytepos
>= 0);
14976 else if (first_unchanged_at_end_row
== NULL
14977 && last_text_row
== NULL
14978 && last_text_row_at_end
== NULL
)
14980 /* Displayed to end of window, but no line containing text was
14981 displayed. Lines were deleted at the end of the window. */
14982 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
14983 int vpos
= XFASTINT (w
->window_end_vpos
);
14984 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
14985 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
14988 row
== NULL
&& vpos
>= first_vpos
;
14989 --vpos
, --current_row
, --desired_row
)
14991 if (desired_row
->enabled_p
)
14993 if (desired_row
->displays_text_p
)
14996 else if (current_row
->displays_text_p
)
15000 xassert (row
!= NULL
);
15001 w
->window_end_vpos
= make_number (vpos
+ 1);
15002 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15003 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15004 xassert (w
->window_end_bytepos
>= 0);
15005 IF_DEBUG (debug_method_add (w
, "C"));
15010 #if 0 /* This leads to problems, for instance when the cursor is
15011 at ZV, and the cursor line displays no text. */
15012 /* Disable rows below what's displayed in the window. This makes
15013 debugging easier. */
15014 enable_glyph_matrix_rows (current_matrix
,
15015 XFASTINT (w
->window_end_vpos
) + 1,
15019 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
15020 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
15022 /* Record that display has not been completed. */
15023 w
->window_end_valid
= Qnil
;
15024 w
->desired_matrix
->no_scrolling_p
= 1;
15032 /***********************************************************************
15033 More debugging support
15034 ***********************************************************************/
15038 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
15039 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
15040 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
15043 /* Dump the contents of glyph matrix MATRIX on stderr.
15045 GLYPHS 0 means don't show glyph contents.
15046 GLYPHS 1 means show glyphs in short form
15047 GLYPHS > 1 means show glyphs in long form. */
15050 dump_glyph_matrix (matrix
, glyphs
)
15051 struct glyph_matrix
*matrix
;
15055 for (i
= 0; i
< matrix
->nrows
; ++i
)
15056 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
15060 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
15061 the glyph row and area where the glyph comes from. */
15064 dump_glyph (row
, glyph
, area
)
15065 struct glyph_row
*row
;
15066 struct glyph
*glyph
;
15069 if (glyph
->type
== CHAR_GLYPH
)
15072 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15073 glyph
- row
->glyphs
[TEXT_AREA
],
15076 (BUFFERP (glyph
->object
)
15078 : (STRINGP (glyph
->object
)
15081 glyph
->pixel_width
,
15083 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
15087 glyph
->left_box_line_p
,
15088 glyph
->right_box_line_p
);
15090 else if (glyph
->type
== STRETCH_GLYPH
)
15093 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15094 glyph
- row
->glyphs
[TEXT_AREA
],
15097 (BUFFERP (glyph
->object
)
15099 : (STRINGP (glyph
->object
)
15102 glyph
->pixel_width
,
15106 glyph
->left_box_line_p
,
15107 glyph
->right_box_line_p
);
15109 else if (glyph
->type
== IMAGE_GLYPH
)
15112 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15113 glyph
- row
->glyphs
[TEXT_AREA
],
15116 (BUFFERP (glyph
->object
)
15118 : (STRINGP (glyph
->object
)
15121 glyph
->pixel_width
,
15125 glyph
->left_box_line_p
,
15126 glyph
->right_box_line_p
);
15128 else if (glyph
->type
== COMPOSITE_GLYPH
)
15131 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15132 glyph
- row
->glyphs
[TEXT_AREA
],
15135 (BUFFERP (glyph
->object
)
15137 : (STRINGP (glyph
->object
)
15140 glyph
->pixel_width
,
15144 glyph
->left_box_line_p
,
15145 glyph
->right_box_line_p
);
15150 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
15151 GLYPHS 0 means don't show glyph contents.
15152 GLYPHS 1 means show glyphs in short form
15153 GLYPHS > 1 means show glyphs in long form. */
15156 dump_glyph_row (row
, vpos
, glyphs
)
15157 struct glyph_row
*row
;
15162 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
15163 fprintf (stderr
, "======================================================================\n");
15165 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
15166 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
15168 MATRIX_ROW_START_CHARPOS (row
),
15169 MATRIX_ROW_END_CHARPOS (row
),
15170 row
->used
[TEXT_AREA
],
15171 row
->contains_overlapping_glyphs_p
,
15173 row
->truncated_on_left_p
,
15174 row
->truncated_on_right_p
,
15176 MATRIX_ROW_CONTINUATION_LINE_P (row
),
15177 row
->displays_text_p
,
15180 row
->ends_in_middle_of_char_p
,
15181 row
->starts_in_middle_of_char_p
,
15187 row
->visible_height
,
15190 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
15191 row
->end
.overlay_string_index
,
15192 row
->continuation_lines_width
);
15193 fprintf (stderr
, "%9d %5d\n",
15194 CHARPOS (row
->start
.string_pos
),
15195 CHARPOS (row
->end
.string_pos
));
15196 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
15197 row
->end
.dpvec_index
);
15204 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15206 struct glyph
*glyph
= row
->glyphs
[area
];
15207 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
15209 /* Glyph for a line end in text. */
15210 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
15213 if (glyph
< glyph_end
)
15214 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15216 for (; glyph
< glyph_end
; ++glyph
)
15217 dump_glyph (row
, glyph
, area
);
15220 else if (glyphs
== 1)
15224 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15226 char *s
= (char *) alloca (row
->used
[area
] + 1);
15229 for (i
= 0; i
< row
->used
[area
]; ++i
)
15231 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15232 if (glyph
->type
== CHAR_GLYPH
15233 && glyph
->u
.ch
< 0x80
15234 && glyph
->u
.ch
>= ' ')
15235 s
[i
] = glyph
->u
.ch
;
15241 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15247 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15248 Sdump_glyph_matrix
, 0, 1, "p",
15249 doc
: /* Dump the current matrix of the selected window to stderr.
15250 Shows contents of glyph row structures. With non-nil
15251 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15252 glyphs in short form, otherwise show glyphs in long form. */)
15254 Lisp_Object glyphs
;
15256 struct window
*w
= XWINDOW (selected_window
);
15257 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15259 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15260 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15261 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15262 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15263 fprintf (stderr
, "=============================================\n");
15264 dump_glyph_matrix (w
->current_matrix
,
15265 NILP (glyphs
) ? 0 : XINT (glyphs
));
15270 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15271 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15274 struct frame
*f
= XFRAME (selected_frame
);
15275 dump_glyph_matrix (f
->current_matrix
, 1);
15280 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15281 doc
: /* Dump glyph row ROW to stderr.
15282 GLYPH 0 means don't dump glyphs.
15283 GLYPH 1 means dump glyphs in short form.
15284 GLYPH > 1 or omitted means dump glyphs in long form. */)
15286 Lisp_Object row
, glyphs
;
15288 struct glyph_matrix
*matrix
;
15291 CHECK_NUMBER (row
);
15292 matrix
= XWINDOW (selected_window
)->current_matrix
;
15294 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15295 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15297 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15302 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15303 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15304 GLYPH 0 means don't dump glyphs.
15305 GLYPH 1 means dump glyphs in short form.
15306 GLYPH > 1 or omitted means dump glyphs in long form. */)
15308 Lisp_Object row
, glyphs
;
15310 struct frame
*sf
= SELECTED_FRAME ();
15311 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15314 CHECK_NUMBER (row
);
15316 if (vpos
>= 0 && vpos
< m
->nrows
)
15317 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15318 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15323 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15324 doc
: /* Toggle tracing of redisplay.
15325 With ARG, turn tracing on if and only if ARG is positive. */)
15330 trace_redisplay_p
= !trace_redisplay_p
;
15333 arg
= Fprefix_numeric_value (arg
);
15334 trace_redisplay_p
= XINT (arg
) > 0;
15341 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15342 doc
: /* Like `format', but print result to stderr.
15343 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15348 Lisp_Object s
= Fformat (nargs
, args
);
15349 fprintf (stderr
, "%s", SDATA (s
));
15353 #endif /* GLYPH_DEBUG */
15357 /***********************************************************************
15358 Building Desired Matrix Rows
15359 ***********************************************************************/
15361 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15362 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15364 static struct glyph_row
*
15365 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15367 Lisp_Object overlay_arrow_string
;
15369 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15370 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15371 struct buffer
*old
= current_buffer
;
15372 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15373 int arrow_len
= SCHARS (overlay_arrow_string
);
15374 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15375 const unsigned char *p
;
15378 int n_glyphs_before
;
15380 set_buffer_temp (buffer
);
15381 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15382 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15383 SET_TEXT_POS (it
.position
, 0, 0);
15385 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15387 while (p
< arrow_end
)
15389 Lisp_Object face
, ilisp
;
15391 /* Get the next character. */
15393 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15395 it
.c
= *p
, it
.len
= 1;
15398 /* Get its face. */
15399 ilisp
= make_number (p
- arrow_string
);
15400 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15401 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15403 /* Compute its width, get its glyphs. */
15404 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15405 SET_TEXT_POS (it
.position
, -1, -1);
15406 PRODUCE_GLYPHS (&it
);
15408 /* If this character doesn't fit any more in the line, we have
15409 to remove some glyphs. */
15410 if (it
.current_x
> it
.last_visible_x
)
15412 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15417 set_buffer_temp (old
);
15418 return it
.glyph_row
;
15422 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15423 glyphs are only inserted for terminal frames since we can't really
15424 win with truncation glyphs when partially visible glyphs are
15425 involved. Which glyphs to insert is determined by
15426 produce_special_glyphs. */
15429 insert_left_trunc_glyphs (it
)
15432 struct it truncate_it
;
15433 struct glyph
*from
, *end
, *to
, *toend
;
15435 xassert (!FRAME_WINDOW_P (it
->f
));
15437 /* Get the truncation glyphs. */
15439 truncate_it
.current_x
= 0;
15440 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15441 truncate_it
.glyph_row
= &scratch_glyph_row
;
15442 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15443 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15444 truncate_it
.object
= make_number (0);
15445 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15447 /* Overwrite glyphs from IT with truncation glyphs. */
15448 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15449 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15450 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15451 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15456 /* There may be padding glyphs left over. Overwrite them too. */
15457 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15459 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15465 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15469 /* Compute the pixel height and width of IT->glyph_row.
15471 Most of the time, ascent and height of a display line will be equal
15472 to the max_ascent and max_height values of the display iterator
15473 structure. This is not the case if
15475 1. We hit ZV without displaying anything. In this case, max_ascent
15476 and max_height will be zero.
15478 2. We have some glyphs that don't contribute to the line height.
15479 (The glyph row flag contributes_to_line_height_p is for future
15480 pixmap extensions).
15482 The first case is easily covered by using default values because in
15483 these cases, the line height does not really matter, except that it
15484 must not be zero. */
15487 compute_line_metrics (it
)
15490 struct glyph_row
*row
= it
->glyph_row
;
15493 if (FRAME_WINDOW_P (it
->f
))
15495 int i
, min_y
, max_y
;
15497 /* The line may consist of one space only, that was added to
15498 place the cursor on it. If so, the row's height hasn't been
15500 if (row
->height
== 0)
15502 if (it
->max_ascent
+ it
->max_descent
== 0)
15503 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15504 row
->ascent
= it
->max_ascent
;
15505 row
->height
= it
->max_ascent
+ it
->max_descent
;
15506 row
->phys_ascent
= it
->max_phys_ascent
;
15507 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15508 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15511 /* Compute the width of this line. */
15512 row
->pixel_width
= row
->x
;
15513 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15514 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15516 xassert (row
->pixel_width
>= 0);
15517 xassert (row
->ascent
>= 0 && row
->height
> 0);
15519 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15520 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15522 /* If first line's physical ascent is larger than its logical
15523 ascent, use the physical ascent, and make the row taller.
15524 This makes accented characters fully visible. */
15525 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
15526 && row
->phys_ascent
> row
->ascent
)
15528 row
->height
+= row
->phys_ascent
- row
->ascent
;
15529 row
->ascent
= row
->phys_ascent
;
15532 /* Compute how much of the line is visible. */
15533 row
->visible_height
= row
->height
;
15535 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
15536 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
15538 if (row
->y
< min_y
)
15539 row
->visible_height
-= min_y
- row
->y
;
15540 if (row
->y
+ row
->height
> max_y
)
15541 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15545 row
->pixel_width
= row
->used
[TEXT_AREA
];
15546 if (row
->continued_p
)
15547 row
->pixel_width
-= it
->continuation_pixel_width
;
15548 else if (row
->truncated_on_right_p
)
15549 row
->pixel_width
-= it
->truncation_pixel_width
;
15550 row
->ascent
= row
->phys_ascent
= 0;
15551 row
->height
= row
->phys_height
= row
->visible_height
= 1;
15552 row
->extra_line_spacing
= 0;
15555 /* Compute a hash code for this row. */
15557 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15558 for (i
= 0; i
< row
->used
[area
]; ++i
)
15559 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
15560 + row
->glyphs
[area
][i
].u
.val
15561 + row
->glyphs
[area
][i
].face_id
15562 + row
->glyphs
[area
][i
].padding_p
15563 + (row
->glyphs
[area
][i
].type
<< 2));
15565 it
->max_ascent
= it
->max_descent
= 0;
15566 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
15570 /* Append one space to the glyph row of iterator IT if doing a
15571 window-based redisplay. The space has the same face as
15572 IT->face_id. Value is non-zero if a space was added.
15574 This function is called to make sure that there is always one glyph
15575 at the end of a glyph row that the cursor can be set on under
15576 window-systems. (If there weren't such a glyph we would not know
15577 how wide and tall a box cursor should be displayed).
15579 At the same time this space let's a nicely handle clearing to the
15580 end of the line if the row ends in italic text. */
15583 append_space_for_newline (it
, default_face_p
)
15585 int default_face_p
;
15587 if (FRAME_WINDOW_P (it
->f
))
15589 int n
= it
->glyph_row
->used
[TEXT_AREA
];
15591 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
15592 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
15594 /* Save some values that must not be changed.
15595 Must save IT->c and IT->len because otherwise
15596 ITERATOR_AT_END_P wouldn't work anymore after
15597 append_space_for_newline has been called. */
15598 enum display_element_type saved_what
= it
->what
;
15599 int saved_c
= it
->c
, saved_len
= it
->len
;
15600 int saved_x
= it
->current_x
;
15601 int saved_face_id
= it
->face_id
;
15602 struct text_pos saved_pos
;
15603 Lisp_Object saved_object
;
15606 saved_object
= it
->object
;
15607 saved_pos
= it
->position
;
15609 it
->what
= IT_CHARACTER
;
15610 bzero (&it
->position
, sizeof it
->position
);
15611 it
->object
= make_number (0);
15615 if (default_face_p
)
15616 it
->face_id
= DEFAULT_FACE_ID
;
15617 else if (it
->face_before_selective_p
)
15618 it
->face_id
= it
->saved_face_id
;
15619 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15620 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
15622 PRODUCE_GLYPHS (it
);
15624 it
->override_ascent
= -1;
15625 it
->constrain_row_ascent_descent_p
= 0;
15626 it
->current_x
= saved_x
;
15627 it
->object
= saved_object
;
15628 it
->position
= saved_pos
;
15629 it
->what
= saved_what
;
15630 it
->face_id
= saved_face_id
;
15631 it
->len
= saved_len
;
15641 /* Extend the face of the last glyph in the text area of IT->glyph_row
15642 to the end of the display line. Called from display_line.
15643 If the glyph row is empty, add a space glyph to it so that we
15644 know the face to draw. Set the glyph row flag fill_line_p. */
15647 extend_face_to_end_of_line (it
)
15651 struct frame
*f
= it
->f
;
15653 /* If line is already filled, do nothing. */
15654 if (it
->current_x
>= it
->last_visible_x
)
15657 /* Face extension extends the background and box of IT->face_id
15658 to the end of the line. If the background equals the background
15659 of the frame, we don't have to do anything. */
15660 if (it
->face_before_selective_p
)
15661 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
15663 face
= FACE_FROM_ID (f
, it
->face_id
);
15665 if (FRAME_WINDOW_P (f
)
15666 && it
->glyph_row
->displays_text_p
15667 && face
->box
== FACE_NO_BOX
15668 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
15672 /* Set the glyph row flag indicating that the face of the last glyph
15673 in the text area has to be drawn to the end of the text area. */
15674 it
->glyph_row
->fill_line_p
= 1;
15676 /* If current character of IT is not ASCII, make sure we have the
15677 ASCII face. This will be automatically undone the next time
15678 get_next_display_element returns a multibyte character. Note
15679 that the character will always be single byte in unibyte text. */
15680 if (!SINGLE_BYTE_CHAR_P (it
->c
))
15682 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
15685 if (FRAME_WINDOW_P (f
))
15687 /* If the row is empty, add a space with the current face of IT,
15688 so that we know which face to draw. */
15689 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
15691 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
15692 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
15693 it
->glyph_row
->used
[TEXT_AREA
] = 1;
15698 /* Save some values that must not be changed. */
15699 int saved_x
= it
->current_x
;
15700 struct text_pos saved_pos
;
15701 Lisp_Object saved_object
;
15702 enum display_element_type saved_what
= it
->what
;
15703 int saved_face_id
= it
->face_id
;
15705 saved_object
= it
->object
;
15706 saved_pos
= it
->position
;
15708 it
->what
= IT_CHARACTER
;
15709 bzero (&it
->position
, sizeof it
->position
);
15710 it
->object
= make_number (0);
15713 it
->face_id
= face
->id
;
15715 PRODUCE_GLYPHS (it
);
15717 while (it
->current_x
<= it
->last_visible_x
)
15718 PRODUCE_GLYPHS (it
);
15720 /* Don't count these blanks really. It would let us insert a left
15721 truncation glyph below and make us set the cursor on them, maybe. */
15722 it
->current_x
= saved_x
;
15723 it
->object
= saved_object
;
15724 it
->position
= saved_pos
;
15725 it
->what
= saved_what
;
15726 it
->face_id
= saved_face_id
;
15731 /* Value is non-zero if text starting at CHARPOS in current_buffer is
15732 trailing whitespace. */
15735 trailing_whitespace_p (charpos
)
15738 int bytepos
= CHAR_TO_BYTE (charpos
);
15741 while (bytepos
< ZV_BYTE
15742 && (c
= FETCH_CHAR (bytepos
),
15743 c
== ' ' || c
== '\t'))
15746 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
15748 if (bytepos
!= PT_BYTE
)
15755 /* Highlight trailing whitespace, if any, in ROW. */
15758 highlight_trailing_whitespace (f
, row
)
15760 struct glyph_row
*row
;
15762 int used
= row
->used
[TEXT_AREA
];
15766 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
15767 struct glyph
*glyph
= start
+ used
- 1;
15769 /* Skip over glyphs inserted to display the cursor at the
15770 end of a line, for extending the face of the last glyph
15771 to the end of the line on terminals, and for truncation
15772 and continuation glyphs. */
15773 while (glyph
>= start
15774 && glyph
->type
== CHAR_GLYPH
15775 && INTEGERP (glyph
->object
))
15778 /* If last glyph is a space or stretch, and it's trailing
15779 whitespace, set the face of all trailing whitespace glyphs in
15780 IT->glyph_row to `trailing-whitespace'. */
15782 && BUFFERP (glyph
->object
)
15783 && (glyph
->type
== STRETCH_GLYPH
15784 || (glyph
->type
== CHAR_GLYPH
15785 && glyph
->u
.ch
== ' '))
15786 && trailing_whitespace_p (glyph
->charpos
))
15788 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
15792 while (glyph
>= start
15793 && BUFFERP (glyph
->object
)
15794 && (glyph
->type
== STRETCH_GLYPH
15795 || (glyph
->type
== CHAR_GLYPH
15796 && glyph
->u
.ch
== ' ')))
15797 (glyph
--)->face_id
= face_id
;
15803 /* Value is non-zero if glyph row ROW in window W should be
15804 used to hold the cursor. */
15807 cursor_row_p (w
, row
)
15809 struct glyph_row
*row
;
15811 int cursor_row_p
= 1;
15813 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15815 /* If the row ends with a newline from a string, we don't want
15816 the cursor there, but we still want it at the start of the
15817 string if the string starts in this row.
15818 If the row is continued it doesn't end in a newline. */
15819 if (CHARPOS (row
->end
.string_pos
) >= 0)
15820 cursor_row_p
= (row
->continued_p
15821 || PT
>= MATRIX_ROW_START_CHARPOS (row
));
15822 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15824 /* If the row ends in middle of a real character,
15825 and the line is continued, we want the cursor here.
15826 That's because MATRIX_ROW_END_CHARPOS would equal
15827 PT if PT is before the character. */
15828 if (!row
->ends_in_ellipsis_p
)
15829 cursor_row_p
= row
->continued_p
;
15831 /* If the row ends in an ellipsis, then
15832 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15833 We want that position to be displayed after the ellipsis. */
15836 /* If the row ends at ZV, display the cursor at the end of that
15837 row instead of at the start of the row below. */
15838 else if (row
->ends_at_zv_p
)
15844 return cursor_row_p
;
15848 /* Construct the glyph row IT->glyph_row in the desired matrix of
15849 IT->w from text at the current position of IT. See dispextern.h
15850 for an overview of struct it. Value is non-zero if
15851 IT->glyph_row displays text, as opposed to a line displaying ZV
15858 struct glyph_row
*row
= it
->glyph_row
;
15859 Lisp_Object overlay_arrow_string
;
15861 /* We always start displaying at hpos zero even if hscrolled. */
15862 xassert (it
->hpos
== 0 && it
->current_x
== 0);
15864 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
15865 >= it
->w
->desired_matrix
->nrows
)
15867 it
->w
->nrows_scale_factor
++;
15868 fonts_changed_p
= 1;
15872 /* Is IT->w showing the region? */
15873 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
15875 /* Clear the result glyph row and enable it. */
15876 prepare_desired_row (row
);
15878 row
->y
= it
->current_y
;
15879 row
->start
= it
->start
;
15880 row
->continuation_lines_width
= it
->continuation_lines_width
;
15881 row
->displays_text_p
= 1;
15882 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
15883 it
->starts_in_middle_of_char_p
= 0;
15885 /* Arrange the overlays nicely for our purposes. Usually, we call
15886 display_line on only one line at a time, in which case this
15887 can't really hurt too much, or we call it on lines which appear
15888 one after another in the buffer, in which case all calls to
15889 recenter_overlay_lists but the first will be pretty cheap. */
15890 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
15892 /* Move over display elements that are not visible because we are
15893 hscrolled. This may stop at an x-position < IT->first_visible_x
15894 if the first glyph is partially visible or if we hit a line end. */
15895 if (it
->current_x
< it
->first_visible_x
)
15897 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
15898 MOVE_TO_POS
| MOVE_TO_X
);
15901 /* Get the initial row height. This is either the height of the
15902 text hscrolled, if there is any, or zero. */
15903 row
->ascent
= it
->max_ascent
;
15904 row
->height
= it
->max_ascent
+ it
->max_descent
;
15905 row
->phys_ascent
= it
->max_phys_ascent
;
15906 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15907 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15909 /* Loop generating characters. The loop is left with IT on the next
15910 character to display. */
15913 int n_glyphs_before
, hpos_before
, x_before
;
15915 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
15917 /* Retrieve the next thing to display. Value is zero if end of
15919 if (!get_next_display_element (it
))
15921 /* Maybe add a space at the end of this line that is used to
15922 display the cursor there under X. Set the charpos of the
15923 first glyph of blank lines not corresponding to any text
15925 #ifdef HAVE_WINDOW_SYSTEM
15926 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15927 row
->exact_window_width_line_p
= 1;
15929 #endif /* HAVE_WINDOW_SYSTEM */
15930 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
15931 || row
->used
[TEXT_AREA
] == 0)
15933 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
15934 row
->displays_text_p
= 0;
15936 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
15937 && (!MINI_WINDOW_P (it
->w
)
15938 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
15939 row
->indicate_empty_line_p
= 1;
15942 it
->continuation_lines_width
= 0;
15943 row
->ends_at_zv_p
= 1;
15947 /* Now, get the metrics of what we want to display. This also
15948 generates glyphs in `row' (which is IT->glyph_row). */
15949 n_glyphs_before
= row
->used
[TEXT_AREA
];
15952 /* Remember the line height so far in case the next element doesn't
15953 fit on the line. */
15954 if (!it
->truncate_lines_p
)
15956 ascent
= it
->max_ascent
;
15957 descent
= it
->max_descent
;
15958 phys_ascent
= it
->max_phys_ascent
;
15959 phys_descent
= it
->max_phys_descent
;
15962 PRODUCE_GLYPHS (it
);
15964 /* If this display element was in marginal areas, continue with
15966 if (it
->area
!= TEXT_AREA
)
15968 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15969 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15970 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15971 row
->phys_height
= max (row
->phys_height
,
15972 it
->max_phys_ascent
+ it
->max_phys_descent
);
15973 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15974 it
->max_extra_line_spacing
);
15975 set_iterator_to_next (it
, 1);
15979 /* Does the display element fit on the line? If we truncate
15980 lines, we should draw past the right edge of the window. If
15981 we don't truncate, we want to stop so that we can display the
15982 continuation glyph before the right margin. If lines are
15983 continued, there are two possible strategies for characters
15984 resulting in more than 1 glyph (e.g. tabs): Display as many
15985 glyphs as possible in this line and leave the rest for the
15986 continuation line, or display the whole element in the next
15987 line. Original redisplay did the former, so we do it also. */
15988 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
15989 hpos_before
= it
->hpos
;
15992 if (/* Not a newline. */
15994 /* Glyphs produced fit entirely in the line. */
15995 && it
->current_x
< it
->last_visible_x
)
15997 it
->hpos
+= nglyphs
;
15998 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15999 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16000 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16001 row
->phys_height
= max (row
->phys_height
,
16002 it
->max_phys_ascent
+ it
->max_phys_descent
);
16003 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16004 it
->max_extra_line_spacing
);
16005 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
16006 row
->x
= x
- it
->first_visible_x
;
16011 struct glyph
*glyph
;
16013 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
16015 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16016 new_x
= x
+ glyph
->pixel_width
;
16018 if (/* Lines are continued. */
16019 !it
->truncate_lines_p
16020 && (/* Glyph doesn't fit on the line. */
16021 new_x
> it
->last_visible_x
16022 /* Or it fits exactly on a window system frame. */
16023 || (new_x
== it
->last_visible_x
16024 && FRAME_WINDOW_P (it
->f
))))
16026 /* End of a continued line. */
16029 || (new_x
== it
->last_visible_x
16030 && FRAME_WINDOW_P (it
->f
)))
16032 /* Current glyph is the only one on the line or
16033 fits exactly on the line. We must continue
16034 the line because we can't draw the cursor
16035 after the glyph. */
16036 row
->continued_p
= 1;
16037 it
->current_x
= new_x
;
16038 it
->continuation_lines_width
+= new_x
;
16040 if (i
== nglyphs
- 1)
16042 set_iterator_to_next (it
, 1);
16043 #ifdef HAVE_WINDOW_SYSTEM
16044 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16046 if (!get_next_display_element (it
))
16048 row
->exact_window_width_line_p
= 1;
16049 it
->continuation_lines_width
= 0;
16050 row
->continued_p
= 0;
16051 row
->ends_at_zv_p
= 1;
16053 else if (ITERATOR_AT_END_OF_LINE_P (it
))
16055 row
->continued_p
= 0;
16056 row
->exact_window_width_line_p
= 1;
16059 #endif /* HAVE_WINDOW_SYSTEM */
16062 else if (CHAR_GLYPH_PADDING_P (*glyph
)
16063 && !FRAME_WINDOW_P (it
->f
))
16065 /* A padding glyph that doesn't fit on this line.
16066 This means the whole character doesn't fit
16068 row
->used
[TEXT_AREA
] = n_glyphs_before
;
16070 /* Fill the rest of the row with continuation
16071 glyphs like in 20.x. */
16072 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
16073 < row
->glyphs
[1 + TEXT_AREA
])
16074 produce_special_glyphs (it
, IT_CONTINUATION
);
16076 row
->continued_p
= 1;
16077 it
->current_x
= x_before
;
16078 it
->continuation_lines_width
+= x_before
;
16080 /* Restore the height to what it was before the
16081 element not fitting on the line. */
16082 it
->max_ascent
= ascent
;
16083 it
->max_descent
= descent
;
16084 it
->max_phys_ascent
= phys_ascent
;
16085 it
->max_phys_descent
= phys_descent
;
16087 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
16089 /* A TAB that extends past the right edge of the
16090 window. This produces a single glyph on
16091 window system frames. We leave the glyph in
16092 this row and let it fill the row, but don't
16093 consume the TAB. */
16094 it
->continuation_lines_width
+= it
->last_visible_x
;
16095 row
->ends_in_middle_of_char_p
= 1;
16096 row
->continued_p
= 1;
16097 glyph
->pixel_width
= it
->last_visible_x
- x
;
16098 it
->starts_in_middle_of_char_p
= 1;
16102 /* Something other than a TAB that draws past
16103 the right edge of the window. Restore
16104 positions to values before the element. */
16105 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16107 /* Display continuation glyphs. */
16108 if (!FRAME_WINDOW_P (it
->f
))
16109 produce_special_glyphs (it
, IT_CONTINUATION
);
16110 row
->continued_p
= 1;
16112 it
->current_x
= x_before
;
16113 it
->continuation_lines_width
+= x
;
16114 extend_face_to_end_of_line (it
);
16116 if (nglyphs
> 1 && i
> 0)
16118 row
->ends_in_middle_of_char_p
= 1;
16119 it
->starts_in_middle_of_char_p
= 1;
16122 /* Restore the height to what it was before the
16123 element not fitting on the line. */
16124 it
->max_ascent
= ascent
;
16125 it
->max_descent
= descent
;
16126 it
->max_phys_ascent
= phys_ascent
;
16127 it
->max_phys_descent
= phys_descent
;
16132 else if (new_x
> it
->first_visible_x
)
16134 /* Increment number of glyphs actually displayed. */
16137 if (x
< it
->first_visible_x
)
16138 /* Glyph is partially visible, i.e. row starts at
16139 negative X position. */
16140 row
->x
= x
- it
->first_visible_x
;
16144 /* Glyph is completely off the left margin of the
16145 window. This should not happen because of the
16146 move_it_in_display_line at the start of this
16147 function, unless the text display area of the
16148 window is empty. */
16149 xassert (it
->first_visible_x
<= it
->last_visible_x
);
16153 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16154 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16155 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16156 row
->phys_height
= max (row
->phys_height
,
16157 it
->max_phys_ascent
+ it
->max_phys_descent
);
16158 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16159 it
->max_extra_line_spacing
);
16161 /* End of this display line if row is continued. */
16162 if (row
->continued_p
|| row
->ends_at_zv_p
)
16167 /* Is this a line end? If yes, we're also done, after making
16168 sure that a non-default face is extended up to the right
16169 margin of the window. */
16170 if (ITERATOR_AT_END_OF_LINE_P (it
))
16172 int used_before
= row
->used
[TEXT_AREA
];
16174 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
16176 #ifdef HAVE_WINDOW_SYSTEM
16177 /* Add a space at the end of the line that is used to
16178 display the cursor there. */
16179 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16180 append_space_for_newline (it
, 0);
16181 #endif /* HAVE_WINDOW_SYSTEM */
16183 /* Extend the face to the end of the line. */
16184 extend_face_to_end_of_line (it
);
16186 /* Make sure we have the position. */
16187 if (used_before
== 0)
16188 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
16190 /* Consume the line end. This skips over invisible lines. */
16191 set_iterator_to_next (it
, 1);
16192 it
->continuation_lines_width
= 0;
16196 /* Proceed with next display element. Note that this skips
16197 over lines invisible because of selective display. */
16198 set_iterator_to_next (it
, 1);
16200 /* If we truncate lines, we are done when the last displayed
16201 glyphs reach past the right margin of the window. */
16202 if (it
->truncate_lines_p
16203 && (FRAME_WINDOW_P (it
->f
)
16204 ? (it
->current_x
>= it
->last_visible_x
)
16205 : (it
->current_x
> it
->last_visible_x
)))
16207 /* Maybe add truncation glyphs. */
16208 if (!FRAME_WINDOW_P (it
->f
))
16212 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16213 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16216 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16218 row
->used
[TEXT_AREA
] = i
;
16219 produce_special_glyphs (it
, IT_TRUNCATION
);
16222 #ifdef HAVE_WINDOW_SYSTEM
16225 /* Don't truncate if we can overflow newline into fringe. */
16226 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16228 if (!get_next_display_element (it
))
16230 it
->continuation_lines_width
= 0;
16231 row
->ends_at_zv_p
= 1;
16232 row
->exact_window_width_line_p
= 1;
16235 if (ITERATOR_AT_END_OF_LINE_P (it
))
16237 row
->exact_window_width_line_p
= 1;
16238 goto at_end_of_line
;
16242 #endif /* HAVE_WINDOW_SYSTEM */
16244 row
->truncated_on_right_p
= 1;
16245 it
->continuation_lines_width
= 0;
16246 reseat_at_next_visible_line_start (it
, 0);
16247 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16248 it
->hpos
= hpos_before
;
16249 it
->current_x
= x_before
;
16254 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16255 at the left window margin. */
16256 if (it
->first_visible_x
16257 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16259 if (!FRAME_WINDOW_P (it
->f
))
16260 insert_left_trunc_glyphs (it
);
16261 row
->truncated_on_left_p
= 1;
16264 /* If the start of this line is the overlay arrow-position, then
16265 mark this glyph row as the one containing the overlay arrow.
16266 This is clearly a mess with variable size fonts. It would be
16267 better to let it be displayed like cursors under X. */
16268 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16269 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16270 !NILP (overlay_arrow_string
)))
16272 /* Overlay arrow in window redisplay is a fringe bitmap. */
16273 if (STRINGP (overlay_arrow_string
))
16275 struct glyph_row
*arrow_row
16276 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
16277 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
16278 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
16279 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
16280 struct glyph
*p2
, *end
;
16282 /* Copy the arrow glyphs. */
16283 while (glyph
< arrow_end
)
16286 /* Throw away padding glyphs. */
16288 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16289 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
16295 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
16300 xassert (INTEGERP (overlay_arrow_string
));
16301 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
16303 overlay_arrow_seen
= 1;
16306 /* Compute pixel dimensions of this line. */
16307 compute_line_metrics (it
);
16309 /* Remember the position at which this line ends. */
16310 row
->end
= it
->current
;
16312 /* Record whether this row ends inside an ellipsis. */
16313 row
->ends_in_ellipsis_p
16314 = (it
->method
== GET_FROM_DISPLAY_VECTOR
16315 && it
->ellipsis_p
);
16317 /* Save fringe bitmaps in this row. */
16318 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
16319 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
16320 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
16321 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
16323 it
->left_user_fringe_bitmap
= 0;
16324 it
->left_user_fringe_face_id
= 0;
16325 it
->right_user_fringe_bitmap
= 0;
16326 it
->right_user_fringe_face_id
= 0;
16328 /* Maybe set the cursor. */
16329 if (it
->w
->cursor
.vpos
< 0
16330 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
16331 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
16332 && cursor_row_p (it
->w
, row
))
16333 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
16335 /* Highlight trailing whitespace. */
16336 if (!NILP (Vshow_trailing_whitespace
))
16337 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
16339 /* Prepare for the next line. This line starts horizontally at (X
16340 HPOS) = (0 0). Vertical positions are incremented. As a
16341 convenience for the caller, IT->glyph_row is set to the next
16343 it
->current_x
= it
->hpos
= 0;
16344 it
->current_y
+= row
->height
;
16347 it
->start
= it
->current
;
16348 return row
->displays_text_p
;
16353 /***********************************************************************
16355 ***********************************************************************/
16357 /* Redisplay the menu bar in the frame for window W.
16359 The menu bar of X frames that don't have X toolkit support is
16360 displayed in a special window W->frame->menu_bar_window.
16362 The menu bar of terminal frames is treated specially as far as
16363 glyph matrices are concerned. Menu bar lines are not part of
16364 windows, so the update is done directly on the frame matrix rows
16365 for the menu bar. */
16368 display_menu_bar (w
)
16371 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16376 /* Don't do all this for graphical frames. */
16378 if (!NILP (Vwindow_system
))
16381 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
16386 if (FRAME_MAC_P (f
))
16390 #ifdef USE_X_TOOLKIT
16391 xassert (!FRAME_WINDOW_P (f
));
16392 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
16393 it
.first_visible_x
= 0;
16394 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16395 #else /* not USE_X_TOOLKIT */
16396 if (FRAME_WINDOW_P (f
))
16398 /* Menu bar lines are displayed in the desired matrix of the
16399 dummy window menu_bar_window. */
16400 struct window
*menu_w
;
16401 xassert (WINDOWP (f
->menu_bar_window
));
16402 menu_w
= XWINDOW (f
->menu_bar_window
);
16403 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
16405 it
.first_visible_x
= 0;
16406 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16410 /* This is a TTY frame, i.e. character hpos/vpos are used as
16412 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
16414 it
.first_visible_x
= 0;
16415 it
.last_visible_x
= FRAME_COLS (f
);
16417 #endif /* not USE_X_TOOLKIT */
16419 if (! mode_line_inverse_video
)
16420 /* Force the menu-bar to be displayed in the default face. */
16421 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16423 /* Clear all rows of the menu bar. */
16424 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
16426 struct glyph_row
*row
= it
.glyph_row
+ i
;
16427 clear_glyph_row (row
);
16428 row
->enabled_p
= 1;
16429 row
->full_width_p
= 1;
16432 /* Display all items of the menu bar. */
16433 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
16434 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
16436 Lisp_Object string
;
16438 /* Stop at nil string. */
16439 string
= AREF (items
, i
+ 1);
16443 /* Remember where item was displayed. */
16444 AREF (items
, i
+ 3) = make_number (it
.hpos
);
16446 /* Display the item, pad with one space. */
16447 if (it
.current_x
< it
.last_visible_x
)
16448 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
16449 SCHARS (string
) + 1, 0, 0, -1);
16452 /* Fill out the line with spaces. */
16453 if (it
.current_x
< it
.last_visible_x
)
16454 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
16456 /* Compute the total height of the lines. */
16457 compute_line_metrics (&it
);
16462 /***********************************************************************
16464 ***********************************************************************/
16466 /* Redisplay mode lines in the window tree whose root is WINDOW. If
16467 FORCE is non-zero, redisplay mode lines unconditionally.
16468 Otherwise, redisplay only mode lines that are garbaged. Value is
16469 the number of windows whose mode lines were redisplayed. */
16472 redisplay_mode_lines (window
, force
)
16473 Lisp_Object window
;
16478 while (!NILP (window
))
16480 struct window
*w
= XWINDOW (window
);
16482 if (WINDOWP (w
->hchild
))
16483 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
16484 else if (WINDOWP (w
->vchild
))
16485 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
16487 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
16488 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
16490 struct text_pos lpoint
;
16491 struct buffer
*old
= current_buffer
;
16493 /* Set the window's buffer for the mode line display. */
16494 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16495 set_buffer_internal_1 (XBUFFER (w
->buffer
));
16497 /* Point refers normally to the selected window. For any
16498 other window, set up appropriate value. */
16499 if (!EQ (window
, selected_window
))
16501 struct text_pos pt
;
16503 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
16504 if (CHARPOS (pt
) < BEGV
)
16505 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16506 else if (CHARPOS (pt
) > (ZV
- 1))
16507 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
16509 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
16512 /* Display mode lines. */
16513 clear_glyph_matrix (w
->desired_matrix
);
16514 if (display_mode_lines (w
))
16517 w
->must_be_updated_p
= 1;
16520 /* Restore old settings. */
16521 set_buffer_internal_1 (old
);
16522 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16532 /* Display the mode and/or top line of window W. Value is the number
16533 of mode lines displayed. */
16536 display_mode_lines (w
)
16539 Lisp_Object old_selected_window
, old_selected_frame
;
16542 old_selected_frame
= selected_frame
;
16543 selected_frame
= w
->frame
;
16544 old_selected_window
= selected_window
;
16545 XSETWINDOW (selected_window
, w
);
16547 /* These will be set while the mode line specs are processed. */
16548 line_number_displayed
= 0;
16549 w
->column_number_displayed
= Qnil
;
16551 if (WINDOW_WANTS_MODELINE_P (w
))
16553 struct window
*sel_w
= XWINDOW (old_selected_window
);
16555 /* Select mode line face based on the real selected window. */
16556 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
16557 current_buffer
->mode_line_format
);
16561 if (WINDOW_WANTS_HEADER_LINE_P (w
))
16563 display_mode_line (w
, HEADER_LINE_FACE_ID
,
16564 current_buffer
->header_line_format
);
16568 selected_frame
= old_selected_frame
;
16569 selected_window
= old_selected_window
;
16574 /* Display mode or top line of window W. FACE_ID specifies which line
16575 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
16576 FORMAT is the mode line format to display. Value is the pixel
16577 height of the mode line displayed. */
16580 display_mode_line (w
, face_id
, format
)
16582 enum face_id face_id
;
16583 Lisp_Object format
;
16587 int count
= SPECPDL_INDEX ();
16589 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16590 prepare_desired_row (it
.glyph_row
);
16592 it
.glyph_row
->mode_line_p
= 1;
16594 if (! mode_line_inverse_video
)
16595 /* Force the mode-line to be displayed in the default face. */
16596 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16598 record_unwind_protect (unwind_format_mode_line
,
16599 format_mode_line_unwind_data (NULL
, 0));
16601 mode_line_target
= MODE_LINE_DISPLAY
;
16603 /* Temporarily make frame's keyboard the current kboard so that
16604 kboard-local variables in the mode_line_format will get the right
16606 push_frame_kboard (it
.f
);
16607 record_unwind_save_match_data ();
16608 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16609 pop_frame_kboard ();
16611 unbind_to (count
, Qnil
);
16613 /* Fill up with spaces. */
16614 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
16616 compute_line_metrics (&it
);
16617 it
.glyph_row
->full_width_p
= 1;
16618 it
.glyph_row
->continued_p
= 0;
16619 it
.glyph_row
->truncated_on_left_p
= 0;
16620 it
.glyph_row
->truncated_on_right_p
= 0;
16622 /* Make a 3D mode-line have a shadow at its right end. */
16623 face
= FACE_FROM_ID (it
.f
, face_id
);
16624 extend_face_to_end_of_line (&it
);
16625 if (face
->box
!= FACE_NO_BOX
)
16627 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
16628 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
16629 last
->right_box_line_p
= 1;
16632 return it
.glyph_row
->height
;
16635 /* Move element ELT in LIST to the front of LIST.
16636 Return the updated list. */
16639 move_elt_to_front (elt
, list
)
16640 Lisp_Object elt
, list
;
16642 register Lisp_Object tail
, prev
;
16643 register Lisp_Object tem
;
16647 while (CONSP (tail
))
16653 /* Splice out the link TAIL. */
16655 list
= XCDR (tail
);
16657 Fsetcdr (prev
, XCDR (tail
));
16659 /* Now make it the first. */
16660 Fsetcdr (tail
, list
);
16665 tail
= XCDR (tail
);
16669 /* Not found--return unchanged LIST. */
16673 /* Contribute ELT to the mode line for window IT->w. How it
16674 translates into text depends on its data type.
16676 IT describes the display environment in which we display, as usual.
16678 DEPTH is the depth in recursion. It is used to prevent
16679 infinite recursion here.
16681 FIELD_WIDTH is the number of characters the display of ELT should
16682 occupy in the mode line, and PRECISION is the maximum number of
16683 characters to display from ELT's representation. See
16684 display_string for details.
16686 Returns the hpos of the end of the text generated by ELT.
16688 PROPS is a property list to add to any string we encounter.
16690 If RISKY is nonzero, remove (disregard) any properties in any string
16691 we encounter, and ignore :eval and :propertize.
16693 The global variable `mode_line_target' determines whether the
16694 output is passed to `store_mode_line_noprop',
16695 `store_mode_line_string', or `display_string'. */
16698 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
16701 int field_width
, precision
;
16702 Lisp_Object elt
, props
;
16705 int n
= 0, field
, prec
;
16710 elt
= build_string ("*too-deep*");
16714 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
16718 /* A string: output it and check for %-constructs within it. */
16722 if (SCHARS (elt
) > 0
16723 && (!NILP (props
) || risky
))
16725 Lisp_Object oprops
, aelt
;
16726 oprops
= Ftext_properties_at (make_number (0), elt
);
16728 /* If the starting string's properties are not what
16729 we want, translate the string. Also, if the string
16730 is risky, do that anyway. */
16732 if (NILP (Fequal (props
, oprops
)) || risky
)
16734 /* If the starting string has properties,
16735 merge the specified ones onto the existing ones. */
16736 if (! NILP (oprops
) && !risky
)
16740 oprops
= Fcopy_sequence (oprops
);
16742 while (CONSP (tem
))
16744 oprops
= Fplist_put (oprops
, XCAR (tem
),
16745 XCAR (XCDR (tem
)));
16746 tem
= XCDR (XCDR (tem
));
16751 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
16752 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
16754 /* AELT is what we want. Move it to the front
16755 without consing. */
16757 mode_line_proptrans_alist
16758 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
16764 /* If AELT has the wrong props, it is useless.
16765 so get rid of it. */
16767 mode_line_proptrans_alist
16768 = Fdelq (aelt
, mode_line_proptrans_alist
);
16770 elt
= Fcopy_sequence (elt
);
16771 Fset_text_properties (make_number (0), Flength (elt
),
16773 /* Add this item to mode_line_proptrans_alist. */
16774 mode_line_proptrans_alist
16775 = Fcons (Fcons (elt
, props
),
16776 mode_line_proptrans_alist
);
16777 /* Truncate mode_line_proptrans_alist
16778 to at most 50 elements. */
16779 tem
= Fnthcdr (make_number (50),
16780 mode_line_proptrans_alist
);
16782 XSETCDR (tem
, Qnil
);
16791 prec
= precision
- n
;
16792 switch (mode_line_target
)
16794 case MODE_LINE_NOPROP
:
16795 case MODE_LINE_TITLE
:
16796 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
16798 case MODE_LINE_STRING
:
16799 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
16801 case MODE_LINE_DISPLAY
:
16802 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
16803 0, prec
, 0, STRING_MULTIBYTE (elt
));
16810 /* Handle the non-literal case. */
16812 while ((precision
<= 0 || n
< precision
)
16813 && SREF (elt
, offset
) != 0
16814 && (mode_line_target
!= MODE_LINE_DISPLAY
16815 || it
->current_x
< it
->last_visible_x
))
16817 int last_offset
= offset
;
16819 /* Advance to end of string or next format specifier. */
16820 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
16823 if (offset
- 1 != last_offset
)
16825 int nchars
, nbytes
;
16827 /* Output to end of string or up to '%'. Field width
16828 is length of string. Don't output more than
16829 PRECISION allows us. */
16832 prec
= c_string_width (SDATA (elt
) + last_offset
,
16833 offset
- last_offset
, precision
- n
,
16836 switch (mode_line_target
)
16838 case MODE_LINE_NOPROP
:
16839 case MODE_LINE_TITLE
:
16840 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
16842 case MODE_LINE_STRING
:
16844 int bytepos
= last_offset
;
16845 int charpos
= string_byte_to_char (elt
, bytepos
);
16846 int endpos
= (precision
<= 0
16847 ? string_byte_to_char (elt
, offset
)
16848 : charpos
+ nchars
);
16850 n
+= store_mode_line_string (NULL
,
16851 Fsubstring (elt
, make_number (charpos
),
16852 make_number (endpos
)),
16856 case MODE_LINE_DISPLAY
:
16858 int bytepos
= last_offset
;
16859 int charpos
= string_byte_to_char (elt
, bytepos
);
16861 if (precision
<= 0)
16862 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
16863 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
16865 STRING_MULTIBYTE (elt
));
16870 else /* c == '%' */
16872 int percent_position
= offset
;
16874 /* Get the specified minimum width. Zero means
16877 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
16878 field
= field
* 10 + c
- '0';
16880 /* Don't pad beyond the total padding allowed. */
16881 if (field_width
- n
> 0 && field
> field_width
- n
)
16882 field
= field_width
- n
;
16884 /* Note that either PRECISION <= 0 or N < PRECISION. */
16885 prec
= precision
- n
;
16888 n
+= display_mode_element (it
, depth
, field
, prec
,
16889 Vglobal_mode_string
, props
,
16894 int bytepos
, charpos
;
16895 unsigned char *spec
;
16897 bytepos
= percent_position
;
16898 charpos
= (STRING_MULTIBYTE (elt
)
16899 ? string_byte_to_char (elt
, bytepos
)
16903 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
16905 switch (mode_line_target
)
16907 case MODE_LINE_NOPROP
:
16908 case MODE_LINE_TITLE
:
16909 n
+= store_mode_line_noprop (spec
, field
, prec
);
16911 case MODE_LINE_STRING
:
16913 int len
= strlen (spec
);
16914 Lisp_Object tem
= make_string (spec
, len
);
16915 props
= Ftext_properties_at (make_number (charpos
), elt
);
16916 /* Should only keep face property in props */
16917 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
16920 case MODE_LINE_DISPLAY
:
16922 int nglyphs_before
, nwritten
;
16924 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16925 nwritten
= display_string (spec
, Qnil
, elt
,
16930 /* Assign to the glyphs written above the
16931 string where the `%x' came from, position
16935 struct glyph
*glyph
16936 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
16940 for (i
= 0; i
< nwritten
; ++i
)
16942 glyph
[i
].object
= elt
;
16943 glyph
[i
].charpos
= charpos
;
16960 /* A symbol: process the value of the symbol recursively
16961 as if it appeared here directly. Avoid error if symbol void.
16962 Special case: if value of symbol is a string, output the string
16965 register Lisp_Object tem
;
16967 /* If the variable is not marked as risky to set
16968 then its contents are risky to use. */
16969 if (NILP (Fget (elt
, Qrisky_local_variable
)))
16972 tem
= Fboundp (elt
);
16975 tem
= Fsymbol_value (elt
);
16976 /* If value is a string, output that string literally:
16977 don't check for % within it. */
16981 if (!EQ (tem
, elt
))
16983 /* Give up right away for nil or t. */
16993 register Lisp_Object car
, tem
;
16995 /* A cons cell: five distinct cases.
16996 If first element is :eval or :propertize, do something special.
16997 If first element is a string or a cons, process all the elements
16998 and effectively concatenate them.
16999 If first element is a negative number, truncate displaying cdr to
17000 at most that many characters. If positive, pad (with spaces)
17001 to at least that many characters.
17002 If first element is a symbol, process the cadr or caddr recursively
17003 according to whether the symbol's value is non-nil or nil. */
17005 if (EQ (car
, QCeval
))
17007 /* An element of the form (:eval FORM) means evaluate FORM
17008 and use the result as mode line elements. */
17013 if (CONSP (XCDR (elt
)))
17016 spec
= safe_eval (XCAR (XCDR (elt
)));
17017 n
+= display_mode_element (it
, depth
, field_width
- n
,
17018 precision
- n
, spec
, props
,
17022 else if (EQ (car
, QCpropertize
))
17024 /* An element of the form (:propertize ELT PROPS...)
17025 means display ELT but applying properties PROPS. */
17030 if (CONSP (XCDR (elt
)))
17031 n
+= display_mode_element (it
, depth
, field_width
- n
,
17032 precision
- n
, XCAR (XCDR (elt
)),
17033 XCDR (XCDR (elt
)), risky
);
17035 else if (SYMBOLP (car
))
17037 tem
= Fboundp (car
);
17041 /* elt is now the cdr, and we know it is a cons cell.
17042 Use its car if CAR has a non-nil value. */
17045 tem
= Fsymbol_value (car
);
17052 /* Symbol's value is nil (or symbol is unbound)
17053 Get the cddr of the original list
17054 and if possible find the caddr and use that. */
17058 else if (!CONSP (elt
))
17063 else if (INTEGERP (car
))
17065 register int lim
= XINT (car
);
17069 /* Negative int means reduce maximum width. */
17070 if (precision
<= 0)
17073 precision
= min (precision
, -lim
);
17077 /* Padding specified. Don't let it be more than
17078 current maximum. */
17080 lim
= min (precision
, lim
);
17082 /* If that's more padding than already wanted, queue it.
17083 But don't reduce padding already specified even if
17084 that is beyond the current truncation point. */
17085 field_width
= max (lim
, field_width
);
17089 else if (STRINGP (car
) || CONSP (car
))
17091 register int limit
= 50;
17092 /* Limit is to protect against circular lists. */
17095 && (precision
<= 0 || n
< precision
))
17097 n
+= display_mode_element (it
, depth
,
17098 /* Do padding only after the last
17099 element in the list. */
17100 (! CONSP (XCDR (elt
))
17103 precision
- n
, XCAR (elt
),
17113 elt
= build_string ("*invalid*");
17117 /* Pad to FIELD_WIDTH. */
17118 if (field_width
> 0 && n
< field_width
)
17120 switch (mode_line_target
)
17122 case MODE_LINE_NOPROP
:
17123 case MODE_LINE_TITLE
:
17124 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
17126 case MODE_LINE_STRING
:
17127 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
17129 case MODE_LINE_DISPLAY
:
17130 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
17139 /* Store a mode-line string element in mode_line_string_list.
17141 If STRING is non-null, display that C string. Otherwise, the Lisp
17142 string LISP_STRING is displayed.
17144 FIELD_WIDTH is the minimum number of output glyphs to produce.
17145 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17146 with spaces. FIELD_WIDTH <= 0 means don't pad.
17148 PRECISION is the maximum number of characters to output from
17149 STRING. PRECISION <= 0 means don't truncate the string.
17151 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
17152 properties to the string.
17154 PROPS are the properties to add to the string.
17155 The mode_line_string_face face property is always added to the string.
17159 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
17161 Lisp_Object lisp_string
;
17170 if (string
!= NULL
)
17172 len
= strlen (string
);
17173 if (precision
> 0 && len
> precision
)
17175 lisp_string
= make_string (string
, len
);
17177 props
= mode_line_string_face_prop
;
17178 else if (!NILP (mode_line_string_face
))
17180 Lisp_Object face
= Fplist_get (props
, Qface
);
17181 props
= Fcopy_sequence (props
);
17183 face
= mode_line_string_face
;
17185 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17186 props
= Fplist_put (props
, Qface
, face
);
17188 Fadd_text_properties (make_number (0), make_number (len
),
17189 props
, lisp_string
);
17193 len
= XFASTINT (Flength (lisp_string
));
17194 if (precision
> 0 && len
> precision
)
17197 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
17200 if (!NILP (mode_line_string_face
))
17204 props
= Ftext_properties_at (make_number (0), lisp_string
);
17205 face
= Fplist_get (props
, Qface
);
17207 face
= mode_line_string_face
;
17209 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17210 props
= Fcons (Qface
, Fcons (face
, Qnil
));
17212 lisp_string
= Fcopy_sequence (lisp_string
);
17215 Fadd_text_properties (make_number (0), make_number (len
),
17216 props
, lisp_string
);
17221 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17225 if (field_width
> len
)
17227 field_width
-= len
;
17228 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17230 Fadd_text_properties (make_number (0), make_number (field_width
),
17231 props
, lisp_string
);
17232 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17240 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17242 doc
: /* Format a string out of a mode line format specification.
17243 First arg FORMAT specifies the mode line format (see `mode-line-format'
17244 for details) to use.
17246 Optional second arg FACE specifies the face property to put
17247 on all characters for which no face is specified.
17248 t means whatever face the window's mode line currently uses
17249 \(either `mode-line' or `mode-line-inactive', depending).
17250 nil means the default is no face property.
17251 If FACE is an integer, the value string has no text properties.
17253 Optional third and fourth args WINDOW and BUFFER specify the window
17254 and buffer to use as the context for the formatting (defaults
17255 are the selected window and the window's buffer). */)
17256 (format
, face
, window
, buffer
)
17257 Lisp_Object format
, face
, window
, buffer
;
17262 struct buffer
*old_buffer
= NULL
;
17264 int no_props
= INTEGERP (face
);
17265 int count
= SPECPDL_INDEX ();
17267 int string_start
= 0;
17270 window
= selected_window
;
17271 CHECK_WINDOW (window
);
17272 w
= XWINDOW (window
);
17275 buffer
= w
->buffer
;
17276 CHECK_BUFFER (buffer
);
17279 return build_string ("");
17287 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
17288 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
17292 face_id
= DEFAULT_FACE_ID
;
17294 if (XBUFFER (buffer
) != current_buffer
)
17295 old_buffer
= current_buffer
;
17297 /* Save things including mode_line_proptrans_alist,
17298 and set that to nil so that we don't alter the outer value. */
17299 record_unwind_protect (unwind_format_mode_line
,
17300 format_mode_line_unwind_data (old_buffer
, 1));
17301 mode_line_proptrans_alist
= Qnil
;
17304 set_buffer_internal_1 (XBUFFER (buffer
));
17306 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17310 mode_line_target
= MODE_LINE_NOPROP
;
17311 mode_line_string_face_prop
= Qnil
;
17312 mode_line_string_list
= Qnil
;
17313 string_start
= MODE_LINE_NOPROP_LEN (0);
17317 mode_line_target
= MODE_LINE_STRING
;
17318 mode_line_string_list
= Qnil
;
17319 mode_line_string_face
= face
;
17320 mode_line_string_face_prop
17321 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
17324 push_frame_kboard (it
.f
);
17325 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17326 pop_frame_kboard ();
17330 len
= MODE_LINE_NOPROP_LEN (string_start
);
17331 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
17335 mode_line_string_list
= Fnreverse (mode_line_string_list
);
17336 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
17337 make_string ("", 0));
17340 unbind_to (count
, Qnil
);
17344 /* Write a null-terminated, right justified decimal representation of
17345 the positive integer D to BUF using a minimal field width WIDTH. */
17348 pint2str (buf
, width
, d
)
17349 register char *buf
;
17350 register int width
;
17353 register char *p
= buf
;
17361 *p
++ = d
% 10 + '0';
17366 for (width
-= (int) (p
- buf
); width
> 0; --width
)
17377 /* Write a null-terminated, right justified decimal and "human
17378 readable" representation of the nonnegative integer D to BUF using
17379 a minimal field width WIDTH. D should be smaller than 999.5e24. */
17381 static const char power_letter
[] =
17395 pint2hrstr (buf
, width
, d
)
17400 /* We aim to represent the nonnegative integer D as
17401 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
17404 /* -1 means: do not use TENTHS. */
17408 /* Length of QUOTIENT.TENTHS as a string. */
17414 if (1000 <= quotient
)
17416 /* Scale to the appropriate EXPONENT. */
17419 remainder
= quotient
% 1000;
17423 while (1000 <= quotient
);
17425 /* Round to nearest and decide whether to use TENTHS or not. */
17428 tenths
= remainder
/ 100;
17429 if (50 <= remainder
% 100)
17436 if (quotient
== 10)
17444 if (500 <= remainder
)
17446 if (quotient
< 999)
17457 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
17458 if (tenths
== -1 && quotient
<= 99)
17465 p
= psuffix
= buf
+ max (width
, length
);
17467 /* Print EXPONENT. */
17469 *psuffix
++ = power_letter
[exponent
];
17472 /* Print TENTHS. */
17475 *--p
= '0' + tenths
;
17479 /* Print QUOTIENT. */
17482 int digit
= quotient
% 10;
17483 *--p
= '0' + digit
;
17485 while ((quotient
/= 10) != 0);
17487 /* Print leading spaces. */
17492 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
17493 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
17494 type of CODING_SYSTEM. Return updated pointer into BUF. */
17496 static unsigned char invalid_eol_type
[] = "(*invalid*)";
17499 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
17500 Lisp_Object coding_system
;
17501 register char *buf
;
17505 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
17506 const unsigned char *eol_str
;
17508 /* The EOL conversion we are using. */
17509 Lisp_Object eoltype
;
17511 val
= Fget (coding_system
, Qcoding_system
);
17514 if (!VECTORP (val
)) /* Not yet decided. */
17519 eoltype
= eol_mnemonic_undecided
;
17520 /* Don't mention EOL conversion if it isn't decided. */
17524 Lisp_Object eolvalue
;
17526 eolvalue
= Fget (coding_system
, Qeol_type
);
17529 *buf
++ = XFASTINT (AREF (val
, 1));
17533 /* The EOL conversion that is normal on this system. */
17535 if (NILP (eolvalue
)) /* Not yet decided. */
17536 eoltype
= eol_mnemonic_undecided
;
17537 else if (VECTORP (eolvalue
)) /* Not yet decided. */
17538 eoltype
= eol_mnemonic_undecided
;
17539 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
17540 eoltype
= (XFASTINT (eolvalue
) == 0
17541 ? eol_mnemonic_unix
17542 : (XFASTINT (eolvalue
) == 1
17543 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
17549 /* Mention the EOL conversion if it is not the usual one. */
17550 if (STRINGP (eoltype
))
17552 eol_str
= SDATA (eoltype
);
17553 eol_str_len
= SBYTES (eoltype
);
17555 else if (INTEGERP (eoltype
)
17556 && CHAR_VALID_P (XINT (eoltype
), 0))
17558 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
17559 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
17564 eol_str
= invalid_eol_type
;
17565 eol_str_len
= sizeof (invalid_eol_type
) - 1;
17567 bcopy (eol_str
, buf
, eol_str_len
);
17568 buf
+= eol_str_len
;
17574 /* Return a string for the output of a mode line %-spec for window W,
17575 generated by character C. PRECISION >= 0 means don't return a
17576 string longer than that value. FIELD_WIDTH > 0 means pad the
17577 string returned with spaces to that value. Return 1 in *MULTIBYTE
17578 if the result is multibyte text.
17580 Note we operate on the current buffer for most purposes,
17581 the exception being w->base_line_pos. */
17583 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
17586 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
17589 int field_width
, precision
;
17593 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17594 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
17595 struct buffer
*b
= current_buffer
;
17603 if (!NILP (b
->read_only
))
17605 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17610 /* This differs from %* only for a modified read-only buffer. */
17611 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17613 if (!NILP (b
->read_only
))
17618 /* This differs from %* in ignoring read-only-ness. */
17619 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17631 if (command_loop_level
> 5)
17633 p
= decode_mode_spec_buf
;
17634 for (i
= 0; i
< command_loop_level
; i
++)
17637 return decode_mode_spec_buf
;
17645 if (command_loop_level
> 5)
17647 p
= decode_mode_spec_buf
;
17648 for (i
= 0; i
< command_loop_level
; i
++)
17651 return decode_mode_spec_buf
;
17658 /* Let lots_of_dashes be a string of infinite length. */
17659 if (mode_line_target
== MODE_LINE_NOPROP
||
17660 mode_line_target
== MODE_LINE_STRING
)
17662 if (field_width
<= 0
17663 || field_width
> sizeof (lots_of_dashes
))
17665 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
17666 decode_mode_spec_buf
[i
] = '-';
17667 decode_mode_spec_buf
[i
] = '\0';
17668 return decode_mode_spec_buf
;
17671 return lots_of_dashes
;
17680 int col
= (int) current_column (); /* iftc */
17681 w
->column_number_displayed
= make_number (col
);
17682 pint2str (decode_mode_spec_buf
, field_width
, col
);
17683 return decode_mode_spec_buf
;
17687 #ifndef SYSTEM_MALLOC
17689 if (NILP (Vmemory_full
))
17692 return "!MEM FULL! ";
17699 /* %F displays the frame name. */
17700 if (!NILP (f
->title
))
17701 return (char *) SDATA (f
->title
);
17702 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
17703 return (char *) SDATA (f
->name
);
17712 int size
= ZV
- BEGV
;
17713 pint2str (decode_mode_spec_buf
, field_width
, size
);
17714 return decode_mode_spec_buf
;
17719 int size
= ZV
- BEGV
;
17720 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
17721 return decode_mode_spec_buf
;
17726 int startpos
= XMARKER (w
->start
)->charpos
;
17727 int startpos_byte
= marker_byte_position (w
->start
);
17728 int line
, linepos
, linepos_byte
, topline
;
17730 int height
= WINDOW_TOTAL_LINES (w
);
17732 /* If we decided that this buffer isn't suitable for line numbers,
17733 don't forget that too fast. */
17734 if (EQ (w
->base_line_pos
, w
->buffer
))
17736 /* But do forget it, if the window shows a different buffer now. */
17737 else if (BUFFERP (w
->base_line_pos
))
17738 w
->base_line_pos
= Qnil
;
17740 /* If the buffer is very big, don't waste time. */
17741 if (INTEGERP (Vline_number_display_limit
)
17742 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
17744 w
->base_line_pos
= Qnil
;
17745 w
->base_line_number
= Qnil
;
17749 if (!NILP (w
->base_line_number
)
17750 && !NILP (w
->base_line_pos
)
17751 && XFASTINT (w
->base_line_pos
) <= startpos
)
17753 line
= XFASTINT (w
->base_line_number
);
17754 linepos
= XFASTINT (w
->base_line_pos
);
17755 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
17760 linepos
= BUF_BEGV (b
);
17761 linepos_byte
= BUF_BEGV_BYTE (b
);
17764 /* Count lines from base line to window start position. */
17765 nlines
= display_count_lines (linepos
, linepos_byte
,
17769 topline
= nlines
+ line
;
17771 /* Determine a new base line, if the old one is too close
17772 or too far away, or if we did not have one.
17773 "Too close" means it's plausible a scroll-down would
17774 go back past it. */
17775 if (startpos
== BUF_BEGV (b
))
17777 w
->base_line_number
= make_number (topline
);
17778 w
->base_line_pos
= make_number (BUF_BEGV (b
));
17780 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
17781 || linepos
== BUF_BEGV (b
))
17783 int limit
= BUF_BEGV (b
);
17784 int limit_byte
= BUF_BEGV_BYTE (b
);
17786 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
17788 if (startpos
- distance
> limit
)
17790 limit
= startpos
- distance
;
17791 limit_byte
= CHAR_TO_BYTE (limit
);
17794 nlines
= display_count_lines (startpos
, startpos_byte
,
17796 - (height
* 2 + 30),
17798 /* If we couldn't find the lines we wanted within
17799 line_number_display_limit_width chars per line,
17800 give up on line numbers for this window. */
17801 if (position
== limit_byte
&& limit
== startpos
- distance
)
17803 w
->base_line_pos
= w
->buffer
;
17804 w
->base_line_number
= Qnil
;
17808 w
->base_line_number
= make_number (topline
- nlines
);
17809 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
17812 /* Now count lines from the start pos to point. */
17813 nlines
= display_count_lines (startpos
, startpos_byte
,
17814 PT_BYTE
, PT
, &junk
);
17816 /* Record that we did display the line number. */
17817 line_number_displayed
= 1;
17819 /* Make the string to show. */
17820 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
17821 return decode_mode_spec_buf
;
17824 char* p
= decode_mode_spec_buf
;
17825 int pad
= field_width
- 2;
17831 return decode_mode_spec_buf
;
17837 obj
= b
->mode_name
;
17841 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
17847 int pos
= marker_position (w
->start
);
17848 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17850 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
17852 if (pos
<= BUF_BEGV (b
))
17857 else if (pos
<= BUF_BEGV (b
))
17861 if (total
> 1000000)
17862 /* Do it differently for a large value, to avoid overflow. */
17863 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17865 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17866 /* We can't normally display a 3-digit number,
17867 so get us a 2-digit number that is close. */
17870 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17871 return decode_mode_spec_buf
;
17875 /* Display percentage of size above the bottom of the screen. */
17878 int toppos
= marker_position (w
->start
);
17879 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
17880 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17882 if (botpos
>= BUF_ZV (b
))
17884 if (toppos
<= BUF_BEGV (b
))
17891 if (total
> 1000000)
17892 /* Do it differently for a large value, to avoid overflow. */
17893 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17895 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17896 /* We can't normally display a 3-digit number,
17897 so get us a 2-digit number that is close. */
17900 if (toppos
<= BUF_BEGV (b
))
17901 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
17903 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17904 return decode_mode_spec_buf
;
17909 /* status of process */
17910 obj
= Fget_buffer_process (Fcurrent_buffer ());
17912 return "no process";
17913 #ifdef subprocesses
17914 obj
= Fsymbol_name (Fprocess_status (obj
));
17918 case 't': /* indicate TEXT or BINARY */
17919 #ifdef MODE_LINE_BINARY_TEXT
17920 return MODE_LINE_BINARY_TEXT (b
);
17926 /* coding-system (not including end-of-line format) */
17928 /* coding-system (including end-of-line type) */
17930 int eol_flag
= (c
== 'Z');
17931 char *p
= decode_mode_spec_buf
;
17933 if (! FRAME_WINDOW_P (f
))
17935 /* No need to mention EOL here--the terminal never needs
17936 to do EOL conversion. */
17937 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
17938 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
17940 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
17943 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
17944 #ifdef subprocesses
17945 obj
= Fget_buffer_process (Fcurrent_buffer ());
17946 if (PROCESSP (obj
))
17948 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
17950 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
17953 #endif /* subprocesses */
17956 return decode_mode_spec_buf
;
17962 *multibyte
= STRING_MULTIBYTE (obj
);
17963 return (char *) SDATA (obj
);
17970 /* Count up to COUNT lines starting from START / START_BYTE.
17971 But don't go beyond LIMIT_BYTE.
17972 Return the number of lines thus found (always nonnegative).
17974 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
17977 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
17978 int start
, start_byte
, limit_byte
, count
;
17981 register unsigned char *cursor
;
17982 unsigned char *base
;
17984 register int ceiling
;
17985 register unsigned char *ceiling_addr
;
17986 int orig_count
= count
;
17988 /* If we are not in selective display mode,
17989 check only for newlines. */
17990 int selective_display
= (!NILP (current_buffer
->selective_display
)
17991 && !INTEGERP (current_buffer
->selective_display
));
17995 while (start_byte
< limit_byte
)
17997 ceiling
= BUFFER_CEILING_OF (start_byte
);
17998 ceiling
= min (limit_byte
- 1, ceiling
);
17999 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
18000 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
18003 if (selective_display
)
18004 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
18007 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
18010 if (cursor
!= ceiling_addr
)
18014 start_byte
+= cursor
- base
+ 1;
18015 *byte_pos_ptr
= start_byte
;
18019 if (++cursor
== ceiling_addr
)
18025 start_byte
+= cursor
- base
;
18030 while (start_byte
> limit_byte
)
18032 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
18033 ceiling
= max (limit_byte
, ceiling
);
18034 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
18035 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
18038 if (selective_display
)
18039 while (--cursor
!= ceiling_addr
18040 && *cursor
!= '\n' && *cursor
!= 015)
18043 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
18046 if (cursor
!= ceiling_addr
)
18050 start_byte
+= cursor
- base
+ 1;
18051 *byte_pos_ptr
= start_byte
;
18052 /* When scanning backwards, we should
18053 not count the newline posterior to which we stop. */
18054 return - orig_count
- 1;
18060 /* Here we add 1 to compensate for the last decrement
18061 of CURSOR, which took it past the valid range. */
18062 start_byte
+= cursor
- base
+ 1;
18066 *byte_pos_ptr
= limit_byte
;
18069 return - orig_count
+ count
;
18070 return orig_count
- count
;
18076 /***********************************************************************
18078 ***********************************************************************/
18080 /* Display a NUL-terminated string, starting with index START.
18082 If STRING is non-null, display that C string. Otherwise, the Lisp
18083 string LISP_STRING is displayed.
18085 If FACE_STRING is not nil, FACE_STRING_POS is a position in
18086 FACE_STRING. Display STRING or LISP_STRING with the face at
18087 FACE_STRING_POS in FACE_STRING:
18089 Display the string in the environment given by IT, but use the
18090 standard display table, temporarily.
18092 FIELD_WIDTH is the minimum number of output glyphs to produce.
18093 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18094 with spaces. If STRING has more characters, more than FIELD_WIDTH
18095 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
18097 PRECISION is the maximum number of characters to output from
18098 STRING. PRECISION < 0 means don't truncate the string.
18100 This is roughly equivalent to printf format specifiers:
18102 FIELD_WIDTH PRECISION PRINTF
18103 ----------------------------------------
18109 MULTIBYTE zero means do not display multibyte chars, > 0 means do
18110 display them, and < 0 means obey the current buffer's value of
18111 enable_multibyte_characters.
18113 Value is the number of columns displayed. */
18116 display_string (string
, lisp_string
, face_string
, face_string_pos
,
18117 start
, it
, field_width
, precision
, max_x
, multibyte
)
18118 unsigned char *string
;
18119 Lisp_Object lisp_string
;
18120 Lisp_Object face_string
;
18121 int face_string_pos
;
18124 int field_width
, precision
, max_x
;
18127 int hpos_at_start
= it
->hpos
;
18128 int saved_face_id
= it
->face_id
;
18129 struct glyph_row
*row
= it
->glyph_row
;
18131 /* Initialize the iterator IT for iteration over STRING beginning
18132 with index START. */
18133 reseat_to_string (it
, string
, lisp_string
, start
,
18134 precision
, field_width
, multibyte
);
18136 /* If displaying STRING, set up the face of the iterator
18137 from LISP_STRING, if that's given. */
18138 if (STRINGP (face_string
))
18144 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
18145 0, it
->region_beg_charpos
,
18146 it
->region_end_charpos
,
18147 &endptr
, it
->base_face_id
, 0);
18148 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18149 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
18152 /* Set max_x to the maximum allowed X position. Don't let it go
18153 beyond the right edge of the window. */
18155 max_x
= it
->last_visible_x
;
18157 max_x
= min (max_x
, it
->last_visible_x
);
18159 /* Skip over display elements that are not visible. because IT->w is
18161 if (it
->current_x
< it
->first_visible_x
)
18162 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
18163 MOVE_TO_POS
| MOVE_TO_X
);
18165 row
->ascent
= it
->max_ascent
;
18166 row
->height
= it
->max_ascent
+ it
->max_descent
;
18167 row
->phys_ascent
= it
->max_phys_ascent
;
18168 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18169 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18171 /* This condition is for the case that we are called with current_x
18172 past last_visible_x. */
18173 while (it
->current_x
< max_x
)
18175 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
18177 /* Get the next display element. */
18178 if (!get_next_display_element (it
))
18181 /* Produce glyphs. */
18182 x_before
= it
->current_x
;
18183 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18184 PRODUCE_GLYPHS (it
);
18186 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
18189 while (i
< nglyphs
)
18191 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18193 if (!it
->truncate_lines_p
18194 && x
+ glyph
->pixel_width
> max_x
)
18196 /* End of continued line or max_x reached. */
18197 if (CHAR_GLYPH_PADDING_P (*glyph
))
18199 /* A wide character is unbreakable. */
18200 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18201 it
->current_x
= x_before
;
18205 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18210 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
18212 /* Glyph is at least partially visible. */
18214 if (x
< it
->first_visible_x
)
18215 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18219 /* Glyph is off the left margin of the display area.
18220 Should not happen. */
18224 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18225 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18226 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18227 row
->phys_height
= max (row
->phys_height
,
18228 it
->max_phys_ascent
+ it
->max_phys_descent
);
18229 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18230 it
->max_extra_line_spacing
);
18231 x
+= glyph
->pixel_width
;
18235 /* Stop if max_x reached. */
18239 /* Stop at line ends. */
18240 if (ITERATOR_AT_END_OF_LINE_P (it
))
18242 it
->continuation_lines_width
= 0;
18246 set_iterator_to_next (it
, 1);
18248 /* Stop if truncating at the right edge. */
18249 if (it
->truncate_lines_p
18250 && it
->current_x
>= it
->last_visible_x
)
18252 /* Add truncation mark, but don't do it if the line is
18253 truncated at a padding space. */
18254 if (IT_CHARPOS (*it
) < it
->string_nchars
)
18256 if (!FRAME_WINDOW_P (it
->f
))
18260 if (it
->current_x
> it
->last_visible_x
)
18262 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18263 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18265 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18267 row
->used
[TEXT_AREA
] = i
;
18268 produce_special_glyphs (it
, IT_TRUNCATION
);
18271 produce_special_glyphs (it
, IT_TRUNCATION
);
18273 it
->glyph_row
->truncated_on_right_p
= 1;
18279 /* Maybe insert a truncation at the left. */
18280 if (it
->first_visible_x
18281 && IT_CHARPOS (*it
) > 0)
18283 if (!FRAME_WINDOW_P (it
->f
))
18284 insert_left_trunc_glyphs (it
);
18285 it
->glyph_row
->truncated_on_left_p
= 1;
18288 it
->face_id
= saved_face_id
;
18290 /* Value is number of columns displayed. */
18291 return it
->hpos
- hpos_at_start
;
18296 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
18297 appears as an element of LIST or as the car of an element of LIST.
18298 If PROPVAL is a list, compare each element against LIST in that
18299 way, and return 1/2 if any element of PROPVAL is found in LIST.
18300 Otherwise return 0. This function cannot quit.
18301 The return value is 2 if the text is invisible but with an ellipsis
18302 and 1 if it's invisible and without an ellipsis. */
18305 invisible_p (propval
, list
)
18306 register Lisp_Object propval
;
18309 register Lisp_Object tail
, proptail
;
18311 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18313 register Lisp_Object tem
;
18315 if (EQ (propval
, tem
))
18317 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
18318 return NILP (XCDR (tem
)) ? 1 : 2;
18321 if (CONSP (propval
))
18323 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
18325 Lisp_Object propelt
;
18326 propelt
= XCAR (proptail
);
18327 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18329 register Lisp_Object tem
;
18331 if (EQ (propelt
, tem
))
18333 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
18334 return NILP (XCDR (tem
)) ? 1 : 2;
18342 /* Calculate a width or height in pixels from a specification using
18343 the following elements:
18346 NUM - a (fractional) multiple of the default font width/height
18347 (NUM) - specifies exactly NUM pixels
18348 UNIT - a fixed number of pixels, see below.
18349 ELEMENT - size of a display element in pixels, see below.
18350 (NUM . SPEC) - equals NUM * SPEC
18351 (+ SPEC SPEC ...) - add pixel values
18352 (- SPEC SPEC ...) - subtract pixel values
18353 (- SPEC) - negate pixel value
18356 INT or FLOAT - a number constant
18357 SYMBOL - use symbol's (buffer local) variable binding.
18360 in - pixels per inch *)
18361 mm - pixels per 1/1000 meter *)
18362 cm - pixels per 1/100 meter *)
18363 width - width of current font in pixels.
18364 height - height of current font in pixels.
18366 *) using the ratio(s) defined in display-pixels-per-inch.
18370 left-fringe - left fringe width in pixels
18371 right-fringe - right fringe width in pixels
18373 left-margin - left margin width in pixels
18374 right-margin - right margin width in pixels
18376 scroll-bar - scroll-bar area width in pixels
18380 Pixels corresponding to 5 inches:
18383 Total width of non-text areas on left side of window (if scroll-bar is on left):
18384 '(space :width (+ left-fringe left-margin scroll-bar))
18386 Align to first text column (in header line):
18387 '(space :align-to 0)
18389 Align to middle of text area minus half the width of variable `my-image'
18390 containing a loaded image:
18391 '(space :align-to (0.5 . (- text my-image)))
18393 Width of left margin minus width of 1 character in the default font:
18394 '(space :width (- left-margin 1))
18396 Width of left margin minus width of 2 characters in the current font:
18397 '(space :width (- left-margin (2 . width)))
18399 Center 1 character over left-margin (in header line):
18400 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
18402 Different ways to express width of left fringe plus left margin minus one pixel:
18403 '(space :width (- (+ left-fringe left-margin) (1)))
18404 '(space :width (+ left-fringe left-margin (- (1))))
18405 '(space :width (+ left-fringe left-margin (-1)))
18409 #define NUMVAL(X) \
18410 ((INTEGERP (X) || FLOATP (X)) \
18415 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
18420 int width_p
, *align_to
;
18424 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
18425 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
18428 return OK_PIXELS (0);
18430 if (SYMBOLP (prop
))
18432 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18434 char *unit
= SDATA (SYMBOL_NAME (prop
));
18436 if (unit
[0] == 'i' && unit
[1] == 'n')
18438 else if (unit
[0] == 'm' && unit
[1] == 'm')
18440 else if (unit
[0] == 'c' && unit
[1] == 'm')
18447 #ifdef HAVE_WINDOW_SYSTEM
18448 if (FRAME_WINDOW_P (it
->f
)
18450 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
18451 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
18453 return OK_PIXELS (ppi
/ pixels
);
18456 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18457 || (CONSP (Vdisplay_pixels_per_inch
)
18459 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18460 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18462 return OK_PIXELS (ppi
/ pixels
);
18468 #ifdef HAVE_WINDOW_SYSTEM
18469 if (EQ (prop
, Qheight
))
18470 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
18471 if (EQ (prop
, Qwidth
))
18472 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
18474 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
18475 return OK_PIXELS (1);
18478 if (EQ (prop
, Qtext
))
18479 return OK_PIXELS (width_p
18480 ? window_box_width (it
->w
, TEXT_AREA
)
18481 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
18483 if (align_to
&& *align_to
< 0)
18486 if (EQ (prop
, Qleft
))
18487 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
18488 if (EQ (prop
, Qright
))
18489 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
18490 if (EQ (prop
, Qcenter
))
18491 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
18492 + window_box_width (it
->w
, TEXT_AREA
) / 2);
18493 if (EQ (prop
, Qleft_fringe
))
18494 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18495 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
18496 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
18497 if (EQ (prop
, Qright_fringe
))
18498 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18499 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18500 : window_box_right_offset (it
->w
, TEXT_AREA
));
18501 if (EQ (prop
, Qleft_margin
))
18502 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
18503 if (EQ (prop
, Qright_margin
))
18504 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
18505 if (EQ (prop
, Qscroll_bar
))
18506 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18508 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18509 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18510 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18515 if (EQ (prop
, Qleft_fringe
))
18516 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18517 if (EQ (prop
, Qright_fringe
))
18518 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18519 if (EQ (prop
, Qleft_margin
))
18520 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18521 if (EQ (prop
, Qright_margin
))
18522 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18523 if (EQ (prop
, Qscroll_bar
))
18524 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18527 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18530 if (INTEGERP (prop
) || FLOATP (prop
))
18532 int base_unit
= (width_p
18533 ? FRAME_COLUMN_WIDTH (it
->f
)
18534 : FRAME_LINE_HEIGHT (it
->f
));
18535 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18540 Lisp_Object car
= XCAR (prop
);
18541 Lisp_Object cdr
= XCDR (prop
);
18545 #ifdef HAVE_WINDOW_SYSTEM
18546 if (valid_image_p (prop
))
18548 int id
= lookup_image (it
->f
, prop
);
18549 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
18551 return OK_PIXELS (width_p
? img
->width
: img
->height
);
18554 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18560 while (CONSP (cdr
))
18562 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
18563 font
, width_p
, align_to
))
18566 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18571 if (EQ (car
, Qminus
))
18573 return OK_PIXELS (pixels
);
18576 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18579 if (INTEGERP (car
) || FLOATP (car
))
18582 pixels
= XFLOATINT (car
);
18584 return OK_PIXELS (pixels
);
18585 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
18586 font
, width_p
, align_to
))
18587 return OK_PIXELS (pixels
* fact
);
18598 /***********************************************************************
18600 ***********************************************************************/
18602 #ifdef HAVE_WINDOW_SYSTEM
18607 dump_glyph_string (s
)
18608 struct glyph_string
*s
;
18610 fprintf (stderr
, "glyph string\n");
18611 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
18612 s
->x
, s
->y
, s
->width
, s
->height
);
18613 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
18614 fprintf (stderr
, " hl = %d\n", s
->hl
);
18615 fprintf (stderr
, " left overhang = %d, right = %d\n",
18616 s
->left_overhang
, s
->right_overhang
);
18617 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
18618 fprintf (stderr
, " extends to end of line = %d\n",
18619 s
->extends_to_end_of_line_p
);
18620 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
18621 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
18624 #endif /* GLYPH_DEBUG */
18626 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
18627 of XChar2b structures for S; it can't be allocated in
18628 init_glyph_string because it must be allocated via `alloca'. W
18629 is the window on which S is drawn. ROW and AREA are the glyph row
18630 and area within the row from which S is constructed. START is the
18631 index of the first glyph structure covered by S. HL is a
18632 face-override for drawing S. */
18635 #define OPTIONAL_HDC(hdc) hdc,
18636 #define DECLARE_HDC(hdc) HDC hdc;
18637 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
18638 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
18641 #ifndef OPTIONAL_HDC
18642 #define OPTIONAL_HDC(hdc)
18643 #define DECLARE_HDC(hdc)
18644 #define ALLOCATE_HDC(hdc, f)
18645 #define RELEASE_HDC(hdc, f)
18649 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
18650 struct glyph_string
*s
;
18654 struct glyph_row
*row
;
18655 enum glyph_row_area area
;
18657 enum draw_glyphs_face hl
;
18659 bzero (s
, sizeof *s
);
18661 s
->f
= XFRAME (w
->frame
);
18665 s
->display
= FRAME_X_DISPLAY (s
->f
);
18666 s
->window
= FRAME_X_WINDOW (s
->f
);
18667 s
->char2b
= char2b
;
18671 s
->first_glyph
= row
->glyphs
[area
] + start
;
18672 s
->height
= row
->height
;
18673 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
18675 /* Display the internal border below the tool-bar window. */
18676 if (WINDOWP (s
->f
->tool_bar_window
)
18677 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
18678 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
18680 s
->ybase
= s
->y
+ row
->ascent
;
18684 /* Append the list of glyph strings with head H and tail T to the list
18685 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
18688 append_glyph_string_lists (head
, tail
, h
, t
)
18689 struct glyph_string
**head
, **tail
;
18690 struct glyph_string
*h
, *t
;
18704 /* Prepend the list of glyph strings with head H and tail T to the
18705 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
18709 prepend_glyph_string_lists (head
, tail
, h
, t
)
18710 struct glyph_string
**head
, **tail
;
18711 struct glyph_string
*h
, *t
;
18725 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
18726 Set *HEAD and *TAIL to the resulting list. */
18729 append_glyph_string (head
, tail
, s
)
18730 struct glyph_string
**head
, **tail
;
18731 struct glyph_string
*s
;
18733 s
->next
= s
->prev
= NULL
;
18734 append_glyph_string_lists (head
, tail
, s
, s
);
18738 /* Get face and two-byte form of character glyph GLYPH on frame F.
18739 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
18740 a pointer to a realized face that is ready for display. */
18742 static INLINE
struct face
*
18743 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
18745 struct glyph
*glyph
;
18751 xassert (glyph
->type
== CHAR_GLYPH
);
18752 face
= FACE_FROM_ID (f
, glyph
->face_id
);
18757 if (!glyph
->multibyte_p
)
18759 /* Unibyte case. We don't have to encode, but we have to make
18760 sure to use a face suitable for unibyte. */
18761 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18763 else if (glyph
->u
.ch
< 128)
18765 /* Case of ASCII in a face known to fit ASCII. */
18766 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18770 int c1
, c2
, charset
;
18772 /* Split characters into bytes. If c2 is -1 afterwards, C is
18773 really a one-byte character so that byte1 is zero. */
18774 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
18776 STORE_XCHAR2B (char2b
, c1
, c2
);
18778 STORE_XCHAR2B (char2b
, 0, c1
);
18780 /* Maybe encode the character in *CHAR2B. */
18781 if (charset
!= CHARSET_ASCII
)
18783 struct font_info
*font_info
18784 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18787 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
18791 /* Make sure X resources of the face are allocated. */
18792 xassert (face
!= NULL
);
18793 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18798 /* Fill glyph string S with composition components specified by S->cmp.
18800 FACES is an array of faces for all components of this composition.
18801 S->gidx is the index of the first component for S.
18803 OVERLAPS non-zero means S should draw the foreground only, and use
18804 its physical height for clipping. See also draw_glyphs.
18806 Value is the index of a component not in S. */
18809 fill_composite_glyph_string (s
, faces
, overlaps
)
18810 struct glyph_string
*s
;
18811 struct face
**faces
;
18818 s
->for_overlaps
= overlaps
;
18820 s
->face
= faces
[s
->gidx
];
18821 s
->font
= s
->face
->font
;
18822 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18824 /* For all glyphs of this composition, starting at the offset
18825 S->gidx, until we reach the end of the definition or encounter a
18826 glyph that requires the different face, add it to S. */
18828 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
18831 /* All glyph strings for the same composition has the same width,
18832 i.e. the width set for the first component of the composition. */
18834 s
->width
= s
->first_glyph
->pixel_width
;
18836 /* If the specified font could not be loaded, use the frame's
18837 default font, but record the fact that we couldn't load it in
18838 the glyph string so that we can draw rectangles for the
18839 characters of the glyph string. */
18840 if (s
->font
== NULL
)
18842 s
->font_not_found_p
= 1;
18843 s
->font
= FRAME_FONT (s
->f
);
18846 /* Adjust base line for subscript/superscript text. */
18847 s
->ybase
+= s
->first_glyph
->voffset
;
18849 xassert (s
->face
&& s
->face
->gc
);
18851 /* This glyph string must always be drawn with 16-bit functions. */
18854 return s
->gidx
+ s
->nchars
;
18858 /* Fill glyph string S from a sequence of character glyphs.
18860 FACE_ID is the face id of the string. START is the index of the
18861 first glyph to consider, END is the index of the last + 1.
18862 OVERLAPS non-zero means S should draw the foreground only, and use
18863 its physical height for clipping. See also draw_glyphs.
18865 Value is the index of the first glyph not in S. */
18868 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
18869 struct glyph_string
*s
;
18871 int start
, end
, overlaps
;
18873 struct glyph
*glyph
, *last
;
18875 int glyph_not_available_p
;
18877 xassert (s
->f
== XFRAME (s
->w
->frame
));
18878 xassert (s
->nchars
== 0);
18879 xassert (start
>= 0 && end
> start
);
18881 s
->for_overlaps
= overlaps
,
18882 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18883 last
= s
->row
->glyphs
[s
->area
] + end
;
18884 voffset
= glyph
->voffset
;
18886 glyph_not_available_p
= glyph
->glyph_not_available_p
;
18888 while (glyph
< last
18889 && glyph
->type
== CHAR_GLYPH
18890 && glyph
->voffset
== voffset
18891 /* Same face id implies same font, nowadays. */
18892 && glyph
->face_id
== face_id
18893 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
18897 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
18898 s
->char2b
+ s
->nchars
,
18900 s
->two_byte_p
= two_byte_p
;
18902 xassert (s
->nchars
<= end
- start
);
18903 s
->width
+= glyph
->pixel_width
;
18907 s
->font
= s
->face
->font
;
18908 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18910 /* If the specified font could not be loaded, use the frame's font,
18911 but record the fact that we couldn't load it in
18912 S->font_not_found_p so that we can draw rectangles for the
18913 characters of the glyph string. */
18914 if (s
->font
== NULL
|| glyph_not_available_p
)
18916 s
->font_not_found_p
= 1;
18917 s
->font
= FRAME_FONT (s
->f
);
18920 /* Adjust base line for subscript/superscript text. */
18921 s
->ybase
+= voffset
;
18923 xassert (s
->face
&& s
->face
->gc
);
18924 return glyph
- s
->row
->glyphs
[s
->area
];
18928 /* Fill glyph string S from image glyph S->first_glyph. */
18931 fill_image_glyph_string (s
)
18932 struct glyph_string
*s
;
18934 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
18935 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
18937 s
->slice
= s
->first_glyph
->slice
;
18938 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
18939 s
->font
= s
->face
->font
;
18940 s
->width
= s
->first_glyph
->pixel_width
;
18942 /* Adjust base line for subscript/superscript text. */
18943 s
->ybase
+= s
->first_glyph
->voffset
;
18947 /* Fill glyph string S from a sequence of stretch glyphs.
18949 ROW is the glyph row in which the glyphs are found, AREA is the
18950 area within the row. START is the index of the first glyph to
18951 consider, END is the index of the last + 1.
18953 Value is the index of the first glyph not in S. */
18956 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
18957 struct glyph_string
*s
;
18958 struct glyph_row
*row
;
18959 enum glyph_row_area area
;
18962 struct glyph
*glyph
, *last
;
18963 int voffset
, face_id
;
18965 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
18967 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18968 last
= s
->row
->glyphs
[s
->area
] + end
;
18969 face_id
= glyph
->face_id
;
18970 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
18971 s
->font
= s
->face
->font
;
18972 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18973 s
->width
= glyph
->pixel_width
;
18975 voffset
= glyph
->voffset
;
18979 && glyph
->type
== STRETCH_GLYPH
18980 && glyph
->voffset
== voffset
18981 && glyph
->face_id
== face_id
);
18983 s
->width
+= glyph
->pixel_width
;
18985 /* Adjust base line for subscript/superscript text. */
18986 s
->ybase
+= voffset
;
18988 /* The case that face->gc == 0 is handled when drawing the glyph
18989 string by calling PREPARE_FACE_FOR_DISPLAY. */
18991 return glyph
- s
->row
->glyphs
[s
->area
];
18996 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
18997 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
18998 assumed to be zero. */
19001 x_get_glyph_overhangs (glyph
, f
, left
, right
)
19002 struct glyph
*glyph
;
19006 *left
= *right
= 0;
19008 if (glyph
->type
== CHAR_GLYPH
)
19012 struct font_info
*font_info
;
19016 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
19018 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
19019 if (font
/* ++KFS: Should this be font_info ? */
19020 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
19022 if (pcm
->rbearing
> pcm
->width
)
19023 *right
= pcm
->rbearing
- pcm
->width
;
19024 if (pcm
->lbearing
< 0)
19025 *left
= -pcm
->lbearing
;
19031 /* Return the index of the first glyph preceding glyph string S that
19032 is overwritten by S because of S's left overhang. Value is -1
19033 if no glyphs are overwritten. */
19036 left_overwritten (s
)
19037 struct glyph_string
*s
;
19041 if (s
->left_overhang
)
19044 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19045 int first
= s
->first_glyph
- glyphs
;
19047 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
19048 x
-= glyphs
[i
].pixel_width
;
19059 /* Return the index of the first glyph preceding glyph string S that
19060 is overwriting S because of its right overhang. Value is -1 if no
19061 glyph in front of S overwrites S. */
19064 left_overwriting (s
)
19065 struct glyph_string
*s
;
19068 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19069 int first
= s
->first_glyph
- glyphs
;
19073 for (i
= first
- 1; i
>= 0; --i
)
19076 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19079 x
-= glyphs
[i
].pixel_width
;
19086 /* Return the index of the last glyph following glyph string S that is
19087 not overwritten by S because of S's right overhang. Value is -1 if
19088 no such glyph is found. */
19091 right_overwritten (s
)
19092 struct glyph_string
*s
;
19096 if (s
->right_overhang
)
19099 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19100 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19101 int end
= s
->row
->used
[s
->area
];
19103 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
19104 x
+= glyphs
[i
].pixel_width
;
19113 /* Return the index of the last glyph following glyph string S that
19114 overwrites S because of its left overhang. Value is negative
19115 if no such glyph is found. */
19118 right_overwriting (s
)
19119 struct glyph_string
*s
;
19122 int end
= s
->row
->used
[s
->area
];
19123 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19124 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19128 for (i
= first
; i
< end
; ++i
)
19131 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19134 x
+= glyphs
[i
].pixel_width
;
19141 /* Get face and two-byte form of character C in face FACE_ID on frame
19142 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19143 means we want to display multibyte text. DISPLAY_P non-zero means
19144 make sure that X resources for the face returned are allocated.
19145 Value is a pointer to a realized face that is ready for display if
19146 DISPLAY_P is non-zero. */
19148 static INLINE
struct face
*
19149 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
19153 int multibyte_p
, display_p
;
19155 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19159 /* Unibyte case. We don't have to encode, but we have to make
19160 sure to use a face suitable for unibyte. */
19161 STORE_XCHAR2B (char2b
, 0, c
);
19162 face_id
= FACE_FOR_CHAR (f
, face
, c
);
19163 face
= FACE_FROM_ID (f
, face_id
);
19167 /* Case of ASCII in a face known to fit ASCII. */
19168 STORE_XCHAR2B (char2b
, 0, c
);
19172 int c1
, c2
, charset
;
19174 /* Split characters into bytes. If c2 is -1 afterwards, C is
19175 really a one-byte character so that byte1 is zero. */
19176 SPLIT_CHAR (c
, charset
, c1
, c2
);
19178 STORE_XCHAR2B (char2b
, c1
, c2
);
19180 STORE_XCHAR2B (char2b
, 0, c1
);
19182 /* Maybe encode the character in *CHAR2B. */
19183 if (face
->font
!= NULL
)
19185 struct font_info
*font_info
19186 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
19188 rif
->encode_char (c
, char2b
, font_info
, 0);
19192 /* Make sure X resources of the face are allocated. */
19193 #ifdef HAVE_X_WINDOWS
19197 xassert (face
!= NULL
);
19198 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19205 /* Set background width of glyph string S. START is the index of the
19206 first glyph following S. LAST_X is the right-most x-position + 1
19207 in the drawing area. */
19210 set_glyph_string_background_width (s
, start
, last_x
)
19211 struct glyph_string
*s
;
19215 /* If the face of this glyph string has to be drawn to the end of
19216 the drawing area, set S->extends_to_end_of_line_p. */
19218 if (start
== s
->row
->used
[s
->area
]
19219 && s
->area
== TEXT_AREA
19220 && ((s
->row
->fill_line_p
19221 && (s
->hl
== DRAW_NORMAL_TEXT
19222 || s
->hl
== DRAW_IMAGE_RAISED
19223 || s
->hl
== DRAW_IMAGE_SUNKEN
))
19224 || s
->hl
== DRAW_MOUSE_FACE
))
19225 s
->extends_to_end_of_line_p
= 1;
19227 /* If S extends its face to the end of the line, set its
19228 background_width to the distance to the right edge of the drawing
19230 if (s
->extends_to_end_of_line_p
)
19231 s
->background_width
= last_x
- s
->x
+ 1;
19233 s
->background_width
= s
->width
;
19237 /* Compute overhangs and x-positions for glyph string S and its
19238 predecessors, or successors. X is the starting x-position for S.
19239 BACKWARD_P non-zero means process predecessors. */
19242 compute_overhangs_and_x (s
, x
, backward_p
)
19243 struct glyph_string
*s
;
19251 if (rif
->compute_glyph_string_overhangs
)
19252 rif
->compute_glyph_string_overhangs (s
);
19262 if (rif
->compute_glyph_string_overhangs
)
19263 rif
->compute_glyph_string_overhangs (s
);
19273 /* The following macros are only called from draw_glyphs below.
19274 They reference the following parameters of that function directly:
19275 `w', `row', `area', and `overlap_p'
19276 as well as the following local variables:
19277 `s', `f', and `hdc' (in W32) */
19280 /* On W32, silently add local `hdc' variable to argument list of
19281 init_glyph_string. */
19282 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19283 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
19285 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19286 init_glyph_string (s, char2b, w, row, area, start, hl)
19289 /* Add a glyph string for a stretch glyph to the list of strings
19290 between HEAD and TAIL. START is the index of the stretch glyph in
19291 row area AREA of glyph row ROW. END is the index of the last glyph
19292 in that glyph row area. X is the current output position assigned
19293 to the new glyph string constructed. HL overrides that face of the
19294 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19295 is the right-most x-position of the drawing area. */
19297 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
19298 and below -- keep them on one line. */
19299 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19302 s = (struct glyph_string *) alloca (sizeof *s); \
19303 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19304 START = fill_stretch_glyph_string (s, row, area, START, END); \
19305 append_glyph_string (&HEAD, &TAIL, s); \
19311 /* Add a glyph string for an image glyph to the list of strings
19312 between HEAD and TAIL. START is the index of the image 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 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19322 s = (struct glyph_string *) alloca (sizeof *s); \
19323 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19324 fill_image_glyph_string (s); \
19325 append_glyph_string (&HEAD, &TAIL, s); \
19332 /* Add a glyph string for a sequence of character glyphs to the list
19333 of strings between HEAD and TAIL. START is the index of the first
19334 glyph in row area AREA of glyph row ROW that is part of the new
19335 glyph string. END is the index of the last glyph in that glyph row
19336 area. X is the current output position assigned to the new glyph
19337 string constructed. HL overrides that face of the glyph; e.g. it
19338 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
19339 right-most x-position of the drawing area. */
19341 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19347 c = (row)->glyphs[area][START].u.ch; \
19348 face_id = (row)->glyphs[area][START].face_id; \
19350 s = (struct glyph_string *) alloca (sizeof *s); \
19351 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
19352 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
19353 append_glyph_string (&HEAD, &TAIL, s); \
19355 START = fill_glyph_string (s, face_id, START, END, overlaps); \
19360 /* Add a glyph string for a composite sequence to the list of strings
19361 between HEAD and TAIL. START is the index of the first glyph in
19362 row area AREA of glyph row ROW that is part of the new glyph
19363 string. END is the index of the last glyph in that glyph row area.
19364 X is the current output position assigned to the new glyph string
19365 constructed. HL overrides that face of the glyph; e.g. it is
19366 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
19367 x-position of the drawing area. */
19369 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19371 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
19372 int face_id = (row)->glyphs[area][START].face_id; \
19373 struct face *base_face = FACE_FROM_ID (f, face_id); \
19374 struct composition *cmp = composition_table[cmp_id]; \
19375 int glyph_len = cmp->glyph_len; \
19377 struct face **faces; \
19378 struct glyph_string *first_s = NULL; \
19381 base_face = base_face->ascii_face; \
19382 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
19383 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
19384 /* At first, fill in `char2b' and `faces'. */ \
19385 for (n = 0; n < glyph_len; n++) \
19387 int c = COMPOSITION_GLYPH (cmp, n); \
19388 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
19389 faces[n] = FACE_FROM_ID (f, this_face_id); \
19390 get_char_face_and_encoding (f, c, this_face_id, \
19391 char2b + n, 1, 1); \
19394 /* Make glyph_strings for each glyph sequence that is drawable by \
19395 the same face, and append them to HEAD/TAIL. */ \
19396 for (n = 0; n < cmp->glyph_len;) \
19398 s = (struct glyph_string *) alloca (sizeof *s); \
19399 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
19400 append_glyph_string (&(HEAD), &(TAIL), s); \
19408 n = fill_composite_glyph_string (s, faces, overlaps); \
19416 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
19417 of AREA of glyph row ROW on window W between indices START and END.
19418 HL overrides the face for drawing glyph strings, e.g. it is
19419 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
19420 x-positions of the drawing area.
19422 This is an ugly monster macro construct because we must use alloca
19423 to allocate glyph strings (because draw_glyphs can be called
19424 asynchronously). */
19426 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19429 HEAD = TAIL = NULL; \
19430 while (START < END) \
19432 struct glyph *first_glyph = (row)->glyphs[area] + START; \
19433 switch (first_glyph->type) \
19436 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
19440 case COMPOSITE_GLYPH: \
19441 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
19445 case STRETCH_GLYPH: \
19446 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
19450 case IMAGE_GLYPH: \
19451 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
19459 set_glyph_string_background_width (s, START, LAST_X); \
19466 /* Draw glyphs between START and END in AREA of ROW on window W,
19467 starting at x-position X. X is relative to AREA in W. HL is a
19468 face-override with the following meaning:
19470 DRAW_NORMAL_TEXT draw normally
19471 DRAW_CURSOR draw in cursor face
19472 DRAW_MOUSE_FACE draw in mouse face.
19473 DRAW_INVERSE_VIDEO draw in mode line face
19474 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
19475 DRAW_IMAGE_RAISED draw an image with a raised relief around it
19477 If OVERLAPS is non-zero, draw only the foreground of characters and
19478 clip to the physical height of ROW. Non-zero value also defines
19479 the overlapping part to be drawn:
19481 OVERLAPS_PRED overlap with preceding rows
19482 OVERLAPS_SUCC overlap with succeeding rows
19483 OVERLAPS_BOTH overlap with both preceding/succeeding rows
19484 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
19486 Value is the x-position reached, relative to AREA of W. */
19489 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
19492 struct glyph_row
*row
;
19493 enum glyph_row_area area
;
19495 enum draw_glyphs_face hl
;
19498 struct glyph_string
*head
, *tail
;
19499 struct glyph_string
*s
;
19500 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
19501 int last_x
, area_width
;
19504 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19507 ALLOCATE_HDC (hdc
, f
);
19509 /* Let's rather be paranoid than getting a SEGV. */
19510 end
= min (end
, row
->used
[area
]);
19511 start
= max (0, start
);
19512 start
= min (end
, start
);
19514 /* Translate X to frame coordinates. Set last_x to the right
19515 end of the drawing area. */
19516 if (row
->full_width_p
)
19518 /* X is relative to the left edge of W, without scroll bars
19520 x
+= WINDOW_LEFT_EDGE_X (w
);
19521 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
19525 int area_left
= window_box_left (w
, area
);
19527 area_width
= window_box_width (w
, area
);
19528 last_x
= area_left
+ area_width
;
19531 /* Build a doubly-linked list of glyph_string structures between
19532 head and tail from what we have to draw. Note that the macro
19533 BUILD_GLYPH_STRINGS will modify its start parameter. That's
19534 the reason we use a separate variable `i'. */
19536 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
19538 x_reached
= tail
->x
+ tail
->background_width
;
19542 /* If there are any glyphs with lbearing < 0 or rbearing > width in
19543 the row, redraw some glyphs in front or following the glyph
19544 strings built above. */
19545 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
19548 struct glyph_string
*h
, *t
;
19550 /* Compute overhangs for all glyph strings. */
19551 if (rif
->compute_glyph_string_overhangs
)
19552 for (s
= head
; s
; s
= s
->next
)
19553 rif
->compute_glyph_string_overhangs (s
);
19555 /* Prepend glyph strings for glyphs in front of the first glyph
19556 string that are overwritten because of the first glyph
19557 string's left overhang. The background of all strings
19558 prepended must be drawn because the first glyph string
19560 i
= left_overwritten (head
);
19564 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
19565 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19567 compute_overhangs_and_x (t
, head
->x
, 1);
19568 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19572 /* Prepend glyph strings for glyphs in front of the first glyph
19573 string that overwrite that glyph string because of their
19574 right overhang. For these strings, only the foreground must
19575 be drawn, because it draws over the glyph string at `head'.
19576 The background must not be drawn because this would overwrite
19577 right overhangs of preceding glyphs for which no glyph
19579 i
= left_overwriting (head
);
19583 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
19584 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19585 for (s
= h
; s
; s
= s
->next
)
19586 s
->background_filled_p
= 1;
19587 compute_overhangs_and_x (t
, head
->x
, 1);
19588 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19591 /* Append glyphs strings for glyphs following the last glyph
19592 string tail that are overwritten by tail. The background of
19593 these strings has to be drawn because tail's foreground draws
19595 i
= right_overwritten (tail
);
19598 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19599 DRAW_NORMAL_TEXT
, x
, last_x
);
19600 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19601 append_glyph_string_lists (&head
, &tail
, h
, t
);
19605 /* Append glyph strings for glyphs following the last glyph
19606 string tail that overwrite tail. The foreground of such
19607 glyphs has to be drawn because it writes into the background
19608 of tail. The background must not be drawn because it could
19609 paint over the foreground of following glyphs. */
19610 i
= right_overwriting (tail
);
19614 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19615 DRAW_NORMAL_TEXT
, x
, last_x
);
19616 for (s
= h
; s
; s
= s
->next
)
19617 s
->background_filled_p
= 1;
19618 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19619 append_glyph_string_lists (&head
, &tail
, h
, t
);
19621 if (clip_head
|| clip_tail
)
19622 for (s
= head
; s
; s
= s
->next
)
19624 s
->clip_head
= clip_head
;
19625 s
->clip_tail
= clip_tail
;
19629 /* Draw all strings. */
19630 for (s
= head
; s
; s
= s
->next
)
19631 rif
->draw_glyph_string (s
);
19633 if (area
== TEXT_AREA
19634 && !row
->full_width_p
19635 /* When drawing overlapping rows, only the glyph strings'
19636 foreground is drawn, which doesn't erase a cursor
19640 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
19641 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
19642 : (tail
? tail
->x
+ tail
->background_width
: x
));
19644 int text_left
= window_box_left (w
, TEXT_AREA
);
19648 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
19649 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
19652 /* Value is the x-position up to which drawn, relative to AREA of W.
19653 This doesn't include parts drawn because of overhangs. */
19654 if (row
->full_width_p
)
19655 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
19657 x_reached
-= window_box_left (w
, area
);
19659 RELEASE_HDC (hdc
, f
);
19664 /* Expand row matrix if too narrow. Don't expand if area
19667 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
19669 if (!fonts_changed_p \
19670 && (it->glyph_row->glyphs[area] \
19671 < it->glyph_row->glyphs[area + 1])) \
19673 it->w->ncols_scale_factor++; \
19674 fonts_changed_p = 1; \
19678 /* Store one glyph for IT->char_to_display in IT->glyph_row.
19679 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19685 struct glyph
*glyph
;
19686 enum glyph_row_area area
= it
->area
;
19688 xassert (it
->glyph_row
);
19689 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
19691 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19692 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19694 glyph
->charpos
= CHARPOS (it
->position
);
19695 glyph
->object
= it
->object
;
19696 glyph
->pixel_width
= it
->pixel_width
;
19697 glyph
->ascent
= it
->ascent
;
19698 glyph
->descent
= it
->descent
;
19699 glyph
->voffset
= it
->voffset
;
19700 glyph
->type
= CHAR_GLYPH
;
19701 glyph
->multibyte_p
= it
->multibyte_p
;
19702 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19703 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19704 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19705 || it
->phys_descent
> it
->descent
);
19706 glyph
->padding_p
= 0;
19707 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
19708 glyph
->face_id
= it
->face_id
;
19709 glyph
->u
.ch
= it
->char_to_display
;
19710 glyph
->slice
= null_glyph_slice
;
19711 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19712 ++it
->glyph_row
->used
[area
];
19715 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19718 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
19719 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19722 append_composite_glyph (it
)
19725 struct glyph
*glyph
;
19726 enum glyph_row_area area
= it
->area
;
19728 xassert (it
->glyph_row
);
19730 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19731 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19733 glyph
->charpos
= CHARPOS (it
->position
);
19734 glyph
->object
= it
->object
;
19735 glyph
->pixel_width
= it
->pixel_width
;
19736 glyph
->ascent
= it
->ascent
;
19737 glyph
->descent
= it
->descent
;
19738 glyph
->voffset
= it
->voffset
;
19739 glyph
->type
= COMPOSITE_GLYPH
;
19740 glyph
->multibyte_p
= it
->multibyte_p
;
19741 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19742 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19743 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19744 || it
->phys_descent
> it
->descent
);
19745 glyph
->padding_p
= 0;
19746 glyph
->glyph_not_available_p
= 0;
19747 glyph
->face_id
= it
->face_id
;
19748 glyph
->u
.cmp_id
= it
->cmp_id
;
19749 glyph
->slice
= null_glyph_slice
;
19750 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19751 ++it
->glyph_row
->used
[area
];
19754 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19758 /* Change IT->ascent and IT->height according to the setting of
19762 take_vertical_position_into_account (it
)
19767 if (it
->voffset
< 0)
19768 /* Increase the ascent so that we can display the text higher
19770 it
->ascent
-= it
->voffset
;
19772 /* Increase the descent so that we can display the text lower
19774 it
->descent
+= it
->voffset
;
19779 /* Produce glyphs/get display metrics for the image IT is loaded with.
19780 See the description of struct display_iterator in dispextern.h for
19781 an overview of struct display_iterator. */
19784 produce_image_glyph (it
)
19789 int glyph_ascent
, crop
;
19790 struct glyph_slice slice
;
19792 xassert (it
->what
== IT_IMAGE
);
19794 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19796 /* Make sure X resources of the face is loaded. */
19797 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19799 if (it
->image_id
< 0)
19801 /* Fringe bitmap. */
19802 it
->ascent
= it
->phys_ascent
= 0;
19803 it
->descent
= it
->phys_descent
= 0;
19804 it
->pixel_width
= 0;
19809 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
19811 /* Make sure X resources of the image is loaded. */
19812 prepare_image_for_display (it
->f
, img
);
19814 slice
.x
= slice
.y
= 0;
19815 slice
.width
= img
->width
;
19816 slice
.height
= img
->height
;
19818 if (INTEGERP (it
->slice
.x
))
19819 slice
.x
= XINT (it
->slice
.x
);
19820 else if (FLOATP (it
->slice
.x
))
19821 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
19823 if (INTEGERP (it
->slice
.y
))
19824 slice
.y
= XINT (it
->slice
.y
);
19825 else if (FLOATP (it
->slice
.y
))
19826 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
19828 if (INTEGERP (it
->slice
.width
))
19829 slice
.width
= XINT (it
->slice
.width
);
19830 else if (FLOATP (it
->slice
.width
))
19831 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
19833 if (INTEGERP (it
->slice
.height
))
19834 slice
.height
= XINT (it
->slice
.height
);
19835 else if (FLOATP (it
->slice
.height
))
19836 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
19838 if (slice
.x
>= img
->width
)
19839 slice
.x
= img
->width
;
19840 if (slice
.y
>= img
->height
)
19841 slice
.y
= img
->height
;
19842 if (slice
.x
+ slice
.width
>= img
->width
)
19843 slice
.width
= img
->width
- slice
.x
;
19844 if (slice
.y
+ slice
.height
> img
->height
)
19845 slice
.height
= img
->height
- slice
.y
;
19847 if (slice
.width
== 0 || slice
.height
== 0)
19850 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
19852 it
->descent
= slice
.height
- glyph_ascent
;
19854 it
->descent
+= img
->vmargin
;
19855 if (slice
.y
+ slice
.height
== img
->height
)
19856 it
->descent
+= img
->vmargin
;
19857 it
->phys_descent
= it
->descent
;
19859 it
->pixel_width
= slice
.width
;
19861 it
->pixel_width
+= img
->hmargin
;
19862 if (slice
.x
+ slice
.width
== img
->width
)
19863 it
->pixel_width
+= img
->hmargin
;
19865 /* It's quite possible for images to have an ascent greater than
19866 their height, so don't get confused in that case. */
19867 if (it
->descent
< 0)
19870 #if 0 /* this breaks image tiling */
19871 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
19872 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
19873 if (face_ascent
> it
->ascent
)
19874 it
->ascent
= it
->phys_ascent
= face_ascent
;
19879 if (face
->box
!= FACE_NO_BOX
)
19881 if (face
->box_line_width
> 0)
19884 it
->ascent
+= face
->box_line_width
;
19885 if (slice
.y
+ slice
.height
== img
->height
)
19886 it
->descent
+= face
->box_line_width
;
19889 if (it
->start_of_box_run_p
&& slice
.x
== 0)
19890 it
->pixel_width
+= abs (face
->box_line_width
);
19891 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
19892 it
->pixel_width
+= abs (face
->box_line_width
);
19895 take_vertical_position_into_account (it
);
19897 /* Automatically crop wide image glyphs at right edge so we can
19898 draw the cursor on same display row. */
19899 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
19900 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
19902 it
->pixel_width
-= crop
;
19903 slice
.width
-= crop
;
19908 struct glyph
*glyph
;
19909 enum glyph_row_area area
= it
->area
;
19911 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19912 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19914 glyph
->charpos
= CHARPOS (it
->position
);
19915 glyph
->object
= it
->object
;
19916 glyph
->pixel_width
= it
->pixel_width
;
19917 glyph
->ascent
= glyph_ascent
;
19918 glyph
->descent
= it
->descent
;
19919 glyph
->voffset
= it
->voffset
;
19920 glyph
->type
= IMAGE_GLYPH
;
19921 glyph
->multibyte_p
= it
->multibyte_p
;
19922 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19923 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19924 glyph
->overlaps_vertically_p
= 0;
19925 glyph
->padding_p
= 0;
19926 glyph
->glyph_not_available_p
= 0;
19927 glyph
->face_id
= it
->face_id
;
19928 glyph
->u
.img_id
= img
->id
;
19929 glyph
->slice
= slice
;
19930 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19931 ++it
->glyph_row
->used
[area
];
19934 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19939 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
19940 of the glyph, WIDTH and HEIGHT are the width and height of the
19941 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
19944 append_stretch_glyph (it
, object
, width
, height
, ascent
)
19946 Lisp_Object object
;
19950 struct glyph
*glyph
;
19951 enum glyph_row_area area
= it
->area
;
19953 xassert (ascent
>= 0 && ascent
<= height
);
19955 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19956 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19958 glyph
->charpos
= CHARPOS (it
->position
);
19959 glyph
->object
= object
;
19960 glyph
->pixel_width
= width
;
19961 glyph
->ascent
= ascent
;
19962 glyph
->descent
= height
- ascent
;
19963 glyph
->voffset
= it
->voffset
;
19964 glyph
->type
= STRETCH_GLYPH
;
19965 glyph
->multibyte_p
= it
->multibyte_p
;
19966 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19967 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19968 glyph
->overlaps_vertically_p
= 0;
19969 glyph
->padding_p
= 0;
19970 glyph
->glyph_not_available_p
= 0;
19971 glyph
->face_id
= it
->face_id
;
19972 glyph
->u
.stretch
.ascent
= ascent
;
19973 glyph
->u
.stretch
.height
= height
;
19974 glyph
->slice
= null_glyph_slice
;
19975 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19976 ++it
->glyph_row
->used
[area
];
19979 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19983 /* Produce a stretch glyph for iterator IT. IT->object is the value
19984 of the glyph property displayed. The value must be a list
19985 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
19988 1. `:width WIDTH' specifies that the space should be WIDTH *
19989 canonical char width wide. WIDTH may be an integer or floating
19992 2. `:relative-width FACTOR' specifies that the width of the stretch
19993 should be computed from the width of the first character having the
19994 `glyph' property, and should be FACTOR times that width.
19996 3. `:align-to HPOS' specifies that the space should be wide enough
19997 to reach HPOS, a value in canonical character units.
19999 Exactly one of the above pairs must be present.
20001 4. `:height HEIGHT' specifies that the height of the stretch produced
20002 should be HEIGHT, measured in canonical character units.
20004 5. `:relative-height FACTOR' specifies that the height of the
20005 stretch should be FACTOR times the height of the characters having
20006 the glyph property.
20008 Either none or exactly one of 4 or 5 must be present.
20010 6. `:ascent ASCENT' specifies that ASCENT percent of the height
20011 of the stretch should be used for the ascent of the stretch.
20012 ASCENT must be in the range 0 <= ASCENT <= 100. */
20015 produce_stretch_glyph (it
)
20018 /* (space :width WIDTH :height HEIGHT ...) */
20019 Lisp_Object prop
, plist
;
20020 int width
= 0, height
= 0, align_to
= -1;
20021 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
20024 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20025 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
20027 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20029 /* List should start with `space'. */
20030 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
20031 plist
= XCDR (it
->object
);
20033 /* Compute the width of the stretch. */
20034 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
20035 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
20037 /* Absolute width `:width WIDTH' specified and valid. */
20038 zero_width_ok_p
= 1;
20041 else if (prop
= Fplist_get (plist
, QCrelative_width
),
20044 /* Relative width `:relative-width FACTOR' specified and valid.
20045 Compute the width of the characters having the `glyph'
20048 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
20051 if (it
->multibyte_p
)
20053 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
20054 - IT_BYTEPOS (*it
));
20055 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
20058 it2
.c
= *p
, it2
.len
= 1;
20060 it2
.glyph_row
= NULL
;
20061 it2
.what
= IT_CHARACTER
;
20062 x_produce_glyphs (&it2
);
20063 width
= NUMVAL (prop
) * it2
.pixel_width
;
20065 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
20066 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
20068 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
20069 align_to
= (align_to
< 0
20071 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
20072 else if (align_to
< 0)
20073 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
20074 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
20075 zero_width_ok_p
= 1;
20078 /* Nothing specified -> width defaults to canonical char width. */
20079 width
= FRAME_COLUMN_WIDTH (it
->f
);
20081 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
20084 /* Compute height. */
20085 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
20086 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20089 zero_height_ok_p
= 1;
20091 else if (prop
= Fplist_get (plist
, QCrelative_height
),
20093 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
20095 height
= FONT_HEIGHT (font
);
20097 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
20100 /* Compute percentage of height used for ascent. If
20101 `:ascent ASCENT' is present and valid, use that. Otherwise,
20102 derive the ascent from the font in use. */
20103 if (prop
= Fplist_get (plist
, QCascent
),
20104 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
20105 ascent
= height
* NUMVAL (prop
) / 100.0;
20106 else if (!NILP (prop
)
20107 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20108 ascent
= min (max (0, (int)tem
), height
);
20110 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
20112 if (width
> 0 && !it
->truncate_lines_p
20113 && it
->current_x
+ width
> it
->last_visible_x
)
20114 width
= it
->last_visible_x
- it
->current_x
- 1;
20116 if (width
> 0 && height
> 0 && it
->glyph_row
)
20118 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
20119 if (!STRINGP (object
))
20120 object
= it
->w
->buffer
;
20121 append_stretch_glyph (it
, object
, width
, height
, ascent
);
20124 it
->pixel_width
= width
;
20125 it
->ascent
= it
->phys_ascent
= ascent
;
20126 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
20127 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
20129 take_vertical_position_into_account (it
);
20132 /* Get line-height and line-spacing property at point.
20133 If line-height has format (HEIGHT TOTAL), return TOTAL
20134 in TOTAL_HEIGHT. */
20137 get_line_height_property (it
, prop
)
20141 Lisp_Object position
;
20143 if (STRINGP (it
->object
))
20144 position
= make_number (IT_STRING_CHARPOS (*it
));
20145 else if (BUFFERP (it
->object
))
20146 position
= make_number (IT_CHARPOS (*it
));
20150 return Fget_char_property (position
, prop
, it
->object
);
20153 /* Calculate line-height and line-spacing properties.
20154 An integer value specifies explicit pixel value.
20155 A float value specifies relative value to current face height.
20156 A cons (float . face-name) specifies relative value to
20157 height of specified face font.
20159 Returns height in pixels, or nil. */
20163 calc_line_height_property (it
, val
, font
, boff
, override
)
20167 int boff
, override
;
20169 Lisp_Object face_name
= Qnil
;
20170 int ascent
, descent
, height
;
20172 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
20177 face_name
= XCAR (val
);
20179 if (!NUMBERP (val
))
20180 val
= make_number (1);
20181 if (NILP (face_name
))
20183 height
= it
->ascent
+ it
->descent
;
20188 if (NILP (face_name
))
20190 font
= FRAME_FONT (it
->f
);
20191 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20193 else if (EQ (face_name
, Qt
))
20201 struct font_info
*font_info
;
20203 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
20205 return make_number (-1);
20207 face
= FACE_FROM_ID (it
->f
, face_id
);
20210 return make_number (-1);
20212 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20213 boff
= font_info
->baseline_offset
;
20214 if (font_info
->vertical_centering
)
20215 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20218 ascent
= FONT_BASE (font
) + boff
;
20219 descent
= FONT_DESCENT (font
) - boff
;
20223 it
->override_ascent
= ascent
;
20224 it
->override_descent
= descent
;
20225 it
->override_boff
= boff
;
20228 height
= ascent
+ descent
;
20232 height
= (int)(XFLOAT_DATA (val
) * height
);
20233 else if (INTEGERP (val
))
20234 height
*= XINT (val
);
20236 return make_number (height
);
20241 Produce glyphs/get display metrics for the display element IT is
20242 loaded with. See the description of struct it in dispextern.h
20243 for an overview of struct it. */
20246 x_produce_glyphs (it
)
20249 int extra_line_spacing
= it
->extra_line_spacing
;
20251 it
->glyph_not_available_p
= 0;
20253 if (it
->what
== IT_CHARACTER
)
20257 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20259 int font_not_found_p
;
20260 struct font_info
*font_info
;
20261 int boff
; /* baseline offset */
20262 /* We may change it->multibyte_p upon unibyte<->multibyte
20263 conversion. So, save the current value now and restore it
20266 Note: It seems that we don't have to record multibyte_p in
20267 struct glyph because the character code itself tells if or
20268 not the character is multibyte. Thus, in the future, we must
20269 consider eliminating the field `multibyte_p' in the struct
20271 int saved_multibyte_p
= it
->multibyte_p
;
20273 /* Maybe translate single-byte characters to multibyte, or the
20275 it
->char_to_display
= it
->c
;
20276 if (!ASCII_BYTE_P (it
->c
))
20278 if (unibyte_display_via_language_environment
20279 && SINGLE_BYTE_CHAR_P (it
->c
)
20281 || !NILP (Vnonascii_translation_table
)))
20283 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20284 it
->multibyte_p
= 1;
20285 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20286 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20288 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
20289 && !it
->multibyte_p
)
20291 it
->multibyte_p
= 1;
20292 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20293 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20297 /* Get font to use. Encode IT->char_to_display. */
20298 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20299 &char2b
, it
->multibyte_p
, 0);
20302 /* When no suitable font found, use the default font. */
20303 font_not_found_p
= font
== NULL
;
20304 if (font_not_found_p
)
20306 font
= FRAME_FONT (it
->f
);
20307 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20312 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20313 boff
= font_info
->baseline_offset
;
20314 if (font_info
->vertical_centering
)
20315 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20318 if (it
->char_to_display
>= ' '
20319 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
20321 /* Either unibyte or ASCII. */
20326 pcm
= rif
->per_char_metric (font
, &char2b
,
20327 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
20329 if (it
->override_ascent
>= 0)
20331 it
->ascent
= it
->override_ascent
;
20332 it
->descent
= it
->override_descent
;
20333 boff
= it
->override_boff
;
20337 it
->ascent
= FONT_BASE (font
) + boff
;
20338 it
->descent
= FONT_DESCENT (font
) - boff
;
20343 it
->phys_ascent
= pcm
->ascent
+ boff
;
20344 it
->phys_descent
= pcm
->descent
- boff
;
20345 it
->pixel_width
= pcm
->width
;
20349 it
->glyph_not_available_p
= 1;
20350 it
->phys_ascent
= it
->ascent
;
20351 it
->phys_descent
= it
->descent
;
20352 it
->pixel_width
= FONT_WIDTH (font
);
20355 if (it
->constrain_row_ascent_descent_p
)
20357 if (it
->descent
> it
->max_descent
)
20359 it
->ascent
+= it
->descent
- it
->max_descent
;
20360 it
->descent
= it
->max_descent
;
20362 if (it
->ascent
> it
->max_ascent
)
20364 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20365 it
->ascent
= it
->max_ascent
;
20367 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20368 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20369 extra_line_spacing
= 0;
20372 /* If this is a space inside a region of text with
20373 `space-width' property, change its width. */
20374 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
20376 it
->pixel_width
*= XFLOATINT (it
->space_width
);
20378 /* If face has a box, add the box thickness to the character
20379 height. If character has a box line to the left and/or
20380 right, add the box line width to the character's width. */
20381 if (face
->box
!= FACE_NO_BOX
)
20383 int thick
= face
->box_line_width
;
20387 it
->ascent
+= thick
;
20388 it
->descent
+= thick
;
20393 if (it
->start_of_box_run_p
)
20394 it
->pixel_width
+= thick
;
20395 if (it
->end_of_box_run_p
)
20396 it
->pixel_width
+= thick
;
20399 /* If face has an overline, add the height of the overline
20400 (1 pixel) and a 1 pixel margin to the character height. */
20401 if (face
->overline_p
)
20402 it
->ascent
+= overline_margin
;
20404 if (it
->constrain_row_ascent_descent_p
)
20406 if (it
->ascent
> it
->max_ascent
)
20407 it
->ascent
= it
->max_ascent
;
20408 if (it
->descent
> it
->max_descent
)
20409 it
->descent
= it
->max_descent
;
20412 take_vertical_position_into_account (it
);
20414 /* If we have to actually produce glyphs, do it. */
20419 /* Translate a space with a `space-width' property
20420 into a stretch glyph. */
20421 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
20422 / FONT_HEIGHT (font
));
20423 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20424 it
->ascent
+ it
->descent
, ascent
);
20429 /* If characters with lbearing or rbearing are displayed
20430 in this line, record that fact in a flag of the
20431 glyph row. This is used to optimize X output code. */
20432 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
20433 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20436 else if (it
->char_to_display
== '\n')
20438 /* A newline has no width but we need the height of the line.
20439 But if previous part of the line set a height, don't
20440 increase that height */
20442 Lisp_Object height
;
20443 Lisp_Object total_height
= Qnil
;
20445 it
->override_ascent
= -1;
20446 it
->pixel_width
= 0;
20449 height
= get_line_height_property(it
, Qline_height
);
20450 /* Split (line-height total-height) list */
20452 && CONSP (XCDR (height
))
20453 && NILP (XCDR (XCDR (height
))))
20455 total_height
= XCAR (XCDR (height
));
20456 height
= XCAR (height
);
20458 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
20460 if (it
->override_ascent
>= 0)
20462 it
->ascent
= it
->override_ascent
;
20463 it
->descent
= it
->override_descent
;
20464 boff
= it
->override_boff
;
20468 it
->ascent
= FONT_BASE (font
) + boff
;
20469 it
->descent
= FONT_DESCENT (font
) - boff
;
20472 if (EQ (height
, Qt
))
20474 if (it
->descent
> it
->max_descent
)
20476 it
->ascent
+= it
->descent
- it
->max_descent
;
20477 it
->descent
= it
->max_descent
;
20479 if (it
->ascent
> it
->max_ascent
)
20481 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20482 it
->ascent
= it
->max_ascent
;
20484 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20485 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20486 it
->constrain_row_ascent_descent_p
= 1;
20487 extra_line_spacing
= 0;
20491 Lisp_Object spacing
;
20493 it
->phys_ascent
= it
->ascent
;
20494 it
->phys_descent
= it
->descent
;
20496 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
20497 && face
->box
!= FACE_NO_BOX
20498 && face
->box_line_width
> 0)
20500 it
->ascent
+= face
->box_line_width
;
20501 it
->descent
+= face
->box_line_width
;
20504 && XINT (height
) > it
->ascent
+ it
->descent
)
20505 it
->ascent
= XINT (height
) - it
->descent
;
20507 if (!NILP (total_height
))
20508 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
20511 spacing
= get_line_height_property(it
, Qline_spacing
);
20512 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
20514 if (INTEGERP (spacing
))
20516 extra_line_spacing
= XINT (spacing
);
20517 if (!NILP (total_height
))
20518 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
20522 else if (it
->char_to_display
== '\t')
20524 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
20525 int x
= it
->current_x
+ it
->continuation_lines_width
;
20526 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
20528 /* If the distance from the current position to the next tab
20529 stop is less than a space character width, use the
20530 tab stop after that. */
20531 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
20532 next_tab_x
+= tab_width
;
20534 it
->pixel_width
= next_tab_x
- x
;
20536 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
20537 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20541 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20542 it
->ascent
+ it
->descent
, it
->ascent
);
20547 /* A multi-byte character. Assume that the display width of the
20548 character is the width of the character multiplied by the
20549 width of the font. */
20551 /* If we found a font, this font should give us the right
20552 metrics. If we didn't find a font, use the frame's
20553 default font and calculate the width of the character
20554 from the charset width; this is what old redisplay code
20557 pcm
= rif
->per_char_metric (font
, &char2b
,
20558 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
20560 if (font_not_found_p
|| !pcm
)
20562 int charset
= CHAR_CHARSET (it
->char_to_display
);
20564 it
->glyph_not_available_p
= 1;
20565 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
20566 * CHARSET_WIDTH (charset
));
20567 it
->phys_ascent
= FONT_BASE (font
) + boff
;
20568 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20572 it
->pixel_width
= pcm
->width
;
20573 it
->phys_ascent
= pcm
->ascent
+ boff
;
20574 it
->phys_descent
= pcm
->descent
- boff
;
20576 && (pcm
->lbearing
< 0
20577 || pcm
->rbearing
> pcm
->width
))
20578 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20581 it
->ascent
= FONT_BASE (font
) + boff
;
20582 it
->descent
= FONT_DESCENT (font
) - boff
;
20583 if (face
->box
!= FACE_NO_BOX
)
20585 int thick
= face
->box_line_width
;
20589 it
->ascent
+= thick
;
20590 it
->descent
+= thick
;
20595 if (it
->start_of_box_run_p
)
20596 it
->pixel_width
+= thick
;
20597 if (it
->end_of_box_run_p
)
20598 it
->pixel_width
+= thick
;
20601 /* If face has an overline, add the height of the overline
20602 (1 pixel) and a 1 pixel margin to the character height. */
20603 if (face
->overline_p
)
20604 it
->ascent
+= overline_margin
;
20606 take_vertical_position_into_account (it
);
20611 it
->multibyte_p
= saved_multibyte_p
;
20613 else if (it
->what
== IT_COMPOSITION
)
20615 /* Note: A composition is represented as one glyph in the
20616 glyph matrix. There are no padding glyphs. */
20619 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20621 int font_not_found_p
;
20622 struct font_info
*font_info
;
20623 int boff
; /* baseline offset */
20624 struct composition
*cmp
= composition_table
[it
->cmp_id
];
20626 /* Maybe translate single-byte characters to multibyte. */
20627 it
->char_to_display
= it
->c
;
20628 if (unibyte_display_via_language_environment
20629 && SINGLE_BYTE_CHAR_P (it
->c
)
20632 && !NILP (Vnonascii_translation_table
))))
20634 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20637 /* Get face and font to use. Encode IT->char_to_display. */
20638 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20639 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20640 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20641 &char2b
, it
->multibyte_p
, 0);
20644 /* When no suitable font found, use the default font. */
20645 font_not_found_p
= font
== NULL
;
20646 if (font_not_found_p
)
20648 font
= FRAME_FONT (it
->f
);
20649 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20654 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20655 boff
= font_info
->baseline_offset
;
20656 if (font_info
->vertical_centering
)
20657 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20660 /* There are no padding glyphs, so there is only one glyph to
20661 produce for the composition. Important is that pixel_width,
20662 ascent and descent are the values of what is drawn by
20663 draw_glyphs (i.e. the values of the overall glyphs composed). */
20666 /* If we have not yet calculated pixel size data of glyphs of
20667 the composition for the current face font, calculate them
20668 now. Theoretically, we have to check all fonts for the
20669 glyphs, but that requires much time and memory space. So,
20670 here we check only the font of the first glyph. This leads
20671 to incorrect display very rarely, and C-l (recenter) can
20672 correct the display anyway. */
20673 if (cmp
->font
!= (void *) font
)
20675 /* Ascent and descent of the font of the first character of
20676 this composition (adjusted by baseline offset). Ascent
20677 and descent of overall glyphs should not be less than
20678 them respectively. */
20679 int font_ascent
= FONT_BASE (font
) + boff
;
20680 int font_descent
= FONT_DESCENT (font
) - boff
;
20681 /* Bounding box of the overall glyphs. */
20682 int leftmost
, rightmost
, lowest
, highest
;
20683 int i
, width
, ascent
, descent
;
20685 cmp
->font
= (void *) font
;
20687 /* Initialize the bounding box. */
20689 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20690 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
20692 width
= pcm
->width
;
20693 ascent
= pcm
->ascent
;
20694 descent
= pcm
->descent
;
20698 width
= FONT_WIDTH (font
);
20699 ascent
= FONT_BASE (font
);
20700 descent
= FONT_DESCENT (font
);
20704 lowest
= - descent
+ boff
;
20705 highest
= ascent
+ boff
;
20709 && font_info
->default_ascent
20710 && CHAR_TABLE_P (Vuse_default_ascent
)
20711 && !NILP (Faref (Vuse_default_ascent
,
20712 make_number (it
->char_to_display
))))
20713 highest
= font_info
->default_ascent
+ boff
;
20715 /* Draw the first glyph at the normal position. It may be
20716 shifted to right later if some other glyphs are drawn at
20718 cmp
->offsets
[0] = 0;
20719 cmp
->offsets
[1] = boff
;
20721 /* Set cmp->offsets for the remaining glyphs. */
20722 for (i
= 1; i
< cmp
->glyph_len
; i
++)
20724 int left
, right
, btm
, top
;
20725 int ch
= COMPOSITION_GLYPH (cmp
, i
);
20726 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
20728 face
= FACE_FROM_ID (it
->f
, face_id
);
20729 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
20730 &char2b
, it
->multibyte_p
, 0);
20734 font
= FRAME_FONT (it
->f
);
20735 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20741 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20742 boff
= font_info
->baseline_offset
;
20743 if (font_info
->vertical_centering
)
20744 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20748 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20749 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
20751 width
= pcm
->width
;
20752 ascent
= pcm
->ascent
;
20753 descent
= pcm
->descent
;
20757 width
= FONT_WIDTH (font
);
20762 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
20764 /* Relative composition with or without
20765 alternate chars. */
20766 left
= (leftmost
+ rightmost
- width
) / 2;
20767 btm
= - descent
+ boff
;
20768 if (font_info
&& font_info
->relative_compose
20769 && (! CHAR_TABLE_P (Vignore_relative_composition
)
20770 || NILP (Faref (Vignore_relative_composition
,
20771 make_number (ch
)))))
20774 if (- descent
>= font_info
->relative_compose
)
20775 /* One extra pixel between two glyphs. */
20777 else if (ascent
<= 0)
20778 /* One extra pixel between two glyphs. */
20779 btm
= lowest
- 1 - ascent
- descent
;
20784 /* A composition rule is specified by an integer
20785 value that encodes global and new reference
20786 points (GREF and NREF). GREF and NREF are
20787 specified by numbers as below:
20789 0---1---2 -- ascent
20793 9--10--11 -- center
20795 ---3---4---5--- baseline
20797 6---7---8 -- descent
20799 int rule
= COMPOSITION_RULE (cmp
, i
);
20800 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
20802 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
20803 grefx
= gref
% 3, nrefx
= nref
% 3;
20804 grefy
= gref
/ 3, nrefy
= nref
/ 3;
20807 + grefx
* (rightmost
- leftmost
) / 2
20808 - nrefx
* width
/ 2);
20809 btm
= ((grefy
== 0 ? highest
20811 : grefy
== 2 ? lowest
20812 : (highest
+ lowest
) / 2)
20813 - (nrefy
== 0 ? ascent
+ descent
20814 : nrefy
== 1 ? descent
- boff
20816 : (ascent
+ descent
) / 2));
20819 cmp
->offsets
[i
* 2] = left
;
20820 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
20822 /* Update the bounding box of the overall glyphs. */
20823 right
= left
+ width
;
20824 top
= btm
+ descent
+ ascent
;
20825 if (left
< leftmost
)
20827 if (right
> rightmost
)
20835 /* If there are glyphs whose x-offsets are negative,
20836 shift all glyphs to the right and make all x-offsets
20840 for (i
= 0; i
< cmp
->glyph_len
; i
++)
20841 cmp
->offsets
[i
* 2] -= leftmost
;
20842 rightmost
-= leftmost
;
20845 cmp
->pixel_width
= rightmost
;
20846 cmp
->ascent
= highest
;
20847 cmp
->descent
= - lowest
;
20848 if (cmp
->ascent
< font_ascent
)
20849 cmp
->ascent
= font_ascent
;
20850 if (cmp
->descent
< font_descent
)
20851 cmp
->descent
= font_descent
;
20854 it
->pixel_width
= cmp
->pixel_width
;
20855 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
20856 it
->descent
= it
->phys_descent
= cmp
->descent
;
20858 if (face
->box
!= FACE_NO_BOX
)
20860 int thick
= face
->box_line_width
;
20864 it
->ascent
+= thick
;
20865 it
->descent
+= thick
;
20870 if (it
->start_of_box_run_p
)
20871 it
->pixel_width
+= thick
;
20872 if (it
->end_of_box_run_p
)
20873 it
->pixel_width
+= thick
;
20876 /* If face has an overline, add the height of the overline
20877 (1 pixel) and a 1 pixel margin to the character height. */
20878 if (face
->overline_p
)
20879 it
->ascent
+= overline_margin
;
20881 take_vertical_position_into_account (it
);
20884 append_composite_glyph (it
);
20886 else if (it
->what
== IT_IMAGE
)
20887 produce_image_glyph (it
);
20888 else if (it
->what
== IT_STRETCH
)
20889 produce_stretch_glyph (it
);
20891 /* Accumulate dimensions. Note: can't assume that it->descent > 0
20892 because this isn't true for images with `:ascent 100'. */
20893 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
20894 if (it
->area
== TEXT_AREA
)
20895 it
->current_x
+= it
->pixel_width
;
20897 if (extra_line_spacing
> 0)
20899 it
->descent
+= extra_line_spacing
;
20900 if (extra_line_spacing
> it
->max_extra_line_spacing
)
20901 it
->max_extra_line_spacing
= extra_line_spacing
;
20904 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
20905 it
->max_descent
= max (it
->max_descent
, it
->descent
);
20906 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
20907 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
20911 Output LEN glyphs starting at START at the nominal cursor position.
20912 Advance the nominal cursor over the text. The global variable
20913 updated_window contains the window being updated, updated_row is
20914 the glyph row being updated, and updated_area is the area of that
20915 row being updated. */
20918 x_write_glyphs (start
, len
)
20919 struct glyph
*start
;
20924 xassert (updated_window
&& updated_row
);
20927 /* Write glyphs. */
20929 hpos
= start
- updated_row
->glyphs
[updated_area
];
20930 x
= draw_glyphs (updated_window
, output_cursor
.x
,
20931 updated_row
, updated_area
,
20933 DRAW_NORMAL_TEXT
, 0);
20935 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
20936 if (updated_area
== TEXT_AREA
20937 && updated_window
->phys_cursor_on_p
20938 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
20939 && updated_window
->phys_cursor
.hpos
>= hpos
20940 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
20941 updated_window
->phys_cursor_on_p
= 0;
20945 /* Advance the output cursor. */
20946 output_cursor
.hpos
+= len
;
20947 output_cursor
.x
= x
;
20952 Insert LEN glyphs from START at the nominal cursor position. */
20955 x_insert_glyphs (start
, len
)
20956 struct glyph
*start
;
20961 int line_height
, shift_by_width
, shifted_region_width
;
20962 struct glyph_row
*row
;
20963 struct glyph
*glyph
;
20964 int frame_x
, frame_y
, hpos
;
20966 xassert (updated_window
&& updated_row
);
20968 w
= updated_window
;
20969 f
= XFRAME (WINDOW_FRAME (w
));
20971 /* Get the height of the line we are in. */
20973 line_height
= row
->height
;
20975 /* Get the width of the glyphs to insert. */
20976 shift_by_width
= 0;
20977 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
20978 shift_by_width
+= glyph
->pixel_width
;
20980 /* Get the width of the region to shift right. */
20981 shifted_region_width
= (window_box_width (w
, updated_area
)
20986 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
20987 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
20989 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
20990 line_height
, shift_by_width
);
20992 /* Write the glyphs. */
20993 hpos
= start
- row
->glyphs
[updated_area
];
20994 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
20996 DRAW_NORMAL_TEXT
, 0);
20998 /* Advance the output cursor. */
20999 output_cursor
.hpos
+= len
;
21000 output_cursor
.x
+= shift_by_width
;
21006 Erase the current text line from the nominal cursor position
21007 (inclusive) to pixel column TO_X (exclusive). The idea is that
21008 everything from TO_X onward is already erased.
21010 TO_X is a pixel position relative to updated_area of
21011 updated_window. TO_X == -1 means clear to the end of this area. */
21014 x_clear_end_of_line (to_x
)
21018 struct window
*w
= updated_window
;
21019 int max_x
, min_y
, max_y
;
21020 int from_x
, from_y
, to_y
;
21022 xassert (updated_window
&& updated_row
);
21023 f
= XFRAME (w
->frame
);
21025 if (updated_row
->full_width_p
)
21026 max_x
= WINDOW_TOTAL_WIDTH (w
);
21028 max_x
= window_box_width (w
, updated_area
);
21029 max_y
= window_text_bottom_y (w
);
21031 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
21032 of window. For TO_X > 0, truncate to end of drawing area. */
21038 to_x
= min (to_x
, max_x
);
21040 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
21042 /* Notice if the cursor will be cleared by this operation. */
21043 if (!updated_row
->full_width_p
)
21044 notice_overwritten_cursor (w
, updated_area
,
21045 output_cursor
.x
, -1,
21047 MATRIX_ROW_BOTTOM_Y (updated_row
));
21049 from_x
= output_cursor
.x
;
21051 /* Translate to frame coordinates. */
21052 if (updated_row
->full_width_p
)
21054 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
21055 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
21059 int area_left
= window_box_left (w
, updated_area
);
21060 from_x
+= area_left
;
21064 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
21065 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
21066 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
21068 /* Prevent inadvertently clearing to end of the X window. */
21069 if (to_x
> from_x
&& to_y
> from_y
)
21072 rif
->clear_frame_area (f
, from_x
, from_y
,
21073 to_x
- from_x
, to_y
- from_y
);
21078 #endif /* HAVE_WINDOW_SYSTEM */
21082 /***********************************************************************
21084 ***********************************************************************/
21086 /* Value is the internal representation of the specified cursor type
21087 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
21088 of the bar cursor. */
21090 static enum text_cursor_kinds
21091 get_specified_cursor_type (arg
, width
)
21095 enum text_cursor_kinds type
;
21100 if (EQ (arg
, Qbox
))
21101 return FILLED_BOX_CURSOR
;
21103 if (EQ (arg
, Qhollow
))
21104 return HOLLOW_BOX_CURSOR
;
21106 if (EQ (arg
, Qbar
))
21113 && EQ (XCAR (arg
), Qbar
)
21114 && INTEGERP (XCDR (arg
))
21115 && XINT (XCDR (arg
)) >= 0)
21117 *width
= XINT (XCDR (arg
));
21121 if (EQ (arg
, Qhbar
))
21124 return HBAR_CURSOR
;
21128 && EQ (XCAR (arg
), Qhbar
)
21129 && INTEGERP (XCDR (arg
))
21130 && XINT (XCDR (arg
)) >= 0)
21132 *width
= XINT (XCDR (arg
));
21133 return HBAR_CURSOR
;
21136 /* Treat anything unknown as "hollow box cursor".
21137 It was bad to signal an error; people have trouble fixing
21138 .Xdefaults with Emacs, when it has something bad in it. */
21139 type
= HOLLOW_BOX_CURSOR
;
21144 /* Set the default cursor types for specified frame. */
21146 set_frame_cursor_types (f
, arg
)
21153 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
21154 FRAME_CURSOR_WIDTH (f
) = width
;
21156 /* By default, set up the blink-off state depending on the on-state. */
21158 tem
= Fassoc (arg
, Vblink_cursor_alist
);
21161 FRAME_BLINK_OFF_CURSOR (f
)
21162 = get_specified_cursor_type (XCDR (tem
), &width
);
21163 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
21166 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
21170 /* Return the cursor we want to be displayed in window W. Return
21171 width of bar/hbar cursor through WIDTH arg. Return with
21172 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
21173 (i.e. if the `system caret' should track this cursor).
21175 In a mini-buffer window, we want the cursor only to appear if we
21176 are reading input from this window. For the selected window, we
21177 want the cursor type given by the frame parameter or buffer local
21178 setting of cursor-type. If explicitly marked off, draw no cursor.
21179 In all other cases, we want a hollow box cursor. */
21181 static enum text_cursor_kinds
21182 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
21184 struct glyph
*glyph
;
21186 int *active_cursor
;
21188 struct frame
*f
= XFRAME (w
->frame
);
21189 struct buffer
*b
= XBUFFER (w
->buffer
);
21190 int cursor_type
= DEFAULT_CURSOR
;
21191 Lisp_Object alt_cursor
;
21192 int non_selected
= 0;
21194 *active_cursor
= 1;
21197 if (cursor_in_echo_area
21198 && FRAME_HAS_MINIBUF_P (f
)
21199 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
21201 if (w
== XWINDOW (echo_area_window
))
21203 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
21205 *width
= FRAME_CURSOR_WIDTH (f
);
21206 return FRAME_DESIRED_CURSOR (f
);
21209 return get_specified_cursor_type (b
->cursor_type
, width
);
21212 *active_cursor
= 0;
21216 /* Nonselected window or nonselected frame. */
21217 else if (w
!= XWINDOW (f
->selected_window
)
21218 #ifdef HAVE_WINDOW_SYSTEM
21219 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
21223 *active_cursor
= 0;
21225 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
21231 /* Never display a cursor in a window in which cursor-type is nil. */
21232 if (NILP (b
->cursor_type
))
21235 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
21238 alt_cursor
= b
->cursor_in_non_selected_windows
;
21239 return get_specified_cursor_type (alt_cursor
, width
);
21242 /* Get the normal cursor type for this window. */
21243 if (EQ (b
->cursor_type
, Qt
))
21245 cursor_type
= FRAME_DESIRED_CURSOR (f
);
21246 *width
= FRAME_CURSOR_WIDTH (f
);
21249 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
21251 /* Use normal cursor if not blinked off. */
21252 if (!w
->cursor_off_p
)
21254 #ifdef HAVE_WINDOW_SYSTEM
21255 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21257 if (cursor_type
== FILLED_BOX_CURSOR
)
21259 /* Using a block cursor on large images can be very annoying.
21260 So use a hollow cursor for "large" images.
21261 If image is not transparent (no mask), also use hollow cursor. */
21262 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21263 if (img
!= NULL
&& IMAGEP (img
->spec
))
21265 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
21266 where N = size of default frame font size.
21267 This should cover most of the "tiny" icons people may use. */
21269 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
21270 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
21271 cursor_type
= HOLLOW_BOX_CURSOR
;
21274 else if (cursor_type
!= NO_CURSOR
)
21276 /* Display current only supports BOX and HOLLOW cursors for images.
21277 So for now, unconditionally use a HOLLOW cursor when cursor is
21278 not a solid box cursor. */
21279 cursor_type
= HOLLOW_BOX_CURSOR
;
21283 return cursor_type
;
21286 /* Cursor is blinked off, so determine how to "toggle" it. */
21288 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
21289 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
21290 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
21292 /* Then see if frame has specified a specific blink off cursor type. */
21293 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
21295 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
21296 return FRAME_BLINK_OFF_CURSOR (f
);
21300 /* Some people liked having a permanently visible blinking cursor,
21301 while others had very strong opinions against it. So it was
21302 decided to remove it. KFS 2003-09-03 */
21304 /* Finally perform built-in cursor blinking:
21305 filled box <-> hollow box
21306 wide [h]bar <-> narrow [h]bar
21307 narrow [h]bar <-> no cursor
21308 other type <-> no cursor */
21310 if (cursor_type
== FILLED_BOX_CURSOR
)
21311 return HOLLOW_BOX_CURSOR
;
21313 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
21316 return cursor_type
;
21324 #ifdef HAVE_WINDOW_SYSTEM
21326 /* Notice when the text cursor of window W has been completely
21327 overwritten by a drawing operation that outputs glyphs in AREA
21328 starting at X0 and ending at X1 in the line starting at Y0 and
21329 ending at Y1. X coordinates are area-relative. X1 < 0 means all
21330 the rest of the line after X0 has been written. Y coordinates
21331 are window-relative. */
21334 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
21336 enum glyph_row_area area
;
21337 int x0
, y0
, x1
, y1
;
21339 int cx0
, cx1
, cy0
, cy1
;
21340 struct glyph_row
*row
;
21342 if (!w
->phys_cursor_on_p
)
21344 if (area
!= TEXT_AREA
)
21347 if (w
->phys_cursor
.vpos
< 0
21348 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
21349 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
21350 !(row
->enabled_p
&& row
->displays_text_p
)))
21353 if (row
->cursor_in_fringe_p
)
21355 row
->cursor_in_fringe_p
= 0;
21356 draw_fringe_bitmap (w
, row
, 0);
21357 w
->phys_cursor_on_p
= 0;
21361 cx0
= w
->phys_cursor
.x
;
21362 cx1
= cx0
+ w
->phys_cursor_width
;
21363 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
21366 /* The cursor image will be completely removed from the
21367 screen if the output area intersects the cursor area in
21368 y-direction. When we draw in [y0 y1[, and some part of
21369 the cursor is at y < y0, that part must have been drawn
21370 before. When scrolling, the cursor is erased before
21371 actually scrolling, so we don't come here. When not
21372 scrolling, the rows above the old cursor row must have
21373 changed, and in this case these rows must have written
21374 over the cursor image.
21376 Likewise if part of the cursor is below y1, with the
21377 exception of the cursor being in the first blank row at
21378 the buffer and window end because update_text_area
21379 doesn't draw that row. (Except when it does, but
21380 that's handled in update_text_area.) */
21382 cy0
= w
->phys_cursor
.y
;
21383 cy1
= cy0
+ w
->phys_cursor_height
;
21384 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
21387 w
->phys_cursor_on_p
= 0;
21390 #endif /* HAVE_WINDOW_SYSTEM */
21393 /************************************************************************
21395 ************************************************************************/
21397 #ifdef HAVE_WINDOW_SYSTEM
21400 Fix the display of area AREA of overlapping row ROW in window W
21401 with respect to the overlapping part OVERLAPS. */
21404 x_fix_overlapping_area (w
, row
, area
, overlaps
)
21406 struct glyph_row
*row
;
21407 enum glyph_row_area area
;
21415 for (i
= 0; i
< row
->used
[area
];)
21417 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
21419 int start
= i
, start_x
= x
;
21423 x
+= row
->glyphs
[area
][i
].pixel_width
;
21426 while (i
< row
->used
[area
]
21427 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
21429 draw_glyphs (w
, start_x
, row
, area
,
21431 DRAW_NORMAL_TEXT
, overlaps
);
21435 x
+= row
->glyphs
[area
][i
].pixel_width
;
21445 Draw the cursor glyph of window W in glyph row ROW. See the
21446 comment of draw_glyphs for the meaning of HL. */
21449 draw_phys_cursor_glyph (w
, row
, hl
)
21451 struct glyph_row
*row
;
21452 enum draw_glyphs_face hl
;
21454 /* If cursor hpos is out of bounds, don't draw garbage. This can
21455 happen in mini-buffer windows when switching between echo area
21456 glyphs and mini-buffer. */
21457 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
21459 int on_p
= w
->phys_cursor_on_p
;
21461 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
21462 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
21464 w
->phys_cursor_on_p
= on_p
;
21466 if (hl
== DRAW_CURSOR
)
21467 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21468 /* When we erase the cursor, and ROW is overlapped by other
21469 rows, make sure that these overlapping parts of other rows
21471 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
21473 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21475 if (row
> w
->current_matrix
->rows
21476 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
21477 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
21478 OVERLAPS_ERASED_CURSOR
);
21480 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
21481 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
21482 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
21483 OVERLAPS_ERASED_CURSOR
);
21490 Erase the image of a cursor of window W from the screen. */
21493 erase_phys_cursor (w
)
21496 struct frame
*f
= XFRAME (w
->frame
);
21497 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21498 int hpos
= w
->phys_cursor
.hpos
;
21499 int vpos
= w
->phys_cursor
.vpos
;
21500 int mouse_face_here_p
= 0;
21501 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
21502 struct glyph_row
*cursor_row
;
21503 struct glyph
*cursor_glyph
;
21504 enum draw_glyphs_face hl
;
21506 /* No cursor displayed or row invalidated => nothing to do on the
21508 if (w
->phys_cursor_type
== NO_CURSOR
)
21509 goto mark_cursor_off
;
21511 /* VPOS >= active_glyphs->nrows means that window has been resized.
21512 Don't bother to erase the cursor. */
21513 if (vpos
>= active_glyphs
->nrows
)
21514 goto mark_cursor_off
;
21516 /* If row containing cursor is marked invalid, there is nothing we
21518 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
21519 if (!cursor_row
->enabled_p
)
21520 goto mark_cursor_off
;
21522 /* If line spacing is > 0, old cursor may only be partially visible in
21523 window after split-window. So adjust visible height. */
21524 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
21525 window_text_bottom_y (w
) - cursor_row
->y
);
21527 /* If row is completely invisible, don't attempt to delete a cursor which
21528 isn't there. This can happen if cursor is at top of a window, and
21529 we switch to a buffer with a header line in that window. */
21530 if (cursor_row
->visible_height
<= 0)
21531 goto mark_cursor_off
;
21533 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
21534 if (cursor_row
->cursor_in_fringe_p
)
21536 cursor_row
->cursor_in_fringe_p
= 0;
21537 draw_fringe_bitmap (w
, cursor_row
, 0);
21538 goto mark_cursor_off
;
21541 /* This can happen when the new row is shorter than the old one.
21542 In this case, either draw_glyphs or clear_end_of_line
21543 should have cleared the cursor. Note that we wouldn't be
21544 able to erase the cursor in this case because we don't have a
21545 cursor glyph at hand. */
21546 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
21547 goto mark_cursor_off
;
21549 /* If the cursor is in the mouse face area, redisplay that when
21550 we clear the cursor. */
21551 if (! NILP (dpyinfo
->mouse_face_window
)
21552 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
21553 && (vpos
> dpyinfo
->mouse_face_beg_row
21554 || (vpos
== dpyinfo
->mouse_face_beg_row
21555 && hpos
>= dpyinfo
->mouse_face_beg_col
))
21556 && (vpos
< dpyinfo
->mouse_face_end_row
21557 || (vpos
== dpyinfo
->mouse_face_end_row
21558 && hpos
< dpyinfo
->mouse_face_end_col
))
21559 /* Don't redraw the cursor's spot in mouse face if it is at the
21560 end of a line (on a newline). The cursor appears there, but
21561 mouse highlighting does not. */
21562 && cursor_row
->used
[TEXT_AREA
] > hpos
)
21563 mouse_face_here_p
= 1;
21565 /* Maybe clear the display under the cursor. */
21566 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
21569 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
21572 cursor_glyph
= get_phys_cursor_glyph (w
);
21573 if (cursor_glyph
== NULL
)
21574 goto mark_cursor_off
;
21576 width
= cursor_glyph
->pixel_width
;
21577 left_x
= window_box_left_offset (w
, TEXT_AREA
);
21578 x
= w
->phys_cursor
.x
;
21580 width
-= left_x
- x
;
21581 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
21582 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
21583 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
21586 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
21589 /* Erase the cursor by redrawing the character underneath it. */
21590 if (mouse_face_here_p
)
21591 hl
= DRAW_MOUSE_FACE
;
21593 hl
= DRAW_NORMAL_TEXT
;
21594 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
21597 w
->phys_cursor_on_p
= 0;
21598 w
->phys_cursor_type
= NO_CURSOR
;
21603 Display or clear cursor of window W. If ON is zero, clear the
21604 cursor. If it is non-zero, display the cursor. If ON is nonzero,
21605 where to put the cursor is specified by HPOS, VPOS, X and Y. */
21608 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
21610 int on
, hpos
, vpos
, x
, y
;
21612 struct frame
*f
= XFRAME (w
->frame
);
21613 int new_cursor_type
;
21614 int new_cursor_width
;
21616 struct glyph_row
*glyph_row
;
21617 struct glyph
*glyph
;
21619 /* This is pointless on invisible frames, and dangerous on garbaged
21620 windows and frames; in the latter case, the frame or window may
21621 be in the midst of changing its size, and x and y may be off the
21623 if (! FRAME_VISIBLE_P (f
)
21624 || FRAME_GARBAGED_P (f
)
21625 || vpos
>= w
->current_matrix
->nrows
21626 || hpos
>= w
->current_matrix
->matrix_w
)
21629 /* If cursor is off and we want it off, return quickly. */
21630 if (!on
&& !w
->phys_cursor_on_p
)
21633 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
21634 /* If cursor row is not enabled, we don't really know where to
21635 display the cursor. */
21636 if (!glyph_row
->enabled_p
)
21638 w
->phys_cursor_on_p
= 0;
21643 if (!glyph_row
->exact_window_width_line_p
21644 || hpos
< glyph_row
->used
[TEXT_AREA
])
21645 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
21647 xassert (interrupt_input_blocked
);
21649 /* Set new_cursor_type to the cursor we want to be displayed. */
21650 new_cursor_type
= get_window_cursor_type (w
, glyph
,
21651 &new_cursor_width
, &active_cursor
);
21653 /* If cursor is currently being shown and we don't want it to be or
21654 it is in the wrong place, or the cursor type is not what we want,
21656 if (w
->phys_cursor_on_p
21658 || w
->phys_cursor
.x
!= x
21659 || w
->phys_cursor
.y
!= y
21660 || new_cursor_type
!= w
->phys_cursor_type
21661 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
21662 && new_cursor_width
!= w
->phys_cursor_width
)))
21663 erase_phys_cursor (w
);
21665 /* Don't check phys_cursor_on_p here because that flag is only set
21666 to zero in some cases where we know that the cursor has been
21667 completely erased, to avoid the extra work of erasing the cursor
21668 twice. In other words, phys_cursor_on_p can be 1 and the cursor
21669 still not be visible, or it has only been partly erased. */
21672 w
->phys_cursor_ascent
= glyph_row
->ascent
;
21673 w
->phys_cursor_height
= glyph_row
->height
;
21675 /* Set phys_cursor_.* before x_draw_.* is called because some
21676 of them may need the information. */
21677 w
->phys_cursor
.x
= x
;
21678 w
->phys_cursor
.y
= glyph_row
->y
;
21679 w
->phys_cursor
.hpos
= hpos
;
21680 w
->phys_cursor
.vpos
= vpos
;
21683 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
21684 new_cursor_type
, new_cursor_width
,
21685 on
, active_cursor
);
21689 /* Switch the display of W's cursor on or off, according to the value
21693 update_window_cursor (w
, on
)
21697 /* Don't update cursor in windows whose frame is in the process
21698 of being deleted. */
21699 if (w
->current_matrix
)
21702 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21703 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21709 /* Call update_window_cursor with parameter ON_P on all leaf windows
21710 in the window tree rooted at W. */
21713 update_cursor_in_window_tree (w
, on_p
)
21719 if (!NILP (w
->hchild
))
21720 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
21721 else if (!NILP (w
->vchild
))
21722 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
21724 update_window_cursor (w
, on_p
);
21726 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
21732 Display the cursor on window W, or clear it, according to ON_P.
21733 Don't change the cursor's position. */
21736 x_update_cursor (f
, on_p
)
21740 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
21745 Clear the cursor of window W to background color, and mark the
21746 cursor as not shown. This is used when the text where the cursor
21747 is is about to be rewritten. */
21753 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
21754 update_window_cursor (w
, 0);
21759 Display the active region described by mouse_face_* according to DRAW. */
21762 show_mouse_face (dpyinfo
, draw
)
21763 Display_Info
*dpyinfo
;
21764 enum draw_glyphs_face draw
;
21766 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
21767 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21769 if (/* If window is in the process of being destroyed, don't bother
21771 w
->current_matrix
!= NULL
21772 /* Don't update mouse highlight if hidden */
21773 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
21774 /* Recognize when we are called to operate on rows that don't exist
21775 anymore. This can happen when a window is split. */
21776 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
21778 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
21779 struct glyph_row
*row
, *first
, *last
;
21781 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
21782 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
21784 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
21786 int start_hpos
, end_hpos
, start_x
;
21788 /* For all but the first row, the highlight starts at column 0. */
21791 start_hpos
= dpyinfo
->mouse_face_beg_col
;
21792 start_x
= dpyinfo
->mouse_face_beg_x
;
21801 end_hpos
= dpyinfo
->mouse_face_end_col
;
21804 end_hpos
= row
->used
[TEXT_AREA
];
21805 if (draw
== DRAW_NORMAL_TEXT
)
21806 row
->fill_line_p
= 1; /* Clear to end of line */
21809 if (end_hpos
> start_hpos
)
21811 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
21812 start_hpos
, end_hpos
,
21816 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
21820 /* When we've written over the cursor, arrange for it to
21821 be displayed again. */
21822 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
21825 display_and_set_cursor (w
, 1,
21826 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21827 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21832 /* Change the mouse cursor. */
21833 if (draw
== DRAW_NORMAL_TEXT
)
21834 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
21835 else if (draw
== DRAW_MOUSE_FACE
)
21836 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
21838 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
21842 Clear out the mouse-highlighted active region.
21843 Redraw it un-highlighted first. Value is non-zero if mouse
21844 face was actually drawn unhighlighted. */
21847 clear_mouse_face (dpyinfo
)
21848 Display_Info
*dpyinfo
;
21852 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
21854 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
21858 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21859 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21860 dpyinfo
->mouse_face_window
= Qnil
;
21861 dpyinfo
->mouse_face_overlay
= Qnil
;
21867 Non-zero if physical cursor of window W is within mouse face. */
21870 cursor_in_mouse_face_p (w
)
21873 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21874 int in_mouse_face
= 0;
21876 if (WINDOWP (dpyinfo
->mouse_face_window
)
21877 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
21879 int hpos
= w
->phys_cursor
.hpos
;
21880 int vpos
= w
->phys_cursor
.vpos
;
21882 if (vpos
>= dpyinfo
->mouse_face_beg_row
21883 && vpos
<= dpyinfo
->mouse_face_end_row
21884 && (vpos
> dpyinfo
->mouse_face_beg_row
21885 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21886 && (vpos
< dpyinfo
->mouse_face_end_row
21887 || hpos
< dpyinfo
->mouse_face_end_col
21888 || dpyinfo
->mouse_face_past_end
))
21892 return in_mouse_face
;
21898 /* Find the glyph matrix position of buffer position CHARPOS in window
21899 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
21900 current glyphs must be up to date. If CHARPOS is above window
21901 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
21902 of last line in W. In the row containing CHARPOS, stop before glyphs
21903 having STOP as object. */
21905 #if 1 /* This is a version of fast_find_position that's more correct
21906 in the presence of hscrolling, for example. I didn't install
21907 it right away because the problem fixed is minor, it failed
21908 in 20.x as well, and I think it's too risky to install
21909 so near the release of 21.1. 2001-09-25 gerd. */
21912 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
21915 int *hpos
, *vpos
, *x
, *y
;
21918 struct glyph_row
*row
, *first
;
21919 struct glyph
*glyph
, *end
;
21922 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21923 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
21928 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
21932 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
21935 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
21939 /* If whole rows or last part of a row came from a display overlay,
21940 row_containing_pos will skip over such rows because their end pos
21941 equals the start pos of the overlay or interval.
21943 Move back if we have a STOP object and previous row's
21944 end glyph came from STOP. */
21947 struct glyph_row
*prev
;
21948 while ((prev
= row
- 1, prev
>= first
)
21949 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
21950 && prev
->used
[TEXT_AREA
] > 0)
21952 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
21953 glyph
= beg
+ prev
->used
[TEXT_AREA
];
21954 while (--glyph
>= beg
21955 && INTEGERP (glyph
->object
));
21957 || !EQ (stop
, glyph
->object
))
21965 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21967 glyph
= row
->glyphs
[TEXT_AREA
];
21968 end
= glyph
+ row
->used
[TEXT_AREA
];
21970 /* Skip over glyphs not having an object at the start of the row.
21971 These are special glyphs like truncation marks on terminal
21973 if (row
->displays_text_p
)
21975 && INTEGERP (glyph
->object
)
21976 && !EQ (stop
, glyph
->object
)
21977 && glyph
->charpos
< 0)
21979 *x
+= glyph
->pixel_width
;
21984 && !INTEGERP (glyph
->object
)
21985 && !EQ (stop
, glyph
->object
)
21986 && (!BUFFERP (glyph
->object
)
21987 || glyph
->charpos
< charpos
))
21989 *x
+= glyph
->pixel_width
;
21993 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
22000 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
22003 int *hpos
, *vpos
, *x
, *y
;
22008 int maybe_next_line_p
= 0;
22009 int line_start_position
;
22010 int yb
= window_text_bottom_y (w
);
22011 struct glyph_row
*row
, *best_row
;
22012 int row_vpos
, best_row_vpos
;
22015 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22016 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22018 while (row
->y
< yb
)
22020 if (row
->used
[TEXT_AREA
])
22021 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
22023 line_start_position
= 0;
22025 if (line_start_position
> pos
)
22027 /* If the position sought is the end of the buffer,
22028 don't include the blank lines at the bottom of the window. */
22029 else if (line_start_position
== pos
22030 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
22032 maybe_next_line_p
= 1;
22035 else if (line_start_position
> 0)
22038 best_row_vpos
= row_vpos
;
22041 if (row
->y
+ row
->height
>= yb
)
22048 /* Find the right column within BEST_ROW. */
22050 current_x
= best_row
->x
;
22051 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
22053 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
22054 int charpos
= glyph
->charpos
;
22056 if (BUFFERP (glyph
->object
))
22058 if (charpos
== pos
)
22061 *vpos
= best_row_vpos
;
22066 else if (charpos
> pos
)
22069 else if (EQ (glyph
->object
, stop
))
22074 current_x
+= glyph
->pixel_width
;
22077 /* If we're looking for the end of the buffer,
22078 and we didn't find it in the line we scanned,
22079 use the start of the following line. */
22080 if (maybe_next_line_p
)
22085 current_x
= best_row
->x
;
22088 *vpos
= best_row_vpos
;
22089 *hpos
= lastcol
+ 1;
22098 /* Find the position of the glyph for position POS in OBJECT in
22099 window W's current matrix, and return in *X, *Y the pixel
22100 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
22102 RIGHT_P non-zero means return the position of the right edge of the
22103 glyph, RIGHT_P zero means return the left edge position.
22105 If no glyph for POS exists in the matrix, return the position of
22106 the glyph with the next smaller position that is in the matrix, if
22107 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
22108 exists in the matrix, return the position of the glyph with the
22109 next larger position in OBJECT.
22111 Value is non-zero if a glyph was found. */
22114 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
22117 Lisp_Object object
;
22118 int *hpos
, *vpos
, *x
, *y
;
22121 int yb
= window_text_bottom_y (w
);
22122 struct glyph_row
*r
;
22123 struct glyph
*best_glyph
= NULL
;
22124 struct glyph_row
*best_row
= NULL
;
22127 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22128 r
->enabled_p
&& r
->y
< yb
;
22131 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
22132 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
22135 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
22136 if (EQ (g
->object
, object
))
22138 if (g
->charpos
== pos
)
22145 else if (best_glyph
== NULL
22146 || ((abs (g
->charpos
- pos
)
22147 < abs (best_glyph
->charpos
- pos
))
22150 : g
->charpos
> pos
)))
22164 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
22168 *x
+= best_glyph
->pixel_width
;
22173 *vpos
= best_row
- w
->current_matrix
->rows
;
22176 return best_glyph
!= NULL
;
22180 /* See if position X, Y is within a hot-spot of an image. */
22183 on_hot_spot_p (hot_spot
, x
, y
)
22184 Lisp_Object hot_spot
;
22187 if (!CONSP (hot_spot
))
22190 if (EQ (XCAR (hot_spot
), Qrect
))
22192 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
22193 Lisp_Object rect
= XCDR (hot_spot
);
22197 if (!CONSP (XCAR (rect
)))
22199 if (!CONSP (XCDR (rect
)))
22201 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
22203 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
22205 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
22207 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
22211 else if (EQ (XCAR (hot_spot
), Qcircle
))
22213 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
22214 Lisp_Object circ
= XCDR (hot_spot
);
22215 Lisp_Object lr
, lx0
, ly0
;
22217 && CONSP (XCAR (circ
))
22218 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
22219 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
22220 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
22222 double r
= XFLOATINT (lr
);
22223 double dx
= XINT (lx0
) - x
;
22224 double dy
= XINT (ly0
) - y
;
22225 return (dx
* dx
+ dy
* dy
<= r
* r
);
22228 else if (EQ (XCAR (hot_spot
), Qpoly
))
22230 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
22231 if (VECTORP (XCDR (hot_spot
)))
22233 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
22234 Lisp_Object
*poly
= v
->contents
;
22238 Lisp_Object lx
, ly
;
22241 /* Need an even number of coordinates, and at least 3 edges. */
22242 if (n
< 6 || n
& 1)
22245 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
22246 If count is odd, we are inside polygon. Pixels on edges
22247 may or may not be included depending on actual geometry of the
22249 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
22250 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
22252 x0
= XINT (lx
), y0
= XINT (ly
);
22253 for (i
= 0; i
< n
; i
+= 2)
22255 int x1
= x0
, y1
= y0
;
22256 if ((lx
= poly
[i
], !INTEGERP (lx
))
22257 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
22259 x0
= XINT (lx
), y0
= XINT (ly
);
22261 /* Does this segment cross the X line? */
22269 if (y
> y0
&& y
> y1
)
22271 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
22277 /* If we don't understand the format, pretend we're not in the hot-spot. */
22282 find_hot_spot (map
, x
, y
)
22286 while (CONSP (map
))
22288 if (CONSP (XCAR (map
))
22289 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
22297 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
22299 doc
: /* Lookup in image map MAP coordinates X and Y.
22300 An image map is an alist where each element has the format (AREA ID PLIST).
22301 An AREA is specified as either a rectangle, a circle, or a polygon:
22302 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
22303 pixel coordinates of the upper left and bottom right corners.
22304 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
22305 and the radius of the circle; r may be a float or integer.
22306 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
22307 vector describes one corner in the polygon.
22308 Returns the alist element for the first matching AREA in MAP. */)
22319 return find_hot_spot (map
, XINT (x
), XINT (y
));
22323 /* Display frame CURSOR, optionally using shape defined by POINTER. */
22325 define_frame_cursor1 (f
, cursor
, pointer
)
22328 Lisp_Object pointer
;
22330 /* Do not change cursor shape while dragging mouse. */
22331 if (!NILP (do_mouse_tracking
))
22334 if (!NILP (pointer
))
22336 if (EQ (pointer
, Qarrow
))
22337 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22338 else if (EQ (pointer
, Qhand
))
22339 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
22340 else if (EQ (pointer
, Qtext
))
22341 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22342 else if (EQ (pointer
, intern ("hdrag")))
22343 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22344 #ifdef HAVE_X_WINDOWS
22345 else if (EQ (pointer
, intern ("vdrag")))
22346 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
22348 else if (EQ (pointer
, intern ("hourglass")))
22349 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
22350 else if (EQ (pointer
, Qmodeline
))
22351 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
22353 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22356 if (cursor
!= No_Cursor
)
22357 rif
->define_frame_cursor (f
, cursor
);
22360 /* Take proper action when mouse has moved to the mode or header line
22361 or marginal area AREA of window W, x-position X and y-position Y.
22362 X is relative to the start of the text display area of W, so the
22363 width of bitmap areas and scroll bars must be subtracted to get a
22364 position relative to the start of the mode line. */
22367 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
22368 Lisp_Object window
;
22370 enum window_part area
;
22372 struct window
*w
= XWINDOW (window
);
22373 struct frame
*f
= XFRAME (w
->frame
);
22374 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22375 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22376 Lisp_Object pointer
= Qnil
;
22377 int charpos
, dx
, dy
, width
, height
;
22378 Lisp_Object string
, object
= Qnil
;
22379 Lisp_Object pos
, help
;
22381 Lisp_Object mouse_face
;
22382 int original_x_pixel
= x
;
22383 struct glyph
* glyph
= NULL
;
22384 struct glyph_row
*row
;
22386 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
22391 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
22392 &object
, &dx
, &dy
, &width
, &height
);
22394 row
= (area
== ON_MODE_LINE
22395 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
22396 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
22399 if (row
->mode_line_p
&& row
->enabled_p
)
22401 glyph
= row
->glyphs
[TEXT_AREA
];
22402 end
= glyph
+ row
->used
[TEXT_AREA
];
22404 for (x0
= original_x_pixel
;
22405 glyph
< end
&& x0
>= glyph
->pixel_width
;
22407 x0
-= glyph
->pixel_width
;
22415 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
22416 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
22417 &object
, &dx
, &dy
, &width
, &height
);
22422 if (IMAGEP (object
))
22424 Lisp_Object image_map
, hotspot
;
22425 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
22427 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
22429 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22431 Lisp_Object area_id
, plist
;
22433 area_id
= XCAR (hotspot
);
22434 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22435 If so, we could look for mouse-enter, mouse-leave
22436 properties in PLIST (and do something...). */
22437 hotspot
= XCDR (hotspot
);
22438 if (CONSP (hotspot
)
22439 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22441 pointer
= Fplist_get (plist
, Qpointer
);
22442 if (NILP (pointer
))
22444 help
= Fplist_get (plist
, Qhelp_echo
);
22447 help_echo_string
= help
;
22448 /* Is this correct? ++kfs */
22449 XSETWINDOW (help_echo_window
, w
);
22450 help_echo_object
= w
->buffer
;
22451 help_echo_pos
= charpos
;
22455 if (NILP (pointer
))
22456 pointer
= Fplist_get (XCDR (object
), QCpointer
);
22459 if (STRINGP (string
))
22461 pos
= make_number (charpos
);
22462 /* If we're on a string with `help-echo' text property, arrange
22463 for the help to be displayed. This is done by setting the
22464 global variable help_echo_string to the help string. */
22467 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
22470 help_echo_string
= help
;
22471 XSETWINDOW (help_echo_window
, w
);
22472 help_echo_object
= string
;
22473 help_echo_pos
= charpos
;
22477 if (NILP (pointer
))
22478 pointer
= Fget_text_property (pos
, Qpointer
, string
);
22480 /* Change the mouse pointer according to what is under X/Y. */
22481 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
22484 map
= Fget_text_property (pos
, Qlocal_map
, string
);
22485 if (!KEYMAPP (map
))
22486 map
= Fget_text_property (pos
, Qkeymap
, string
);
22487 if (!KEYMAPP (map
))
22488 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
22491 /* Change the mouse face according to what is under X/Y. */
22492 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
22493 if (!NILP (mouse_face
)
22494 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22499 struct glyph
* tmp_glyph
;
22503 int total_pixel_width
;
22508 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
22509 Qmouse_face
, string
, Qnil
);
22511 b
= make_number (0);
22513 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
22515 e
= make_number (SCHARS (string
));
22517 /* Calculate the position(glyph position: GPOS) of GLYPH in
22518 displayed string. GPOS is different from CHARPOS.
22520 CHARPOS is the position of glyph in internal string
22521 object. A mode line string format has structures which
22522 is converted to a flatten by emacs lisp interpreter.
22523 The internal string is an element of the structures.
22524 The displayed string is the flatten string. */
22525 for (tmp_glyph
= glyph
- 1, gpos
= 0;
22526 tmp_glyph
->charpos
>= XINT (b
);
22527 tmp_glyph
--, gpos
++)
22529 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22533 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
22534 displayed string holding GLYPH.
22536 GSEQ_LENGTH is different from SCHARS (STRING).
22537 SCHARS (STRING) returns the length of the internal string. */
22538 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
22539 tmp_glyph
->charpos
< XINT (e
);
22540 tmp_glyph
++, gseq_length
++)
22542 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22546 total_pixel_width
= 0;
22547 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
22548 total_pixel_width
+= tmp_glyph
->pixel_width
;
22550 /* Pre calculation of re-rendering position */
22552 hpos
= (area
== ON_MODE_LINE
22553 ? (w
->current_matrix
)->nrows
- 1
22556 /* If the re-rendering position is included in the last
22557 re-rendering area, we should do nothing. */
22558 if ( EQ (window
, dpyinfo
->mouse_face_window
)
22559 && dpyinfo
->mouse_face_beg_col
<= vpos
22560 && vpos
< dpyinfo
->mouse_face_end_col
22561 && dpyinfo
->mouse_face_beg_row
== hpos
)
22564 if (clear_mouse_face (dpyinfo
))
22565 cursor
= No_Cursor
;
22567 dpyinfo
->mouse_face_beg_col
= vpos
;
22568 dpyinfo
->mouse_face_beg_row
= hpos
;
22570 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
22571 dpyinfo
->mouse_face_beg_y
= 0;
22573 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
22574 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
22576 dpyinfo
->mouse_face_end_x
= 0;
22577 dpyinfo
->mouse_face_end_y
= 0;
22579 dpyinfo
->mouse_face_past_end
= 0;
22580 dpyinfo
->mouse_face_window
= window
;
22582 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
22585 glyph
->face_id
, 1);
22586 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22588 if (NILP (pointer
))
22591 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22592 clear_mouse_face (dpyinfo
);
22594 define_frame_cursor1 (f
, cursor
, pointer
);
22599 Take proper action when the mouse has moved to position X, Y on
22600 frame F as regards highlighting characters that have mouse-face
22601 properties. Also de-highlighting chars where the mouse was before.
22602 X and Y can be negative or out of range. */
22605 note_mouse_highlight (f
, x
, y
)
22609 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22610 enum window_part part
;
22611 Lisp_Object window
;
22613 Cursor cursor
= No_Cursor
;
22614 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
22617 /* When a menu is active, don't highlight because this looks odd. */
22618 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
22619 if (popup_activated ())
22623 if (NILP (Vmouse_highlight
)
22624 || !f
->glyphs_initialized_p
)
22627 dpyinfo
->mouse_face_mouse_x
= x
;
22628 dpyinfo
->mouse_face_mouse_y
= y
;
22629 dpyinfo
->mouse_face_mouse_frame
= f
;
22631 if (dpyinfo
->mouse_face_defer
)
22634 if (gc_in_progress
)
22636 dpyinfo
->mouse_face_deferred_gc
= 1;
22640 /* Which window is that in? */
22641 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
22643 /* If we were displaying active text in another window, clear that.
22644 Also clear if we move out of text area in same window. */
22645 if (! EQ (window
, dpyinfo
->mouse_face_window
)
22646 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
22647 && !NILP (dpyinfo
->mouse_face_window
)))
22648 clear_mouse_face (dpyinfo
);
22650 /* Not on a window -> return. */
22651 if (!WINDOWP (window
))
22654 /* Reset help_echo_string. It will get recomputed below. */
22655 help_echo_string
= Qnil
;
22657 /* Convert to window-relative pixel coordinates. */
22658 w
= XWINDOW (window
);
22659 frame_to_window_pixel_xy (w
, &x
, &y
);
22661 /* Handle tool-bar window differently since it doesn't display a
22663 if (EQ (window
, f
->tool_bar_window
))
22665 note_tool_bar_highlight (f
, x
, y
);
22669 /* Mouse is on the mode, header line or margin? */
22670 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
22671 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
22673 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
22677 if (part
== ON_VERTICAL_BORDER
)
22679 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22680 help_echo_string
= build_string ("drag-mouse-1: resize");
22682 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
22683 || part
== ON_SCROLL_BAR
)
22684 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22686 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22688 /* Are we in a window whose display is up to date?
22689 And verify the buffer's text has not changed. */
22690 b
= XBUFFER (w
->buffer
);
22691 if (part
== ON_TEXT
22692 && EQ (w
->window_end_valid
, w
->buffer
)
22693 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
22694 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
22696 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
22697 struct glyph
*glyph
;
22698 Lisp_Object object
;
22699 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
22700 Lisp_Object
*overlay_vec
= NULL
;
22702 struct buffer
*obuf
;
22703 int obegv
, ozv
, same_region
;
22705 /* Find the glyph under X/Y. */
22706 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
22708 /* Look for :pointer property on image. */
22709 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22711 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22712 if (img
!= NULL
&& IMAGEP (img
->spec
))
22714 Lisp_Object image_map
, hotspot
;
22715 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
22717 && (hotspot
= find_hot_spot (image_map
,
22718 glyph
->slice
.x
+ dx
,
22719 glyph
->slice
.y
+ dy
),
22721 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22723 Lisp_Object area_id
, plist
;
22725 area_id
= XCAR (hotspot
);
22726 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22727 If so, we could look for mouse-enter, mouse-leave
22728 properties in PLIST (and do something...). */
22729 hotspot
= XCDR (hotspot
);
22730 if (CONSP (hotspot
)
22731 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22733 pointer
= Fplist_get (plist
, Qpointer
);
22734 if (NILP (pointer
))
22736 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
22737 if (!NILP (help_echo_string
))
22739 help_echo_window
= window
;
22740 help_echo_object
= glyph
->object
;
22741 help_echo_pos
= glyph
->charpos
;
22745 if (NILP (pointer
))
22746 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
22750 /* Clear mouse face if X/Y not over text. */
22752 || area
!= TEXT_AREA
22753 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
22755 if (clear_mouse_face (dpyinfo
))
22756 cursor
= No_Cursor
;
22757 if (NILP (pointer
))
22759 if (area
!= TEXT_AREA
)
22760 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22762 pointer
= Vvoid_text_area_pointer
;
22767 pos
= glyph
->charpos
;
22768 object
= glyph
->object
;
22769 if (!STRINGP (object
) && !BUFFERP (object
))
22772 /* If we get an out-of-range value, return now; avoid an error. */
22773 if (BUFFERP (object
) && pos
> BUF_Z (b
))
22776 /* Make the window's buffer temporarily current for
22777 overlays_at and compute_char_face. */
22778 obuf
= current_buffer
;
22779 current_buffer
= b
;
22785 /* Is this char mouse-active or does it have help-echo? */
22786 position
= make_number (pos
);
22788 if (BUFFERP (object
))
22790 /* Put all the overlays we want in a vector in overlay_vec. */
22791 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
22792 /* Sort overlays into increasing priority order. */
22793 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
22798 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
22799 && vpos
>= dpyinfo
->mouse_face_beg_row
22800 && vpos
<= dpyinfo
->mouse_face_end_row
22801 && (vpos
> dpyinfo
->mouse_face_beg_row
22802 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22803 && (vpos
< dpyinfo
->mouse_face_end_row
22804 || hpos
< dpyinfo
->mouse_face_end_col
22805 || dpyinfo
->mouse_face_past_end
));
22808 cursor
= No_Cursor
;
22810 /* Check mouse-face highlighting. */
22812 /* If there exists an overlay with mouse-face overlapping
22813 the one we are currently highlighting, we have to
22814 check if we enter the overlapping overlay, and then
22815 highlight only that. */
22816 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
22817 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
22819 /* Find the highest priority overlay that has a mouse-face
22822 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
22824 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
22825 if (!NILP (mouse_face
))
22826 overlay
= overlay_vec
[i
];
22829 /* If we're actually highlighting the same overlay as
22830 before, there's no need to do that again. */
22831 if (!NILP (overlay
)
22832 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
22833 goto check_help_echo
;
22835 dpyinfo
->mouse_face_overlay
= overlay
;
22837 /* Clear the display of the old active region, if any. */
22838 if (clear_mouse_face (dpyinfo
))
22839 cursor
= No_Cursor
;
22841 /* If no overlay applies, get a text property. */
22842 if (NILP (overlay
))
22843 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
22845 /* Handle the overlay case. */
22846 if (!NILP (overlay
))
22848 /* Find the range of text around this char that
22849 should be active. */
22850 Lisp_Object before
, after
;
22853 before
= Foverlay_start (overlay
);
22854 after
= Foverlay_end (overlay
);
22855 /* Record this as the current active region. */
22856 fast_find_position (w
, XFASTINT (before
),
22857 &dpyinfo
->mouse_face_beg_col
,
22858 &dpyinfo
->mouse_face_beg_row
,
22859 &dpyinfo
->mouse_face_beg_x
,
22860 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22862 dpyinfo
->mouse_face_past_end
22863 = !fast_find_position (w
, XFASTINT (after
),
22864 &dpyinfo
->mouse_face_end_col
,
22865 &dpyinfo
->mouse_face_end_row
,
22866 &dpyinfo
->mouse_face_end_x
,
22867 &dpyinfo
->mouse_face_end_y
, Qnil
);
22868 dpyinfo
->mouse_face_window
= window
;
22870 dpyinfo
->mouse_face_face_id
22871 = face_at_buffer_position (w
, pos
, 0, 0,
22873 !dpyinfo
->mouse_face_hidden
);
22875 /* Display it as active. */
22876 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22877 cursor
= No_Cursor
;
22879 /* Handle the text property case. */
22880 else if (!NILP (mouse_face
) && BUFFERP (object
))
22882 /* Find the range of text around this char that
22883 should be active. */
22884 Lisp_Object before
, after
, beginning
, end
;
22887 beginning
= Fmarker_position (w
->start
);
22888 end
= make_number (BUF_Z (XBUFFER (object
))
22889 - XFASTINT (w
->window_end_pos
));
22891 = Fprevious_single_property_change (make_number (pos
+ 1),
22893 object
, beginning
);
22895 = Fnext_single_property_change (position
, Qmouse_face
,
22898 /* Record this as the current active region. */
22899 fast_find_position (w
, XFASTINT (before
),
22900 &dpyinfo
->mouse_face_beg_col
,
22901 &dpyinfo
->mouse_face_beg_row
,
22902 &dpyinfo
->mouse_face_beg_x
,
22903 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22904 dpyinfo
->mouse_face_past_end
22905 = !fast_find_position (w
, XFASTINT (after
),
22906 &dpyinfo
->mouse_face_end_col
,
22907 &dpyinfo
->mouse_face_end_row
,
22908 &dpyinfo
->mouse_face_end_x
,
22909 &dpyinfo
->mouse_face_end_y
, Qnil
);
22910 dpyinfo
->mouse_face_window
= window
;
22912 if (BUFFERP (object
))
22913 dpyinfo
->mouse_face_face_id
22914 = face_at_buffer_position (w
, pos
, 0, 0,
22916 !dpyinfo
->mouse_face_hidden
);
22918 /* Display it as active. */
22919 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22920 cursor
= No_Cursor
;
22922 else if (!NILP (mouse_face
) && STRINGP (object
))
22927 b
= Fprevious_single_property_change (make_number (pos
+ 1),
22930 e
= Fnext_single_property_change (position
, Qmouse_face
,
22933 b
= make_number (0);
22935 e
= make_number (SCHARS (object
) - 1);
22937 fast_find_string_pos (w
, XINT (b
), object
,
22938 &dpyinfo
->mouse_face_beg_col
,
22939 &dpyinfo
->mouse_face_beg_row
,
22940 &dpyinfo
->mouse_face_beg_x
,
22941 &dpyinfo
->mouse_face_beg_y
, 0);
22942 fast_find_string_pos (w
, XINT (e
), object
,
22943 &dpyinfo
->mouse_face_end_col
,
22944 &dpyinfo
->mouse_face_end_row
,
22945 &dpyinfo
->mouse_face_end_x
,
22946 &dpyinfo
->mouse_face_end_y
, 1);
22947 dpyinfo
->mouse_face_past_end
= 0;
22948 dpyinfo
->mouse_face_window
= window
;
22949 dpyinfo
->mouse_face_face_id
22950 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
22951 glyph
->face_id
, 1);
22952 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22953 cursor
= No_Cursor
;
22955 else if (STRINGP (object
) && NILP (mouse_face
))
22957 /* A string which doesn't have mouse-face, but
22958 the text ``under'' it might have. */
22959 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
22960 int start
= MATRIX_ROW_START_CHARPOS (r
);
22962 pos
= string_buffer_position (w
, object
, start
);
22964 mouse_face
= get_char_property_and_overlay (make_number (pos
),
22968 if (!NILP (mouse_face
) && !NILP (overlay
))
22970 Lisp_Object before
= Foverlay_start (overlay
);
22971 Lisp_Object after
= Foverlay_end (overlay
);
22974 /* Note that we might not be able to find position
22975 BEFORE in the glyph matrix if the overlay is
22976 entirely covered by a `display' property. In
22977 this case, we overshoot. So let's stop in
22978 the glyph matrix before glyphs for OBJECT. */
22979 fast_find_position (w
, XFASTINT (before
),
22980 &dpyinfo
->mouse_face_beg_col
,
22981 &dpyinfo
->mouse_face_beg_row
,
22982 &dpyinfo
->mouse_face_beg_x
,
22983 &dpyinfo
->mouse_face_beg_y
,
22986 dpyinfo
->mouse_face_past_end
22987 = !fast_find_position (w
, XFASTINT (after
),
22988 &dpyinfo
->mouse_face_end_col
,
22989 &dpyinfo
->mouse_face_end_row
,
22990 &dpyinfo
->mouse_face_end_x
,
22991 &dpyinfo
->mouse_face_end_y
,
22993 dpyinfo
->mouse_face_window
= window
;
22994 dpyinfo
->mouse_face_face_id
22995 = face_at_buffer_position (w
, pos
, 0, 0,
22997 !dpyinfo
->mouse_face_hidden
);
22999 /* Display it as active. */
23000 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23001 cursor
= No_Cursor
;
23008 /* Look for a `help-echo' property. */
23009 if (NILP (help_echo_string
)) {
23010 Lisp_Object help
, overlay
;
23012 /* Check overlays first. */
23013 help
= overlay
= Qnil
;
23014 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
23016 overlay
= overlay_vec
[i
];
23017 help
= Foverlay_get (overlay
, Qhelp_echo
);
23022 help_echo_string
= help
;
23023 help_echo_window
= window
;
23024 help_echo_object
= overlay
;
23025 help_echo_pos
= pos
;
23029 Lisp_Object object
= glyph
->object
;
23030 int charpos
= glyph
->charpos
;
23032 /* Try text properties. */
23033 if (STRINGP (object
)
23035 && charpos
< SCHARS (object
))
23037 help
= Fget_text_property (make_number (charpos
),
23038 Qhelp_echo
, object
);
23041 /* If the string itself doesn't specify a help-echo,
23042 see if the buffer text ``under'' it does. */
23043 struct glyph_row
*r
23044 = MATRIX_ROW (w
->current_matrix
, vpos
);
23045 int start
= MATRIX_ROW_START_CHARPOS (r
);
23046 int pos
= string_buffer_position (w
, object
, start
);
23049 help
= Fget_char_property (make_number (pos
),
23050 Qhelp_echo
, w
->buffer
);
23054 object
= w
->buffer
;
23059 else if (BUFFERP (object
)
23062 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
23067 help_echo_string
= help
;
23068 help_echo_window
= window
;
23069 help_echo_object
= object
;
23070 help_echo_pos
= charpos
;
23075 /* Look for a `pointer' property. */
23076 if (NILP (pointer
))
23078 /* Check overlays first. */
23079 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
23080 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
23082 if (NILP (pointer
))
23084 Lisp_Object object
= glyph
->object
;
23085 int charpos
= glyph
->charpos
;
23087 /* Try text properties. */
23088 if (STRINGP (object
)
23090 && charpos
< SCHARS (object
))
23092 pointer
= Fget_text_property (make_number (charpos
),
23094 if (NILP (pointer
))
23096 /* If the string itself doesn't specify a pointer,
23097 see if the buffer text ``under'' it does. */
23098 struct glyph_row
*r
23099 = MATRIX_ROW (w
->current_matrix
, vpos
);
23100 int start
= MATRIX_ROW_START_CHARPOS (r
);
23101 int pos
= string_buffer_position (w
, object
, start
);
23103 pointer
= Fget_char_property (make_number (pos
),
23104 Qpointer
, w
->buffer
);
23107 else if (BUFFERP (object
)
23110 pointer
= Fget_text_property (make_number (charpos
),
23117 current_buffer
= obuf
;
23122 define_frame_cursor1 (f
, cursor
, pointer
);
23127 Clear any mouse-face on window W. This function is part of the
23128 redisplay interface, and is called from try_window_id and similar
23129 functions to ensure the mouse-highlight is off. */
23132 x_clear_window_mouse_face (w
)
23135 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23136 Lisp_Object window
;
23139 XSETWINDOW (window
, w
);
23140 if (EQ (window
, dpyinfo
->mouse_face_window
))
23141 clear_mouse_face (dpyinfo
);
23147 Just discard the mouse face information for frame F, if any.
23148 This is used when the size of F is changed. */
23151 cancel_mouse_face (f
)
23154 Lisp_Object window
;
23155 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23157 window
= dpyinfo
->mouse_face_window
;
23158 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
23160 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
23161 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
23162 dpyinfo
->mouse_face_window
= Qnil
;
23167 #endif /* HAVE_WINDOW_SYSTEM */
23170 /***********************************************************************
23172 ***********************************************************************/
23174 #ifdef HAVE_WINDOW_SYSTEM
23176 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
23177 which intersects rectangle R. R is in window-relative coordinates. */
23180 expose_area (w
, row
, r
, area
)
23182 struct glyph_row
*row
;
23184 enum glyph_row_area area
;
23186 struct glyph
*first
= row
->glyphs
[area
];
23187 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
23188 struct glyph
*last
;
23189 int first_x
, start_x
, x
;
23191 if (area
== TEXT_AREA
&& row
->fill_line_p
)
23192 /* If row extends face to end of line write the whole line. */
23193 draw_glyphs (w
, 0, row
, area
,
23194 0, row
->used
[area
],
23195 DRAW_NORMAL_TEXT
, 0);
23198 /* Set START_X to the window-relative start position for drawing glyphs of
23199 AREA. The first glyph of the text area can be partially visible.
23200 The first glyphs of other areas cannot. */
23201 start_x
= window_box_left_offset (w
, area
);
23203 if (area
== TEXT_AREA
)
23206 /* Find the first glyph that must be redrawn. */
23208 && x
+ first
->pixel_width
< r
->x
)
23210 x
+= first
->pixel_width
;
23214 /* Find the last one. */
23218 && x
< r
->x
+ r
->width
)
23220 x
+= last
->pixel_width
;
23226 draw_glyphs (w
, first_x
- start_x
, row
, area
,
23227 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
23228 DRAW_NORMAL_TEXT
, 0);
23233 /* Redraw the parts of the glyph row ROW on window W intersecting
23234 rectangle R. R is in window-relative coordinates. Value is
23235 non-zero if mouse-face was overwritten. */
23238 expose_line (w
, row
, r
)
23240 struct glyph_row
*row
;
23243 xassert (row
->enabled_p
);
23245 if (row
->mode_line_p
|| w
->pseudo_window_p
)
23246 draw_glyphs (w
, 0, row
, TEXT_AREA
,
23247 0, row
->used
[TEXT_AREA
],
23248 DRAW_NORMAL_TEXT
, 0);
23251 if (row
->used
[LEFT_MARGIN_AREA
])
23252 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
23253 if (row
->used
[TEXT_AREA
])
23254 expose_area (w
, row
, r
, TEXT_AREA
);
23255 if (row
->used
[RIGHT_MARGIN_AREA
])
23256 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
23257 draw_row_fringe_bitmaps (w
, row
);
23260 return row
->mouse_face_p
;
23264 /* Redraw those parts of glyphs rows during expose event handling that
23265 overlap other rows. Redrawing of an exposed line writes over parts
23266 of lines overlapping that exposed line; this function fixes that.
23268 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
23269 row in W's current matrix that is exposed and overlaps other rows.
23270 LAST_OVERLAPPING_ROW is the last such row. */
23273 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
23275 struct glyph_row
*first_overlapping_row
;
23276 struct glyph_row
*last_overlapping_row
;
23278 struct glyph_row
*row
;
23280 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
23281 if (row
->overlapping_p
)
23283 xassert (row
->enabled_p
&& !row
->mode_line_p
);
23285 if (row
->used
[LEFT_MARGIN_AREA
])
23286 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
23288 if (row
->used
[TEXT_AREA
])
23289 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
23291 if (row
->used
[RIGHT_MARGIN_AREA
])
23292 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
23297 /* Return non-zero if W's cursor intersects rectangle R. */
23300 phys_cursor_in_rect_p (w
, r
)
23304 XRectangle cr
, result
;
23305 struct glyph
*cursor_glyph
;
23307 cursor_glyph
= get_phys_cursor_glyph (w
);
23310 /* r is relative to W's box, but w->phys_cursor.x is relative
23311 to left edge of W's TEXT area. Adjust it. */
23312 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
23313 cr
.y
= w
->phys_cursor
.y
;
23314 cr
.width
= cursor_glyph
->pixel_width
;
23315 cr
.height
= w
->phys_cursor_height
;
23316 /* ++KFS: W32 version used W32-specific IntersectRect here, but
23317 I assume the effect is the same -- and this is portable. */
23318 return x_intersect_rectangles (&cr
, r
, &result
);
23326 Draw a vertical window border to the right of window W if W doesn't
23327 have vertical scroll bars. */
23330 x_draw_vertical_border (w
)
23333 /* We could do better, if we knew what type of scroll-bar the adjacent
23334 windows (on either side) have... But we don't :-(
23335 However, I think this works ok. ++KFS 2003-04-25 */
23337 /* Redraw borders between horizontally adjacent windows. Don't
23338 do it for frames with vertical scroll bars because either the
23339 right scroll bar of a window, or the left scroll bar of its
23340 neighbor will suffice as a border. */
23341 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
23344 if (!WINDOW_RIGHTMOST_P (w
)
23345 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
23347 int x0
, x1
, y0
, y1
;
23349 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23352 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23355 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
23357 else if (!WINDOW_LEFTMOST_P (w
)
23358 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
23360 int x0
, x1
, y0
, y1
;
23362 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23365 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23368 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
23373 /* Redraw the part of window W intersection rectangle FR. Pixel
23374 coordinates in FR are frame-relative. Call this function with
23375 input blocked. Value is non-zero if the exposure overwrites
23379 expose_window (w
, fr
)
23383 struct frame
*f
= XFRAME (w
->frame
);
23385 int mouse_face_overwritten_p
= 0;
23387 /* If window is not yet fully initialized, do nothing. This can
23388 happen when toolkit scroll bars are used and a window is split.
23389 Reconfiguring the scroll bar will generate an expose for a newly
23391 if (w
->current_matrix
== NULL
)
23394 /* When we're currently updating the window, display and current
23395 matrix usually don't agree. Arrange for a thorough display
23397 if (w
== updated_window
)
23399 SET_FRAME_GARBAGED (f
);
23403 /* Frame-relative pixel rectangle of W. */
23404 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
23405 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
23406 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
23407 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
23409 if (x_intersect_rectangles (fr
, &wr
, &r
))
23411 int yb
= window_text_bottom_y (w
);
23412 struct glyph_row
*row
;
23413 int cursor_cleared_p
;
23414 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
23416 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
23417 r
.x
, r
.y
, r
.width
, r
.height
));
23419 /* Convert to window coordinates. */
23420 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
23421 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
23423 /* Turn off the cursor. */
23424 if (!w
->pseudo_window_p
23425 && phys_cursor_in_rect_p (w
, &r
))
23427 x_clear_cursor (w
);
23428 cursor_cleared_p
= 1;
23431 cursor_cleared_p
= 0;
23433 /* Update lines intersecting rectangle R. */
23434 first_overlapping_row
= last_overlapping_row
= NULL
;
23435 for (row
= w
->current_matrix
->rows
;
23440 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
23442 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
23443 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
23444 || (r
.y
>= y0
&& r
.y
< y1
)
23445 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
23447 /* A header line may be overlapping, but there is no need
23448 to fix overlapping areas for them. KFS 2005-02-12 */
23449 if (row
->overlapping_p
&& !row
->mode_line_p
)
23451 if (first_overlapping_row
== NULL
)
23452 first_overlapping_row
= row
;
23453 last_overlapping_row
= row
;
23456 if (expose_line (w
, row
, &r
))
23457 mouse_face_overwritten_p
= 1;
23464 /* Display the mode line if there is one. */
23465 if (WINDOW_WANTS_MODELINE_P (w
)
23466 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
23468 && row
->y
< r
.y
+ r
.height
)
23470 if (expose_line (w
, row
, &r
))
23471 mouse_face_overwritten_p
= 1;
23474 if (!w
->pseudo_window_p
)
23476 /* Fix the display of overlapping rows. */
23477 if (first_overlapping_row
)
23478 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
23480 /* Draw border between windows. */
23481 x_draw_vertical_border (w
);
23483 /* Turn the cursor on again. */
23484 if (cursor_cleared_p
)
23485 update_window_cursor (w
, 1);
23489 return mouse_face_overwritten_p
;
23494 /* Redraw (parts) of all windows in the window tree rooted at W that
23495 intersect R. R contains frame pixel coordinates. Value is
23496 non-zero if the exposure overwrites mouse-face. */
23499 expose_window_tree (w
, r
)
23503 struct frame
*f
= XFRAME (w
->frame
);
23504 int mouse_face_overwritten_p
= 0;
23506 while (w
&& !FRAME_GARBAGED_P (f
))
23508 if (!NILP (w
->hchild
))
23509 mouse_face_overwritten_p
23510 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
23511 else if (!NILP (w
->vchild
))
23512 mouse_face_overwritten_p
23513 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
23515 mouse_face_overwritten_p
|= expose_window (w
, r
);
23517 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
23520 return mouse_face_overwritten_p
;
23525 Redisplay an exposed area of frame F. X and Y are the upper-left
23526 corner of the exposed rectangle. W and H are width and height of
23527 the exposed area. All are pixel values. W or H zero means redraw
23528 the entire frame. */
23531 expose_frame (f
, x
, y
, w
, h
)
23536 int mouse_face_overwritten_p
= 0;
23538 TRACE ((stderr
, "expose_frame "));
23540 /* No need to redraw if frame will be redrawn soon. */
23541 if (FRAME_GARBAGED_P (f
))
23543 TRACE ((stderr
, " garbaged\n"));
23547 /* If basic faces haven't been realized yet, there is no point in
23548 trying to redraw anything. This can happen when we get an expose
23549 event while Emacs is starting, e.g. by moving another window. */
23550 if (FRAME_FACE_CACHE (f
) == NULL
23551 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
23553 TRACE ((stderr
, " no faces\n"));
23557 if (w
== 0 || h
== 0)
23560 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
23561 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
23571 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
23572 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
23574 if (WINDOWP (f
->tool_bar_window
))
23575 mouse_face_overwritten_p
23576 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
23578 #ifdef HAVE_X_WINDOWS
23580 #ifndef USE_X_TOOLKIT
23581 if (WINDOWP (f
->menu_bar_window
))
23582 mouse_face_overwritten_p
23583 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
23584 #endif /* not USE_X_TOOLKIT */
23588 /* Some window managers support a focus-follows-mouse style with
23589 delayed raising of frames. Imagine a partially obscured frame,
23590 and moving the mouse into partially obscured mouse-face on that
23591 frame. The visible part of the mouse-face will be highlighted,
23592 then the WM raises the obscured frame. With at least one WM, KDE
23593 2.1, Emacs is not getting any event for the raising of the frame
23594 (even tried with SubstructureRedirectMask), only Expose events.
23595 These expose events will draw text normally, i.e. not
23596 highlighted. Which means we must redo the highlight here.
23597 Subsume it under ``we love X''. --gerd 2001-08-15 */
23598 /* Included in Windows version because Windows most likely does not
23599 do the right thing if any third party tool offers
23600 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
23601 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
23603 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23604 if (f
== dpyinfo
->mouse_face_mouse_frame
)
23606 int x
= dpyinfo
->mouse_face_mouse_x
;
23607 int y
= dpyinfo
->mouse_face_mouse_y
;
23608 clear_mouse_face (dpyinfo
);
23609 note_mouse_highlight (f
, x
, y
);
23616 Determine the intersection of two rectangles R1 and R2. Return
23617 the intersection in *RESULT. Value is non-zero if RESULT is not
23621 x_intersect_rectangles (r1
, r2
, result
)
23622 XRectangle
*r1
, *r2
, *result
;
23624 XRectangle
*left
, *right
;
23625 XRectangle
*upper
, *lower
;
23626 int intersection_p
= 0;
23628 /* Rearrange so that R1 is the left-most rectangle. */
23630 left
= r1
, right
= r2
;
23632 left
= r2
, right
= r1
;
23634 /* X0 of the intersection is right.x0, if this is inside R1,
23635 otherwise there is no intersection. */
23636 if (right
->x
<= left
->x
+ left
->width
)
23638 result
->x
= right
->x
;
23640 /* The right end of the intersection is the minimum of the
23641 the right ends of left and right. */
23642 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
23645 /* Same game for Y. */
23647 upper
= r1
, lower
= r2
;
23649 upper
= r2
, lower
= r1
;
23651 /* The upper end of the intersection is lower.y0, if this is inside
23652 of upper. Otherwise, there is no intersection. */
23653 if (lower
->y
<= upper
->y
+ upper
->height
)
23655 result
->y
= lower
->y
;
23657 /* The lower end of the intersection is the minimum of the lower
23658 ends of upper and lower. */
23659 result
->height
= (min (lower
->y
+ lower
->height
,
23660 upper
->y
+ upper
->height
)
23662 intersection_p
= 1;
23666 return intersection_p
;
23669 #endif /* HAVE_WINDOW_SYSTEM */
23672 /***********************************************************************
23674 ***********************************************************************/
23679 Vwith_echo_area_save_vector
= Qnil
;
23680 staticpro (&Vwith_echo_area_save_vector
);
23682 Vmessage_stack
= Qnil
;
23683 staticpro (&Vmessage_stack
);
23685 Qinhibit_redisplay
= intern ("inhibit-redisplay");
23686 staticpro (&Qinhibit_redisplay
);
23688 message_dolog_marker1
= Fmake_marker ();
23689 staticpro (&message_dolog_marker1
);
23690 message_dolog_marker2
= Fmake_marker ();
23691 staticpro (&message_dolog_marker2
);
23692 message_dolog_marker3
= Fmake_marker ();
23693 staticpro (&message_dolog_marker3
);
23696 defsubr (&Sdump_frame_glyph_matrix
);
23697 defsubr (&Sdump_glyph_matrix
);
23698 defsubr (&Sdump_glyph_row
);
23699 defsubr (&Sdump_tool_bar_row
);
23700 defsubr (&Strace_redisplay
);
23701 defsubr (&Strace_to_stderr
);
23703 #ifdef HAVE_WINDOW_SYSTEM
23704 defsubr (&Stool_bar_lines_needed
);
23705 defsubr (&Slookup_image_map
);
23707 defsubr (&Sformat_mode_line
);
23709 staticpro (&Qmenu_bar_update_hook
);
23710 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
23712 staticpro (&Qoverriding_terminal_local_map
);
23713 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
23715 staticpro (&Qoverriding_local_map
);
23716 Qoverriding_local_map
= intern ("overriding-local-map");
23718 staticpro (&Qwindow_scroll_functions
);
23719 Qwindow_scroll_functions
= intern ("window-scroll-functions");
23721 staticpro (&Qredisplay_end_trigger_functions
);
23722 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
23724 staticpro (&Qinhibit_point_motion_hooks
);
23725 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
23727 QCdata
= intern (":data");
23728 staticpro (&QCdata
);
23729 Qdisplay
= intern ("display");
23730 staticpro (&Qdisplay
);
23731 Qspace_width
= intern ("space-width");
23732 staticpro (&Qspace_width
);
23733 Qraise
= intern ("raise");
23734 staticpro (&Qraise
);
23735 Qslice
= intern ("slice");
23736 staticpro (&Qslice
);
23737 Qspace
= intern ("space");
23738 staticpro (&Qspace
);
23739 Qmargin
= intern ("margin");
23740 staticpro (&Qmargin
);
23741 Qpointer
= intern ("pointer");
23742 staticpro (&Qpointer
);
23743 Qleft_margin
= intern ("left-margin");
23744 staticpro (&Qleft_margin
);
23745 Qright_margin
= intern ("right-margin");
23746 staticpro (&Qright_margin
);
23747 Qcenter
= intern ("center");
23748 staticpro (&Qcenter
);
23749 Qline_height
= intern ("line-height");
23750 staticpro (&Qline_height
);
23751 QCalign_to
= intern (":align-to");
23752 staticpro (&QCalign_to
);
23753 QCrelative_width
= intern (":relative-width");
23754 staticpro (&QCrelative_width
);
23755 QCrelative_height
= intern (":relative-height");
23756 staticpro (&QCrelative_height
);
23757 QCeval
= intern (":eval");
23758 staticpro (&QCeval
);
23759 QCpropertize
= intern (":propertize");
23760 staticpro (&QCpropertize
);
23761 QCfile
= intern (":file");
23762 staticpro (&QCfile
);
23763 Qfontified
= intern ("fontified");
23764 staticpro (&Qfontified
);
23765 Qfontification_functions
= intern ("fontification-functions");
23766 staticpro (&Qfontification_functions
);
23767 Qtrailing_whitespace
= intern ("trailing-whitespace");
23768 staticpro (&Qtrailing_whitespace
);
23769 Qescape_glyph
= intern ("escape-glyph");
23770 staticpro (&Qescape_glyph
);
23771 Qnobreak_space
= intern ("nobreak-space");
23772 staticpro (&Qnobreak_space
);
23773 Qimage
= intern ("image");
23774 staticpro (&Qimage
);
23775 QCmap
= intern (":map");
23776 staticpro (&QCmap
);
23777 QCpointer
= intern (":pointer");
23778 staticpro (&QCpointer
);
23779 Qrect
= intern ("rect");
23780 staticpro (&Qrect
);
23781 Qcircle
= intern ("circle");
23782 staticpro (&Qcircle
);
23783 Qpoly
= intern ("poly");
23784 staticpro (&Qpoly
);
23785 Qmessage_truncate_lines
= intern ("message-truncate-lines");
23786 staticpro (&Qmessage_truncate_lines
);
23787 Qgrow_only
= intern ("grow-only");
23788 staticpro (&Qgrow_only
);
23789 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
23790 staticpro (&Qinhibit_menubar_update
);
23791 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
23792 staticpro (&Qinhibit_eval_during_redisplay
);
23793 Qposition
= intern ("position");
23794 staticpro (&Qposition
);
23795 Qbuffer_position
= intern ("buffer-position");
23796 staticpro (&Qbuffer_position
);
23797 Qobject
= intern ("object");
23798 staticpro (&Qobject
);
23799 Qbar
= intern ("bar");
23801 Qhbar
= intern ("hbar");
23802 staticpro (&Qhbar
);
23803 Qbox
= intern ("box");
23805 Qhollow
= intern ("hollow");
23806 staticpro (&Qhollow
);
23807 Qhand
= intern ("hand");
23808 staticpro (&Qhand
);
23809 Qarrow
= intern ("arrow");
23810 staticpro (&Qarrow
);
23811 Qtext
= intern ("text");
23812 staticpro (&Qtext
);
23813 Qrisky_local_variable
= intern ("risky-local-variable");
23814 staticpro (&Qrisky_local_variable
);
23815 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
23816 staticpro (&Qinhibit_free_realized_faces
);
23818 list_of_error
= Fcons (Fcons (intern ("error"),
23819 Fcons (intern ("void-variable"), Qnil
)),
23821 staticpro (&list_of_error
);
23823 Qlast_arrow_position
= intern ("last-arrow-position");
23824 staticpro (&Qlast_arrow_position
);
23825 Qlast_arrow_string
= intern ("last-arrow-string");
23826 staticpro (&Qlast_arrow_string
);
23828 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
23829 staticpro (&Qoverlay_arrow_string
);
23830 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
23831 staticpro (&Qoverlay_arrow_bitmap
);
23833 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
23834 staticpro (&echo_buffer
[0]);
23835 staticpro (&echo_buffer
[1]);
23837 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
23838 staticpro (&echo_area_buffer
[0]);
23839 staticpro (&echo_area_buffer
[1]);
23841 Vmessages_buffer_name
= build_string ("*Messages*");
23842 staticpro (&Vmessages_buffer_name
);
23844 mode_line_proptrans_alist
= Qnil
;
23845 staticpro (&mode_line_proptrans_alist
);
23846 mode_line_string_list
= Qnil
;
23847 staticpro (&mode_line_string_list
);
23848 mode_line_string_face
= Qnil
;
23849 staticpro (&mode_line_string_face
);
23850 mode_line_string_face_prop
= Qnil
;
23851 staticpro (&mode_line_string_face_prop
);
23852 Vmode_line_unwind_vector
= Qnil
;
23853 staticpro (&Vmode_line_unwind_vector
);
23855 help_echo_string
= Qnil
;
23856 staticpro (&help_echo_string
);
23857 help_echo_object
= Qnil
;
23858 staticpro (&help_echo_object
);
23859 help_echo_window
= Qnil
;
23860 staticpro (&help_echo_window
);
23861 previous_help_echo_string
= Qnil
;
23862 staticpro (&previous_help_echo_string
);
23863 help_echo_pos
= -1;
23865 #ifdef HAVE_WINDOW_SYSTEM
23866 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
23867 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
23868 For example, if a block cursor is over a tab, it will be drawn as
23869 wide as that tab on the display. */);
23870 x_stretch_cursor_p
= 0;
23873 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
23874 doc
: /* *Non-nil means highlight trailing whitespace.
23875 The face used for trailing whitespace is `trailing-whitespace'. */);
23876 Vshow_trailing_whitespace
= Qnil
;
23878 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
23879 doc
: /* *Control highlighting of nobreak space and soft hyphen.
23880 A value of t means highlight the character itself (for nobreak space,
23881 use face `nobreak-space').
23882 A value of nil means no highlighting.
23883 Other values mean display the escape glyph followed by an ordinary
23884 space or ordinary hyphen. */);
23885 Vnobreak_char_display
= Qt
;
23887 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
23888 doc
: /* *The pointer shape to show in void text areas.
23889 A value of nil means to show the text pointer. Other options are `arrow',
23890 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
23891 Vvoid_text_area_pointer
= Qarrow
;
23893 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
23894 doc
: /* Non-nil means don't actually do any redisplay.
23895 This is used for internal purposes. */);
23896 Vinhibit_redisplay
= Qnil
;
23898 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
23899 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
23900 Vglobal_mode_string
= Qnil
;
23902 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
23903 doc
: /* Marker for where to display an arrow on top of the buffer text.
23904 This must be the beginning of a line in order to work.
23905 See also `overlay-arrow-string'. */);
23906 Voverlay_arrow_position
= Qnil
;
23908 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
23909 doc
: /* String to display as an arrow in non-window frames.
23910 See also `overlay-arrow-position'. */);
23911 Voverlay_arrow_string
= build_string ("=>");
23913 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
23914 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
23915 The symbols on this list are examined during redisplay to determine
23916 where to display overlay arrows. */);
23917 Voverlay_arrow_variable_list
23918 = Fcons (intern ("overlay-arrow-position"), Qnil
);
23920 DEFVAR_INT ("scroll-step", &scroll_step
,
23921 doc
: /* *The number of lines to try scrolling a window by when point moves out.
23922 If that fails to bring point back on frame, point is centered instead.
23923 If this is zero, point is always centered after it moves off frame.
23924 If you want scrolling to always be a line at a time, you should set
23925 `scroll-conservatively' to a large value rather than set this to 1. */);
23927 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
23928 doc
: /* *Scroll up to this many lines, to bring point back on screen.
23929 A value of zero means to scroll the text to center point vertically
23930 in the window. */);
23931 scroll_conservatively
= 0;
23933 DEFVAR_INT ("scroll-margin", &scroll_margin
,
23934 doc
: /* *Number of lines of margin at the top and bottom of a window.
23935 Recenter the window whenever point gets within this many lines
23936 of the top or bottom of the window. */);
23939 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
23940 doc
: /* Pixels per inch value for non-window system displays.
23941 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
23942 Vdisplay_pixels_per_inch
= make_float (72.0);
23945 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
23948 DEFVAR_BOOL ("truncate-partial-width-windows",
23949 &truncate_partial_width_windows
,
23950 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
23951 truncate_partial_width_windows
= 1;
23953 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
23954 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
23955 Any other value means to use the appropriate face, `mode-line',
23956 `header-line', or `menu' respectively. */);
23957 mode_line_inverse_video
= 1;
23959 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
23960 doc
: /* *Maximum buffer size for which line number should be displayed.
23961 If the buffer is bigger than this, the line number does not appear
23962 in the mode line. A value of nil means no limit. */);
23963 Vline_number_display_limit
= Qnil
;
23965 DEFVAR_INT ("line-number-display-limit-width",
23966 &line_number_display_limit_width
,
23967 doc
: /* *Maximum line width (in characters) for line number display.
23968 If the average length of the lines near point is bigger than this, then the
23969 line number may be omitted from the mode line. */);
23970 line_number_display_limit_width
= 200;
23972 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
23973 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
23974 highlight_nonselected_windows
= 0;
23976 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
23977 doc
: /* Non-nil if more than one frame is visible on this display.
23978 Minibuffer-only frames don't count, but iconified frames do.
23979 This variable is not guaranteed to be accurate except while processing
23980 `frame-title-format' and `icon-title-format'. */);
23982 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
23983 doc
: /* Template for displaying the title bar of visible frames.
23984 \(Assuming the window manager supports this feature.)
23985 This variable has the same structure as `mode-line-format' (which see),
23986 and is used only on frames for which no explicit name has been set
23987 \(see `modify-frame-parameters'). */);
23989 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
23990 doc
: /* Template for displaying the title bar of an iconified frame.
23991 \(Assuming the window manager supports this feature.)
23992 This variable has the same structure as `mode-line-format' (which see),
23993 and is used only on frames for which no explicit name has been set
23994 \(see `modify-frame-parameters'). */);
23996 = Vframe_title_format
23997 = Fcons (intern ("multiple-frames"),
23998 Fcons (build_string ("%b"),
23999 Fcons (Fcons (empty_string
,
24000 Fcons (intern ("invocation-name"),
24001 Fcons (build_string ("@"),
24002 Fcons (intern ("system-name"),
24006 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
24007 doc
: /* Maximum number of lines to keep in the message log buffer.
24008 If nil, disable message logging. If t, log messages but don't truncate
24009 the buffer when it becomes large. */);
24010 Vmessage_log_max
= make_number (50);
24012 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
24013 doc
: /* Functions called before redisplay, if window sizes have changed.
24014 The value should be a list of functions that take one argument.
24015 Just before redisplay, for each frame, if any of its windows have changed
24016 size since the last redisplay, or have been split or deleted,
24017 all the functions in the list are called, with the frame as argument. */);
24018 Vwindow_size_change_functions
= Qnil
;
24020 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
24021 doc
: /* List of functions to call before redisplaying a window with scrolling.
24022 Each function is called with two arguments, the window
24023 and its new display-start position. Note that the value of `window-end'
24024 is not valid when these functions are called. */);
24025 Vwindow_scroll_functions
= Qnil
;
24027 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
24028 doc
: /* Functions called when redisplay of a window reaches the end trigger.
24029 Each function is called with two arguments, the window and the end trigger value.
24030 See `set-window-redisplay-end-trigger'. */);
24031 Vredisplay_end_trigger_functions
= Qnil
;
24033 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
24034 doc
: /* *Non-nil means autoselect window with mouse pointer.
24035 If nil, do not autoselect windows.
24036 A positive number means delay autoselection by that many seconds: a
24037 window is autoselected only after the mouse has remained in that
24038 window for the duration of the delay.
24039 A negative number has a similar effect, but causes windows to be
24040 autoselected only after the mouse has stopped moving. \(Because of
24041 the way Emacs compares mouse events, you will occasionally wait twice
24042 that time before the window gets selected.\)
24043 Any other value means to autoselect window instantaneously when the
24044 mouse pointer enters it.
24046 Autoselection selects the minibuffer only if it is active, and never
24047 unselects the minibuffer if it is active. */);
24048 Vmouse_autoselect_window
= Qnil
;
24050 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
24051 doc
: /* *Non-nil means automatically resize tool-bars.
24052 This increases a tool-bar's height if not all tool-bar items are visible.
24053 It decreases a tool-bar's height when it would display blank lines
24055 auto_resize_tool_bars_p
= 1;
24057 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
24058 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
24059 auto_raise_tool_bar_buttons_p
= 1;
24061 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
24062 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
24063 make_cursor_line_fully_visible_p
= 1;
24065 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
24066 doc
: /* *Border below tool-bar in pixels.
24067 If an integer, use it as the height of the border.
24068 If it is one of `internal-border-width' or `border-width', use the
24069 value of the corresponding frame parameter.
24070 Otherwise, no border is added below the tool-bar. */);
24071 Vtool_bar_border
= Qinternal_border_width
;
24073 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
24074 doc
: /* *Margin around tool-bar buttons in pixels.
24075 If an integer, use that for both horizontal and vertical margins.
24076 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
24077 HORZ specifying the horizontal margin, and VERT specifying the
24078 vertical margin. */);
24079 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
24081 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
24082 doc
: /* *Relief thickness of tool-bar buttons. */);
24083 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
24085 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
24086 doc
: /* List of functions to call to fontify regions of text.
24087 Each function is called with one argument POS. Functions must
24088 fontify a region starting at POS in the current buffer, and give
24089 fontified regions the property `fontified'. */);
24090 Vfontification_functions
= Qnil
;
24091 Fmake_variable_buffer_local (Qfontification_functions
);
24093 DEFVAR_BOOL ("unibyte-display-via-language-environment",
24094 &unibyte_display_via_language_environment
,
24095 doc
: /* *Non-nil means display unibyte text according to language environment.
24096 Specifically this means that unibyte non-ASCII characters
24097 are displayed by converting them to the equivalent multibyte characters
24098 according to the current language environment. As a result, they are
24099 displayed according to the current fontset. */);
24100 unibyte_display_via_language_environment
= 0;
24102 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
24103 doc
: /* *Maximum height for resizing mini-windows.
24104 If a float, it specifies a fraction of the mini-window frame's height.
24105 If an integer, it specifies a number of lines. */);
24106 Vmax_mini_window_height
= make_float (0.25);
24108 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
24109 doc
: /* *How to resize mini-windows.
24110 A value of nil means don't automatically resize mini-windows.
24111 A value of t means resize them to fit the text displayed in them.
24112 A value of `grow-only', the default, means let mini-windows grow
24113 only, until their display becomes empty, at which point the windows
24114 go back to their normal size. */);
24115 Vresize_mini_windows
= Qgrow_only
;
24117 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
24118 doc
: /* Alist specifying how to blink the cursor off.
24119 Each element has the form (ON-STATE . OFF-STATE). Whenever the
24120 `cursor-type' frame-parameter or variable equals ON-STATE,
24121 comparing using `equal', Emacs uses OFF-STATE to specify
24122 how to blink it off. ON-STATE and OFF-STATE are values for
24123 the `cursor-type' frame parameter.
24125 If a frame's ON-STATE has no entry in this list,
24126 the frame's other specifications determine how to blink the cursor off. */);
24127 Vblink_cursor_alist
= Qnil
;
24129 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
24130 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
24131 automatic_hscrolling_p
= 1;
24133 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
24134 doc
: /* *How many columns away from the window edge point is allowed to get
24135 before automatic hscrolling will horizontally scroll the window. */);
24136 hscroll_margin
= 5;
24138 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
24139 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
24140 When point is less than `hscroll-margin' columns from the window
24141 edge, automatic hscrolling will scroll the window by the amount of columns
24142 determined by this variable. If its value is a positive integer, scroll that
24143 many columns. If it's a positive floating-point number, it specifies the
24144 fraction of the window's width to scroll. If it's nil or zero, point will be
24145 centered horizontally after the scroll. Any other value, including negative
24146 numbers, are treated as if the value were zero.
24148 Automatic hscrolling always moves point outside the scroll margin, so if
24149 point was more than scroll step columns inside the margin, the window will
24150 scroll more than the value given by the scroll step.
24152 Note that the lower bound for automatic hscrolling specified by `scroll-left'
24153 and `scroll-right' overrides this variable's effect. */);
24154 Vhscroll_step
= make_number (0);
24156 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
24157 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
24158 Bind this around calls to `message' to let it take effect. */);
24159 message_truncate_lines
= 0;
24161 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
24162 doc
: /* Normal hook run to update the menu bar definitions.
24163 Redisplay runs this hook before it redisplays the menu bar.
24164 This is used to update submenus such as Buffers,
24165 whose contents depend on various data. */);
24166 Vmenu_bar_update_hook
= Qnil
;
24168 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
24169 doc
: /* Frame for which we are updating a menu.
24170 The enable predicate for a menu binding should check this variable. */);
24171 Vmenu_updating_frame
= Qnil
;
24173 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
24174 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
24175 inhibit_menubar_update
= 0;
24177 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
24178 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
24179 inhibit_eval_during_redisplay
= 0;
24181 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
24182 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
24183 inhibit_free_realized_faces
= 0;
24186 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
24187 doc
: /* Inhibit try_window_id display optimization. */);
24188 inhibit_try_window_id
= 0;
24190 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
24191 doc
: /* Inhibit try_window_reusing display optimization. */);
24192 inhibit_try_window_reusing
= 0;
24194 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
24195 doc
: /* Inhibit try_cursor_movement display optimization. */);
24196 inhibit_try_cursor_movement
= 0;
24197 #endif /* GLYPH_DEBUG */
24199 DEFVAR_INT ("overline-margin", &overline_margin
,
24200 doc
: /* *Space between overline and text, in pixels.
24201 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
24202 margin to the caracter height. */);
24203 overline_margin
= 2;
24207 /* Initialize this module when Emacs starts. */
24212 Lisp_Object root_window
;
24213 struct window
*mini_w
;
24215 current_header_line_height
= current_mode_line_height
= -1;
24217 CHARPOS (this_line_start_pos
) = 0;
24219 mini_w
= XWINDOW (minibuf_window
);
24220 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
24222 if (!noninteractive
)
24224 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
24227 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
24228 set_window_height (root_window
,
24229 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
24231 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
24232 set_window_height (minibuf_window
, 1, 0);
24234 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
24235 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
24237 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
24238 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
24239 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
24241 /* The default ellipsis glyphs `...'. */
24242 for (i
= 0; i
< 3; ++i
)
24243 default_invis_vector
[i
] = make_number ('.');
24247 /* Allocate the buffer for frame titles.
24248 Also used for `format-mode-line'. */
24250 mode_line_noprop_buf
= (char *) xmalloc (size
);
24251 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
24252 mode_line_noprop_ptr
= mode_line_noprop_buf
;
24253 mode_line_target
= MODE_LINE_DISPLAY
;
24256 help_echo_showing_p
= 0;
24260 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
24261 (do not change this comment) */