1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
3 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
27 Emacs separates the task of updating the display from code
28 modifying global state, e.g. buffer text. This way functions
29 operating on buffers don't also have to be concerned with updating
32 Updating the display is triggered by the Lisp interpreter when it
33 decides it's time to do it. This is done either automatically for
34 you as part of the interpreter's command loop or as the result of
35 calling Lisp functions like `sit-for'. The C function `redisplay'
36 in xdisp.c is the only entry into the inner redisplay code. (Or,
37 let's say almost---see the description of direct update
40 The following diagram shows how redisplay code is invoked. As you
41 can see, Lisp calls redisplay and vice versa. Under window systems
42 like X, some portions of the redisplay code are also called
43 asynchronously during mouse movement or expose events. It is very
44 important that these code parts do NOT use the C library (malloc,
45 free) because many C libraries under Unix are not reentrant. They
46 may also NOT call functions of the Lisp interpreter which could
47 change the interpreter's state. If you don't follow these rules,
48 you will encounter bugs which are very hard to explain.
50 (Direct functions, see below)
51 direct_output_for_insert,
52 direct_forward_char (dispnew.c)
53 +---------------------------------+
56 +--------------+ redisplay +----------------+
57 | Lisp machine |---------------->| Redisplay code |<--+
58 +--------------+ (xdisp.c) +----------------+ |
60 +----------------------------------+ |
61 Don't use this path when called |
64 expose_window (asynchronous) |
66 X expose events -----+
68 What does redisplay do? Obviously, it has to figure out somehow what
69 has been changed since the last time the display has been updated,
70 and to make these changes visible. Preferably it would do that in
71 a moderately intelligent way, i.e. fast.
73 Changes in buffer text can be deduced from window and buffer
74 structures, and from some global variables like `beg_unchanged' and
75 `end_unchanged'. The contents of the display are additionally
76 recorded in a `glyph matrix', a two-dimensional matrix of glyph
77 structures. Each row in such a matrix corresponds to a line on the
78 display, and each glyph in a row corresponds to a column displaying
79 a character, an image, or what else. This matrix is called the
80 `current glyph matrix' or `current matrix' in redisplay
83 For buffer parts that have been changed since the last update, a
84 second glyph matrix is constructed, the so called `desired glyph
85 matrix' or short `desired matrix'. Current and desired matrix are
86 then compared to find a cheap way to update the display, e.g. by
87 reusing part of the display by scrolling lines.
92 You will find a lot of redisplay optimizations when you start
93 looking at the innards of redisplay. The overall goal of all these
94 optimizations is to make redisplay fast because it is done
97 Two optimizations are not found in xdisp.c. These are the direct
98 operations mentioned above. As the name suggests they follow a
99 different principle than the rest of redisplay. Instead of
100 building a desired matrix and then comparing it with the current
101 display, they perform their actions directly on the display and on
104 One direct operation updates the display after one character has
105 been entered. The other one moves the cursor by one position
106 forward or backward. You find these functions under the names
107 `direct_output_for_insert' and `direct_output_forward_char' in
113 Desired matrices are always built per Emacs window. The function
114 `display_line' is the central function to look at if you are
115 interested. It constructs one row in a desired matrix given an
116 iterator structure containing both a buffer position and a
117 description of the environment in which the text is to be
118 displayed. But this is too early, read on.
120 Characters and pixmaps displayed for a range of buffer text depend
121 on various settings of buffers and windows, on overlays and text
122 properties, on display tables, on selective display. The good news
123 is that all this hairy stuff is hidden behind a small set of
124 interface functions taking an iterator structure (struct it)
127 Iteration over things to be displayed is then simple. It is
128 started by initializing an iterator with a call to init_iterator.
129 Calls to get_next_display_element fill the iterator structure with
130 relevant information about the next thing to display. Calls to
131 set_iterator_to_next move the iterator to the next thing.
133 Besides this, an iterator also contains information about the
134 display environment in which glyphs for display elements are to be
135 produced. It has fields for the width and height of the display,
136 the information whether long lines are truncated or continued, a
137 current X and Y position, and lots of other stuff you can better
140 Glyphs in a desired matrix are normally constructed in a loop
141 calling get_next_display_element and then produce_glyphs. The call
142 to produce_glyphs will fill the iterator structure with pixel
143 information about the element being displayed and at the same time
144 produce glyphs for it. If the display element fits on the line
145 being displayed, set_iterator_to_next is called next, otherwise the
146 glyphs produced are discarded.
151 That just couldn't be all, could it? What about terminal types not
152 supporting operations on sub-windows of the screen? To update the
153 display on such a terminal, window-based glyph matrices are not
154 well suited. To be able to reuse part of the display (scrolling
155 lines up and down), we must instead have a view of the whole
156 screen. This is what `frame matrices' are for. They are a trick.
158 Frames on terminals like above have a glyph pool. Windows on such
159 a frame sub-allocate their glyph memory from their frame's glyph
160 pool. The frame itself is given its own glyph matrices. By
161 coincidence---or maybe something else---rows in window glyph
162 matrices are slices of corresponding rows in frame matrices. Thus
163 writing to window matrices implicitly updates a frame matrix which
164 provides us with the view of the whole screen that we originally
165 wanted to have without having to move many bytes around. To be
166 honest, there is a little bit more done, but not much more. If you
167 plan to extend that code, take a look at dispnew.c. The function
168 build_frame_matrix is a good starting point. */
174 #include "keyboard.h"
177 #include "termchar.h"
178 #include "dispextern.h"
182 #include "commands.h"
186 #include "termhooks.h"
187 #include "intervals.h"
190 #include "region-cache.h"
192 #include "blockinput.h"
194 #ifdef HAVE_X_WINDOWS
204 #ifndef FRAME_X_OUTPUT
205 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
208 #define INFINITY 10000000
210 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
212 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
213 extern int pending_menu_activation
;
216 extern int interrupt_input
;
217 extern int command_loop_level
;
219 extern Lisp_Object do_mouse_tracking
;
221 extern int minibuffer_auto_raise
;
222 extern Lisp_Object Vminibuffer_list
;
224 extern Lisp_Object Qface
;
225 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
227 extern Lisp_Object Voverriding_local_map
;
228 extern Lisp_Object Voverriding_local_map_menu_flag
;
229 extern Lisp_Object Qmenu_item
;
230 extern Lisp_Object Qwhen
;
231 extern Lisp_Object Qhelp_echo
;
233 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
234 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
235 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
236 Lisp_Object Qinhibit_point_motion_hooks
;
237 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
238 Lisp_Object Qfontified
;
239 Lisp_Object Qgrow_only
;
240 Lisp_Object Qinhibit_eval_during_redisplay
;
241 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
244 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
247 Lisp_Object Qarrow
, Qhand
, Qtext
;
249 Lisp_Object Qrisky_local_variable
;
251 /* Holds the list (error). */
252 Lisp_Object list_of_error
;
254 /* Functions called to fontify regions of text. */
256 Lisp_Object Vfontification_functions
;
257 Lisp_Object Qfontification_functions
;
259 /* Non-nil means automatically select any window when the mouse
260 cursor moves into it. */
261 Lisp_Object Vmouse_autoselect_window
;
263 /* Non-zero means draw tool bar buttons raised when the mouse moves
266 int auto_raise_tool_bar_buttons_p
;
268 /* Non-zero means to reposition window if cursor line is only partially visible. */
270 int make_cursor_line_fully_visible_p
;
272 /* Margin below tool bar in pixels. 0 or nil means no margin.
273 If value is `internal-border-width' or `border-width',
274 the corresponding frame parameter is used. */
276 Lisp_Object Vtool_bar_border
;
278 /* Margin around tool bar buttons in pixels. */
280 Lisp_Object Vtool_bar_button_margin
;
282 /* Thickness of shadow to draw around tool bar buttons. */
284 EMACS_INT tool_bar_button_relief
;
286 /* Non-nil means automatically resize tool-bars so that all tool-bar
287 items are visible, and no blank lines remain.
289 If value is `grow-only', only make tool-bar bigger. */
291 Lisp_Object Vauto_resize_tool_bars
;
293 /* Non-zero means draw block and hollow cursor as wide as the glyph
294 under it. For example, if a block cursor is over a tab, it will be
295 drawn as wide as that tab on the display. */
297 int x_stretch_cursor_p
;
299 /* Non-nil means don't actually do any redisplay. */
301 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
303 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
305 int inhibit_eval_during_redisplay
;
307 /* Names of text properties relevant for redisplay. */
309 Lisp_Object Qdisplay
;
310 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
312 /* Symbols used in text property values. */
314 Lisp_Object Vdisplay_pixels_per_inch
;
315 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
316 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
319 Lisp_Object Qmargin
, Qpointer
;
320 Lisp_Object Qline_height
;
321 extern Lisp_Object Qheight
;
322 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
323 extern Lisp_Object Qscroll_bar
;
324 extern Lisp_Object Qcursor
;
326 /* Non-nil means highlight trailing whitespace. */
328 Lisp_Object Vshow_trailing_whitespace
;
330 /* Non-nil means escape non-break space and hyphens. */
332 Lisp_Object Vnobreak_char_display
;
334 #ifdef HAVE_WINDOW_SYSTEM
335 extern Lisp_Object Voverflow_newline_into_fringe
;
337 /* Test if overflow newline into fringe. Called with iterator IT
338 at or past right window margin, and with IT->current_x set. */
340 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
341 (!NILP (Voverflow_newline_into_fringe) \
342 && FRAME_WINDOW_P (it->f) \
343 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
344 && it->current_x == it->last_visible_x)
346 #endif /* HAVE_WINDOW_SYSTEM */
348 /* Non-nil means show the text cursor in void text areas
349 i.e. in blank areas after eol and eob. This used to be
350 the default in 21.3. */
352 Lisp_Object Vvoid_text_area_pointer
;
354 /* Name of the face used to highlight trailing whitespace. */
356 Lisp_Object Qtrailing_whitespace
;
358 /* Name and number of the face used to highlight escape glyphs. */
360 Lisp_Object Qescape_glyph
;
362 /* Name and number of the face used to highlight non-breaking spaces. */
364 Lisp_Object Qnobreak_space
;
366 /* The symbol `image' which is the car of the lists used to represent
371 /* The image map types. */
372 Lisp_Object QCmap
, QCpointer
;
373 Lisp_Object Qrect
, Qcircle
, Qpoly
;
375 /* Non-zero means print newline to stdout before next mini-buffer
378 int noninteractive_need_newline
;
380 /* Non-zero means print newline to message log before next message. */
382 static int message_log_need_newline
;
384 /* Three markers that message_dolog uses.
385 It could allocate them itself, but that causes trouble
386 in handling memory-full errors. */
387 static Lisp_Object message_dolog_marker1
;
388 static Lisp_Object message_dolog_marker2
;
389 static Lisp_Object message_dolog_marker3
;
391 /* The buffer position of the first character appearing entirely or
392 partially on the line of the selected window which contains the
393 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
394 redisplay optimization in redisplay_internal. */
396 static struct text_pos this_line_start_pos
;
398 /* Number of characters past the end of the line above, including the
399 terminating newline. */
401 static struct text_pos this_line_end_pos
;
403 /* The vertical positions and the height of this line. */
405 static int this_line_vpos
;
406 static int this_line_y
;
407 static int this_line_pixel_height
;
409 /* X position at which this display line starts. Usually zero;
410 negative if first character is partially visible. */
412 static int this_line_start_x
;
414 /* Buffer that this_line_.* variables are referring to. */
416 static struct buffer
*this_line_buffer
;
418 /* Nonzero means truncate lines in all windows less wide than the
421 int truncate_partial_width_windows
;
423 /* A flag to control how to display unibyte 8-bit character. */
425 int unibyte_display_via_language_environment
;
427 /* Nonzero means we have more than one non-mini-buffer-only frame.
428 Not guaranteed to be accurate except while parsing
429 frame-title-format. */
433 Lisp_Object Vglobal_mode_string
;
436 /* List of variables (symbols) which hold markers for overlay arrows.
437 The symbols on this list are examined during redisplay to determine
438 where to display overlay arrows. */
440 Lisp_Object Voverlay_arrow_variable_list
;
442 /* Marker for where to display an arrow on top of the buffer text. */
444 Lisp_Object Voverlay_arrow_position
;
446 /* String to display for the arrow. Only used on terminal frames. */
448 Lisp_Object Voverlay_arrow_string
;
450 /* Values of those variables at last redisplay are stored as
451 properties on `overlay-arrow-position' symbol. However, if
452 Voverlay_arrow_position is a marker, last-arrow-position is its
453 numerical position. */
455 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
457 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
458 properties on a symbol in overlay-arrow-variable-list. */
460 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
462 /* Like mode-line-format, but for the title bar on a visible frame. */
464 Lisp_Object Vframe_title_format
;
466 /* Like mode-line-format, but for the title bar on an iconified frame. */
468 Lisp_Object Vicon_title_format
;
470 /* List of functions to call when a window's size changes. These
471 functions get one arg, a frame on which one or more windows' sizes
474 static Lisp_Object Vwindow_size_change_functions
;
476 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
478 /* Nonzero if an overlay arrow has been displayed in this window. */
480 static int overlay_arrow_seen
;
482 /* Nonzero means highlight the region even in nonselected windows. */
484 int highlight_nonselected_windows
;
486 /* If cursor motion alone moves point off frame, try scrolling this
487 many lines up or down if that will bring it back. */
489 static EMACS_INT scroll_step
;
491 /* Nonzero means scroll just far enough to bring point back on the
492 screen, when appropriate. */
494 static EMACS_INT scroll_conservatively
;
496 /* Recenter the window whenever point gets within this many lines of
497 the top or bottom of the window. This value is translated into a
498 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
499 that there is really a fixed pixel height scroll margin. */
501 EMACS_INT scroll_margin
;
503 /* Number of windows showing the buffer of the selected window (or
504 another buffer with the same base buffer). keyboard.c refers to
509 /* Vector containing glyphs for an ellipsis `...'. */
511 static Lisp_Object default_invis_vector
[3];
513 /* Zero means display the mode-line/header-line/menu-bar in the default face
514 (this slightly odd definition is for compatibility with previous versions
515 of emacs), non-zero means display them using their respective faces.
517 This variable is deprecated. */
519 int mode_line_inverse_video
;
521 /* Prompt to display in front of the mini-buffer contents. */
523 Lisp_Object minibuf_prompt
;
525 /* Width of current mini-buffer prompt. Only set after display_line
526 of the line that contains the prompt. */
528 int minibuf_prompt_width
;
530 /* This is the window where the echo area message was displayed. It
531 is always a mini-buffer window, but it may not be the same window
532 currently active as a mini-buffer. */
534 Lisp_Object echo_area_window
;
536 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
537 pushes the current message and the value of
538 message_enable_multibyte on the stack, the function restore_message
539 pops the stack and displays MESSAGE again. */
541 Lisp_Object Vmessage_stack
;
543 /* Nonzero means multibyte characters were enabled when the echo area
544 message was specified. */
546 int message_enable_multibyte
;
548 /* Nonzero if we should redraw the mode lines on the next redisplay. */
550 int update_mode_lines
;
552 /* Nonzero if window sizes or contents have changed since last
553 redisplay that finished. */
555 int windows_or_buffers_changed
;
557 /* Nonzero means a frame's cursor type has been changed. */
559 int cursor_type_changed
;
561 /* Nonzero after display_mode_line if %l was used and it displayed a
564 int line_number_displayed
;
566 /* Maximum buffer size for which to display line numbers. */
568 Lisp_Object Vline_number_display_limit
;
570 /* Line width to consider when repositioning for line number display. */
572 static EMACS_INT line_number_display_limit_width
;
574 /* Number of lines to keep in the message log buffer. t means
575 infinite. nil means don't log at all. */
577 Lisp_Object Vmessage_log_max
;
579 /* The name of the *Messages* buffer, a string. */
581 static Lisp_Object Vmessages_buffer_name
;
583 /* Current, index 0, and last displayed echo area message. Either
584 buffers from echo_buffers, or nil to indicate no message. */
586 Lisp_Object echo_area_buffer
[2];
588 /* The buffers referenced from echo_area_buffer. */
590 static Lisp_Object echo_buffer
[2];
592 /* A vector saved used in with_area_buffer to reduce consing. */
594 static Lisp_Object Vwith_echo_area_save_vector
;
596 /* Non-zero means display_echo_area should display the last echo area
597 message again. Set by redisplay_preserve_echo_area. */
599 static int display_last_displayed_message_p
;
601 /* Nonzero if echo area is being used by print; zero if being used by
604 int message_buf_print
;
606 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
608 Lisp_Object Qinhibit_menubar_update
;
609 int inhibit_menubar_update
;
611 /* When evaluating expressions from menu bar items (enable conditions,
612 for instance), this is the frame they are being processed for. */
614 Lisp_Object Vmenu_updating_frame
;
616 /* Maximum height for resizing mini-windows. Either a float
617 specifying a fraction of the available height, or an integer
618 specifying a number of lines. */
620 Lisp_Object Vmax_mini_window_height
;
622 /* Non-zero means messages should be displayed with truncated
623 lines instead of being continued. */
625 int message_truncate_lines
;
626 Lisp_Object Qmessage_truncate_lines
;
628 /* Set to 1 in clear_message to make redisplay_internal aware
629 of an emptied echo area. */
631 static int message_cleared_p
;
633 /* How to blink the default frame cursor off. */
634 Lisp_Object Vblink_cursor_alist
;
636 /* A scratch glyph row with contents used for generating truncation
637 glyphs. Also used in direct_output_for_insert. */
639 #define MAX_SCRATCH_GLYPHS 100
640 struct glyph_row scratch_glyph_row
;
641 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
643 /* Ascent and height of the last line processed by move_it_to. */
645 static int last_max_ascent
, last_height
;
647 /* Non-zero if there's a help-echo in the echo area. */
649 int help_echo_showing_p
;
651 /* If >= 0, computed, exact values of mode-line and header-line height
652 to use in the macros CURRENT_MODE_LINE_HEIGHT and
653 CURRENT_HEADER_LINE_HEIGHT. */
655 int current_mode_line_height
, current_header_line_height
;
657 /* The maximum distance to look ahead for text properties. Values
658 that are too small let us call compute_char_face and similar
659 functions too often which is expensive. Values that are too large
660 let us call compute_char_face and alike too often because we
661 might not be interested in text properties that far away. */
663 #define TEXT_PROP_DISTANCE_LIMIT 100
667 /* Variables to turn off display optimizations from Lisp. */
669 int inhibit_try_window_id
, inhibit_try_window_reusing
;
670 int inhibit_try_cursor_movement
;
672 /* Non-zero means print traces of redisplay if compiled with
675 int trace_redisplay_p
;
677 #endif /* GLYPH_DEBUG */
679 #ifdef DEBUG_TRACE_MOVE
680 /* Non-zero means trace with TRACE_MOVE to stderr. */
683 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
685 #define TRACE_MOVE(x) (void) 0
688 /* Non-zero means automatically scroll windows horizontally to make
691 int automatic_hscrolling_p
;
693 /* How close to the margin can point get before the window is scrolled
695 EMACS_INT hscroll_margin
;
697 /* How much to scroll horizontally when point is inside the above margin. */
698 Lisp_Object Vhscroll_step
;
700 /* The variable `resize-mini-windows'. If nil, don't resize
701 mini-windows. If t, always resize them to fit the text they
702 display. If `grow-only', let mini-windows grow only until they
705 Lisp_Object Vresize_mini_windows
;
707 /* Buffer being redisplayed -- for redisplay_window_error. */
709 struct buffer
*displayed_buffer
;
711 /* Space between overline and text. */
713 EMACS_INT overline_margin
;
715 /* Value returned from text property handlers (see below). */
720 HANDLED_RECOMPUTE_PROPS
,
721 HANDLED_OVERLAY_STRING_CONSUMED
,
725 /* A description of text properties that redisplay is interested
730 /* The name of the property. */
733 /* A unique index for the property. */
736 /* A handler function called to set up iterator IT from the property
737 at IT's current position. Value is used to steer handle_stop. */
738 enum prop_handled (*handler
) P_ ((struct it
*it
));
741 static enum prop_handled handle_face_prop
P_ ((struct it
*));
742 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
743 static enum prop_handled handle_display_prop
P_ ((struct it
*));
744 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
745 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
746 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
748 /* Properties handled by iterators. */
750 static struct props it_props
[] =
752 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
753 /* Handle `face' before `display' because some sub-properties of
754 `display' need to know the face. */
755 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
756 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
757 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
758 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
762 /* Value is the position described by X. If X is a marker, value is
763 the marker_position of X. Otherwise, value is X. */
765 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
767 /* Enumeration returned by some move_it_.* functions internally. */
771 /* Not used. Undefined value. */
774 /* Move ended at the requested buffer position or ZV. */
775 MOVE_POS_MATCH_OR_ZV
,
777 /* Move ended at the requested X pixel position. */
780 /* Move within a line ended at the end of a line that must be
784 /* Move within a line ended at the end of a line that would
785 be displayed truncated. */
788 /* Move within a line ended at a line end. */
792 /* This counter is used to clear the face cache every once in a while
793 in redisplay_internal. It is incremented for each redisplay.
794 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
797 #define CLEAR_FACE_CACHE_COUNT 500
798 static int clear_face_cache_count
;
800 /* Similarly for the image cache. */
802 #ifdef HAVE_WINDOW_SYSTEM
803 #define CLEAR_IMAGE_CACHE_COUNT 101
804 static int clear_image_cache_count
;
807 /* Non-zero while redisplay_internal is in progress. */
811 /* Non-zero means don't free realized faces. Bound while freeing
812 realized faces is dangerous because glyph matrices might still
815 int inhibit_free_realized_faces
;
816 Lisp_Object Qinhibit_free_realized_faces
;
818 /* If a string, XTread_socket generates an event to display that string.
819 (The display is done in read_char.) */
821 Lisp_Object help_echo_string
;
822 Lisp_Object help_echo_window
;
823 Lisp_Object help_echo_object
;
826 /* Temporary variable for XTread_socket. */
828 Lisp_Object previous_help_echo_string
;
830 /* Null glyph slice */
832 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
835 /* Function prototypes. */
837 static void setup_for_ellipsis
P_ ((struct it
*, int));
838 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
839 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
840 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
841 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
842 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
843 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
846 static int invisible_text_between_p
P_ ((struct it
*, int, int));
849 static void pint2str
P_ ((char *, int, int));
850 static void pint2hrstr
P_ ((char *, int, int));
851 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
853 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
854 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
855 static void store_mode_line_noprop_char
P_ ((char));
856 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
857 static void x_consider_frame_title
P_ ((Lisp_Object
));
858 static void handle_stop
P_ ((struct it
*));
859 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
860 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
861 static void ensure_echo_area_buffers
P_ ((void));
862 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
863 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
864 static int with_echo_area_buffer
P_ ((struct window
*, int,
865 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
866 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
867 static void clear_garbaged_frames
P_ ((void));
868 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
869 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
870 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
871 static int display_echo_area
P_ ((struct window
*));
872 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
873 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
874 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
875 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
876 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
878 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
879 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
880 static void insert_left_trunc_glyphs
P_ ((struct it
*));
881 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
883 static void extend_face_to_end_of_line
P_ ((struct it
*));
884 static int append_space_for_newline
P_ ((struct it
*, int));
885 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
886 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
887 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
888 static int trailing_whitespace_p
P_ ((int));
889 static int message_log_check_duplicate
P_ ((int, int, int, int));
890 static void push_it
P_ ((struct it
*));
891 static void pop_it
P_ ((struct it
*));
892 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
893 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
894 static void redisplay_internal
P_ ((int));
895 static int echo_area_display
P_ ((int));
896 static void redisplay_windows
P_ ((Lisp_Object
));
897 static void redisplay_window
P_ ((Lisp_Object
, int));
898 static Lisp_Object
redisplay_window_error ();
899 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
900 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
901 static int update_menu_bar
P_ ((struct frame
*, int, int));
902 static int try_window_reusing_current_matrix
P_ ((struct window
*));
903 static int try_window_id
P_ ((struct window
*));
904 static int display_line
P_ ((struct it
*));
905 static int display_mode_lines
P_ ((struct window
*));
906 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
907 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
908 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
909 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
910 static void display_menu_bar
P_ ((struct window
*));
911 static int display_count_lines
P_ ((int, int, int, int, int *));
912 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
913 int, int, struct it
*, int, int, int, int));
914 static void compute_line_metrics
P_ ((struct it
*));
915 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
916 static int get_overlay_strings
P_ ((struct it
*, int));
917 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
918 static void next_overlay_string
P_ ((struct it
*));
919 static void reseat
P_ ((struct it
*, struct text_pos
, int));
920 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
921 static void back_to_previous_visible_line_start
P_ ((struct it
*));
922 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
923 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
924 static int next_element_from_ellipsis
P_ ((struct it
*));
925 static int next_element_from_display_vector
P_ ((struct it
*));
926 static int next_element_from_string
P_ ((struct it
*));
927 static int next_element_from_c_string
P_ ((struct it
*));
928 static int next_element_from_buffer
P_ ((struct it
*));
929 static int next_element_from_composition
P_ ((struct it
*));
930 static int next_element_from_image
P_ ((struct it
*));
931 static int next_element_from_stretch
P_ ((struct it
*));
932 static void load_overlay_strings
P_ ((struct it
*, int));
933 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
934 struct display_pos
*));
935 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
936 Lisp_Object
, int, int, int, int));
937 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
939 void move_it_vertically_backward
P_ ((struct it
*, int));
940 static void init_to_row_start
P_ ((struct it
*, struct window
*,
941 struct glyph_row
*));
942 static int init_to_row_end
P_ ((struct it
*, struct window
*,
943 struct glyph_row
*));
944 static void back_to_previous_line_start
P_ ((struct it
*));
945 static int forward_to_next_line_start
P_ ((struct it
*, int *));
946 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
948 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
949 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
950 static int number_of_chars
P_ ((unsigned char *, int));
951 static void compute_stop_pos
P_ ((struct it
*));
952 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
954 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
955 static int next_overlay_change
P_ ((int));
956 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
957 Lisp_Object
, Lisp_Object
,
958 struct text_pos
*, int));
959 static int underlying_face_id
P_ ((struct it
*));
960 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
963 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
964 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
966 #ifdef HAVE_WINDOW_SYSTEM
968 static void update_tool_bar
P_ ((struct frame
*, int));
969 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
970 static int redisplay_tool_bar
P_ ((struct frame
*));
971 static void display_tool_bar_line
P_ ((struct it
*, int));
972 static void notice_overwritten_cursor
P_ ((struct window
*,
974 int, int, int, int));
978 #endif /* HAVE_WINDOW_SYSTEM */
981 /***********************************************************************
982 Window display dimensions
983 ***********************************************************************/
985 /* Return the bottom boundary y-position for text lines in window W.
986 This is the first y position at which a line cannot start.
987 It is relative to the top of the window.
989 This is the height of W minus the height of a mode line, if any. */
992 window_text_bottom_y (w
)
995 int height
= WINDOW_TOTAL_HEIGHT (w
);
997 if (WINDOW_WANTS_MODELINE_P (w
))
998 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1002 /* Return the pixel width of display area AREA of window W. AREA < 0
1003 means return the total width of W, not including fringes to
1004 the left and right of the window. */
1007 window_box_width (w
, area
)
1011 int cols
= XFASTINT (w
->total_cols
);
1014 if (!w
->pseudo_window_p
)
1016 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1018 if (area
== TEXT_AREA
)
1020 if (INTEGERP (w
->left_margin_cols
))
1021 cols
-= XFASTINT (w
->left_margin_cols
);
1022 if (INTEGERP (w
->right_margin_cols
))
1023 cols
-= XFASTINT (w
->right_margin_cols
);
1024 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1026 else if (area
== LEFT_MARGIN_AREA
)
1028 cols
= (INTEGERP (w
->left_margin_cols
)
1029 ? XFASTINT (w
->left_margin_cols
) : 0);
1032 else if (area
== RIGHT_MARGIN_AREA
)
1034 cols
= (INTEGERP (w
->right_margin_cols
)
1035 ? XFASTINT (w
->right_margin_cols
) : 0);
1040 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1044 /* Return the pixel height of the display area of window W, not
1045 including mode lines of W, if any. */
1048 window_box_height (w
)
1051 struct frame
*f
= XFRAME (w
->frame
);
1052 int height
= WINDOW_TOTAL_HEIGHT (w
);
1054 xassert (height
>= 0);
1056 /* Note: the code below that determines the mode-line/header-line
1057 height is essentially the same as that contained in the macro
1058 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1059 the appropriate glyph row has its `mode_line_p' flag set,
1060 and if it doesn't, uses estimate_mode_line_height instead. */
1062 if (WINDOW_WANTS_MODELINE_P (w
))
1064 struct glyph_row
*ml_row
1065 = (w
->current_matrix
&& w
->current_matrix
->rows
1066 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1068 if (ml_row
&& ml_row
->mode_line_p
)
1069 height
-= ml_row
->height
;
1071 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1074 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1076 struct glyph_row
*hl_row
1077 = (w
->current_matrix
&& w
->current_matrix
->rows
1078 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1080 if (hl_row
&& hl_row
->mode_line_p
)
1081 height
-= hl_row
->height
;
1083 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1086 /* With a very small font and a mode-line that's taller than
1087 default, we might end up with a negative height. */
1088 return max (0, height
);
1091 /* Return the window-relative coordinate of the left edge of display
1092 area AREA of window W. AREA < 0 means return the left edge of the
1093 whole window, to the right of the left fringe of W. */
1096 window_box_left_offset (w
, area
)
1102 if (w
->pseudo_window_p
)
1105 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1107 if (area
== TEXT_AREA
)
1108 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1109 + window_box_width (w
, LEFT_MARGIN_AREA
));
1110 else if (area
== RIGHT_MARGIN_AREA
)
1111 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1112 + window_box_width (w
, LEFT_MARGIN_AREA
)
1113 + window_box_width (w
, TEXT_AREA
)
1114 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1116 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1117 else if (area
== LEFT_MARGIN_AREA
1118 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1119 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1125 /* Return the window-relative coordinate of the right edge of display
1126 area AREA of window W. AREA < 0 means return the left edge of the
1127 whole window, to the left of the right fringe of W. */
1130 window_box_right_offset (w
, area
)
1134 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1137 /* Return the frame-relative coordinate of the left edge of display
1138 area AREA of window W. AREA < 0 means return the left edge of the
1139 whole window, to the right of the left fringe of W. */
1142 window_box_left (w
, area
)
1146 struct frame
*f
= XFRAME (w
->frame
);
1149 if (w
->pseudo_window_p
)
1150 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1152 x
= (WINDOW_LEFT_EDGE_X (w
)
1153 + window_box_left_offset (w
, area
));
1159 /* Return the frame-relative coordinate of the right edge of display
1160 area AREA of window W. AREA < 0 means return the left edge of the
1161 whole window, to the left of the right fringe of W. */
1164 window_box_right (w
, area
)
1168 return window_box_left (w
, area
) + window_box_width (w
, area
);
1171 /* Get the bounding box of the display area AREA of window W, without
1172 mode lines, in frame-relative coordinates. AREA < 0 means the
1173 whole window, not including the left and right fringes of
1174 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1175 coordinates of the upper-left corner of the box. Return in
1176 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1179 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1182 int *box_x
, *box_y
, *box_width
, *box_height
;
1185 *box_width
= window_box_width (w
, area
);
1187 *box_height
= window_box_height (w
);
1189 *box_x
= window_box_left (w
, area
);
1192 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1193 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1194 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1199 /* Get the bounding box of the display area AREA of window W, without
1200 mode lines. AREA < 0 means the whole window, not including the
1201 left and right fringe of the window. Return in *TOP_LEFT_X
1202 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1203 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1204 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1208 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1209 bottom_right_x
, bottom_right_y
)
1212 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1214 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1216 *bottom_right_x
+= *top_left_x
;
1217 *bottom_right_y
+= *top_left_y
;
1222 /***********************************************************************
1224 ***********************************************************************/
1226 /* Return the bottom y-position of the line the iterator IT is in.
1227 This can modify IT's settings. */
1233 int line_height
= it
->max_ascent
+ it
->max_descent
;
1234 int line_top_y
= it
->current_y
;
1236 if (line_height
== 0)
1239 line_height
= last_height
;
1240 else if (IT_CHARPOS (*it
) < ZV
)
1242 move_it_by_lines (it
, 1, 1);
1243 line_height
= (it
->max_ascent
|| it
->max_descent
1244 ? it
->max_ascent
+ it
->max_descent
1249 struct glyph_row
*row
= it
->glyph_row
;
1251 /* Use the default character height. */
1252 it
->glyph_row
= NULL
;
1253 it
->what
= IT_CHARACTER
;
1256 PRODUCE_GLYPHS (it
);
1257 line_height
= it
->ascent
+ it
->descent
;
1258 it
->glyph_row
= row
;
1262 return line_top_y
+ line_height
;
1266 /* Return 1 if position CHARPOS is visible in window W.
1267 CHARPOS < 0 means return info about WINDOW_END position.
1268 If visible, set *X and *Y to pixel coordinates of top left corner.
1269 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1270 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1273 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1275 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1278 struct text_pos top
;
1280 struct buffer
*old_buffer
= NULL
;
1285 if (XBUFFER (w
->buffer
) != current_buffer
)
1287 old_buffer
= current_buffer
;
1288 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1291 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1293 /* Compute exact mode line heights. */
1294 if (WINDOW_WANTS_MODELINE_P (w
))
1295 current_mode_line_height
1296 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1297 current_buffer
->mode_line_format
);
1299 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1300 current_header_line_height
1301 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1302 current_buffer
->header_line_format
);
1304 start_display (&it
, w
, top
);
1305 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1306 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1308 /* Note that we may overshoot because of invisible text. */
1309 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1311 int top_x
= it
.current_x
;
1312 int top_y
= it
.current_y
;
1313 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1314 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1316 if (top_y
< window_top_y
)
1317 visible_p
= bottom_y
> window_top_y
;
1318 else if (top_y
< it
.last_visible_y
)
1323 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1324 *rtop
= max (0, window_top_y
- top_y
);
1325 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1326 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1327 - max (top_y
, window_top_y
)));
1336 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1337 move_it_by_lines (&it
, 1, 0);
1338 if (charpos
< IT_CHARPOS (it
)
1339 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1342 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1344 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1345 *rtop
= max (0, -it2
.current_y
);
1346 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1347 - it
.last_visible_y
));
1348 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1350 - max (it2
.current_y
,
1351 WINDOW_HEADER_LINE_HEIGHT (w
))));
1357 set_buffer_internal_1 (old_buffer
);
1359 current_header_line_height
= current_mode_line_height
= -1;
1361 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1362 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1365 /* Debugging code. */
1367 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1368 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1370 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1377 /* Return the next character from STR which is MAXLEN bytes long.
1378 Return in *LEN the length of the character. This is like
1379 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1380 we find one, we return a `?', but with the length of the invalid
1384 string_char_and_length (str
, maxlen
, len
)
1385 const unsigned char *str
;
1390 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1391 if (!CHAR_VALID_P (c
, 1))
1392 /* We may not change the length here because other places in Emacs
1393 don't use this function, i.e. they silently accept invalid
1402 /* Given a position POS containing a valid character and byte position
1403 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1405 static struct text_pos
1406 string_pos_nchars_ahead (pos
, string
, nchars
)
1407 struct text_pos pos
;
1411 xassert (STRINGP (string
) && nchars
>= 0);
1413 if (STRING_MULTIBYTE (string
))
1415 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1416 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1421 string_char_and_length (p
, rest
, &len
);
1422 p
+= len
, rest
-= len
;
1423 xassert (rest
>= 0);
1425 BYTEPOS (pos
) += len
;
1429 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1435 /* Value is the text position, i.e. character and byte position,
1436 for character position CHARPOS in STRING. */
1438 static INLINE
struct text_pos
1439 string_pos (charpos
, string
)
1443 struct text_pos pos
;
1444 xassert (STRINGP (string
));
1445 xassert (charpos
>= 0);
1446 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1451 /* Value is a text position, i.e. character and byte position, for
1452 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1453 means recognize multibyte characters. */
1455 static struct text_pos
1456 c_string_pos (charpos
, s
, multibyte_p
)
1461 struct text_pos pos
;
1463 xassert (s
!= NULL
);
1464 xassert (charpos
>= 0);
1468 int rest
= strlen (s
), len
;
1470 SET_TEXT_POS (pos
, 0, 0);
1473 string_char_and_length (s
, rest
, &len
);
1474 s
+= len
, rest
-= len
;
1475 xassert (rest
>= 0);
1477 BYTEPOS (pos
) += len
;
1481 SET_TEXT_POS (pos
, charpos
, charpos
);
1487 /* Value is the number of characters in C string S. MULTIBYTE_P
1488 non-zero means recognize multibyte characters. */
1491 number_of_chars (s
, multibyte_p
)
1499 int rest
= strlen (s
), len
;
1500 unsigned char *p
= (unsigned char *) s
;
1502 for (nchars
= 0; rest
> 0; ++nchars
)
1504 string_char_and_length (p
, rest
, &len
);
1505 rest
-= len
, p
+= len
;
1509 nchars
= strlen (s
);
1515 /* Compute byte position NEWPOS->bytepos corresponding to
1516 NEWPOS->charpos. POS is a known position in string STRING.
1517 NEWPOS->charpos must be >= POS.charpos. */
1520 compute_string_pos (newpos
, pos
, string
)
1521 struct text_pos
*newpos
, pos
;
1524 xassert (STRINGP (string
));
1525 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1527 if (STRING_MULTIBYTE (string
))
1528 *newpos
= string_pos_nchars_ahead (pos
, string
,
1529 CHARPOS (*newpos
) - CHARPOS (pos
));
1531 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1535 Return an estimation of the pixel height of mode or top lines on
1536 frame F. FACE_ID specifies what line's height to estimate. */
1539 estimate_mode_line_height (f
, face_id
)
1541 enum face_id face_id
;
1543 #ifdef HAVE_WINDOW_SYSTEM
1544 if (FRAME_WINDOW_P (f
))
1546 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1548 /* This function is called so early when Emacs starts that the face
1549 cache and mode line face are not yet initialized. */
1550 if (FRAME_FACE_CACHE (f
))
1552 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1556 height
= FONT_HEIGHT (face
->font
);
1557 if (face
->box_line_width
> 0)
1558 height
+= 2 * face
->box_line_width
;
1569 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1570 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1571 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1572 not force the value into range. */
1575 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1577 register int pix_x
, pix_y
;
1579 NativeRectangle
*bounds
;
1583 #ifdef HAVE_WINDOW_SYSTEM
1584 if (FRAME_WINDOW_P (f
))
1586 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1587 even for negative values. */
1589 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1591 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1593 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1594 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1597 STORE_NATIVE_RECT (*bounds
,
1598 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1599 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1600 FRAME_COLUMN_WIDTH (f
) - 1,
1601 FRAME_LINE_HEIGHT (f
) - 1);
1607 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1608 pix_x
= FRAME_TOTAL_COLS (f
);
1612 else if (pix_y
> FRAME_LINES (f
))
1613 pix_y
= FRAME_LINES (f
);
1623 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1624 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1625 can't tell the positions because W's display is not up to date,
1629 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1632 int *frame_x
, *frame_y
;
1634 #ifdef HAVE_WINDOW_SYSTEM
1635 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1639 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1640 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1642 if (display_completed
)
1644 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1645 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1646 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1652 hpos
+= glyph
->pixel_width
;
1656 /* If first glyph is partially visible, its first visible position is still 0. */
1668 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1669 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1680 #ifdef HAVE_WINDOW_SYSTEM
1682 /* Find the glyph under window-relative coordinates X/Y in window W.
1683 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1684 strings. Return in *HPOS and *VPOS the row and column number of
1685 the glyph found. Return in *AREA the glyph area containing X.
1686 Value is a pointer to the glyph found or null if X/Y is not on
1687 text, or we can't tell because W's current matrix is not up to
1690 static struct glyph
*
1691 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1694 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1696 struct glyph
*glyph
, *end
;
1697 struct glyph_row
*row
= NULL
;
1700 /* Find row containing Y. Give up if some row is not enabled. */
1701 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1703 row
= MATRIX_ROW (w
->current_matrix
, i
);
1704 if (!row
->enabled_p
)
1706 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1713 /* Give up if Y is not in the window. */
1714 if (i
== w
->current_matrix
->nrows
)
1717 /* Get the glyph area containing X. */
1718 if (w
->pseudo_window_p
)
1725 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1727 *area
= LEFT_MARGIN_AREA
;
1728 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1730 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1733 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1737 *area
= RIGHT_MARGIN_AREA
;
1738 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1742 /* Find glyph containing X. */
1743 glyph
= row
->glyphs
[*area
];
1744 end
= glyph
+ row
->used
[*area
];
1746 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1748 x
-= glyph
->pixel_width
;
1758 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1761 *hpos
= glyph
- row
->glyphs
[*area
];
1767 Convert frame-relative x/y to coordinates relative to window W.
1768 Takes pseudo-windows into account. */
1771 frame_to_window_pixel_xy (w
, x
, y
)
1775 if (w
->pseudo_window_p
)
1777 /* A pseudo-window is always full-width, and starts at the
1778 left edge of the frame, plus a frame border. */
1779 struct frame
*f
= XFRAME (w
->frame
);
1780 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1781 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1785 *x
-= WINDOW_LEFT_EDGE_X (w
);
1786 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1791 Return in RECTS[] at most N clipping rectangles for glyph string S.
1792 Return the number of stored rectangles. */
1795 get_glyph_string_clip_rects (s
, rects
, n
)
1796 struct glyph_string
*s
;
1797 NativeRectangle
*rects
;
1805 if (s
->row
->full_width_p
)
1807 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1808 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1809 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1811 /* Unless displaying a mode or menu bar line, which are always
1812 fully visible, clip to the visible part of the row. */
1813 if (s
->w
->pseudo_window_p
)
1814 r
.height
= s
->row
->visible_height
;
1816 r
.height
= s
->height
;
1820 /* This is a text line that may be partially visible. */
1821 r
.x
= window_box_left (s
->w
, s
->area
);
1822 r
.width
= window_box_width (s
->w
, s
->area
);
1823 r
.height
= s
->row
->visible_height
;
1827 if (r
.x
< s
->clip_head
->x
)
1829 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1830 r
.width
-= s
->clip_head
->x
- r
.x
;
1833 r
.x
= s
->clip_head
->x
;
1836 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1838 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1839 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1844 /* If S draws overlapping rows, it's sufficient to use the top and
1845 bottom of the window for clipping because this glyph string
1846 intentionally draws over other lines. */
1847 if (s
->for_overlaps
)
1849 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1850 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1852 /* Alas, the above simple strategy does not work for the
1853 environments with anti-aliased text: if the same text is
1854 drawn onto the same place multiple times, it gets thicker.
1855 If the overlap we are processing is for the erased cursor, we
1856 take the intersection with the rectagle of the cursor. */
1857 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1859 XRectangle rc
, r_save
= r
;
1861 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1862 rc
.y
= s
->w
->phys_cursor
.y
;
1863 rc
.width
= s
->w
->phys_cursor_width
;
1864 rc
.height
= s
->w
->phys_cursor_height
;
1866 x_intersect_rectangles (&r_save
, &rc
, &r
);
1871 /* Don't use S->y for clipping because it doesn't take partially
1872 visible lines into account. For example, it can be negative for
1873 partially visible lines at the top of a window. */
1874 if (!s
->row
->full_width_p
1875 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1876 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1878 r
.y
= max (0, s
->row
->y
);
1880 /* If drawing a tool-bar window, draw it over the internal border
1881 at the top of the window. */
1882 if (WINDOWP (s
->f
->tool_bar_window
)
1883 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1884 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1887 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1889 /* If drawing the cursor, don't let glyph draw outside its
1890 advertised boundaries. Cleartype does this under some circumstances. */
1891 if (s
->hl
== DRAW_CURSOR
)
1893 struct glyph
*glyph
= s
->first_glyph
;
1898 r
.width
-= s
->x
- r
.x
;
1901 r
.width
= min (r
.width
, glyph
->pixel_width
);
1903 /* If r.y is below window bottom, ensure that we still see a cursor. */
1904 height
= min (glyph
->ascent
+ glyph
->descent
,
1905 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1906 max_y
= window_text_bottom_y (s
->w
) - height
;
1907 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1908 if (s
->ybase
- glyph
->ascent
> max_y
)
1915 /* Don't draw cursor glyph taller than our actual glyph. */
1916 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1917 if (height
< r
.height
)
1919 max_y
= r
.y
+ r
.height
;
1920 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1921 r
.height
= min (max_y
- r
.y
, height
);
1926 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1927 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1929 #ifdef CONVERT_FROM_XRECT
1930 CONVERT_FROM_XRECT (r
, *rects
);
1938 /* If we are processing overlapping and allowed to return
1939 multiple clipping rectangles, we exclude the row of the glyph
1940 string from the clipping rectangle. This is to avoid drawing
1941 the same text on the environment with anti-aliasing. */
1942 #ifdef CONVERT_FROM_XRECT
1945 XRectangle
*rs
= rects
;
1947 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
1949 if (s
->for_overlaps
& OVERLAPS_PRED
)
1952 if (r
.y
+ r
.height
> row_y
)
1955 rs
[i
].height
= row_y
- r
.y
;
1961 if (s
->for_overlaps
& OVERLAPS_SUCC
)
1964 if (r
.y
< row_y
+ s
->row
->visible_height
)
1966 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
1968 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
1969 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
1978 #ifdef CONVERT_FROM_XRECT
1979 for (i
= 0; i
< n
; i
++)
1980 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
1987 Return in *NR the clipping rectangle for glyph string S. */
1990 get_glyph_string_clip_rect (s
, nr
)
1991 struct glyph_string
*s
;
1992 NativeRectangle
*nr
;
1994 get_glyph_string_clip_rects (s
, nr
, 1);
1999 Return the position and height of the phys cursor in window W.
2000 Set w->phys_cursor_width to width of phys cursor.
2004 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2006 struct glyph_row
*row
;
2007 struct glyph
*glyph
;
2008 int *xp
, *yp
, *heightp
;
2010 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2011 int x
, y
, wd
, h
, h0
, y0
;
2013 /* Compute the width of the rectangle to draw. If on a stretch
2014 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2015 rectangle as wide as the glyph, but use a canonical character
2017 wd
= glyph
->pixel_width
- 1;
2022 x
= w
->phys_cursor
.x
;
2029 if (glyph
->type
== STRETCH_GLYPH
2030 && !x_stretch_cursor_p
)
2031 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2032 w
->phys_cursor_width
= wd
;
2034 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2036 /* If y is below window bottom, ensure that we still see a cursor. */
2037 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2039 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2040 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2042 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2045 h
= max (h
- (y0
- y
) + 1, h0
);
2050 y0
= window_text_bottom_y (w
) - h0
;
2058 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2059 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2064 * Remember which glyph the mouse is over.
2068 remember_mouse_glyph (f
, gx
, gy
, rect
)
2071 NativeRectangle
*rect
;
2075 struct glyph_row
*r
, *gr
, *end_row
;
2076 enum window_part part
;
2077 enum glyph_row_area area
;
2078 int x
, y
, width
, height
;
2080 /* Try to determine frame pixel position and size of the glyph under
2081 frame pixel coordinates X/Y on frame F. */
2083 if (!f
->glyphs_initialized_p
2084 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2087 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2088 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2092 w
= XWINDOW (window
);
2093 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2094 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2096 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2097 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2099 if (w
->pseudo_window_p
)
2102 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2108 case ON_LEFT_MARGIN
:
2109 area
= LEFT_MARGIN_AREA
;
2112 case ON_RIGHT_MARGIN
:
2113 area
= RIGHT_MARGIN_AREA
;
2116 case ON_HEADER_LINE
:
2118 gr
= (part
== ON_HEADER_LINE
2119 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2120 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2123 goto text_glyph_row_found
;
2130 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2131 if (r
->y
+ r
->height
> y
)
2137 text_glyph_row_found
:
2140 struct glyph
*g
= gr
->glyphs
[area
];
2141 struct glyph
*end
= g
+ gr
->used
[area
];
2143 height
= gr
->height
;
2144 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2145 if (gx
+ g
->pixel_width
> x
)
2150 if (g
->type
== IMAGE_GLYPH
)
2152 /* Don't remember when mouse is over image, as
2153 image may have hot-spots. */
2154 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2157 width
= g
->pixel_width
;
2161 /* Use nominal char spacing at end of line. */
2163 gx
+= (x
/ width
) * width
;
2166 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2167 gx
+= window_box_left_offset (w
, area
);
2171 /* Use nominal line height at end of window. */
2172 gx
= (x
/ width
) * width
;
2174 gy
+= (y
/ height
) * height
;
2178 case ON_LEFT_FRINGE
:
2179 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2180 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2181 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2182 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2185 case ON_RIGHT_FRINGE
:
2186 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2187 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2188 : window_box_right_offset (w
, TEXT_AREA
));
2189 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2193 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2195 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2196 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2197 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2199 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2203 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2204 if (r
->y
+ r
->height
> y
)
2211 height
= gr
->height
;
2214 /* Use nominal line height at end of window. */
2216 gy
+= (y
/ height
) * height
;
2223 /* If there is no glyph under the mouse, then we divide the screen
2224 into a grid of the smallest glyph in the frame, and use that
2227 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2228 round down even for negative values. */
2234 gx
= (gx
/ width
) * width
;
2235 gy
= (gy
/ height
) * height
;
2240 gx
+= WINDOW_LEFT_EDGE_X (w
);
2241 gy
+= WINDOW_TOP_EDGE_Y (w
);
2244 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2246 /* Visible feedback for debugging. */
2249 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2250 f
->output_data
.x
->normal_gc
,
2251 gx
, gy
, width
, height
);
2257 #endif /* HAVE_WINDOW_SYSTEM */
2260 /***********************************************************************
2261 Lisp form evaluation
2262 ***********************************************************************/
2264 /* Error handler for safe_eval and safe_call. */
2267 safe_eval_handler (arg
)
2270 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2275 /* Evaluate SEXPR and return the result, or nil if something went
2276 wrong. Prevent redisplay during the evaluation. */
2284 if (inhibit_eval_during_redisplay
)
2288 int count
= SPECPDL_INDEX ();
2289 struct gcpro gcpro1
;
2292 specbind (Qinhibit_redisplay
, Qt
);
2293 /* Use Qt to ensure debugger does not run,
2294 so there is no possibility of wanting to redisplay. */
2295 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
2298 val
= unbind_to (count
, val
);
2305 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2306 Return the result, or nil if something went wrong. Prevent
2307 redisplay during the evaluation. */
2310 safe_call (nargs
, args
)
2316 if (inhibit_eval_during_redisplay
)
2320 int count
= SPECPDL_INDEX ();
2321 struct gcpro gcpro1
;
2324 gcpro1
.nvars
= nargs
;
2325 specbind (Qinhibit_redisplay
, Qt
);
2326 /* Use Qt to ensure debugger does not run,
2327 so there is no possibility of wanting to redisplay. */
2328 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2331 val
= unbind_to (count
, val
);
2338 /* Call function FN with one argument ARG.
2339 Return the result, or nil if something went wrong. */
2342 safe_call1 (fn
, arg
)
2343 Lisp_Object fn
, arg
;
2345 Lisp_Object args
[2];
2348 return safe_call (2, args
);
2353 /***********************************************************************
2355 ***********************************************************************/
2359 /* Define CHECK_IT to perform sanity checks on iterators.
2360 This is for debugging. It is too slow to do unconditionally. */
2366 if (it
->method
== GET_FROM_STRING
)
2368 xassert (STRINGP (it
->string
));
2369 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2373 xassert (IT_STRING_CHARPOS (*it
) < 0);
2374 if (it
->method
== GET_FROM_BUFFER
)
2376 /* Check that character and byte positions agree. */
2377 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2382 xassert (it
->current
.dpvec_index
>= 0);
2384 xassert (it
->current
.dpvec_index
< 0);
2387 #define CHECK_IT(IT) check_it ((IT))
2391 #define CHECK_IT(IT) (void) 0
2398 /* Check that the window end of window W is what we expect it
2399 to be---the last row in the current matrix displaying text. */
2402 check_window_end (w
)
2405 if (!MINI_WINDOW_P (w
)
2406 && !NILP (w
->window_end_valid
))
2408 struct glyph_row
*row
;
2409 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2410 XFASTINT (w
->window_end_vpos
)),
2412 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2413 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2417 #define CHECK_WINDOW_END(W) check_window_end ((W))
2419 #else /* not GLYPH_DEBUG */
2421 #define CHECK_WINDOW_END(W) (void) 0
2423 #endif /* not GLYPH_DEBUG */
2427 /***********************************************************************
2428 Iterator initialization
2429 ***********************************************************************/
2431 /* Initialize IT for displaying current_buffer in window W, starting
2432 at character position CHARPOS. CHARPOS < 0 means that no buffer
2433 position is specified which is useful when the iterator is assigned
2434 a position later. BYTEPOS is the byte position corresponding to
2435 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2437 If ROW is not null, calls to produce_glyphs with IT as parameter
2438 will produce glyphs in that row.
2440 BASE_FACE_ID is the id of a base face to use. It must be one of
2441 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2442 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2443 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2445 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2446 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2447 will be initialized to use the corresponding mode line glyph row of
2448 the desired matrix of W. */
2451 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2454 int charpos
, bytepos
;
2455 struct glyph_row
*row
;
2456 enum face_id base_face_id
;
2458 int highlight_region_p
;
2460 /* Some precondition checks. */
2461 xassert (w
!= NULL
&& it
!= NULL
);
2462 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2465 /* If face attributes have been changed since the last redisplay,
2466 free realized faces now because they depend on face definitions
2467 that might have changed. Don't free faces while there might be
2468 desired matrices pending which reference these faces. */
2469 if (face_change_count
&& !inhibit_free_realized_faces
)
2471 face_change_count
= 0;
2472 free_all_realized_faces (Qnil
);
2475 /* Use one of the mode line rows of W's desired matrix if
2479 if (base_face_id
== MODE_LINE_FACE_ID
2480 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2481 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2482 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2483 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2487 bzero (it
, sizeof *it
);
2488 it
->current
.overlay_string_index
= -1;
2489 it
->current
.dpvec_index
= -1;
2490 it
->base_face_id
= base_face_id
;
2492 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2494 /* The window in which we iterate over current_buffer: */
2495 XSETWINDOW (it
->window
, w
);
2497 it
->f
= XFRAME (w
->frame
);
2499 /* Extra space between lines (on window systems only). */
2500 if (base_face_id
== DEFAULT_FACE_ID
2501 && FRAME_WINDOW_P (it
->f
))
2503 if (NATNUMP (current_buffer
->extra_line_spacing
))
2504 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2505 else if (FLOATP (current_buffer
->extra_line_spacing
))
2506 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2507 * FRAME_LINE_HEIGHT (it
->f
));
2508 else if (it
->f
->extra_line_spacing
> 0)
2509 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2510 it
->max_extra_line_spacing
= 0;
2513 /* If realized faces have been removed, e.g. because of face
2514 attribute changes of named faces, recompute them. When running
2515 in batch mode, the face cache of the initial frame is null. If
2516 we happen to get called, make a dummy face cache. */
2517 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2518 init_frame_faces (it
->f
);
2519 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2520 recompute_basic_faces (it
->f
);
2522 /* Current value of the `slice', `space-width', and 'height' properties. */
2523 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2524 it
->space_width
= Qnil
;
2525 it
->font_height
= Qnil
;
2526 it
->override_ascent
= -1;
2528 /* Are control characters displayed as `^C'? */
2529 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2531 /* -1 means everything between a CR and the following line end
2532 is invisible. >0 means lines indented more than this value are
2534 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2535 ? XFASTINT (current_buffer
->selective_display
)
2536 : (!NILP (current_buffer
->selective_display
)
2538 it
->selective_display_ellipsis_p
2539 = !NILP (current_buffer
->selective_display_ellipses
);
2541 /* Display table to use. */
2542 it
->dp
= window_display_table (w
);
2544 /* Are multibyte characters enabled in current_buffer? */
2545 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2547 /* Non-zero if we should highlight the region. */
2549 = (!NILP (Vtransient_mark_mode
)
2550 && !NILP (current_buffer
->mark_active
)
2551 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2553 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2554 start and end of a visible region in window IT->w. Set both to
2555 -1 to indicate no region. */
2556 if (highlight_region_p
2557 /* Maybe highlight only in selected window. */
2558 && (/* Either show region everywhere. */
2559 highlight_nonselected_windows
2560 /* Or show region in the selected window. */
2561 || w
== XWINDOW (selected_window
)
2562 /* Or show the region if we are in the mini-buffer and W is
2563 the window the mini-buffer refers to. */
2564 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2565 && WINDOWP (minibuf_selected_window
)
2566 && w
== XWINDOW (minibuf_selected_window
))))
2568 int charpos
= marker_position (current_buffer
->mark
);
2569 it
->region_beg_charpos
= min (PT
, charpos
);
2570 it
->region_end_charpos
= max (PT
, charpos
);
2573 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2575 /* Get the position at which the redisplay_end_trigger hook should
2576 be run, if it is to be run at all. */
2577 if (MARKERP (w
->redisplay_end_trigger
)
2578 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2579 it
->redisplay_end_trigger_charpos
2580 = marker_position (w
->redisplay_end_trigger
);
2581 else if (INTEGERP (w
->redisplay_end_trigger
))
2582 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2584 /* Correct bogus values of tab_width. */
2585 it
->tab_width
= XINT (current_buffer
->tab_width
);
2586 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2589 /* Are lines in the display truncated? */
2590 it
->truncate_lines_p
2591 = (base_face_id
!= DEFAULT_FACE_ID
2592 || XINT (it
->w
->hscroll
)
2593 || (truncate_partial_width_windows
2594 && !WINDOW_FULL_WIDTH_P (it
->w
))
2595 || !NILP (current_buffer
->truncate_lines
));
2597 /* Get dimensions of truncation and continuation glyphs. These are
2598 displayed as fringe bitmaps under X, so we don't need them for such
2600 if (!FRAME_WINDOW_P (it
->f
))
2602 if (it
->truncate_lines_p
)
2604 /* We will need the truncation glyph. */
2605 xassert (it
->glyph_row
== NULL
);
2606 produce_special_glyphs (it
, IT_TRUNCATION
);
2607 it
->truncation_pixel_width
= it
->pixel_width
;
2611 /* We will need the continuation glyph. */
2612 xassert (it
->glyph_row
== NULL
);
2613 produce_special_glyphs (it
, IT_CONTINUATION
);
2614 it
->continuation_pixel_width
= it
->pixel_width
;
2617 /* Reset these values to zero because the produce_special_glyphs
2618 above has changed them. */
2619 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2620 it
->phys_ascent
= it
->phys_descent
= 0;
2623 /* Set this after getting the dimensions of truncation and
2624 continuation glyphs, so that we don't produce glyphs when calling
2625 produce_special_glyphs, above. */
2626 it
->glyph_row
= row
;
2627 it
->area
= TEXT_AREA
;
2629 /* Get the dimensions of the display area. The display area
2630 consists of the visible window area plus a horizontally scrolled
2631 part to the left of the window. All x-values are relative to the
2632 start of this total display area. */
2633 if (base_face_id
!= DEFAULT_FACE_ID
)
2635 /* Mode lines, menu bar in terminal frames. */
2636 it
->first_visible_x
= 0;
2637 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2642 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2643 it
->last_visible_x
= (it
->first_visible_x
2644 + window_box_width (w
, TEXT_AREA
));
2646 /* If we truncate lines, leave room for the truncator glyph(s) at
2647 the right margin. Otherwise, leave room for the continuation
2648 glyph(s). Truncation and continuation glyphs are not inserted
2649 for window-based redisplay. */
2650 if (!FRAME_WINDOW_P (it
->f
))
2652 if (it
->truncate_lines_p
)
2653 it
->last_visible_x
-= it
->truncation_pixel_width
;
2655 it
->last_visible_x
-= it
->continuation_pixel_width
;
2658 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2659 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2662 /* Leave room for a border glyph. */
2663 if (!FRAME_WINDOW_P (it
->f
)
2664 && !WINDOW_RIGHTMOST_P (it
->w
))
2665 it
->last_visible_x
-= 1;
2667 it
->last_visible_y
= window_text_bottom_y (w
);
2669 /* For mode lines and alike, arrange for the first glyph having a
2670 left box line if the face specifies a box. */
2671 if (base_face_id
!= DEFAULT_FACE_ID
)
2675 it
->face_id
= base_face_id
;
2677 /* If we have a boxed mode line, make the first character appear
2678 with a left box line. */
2679 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2680 if (face
->box
!= FACE_NO_BOX
)
2681 it
->start_of_box_run_p
= 1;
2684 /* If a buffer position was specified, set the iterator there,
2685 getting overlays and face properties from that position. */
2686 if (charpos
>= BUF_BEG (current_buffer
))
2688 it
->end_charpos
= ZV
;
2690 IT_CHARPOS (*it
) = charpos
;
2692 /* Compute byte position if not specified. */
2693 if (bytepos
< charpos
)
2694 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2696 IT_BYTEPOS (*it
) = bytepos
;
2698 it
->start
= it
->current
;
2700 /* Compute faces etc. */
2701 reseat (it
, it
->current
.pos
, 1);
2708 /* Initialize IT for the display of window W with window start POS. */
2711 start_display (it
, w
, pos
)
2714 struct text_pos pos
;
2716 struct glyph_row
*row
;
2717 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2719 row
= w
->desired_matrix
->rows
+ first_vpos
;
2720 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2721 it
->first_vpos
= first_vpos
;
2723 /* Don't reseat to previous visible line start if current start
2724 position is in a string or image. */
2725 if (it
->method
== GET_FROM_BUFFER
&& !it
->truncate_lines_p
)
2727 int start_at_line_beg_p
;
2728 int first_y
= it
->current_y
;
2730 /* If window start is not at a line start, skip forward to POS to
2731 get the correct continuation lines width. */
2732 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2733 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2734 if (!start_at_line_beg_p
)
2738 reseat_at_previous_visible_line_start (it
);
2739 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2741 new_x
= it
->current_x
+ it
->pixel_width
;
2743 /* If lines are continued, this line may end in the middle
2744 of a multi-glyph character (e.g. a control character
2745 displayed as \003, or in the middle of an overlay
2746 string). In this case move_it_to above will not have
2747 taken us to the start of the continuation line but to the
2748 end of the continued line. */
2749 if (it
->current_x
> 0
2750 && !it
->truncate_lines_p
/* Lines are continued. */
2751 && (/* And glyph doesn't fit on the line. */
2752 new_x
> it
->last_visible_x
2753 /* Or it fits exactly and we're on a window
2755 || (new_x
== it
->last_visible_x
2756 && FRAME_WINDOW_P (it
->f
))))
2758 if (it
->current
.dpvec_index
>= 0
2759 || it
->current
.overlay_string_index
>= 0)
2761 set_iterator_to_next (it
, 1);
2762 move_it_in_display_line_to (it
, -1, -1, 0);
2765 it
->continuation_lines_width
+= it
->current_x
;
2768 /* We're starting a new display line, not affected by the
2769 height of the continued line, so clear the appropriate
2770 fields in the iterator structure. */
2771 it
->max_ascent
= it
->max_descent
= 0;
2772 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2774 it
->current_y
= first_y
;
2776 it
->current_x
= it
->hpos
= 0;
2780 #if 0 /* Don't assert the following because start_display is sometimes
2781 called intentionally with a window start that is not at a
2782 line start. Please leave this code in as a comment. */
2784 /* Window start should be on a line start, now. */
2785 xassert (it
->continuation_lines_width
2786 || IT_CHARPOS (it
) == BEGV
2787 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2792 /* Return 1 if POS is a position in ellipses displayed for invisible
2793 text. W is the window we display, for text property lookup. */
2796 in_ellipses_for_invisible_text_p (pos
, w
)
2797 struct display_pos
*pos
;
2800 Lisp_Object prop
, window
;
2802 int charpos
= CHARPOS (pos
->pos
);
2804 /* If POS specifies a position in a display vector, this might
2805 be for an ellipsis displayed for invisible text. We won't
2806 get the iterator set up for delivering that ellipsis unless
2807 we make sure that it gets aware of the invisible text. */
2808 if (pos
->dpvec_index
>= 0
2809 && pos
->overlay_string_index
< 0
2810 && CHARPOS (pos
->string_pos
) < 0
2812 && (XSETWINDOW (window
, w
),
2813 prop
= Fget_char_property (make_number (charpos
),
2814 Qinvisible
, window
),
2815 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2817 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2819 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2826 /* Initialize IT for stepping through current_buffer in window W,
2827 starting at position POS that includes overlay string and display
2828 vector/ control character translation position information. Value
2829 is zero if there are overlay strings with newlines at POS. */
2832 init_from_display_pos (it
, w
, pos
)
2835 struct display_pos
*pos
;
2837 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2838 int i
, overlay_strings_with_newlines
= 0;
2840 /* If POS specifies a position in a display vector, this might
2841 be for an ellipsis displayed for invisible text. We won't
2842 get the iterator set up for delivering that ellipsis unless
2843 we make sure that it gets aware of the invisible text. */
2844 if (in_ellipses_for_invisible_text_p (pos
, w
))
2850 /* Keep in mind: the call to reseat in init_iterator skips invisible
2851 text, so we might end up at a position different from POS. This
2852 is only a problem when POS is a row start after a newline and an
2853 overlay starts there with an after-string, and the overlay has an
2854 invisible property. Since we don't skip invisible text in
2855 display_line and elsewhere immediately after consuming the
2856 newline before the row start, such a POS will not be in a string,
2857 but the call to init_iterator below will move us to the
2859 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2861 /* This only scans the current chunk -- it should scan all chunks.
2862 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2863 to 16 in 22.1 to make this a lesser problem. */
2864 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2866 const char *s
= SDATA (it
->overlay_strings
[i
]);
2867 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2869 while (s
< e
&& *s
!= '\n')
2874 overlay_strings_with_newlines
= 1;
2879 /* If position is within an overlay string, set up IT to the right
2881 if (pos
->overlay_string_index
>= 0)
2885 /* If the first overlay string happens to have a `display'
2886 property for an image, the iterator will be set up for that
2887 image, and we have to undo that setup first before we can
2888 correct the overlay string index. */
2889 if (it
->method
== GET_FROM_IMAGE
)
2892 /* We already have the first chunk of overlay strings in
2893 IT->overlay_strings. Load more until the one for
2894 pos->overlay_string_index is in IT->overlay_strings. */
2895 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2897 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2898 it
->current
.overlay_string_index
= 0;
2901 load_overlay_strings (it
, 0);
2902 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2906 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2907 relative_index
= (it
->current
.overlay_string_index
2908 % OVERLAY_STRING_CHUNK_SIZE
);
2909 it
->string
= it
->overlay_strings
[relative_index
];
2910 xassert (STRINGP (it
->string
));
2911 it
->current
.string_pos
= pos
->string_pos
;
2912 it
->method
= GET_FROM_STRING
;
2915 #if 0 /* This is bogus because POS not having an overlay string
2916 position does not mean it's after the string. Example: A
2917 line starting with a before-string and initialization of IT
2918 to the previous row's end position. */
2919 else if (it
->current
.overlay_string_index
>= 0)
2921 /* If POS says we're already after an overlay string ending at
2922 POS, make sure to pop the iterator because it will be in
2923 front of that overlay string. When POS is ZV, we've thereby
2924 also ``processed'' overlay strings at ZV. */
2927 xassert (it
->current
.overlay_string_index
== -1);
2928 xassert (it
->method
== GET_FROM_BUFFER
);
2929 if (CHARPOS (pos
->pos
) == ZV
)
2930 it
->overlay_strings_at_end_processed_p
= 1;
2934 if (CHARPOS (pos
->string_pos
) >= 0)
2936 /* Recorded position is not in an overlay string, but in another
2937 string. This can only be a string from a `display' property.
2938 IT should already be filled with that string. */
2939 it
->current
.string_pos
= pos
->string_pos
;
2940 xassert (STRINGP (it
->string
));
2943 /* Restore position in display vector translations, control
2944 character translations or ellipses. */
2945 if (pos
->dpvec_index
>= 0)
2947 if (it
->dpvec
== NULL
)
2948 get_next_display_element (it
);
2949 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2950 it
->current
.dpvec_index
= pos
->dpvec_index
;
2954 return !overlay_strings_with_newlines
;
2958 /* Initialize IT for stepping through current_buffer in window W
2959 starting at ROW->start. */
2962 init_to_row_start (it
, w
, row
)
2965 struct glyph_row
*row
;
2967 init_from_display_pos (it
, w
, &row
->start
);
2968 it
->start
= row
->start
;
2969 it
->continuation_lines_width
= row
->continuation_lines_width
;
2974 /* Initialize IT for stepping through current_buffer in window W
2975 starting in the line following ROW, i.e. starting at ROW->end.
2976 Value is zero if there are overlay strings with newlines at ROW's
2980 init_to_row_end (it
, w
, row
)
2983 struct glyph_row
*row
;
2987 if (init_from_display_pos (it
, w
, &row
->end
))
2989 if (row
->continued_p
)
2990 it
->continuation_lines_width
2991 = row
->continuation_lines_width
+ row
->pixel_width
;
3002 /***********************************************************************
3004 ***********************************************************************/
3006 /* Called when IT reaches IT->stop_charpos. Handle text property and
3007 overlay changes. Set IT->stop_charpos to the next position where
3014 enum prop_handled handled
;
3015 int handle_overlay_change_p
;
3019 it
->current
.dpvec_index
= -1;
3020 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3021 it
->ignore_overlay_strings_at_pos_p
= 0;
3023 /* Use face of preceding text for ellipsis (if invisible) */
3024 if (it
->selective_display_ellipsis_p
)
3025 it
->saved_face_id
= it
->face_id
;
3029 handled
= HANDLED_NORMALLY
;
3031 /* Call text property handlers. */
3032 for (p
= it_props
; p
->handler
; ++p
)
3034 handled
= p
->handler (it
);
3036 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3038 else if (handled
== HANDLED_RETURN
)
3040 /* We still want to show before and after strings from
3041 overlays even if the actual buffer text is replaced. */
3042 if (!handle_overlay_change_p
|| it
->sp
> 1)
3044 if (!get_overlay_strings_1 (it
, 0, 0))
3046 it
->ignore_overlay_strings_at_pos_p
= 1;
3047 it
->string_from_display_prop_p
= 0;
3048 handle_overlay_change_p
= 0;
3049 handled
= HANDLED_RECOMPUTE_PROPS
;
3052 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3053 handle_overlay_change_p
= 0;
3056 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3058 /* Don't check for overlay strings below when set to deliver
3059 characters from a display vector. */
3060 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3061 handle_overlay_change_p
= 0;
3063 /* Handle overlay changes.
3064 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3065 if it finds overlays. */
3066 if (handle_overlay_change_p
)
3067 handled
= handle_overlay_change (it
);
3070 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3072 /* Determine where to stop next. */
3073 if (handled
== HANDLED_NORMALLY
)
3074 compute_stop_pos (it
);
3078 /* Compute IT->stop_charpos from text property and overlay change
3079 information for IT's current position. */
3082 compute_stop_pos (it
)
3085 register INTERVAL iv
, next_iv
;
3086 Lisp_Object object
, limit
, position
;
3088 /* If nowhere else, stop at the end. */
3089 it
->stop_charpos
= it
->end_charpos
;
3091 if (STRINGP (it
->string
))
3093 /* Strings are usually short, so don't limit the search for
3095 object
= it
->string
;
3097 position
= make_number (IT_STRING_CHARPOS (*it
));
3103 /* If next overlay change is in front of the current stop pos
3104 (which is IT->end_charpos), stop there. Note: value of
3105 next_overlay_change is point-max if no overlay change
3107 charpos
= next_overlay_change (IT_CHARPOS (*it
));
3108 if (charpos
< it
->stop_charpos
)
3109 it
->stop_charpos
= charpos
;
3111 /* If showing the region, we have to stop at the region
3112 start or end because the face might change there. */
3113 if (it
->region_beg_charpos
> 0)
3115 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3116 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3117 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3118 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3121 /* Set up variables for computing the stop position from text
3122 property changes. */
3123 XSETBUFFER (object
, current_buffer
);
3124 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3125 position
= make_number (IT_CHARPOS (*it
));
3129 /* Get the interval containing IT's position. Value is a null
3130 interval if there isn't such an interval. */
3131 iv
= validate_interval_range (object
, &position
, &position
, 0);
3132 if (!NULL_INTERVAL_P (iv
))
3134 Lisp_Object values_here
[LAST_PROP_IDX
];
3137 /* Get properties here. */
3138 for (p
= it_props
; p
->handler
; ++p
)
3139 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3141 /* Look for an interval following iv that has different
3143 for (next_iv
= next_interval (iv
);
3144 (!NULL_INTERVAL_P (next_iv
)
3146 || XFASTINT (limit
) > next_iv
->position
));
3147 next_iv
= next_interval (next_iv
))
3149 for (p
= it_props
; p
->handler
; ++p
)
3151 Lisp_Object new_value
;
3153 new_value
= textget (next_iv
->plist
, *p
->name
);
3154 if (!EQ (values_here
[p
->idx
], new_value
))
3162 if (!NULL_INTERVAL_P (next_iv
))
3164 if (INTEGERP (limit
)
3165 && next_iv
->position
>= XFASTINT (limit
))
3166 /* No text property change up to limit. */
3167 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3169 /* Text properties change in next_iv. */
3170 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3174 xassert (STRINGP (it
->string
)
3175 || (it
->stop_charpos
>= BEGV
3176 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3180 /* Return the position of the next overlay change after POS in
3181 current_buffer. Value is point-max if no overlay change
3182 follows. This is like `next-overlay-change' but doesn't use
3186 next_overlay_change (pos
)
3191 Lisp_Object
*overlays
;
3194 /* Get all overlays at the given position. */
3195 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3197 /* If any of these overlays ends before endpos,
3198 use its ending point instead. */
3199 for (i
= 0; i
< noverlays
; ++i
)
3204 oend
= OVERLAY_END (overlays
[i
]);
3205 oendpos
= OVERLAY_POSITION (oend
);
3206 endpos
= min (endpos
, oendpos
);
3214 /***********************************************************************
3216 ***********************************************************************/
3218 /* Handle changes in the `fontified' property of the current buffer by
3219 calling hook functions from Qfontification_functions to fontify
3222 static enum prop_handled
3223 handle_fontified_prop (it
)
3226 Lisp_Object prop
, pos
;
3227 enum prop_handled handled
= HANDLED_NORMALLY
;
3229 if (!NILP (Vmemory_full
))
3232 /* Get the value of the `fontified' property at IT's current buffer
3233 position. (The `fontified' property doesn't have a special
3234 meaning in strings.) If the value is nil, call functions from
3235 Qfontification_functions. */
3236 if (!STRINGP (it
->string
)
3238 && !NILP (Vfontification_functions
)
3239 && !NILP (Vrun_hooks
)
3240 && (pos
= make_number (IT_CHARPOS (*it
)),
3241 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3242 /* Ignore the special cased nil value always present at EOB since
3243 no amount of fontifying will be able to change it. */
3244 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3246 int count
= SPECPDL_INDEX ();
3249 val
= Vfontification_functions
;
3250 specbind (Qfontification_functions
, Qnil
);
3252 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3253 safe_call1 (val
, pos
);
3256 Lisp_Object globals
, fn
;
3257 struct gcpro gcpro1
, gcpro2
;
3260 GCPRO2 (val
, globals
);
3262 for (; CONSP (val
); val
= XCDR (val
))
3268 /* A value of t indicates this hook has a local
3269 binding; it means to run the global binding too.
3270 In a global value, t should not occur. If it
3271 does, we must ignore it to avoid an endless
3273 for (globals
= Fdefault_value (Qfontification_functions
);
3275 globals
= XCDR (globals
))
3277 fn
= XCAR (globals
);
3279 safe_call1 (fn
, pos
);
3283 safe_call1 (fn
, pos
);
3289 unbind_to (count
, Qnil
);
3291 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3292 something. This avoids an endless loop if they failed to
3293 fontify the text for which reason ever. */
3294 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3295 handled
= HANDLED_RECOMPUTE_PROPS
;
3303 /***********************************************************************
3305 ***********************************************************************/
3307 /* Set up iterator IT from face properties at its current position.
3308 Called from handle_stop. */
3310 static enum prop_handled
3311 handle_face_prop (it
)
3314 int new_face_id
, next_stop
;
3316 if (!STRINGP (it
->string
))
3319 = face_at_buffer_position (it
->w
,
3321 it
->region_beg_charpos
,
3322 it
->region_end_charpos
,
3325 + TEXT_PROP_DISTANCE_LIMIT
),
3328 /* Is this a start of a run of characters with box face?
3329 Caveat: this can be called for a freshly initialized
3330 iterator; face_id is -1 in this case. We know that the new
3331 face will not change until limit, i.e. if the new face has a
3332 box, all characters up to limit will have one. But, as
3333 usual, we don't know whether limit is really the end. */
3334 if (new_face_id
!= it
->face_id
)
3336 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3338 /* If new face has a box but old face has not, this is
3339 the start of a run of characters with box, i.e. it has
3340 a shadow on the left side. The value of face_id of the
3341 iterator will be -1 if this is the initial call that gets
3342 the face. In this case, we have to look in front of IT's
3343 position and see whether there is a face != new_face_id. */
3344 it
->start_of_box_run_p
3345 = (new_face
->box
!= FACE_NO_BOX
3346 && (it
->face_id
>= 0
3347 || IT_CHARPOS (*it
) == BEG
3348 || new_face_id
!= face_before_it_pos (it
)));
3349 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3354 int base_face_id
, bufpos
;
3356 Lisp_Object from_overlay
3357 = (it
->current
.overlay_string_index
>= 0
3358 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3361 /* See if we got to this string directly or indirectly from
3362 an overlay property. That includes the before-string or
3363 after-string of an overlay, strings in display properties
3364 provided by an overlay, their text properties, etc.
3366 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3367 if (! NILP (from_overlay
))
3368 for (i
= it
->sp
- 1; i
>= 0; i
--)
3370 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3372 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3373 else if (! NILP (it
->stack
[i
].from_overlay
))
3374 from_overlay
= it
->stack
[i
].from_overlay
;
3376 if (!NILP (from_overlay
))
3380 if (! NILP (from_overlay
))
3382 bufpos
= IT_CHARPOS (*it
);
3383 /* For a string from an overlay, the base face depends
3384 only on text properties and ignores overlays. */
3386 = face_for_overlay_string (it
->w
,
3388 it
->region_beg_charpos
,
3389 it
->region_end_charpos
,
3392 + TEXT_PROP_DISTANCE_LIMIT
),
3400 /* For strings from a `display' property, use the face at
3401 IT's current buffer position as the base face to merge
3402 with, so that overlay strings appear in the same face as
3403 surrounding text, unless they specify their own
3405 base_face_id
= underlying_face_id (it
);
3408 new_face_id
= face_at_string_position (it
->w
,
3410 IT_STRING_CHARPOS (*it
),
3412 it
->region_beg_charpos
,
3413 it
->region_end_charpos
,
3417 #if 0 /* This shouldn't be neccessary. Let's check it. */
3418 /* If IT is used to display a mode line we would really like to
3419 use the mode line face instead of the frame's default face. */
3420 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3421 && new_face_id
== DEFAULT_FACE_ID
)
3422 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3425 /* Is this a start of a run of characters with box? Caveat:
3426 this can be called for a freshly allocated iterator; face_id
3427 is -1 is this case. We know that the new face will not
3428 change until the next check pos, i.e. if the new face has a
3429 box, all characters up to that position will have a
3430 box. But, as usual, we don't know whether that position
3431 is really the end. */
3432 if (new_face_id
!= it
->face_id
)
3434 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3435 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3437 /* If new face has a box but old face hasn't, this is the
3438 start of a run of characters with box, i.e. it has a
3439 shadow on the left side. */
3440 it
->start_of_box_run_p
3441 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3442 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3446 it
->face_id
= new_face_id
;
3447 return HANDLED_NORMALLY
;
3451 /* Return the ID of the face ``underlying'' IT's current position,
3452 which is in a string. If the iterator is associated with a
3453 buffer, return the face at IT's current buffer position.
3454 Otherwise, use the iterator's base_face_id. */
3457 underlying_face_id (it
)
3460 int face_id
= it
->base_face_id
, i
;
3462 xassert (STRINGP (it
->string
));
3464 for (i
= it
->sp
- 1; i
>= 0; --i
)
3465 if (NILP (it
->stack
[i
].string
))
3466 face_id
= it
->stack
[i
].face_id
;
3472 /* Compute the face one character before or after the current position
3473 of IT. BEFORE_P non-zero means get the face in front of IT's
3474 position. Value is the id of the face. */
3477 face_before_or_after_it_pos (it
, before_p
)
3482 int next_check_charpos
;
3483 struct text_pos pos
;
3485 xassert (it
->s
== NULL
);
3487 if (STRINGP (it
->string
))
3489 int bufpos
, base_face_id
;
3491 /* No face change past the end of the string (for the case
3492 we are padding with spaces). No face change before the
3494 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3495 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3498 /* Set pos to the position before or after IT's current position. */
3500 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3502 /* For composition, we must check the character after the
3504 pos
= (it
->what
== IT_COMPOSITION
3505 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3506 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3508 if (it
->current
.overlay_string_index
>= 0)
3509 bufpos
= IT_CHARPOS (*it
);
3513 base_face_id
= underlying_face_id (it
);
3515 /* Get the face for ASCII, or unibyte. */
3516 face_id
= face_at_string_position (it
->w
,
3520 it
->region_beg_charpos
,
3521 it
->region_end_charpos
,
3522 &next_check_charpos
,
3525 /* Correct the face for charsets different from ASCII. Do it
3526 for the multibyte case only. The face returned above is
3527 suitable for unibyte text if IT->string is unibyte. */
3528 if (STRING_MULTIBYTE (it
->string
))
3530 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3531 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3533 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3535 c
= string_char_and_length (p
, rest
, &len
);
3536 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3541 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3542 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3545 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3546 pos
= it
->current
.pos
;
3549 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3552 if (it
->what
== IT_COMPOSITION
)
3553 /* For composition, we must check the position after the
3555 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3557 INC_TEXT_POS (pos
, it
->multibyte_p
);
3560 /* Determine face for CHARSET_ASCII, or unibyte. */
3561 face_id
= face_at_buffer_position (it
->w
,
3563 it
->region_beg_charpos
,
3564 it
->region_end_charpos
,
3565 &next_check_charpos
,
3568 /* Correct the face for charsets different from ASCII. Do it
3569 for the multibyte case only. The face returned above is
3570 suitable for unibyte text if current_buffer is unibyte. */
3571 if (it
->multibyte_p
)
3573 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3574 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3575 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3584 /***********************************************************************
3586 ***********************************************************************/
3588 /* Set up iterator IT from invisible properties at its current
3589 position. Called from handle_stop. */
3591 static enum prop_handled
3592 handle_invisible_prop (it
)
3595 enum prop_handled handled
= HANDLED_NORMALLY
;
3597 if (STRINGP (it
->string
))
3599 extern Lisp_Object Qinvisible
;
3600 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3602 /* Get the value of the invisible text property at the
3603 current position. Value will be nil if there is no such
3605 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3606 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3609 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3611 handled
= HANDLED_RECOMPUTE_PROPS
;
3613 /* Get the position at which the next change of the
3614 invisible text property can be found in IT->string.
3615 Value will be nil if the property value is the same for
3616 all the rest of IT->string. */
3617 XSETINT (limit
, SCHARS (it
->string
));
3618 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3621 /* Text at current position is invisible. The next
3622 change in the property is at position end_charpos.
3623 Move IT's current position to that position. */
3624 if (INTEGERP (end_charpos
)
3625 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3627 struct text_pos old
;
3628 old
= it
->current
.string_pos
;
3629 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3630 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3634 /* The rest of the string is invisible. If this is an
3635 overlay string, proceed with the next overlay string
3636 or whatever comes and return a character from there. */
3637 if (it
->current
.overlay_string_index
>= 0)
3639 next_overlay_string (it
);
3640 /* Don't check for overlay strings when we just
3641 finished processing them. */
3642 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3646 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3647 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3655 EMACS_INT newpos
, next_stop
, start_charpos
;
3656 Lisp_Object pos
, prop
, overlay
;
3658 /* First of all, is there invisible text at this position? */
3659 start_charpos
= IT_CHARPOS (*it
);
3660 pos
= make_number (IT_CHARPOS (*it
));
3661 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3663 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3665 /* If we are on invisible text, skip over it. */
3666 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3668 /* Record whether we have to display an ellipsis for the
3670 int display_ellipsis_p
= invis_p
== 2;
3672 handled
= HANDLED_RECOMPUTE_PROPS
;
3674 /* Loop skipping over invisible text. The loop is left at
3675 ZV or with IT on the first char being visible again. */
3678 /* Try to skip some invisible text. Return value is the
3679 position reached which can be equal to IT's position
3680 if there is nothing invisible here. This skips both
3681 over invisible text properties and overlays with
3682 invisible property. */
3683 newpos
= skip_invisible (IT_CHARPOS (*it
),
3684 &next_stop
, ZV
, it
->window
);
3686 /* If we skipped nothing at all we weren't at invisible
3687 text in the first place. If everything to the end of
3688 the buffer was skipped, end the loop. */
3689 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3693 /* We skipped some characters but not necessarily
3694 all there are. Check if we ended up on visible
3695 text. Fget_char_property returns the property of
3696 the char before the given position, i.e. if we
3697 get invis_p = 0, this means that the char at
3698 newpos is visible. */
3699 pos
= make_number (newpos
);
3700 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3701 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3704 /* If we ended up on invisible text, proceed to
3705 skip starting with next_stop. */
3707 IT_CHARPOS (*it
) = next_stop
;
3709 /* If there are adjacent invisible texts, don't lose the
3710 second one's ellipsis. */
3712 display_ellipsis_p
= 1;
3716 /* The position newpos is now either ZV or on visible text. */
3717 IT_CHARPOS (*it
) = newpos
;
3718 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3720 /* If there are before-strings at the start of invisible
3721 text, and the text is invisible because of a text
3722 property, arrange to show before-strings because 20.x did
3723 it that way. (If the text is invisible because of an
3724 overlay property instead of a text property, this is
3725 already handled in the overlay code.) */
3727 && get_overlay_strings (it
, start_charpos
))
3729 handled
= HANDLED_RECOMPUTE_PROPS
;
3730 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3732 else if (display_ellipsis_p
)
3734 /* Make sure that the glyphs of the ellipsis will get
3735 correct `charpos' values. If we would not update
3736 it->position here, the glyphs would belong to the
3737 last visible character _before_ the invisible
3738 text, which confuses `set_cursor_from_row'.
3740 We use the last invisible position instead of the
3741 first because this way the cursor is always drawn on
3742 the first "." of the ellipsis, whenever PT is inside
3743 the invisible text. Otherwise the cursor would be
3744 placed _after_ the ellipsis when the point is after the
3745 first invisible character. */
3746 if (!STRINGP (it
->object
))
3748 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3749 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3751 setup_for_ellipsis (it
, 0);
3752 /* Let the ellipsis display before
3753 considering any properties of the following char.
3754 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3755 handled
= HANDLED_RETURN
;
3764 /* Make iterator IT return `...' next.
3765 Replaces LEN characters from buffer. */
3768 setup_for_ellipsis (it
, len
)
3772 /* Use the display table definition for `...'. Invalid glyphs
3773 will be handled by the method returning elements from dpvec. */
3774 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3776 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3777 it
->dpvec
= v
->contents
;
3778 it
->dpend
= v
->contents
+ v
->size
;
3782 /* Default `...'. */
3783 it
->dpvec
= default_invis_vector
;
3784 it
->dpend
= default_invis_vector
+ 3;
3787 it
->dpvec_char_len
= len
;
3788 it
->current
.dpvec_index
= 0;
3789 it
->dpvec_face_id
= -1;
3791 /* Remember the current face id in case glyphs specify faces.
3792 IT's face is restored in set_iterator_to_next.
3793 saved_face_id was set to preceding char's face in handle_stop. */
3794 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3795 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3797 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3803 /***********************************************************************
3805 ***********************************************************************/
3807 /* Set up iterator IT from `display' property at its current position.
3808 Called from handle_stop.
3809 We return HANDLED_RETURN if some part of the display property
3810 overrides the display of the buffer text itself.
3811 Otherwise we return HANDLED_NORMALLY. */
3813 static enum prop_handled
3814 handle_display_prop (it
)
3817 Lisp_Object prop
, object
, overlay
;
3818 struct text_pos
*position
;
3819 /* Nonzero if some property replaces the display of the text itself. */
3820 int display_replaced_p
= 0;
3822 if (STRINGP (it
->string
))
3824 object
= it
->string
;
3825 position
= &it
->current
.string_pos
;
3829 XSETWINDOW (object
, it
->w
);
3830 position
= &it
->current
.pos
;
3833 /* Reset those iterator values set from display property values. */
3834 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3835 it
->space_width
= Qnil
;
3836 it
->font_height
= Qnil
;
3839 /* We don't support recursive `display' properties, i.e. string
3840 values that have a string `display' property, that have a string
3841 `display' property etc. */
3842 if (!it
->string_from_display_prop_p
)
3843 it
->area
= TEXT_AREA
;
3845 prop
= get_char_property_and_overlay (make_number (position
->charpos
),
3846 Qdisplay
, object
, &overlay
);
3848 return HANDLED_NORMALLY
;
3849 /* Now OVERLAY is the overlay that gave us this property, or nil
3850 if it was a text property. */
3852 if (!STRINGP (it
->string
))
3853 object
= it
->w
->buffer
;
3856 /* Simple properties. */
3857 && !EQ (XCAR (prop
), Qimage
)
3858 && !EQ (XCAR (prop
), Qspace
)
3859 && !EQ (XCAR (prop
), Qwhen
)
3860 && !EQ (XCAR (prop
), Qslice
)
3861 && !EQ (XCAR (prop
), Qspace_width
)
3862 && !EQ (XCAR (prop
), Qheight
)
3863 && !EQ (XCAR (prop
), Qraise
)
3864 /* Marginal area specifications. */
3865 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3866 && !EQ (XCAR (prop
), Qleft_fringe
)
3867 && !EQ (XCAR (prop
), Qright_fringe
)
3868 && !NILP (XCAR (prop
)))
3870 for (; CONSP (prop
); prop
= XCDR (prop
))
3872 if (handle_single_display_spec (it
, XCAR (prop
), object
, overlay
,
3873 position
, display_replaced_p
))
3875 display_replaced_p
= 1;
3876 /* If some text in a string is replaced, `position' no
3877 longer points to the position of `object'. */
3878 if (STRINGP (object
))
3883 else if (VECTORP (prop
))
3886 for (i
= 0; i
< ASIZE (prop
); ++i
)
3887 if (handle_single_display_spec (it
, AREF (prop
, i
), object
, overlay
,
3888 position
, display_replaced_p
))
3890 display_replaced_p
= 1;
3891 /* If some text in a string is replaced, `position' no
3892 longer points to the position of `object'. */
3893 if (STRINGP (object
))
3899 int ret
= handle_single_display_spec (it
, prop
, object
, overlay
,
3901 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3902 return HANDLED_RECOMPUTE_PROPS
;
3904 display_replaced_p
= 1;
3907 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3911 /* Value is the position of the end of the `display' property starting
3912 at START_POS in OBJECT. */
3914 static struct text_pos
3915 display_prop_end (it
, object
, start_pos
)
3918 struct text_pos start_pos
;
3921 struct text_pos end_pos
;
3923 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3924 Qdisplay
, object
, Qnil
);
3925 CHARPOS (end_pos
) = XFASTINT (end
);
3926 if (STRINGP (object
))
3927 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3929 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3935 /* Set up IT from a single `display' specification PROP. OBJECT
3936 is the object in which the `display' property was found. *POSITION
3937 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3938 means that we previously saw a display specification which already
3939 replaced text display with something else, for example an image;
3940 we ignore such properties after the first one has been processed.
3942 OVERLAY is the overlay this `display' property came from,
3943 or nil if it was a text property.
3945 If PROP is a `space' or `image' specification, and in some other
3946 cases too, set *POSITION to the position where the `display'
3949 Value is non-zero if something was found which replaces the display
3950 of buffer or string text. Specifically, the value is -1 if that
3951 "something" is "nothing". */
3954 handle_single_display_spec (it
, spec
, object
, overlay
, position
,
3955 display_replaced_before_p
)
3959 Lisp_Object overlay
;
3960 struct text_pos
*position
;
3961 int display_replaced_before_p
;
3964 Lisp_Object location
, value
;
3965 struct text_pos start_pos
, save_pos
;
3968 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3969 If the result is non-nil, use VALUE instead of SPEC. */
3971 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3980 if (!NILP (form
) && !EQ (form
, Qt
))
3982 int count
= SPECPDL_INDEX ();
3983 struct gcpro gcpro1
;
3985 /* Bind `object' to the object having the `display' property, a
3986 buffer or string. Bind `position' to the position in the
3987 object where the property was found, and `buffer-position'
3988 to the current position in the buffer. */
3989 specbind (Qobject
, object
);
3990 specbind (Qposition
, make_number (CHARPOS (*position
)));
3991 specbind (Qbuffer_position
,
3992 make_number (STRINGP (object
)
3993 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3995 form
= safe_eval (form
);
3997 unbind_to (count
, Qnil
);
4003 /* Handle `(height HEIGHT)' specifications. */
4005 && EQ (XCAR (spec
), Qheight
)
4006 && CONSP (XCDR (spec
)))
4008 if (!FRAME_WINDOW_P (it
->f
))
4011 it
->font_height
= XCAR (XCDR (spec
));
4012 if (!NILP (it
->font_height
))
4014 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4015 int new_height
= -1;
4017 if (CONSP (it
->font_height
)
4018 && (EQ (XCAR (it
->font_height
), Qplus
)
4019 || EQ (XCAR (it
->font_height
), Qminus
))
4020 && CONSP (XCDR (it
->font_height
))
4021 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4023 /* `(+ N)' or `(- N)' where N is an integer. */
4024 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4025 if (EQ (XCAR (it
->font_height
), Qplus
))
4027 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4029 else if (FUNCTIONP (it
->font_height
))
4031 /* Call function with current height as argument.
4032 Value is the new height. */
4034 height
= safe_call1 (it
->font_height
,
4035 face
->lface
[LFACE_HEIGHT_INDEX
]);
4036 if (NUMBERP (height
))
4037 new_height
= XFLOATINT (height
);
4039 else if (NUMBERP (it
->font_height
))
4041 /* Value is a multiple of the canonical char height. */
4044 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
4045 new_height
= (XFLOATINT (it
->font_height
)
4046 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4050 /* Evaluate IT->font_height with `height' bound to the
4051 current specified height to get the new height. */
4052 int count
= SPECPDL_INDEX ();
4054 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4055 value
= safe_eval (it
->font_height
);
4056 unbind_to (count
, Qnil
);
4058 if (NUMBERP (value
))
4059 new_height
= XFLOATINT (value
);
4063 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4069 /* Handle `(space-width WIDTH)'. */
4071 && EQ (XCAR (spec
), Qspace_width
)
4072 && CONSP (XCDR (spec
)))
4074 if (!FRAME_WINDOW_P (it
->f
))
4077 value
= XCAR (XCDR (spec
));
4078 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4079 it
->space_width
= value
;
4084 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4086 && EQ (XCAR (spec
), Qslice
))
4090 if (!FRAME_WINDOW_P (it
->f
))
4093 if (tem
= XCDR (spec
), CONSP (tem
))
4095 it
->slice
.x
= XCAR (tem
);
4096 if (tem
= XCDR (tem
), CONSP (tem
))
4098 it
->slice
.y
= XCAR (tem
);
4099 if (tem
= XCDR (tem
), CONSP (tem
))
4101 it
->slice
.width
= XCAR (tem
);
4102 if (tem
= XCDR (tem
), CONSP (tem
))
4103 it
->slice
.height
= XCAR (tem
);
4111 /* Handle `(raise FACTOR)'. */
4113 && EQ (XCAR (spec
), Qraise
)
4114 && CONSP (XCDR (spec
)))
4116 if (!FRAME_WINDOW_P (it
->f
))
4119 #ifdef HAVE_WINDOW_SYSTEM
4120 value
= XCAR (XCDR (spec
));
4121 if (NUMBERP (value
))
4123 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4124 it
->voffset
= - (XFLOATINT (value
)
4125 * (FONT_HEIGHT (face
->font
)));
4127 #endif /* HAVE_WINDOW_SYSTEM */
4132 /* Don't handle the other kinds of display specifications
4133 inside a string that we got from a `display' property. */
4134 if (it
->string_from_display_prop_p
)
4137 /* Characters having this form of property are not displayed, so
4138 we have to find the end of the property. */
4139 start_pos
= *position
;
4140 *position
= display_prop_end (it
, object
, start_pos
);
4143 /* Stop the scan at that end position--we assume that all
4144 text properties change there. */
4145 it
->stop_charpos
= position
->charpos
;
4147 /* Handle `(left-fringe BITMAP [FACE])'
4148 and `(right-fringe BITMAP [FACE])'. */
4150 && (EQ (XCAR (spec
), Qleft_fringe
)
4151 || EQ (XCAR (spec
), Qright_fringe
))
4152 && CONSP (XCDR (spec
)))
4154 int face_id
= DEFAULT_FACE_ID
;
4157 if (!FRAME_WINDOW_P (it
->f
))
4158 /* If we return here, POSITION has been advanced
4159 across the text with this property. */
4162 #ifdef HAVE_WINDOW_SYSTEM
4163 value
= XCAR (XCDR (spec
));
4164 if (!SYMBOLP (value
)
4165 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4166 /* If we return here, POSITION has been advanced
4167 across the text with this property. */
4170 if (CONSP (XCDR (XCDR (spec
))))
4172 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4173 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4174 'A', FRINGE_FACE_ID
, 0);
4179 /* Save current settings of IT so that we can restore them
4180 when we are finished with the glyph property value. */
4182 save_pos
= it
->position
;
4183 it
->position
= *position
;
4185 it
->position
= save_pos
;
4187 it
->area
= TEXT_AREA
;
4188 it
->what
= IT_IMAGE
;
4189 it
->image_id
= -1; /* no image */
4190 it
->position
= start_pos
;
4191 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4192 it
->method
= GET_FROM_IMAGE
;
4193 it
->from_overlay
= Qnil
;
4194 it
->face_id
= face_id
;
4196 /* Say that we haven't consumed the characters with
4197 `display' property yet. The call to pop_it in
4198 set_iterator_to_next will clean this up. */
4199 *position
= start_pos
;
4201 if (EQ (XCAR (spec
), Qleft_fringe
))
4203 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4204 it
->left_user_fringe_face_id
= face_id
;
4208 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4209 it
->right_user_fringe_face_id
= face_id
;
4211 #endif /* HAVE_WINDOW_SYSTEM */
4215 /* Prepare to handle `((margin left-margin) ...)',
4216 `((margin right-margin) ...)' and `((margin nil) ...)'
4217 prefixes for display specifications. */
4218 location
= Qunbound
;
4219 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4223 value
= XCDR (spec
);
4225 value
= XCAR (value
);
4228 if (EQ (XCAR (tem
), Qmargin
)
4229 && (tem
= XCDR (tem
),
4230 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4232 || EQ (tem
, Qleft_margin
)
4233 || EQ (tem
, Qright_margin
))))
4237 if (EQ (location
, Qunbound
))
4243 /* After this point, VALUE is the property after any
4244 margin prefix has been stripped. It must be a string,
4245 an image specification, or `(space ...)'.
4247 LOCATION specifies where to display: `left-margin',
4248 `right-margin' or nil. */
4250 valid_p
= (STRINGP (value
)
4251 #ifdef HAVE_WINDOW_SYSTEM
4252 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4253 #endif /* not HAVE_WINDOW_SYSTEM */
4254 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4256 if (valid_p
&& !display_replaced_before_p
)
4258 /* Save current settings of IT so that we can restore them
4259 when we are finished with the glyph property value. */
4260 save_pos
= it
->position
;
4261 it
->position
= *position
;
4263 it
->position
= save_pos
;
4264 it
->from_overlay
= overlay
;
4266 if (NILP (location
))
4267 it
->area
= TEXT_AREA
;
4268 else if (EQ (location
, Qleft_margin
))
4269 it
->area
= LEFT_MARGIN_AREA
;
4271 it
->area
= RIGHT_MARGIN_AREA
;
4273 if (STRINGP (value
))
4275 if (SCHARS (value
) == 0)
4278 return -1; /* Replaced by "", i.e. nothing. */
4281 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4282 it
->current
.overlay_string_index
= -1;
4283 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4284 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4285 it
->method
= GET_FROM_STRING
;
4286 it
->stop_charpos
= 0;
4287 it
->string_from_display_prop_p
= 1;
4288 /* Say that we haven't consumed the characters with
4289 `display' property yet. The call to pop_it in
4290 set_iterator_to_next will clean this up. */
4291 if (BUFFERP (object
))
4292 it
->current
.pos
= start_pos
;
4294 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4296 it
->method
= GET_FROM_STRETCH
;
4298 it
->position
= start_pos
;
4299 if (BUFFERP (object
))
4300 it
->current
.pos
= start_pos
;
4302 #ifdef HAVE_WINDOW_SYSTEM
4305 it
->what
= IT_IMAGE
;
4306 it
->image_id
= lookup_image (it
->f
, value
);
4307 it
->position
= start_pos
;
4308 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4309 it
->method
= GET_FROM_IMAGE
;
4311 /* Say that we haven't consumed the characters with
4312 `display' property yet. The call to pop_it in
4313 set_iterator_to_next will clean this up. */
4314 if (BUFFERP (object
))
4315 it
->current
.pos
= start_pos
;
4317 #endif /* HAVE_WINDOW_SYSTEM */
4322 /* Invalid property or property not supported. Restore
4323 POSITION to what it was before. */
4324 *position
= start_pos
;
4329 /* Check if SPEC is a display sub-property value whose text should be
4330 treated as intangible. */
4333 single_display_spec_intangible_p (prop
)
4336 /* Skip over `when FORM'. */
4337 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4351 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4352 we don't need to treat text as intangible. */
4353 if (EQ (XCAR (prop
), Qmargin
))
4361 || EQ (XCAR (prop
), Qleft_margin
)
4362 || EQ (XCAR (prop
), Qright_margin
))
4366 return (CONSP (prop
)
4367 && (EQ (XCAR (prop
), Qimage
)
4368 || EQ (XCAR (prop
), Qspace
)));
4372 /* Check if PROP is a display property value whose text should be
4373 treated as intangible. */
4376 display_prop_intangible_p (prop
)
4380 && CONSP (XCAR (prop
))
4381 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4383 /* A list of sub-properties. */
4384 while (CONSP (prop
))
4386 if (single_display_spec_intangible_p (XCAR (prop
)))
4391 else if (VECTORP (prop
))
4393 /* A vector of sub-properties. */
4395 for (i
= 0; i
< ASIZE (prop
); ++i
)
4396 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4400 return single_display_spec_intangible_p (prop
);
4406 /* Return 1 if PROP is a display sub-property value containing STRING. */
4409 single_display_spec_string_p (prop
, string
)
4410 Lisp_Object prop
, string
;
4412 if (EQ (string
, prop
))
4415 /* Skip over `when FORM'. */
4416 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4425 /* Skip over `margin LOCATION'. */
4426 if (EQ (XCAR (prop
), Qmargin
))
4437 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4441 /* Return 1 if STRING appears in the `display' property PROP. */
4444 display_prop_string_p (prop
, string
)
4445 Lisp_Object prop
, string
;
4448 && CONSP (XCAR (prop
))
4449 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4451 /* A list of sub-properties. */
4452 while (CONSP (prop
))
4454 if (single_display_spec_string_p (XCAR (prop
), string
))
4459 else if (VECTORP (prop
))
4461 /* A vector of sub-properties. */
4463 for (i
= 0; i
< ASIZE (prop
); ++i
)
4464 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4468 return single_display_spec_string_p (prop
, string
);
4474 /* Determine from which buffer position in W's buffer STRING comes
4475 from. AROUND_CHARPOS is an approximate position where it could
4476 be from. Value is the buffer position or 0 if it couldn't be
4479 W's buffer must be current.
4481 This function is necessary because we don't record buffer positions
4482 in glyphs generated from strings (to keep struct glyph small).
4483 This function may only use code that doesn't eval because it is
4484 called asynchronously from note_mouse_highlight. */
4487 string_buffer_position (w
, string
, around_charpos
)
4492 Lisp_Object limit
, prop
, pos
;
4493 const int MAX_DISTANCE
= 1000;
4496 pos
= make_number (around_charpos
);
4497 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4498 while (!found
&& !EQ (pos
, limit
))
4500 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4501 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4504 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4509 pos
= make_number (around_charpos
);
4510 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4511 while (!found
&& !EQ (pos
, limit
))
4513 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4514 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4517 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4522 return found
? XINT (pos
) : 0;
4527 /***********************************************************************
4528 `composition' property
4529 ***********************************************************************/
4531 /* Set up iterator IT from `composition' property at its current
4532 position. Called from handle_stop. */
4534 static enum prop_handled
4535 handle_composition_prop (it
)
4538 Lisp_Object prop
, string
;
4539 int pos
, pos_byte
, end
;
4540 enum prop_handled handled
= HANDLED_NORMALLY
;
4542 if (STRINGP (it
->string
))
4544 pos
= IT_STRING_CHARPOS (*it
);
4545 pos_byte
= IT_STRING_BYTEPOS (*it
);
4546 string
= it
->string
;
4550 pos
= IT_CHARPOS (*it
);
4551 pos_byte
= IT_BYTEPOS (*it
);
4555 /* If there's a valid composition and point is not inside of the
4556 composition (in the case that the composition is from the current
4557 buffer), draw a glyph composed from the composition components. */
4558 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
4559 && COMPOSITION_VALID_P (pos
, end
, prop
)
4560 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
4562 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4566 struct composition
*cmp
= composition_table
[id
];
4568 if (cmp
->glyph_len
== 0)
4571 if (STRINGP (it
->string
))
4573 IT_STRING_CHARPOS (*it
) = end
;
4574 IT_STRING_BYTEPOS (*it
) = string_char_to_byte (it
->string
,
4579 IT_CHARPOS (*it
) = end
;
4580 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (end
);
4582 return HANDLED_RECOMPUTE_PROPS
;
4585 it
->stop_charpos
= end
;
4588 it
->method
= GET_FROM_COMPOSITION
;
4590 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4591 /* For a terminal, draw only the first character of the
4593 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4594 it
->len
= (STRINGP (it
->string
)
4595 ? string_char_to_byte (it
->string
, end
)
4596 : CHAR_TO_BYTE (end
)) - pos_byte
;
4597 handled
= HANDLED_RETURN
;
4606 /***********************************************************************
4608 ***********************************************************************/
4610 /* The following structure is used to record overlay strings for
4611 later sorting in load_overlay_strings. */
4613 struct overlay_entry
4615 Lisp_Object overlay
;
4622 /* Set up iterator IT from overlay strings at its current position.
4623 Called from handle_stop. */
4625 static enum prop_handled
4626 handle_overlay_change (it
)
4629 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4630 return HANDLED_RECOMPUTE_PROPS
;
4632 return HANDLED_NORMALLY
;
4636 /* Set up the next overlay string for delivery by IT, if there is an
4637 overlay string to deliver. Called by set_iterator_to_next when the
4638 end of the current overlay string is reached. If there are more
4639 overlay strings to display, IT->string and
4640 IT->current.overlay_string_index are set appropriately here.
4641 Otherwise IT->string is set to nil. */
4644 next_overlay_string (it
)
4647 ++it
->current
.overlay_string_index
;
4648 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4650 /* No more overlay strings. Restore IT's settings to what
4651 they were before overlay strings were processed, and
4652 continue to deliver from current_buffer. */
4653 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4657 || it
->method
== GET_FROM_COMPOSITION
4658 || (NILP (it
->string
)
4659 && it
->method
== GET_FROM_BUFFER
4660 && it
->stop_charpos
>= BEGV
4661 && it
->stop_charpos
<= it
->end_charpos
));
4662 it
->current
.overlay_string_index
= -1;
4663 it
->n_overlay_strings
= 0;
4665 /* If we're at the end of the buffer, record that we have
4666 processed the overlay strings there already, so that
4667 next_element_from_buffer doesn't try it again. */
4668 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4669 it
->overlay_strings_at_end_processed_p
= 1;
4671 /* If we have to display `...' for invisible text, set
4672 the iterator up for that. */
4673 if (display_ellipsis_p
)
4674 setup_for_ellipsis (it
, 0);
4678 /* There are more overlay strings to process. If
4679 IT->current.overlay_string_index has advanced to a position
4680 where we must load IT->overlay_strings with more strings, do
4682 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4684 if (it
->current
.overlay_string_index
&& i
== 0)
4685 load_overlay_strings (it
, 0);
4687 /* Initialize IT to deliver display elements from the overlay
4689 it
->string
= it
->overlay_strings
[i
];
4690 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4691 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4692 it
->method
= GET_FROM_STRING
;
4693 it
->stop_charpos
= 0;
4700 /* Compare two overlay_entry structures E1 and E2. Used as a
4701 comparison function for qsort in load_overlay_strings. Overlay
4702 strings for the same position are sorted so that
4704 1. All after-strings come in front of before-strings, except
4705 when they come from the same overlay.
4707 2. Within after-strings, strings are sorted so that overlay strings
4708 from overlays with higher priorities come first.
4710 2. Within before-strings, strings are sorted so that overlay
4711 strings from overlays with higher priorities come last.
4713 Value is analogous to strcmp. */
4717 compare_overlay_entries (e1
, e2
)
4720 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4721 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4724 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4726 /* Let after-strings appear in front of before-strings if
4727 they come from different overlays. */
4728 if (EQ (entry1
->overlay
, entry2
->overlay
))
4729 result
= entry1
->after_string_p
? 1 : -1;
4731 result
= entry1
->after_string_p
? -1 : 1;
4733 else if (entry1
->after_string_p
)
4734 /* After-strings sorted in order of decreasing priority. */
4735 result
= entry2
->priority
- entry1
->priority
;
4737 /* Before-strings sorted in order of increasing priority. */
4738 result
= entry1
->priority
- entry2
->priority
;
4744 /* Load the vector IT->overlay_strings with overlay strings from IT's
4745 current buffer position, or from CHARPOS if that is > 0. Set
4746 IT->n_overlays to the total number of overlay strings found.
4748 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4749 a time. On entry into load_overlay_strings,
4750 IT->current.overlay_string_index gives the number of overlay
4751 strings that have already been loaded by previous calls to this
4754 IT->add_overlay_start contains an additional overlay start
4755 position to consider for taking overlay strings from, if non-zero.
4756 This position comes into play when the overlay has an `invisible'
4757 property, and both before and after-strings. When we've skipped to
4758 the end of the overlay, because of its `invisible' property, we
4759 nevertheless want its before-string to appear.
4760 IT->add_overlay_start will contain the overlay start position
4763 Overlay strings are sorted so that after-string strings come in
4764 front of before-string strings. Within before and after-strings,
4765 strings are sorted by overlay priority. See also function
4766 compare_overlay_entries. */
4769 load_overlay_strings (it
, charpos
)
4773 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4774 Lisp_Object overlay
, window
, str
, invisible
;
4775 struct Lisp_Overlay
*ov
;
4778 int n
= 0, i
, j
, invis_p
;
4779 struct overlay_entry
*entries
4780 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4783 charpos
= IT_CHARPOS (*it
);
4785 /* Append the overlay string STRING of overlay OVERLAY to vector
4786 `entries' which has size `size' and currently contains `n'
4787 elements. AFTER_P non-zero means STRING is an after-string of
4789 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4792 Lisp_Object priority; \
4796 int new_size = 2 * size; \
4797 struct overlay_entry *old = entries; \
4799 (struct overlay_entry *) alloca (new_size \
4800 * sizeof *entries); \
4801 bcopy (old, entries, size * sizeof *entries); \
4805 entries[n].string = (STRING); \
4806 entries[n].overlay = (OVERLAY); \
4807 priority = Foverlay_get ((OVERLAY), Qpriority); \
4808 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4809 entries[n].after_string_p = (AFTER_P); \
4814 /* Process overlay before the overlay center. */
4815 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4817 XSETMISC (overlay
, ov
);
4818 xassert (OVERLAYP (overlay
));
4819 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4820 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4825 /* Skip this overlay if it doesn't start or end at IT's current
4827 if (end
!= charpos
&& start
!= charpos
)
4830 /* Skip this overlay if it doesn't apply to IT->w. */
4831 window
= Foverlay_get (overlay
, Qwindow
);
4832 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4835 /* If the text ``under'' the overlay is invisible, both before-
4836 and after-strings from this overlay are visible; start and
4837 end position are indistinguishable. */
4838 invisible
= Foverlay_get (overlay
, Qinvisible
);
4839 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4841 /* If overlay has a non-empty before-string, record it. */
4842 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4843 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4845 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4847 /* If overlay has a non-empty after-string, record it. */
4848 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4849 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4851 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4854 /* Process overlays after the overlay center. */
4855 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4857 XSETMISC (overlay
, ov
);
4858 xassert (OVERLAYP (overlay
));
4859 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4860 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4862 if (start
> charpos
)
4865 /* Skip this overlay if it doesn't start or end at IT's current
4867 if (end
!= charpos
&& start
!= charpos
)
4870 /* Skip this overlay if it doesn't apply to IT->w. */
4871 window
= Foverlay_get (overlay
, Qwindow
);
4872 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4875 /* If the text ``under'' the overlay is invisible, it has a zero
4876 dimension, and both before- and after-strings apply. */
4877 invisible
= Foverlay_get (overlay
, Qinvisible
);
4878 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4880 /* If overlay has a non-empty before-string, record it. */
4881 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4882 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4884 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4886 /* If overlay has a non-empty after-string, record it. */
4887 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4888 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4890 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4893 #undef RECORD_OVERLAY_STRING
4897 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4899 /* Record the total number of strings to process. */
4900 it
->n_overlay_strings
= n
;
4902 /* IT->current.overlay_string_index is the number of overlay strings
4903 that have already been consumed by IT. Copy some of the
4904 remaining overlay strings to IT->overlay_strings. */
4906 j
= it
->current
.overlay_string_index
;
4907 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4909 it
->overlay_strings
[i
] = entries
[j
].string
;
4910 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
4917 /* Get the first chunk of overlay strings at IT's current buffer
4918 position, or at CHARPOS if that is > 0. Value is non-zero if at
4919 least one overlay string was found. */
4922 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
4926 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4927 process. This fills IT->overlay_strings with strings, and sets
4928 IT->n_overlay_strings to the total number of strings to process.
4929 IT->pos.overlay_string_index has to be set temporarily to zero
4930 because load_overlay_strings needs this; it must be set to -1
4931 when no overlay strings are found because a zero value would
4932 indicate a position in the first overlay string. */
4933 it
->current
.overlay_string_index
= 0;
4934 load_overlay_strings (it
, charpos
);
4936 /* If we found overlay strings, set up IT to deliver display
4937 elements from the first one. Otherwise set up IT to deliver
4938 from current_buffer. */
4939 if (it
->n_overlay_strings
)
4941 /* Make sure we know settings in current_buffer, so that we can
4942 restore meaningful values when we're done with the overlay
4945 compute_stop_pos (it
);
4946 xassert (it
->face_id
>= 0);
4948 /* Save IT's settings. They are restored after all overlay
4949 strings have been processed. */
4950 xassert (!compute_stop_p
|| it
->sp
== 0);
4953 /* Set up IT to deliver display elements from the first overlay
4955 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4956 it
->string
= it
->overlay_strings
[0];
4957 it
->from_overlay
= Qnil
;
4958 it
->stop_charpos
= 0;
4959 xassert (STRINGP (it
->string
));
4960 it
->end_charpos
= SCHARS (it
->string
);
4961 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4962 it
->method
= GET_FROM_STRING
;
4966 it
->current
.overlay_string_index
= -1;
4971 get_overlay_strings (it
, charpos
)
4976 it
->method
= GET_FROM_BUFFER
;
4978 (void) get_overlay_strings_1 (it
, charpos
, 1);
4982 /* Value is non-zero if we found at least one overlay string. */
4983 return STRINGP (it
->string
);
4988 /***********************************************************************
4989 Saving and restoring state
4990 ***********************************************************************/
4992 /* Save current settings of IT on IT->stack. Called, for example,
4993 before setting up IT for an overlay string, to be able to restore
4994 IT's settings to what they were after the overlay string has been
5001 struct iterator_stack_entry
*p
;
5003 xassert (it
->sp
< IT_STACK_SIZE
);
5004 p
= it
->stack
+ it
->sp
;
5006 p
->stop_charpos
= it
->stop_charpos
;
5007 xassert (it
->face_id
>= 0);
5008 p
->face_id
= it
->face_id
;
5009 p
->string
= it
->string
;
5010 p
->method
= it
->method
;
5011 p
->from_overlay
= it
->from_overlay
;
5014 case GET_FROM_IMAGE
:
5015 p
->u
.image
.object
= it
->object
;
5016 p
->u
.image
.image_id
= it
->image_id
;
5017 p
->u
.image
.slice
= it
->slice
;
5019 case GET_FROM_COMPOSITION
:
5020 p
->u
.comp
.object
= it
->object
;
5021 p
->u
.comp
.c
= it
->c
;
5022 p
->u
.comp
.len
= it
->len
;
5023 p
->u
.comp
.cmp_id
= it
->cmp_id
;
5024 p
->u
.comp
.cmp_len
= it
->cmp_len
;
5026 case GET_FROM_STRETCH
:
5027 p
->u
.stretch
.object
= it
->object
;
5030 p
->position
= it
->position
;
5031 p
->current
= it
->current
;
5032 p
->end_charpos
= it
->end_charpos
;
5033 p
->string_nchars
= it
->string_nchars
;
5035 p
->multibyte_p
= it
->multibyte_p
;
5036 p
->space_width
= it
->space_width
;
5037 p
->font_height
= it
->font_height
;
5038 p
->voffset
= it
->voffset
;
5039 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5040 p
->display_ellipsis_p
= 0;
5045 /* Restore IT's settings from IT->stack. Called, for example, when no
5046 more overlay strings must be processed, and we return to delivering
5047 display elements from a buffer, or when the end of a string from a
5048 `display' property is reached and we return to delivering display
5049 elements from an overlay string, or from a buffer. */
5055 struct iterator_stack_entry
*p
;
5057 xassert (it
->sp
> 0);
5059 p
= it
->stack
+ it
->sp
;
5060 it
->stop_charpos
= p
->stop_charpos
;
5061 it
->face_id
= p
->face_id
;
5062 it
->current
= p
->current
;
5063 it
->position
= p
->position
;
5064 it
->string
= p
->string
;
5065 it
->from_overlay
= p
->from_overlay
;
5066 if (NILP (it
->string
))
5067 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5068 it
->method
= p
->method
;
5071 case GET_FROM_IMAGE
:
5072 it
->image_id
= p
->u
.image
.image_id
;
5073 it
->object
= p
->u
.image
.object
;
5074 it
->slice
= p
->u
.image
.slice
;
5076 case GET_FROM_COMPOSITION
:
5077 it
->object
= p
->u
.comp
.object
;
5078 it
->c
= p
->u
.comp
.c
;
5079 it
->len
= p
->u
.comp
.len
;
5080 it
->cmp_id
= p
->u
.comp
.cmp_id
;
5081 it
->cmp_len
= p
->u
.comp
.cmp_len
;
5083 case GET_FROM_STRETCH
:
5084 it
->object
= p
->u
.comp
.object
;
5086 case GET_FROM_BUFFER
:
5087 it
->object
= it
->w
->buffer
;
5089 case GET_FROM_STRING
:
5090 it
->object
= it
->string
;
5093 it
->end_charpos
= p
->end_charpos
;
5094 it
->string_nchars
= p
->string_nchars
;
5096 it
->multibyte_p
= p
->multibyte_p
;
5097 it
->space_width
= p
->space_width
;
5098 it
->font_height
= p
->font_height
;
5099 it
->voffset
= p
->voffset
;
5100 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5105 /***********************************************************************
5107 ***********************************************************************/
5109 /* Set IT's current position to the previous line start. */
5112 back_to_previous_line_start (it
)
5115 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5116 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5120 /* Move IT to the next line start.
5122 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5123 we skipped over part of the text (as opposed to moving the iterator
5124 continuously over the text). Otherwise, don't change the value
5127 Newlines may come from buffer text, overlay strings, or strings
5128 displayed via the `display' property. That's the reason we can't
5129 simply use find_next_newline_no_quit.
5131 Note that this function may not skip over invisible text that is so
5132 because of text properties and immediately follows a newline. If
5133 it would, function reseat_at_next_visible_line_start, when called
5134 from set_iterator_to_next, would effectively make invisible
5135 characters following a newline part of the wrong glyph row, which
5136 leads to wrong cursor motion. */
5139 forward_to_next_line_start (it
, skipped_p
)
5143 int old_selective
, newline_found_p
, n
;
5144 const int MAX_NEWLINE_DISTANCE
= 500;
5146 /* If already on a newline, just consume it to avoid unintended
5147 skipping over invisible text below. */
5148 if (it
->what
== IT_CHARACTER
5150 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5152 set_iterator_to_next (it
, 0);
5157 /* Don't handle selective display in the following. It's (a)
5158 unnecessary because it's done by the caller, and (b) leads to an
5159 infinite recursion because next_element_from_ellipsis indirectly
5160 calls this function. */
5161 old_selective
= it
->selective
;
5164 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5165 from buffer text. */
5166 for (n
= newline_found_p
= 0;
5167 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5168 n
+= STRINGP (it
->string
) ? 0 : 1)
5170 if (!get_next_display_element (it
))
5172 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5173 set_iterator_to_next (it
, 0);
5176 /* If we didn't find a newline near enough, see if we can use a
5178 if (!newline_found_p
)
5180 int start
= IT_CHARPOS (*it
);
5181 int limit
= find_next_newline_no_quit (start
, 1);
5184 xassert (!STRINGP (it
->string
));
5186 /* If there isn't any `display' property in sight, and no
5187 overlays, we can just use the position of the newline in
5189 if (it
->stop_charpos
>= limit
5190 || ((pos
= Fnext_single_property_change (make_number (start
),
5192 Qnil
, make_number (limit
)),
5194 && next_overlay_change (start
) == ZV
))
5196 IT_CHARPOS (*it
) = limit
;
5197 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5198 *skipped_p
= newline_found_p
= 1;
5202 while (get_next_display_element (it
)
5203 && !newline_found_p
)
5205 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5206 set_iterator_to_next (it
, 0);
5211 it
->selective
= old_selective
;
5212 return newline_found_p
;
5216 /* Set IT's current position to the previous visible line start. Skip
5217 invisible text that is so either due to text properties or due to
5218 selective display. Caution: this does not change IT->current_x and
5222 back_to_previous_visible_line_start (it
)
5225 while (IT_CHARPOS (*it
) > BEGV
)
5227 back_to_previous_line_start (it
);
5229 if (IT_CHARPOS (*it
) <= BEGV
)
5232 /* If selective > 0, then lines indented more than that values
5234 if (it
->selective
> 0
5235 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5236 (double) it
->selective
)) /* iftc */
5239 /* Check the newline before point for invisibility. */
5242 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5243 Qinvisible
, it
->window
);
5244 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5248 if (IT_CHARPOS (*it
) <= BEGV
)
5255 Lisp_Object val
, overlay
;
5257 /* If newline is part of a composition, continue from start of composition */
5258 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5259 && beg
< IT_CHARPOS (*it
))
5262 /* If newline is replaced by a display property, find start of overlay
5263 or interval and continue search from that point. */
5265 pos
= --IT_CHARPOS (it2
);
5268 if (handle_display_prop (&it2
) == HANDLED_RETURN
5269 && !NILP (val
= get_char_property_and_overlay
5270 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5271 && (OVERLAYP (overlay
)
5272 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5273 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5276 /* Newline is not replaced by anything -- so we are done. */
5282 IT_CHARPOS (*it
) = beg
;
5283 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5287 it
->continuation_lines_width
= 0;
5289 xassert (IT_CHARPOS (*it
) >= BEGV
);
5290 xassert (IT_CHARPOS (*it
) == BEGV
5291 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5296 /* Reseat iterator IT at the previous visible line start. Skip
5297 invisible text that is so either due to text properties or due to
5298 selective display. At the end, update IT's overlay information,
5299 face information etc. */
5302 reseat_at_previous_visible_line_start (it
)
5305 back_to_previous_visible_line_start (it
);
5306 reseat (it
, it
->current
.pos
, 1);
5311 /* Reseat iterator IT on the next visible line start in the current
5312 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5313 preceding the line start. Skip over invisible text that is so
5314 because of selective display. Compute faces, overlays etc at the
5315 new position. Note that this function does not skip over text that
5316 is invisible because of text properties. */
5319 reseat_at_next_visible_line_start (it
, on_newline_p
)
5323 int newline_found_p
, skipped_p
= 0;
5325 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5327 /* Skip over lines that are invisible because they are indented
5328 more than the value of IT->selective. */
5329 if (it
->selective
> 0)
5330 while (IT_CHARPOS (*it
) < ZV
5331 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5332 (double) it
->selective
)) /* iftc */
5334 xassert (IT_BYTEPOS (*it
) == BEGV
5335 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5336 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5339 /* Position on the newline if that's what's requested. */
5340 if (on_newline_p
&& newline_found_p
)
5342 if (STRINGP (it
->string
))
5344 if (IT_STRING_CHARPOS (*it
) > 0)
5346 --IT_STRING_CHARPOS (*it
);
5347 --IT_STRING_BYTEPOS (*it
);
5350 else if (IT_CHARPOS (*it
) > BEGV
)
5354 reseat (it
, it
->current
.pos
, 0);
5358 reseat (it
, it
->current
.pos
, 0);
5365 /***********************************************************************
5366 Changing an iterator's position
5367 ***********************************************************************/
5369 /* Change IT's current position to POS in current_buffer. If FORCE_P
5370 is non-zero, always check for text properties at the new position.
5371 Otherwise, text properties are only looked up if POS >=
5372 IT->check_charpos of a property. */
5375 reseat (it
, pos
, force_p
)
5377 struct text_pos pos
;
5380 int original_pos
= IT_CHARPOS (*it
);
5382 reseat_1 (it
, pos
, 0);
5384 /* Determine where to check text properties. Avoid doing it
5385 where possible because text property lookup is very expensive. */
5387 || CHARPOS (pos
) > it
->stop_charpos
5388 || CHARPOS (pos
) < original_pos
)
5395 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5396 IT->stop_pos to POS, also. */
5399 reseat_1 (it
, pos
, set_stop_p
)
5401 struct text_pos pos
;
5404 /* Don't call this function when scanning a C string. */
5405 xassert (it
->s
== NULL
);
5407 /* POS must be a reasonable value. */
5408 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5410 it
->current
.pos
= it
->position
= pos
;
5411 it
->end_charpos
= ZV
;
5413 it
->current
.dpvec_index
= -1;
5414 it
->current
.overlay_string_index
= -1;
5415 IT_STRING_CHARPOS (*it
) = -1;
5416 IT_STRING_BYTEPOS (*it
) = -1;
5418 it
->method
= GET_FROM_BUFFER
;
5419 it
->object
= it
->w
->buffer
;
5420 it
->area
= TEXT_AREA
;
5421 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5423 it
->string_from_display_prop_p
= 0;
5424 it
->face_before_selective_p
= 0;
5427 it
->stop_charpos
= CHARPOS (pos
);
5431 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5432 If S is non-null, it is a C string to iterate over. Otherwise,
5433 STRING gives a Lisp string to iterate over.
5435 If PRECISION > 0, don't return more then PRECISION number of
5436 characters from the string.
5438 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5439 characters have been returned. FIELD_WIDTH < 0 means an infinite
5442 MULTIBYTE = 0 means disable processing of multibyte characters,
5443 MULTIBYTE > 0 means enable it,
5444 MULTIBYTE < 0 means use IT->multibyte_p.
5446 IT must be initialized via a prior call to init_iterator before
5447 calling this function. */
5450 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5455 int precision
, field_width
, multibyte
;
5457 /* No region in strings. */
5458 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5460 /* No text property checks performed by default, but see below. */
5461 it
->stop_charpos
= -1;
5463 /* Set iterator position and end position. */
5464 bzero (&it
->current
, sizeof it
->current
);
5465 it
->current
.overlay_string_index
= -1;
5466 it
->current
.dpvec_index
= -1;
5467 xassert (charpos
>= 0);
5469 /* If STRING is specified, use its multibyteness, otherwise use the
5470 setting of MULTIBYTE, if specified. */
5472 it
->multibyte_p
= multibyte
> 0;
5476 xassert (STRINGP (string
));
5477 it
->string
= string
;
5479 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5480 it
->method
= GET_FROM_STRING
;
5481 it
->current
.string_pos
= string_pos (charpos
, string
);
5488 /* Note that we use IT->current.pos, not it->current.string_pos,
5489 for displaying C strings. */
5490 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5491 if (it
->multibyte_p
)
5493 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5494 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5498 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5499 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5502 it
->method
= GET_FROM_C_STRING
;
5505 /* PRECISION > 0 means don't return more than PRECISION characters
5507 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5508 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5510 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5511 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5512 FIELD_WIDTH < 0 means infinite field width. This is useful for
5513 padding with `-' at the end of a mode line. */
5514 if (field_width
< 0)
5515 field_width
= INFINITY
;
5516 if (field_width
> it
->end_charpos
- charpos
)
5517 it
->end_charpos
= charpos
+ field_width
;
5519 /* Use the standard display table for displaying strings. */
5520 if (DISP_TABLE_P (Vstandard_display_table
))
5521 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5523 it
->stop_charpos
= charpos
;
5529 /***********************************************************************
5531 ***********************************************************************/
5533 /* Map enum it_method value to corresponding next_element_from_* function. */
5535 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5537 next_element_from_buffer
,
5538 next_element_from_display_vector
,
5539 next_element_from_composition
,
5540 next_element_from_string
,
5541 next_element_from_c_string
,
5542 next_element_from_image
,
5543 next_element_from_stretch
5547 /* Load IT's display element fields with information about the next
5548 display element from the current position of IT. Value is zero if
5549 end of buffer (or C string) is reached. */
5551 static struct frame
*last_escape_glyph_frame
= NULL
;
5552 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5553 static int last_escape_glyph_merged_face_id
= 0;
5556 get_next_display_element (it
)
5559 /* Non-zero means that we found a display element. Zero means that
5560 we hit the end of what we iterate over. Performance note: the
5561 function pointer `method' used here turns out to be faster than
5562 using a sequence of if-statements. */
5566 success_p
= (*get_next_element
[it
->method
]) (it
);
5568 if (it
->what
== IT_CHARACTER
)
5570 /* Map via display table or translate control characters.
5571 IT->c, IT->len etc. have been set to the next character by
5572 the function call above. If we have a display table, and it
5573 contains an entry for IT->c, translate it. Don't do this if
5574 IT->c itself comes from a display table, otherwise we could
5575 end up in an infinite recursion. (An alternative could be to
5576 count the recursion depth of this function and signal an
5577 error when a certain maximum depth is reached.) Is it worth
5579 if (success_p
&& it
->dpvec
== NULL
)
5584 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5587 struct Lisp_Vector
*v
= XVECTOR (dv
);
5589 /* Return the first character from the display table
5590 entry, if not empty. If empty, don't display the
5591 current character. */
5594 it
->dpvec_char_len
= it
->len
;
5595 it
->dpvec
= v
->contents
;
5596 it
->dpend
= v
->contents
+ v
->size
;
5597 it
->current
.dpvec_index
= 0;
5598 it
->dpvec_face_id
= -1;
5599 it
->saved_face_id
= it
->face_id
;
5600 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5605 set_iterator_to_next (it
, 0);
5610 /* Translate control characters into `\003' or `^C' form.
5611 Control characters coming from a display table entry are
5612 currently not translated because we use IT->dpvec to hold
5613 the translation. This could easily be changed but I
5614 don't believe that it is worth doing.
5616 If it->multibyte_p is nonzero, eight-bit characters and
5617 non-printable multibyte characters are also translated to
5620 If it->multibyte_p is zero, eight-bit characters that
5621 don't have corresponding multibyte char code are also
5622 translated to octal form. */
5623 else if ((it
->c
< ' '
5624 && (it
->area
!= TEXT_AREA
5625 /* In mode line, treat \n like other crl chars. */
5627 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5628 || (it
->c
!= '\n' && it
->c
!= '\t')))
5632 || !CHAR_PRINTABLE_P (it
->c
)
5633 || (!NILP (Vnobreak_char_display
)
5634 && (it
->c
== 0x8a0 || it
->c
== 0x8ad
5635 || it
->c
== 0x920 || it
->c
== 0x92d
5636 || it
->c
== 0xe20 || it
->c
== 0xe2d
5637 || it
->c
== 0xf20 || it
->c
== 0xf2d)))
5639 && (!unibyte_display_via_language_environment
5640 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
5642 /* IT->c is a control character which must be displayed
5643 either as '\003' or as `^C' where the '\\' and '^'
5644 can be defined in the display table. Fill
5645 IT->ctl_chars with glyphs for what we have to
5646 display. Then, set IT->dpvec to these glyphs. */
5649 int face_id
, lface_id
= 0 ;
5652 /* Handle control characters with ^. */
5654 if (it
->c
< 128 && it
->ctl_arrow_p
)
5656 g
= '^'; /* default glyph for Control */
5657 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5659 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5660 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5662 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5663 lface_id
= FAST_GLYPH_FACE (g
);
5667 g
= FAST_GLYPH_CHAR (g
);
5668 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5671 else if (it
->f
== last_escape_glyph_frame
5672 && it
->face_id
== last_escape_glyph_face_id
)
5674 face_id
= last_escape_glyph_merged_face_id
;
5678 /* Merge the escape-glyph face into the current face. */
5679 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5681 last_escape_glyph_frame
= it
->f
;
5682 last_escape_glyph_face_id
= it
->face_id
;
5683 last_escape_glyph_merged_face_id
= face_id
;
5686 XSETINT (it
->ctl_chars
[0], g
);
5688 XSETINT (it
->ctl_chars
[1], g
);
5690 goto display_control
;
5693 /* Handle non-break space in the mode where it only gets
5696 if (EQ (Vnobreak_char_display
, Qt
)
5697 && (it
->c
== 0x8a0 || it
->c
== 0x920
5698 || it
->c
== 0xe20 || it
->c
== 0xf20))
5700 /* Merge the no-break-space face into the current face. */
5701 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5705 XSETINT (it
->ctl_chars
[0], g
);
5707 goto display_control
;
5710 /* Handle sequences that start with the "escape glyph". */
5712 /* the default escape glyph is \. */
5713 escape_glyph
= '\\';
5716 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5717 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5719 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5720 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5724 /* The display table specified a face.
5725 Merge it into face_id and also into escape_glyph. */
5726 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5727 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5730 else if (it
->f
== last_escape_glyph_frame
5731 && it
->face_id
== last_escape_glyph_face_id
)
5733 face_id
= last_escape_glyph_merged_face_id
;
5737 /* Merge the escape-glyph face into the current face. */
5738 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5740 last_escape_glyph_frame
= it
->f
;
5741 last_escape_glyph_face_id
= it
->face_id
;
5742 last_escape_glyph_merged_face_id
= face_id
;
5745 /* Handle soft hyphens in the mode where they only get
5748 if (EQ (Vnobreak_char_display
, Qt
)
5749 && (it
->c
== 0x8ad || it
->c
== 0x92d
5750 || it
->c
== 0xe2d || it
->c
== 0xf2d))
5753 XSETINT (it
->ctl_chars
[0], g
);
5755 goto display_control
;
5758 /* Handle non-break space and soft hyphen
5759 with the escape glyph. */
5761 if (it
->c
== 0x8a0 || it
->c
== 0x8ad
5762 || it
->c
== 0x920 || it
->c
== 0x92d
5763 || it
->c
== 0xe20 || it
->c
== 0xe2d
5764 || it
->c
== 0xf20 || it
->c
== 0xf2d)
5766 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5767 g
= it
->c
= ((it
->c
& 0xf) == 0 ? ' ' : '-');
5768 XSETINT (it
->ctl_chars
[1], g
);
5770 goto display_control
;
5774 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5778 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5779 if (SINGLE_BYTE_CHAR_P (it
->c
))
5780 str
[0] = it
->c
, len
= 1;
5783 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5786 /* It's an invalid character, which shouldn't
5787 happen actually, but due to bugs it may
5788 happen. Let's print the char as is, there's
5789 not much meaningful we can do with it. */
5791 str
[1] = it
->c
>> 8;
5792 str
[2] = it
->c
>> 16;
5793 str
[3] = it
->c
>> 24;
5798 for (i
= 0; i
< len
; i
++)
5800 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5801 /* Insert three more glyphs into IT->ctl_chars for
5802 the octal display of the character. */
5803 g
= ((str
[i
] >> 6) & 7) + '0';
5804 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5805 g
= ((str
[i
] >> 3) & 7) + '0';
5806 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5807 g
= (str
[i
] & 7) + '0';
5808 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5814 /* Set up IT->dpvec and return first character from it. */
5815 it
->dpvec_char_len
= it
->len
;
5816 it
->dpvec
= it
->ctl_chars
;
5817 it
->dpend
= it
->dpvec
+ ctl_len
;
5818 it
->current
.dpvec_index
= 0;
5819 it
->dpvec_face_id
= face_id
;
5820 it
->saved_face_id
= it
->face_id
;
5821 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5827 /* Adjust face id for a multibyte character. There are no
5828 multibyte character in unibyte text. */
5831 && FRAME_WINDOW_P (it
->f
))
5833 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5834 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5838 /* Is this character the last one of a run of characters with
5839 box? If yes, set IT->end_of_box_run_p to 1. */
5846 it
->end_of_box_run_p
5847 = ((face_id
= face_after_it_pos (it
),
5848 face_id
!= it
->face_id
)
5849 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5850 face
->box
== FACE_NO_BOX
));
5853 /* Value is 0 if end of buffer or string reached. */
5858 /* Move IT to the next display element.
5860 RESEAT_P non-zero means if called on a newline in buffer text,
5861 skip to the next visible line start.
5863 Functions get_next_display_element and set_iterator_to_next are
5864 separate because I find this arrangement easier to handle than a
5865 get_next_display_element function that also increments IT's
5866 position. The way it is we can first look at an iterator's current
5867 display element, decide whether it fits on a line, and if it does,
5868 increment the iterator position. The other way around we probably
5869 would either need a flag indicating whether the iterator has to be
5870 incremented the next time, or we would have to implement a
5871 decrement position function which would not be easy to write. */
5874 set_iterator_to_next (it
, reseat_p
)
5878 /* Reset flags indicating start and end of a sequence of characters
5879 with box. Reset them at the start of this function because
5880 moving the iterator to a new position might set them. */
5881 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5885 case GET_FROM_BUFFER
:
5886 /* The current display element of IT is a character from
5887 current_buffer. Advance in the buffer, and maybe skip over
5888 invisible lines that are so because of selective display. */
5889 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5890 reseat_at_next_visible_line_start (it
, 0);
5893 xassert (it
->len
!= 0);
5894 IT_BYTEPOS (*it
) += it
->len
;
5895 IT_CHARPOS (*it
) += 1;
5896 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5900 case GET_FROM_COMPOSITION
:
5901 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5902 xassert (it
->sp
> 0);
5904 if (it
->method
== GET_FROM_STRING
)
5906 IT_STRING_BYTEPOS (*it
) += it
->len
;
5907 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5908 goto consider_string_end
;
5910 else if (it
->method
== GET_FROM_BUFFER
)
5912 IT_BYTEPOS (*it
) += it
->len
;
5913 IT_CHARPOS (*it
) += it
->cmp_len
;
5917 case GET_FROM_C_STRING
:
5918 /* Current display element of IT is from a C string. */
5919 IT_BYTEPOS (*it
) += it
->len
;
5920 IT_CHARPOS (*it
) += 1;
5923 case GET_FROM_DISPLAY_VECTOR
:
5924 /* Current display element of IT is from a display table entry.
5925 Advance in the display table definition. Reset it to null if
5926 end reached, and continue with characters from buffers/
5928 ++it
->current
.dpvec_index
;
5930 /* Restore face of the iterator to what they were before the
5931 display vector entry (these entries may contain faces). */
5932 it
->face_id
= it
->saved_face_id
;
5934 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5936 int recheck_faces
= it
->ellipsis_p
;
5939 it
->method
= GET_FROM_C_STRING
;
5940 else if (STRINGP (it
->string
))
5941 it
->method
= GET_FROM_STRING
;
5944 it
->method
= GET_FROM_BUFFER
;
5945 it
->object
= it
->w
->buffer
;
5949 it
->current
.dpvec_index
= -1;
5951 /* Skip over characters which were displayed via IT->dpvec. */
5952 if (it
->dpvec_char_len
< 0)
5953 reseat_at_next_visible_line_start (it
, 1);
5954 else if (it
->dpvec_char_len
> 0)
5956 if (it
->method
== GET_FROM_STRING
5957 && it
->n_overlay_strings
> 0)
5958 it
->ignore_overlay_strings_at_pos_p
= 1;
5959 it
->len
= it
->dpvec_char_len
;
5960 set_iterator_to_next (it
, reseat_p
);
5963 /* Maybe recheck faces after display vector */
5965 it
->stop_charpos
= IT_CHARPOS (*it
);
5969 case GET_FROM_STRING
:
5970 /* Current display element is a character from a Lisp string. */
5971 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5972 IT_STRING_BYTEPOS (*it
) += it
->len
;
5973 IT_STRING_CHARPOS (*it
) += 1;
5975 consider_string_end
:
5977 if (it
->current
.overlay_string_index
>= 0)
5979 /* IT->string is an overlay string. Advance to the
5980 next, if there is one. */
5981 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5982 next_overlay_string (it
);
5986 /* IT->string is not an overlay string. If we reached
5987 its end, and there is something on IT->stack, proceed
5988 with what is on the stack. This can be either another
5989 string, this time an overlay string, or a buffer. */
5990 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5994 if (it
->method
== GET_FROM_STRING
)
5995 goto consider_string_end
;
6000 case GET_FROM_IMAGE
:
6001 case GET_FROM_STRETCH
:
6002 /* The position etc with which we have to proceed are on
6003 the stack. The position may be at the end of a string,
6004 if the `display' property takes up the whole string. */
6005 xassert (it
->sp
> 0);
6007 if (it
->method
== GET_FROM_STRING
)
6008 goto consider_string_end
;
6012 /* There are no other methods defined, so this should be a bug. */
6016 xassert (it
->method
!= GET_FROM_STRING
6017 || (STRINGP (it
->string
)
6018 && IT_STRING_CHARPOS (*it
) >= 0));
6021 /* Load IT's display element fields with information about the next
6022 display element which comes from a display table entry or from the
6023 result of translating a control character to one of the forms `^C'
6026 IT->dpvec holds the glyphs to return as characters.
6027 IT->saved_face_id holds the face id before the display vector--
6028 it is restored into IT->face_idin set_iterator_to_next. */
6031 next_element_from_display_vector (it
)
6035 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6037 it
->face_id
= it
->saved_face_id
;
6039 if (INTEGERP (*it
->dpvec
)
6040 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
6044 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
6045 it
->c
= FAST_GLYPH_CHAR (g
);
6046 it
->len
= CHAR_BYTES (it
->c
);
6048 /* The entry may contain a face id to use. Such a face id is
6049 the id of a Lisp face, not a realized face. A face id of
6050 zero means no face is specified. */
6051 if (it
->dpvec_face_id
>= 0)
6052 it
->face_id
= it
->dpvec_face_id
;
6055 int lface_id
= FAST_GLYPH_FACE (g
);
6057 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6062 /* Display table entry is invalid. Return a space. */
6063 it
->c
= ' ', it
->len
= 1;
6065 /* Don't change position and object of the iterator here. They are
6066 still the values of the character that had this display table
6067 entry or was translated, and that's what we want. */
6068 it
->what
= IT_CHARACTER
;
6073 /* Load IT with the next display element from Lisp string IT->string.
6074 IT->current.string_pos is the current position within the string.
6075 If IT->current.overlay_string_index >= 0, the Lisp string is an
6079 next_element_from_string (it
)
6082 struct text_pos position
;
6084 xassert (STRINGP (it
->string
));
6085 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6086 position
= it
->current
.string_pos
;
6088 /* Time to check for invisible text? */
6089 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6090 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6094 /* Since a handler may have changed IT->method, we must
6096 return get_next_display_element (it
);
6099 if (it
->current
.overlay_string_index
>= 0)
6101 /* Get the next character from an overlay string. In overlay
6102 strings, There is no field width or padding with spaces to
6104 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6109 else if (STRING_MULTIBYTE (it
->string
))
6111 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6112 const unsigned char *s
= (SDATA (it
->string
)
6113 + IT_STRING_BYTEPOS (*it
));
6114 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
6118 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6124 /* Get the next character from a Lisp string that is not an
6125 overlay string. Such strings come from the mode line, for
6126 example. We may have to pad with spaces, or truncate the
6127 string. See also next_element_from_c_string. */
6128 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6133 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6135 /* Pad with spaces. */
6136 it
->c
= ' ', it
->len
= 1;
6137 CHARPOS (position
) = BYTEPOS (position
) = -1;
6139 else if (STRING_MULTIBYTE (it
->string
))
6141 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6142 const unsigned char *s
= (SDATA (it
->string
)
6143 + IT_STRING_BYTEPOS (*it
));
6144 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
6148 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6153 /* Record what we have and where it came from. */
6154 it
->what
= IT_CHARACTER
;
6155 it
->object
= it
->string
;
6156 it
->position
= position
;
6161 /* Load IT with next display element from C string IT->s.
6162 IT->string_nchars is the maximum number of characters to return
6163 from the string. IT->end_charpos may be greater than
6164 IT->string_nchars when this function is called, in which case we
6165 may have to return padding spaces. Value is zero if end of string
6166 reached, including padding spaces. */
6169 next_element_from_c_string (it
)
6175 it
->what
= IT_CHARACTER
;
6176 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6179 /* IT's position can be greater IT->string_nchars in case a field
6180 width or precision has been specified when the iterator was
6182 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6184 /* End of the game. */
6188 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6190 /* Pad with spaces. */
6191 it
->c
= ' ', it
->len
= 1;
6192 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6194 else if (it
->multibyte_p
)
6196 /* Implementation note: The calls to strlen apparently aren't a
6197 performance problem because there is no noticeable performance
6198 difference between Emacs running in unibyte or multibyte mode. */
6199 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6200 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
6204 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6210 /* Set up IT to return characters from an ellipsis, if appropriate.
6211 The definition of the ellipsis glyphs may come from a display table
6212 entry. This function Fills IT with the first glyph from the
6213 ellipsis if an ellipsis is to be displayed. */
6216 next_element_from_ellipsis (it
)
6219 if (it
->selective_display_ellipsis_p
)
6220 setup_for_ellipsis (it
, it
->len
);
6223 /* The face at the current position may be different from the
6224 face we find after the invisible text. Remember what it
6225 was in IT->saved_face_id, and signal that it's there by
6226 setting face_before_selective_p. */
6227 it
->saved_face_id
= it
->face_id
;
6228 it
->method
= GET_FROM_BUFFER
;
6229 it
->object
= it
->w
->buffer
;
6230 reseat_at_next_visible_line_start (it
, 1);
6231 it
->face_before_selective_p
= 1;
6234 return get_next_display_element (it
);
6238 /* Deliver an image display element. The iterator IT is already
6239 filled with image information (done in handle_display_prop). Value
6244 next_element_from_image (it
)
6247 it
->what
= IT_IMAGE
;
6252 /* Fill iterator IT with next display element from a stretch glyph
6253 property. IT->object is the value of the text property. Value is
6257 next_element_from_stretch (it
)
6260 it
->what
= IT_STRETCH
;
6265 /* Load IT with the next display element from current_buffer. Value
6266 is zero if end of buffer reached. IT->stop_charpos is the next
6267 position at which to stop and check for text properties or buffer
6271 next_element_from_buffer (it
)
6276 /* Check this assumption, otherwise, we would never enter the
6277 if-statement, below. */
6278 xassert (IT_CHARPOS (*it
) >= BEGV
6279 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
6281 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6283 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6285 int overlay_strings_follow_p
;
6287 /* End of the game, except when overlay strings follow that
6288 haven't been returned yet. */
6289 if (it
->overlay_strings_at_end_processed_p
)
6290 overlay_strings_follow_p
= 0;
6293 it
->overlay_strings_at_end_processed_p
= 1;
6294 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6297 if (overlay_strings_follow_p
)
6298 success_p
= get_next_display_element (it
);
6302 it
->position
= it
->current
.pos
;
6309 return get_next_display_element (it
);
6314 /* No face changes, overlays etc. in sight, so just return a
6315 character from current_buffer. */
6318 /* Maybe run the redisplay end trigger hook. Performance note:
6319 This doesn't seem to cost measurable time. */
6320 if (it
->redisplay_end_trigger_charpos
6322 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6323 run_redisplay_end_trigger_hook (it
);
6325 /* Get the next character, maybe multibyte. */
6326 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6327 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6329 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
6330 - IT_BYTEPOS (*it
));
6331 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
6334 it
->c
= *p
, it
->len
= 1;
6336 /* Record what we have and where it came from. */
6337 it
->what
= IT_CHARACTER
;
6338 it
->object
= it
->w
->buffer
;
6339 it
->position
= it
->current
.pos
;
6341 /* Normally we return the character found above, except when we
6342 really want to return an ellipsis for selective display. */
6347 /* A value of selective > 0 means hide lines indented more
6348 than that number of columns. */
6349 if (it
->selective
> 0
6350 && IT_CHARPOS (*it
) + 1 < ZV
6351 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6352 IT_BYTEPOS (*it
) + 1,
6353 (double) it
->selective
)) /* iftc */
6355 success_p
= next_element_from_ellipsis (it
);
6356 it
->dpvec_char_len
= -1;
6359 else if (it
->c
== '\r' && it
->selective
== -1)
6361 /* A value of selective == -1 means that everything from the
6362 CR to the end of the line is invisible, with maybe an
6363 ellipsis displayed for it. */
6364 success_p
= next_element_from_ellipsis (it
);
6365 it
->dpvec_char_len
= -1;
6370 /* Value is zero if end of buffer reached. */
6371 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6376 /* Run the redisplay end trigger hook for IT. */
6379 run_redisplay_end_trigger_hook (it
)
6382 Lisp_Object args
[3];
6384 /* IT->glyph_row should be non-null, i.e. we should be actually
6385 displaying something, or otherwise we should not run the hook. */
6386 xassert (it
->glyph_row
);
6388 /* Set up hook arguments. */
6389 args
[0] = Qredisplay_end_trigger_functions
;
6390 args
[1] = it
->window
;
6391 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6392 it
->redisplay_end_trigger_charpos
= 0;
6394 /* Since we are *trying* to run these functions, don't try to run
6395 them again, even if they get an error. */
6396 it
->w
->redisplay_end_trigger
= Qnil
;
6397 Frun_hook_with_args (3, args
);
6399 /* Notice if it changed the face of the character we are on. */
6400 handle_face_prop (it
);
6404 /* Deliver a composition display element. The iterator IT is already
6405 filled with composition information (done in
6406 handle_composition_prop). Value is always 1. */
6409 next_element_from_composition (it
)
6412 it
->what
= IT_COMPOSITION
;
6413 it
->position
= (STRINGP (it
->string
)
6414 ? it
->current
.string_pos
6416 if (STRINGP (it
->string
))
6417 it
->object
= it
->string
;
6419 it
->object
= it
->w
->buffer
;
6425 /***********************************************************************
6426 Moving an iterator without producing glyphs
6427 ***********************************************************************/
6429 /* Check if iterator is at a position corresponding to a valid buffer
6430 position after some move_it_ call. */
6432 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6433 ((it)->method == GET_FROM_STRING \
6434 ? IT_STRING_CHARPOS (*it) == 0 \
6438 /* Move iterator IT to a specified buffer or X position within one
6439 line on the display without producing glyphs.
6441 OP should be a bit mask including some or all of these bits:
6442 MOVE_TO_X: Stop on reaching x-position TO_X.
6443 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6444 Regardless of OP's value, stop in reaching the end of the display line.
6446 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6447 This means, in particular, that TO_X includes window's horizontal
6450 The return value has several possible values that
6451 say what condition caused the scan to stop:
6453 MOVE_POS_MATCH_OR_ZV
6454 - when TO_POS or ZV was reached.
6457 -when TO_X was reached before TO_POS or ZV were reached.
6460 - when we reached the end of the display area and the line must
6464 - when we reached the end of the display area and the line is
6468 - when we stopped at a line end, i.e. a newline or a CR and selective
6471 static enum move_it_result
6472 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
6474 int to_charpos
, to_x
, op
;
6476 enum move_it_result result
= MOVE_UNDEFINED
;
6477 struct glyph_row
*saved_glyph_row
;
6479 /* Don't produce glyphs in produce_glyphs. */
6480 saved_glyph_row
= it
->glyph_row
;
6481 it
->glyph_row
= NULL
;
6483 #define BUFFER_POS_REACHED_P() \
6484 ((op & MOVE_TO_POS) != 0 \
6485 && BUFFERP (it->object) \
6486 && IT_CHARPOS (*it) >= to_charpos \
6487 && (it->method == GET_FROM_BUFFER \
6488 || (it->method == GET_FROM_DISPLAY_VECTOR \
6489 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6494 int x
, i
, ascent
= 0, descent
= 0;
6496 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
6497 if ((op
& MOVE_TO_POS
) != 0
6498 && BUFFERP (it
->object
)
6499 && it
->method
== GET_FROM_BUFFER
6500 && IT_CHARPOS (*it
) > to_charpos
)
6502 result
= MOVE_POS_MATCH_OR_ZV
;
6506 /* Stop when ZV reached.
6507 We used to stop here when TO_CHARPOS reached as well, but that is
6508 too soon if this glyph does not fit on this line. So we handle it
6509 explicitly below. */
6510 if (!get_next_display_element (it
)
6511 || (it
->truncate_lines_p
6512 && BUFFER_POS_REACHED_P ()))
6514 result
= MOVE_POS_MATCH_OR_ZV
;
6518 /* The call to produce_glyphs will get the metrics of the
6519 display element IT is loaded with. We record in x the
6520 x-position before this display element in case it does not
6524 /* Remember the line height so far in case the next element doesn't
6526 if (!it
->truncate_lines_p
)
6528 ascent
= it
->max_ascent
;
6529 descent
= it
->max_descent
;
6532 PRODUCE_GLYPHS (it
);
6534 if (it
->area
!= TEXT_AREA
)
6536 set_iterator_to_next (it
, 1);
6540 /* The number of glyphs we get back in IT->nglyphs will normally
6541 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6542 character on a terminal frame, or (iii) a line end. For the
6543 second case, IT->nglyphs - 1 padding glyphs will be present
6544 (on X frames, there is only one glyph produced for a
6545 composite character.
6547 The behavior implemented below means, for continuation lines,
6548 that as many spaces of a TAB as fit on the current line are
6549 displayed there. For terminal frames, as many glyphs of a
6550 multi-glyph character are displayed in the current line, too.
6551 This is what the old redisplay code did, and we keep it that
6552 way. Under X, the whole shape of a complex character must
6553 fit on the line or it will be completely displayed in the
6556 Note that both for tabs and padding glyphs, all glyphs have
6560 /* More than one glyph or glyph doesn't fit on line. All
6561 glyphs have the same width. */
6562 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6564 int x_before_this_char
= x
;
6565 int hpos_before_this_char
= it
->hpos
;
6567 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6569 new_x
= x
+ single_glyph_width
;
6571 /* We want to leave anything reaching TO_X to the caller. */
6572 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6574 if (BUFFER_POS_REACHED_P ())
6575 goto buffer_pos_reached
;
6577 result
= MOVE_X_REACHED
;
6580 else if (/* Lines are continued. */
6581 !it
->truncate_lines_p
6582 && (/* And glyph doesn't fit on the line. */
6583 new_x
> it
->last_visible_x
6584 /* Or it fits exactly and we're on a window
6586 || (new_x
== it
->last_visible_x
6587 && FRAME_WINDOW_P (it
->f
))))
6589 if (/* IT->hpos == 0 means the very first glyph
6590 doesn't fit on the line, e.g. a wide image. */
6592 || (new_x
== it
->last_visible_x
6593 && FRAME_WINDOW_P (it
->f
)))
6596 it
->current_x
= new_x
;
6598 /* The character's last glyph just barely fits
6600 if (i
== it
->nglyphs
- 1)
6602 /* If this is the destination position,
6603 return a position *before* it in this row,
6604 now that we know it fits in this row. */
6605 if (BUFFER_POS_REACHED_P ())
6607 it
->hpos
= hpos_before_this_char
;
6608 it
->current_x
= x_before_this_char
;
6609 result
= MOVE_POS_MATCH_OR_ZV
;
6613 set_iterator_to_next (it
, 1);
6614 #ifdef HAVE_WINDOW_SYSTEM
6615 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6617 if (!get_next_display_element (it
))
6619 result
= MOVE_POS_MATCH_OR_ZV
;
6622 if (BUFFER_POS_REACHED_P ())
6624 if (ITERATOR_AT_END_OF_LINE_P (it
))
6625 result
= MOVE_POS_MATCH_OR_ZV
;
6627 result
= MOVE_LINE_CONTINUED
;
6630 if (ITERATOR_AT_END_OF_LINE_P (it
))
6632 result
= MOVE_NEWLINE_OR_CR
;
6636 #endif /* HAVE_WINDOW_SYSTEM */
6642 it
->max_ascent
= ascent
;
6643 it
->max_descent
= descent
;
6646 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6648 result
= MOVE_LINE_CONTINUED
;
6651 else if (BUFFER_POS_REACHED_P ())
6652 goto buffer_pos_reached
;
6653 else if (new_x
> it
->first_visible_x
)
6655 /* Glyph is visible. Increment number of glyphs that
6656 would be displayed. */
6661 /* Glyph is completely off the left margin of the display
6662 area. Nothing to do. */
6666 if (result
!= MOVE_UNDEFINED
)
6669 else if (BUFFER_POS_REACHED_P ())
6673 it
->max_ascent
= ascent
;
6674 it
->max_descent
= descent
;
6675 result
= MOVE_POS_MATCH_OR_ZV
;
6678 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6680 /* Stop when TO_X specified and reached. This check is
6681 necessary here because of lines consisting of a line end,
6682 only. The line end will not produce any glyphs and we
6683 would never get MOVE_X_REACHED. */
6684 xassert (it
->nglyphs
== 0);
6685 result
= MOVE_X_REACHED
;
6689 /* Is this a line end? If yes, we're done. */
6690 if (ITERATOR_AT_END_OF_LINE_P (it
))
6692 result
= MOVE_NEWLINE_OR_CR
;
6696 /* The current display element has been consumed. Advance
6698 set_iterator_to_next (it
, 1);
6700 /* Stop if lines are truncated and IT's current x-position is
6701 past the right edge of the window now. */
6702 if (it
->truncate_lines_p
6703 && it
->current_x
>= it
->last_visible_x
)
6705 #ifdef HAVE_WINDOW_SYSTEM
6706 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6708 if (!get_next_display_element (it
)
6709 || BUFFER_POS_REACHED_P ())
6711 result
= MOVE_POS_MATCH_OR_ZV
;
6714 if (ITERATOR_AT_END_OF_LINE_P (it
))
6716 result
= MOVE_NEWLINE_OR_CR
;
6720 #endif /* HAVE_WINDOW_SYSTEM */
6721 result
= MOVE_LINE_TRUNCATED
;
6726 #undef BUFFER_POS_REACHED_P
6728 /* Restore the iterator settings altered at the beginning of this
6730 it
->glyph_row
= saved_glyph_row
;
6735 /* Move IT forward until it satisfies one or more of the criteria in
6736 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6738 OP is a bit-mask that specifies where to stop, and in particular,
6739 which of those four position arguments makes a difference. See the
6740 description of enum move_operation_enum.
6742 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6743 screen line, this function will set IT to the next position >
6747 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6749 int to_charpos
, to_x
, to_y
, to_vpos
;
6752 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6758 if (op
& MOVE_TO_VPOS
)
6760 /* If no TO_CHARPOS and no TO_X specified, stop at the
6761 start of the line TO_VPOS. */
6762 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6764 if (it
->vpos
== to_vpos
)
6770 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6774 /* TO_VPOS >= 0 means stop at TO_X in the line at
6775 TO_VPOS, or at TO_POS, whichever comes first. */
6776 if (it
->vpos
== to_vpos
)
6782 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6784 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6789 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6791 /* We have reached TO_X but not in the line we want. */
6792 skip
= move_it_in_display_line_to (it
, to_charpos
,
6794 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6802 else if (op
& MOVE_TO_Y
)
6804 struct it it_backup
;
6806 /* TO_Y specified means stop at TO_X in the line containing
6807 TO_Y---or at TO_CHARPOS if this is reached first. The
6808 problem is that we can't really tell whether the line
6809 contains TO_Y before we have completely scanned it, and
6810 this may skip past TO_X. What we do is to first scan to
6813 If TO_X is not specified, use a TO_X of zero. The reason
6814 is to make the outcome of this function more predictable.
6815 If we didn't use TO_X == 0, we would stop at the end of
6816 the line which is probably not what a caller would expect
6818 skip
= move_it_in_display_line_to (it
, to_charpos
,
6822 | (op
& MOVE_TO_POS
)));
6824 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6825 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6831 /* If TO_X was reached, we would like to know whether TO_Y
6832 is in the line. This can only be said if we know the
6833 total line height which requires us to scan the rest of
6835 if (skip
== MOVE_X_REACHED
)
6838 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6839 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6841 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6844 /* Now, decide whether TO_Y is in this line. */
6845 line_height
= it
->max_ascent
+ it
->max_descent
;
6846 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6848 if (to_y
>= it
->current_y
6849 && to_y
< it
->current_y
+ line_height
)
6851 if (skip
== MOVE_X_REACHED
)
6852 /* If TO_Y is in this line and TO_X was reached above,
6853 we scanned too far. We have to restore IT's settings
6854 to the ones before skipping. */
6858 else if (skip
== MOVE_X_REACHED
)
6861 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6868 else if (BUFFERP (it
->object
)
6869 && it
->method
== GET_FROM_BUFFER
6870 && IT_CHARPOS (*it
) >= to_charpos
)
6871 skip
= MOVE_POS_MATCH_OR_ZV
;
6873 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6877 case MOVE_POS_MATCH_OR_ZV
:
6881 case MOVE_NEWLINE_OR_CR
:
6882 set_iterator_to_next (it
, 1);
6883 it
->continuation_lines_width
= 0;
6886 case MOVE_LINE_TRUNCATED
:
6887 it
->continuation_lines_width
= 0;
6888 reseat_at_next_visible_line_start (it
, 0);
6889 if ((op
& MOVE_TO_POS
) != 0
6890 && IT_CHARPOS (*it
) > to_charpos
)
6897 case MOVE_LINE_CONTINUED
:
6898 /* For continued lines ending in a tab, some of the glyphs
6899 associated with the tab are displayed on the current
6900 line. Since it->current_x does not include these glyphs,
6901 we use it->last_visible_x instead. */
6902 it
->continuation_lines_width
+=
6903 (it
->c
== '\t') ? it
->last_visible_x
: it
->current_x
;
6910 /* Reset/increment for the next run. */
6911 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6912 it
->current_x
= it
->hpos
= 0;
6913 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6915 last_height
= it
->max_ascent
+ it
->max_descent
;
6916 last_max_ascent
= it
->max_ascent
;
6917 it
->max_ascent
= it
->max_descent
= 0;
6922 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6926 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6928 If DY > 0, move IT backward at least that many pixels. DY = 0
6929 means move IT backward to the preceding line start or BEGV. This
6930 function may move over more than DY pixels if IT->current_y - DY
6931 ends up in the middle of a line; in this case IT->current_y will be
6932 set to the top of the line moved to. */
6935 move_it_vertically_backward (it
, dy
)
6946 start_pos
= IT_CHARPOS (*it
);
6948 /* Estimate how many newlines we must move back. */
6949 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6951 /* Set the iterator's position that many lines back. */
6952 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6953 back_to_previous_visible_line_start (it
);
6955 /* Reseat the iterator here. When moving backward, we don't want
6956 reseat to skip forward over invisible text, set up the iterator
6957 to deliver from overlay strings at the new position etc. So,
6958 use reseat_1 here. */
6959 reseat_1 (it
, it
->current
.pos
, 1);
6961 /* We are now surely at a line start. */
6962 it
->current_x
= it
->hpos
= 0;
6963 it
->continuation_lines_width
= 0;
6965 /* Move forward and see what y-distance we moved. First move to the
6966 start of the next line so that we get its height. We need this
6967 height to be able to tell whether we reached the specified
6970 it2
.max_ascent
= it2
.max_descent
= 0;
6973 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6974 MOVE_TO_POS
| MOVE_TO_VPOS
);
6976 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
6977 xassert (IT_CHARPOS (*it
) >= BEGV
);
6980 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6981 xassert (IT_CHARPOS (*it
) >= BEGV
);
6982 /* H is the actual vertical distance from the position in *IT
6983 and the starting position. */
6984 h
= it2
.current_y
- it
->current_y
;
6985 /* NLINES is the distance in number of lines. */
6986 nlines
= it2
.vpos
- it
->vpos
;
6988 /* Correct IT's y and vpos position
6989 so that they are relative to the starting point. */
6995 /* DY == 0 means move to the start of the screen line. The
6996 value of nlines is > 0 if continuation lines were involved. */
6998 move_it_by_lines (it
, nlines
, 1);
7000 /* I think this assert is bogus if buffer contains
7001 invisible text or images. KFS. */
7002 xassert (IT_CHARPOS (*it
) <= start_pos
);
7007 /* The y-position we try to reach, relative to *IT.
7008 Note that H has been subtracted in front of the if-statement. */
7009 int target_y
= it
->current_y
+ h
- dy
;
7010 int y0
= it3
.current_y
;
7011 int y1
= line_bottom_y (&it3
);
7012 int line_height
= y1
- y0
;
7014 /* If we did not reach target_y, try to move further backward if
7015 we can. If we moved too far backward, try to move forward. */
7016 if (target_y
< it
->current_y
7017 /* This is heuristic. In a window that's 3 lines high, with
7018 a line height of 13 pixels each, recentering with point
7019 on the bottom line will try to move -39/2 = 19 pixels
7020 backward. Try to avoid moving into the first line. */
7021 && (it
->current_y
- target_y
7022 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7023 && IT_CHARPOS (*it
) > BEGV
)
7025 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7026 target_y
- it
->current_y
));
7027 dy
= it
->current_y
- target_y
;
7028 goto move_further_back
;
7030 else if (target_y
>= it
->current_y
+ line_height
7031 && IT_CHARPOS (*it
) < ZV
)
7033 /* Should move forward by at least one line, maybe more.
7035 Note: Calling move_it_by_lines can be expensive on
7036 terminal frames, where compute_motion is used (via
7037 vmotion) to do the job, when there are very long lines
7038 and truncate-lines is nil. That's the reason for
7039 treating terminal frames specially here. */
7041 if (!FRAME_WINDOW_P (it
->f
))
7042 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7047 move_it_by_lines (it
, 1, 1);
7049 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7053 /* I think this assert is bogus if buffer contains
7054 invisible text or images. KFS. */
7055 xassert (IT_CHARPOS (*it
) >= BEGV
);
7062 /* Move IT by a specified amount of pixel lines DY. DY negative means
7063 move backwards. DY = 0 means move to start of screen line. At the
7064 end, IT will be on the start of a screen line. */
7067 move_it_vertically (it
, dy
)
7072 move_it_vertically_backward (it
, -dy
);
7075 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7076 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7077 MOVE_TO_POS
| MOVE_TO_Y
);
7078 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7080 /* If buffer ends in ZV without a newline, move to the start of
7081 the line to satisfy the post-condition. */
7082 if (IT_CHARPOS (*it
) == ZV
7084 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7085 move_it_by_lines (it
, 0, 0);
7090 /* Move iterator IT past the end of the text line it is in. */
7093 move_it_past_eol (it
)
7096 enum move_it_result rc
;
7098 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7099 if (rc
== MOVE_NEWLINE_OR_CR
)
7100 set_iterator_to_next (it
, 0);
7104 #if 0 /* Currently not used. */
7106 /* Return non-zero if some text between buffer positions START_CHARPOS
7107 and END_CHARPOS is invisible. IT->window is the window for text
7111 invisible_text_between_p (it
, start_charpos
, end_charpos
)
7113 int start_charpos
, end_charpos
;
7115 Lisp_Object prop
, limit
;
7116 int invisible_found_p
;
7118 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
7120 /* Is text at START invisible? */
7121 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
7123 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
7124 invisible_found_p
= 1;
7127 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
7129 make_number (end_charpos
));
7130 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
7133 return invisible_found_p
;
7139 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7140 negative means move up. DVPOS == 0 means move to the start of the
7141 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7142 NEED_Y_P is zero, IT->current_y will be left unchanged.
7144 Further optimization ideas: If we would know that IT->f doesn't use
7145 a face with proportional font, we could be faster for
7146 truncate-lines nil. */
7149 move_it_by_lines (it
, dvpos
, need_y_p
)
7151 int dvpos
, need_y_p
;
7153 struct position pos
;
7155 /* The commented-out optimization uses vmotion on terminals. This
7156 gives bad results, because elements like it->what, on which
7157 callers such as pos_visible_p rely, aren't updated. */
7158 /* if (!FRAME_WINDOW_P (it->f))
7160 struct text_pos textpos;
7162 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7163 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7164 reseat (it, textpos, 1);
7165 it->vpos += pos.vpos;
7166 it->current_y += pos.vpos;
7172 /* DVPOS == 0 means move to the start of the screen line. */
7173 move_it_vertically_backward (it
, 0);
7174 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7175 /* Let next call to line_bottom_y calculate real line height */
7180 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7181 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7182 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7187 int start_charpos
, i
;
7189 /* Start at the beginning of the screen line containing IT's
7190 position. This may actually move vertically backwards,
7191 in case of overlays, so adjust dvpos accordingly. */
7193 move_it_vertically_backward (it
, 0);
7196 /* Go back -DVPOS visible lines and reseat the iterator there. */
7197 start_charpos
= IT_CHARPOS (*it
);
7198 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7199 back_to_previous_visible_line_start (it
);
7200 reseat (it
, it
->current
.pos
, 1);
7202 /* Move further back if we end up in a string or an image. */
7203 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7205 /* First try to move to start of display line. */
7207 move_it_vertically_backward (it
, 0);
7209 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7211 /* If start of line is still in string or image,
7212 move further back. */
7213 back_to_previous_visible_line_start (it
);
7214 reseat (it
, it
->current
.pos
, 1);
7218 it
->current_x
= it
->hpos
= 0;
7220 /* Above call may have moved too far if continuation lines
7221 are involved. Scan forward and see if it did. */
7223 it2
.vpos
= it2
.current_y
= 0;
7224 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7225 it
->vpos
-= it2
.vpos
;
7226 it
->current_y
-= it2
.current_y
;
7227 it
->current_x
= it
->hpos
= 0;
7229 /* If we moved too far back, move IT some lines forward. */
7230 if (it2
.vpos
> -dvpos
)
7232 int delta
= it2
.vpos
+ dvpos
;
7234 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7235 /* Move back again if we got too far ahead. */
7236 if (IT_CHARPOS (*it
) >= start_charpos
)
7242 /* Return 1 if IT points into the middle of a display vector. */
7245 in_display_vector_p (it
)
7248 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7249 && it
->current
.dpvec_index
> 0
7250 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7254 /***********************************************************************
7256 ***********************************************************************/
7259 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7263 add_to_log (format
, arg1
, arg2
)
7265 Lisp_Object arg1
, arg2
;
7267 Lisp_Object args
[3];
7268 Lisp_Object msg
, fmt
;
7271 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7274 /* Do nothing if called asynchronously. Inserting text into
7275 a buffer may call after-change-functions and alike and
7276 that would means running Lisp asynchronously. */
7277 if (handling_signal
)
7281 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7283 args
[0] = fmt
= build_string (format
);
7286 msg
= Fformat (3, args
);
7288 len
= SBYTES (msg
) + 1;
7289 SAFE_ALLOCA (buffer
, char *, len
);
7290 bcopy (SDATA (msg
), buffer
, len
);
7292 message_dolog (buffer
, len
- 1, 1, 0);
7299 /* Output a newline in the *Messages* buffer if "needs" one. */
7302 message_log_maybe_newline ()
7304 if (message_log_need_newline
)
7305 message_dolog ("", 0, 1, 0);
7309 /* Add a string M of length NBYTES to the message log, optionally
7310 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7311 nonzero, means interpret the contents of M as multibyte. This
7312 function calls low-level routines in order to bypass text property
7313 hooks, etc. which might not be safe to run.
7315 This may GC (insert may run before/after change hooks),
7316 so the buffer M must NOT point to a Lisp string. */
7319 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7321 int nbytes
, nlflag
, multibyte
;
7323 if (!NILP (Vmemory_full
))
7326 if (!NILP (Vmessage_log_max
))
7328 struct buffer
*oldbuf
;
7329 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7330 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7331 int point_at_end
= 0;
7333 Lisp_Object old_deactivate_mark
, tem
;
7334 struct gcpro gcpro1
;
7336 old_deactivate_mark
= Vdeactivate_mark
;
7337 oldbuf
= current_buffer
;
7338 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7339 current_buffer
->undo_list
= Qt
;
7341 oldpoint
= message_dolog_marker1
;
7342 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7343 oldbegv
= message_dolog_marker2
;
7344 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7345 oldzv
= message_dolog_marker3
;
7346 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7347 GCPRO1 (old_deactivate_mark
);
7355 BEGV_BYTE
= BEG_BYTE
;
7358 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7360 /* Insert the string--maybe converting multibyte to single byte
7361 or vice versa, so that all the text fits the buffer. */
7363 && NILP (current_buffer
->enable_multibyte_characters
))
7365 int i
, c
, char_bytes
;
7366 unsigned char work
[1];
7368 /* Convert a multibyte string to single-byte
7369 for the *Message* buffer. */
7370 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7372 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7373 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7375 : multibyte_char_to_unibyte (c
, Qnil
));
7376 insert_1_both (work
, 1, 1, 1, 0, 0);
7379 else if (! multibyte
7380 && ! NILP (current_buffer
->enable_multibyte_characters
))
7382 int i
, c
, char_bytes
;
7383 unsigned char *msg
= (unsigned char *) m
;
7384 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7385 /* Convert a single-byte string to multibyte
7386 for the *Message* buffer. */
7387 for (i
= 0; i
< nbytes
; i
++)
7389 c
= unibyte_char_to_multibyte (msg
[i
]);
7390 char_bytes
= CHAR_STRING (c
, str
);
7391 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7395 insert_1 (m
, nbytes
, 1, 0, 0);
7399 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7400 insert_1 ("\n", 1, 1, 0, 0);
7402 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7404 this_bol_byte
= PT_BYTE
;
7406 /* See if this line duplicates the previous one.
7407 If so, combine duplicates. */
7410 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7412 prev_bol_byte
= PT_BYTE
;
7414 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7415 this_bol
, this_bol_byte
);
7418 del_range_both (prev_bol
, prev_bol_byte
,
7419 this_bol
, this_bol_byte
, 0);
7425 /* If you change this format, don't forget to also
7426 change message_log_check_duplicate. */
7427 sprintf (dupstr
, " [%d times]", dup
);
7428 duplen
= strlen (dupstr
);
7429 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7430 insert_1 (dupstr
, duplen
, 1, 0, 1);
7435 /* If we have more than the desired maximum number of lines
7436 in the *Messages* buffer now, delete the oldest ones.
7437 This is safe because we don't have undo in this buffer. */
7439 if (NATNUMP (Vmessage_log_max
))
7441 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7442 -XFASTINT (Vmessage_log_max
) - 1, 0);
7443 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7446 BEGV
= XMARKER (oldbegv
)->charpos
;
7447 BEGV_BYTE
= marker_byte_position (oldbegv
);
7456 ZV
= XMARKER (oldzv
)->charpos
;
7457 ZV_BYTE
= marker_byte_position (oldzv
);
7461 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7463 /* We can't do Fgoto_char (oldpoint) because it will run some
7465 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7466 XMARKER (oldpoint
)->bytepos
);
7469 unchain_marker (XMARKER (oldpoint
));
7470 unchain_marker (XMARKER (oldbegv
));
7471 unchain_marker (XMARKER (oldzv
));
7473 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7474 set_buffer_internal (oldbuf
);
7476 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7477 message_log_need_newline
= !nlflag
;
7478 Vdeactivate_mark
= old_deactivate_mark
;
7483 /* We are at the end of the buffer after just having inserted a newline.
7484 (Note: We depend on the fact we won't be crossing the gap.)
7485 Check to see if the most recent message looks a lot like the previous one.
7486 Return 0 if different, 1 if the new one should just replace it, or a
7487 value N > 1 if we should also append " [N times]". */
7490 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7491 int prev_bol
, this_bol
;
7492 int prev_bol_byte
, this_bol_byte
;
7495 int len
= Z_BYTE
- 1 - this_bol_byte
;
7497 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7498 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7500 for (i
= 0; i
< len
; i
++)
7502 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7510 if (*p1
++ == ' ' && *p1
++ == '[')
7513 while (*p1
>= '0' && *p1
<= '9')
7514 n
= n
* 10 + *p1
++ - '0';
7515 if (strncmp (p1
, " times]\n", 8) == 0)
7522 /* Display an echo area message M with a specified length of NBYTES
7523 bytes. The string may include null characters. If M is 0, clear
7524 out any existing message, and let the mini-buffer text show
7527 This may GC, so the buffer M must NOT point to a Lisp string. */
7530 message2 (m
, nbytes
, multibyte
)
7535 /* First flush out any partial line written with print. */
7536 message_log_maybe_newline ();
7538 message_dolog (m
, nbytes
, 1, multibyte
);
7539 message2_nolog (m
, nbytes
, multibyte
);
7543 /* The non-logging counterpart of message2. */
7546 message2_nolog (m
, nbytes
, multibyte
)
7548 int nbytes
, multibyte
;
7550 struct frame
*sf
= SELECTED_FRAME ();
7551 message_enable_multibyte
= multibyte
;
7555 if (noninteractive_need_newline
)
7556 putc ('\n', stderr
);
7557 noninteractive_need_newline
= 0;
7559 fwrite (m
, nbytes
, 1, stderr
);
7560 if (cursor_in_echo_area
== 0)
7561 fprintf (stderr
, "\n");
7564 /* A null message buffer means that the frame hasn't really been
7565 initialized yet. Error messages get reported properly by
7566 cmd_error, so this must be just an informative message; toss it. */
7567 else if (INTERACTIVE
7568 && sf
->glyphs_initialized_p
7569 && FRAME_MESSAGE_BUF (sf
))
7571 Lisp_Object mini_window
;
7574 /* Get the frame containing the mini-buffer
7575 that the selected frame is using. */
7576 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7577 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7579 FRAME_SAMPLE_VISIBILITY (f
);
7580 if (FRAME_VISIBLE_P (sf
)
7581 && ! FRAME_VISIBLE_P (f
))
7582 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7586 set_message (m
, Qnil
, nbytes
, multibyte
);
7587 if (minibuffer_auto_raise
)
7588 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7591 clear_message (1, 1);
7593 do_pending_window_change (0);
7594 echo_area_display (1);
7595 do_pending_window_change (0);
7596 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7597 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7602 /* Display an echo area message M with a specified length of NBYTES
7603 bytes. The string may include null characters. If M is not a
7604 string, clear out any existing message, and let the mini-buffer
7607 This function cancels echoing. */
7610 message3 (m
, nbytes
, multibyte
)
7615 struct gcpro gcpro1
;
7618 clear_message (1,1);
7621 /* First flush out any partial line written with print. */
7622 message_log_maybe_newline ();
7628 SAFE_ALLOCA (buffer
, char *, nbytes
);
7629 bcopy (SDATA (m
), buffer
, nbytes
);
7630 message_dolog (buffer
, nbytes
, 1, multibyte
);
7633 message3_nolog (m
, nbytes
, multibyte
);
7639 /* The non-logging version of message3.
7640 This does not cancel echoing, because it is used for echoing.
7641 Perhaps we need to make a separate function for echoing
7642 and make this cancel echoing. */
7645 message3_nolog (m
, nbytes
, multibyte
)
7647 int nbytes
, multibyte
;
7649 struct frame
*sf
= SELECTED_FRAME ();
7650 message_enable_multibyte
= multibyte
;
7654 if (noninteractive_need_newline
)
7655 putc ('\n', stderr
);
7656 noninteractive_need_newline
= 0;
7658 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7659 if (cursor_in_echo_area
== 0)
7660 fprintf (stderr
, "\n");
7663 /* A null message buffer means that the frame hasn't really been
7664 initialized yet. Error messages get reported properly by
7665 cmd_error, so this must be just an informative message; toss it. */
7666 else if (INTERACTIVE
7667 && sf
->glyphs_initialized_p
7668 && FRAME_MESSAGE_BUF (sf
))
7670 Lisp_Object mini_window
;
7674 /* Get the frame containing the mini-buffer
7675 that the selected frame is using. */
7676 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7677 frame
= XWINDOW (mini_window
)->frame
;
7680 FRAME_SAMPLE_VISIBILITY (f
);
7681 if (FRAME_VISIBLE_P (sf
)
7682 && !FRAME_VISIBLE_P (f
))
7683 Fmake_frame_visible (frame
);
7685 if (STRINGP (m
) && SCHARS (m
) > 0)
7687 set_message (NULL
, m
, nbytes
, multibyte
);
7688 if (minibuffer_auto_raise
)
7689 Fraise_frame (frame
);
7690 /* Assume we are not echoing.
7691 (If we are, echo_now will override this.) */
7692 echo_message_buffer
= Qnil
;
7695 clear_message (1, 1);
7697 do_pending_window_change (0);
7698 echo_area_display (1);
7699 do_pending_window_change (0);
7700 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7701 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7706 /* Display a null-terminated echo area message M. If M is 0, clear
7707 out any existing message, and let the mini-buffer text show through.
7709 The buffer M must continue to exist until after the echo area gets
7710 cleared or some other message gets displayed there. Do not pass
7711 text that is stored in a Lisp string. Do not pass text in a buffer
7712 that was alloca'd. */
7718 message2 (m
, (m
? strlen (m
) : 0), 0);
7722 /* The non-logging counterpart of message1. */
7728 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7731 /* Display a message M which contains a single %s
7732 which gets replaced with STRING. */
7735 message_with_string (m
, string
, log
)
7740 CHECK_STRING (string
);
7746 if (noninteractive_need_newline
)
7747 putc ('\n', stderr
);
7748 noninteractive_need_newline
= 0;
7749 fprintf (stderr
, m
, SDATA (string
));
7750 if (cursor_in_echo_area
== 0)
7751 fprintf (stderr
, "\n");
7755 else if (INTERACTIVE
)
7757 /* The frame whose minibuffer we're going to display the message on.
7758 It may be larger than the selected frame, so we need
7759 to use its buffer, not the selected frame's buffer. */
7760 Lisp_Object mini_window
;
7761 struct frame
*f
, *sf
= SELECTED_FRAME ();
7763 /* Get the frame containing the minibuffer
7764 that the selected frame is using. */
7765 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7766 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7768 /* A null message buffer means that the frame hasn't really been
7769 initialized yet. Error messages get reported properly by
7770 cmd_error, so this must be just an informative message; toss it. */
7771 if (FRAME_MESSAGE_BUF (f
))
7773 Lisp_Object args
[2], message
;
7774 struct gcpro gcpro1
, gcpro2
;
7776 args
[0] = build_string (m
);
7777 args
[1] = message
= string
;
7778 GCPRO2 (args
[0], message
);
7781 message
= Fformat (2, args
);
7784 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7786 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7790 /* Print should start at the beginning of the message
7791 buffer next time. */
7792 message_buf_print
= 0;
7798 /* Dump an informative message to the minibuf. If M is 0, clear out
7799 any existing message, and let the mini-buffer text show through. */
7803 message (m
, a1
, a2
, a3
)
7805 EMACS_INT a1
, a2
, a3
;
7811 if (noninteractive_need_newline
)
7812 putc ('\n', stderr
);
7813 noninteractive_need_newline
= 0;
7814 fprintf (stderr
, m
, a1
, a2
, a3
);
7815 if (cursor_in_echo_area
== 0)
7816 fprintf (stderr
, "\n");
7820 else if (INTERACTIVE
)
7822 /* The frame whose mini-buffer we're going to display the message
7823 on. It may be larger than the selected frame, so we need to
7824 use its buffer, not the selected frame's buffer. */
7825 Lisp_Object mini_window
;
7826 struct frame
*f
, *sf
= SELECTED_FRAME ();
7828 /* Get the frame containing the mini-buffer
7829 that the selected frame is using. */
7830 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7831 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7833 /* A null message buffer means that the frame hasn't really been
7834 initialized yet. Error messages get reported properly by
7835 cmd_error, so this must be just an informative message; toss
7837 if (FRAME_MESSAGE_BUF (f
))
7848 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7849 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7851 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7852 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7854 #endif /* NO_ARG_ARRAY */
7856 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7861 /* Print should start at the beginning of the message
7862 buffer next time. */
7863 message_buf_print
= 0;
7869 /* The non-logging version of message. */
7872 message_nolog (m
, a1
, a2
, a3
)
7874 EMACS_INT a1
, a2
, a3
;
7876 Lisp_Object old_log_max
;
7877 old_log_max
= Vmessage_log_max
;
7878 Vmessage_log_max
= Qnil
;
7879 message (m
, a1
, a2
, a3
);
7880 Vmessage_log_max
= old_log_max
;
7884 /* Display the current message in the current mini-buffer. This is
7885 only called from error handlers in process.c, and is not time
7891 if (!NILP (echo_area_buffer
[0]))
7894 string
= Fcurrent_message ();
7895 message3 (string
, SBYTES (string
),
7896 !NILP (current_buffer
->enable_multibyte_characters
));
7901 /* Make sure echo area buffers in `echo_buffers' are live.
7902 If they aren't, make new ones. */
7905 ensure_echo_area_buffers ()
7909 for (i
= 0; i
< 2; ++i
)
7910 if (!BUFFERP (echo_buffer
[i
])
7911 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7914 Lisp_Object old_buffer
;
7917 old_buffer
= echo_buffer
[i
];
7918 sprintf (name
, " *Echo Area %d*", i
);
7919 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7920 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7922 for (j
= 0; j
< 2; ++j
)
7923 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7924 echo_area_buffer
[j
] = echo_buffer
[i
];
7929 /* Call FN with args A1..A4 with either the current or last displayed
7930 echo_area_buffer as current buffer.
7932 WHICH zero means use the current message buffer
7933 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7934 from echo_buffer[] and clear it.
7936 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7937 suitable buffer from echo_buffer[] and clear it.
7939 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
7940 that the current message becomes the last displayed one, make
7941 choose a suitable buffer for echo_area_buffer[0], and clear it.
7943 Value is what FN returns. */
7946 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7949 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7955 int this_one
, the_other
, clear_buffer_p
, rc
;
7956 int count
= SPECPDL_INDEX ();
7958 /* If buffers aren't live, make new ones. */
7959 ensure_echo_area_buffers ();
7964 this_one
= 0, the_other
= 1;
7966 this_one
= 1, the_other
= 0;
7969 this_one
= 0, the_other
= 1;
7972 /* We need a fresh one in case the current echo buffer equals
7973 the one containing the last displayed echo area message. */
7974 if (!NILP (echo_area_buffer
[this_one
])
7975 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
7976 echo_area_buffer
[this_one
] = Qnil
;
7979 /* Choose a suitable buffer from echo_buffer[] is we don't
7981 if (NILP (echo_area_buffer
[this_one
]))
7983 echo_area_buffer
[this_one
]
7984 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7985 ? echo_buffer
[the_other
]
7986 : echo_buffer
[this_one
]);
7990 buffer
= echo_area_buffer
[this_one
];
7992 /* Don't get confused by reusing the buffer used for echoing
7993 for a different purpose. */
7994 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7997 record_unwind_protect (unwind_with_echo_area_buffer
,
7998 with_echo_area_buffer_unwind_data (w
));
8000 /* Make the echo area buffer current. Note that for display
8001 purposes, it is not necessary that the displayed window's buffer
8002 == current_buffer, except for text property lookup. So, let's
8003 only set that buffer temporarily here without doing a full
8004 Fset_window_buffer. We must also change w->pointm, though,
8005 because otherwise an assertions in unshow_buffer fails, and Emacs
8007 set_buffer_internal_1 (XBUFFER (buffer
));
8011 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8014 current_buffer
->undo_list
= Qt
;
8015 current_buffer
->read_only
= Qnil
;
8016 specbind (Qinhibit_read_only
, Qt
);
8017 specbind (Qinhibit_modification_hooks
, Qt
);
8019 if (clear_buffer_p
&& Z
> BEG
)
8022 xassert (BEGV
>= BEG
);
8023 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8025 rc
= fn (a1
, a2
, a3
, a4
);
8027 xassert (BEGV
>= BEG
);
8028 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8030 unbind_to (count
, Qnil
);
8035 /* Save state that should be preserved around the call to the function
8036 FN called in with_echo_area_buffer. */
8039 with_echo_area_buffer_unwind_data (w
)
8045 /* Reduce consing by keeping one vector in
8046 Vwith_echo_area_save_vector. */
8047 vector
= Vwith_echo_area_save_vector
;
8048 Vwith_echo_area_save_vector
= Qnil
;
8051 vector
= Fmake_vector (make_number (7), Qnil
);
8053 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
8054 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
8055 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
8059 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
8060 AREF (vector
, i
) = w
->buffer
; ++i
;
8061 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
8062 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
8067 for (; i
< end
; ++i
)
8068 AREF (vector
, i
) = Qnil
;
8071 xassert (i
== ASIZE (vector
));
8076 /* Restore global state from VECTOR which was created by
8077 with_echo_area_buffer_unwind_data. */
8080 unwind_with_echo_area_buffer (vector
)
8083 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8084 Vdeactivate_mark
= AREF (vector
, 1);
8085 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8087 if (WINDOWP (AREF (vector
, 3)))
8090 Lisp_Object buffer
, charpos
, bytepos
;
8092 w
= XWINDOW (AREF (vector
, 3));
8093 buffer
= AREF (vector
, 4);
8094 charpos
= AREF (vector
, 5);
8095 bytepos
= AREF (vector
, 6);
8098 set_marker_both (w
->pointm
, buffer
,
8099 XFASTINT (charpos
), XFASTINT (bytepos
));
8102 Vwith_echo_area_save_vector
= vector
;
8107 /* Set up the echo area for use by print functions. MULTIBYTE_P
8108 non-zero means we will print multibyte. */
8111 setup_echo_area_for_printing (multibyte_p
)
8114 /* If we can't find an echo area any more, exit. */
8115 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8118 ensure_echo_area_buffers ();
8120 if (!message_buf_print
)
8122 /* A message has been output since the last time we printed.
8123 Choose a fresh echo area buffer. */
8124 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8125 echo_area_buffer
[0] = echo_buffer
[1];
8127 echo_area_buffer
[0] = echo_buffer
[0];
8129 /* Switch to that buffer and clear it. */
8130 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8131 current_buffer
->truncate_lines
= Qnil
;
8135 int count
= SPECPDL_INDEX ();
8136 specbind (Qinhibit_read_only
, Qt
);
8137 /* Note that undo recording is always disabled. */
8139 unbind_to (count
, Qnil
);
8141 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8143 /* Set up the buffer for the multibyteness we need. */
8145 != !NILP (current_buffer
->enable_multibyte_characters
))
8146 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8148 /* Raise the frame containing the echo area. */
8149 if (minibuffer_auto_raise
)
8151 struct frame
*sf
= SELECTED_FRAME ();
8152 Lisp_Object mini_window
;
8153 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8154 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8157 message_log_maybe_newline ();
8158 message_buf_print
= 1;
8162 if (NILP (echo_area_buffer
[0]))
8164 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8165 echo_area_buffer
[0] = echo_buffer
[1];
8167 echo_area_buffer
[0] = echo_buffer
[0];
8170 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8172 /* Someone switched buffers between print requests. */
8173 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8174 current_buffer
->truncate_lines
= Qnil
;
8180 /* Display an echo area message in window W. Value is non-zero if W's
8181 height is changed. If display_last_displayed_message_p is
8182 non-zero, display the message that was last displayed, otherwise
8183 display the current message. */
8186 display_echo_area (w
)
8189 int i
, no_message_p
, window_height_changed_p
, count
;
8191 /* Temporarily disable garbage collections while displaying the echo
8192 area. This is done because a GC can print a message itself.
8193 That message would modify the echo area buffer's contents while a
8194 redisplay of the buffer is going on, and seriously confuse
8196 count
= inhibit_garbage_collection ();
8198 /* If there is no message, we must call display_echo_area_1
8199 nevertheless because it resizes the window. But we will have to
8200 reset the echo_area_buffer in question to nil at the end because
8201 with_echo_area_buffer will sets it to an empty buffer. */
8202 i
= display_last_displayed_message_p
? 1 : 0;
8203 no_message_p
= NILP (echo_area_buffer
[i
]);
8205 window_height_changed_p
8206 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8207 display_echo_area_1
,
8208 (EMACS_INT
) w
, Qnil
, 0, 0);
8211 echo_area_buffer
[i
] = Qnil
;
8213 unbind_to (count
, Qnil
);
8214 return window_height_changed_p
;
8218 /* Helper for display_echo_area. Display the current buffer which
8219 contains the current echo area message in window W, a mini-window,
8220 a pointer to which is passed in A1. A2..A4 are currently not used.
8221 Change the height of W so that all of the message is displayed.
8222 Value is non-zero if height of W was changed. */
8225 display_echo_area_1 (a1
, a2
, a3
, a4
)
8230 struct window
*w
= (struct window
*) a1
;
8232 struct text_pos start
;
8233 int window_height_changed_p
= 0;
8235 /* Do this before displaying, so that we have a large enough glyph
8236 matrix for the display. If we can't get enough space for the
8237 whole text, display the last N lines. That works by setting w->start. */
8238 window_height_changed_p
= resize_mini_window (w
, 0);
8240 /* Use the starting position chosen by resize_mini_window. */
8241 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8244 clear_glyph_matrix (w
->desired_matrix
);
8245 XSETWINDOW (window
, w
);
8246 try_window (window
, start
, 0);
8248 return window_height_changed_p
;
8252 /* Resize the echo area window to exactly the size needed for the
8253 currently displayed message, if there is one. If a mini-buffer
8254 is active, don't shrink it. */
8257 resize_echo_area_exactly ()
8259 if (BUFFERP (echo_area_buffer
[0])
8260 && WINDOWP (echo_area_window
))
8262 struct window
*w
= XWINDOW (echo_area_window
);
8264 Lisp_Object resize_exactly
;
8266 if (minibuf_level
== 0)
8267 resize_exactly
= Qt
;
8269 resize_exactly
= Qnil
;
8271 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8272 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8275 ++windows_or_buffers_changed
;
8276 ++update_mode_lines
;
8277 redisplay_internal (0);
8283 /* Callback function for with_echo_area_buffer, when used from
8284 resize_echo_area_exactly. A1 contains a pointer to the window to
8285 resize, EXACTLY non-nil means resize the mini-window exactly to the
8286 size of the text displayed. A3 and A4 are not used. Value is what
8287 resize_mini_window returns. */
8290 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8292 Lisp_Object exactly
;
8295 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8299 /* Resize mini-window W to fit the size of its contents. EXACT:P
8300 means size the window exactly to the size needed. Otherwise, it's
8301 only enlarged until W's buffer is empty.
8303 Set W->start to the right place to begin display. If the whole
8304 contents fit, start at the beginning. Otherwise, start so as
8305 to make the end of the contents appear. This is particularly
8306 important for y-or-n-p, but seems desirable generally.
8308 Value is non-zero if the window height has been changed. */
8311 resize_mini_window (w
, exact_p
)
8315 struct frame
*f
= XFRAME (w
->frame
);
8316 int window_height_changed_p
= 0;
8318 xassert (MINI_WINDOW_P (w
));
8320 /* By default, start display at the beginning. */
8321 set_marker_both (w
->start
, w
->buffer
,
8322 BUF_BEGV (XBUFFER (w
->buffer
)),
8323 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8325 /* Don't resize windows while redisplaying a window; it would
8326 confuse redisplay functions when the size of the window they are
8327 displaying changes from under them. Such a resizing can happen,
8328 for instance, when which-func prints a long message while
8329 we are running fontification-functions. We're running these
8330 functions with safe_call which binds inhibit-redisplay to t. */
8331 if (!NILP (Vinhibit_redisplay
))
8334 /* Nil means don't try to resize. */
8335 if (NILP (Vresize_mini_windows
)
8336 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8339 if (!FRAME_MINIBUF_ONLY_P (f
))
8342 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8343 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8344 int height
, max_height
;
8345 int unit
= FRAME_LINE_HEIGHT (f
);
8346 struct text_pos start
;
8347 struct buffer
*old_current_buffer
= NULL
;
8349 if (current_buffer
!= XBUFFER (w
->buffer
))
8351 old_current_buffer
= current_buffer
;
8352 set_buffer_internal (XBUFFER (w
->buffer
));
8355 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8357 /* Compute the max. number of lines specified by the user. */
8358 if (FLOATP (Vmax_mini_window_height
))
8359 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8360 else if (INTEGERP (Vmax_mini_window_height
))
8361 max_height
= XINT (Vmax_mini_window_height
);
8363 max_height
= total_height
/ 4;
8365 /* Correct that max. height if it's bogus. */
8366 max_height
= max (1, max_height
);
8367 max_height
= min (total_height
, max_height
);
8369 /* Find out the height of the text in the window. */
8370 if (it
.truncate_lines_p
)
8375 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8376 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8377 height
= it
.current_y
+ last_height
;
8379 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8380 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8381 height
= (height
+ unit
- 1) / unit
;
8384 /* Compute a suitable window start. */
8385 if (height
> max_height
)
8387 height
= max_height
;
8388 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8389 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8390 start
= it
.current
.pos
;
8393 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8394 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8396 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8398 /* Let it grow only, until we display an empty message, in which
8399 case the window shrinks again. */
8400 if (height
> WINDOW_TOTAL_LINES (w
))
8402 int old_height
= WINDOW_TOTAL_LINES (w
);
8403 freeze_window_starts (f
, 1);
8404 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8405 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8407 else if (height
< WINDOW_TOTAL_LINES (w
)
8408 && (exact_p
|| BEGV
== ZV
))
8410 int old_height
= WINDOW_TOTAL_LINES (w
);
8411 freeze_window_starts (f
, 0);
8412 shrink_mini_window (w
);
8413 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8418 /* Always resize to exact size needed. */
8419 if (height
> WINDOW_TOTAL_LINES (w
))
8421 int old_height
= WINDOW_TOTAL_LINES (w
);
8422 freeze_window_starts (f
, 1);
8423 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8424 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8426 else if (height
< WINDOW_TOTAL_LINES (w
))
8428 int old_height
= WINDOW_TOTAL_LINES (w
);
8429 freeze_window_starts (f
, 0);
8430 shrink_mini_window (w
);
8434 freeze_window_starts (f
, 1);
8435 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8438 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8442 if (old_current_buffer
)
8443 set_buffer_internal (old_current_buffer
);
8446 return window_height_changed_p
;
8450 /* Value is the current message, a string, or nil if there is no
8458 if (NILP (echo_area_buffer
[0]))
8462 with_echo_area_buffer (0, 0, current_message_1
,
8463 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8465 echo_area_buffer
[0] = Qnil
;
8473 current_message_1 (a1
, a2
, a3
, a4
)
8478 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8481 *msg
= make_buffer_string (BEG
, Z
, 1);
8488 /* Push the current message on Vmessage_stack for later restauration
8489 by restore_message. Value is non-zero if the current message isn't
8490 empty. This is a relatively infrequent operation, so it's not
8491 worth optimizing. */
8497 msg
= current_message ();
8498 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8499 return STRINGP (msg
);
8503 /* Restore message display from the top of Vmessage_stack. */
8510 xassert (CONSP (Vmessage_stack
));
8511 msg
= XCAR (Vmessage_stack
);
8513 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8515 message3_nolog (msg
, 0, 0);
8519 /* Handler for record_unwind_protect calling pop_message. */
8522 pop_message_unwind (dummy
)
8529 /* Pop the top-most entry off Vmessage_stack. */
8534 xassert (CONSP (Vmessage_stack
));
8535 Vmessage_stack
= XCDR (Vmessage_stack
);
8539 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8540 exits. If the stack is not empty, we have a missing pop_message
8544 check_message_stack ()
8546 if (!NILP (Vmessage_stack
))
8551 /* Truncate to NCHARS what will be displayed in the echo area the next
8552 time we display it---but don't redisplay it now. */
8555 truncate_echo_area (nchars
)
8559 echo_area_buffer
[0] = Qnil
;
8560 /* A null message buffer means that the frame hasn't really been
8561 initialized yet. Error messages get reported properly by
8562 cmd_error, so this must be just an informative message; toss it. */
8563 else if (!noninteractive
8565 && !NILP (echo_area_buffer
[0]))
8567 struct frame
*sf
= SELECTED_FRAME ();
8568 if (FRAME_MESSAGE_BUF (sf
))
8569 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8574 /* Helper function for truncate_echo_area. Truncate the current
8575 message to at most NCHARS characters. */
8578 truncate_message_1 (nchars
, a2
, a3
, a4
)
8583 if (BEG
+ nchars
< Z
)
8584 del_range (BEG
+ nchars
, Z
);
8586 echo_area_buffer
[0] = Qnil
;
8591 /* Set the current message to a substring of S or STRING.
8593 If STRING is a Lisp string, set the message to the first NBYTES
8594 bytes from STRING. NBYTES zero means use the whole string. If
8595 STRING is multibyte, the message will be displayed multibyte.
8597 If S is not null, set the message to the first LEN bytes of S. LEN
8598 zero means use the whole string. MULTIBYTE_P non-zero means S is
8599 multibyte. Display the message multibyte in that case.
8601 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8602 to t before calling set_message_1 (which calls insert).
8606 set_message (s
, string
, nbytes
, multibyte_p
)
8609 int nbytes
, multibyte_p
;
8611 message_enable_multibyte
8612 = ((s
&& multibyte_p
)
8613 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8615 with_echo_area_buffer (0, -1, set_message_1
,
8616 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8617 message_buf_print
= 0;
8618 help_echo_showing_p
= 0;
8622 /* Helper function for set_message. Arguments have the same meaning
8623 as there, with A1 corresponding to S and A2 corresponding to STRING
8624 This function is called with the echo area buffer being
8628 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8631 EMACS_INT nbytes
, multibyte_p
;
8633 const char *s
= (const char *) a1
;
8634 Lisp_Object string
= a2
;
8636 /* Change multibyteness of the echo buffer appropriately. */
8637 if (message_enable_multibyte
8638 != !NILP (current_buffer
->enable_multibyte_characters
))
8639 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8641 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8643 /* Insert new message at BEG. */
8644 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8646 if (STRINGP (string
))
8651 nbytes
= SBYTES (string
);
8652 nchars
= string_byte_to_char (string
, nbytes
);
8654 /* This function takes care of single/multibyte conversion. We
8655 just have to ensure that the echo area buffer has the right
8656 setting of enable_multibyte_characters. */
8657 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8662 nbytes
= strlen (s
);
8664 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8666 /* Convert from multi-byte to single-byte. */
8668 unsigned char work
[1];
8670 /* Convert a multibyte string to single-byte. */
8671 for (i
= 0; i
< nbytes
; i
+= n
)
8673 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8674 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
8676 : multibyte_char_to_unibyte (c
, Qnil
));
8677 insert_1_both (work
, 1, 1, 1, 0, 0);
8680 else if (!multibyte_p
8681 && !NILP (current_buffer
->enable_multibyte_characters
))
8683 /* Convert from single-byte to multi-byte. */
8685 const unsigned char *msg
= (const unsigned char *) s
;
8686 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8688 /* Convert a single-byte string to multibyte. */
8689 for (i
= 0; i
< nbytes
; i
++)
8691 c
= unibyte_char_to_multibyte (msg
[i
]);
8692 n
= CHAR_STRING (c
, str
);
8693 insert_1_both (str
, 1, n
, 1, 0, 0);
8697 insert_1 (s
, nbytes
, 1, 0, 0);
8704 /* Clear messages. CURRENT_P non-zero means clear the current
8705 message. LAST_DISPLAYED_P non-zero means clear the message
8709 clear_message (current_p
, last_displayed_p
)
8710 int current_p
, last_displayed_p
;
8714 echo_area_buffer
[0] = Qnil
;
8715 message_cleared_p
= 1;
8718 if (last_displayed_p
)
8719 echo_area_buffer
[1] = Qnil
;
8721 message_buf_print
= 0;
8724 /* Clear garbaged frames.
8726 This function is used where the old redisplay called
8727 redraw_garbaged_frames which in turn called redraw_frame which in
8728 turn called clear_frame. The call to clear_frame was a source of
8729 flickering. I believe a clear_frame is not necessary. It should
8730 suffice in the new redisplay to invalidate all current matrices,
8731 and ensure a complete redisplay of all windows. */
8734 clear_garbaged_frames ()
8738 Lisp_Object tail
, frame
;
8739 int changed_count
= 0;
8741 FOR_EACH_FRAME (tail
, frame
)
8743 struct frame
*f
= XFRAME (frame
);
8745 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8749 Fredraw_frame (frame
);
8750 f
->force_flush_display_p
= 1;
8752 clear_current_matrices (f
);
8761 ++windows_or_buffers_changed
;
8766 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8767 is non-zero update selected_frame. Value is non-zero if the
8768 mini-windows height has been changed. */
8771 echo_area_display (update_frame_p
)
8774 Lisp_Object mini_window
;
8777 int window_height_changed_p
= 0;
8778 struct frame
*sf
= SELECTED_FRAME ();
8780 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8781 w
= XWINDOW (mini_window
);
8782 f
= XFRAME (WINDOW_FRAME (w
));
8784 /* Don't display if frame is invisible or not yet initialized. */
8785 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8788 #ifdef HAVE_WINDOW_SYSTEM
8789 /* When Emacs starts, selected_frame may be the initial terminal
8790 frame. If we let this through, a message would be displayed on
8792 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
8794 #endif /* HAVE_WINDOW_SYSTEM */
8796 /* Redraw garbaged frames. */
8798 clear_garbaged_frames ();
8800 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8802 echo_area_window
= mini_window
;
8803 window_height_changed_p
= display_echo_area (w
);
8804 w
->must_be_updated_p
= 1;
8806 /* Update the display, unless called from redisplay_internal.
8807 Also don't update the screen during redisplay itself. The
8808 update will happen at the end of redisplay, and an update
8809 here could cause confusion. */
8810 if (update_frame_p
&& !redisplaying_p
)
8814 /* If the display update has been interrupted by pending
8815 input, update mode lines in the frame. Due to the
8816 pending input, it might have been that redisplay hasn't
8817 been called, so that mode lines above the echo area are
8818 garbaged. This looks odd, so we prevent it here. */
8819 if (!display_completed
)
8820 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8822 if (window_height_changed_p
8823 /* Don't do this if Emacs is shutting down. Redisplay
8824 needs to run hooks. */
8825 && !NILP (Vrun_hooks
))
8827 /* Must update other windows. Likewise as in other
8828 cases, don't let this update be interrupted by
8830 int count
= SPECPDL_INDEX ();
8831 specbind (Qredisplay_dont_pause
, Qt
);
8832 windows_or_buffers_changed
= 1;
8833 redisplay_internal (0);
8834 unbind_to (count
, Qnil
);
8836 else if (FRAME_WINDOW_P (f
) && n
== 0)
8838 /* Window configuration is the same as before.
8839 Can do with a display update of the echo area,
8840 unless we displayed some mode lines. */
8841 update_single_window (w
, 1);
8842 FRAME_RIF (f
)->flush_display (f
);
8845 update_frame (f
, 1, 1);
8847 /* If cursor is in the echo area, make sure that the next
8848 redisplay displays the minibuffer, so that the cursor will
8849 be replaced with what the minibuffer wants. */
8850 if (cursor_in_echo_area
)
8851 ++windows_or_buffers_changed
;
8854 else if (!EQ (mini_window
, selected_window
))
8855 windows_or_buffers_changed
++;
8857 /* Last displayed message is now the current message. */
8858 echo_area_buffer
[1] = echo_area_buffer
[0];
8859 /* Inform read_char that we're not echoing. */
8860 echo_message_buffer
= Qnil
;
8862 /* Prevent redisplay optimization in redisplay_internal by resetting
8863 this_line_start_pos. This is done because the mini-buffer now
8864 displays the message instead of its buffer text. */
8865 if (EQ (mini_window
, selected_window
))
8866 CHARPOS (this_line_start_pos
) = 0;
8868 return window_height_changed_p
;
8873 /***********************************************************************
8874 Mode Lines and Frame Titles
8875 ***********************************************************************/
8877 /* A buffer for constructing non-propertized mode-line strings and
8878 frame titles in it; allocated from the heap in init_xdisp and
8879 resized as needed in store_mode_line_noprop_char. */
8881 static char *mode_line_noprop_buf
;
8883 /* The buffer's end, and a current output position in it. */
8885 static char *mode_line_noprop_buf_end
;
8886 static char *mode_line_noprop_ptr
;
8888 #define MODE_LINE_NOPROP_LEN(start) \
8889 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8892 MODE_LINE_DISPLAY
= 0,
8898 /* Alist that caches the results of :propertize.
8899 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8900 static Lisp_Object mode_line_proptrans_alist
;
8902 /* List of strings making up the mode-line. */
8903 static Lisp_Object mode_line_string_list
;
8905 /* Base face property when building propertized mode line string. */
8906 static Lisp_Object mode_line_string_face
;
8907 static Lisp_Object mode_line_string_face_prop
;
8910 /* Unwind data for mode line strings */
8912 static Lisp_Object Vmode_line_unwind_vector
;
8915 format_mode_line_unwind_data (obuf
, save_proptrans
)
8916 struct buffer
*obuf
;
8920 /* Reduce consing by keeping one vector in
8921 Vwith_echo_area_save_vector. */
8922 vector
= Vmode_line_unwind_vector
;
8923 Vmode_line_unwind_vector
= Qnil
;
8926 vector
= Fmake_vector (make_number (7), Qnil
);
8928 AREF (vector
, 0) = make_number (mode_line_target
);
8929 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8930 AREF (vector
, 2) = mode_line_string_list
;
8931 AREF (vector
, 3) = (save_proptrans
? mode_line_proptrans_alist
: Qt
);
8932 AREF (vector
, 4) = mode_line_string_face
;
8933 AREF (vector
, 5) = mode_line_string_face_prop
;
8936 XSETBUFFER (AREF (vector
, 6), obuf
);
8938 AREF (vector
, 6) = Qnil
;
8944 unwind_format_mode_line (vector
)
8947 mode_line_target
= XINT (AREF (vector
, 0));
8948 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8949 mode_line_string_list
= AREF (vector
, 2);
8950 if (! EQ (AREF (vector
, 3), Qt
))
8951 mode_line_proptrans_alist
= AREF (vector
, 3);
8952 mode_line_string_face
= AREF (vector
, 4);
8953 mode_line_string_face_prop
= AREF (vector
, 5);
8955 if (!NILP (AREF (vector
, 6)))
8957 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8958 AREF (vector
, 6) = Qnil
;
8961 Vmode_line_unwind_vector
= vector
;
8966 /* Store a single character C for the frame title in mode_line_noprop_buf.
8967 Re-allocate mode_line_noprop_buf if necessary. */
8971 store_mode_line_noprop_char (char c
)
8973 store_mode_line_noprop_char (c
)
8977 /* If output position has reached the end of the allocated buffer,
8978 double the buffer's size. */
8979 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8981 int len
= MODE_LINE_NOPROP_LEN (0);
8982 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8983 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8984 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8985 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8988 *mode_line_noprop_ptr
++ = c
;
8992 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8993 mode_line_noprop_ptr. STR is the string to store. Do not copy
8994 characters that yield more columns than PRECISION; PRECISION <= 0
8995 means copy the whole string. Pad with spaces until FIELD_WIDTH
8996 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8997 pad. Called from display_mode_element when it is used to build a
9001 store_mode_line_noprop (str
, field_width
, precision
)
9002 const unsigned char *str
;
9003 int field_width
, precision
;
9008 /* Copy at most PRECISION chars from STR. */
9009 nbytes
= strlen (str
);
9010 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9012 store_mode_line_noprop_char (*str
++);
9014 /* Fill up with spaces until FIELD_WIDTH reached. */
9015 while (field_width
> 0
9018 store_mode_line_noprop_char (' ');
9025 /***********************************************************************
9027 ***********************************************************************/
9029 #ifdef HAVE_WINDOW_SYSTEM
9031 /* Set the title of FRAME, if it has changed. The title format is
9032 Vicon_title_format if FRAME is iconified, otherwise it is
9033 frame_title_format. */
9036 x_consider_frame_title (frame
)
9039 struct frame
*f
= XFRAME (frame
);
9041 if (FRAME_WINDOW_P (f
)
9042 || FRAME_MINIBUF_ONLY_P (f
)
9043 || f
->explicit_name
)
9045 /* Do we have more than one visible frame on this X display? */
9052 int count
= SPECPDL_INDEX ();
9054 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9056 Lisp_Object other_frame
= XCAR (tail
);
9057 struct frame
*tf
= XFRAME (other_frame
);
9060 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9061 && !FRAME_MINIBUF_ONLY_P (tf
)
9062 && !EQ (other_frame
, tip_frame
)
9063 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9067 /* Set global variable indicating that multiple frames exist. */
9068 multiple_frames
= CONSP (tail
);
9070 /* Switch to the buffer of selected window of the frame. Set up
9071 mode_line_target so that display_mode_element will output into
9072 mode_line_noprop_buf; then display the title. */
9073 record_unwind_protect (unwind_format_mode_line
,
9074 format_mode_line_unwind_data (current_buffer
, 0));
9076 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9077 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9079 mode_line_target
= MODE_LINE_TITLE
;
9080 title_start
= MODE_LINE_NOPROP_LEN (0);
9081 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9082 NULL
, DEFAULT_FACE_ID
);
9083 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9084 len
= MODE_LINE_NOPROP_LEN (title_start
);
9085 title
= mode_line_noprop_buf
+ title_start
;
9086 unbind_to (count
, Qnil
);
9088 /* Set the title only if it's changed. This avoids consing in
9089 the common case where it hasn't. (If it turns out that we've
9090 already wasted too much time by walking through the list with
9091 display_mode_element, then we might need to optimize at a
9092 higher level than this.) */
9093 if (! STRINGP (f
->name
)
9094 || SBYTES (f
->name
) != len
9095 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9096 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9100 #endif /* not HAVE_WINDOW_SYSTEM */
9105 /***********************************************************************
9107 ***********************************************************************/
9110 /* Prepare for redisplay by updating menu-bar item lists when
9111 appropriate. This can call eval. */
9114 prepare_menu_bars ()
9117 struct gcpro gcpro1
, gcpro2
;
9119 Lisp_Object tooltip_frame
;
9121 #ifdef HAVE_WINDOW_SYSTEM
9122 tooltip_frame
= tip_frame
;
9124 tooltip_frame
= Qnil
;
9127 /* Update all frame titles based on their buffer names, etc. We do
9128 this before the menu bars so that the buffer-menu will show the
9129 up-to-date frame titles. */
9130 #ifdef HAVE_WINDOW_SYSTEM
9131 if (windows_or_buffers_changed
|| update_mode_lines
)
9133 Lisp_Object tail
, frame
;
9135 FOR_EACH_FRAME (tail
, frame
)
9138 if (!EQ (frame
, tooltip_frame
)
9139 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9140 x_consider_frame_title (frame
);
9143 #endif /* HAVE_WINDOW_SYSTEM */
9145 /* Update the menu bar item lists, if appropriate. This has to be
9146 done before any actual redisplay or generation of display lines. */
9147 all_windows
= (update_mode_lines
9148 || buffer_shared
> 1
9149 || windows_or_buffers_changed
);
9152 Lisp_Object tail
, frame
;
9153 int count
= SPECPDL_INDEX ();
9154 /* 1 means that update_menu_bar has run its hooks
9155 so any further calls to update_menu_bar shouldn't do so again. */
9156 int menu_bar_hooks_run
= 0;
9158 record_unwind_save_match_data ();
9160 FOR_EACH_FRAME (tail
, frame
)
9164 /* Ignore tooltip frame. */
9165 if (EQ (frame
, tooltip_frame
))
9168 /* If a window on this frame changed size, report that to
9169 the user and clear the size-change flag. */
9170 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9172 Lisp_Object functions
;
9174 /* Clear flag first in case we get an error below. */
9175 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9176 functions
= Vwindow_size_change_functions
;
9177 GCPRO2 (tail
, functions
);
9179 while (CONSP (functions
))
9181 call1 (XCAR (functions
), frame
);
9182 functions
= XCDR (functions
);
9188 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9189 #ifdef HAVE_WINDOW_SYSTEM
9190 update_tool_bar (f
, 0);
9192 mac_update_title_bar (f
, 0);
9198 unbind_to (count
, Qnil
);
9202 struct frame
*sf
= SELECTED_FRAME ();
9203 update_menu_bar (sf
, 1, 0);
9204 #ifdef HAVE_WINDOW_SYSTEM
9205 update_tool_bar (sf
, 1);
9207 mac_update_title_bar (sf
, 1);
9212 /* Motif needs this. See comment in xmenu.c. Turn it off when
9213 pending_menu_activation is not defined. */
9214 #ifdef USE_X_TOOLKIT
9215 pending_menu_activation
= 0;
9220 /* Update the menu bar item list for frame F. This has to be done
9221 before we start to fill in any display lines, because it can call
9224 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9226 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9227 already ran the menu bar hooks for this redisplay, so there
9228 is no need to run them again. The return value is the
9229 updated value of this flag, to pass to the next call. */
9232 update_menu_bar (f
, save_match_data
, hooks_run
)
9234 int save_match_data
;
9238 register struct window
*w
;
9240 /* If called recursively during a menu update, do nothing. This can
9241 happen when, for instance, an activate-menubar-hook causes a
9243 if (inhibit_menubar_update
)
9246 window
= FRAME_SELECTED_WINDOW (f
);
9247 w
= XWINDOW (window
);
9249 #if 0 /* The if statement below this if statement used to include the
9250 condition !NILP (w->update_mode_line), rather than using
9251 update_mode_lines directly, and this if statement may have
9252 been added to make that condition work. Now the if
9253 statement below matches its comment, this isn't needed. */
9254 if (update_mode_lines
)
9255 w
->update_mode_line
= Qt
;
9258 if (FRAME_WINDOW_P (f
)
9260 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9261 || defined (USE_GTK)
9262 FRAME_EXTERNAL_MENU_BAR (f
)
9264 FRAME_MENU_BAR_LINES (f
) > 0
9266 : FRAME_MENU_BAR_LINES (f
) > 0)
9268 /* If the user has switched buffers or windows, we need to
9269 recompute to reflect the new bindings. But we'll
9270 recompute when update_mode_lines is set too; that means
9271 that people can use force-mode-line-update to request
9272 that the menu bar be recomputed. The adverse effect on
9273 the rest of the redisplay algorithm is about the same as
9274 windows_or_buffers_changed anyway. */
9275 if (windows_or_buffers_changed
9276 /* This used to test w->update_mode_line, but we believe
9277 there is no need to recompute the menu in that case. */
9278 || update_mode_lines
9279 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9280 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9281 != !NILP (w
->last_had_star
))
9282 || ((!NILP (Vtransient_mark_mode
)
9283 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9284 != !NILP (w
->region_showing
)))
9286 struct buffer
*prev
= current_buffer
;
9287 int count
= SPECPDL_INDEX ();
9289 specbind (Qinhibit_menubar_update
, Qt
);
9291 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9292 if (save_match_data
)
9293 record_unwind_save_match_data ();
9294 if (NILP (Voverriding_local_map_menu_flag
))
9296 specbind (Qoverriding_terminal_local_map
, Qnil
);
9297 specbind (Qoverriding_local_map
, Qnil
);
9302 /* Run the Lucid hook. */
9303 safe_run_hooks (Qactivate_menubar_hook
);
9305 /* If it has changed current-menubar from previous value,
9306 really recompute the menu-bar from the value. */
9307 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9308 call0 (Qrecompute_lucid_menubar
);
9310 safe_run_hooks (Qmenu_bar_update_hook
);
9315 XSETFRAME (Vmenu_updating_frame
, f
);
9316 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9318 /* Redisplay the menu bar in case we changed it. */
9319 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9320 || defined (USE_GTK)
9321 if (FRAME_WINDOW_P (f
))
9324 /* All frames on Mac OS share the same menubar. So only
9325 the selected frame should be allowed to set it. */
9326 if (f
== SELECTED_FRAME ())
9328 set_frame_menubar (f
, 0, 0);
9331 /* On a terminal screen, the menu bar is an ordinary screen
9332 line, and this makes it get updated. */
9333 w
->update_mode_line
= Qt
;
9334 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9335 /* In the non-toolkit version, the menu bar is an ordinary screen
9336 line, and this makes it get updated. */
9337 w
->update_mode_line
= Qt
;
9338 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9340 unbind_to (count
, Qnil
);
9341 set_buffer_internal_1 (prev
);
9350 /***********************************************************************
9352 ***********************************************************************/
9354 #ifdef HAVE_WINDOW_SYSTEM
9357 Nominal cursor position -- where to draw output.
9358 HPOS and VPOS are window relative glyph matrix coordinates.
9359 X and Y are window relative pixel coordinates. */
9361 struct cursor_pos output_cursor
;
9365 Set the global variable output_cursor to CURSOR. All cursor
9366 positions are relative to updated_window. */
9369 set_output_cursor (cursor
)
9370 struct cursor_pos
*cursor
;
9372 output_cursor
.hpos
= cursor
->hpos
;
9373 output_cursor
.vpos
= cursor
->vpos
;
9374 output_cursor
.x
= cursor
->x
;
9375 output_cursor
.y
= cursor
->y
;
9380 Set a nominal cursor position.
9382 HPOS and VPOS are column/row positions in a window glyph matrix. X
9383 and Y are window text area relative pixel positions.
9385 If this is done during an update, updated_window will contain the
9386 window that is being updated and the position is the future output
9387 cursor position for that window. If updated_window is null, use
9388 selected_window and display the cursor at the given position. */
9391 x_cursor_to (vpos
, hpos
, y
, x
)
9392 int vpos
, hpos
, y
, x
;
9396 /* If updated_window is not set, work on selected_window. */
9400 w
= XWINDOW (selected_window
);
9402 /* Set the output cursor. */
9403 output_cursor
.hpos
= hpos
;
9404 output_cursor
.vpos
= vpos
;
9405 output_cursor
.x
= x
;
9406 output_cursor
.y
= y
;
9408 /* If not called as part of an update, really display the cursor.
9409 This will also set the cursor position of W. */
9410 if (updated_window
== NULL
)
9413 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9414 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
9415 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
9420 #endif /* HAVE_WINDOW_SYSTEM */
9423 /***********************************************************************
9425 ***********************************************************************/
9427 #ifdef HAVE_WINDOW_SYSTEM
9429 /* Where the mouse was last time we reported a mouse event. */
9431 FRAME_PTR last_mouse_frame
;
9433 /* Tool-bar item index of the item on which a mouse button was pressed
9436 int last_tool_bar_item
;
9439 /* Update the tool-bar item list for frame F. This has to be done
9440 before we start to fill in any display lines. Called from
9441 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9442 and restore it here. */
9445 update_tool_bar (f
, save_match_data
)
9447 int save_match_data
;
9449 #if defined (USE_GTK) || USE_MAC_TOOLBAR
9450 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9452 int do_update
= WINDOWP (f
->tool_bar_window
)
9453 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9461 window
= FRAME_SELECTED_WINDOW (f
);
9462 w
= XWINDOW (window
);
9464 /* If the user has switched buffers or windows, we need to
9465 recompute to reflect the new bindings. But we'll
9466 recompute when update_mode_lines is set too; that means
9467 that people can use force-mode-line-update to request
9468 that the menu bar be recomputed. The adverse effect on
9469 the rest of the redisplay algorithm is about the same as
9470 windows_or_buffers_changed anyway. */
9471 if (windows_or_buffers_changed
9472 || !NILP (w
->update_mode_line
)
9473 || update_mode_lines
9474 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9475 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9476 != !NILP (w
->last_had_star
))
9477 || ((!NILP (Vtransient_mark_mode
)
9478 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9479 != !NILP (w
->region_showing
)))
9481 struct buffer
*prev
= current_buffer
;
9482 int count
= SPECPDL_INDEX ();
9483 Lisp_Object new_tool_bar
;
9485 struct gcpro gcpro1
;
9487 /* Set current_buffer to the buffer of the selected
9488 window of the frame, so that we get the right local
9490 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9492 /* Save match data, if we must. */
9493 if (save_match_data
)
9494 record_unwind_save_match_data ();
9496 /* Make sure that we don't accidentally use bogus keymaps. */
9497 if (NILP (Voverriding_local_map_menu_flag
))
9499 specbind (Qoverriding_terminal_local_map
, Qnil
);
9500 specbind (Qoverriding_local_map
, Qnil
);
9503 GCPRO1 (new_tool_bar
);
9505 /* Build desired tool-bar items from keymaps. */
9506 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9509 /* Redisplay the tool-bar if we changed it. */
9510 if (new_n_tool_bar
!= f
->n_tool_bar_items
9511 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9513 /* Redisplay that happens asynchronously due to an expose event
9514 may access f->tool_bar_items. Make sure we update both
9515 variables within BLOCK_INPUT so no such event interrupts. */
9517 f
->tool_bar_items
= new_tool_bar
;
9518 f
->n_tool_bar_items
= new_n_tool_bar
;
9519 w
->update_mode_line
= Qt
;
9525 unbind_to (count
, Qnil
);
9526 set_buffer_internal_1 (prev
);
9532 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9533 F's desired tool-bar contents. F->tool_bar_items must have
9534 been set up previously by calling prepare_menu_bars. */
9537 build_desired_tool_bar_string (f
)
9540 int i
, size
, size_needed
;
9541 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9542 Lisp_Object image
, plist
, props
;
9544 image
= plist
= props
= Qnil
;
9545 GCPRO3 (image
, plist
, props
);
9547 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9548 Otherwise, make a new string. */
9550 /* The size of the string we might be able to reuse. */
9551 size
= (STRINGP (f
->desired_tool_bar_string
)
9552 ? SCHARS (f
->desired_tool_bar_string
)
9555 /* We need one space in the string for each image. */
9556 size_needed
= f
->n_tool_bar_items
;
9558 /* Reuse f->desired_tool_bar_string, if possible. */
9559 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9560 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9564 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9565 Fremove_text_properties (make_number (0), make_number (size
),
9566 props
, f
->desired_tool_bar_string
);
9569 /* Put a `display' property on the string for the images to display,
9570 put a `menu_item' property on tool-bar items with a value that
9571 is the index of the item in F's tool-bar item vector. */
9572 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9574 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9576 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9577 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9578 int hmargin
, vmargin
, relief
, idx
, end
;
9579 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9581 /* If image is a vector, choose the image according to the
9583 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9584 if (VECTORP (image
))
9588 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9589 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9592 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9593 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9595 xassert (ASIZE (image
) >= idx
);
9596 image
= AREF (image
, idx
);
9601 /* Ignore invalid image specifications. */
9602 if (!valid_image_p (image
))
9605 /* Display the tool-bar button pressed, or depressed. */
9606 plist
= Fcopy_sequence (XCDR (image
));
9608 /* Compute margin and relief to draw. */
9609 relief
= (tool_bar_button_relief
>= 0
9610 ? tool_bar_button_relief
9611 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9612 hmargin
= vmargin
= relief
;
9614 if (INTEGERP (Vtool_bar_button_margin
)
9615 && XINT (Vtool_bar_button_margin
) > 0)
9617 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9618 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9620 else if (CONSP (Vtool_bar_button_margin
))
9622 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9623 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9624 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9626 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9627 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9628 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9631 if (auto_raise_tool_bar_buttons_p
)
9633 /* Add a `:relief' property to the image spec if the item is
9637 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9644 /* If image is selected, display it pressed, i.e. with a
9645 negative relief. If it's not selected, display it with a
9647 plist
= Fplist_put (plist
, QCrelief
,
9649 ? make_number (-relief
)
9650 : make_number (relief
)));
9655 /* Put a margin around the image. */
9656 if (hmargin
|| vmargin
)
9658 if (hmargin
== vmargin
)
9659 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9661 plist
= Fplist_put (plist
, QCmargin
,
9662 Fcons (make_number (hmargin
),
9663 make_number (vmargin
)));
9666 /* If button is not enabled, and we don't have special images
9667 for the disabled state, make the image appear disabled by
9668 applying an appropriate algorithm to it. */
9669 if (!enabled_p
&& idx
< 0)
9670 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9672 /* Put a `display' text property on the string for the image to
9673 display. Put a `menu-item' property on the string that gives
9674 the start of this item's properties in the tool-bar items
9676 image
= Fcons (Qimage
, plist
);
9677 props
= list4 (Qdisplay
, image
,
9678 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9680 /* Let the last image hide all remaining spaces in the tool bar
9681 string. The string can be longer than needed when we reuse a
9683 if (i
+ 1 == f
->n_tool_bar_items
)
9684 end
= SCHARS (f
->desired_tool_bar_string
);
9687 Fadd_text_properties (make_number (i
), make_number (end
),
9688 props
, f
->desired_tool_bar_string
);
9696 /* Display one line of the tool-bar of frame IT->f.
9698 HEIGHT specifies the desired height of the tool-bar line.
9699 If the actual height of the glyph row is less than HEIGHT, the
9700 row's height is increased to HEIGHT, and the icons are centered
9701 vertically in the new height.
9703 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
9704 count a final empty row in case the tool-bar width exactly matches
9709 display_tool_bar_line (it
, height
)
9713 struct glyph_row
*row
= it
->glyph_row
;
9714 int max_x
= it
->last_visible_x
;
9717 prepare_desired_row (row
);
9718 row
->y
= it
->current_y
;
9720 /* Note that this isn't made use of if the face hasn't a box,
9721 so there's no need to check the face here. */
9722 it
->start_of_box_run_p
= 1;
9724 while (it
->current_x
< max_x
)
9726 int x
, n_glyphs_before
, i
, nglyphs
;
9727 struct it it_before
;
9729 /* Get the next display element. */
9730 if (!get_next_display_element (it
))
9732 /* Don't count empty row if we are counting needed tool-bar lines. */
9733 if (height
< 0 && !it
->hpos
)
9738 /* Produce glyphs. */
9739 n_glyphs_before
= row
->used
[TEXT_AREA
];
9742 PRODUCE_GLYPHS (it
);
9744 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
9746 x
= it_before
.current_x
;
9749 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9751 if (x
+ glyph
->pixel_width
> max_x
)
9753 /* Glyph doesn't fit on line. Backtrack. */
9754 row
->used
[TEXT_AREA
] = n_glyphs_before
;
9756 /* If this is the only glyph on this line, it will never fit on the
9757 toolbar, so skip it. But ensure there is at least one glyph,
9758 so we don't accidentally disable the tool-bar. */
9759 if (n_glyphs_before
== 0
9760 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
9766 x
+= glyph
->pixel_width
;
9770 /* Stop at line ends. */
9771 if (ITERATOR_AT_END_OF_LINE_P (it
))
9774 set_iterator_to_next (it
, 1);
9779 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9781 /* Use default face for the border below the tool bar.
9783 FIXME: When auto-resize-tool-bars is grow-only, there is
9784 no additional border below the possibly empty tool-bar lines.
9785 So to make the extra empty lines look "normal", we have to
9786 use the tool-bar face for the border too. */
9787 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
9788 it
->face_id
= DEFAULT_FACE_ID
;
9790 extend_face_to_end_of_line (it
);
9791 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9792 last
->right_box_line_p
= 1;
9793 if (last
== row
->glyphs
[TEXT_AREA
])
9794 last
->left_box_line_p
= 1;
9796 /* Make line the desired height and center it vertically. */
9797 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
9799 /* Don't add more than one line height. */
9800 height
%= FRAME_LINE_HEIGHT (it
->f
);
9801 it
->max_ascent
+= height
/ 2;
9802 it
->max_descent
+= (height
+ 1) / 2;
9805 compute_line_metrics (it
);
9807 /* If line is empty, make it occupy the rest of the tool-bar. */
9808 if (!row
->displays_text_p
)
9810 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9811 row
->visible_height
= row
->height
;
9812 row
->ascent
= row
->phys_ascent
= 0;
9813 row
->extra_line_spacing
= 0;
9816 row
->full_width_p
= 1;
9817 row
->continued_p
= 0;
9818 row
->truncated_on_left_p
= 0;
9819 row
->truncated_on_right_p
= 0;
9821 it
->current_x
= it
->hpos
= 0;
9822 it
->current_y
+= row
->height
;
9828 /* Max tool-bar height. */
9830 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
9831 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
9833 /* Value is the number of screen lines needed to make all tool-bar
9834 items of frame F visible. The number of actual rows needed is
9835 returned in *N_ROWS if non-NULL. */
9838 tool_bar_lines_needed (f
, n_rows
)
9842 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9844 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
9845 the desired matrix, so use (unused) mode-line row as temporary row to
9846 avoid destroying the first tool-bar row. */
9847 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
9849 /* Initialize an iterator for iteration over
9850 F->desired_tool_bar_string in the tool-bar window of frame F. */
9851 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
9852 it
.first_visible_x
= 0;
9853 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9854 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9856 while (!ITERATOR_AT_END_P (&it
))
9858 clear_glyph_row (temp_row
);
9859 it
.glyph_row
= temp_row
;
9860 display_tool_bar_line (&it
, -1);
9862 clear_glyph_row (temp_row
);
9864 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
9866 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
9868 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9872 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9874 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9883 frame
= selected_frame
;
9885 CHECK_FRAME (frame
);
9888 if (WINDOWP (f
->tool_bar_window
)
9889 || (w
= XWINDOW (f
->tool_bar_window
),
9890 WINDOW_TOTAL_LINES (w
) > 0))
9892 update_tool_bar (f
, 1);
9893 if (f
->n_tool_bar_items
)
9895 build_desired_tool_bar_string (f
);
9896 nlines
= tool_bar_lines_needed (f
, NULL
);
9900 return make_number (nlines
);
9904 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9905 height should be changed. */
9908 redisplay_tool_bar (f
)
9913 struct glyph_row
*row
;
9915 #if defined (USE_GTK) || USE_MAC_TOOLBAR
9916 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9917 update_frame_tool_bar (f
);
9921 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9922 do anything. This means you must start with tool-bar-lines
9923 non-zero to get the auto-sizing effect. Or in other words, you
9924 can turn off tool-bars by specifying tool-bar-lines zero. */
9925 if (!WINDOWP (f
->tool_bar_window
)
9926 || (w
= XWINDOW (f
->tool_bar_window
),
9927 WINDOW_TOTAL_LINES (w
) == 0))
9930 /* Set up an iterator for the tool-bar window. */
9931 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9932 it
.first_visible_x
= 0;
9933 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9936 /* Build a string that represents the contents of the tool-bar. */
9937 build_desired_tool_bar_string (f
);
9938 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9940 if (f
->n_tool_bar_rows
== 0)
9944 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
9945 nlines
!= WINDOW_TOTAL_LINES (w
)))
9947 extern Lisp_Object Qtool_bar_lines
;
9949 int old_height
= WINDOW_TOTAL_LINES (w
);
9951 XSETFRAME (frame
, f
);
9952 Fmodify_frame_parameters (frame
,
9953 Fcons (Fcons (Qtool_bar_lines
,
9954 make_number (nlines
)),
9956 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9958 clear_glyph_matrix (w
->desired_matrix
);
9959 fonts_changed_p
= 1;
9965 /* Display as many lines as needed to display all tool-bar items. */
9967 if (f
->n_tool_bar_rows
> 0)
9969 int border
, rows
, height
, extra
;
9971 if (INTEGERP (Vtool_bar_border
))
9972 border
= XINT (Vtool_bar_border
);
9973 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
9974 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
9975 else if (EQ (Vtool_bar_border
, Qborder_width
))
9976 border
= f
->border_width
;
9982 rows
= f
->n_tool_bar_rows
;
9983 height
= max (1, (it
.last_visible_y
- border
) / rows
);
9984 extra
= it
.last_visible_y
- border
- height
* rows
;
9986 while (it
.current_y
< it
.last_visible_y
)
9989 if (extra
> 0 && rows
-- > 0)
9991 h
= (extra
+ rows
- 1) / rows
;
9994 display_tool_bar_line (&it
, height
+ h
);
9999 while (it
.current_y
< it
.last_visible_y
)
10000 display_tool_bar_line (&it
, 0);
10003 /* It doesn't make much sense to try scrolling in the tool-bar
10004 window, so don't do it. */
10005 w
->desired_matrix
->no_scrolling_p
= 1;
10006 w
->must_be_updated_p
= 1;
10008 if (!NILP (Vauto_resize_tool_bars
))
10010 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10011 int change_height_p
= 0;
10013 /* If we couldn't display everything, change the tool-bar's
10014 height if there is room for more. */
10015 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10016 && it
.current_y
< max_tool_bar_height
)
10017 change_height_p
= 1;
10019 row
= it
.glyph_row
- 1;
10021 /* If there are blank lines at the end, except for a partially
10022 visible blank line at the end that is smaller than
10023 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10024 if (!row
->displays_text_p
10025 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10026 change_height_p
= 1;
10028 /* If row displays tool-bar items, but is partially visible,
10029 change the tool-bar's height. */
10030 if (row
->displays_text_p
10031 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10032 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10033 change_height_p
= 1;
10035 /* Resize windows as needed by changing the `tool-bar-lines'
10036 frame parameter. */
10037 if (change_height_p
)
10039 extern Lisp_Object Qtool_bar_lines
;
10041 int old_height
= WINDOW_TOTAL_LINES (w
);
10043 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10045 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10046 && !f
->minimize_tool_bar_window_p
)
10047 ? (nlines
> old_height
)
10048 : (nlines
!= old_height
));
10049 f
->minimize_tool_bar_window_p
= 0;
10051 if (change_height_p
)
10053 XSETFRAME (frame
, f
);
10054 Fmodify_frame_parameters (frame
,
10055 Fcons (Fcons (Qtool_bar_lines
,
10056 make_number (nlines
)),
10058 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10060 clear_glyph_matrix (w
->desired_matrix
);
10061 f
->n_tool_bar_rows
= nrows
;
10062 fonts_changed_p
= 1;
10069 f
->minimize_tool_bar_window_p
= 0;
10074 /* Get information about the tool-bar item which is displayed in GLYPH
10075 on frame F. Return in *PROP_IDX the index where tool-bar item
10076 properties start in F->tool_bar_items. Value is zero if
10077 GLYPH doesn't display a tool-bar item. */
10080 tool_bar_item_info (f
, glyph
, prop_idx
)
10082 struct glyph
*glyph
;
10089 /* This function can be called asynchronously, which means we must
10090 exclude any possibility that Fget_text_property signals an
10092 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10093 charpos
= max (0, charpos
);
10095 /* Get the text property `menu-item' at pos. The value of that
10096 property is the start index of this item's properties in
10097 F->tool_bar_items. */
10098 prop
= Fget_text_property (make_number (charpos
),
10099 Qmenu_item
, f
->current_tool_bar_string
);
10100 if (INTEGERP (prop
))
10102 *prop_idx
= XINT (prop
);
10112 /* Get information about the tool-bar item at position X/Y on frame F.
10113 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10114 the current matrix of the tool-bar window of F, or NULL if not
10115 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10116 item in F->tool_bar_items. Value is
10118 -1 if X/Y is not on a tool-bar item
10119 0 if X/Y is on the same item that was highlighted before.
10123 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10126 struct glyph
**glyph
;
10127 int *hpos
, *vpos
, *prop_idx
;
10129 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10130 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10133 /* Find the glyph under X/Y. */
10134 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10135 if (*glyph
== NULL
)
10138 /* Get the start of this tool-bar item's properties in
10139 f->tool_bar_items. */
10140 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10143 /* Is mouse on the highlighted item? */
10144 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10145 && *vpos
>= dpyinfo
->mouse_face_beg_row
10146 && *vpos
<= dpyinfo
->mouse_face_end_row
10147 && (*vpos
> dpyinfo
->mouse_face_beg_row
10148 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10149 && (*vpos
< dpyinfo
->mouse_face_end_row
10150 || *hpos
< dpyinfo
->mouse_face_end_col
10151 || dpyinfo
->mouse_face_past_end
))
10159 Handle mouse button event on the tool-bar of frame F, at
10160 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10161 0 for button release. MODIFIERS is event modifiers for button
10165 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10168 unsigned int modifiers
;
10170 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10171 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10172 int hpos
, vpos
, prop_idx
;
10173 struct glyph
*glyph
;
10174 Lisp_Object enabled_p
;
10176 /* If not on the highlighted tool-bar item, return. */
10177 frame_to_window_pixel_xy (w
, &x
, &y
);
10178 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10181 /* If item is disabled, do nothing. */
10182 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10183 if (NILP (enabled_p
))
10188 /* Show item in pressed state. */
10189 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10190 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10191 last_tool_bar_item
= prop_idx
;
10195 Lisp_Object key
, frame
;
10196 struct input_event event
;
10197 EVENT_INIT (event
);
10199 /* Show item in released state. */
10200 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10201 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10203 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10205 XSETFRAME (frame
, f
);
10206 event
.kind
= TOOL_BAR_EVENT
;
10207 event
.frame_or_window
= frame
;
10209 kbd_buffer_store_event (&event
);
10211 event
.kind
= TOOL_BAR_EVENT
;
10212 event
.frame_or_window
= frame
;
10214 event
.modifiers
= modifiers
;
10215 kbd_buffer_store_event (&event
);
10216 last_tool_bar_item
= -1;
10221 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10222 tool-bar window-relative coordinates X/Y. Called from
10223 note_mouse_highlight. */
10226 note_tool_bar_highlight (f
, x
, y
)
10230 Lisp_Object window
= f
->tool_bar_window
;
10231 struct window
*w
= XWINDOW (window
);
10232 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10234 struct glyph
*glyph
;
10235 struct glyph_row
*row
;
10237 Lisp_Object enabled_p
;
10239 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10240 int mouse_down_p
, rc
;
10242 /* Function note_mouse_highlight is called with negative x(y
10243 values when mouse moves outside of the frame. */
10244 if (x
<= 0 || y
<= 0)
10246 clear_mouse_face (dpyinfo
);
10250 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10253 /* Not on tool-bar item. */
10254 clear_mouse_face (dpyinfo
);
10258 /* On same tool-bar item as before. */
10259 goto set_help_echo
;
10261 clear_mouse_face (dpyinfo
);
10263 /* Mouse is down, but on different tool-bar item? */
10264 mouse_down_p
= (dpyinfo
->grabbed
10265 && f
== last_mouse_frame
10266 && FRAME_LIVE_P (f
));
10268 && last_tool_bar_item
!= prop_idx
)
10271 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10272 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10274 /* If tool-bar item is not enabled, don't highlight it. */
10275 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10276 if (!NILP (enabled_p
))
10278 /* Compute the x-position of the glyph. In front and past the
10279 image is a space. We include this in the highlighted area. */
10280 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10281 for (i
= x
= 0; i
< hpos
; ++i
)
10282 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10284 /* Record this as the current active region. */
10285 dpyinfo
->mouse_face_beg_col
= hpos
;
10286 dpyinfo
->mouse_face_beg_row
= vpos
;
10287 dpyinfo
->mouse_face_beg_x
= x
;
10288 dpyinfo
->mouse_face_beg_y
= row
->y
;
10289 dpyinfo
->mouse_face_past_end
= 0;
10291 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10292 dpyinfo
->mouse_face_end_row
= vpos
;
10293 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10294 dpyinfo
->mouse_face_end_y
= row
->y
;
10295 dpyinfo
->mouse_face_window
= window
;
10296 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10298 /* Display it as active. */
10299 show_mouse_face (dpyinfo
, draw
);
10300 dpyinfo
->mouse_face_image_state
= draw
;
10305 /* Set help_echo_string to a help string to display for this tool-bar item.
10306 XTread_socket does the rest. */
10307 help_echo_object
= help_echo_window
= Qnil
;
10308 help_echo_pos
= -1;
10309 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10310 if (NILP (help_echo_string
))
10311 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10314 #endif /* HAVE_WINDOW_SYSTEM */
10318 /************************************************************************
10319 Horizontal scrolling
10320 ************************************************************************/
10322 static int hscroll_window_tree
P_ ((Lisp_Object
));
10323 static int hscroll_windows
P_ ((Lisp_Object
));
10325 /* For all leaf windows in the window tree rooted at WINDOW, set their
10326 hscroll value so that PT is (i) visible in the window, and (ii) so
10327 that it is not within a certain margin at the window's left and
10328 right border. Value is non-zero if any window's hscroll has been
10332 hscroll_window_tree (window
)
10333 Lisp_Object window
;
10335 int hscrolled_p
= 0;
10336 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10337 int hscroll_step_abs
= 0;
10338 double hscroll_step_rel
= 0;
10340 if (hscroll_relative_p
)
10342 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10343 if (hscroll_step_rel
< 0)
10345 hscroll_relative_p
= 0;
10346 hscroll_step_abs
= 0;
10349 else if (INTEGERP (Vhscroll_step
))
10351 hscroll_step_abs
= XINT (Vhscroll_step
);
10352 if (hscroll_step_abs
< 0)
10353 hscroll_step_abs
= 0;
10356 hscroll_step_abs
= 0;
10358 while (WINDOWP (window
))
10360 struct window
*w
= XWINDOW (window
);
10362 if (WINDOWP (w
->hchild
))
10363 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10364 else if (WINDOWP (w
->vchild
))
10365 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10366 else if (w
->cursor
.vpos
>= 0)
10369 int text_area_width
;
10370 struct glyph_row
*current_cursor_row
10371 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10372 struct glyph_row
*desired_cursor_row
10373 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10374 struct glyph_row
*cursor_row
10375 = (desired_cursor_row
->enabled_p
10376 ? desired_cursor_row
10377 : current_cursor_row
);
10379 text_area_width
= window_box_width (w
, TEXT_AREA
);
10381 /* Scroll when cursor is inside this scroll margin. */
10382 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10384 if ((XFASTINT (w
->hscroll
)
10385 && w
->cursor
.x
<= h_margin
)
10386 || (cursor_row
->enabled_p
10387 && cursor_row
->truncated_on_right_p
10388 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
10392 struct buffer
*saved_current_buffer
;
10396 /* Find point in a display of infinite width. */
10397 saved_current_buffer
= current_buffer
;
10398 current_buffer
= XBUFFER (w
->buffer
);
10400 if (w
== XWINDOW (selected_window
))
10401 pt
= BUF_PT (current_buffer
);
10404 pt
= marker_position (w
->pointm
);
10405 pt
= max (BEGV
, pt
);
10409 /* Move iterator to pt starting at cursor_row->start in
10410 a line with infinite width. */
10411 init_to_row_start (&it
, w
, cursor_row
);
10412 it
.last_visible_x
= INFINITY
;
10413 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10414 current_buffer
= saved_current_buffer
;
10416 /* Position cursor in window. */
10417 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10418 hscroll
= max (0, (it
.current_x
10419 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10420 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10421 : (text_area_width
/ 2))))
10422 / FRAME_COLUMN_WIDTH (it
.f
);
10423 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10425 if (hscroll_relative_p
)
10426 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10429 wanted_x
= text_area_width
10430 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10433 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10437 if (hscroll_relative_p
)
10438 wanted_x
= text_area_width
* hscroll_step_rel
10441 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10444 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10446 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10448 /* Don't call Fset_window_hscroll if value hasn't
10449 changed because it will prevent redisplay
10451 if (XFASTINT (w
->hscroll
) != hscroll
)
10453 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10454 w
->hscroll
= make_number (hscroll
);
10463 /* Value is non-zero if hscroll of any leaf window has been changed. */
10464 return hscrolled_p
;
10468 /* Set hscroll so that cursor is visible and not inside horizontal
10469 scroll margins for all windows in the tree rooted at WINDOW. See
10470 also hscroll_window_tree above. Value is non-zero if any window's
10471 hscroll has been changed. If it has, desired matrices on the frame
10472 of WINDOW are cleared. */
10475 hscroll_windows (window
)
10476 Lisp_Object window
;
10480 if (automatic_hscrolling_p
)
10482 hscrolled_p
= hscroll_window_tree (window
);
10484 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10488 return hscrolled_p
;
10493 /************************************************************************
10495 ************************************************************************/
10497 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10498 to a non-zero value. This is sometimes handy to have in a debugger
10503 /* First and last unchanged row for try_window_id. */
10505 int debug_first_unchanged_at_end_vpos
;
10506 int debug_last_unchanged_at_beg_vpos
;
10508 /* Delta vpos and y. */
10510 int debug_dvpos
, debug_dy
;
10512 /* Delta in characters and bytes for try_window_id. */
10514 int debug_delta
, debug_delta_bytes
;
10516 /* Values of window_end_pos and window_end_vpos at the end of
10519 EMACS_INT debug_end_pos
, debug_end_vpos
;
10521 /* Append a string to W->desired_matrix->method. FMT is a printf
10522 format string. A1...A9 are a supplement for a variable-length
10523 argument list. If trace_redisplay_p is non-zero also printf the
10524 resulting string to stderr. */
10527 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10530 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10533 char *method
= w
->desired_matrix
->method
;
10534 int len
= strlen (method
);
10535 int size
= sizeof w
->desired_matrix
->method
;
10536 int remaining
= size
- len
- 1;
10538 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10539 if (len
&& remaining
)
10542 --remaining
, ++len
;
10545 strncpy (method
+ len
, buffer
, remaining
);
10547 if (trace_redisplay_p
)
10548 fprintf (stderr
, "%p (%s): %s\n",
10550 ((BUFFERP (w
->buffer
)
10551 && STRINGP (XBUFFER (w
->buffer
)->name
))
10552 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10557 #endif /* GLYPH_DEBUG */
10560 /* Value is non-zero if all changes in window W, which displays
10561 current_buffer, are in the text between START and END. START is a
10562 buffer position, END is given as a distance from Z. Used in
10563 redisplay_internal for display optimization. */
10566 text_outside_line_unchanged_p (w
, start
, end
)
10570 int unchanged_p
= 1;
10572 /* If text or overlays have changed, see where. */
10573 if (XFASTINT (w
->last_modified
) < MODIFF
10574 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10576 /* Gap in the line? */
10577 if (GPT
< start
|| Z
- GPT
< end
)
10580 /* Changes start in front of the line, or end after it? */
10582 && (BEG_UNCHANGED
< start
- 1
10583 || END_UNCHANGED
< end
))
10586 /* If selective display, can't optimize if changes start at the
10587 beginning of the line. */
10589 && INTEGERP (current_buffer
->selective_display
)
10590 && XINT (current_buffer
->selective_display
) > 0
10591 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10594 /* If there are overlays at the start or end of the line, these
10595 may have overlay strings with newlines in them. A change at
10596 START, for instance, may actually concern the display of such
10597 overlay strings as well, and they are displayed on different
10598 lines. So, quickly rule out this case. (For the future, it
10599 might be desirable to implement something more telling than
10600 just BEG/END_UNCHANGED.) */
10603 if (BEG
+ BEG_UNCHANGED
== start
10604 && overlay_touches_p (start
))
10606 if (END_UNCHANGED
== end
10607 && overlay_touches_p (Z
- end
))
10612 return unchanged_p
;
10616 /* Do a frame update, taking possible shortcuts into account. This is
10617 the main external entry point for redisplay.
10619 If the last redisplay displayed an echo area message and that message
10620 is no longer requested, we clear the echo area or bring back the
10621 mini-buffer if that is in use. */
10626 redisplay_internal (0);
10631 overlay_arrow_string_or_property (var
)
10636 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10639 return Voverlay_arrow_string
;
10642 /* Return 1 if there are any overlay-arrows in current_buffer. */
10644 overlay_arrow_in_current_buffer_p ()
10648 for (vlist
= Voverlay_arrow_variable_list
;
10650 vlist
= XCDR (vlist
))
10652 Lisp_Object var
= XCAR (vlist
);
10655 if (!SYMBOLP (var
))
10657 val
= find_symbol_value (var
);
10659 && current_buffer
== XMARKER (val
)->buffer
)
10666 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
10670 overlay_arrows_changed_p ()
10674 for (vlist
= Voverlay_arrow_variable_list
;
10676 vlist
= XCDR (vlist
))
10678 Lisp_Object var
= XCAR (vlist
);
10679 Lisp_Object val
, pstr
;
10681 if (!SYMBOLP (var
))
10683 val
= find_symbol_value (var
);
10684 if (!MARKERP (val
))
10686 if (! EQ (COERCE_MARKER (val
),
10687 Fget (var
, Qlast_arrow_position
))
10688 || ! (pstr
= overlay_arrow_string_or_property (var
),
10689 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
10695 /* Mark overlay arrows to be updated on next redisplay. */
10698 update_overlay_arrows (up_to_date
)
10703 for (vlist
= Voverlay_arrow_variable_list
;
10705 vlist
= XCDR (vlist
))
10707 Lisp_Object var
= XCAR (vlist
);
10709 if (!SYMBOLP (var
))
10712 if (up_to_date
> 0)
10714 Lisp_Object val
= find_symbol_value (var
);
10715 Fput (var
, Qlast_arrow_position
,
10716 COERCE_MARKER (val
));
10717 Fput (var
, Qlast_arrow_string
,
10718 overlay_arrow_string_or_property (var
));
10720 else if (up_to_date
< 0
10721 || !NILP (Fget (var
, Qlast_arrow_position
)))
10723 Fput (var
, Qlast_arrow_position
, Qt
);
10724 Fput (var
, Qlast_arrow_string
, Qt
);
10730 /* Return overlay arrow string to display at row.
10731 Return integer (bitmap number) for arrow bitmap in left fringe.
10732 Return nil if no overlay arrow. */
10735 overlay_arrow_at_row (it
, row
)
10737 struct glyph_row
*row
;
10741 for (vlist
= Voverlay_arrow_variable_list
;
10743 vlist
= XCDR (vlist
))
10745 Lisp_Object var
= XCAR (vlist
);
10748 if (!SYMBOLP (var
))
10751 val
= find_symbol_value (var
);
10754 && current_buffer
== XMARKER (val
)->buffer
10755 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10757 if (FRAME_WINDOW_P (it
->f
)
10758 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10760 #ifdef HAVE_WINDOW_SYSTEM
10761 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10764 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10765 return make_number (fringe_bitmap
);
10768 return make_number (-1); /* Use default arrow bitmap */
10770 return overlay_arrow_string_or_property (var
);
10777 /* Return 1 if point moved out of or into a composition. Otherwise
10778 return 0. PREV_BUF and PREV_PT are the last point buffer and
10779 position. BUF and PT are the current point buffer and position. */
10782 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10783 struct buffer
*prev_buf
, *buf
;
10788 Lisp_Object buffer
;
10790 XSETBUFFER (buffer
, buf
);
10791 /* Check a composition at the last point if point moved within the
10793 if (prev_buf
== buf
)
10796 /* Point didn't move. */
10799 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10800 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10801 && COMPOSITION_VALID_P (start
, end
, prop
)
10802 && start
< prev_pt
&& end
> prev_pt
)
10803 /* The last point was within the composition. Return 1 iff
10804 point moved out of the composition. */
10805 return (pt
<= start
|| pt
>= end
);
10808 /* Check a composition at the current point. */
10809 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10810 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10811 && COMPOSITION_VALID_P (start
, end
, prop
)
10812 && start
< pt
&& end
> pt
);
10816 /* Reconsider the setting of B->clip_changed which is displayed
10820 reconsider_clip_changes (w
, b
)
10824 if (b
->clip_changed
10825 && !NILP (w
->window_end_valid
)
10826 && w
->current_matrix
->buffer
== b
10827 && w
->current_matrix
->zv
== BUF_ZV (b
)
10828 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10829 b
->clip_changed
= 0;
10831 /* If display wasn't paused, and W is not a tool bar window, see if
10832 point has been moved into or out of a composition. In that case,
10833 we set b->clip_changed to 1 to force updating the screen. If
10834 b->clip_changed has already been set to 1, we can skip this
10836 if (!b
->clip_changed
10837 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10841 if (w
== XWINDOW (selected_window
))
10842 pt
= BUF_PT (current_buffer
);
10844 pt
= marker_position (w
->pointm
);
10846 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10847 || pt
!= XINT (w
->last_point
))
10848 && check_point_in_composition (w
->current_matrix
->buffer
,
10849 XINT (w
->last_point
),
10850 XBUFFER (w
->buffer
), pt
))
10851 b
->clip_changed
= 1;
10856 /* Select FRAME to forward the values of frame-local variables into C
10857 variables so that the redisplay routines can access those values
10861 select_frame_for_redisplay (frame
)
10864 Lisp_Object tail
, sym
, val
;
10865 Lisp_Object old
= selected_frame
;
10867 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
10869 selected_frame
= frame
;
10871 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10872 if (CONSP (XCAR (tail
))
10873 && (sym
= XCAR (XCAR (tail
)),
10875 && (sym
= indirect_variable (sym
),
10876 val
= SYMBOL_VALUE (sym
),
10877 (BUFFER_LOCAL_VALUEP (val
)))
10878 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10879 /* Use find_symbol_value rather than Fsymbol_value
10880 to avoid an error if it is void. */
10881 find_symbol_value (sym
);
10883 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10884 if (CONSP (XCAR (tail
))
10885 && (sym
= XCAR (XCAR (tail
)),
10887 && (sym
= indirect_variable (sym
),
10888 val
= SYMBOL_VALUE (sym
),
10889 (BUFFER_LOCAL_VALUEP (val
)))
10890 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10891 find_symbol_value (sym
);
10895 #define STOP_POLLING \
10896 do { if (! polling_stopped_here) stop_polling (); \
10897 polling_stopped_here = 1; } while (0)
10899 #define RESUME_POLLING \
10900 do { if (polling_stopped_here) start_polling (); \
10901 polling_stopped_here = 0; } while (0)
10904 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10905 response to any user action; therefore, we should preserve the echo
10906 area. (Actually, our caller does that job.) Perhaps in the future
10907 avoid recentering windows if it is not necessary; currently that
10908 causes some problems. */
10911 redisplay_internal (preserve_echo_area
)
10912 int preserve_echo_area
;
10914 struct window
*w
= XWINDOW (selected_window
);
10917 int must_finish
= 0;
10918 struct text_pos tlbufpos
, tlendpos
;
10919 int number_of_visible_frames
;
10922 int polling_stopped_here
= 0;
10923 Lisp_Object old_frame
= selected_frame
;
10925 /* Non-zero means redisplay has to consider all windows on all
10926 frames. Zero means, only selected_window is considered. */
10927 int consider_all_windows_p
;
10929 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10931 /* No redisplay if running in batch mode or frame is not yet fully
10932 initialized, or redisplay is explicitly turned off by setting
10933 Vinhibit_redisplay. */
10935 || !NILP (Vinhibit_redisplay
))
10938 /* Don't examine these until after testing Vinhibit_redisplay.
10939 When Emacs is shutting down, perhaps because its connection to
10940 X has dropped, we should not look at them at all. */
10941 f
= XFRAME (w
->frame
);
10942 sf
= SELECTED_FRAME ();
10944 if (!f
->glyphs_initialized_p
)
10947 /* The flag redisplay_performed_directly_p is set by
10948 direct_output_for_insert when it already did the whole screen
10949 update necessary. */
10950 if (redisplay_performed_directly_p
)
10952 redisplay_performed_directly_p
= 0;
10953 if (!hscroll_windows (selected_window
))
10957 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (MAC_OS)
10958 if (popup_activated ())
10962 /* I don't think this happens but let's be paranoid. */
10963 if (redisplaying_p
)
10966 /* Record a function that resets redisplaying_p to its old value
10967 when we leave this function. */
10968 count
= SPECPDL_INDEX ();
10969 record_unwind_protect (unwind_redisplay
,
10970 Fcons (make_number (redisplaying_p
), selected_frame
));
10972 specbind (Qinhibit_free_realized_faces
, Qnil
);
10975 Lisp_Object tail
, frame
;
10977 FOR_EACH_FRAME (tail
, frame
)
10979 struct frame
*f
= XFRAME (frame
);
10980 f
->already_hscrolled_p
= 0;
10985 if (!EQ (old_frame
, selected_frame
)
10986 && FRAME_LIVE_P (XFRAME (old_frame
)))
10987 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
10988 selected_frame and selected_window to be temporarily out-of-sync so
10989 when we come back here via `goto retry', we need to resync because we
10990 may need to run Elisp code (via prepare_menu_bars). */
10991 select_frame_for_redisplay (old_frame
);
10994 reconsider_clip_changes (w
, current_buffer
);
10995 last_escape_glyph_frame
= NULL
;
10996 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
10998 /* If new fonts have been loaded that make a glyph matrix adjustment
10999 necessary, do it. */
11000 if (fonts_changed_p
)
11002 adjust_glyphs (NULL
);
11003 ++windows_or_buffers_changed
;
11004 fonts_changed_p
= 0;
11007 /* If face_change_count is non-zero, init_iterator will free all
11008 realized faces, which includes the faces referenced from current
11009 matrices. So, we can't reuse current matrices in this case. */
11010 if (face_change_count
)
11011 ++windows_or_buffers_changed
;
11013 if (FRAME_TERMCAP_P (sf
)
11014 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11016 /* Since frames on a single ASCII terminal share the same
11017 display area, displaying a different frame means redisplay
11018 the whole thing. */
11019 windows_or_buffers_changed
++;
11020 SET_FRAME_GARBAGED (sf
);
11021 FRAME_TTY (sf
)->previous_frame
= sf
;
11024 /* Set the visible flags for all frames. Do this before checking
11025 for resized or garbaged frames; they want to know if their frames
11026 are visible. See the comment in frame.h for
11027 FRAME_SAMPLE_VISIBILITY. */
11029 Lisp_Object tail
, frame
;
11031 number_of_visible_frames
= 0;
11033 FOR_EACH_FRAME (tail
, frame
)
11035 struct frame
*f
= XFRAME (frame
);
11037 FRAME_SAMPLE_VISIBILITY (f
);
11038 if (FRAME_VISIBLE_P (f
))
11039 ++number_of_visible_frames
;
11040 clear_desired_matrices (f
);
11045 /* Notice any pending interrupt request to change frame size. */
11046 do_pending_window_change (1);
11048 /* Clear frames marked as garbaged. */
11049 if (frame_garbaged
)
11050 clear_garbaged_frames ();
11052 /* Build menubar and tool-bar items. */
11053 if (NILP (Vmemory_full
))
11054 prepare_menu_bars ();
11056 if (windows_or_buffers_changed
)
11057 update_mode_lines
++;
11059 /* Detect case that we need to write or remove a star in the mode line. */
11060 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11062 w
->update_mode_line
= Qt
;
11063 if (buffer_shared
> 1)
11064 update_mode_lines
++;
11067 /* Avoid invocation of point motion hooks by `current_column' below. */
11068 count1
= SPECPDL_INDEX ();
11069 specbind (Qinhibit_point_motion_hooks
, Qt
);
11071 /* If %c is in the mode line, update it if needed. */
11072 if (!NILP (w
->column_number_displayed
)
11073 /* This alternative quickly identifies a common case
11074 where no change is needed. */
11075 && !(PT
== XFASTINT (w
->last_point
)
11076 && XFASTINT (w
->last_modified
) >= MODIFF
11077 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11078 && (XFASTINT (w
->column_number_displayed
)
11079 != (int) current_column ())) /* iftc */
11080 w
->update_mode_line
= Qt
;
11082 unbind_to (count1
, Qnil
);
11084 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11086 /* The variable buffer_shared is set in redisplay_window and
11087 indicates that we redisplay a buffer in different windows. See
11089 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11090 || cursor_type_changed
);
11092 /* If specs for an arrow have changed, do thorough redisplay
11093 to ensure we remove any arrow that should no longer exist. */
11094 if (overlay_arrows_changed_p ())
11095 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11097 /* Normally the message* functions will have already displayed and
11098 updated the echo area, but the frame may have been trashed, or
11099 the update may have been preempted, so display the echo area
11100 again here. Checking message_cleared_p captures the case that
11101 the echo area should be cleared. */
11102 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11103 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11104 || (message_cleared_p
11105 && minibuf_level
== 0
11106 /* If the mini-window is currently selected, this means the
11107 echo-area doesn't show through. */
11108 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11110 int window_height_changed_p
= echo_area_display (0);
11113 /* If we don't display the current message, don't clear the
11114 message_cleared_p flag, because, if we did, we wouldn't clear
11115 the echo area in the next redisplay which doesn't preserve
11117 if (!display_last_displayed_message_p
)
11118 message_cleared_p
= 0;
11120 if (fonts_changed_p
)
11122 else if (window_height_changed_p
)
11124 consider_all_windows_p
= 1;
11125 ++update_mode_lines
;
11126 ++windows_or_buffers_changed
;
11128 /* If window configuration was changed, frames may have been
11129 marked garbaged. Clear them or we will experience
11130 surprises wrt scrolling. */
11131 if (frame_garbaged
)
11132 clear_garbaged_frames ();
11135 else if (EQ (selected_window
, minibuf_window
)
11136 && (current_buffer
->clip_changed
11137 || XFASTINT (w
->last_modified
) < MODIFF
11138 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11139 && resize_mini_window (w
, 0))
11141 /* Resized active mini-window to fit the size of what it is
11142 showing if its contents might have changed. */
11144 consider_all_windows_p
= 1;
11145 ++windows_or_buffers_changed
;
11146 ++update_mode_lines
;
11148 /* If window configuration was changed, frames may have been
11149 marked garbaged. Clear them or we will experience
11150 surprises wrt scrolling. */
11151 if (frame_garbaged
)
11152 clear_garbaged_frames ();
11156 /* If showing the region, and mark has changed, we must redisplay
11157 the whole window. The assignment to this_line_start_pos prevents
11158 the optimization directly below this if-statement. */
11159 if (((!NILP (Vtransient_mark_mode
)
11160 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11161 != !NILP (w
->region_showing
))
11162 || (!NILP (w
->region_showing
)
11163 && !EQ (w
->region_showing
,
11164 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11165 CHARPOS (this_line_start_pos
) = 0;
11167 /* Optimize the case that only the line containing the cursor in the
11168 selected window has changed. Variables starting with this_ are
11169 set in display_line and record information about the line
11170 containing the cursor. */
11171 tlbufpos
= this_line_start_pos
;
11172 tlendpos
= this_line_end_pos
;
11173 if (!consider_all_windows_p
11174 && CHARPOS (tlbufpos
) > 0
11175 && NILP (w
->update_mode_line
)
11176 && !current_buffer
->clip_changed
11177 && !current_buffer
->prevent_redisplay_optimizations_p
11178 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11179 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11180 /* Make sure recorded data applies to current buffer, etc. */
11181 && this_line_buffer
== current_buffer
11182 && current_buffer
== XBUFFER (w
->buffer
)
11183 && NILP (w
->force_start
)
11184 && NILP (w
->optional_new_start
)
11185 /* Point must be on the line that we have info recorded about. */
11186 && PT
>= CHARPOS (tlbufpos
)
11187 && PT
<= Z
- CHARPOS (tlendpos
)
11188 /* All text outside that line, including its final newline,
11189 must be unchanged */
11190 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11191 CHARPOS (tlendpos
)))
11193 if (CHARPOS (tlbufpos
) > BEGV
11194 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11195 && (CHARPOS (tlbufpos
) == ZV
11196 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11197 /* Former continuation line has disappeared by becoming empty */
11199 else if (XFASTINT (w
->last_modified
) < MODIFF
11200 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11201 || MINI_WINDOW_P (w
))
11203 /* We have to handle the case of continuation around a
11204 wide-column character (See the comment in indent.c around
11207 For instance, in the following case:
11209 -------- Insert --------
11210 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11211 J_I_ ==> J_I_ `^^' are cursors.
11215 As we have to redraw the line above, we should goto cancel. */
11218 int line_height_before
= this_line_pixel_height
;
11220 /* Note that start_display will handle the case that the
11221 line starting at tlbufpos is a continuation lines. */
11222 start_display (&it
, w
, tlbufpos
);
11224 /* Implementation note: It this still necessary? */
11225 if (it
.current_x
!= this_line_start_x
)
11228 TRACE ((stderr
, "trying display optimization 1\n"));
11229 w
->cursor
.vpos
= -1;
11230 overlay_arrow_seen
= 0;
11231 it
.vpos
= this_line_vpos
;
11232 it
.current_y
= this_line_y
;
11233 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11234 display_line (&it
);
11236 /* If line contains point, is not continued,
11237 and ends at same distance from eob as before, we win */
11238 if (w
->cursor
.vpos
>= 0
11239 /* Line is not continued, otherwise this_line_start_pos
11240 would have been set to 0 in display_line. */
11241 && CHARPOS (this_line_start_pos
)
11242 /* Line ends as before. */
11243 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11244 /* Line has same height as before. Otherwise other lines
11245 would have to be shifted up or down. */
11246 && this_line_pixel_height
== line_height_before
)
11248 /* If this is not the window's last line, we must adjust
11249 the charstarts of the lines below. */
11250 if (it
.current_y
< it
.last_visible_y
)
11252 struct glyph_row
*row
11253 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11254 int delta
, delta_bytes
;
11256 if (Z
- CHARPOS (tlendpos
) == ZV
)
11258 /* This line ends at end of (accessible part of)
11259 buffer. There is no newline to count. */
11261 - CHARPOS (tlendpos
)
11262 - MATRIX_ROW_START_CHARPOS (row
));
11263 delta_bytes
= (Z_BYTE
11264 - BYTEPOS (tlendpos
)
11265 - MATRIX_ROW_START_BYTEPOS (row
));
11269 /* This line ends in a newline. Must take
11270 account of the newline and the rest of the
11271 text that follows. */
11273 - CHARPOS (tlendpos
)
11274 - MATRIX_ROW_START_CHARPOS (row
));
11275 delta_bytes
= (Z_BYTE
11276 - BYTEPOS (tlendpos
)
11277 - MATRIX_ROW_START_BYTEPOS (row
));
11280 increment_matrix_positions (w
->current_matrix
,
11281 this_line_vpos
+ 1,
11282 w
->current_matrix
->nrows
,
11283 delta
, delta_bytes
);
11286 /* If this row displays text now but previously didn't,
11287 or vice versa, w->window_end_vpos may have to be
11289 if ((it
.glyph_row
- 1)->displays_text_p
)
11291 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11292 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11294 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11295 && this_line_vpos
> 0)
11296 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11297 w
->window_end_valid
= Qnil
;
11299 /* Update hint: No need to try to scroll in update_window. */
11300 w
->desired_matrix
->no_scrolling_p
= 1;
11303 *w
->desired_matrix
->method
= 0;
11304 debug_method_add (w
, "optimization 1");
11306 #ifdef HAVE_WINDOW_SYSTEM
11307 update_window_fringes (w
, 0);
11314 else if (/* Cursor position hasn't changed. */
11315 PT
== XFASTINT (w
->last_point
)
11316 /* Make sure the cursor was last displayed
11317 in this window. Otherwise we have to reposition it. */
11318 && 0 <= w
->cursor
.vpos
11319 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11323 do_pending_window_change (1);
11325 /* We used to always goto end_of_redisplay here, but this
11326 isn't enough if we have a blinking cursor. */
11327 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11328 goto end_of_redisplay
;
11332 /* If highlighting the region, or if the cursor is in the echo area,
11333 then we can't just move the cursor. */
11334 else if (! (!NILP (Vtransient_mark_mode
)
11335 && !NILP (current_buffer
->mark_active
))
11336 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11337 || highlight_nonselected_windows
)
11338 && NILP (w
->region_showing
)
11339 && NILP (Vshow_trailing_whitespace
)
11340 && !cursor_in_echo_area
)
11343 struct glyph_row
*row
;
11345 /* Skip from tlbufpos to PT and see where it is. Note that
11346 PT may be in invisible text. If so, we will end at the
11347 next visible position. */
11348 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11349 NULL
, DEFAULT_FACE_ID
);
11350 it
.current_x
= this_line_start_x
;
11351 it
.current_y
= this_line_y
;
11352 it
.vpos
= this_line_vpos
;
11354 /* The call to move_it_to stops in front of PT, but
11355 moves over before-strings. */
11356 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11358 if (it
.vpos
== this_line_vpos
11359 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11362 xassert (this_line_vpos
== it
.vpos
);
11363 xassert (this_line_y
== it
.current_y
);
11364 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11366 *w
->desired_matrix
->method
= 0;
11367 debug_method_add (w
, "optimization 3");
11376 /* Text changed drastically or point moved off of line. */
11377 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11380 CHARPOS (this_line_start_pos
) = 0;
11381 consider_all_windows_p
|= buffer_shared
> 1;
11382 ++clear_face_cache_count
;
11383 #ifdef HAVE_WINDOW_SYSTEM
11384 ++clear_image_cache_count
;
11387 /* Build desired matrices, and update the display. If
11388 consider_all_windows_p is non-zero, do it for all windows on all
11389 frames. Otherwise do it for selected_window, only. */
11391 if (consider_all_windows_p
)
11393 Lisp_Object tail
, frame
;
11395 FOR_EACH_FRAME (tail
, frame
)
11396 XFRAME (frame
)->updated_p
= 0;
11398 /* Recompute # windows showing selected buffer. This will be
11399 incremented each time such a window is displayed. */
11402 FOR_EACH_FRAME (tail
, frame
)
11404 struct frame
*f
= XFRAME (frame
);
11406 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
11408 if (! EQ (frame
, selected_frame
))
11409 /* Select the frame, for the sake of frame-local
11411 select_frame_for_redisplay (frame
);
11413 /* Mark all the scroll bars to be removed; we'll redeem
11414 the ones we want when we redisplay their windows. */
11415 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
11416 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
11418 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11419 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11421 /* Any scroll bars which redisplay_windows should have
11422 nuked should now go away. */
11423 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
11424 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
11426 /* If fonts changed, display again. */
11427 /* ??? rms: I suspect it is a mistake to jump all the way
11428 back to retry here. It should just retry this frame. */
11429 if (fonts_changed_p
)
11432 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11434 /* See if we have to hscroll. */
11435 if (!f
->already_hscrolled_p
)
11437 f
->already_hscrolled_p
= 1;
11438 if (hscroll_windows (f
->root_window
))
11442 /* Prevent various kinds of signals during display
11443 update. stdio is not robust about handling
11444 signals, which can cause an apparent I/O
11446 if (interrupt_input
)
11447 unrequest_sigio ();
11450 /* Update the display. */
11451 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11452 pause
|= update_frame (f
, 0, 0);
11453 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
11465 /* Do the mark_window_display_accurate after all windows have
11466 been redisplayed because this call resets flags in buffers
11467 which are needed for proper redisplay. */
11468 FOR_EACH_FRAME (tail
, frame
)
11470 struct frame
*f
= XFRAME (frame
);
11473 mark_window_display_accurate (f
->root_window
, 1);
11474 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
11475 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
11480 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11482 Lisp_Object mini_window
;
11483 struct frame
*mini_frame
;
11485 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11486 /* Use list_of_error, not Qerror, so that
11487 we catch only errors and don't run the debugger. */
11488 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11490 redisplay_window_error
);
11492 /* Compare desired and current matrices, perform output. */
11495 /* If fonts changed, display again. */
11496 if (fonts_changed_p
)
11499 /* Prevent various kinds of signals during display update.
11500 stdio is not robust about handling signals,
11501 which can cause an apparent I/O error. */
11502 if (interrupt_input
)
11503 unrequest_sigio ();
11506 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11508 if (hscroll_windows (selected_window
))
11511 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11512 pause
= update_frame (sf
, 0, 0);
11515 /* We may have called echo_area_display at the top of this
11516 function. If the echo area is on another frame, that may
11517 have put text on a frame other than the selected one, so the
11518 above call to update_frame would not have caught it. Catch
11520 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11521 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11523 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11525 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11526 pause
|= update_frame (mini_frame
, 0, 0);
11527 if (!pause
&& hscroll_windows (mini_window
))
11532 /* If display was paused because of pending input, make sure we do a
11533 thorough update the next time. */
11536 /* Prevent the optimization at the beginning of
11537 redisplay_internal that tries a single-line update of the
11538 line containing the cursor in the selected window. */
11539 CHARPOS (this_line_start_pos
) = 0;
11541 /* Let the overlay arrow be updated the next time. */
11542 update_overlay_arrows (0);
11544 /* If we pause after scrolling, some rows in the current
11545 matrices of some windows are not valid. */
11546 if (!WINDOW_FULL_WIDTH_P (w
)
11547 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11548 update_mode_lines
= 1;
11552 if (!consider_all_windows_p
)
11554 /* This has already been done above if
11555 consider_all_windows_p is set. */
11556 mark_window_display_accurate_1 (w
, 1);
11558 /* Say overlay arrows are up to date. */
11559 update_overlay_arrows (1);
11561 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
11562 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
11565 update_mode_lines
= 0;
11566 windows_or_buffers_changed
= 0;
11567 cursor_type_changed
= 0;
11570 /* Start SIGIO interrupts coming again. Having them off during the
11571 code above makes it less likely one will discard output, but not
11572 impossible, since there might be stuff in the system buffer here.
11573 But it is much hairier to try to do anything about that. */
11574 if (interrupt_input
)
11578 /* If a frame has become visible which was not before, redisplay
11579 again, so that we display it. Expose events for such a frame
11580 (which it gets when becoming visible) don't call the parts of
11581 redisplay constructing glyphs, so simply exposing a frame won't
11582 display anything in this case. So, we have to display these
11583 frames here explicitly. */
11586 Lisp_Object tail
, frame
;
11589 FOR_EACH_FRAME (tail
, frame
)
11591 int this_is_visible
= 0;
11593 if (XFRAME (frame
)->visible
)
11594 this_is_visible
= 1;
11595 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11596 if (XFRAME (frame
)->visible
)
11597 this_is_visible
= 1;
11599 if (this_is_visible
)
11603 if (new_count
!= number_of_visible_frames
)
11604 windows_or_buffers_changed
++;
11607 /* Change frame size now if a change is pending. */
11608 do_pending_window_change (1);
11610 /* If we just did a pending size change, or have additional
11611 visible frames, redisplay again. */
11612 if (windows_or_buffers_changed
&& !pause
)
11615 /* Clear the face cache eventually. */
11616 if (consider_all_windows_p
)
11618 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11620 clear_face_cache (0);
11621 clear_face_cache_count
= 0;
11623 #ifdef HAVE_WINDOW_SYSTEM
11624 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11626 Lisp_Object tail
, frame
;
11627 FOR_EACH_FRAME (tail
, frame
)
11629 struct frame
*f
= XFRAME (frame
);
11630 if (FRAME_WINDOW_P (f
))
11631 clear_image_cache (f
, 0);
11633 clear_image_cache_count
= 0;
11635 #endif /* HAVE_WINDOW_SYSTEM */
11639 unbind_to (count
, Qnil
);
11644 /* Redisplay, but leave alone any recent echo area message unless
11645 another message has been requested in its place.
11647 This is useful in situations where you need to redisplay but no
11648 user action has occurred, making it inappropriate for the message
11649 area to be cleared. See tracking_off and
11650 wait_reading_process_output for examples of these situations.
11652 FROM_WHERE is an integer saying from where this function was
11653 called. This is useful for debugging. */
11656 redisplay_preserve_echo_area (from_where
)
11659 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
11661 if (!NILP (echo_area_buffer
[1]))
11663 /* We have a previously displayed message, but no current
11664 message. Redisplay the previous message. */
11665 display_last_displayed_message_p
= 1;
11666 redisplay_internal (1);
11667 display_last_displayed_message_p
= 0;
11670 redisplay_internal (1);
11672 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
11673 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11674 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
11678 /* Function registered with record_unwind_protect in
11679 redisplay_internal. Reset redisplaying_p to the value it had
11680 before redisplay_internal was called, and clear
11681 prevent_freeing_realized_faces_p. It also selects the previously
11682 selected frame, unless it has been deleted (by an X connection
11683 failure during redisplay, for example). */
11686 unwind_redisplay (val
)
11689 Lisp_Object old_redisplaying_p
, old_frame
;
11691 old_redisplaying_p
= XCAR (val
);
11692 redisplaying_p
= XFASTINT (old_redisplaying_p
);
11693 old_frame
= XCDR (val
);
11694 if (! EQ (old_frame
, selected_frame
)
11695 && FRAME_LIVE_P (XFRAME (old_frame
)))
11696 select_frame_for_redisplay (old_frame
);
11701 /* Mark the display of window W as accurate or inaccurate. If
11702 ACCURATE_P is non-zero mark display of W as accurate. If
11703 ACCURATE_P is zero, arrange for W to be redisplayed the next time
11704 redisplay_internal is called. */
11707 mark_window_display_accurate_1 (w
, accurate_p
)
11711 if (BUFFERP (w
->buffer
))
11713 struct buffer
*b
= XBUFFER (w
->buffer
);
11716 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
11717 w
->last_overlay_modified
11718 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
11720 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
11724 b
->clip_changed
= 0;
11725 b
->prevent_redisplay_optimizations_p
= 0;
11727 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
11728 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
11729 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
11730 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
11732 w
->current_matrix
->buffer
= b
;
11733 w
->current_matrix
->begv
= BUF_BEGV (b
);
11734 w
->current_matrix
->zv
= BUF_ZV (b
);
11736 w
->last_cursor
= w
->cursor
;
11737 w
->last_cursor_off_p
= w
->cursor_off_p
;
11739 if (w
== XWINDOW (selected_window
))
11740 w
->last_point
= make_number (BUF_PT (b
));
11742 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
11748 w
->window_end_valid
= w
->buffer
;
11749 #if 0 /* This is incorrect with variable-height lines. */
11750 xassert (XINT (w
->window_end_vpos
)
11751 < (WINDOW_TOTAL_LINES (w
)
11752 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
11754 w
->update_mode_line
= Qnil
;
11759 /* Mark the display of windows in the window tree rooted at WINDOW as
11760 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
11761 windows as accurate. If ACCURATE_P is zero, arrange for windows to
11762 be redisplayed the next time redisplay_internal is called. */
11765 mark_window_display_accurate (window
, accurate_p
)
11766 Lisp_Object window
;
11771 for (; !NILP (window
); window
= w
->next
)
11773 w
= XWINDOW (window
);
11774 mark_window_display_accurate_1 (w
, accurate_p
);
11776 if (!NILP (w
->vchild
))
11777 mark_window_display_accurate (w
->vchild
, accurate_p
);
11778 if (!NILP (w
->hchild
))
11779 mark_window_display_accurate (w
->hchild
, accurate_p
);
11784 update_overlay_arrows (1);
11788 /* Force a thorough redisplay the next time by setting
11789 last_arrow_position and last_arrow_string to t, which is
11790 unequal to any useful value of Voverlay_arrow_... */
11791 update_overlay_arrows (-1);
11796 /* Return value in display table DP (Lisp_Char_Table *) for character
11797 C. Since a display table doesn't have any parent, we don't have to
11798 follow parent. Do not call this function directly but use the
11799 macro DISP_CHAR_VECTOR. */
11802 disp_char_vector (dp
, c
)
11803 struct Lisp_Char_Table
*dp
;
11809 if (SINGLE_BYTE_CHAR_P (c
))
11810 return (dp
->contents
[c
]);
11812 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
11815 else if (code
[2] < 32)
11818 /* Here, the possible range of code[0] (== charset ID) is
11819 128..max_charset. Since the top level char table contains data
11820 for multibyte characters after 256th element, we must increment
11821 code[0] by 128 to get a correct index. */
11823 code
[3] = -1; /* anchor */
11825 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
11827 val
= dp
->contents
[code
[i
]];
11828 if (!SUB_CHAR_TABLE_P (val
))
11829 return (NILP (val
) ? dp
->defalt
: val
);
11832 /* Here, val is a sub char table. We return the default value of
11834 return (dp
->defalt
);
11839 /***********************************************************************
11841 ***********************************************************************/
11843 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11846 redisplay_windows (window
)
11847 Lisp_Object window
;
11849 while (!NILP (window
))
11851 struct window
*w
= XWINDOW (window
);
11853 if (!NILP (w
->hchild
))
11854 redisplay_windows (w
->hchild
);
11855 else if (!NILP (w
->vchild
))
11856 redisplay_windows (w
->vchild
);
11859 displayed_buffer
= XBUFFER (w
->buffer
);
11860 /* Use list_of_error, not Qerror, so that
11861 we catch only errors and don't run the debugger. */
11862 internal_condition_case_1 (redisplay_window_0
, window
,
11864 redisplay_window_error
);
11872 redisplay_window_error ()
11874 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11879 redisplay_window_0 (window
)
11880 Lisp_Object window
;
11882 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11883 redisplay_window (window
, 0);
11888 redisplay_window_1 (window
)
11889 Lisp_Object window
;
11891 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11892 redisplay_window (window
, 1);
11897 /* Increment GLYPH until it reaches END or CONDITION fails while
11898 adding (GLYPH)->pixel_width to X. */
11900 #define SKIP_GLYPHS(glyph, end, x, condition) \
11903 (x) += (glyph)->pixel_width; \
11906 while ((glyph) < (end) && (condition))
11909 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11910 DELTA is the number of bytes by which positions recorded in ROW
11911 differ from current buffer positions.
11913 Return 0 if cursor is not on this row. 1 otherwise. */
11916 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11918 struct glyph_row
*row
;
11919 struct glyph_matrix
*matrix
;
11920 int delta
, delta_bytes
, dy
, dvpos
;
11922 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11923 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11924 struct glyph
*cursor
= NULL
;
11925 /* The first glyph that starts a sequence of glyphs from string. */
11926 struct glyph
*string_start
;
11927 /* The X coordinate of string_start. */
11928 int string_start_x
;
11929 /* The last known character position. */
11930 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11931 /* The last known character position before string_start. */
11932 int string_before_pos
;
11935 int cursor_from_overlay_pos
= 0;
11936 int pt_old
= PT
- delta
;
11938 /* Skip over glyphs not having an object at the start of the row.
11939 These are special glyphs like truncation marks on terminal
11941 if (row
->displays_text_p
)
11943 && INTEGERP (glyph
->object
)
11944 && glyph
->charpos
< 0)
11946 x
+= glyph
->pixel_width
;
11950 string_start
= NULL
;
11952 && !INTEGERP (glyph
->object
)
11953 && (!BUFFERP (glyph
->object
)
11954 || (last_pos
= glyph
->charpos
) < pt_old
))
11956 if (! STRINGP (glyph
->object
))
11958 string_start
= NULL
;
11959 x
+= glyph
->pixel_width
;
11961 if (cursor_from_overlay_pos
11962 && last_pos
>= cursor_from_overlay_pos
)
11964 cursor_from_overlay_pos
= 0;
11970 if (string_start
== NULL
)
11972 string_before_pos
= last_pos
;
11973 string_start
= glyph
;
11974 string_start_x
= x
;
11976 /* Skip all glyphs from string. */
11981 if ((cursor
== NULL
|| glyph
> cursor
)
11982 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
11983 Qcursor
, (glyph
)->object
),
11985 && (pos
= string_buffer_position (w
, glyph
->object
,
11986 string_before_pos
),
11987 (pos
== 0 /* From overlay */
11988 || pos
== pt_old
)))
11990 /* Estimate overlay buffer position from the buffer
11991 positions of the glyphs before and after the overlay.
11992 Add 1 to last_pos so that if point corresponds to the
11993 glyph right after the overlay, we still use a 'cursor'
11994 property found in that overlay. */
11995 cursor_from_overlay_pos
= (pos
? 0 : last_pos
11996 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
12000 x
+= glyph
->pixel_width
;
12003 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
12007 if (cursor
!= NULL
)
12012 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
12014 /* Scan back over the ellipsis glyphs, decrementing positions. */
12015 while (glyph
> row
->glyphs
[TEXT_AREA
]
12016 && (glyph
- 1)->charpos
== last_pos
)
12017 glyph
--, x
-= glyph
->pixel_width
;
12018 /* That loop always goes one position too far,
12019 including the glyph before the ellipsis.
12020 So scan forward over that one. */
12021 x
+= glyph
->pixel_width
;
12024 else if (string_start
12025 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
12027 /* We may have skipped over point because the previous glyphs
12028 are from string. As there's no easy way to know the
12029 character position of the current glyph, find the correct
12030 glyph on point by scanning from string_start again. */
12032 Lisp_Object string
;
12033 struct glyph
*stop
= glyph
;
12036 limit
= make_number (pt_old
+ 1);
12037 glyph
= string_start
;
12038 x
= string_start_x
;
12039 string
= glyph
->object
;
12040 pos
= string_buffer_position (w
, string
, string_before_pos
);
12041 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
12042 because we always put cursor after overlay strings. */
12043 while (pos
== 0 && glyph
< stop
)
12045 string
= glyph
->object
;
12046 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12048 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
12051 while (glyph
< stop
)
12053 pos
= XINT (Fnext_single_char_property_change
12054 (make_number (pos
), Qdisplay
, Qnil
, limit
));
12057 /* Skip glyphs from the same string. */
12058 string
= glyph
->object
;
12059 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12060 /* Skip glyphs from an overlay. */
12061 while (glyph
< stop
12062 && ! string_buffer_position (w
, glyph
->object
, pos
))
12064 string
= glyph
->object
;
12065 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12069 /* If we reached the end of the line, and end was from a string,
12070 cursor is not on this line. */
12071 if (glyph
== end
&& row
->continued_p
)
12075 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12077 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12078 w
->cursor
.y
= row
->y
+ dy
;
12080 if (w
== XWINDOW (selected_window
))
12082 if (!row
->continued_p
12083 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12086 this_line_buffer
= XBUFFER (w
->buffer
);
12088 CHARPOS (this_line_start_pos
)
12089 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12090 BYTEPOS (this_line_start_pos
)
12091 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12093 CHARPOS (this_line_end_pos
)
12094 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12095 BYTEPOS (this_line_end_pos
)
12096 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12098 this_line_y
= w
->cursor
.y
;
12099 this_line_pixel_height
= row
->height
;
12100 this_line_vpos
= w
->cursor
.vpos
;
12101 this_line_start_x
= row
->x
;
12104 CHARPOS (this_line_start_pos
) = 0;
12111 /* Run window scroll functions, if any, for WINDOW with new window
12112 start STARTP. Sets the window start of WINDOW to that position.
12114 We assume that the window's buffer is really current. */
12116 static INLINE
struct text_pos
12117 run_window_scroll_functions (window
, startp
)
12118 Lisp_Object window
;
12119 struct text_pos startp
;
12121 struct window
*w
= XWINDOW (window
);
12122 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12124 if (current_buffer
!= XBUFFER (w
->buffer
))
12127 if (!NILP (Vwindow_scroll_functions
))
12129 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12130 make_number (CHARPOS (startp
)));
12131 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12132 /* In case the hook functions switch buffers. */
12133 if (current_buffer
!= XBUFFER (w
->buffer
))
12134 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12141 /* Make sure the line containing the cursor is fully visible.
12142 A value of 1 means there is nothing to be done.
12143 (Either the line is fully visible, or it cannot be made so,
12144 or we cannot tell.)
12146 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12147 is higher than window.
12149 A value of 0 means the caller should do scrolling
12150 as if point had gone off the screen. */
12153 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12156 int current_matrix_p
;
12158 struct glyph_matrix
*matrix
;
12159 struct glyph_row
*row
;
12162 if (!make_cursor_line_fully_visible_p
)
12165 /* It's not always possible to find the cursor, e.g, when a window
12166 is full of overlay strings. Don't do anything in that case. */
12167 if (w
->cursor
.vpos
< 0)
12170 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12171 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12173 /* If the cursor row is not partially visible, there's nothing to do. */
12174 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12177 /* If the row the cursor is in is taller than the window's height,
12178 it's not clear what to do, so do nothing. */
12179 window_height
= window_box_height (w
);
12180 if (row
->height
>= window_height
)
12182 if (!force_p
|| MINI_WINDOW_P (w
)
12183 || w
->vscroll
|| w
->cursor
.vpos
== 0)
12189 /* This code used to try to scroll the window just enough to make
12190 the line visible. It returned 0 to say that the caller should
12191 allocate larger glyph matrices. */
12193 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
12195 int dy
= row
->height
- row
->visible_height
;
12198 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12200 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
12202 int dy
= - (row
->height
- row
->visible_height
);
12205 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12208 /* When we change the cursor y-position of the selected window,
12209 change this_line_y as well so that the display optimization for
12210 the cursor line of the selected window in redisplay_internal uses
12211 the correct y-position. */
12212 if (w
== XWINDOW (selected_window
))
12213 this_line_y
= w
->cursor
.y
;
12215 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
12216 redisplay with larger matrices. */
12217 if (matrix
->nrows
< required_matrix_height (w
))
12219 fonts_changed_p
= 1;
12228 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
12229 non-zero means only WINDOW is redisplayed in redisplay_internal.
12230 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
12231 in redisplay_window to bring a partially visible line into view in
12232 the case that only the cursor has moved.
12234 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
12235 last screen line's vertical height extends past the end of the screen.
12239 1 if scrolling succeeded
12241 0 if scrolling didn't find point.
12243 -1 if new fonts have been loaded so that we must interrupt
12244 redisplay, adjust glyph matrices, and try again. */
12250 SCROLLING_NEED_LARGER_MATRICES
12254 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
12255 scroll_step
, temp_scroll_step
, last_line_misfit
)
12256 Lisp_Object window
;
12257 int just_this_one_p
;
12258 EMACS_INT scroll_conservatively
, scroll_step
;
12259 int temp_scroll_step
;
12260 int last_line_misfit
;
12262 struct window
*w
= XWINDOW (window
);
12263 struct frame
*f
= XFRAME (w
->frame
);
12264 struct text_pos scroll_margin_pos
;
12265 struct text_pos pos
;
12266 struct text_pos startp
;
12268 Lisp_Object window_end
;
12269 int this_scroll_margin
;
12273 int amount_to_scroll
= 0;
12274 Lisp_Object aggressive
;
12276 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
12279 debug_method_add (w
, "try_scrolling");
12282 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12284 /* Compute scroll margin height in pixels. We scroll when point is
12285 within this distance from the top or bottom of the window. */
12286 if (scroll_margin
> 0)
12288 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12289 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12292 this_scroll_margin
= 0;
12294 /* Force scroll_conservatively to have a reasonable value so it doesn't
12295 cause an overflow while computing how much to scroll. */
12296 if (scroll_conservatively
)
12297 scroll_conservatively
= min (scroll_conservatively
,
12298 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
12300 /* Compute how much we should try to scroll maximally to bring point
12302 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
12303 scroll_max
= max (scroll_step
,
12304 max (scroll_conservatively
, temp_scroll_step
));
12305 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
12306 || NUMBERP (current_buffer
->scroll_up_aggressively
))
12307 /* We're trying to scroll because of aggressive scrolling
12308 but no scroll_step is set. Choose an arbitrary one. Maybe
12309 there should be a variable for this. */
12313 scroll_max
*= FRAME_LINE_HEIGHT (f
);
12315 /* Decide whether we have to scroll down. Start at the window end
12316 and move this_scroll_margin up to find the position of the scroll
12318 window_end
= Fwindow_end (window
, Qt
);
12322 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
12323 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
12325 if (this_scroll_margin
|| extra_scroll_margin_lines
)
12327 start_display (&it
, w
, scroll_margin_pos
);
12328 if (this_scroll_margin
)
12329 move_it_vertically_backward (&it
, this_scroll_margin
);
12330 if (extra_scroll_margin_lines
)
12331 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
12332 scroll_margin_pos
= it
.current
.pos
;
12335 if (PT
>= CHARPOS (scroll_margin_pos
))
12339 /* Point is in the scroll margin at the bottom of the window, or
12340 below. Compute a new window start that makes point visible. */
12342 /* Compute the distance from the scroll margin to PT.
12343 Give up if the distance is greater than scroll_max. */
12344 start_display (&it
, w
, scroll_margin_pos
);
12346 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12347 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12349 /* To make point visible, we have to move the window start
12350 down so that the line the cursor is in is visible, which
12351 means we have to add in the height of the cursor line. */
12352 dy
= line_bottom_y (&it
) - y0
;
12354 if (dy
> scroll_max
)
12355 return SCROLLING_FAILED
;
12357 /* Move the window start down. If scrolling conservatively,
12358 move it just enough down to make point visible. If
12359 scroll_step is set, move it down by scroll_step. */
12360 start_display (&it
, w
, startp
);
12362 if (scroll_conservatively
)
12363 /* Set AMOUNT_TO_SCROLL to at least one line,
12364 and at most scroll_conservatively lines. */
12366 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12367 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12368 else if (scroll_step
|| temp_scroll_step
)
12369 amount_to_scroll
= scroll_max
;
12372 aggressive
= current_buffer
->scroll_up_aggressively
;
12373 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12374 if (NUMBERP (aggressive
))
12376 double float_amount
= XFLOATINT (aggressive
) * height
;
12377 amount_to_scroll
= float_amount
;
12378 if (amount_to_scroll
== 0 && float_amount
> 0)
12379 amount_to_scroll
= 1;
12383 if (amount_to_scroll
<= 0)
12384 return SCROLLING_FAILED
;
12386 /* If moving by amount_to_scroll leaves STARTP unchanged,
12387 move it down one screen line. */
12389 move_it_vertically (&it
, amount_to_scroll
);
12390 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12391 move_it_by_lines (&it
, 1, 1);
12392 startp
= it
.current
.pos
;
12396 /* See if point is inside the scroll margin at the top of the
12398 scroll_margin_pos
= startp
;
12399 if (this_scroll_margin
)
12401 start_display (&it
, w
, startp
);
12402 move_it_vertically (&it
, this_scroll_margin
);
12403 scroll_margin_pos
= it
.current
.pos
;
12406 if (PT
< CHARPOS (scroll_margin_pos
))
12408 /* Point is in the scroll margin at the top of the window or
12409 above what is displayed in the window. */
12412 /* Compute the vertical distance from PT to the scroll
12413 margin position. Give up if distance is greater than
12415 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12416 start_display (&it
, w
, pos
);
12418 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12419 it
.last_visible_y
, -1,
12420 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12421 dy
= it
.current_y
- y0
;
12422 if (dy
> scroll_max
)
12423 return SCROLLING_FAILED
;
12425 /* Compute new window start. */
12426 start_display (&it
, w
, startp
);
12428 if (scroll_conservatively
)
12430 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12431 else if (scroll_step
|| temp_scroll_step
)
12432 amount_to_scroll
= scroll_max
;
12435 aggressive
= current_buffer
->scroll_down_aggressively
;
12436 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12437 if (NUMBERP (aggressive
))
12439 double float_amount
= XFLOATINT (aggressive
) * height
;
12440 amount_to_scroll
= float_amount
;
12441 if (amount_to_scroll
== 0 && float_amount
> 0)
12442 amount_to_scroll
= 1;
12446 if (amount_to_scroll
<= 0)
12447 return SCROLLING_FAILED
;
12449 move_it_vertically_backward (&it
, amount_to_scroll
);
12450 startp
= it
.current
.pos
;
12454 /* Run window scroll functions. */
12455 startp
= run_window_scroll_functions (window
, startp
);
12457 /* Display the window. Give up if new fonts are loaded, or if point
12459 if (!try_window (window
, startp
, 0))
12460 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12461 else if (w
->cursor
.vpos
< 0)
12463 clear_glyph_matrix (w
->desired_matrix
);
12464 rc
= SCROLLING_FAILED
;
12468 /* Maybe forget recorded base line for line number display. */
12469 if (!just_this_one_p
12470 || current_buffer
->clip_changed
12471 || BEG_UNCHANGED
< CHARPOS (startp
))
12472 w
->base_line_number
= Qnil
;
12474 /* If cursor ends up on a partially visible line,
12475 treat that as being off the bottom of the screen. */
12476 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12478 clear_glyph_matrix (w
->desired_matrix
);
12479 ++extra_scroll_margin_lines
;
12482 rc
= SCROLLING_SUCCESS
;
12489 /* Compute a suitable window start for window W if display of W starts
12490 on a continuation line. Value is non-zero if a new window start
12493 The new window start will be computed, based on W's width, starting
12494 from the start of the continued line. It is the start of the
12495 screen line with the minimum distance from the old start W->start. */
12498 compute_window_start_on_continuation_line (w
)
12501 struct text_pos pos
, start_pos
;
12502 int window_start_changed_p
= 0;
12504 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12506 /* If window start is on a continuation line... Window start may be
12507 < BEGV in case there's invisible text at the start of the
12508 buffer (M-x rmail, for example). */
12509 if (CHARPOS (start_pos
) > BEGV
12510 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12513 struct glyph_row
*row
;
12515 /* Handle the case that the window start is out of range. */
12516 if (CHARPOS (start_pos
) < BEGV
)
12517 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12518 else if (CHARPOS (start_pos
) > ZV
)
12519 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12521 /* Find the start of the continued line. This should be fast
12522 because scan_buffer is fast (newline cache). */
12523 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12524 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12525 row
, DEFAULT_FACE_ID
);
12526 reseat_at_previous_visible_line_start (&it
);
12528 /* If the line start is "too far" away from the window start,
12529 say it takes too much time to compute a new window start. */
12530 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12531 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12533 int min_distance
, distance
;
12535 /* Move forward by display lines to find the new window
12536 start. If window width was enlarged, the new start can
12537 be expected to be > the old start. If window width was
12538 decreased, the new window start will be < the old start.
12539 So, we're looking for the display line start with the
12540 minimum distance from the old window start. */
12541 pos
= it
.current
.pos
;
12542 min_distance
= INFINITY
;
12543 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12544 distance
< min_distance
)
12546 min_distance
= distance
;
12547 pos
= it
.current
.pos
;
12548 move_it_by_lines (&it
, 1, 0);
12551 /* Set the window start there. */
12552 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12553 window_start_changed_p
= 1;
12557 return window_start_changed_p
;
12561 /* Try cursor movement in case text has not changed in window WINDOW,
12562 with window start STARTP. Value is
12564 CURSOR_MOVEMENT_SUCCESS if successful
12566 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12568 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12569 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12570 we want to scroll as if scroll-step were set to 1. See the code.
12572 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12573 which case we have to abort this redisplay, and adjust matrices
12578 CURSOR_MOVEMENT_SUCCESS
,
12579 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12580 CURSOR_MOVEMENT_MUST_SCROLL
,
12581 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12585 try_cursor_movement (window
, startp
, scroll_step
)
12586 Lisp_Object window
;
12587 struct text_pos startp
;
12590 struct window
*w
= XWINDOW (window
);
12591 struct frame
*f
= XFRAME (w
->frame
);
12592 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12595 if (inhibit_try_cursor_movement
)
12599 /* Handle case where text has not changed, only point, and it has
12600 not moved off the frame. */
12601 if (/* Point may be in this window. */
12602 PT
>= CHARPOS (startp
)
12603 /* Selective display hasn't changed. */
12604 && !current_buffer
->clip_changed
12605 /* Function force-mode-line-update is used to force a thorough
12606 redisplay. It sets either windows_or_buffers_changed or
12607 update_mode_lines. So don't take a shortcut here for these
12609 && !update_mode_lines
12610 && !windows_or_buffers_changed
12611 && !cursor_type_changed
12612 /* Can't use this case if highlighting a region. When a
12613 region exists, cursor movement has to do more than just
12615 && !(!NILP (Vtransient_mark_mode
)
12616 && !NILP (current_buffer
->mark_active
))
12617 && NILP (w
->region_showing
)
12618 && NILP (Vshow_trailing_whitespace
)
12619 /* Right after splitting windows, last_point may be nil. */
12620 && INTEGERP (w
->last_point
)
12621 /* This code is not used for mini-buffer for the sake of the case
12622 of redisplaying to replace an echo area message; since in
12623 that case the mini-buffer contents per se are usually
12624 unchanged. This code is of no real use in the mini-buffer
12625 since the handling of this_line_start_pos, etc., in redisplay
12626 handles the same cases. */
12627 && !EQ (window
, minibuf_window
)
12628 /* When splitting windows or for new windows, it happens that
12629 redisplay is called with a nil window_end_vpos or one being
12630 larger than the window. This should really be fixed in
12631 window.c. I don't have this on my list, now, so we do
12632 approximately the same as the old redisplay code. --gerd. */
12633 && INTEGERP (w
->window_end_vpos
)
12634 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12635 && (FRAME_WINDOW_P (f
)
12636 || !overlay_arrow_in_current_buffer_p ()))
12638 int this_scroll_margin
, top_scroll_margin
;
12639 struct glyph_row
*row
= NULL
;
12642 debug_method_add (w
, "cursor movement");
12645 /* Scroll if point within this distance from the top or bottom
12646 of the window. This is a pixel value. */
12647 this_scroll_margin
= max (0, scroll_margin
);
12648 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12649 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12651 top_scroll_margin
= this_scroll_margin
;
12652 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12653 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12655 /* Start with the row the cursor was displayed during the last
12656 not paused redisplay. Give up if that row is not valid. */
12657 if (w
->last_cursor
.vpos
< 0
12658 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12659 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12662 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12663 if (row
->mode_line_p
)
12665 if (!row
->enabled_p
)
12666 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12669 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12672 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12674 if (PT
> XFASTINT (w
->last_point
))
12676 /* Point has moved forward. */
12677 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12678 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12680 xassert (row
->enabled_p
);
12684 /* The end position of a row equals the start position
12685 of the next row. If PT is there, we would rather
12686 display it in the next line. */
12687 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12688 && MATRIX_ROW_END_CHARPOS (row
) == PT
12689 && !cursor_row_p (w
, row
))
12692 /* If within the scroll margin, scroll. Note that
12693 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
12694 the next line would be drawn, and that
12695 this_scroll_margin can be zero. */
12696 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
12697 || PT
> MATRIX_ROW_END_CHARPOS (row
)
12698 /* Line is completely visible last line in window
12699 and PT is to be set in the next line. */
12700 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
12701 && PT
== MATRIX_ROW_END_CHARPOS (row
)
12702 && !row
->ends_at_zv_p
12703 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12706 else if (PT
< XFASTINT (w
->last_point
))
12708 /* Cursor has to be moved backward. Note that PT >=
12709 CHARPOS (startp) because of the outer if-statement. */
12710 while (!row
->mode_line_p
12711 && (MATRIX_ROW_START_CHARPOS (row
) > PT
12712 || (MATRIX_ROW_START_CHARPOS (row
) == PT
12713 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
12714 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
12715 row
> w
->current_matrix
->rows
12716 && (row
-1)->ends_in_newline_from_string_p
))))
12717 && (row
->y
> top_scroll_margin
12718 || CHARPOS (startp
) == BEGV
))
12720 xassert (row
->enabled_p
);
12724 /* Consider the following case: Window starts at BEGV,
12725 there is invisible, intangible text at BEGV, so that
12726 display starts at some point START > BEGV. It can
12727 happen that we are called with PT somewhere between
12728 BEGV and START. Try to handle that case. */
12729 if (row
< w
->current_matrix
->rows
12730 || row
->mode_line_p
)
12732 row
= w
->current_matrix
->rows
;
12733 if (row
->mode_line_p
)
12737 /* Due to newlines in overlay strings, we may have to
12738 skip forward over overlay strings. */
12739 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12740 && MATRIX_ROW_END_CHARPOS (row
) == PT
12741 && !cursor_row_p (w
, row
))
12744 /* If within the scroll margin, scroll. */
12745 if (row
->y
< top_scroll_margin
12746 && CHARPOS (startp
) != BEGV
)
12751 /* Cursor did not move. So don't scroll even if cursor line
12752 is partially visible, as it was so before. */
12753 rc
= CURSOR_MOVEMENT_SUCCESS
;
12756 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
12757 || PT
> MATRIX_ROW_END_CHARPOS (row
))
12759 /* if PT is not in the glyph row, give up. */
12760 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12762 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
12763 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
12764 && make_cursor_line_fully_visible_p
)
12766 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
12767 && !row
->ends_at_zv_p
12768 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12769 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12770 else if (row
->height
> window_box_height (w
))
12772 /* If we end up in a partially visible line, let's
12773 make it fully visible, except when it's taller
12774 than the window, in which case we can't do much
12777 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12781 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12782 if (!cursor_row_fully_visible_p (w
, 0, 1))
12783 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12785 rc
= CURSOR_MOVEMENT_SUCCESS
;
12789 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12794 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
12796 rc
= CURSOR_MOVEMENT_SUCCESS
;
12801 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12802 && MATRIX_ROW_START_CHARPOS (row
) == PT
12803 && cursor_row_p (w
, row
));
12812 set_vertical_scroll_bar (w
)
12815 int start
, end
, whole
;
12817 /* Calculate the start and end positions for the current window.
12818 At some point, it would be nice to choose between scrollbars
12819 which reflect the whole buffer size, with special markers
12820 indicating narrowing, and scrollbars which reflect only the
12823 Note that mini-buffers sometimes aren't displaying any text. */
12824 if (!MINI_WINDOW_P (w
)
12825 || (w
== XWINDOW (minibuf_window
)
12826 && NILP (echo_area_buffer
[0])))
12828 struct buffer
*buf
= XBUFFER (w
->buffer
);
12829 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12830 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12831 /* I don't think this is guaranteed to be right. For the
12832 moment, we'll pretend it is. */
12833 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12837 if (whole
< (end
- start
))
12838 whole
= end
- start
;
12841 start
= end
= whole
= 0;
12843 /* Indicate what this scroll bar ought to be displaying now. */
12844 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
12845 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
12846 (w
, end
- start
, whole
, start
);
12850 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
12851 selected_window is redisplayed.
12853 We can return without actually redisplaying the window if
12854 fonts_changed_p is nonzero. In that case, redisplay_internal will
12858 redisplay_window (window
, just_this_one_p
)
12859 Lisp_Object window
;
12860 int just_this_one_p
;
12862 struct window
*w
= XWINDOW (window
);
12863 struct frame
*f
= XFRAME (w
->frame
);
12864 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12865 struct buffer
*old
= current_buffer
;
12866 struct text_pos lpoint
, opoint
, startp
;
12867 int update_mode_line
;
12870 /* Record it now because it's overwritten. */
12871 int current_matrix_up_to_date_p
= 0;
12872 int used_current_matrix_p
= 0;
12873 /* This is less strict than current_matrix_up_to_date_p.
12874 It indictes that the buffer contents and narrowing are unchanged. */
12875 int buffer_unchanged_p
= 0;
12876 int temp_scroll_step
= 0;
12877 int count
= SPECPDL_INDEX ();
12879 int centering_position
= -1;
12880 int last_line_misfit
= 0;
12881 int beg_unchanged
, end_unchanged
;
12883 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12886 /* W must be a leaf window here. */
12887 xassert (!NILP (w
->buffer
));
12889 *w
->desired_matrix
->method
= 0;
12892 specbind (Qinhibit_point_motion_hooks
, Qt
);
12894 reconsider_clip_changes (w
, buffer
);
12896 /* Has the mode line to be updated? */
12897 update_mode_line
= (!NILP (w
->update_mode_line
)
12898 || update_mode_lines
12899 || buffer
->clip_changed
12900 || buffer
->prevent_redisplay_optimizations_p
);
12902 if (MINI_WINDOW_P (w
))
12904 if (w
== XWINDOW (echo_area_window
)
12905 && !NILP (echo_area_buffer
[0]))
12907 if (update_mode_line
)
12908 /* We may have to update a tty frame's menu bar or a
12909 tool-bar. Example `M-x C-h C-h C-g'. */
12910 goto finish_menu_bars
;
12912 /* We've already displayed the echo area glyphs in this window. */
12913 goto finish_scroll_bars
;
12915 else if ((w
!= XWINDOW (minibuf_window
)
12916 || minibuf_level
== 0)
12917 /* When buffer is nonempty, redisplay window normally. */
12918 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12919 /* Quail displays non-mini buffers in minibuffer window.
12920 In that case, redisplay the window normally. */
12921 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12923 /* W is a mini-buffer window, but it's not active, so clear
12925 int yb
= window_text_bottom_y (w
);
12926 struct glyph_row
*row
;
12929 for (y
= 0, row
= w
->desired_matrix
->rows
;
12931 y
+= row
->height
, ++row
)
12932 blank_row (w
, row
, y
);
12933 goto finish_scroll_bars
;
12936 clear_glyph_matrix (w
->desired_matrix
);
12939 /* Otherwise set up data on this window; select its buffer and point
12941 /* Really select the buffer, for the sake of buffer-local
12943 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12944 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12946 beg_unchanged
= BEG_UNCHANGED
;
12947 end_unchanged
= END_UNCHANGED
;
12949 current_matrix_up_to_date_p
12950 = (!NILP (w
->window_end_valid
)
12951 && !current_buffer
->clip_changed
12952 && !current_buffer
->prevent_redisplay_optimizations_p
12953 && XFASTINT (w
->last_modified
) >= MODIFF
12954 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12957 = (!NILP (w
->window_end_valid
)
12958 && !current_buffer
->clip_changed
12959 && XFASTINT (w
->last_modified
) >= MODIFF
12960 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12962 /* When windows_or_buffers_changed is non-zero, we can't rely on
12963 the window end being valid, so set it to nil there. */
12964 if (windows_or_buffers_changed
)
12966 /* If window starts on a continuation line, maybe adjust the
12967 window start in case the window's width changed. */
12968 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12969 compute_window_start_on_continuation_line (w
);
12971 w
->window_end_valid
= Qnil
;
12974 /* Some sanity checks. */
12975 CHECK_WINDOW_END (w
);
12976 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12978 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12981 /* If %c is in mode line, update it if needed. */
12982 if (!NILP (w
->column_number_displayed
)
12983 /* This alternative quickly identifies a common case
12984 where no change is needed. */
12985 && !(PT
== XFASTINT (w
->last_point
)
12986 && XFASTINT (w
->last_modified
) >= MODIFF
12987 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12988 && (XFASTINT (w
->column_number_displayed
)
12989 != (int) current_column ())) /* iftc */
12990 update_mode_line
= 1;
12992 /* Count number of windows showing the selected buffer. An indirect
12993 buffer counts as its base buffer. */
12994 if (!just_this_one_p
)
12996 struct buffer
*current_base
, *window_base
;
12997 current_base
= current_buffer
;
12998 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12999 if (current_base
->base_buffer
)
13000 current_base
= current_base
->base_buffer
;
13001 if (window_base
->base_buffer
)
13002 window_base
= window_base
->base_buffer
;
13003 if (current_base
== window_base
)
13007 /* Point refers normally to the selected window. For any other
13008 window, set up appropriate value. */
13009 if (!EQ (window
, selected_window
))
13011 int new_pt
= XMARKER (w
->pointm
)->charpos
;
13012 int new_pt_byte
= marker_byte_position (w
->pointm
);
13016 new_pt_byte
= BEGV_BYTE
;
13017 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13019 else if (new_pt
> (ZV
- 1))
13022 new_pt_byte
= ZV_BYTE
;
13023 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13026 /* We don't use SET_PT so that the point-motion hooks don't run. */
13027 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
13030 /* If any of the character widths specified in the display table
13031 have changed, invalidate the width run cache. It's true that
13032 this may be a bit late to catch such changes, but the rest of
13033 redisplay goes (non-fatally) haywire when the display table is
13034 changed, so why should we worry about doing any better? */
13035 if (current_buffer
->width_run_cache
)
13037 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
13039 if (! disptab_matches_widthtab (disptab
,
13040 XVECTOR (current_buffer
->width_table
)))
13042 invalidate_region_cache (current_buffer
,
13043 current_buffer
->width_run_cache
,
13045 recompute_width_table (current_buffer
, disptab
);
13049 /* If window-start is screwed up, choose a new one. */
13050 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
13053 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13055 /* If someone specified a new starting point but did not insist,
13056 check whether it can be used. */
13057 if (!NILP (w
->optional_new_start
)
13058 && CHARPOS (startp
) >= BEGV
13059 && CHARPOS (startp
) <= ZV
)
13061 w
->optional_new_start
= Qnil
;
13062 start_display (&it
, w
, startp
);
13063 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
13064 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13065 if (IT_CHARPOS (it
) == PT
)
13066 w
->force_start
= Qt
;
13067 /* IT may overshoot PT if text at PT is invisible. */
13068 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
13069 w
->force_start
= Qt
;
13074 /* Handle case where place to start displaying has been specified,
13075 unless the specified location is outside the accessible range. */
13076 if (!NILP (w
->force_start
)
13077 || w
->frozen_window_start_p
)
13079 /* We set this later on if we have to adjust point. */
13083 w
->force_start
= Qnil
;
13085 w
->window_end_valid
= Qnil
;
13087 /* Forget any recorded base line for line number display. */
13088 if (!buffer_unchanged_p
)
13089 w
->base_line_number
= Qnil
;
13091 /* Redisplay the mode line. Select the buffer properly for that.
13092 Also, run the hook window-scroll-functions
13093 because we have scrolled. */
13094 /* Note, we do this after clearing force_start because
13095 if there's an error, it is better to forget about force_start
13096 than to get into an infinite loop calling the hook functions
13097 and having them get more errors. */
13098 if (!update_mode_line
13099 || ! NILP (Vwindow_scroll_functions
))
13101 update_mode_line
= 1;
13102 w
->update_mode_line
= Qt
;
13103 startp
= run_window_scroll_functions (window
, startp
);
13106 w
->last_modified
= make_number (0);
13107 w
->last_overlay_modified
= make_number (0);
13108 if (CHARPOS (startp
) < BEGV
)
13109 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
13110 else if (CHARPOS (startp
) > ZV
)
13111 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
13113 /* Redisplay, then check if cursor has been set during the
13114 redisplay. Give up if new fonts were loaded. */
13115 val
= try_window (window
, startp
, 1);
13118 w
->force_start
= Qt
;
13119 clear_glyph_matrix (w
->desired_matrix
);
13120 goto need_larger_matrices
;
13122 /* Point was outside the scroll margins. */
13124 new_vpos
= window_box_height (w
) / 2;
13126 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
13128 /* If point does not appear, try to move point so it does
13129 appear. The desired matrix has been built above, so we
13130 can use it here. */
13131 new_vpos
= window_box_height (w
) / 2;
13134 if (!cursor_row_fully_visible_p (w
, 0, 0))
13136 /* Point does appear, but on a line partly visible at end of window.
13137 Move it back to a fully-visible line. */
13138 new_vpos
= window_box_height (w
);
13141 /* If we need to move point for either of the above reasons,
13142 now actually do it. */
13145 struct glyph_row
*row
;
13147 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13148 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13151 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13152 MATRIX_ROW_START_BYTEPOS (row
));
13154 if (w
!= XWINDOW (selected_window
))
13155 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13156 else if (current_buffer
== old
)
13157 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13159 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13161 /* If we are highlighting the region, then we just changed
13162 the region, so redisplay to show it. */
13163 if (!NILP (Vtransient_mark_mode
)
13164 && !NILP (current_buffer
->mark_active
))
13166 clear_glyph_matrix (w
->desired_matrix
);
13167 if (!try_window (window
, startp
, 0))
13168 goto need_larger_matrices
;
13173 debug_method_add (w
, "forced window start");
13178 /* Handle case where text has not changed, only point, and it has
13179 not moved off the frame, and we are not retrying after hscroll.
13180 (current_matrix_up_to_date_p is nonzero when retrying.) */
13181 if (current_matrix_up_to_date_p
13182 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13183 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13187 case CURSOR_MOVEMENT_SUCCESS
:
13188 used_current_matrix_p
= 1;
13191 #if 0 /* try_cursor_movement never returns this value. */
13192 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
13193 goto need_larger_matrices
;
13196 case CURSOR_MOVEMENT_MUST_SCROLL
:
13197 goto try_to_scroll
;
13203 /* If current starting point was originally the beginning of a line
13204 but no longer is, find a new starting point. */
13205 else if (!NILP (w
->start_at_line_beg
)
13206 && !(CHARPOS (startp
) <= BEGV
13207 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13210 debug_method_add (w
, "recenter 1");
13215 /* Try scrolling with try_window_id. Value is > 0 if update has
13216 been done, it is -1 if we know that the same window start will
13217 not work. It is 0 if unsuccessful for some other reason. */
13218 else if ((tem
= try_window_id (w
)) != 0)
13221 debug_method_add (w
, "try_window_id %d", tem
);
13224 if (fonts_changed_p
)
13225 goto need_larger_matrices
;
13229 /* Otherwise try_window_id has returned -1 which means that we
13230 don't want the alternative below this comment to execute. */
13232 else if (CHARPOS (startp
) >= BEGV
13233 && CHARPOS (startp
) <= ZV
13234 && PT
>= CHARPOS (startp
)
13235 && (CHARPOS (startp
) < ZV
13236 /* Avoid starting at end of buffer. */
13237 || CHARPOS (startp
) == BEGV
13238 || (XFASTINT (w
->last_modified
) >= MODIFF
13239 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
13242 /* If first window line is a continuation line, and window start
13243 is inside the modified region, but the first change is before
13244 current window start, we must select a new window start.
13246 However, if this is the result of a down-mouse event (e.g. by
13247 extending the mouse-drag-overlay), we don't want to select a
13248 new window start, since that would change the position under
13249 the mouse, resulting in an unwanted mouse-movement rather
13250 than a simple mouse-click. */
13251 if (NILP (w
->start_at_line_beg
)
13252 && NILP (do_mouse_tracking
)
13253 && CHARPOS (startp
) > BEGV
13254 && CHARPOS (startp
) > BEG
+ beg_unchanged
13255 && CHARPOS (startp
) <= Z
- end_unchanged
)
13257 w
->force_start
= Qt
;
13258 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13259 compute_window_start_on_continuation_line (w
);
13260 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13265 debug_method_add (w
, "same window start");
13268 /* Try to redisplay starting at same place as before.
13269 If point has not moved off frame, accept the results. */
13270 if (!current_matrix_up_to_date_p
13271 /* Don't use try_window_reusing_current_matrix in this case
13272 because a window scroll function can have changed the
13274 || !NILP (Vwindow_scroll_functions
)
13275 || MINI_WINDOW_P (w
)
13276 || !(used_current_matrix_p
13277 = try_window_reusing_current_matrix (w
)))
13279 IF_DEBUG (debug_method_add (w
, "1"));
13280 if (try_window (window
, startp
, 1) < 0)
13281 /* -1 means we need to scroll.
13282 0 means we need new matrices, but fonts_changed_p
13283 is set in that case, so we will detect it below. */
13284 goto try_to_scroll
;
13287 if (fonts_changed_p
)
13288 goto need_larger_matrices
;
13290 if (w
->cursor
.vpos
>= 0)
13292 if (!just_this_one_p
13293 || current_buffer
->clip_changed
13294 || BEG_UNCHANGED
< CHARPOS (startp
))
13295 /* Forget any recorded base line for line number display. */
13296 w
->base_line_number
= Qnil
;
13298 if (!cursor_row_fully_visible_p (w
, 1, 0))
13300 clear_glyph_matrix (w
->desired_matrix
);
13301 last_line_misfit
= 1;
13303 /* Drop through and scroll. */
13308 clear_glyph_matrix (w
->desired_matrix
);
13313 w
->last_modified
= make_number (0);
13314 w
->last_overlay_modified
= make_number (0);
13316 /* Redisplay the mode line. Select the buffer properly for that. */
13317 if (!update_mode_line
)
13319 update_mode_line
= 1;
13320 w
->update_mode_line
= Qt
;
13323 /* Try to scroll by specified few lines. */
13324 if ((scroll_conservatively
13326 || temp_scroll_step
13327 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13328 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13329 && !current_buffer
->clip_changed
13330 && CHARPOS (startp
) >= BEGV
13331 && CHARPOS (startp
) <= ZV
)
13333 /* The function returns -1 if new fonts were loaded, 1 if
13334 successful, 0 if not successful. */
13335 int rc
= try_scrolling (window
, just_this_one_p
,
13336 scroll_conservatively
,
13338 temp_scroll_step
, last_line_misfit
);
13341 case SCROLLING_SUCCESS
:
13344 case SCROLLING_NEED_LARGER_MATRICES
:
13345 goto need_larger_matrices
;
13347 case SCROLLING_FAILED
:
13355 /* Finally, just choose place to start which centers point */
13358 if (centering_position
< 0)
13359 centering_position
= window_box_height (w
) / 2;
13362 debug_method_add (w
, "recenter");
13365 /* w->vscroll = 0; */
13367 /* Forget any previously recorded base line for line number display. */
13368 if (!buffer_unchanged_p
)
13369 w
->base_line_number
= Qnil
;
13371 /* Move backward half the height of the window. */
13372 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13373 it
.current_y
= it
.last_visible_y
;
13374 move_it_vertically_backward (&it
, centering_position
);
13375 xassert (IT_CHARPOS (it
) >= BEGV
);
13377 /* The function move_it_vertically_backward may move over more
13378 than the specified y-distance. If it->w is small, e.g. a
13379 mini-buffer window, we may end up in front of the window's
13380 display area. Start displaying at the start of the line
13381 containing PT in this case. */
13382 if (it
.current_y
<= 0)
13384 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13385 move_it_vertically_backward (&it
, 0);
13387 /* I think this assert is bogus if buffer contains
13388 invisible text or images. KFS. */
13389 xassert (IT_CHARPOS (it
) <= PT
);
13394 it
.current_x
= it
.hpos
= 0;
13396 /* Set startp here explicitly in case that helps avoid an infinite loop
13397 in case the window-scroll-functions functions get errors. */
13398 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13400 /* Run scroll hooks. */
13401 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13403 /* Redisplay the window. */
13404 if (!current_matrix_up_to_date_p
13405 || windows_or_buffers_changed
13406 || cursor_type_changed
13407 /* Don't use try_window_reusing_current_matrix in this case
13408 because it can have changed the buffer. */
13409 || !NILP (Vwindow_scroll_functions
)
13410 || !just_this_one_p
13411 || MINI_WINDOW_P (w
)
13412 || !(used_current_matrix_p
13413 = try_window_reusing_current_matrix (w
)))
13414 try_window (window
, startp
, 0);
13416 /* If new fonts have been loaded (due to fontsets), give up. We
13417 have to start a new redisplay since we need to re-adjust glyph
13419 if (fonts_changed_p
)
13420 goto need_larger_matrices
;
13422 /* If cursor did not appear assume that the middle of the window is
13423 in the first line of the window. Do it again with the next line.
13424 (Imagine a window of height 100, displaying two lines of height
13425 60. Moving back 50 from it->last_visible_y will end in the first
13427 if (w
->cursor
.vpos
< 0)
13429 if (!NILP (w
->window_end_valid
)
13430 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13432 clear_glyph_matrix (w
->desired_matrix
);
13433 move_it_by_lines (&it
, 1, 0);
13434 try_window (window
, it
.current
.pos
, 0);
13436 else if (PT
< IT_CHARPOS (it
))
13438 clear_glyph_matrix (w
->desired_matrix
);
13439 move_it_by_lines (&it
, -1, 0);
13440 try_window (window
, it
.current
.pos
, 0);
13444 /* Not much we can do about it. */
13448 /* Consider the following case: Window starts at BEGV, there is
13449 invisible, intangible text at BEGV, so that display starts at
13450 some point START > BEGV. It can happen that we are called with
13451 PT somewhere between BEGV and START. Try to handle that case. */
13452 if (w
->cursor
.vpos
< 0)
13454 struct glyph_row
*row
= w
->current_matrix
->rows
;
13455 if (row
->mode_line_p
)
13457 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13460 if (!cursor_row_fully_visible_p (w
, 0, 0))
13462 /* If vscroll is enabled, disable it and try again. */
13466 clear_glyph_matrix (w
->desired_matrix
);
13470 /* If centering point failed to make the whole line visible,
13471 put point at the top instead. That has to make the whole line
13472 visible, if it can be done. */
13473 if (centering_position
== 0)
13476 clear_glyph_matrix (w
->desired_matrix
);
13477 centering_position
= 0;
13483 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13484 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13485 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13488 /* Display the mode line, if we must. */
13489 if ((update_mode_line
13490 /* If window not full width, must redo its mode line
13491 if (a) the window to its side is being redone and
13492 (b) we do a frame-based redisplay. This is a consequence
13493 of how inverted lines are drawn in frame-based redisplay. */
13494 || (!just_this_one_p
13495 && !FRAME_WINDOW_P (f
)
13496 && !WINDOW_FULL_WIDTH_P (w
))
13497 /* Line number to display. */
13498 || INTEGERP (w
->base_line_pos
)
13499 /* Column number is displayed and different from the one displayed. */
13500 || (!NILP (w
->column_number_displayed
)
13501 && (XFASTINT (w
->column_number_displayed
)
13502 != (int) current_column ()))) /* iftc */
13503 /* This means that the window has a mode line. */
13504 && (WINDOW_WANTS_MODELINE_P (w
)
13505 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13507 display_mode_lines (w
);
13509 /* If mode line height has changed, arrange for a thorough
13510 immediate redisplay using the correct mode line height. */
13511 if (WINDOW_WANTS_MODELINE_P (w
)
13512 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13514 fonts_changed_p
= 1;
13515 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13516 = DESIRED_MODE_LINE_HEIGHT (w
);
13519 /* If top line height has changed, arrange for a thorough
13520 immediate redisplay using the correct mode line height. */
13521 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13522 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13524 fonts_changed_p
= 1;
13525 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13526 = DESIRED_HEADER_LINE_HEIGHT (w
);
13529 if (fonts_changed_p
)
13530 goto need_larger_matrices
;
13533 if (!line_number_displayed
13534 && !BUFFERP (w
->base_line_pos
))
13536 w
->base_line_pos
= Qnil
;
13537 w
->base_line_number
= Qnil
;
13542 /* When we reach a frame's selected window, redo the frame's menu bar. */
13543 if (update_mode_line
13544 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13546 int redisplay_menu_p
= 0;
13547 int redisplay_tool_bar_p
= 0;
13549 if (FRAME_WINDOW_P (f
))
13551 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
13552 || defined (USE_GTK)
13553 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13555 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13559 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13561 if (redisplay_menu_p
)
13562 display_menu_bar (w
);
13564 #ifdef HAVE_WINDOW_SYSTEM
13565 if (FRAME_WINDOW_P (f
))
13567 #if defined (USE_GTK) || USE_MAC_TOOLBAR
13568 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13570 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13571 && (FRAME_TOOL_BAR_LINES (f
) > 0
13572 || !NILP (Vauto_resize_tool_bars
));
13575 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
13577 extern int ignore_mouse_drag_p
;
13578 ignore_mouse_drag_p
= 1;
13584 #ifdef HAVE_WINDOW_SYSTEM
13585 if (FRAME_WINDOW_P (f
)
13586 && update_window_fringes (w
, (just_this_one_p
13587 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13588 || w
->pseudo_window_p
)))
13592 if (draw_window_fringes (w
, 1))
13593 x_draw_vertical_border (w
);
13597 #endif /* HAVE_WINDOW_SYSTEM */
13599 /* We go to this label, with fonts_changed_p nonzero,
13600 if it is necessary to try again using larger glyph matrices.
13601 We have to redeem the scroll bar even in this case,
13602 because the loop in redisplay_internal expects that. */
13603 need_larger_matrices
:
13605 finish_scroll_bars
:
13607 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13609 /* Set the thumb's position and size. */
13610 set_vertical_scroll_bar (w
);
13612 /* Note that we actually used the scroll bar attached to this
13613 window, so it shouldn't be deleted at the end of redisplay. */
13614 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
13615 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
13618 /* Restore current_buffer and value of point in it. */
13619 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13620 set_buffer_internal_1 (old
);
13621 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
13622 shorter. This can be caused by log truncation in *Messages*. */
13623 if (CHARPOS (lpoint
) <= ZV
)
13624 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13626 unbind_to (count
, Qnil
);
13630 /* Build the complete desired matrix of WINDOW with a window start
13631 buffer position POS.
13633 Value is 1 if successful. It is zero if fonts were loaded during
13634 redisplay which makes re-adjusting glyph matrices necessary, and -1
13635 if point would appear in the scroll margins.
13636 (We check that only if CHECK_MARGINS is nonzero. */
13639 try_window (window
, pos
, check_margins
)
13640 Lisp_Object window
;
13641 struct text_pos pos
;
13644 struct window
*w
= XWINDOW (window
);
13646 struct glyph_row
*last_text_row
= NULL
;
13647 struct frame
*f
= XFRAME (w
->frame
);
13649 /* Make POS the new window start. */
13650 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13652 /* Mark cursor position as unknown. No overlay arrow seen. */
13653 w
->cursor
.vpos
= -1;
13654 overlay_arrow_seen
= 0;
13656 /* Initialize iterator and info to start at POS. */
13657 start_display (&it
, w
, pos
);
13659 /* Display all lines of W. */
13660 while (it
.current_y
< it
.last_visible_y
)
13662 if (display_line (&it
))
13663 last_text_row
= it
.glyph_row
- 1;
13664 if (fonts_changed_p
)
13668 /* Don't let the cursor end in the scroll margins. */
13670 && !MINI_WINDOW_P (w
))
13672 int this_scroll_margin
;
13674 this_scroll_margin
= max (0, scroll_margin
);
13675 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13676 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13678 if ((w
->cursor
.y
>= 0 /* not vscrolled */
13679 && w
->cursor
.y
< this_scroll_margin
13680 && CHARPOS (pos
) > BEGV
13681 && IT_CHARPOS (it
) < ZV
)
13682 /* rms: considering make_cursor_line_fully_visible_p here
13683 seems to give wrong results. We don't want to recenter
13684 when the last line is partly visible, we want to allow
13685 that case to be handled in the usual way. */
13686 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
13688 w
->cursor
.vpos
= -1;
13689 clear_glyph_matrix (w
->desired_matrix
);
13694 /* If bottom moved off end of frame, change mode line percentage. */
13695 if (XFASTINT (w
->window_end_pos
) <= 0
13696 && Z
!= IT_CHARPOS (it
))
13697 w
->update_mode_line
= Qt
;
13699 /* Set window_end_pos to the offset of the last character displayed
13700 on the window from the end of current_buffer. Set
13701 window_end_vpos to its row number. */
13704 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
13705 w
->window_end_bytepos
13706 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13708 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13710 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13711 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
13712 ->displays_text_p
);
13716 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13717 w
->window_end_pos
= make_number (Z
- ZV
);
13718 w
->window_end_vpos
= make_number (0);
13721 /* But that is not valid info until redisplay finishes. */
13722 w
->window_end_valid
= Qnil
;
13728 /************************************************************************
13729 Window redisplay reusing current matrix when buffer has not changed
13730 ************************************************************************/
13732 /* Try redisplay of window W showing an unchanged buffer with a
13733 different window start than the last time it was displayed by
13734 reusing its current matrix. Value is non-zero if successful.
13735 W->start is the new window start. */
13738 try_window_reusing_current_matrix (w
)
13741 struct frame
*f
= XFRAME (w
->frame
);
13742 struct glyph_row
*row
, *bottom_row
;
13745 struct text_pos start
, new_start
;
13746 int nrows_scrolled
, i
;
13747 struct glyph_row
*last_text_row
;
13748 struct glyph_row
*last_reused_text_row
;
13749 struct glyph_row
*start_row
;
13750 int start_vpos
, min_y
, max_y
;
13753 if (inhibit_try_window_reusing
)
13757 if (/* This function doesn't handle terminal frames. */
13758 !FRAME_WINDOW_P (f
)
13759 /* Don't try to reuse the display if windows have been split
13761 || windows_or_buffers_changed
13762 || cursor_type_changed
)
13765 /* Can't do this if region may have changed. */
13766 if ((!NILP (Vtransient_mark_mode
)
13767 && !NILP (current_buffer
->mark_active
))
13768 || !NILP (w
->region_showing
)
13769 || !NILP (Vshow_trailing_whitespace
))
13772 /* If top-line visibility has changed, give up. */
13773 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13774 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
13777 /* Give up if old or new display is scrolled vertically. We could
13778 make this function handle this, but right now it doesn't. */
13779 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13780 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
13783 /* The variable new_start now holds the new window start. The old
13784 start `start' can be determined from the current matrix. */
13785 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
13786 start
= start_row
->start
.pos
;
13787 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13789 /* Clear the desired matrix for the display below. */
13790 clear_glyph_matrix (w
->desired_matrix
);
13792 if (CHARPOS (new_start
) <= CHARPOS (start
))
13796 /* Don't use this method if the display starts with an ellipsis
13797 displayed for invisible text. It's not easy to handle that case
13798 below, and it's certainly not worth the effort since this is
13799 not a frequent case. */
13800 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
13803 IF_DEBUG (debug_method_add (w
, "twu1"));
13805 /* Display up to a row that can be reused. The variable
13806 last_text_row is set to the last row displayed that displays
13807 text. Note that it.vpos == 0 if or if not there is a
13808 header-line; it's not the same as the MATRIX_ROW_VPOS! */
13809 start_display (&it
, w
, new_start
);
13810 first_row_y
= it
.current_y
;
13811 w
->cursor
.vpos
= -1;
13812 last_text_row
= last_reused_text_row
= NULL
;
13814 while (it
.current_y
< it
.last_visible_y
13815 && !fonts_changed_p
)
13817 /* If we have reached into the characters in the START row,
13818 that means the line boundaries have changed. So we
13819 can't start copying with the row START. Maybe it will
13820 work to start copying with the following row. */
13821 while (IT_CHARPOS (it
) > CHARPOS (start
))
13823 /* Advance to the next row as the "start". */
13825 start
= start_row
->start
.pos
;
13826 /* If there are no more rows to try, or just one, give up. */
13827 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
13828 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
13829 || CHARPOS (start
) == ZV
)
13831 clear_glyph_matrix (w
->desired_matrix
);
13835 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13837 /* If we have reached alignment,
13838 we can copy the rest of the rows. */
13839 if (IT_CHARPOS (it
) == CHARPOS (start
))
13842 if (display_line (&it
))
13843 last_text_row
= it
.glyph_row
- 1;
13846 /* A value of current_y < last_visible_y means that we stopped
13847 at the previous window start, which in turn means that we
13848 have at least one reusable row. */
13849 if (it
.current_y
< it
.last_visible_y
)
13851 /* IT.vpos always starts from 0; it counts text lines. */
13852 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
13854 /* Find PT if not already found in the lines displayed. */
13855 if (w
->cursor
.vpos
< 0)
13857 int dy
= it
.current_y
- start_row
->y
;
13859 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13860 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
13862 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
13863 dy
, nrows_scrolled
);
13866 clear_glyph_matrix (w
->desired_matrix
);
13871 /* Scroll the display. Do it before the current matrix is
13872 changed. The problem here is that update has not yet
13873 run, i.e. part of the current matrix is not up to date.
13874 scroll_run_hook will clear the cursor, and use the
13875 current matrix to get the height of the row the cursor is
13877 run
.current_y
= start_row
->y
;
13878 run
.desired_y
= it
.current_y
;
13879 run
.height
= it
.last_visible_y
- it
.current_y
;
13881 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
13884 FRAME_RIF (f
)->update_window_begin_hook (w
);
13885 FRAME_RIF (f
)->clear_window_mouse_face (w
);
13886 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
13887 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
13891 /* Shift current matrix down by nrows_scrolled lines. */
13892 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13893 rotate_matrix (w
->current_matrix
,
13895 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13898 /* Disable lines that must be updated. */
13899 for (i
= 0; i
< nrows_scrolled
; ++i
)
13900 (start_row
+ i
)->enabled_p
= 0;
13902 /* Re-compute Y positions. */
13903 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13904 max_y
= it
.last_visible_y
;
13905 for (row
= start_row
+ nrows_scrolled
;
13909 row
->y
= it
.current_y
;
13910 row
->visible_height
= row
->height
;
13912 if (row
->y
< min_y
)
13913 row
->visible_height
-= min_y
- row
->y
;
13914 if (row
->y
+ row
->height
> max_y
)
13915 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13916 row
->redraw_fringe_bitmaps_p
= 1;
13918 it
.current_y
+= row
->height
;
13920 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13921 last_reused_text_row
= row
;
13922 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13926 /* Disable lines in the current matrix which are now
13927 below the window. */
13928 for (++row
; row
< bottom_row
; ++row
)
13929 row
->enabled_p
= row
->mode_line_p
= 0;
13932 /* Update window_end_pos etc.; last_reused_text_row is the last
13933 reused row from the current matrix containing text, if any.
13934 The value of last_text_row is the last displayed line
13935 containing text. */
13936 if (last_reused_text_row
)
13938 w
->window_end_bytepos
13939 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13941 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13943 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13944 w
->current_matrix
));
13946 else if (last_text_row
)
13948 w
->window_end_bytepos
13949 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13951 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13953 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13957 /* This window must be completely empty. */
13958 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13959 w
->window_end_pos
= make_number (Z
- ZV
);
13960 w
->window_end_vpos
= make_number (0);
13962 w
->window_end_valid
= Qnil
;
13964 /* Update hint: don't try scrolling again in update_window. */
13965 w
->desired_matrix
->no_scrolling_p
= 1;
13968 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13972 else if (CHARPOS (new_start
) > CHARPOS (start
))
13974 struct glyph_row
*pt_row
, *row
;
13975 struct glyph_row
*first_reusable_row
;
13976 struct glyph_row
*first_row_to_display
;
13978 int yb
= window_text_bottom_y (w
);
13980 /* Find the row starting at new_start, if there is one. Don't
13981 reuse a partially visible line at the end. */
13982 first_reusable_row
= start_row
;
13983 while (first_reusable_row
->enabled_p
13984 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13985 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13986 < CHARPOS (new_start
)))
13987 ++first_reusable_row
;
13989 /* Give up if there is no row to reuse. */
13990 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13991 || !first_reusable_row
->enabled_p
13992 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13993 != CHARPOS (new_start
)))
13996 /* We can reuse fully visible rows beginning with
13997 first_reusable_row to the end of the window. Set
13998 first_row_to_display to the first row that cannot be reused.
13999 Set pt_row to the row containing point, if there is any. */
14001 for (first_row_to_display
= first_reusable_row
;
14002 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
14003 ++first_row_to_display
)
14005 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
14006 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
14007 pt_row
= first_row_to_display
;
14010 /* Start displaying at the start of first_row_to_display. */
14011 xassert (first_row_to_display
->y
< yb
);
14012 init_to_row_start (&it
, w
, first_row_to_display
);
14014 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
14016 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
14018 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
14019 + WINDOW_HEADER_LINE_HEIGHT (w
));
14021 /* Display lines beginning with first_row_to_display in the
14022 desired matrix. Set last_text_row to the last row displayed
14023 that displays text. */
14024 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
14025 if (pt_row
== NULL
)
14026 w
->cursor
.vpos
= -1;
14027 last_text_row
= NULL
;
14028 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
14029 if (display_line (&it
))
14030 last_text_row
= it
.glyph_row
- 1;
14032 /* Give up If point isn't in a row displayed or reused. */
14033 if (w
->cursor
.vpos
< 0)
14035 clear_glyph_matrix (w
->desired_matrix
);
14039 /* If point is in a reused row, adjust y and vpos of the cursor
14043 w
->cursor
.vpos
-= nrows_scrolled
;
14044 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
14047 /* Scroll the display. */
14048 run
.current_y
= first_reusable_row
->y
;
14049 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14050 run
.height
= it
.last_visible_y
- run
.current_y
;
14051 dy
= run
.current_y
- run
.desired_y
;
14056 FRAME_RIF (f
)->update_window_begin_hook (w
);
14057 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14058 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14059 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14063 /* Adjust Y positions of reused rows. */
14064 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14065 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14066 max_y
= it
.last_visible_y
;
14067 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
14070 row
->visible_height
= row
->height
;
14071 if (row
->y
< min_y
)
14072 row
->visible_height
-= min_y
- row
->y
;
14073 if (row
->y
+ row
->height
> max_y
)
14074 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14075 row
->redraw_fringe_bitmaps_p
= 1;
14078 /* Scroll the current matrix. */
14079 xassert (nrows_scrolled
> 0);
14080 rotate_matrix (w
->current_matrix
,
14082 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14085 /* Disable rows not reused. */
14086 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
14087 row
->enabled_p
= 0;
14089 /* Point may have moved to a different line, so we cannot assume that
14090 the previous cursor position is valid; locate the correct row. */
14093 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
14094 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
14098 w
->cursor
.y
= row
->y
;
14100 if (row
< bottom_row
)
14102 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14103 while (glyph
->charpos
< PT
)
14106 w
->cursor
.x
+= glyph
->pixel_width
;
14112 /* Adjust window end. A null value of last_text_row means that
14113 the window end is in reused rows which in turn means that
14114 only its vpos can have changed. */
14117 w
->window_end_bytepos
14118 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14120 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14122 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14127 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
14130 w
->window_end_valid
= Qnil
;
14131 w
->desired_matrix
->no_scrolling_p
= 1;
14134 debug_method_add (w
, "try_window_reusing_current_matrix 2");
14144 /************************************************************************
14145 Window redisplay reusing current matrix when buffer has changed
14146 ************************************************************************/
14148 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
14149 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
14151 static struct glyph_row
*
14152 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
14153 struct glyph_row
*));
14156 /* Return the last row in MATRIX displaying text. If row START is
14157 non-null, start searching with that row. IT gives the dimensions
14158 of the display. Value is null if matrix is empty; otherwise it is
14159 a pointer to the row found. */
14161 static struct glyph_row
*
14162 find_last_row_displaying_text (matrix
, it
, start
)
14163 struct glyph_matrix
*matrix
;
14165 struct glyph_row
*start
;
14167 struct glyph_row
*row
, *row_found
;
14169 /* Set row_found to the last row in IT->w's current matrix
14170 displaying text. The loop looks funny but think of partially
14173 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14174 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14176 xassert (row
->enabled_p
);
14178 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
14187 /* Return the last row in the current matrix of W that is not affected
14188 by changes at the start of current_buffer that occurred since W's
14189 current matrix was built. Value is null if no such row exists.
14191 BEG_UNCHANGED us the number of characters unchanged at the start of
14192 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
14193 first changed character in current_buffer. Characters at positions <
14194 BEG + BEG_UNCHANGED are at the same buffer positions as they were
14195 when the current matrix was built. */
14197 static struct glyph_row
*
14198 find_last_unchanged_at_beg_row (w
)
14201 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
14202 struct glyph_row
*row
;
14203 struct glyph_row
*row_found
= NULL
;
14204 int yb
= window_text_bottom_y (w
);
14206 /* Find the last row displaying unchanged text. */
14207 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14208 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14209 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
14211 if (/* If row ends before first_changed_pos, it is unchanged,
14212 except in some case. */
14213 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
14214 /* When row ends in ZV and we write at ZV it is not
14216 && !row
->ends_at_zv_p
14217 /* When first_changed_pos is the end of a continued line,
14218 row is not unchanged because it may be no longer
14220 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
14221 && (row
->continued_p
14222 || row
->exact_window_width_line_p
)))
14225 /* Stop if last visible row. */
14226 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
14236 /* Find the first glyph row in the current matrix of W that is not
14237 affected by changes at the end of current_buffer since the
14238 time W's current matrix was built.
14240 Return in *DELTA the number of chars by which buffer positions in
14241 unchanged text at the end of current_buffer must be adjusted.
14243 Return in *DELTA_BYTES the corresponding number of bytes.
14245 Value is null if no such row exists, i.e. all rows are affected by
14248 static struct glyph_row
*
14249 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
14251 int *delta
, *delta_bytes
;
14253 struct glyph_row
*row
;
14254 struct glyph_row
*row_found
= NULL
;
14256 *delta
= *delta_bytes
= 0;
14258 /* Display must not have been paused, otherwise the current matrix
14259 is not up to date. */
14260 if (NILP (w
->window_end_valid
))
14263 /* A value of window_end_pos >= END_UNCHANGED means that the window
14264 end is in the range of changed text. If so, there is no
14265 unchanged row at the end of W's current matrix. */
14266 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
14269 /* Set row to the last row in W's current matrix displaying text. */
14270 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14272 /* If matrix is entirely empty, no unchanged row exists. */
14273 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14275 /* The value of row is the last glyph row in the matrix having a
14276 meaningful buffer position in it. The end position of row
14277 corresponds to window_end_pos. This allows us to translate
14278 buffer positions in the current matrix to current buffer
14279 positions for characters not in changed text. */
14280 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14281 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14282 int last_unchanged_pos
, last_unchanged_pos_old
;
14283 struct glyph_row
*first_text_row
14284 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14286 *delta
= Z
- Z_old
;
14287 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14289 /* Set last_unchanged_pos to the buffer position of the last
14290 character in the buffer that has not been changed. Z is the
14291 index + 1 of the last character in current_buffer, i.e. by
14292 subtracting END_UNCHANGED we get the index of the last
14293 unchanged character, and we have to add BEG to get its buffer
14295 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
14296 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
14298 /* Search backward from ROW for a row displaying a line that
14299 starts at a minimum position >= last_unchanged_pos_old. */
14300 for (; row
> first_text_row
; --row
)
14302 /* This used to abort, but it can happen.
14303 It is ok to just stop the search instead here. KFS. */
14304 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14307 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
14312 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
14319 /* Make sure that glyph rows in the current matrix of window W
14320 reference the same glyph memory as corresponding rows in the
14321 frame's frame matrix. This function is called after scrolling W's
14322 current matrix on a terminal frame in try_window_id and
14323 try_window_reusing_current_matrix. */
14326 sync_frame_with_window_matrix_rows (w
)
14329 struct frame
*f
= XFRAME (w
->frame
);
14330 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
14332 /* Preconditions: W must be a leaf window and full-width. Its frame
14333 must have a frame matrix. */
14334 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
14335 xassert (WINDOW_FULL_WIDTH_P (w
));
14336 xassert (!FRAME_WINDOW_P (f
));
14338 /* If W is a full-width window, glyph pointers in W's current matrix
14339 have, by definition, to be the same as glyph pointers in the
14340 corresponding frame matrix. Note that frame matrices have no
14341 marginal areas (see build_frame_matrix). */
14342 window_row
= w
->current_matrix
->rows
;
14343 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14344 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14345 while (window_row
< window_row_end
)
14347 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14348 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14350 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14351 frame_row
->glyphs
[TEXT_AREA
] = start
;
14352 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14353 frame_row
->glyphs
[LAST_AREA
] = end
;
14355 /* Disable frame rows whose corresponding window rows have
14356 been disabled in try_window_id. */
14357 if (!window_row
->enabled_p
)
14358 frame_row
->enabled_p
= 0;
14360 ++window_row
, ++frame_row
;
14365 /* Find the glyph row in window W containing CHARPOS. Consider all
14366 rows between START and END (not inclusive). END null means search
14367 all rows to the end of the display area of W. Value is the row
14368 containing CHARPOS or null. */
14371 row_containing_pos (w
, charpos
, start
, end
, dy
)
14374 struct glyph_row
*start
, *end
;
14377 struct glyph_row
*row
= start
;
14380 /* If we happen to start on a header-line, skip that. */
14381 if (row
->mode_line_p
)
14384 if ((end
&& row
>= end
) || !row
->enabled_p
)
14387 last_y
= window_text_bottom_y (w
) - dy
;
14391 /* Give up if we have gone too far. */
14392 if (end
&& row
>= end
)
14394 /* This formerly returned if they were equal.
14395 I think that both quantities are of a "last plus one" type;
14396 if so, when they are equal, the row is within the screen. -- rms. */
14397 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14400 /* If it is in this row, return this row. */
14401 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14402 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14403 /* The end position of a row equals the start
14404 position of the next row. If CHARPOS is there, we
14405 would rather display it in the next line, except
14406 when this line ends in ZV. */
14407 && !row
->ends_at_zv_p
14408 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14409 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14416 /* Try to redisplay window W by reusing its existing display. W's
14417 current matrix must be up to date when this function is called,
14418 i.e. window_end_valid must not be nil.
14422 1 if display has been updated
14423 0 if otherwise unsuccessful
14424 -1 if redisplay with same window start is known not to succeed
14426 The following steps are performed:
14428 1. Find the last row in the current matrix of W that is not
14429 affected by changes at the start of current_buffer. If no such row
14432 2. Find the first row in W's current matrix that is not affected by
14433 changes at the end of current_buffer. Maybe there is no such row.
14435 3. Display lines beginning with the row + 1 found in step 1 to the
14436 row found in step 2 or, if step 2 didn't find a row, to the end of
14439 4. If cursor is not known to appear on the window, give up.
14441 5. If display stopped at the row found in step 2, scroll the
14442 display and current matrix as needed.
14444 6. Maybe display some lines at the end of W, if we must. This can
14445 happen under various circumstances, like a partially visible line
14446 becoming fully visible, or because newly displayed lines are displayed
14447 in smaller font sizes.
14449 7. Update W's window end information. */
14455 struct frame
*f
= XFRAME (w
->frame
);
14456 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14457 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14458 struct glyph_row
*last_unchanged_at_beg_row
;
14459 struct glyph_row
*first_unchanged_at_end_row
;
14460 struct glyph_row
*row
;
14461 struct glyph_row
*bottom_row
;
14464 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14465 struct text_pos start_pos
;
14467 int first_unchanged_at_end_vpos
= 0;
14468 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14469 struct text_pos start
;
14470 int first_changed_charpos
, last_changed_charpos
;
14473 if (inhibit_try_window_id
)
14477 /* This is handy for debugging. */
14479 #define GIVE_UP(X) \
14481 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14485 #define GIVE_UP(X) return 0
14488 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14490 /* Don't use this for mini-windows because these can show
14491 messages and mini-buffers, and we don't handle that here. */
14492 if (MINI_WINDOW_P (w
))
14495 /* This flag is used to prevent redisplay optimizations. */
14496 if (windows_or_buffers_changed
|| cursor_type_changed
)
14499 /* Verify that narrowing has not changed.
14500 Also verify that we were not told to prevent redisplay optimizations.
14501 It would be nice to further
14502 reduce the number of cases where this prevents try_window_id. */
14503 if (current_buffer
->clip_changed
14504 || current_buffer
->prevent_redisplay_optimizations_p
)
14507 /* Window must either use window-based redisplay or be full width. */
14508 if (!FRAME_WINDOW_P (f
)
14509 && (!FRAME_LINE_INS_DEL_OK (f
)
14510 || !WINDOW_FULL_WIDTH_P (w
)))
14513 /* Give up if point is not known NOT to appear in W. */
14514 if (PT
< CHARPOS (start
))
14517 /* Another way to prevent redisplay optimizations. */
14518 if (XFASTINT (w
->last_modified
) == 0)
14521 /* Verify that window is not hscrolled. */
14522 if (XFASTINT (w
->hscroll
) != 0)
14525 /* Verify that display wasn't paused. */
14526 if (NILP (w
->window_end_valid
))
14529 /* Can't use this if highlighting a region because a cursor movement
14530 will do more than just set the cursor. */
14531 if (!NILP (Vtransient_mark_mode
)
14532 && !NILP (current_buffer
->mark_active
))
14535 /* Likewise if highlighting trailing whitespace. */
14536 if (!NILP (Vshow_trailing_whitespace
))
14539 /* Likewise if showing a region. */
14540 if (!NILP (w
->region_showing
))
14543 /* Can use this if overlay arrow position and or string have changed. */
14544 if (overlay_arrows_changed_p ())
14548 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14549 only if buffer has really changed. The reason is that the gap is
14550 initially at Z for freshly visited files. The code below would
14551 set end_unchanged to 0 in that case. */
14552 if (MODIFF
> SAVE_MODIFF
14553 /* This seems to happen sometimes after saving a buffer. */
14554 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14556 if (GPT
- BEG
< BEG_UNCHANGED
)
14557 BEG_UNCHANGED
= GPT
- BEG
;
14558 if (Z
- GPT
< END_UNCHANGED
)
14559 END_UNCHANGED
= Z
- GPT
;
14562 /* The position of the first and last character that has been changed. */
14563 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14564 last_changed_charpos
= Z
- END_UNCHANGED
;
14566 /* If window starts after a line end, and the last change is in
14567 front of that newline, then changes don't affect the display.
14568 This case happens with stealth-fontification. Note that although
14569 the display is unchanged, glyph positions in the matrix have to
14570 be adjusted, of course. */
14571 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14572 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14573 && ((last_changed_charpos
< CHARPOS (start
)
14574 && CHARPOS (start
) == BEGV
)
14575 || (last_changed_charpos
< CHARPOS (start
) - 1
14576 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14578 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14579 struct glyph_row
*r0
;
14581 /* Compute how many chars/bytes have been added to or removed
14582 from the buffer. */
14583 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14584 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14586 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14588 /* Give up if PT is not in the window. Note that it already has
14589 been checked at the start of try_window_id that PT is not in
14590 front of the window start. */
14591 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14594 /* If window start is unchanged, we can reuse the whole matrix
14595 as is, after adjusting glyph positions. No need to compute
14596 the window end again, since its offset from Z hasn't changed. */
14597 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14598 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14599 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14600 /* PT must not be in a partially visible line. */
14601 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14602 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14604 /* Adjust positions in the glyph matrix. */
14605 if (delta
|| delta_bytes
)
14607 struct glyph_row
*r1
14608 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14609 increment_matrix_positions (w
->current_matrix
,
14610 MATRIX_ROW_VPOS (r0
, current_matrix
),
14611 MATRIX_ROW_VPOS (r1
, current_matrix
),
14612 delta
, delta_bytes
);
14615 /* Set the cursor. */
14616 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14618 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14625 /* Handle the case that changes are all below what is displayed in
14626 the window, and that PT is in the window. This shortcut cannot
14627 be taken if ZV is visible in the window, and text has been added
14628 there that is visible in the window. */
14629 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14630 /* ZV is not visible in the window, or there are no
14631 changes at ZV, actually. */
14632 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14633 || first_changed_charpos
== last_changed_charpos
))
14635 struct glyph_row
*r0
;
14637 /* Give up if PT is not in the window. Note that it already has
14638 been checked at the start of try_window_id that PT is not in
14639 front of the window start. */
14640 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14643 /* If window start is unchanged, we can reuse the whole matrix
14644 as is, without changing glyph positions since no text has
14645 been added/removed in front of the window end. */
14646 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14647 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14648 /* PT must not be in a partially visible line. */
14649 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14650 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14652 /* We have to compute the window end anew since text
14653 can have been added/removed after it. */
14655 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14656 w
->window_end_bytepos
14657 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14659 /* Set the cursor. */
14660 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14662 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14669 /* Give up if window start is in the changed area.
14671 The condition used to read
14673 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
14675 but why that was tested escapes me at the moment. */
14676 if (CHARPOS (start
) >= first_changed_charpos
14677 && CHARPOS (start
) <= last_changed_charpos
)
14680 /* Check that window start agrees with the start of the first glyph
14681 row in its current matrix. Check this after we know the window
14682 start is not in changed text, otherwise positions would not be
14684 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14685 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
14688 /* Give up if the window ends in strings. Overlay strings
14689 at the end are difficult to handle, so don't try. */
14690 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
14691 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
14694 /* Compute the position at which we have to start displaying new
14695 lines. Some of the lines at the top of the window might be
14696 reusable because they are not displaying changed text. Find the
14697 last row in W's current matrix not affected by changes at the
14698 start of current_buffer. Value is null if changes start in the
14699 first line of window. */
14700 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
14701 if (last_unchanged_at_beg_row
)
14703 /* Avoid starting to display in the moddle of a character, a TAB
14704 for instance. This is easier than to set up the iterator
14705 exactly, and it's not a frequent case, so the additional
14706 effort wouldn't really pay off. */
14707 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
14708 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
14709 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
14710 --last_unchanged_at_beg_row
;
14712 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
14715 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
14717 start_pos
= it
.current
.pos
;
14719 /* Start displaying new lines in the desired matrix at the same
14720 vpos we would use in the current matrix, i.e. below
14721 last_unchanged_at_beg_row. */
14722 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
14724 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14725 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
14727 xassert (it
.hpos
== 0 && it
.current_x
== 0);
14731 /* There are no reusable lines at the start of the window.
14732 Start displaying in the first text line. */
14733 start_display (&it
, w
, start
);
14734 it
.vpos
= it
.first_vpos
;
14735 start_pos
= it
.current
.pos
;
14738 /* Find the first row that is not affected by changes at the end of
14739 the buffer. Value will be null if there is no unchanged row, in
14740 which case we must redisplay to the end of the window. delta
14741 will be set to the value by which buffer positions beginning with
14742 first_unchanged_at_end_row have to be adjusted due to text
14744 first_unchanged_at_end_row
14745 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
14746 IF_DEBUG (debug_delta
= delta
);
14747 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
14749 /* Set stop_pos to the buffer position up to which we will have to
14750 display new lines. If first_unchanged_at_end_row != NULL, this
14751 is the buffer position of the start of the line displayed in that
14752 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
14753 that we don't stop at a buffer position. */
14755 if (first_unchanged_at_end_row
)
14757 xassert (last_unchanged_at_beg_row
== NULL
14758 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
14760 /* If this is a continuation line, move forward to the next one
14761 that isn't. Changes in lines above affect this line.
14762 Caution: this may move first_unchanged_at_end_row to a row
14763 not displaying text. */
14764 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
14765 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14766 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14767 < it
.last_visible_y
))
14768 ++first_unchanged_at_end_row
;
14770 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14771 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14772 >= it
.last_visible_y
))
14773 first_unchanged_at_end_row
= NULL
;
14776 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
14778 first_unchanged_at_end_vpos
14779 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
14780 xassert (stop_pos
>= Z
- END_UNCHANGED
);
14783 else if (last_unchanged_at_beg_row
== NULL
)
14789 /* Either there is no unchanged row at the end, or the one we have
14790 now displays text. This is a necessary condition for the window
14791 end pos calculation at the end of this function. */
14792 xassert (first_unchanged_at_end_row
== NULL
14793 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
14795 debug_last_unchanged_at_beg_vpos
14796 = (last_unchanged_at_beg_row
14797 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
14799 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
14801 #endif /* GLYPH_DEBUG != 0 */
14804 /* Display new lines. Set last_text_row to the last new line
14805 displayed which has text on it, i.e. might end up as being the
14806 line where the window_end_vpos is. */
14807 w
->cursor
.vpos
= -1;
14808 last_text_row
= NULL
;
14809 overlay_arrow_seen
= 0;
14810 while (it
.current_y
< it
.last_visible_y
14811 && !fonts_changed_p
14812 && (first_unchanged_at_end_row
== NULL
14813 || IT_CHARPOS (it
) < stop_pos
))
14815 if (display_line (&it
))
14816 last_text_row
= it
.glyph_row
- 1;
14819 if (fonts_changed_p
)
14823 /* Compute differences in buffer positions, y-positions etc. for
14824 lines reused at the bottom of the window. Compute what we can
14826 if (first_unchanged_at_end_row
14827 /* No lines reused because we displayed everything up to the
14828 bottom of the window. */
14829 && it
.current_y
< it
.last_visible_y
)
14832 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
14834 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
14835 run
.current_y
= first_unchanged_at_end_row
->y
;
14836 run
.desired_y
= run
.current_y
+ dy
;
14837 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
14841 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
14842 first_unchanged_at_end_row
= NULL
;
14844 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
14847 /* Find the cursor if not already found. We have to decide whether
14848 PT will appear on this window (it sometimes doesn't, but this is
14849 not a very frequent case.) This decision has to be made before
14850 the current matrix is altered. A value of cursor.vpos < 0 means
14851 that PT is either in one of the lines beginning at
14852 first_unchanged_at_end_row or below the window. Don't care for
14853 lines that might be displayed later at the window end; as
14854 mentioned, this is not a frequent case. */
14855 if (w
->cursor
.vpos
< 0)
14857 /* Cursor in unchanged rows at the top? */
14858 if (PT
< CHARPOS (start_pos
)
14859 && last_unchanged_at_beg_row
)
14861 row
= row_containing_pos (w
, PT
,
14862 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
14863 last_unchanged_at_beg_row
+ 1, 0);
14865 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14868 /* Start from first_unchanged_at_end_row looking for PT. */
14869 else if (first_unchanged_at_end_row
)
14871 row
= row_containing_pos (w
, PT
- delta
,
14872 first_unchanged_at_end_row
, NULL
, 0);
14874 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
14875 delta_bytes
, dy
, dvpos
);
14878 /* Give up if cursor was not found. */
14879 if (w
->cursor
.vpos
< 0)
14881 clear_glyph_matrix (w
->desired_matrix
);
14886 /* Don't let the cursor end in the scroll margins. */
14888 int this_scroll_margin
, cursor_height
;
14890 this_scroll_margin
= max (0, scroll_margin
);
14891 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14892 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14893 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
14895 if ((w
->cursor
.y
< this_scroll_margin
14896 && CHARPOS (start
) > BEGV
)
14897 /* Old redisplay didn't take scroll margin into account at the bottom,
14898 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14899 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14900 ? cursor_height
+ this_scroll_margin
14901 : 1)) > it
.last_visible_y
)
14903 w
->cursor
.vpos
= -1;
14904 clear_glyph_matrix (w
->desired_matrix
);
14909 /* Scroll the display. Do it before changing the current matrix so
14910 that xterm.c doesn't get confused about where the cursor glyph is
14912 if (dy
&& run
.height
)
14916 if (FRAME_WINDOW_P (f
))
14918 FRAME_RIF (f
)->update_window_begin_hook (w
);
14919 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14920 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14921 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14925 /* Terminal frame. In this case, dvpos gives the number of
14926 lines to scroll by; dvpos < 0 means scroll up. */
14927 int first_unchanged_at_end_vpos
14928 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14929 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14930 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14931 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14932 + window_internal_height (w
));
14934 /* Perform the operation on the screen. */
14937 /* Scroll last_unchanged_at_beg_row to the end of the
14938 window down dvpos lines. */
14939 set_terminal_window (f
, end
);
14941 /* On dumb terminals delete dvpos lines at the end
14942 before inserting dvpos empty lines. */
14943 if (!FRAME_SCROLL_REGION_OK (f
))
14944 ins_del_lines (f
, end
- dvpos
, -dvpos
);
14946 /* Insert dvpos empty lines in front of
14947 last_unchanged_at_beg_row. */
14948 ins_del_lines (f
, from
, dvpos
);
14950 else if (dvpos
< 0)
14952 /* Scroll up last_unchanged_at_beg_vpos to the end of
14953 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14954 set_terminal_window (f
, end
);
14956 /* Delete dvpos lines in front of
14957 last_unchanged_at_beg_vpos. ins_del_lines will set
14958 the cursor to the given vpos and emit |dvpos| delete
14960 ins_del_lines (f
, from
+ dvpos
, dvpos
);
14962 /* On a dumb terminal insert dvpos empty lines at the
14964 if (!FRAME_SCROLL_REGION_OK (f
))
14965 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
14968 set_terminal_window (f
, 0);
14974 /* Shift reused rows of the current matrix to the right position.
14975 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14977 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14978 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14981 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14982 bottom_vpos
, dvpos
);
14983 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14986 else if (dvpos
> 0)
14988 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14989 bottom_vpos
, dvpos
);
14990 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14991 first_unchanged_at_end_vpos
+ dvpos
, 0);
14994 /* For frame-based redisplay, make sure that current frame and window
14995 matrix are in sync with respect to glyph memory. */
14996 if (!FRAME_WINDOW_P (f
))
14997 sync_frame_with_window_matrix_rows (w
);
14999 /* Adjust buffer positions in reused rows. */
15000 if (delta
|| delta_bytes
)
15001 increment_matrix_positions (current_matrix
,
15002 first_unchanged_at_end_vpos
+ dvpos
,
15003 bottom_vpos
, delta
, delta_bytes
);
15005 /* Adjust Y positions. */
15007 shift_glyph_matrix (w
, current_matrix
,
15008 first_unchanged_at_end_vpos
+ dvpos
,
15011 if (first_unchanged_at_end_row
)
15013 first_unchanged_at_end_row
+= dvpos
;
15014 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
15015 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
15016 first_unchanged_at_end_row
= NULL
;
15019 /* If scrolling up, there may be some lines to display at the end of
15021 last_text_row_at_end
= NULL
;
15024 /* Scrolling up can leave for example a partially visible line
15025 at the end of the window to be redisplayed. */
15026 /* Set last_row to the glyph row in the current matrix where the
15027 window end line is found. It has been moved up or down in
15028 the matrix by dvpos. */
15029 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
15030 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
15032 /* If last_row is the window end line, it should display text. */
15033 xassert (last_row
->displays_text_p
);
15035 /* If window end line was partially visible before, begin
15036 displaying at that line. Otherwise begin displaying with the
15037 line following it. */
15038 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
15040 init_to_row_start (&it
, w
, last_row
);
15041 it
.vpos
= last_vpos
;
15042 it
.current_y
= last_row
->y
;
15046 init_to_row_end (&it
, w
, last_row
);
15047 it
.vpos
= 1 + last_vpos
;
15048 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
15052 /* We may start in a continuation line. If so, we have to
15053 get the right continuation_lines_width and current_x. */
15054 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
15055 it
.hpos
= it
.current_x
= 0;
15057 /* Display the rest of the lines at the window end. */
15058 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15059 while (it
.current_y
< it
.last_visible_y
15060 && !fonts_changed_p
)
15062 /* Is it always sure that the display agrees with lines in
15063 the current matrix? I don't think so, so we mark rows
15064 displayed invalid in the current matrix by setting their
15065 enabled_p flag to zero. */
15066 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
15067 if (display_line (&it
))
15068 last_text_row_at_end
= it
.glyph_row
- 1;
15072 /* Update window_end_pos and window_end_vpos. */
15073 if (first_unchanged_at_end_row
15074 && !last_text_row_at_end
)
15076 /* Window end line if one of the preserved rows from the current
15077 matrix. Set row to the last row displaying text in current
15078 matrix starting at first_unchanged_at_end_row, after
15080 xassert (first_unchanged_at_end_row
->displays_text_p
);
15081 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
15082 first_unchanged_at_end_row
);
15083 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
15085 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15086 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15088 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
15089 xassert (w
->window_end_bytepos
>= 0);
15090 IF_DEBUG (debug_method_add (w
, "A"));
15092 else if (last_text_row_at_end
)
15095 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
15096 w
->window_end_bytepos
15097 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
15099 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
15100 xassert (w
->window_end_bytepos
>= 0);
15101 IF_DEBUG (debug_method_add (w
, "B"));
15103 else if (last_text_row
)
15105 /* We have displayed either to the end of the window or at the
15106 end of the window, i.e. the last row with text is to be found
15107 in the desired matrix. */
15109 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15110 w
->window_end_bytepos
15111 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15113 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
15114 xassert (w
->window_end_bytepos
>= 0);
15116 else if (first_unchanged_at_end_row
== NULL
15117 && last_text_row
== NULL
15118 && last_text_row_at_end
== NULL
)
15120 /* Displayed to end of window, but no line containing text was
15121 displayed. Lines were deleted at the end of the window. */
15122 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
15123 int vpos
= XFASTINT (w
->window_end_vpos
);
15124 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
15125 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
15128 row
== NULL
&& vpos
>= first_vpos
;
15129 --vpos
, --current_row
, --desired_row
)
15131 if (desired_row
->enabled_p
)
15133 if (desired_row
->displays_text_p
)
15136 else if (current_row
->displays_text_p
)
15140 xassert (row
!= NULL
);
15141 w
->window_end_vpos
= make_number (vpos
+ 1);
15142 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15143 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15144 xassert (w
->window_end_bytepos
>= 0);
15145 IF_DEBUG (debug_method_add (w
, "C"));
15150 #if 0 /* This leads to problems, for instance when the cursor is
15151 at ZV, and the cursor line displays no text. */
15152 /* Disable rows below what's displayed in the window. This makes
15153 debugging easier. */
15154 enable_glyph_matrix_rows (current_matrix
,
15155 XFASTINT (w
->window_end_vpos
) + 1,
15159 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
15160 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
15162 /* Record that display has not been completed. */
15163 w
->window_end_valid
= Qnil
;
15164 w
->desired_matrix
->no_scrolling_p
= 1;
15172 /***********************************************************************
15173 More debugging support
15174 ***********************************************************************/
15178 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
15179 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
15180 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
15183 /* Dump the contents of glyph matrix MATRIX on stderr.
15185 GLYPHS 0 means don't show glyph contents.
15186 GLYPHS 1 means show glyphs in short form
15187 GLYPHS > 1 means show glyphs in long form. */
15190 dump_glyph_matrix (matrix
, glyphs
)
15191 struct glyph_matrix
*matrix
;
15195 for (i
= 0; i
< matrix
->nrows
; ++i
)
15196 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
15200 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
15201 the glyph row and area where the glyph comes from. */
15204 dump_glyph (row
, glyph
, area
)
15205 struct glyph_row
*row
;
15206 struct glyph
*glyph
;
15209 if (glyph
->type
== CHAR_GLYPH
)
15212 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15213 glyph
- row
->glyphs
[TEXT_AREA
],
15216 (BUFFERP (glyph
->object
)
15218 : (STRINGP (glyph
->object
)
15221 glyph
->pixel_width
,
15223 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
15227 glyph
->left_box_line_p
,
15228 glyph
->right_box_line_p
);
15230 else if (glyph
->type
== STRETCH_GLYPH
)
15233 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15234 glyph
- row
->glyphs
[TEXT_AREA
],
15237 (BUFFERP (glyph
->object
)
15239 : (STRINGP (glyph
->object
)
15242 glyph
->pixel_width
,
15246 glyph
->left_box_line_p
,
15247 glyph
->right_box_line_p
);
15249 else if (glyph
->type
== IMAGE_GLYPH
)
15252 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15253 glyph
- row
->glyphs
[TEXT_AREA
],
15256 (BUFFERP (glyph
->object
)
15258 : (STRINGP (glyph
->object
)
15261 glyph
->pixel_width
,
15265 glyph
->left_box_line_p
,
15266 glyph
->right_box_line_p
);
15268 else if (glyph
->type
== COMPOSITE_GLYPH
)
15271 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15272 glyph
- row
->glyphs
[TEXT_AREA
],
15275 (BUFFERP (glyph
->object
)
15277 : (STRINGP (glyph
->object
)
15280 glyph
->pixel_width
,
15284 glyph
->left_box_line_p
,
15285 glyph
->right_box_line_p
);
15290 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
15291 GLYPHS 0 means don't show glyph contents.
15292 GLYPHS 1 means show glyphs in short form
15293 GLYPHS > 1 means show glyphs in long form. */
15296 dump_glyph_row (row
, vpos
, glyphs
)
15297 struct glyph_row
*row
;
15302 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
15303 fprintf (stderr
, "======================================================================\n");
15305 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
15306 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
15308 MATRIX_ROW_START_CHARPOS (row
),
15309 MATRIX_ROW_END_CHARPOS (row
),
15310 row
->used
[TEXT_AREA
],
15311 row
->contains_overlapping_glyphs_p
,
15313 row
->truncated_on_left_p
,
15314 row
->truncated_on_right_p
,
15316 MATRIX_ROW_CONTINUATION_LINE_P (row
),
15317 row
->displays_text_p
,
15320 row
->ends_in_middle_of_char_p
,
15321 row
->starts_in_middle_of_char_p
,
15327 row
->visible_height
,
15330 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
15331 row
->end
.overlay_string_index
,
15332 row
->continuation_lines_width
);
15333 fprintf (stderr
, "%9d %5d\n",
15334 CHARPOS (row
->start
.string_pos
),
15335 CHARPOS (row
->end
.string_pos
));
15336 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
15337 row
->end
.dpvec_index
);
15344 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15346 struct glyph
*glyph
= row
->glyphs
[area
];
15347 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
15349 /* Glyph for a line end in text. */
15350 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
15353 if (glyph
< glyph_end
)
15354 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15356 for (; glyph
< glyph_end
; ++glyph
)
15357 dump_glyph (row
, glyph
, area
);
15360 else if (glyphs
== 1)
15364 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15366 char *s
= (char *) alloca (row
->used
[area
] + 1);
15369 for (i
= 0; i
< row
->used
[area
]; ++i
)
15371 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15372 if (glyph
->type
== CHAR_GLYPH
15373 && glyph
->u
.ch
< 0x80
15374 && glyph
->u
.ch
>= ' ')
15375 s
[i
] = glyph
->u
.ch
;
15381 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15387 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15388 Sdump_glyph_matrix
, 0, 1, "p",
15389 doc
: /* Dump the current matrix of the selected window to stderr.
15390 Shows contents of glyph row structures. With non-nil
15391 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15392 glyphs in short form, otherwise show glyphs in long form. */)
15394 Lisp_Object glyphs
;
15396 struct window
*w
= XWINDOW (selected_window
);
15397 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15399 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15400 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15401 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15402 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15403 fprintf (stderr
, "=============================================\n");
15404 dump_glyph_matrix (w
->current_matrix
,
15405 NILP (glyphs
) ? 0 : XINT (glyphs
));
15410 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15411 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15414 struct frame
*f
= XFRAME (selected_frame
);
15415 dump_glyph_matrix (f
->current_matrix
, 1);
15420 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15421 doc
: /* Dump glyph row ROW to stderr.
15422 GLYPH 0 means don't dump glyphs.
15423 GLYPH 1 means dump glyphs in short form.
15424 GLYPH > 1 or omitted means dump glyphs in long form. */)
15426 Lisp_Object row
, glyphs
;
15428 struct glyph_matrix
*matrix
;
15431 CHECK_NUMBER (row
);
15432 matrix
= XWINDOW (selected_window
)->current_matrix
;
15434 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15435 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15437 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15442 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15443 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15444 GLYPH 0 means don't dump glyphs.
15445 GLYPH 1 means dump glyphs in short form.
15446 GLYPH > 1 or omitted means dump glyphs in long form. */)
15448 Lisp_Object row
, glyphs
;
15450 struct frame
*sf
= SELECTED_FRAME ();
15451 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15454 CHECK_NUMBER (row
);
15456 if (vpos
>= 0 && vpos
< m
->nrows
)
15457 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15458 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15463 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15464 doc
: /* Toggle tracing of redisplay.
15465 With ARG, turn tracing on if and only if ARG is positive. */)
15470 trace_redisplay_p
= !trace_redisplay_p
;
15473 arg
= Fprefix_numeric_value (arg
);
15474 trace_redisplay_p
= XINT (arg
) > 0;
15481 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15482 doc
: /* Like `format', but print result to stderr.
15483 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15488 Lisp_Object s
= Fformat (nargs
, args
);
15489 fprintf (stderr
, "%s", SDATA (s
));
15493 #endif /* GLYPH_DEBUG */
15497 /***********************************************************************
15498 Building Desired Matrix Rows
15499 ***********************************************************************/
15501 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15502 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15504 static struct glyph_row
*
15505 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15507 Lisp_Object overlay_arrow_string
;
15509 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15510 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15511 struct buffer
*old
= current_buffer
;
15512 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15513 int arrow_len
= SCHARS (overlay_arrow_string
);
15514 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15515 const unsigned char *p
;
15518 int n_glyphs_before
;
15520 set_buffer_temp (buffer
);
15521 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15522 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15523 SET_TEXT_POS (it
.position
, 0, 0);
15525 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15527 while (p
< arrow_end
)
15529 Lisp_Object face
, ilisp
;
15531 /* Get the next character. */
15533 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15535 it
.c
= *p
, it
.len
= 1;
15538 /* Get its face. */
15539 ilisp
= make_number (p
- arrow_string
);
15540 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15541 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15543 /* Compute its width, get its glyphs. */
15544 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15545 SET_TEXT_POS (it
.position
, -1, -1);
15546 PRODUCE_GLYPHS (&it
);
15548 /* If this character doesn't fit any more in the line, we have
15549 to remove some glyphs. */
15550 if (it
.current_x
> it
.last_visible_x
)
15552 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15557 set_buffer_temp (old
);
15558 return it
.glyph_row
;
15562 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15563 glyphs are only inserted for terminal frames since we can't really
15564 win with truncation glyphs when partially visible glyphs are
15565 involved. Which glyphs to insert is determined by
15566 produce_special_glyphs. */
15569 insert_left_trunc_glyphs (it
)
15572 struct it truncate_it
;
15573 struct glyph
*from
, *end
, *to
, *toend
;
15575 xassert (!FRAME_WINDOW_P (it
->f
));
15577 /* Get the truncation glyphs. */
15579 truncate_it
.current_x
= 0;
15580 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15581 truncate_it
.glyph_row
= &scratch_glyph_row
;
15582 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15583 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15584 truncate_it
.object
= make_number (0);
15585 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15587 /* Overwrite glyphs from IT with truncation glyphs. */
15588 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15589 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15590 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15591 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15596 /* There may be padding glyphs left over. Overwrite them too. */
15597 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15599 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15605 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15609 /* Compute the pixel height and width of IT->glyph_row.
15611 Most of the time, ascent and height of a display line will be equal
15612 to the max_ascent and max_height values of the display iterator
15613 structure. This is not the case if
15615 1. We hit ZV without displaying anything. In this case, max_ascent
15616 and max_height will be zero.
15618 2. We have some glyphs that don't contribute to the line height.
15619 (The glyph row flag contributes_to_line_height_p is for future
15620 pixmap extensions).
15622 The first case is easily covered by using default values because in
15623 these cases, the line height does not really matter, except that it
15624 must not be zero. */
15627 compute_line_metrics (it
)
15630 struct glyph_row
*row
= it
->glyph_row
;
15633 if (FRAME_WINDOW_P (it
->f
))
15635 int i
, min_y
, max_y
;
15637 /* The line may consist of one space only, that was added to
15638 place the cursor on it. If so, the row's height hasn't been
15640 if (row
->height
== 0)
15642 if (it
->max_ascent
+ it
->max_descent
== 0)
15643 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15644 row
->ascent
= it
->max_ascent
;
15645 row
->height
= it
->max_ascent
+ it
->max_descent
;
15646 row
->phys_ascent
= it
->max_phys_ascent
;
15647 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15648 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15651 /* Compute the width of this line. */
15652 row
->pixel_width
= row
->x
;
15653 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15654 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15656 xassert (row
->pixel_width
>= 0);
15657 xassert (row
->ascent
>= 0 && row
->height
> 0);
15659 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15660 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15662 /* If first line's physical ascent is larger than its logical
15663 ascent, use the physical ascent, and make the row taller.
15664 This makes accented characters fully visible. */
15665 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
15666 && row
->phys_ascent
> row
->ascent
)
15668 row
->height
+= row
->phys_ascent
- row
->ascent
;
15669 row
->ascent
= row
->phys_ascent
;
15672 /* Compute how much of the line is visible. */
15673 row
->visible_height
= row
->height
;
15675 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
15676 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
15678 if (row
->y
< min_y
)
15679 row
->visible_height
-= min_y
- row
->y
;
15680 if (row
->y
+ row
->height
> max_y
)
15681 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15685 row
->pixel_width
= row
->used
[TEXT_AREA
];
15686 if (row
->continued_p
)
15687 row
->pixel_width
-= it
->continuation_pixel_width
;
15688 else if (row
->truncated_on_right_p
)
15689 row
->pixel_width
-= it
->truncation_pixel_width
;
15690 row
->ascent
= row
->phys_ascent
= 0;
15691 row
->height
= row
->phys_height
= row
->visible_height
= 1;
15692 row
->extra_line_spacing
= 0;
15695 /* Compute a hash code for this row. */
15697 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15698 for (i
= 0; i
< row
->used
[area
]; ++i
)
15699 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
15700 + row
->glyphs
[area
][i
].u
.val
15701 + row
->glyphs
[area
][i
].face_id
15702 + row
->glyphs
[area
][i
].padding_p
15703 + (row
->glyphs
[area
][i
].type
<< 2));
15705 it
->max_ascent
= it
->max_descent
= 0;
15706 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
15710 /* Append one space to the glyph row of iterator IT if doing a
15711 window-based redisplay. The space has the same face as
15712 IT->face_id. Value is non-zero if a space was added.
15714 This function is called to make sure that there is always one glyph
15715 at the end of a glyph row that the cursor can be set on under
15716 window-systems. (If there weren't such a glyph we would not know
15717 how wide and tall a box cursor should be displayed).
15719 At the same time this space let's a nicely handle clearing to the
15720 end of the line if the row ends in italic text. */
15723 append_space_for_newline (it
, default_face_p
)
15725 int default_face_p
;
15727 if (FRAME_WINDOW_P (it
->f
))
15729 int n
= it
->glyph_row
->used
[TEXT_AREA
];
15731 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
15732 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
15734 /* Save some values that must not be changed.
15735 Must save IT->c and IT->len because otherwise
15736 ITERATOR_AT_END_P wouldn't work anymore after
15737 append_space_for_newline has been called. */
15738 enum display_element_type saved_what
= it
->what
;
15739 int saved_c
= it
->c
, saved_len
= it
->len
;
15740 int saved_x
= it
->current_x
;
15741 int saved_face_id
= it
->face_id
;
15742 struct text_pos saved_pos
;
15743 Lisp_Object saved_object
;
15746 saved_object
= it
->object
;
15747 saved_pos
= it
->position
;
15749 it
->what
= IT_CHARACTER
;
15750 bzero (&it
->position
, sizeof it
->position
);
15751 it
->object
= make_number (0);
15755 if (default_face_p
)
15756 it
->face_id
= DEFAULT_FACE_ID
;
15757 else if (it
->face_before_selective_p
)
15758 it
->face_id
= it
->saved_face_id
;
15759 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15760 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
15762 PRODUCE_GLYPHS (it
);
15764 it
->override_ascent
= -1;
15765 it
->constrain_row_ascent_descent_p
= 0;
15766 it
->current_x
= saved_x
;
15767 it
->object
= saved_object
;
15768 it
->position
= saved_pos
;
15769 it
->what
= saved_what
;
15770 it
->face_id
= saved_face_id
;
15771 it
->len
= saved_len
;
15781 /* Extend the face of the last glyph in the text area of IT->glyph_row
15782 to the end of the display line. Called from display_line.
15783 If the glyph row is empty, add a space glyph to it so that we
15784 know the face to draw. Set the glyph row flag fill_line_p. */
15787 extend_face_to_end_of_line (it
)
15791 struct frame
*f
= it
->f
;
15793 /* If line is already filled, do nothing. */
15794 if (it
->current_x
>= it
->last_visible_x
)
15797 /* Face extension extends the background and box of IT->face_id
15798 to the end of the line. If the background equals the background
15799 of the frame, we don't have to do anything. */
15800 if (it
->face_before_selective_p
)
15801 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
15803 face
= FACE_FROM_ID (f
, it
->face_id
);
15805 if (FRAME_WINDOW_P (f
)
15806 && it
->glyph_row
->displays_text_p
15807 && face
->box
== FACE_NO_BOX
15808 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
15812 /* Set the glyph row flag indicating that the face of the last glyph
15813 in the text area has to be drawn to the end of the text area. */
15814 it
->glyph_row
->fill_line_p
= 1;
15816 /* If current character of IT is not ASCII, make sure we have the
15817 ASCII face. This will be automatically undone the next time
15818 get_next_display_element returns a multibyte character. Note
15819 that the character will always be single byte in unibyte text. */
15820 if (!SINGLE_BYTE_CHAR_P (it
->c
))
15822 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
15825 if (FRAME_WINDOW_P (f
))
15827 /* If the row is empty, add a space with the current face of IT,
15828 so that we know which face to draw. */
15829 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
15831 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
15832 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
15833 it
->glyph_row
->used
[TEXT_AREA
] = 1;
15838 /* Save some values that must not be changed. */
15839 int saved_x
= it
->current_x
;
15840 struct text_pos saved_pos
;
15841 Lisp_Object saved_object
;
15842 enum display_element_type saved_what
= it
->what
;
15843 int saved_face_id
= it
->face_id
;
15845 saved_object
= it
->object
;
15846 saved_pos
= it
->position
;
15848 it
->what
= IT_CHARACTER
;
15849 bzero (&it
->position
, sizeof it
->position
);
15850 it
->object
= make_number (0);
15853 it
->face_id
= face
->id
;
15855 PRODUCE_GLYPHS (it
);
15857 while (it
->current_x
<= it
->last_visible_x
)
15858 PRODUCE_GLYPHS (it
);
15860 /* Don't count these blanks really. It would let us insert a left
15861 truncation glyph below and make us set the cursor on them, maybe. */
15862 it
->current_x
= saved_x
;
15863 it
->object
= saved_object
;
15864 it
->position
= saved_pos
;
15865 it
->what
= saved_what
;
15866 it
->face_id
= saved_face_id
;
15871 /* Value is non-zero if text starting at CHARPOS in current_buffer is
15872 trailing whitespace. */
15875 trailing_whitespace_p (charpos
)
15878 int bytepos
= CHAR_TO_BYTE (charpos
);
15881 while (bytepos
< ZV_BYTE
15882 && (c
= FETCH_CHAR (bytepos
),
15883 c
== ' ' || c
== '\t'))
15886 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
15888 if (bytepos
!= PT_BYTE
)
15895 /* Highlight trailing whitespace, if any, in ROW. */
15898 highlight_trailing_whitespace (f
, row
)
15900 struct glyph_row
*row
;
15902 int used
= row
->used
[TEXT_AREA
];
15906 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
15907 struct glyph
*glyph
= start
+ used
- 1;
15909 /* Skip over glyphs inserted to display the cursor at the
15910 end of a line, for extending the face of the last glyph
15911 to the end of the line on terminals, and for truncation
15912 and continuation glyphs. */
15913 while (glyph
>= start
15914 && glyph
->type
== CHAR_GLYPH
15915 && INTEGERP (glyph
->object
))
15918 /* If last glyph is a space or stretch, and it's trailing
15919 whitespace, set the face of all trailing whitespace glyphs in
15920 IT->glyph_row to `trailing-whitespace'. */
15922 && BUFFERP (glyph
->object
)
15923 && (glyph
->type
== STRETCH_GLYPH
15924 || (glyph
->type
== CHAR_GLYPH
15925 && glyph
->u
.ch
== ' '))
15926 && trailing_whitespace_p (glyph
->charpos
))
15928 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
15932 while (glyph
>= start
15933 && BUFFERP (glyph
->object
)
15934 && (glyph
->type
== STRETCH_GLYPH
15935 || (glyph
->type
== CHAR_GLYPH
15936 && glyph
->u
.ch
== ' ')))
15937 (glyph
--)->face_id
= face_id
;
15943 /* Value is non-zero if glyph row ROW in window W should be
15944 used to hold the cursor. */
15947 cursor_row_p (w
, row
)
15949 struct glyph_row
*row
;
15951 int cursor_row_p
= 1;
15953 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15955 /* Suppose the row ends on a string.
15956 Unless the row is continued, that means it ends on a newline
15957 in the string. If it's anything other than a display string
15958 (e.g. a before-string from an overlay), we don't want the
15959 cursor there. (This heuristic seems to give the optimal
15960 behavior for the various types of multi-line strings.) */
15961 if (CHARPOS (row
->end
.string_pos
) >= 0)
15963 if (row
->continued_p
)
15967 /* Check for `display' property. */
15968 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
15969 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
15970 struct glyph
*glyph
;
15973 for (glyph
= end
; glyph
>= beg
; --glyph
)
15974 if (STRINGP (glyph
->object
))
15977 = Fget_char_property (make_number (PT
),
15981 && display_prop_string_p (prop
, glyph
->object
));
15986 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15988 /* If the row ends in middle of a real character,
15989 and the line is continued, we want the cursor here.
15990 That's because MATRIX_ROW_END_CHARPOS would equal
15991 PT if PT is before the character. */
15992 if (!row
->ends_in_ellipsis_p
)
15993 cursor_row_p
= row
->continued_p
;
15995 /* If the row ends in an ellipsis, then
15996 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15997 We want that position to be displayed after the ellipsis. */
16000 /* If the row ends at ZV, display the cursor at the end of that
16001 row instead of at the start of the row below. */
16002 else if (row
->ends_at_zv_p
)
16008 return cursor_row_p
;
16012 /* Construct the glyph row IT->glyph_row in the desired matrix of
16013 IT->w from text at the current position of IT. See dispextern.h
16014 for an overview of struct it. Value is non-zero if
16015 IT->glyph_row displays text, as opposed to a line displaying ZV
16022 struct glyph_row
*row
= it
->glyph_row
;
16023 Lisp_Object overlay_arrow_string
;
16025 /* We always start displaying at hpos zero even if hscrolled. */
16026 xassert (it
->hpos
== 0 && it
->current_x
== 0);
16028 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
16029 >= it
->w
->desired_matrix
->nrows
)
16031 it
->w
->nrows_scale_factor
++;
16032 fonts_changed_p
= 1;
16036 /* Is IT->w showing the region? */
16037 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
16039 /* Clear the result glyph row and enable it. */
16040 prepare_desired_row (row
);
16042 row
->y
= it
->current_y
;
16043 row
->start
= it
->start
;
16044 row
->continuation_lines_width
= it
->continuation_lines_width
;
16045 row
->displays_text_p
= 1;
16046 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
16047 it
->starts_in_middle_of_char_p
= 0;
16049 /* Arrange the overlays nicely for our purposes. Usually, we call
16050 display_line on only one line at a time, in which case this
16051 can't really hurt too much, or we call it on lines which appear
16052 one after another in the buffer, in which case all calls to
16053 recenter_overlay_lists but the first will be pretty cheap. */
16054 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
16056 /* Move over display elements that are not visible because we are
16057 hscrolled. This may stop at an x-position < IT->first_visible_x
16058 if the first glyph is partially visible or if we hit a line end. */
16059 if (it
->current_x
< it
->first_visible_x
)
16061 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
16062 MOVE_TO_POS
| MOVE_TO_X
);
16065 /* Get the initial row height. This is either the height of the
16066 text hscrolled, if there is any, or zero. */
16067 row
->ascent
= it
->max_ascent
;
16068 row
->height
= it
->max_ascent
+ it
->max_descent
;
16069 row
->phys_ascent
= it
->max_phys_ascent
;
16070 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16071 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16073 /* Loop generating characters. The loop is left with IT on the next
16074 character to display. */
16077 int n_glyphs_before
, hpos_before
, x_before
;
16079 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
16081 /* Retrieve the next thing to display. Value is zero if end of
16083 if (!get_next_display_element (it
))
16085 /* Maybe add a space at the end of this line that is used to
16086 display the cursor there under X. Set the charpos of the
16087 first glyph of blank lines not corresponding to any text
16089 #ifdef HAVE_WINDOW_SYSTEM
16090 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16091 row
->exact_window_width_line_p
= 1;
16093 #endif /* HAVE_WINDOW_SYSTEM */
16094 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
16095 || row
->used
[TEXT_AREA
] == 0)
16097 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
16098 row
->displays_text_p
= 0;
16100 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
16101 && (!MINI_WINDOW_P (it
->w
)
16102 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
16103 row
->indicate_empty_line_p
= 1;
16106 it
->continuation_lines_width
= 0;
16107 row
->ends_at_zv_p
= 1;
16111 /* Now, get the metrics of what we want to display. This also
16112 generates glyphs in `row' (which is IT->glyph_row). */
16113 n_glyphs_before
= row
->used
[TEXT_AREA
];
16116 /* Remember the line height so far in case the next element doesn't
16117 fit on the line. */
16118 if (!it
->truncate_lines_p
)
16120 ascent
= it
->max_ascent
;
16121 descent
= it
->max_descent
;
16122 phys_ascent
= it
->max_phys_ascent
;
16123 phys_descent
= it
->max_phys_descent
;
16126 PRODUCE_GLYPHS (it
);
16128 /* If this display element was in marginal areas, continue with
16130 if (it
->area
!= TEXT_AREA
)
16132 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16133 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16134 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16135 row
->phys_height
= max (row
->phys_height
,
16136 it
->max_phys_ascent
+ it
->max_phys_descent
);
16137 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16138 it
->max_extra_line_spacing
);
16139 set_iterator_to_next (it
, 1);
16143 /* Does the display element fit on the line? If we truncate
16144 lines, we should draw past the right edge of the window. If
16145 we don't truncate, we want to stop so that we can display the
16146 continuation glyph before the right margin. If lines are
16147 continued, there are two possible strategies for characters
16148 resulting in more than 1 glyph (e.g. tabs): Display as many
16149 glyphs as possible in this line and leave the rest for the
16150 continuation line, or display the whole element in the next
16151 line. Original redisplay did the former, so we do it also. */
16152 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
16153 hpos_before
= it
->hpos
;
16156 if (/* Not a newline. */
16158 /* Glyphs produced fit entirely in the line. */
16159 && it
->current_x
< it
->last_visible_x
)
16161 it
->hpos
+= nglyphs
;
16162 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16163 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16164 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16165 row
->phys_height
= max (row
->phys_height
,
16166 it
->max_phys_ascent
+ it
->max_phys_descent
);
16167 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16168 it
->max_extra_line_spacing
);
16169 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
16170 row
->x
= x
- it
->first_visible_x
;
16175 struct glyph
*glyph
;
16177 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
16179 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16180 new_x
= x
+ glyph
->pixel_width
;
16182 if (/* Lines are continued. */
16183 !it
->truncate_lines_p
16184 && (/* Glyph doesn't fit on the line. */
16185 new_x
> it
->last_visible_x
16186 /* Or it fits exactly on a window system frame. */
16187 || (new_x
== it
->last_visible_x
16188 && FRAME_WINDOW_P (it
->f
))))
16190 /* End of a continued line. */
16193 || (new_x
== it
->last_visible_x
16194 && FRAME_WINDOW_P (it
->f
)))
16196 /* Current glyph is the only one on the line or
16197 fits exactly on the line. We must continue
16198 the line because we can't draw the cursor
16199 after the glyph. */
16200 row
->continued_p
= 1;
16201 it
->current_x
= new_x
;
16202 it
->continuation_lines_width
+= new_x
;
16204 if (i
== nglyphs
- 1)
16206 set_iterator_to_next (it
, 1);
16207 #ifdef HAVE_WINDOW_SYSTEM
16208 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16210 if (!get_next_display_element (it
))
16212 row
->exact_window_width_line_p
= 1;
16213 it
->continuation_lines_width
= 0;
16214 row
->continued_p
= 0;
16215 row
->ends_at_zv_p
= 1;
16217 else if (ITERATOR_AT_END_OF_LINE_P (it
))
16219 row
->continued_p
= 0;
16220 row
->exact_window_width_line_p
= 1;
16223 #endif /* HAVE_WINDOW_SYSTEM */
16226 else if (CHAR_GLYPH_PADDING_P (*glyph
)
16227 && !FRAME_WINDOW_P (it
->f
))
16229 /* A padding glyph that doesn't fit on this line.
16230 This means the whole character doesn't fit
16232 row
->used
[TEXT_AREA
] = n_glyphs_before
;
16234 /* Fill the rest of the row with continuation
16235 glyphs like in 20.x. */
16236 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
16237 < row
->glyphs
[1 + TEXT_AREA
])
16238 produce_special_glyphs (it
, IT_CONTINUATION
);
16240 row
->continued_p
= 1;
16241 it
->current_x
= x_before
;
16242 it
->continuation_lines_width
+= x_before
;
16244 /* Restore the height to what it was before the
16245 element not fitting on the line. */
16246 it
->max_ascent
= ascent
;
16247 it
->max_descent
= descent
;
16248 it
->max_phys_ascent
= phys_ascent
;
16249 it
->max_phys_descent
= phys_descent
;
16251 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
16253 /* A TAB that extends past the right edge of the
16254 window. This produces a single glyph on
16255 window system frames. We leave the glyph in
16256 this row and let it fill the row, but don't
16257 consume the TAB. */
16258 it
->continuation_lines_width
+= it
->last_visible_x
;
16259 row
->ends_in_middle_of_char_p
= 1;
16260 row
->continued_p
= 1;
16261 glyph
->pixel_width
= it
->last_visible_x
- x
;
16262 it
->starts_in_middle_of_char_p
= 1;
16266 /* Something other than a TAB that draws past
16267 the right edge of the window. Restore
16268 positions to values before the element. */
16269 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16271 /* Display continuation glyphs. */
16272 if (!FRAME_WINDOW_P (it
->f
))
16273 produce_special_glyphs (it
, IT_CONTINUATION
);
16274 row
->continued_p
= 1;
16276 it
->current_x
= x_before
;
16277 it
->continuation_lines_width
+= x
;
16278 extend_face_to_end_of_line (it
);
16280 if (nglyphs
> 1 && i
> 0)
16282 row
->ends_in_middle_of_char_p
= 1;
16283 it
->starts_in_middle_of_char_p
= 1;
16286 /* Restore the height to what it was before the
16287 element not fitting on the line. */
16288 it
->max_ascent
= ascent
;
16289 it
->max_descent
= descent
;
16290 it
->max_phys_ascent
= phys_ascent
;
16291 it
->max_phys_descent
= phys_descent
;
16296 else if (new_x
> it
->first_visible_x
)
16298 /* Increment number of glyphs actually displayed. */
16301 if (x
< it
->first_visible_x
)
16302 /* Glyph is partially visible, i.e. row starts at
16303 negative X position. */
16304 row
->x
= x
- it
->first_visible_x
;
16308 /* Glyph is completely off the left margin of the
16309 window. This should not happen because of the
16310 move_it_in_display_line at the start of this
16311 function, unless the text display area of the
16312 window is empty. */
16313 xassert (it
->first_visible_x
<= it
->last_visible_x
);
16317 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16318 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16319 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16320 row
->phys_height
= max (row
->phys_height
,
16321 it
->max_phys_ascent
+ it
->max_phys_descent
);
16322 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16323 it
->max_extra_line_spacing
);
16325 /* End of this display line if row is continued. */
16326 if (row
->continued_p
|| row
->ends_at_zv_p
)
16331 /* Is this a line end? If yes, we're also done, after making
16332 sure that a non-default face is extended up to the right
16333 margin of the window. */
16334 if (ITERATOR_AT_END_OF_LINE_P (it
))
16336 int used_before
= row
->used
[TEXT_AREA
];
16338 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
16340 #ifdef HAVE_WINDOW_SYSTEM
16341 /* Add a space at the end of the line that is used to
16342 display the cursor there. */
16343 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16344 append_space_for_newline (it
, 0);
16345 #endif /* HAVE_WINDOW_SYSTEM */
16347 /* Extend the face to the end of the line. */
16348 extend_face_to_end_of_line (it
);
16350 /* Make sure we have the position. */
16351 if (used_before
== 0)
16352 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
16354 /* Consume the line end. This skips over invisible lines. */
16355 set_iterator_to_next (it
, 1);
16356 it
->continuation_lines_width
= 0;
16360 /* Proceed with next display element. Note that this skips
16361 over lines invisible because of selective display. */
16362 set_iterator_to_next (it
, 1);
16364 /* If we truncate lines, we are done when the last displayed
16365 glyphs reach past the right margin of the window. */
16366 if (it
->truncate_lines_p
16367 && (FRAME_WINDOW_P (it
->f
)
16368 ? (it
->current_x
>= it
->last_visible_x
)
16369 : (it
->current_x
> it
->last_visible_x
)))
16371 /* Maybe add truncation glyphs. */
16372 if (!FRAME_WINDOW_P (it
->f
))
16376 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16377 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16380 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16382 row
->used
[TEXT_AREA
] = i
;
16383 produce_special_glyphs (it
, IT_TRUNCATION
);
16386 #ifdef HAVE_WINDOW_SYSTEM
16389 /* Don't truncate if we can overflow newline into fringe. */
16390 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16392 if (!get_next_display_element (it
))
16394 it
->continuation_lines_width
= 0;
16395 row
->ends_at_zv_p
= 1;
16396 row
->exact_window_width_line_p
= 1;
16399 if (ITERATOR_AT_END_OF_LINE_P (it
))
16401 row
->exact_window_width_line_p
= 1;
16402 goto at_end_of_line
;
16406 #endif /* HAVE_WINDOW_SYSTEM */
16408 row
->truncated_on_right_p
= 1;
16409 it
->continuation_lines_width
= 0;
16410 reseat_at_next_visible_line_start (it
, 0);
16411 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16412 it
->hpos
= hpos_before
;
16413 it
->current_x
= x_before
;
16418 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16419 at the left window margin. */
16420 if (it
->first_visible_x
16421 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16423 if (!FRAME_WINDOW_P (it
->f
))
16424 insert_left_trunc_glyphs (it
);
16425 row
->truncated_on_left_p
= 1;
16428 /* If the start of this line is the overlay arrow-position, then
16429 mark this glyph row as the one containing the overlay arrow.
16430 This is clearly a mess with variable size fonts. It would be
16431 better to let it be displayed like cursors under X. */
16432 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16433 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16434 !NILP (overlay_arrow_string
)))
16436 /* Overlay arrow in window redisplay is a fringe bitmap. */
16437 if (STRINGP (overlay_arrow_string
))
16439 struct glyph_row
*arrow_row
16440 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
16441 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
16442 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
16443 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
16444 struct glyph
*p2
, *end
;
16446 /* Copy the arrow glyphs. */
16447 while (glyph
< arrow_end
)
16450 /* Throw away padding glyphs. */
16452 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16453 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
16459 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
16464 xassert (INTEGERP (overlay_arrow_string
));
16465 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
16467 overlay_arrow_seen
= 1;
16470 /* Compute pixel dimensions of this line. */
16471 compute_line_metrics (it
);
16473 /* Remember the position at which this line ends. */
16474 row
->end
= it
->current
;
16476 /* Record whether this row ends inside an ellipsis. */
16477 row
->ends_in_ellipsis_p
16478 = (it
->method
== GET_FROM_DISPLAY_VECTOR
16479 && it
->ellipsis_p
);
16481 /* Save fringe bitmaps in this row. */
16482 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
16483 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
16484 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
16485 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
16487 it
->left_user_fringe_bitmap
= 0;
16488 it
->left_user_fringe_face_id
= 0;
16489 it
->right_user_fringe_bitmap
= 0;
16490 it
->right_user_fringe_face_id
= 0;
16492 /* Maybe set the cursor. */
16493 if (it
->w
->cursor
.vpos
< 0
16494 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
16495 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
16496 && cursor_row_p (it
->w
, row
))
16497 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
16499 /* Highlight trailing whitespace. */
16500 if (!NILP (Vshow_trailing_whitespace
))
16501 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
16503 /* Prepare for the next line. This line starts horizontally at (X
16504 HPOS) = (0 0). Vertical positions are incremented. As a
16505 convenience for the caller, IT->glyph_row is set to the next
16507 it
->current_x
= it
->hpos
= 0;
16508 it
->current_y
+= row
->height
;
16511 it
->start
= it
->current
;
16512 return row
->displays_text_p
;
16517 /***********************************************************************
16519 ***********************************************************************/
16521 /* Redisplay the menu bar in the frame for window W.
16523 The menu bar of X frames that don't have X toolkit support is
16524 displayed in a special window W->frame->menu_bar_window.
16526 The menu bar of terminal frames is treated specially as far as
16527 glyph matrices are concerned. Menu bar lines are not part of
16528 windows, so the update is done directly on the frame matrix rows
16529 for the menu bar. */
16532 display_menu_bar (w
)
16535 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16540 /* Don't do all this for graphical frames. */
16542 if (FRAME_W32_P (f
))
16545 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
16550 if (FRAME_MAC_P (f
))
16554 #ifdef USE_X_TOOLKIT
16555 xassert (!FRAME_WINDOW_P (f
));
16556 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
16557 it
.first_visible_x
= 0;
16558 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16559 #else /* not USE_X_TOOLKIT */
16560 if (FRAME_WINDOW_P (f
))
16562 /* Menu bar lines are displayed in the desired matrix of the
16563 dummy window menu_bar_window. */
16564 struct window
*menu_w
;
16565 xassert (WINDOWP (f
->menu_bar_window
));
16566 menu_w
= XWINDOW (f
->menu_bar_window
);
16567 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
16569 it
.first_visible_x
= 0;
16570 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16574 /* This is a TTY frame, i.e. character hpos/vpos are used as
16576 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
16578 it
.first_visible_x
= 0;
16579 it
.last_visible_x
= FRAME_COLS (f
);
16581 #endif /* not USE_X_TOOLKIT */
16583 if (! mode_line_inverse_video
)
16584 /* Force the menu-bar to be displayed in the default face. */
16585 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16587 /* Clear all rows of the menu bar. */
16588 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
16590 struct glyph_row
*row
= it
.glyph_row
+ i
;
16591 clear_glyph_row (row
);
16592 row
->enabled_p
= 1;
16593 row
->full_width_p
= 1;
16596 /* Display all items of the menu bar. */
16597 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
16598 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
16600 Lisp_Object string
;
16602 /* Stop at nil string. */
16603 string
= AREF (items
, i
+ 1);
16607 /* Remember where item was displayed. */
16608 AREF (items
, i
+ 3) = make_number (it
.hpos
);
16610 /* Display the item, pad with one space. */
16611 if (it
.current_x
< it
.last_visible_x
)
16612 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
16613 SCHARS (string
) + 1, 0, 0, -1);
16616 /* Fill out the line with spaces. */
16617 if (it
.current_x
< it
.last_visible_x
)
16618 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
16620 /* Compute the total height of the lines. */
16621 compute_line_metrics (&it
);
16626 /***********************************************************************
16628 ***********************************************************************/
16630 /* Redisplay mode lines in the window tree whose root is WINDOW. If
16631 FORCE is non-zero, redisplay mode lines unconditionally.
16632 Otherwise, redisplay only mode lines that are garbaged. Value is
16633 the number of windows whose mode lines were redisplayed. */
16636 redisplay_mode_lines (window
, force
)
16637 Lisp_Object window
;
16642 while (!NILP (window
))
16644 struct window
*w
= XWINDOW (window
);
16646 if (WINDOWP (w
->hchild
))
16647 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
16648 else if (WINDOWP (w
->vchild
))
16649 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
16651 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
16652 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
16654 struct text_pos lpoint
;
16655 struct buffer
*old
= current_buffer
;
16657 /* Set the window's buffer for the mode line display. */
16658 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16659 set_buffer_internal_1 (XBUFFER (w
->buffer
));
16661 /* Point refers normally to the selected window. For any
16662 other window, set up appropriate value. */
16663 if (!EQ (window
, selected_window
))
16665 struct text_pos pt
;
16667 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
16668 if (CHARPOS (pt
) < BEGV
)
16669 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16670 else if (CHARPOS (pt
) > (ZV
- 1))
16671 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
16673 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
16676 /* Display mode lines. */
16677 clear_glyph_matrix (w
->desired_matrix
);
16678 if (display_mode_lines (w
))
16681 w
->must_be_updated_p
= 1;
16684 /* Restore old settings. */
16685 set_buffer_internal_1 (old
);
16686 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16696 /* Display the mode and/or top line of window W. Value is the number
16697 of mode lines displayed. */
16700 display_mode_lines (w
)
16703 Lisp_Object old_selected_window
, old_selected_frame
;
16706 old_selected_frame
= selected_frame
;
16707 selected_frame
= w
->frame
;
16708 old_selected_window
= selected_window
;
16709 XSETWINDOW (selected_window
, w
);
16711 /* These will be set while the mode line specs are processed. */
16712 line_number_displayed
= 0;
16713 w
->column_number_displayed
= Qnil
;
16715 if (WINDOW_WANTS_MODELINE_P (w
))
16717 struct window
*sel_w
= XWINDOW (old_selected_window
);
16719 /* Select mode line face based on the real selected window. */
16720 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
16721 current_buffer
->mode_line_format
);
16725 if (WINDOW_WANTS_HEADER_LINE_P (w
))
16727 display_mode_line (w
, HEADER_LINE_FACE_ID
,
16728 current_buffer
->header_line_format
);
16732 selected_frame
= old_selected_frame
;
16733 selected_window
= old_selected_window
;
16738 /* Display mode or top line of window W. FACE_ID specifies which line
16739 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
16740 FORMAT is the mode line format to display. Value is the pixel
16741 height of the mode line displayed. */
16744 display_mode_line (w
, face_id
, format
)
16746 enum face_id face_id
;
16747 Lisp_Object format
;
16751 int count
= SPECPDL_INDEX ();
16753 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16754 /* Don't extend on a previously drawn mode-line.
16755 This may happen if called from pos_visible_p. */
16756 it
.glyph_row
->enabled_p
= 0;
16757 prepare_desired_row (it
.glyph_row
);
16759 it
.glyph_row
->mode_line_p
= 1;
16761 if (! mode_line_inverse_video
)
16762 /* Force the mode-line to be displayed in the default face. */
16763 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16765 record_unwind_protect (unwind_format_mode_line
,
16766 format_mode_line_unwind_data (NULL
, 0));
16768 mode_line_target
= MODE_LINE_DISPLAY
;
16770 /* Temporarily make frame's keyboard the current kboard so that
16771 kboard-local variables in the mode_line_format will get the right
16773 push_kboard (FRAME_KBOARD (it
.f
));
16774 record_unwind_save_match_data ();
16775 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16778 unbind_to (count
, Qnil
);
16780 /* Fill up with spaces. */
16781 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
16783 compute_line_metrics (&it
);
16784 it
.glyph_row
->full_width_p
= 1;
16785 it
.glyph_row
->continued_p
= 0;
16786 it
.glyph_row
->truncated_on_left_p
= 0;
16787 it
.glyph_row
->truncated_on_right_p
= 0;
16789 /* Make a 3D mode-line have a shadow at its right end. */
16790 face
= FACE_FROM_ID (it
.f
, face_id
);
16791 extend_face_to_end_of_line (&it
);
16792 if (face
->box
!= FACE_NO_BOX
)
16794 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
16795 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
16796 last
->right_box_line_p
= 1;
16799 return it
.glyph_row
->height
;
16802 /* Move element ELT in LIST to the front of LIST.
16803 Return the updated list. */
16806 move_elt_to_front (elt
, list
)
16807 Lisp_Object elt
, list
;
16809 register Lisp_Object tail
, prev
;
16810 register Lisp_Object tem
;
16814 while (CONSP (tail
))
16820 /* Splice out the link TAIL. */
16822 list
= XCDR (tail
);
16824 Fsetcdr (prev
, XCDR (tail
));
16826 /* Now make it the first. */
16827 Fsetcdr (tail
, list
);
16832 tail
= XCDR (tail
);
16836 /* Not found--return unchanged LIST. */
16840 /* Contribute ELT to the mode line for window IT->w. How it
16841 translates into text depends on its data type.
16843 IT describes the display environment in which we display, as usual.
16845 DEPTH is the depth in recursion. It is used to prevent
16846 infinite recursion here.
16848 FIELD_WIDTH is the number of characters the display of ELT should
16849 occupy in the mode line, and PRECISION is the maximum number of
16850 characters to display from ELT's representation. See
16851 display_string for details.
16853 Returns the hpos of the end of the text generated by ELT.
16855 PROPS is a property list to add to any string we encounter.
16857 If RISKY is nonzero, remove (disregard) any properties in any string
16858 we encounter, and ignore :eval and :propertize.
16860 The global variable `mode_line_target' determines whether the
16861 output is passed to `store_mode_line_noprop',
16862 `store_mode_line_string', or `display_string'. */
16865 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
16868 int field_width
, precision
;
16869 Lisp_Object elt
, props
;
16872 int n
= 0, field
, prec
;
16877 elt
= build_string ("*too-deep*");
16881 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
16885 /* A string: output it and check for %-constructs within it. */
16889 if (SCHARS (elt
) > 0
16890 && (!NILP (props
) || risky
))
16892 Lisp_Object oprops
, aelt
;
16893 oprops
= Ftext_properties_at (make_number (0), elt
);
16895 /* If the starting string's properties are not what
16896 we want, translate the string. Also, if the string
16897 is risky, do that anyway. */
16899 if (NILP (Fequal (props
, oprops
)) || risky
)
16901 /* If the starting string has properties,
16902 merge the specified ones onto the existing ones. */
16903 if (! NILP (oprops
) && !risky
)
16907 oprops
= Fcopy_sequence (oprops
);
16909 while (CONSP (tem
))
16911 oprops
= Fplist_put (oprops
, XCAR (tem
),
16912 XCAR (XCDR (tem
)));
16913 tem
= XCDR (XCDR (tem
));
16918 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
16919 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
16921 /* AELT is what we want. Move it to the front
16922 without consing. */
16924 mode_line_proptrans_alist
16925 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
16931 /* If AELT has the wrong props, it is useless.
16932 so get rid of it. */
16934 mode_line_proptrans_alist
16935 = Fdelq (aelt
, mode_line_proptrans_alist
);
16937 elt
= Fcopy_sequence (elt
);
16938 Fset_text_properties (make_number (0), Flength (elt
),
16940 /* Add this item to mode_line_proptrans_alist. */
16941 mode_line_proptrans_alist
16942 = Fcons (Fcons (elt
, props
),
16943 mode_line_proptrans_alist
);
16944 /* Truncate mode_line_proptrans_alist
16945 to at most 50 elements. */
16946 tem
= Fnthcdr (make_number (50),
16947 mode_line_proptrans_alist
);
16949 XSETCDR (tem
, Qnil
);
16958 prec
= precision
- n
;
16959 switch (mode_line_target
)
16961 case MODE_LINE_NOPROP
:
16962 case MODE_LINE_TITLE
:
16963 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
16965 case MODE_LINE_STRING
:
16966 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
16968 case MODE_LINE_DISPLAY
:
16969 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
16970 0, prec
, 0, STRING_MULTIBYTE (elt
));
16977 /* Handle the non-literal case. */
16979 while ((precision
<= 0 || n
< precision
)
16980 && SREF (elt
, offset
) != 0
16981 && (mode_line_target
!= MODE_LINE_DISPLAY
16982 || it
->current_x
< it
->last_visible_x
))
16984 int last_offset
= offset
;
16986 /* Advance to end of string or next format specifier. */
16987 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
16990 if (offset
- 1 != last_offset
)
16992 int nchars
, nbytes
;
16994 /* Output to end of string or up to '%'. Field width
16995 is length of string. Don't output more than
16996 PRECISION allows us. */
16999 prec
= c_string_width (SDATA (elt
) + last_offset
,
17000 offset
- last_offset
, precision
- n
,
17003 switch (mode_line_target
)
17005 case MODE_LINE_NOPROP
:
17006 case MODE_LINE_TITLE
:
17007 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
17009 case MODE_LINE_STRING
:
17011 int bytepos
= last_offset
;
17012 int charpos
= string_byte_to_char (elt
, bytepos
);
17013 int endpos
= (precision
<= 0
17014 ? string_byte_to_char (elt
, offset
)
17015 : charpos
+ nchars
);
17017 n
+= store_mode_line_string (NULL
,
17018 Fsubstring (elt
, make_number (charpos
),
17019 make_number (endpos
)),
17023 case MODE_LINE_DISPLAY
:
17025 int bytepos
= last_offset
;
17026 int charpos
= string_byte_to_char (elt
, bytepos
);
17028 if (precision
<= 0)
17029 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
17030 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
17032 STRING_MULTIBYTE (elt
));
17037 else /* c == '%' */
17039 int percent_position
= offset
;
17041 /* Get the specified minimum width. Zero means
17044 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
17045 field
= field
* 10 + c
- '0';
17047 /* Don't pad beyond the total padding allowed. */
17048 if (field_width
- n
> 0 && field
> field_width
- n
)
17049 field
= field_width
- n
;
17051 /* Note that either PRECISION <= 0 or N < PRECISION. */
17052 prec
= precision
- n
;
17055 n
+= display_mode_element (it
, depth
, field
, prec
,
17056 Vglobal_mode_string
, props
,
17061 int bytepos
, charpos
;
17062 unsigned char *spec
;
17064 bytepos
= percent_position
;
17065 charpos
= (STRING_MULTIBYTE (elt
)
17066 ? string_byte_to_char (elt
, bytepos
)
17070 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
17072 switch (mode_line_target
)
17074 case MODE_LINE_NOPROP
:
17075 case MODE_LINE_TITLE
:
17076 n
+= store_mode_line_noprop (spec
, field
, prec
);
17078 case MODE_LINE_STRING
:
17080 int len
= strlen (spec
);
17081 Lisp_Object tem
= make_string (spec
, len
);
17082 props
= Ftext_properties_at (make_number (charpos
), elt
);
17083 /* Should only keep face property in props */
17084 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
17087 case MODE_LINE_DISPLAY
:
17089 int nglyphs_before
, nwritten
;
17091 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17092 nwritten
= display_string (spec
, Qnil
, elt
,
17097 /* Assign to the glyphs written above the
17098 string where the `%x' came from, position
17102 struct glyph
*glyph
17103 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
17107 for (i
= 0; i
< nwritten
; ++i
)
17109 glyph
[i
].object
= elt
;
17110 glyph
[i
].charpos
= charpos
;
17127 /* A symbol: process the value of the symbol recursively
17128 as if it appeared here directly. Avoid error if symbol void.
17129 Special case: if value of symbol is a string, output the string
17132 register Lisp_Object tem
;
17134 /* If the variable is not marked as risky to set
17135 then its contents are risky to use. */
17136 if (NILP (Fget (elt
, Qrisky_local_variable
)))
17139 tem
= Fboundp (elt
);
17142 tem
= Fsymbol_value (elt
);
17143 /* If value is a string, output that string literally:
17144 don't check for % within it. */
17148 if (!EQ (tem
, elt
))
17150 /* Give up right away for nil or t. */
17160 register Lisp_Object car
, tem
;
17162 /* A cons cell: five distinct cases.
17163 If first element is :eval or :propertize, do something special.
17164 If first element is a string or a cons, process all the elements
17165 and effectively concatenate them.
17166 If first element is a negative number, truncate displaying cdr to
17167 at most that many characters. If positive, pad (with spaces)
17168 to at least that many characters.
17169 If first element is a symbol, process the cadr or caddr recursively
17170 according to whether the symbol's value is non-nil or nil. */
17172 if (EQ (car
, QCeval
))
17174 /* An element of the form (:eval FORM) means evaluate FORM
17175 and use the result as mode line elements. */
17180 if (CONSP (XCDR (elt
)))
17183 spec
= safe_eval (XCAR (XCDR (elt
)));
17184 n
+= display_mode_element (it
, depth
, field_width
- n
,
17185 precision
- n
, spec
, props
,
17189 else if (EQ (car
, QCpropertize
))
17191 /* An element of the form (:propertize ELT PROPS...)
17192 means display ELT but applying properties PROPS. */
17197 if (CONSP (XCDR (elt
)))
17198 n
+= display_mode_element (it
, depth
, field_width
- n
,
17199 precision
- n
, XCAR (XCDR (elt
)),
17200 XCDR (XCDR (elt
)), risky
);
17202 else if (SYMBOLP (car
))
17204 tem
= Fboundp (car
);
17208 /* elt is now the cdr, and we know it is a cons cell.
17209 Use its car if CAR has a non-nil value. */
17212 tem
= Fsymbol_value (car
);
17219 /* Symbol's value is nil (or symbol is unbound)
17220 Get the cddr of the original list
17221 and if possible find the caddr and use that. */
17225 else if (!CONSP (elt
))
17230 else if (INTEGERP (car
))
17232 register int lim
= XINT (car
);
17236 /* Negative int means reduce maximum width. */
17237 if (precision
<= 0)
17240 precision
= min (precision
, -lim
);
17244 /* Padding specified. Don't let it be more than
17245 current maximum. */
17247 lim
= min (precision
, lim
);
17249 /* If that's more padding than already wanted, queue it.
17250 But don't reduce padding already specified even if
17251 that is beyond the current truncation point. */
17252 field_width
= max (lim
, field_width
);
17256 else if (STRINGP (car
) || CONSP (car
))
17258 register int limit
= 50;
17259 /* Limit is to protect against circular lists. */
17262 && (precision
<= 0 || n
< precision
))
17264 n
+= display_mode_element (it
, depth
,
17265 /* Do padding only after the last
17266 element in the list. */
17267 (! CONSP (XCDR (elt
))
17270 precision
- n
, XCAR (elt
),
17280 elt
= build_string ("*invalid*");
17284 /* Pad to FIELD_WIDTH. */
17285 if (field_width
> 0 && n
< field_width
)
17287 switch (mode_line_target
)
17289 case MODE_LINE_NOPROP
:
17290 case MODE_LINE_TITLE
:
17291 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
17293 case MODE_LINE_STRING
:
17294 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
17296 case MODE_LINE_DISPLAY
:
17297 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
17306 /* Store a mode-line string element in mode_line_string_list.
17308 If STRING is non-null, display that C string. Otherwise, the Lisp
17309 string LISP_STRING is displayed.
17311 FIELD_WIDTH is the minimum number of output glyphs to produce.
17312 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17313 with spaces. FIELD_WIDTH <= 0 means don't pad.
17315 PRECISION is the maximum number of characters to output from
17316 STRING. PRECISION <= 0 means don't truncate the string.
17318 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
17319 properties to the string.
17321 PROPS are the properties to add to the string.
17322 The mode_line_string_face face property is always added to the string.
17326 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
17328 Lisp_Object lisp_string
;
17337 if (string
!= NULL
)
17339 len
= strlen (string
);
17340 if (precision
> 0 && len
> precision
)
17342 lisp_string
= make_string (string
, len
);
17344 props
= mode_line_string_face_prop
;
17345 else if (!NILP (mode_line_string_face
))
17347 Lisp_Object face
= Fplist_get (props
, Qface
);
17348 props
= Fcopy_sequence (props
);
17350 face
= mode_line_string_face
;
17352 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17353 props
= Fplist_put (props
, Qface
, face
);
17355 Fadd_text_properties (make_number (0), make_number (len
),
17356 props
, lisp_string
);
17360 len
= XFASTINT (Flength (lisp_string
));
17361 if (precision
> 0 && len
> precision
)
17364 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
17367 if (!NILP (mode_line_string_face
))
17371 props
= Ftext_properties_at (make_number (0), lisp_string
);
17372 face
= Fplist_get (props
, Qface
);
17374 face
= mode_line_string_face
;
17376 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17377 props
= Fcons (Qface
, Fcons (face
, Qnil
));
17379 lisp_string
= Fcopy_sequence (lisp_string
);
17382 Fadd_text_properties (make_number (0), make_number (len
),
17383 props
, lisp_string
);
17388 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17392 if (field_width
> len
)
17394 field_width
-= len
;
17395 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17397 Fadd_text_properties (make_number (0), make_number (field_width
),
17398 props
, lisp_string
);
17399 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17407 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17409 doc
: /* Format a string out of a mode line format specification.
17410 First arg FORMAT specifies the mode line format (see `mode-line-format'
17411 for details) to use.
17413 Optional second arg FACE specifies the face property to put
17414 on all characters for which no face is specified.
17415 The value t means whatever face the window's mode line currently uses
17416 \(either `mode-line' or `mode-line-inactive', depending).
17417 A value of nil means the default is no face property.
17418 If FACE is an integer, the value string has no text properties.
17420 Optional third and fourth args WINDOW and BUFFER specify the window
17421 and buffer to use as the context for the formatting (defaults
17422 are the selected window and the window's buffer). */)
17423 (format
, face
, window
, buffer
)
17424 Lisp_Object format
, face
, window
, buffer
;
17429 struct buffer
*old_buffer
= NULL
;
17431 int no_props
= INTEGERP (face
);
17432 int count
= SPECPDL_INDEX ();
17434 int string_start
= 0;
17437 window
= selected_window
;
17438 CHECK_WINDOW (window
);
17439 w
= XWINDOW (window
);
17442 buffer
= w
->buffer
;
17443 CHECK_BUFFER (buffer
);
17445 /* Make formatting the modeline a non-op when noninteractive, otherwise
17446 there will be problems later caused by a partially initialized frame. */
17447 if (NILP (format
) || noninteractive
)
17448 return empty_unibyte_string
;
17456 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
17457 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
17461 face_id
= DEFAULT_FACE_ID
;
17463 if (XBUFFER (buffer
) != current_buffer
)
17464 old_buffer
= current_buffer
;
17466 /* Save things including mode_line_proptrans_alist,
17467 and set that to nil so that we don't alter the outer value. */
17468 record_unwind_protect (unwind_format_mode_line
,
17469 format_mode_line_unwind_data (old_buffer
, 1));
17470 mode_line_proptrans_alist
= Qnil
;
17473 set_buffer_internal_1 (XBUFFER (buffer
));
17475 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17479 mode_line_target
= MODE_LINE_NOPROP
;
17480 mode_line_string_face_prop
= Qnil
;
17481 mode_line_string_list
= Qnil
;
17482 string_start
= MODE_LINE_NOPROP_LEN (0);
17486 mode_line_target
= MODE_LINE_STRING
;
17487 mode_line_string_list
= Qnil
;
17488 mode_line_string_face
= face
;
17489 mode_line_string_face_prop
17490 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
17493 push_kboard (FRAME_KBOARD (it
.f
));
17494 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17499 len
= MODE_LINE_NOPROP_LEN (string_start
);
17500 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
17504 mode_line_string_list
= Fnreverse (mode_line_string_list
);
17505 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
17506 empty_unibyte_string
);
17509 unbind_to (count
, Qnil
);
17513 /* Write a null-terminated, right justified decimal representation of
17514 the positive integer D to BUF using a minimal field width WIDTH. */
17517 pint2str (buf
, width
, d
)
17518 register char *buf
;
17519 register int width
;
17522 register char *p
= buf
;
17530 *p
++ = d
% 10 + '0';
17535 for (width
-= (int) (p
- buf
); width
> 0; --width
)
17546 /* Write a null-terminated, right justified decimal and "human
17547 readable" representation of the nonnegative integer D to BUF using
17548 a minimal field width WIDTH. D should be smaller than 999.5e24. */
17550 static const char power_letter
[] =
17564 pint2hrstr (buf
, width
, d
)
17569 /* We aim to represent the nonnegative integer D as
17570 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
17573 /* -1 means: do not use TENTHS. */
17577 /* Length of QUOTIENT.TENTHS as a string. */
17583 if (1000 <= quotient
)
17585 /* Scale to the appropriate EXPONENT. */
17588 remainder
= quotient
% 1000;
17592 while (1000 <= quotient
);
17594 /* Round to nearest and decide whether to use TENTHS or not. */
17597 tenths
= remainder
/ 100;
17598 if (50 <= remainder
% 100)
17605 if (quotient
== 10)
17613 if (500 <= remainder
)
17615 if (quotient
< 999)
17626 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
17627 if (tenths
== -1 && quotient
<= 99)
17634 p
= psuffix
= buf
+ max (width
, length
);
17636 /* Print EXPONENT. */
17638 *psuffix
++ = power_letter
[exponent
];
17641 /* Print TENTHS. */
17644 *--p
= '0' + tenths
;
17648 /* Print QUOTIENT. */
17651 int digit
= quotient
% 10;
17652 *--p
= '0' + digit
;
17654 while ((quotient
/= 10) != 0);
17656 /* Print leading spaces. */
17661 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
17662 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
17663 type of CODING_SYSTEM. Return updated pointer into BUF. */
17665 static unsigned char invalid_eol_type
[] = "(*invalid*)";
17668 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
17669 Lisp_Object coding_system
;
17670 register char *buf
;
17674 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
17675 const unsigned char *eol_str
;
17677 /* The EOL conversion we are using. */
17678 Lisp_Object eoltype
;
17680 val
= Fget (coding_system
, Qcoding_system
);
17683 if (!VECTORP (val
)) /* Not yet decided. */
17688 eoltype
= eol_mnemonic_undecided
;
17689 /* Don't mention EOL conversion if it isn't decided. */
17693 Lisp_Object eolvalue
;
17695 eolvalue
= Fget (coding_system
, Qeol_type
);
17698 *buf
++ = XFASTINT (AREF (val
, 1));
17702 /* The EOL conversion that is normal on this system. */
17704 if (NILP (eolvalue
)) /* Not yet decided. */
17705 eoltype
= eol_mnemonic_undecided
;
17706 else if (VECTORP (eolvalue
)) /* Not yet decided. */
17707 eoltype
= eol_mnemonic_undecided
;
17708 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
17709 eoltype
= (XFASTINT (eolvalue
) == 0
17710 ? eol_mnemonic_unix
17711 : (XFASTINT (eolvalue
) == 1
17712 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
17718 /* Mention the EOL conversion if it is not the usual one. */
17719 if (STRINGP (eoltype
))
17721 eol_str
= SDATA (eoltype
);
17722 eol_str_len
= SBYTES (eoltype
);
17724 else if (INTEGERP (eoltype
)
17725 && CHAR_VALID_P (XINT (eoltype
), 0))
17727 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
17728 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
17733 eol_str
= invalid_eol_type
;
17734 eol_str_len
= sizeof (invalid_eol_type
) - 1;
17736 bcopy (eol_str
, buf
, eol_str_len
);
17737 buf
+= eol_str_len
;
17743 /* Return a string for the output of a mode line %-spec for window W,
17744 generated by character C. PRECISION >= 0 means don't return a
17745 string longer than that value. FIELD_WIDTH > 0 means pad the
17746 string returned with spaces to that value. Return 1 in *MULTIBYTE
17747 if the result is multibyte text.
17749 Note we operate on the current buffer for most purposes,
17750 the exception being w->base_line_pos. */
17752 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
17755 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
17758 int field_width
, precision
;
17762 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17763 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
17764 struct buffer
*b
= current_buffer
;
17772 if (!NILP (b
->read_only
))
17774 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17779 /* This differs from %* only for a modified read-only buffer. */
17780 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17782 if (!NILP (b
->read_only
))
17787 /* This differs from %* in ignoring read-only-ness. */
17788 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17800 if (command_loop_level
> 5)
17802 p
= decode_mode_spec_buf
;
17803 for (i
= 0; i
< command_loop_level
; i
++)
17806 return decode_mode_spec_buf
;
17814 if (command_loop_level
> 5)
17816 p
= decode_mode_spec_buf
;
17817 for (i
= 0; i
< command_loop_level
; i
++)
17820 return decode_mode_spec_buf
;
17827 /* Let lots_of_dashes be a string of infinite length. */
17828 if (mode_line_target
== MODE_LINE_NOPROP
||
17829 mode_line_target
== MODE_LINE_STRING
)
17831 if (field_width
<= 0
17832 || field_width
> sizeof (lots_of_dashes
))
17834 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
17835 decode_mode_spec_buf
[i
] = '-';
17836 decode_mode_spec_buf
[i
] = '\0';
17837 return decode_mode_spec_buf
;
17840 return lots_of_dashes
;
17848 /* %c and %l are ignored in `frame-title-format'.
17849 (In redisplay_internal, the frame title is drawn _before_ the
17850 windows are updated, so the stuff which depends on actual
17851 window contents (such as %l) may fail to render properly, or
17852 even crash emacs.) */
17853 if (mode_line_target
== MODE_LINE_TITLE
)
17857 int col
= (int) current_column (); /* iftc */
17858 w
->column_number_displayed
= make_number (col
);
17859 pint2str (decode_mode_spec_buf
, field_width
, col
);
17860 return decode_mode_spec_buf
;
17864 #ifndef SYSTEM_MALLOC
17866 if (NILP (Vmemory_full
))
17869 return "!MEM FULL! ";
17876 /* %F displays the frame name. */
17877 if (!NILP (f
->title
))
17878 return (char *) SDATA (f
->title
);
17879 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
17880 return (char *) SDATA (f
->name
);
17889 int size
= ZV
- BEGV
;
17890 pint2str (decode_mode_spec_buf
, field_width
, size
);
17891 return decode_mode_spec_buf
;
17896 int size
= ZV
- BEGV
;
17897 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
17898 return decode_mode_spec_buf
;
17903 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
17904 int topline
, nlines
, junk
, height
;
17906 /* %c and %l are ignored in `frame-title-format'. */
17907 if (mode_line_target
== MODE_LINE_TITLE
)
17910 startpos
= XMARKER (w
->start
)->charpos
;
17911 startpos_byte
= marker_byte_position (w
->start
);
17912 height
= WINDOW_TOTAL_LINES (w
);
17914 /* If we decided that this buffer isn't suitable for line numbers,
17915 don't forget that too fast. */
17916 if (EQ (w
->base_line_pos
, w
->buffer
))
17918 /* But do forget it, if the window shows a different buffer now. */
17919 else if (BUFFERP (w
->base_line_pos
))
17920 w
->base_line_pos
= Qnil
;
17922 /* If the buffer is very big, don't waste time. */
17923 if (INTEGERP (Vline_number_display_limit
)
17924 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
17926 w
->base_line_pos
= Qnil
;
17927 w
->base_line_number
= Qnil
;
17931 if (!NILP (w
->base_line_number
)
17932 && !NILP (w
->base_line_pos
)
17933 && XFASTINT (w
->base_line_pos
) <= startpos
)
17935 line
= XFASTINT (w
->base_line_number
);
17936 linepos
= XFASTINT (w
->base_line_pos
);
17937 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
17942 linepos
= BUF_BEGV (b
);
17943 linepos_byte
= BUF_BEGV_BYTE (b
);
17946 /* Count lines from base line to window start position. */
17947 nlines
= display_count_lines (linepos
, linepos_byte
,
17951 topline
= nlines
+ line
;
17953 /* Determine a new base line, if the old one is too close
17954 or too far away, or if we did not have one.
17955 "Too close" means it's plausible a scroll-down would
17956 go back past it. */
17957 if (startpos
== BUF_BEGV (b
))
17959 w
->base_line_number
= make_number (topline
);
17960 w
->base_line_pos
= make_number (BUF_BEGV (b
));
17962 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
17963 || linepos
== BUF_BEGV (b
))
17965 int limit
= BUF_BEGV (b
);
17966 int limit_byte
= BUF_BEGV_BYTE (b
);
17968 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
17970 if (startpos
- distance
> limit
)
17972 limit
= startpos
- distance
;
17973 limit_byte
= CHAR_TO_BYTE (limit
);
17976 nlines
= display_count_lines (startpos
, startpos_byte
,
17978 - (height
* 2 + 30),
17980 /* If we couldn't find the lines we wanted within
17981 line_number_display_limit_width chars per line,
17982 give up on line numbers for this window. */
17983 if (position
== limit_byte
&& limit
== startpos
- distance
)
17985 w
->base_line_pos
= w
->buffer
;
17986 w
->base_line_number
= Qnil
;
17990 w
->base_line_number
= make_number (topline
- nlines
);
17991 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
17994 /* Now count lines from the start pos to point. */
17995 nlines
= display_count_lines (startpos
, startpos_byte
,
17996 PT_BYTE
, PT
, &junk
);
17998 /* Record that we did display the line number. */
17999 line_number_displayed
= 1;
18001 /* Make the string to show. */
18002 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
18003 return decode_mode_spec_buf
;
18006 char* p
= decode_mode_spec_buf
;
18007 int pad
= field_width
- 2;
18013 return decode_mode_spec_buf
;
18019 obj
= b
->mode_name
;
18023 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
18029 int pos
= marker_position (w
->start
);
18030 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18032 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
18034 if (pos
<= BUF_BEGV (b
))
18039 else if (pos
<= BUF_BEGV (b
))
18043 if (total
> 1000000)
18044 /* Do it differently for a large value, to avoid overflow. */
18045 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18047 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18048 /* We can't normally display a 3-digit number,
18049 so get us a 2-digit number that is close. */
18052 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18053 return decode_mode_spec_buf
;
18057 /* Display percentage of size above the bottom of the screen. */
18060 int toppos
= marker_position (w
->start
);
18061 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
18062 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18064 if (botpos
>= BUF_ZV (b
))
18066 if (toppos
<= BUF_BEGV (b
))
18073 if (total
> 1000000)
18074 /* Do it differently for a large value, to avoid overflow. */
18075 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18077 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18078 /* We can't normally display a 3-digit number,
18079 so get us a 2-digit number that is close. */
18082 if (toppos
<= BUF_BEGV (b
))
18083 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
18085 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18086 return decode_mode_spec_buf
;
18091 /* status of process */
18092 obj
= Fget_buffer_process (Fcurrent_buffer ());
18094 return "no process";
18095 #ifdef subprocesses
18096 obj
= Fsymbol_name (Fprocess_status (obj
));
18103 val
= call1 (intern ("file-remote-p"), current_buffer
->directory
);
18110 case 't': /* indicate TEXT or BINARY */
18111 #ifdef MODE_LINE_BINARY_TEXT
18112 return MODE_LINE_BINARY_TEXT (b
);
18118 /* coding-system (not including end-of-line format) */
18120 /* coding-system (including end-of-line type) */
18122 int eol_flag
= (c
== 'Z');
18123 char *p
= decode_mode_spec_buf
;
18125 if (! FRAME_WINDOW_P (f
))
18127 /* No need to mention EOL here--the terminal never needs
18128 to do EOL conversion. */
18129 p
= decode_mode_spec_coding (FRAME_KEYBOARD_CODING (f
)->symbol
, p
, 0);
18130 p
= decode_mode_spec_coding (FRAME_TERMINAL_CODING (f
)->symbol
, p
, 0);
18132 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
18135 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
18136 #ifdef subprocesses
18137 obj
= Fget_buffer_process (Fcurrent_buffer ());
18138 if (PROCESSP (obj
))
18140 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
18142 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
18145 #endif /* subprocesses */
18148 return decode_mode_spec_buf
;
18154 *multibyte
= STRING_MULTIBYTE (obj
);
18155 return (char *) SDATA (obj
);
18162 /* Count up to COUNT lines starting from START / START_BYTE.
18163 But don't go beyond LIMIT_BYTE.
18164 Return the number of lines thus found (always nonnegative).
18166 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
18169 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
18170 int start
, start_byte
, limit_byte
, count
;
18173 register unsigned char *cursor
;
18174 unsigned char *base
;
18176 register int ceiling
;
18177 register unsigned char *ceiling_addr
;
18178 int orig_count
= count
;
18180 /* If we are not in selective display mode,
18181 check only for newlines. */
18182 int selective_display
= (!NILP (current_buffer
->selective_display
)
18183 && !INTEGERP (current_buffer
->selective_display
));
18187 while (start_byte
< limit_byte
)
18189 ceiling
= BUFFER_CEILING_OF (start_byte
);
18190 ceiling
= min (limit_byte
- 1, ceiling
);
18191 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
18192 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
18195 if (selective_display
)
18196 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
18199 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
18202 if (cursor
!= ceiling_addr
)
18206 start_byte
+= cursor
- base
+ 1;
18207 *byte_pos_ptr
= start_byte
;
18211 if (++cursor
== ceiling_addr
)
18217 start_byte
+= cursor
- base
;
18222 while (start_byte
> limit_byte
)
18224 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
18225 ceiling
= max (limit_byte
, ceiling
);
18226 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
18227 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
18230 if (selective_display
)
18231 while (--cursor
!= ceiling_addr
18232 && *cursor
!= '\n' && *cursor
!= 015)
18235 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
18238 if (cursor
!= ceiling_addr
)
18242 start_byte
+= cursor
- base
+ 1;
18243 *byte_pos_ptr
= start_byte
;
18244 /* When scanning backwards, we should
18245 not count the newline posterior to which we stop. */
18246 return - orig_count
- 1;
18252 /* Here we add 1 to compensate for the last decrement
18253 of CURSOR, which took it past the valid range. */
18254 start_byte
+= cursor
- base
+ 1;
18258 *byte_pos_ptr
= limit_byte
;
18261 return - orig_count
+ count
;
18262 return orig_count
- count
;
18268 /***********************************************************************
18270 ***********************************************************************/
18272 /* Display a NUL-terminated string, starting with index START.
18274 If STRING is non-null, display that C string. Otherwise, the Lisp
18275 string LISP_STRING is displayed.
18277 If FACE_STRING is not nil, FACE_STRING_POS is a position in
18278 FACE_STRING. Display STRING or LISP_STRING with the face at
18279 FACE_STRING_POS in FACE_STRING:
18281 Display the string in the environment given by IT, but use the
18282 standard display table, temporarily.
18284 FIELD_WIDTH is the minimum number of output glyphs to produce.
18285 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18286 with spaces. If STRING has more characters, more than FIELD_WIDTH
18287 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
18289 PRECISION is the maximum number of characters to output from
18290 STRING. PRECISION < 0 means don't truncate the string.
18292 This is roughly equivalent to printf format specifiers:
18294 FIELD_WIDTH PRECISION PRINTF
18295 ----------------------------------------
18301 MULTIBYTE zero means do not display multibyte chars, > 0 means do
18302 display them, and < 0 means obey the current buffer's value of
18303 enable_multibyte_characters.
18305 Value is the number of columns displayed. */
18308 display_string (string
, lisp_string
, face_string
, face_string_pos
,
18309 start
, it
, field_width
, precision
, max_x
, multibyte
)
18310 unsigned char *string
;
18311 Lisp_Object lisp_string
;
18312 Lisp_Object face_string
;
18313 int face_string_pos
;
18316 int field_width
, precision
, max_x
;
18319 int hpos_at_start
= it
->hpos
;
18320 int saved_face_id
= it
->face_id
;
18321 struct glyph_row
*row
= it
->glyph_row
;
18323 /* Initialize the iterator IT for iteration over STRING beginning
18324 with index START. */
18325 reseat_to_string (it
, string
, lisp_string
, start
,
18326 precision
, field_width
, multibyte
);
18328 /* If displaying STRING, set up the face of the iterator
18329 from LISP_STRING, if that's given. */
18330 if (STRINGP (face_string
))
18336 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
18337 0, it
->region_beg_charpos
,
18338 it
->region_end_charpos
,
18339 &endptr
, it
->base_face_id
, 0);
18340 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18341 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
18344 /* Set max_x to the maximum allowed X position. Don't let it go
18345 beyond the right edge of the window. */
18347 max_x
= it
->last_visible_x
;
18349 max_x
= min (max_x
, it
->last_visible_x
);
18351 /* Skip over display elements that are not visible. because IT->w is
18353 if (it
->current_x
< it
->first_visible_x
)
18354 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
18355 MOVE_TO_POS
| MOVE_TO_X
);
18357 row
->ascent
= it
->max_ascent
;
18358 row
->height
= it
->max_ascent
+ it
->max_descent
;
18359 row
->phys_ascent
= it
->max_phys_ascent
;
18360 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18361 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18363 /* This condition is for the case that we are called with current_x
18364 past last_visible_x. */
18365 while (it
->current_x
< max_x
)
18367 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
18369 /* Get the next display element. */
18370 if (!get_next_display_element (it
))
18373 /* Produce glyphs. */
18374 x_before
= it
->current_x
;
18375 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18376 PRODUCE_GLYPHS (it
);
18378 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
18381 while (i
< nglyphs
)
18383 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18385 if (!it
->truncate_lines_p
18386 && x
+ glyph
->pixel_width
> max_x
)
18388 /* End of continued line or max_x reached. */
18389 if (CHAR_GLYPH_PADDING_P (*glyph
))
18391 /* A wide character is unbreakable. */
18392 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18393 it
->current_x
= x_before
;
18397 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18402 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
18404 /* Glyph is at least partially visible. */
18406 if (x
< it
->first_visible_x
)
18407 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18411 /* Glyph is off the left margin of the display area.
18412 Should not happen. */
18416 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18417 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18418 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18419 row
->phys_height
= max (row
->phys_height
,
18420 it
->max_phys_ascent
+ it
->max_phys_descent
);
18421 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18422 it
->max_extra_line_spacing
);
18423 x
+= glyph
->pixel_width
;
18427 /* Stop if max_x reached. */
18431 /* Stop at line ends. */
18432 if (ITERATOR_AT_END_OF_LINE_P (it
))
18434 it
->continuation_lines_width
= 0;
18438 set_iterator_to_next (it
, 1);
18440 /* Stop if truncating at the right edge. */
18441 if (it
->truncate_lines_p
18442 && it
->current_x
>= it
->last_visible_x
)
18444 /* Add truncation mark, but don't do it if the line is
18445 truncated at a padding space. */
18446 if (IT_CHARPOS (*it
) < it
->string_nchars
)
18448 if (!FRAME_WINDOW_P (it
->f
))
18452 if (it
->current_x
> it
->last_visible_x
)
18454 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18455 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18457 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18459 row
->used
[TEXT_AREA
] = i
;
18460 produce_special_glyphs (it
, IT_TRUNCATION
);
18463 produce_special_glyphs (it
, IT_TRUNCATION
);
18465 it
->glyph_row
->truncated_on_right_p
= 1;
18471 /* Maybe insert a truncation at the left. */
18472 if (it
->first_visible_x
18473 && IT_CHARPOS (*it
) > 0)
18475 if (!FRAME_WINDOW_P (it
->f
))
18476 insert_left_trunc_glyphs (it
);
18477 it
->glyph_row
->truncated_on_left_p
= 1;
18480 it
->face_id
= saved_face_id
;
18482 /* Value is number of columns displayed. */
18483 return it
->hpos
- hpos_at_start
;
18488 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
18489 appears as an element of LIST or as the car of an element of LIST.
18490 If PROPVAL is a list, compare each element against LIST in that
18491 way, and return 1/2 if any element of PROPVAL is found in LIST.
18492 Otherwise return 0. This function cannot quit.
18493 The return value is 2 if the text is invisible but with an ellipsis
18494 and 1 if it's invisible and without an ellipsis. */
18497 invisible_p (propval
, list
)
18498 register Lisp_Object propval
;
18501 register Lisp_Object tail
, proptail
;
18503 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18505 register Lisp_Object tem
;
18507 if (EQ (propval
, tem
))
18509 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
18510 return NILP (XCDR (tem
)) ? 1 : 2;
18513 if (CONSP (propval
))
18515 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
18517 Lisp_Object propelt
;
18518 propelt
= XCAR (proptail
);
18519 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18521 register Lisp_Object tem
;
18523 if (EQ (propelt
, tem
))
18525 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
18526 return NILP (XCDR (tem
)) ? 1 : 2;
18534 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
18535 doc
: /* Non-nil if the property makes the text invisible.
18536 POS-OR-PROP can be a marker or number, in which case it is taken to be
18537 a position in the current buffer and the value of the `invisible' property
18538 is checked; or it can be some other value, which is then presumed to be the
18539 value of the `invisible' property of the text of interest.
18540 The non-nil value returned can be t for truly invisible text or something
18541 else if the text is replaced by an ellipsis. */)
18543 Lisp_Object pos_or_prop
;
18546 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
18547 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
18549 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
18550 return (invis
== 0 ? Qnil
18552 : make_number (invis
));
18555 /* Calculate a width or height in pixels from a specification using
18556 the following elements:
18559 NUM - a (fractional) multiple of the default font width/height
18560 (NUM) - specifies exactly NUM pixels
18561 UNIT - a fixed number of pixels, see below.
18562 ELEMENT - size of a display element in pixels, see below.
18563 (NUM . SPEC) - equals NUM * SPEC
18564 (+ SPEC SPEC ...) - add pixel values
18565 (- SPEC SPEC ...) - subtract pixel values
18566 (- SPEC) - negate pixel value
18569 INT or FLOAT - a number constant
18570 SYMBOL - use symbol's (buffer local) variable binding.
18573 in - pixels per inch *)
18574 mm - pixels per 1/1000 meter *)
18575 cm - pixels per 1/100 meter *)
18576 width - width of current font in pixels.
18577 height - height of current font in pixels.
18579 *) using the ratio(s) defined in display-pixels-per-inch.
18583 left-fringe - left fringe width in pixels
18584 right-fringe - right fringe width in pixels
18586 left-margin - left margin width in pixels
18587 right-margin - right margin width in pixels
18589 scroll-bar - scroll-bar area width in pixels
18593 Pixels corresponding to 5 inches:
18596 Total width of non-text areas on left side of window (if scroll-bar is on left):
18597 '(space :width (+ left-fringe left-margin scroll-bar))
18599 Align to first text column (in header line):
18600 '(space :align-to 0)
18602 Align to middle of text area minus half the width of variable `my-image'
18603 containing a loaded image:
18604 '(space :align-to (0.5 . (- text my-image)))
18606 Width of left margin minus width of 1 character in the default font:
18607 '(space :width (- left-margin 1))
18609 Width of left margin minus width of 2 characters in the current font:
18610 '(space :width (- left-margin (2 . width)))
18612 Center 1 character over left-margin (in header line):
18613 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
18615 Different ways to express width of left fringe plus left margin minus one pixel:
18616 '(space :width (- (+ left-fringe left-margin) (1)))
18617 '(space :width (+ left-fringe left-margin (- (1))))
18618 '(space :width (+ left-fringe left-margin (-1)))
18622 #define NUMVAL(X) \
18623 ((INTEGERP (X) || FLOATP (X)) \
18628 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
18633 int width_p
, *align_to
;
18637 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
18638 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
18641 return OK_PIXELS (0);
18643 xassert (FRAME_LIVE_P (it
->f
));
18645 if (SYMBOLP (prop
))
18647 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18649 char *unit
= SDATA (SYMBOL_NAME (prop
));
18651 if (unit
[0] == 'i' && unit
[1] == 'n')
18653 else if (unit
[0] == 'm' && unit
[1] == 'm')
18655 else if (unit
[0] == 'c' && unit
[1] == 'm')
18662 #ifdef HAVE_WINDOW_SYSTEM
18663 if (FRAME_WINDOW_P (it
->f
)
18665 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
18666 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
18668 return OK_PIXELS (ppi
/ pixels
);
18671 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18672 || (CONSP (Vdisplay_pixels_per_inch
)
18674 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18675 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18677 return OK_PIXELS (ppi
/ pixels
);
18683 #ifdef HAVE_WINDOW_SYSTEM
18684 if (EQ (prop
, Qheight
))
18685 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
18686 if (EQ (prop
, Qwidth
))
18687 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
18689 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
18690 return OK_PIXELS (1);
18693 if (EQ (prop
, Qtext
))
18694 return OK_PIXELS (width_p
18695 ? window_box_width (it
->w
, TEXT_AREA
)
18696 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
18698 if (align_to
&& *align_to
< 0)
18701 if (EQ (prop
, Qleft
))
18702 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
18703 if (EQ (prop
, Qright
))
18704 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
18705 if (EQ (prop
, Qcenter
))
18706 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
18707 + window_box_width (it
->w
, TEXT_AREA
) / 2);
18708 if (EQ (prop
, Qleft_fringe
))
18709 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18710 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
18711 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
18712 if (EQ (prop
, Qright_fringe
))
18713 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18714 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18715 : window_box_right_offset (it
->w
, TEXT_AREA
));
18716 if (EQ (prop
, Qleft_margin
))
18717 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
18718 if (EQ (prop
, Qright_margin
))
18719 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
18720 if (EQ (prop
, Qscroll_bar
))
18721 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18723 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18724 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18725 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18730 if (EQ (prop
, Qleft_fringe
))
18731 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18732 if (EQ (prop
, Qright_fringe
))
18733 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18734 if (EQ (prop
, Qleft_margin
))
18735 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18736 if (EQ (prop
, Qright_margin
))
18737 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18738 if (EQ (prop
, Qscroll_bar
))
18739 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18742 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18745 if (INTEGERP (prop
) || FLOATP (prop
))
18747 int base_unit
= (width_p
18748 ? FRAME_COLUMN_WIDTH (it
->f
)
18749 : FRAME_LINE_HEIGHT (it
->f
));
18750 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18755 Lisp_Object car
= XCAR (prop
);
18756 Lisp_Object cdr
= XCDR (prop
);
18760 #ifdef HAVE_WINDOW_SYSTEM
18761 if (FRAME_WINDOW_P (it
->f
)
18762 && valid_image_p (prop
))
18764 int id
= lookup_image (it
->f
, prop
);
18765 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
18767 return OK_PIXELS (width_p
? img
->width
: img
->height
);
18770 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18776 while (CONSP (cdr
))
18778 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
18779 font
, width_p
, align_to
))
18782 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18787 if (EQ (car
, Qminus
))
18789 return OK_PIXELS (pixels
);
18792 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18795 if (INTEGERP (car
) || FLOATP (car
))
18798 pixels
= XFLOATINT (car
);
18800 return OK_PIXELS (pixels
);
18801 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
18802 font
, width_p
, align_to
))
18803 return OK_PIXELS (pixels
* fact
);
18814 /***********************************************************************
18816 ***********************************************************************/
18818 #ifdef HAVE_WINDOW_SYSTEM
18823 dump_glyph_string (s
)
18824 struct glyph_string
*s
;
18826 fprintf (stderr
, "glyph string\n");
18827 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
18828 s
->x
, s
->y
, s
->width
, s
->height
);
18829 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
18830 fprintf (stderr
, " hl = %d\n", s
->hl
);
18831 fprintf (stderr
, " left overhang = %d, right = %d\n",
18832 s
->left_overhang
, s
->right_overhang
);
18833 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
18834 fprintf (stderr
, " extends to end of line = %d\n",
18835 s
->extends_to_end_of_line_p
);
18836 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
18837 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
18840 #endif /* GLYPH_DEBUG */
18842 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
18843 of XChar2b structures for S; it can't be allocated in
18844 init_glyph_string because it must be allocated via `alloca'. W
18845 is the window on which S is drawn. ROW and AREA are the glyph row
18846 and area within the row from which S is constructed. START is the
18847 index of the first glyph structure covered by S. HL is a
18848 face-override for drawing S. */
18851 #define OPTIONAL_HDC(hdc) hdc,
18852 #define DECLARE_HDC(hdc) HDC hdc;
18853 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
18854 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
18857 #ifndef OPTIONAL_HDC
18858 #define OPTIONAL_HDC(hdc)
18859 #define DECLARE_HDC(hdc)
18860 #define ALLOCATE_HDC(hdc, f)
18861 #define RELEASE_HDC(hdc, f)
18865 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
18866 struct glyph_string
*s
;
18870 struct glyph_row
*row
;
18871 enum glyph_row_area area
;
18873 enum draw_glyphs_face hl
;
18875 bzero (s
, sizeof *s
);
18877 s
->f
= XFRAME (w
->frame
);
18881 s
->display
= FRAME_X_DISPLAY (s
->f
);
18882 s
->window
= FRAME_X_WINDOW (s
->f
);
18883 s
->char2b
= char2b
;
18887 s
->first_glyph
= row
->glyphs
[area
] + start
;
18888 s
->height
= row
->height
;
18889 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
18891 /* Display the internal border below the tool-bar window. */
18892 if (WINDOWP (s
->f
->tool_bar_window
)
18893 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
18894 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
18896 s
->ybase
= s
->y
+ row
->ascent
;
18900 /* Append the list of glyph strings with head H and tail T to the list
18901 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
18904 append_glyph_string_lists (head
, tail
, h
, t
)
18905 struct glyph_string
**head
, **tail
;
18906 struct glyph_string
*h
, *t
;
18920 /* Prepend the list of glyph strings with head H and tail T to the
18921 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
18925 prepend_glyph_string_lists (head
, tail
, h
, t
)
18926 struct glyph_string
**head
, **tail
;
18927 struct glyph_string
*h
, *t
;
18941 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
18942 Set *HEAD and *TAIL to the resulting list. */
18945 append_glyph_string (head
, tail
, s
)
18946 struct glyph_string
**head
, **tail
;
18947 struct glyph_string
*s
;
18949 s
->next
= s
->prev
= NULL
;
18950 append_glyph_string_lists (head
, tail
, s
, s
);
18954 /* Get face and two-byte form of character glyph GLYPH on frame F.
18955 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
18956 a pointer to a realized face that is ready for display. */
18958 static INLINE
struct face
*
18959 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
18961 struct glyph
*glyph
;
18967 xassert (glyph
->type
== CHAR_GLYPH
);
18968 face
= FACE_FROM_ID (f
, glyph
->face_id
);
18973 if (!glyph
->multibyte_p
)
18975 /* Unibyte case. We don't have to encode, but we have to make
18976 sure to use a face suitable for unibyte. */
18977 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18979 else if (glyph
->u
.ch
< 128)
18981 /* Case of ASCII in a face known to fit ASCII. */
18982 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18986 int c1
, c2
, charset
;
18988 /* Split characters into bytes. If c2 is -1 afterwards, C is
18989 really a one-byte character so that byte1 is zero. */
18990 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
18992 STORE_XCHAR2B (char2b
, c1
, c2
);
18994 STORE_XCHAR2B (char2b
, 0, c1
);
18996 /* Maybe encode the character in *CHAR2B. */
18997 if (charset
!= CHARSET_ASCII
)
18999 struct font_info
*font_info
19000 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
19003 = FRAME_RIF (f
)->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
19007 /* Make sure X resources of the face are allocated. */
19008 xassert (face
!= NULL
);
19009 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19014 /* Fill glyph string S with composition components specified by S->cmp.
19016 FACES is an array of faces for all components of this composition.
19017 S->gidx is the index of the first component for S.
19019 OVERLAPS non-zero means S should draw the foreground only, and use
19020 its physical height for clipping. See also draw_glyphs.
19022 Value is the index of a component not in S. */
19025 fill_composite_glyph_string (s
, faces
, overlaps
)
19026 struct glyph_string
*s
;
19027 struct face
**faces
;
19034 s
->for_overlaps
= overlaps
;
19036 s
->face
= faces
[s
->gidx
];
19037 s
->font
= s
->face
->font
;
19038 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
19040 /* For all glyphs of this composition, starting at the offset
19041 S->gidx, until we reach the end of the definition or encounter a
19042 glyph that requires the different face, add it to S. */
19044 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
19047 /* All glyph strings for the same composition has the same width,
19048 i.e. the width set for the first component of the composition. */
19050 s
->width
= s
->first_glyph
->pixel_width
;
19052 /* If the specified font could not be loaded, use the frame's
19053 default font, but record the fact that we couldn't load it in
19054 the glyph string so that we can draw rectangles for the
19055 characters of the glyph string. */
19056 if (s
->font
== NULL
)
19058 s
->font_not_found_p
= 1;
19059 s
->font
= FRAME_FONT (s
->f
);
19062 /* Adjust base line for subscript/superscript text. */
19063 s
->ybase
+= s
->first_glyph
->voffset
;
19065 xassert (s
->face
&& s
->face
->gc
);
19067 /* This glyph string must always be drawn with 16-bit functions. */
19070 return s
->gidx
+ s
->nchars
;
19074 /* Fill glyph string S from a sequence of character glyphs.
19076 FACE_ID is the face id of the string. START is the index of the
19077 first glyph to consider, END is the index of the last + 1.
19078 OVERLAPS non-zero means S should draw the foreground only, and use
19079 its physical height for clipping. See also draw_glyphs.
19081 Value is the index of the first glyph not in S. */
19084 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
19085 struct glyph_string
*s
;
19087 int start
, end
, overlaps
;
19089 struct glyph
*glyph
, *last
;
19091 int glyph_not_available_p
;
19093 xassert (s
->f
== XFRAME (s
->w
->frame
));
19094 xassert (s
->nchars
== 0);
19095 xassert (start
>= 0 && end
> start
);
19097 s
->for_overlaps
= overlaps
,
19098 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19099 last
= s
->row
->glyphs
[s
->area
] + end
;
19100 voffset
= glyph
->voffset
;
19102 glyph_not_available_p
= glyph
->glyph_not_available_p
;
19104 while (glyph
< last
19105 && glyph
->type
== CHAR_GLYPH
19106 && glyph
->voffset
== voffset
19107 /* Same face id implies same font, nowadays. */
19108 && glyph
->face_id
== face_id
19109 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
19113 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
19114 s
->char2b
+ s
->nchars
,
19116 s
->two_byte_p
= two_byte_p
;
19118 xassert (s
->nchars
<= end
- start
);
19119 s
->width
+= glyph
->pixel_width
;
19123 s
->font
= s
->face
->font
;
19124 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
19126 /* If the specified font could not be loaded, use the frame's font,
19127 but record the fact that we couldn't load it in
19128 S->font_not_found_p so that we can draw rectangles for the
19129 characters of the glyph string. */
19130 if (s
->font
== NULL
|| glyph_not_available_p
)
19132 s
->font_not_found_p
= 1;
19133 s
->font
= FRAME_FONT (s
->f
);
19136 /* Adjust base line for subscript/superscript text. */
19137 s
->ybase
+= voffset
;
19139 xassert (s
->face
&& s
->face
->gc
);
19140 return glyph
- s
->row
->glyphs
[s
->area
];
19144 /* Fill glyph string S from image glyph S->first_glyph. */
19147 fill_image_glyph_string (s
)
19148 struct glyph_string
*s
;
19150 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
19151 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
19153 s
->slice
= s
->first_glyph
->slice
;
19154 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
19155 s
->font
= s
->face
->font
;
19156 s
->width
= s
->first_glyph
->pixel_width
;
19158 /* Adjust base line for subscript/superscript text. */
19159 s
->ybase
+= s
->first_glyph
->voffset
;
19163 /* Fill glyph string S from a sequence of stretch glyphs.
19165 ROW is the glyph row in which the glyphs are found, AREA is the
19166 area within the row. START is the index of the first glyph to
19167 consider, END is the index of the last + 1.
19169 Value is the index of the first glyph not in S. */
19172 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
19173 struct glyph_string
*s
;
19174 struct glyph_row
*row
;
19175 enum glyph_row_area area
;
19178 struct glyph
*glyph
, *last
;
19179 int voffset
, face_id
;
19181 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
19183 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19184 last
= s
->row
->glyphs
[s
->area
] + end
;
19185 face_id
= glyph
->face_id
;
19186 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19187 s
->font
= s
->face
->font
;
19188 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
19189 s
->width
= glyph
->pixel_width
;
19191 voffset
= glyph
->voffset
;
19195 && glyph
->type
== STRETCH_GLYPH
19196 && glyph
->voffset
== voffset
19197 && glyph
->face_id
== face_id
);
19199 s
->width
+= glyph
->pixel_width
;
19201 /* Adjust base line for subscript/superscript text. */
19202 s
->ybase
+= voffset
;
19204 /* The case that face->gc == 0 is handled when drawing the glyph
19205 string by calling PREPARE_FACE_FOR_DISPLAY. */
19207 return glyph
- s
->row
->glyphs
[s
->area
];
19212 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
19213 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
19214 assumed to be zero. */
19217 x_get_glyph_overhangs (glyph
, f
, left
, right
)
19218 struct glyph
*glyph
;
19222 *left
= *right
= 0;
19224 if (glyph
->type
== CHAR_GLYPH
)
19228 struct font_info
*font_info
;
19232 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
19234 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
19235 if (font
/* ++KFS: Should this be font_info ? */
19236 && (pcm
= FRAME_RIF (f
)->per_char_metric (font
, &char2b
, glyph
->font_type
)))
19238 if (pcm
->rbearing
> pcm
->width
)
19239 *right
= pcm
->rbearing
- pcm
->width
;
19240 if (pcm
->lbearing
< 0)
19241 *left
= -pcm
->lbearing
;
19247 /* Return the index of the first glyph preceding glyph string S that
19248 is overwritten by S because of S's left overhang. Value is -1
19249 if no glyphs are overwritten. */
19252 left_overwritten (s
)
19253 struct glyph_string
*s
;
19257 if (s
->left_overhang
)
19260 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19261 int first
= s
->first_glyph
- glyphs
;
19263 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
19264 x
-= glyphs
[i
].pixel_width
;
19275 /* Return the index of the first glyph preceding glyph string S that
19276 is overwriting S because of its right overhang. Value is -1 if no
19277 glyph in front of S overwrites S. */
19280 left_overwriting (s
)
19281 struct glyph_string
*s
;
19284 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19285 int first
= s
->first_glyph
- glyphs
;
19289 for (i
= first
- 1; i
>= 0; --i
)
19292 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19295 x
-= glyphs
[i
].pixel_width
;
19302 /* Return the index of the last glyph following glyph string S that is
19303 not overwritten by S because of S's right overhang. Value is -1 if
19304 no such glyph is found. */
19307 right_overwritten (s
)
19308 struct glyph_string
*s
;
19312 if (s
->right_overhang
)
19315 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19316 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19317 int end
= s
->row
->used
[s
->area
];
19319 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
19320 x
+= glyphs
[i
].pixel_width
;
19329 /* Return the index of the last glyph following glyph string S that
19330 overwrites S because of its left overhang. Value is negative
19331 if no such glyph is found. */
19334 right_overwriting (s
)
19335 struct glyph_string
*s
;
19338 int end
= s
->row
->used
[s
->area
];
19339 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19340 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19344 for (i
= first
; i
< end
; ++i
)
19347 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19350 x
+= glyphs
[i
].pixel_width
;
19357 /* Get face and two-byte form of character C in face FACE_ID on frame
19358 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19359 means we want to display multibyte text. DISPLAY_P non-zero means
19360 make sure that X resources for the face returned are allocated.
19361 Value is a pointer to a realized face that is ready for display if
19362 DISPLAY_P is non-zero. */
19364 static INLINE
struct face
*
19365 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
19369 int multibyte_p
, display_p
;
19371 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19375 /* Unibyte case. We don't have to encode, but we have to make
19376 sure to use a face suitable for unibyte. */
19377 STORE_XCHAR2B (char2b
, 0, c
);
19378 face_id
= FACE_FOR_CHAR (f
, face
, c
);
19379 face
= FACE_FROM_ID (f
, face_id
);
19383 /* Case of ASCII in a face known to fit ASCII. */
19384 STORE_XCHAR2B (char2b
, 0, c
);
19388 int c1
, c2
, charset
;
19390 /* Split characters into bytes. If c2 is -1 afterwards, C is
19391 really a one-byte character so that byte1 is zero. */
19392 SPLIT_CHAR (c
, charset
, c1
, c2
);
19394 STORE_XCHAR2B (char2b
, c1
, c2
);
19396 STORE_XCHAR2B (char2b
, 0, c1
);
19398 /* Maybe encode the character in *CHAR2B. */
19399 if (face
->font
!= NULL
)
19401 struct font_info
*font_info
19402 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
19404 FRAME_RIF (f
)->encode_char (c
, char2b
, font_info
, 0);
19408 /* Make sure X resources of the face are allocated. */
19409 #ifdef HAVE_X_WINDOWS
19413 xassert (face
!= NULL
);
19414 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19421 /* Set background width of glyph string S. START is the index of the
19422 first glyph following S. LAST_X is the right-most x-position + 1
19423 in the drawing area. */
19426 set_glyph_string_background_width (s
, start
, last_x
)
19427 struct glyph_string
*s
;
19431 /* If the face of this glyph string has to be drawn to the end of
19432 the drawing area, set S->extends_to_end_of_line_p. */
19434 if (start
== s
->row
->used
[s
->area
]
19435 && s
->area
== TEXT_AREA
19436 && ((s
->row
->fill_line_p
19437 && (s
->hl
== DRAW_NORMAL_TEXT
19438 || s
->hl
== DRAW_IMAGE_RAISED
19439 || s
->hl
== DRAW_IMAGE_SUNKEN
))
19440 || s
->hl
== DRAW_MOUSE_FACE
))
19441 s
->extends_to_end_of_line_p
= 1;
19443 /* If S extends its face to the end of the line, set its
19444 background_width to the distance to the right edge of the drawing
19446 if (s
->extends_to_end_of_line_p
)
19447 s
->background_width
= last_x
- s
->x
+ 1;
19449 s
->background_width
= s
->width
;
19453 /* Compute overhangs and x-positions for glyph string S and its
19454 predecessors, or successors. X is the starting x-position for S.
19455 BACKWARD_P non-zero means process predecessors. */
19458 compute_overhangs_and_x (s
, x
, backward_p
)
19459 struct glyph_string
*s
;
19467 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
19468 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
19478 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
19479 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
19489 /* The following macros are only called from draw_glyphs below.
19490 They reference the following parameters of that function directly:
19491 `w', `row', `area', and `overlap_p'
19492 as well as the following local variables:
19493 `s', `f', and `hdc' (in W32) */
19496 /* On W32, silently add local `hdc' variable to argument list of
19497 init_glyph_string. */
19498 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19499 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
19501 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19502 init_glyph_string (s, char2b, w, row, area, start, hl)
19505 /* Add a glyph string for a stretch glyph to the list of strings
19506 between HEAD and TAIL. START is the index of the stretch glyph in
19507 row area AREA of glyph row ROW. END is the index of the last glyph
19508 in that glyph row area. X is the current output position assigned
19509 to the new glyph string constructed. HL overrides that face of the
19510 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19511 is the right-most x-position of the drawing area. */
19513 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
19514 and below -- keep them on one line. */
19515 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19518 s = (struct glyph_string *) alloca (sizeof *s); \
19519 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19520 START = fill_stretch_glyph_string (s, row, area, START, END); \
19521 append_glyph_string (&HEAD, &TAIL, s); \
19527 /* Add a glyph string for an image glyph to the list of strings
19528 between HEAD and TAIL. START is the index of the image glyph in
19529 row area AREA of glyph row ROW. END is the index of the last glyph
19530 in that glyph row area. X is the current output position assigned
19531 to the new glyph string constructed. HL overrides that face of the
19532 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19533 is the right-most x-position of the drawing area. */
19535 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19538 s = (struct glyph_string *) alloca (sizeof *s); \
19539 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19540 fill_image_glyph_string (s); \
19541 append_glyph_string (&HEAD, &TAIL, s); \
19548 /* Add a glyph string for a sequence of character glyphs to the list
19549 of strings between HEAD and TAIL. START is the index of the first
19550 glyph in row area AREA of glyph row ROW that is part of the new
19551 glyph string. END is the index of the last glyph in that glyph row
19552 area. X is the current output position assigned to the new glyph
19553 string constructed. HL overrides that face of the glyph; e.g. it
19554 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
19555 right-most x-position of the drawing area. */
19557 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19563 c = (row)->glyphs[area][START].u.ch; \
19564 face_id = (row)->glyphs[area][START].face_id; \
19566 s = (struct glyph_string *) alloca (sizeof *s); \
19567 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
19568 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
19569 append_glyph_string (&HEAD, &TAIL, s); \
19571 START = fill_glyph_string (s, face_id, START, END, overlaps); \
19576 /* Add a glyph string for a composite sequence to the list of strings
19577 between HEAD and TAIL. START is the index of the first glyph in
19578 row area AREA of glyph row ROW that is part of the new glyph
19579 string. END is the index of the last glyph in that glyph row area.
19580 X is the current output position assigned to the new glyph string
19581 constructed. HL overrides that face of the glyph; e.g. it is
19582 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
19583 x-position of the drawing area. */
19585 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19587 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
19588 int face_id = (row)->glyphs[area][START].face_id; \
19589 struct face *base_face = FACE_FROM_ID (f, face_id); \
19590 struct composition *cmp = composition_table[cmp_id]; \
19591 int glyph_len = cmp->glyph_len; \
19593 struct face **faces; \
19594 struct glyph_string *first_s = NULL; \
19597 base_face = base_face->ascii_face; \
19598 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
19599 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
19600 /* At first, fill in `char2b' and `faces'. */ \
19601 for (n = 0; n < glyph_len; n++) \
19603 int c = COMPOSITION_GLYPH (cmp, n); \
19604 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
19605 faces[n] = FACE_FROM_ID (f, this_face_id); \
19606 get_char_face_and_encoding (f, c, this_face_id, \
19607 char2b + n, 1, 1); \
19610 /* Make glyph_strings for each glyph sequence that is drawable by \
19611 the same face, and append them to HEAD/TAIL. */ \
19612 for (n = 0; n < cmp->glyph_len;) \
19614 s = (struct glyph_string *) alloca (sizeof *s); \
19615 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
19616 append_glyph_string (&(HEAD), &(TAIL), s); \
19624 n = fill_composite_glyph_string (s, faces, overlaps); \
19632 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
19633 of AREA of glyph row ROW on window W between indices START and END.
19634 HL overrides the face for drawing glyph strings, e.g. it is
19635 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
19636 x-positions of the drawing area.
19638 This is an ugly monster macro construct because we must use alloca
19639 to allocate glyph strings (because draw_glyphs can be called
19640 asynchronously). */
19642 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19645 HEAD = TAIL = NULL; \
19646 while (START < END) \
19648 struct glyph *first_glyph = (row)->glyphs[area] + START; \
19649 switch (first_glyph->type) \
19652 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
19656 case COMPOSITE_GLYPH: \
19657 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
19661 case STRETCH_GLYPH: \
19662 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
19666 case IMAGE_GLYPH: \
19667 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
19675 set_glyph_string_background_width (s, START, LAST_X); \
19682 /* Draw glyphs between START and END in AREA of ROW on window W,
19683 starting at x-position X. X is relative to AREA in W. HL is a
19684 face-override with the following meaning:
19686 DRAW_NORMAL_TEXT draw normally
19687 DRAW_CURSOR draw in cursor face
19688 DRAW_MOUSE_FACE draw in mouse face.
19689 DRAW_INVERSE_VIDEO draw in mode line face
19690 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
19691 DRAW_IMAGE_RAISED draw an image with a raised relief around it
19693 If OVERLAPS is non-zero, draw only the foreground of characters and
19694 clip to the physical height of ROW. Non-zero value also defines
19695 the overlapping part to be drawn:
19697 OVERLAPS_PRED overlap with preceding rows
19698 OVERLAPS_SUCC overlap with succeeding rows
19699 OVERLAPS_BOTH overlap with both preceding/succeeding rows
19700 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
19702 Value is the x-position reached, relative to AREA of W. */
19705 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
19708 struct glyph_row
*row
;
19709 enum glyph_row_area area
;
19711 enum draw_glyphs_face hl
;
19714 struct glyph_string
*head
, *tail
;
19715 struct glyph_string
*s
;
19716 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
19717 int last_x
, area_width
;
19720 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19723 ALLOCATE_HDC (hdc
, f
);
19725 /* Let's rather be paranoid than getting a SEGV. */
19726 end
= min (end
, row
->used
[area
]);
19727 start
= max (0, start
);
19728 start
= min (end
, start
);
19730 /* Translate X to frame coordinates. Set last_x to the right
19731 end of the drawing area. */
19732 if (row
->full_width_p
)
19734 /* X is relative to the left edge of W, without scroll bars
19736 x
+= WINDOW_LEFT_EDGE_X (w
);
19737 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
19741 int area_left
= window_box_left (w
, area
);
19743 area_width
= window_box_width (w
, area
);
19744 last_x
= area_left
+ area_width
;
19747 /* Build a doubly-linked list of glyph_string structures between
19748 head and tail from what we have to draw. Note that the macro
19749 BUILD_GLYPH_STRINGS will modify its start parameter. That's
19750 the reason we use a separate variable `i'. */
19752 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
19754 x_reached
= tail
->x
+ tail
->background_width
;
19758 /* If there are any glyphs with lbearing < 0 or rbearing > width in
19759 the row, redraw some glyphs in front or following the glyph
19760 strings built above. */
19761 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
19764 struct glyph_string
*h
, *t
;
19766 /* Compute overhangs for all glyph strings. */
19767 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
19768 for (s
= head
; s
; s
= s
->next
)
19769 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
19771 /* Prepend glyph strings for glyphs in front of the first glyph
19772 string that are overwritten because of the first glyph
19773 string's left overhang. The background of all strings
19774 prepended must be drawn because the first glyph string
19776 i
= left_overwritten (head
);
19780 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
19781 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19783 compute_overhangs_and_x (t
, head
->x
, 1);
19784 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19788 /* Prepend glyph strings for glyphs in front of the first glyph
19789 string that overwrite that glyph string because of their
19790 right overhang. For these strings, only the foreground must
19791 be drawn, because it draws over the glyph string at `head'.
19792 The background must not be drawn because this would overwrite
19793 right overhangs of preceding glyphs for which no glyph
19795 i
= left_overwriting (head
);
19799 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
19800 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19801 for (s
= h
; s
; s
= s
->next
)
19802 s
->background_filled_p
= 1;
19803 compute_overhangs_and_x (t
, head
->x
, 1);
19804 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19807 /* Append glyphs strings for glyphs following the last glyph
19808 string tail that are overwritten by tail. The background of
19809 these strings has to be drawn because tail's foreground draws
19811 i
= right_overwritten (tail
);
19814 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19815 DRAW_NORMAL_TEXT
, x
, last_x
);
19816 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19817 append_glyph_string_lists (&head
, &tail
, h
, t
);
19821 /* Append glyph strings for glyphs following the last glyph
19822 string tail that overwrite tail. The foreground of such
19823 glyphs has to be drawn because it writes into the background
19824 of tail. The background must not be drawn because it could
19825 paint over the foreground of following glyphs. */
19826 i
= right_overwriting (tail
);
19830 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19831 DRAW_NORMAL_TEXT
, x
, last_x
);
19832 for (s
= h
; s
; s
= s
->next
)
19833 s
->background_filled_p
= 1;
19834 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19835 append_glyph_string_lists (&head
, &tail
, h
, t
);
19837 if (clip_head
|| clip_tail
)
19838 for (s
= head
; s
; s
= s
->next
)
19840 s
->clip_head
= clip_head
;
19841 s
->clip_tail
= clip_tail
;
19845 /* Draw all strings. */
19846 for (s
= head
; s
; s
= s
->next
)
19847 FRAME_RIF (f
)->draw_glyph_string (s
);
19849 if (area
== TEXT_AREA
19850 && !row
->full_width_p
19851 /* When drawing overlapping rows, only the glyph strings'
19852 foreground is drawn, which doesn't erase a cursor
19856 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
19857 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
19858 : (tail
? tail
->x
+ tail
->background_width
: x
));
19860 int text_left
= window_box_left (w
, TEXT_AREA
);
19864 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
19865 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
19868 /* Value is the x-position up to which drawn, relative to AREA of W.
19869 This doesn't include parts drawn because of overhangs. */
19870 if (row
->full_width_p
)
19871 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
19873 x_reached
-= window_box_left (w
, area
);
19875 RELEASE_HDC (hdc
, f
);
19880 /* Expand row matrix if too narrow. Don't expand if area
19883 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
19885 if (!fonts_changed_p \
19886 && (it->glyph_row->glyphs[area] \
19887 < it->glyph_row->glyphs[area + 1])) \
19889 it->w->ncols_scale_factor++; \
19890 fonts_changed_p = 1; \
19894 /* Store one glyph for IT->char_to_display in IT->glyph_row.
19895 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19901 struct glyph
*glyph
;
19902 enum glyph_row_area area
= it
->area
;
19904 xassert (it
->glyph_row
);
19905 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
19907 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19908 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19910 glyph
->charpos
= CHARPOS (it
->position
);
19911 glyph
->object
= it
->object
;
19912 glyph
->pixel_width
= it
->pixel_width
;
19913 glyph
->ascent
= it
->ascent
;
19914 glyph
->descent
= it
->descent
;
19915 glyph
->voffset
= it
->voffset
;
19916 glyph
->type
= CHAR_GLYPH
;
19917 glyph
->multibyte_p
= it
->multibyte_p
;
19918 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19919 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19920 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19921 || it
->phys_descent
> it
->descent
);
19922 glyph
->padding_p
= 0;
19923 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
19924 glyph
->face_id
= it
->face_id
;
19925 glyph
->u
.ch
= it
->char_to_display
;
19926 glyph
->slice
= null_glyph_slice
;
19927 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19928 ++it
->glyph_row
->used
[area
];
19931 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19934 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
19935 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19938 append_composite_glyph (it
)
19941 struct glyph
*glyph
;
19942 enum glyph_row_area area
= it
->area
;
19944 xassert (it
->glyph_row
);
19946 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19947 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19949 glyph
->charpos
= CHARPOS (it
->position
);
19950 glyph
->object
= it
->object
;
19951 glyph
->pixel_width
= it
->pixel_width
;
19952 glyph
->ascent
= it
->ascent
;
19953 glyph
->descent
= it
->descent
;
19954 glyph
->voffset
= it
->voffset
;
19955 glyph
->type
= COMPOSITE_GLYPH
;
19956 glyph
->multibyte_p
= it
->multibyte_p
;
19957 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19958 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19959 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19960 || it
->phys_descent
> it
->descent
);
19961 glyph
->padding_p
= 0;
19962 glyph
->glyph_not_available_p
= 0;
19963 glyph
->face_id
= it
->face_id
;
19964 glyph
->u
.cmp_id
= it
->cmp_id
;
19965 glyph
->slice
= null_glyph_slice
;
19966 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19967 ++it
->glyph_row
->used
[area
];
19970 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19974 /* Change IT->ascent and IT->height according to the setting of
19978 take_vertical_position_into_account (it
)
19983 if (it
->voffset
< 0)
19984 /* Increase the ascent so that we can display the text higher
19986 it
->ascent
-= it
->voffset
;
19988 /* Increase the descent so that we can display the text lower
19990 it
->descent
+= it
->voffset
;
19995 /* Produce glyphs/get display metrics for the image IT is loaded with.
19996 See the description of struct display_iterator in dispextern.h for
19997 an overview of struct display_iterator. */
20000 produce_image_glyph (it
)
20005 int glyph_ascent
, crop
;
20006 struct glyph_slice slice
;
20008 xassert (it
->what
== IT_IMAGE
);
20010 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20012 /* Make sure X resources of the face is loaded. */
20013 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20015 if (it
->image_id
< 0)
20017 /* Fringe bitmap. */
20018 it
->ascent
= it
->phys_ascent
= 0;
20019 it
->descent
= it
->phys_descent
= 0;
20020 it
->pixel_width
= 0;
20025 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
20027 /* Make sure X resources of the image is loaded. */
20028 prepare_image_for_display (it
->f
, img
);
20030 slice
.x
= slice
.y
= 0;
20031 slice
.width
= img
->width
;
20032 slice
.height
= img
->height
;
20034 if (INTEGERP (it
->slice
.x
))
20035 slice
.x
= XINT (it
->slice
.x
);
20036 else if (FLOATP (it
->slice
.x
))
20037 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
20039 if (INTEGERP (it
->slice
.y
))
20040 slice
.y
= XINT (it
->slice
.y
);
20041 else if (FLOATP (it
->slice
.y
))
20042 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
20044 if (INTEGERP (it
->slice
.width
))
20045 slice
.width
= XINT (it
->slice
.width
);
20046 else if (FLOATP (it
->slice
.width
))
20047 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
20049 if (INTEGERP (it
->slice
.height
))
20050 slice
.height
= XINT (it
->slice
.height
);
20051 else if (FLOATP (it
->slice
.height
))
20052 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
20054 if (slice
.x
>= img
->width
)
20055 slice
.x
= img
->width
;
20056 if (slice
.y
>= img
->height
)
20057 slice
.y
= img
->height
;
20058 if (slice
.x
+ slice
.width
>= img
->width
)
20059 slice
.width
= img
->width
- slice
.x
;
20060 if (slice
.y
+ slice
.height
> img
->height
)
20061 slice
.height
= img
->height
- slice
.y
;
20063 if (slice
.width
== 0 || slice
.height
== 0)
20066 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
20068 it
->descent
= slice
.height
- glyph_ascent
;
20070 it
->descent
+= img
->vmargin
;
20071 if (slice
.y
+ slice
.height
== img
->height
)
20072 it
->descent
+= img
->vmargin
;
20073 it
->phys_descent
= it
->descent
;
20075 it
->pixel_width
= slice
.width
;
20077 it
->pixel_width
+= img
->hmargin
;
20078 if (slice
.x
+ slice
.width
== img
->width
)
20079 it
->pixel_width
+= img
->hmargin
;
20081 /* It's quite possible for images to have an ascent greater than
20082 their height, so don't get confused in that case. */
20083 if (it
->descent
< 0)
20086 #if 0 /* this breaks image tiling */
20087 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
20088 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
20089 if (face_ascent
> it
->ascent
)
20090 it
->ascent
= it
->phys_ascent
= face_ascent
;
20095 if (face
->box
!= FACE_NO_BOX
)
20097 if (face
->box_line_width
> 0)
20100 it
->ascent
+= face
->box_line_width
;
20101 if (slice
.y
+ slice
.height
== img
->height
)
20102 it
->descent
+= face
->box_line_width
;
20105 if (it
->start_of_box_run_p
&& slice
.x
== 0)
20106 it
->pixel_width
+= eabs (face
->box_line_width
);
20107 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
20108 it
->pixel_width
+= eabs (face
->box_line_width
);
20111 take_vertical_position_into_account (it
);
20113 /* Automatically crop wide image glyphs at right edge so we can
20114 draw the cursor on same display row. */
20115 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
20116 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
20118 it
->pixel_width
-= crop
;
20119 slice
.width
-= crop
;
20124 struct glyph
*glyph
;
20125 enum glyph_row_area area
= it
->area
;
20127 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20128 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20130 glyph
->charpos
= CHARPOS (it
->position
);
20131 glyph
->object
= it
->object
;
20132 glyph
->pixel_width
= it
->pixel_width
;
20133 glyph
->ascent
= glyph_ascent
;
20134 glyph
->descent
= it
->descent
;
20135 glyph
->voffset
= it
->voffset
;
20136 glyph
->type
= IMAGE_GLYPH
;
20137 glyph
->multibyte_p
= it
->multibyte_p
;
20138 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20139 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20140 glyph
->overlaps_vertically_p
= 0;
20141 glyph
->padding_p
= 0;
20142 glyph
->glyph_not_available_p
= 0;
20143 glyph
->face_id
= it
->face_id
;
20144 glyph
->u
.img_id
= img
->id
;
20145 glyph
->slice
= slice
;
20146 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20147 ++it
->glyph_row
->used
[area
];
20150 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20155 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
20156 of the glyph, WIDTH and HEIGHT are the width and height of the
20157 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
20160 append_stretch_glyph (it
, object
, width
, height
, ascent
)
20162 Lisp_Object object
;
20166 struct glyph
*glyph
;
20167 enum glyph_row_area area
= it
->area
;
20169 xassert (ascent
>= 0 && ascent
<= height
);
20171 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20172 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20174 glyph
->charpos
= CHARPOS (it
->position
);
20175 glyph
->object
= object
;
20176 glyph
->pixel_width
= width
;
20177 glyph
->ascent
= ascent
;
20178 glyph
->descent
= height
- ascent
;
20179 glyph
->voffset
= it
->voffset
;
20180 glyph
->type
= STRETCH_GLYPH
;
20181 glyph
->multibyte_p
= it
->multibyte_p
;
20182 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20183 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20184 glyph
->overlaps_vertically_p
= 0;
20185 glyph
->padding_p
= 0;
20186 glyph
->glyph_not_available_p
= 0;
20187 glyph
->face_id
= it
->face_id
;
20188 glyph
->u
.stretch
.ascent
= ascent
;
20189 glyph
->u
.stretch
.height
= height
;
20190 glyph
->slice
= null_glyph_slice
;
20191 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20192 ++it
->glyph_row
->used
[area
];
20195 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20199 /* Produce a stretch glyph for iterator IT. IT->object is the value
20200 of the glyph property displayed. The value must be a list
20201 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
20204 1. `:width WIDTH' specifies that the space should be WIDTH *
20205 canonical char width wide. WIDTH may be an integer or floating
20208 2. `:relative-width FACTOR' specifies that the width of the stretch
20209 should be computed from the width of the first character having the
20210 `glyph' property, and should be FACTOR times that width.
20212 3. `:align-to HPOS' specifies that the space should be wide enough
20213 to reach HPOS, a value in canonical character units.
20215 Exactly one of the above pairs must be present.
20217 4. `:height HEIGHT' specifies that the height of the stretch produced
20218 should be HEIGHT, measured in canonical character units.
20220 5. `:relative-height FACTOR' specifies that the height of the
20221 stretch should be FACTOR times the height of the characters having
20222 the glyph property.
20224 Either none or exactly one of 4 or 5 must be present.
20226 6. `:ascent ASCENT' specifies that ASCENT percent of the height
20227 of the stretch should be used for the ascent of the stretch.
20228 ASCENT must be in the range 0 <= ASCENT <= 100. */
20231 produce_stretch_glyph (it
)
20234 /* (space :width WIDTH :height HEIGHT ...) */
20235 Lisp_Object prop
, plist
;
20236 int width
= 0, height
= 0, align_to
= -1;
20237 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
20240 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20241 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
20243 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20245 /* List should start with `space'. */
20246 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
20247 plist
= XCDR (it
->object
);
20249 /* Compute the width of the stretch. */
20250 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
20251 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
20253 /* Absolute width `:width WIDTH' specified and valid. */
20254 zero_width_ok_p
= 1;
20257 else if (prop
= Fplist_get (plist
, QCrelative_width
),
20260 /* Relative width `:relative-width FACTOR' specified and valid.
20261 Compute the width of the characters having the `glyph'
20264 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
20267 if (it
->multibyte_p
)
20269 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
20270 - IT_BYTEPOS (*it
));
20271 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
20274 it2
.c
= *p
, it2
.len
= 1;
20276 it2
.glyph_row
= NULL
;
20277 it2
.what
= IT_CHARACTER
;
20278 x_produce_glyphs (&it2
);
20279 width
= NUMVAL (prop
) * it2
.pixel_width
;
20281 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
20282 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
20284 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
20285 align_to
= (align_to
< 0
20287 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
20288 else if (align_to
< 0)
20289 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
20290 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
20291 zero_width_ok_p
= 1;
20294 /* Nothing specified -> width defaults to canonical char width. */
20295 width
= FRAME_COLUMN_WIDTH (it
->f
);
20297 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
20300 /* Compute height. */
20301 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
20302 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20305 zero_height_ok_p
= 1;
20307 else if (prop
= Fplist_get (plist
, QCrelative_height
),
20309 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
20311 height
= FONT_HEIGHT (font
);
20313 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
20316 /* Compute percentage of height used for ascent. If
20317 `:ascent ASCENT' is present and valid, use that. Otherwise,
20318 derive the ascent from the font in use. */
20319 if (prop
= Fplist_get (plist
, QCascent
),
20320 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
20321 ascent
= height
* NUMVAL (prop
) / 100.0;
20322 else if (!NILP (prop
)
20323 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20324 ascent
= min (max (0, (int)tem
), height
);
20326 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
20328 if (width
> 0 && !it
->truncate_lines_p
20329 && it
->current_x
+ width
> it
->last_visible_x
)
20330 width
= it
->last_visible_x
- it
->current_x
- 1;
20332 if (width
> 0 && height
> 0 && it
->glyph_row
)
20334 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
20335 if (!STRINGP (object
))
20336 object
= it
->w
->buffer
;
20337 append_stretch_glyph (it
, object
, width
, height
, ascent
);
20340 it
->pixel_width
= width
;
20341 it
->ascent
= it
->phys_ascent
= ascent
;
20342 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
20343 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
20345 take_vertical_position_into_account (it
);
20348 /* Get line-height and line-spacing property at point.
20349 If line-height has format (HEIGHT TOTAL), return TOTAL
20350 in TOTAL_HEIGHT. */
20353 get_line_height_property (it
, prop
)
20357 Lisp_Object position
;
20359 if (STRINGP (it
->object
))
20360 position
= make_number (IT_STRING_CHARPOS (*it
));
20361 else if (BUFFERP (it
->object
))
20362 position
= make_number (IT_CHARPOS (*it
));
20366 return Fget_char_property (position
, prop
, it
->object
);
20369 /* Calculate line-height and line-spacing properties.
20370 An integer value specifies explicit pixel value.
20371 A float value specifies relative value to current face height.
20372 A cons (float . face-name) specifies relative value to
20373 height of specified face font.
20375 Returns height in pixels, or nil. */
20379 calc_line_height_property (it
, val
, font
, boff
, override
)
20383 int boff
, override
;
20385 Lisp_Object face_name
= Qnil
;
20386 int ascent
, descent
, height
;
20388 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
20393 face_name
= XCAR (val
);
20395 if (!NUMBERP (val
))
20396 val
= make_number (1);
20397 if (NILP (face_name
))
20399 height
= it
->ascent
+ it
->descent
;
20404 if (NILP (face_name
))
20406 font
= FRAME_FONT (it
->f
);
20407 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20409 else if (EQ (face_name
, Qt
))
20417 struct font_info
*font_info
;
20419 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
20421 return make_number (-1);
20423 face
= FACE_FROM_ID (it
->f
, face_id
);
20426 return make_number (-1);
20428 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20429 boff
= font_info
->baseline_offset
;
20430 if (font_info
->vertical_centering
)
20431 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20434 ascent
= FONT_BASE (font
) + boff
;
20435 descent
= FONT_DESCENT (font
) - boff
;
20439 it
->override_ascent
= ascent
;
20440 it
->override_descent
= descent
;
20441 it
->override_boff
= boff
;
20444 height
= ascent
+ descent
;
20448 height
= (int)(XFLOAT_DATA (val
) * height
);
20449 else if (INTEGERP (val
))
20450 height
*= XINT (val
);
20452 return make_number (height
);
20457 Produce glyphs/get display metrics for the display element IT is
20458 loaded with. See the description of struct it in dispextern.h
20459 for an overview of struct it. */
20462 x_produce_glyphs (it
)
20465 int extra_line_spacing
= it
->extra_line_spacing
;
20467 it
->glyph_not_available_p
= 0;
20469 if (it
->what
== IT_CHARACTER
)
20473 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20475 int font_not_found_p
;
20476 struct font_info
*font_info
;
20477 int boff
; /* baseline offset */
20478 /* We may change it->multibyte_p upon unibyte<->multibyte
20479 conversion. So, save the current value now and restore it
20482 Note: It seems that we don't have to record multibyte_p in
20483 struct glyph because the character code itself tells if or
20484 not the character is multibyte. Thus, in the future, we must
20485 consider eliminating the field `multibyte_p' in the struct
20487 int saved_multibyte_p
= it
->multibyte_p
;
20489 /* Maybe translate single-byte characters to multibyte, or the
20491 it
->char_to_display
= it
->c
;
20492 if (!ASCII_BYTE_P (it
->c
))
20494 if (unibyte_display_via_language_environment
20495 && SINGLE_BYTE_CHAR_P (it
->c
)
20497 || !NILP (Vnonascii_translation_table
)))
20499 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20500 it
->multibyte_p
= 1;
20501 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20502 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20504 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
20505 && !it
->multibyte_p
)
20507 it
->multibyte_p
= 1;
20508 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20509 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20513 /* Get font to use. Encode IT->char_to_display. */
20514 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20515 &char2b
, it
->multibyte_p
, 0);
20518 /* When no suitable font found, use the default font. */
20519 font_not_found_p
= font
== NULL
;
20520 if (font_not_found_p
)
20522 font
= FRAME_FONT (it
->f
);
20523 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20528 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20529 boff
= font_info
->baseline_offset
;
20530 if (font_info
->vertical_centering
)
20531 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20534 if (it
->char_to_display
>= ' '
20535 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
20537 /* Either unibyte or ASCII. */
20542 pcm
= FRAME_RIF (it
->f
)->per_char_metric
20543 (font
, &char2b
, FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
20545 if (it
->override_ascent
>= 0)
20547 it
->ascent
= it
->override_ascent
;
20548 it
->descent
= it
->override_descent
;
20549 boff
= it
->override_boff
;
20553 it
->ascent
= FONT_BASE (font
) + boff
;
20554 it
->descent
= FONT_DESCENT (font
) - boff
;
20559 it
->phys_ascent
= pcm
->ascent
+ boff
;
20560 it
->phys_descent
= pcm
->descent
- boff
;
20561 it
->pixel_width
= pcm
->width
;
20565 it
->glyph_not_available_p
= 1;
20566 it
->phys_ascent
= it
->ascent
;
20567 it
->phys_descent
= it
->descent
;
20568 it
->pixel_width
= FONT_WIDTH (font
);
20571 if (it
->constrain_row_ascent_descent_p
)
20573 if (it
->descent
> it
->max_descent
)
20575 it
->ascent
+= it
->descent
- it
->max_descent
;
20576 it
->descent
= it
->max_descent
;
20578 if (it
->ascent
> it
->max_ascent
)
20580 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20581 it
->ascent
= it
->max_ascent
;
20583 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20584 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20585 extra_line_spacing
= 0;
20588 /* If this is a space inside a region of text with
20589 `space-width' property, change its width. */
20590 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
20592 it
->pixel_width
*= XFLOATINT (it
->space_width
);
20594 /* If face has a box, add the box thickness to the character
20595 height. If character has a box line to the left and/or
20596 right, add the box line width to the character's width. */
20597 if (face
->box
!= FACE_NO_BOX
)
20599 int thick
= face
->box_line_width
;
20603 it
->ascent
+= thick
;
20604 it
->descent
+= thick
;
20609 if (it
->start_of_box_run_p
)
20610 it
->pixel_width
+= thick
;
20611 if (it
->end_of_box_run_p
)
20612 it
->pixel_width
+= thick
;
20615 /* If face has an overline, add the height of the overline
20616 (1 pixel) and a 1 pixel margin to the character height. */
20617 if (face
->overline_p
)
20618 it
->ascent
+= overline_margin
;
20620 if (it
->constrain_row_ascent_descent_p
)
20622 if (it
->ascent
> it
->max_ascent
)
20623 it
->ascent
= it
->max_ascent
;
20624 if (it
->descent
> it
->max_descent
)
20625 it
->descent
= it
->max_descent
;
20628 take_vertical_position_into_account (it
);
20630 /* If we have to actually produce glyphs, do it. */
20635 /* Translate a space with a `space-width' property
20636 into a stretch glyph. */
20637 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
20638 / FONT_HEIGHT (font
));
20639 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20640 it
->ascent
+ it
->descent
, ascent
);
20645 /* If characters with lbearing or rbearing are displayed
20646 in this line, record that fact in a flag of the
20647 glyph row. This is used to optimize X output code. */
20648 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
20649 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20652 else if (it
->char_to_display
== '\n')
20654 /* A newline has no width but we need the height of the line.
20655 But if previous part of the line set a height, don't
20656 increase that height */
20658 Lisp_Object height
;
20659 Lisp_Object total_height
= Qnil
;
20661 it
->override_ascent
= -1;
20662 it
->pixel_width
= 0;
20665 height
= get_line_height_property(it
, Qline_height
);
20666 /* Split (line-height total-height) list */
20668 && CONSP (XCDR (height
))
20669 && NILP (XCDR (XCDR (height
))))
20671 total_height
= XCAR (XCDR (height
));
20672 height
= XCAR (height
);
20674 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
20676 if (it
->override_ascent
>= 0)
20678 it
->ascent
= it
->override_ascent
;
20679 it
->descent
= it
->override_descent
;
20680 boff
= it
->override_boff
;
20684 it
->ascent
= FONT_BASE (font
) + boff
;
20685 it
->descent
= FONT_DESCENT (font
) - boff
;
20688 if (EQ (height
, Qt
))
20690 if (it
->descent
> it
->max_descent
)
20692 it
->ascent
+= it
->descent
- it
->max_descent
;
20693 it
->descent
= it
->max_descent
;
20695 if (it
->ascent
> it
->max_ascent
)
20697 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20698 it
->ascent
= it
->max_ascent
;
20700 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20701 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20702 it
->constrain_row_ascent_descent_p
= 1;
20703 extra_line_spacing
= 0;
20707 Lisp_Object spacing
;
20709 it
->phys_ascent
= it
->ascent
;
20710 it
->phys_descent
= it
->descent
;
20712 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
20713 && face
->box
!= FACE_NO_BOX
20714 && face
->box_line_width
> 0)
20716 it
->ascent
+= face
->box_line_width
;
20717 it
->descent
+= face
->box_line_width
;
20720 && XINT (height
) > it
->ascent
+ it
->descent
)
20721 it
->ascent
= XINT (height
) - it
->descent
;
20723 if (!NILP (total_height
))
20724 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
20727 spacing
= get_line_height_property(it
, Qline_spacing
);
20728 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
20730 if (INTEGERP (spacing
))
20732 extra_line_spacing
= XINT (spacing
);
20733 if (!NILP (total_height
))
20734 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
20738 else if (it
->char_to_display
== '\t')
20740 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
20741 int x
= it
->current_x
+ it
->continuation_lines_width
;
20742 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
20744 /* If the distance from the current position to the next tab
20745 stop is less than a space character width, use the
20746 tab stop after that. */
20747 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
20748 next_tab_x
+= tab_width
;
20750 it
->pixel_width
= next_tab_x
- x
;
20752 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
20753 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20757 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20758 it
->ascent
+ it
->descent
, it
->ascent
);
20763 /* A multi-byte character. Assume that the display width of the
20764 character is the width of the character multiplied by the
20765 width of the font. */
20767 /* If we found a font, this font should give us the right
20768 metrics. If we didn't find a font, use the frame's
20769 default font and calculate the width of the character
20770 from the charset width; this is what old redisplay code
20773 pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
20774 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
20776 if (font_not_found_p
|| !pcm
)
20778 int charset
= CHAR_CHARSET (it
->char_to_display
);
20780 it
->glyph_not_available_p
= 1;
20781 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
20782 * CHARSET_WIDTH (charset
));
20783 it
->phys_ascent
= FONT_BASE (font
) + boff
;
20784 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20788 it
->pixel_width
= pcm
->width
;
20789 it
->phys_ascent
= pcm
->ascent
+ boff
;
20790 it
->phys_descent
= pcm
->descent
- boff
;
20792 && (pcm
->lbearing
< 0
20793 || pcm
->rbearing
> pcm
->width
))
20794 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20797 it
->ascent
= FONT_BASE (font
) + boff
;
20798 it
->descent
= FONT_DESCENT (font
) - boff
;
20799 if (face
->box
!= FACE_NO_BOX
)
20801 int thick
= face
->box_line_width
;
20805 it
->ascent
+= thick
;
20806 it
->descent
+= thick
;
20811 if (it
->start_of_box_run_p
)
20812 it
->pixel_width
+= thick
;
20813 if (it
->end_of_box_run_p
)
20814 it
->pixel_width
+= thick
;
20817 /* If face has an overline, add the height of the overline
20818 (1 pixel) and a 1 pixel margin to the character height. */
20819 if (face
->overline_p
)
20820 it
->ascent
+= overline_margin
;
20822 take_vertical_position_into_account (it
);
20827 it
->multibyte_p
= saved_multibyte_p
;
20829 else if (it
->what
== IT_COMPOSITION
)
20831 /* Note: A composition is represented as one glyph in the
20832 glyph matrix. There are no padding glyphs. */
20835 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20837 int font_not_found_p
;
20838 struct font_info
*font_info
;
20839 int boff
; /* baseline offset */
20840 struct composition
*cmp
= composition_table
[it
->cmp_id
];
20842 /* Maybe translate single-byte characters to multibyte. */
20843 it
->char_to_display
= it
->c
;
20844 if (unibyte_display_via_language_environment
20845 && SINGLE_BYTE_CHAR_P (it
->c
)
20848 && !NILP (Vnonascii_translation_table
))))
20850 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20853 /* Get face and font to use. Encode IT->char_to_display. */
20854 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20855 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20856 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20857 &char2b
, it
->multibyte_p
, 0);
20860 /* When no suitable font found, use the default font. */
20861 font_not_found_p
= font
== NULL
;
20862 if (font_not_found_p
)
20864 font
= FRAME_FONT (it
->f
);
20865 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20870 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20871 boff
= font_info
->baseline_offset
;
20872 if (font_info
->vertical_centering
)
20873 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20876 /* There are no padding glyphs, so there is only one glyph to
20877 produce for the composition. Important is that pixel_width,
20878 ascent and descent are the values of what is drawn by
20879 draw_glyphs (i.e. the values of the overall glyphs composed). */
20882 /* If we have not yet calculated pixel size data of glyphs of
20883 the composition for the current face font, calculate them
20884 now. Theoretically, we have to check all fonts for the
20885 glyphs, but that requires much time and memory space. So,
20886 here we check only the font of the first glyph. This leads
20887 to incorrect display very rarely, and C-l (recenter) can
20888 correct the display anyway. */
20889 if (cmp
->font
!= (void *) font
)
20891 /* Ascent and descent of the font of the first character of
20892 this composition (adjusted by baseline offset). Ascent
20893 and descent of overall glyphs should not be less than
20894 them respectively. */
20895 int font_ascent
= FONT_BASE (font
) + boff
;
20896 int font_descent
= FONT_DESCENT (font
) - boff
;
20897 /* Bounding box of the overall glyphs. */
20898 int leftmost
, rightmost
, lowest
, highest
;
20899 int i
, width
, ascent
, descent
;
20901 cmp
->font
= (void *) font
;
20903 /* Initialize the bounding box. */
20905 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
20906 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
20908 width
= pcm
->width
;
20909 ascent
= pcm
->ascent
;
20910 descent
= pcm
->descent
;
20914 width
= FONT_WIDTH (font
);
20915 ascent
= FONT_BASE (font
);
20916 descent
= FONT_DESCENT (font
);
20920 lowest
= - descent
+ boff
;
20921 highest
= ascent
+ boff
;
20925 && font_info
->default_ascent
20926 && CHAR_TABLE_P (Vuse_default_ascent
)
20927 && !NILP (Faref (Vuse_default_ascent
,
20928 make_number (it
->char_to_display
))))
20929 highest
= font_info
->default_ascent
+ boff
;
20931 /* Draw the first glyph at the normal position. It may be
20932 shifted to right later if some other glyphs are drawn at
20934 cmp
->offsets
[0] = 0;
20935 cmp
->offsets
[1] = boff
;
20937 /* Set cmp->offsets for the remaining glyphs. */
20938 for (i
= 1; i
< cmp
->glyph_len
; i
++)
20940 int left
, right
, btm
, top
;
20941 int ch
= COMPOSITION_GLYPH (cmp
, i
);
20942 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
20944 face
= FACE_FROM_ID (it
->f
, face_id
);
20945 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
20946 &char2b
, it
->multibyte_p
, 0);
20950 font
= FRAME_FONT (it
->f
);
20951 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20957 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20958 boff
= font_info
->baseline_offset
;
20959 if (font_info
->vertical_centering
)
20960 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20964 && (pcm
= FRAME_RIF (it
->f
)->per_char_metric (font
, &char2b
,
20965 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
20967 width
= pcm
->width
;
20968 ascent
= pcm
->ascent
;
20969 descent
= pcm
->descent
;
20973 width
= FONT_WIDTH (font
);
20978 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
20980 /* Relative composition with or without
20981 alternate chars. */
20982 left
= (leftmost
+ rightmost
- width
) / 2;
20983 btm
= - descent
+ boff
;
20984 if (font_info
&& font_info
->relative_compose
20985 && (! CHAR_TABLE_P (Vignore_relative_composition
)
20986 || NILP (Faref (Vignore_relative_composition
,
20987 make_number (ch
)))))
20990 if (- descent
>= font_info
->relative_compose
)
20991 /* One extra pixel between two glyphs. */
20993 else if (ascent
<= 0)
20994 /* One extra pixel between two glyphs. */
20995 btm
= lowest
- 1 - ascent
- descent
;
21000 /* A composition rule is specified by an integer
21001 value that encodes global and new reference
21002 points (GREF and NREF). GREF and NREF are
21003 specified by numbers as below:
21005 0---1---2 -- ascent
21009 9--10--11 -- center
21011 ---3---4---5--- baseline
21013 6---7---8 -- descent
21015 int rule
= COMPOSITION_RULE (cmp
, i
);
21016 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
21018 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
21019 grefx
= gref
% 3, nrefx
= nref
% 3;
21020 grefy
= gref
/ 3, nrefy
= nref
/ 3;
21023 + grefx
* (rightmost
- leftmost
) / 2
21024 - nrefx
* width
/ 2);
21025 btm
= ((grefy
== 0 ? highest
21027 : grefy
== 2 ? lowest
21028 : (highest
+ lowest
) / 2)
21029 - (nrefy
== 0 ? ascent
+ descent
21030 : nrefy
== 1 ? descent
- boff
21032 : (ascent
+ descent
) / 2));
21035 cmp
->offsets
[i
* 2] = left
;
21036 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
21038 /* Update the bounding box of the overall glyphs. */
21039 right
= left
+ width
;
21040 top
= btm
+ descent
+ ascent
;
21041 if (left
< leftmost
)
21043 if (right
> rightmost
)
21051 /* If there are glyphs whose x-offsets are negative,
21052 shift all glyphs to the right and make all x-offsets
21056 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21057 cmp
->offsets
[i
* 2] -= leftmost
;
21058 rightmost
-= leftmost
;
21061 cmp
->pixel_width
= rightmost
;
21062 cmp
->ascent
= highest
;
21063 cmp
->descent
= - lowest
;
21064 if (cmp
->ascent
< font_ascent
)
21065 cmp
->ascent
= font_ascent
;
21066 if (cmp
->descent
< font_descent
)
21067 cmp
->descent
= font_descent
;
21070 it
->pixel_width
= cmp
->pixel_width
;
21071 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
21072 it
->descent
= it
->phys_descent
= cmp
->descent
;
21074 if (face
->box
!= FACE_NO_BOX
)
21076 int thick
= face
->box_line_width
;
21080 it
->ascent
+= thick
;
21081 it
->descent
+= thick
;
21086 if (it
->start_of_box_run_p
)
21087 it
->pixel_width
+= thick
;
21088 if (it
->end_of_box_run_p
)
21089 it
->pixel_width
+= thick
;
21092 /* If face has an overline, add the height of the overline
21093 (1 pixel) and a 1 pixel margin to the character height. */
21094 if (face
->overline_p
)
21095 it
->ascent
+= overline_margin
;
21097 take_vertical_position_into_account (it
);
21100 append_composite_glyph (it
);
21102 else if (it
->what
== IT_IMAGE
)
21103 produce_image_glyph (it
);
21104 else if (it
->what
== IT_STRETCH
)
21105 produce_stretch_glyph (it
);
21107 /* Accumulate dimensions. Note: can't assume that it->descent > 0
21108 because this isn't true for images with `:ascent 100'. */
21109 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
21110 if (it
->area
== TEXT_AREA
)
21111 it
->current_x
+= it
->pixel_width
;
21113 if (extra_line_spacing
> 0)
21115 it
->descent
+= extra_line_spacing
;
21116 if (extra_line_spacing
> it
->max_extra_line_spacing
)
21117 it
->max_extra_line_spacing
= extra_line_spacing
;
21120 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
21121 it
->max_descent
= max (it
->max_descent
, it
->descent
);
21122 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
21123 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
21127 Output LEN glyphs starting at START at the nominal cursor position.
21128 Advance the nominal cursor over the text. The global variable
21129 updated_window contains the window being updated, updated_row is
21130 the glyph row being updated, and updated_area is the area of that
21131 row being updated. */
21134 x_write_glyphs (start
, len
)
21135 struct glyph
*start
;
21140 xassert (updated_window
&& updated_row
);
21143 /* Write glyphs. */
21145 hpos
= start
- updated_row
->glyphs
[updated_area
];
21146 x
= draw_glyphs (updated_window
, output_cursor
.x
,
21147 updated_row
, updated_area
,
21149 DRAW_NORMAL_TEXT
, 0);
21151 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
21152 if (updated_area
== TEXT_AREA
21153 && updated_window
->phys_cursor_on_p
21154 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
21155 && updated_window
->phys_cursor
.hpos
>= hpos
21156 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
21157 updated_window
->phys_cursor_on_p
= 0;
21161 /* Advance the output cursor. */
21162 output_cursor
.hpos
+= len
;
21163 output_cursor
.x
= x
;
21168 Insert LEN glyphs from START at the nominal cursor position. */
21171 x_insert_glyphs (start
, len
)
21172 struct glyph
*start
;
21177 int line_height
, shift_by_width
, shifted_region_width
;
21178 struct glyph_row
*row
;
21179 struct glyph
*glyph
;
21180 int frame_x
, frame_y
, hpos
;
21182 xassert (updated_window
&& updated_row
);
21184 w
= updated_window
;
21185 f
= XFRAME (WINDOW_FRAME (w
));
21187 /* Get the height of the line we are in. */
21189 line_height
= row
->height
;
21191 /* Get the width of the glyphs to insert. */
21192 shift_by_width
= 0;
21193 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
21194 shift_by_width
+= glyph
->pixel_width
;
21196 /* Get the width of the region to shift right. */
21197 shifted_region_width
= (window_box_width (w
, updated_area
)
21202 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
21203 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
21205 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
21206 line_height
, shift_by_width
);
21208 /* Write the glyphs. */
21209 hpos
= start
- row
->glyphs
[updated_area
];
21210 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
21212 DRAW_NORMAL_TEXT
, 0);
21214 /* Advance the output cursor. */
21215 output_cursor
.hpos
+= len
;
21216 output_cursor
.x
+= shift_by_width
;
21222 Erase the current text line from the nominal cursor position
21223 (inclusive) to pixel column TO_X (exclusive). The idea is that
21224 everything from TO_X onward is already erased.
21226 TO_X is a pixel position relative to updated_area of
21227 updated_window. TO_X == -1 means clear to the end of this area. */
21230 x_clear_end_of_line (to_x
)
21234 struct window
*w
= updated_window
;
21235 int max_x
, min_y
, max_y
;
21236 int from_x
, from_y
, to_y
;
21238 xassert (updated_window
&& updated_row
);
21239 f
= XFRAME (w
->frame
);
21241 if (updated_row
->full_width_p
)
21242 max_x
= WINDOW_TOTAL_WIDTH (w
);
21244 max_x
= window_box_width (w
, updated_area
);
21245 max_y
= window_text_bottom_y (w
);
21247 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
21248 of window. For TO_X > 0, truncate to end of drawing area. */
21254 to_x
= min (to_x
, max_x
);
21256 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
21258 /* Notice if the cursor will be cleared by this operation. */
21259 if (!updated_row
->full_width_p
)
21260 notice_overwritten_cursor (w
, updated_area
,
21261 output_cursor
.x
, -1,
21263 MATRIX_ROW_BOTTOM_Y (updated_row
));
21265 from_x
= output_cursor
.x
;
21267 /* Translate to frame coordinates. */
21268 if (updated_row
->full_width_p
)
21270 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
21271 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
21275 int area_left
= window_box_left (w
, updated_area
);
21276 from_x
+= area_left
;
21280 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
21281 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
21282 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
21284 /* Prevent inadvertently clearing to end of the X window. */
21285 if (to_x
> from_x
&& to_y
> from_y
)
21288 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
21289 to_x
- from_x
, to_y
- from_y
);
21294 #endif /* HAVE_WINDOW_SYSTEM */
21298 /***********************************************************************
21300 ***********************************************************************/
21302 /* Value is the internal representation of the specified cursor type
21303 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
21304 of the bar cursor. */
21306 static enum text_cursor_kinds
21307 get_specified_cursor_type (arg
, width
)
21311 enum text_cursor_kinds type
;
21316 if (EQ (arg
, Qbox
))
21317 return FILLED_BOX_CURSOR
;
21319 if (EQ (arg
, Qhollow
))
21320 return HOLLOW_BOX_CURSOR
;
21322 if (EQ (arg
, Qbar
))
21329 && EQ (XCAR (arg
), Qbar
)
21330 && INTEGERP (XCDR (arg
))
21331 && XINT (XCDR (arg
)) >= 0)
21333 *width
= XINT (XCDR (arg
));
21337 if (EQ (arg
, Qhbar
))
21340 return HBAR_CURSOR
;
21344 && EQ (XCAR (arg
), Qhbar
)
21345 && INTEGERP (XCDR (arg
))
21346 && XINT (XCDR (arg
)) >= 0)
21348 *width
= XINT (XCDR (arg
));
21349 return HBAR_CURSOR
;
21352 /* Treat anything unknown as "hollow box cursor".
21353 It was bad to signal an error; people have trouble fixing
21354 .Xdefaults with Emacs, when it has something bad in it. */
21355 type
= HOLLOW_BOX_CURSOR
;
21360 /* Set the default cursor types for specified frame. */
21362 set_frame_cursor_types (f
, arg
)
21369 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
21370 FRAME_CURSOR_WIDTH (f
) = width
;
21372 /* By default, set up the blink-off state depending on the on-state. */
21374 tem
= Fassoc (arg
, Vblink_cursor_alist
);
21377 FRAME_BLINK_OFF_CURSOR (f
)
21378 = get_specified_cursor_type (XCDR (tem
), &width
);
21379 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
21382 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
21386 /* Return the cursor we want to be displayed in window W. Return
21387 width of bar/hbar cursor through WIDTH arg. Return with
21388 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
21389 (i.e. if the `system caret' should track this cursor).
21391 In a mini-buffer window, we want the cursor only to appear if we
21392 are reading input from this window. For the selected window, we
21393 want the cursor type given by the frame parameter or buffer local
21394 setting of cursor-type. If explicitly marked off, draw no cursor.
21395 In all other cases, we want a hollow box cursor. */
21397 static enum text_cursor_kinds
21398 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
21400 struct glyph
*glyph
;
21402 int *active_cursor
;
21404 struct frame
*f
= XFRAME (w
->frame
);
21405 struct buffer
*b
= XBUFFER (w
->buffer
);
21406 int cursor_type
= DEFAULT_CURSOR
;
21407 Lisp_Object alt_cursor
;
21408 int non_selected
= 0;
21410 *active_cursor
= 1;
21413 if (cursor_in_echo_area
21414 && FRAME_HAS_MINIBUF_P (f
)
21415 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
21417 if (w
== XWINDOW (echo_area_window
))
21419 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
21421 *width
= FRAME_CURSOR_WIDTH (f
);
21422 return FRAME_DESIRED_CURSOR (f
);
21425 return get_specified_cursor_type (b
->cursor_type
, width
);
21428 *active_cursor
= 0;
21432 /* Detect a nonselected window or nonselected frame. */
21433 else if (w
!= XWINDOW (f
->selected_window
)
21434 #ifdef HAVE_WINDOW_SYSTEM
21435 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
21439 *active_cursor
= 0;
21441 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
21447 /* Never display a cursor in a window in which cursor-type is nil. */
21448 if (NILP (b
->cursor_type
))
21451 /* Get the normal cursor type for this window. */
21452 if (EQ (b
->cursor_type
, Qt
))
21454 cursor_type
= FRAME_DESIRED_CURSOR (f
);
21455 *width
= FRAME_CURSOR_WIDTH (f
);
21458 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
21460 /* Use cursor-in-non-selected-windows instead
21461 for non-selected window or frame. */
21464 alt_cursor
= b
->cursor_in_non_selected_windows
;
21465 if (!EQ (Qt
, alt_cursor
))
21466 return get_specified_cursor_type (alt_cursor
, width
);
21467 /* t means modify the normal cursor type. */
21468 if (cursor_type
== FILLED_BOX_CURSOR
)
21469 cursor_type
= HOLLOW_BOX_CURSOR
;
21470 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
21472 return cursor_type
;
21475 /* Use normal cursor if not blinked off. */
21476 if (!w
->cursor_off_p
)
21478 #ifdef HAVE_WINDOW_SYSTEM
21479 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21481 if (cursor_type
== FILLED_BOX_CURSOR
)
21483 /* Using a block cursor on large images can be very annoying.
21484 So use a hollow cursor for "large" images.
21485 If image is not transparent (no mask), also use hollow cursor. */
21486 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21487 if (img
!= NULL
&& IMAGEP (img
->spec
))
21489 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
21490 where N = size of default frame font size.
21491 This should cover most of the "tiny" icons people may use. */
21493 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
21494 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
21495 cursor_type
= HOLLOW_BOX_CURSOR
;
21498 else if (cursor_type
!= NO_CURSOR
)
21500 /* Display current only supports BOX and HOLLOW cursors for images.
21501 So for now, unconditionally use a HOLLOW cursor when cursor is
21502 not a solid box cursor. */
21503 cursor_type
= HOLLOW_BOX_CURSOR
;
21507 return cursor_type
;
21510 /* Cursor is blinked off, so determine how to "toggle" it. */
21512 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
21513 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
21514 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
21516 /* Then see if frame has specified a specific blink off cursor type. */
21517 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
21519 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
21520 return FRAME_BLINK_OFF_CURSOR (f
);
21524 /* Some people liked having a permanently visible blinking cursor,
21525 while others had very strong opinions against it. So it was
21526 decided to remove it. KFS 2003-09-03 */
21528 /* Finally perform built-in cursor blinking:
21529 filled box <-> hollow box
21530 wide [h]bar <-> narrow [h]bar
21531 narrow [h]bar <-> no cursor
21532 other type <-> no cursor */
21534 if (cursor_type
== FILLED_BOX_CURSOR
)
21535 return HOLLOW_BOX_CURSOR
;
21537 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
21540 return cursor_type
;
21548 #ifdef HAVE_WINDOW_SYSTEM
21550 /* Notice when the text cursor of window W has been completely
21551 overwritten by a drawing operation that outputs glyphs in AREA
21552 starting at X0 and ending at X1 in the line starting at Y0 and
21553 ending at Y1. X coordinates are area-relative. X1 < 0 means all
21554 the rest of the line after X0 has been written. Y coordinates
21555 are window-relative. */
21558 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
21560 enum glyph_row_area area
;
21561 int x0
, y0
, x1
, y1
;
21563 int cx0
, cx1
, cy0
, cy1
;
21564 struct glyph_row
*row
;
21566 if (!w
->phys_cursor_on_p
)
21568 if (area
!= TEXT_AREA
)
21571 if (w
->phys_cursor
.vpos
< 0
21572 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
21573 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
21574 !(row
->enabled_p
&& row
->displays_text_p
)))
21577 if (row
->cursor_in_fringe_p
)
21579 row
->cursor_in_fringe_p
= 0;
21580 draw_fringe_bitmap (w
, row
, 0);
21581 w
->phys_cursor_on_p
= 0;
21585 cx0
= w
->phys_cursor
.x
;
21586 cx1
= cx0
+ w
->phys_cursor_width
;
21587 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
21590 /* The cursor image will be completely removed from the
21591 screen if the output area intersects the cursor area in
21592 y-direction. When we draw in [y0 y1[, and some part of
21593 the cursor is at y < y0, that part must have been drawn
21594 before. When scrolling, the cursor is erased before
21595 actually scrolling, so we don't come here. When not
21596 scrolling, the rows above the old cursor row must have
21597 changed, and in this case these rows must have written
21598 over the cursor image.
21600 Likewise if part of the cursor is below y1, with the
21601 exception of the cursor being in the first blank row at
21602 the buffer and window end because update_text_area
21603 doesn't draw that row. (Except when it does, but
21604 that's handled in update_text_area.) */
21606 cy0
= w
->phys_cursor
.y
;
21607 cy1
= cy0
+ w
->phys_cursor_height
;
21608 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
21611 w
->phys_cursor_on_p
= 0;
21614 #endif /* HAVE_WINDOW_SYSTEM */
21617 /************************************************************************
21619 ************************************************************************/
21621 #ifdef HAVE_WINDOW_SYSTEM
21624 Fix the display of area AREA of overlapping row ROW in window W
21625 with respect to the overlapping part OVERLAPS. */
21628 x_fix_overlapping_area (w
, row
, area
, overlaps
)
21630 struct glyph_row
*row
;
21631 enum glyph_row_area area
;
21639 for (i
= 0; i
< row
->used
[area
];)
21641 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
21643 int start
= i
, start_x
= x
;
21647 x
+= row
->glyphs
[area
][i
].pixel_width
;
21650 while (i
< row
->used
[area
]
21651 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
21653 draw_glyphs (w
, start_x
, row
, area
,
21655 DRAW_NORMAL_TEXT
, overlaps
);
21659 x
+= row
->glyphs
[area
][i
].pixel_width
;
21669 Draw the cursor glyph of window W in glyph row ROW. See the
21670 comment of draw_glyphs for the meaning of HL. */
21673 draw_phys_cursor_glyph (w
, row
, hl
)
21675 struct glyph_row
*row
;
21676 enum draw_glyphs_face hl
;
21678 /* If cursor hpos is out of bounds, don't draw garbage. This can
21679 happen in mini-buffer windows when switching between echo area
21680 glyphs and mini-buffer. */
21681 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
21683 int on_p
= w
->phys_cursor_on_p
;
21685 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
21686 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
21688 w
->phys_cursor_on_p
= on_p
;
21690 if (hl
== DRAW_CURSOR
)
21691 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21692 /* When we erase the cursor, and ROW is overlapped by other
21693 rows, make sure that these overlapping parts of other rows
21695 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
21697 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21699 if (row
> w
->current_matrix
->rows
21700 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
21701 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
21702 OVERLAPS_ERASED_CURSOR
);
21704 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
21705 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
21706 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
21707 OVERLAPS_ERASED_CURSOR
);
21714 Erase the image of a cursor of window W from the screen. */
21717 erase_phys_cursor (w
)
21720 struct frame
*f
= XFRAME (w
->frame
);
21721 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21722 int hpos
= w
->phys_cursor
.hpos
;
21723 int vpos
= w
->phys_cursor
.vpos
;
21724 int mouse_face_here_p
= 0;
21725 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
21726 struct glyph_row
*cursor_row
;
21727 struct glyph
*cursor_glyph
;
21728 enum draw_glyphs_face hl
;
21730 /* No cursor displayed or row invalidated => nothing to do on the
21732 if (w
->phys_cursor_type
== NO_CURSOR
)
21733 goto mark_cursor_off
;
21735 /* VPOS >= active_glyphs->nrows means that window has been resized.
21736 Don't bother to erase the cursor. */
21737 if (vpos
>= active_glyphs
->nrows
)
21738 goto mark_cursor_off
;
21740 /* If row containing cursor is marked invalid, there is nothing we
21742 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
21743 if (!cursor_row
->enabled_p
)
21744 goto mark_cursor_off
;
21746 /* If line spacing is > 0, old cursor may only be partially visible in
21747 window after split-window. So adjust visible height. */
21748 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
21749 window_text_bottom_y (w
) - cursor_row
->y
);
21751 /* If row is completely invisible, don't attempt to delete a cursor which
21752 isn't there. This can happen if cursor is at top of a window, and
21753 we switch to a buffer with a header line in that window. */
21754 if (cursor_row
->visible_height
<= 0)
21755 goto mark_cursor_off
;
21757 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
21758 if (cursor_row
->cursor_in_fringe_p
)
21760 cursor_row
->cursor_in_fringe_p
= 0;
21761 draw_fringe_bitmap (w
, cursor_row
, 0);
21762 goto mark_cursor_off
;
21765 /* This can happen when the new row is shorter than the old one.
21766 In this case, either draw_glyphs or clear_end_of_line
21767 should have cleared the cursor. Note that we wouldn't be
21768 able to erase the cursor in this case because we don't have a
21769 cursor glyph at hand. */
21770 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
21771 goto mark_cursor_off
;
21773 /* If the cursor is in the mouse face area, redisplay that when
21774 we clear the cursor. */
21775 if (! NILP (dpyinfo
->mouse_face_window
)
21776 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
21777 && (vpos
> dpyinfo
->mouse_face_beg_row
21778 || (vpos
== dpyinfo
->mouse_face_beg_row
21779 && hpos
>= dpyinfo
->mouse_face_beg_col
))
21780 && (vpos
< dpyinfo
->mouse_face_end_row
21781 || (vpos
== dpyinfo
->mouse_face_end_row
21782 && hpos
< dpyinfo
->mouse_face_end_col
))
21783 /* Don't redraw the cursor's spot in mouse face if it is at the
21784 end of a line (on a newline). The cursor appears there, but
21785 mouse highlighting does not. */
21786 && cursor_row
->used
[TEXT_AREA
] > hpos
)
21787 mouse_face_here_p
= 1;
21789 /* Maybe clear the display under the cursor. */
21790 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
21793 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
21796 cursor_glyph
= get_phys_cursor_glyph (w
);
21797 if (cursor_glyph
== NULL
)
21798 goto mark_cursor_off
;
21800 width
= cursor_glyph
->pixel_width
;
21801 left_x
= window_box_left_offset (w
, TEXT_AREA
);
21802 x
= w
->phys_cursor
.x
;
21804 width
-= left_x
- x
;
21805 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
21806 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
21807 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
21810 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
21813 /* Erase the cursor by redrawing the character underneath it. */
21814 if (mouse_face_here_p
)
21815 hl
= DRAW_MOUSE_FACE
;
21817 hl
= DRAW_NORMAL_TEXT
;
21818 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
21821 w
->phys_cursor_on_p
= 0;
21822 w
->phys_cursor_type
= NO_CURSOR
;
21827 Display or clear cursor of window W. If ON is zero, clear the
21828 cursor. If it is non-zero, display the cursor. If ON is nonzero,
21829 where to put the cursor is specified by HPOS, VPOS, X and Y. */
21832 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
21834 int on
, hpos
, vpos
, x
, y
;
21836 struct frame
*f
= XFRAME (w
->frame
);
21837 int new_cursor_type
;
21838 int new_cursor_width
;
21840 struct glyph_row
*glyph_row
;
21841 struct glyph
*glyph
;
21843 /* This is pointless on invisible frames, and dangerous on garbaged
21844 windows and frames; in the latter case, the frame or window may
21845 be in the midst of changing its size, and x and y may be off the
21847 if (! FRAME_VISIBLE_P (f
)
21848 || FRAME_GARBAGED_P (f
)
21849 || vpos
>= w
->current_matrix
->nrows
21850 || hpos
>= w
->current_matrix
->matrix_w
)
21853 /* If cursor is off and we want it off, return quickly. */
21854 if (!on
&& !w
->phys_cursor_on_p
)
21857 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
21858 /* If cursor row is not enabled, we don't really know where to
21859 display the cursor. */
21860 if (!glyph_row
->enabled_p
)
21862 w
->phys_cursor_on_p
= 0;
21867 if (!glyph_row
->exact_window_width_line_p
21868 || hpos
< glyph_row
->used
[TEXT_AREA
])
21869 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
21871 xassert (interrupt_input_blocked
);
21873 /* Set new_cursor_type to the cursor we want to be displayed. */
21874 new_cursor_type
= get_window_cursor_type (w
, glyph
,
21875 &new_cursor_width
, &active_cursor
);
21877 /* If cursor is currently being shown and we don't want it to be or
21878 it is in the wrong place, or the cursor type is not what we want,
21880 if (w
->phys_cursor_on_p
21882 || w
->phys_cursor
.x
!= x
21883 || w
->phys_cursor
.y
!= y
21884 || new_cursor_type
!= w
->phys_cursor_type
21885 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
21886 && new_cursor_width
!= w
->phys_cursor_width
)))
21887 erase_phys_cursor (w
);
21889 /* Don't check phys_cursor_on_p here because that flag is only set
21890 to zero in some cases where we know that the cursor has been
21891 completely erased, to avoid the extra work of erasing the cursor
21892 twice. In other words, phys_cursor_on_p can be 1 and the cursor
21893 still not be visible, or it has only been partly erased. */
21896 w
->phys_cursor_ascent
= glyph_row
->ascent
;
21897 w
->phys_cursor_height
= glyph_row
->height
;
21899 /* Set phys_cursor_.* before x_draw_.* is called because some
21900 of them may need the information. */
21901 w
->phys_cursor
.x
= x
;
21902 w
->phys_cursor
.y
= glyph_row
->y
;
21903 w
->phys_cursor
.hpos
= hpos
;
21904 w
->phys_cursor
.vpos
= vpos
;
21907 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
21908 new_cursor_type
, new_cursor_width
,
21909 on
, active_cursor
);
21913 /* Switch the display of W's cursor on or off, according to the value
21917 update_window_cursor (w
, on
)
21921 /* Don't update cursor in windows whose frame is in the process
21922 of being deleted. */
21923 if (w
->current_matrix
)
21926 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21927 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21933 /* Call update_window_cursor with parameter ON_P on all leaf windows
21934 in the window tree rooted at W. */
21937 update_cursor_in_window_tree (w
, on_p
)
21943 if (!NILP (w
->hchild
))
21944 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
21945 else if (!NILP (w
->vchild
))
21946 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
21948 update_window_cursor (w
, on_p
);
21950 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
21956 Display the cursor on window W, or clear it, according to ON_P.
21957 Don't change the cursor's position. */
21960 x_update_cursor (f
, on_p
)
21964 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
21969 Clear the cursor of window W to background color, and mark the
21970 cursor as not shown. This is used when the text where the cursor
21971 is is about to be rewritten. */
21977 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
21978 update_window_cursor (w
, 0);
21983 Display the active region described by mouse_face_* according to DRAW. */
21986 show_mouse_face (dpyinfo
, draw
)
21987 Display_Info
*dpyinfo
;
21988 enum draw_glyphs_face draw
;
21990 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
21991 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21993 if (/* If window is in the process of being destroyed, don't bother
21995 w
->current_matrix
!= NULL
21996 /* Don't update mouse highlight if hidden */
21997 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
21998 /* Recognize when we are called to operate on rows that don't exist
21999 anymore. This can happen when a window is split. */
22000 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
22002 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
22003 struct glyph_row
*row
, *first
, *last
;
22005 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
22006 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
22008 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
22010 int start_hpos
, end_hpos
, start_x
;
22012 /* For all but the first row, the highlight starts at column 0. */
22015 start_hpos
= dpyinfo
->mouse_face_beg_col
;
22016 start_x
= dpyinfo
->mouse_face_beg_x
;
22025 end_hpos
= dpyinfo
->mouse_face_end_col
;
22028 end_hpos
= row
->used
[TEXT_AREA
];
22029 if (draw
== DRAW_NORMAL_TEXT
)
22030 row
->fill_line_p
= 1; /* Clear to end of line */
22033 if (end_hpos
> start_hpos
)
22035 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
22036 start_hpos
, end_hpos
,
22040 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
22044 /* When we've written over the cursor, arrange for it to
22045 be displayed again. */
22046 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
22049 display_and_set_cursor (w
, 1,
22050 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22051 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22056 /* Change the mouse cursor. */
22057 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
22058 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
22059 else if (draw
== DRAW_MOUSE_FACE
)
22060 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
22062 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
22066 Clear out the mouse-highlighted active region.
22067 Redraw it un-highlighted first. Value is non-zero if mouse
22068 face was actually drawn unhighlighted. */
22071 clear_mouse_face (dpyinfo
)
22072 Display_Info
*dpyinfo
;
22076 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
22078 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
22082 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22083 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22084 dpyinfo
->mouse_face_window
= Qnil
;
22085 dpyinfo
->mouse_face_overlay
= Qnil
;
22091 Non-zero if physical cursor of window W is within mouse face. */
22094 cursor_in_mouse_face_p (w
)
22097 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22098 int in_mouse_face
= 0;
22100 if (WINDOWP (dpyinfo
->mouse_face_window
)
22101 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
22103 int hpos
= w
->phys_cursor
.hpos
;
22104 int vpos
= w
->phys_cursor
.vpos
;
22106 if (vpos
>= dpyinfo
->mouse_face_beg_row
22107 && vpos
<= dpyinfo
->mouse_face_end_row
22108 && (vpos
> dpyinfo
->mouse_face_beg_row
22109 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22110 && (vpos
< dpyinfo
->mouse_face_end_row
22111 || hpos
< dpyinfo
->mouse_face_end_col
22112 || dpyinfo
->mouse_face_past_end
))
22116 return in_mouse_face
;
22122 /* Find the glyph matrix position of buffer position CHARPOS in window
22123 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
22124 current glyphs must be up to date. If CHARPOS is above window
22125 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
22126 of last line in W. In the row containing CHARPOS, stop before glyphs
22127 having STOP as object. */
22129 #if 1 /* This is a version of fast_find_position that's more correct
22130 in the presence of hscrolling, for example. I didn't install
22131 it right away because the problem fixed is minor, it failed
22132 in 20.x as well, and I think it's too risky to install
22133 so near the release of 21.1. 2001-09-25 gerd. */
22136 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
22139 int *hpos
, *vpos
, *x
, *y
;
22142 struct glyph_row
*row
, *first
;
22143 struct glyph
*glyph
, *end
;
22146 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22147 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
22152 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
22156 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
22159 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22163 /* If whole rows or last part of a row came from a display overlay,
22164 row_containing_pos will skip over such rows because their end pos
22165 equals the start pos of the overlay or interval.
22167 Move back if we have a STOP object and previous row's
22168 end glyph came from STOP. */
22171 struct glyph_row
*prev
;
22172 while ((prev
= row
- 1, prev
>= first
)
22173 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
22174 && prev
->used
[TEXT_AREA
] > 0)
22176 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
22177 glyph
= beg
+ prev
->used
[TEXT_AREA
];
22178 while (--glyph
>= beg
22179 && INTEGERP (glyph
->object
));
22181 || !EQ (stop
, glyph
->object
))
22189 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22191 glyph
= row
->glyphs
[TEXT_AREA
];
22192 end
= glyph
+ row
->used
[TEXT_AREA
];
22194 /* Skip over glyphs not having an object at the start of the row.
22195 These are special glyphs like truncation marks on terminal
22197 if (row
->displays_text_p
)
22199 && INTEGERP (glyph
->object
)
22200 && !EQ (stop
, glyph
->object
)
22201 && glyph
->charpos
< 0)
22203 *x
+= glyph
->pixel_width
;
22208 && !INTEGERP (glyph
->object
)
22209 && !EQ (stop
, glyph
->object
)
22210 && (!BUFFERP (glyph
->object
)
22211 || glyph
->charpos
< charpos
))
22213 *x
+= glyph
->pixel_width
;
22217 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
22224 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
22227 int *hpos
, *vpos
, *x
, *y
;
22232 int maybe_next_line_p
= 0;
22233 int line_start_position
;
22234 int yb
= window_text_bottom_y (w
);
22235 struct glyph_row
*row
, *best_row
;
22236 int row_vpos
, best_row_vpos
;
22239 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22240 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22242 while (row
->y
< yb
)
22244 if (row
->used
[TEXT_AREA
])
22245 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
22247 line_start_position
= 0;
22249 if (line_start_position
> pos
)
22251 /* If the position sought is the end of the buffer,
22252 don't include the blank lines at the bottom of the window. */
22253 else if (line_start_position
== pos
22254 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
22256 maybe_next_line_p
= 1;
22259 else if (line_start_position
> 0)
22262 best_row_vpos
= row_vpos
;
22265 if (row
->y
+ row
->height
>= yb
)
22272 /* Find the right column within BEST_ROW. */
22274 current_x
= best_row
->x
;
22275 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
22277 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
22278 int charpos
= glyph
->charpos
;
22280 if (BUFFERP (glyph
->object
))
22282 if (charpos
== pos
)
22285 *vpos
= best_row_vpos
;
22290 else if (charpos
> pos
)
22293 else if (EQ (glyph
->object
, stop
))
22298 current_x
+= glyph
->pixel_width
;
22301 /* If we're looking for the end of the buffer,
22302 and we didn't find it in the line we scanned,
22303 use the start of the following line. */
22304 if (maybe_next_line_p
)
22309 current_x
= best_row
->x
;
22312 *vpos
= best_row_vpos
;
22313 *hpos
= lastcol
+ 1;
22322 /* Find the position of the glyph for position POS in OBJECT in
22323 window W's current matrix, and return in *X, *Y the pixel
22324 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
22326 RIGHT_P non-zero means return the position of the right edge of the
22327 glyph, RIGHT_P zero means return the left edge position.
22329 If no glyph for POS exists in the matrix, return the position of
22330 the glyph with the next smaller position that is in the matrix, if
22331 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
22332 exists in the matrix, return the position of the glyph with the
22333 next larger position in OBJECT.
22335 Value is non-zero if a glyph was found. */
22338 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
22341 Lisp_Object object
;
22342 int *hpos
, *vpos
, *x
, *y
;
22345 int yb
= window_text_bottom_y (w
);
22346 struct glyph_row
*r
;
22347 struct glyph
*best_glyph
= NULL
;
22348 struct glyph_row
*best_row
= NULL
;
22351 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22352 r
->enabled_p
&& r
->y
< yb
;
22355 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
22356 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
22359 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
22360 if (EQ (g
->object
, object
))
22362 if (g
->charpos
== pos
)
22369 else if (best_glyph
== NULL
22370 || ((eabs (g
->charpos
- pos
)
22371 < eabs (best_glyph
->charpos
- pos
))
22374 : g
->charpos
> pos
)))
22388 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
22392 *x
+= best_glyph
->pixel_width
;
22397 *vpos
= best_row
- w
->current_matrix
->rows
;
22400 return best_glyph
!= NULL
;
22404 /* See if position X, Y is within a hot-spot of an image. */
22407 on_hot_spot_p (hot_spot
, x
, y
)
22408 Lisp_Object hot_spot
;
22411 if (!CONSP (hot_spot
))
22414 if (EQ (XCAR (hot_spot
), Qrect
))
22416 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
22417 Lisp_Object rect
= XCDR (hot_spot
);
22421 if (!CONSP (XCAR (rect
)))
22423 if (!CONSP (XCDR (rect
)))
22425 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
22427 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
22429 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
22431 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
22435 else if (EQ (XCAR (hot_spot
), Qcircle
))
22437 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
22438 Lisp_Object circ
= XCDR (hot_spot
);
22439 Lisp_Object lr
, lx0
, ly0
;
22441 && CONSP (XCAR (circ
))
22442 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
22443 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
22444 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
22446 double r
= XFLOATINT (lr
);
22447 double dx
= XINT (lx0
) - x
;
22448 double dy
= XINT (ly0
) - y
;
22449 return (dx
* dx
+ dy
* dy
<= r
* r
);
22452 else if (EQ (XCAR (hot_spot
), Qpoly
))
22454 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
22455 if (VECTORP (XCDR (hot_spot
)))
22457 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
22458 Lisp_Object
*poly
= v
->contents
;
22462 Lisp_Object lx
, ly
;
22465 /* Need an even number of coordinates, and at least 3 edges. */
22466 if (n
< 6 || n
& 1)
22469 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
22470 If count is odd, we are inside polygon. Pixels on edges
22471 may or may not be included depending on actual geometry of the
22473 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
22474 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
22476 x0
= XINT (lx
), y0
= XINT (ly
);
22477 for (i
= 0; i
< n
; i
+= 2)
22479 int x1
= x0
, y1
= y0
;
22480 if ((lx
= poly
[i
], !INTEGERP (lx
))
22481 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
22483 x0
= XINT (lx
), y0
= XINT (ly
);
22485 /* Does this segment cross the X line? */
22493 if (y
> y0
&& y
> y1
)
22495 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
22505 find_hot_spot (map
, x
, y
)
22509 while (CONSP (map
))
22511 if (CONSP (XCAR (map
))
22512 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
22520 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
22522 doc
: /* Lookup in image map MAP coordinates X and Y.
22523 An image map is an alist where each element has the format (AREA ID PLIST).
22524 An AREA is specified as either a rectangle, a circle, or a polygon:
22525 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
22526 pixel coordinates of the upper left and bottom right corners.
22527 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
22528 and the radius of the circle; r may be a float or integer.
22529 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
22530 vector describes one corner in the polygon.
22531 Returns the alist element for the first matching AREA in MAP. */)
22542 return find_hot_spot (map
, XINT (x
), XINT (y
));
22546 /* Display frame CURSOR, optionally using shape defined by POINTER. */
22548 define_frame_cursor1 (f
, cursor
, pointer
)
22551 Lisp_Object pointer
;
22553 /* Do not change cursor shape while dragging mouse. */
22554 if (!NILP (do_mouse_tracking
))
22557 if (!NILP (pointer
))
22559 if (EQ (pointer
, Qarrow
))
22560 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22561 else if (EQ (pointer
, Qhand
))
22562 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
22563 else if (EQ (pointer
, Qtext
))
22564 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22565 else if (EQ (pointer
, intern ("hdrag")))
22566 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22567 #ifdef HAVE_X_WINDOWS
22568 else if (EQ (pointer
, intern ("vdrag")))
22569 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
22571 else if (EQ (pointer
, intern ("hourglass")))
22572 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
22573 else if (EQ (pointer
, Qmodeline
))
22574 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
22576 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22579 if (cursor
!= No_Cursor
)
22580 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
22583 /* Take proper action when mouse has moved to the mode or header line
22584 or marginal area AREA of window W, x-position X and y-position Y.
22585 X is relative to the start of the text display area of W, so the
22586 width of bitmap areas and scroll bars must be subtracted to get a
22587 position relative to the start of the mode line. */
22590 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
22591 Lisp_Object window
;
22593 enum window_part area
;
22595 struct window
*w
= XWINDOW (window
);
22596 struct frame
*f
= XFRAME (w
->frame
);
22597 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22598 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22599 Lisp_Object pointer
= Qnil
;
22600 int charpos
, dx
, dy
, width
, height
;
22601 Lisp_Object string
, object
= Qnil
;
22602 Lisp_Object pos
, help
;
22604 Lisp_Object mouse_face
;
22605 int original_x_pixel
= x
;
22606 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
22607 struct glyph_row
*row
;
22609 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
22614 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
22615 &object
, &dx
, &dy
, &width
, &height
);
22617 row
= (area
== ON_MODE_LINE
22618 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
22619 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
22622 if (row
->mode_line_p
&& row
->enabled_p
)
22624 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
22625 end
= glyph
+ row
->used
[TEXT_AREA
];
22627 for (x0
= original_x_pixel
;
22628 glyph
< end
&& x0
>= glyph
->pixel_width
;
22630 x0
-= glyph
->pixel_width
;
22638 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
22639 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
22640 &object
, &dx
, &dy
, &width
, &height
);
22645 if (IMAGEP (object
))
22647 Lisp_Object image_map
, hotspot
;
22648 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
22650 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
22652 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22654 Lisp_Object area_id
, plist
;
22656 area_id
= XCAR (hotspot
);
22657 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22658 If so, we could look for mouse-enter, mouse-leave
22659 properties in PLIST (and do something...). */
22660 hotspot
= XCDR (hotspot
);
22661 if (CONSP (hotspot
)
22662 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22664 pointer
= Fplist_get (plist
, Qpointer
);
22665 if (NILP (pointer
))
22667 help
= Fplist_get (plist
, Qhelp_echo
);
22670 help_echo_string
= help
;
22671 /* Is this correct? ++kfs */
22672 XSETWINDOW (help_echo_window
, w
);
22673 help_echo_object
= w
->buffer
;
22674 help_echo_pos
= charpos
;
22678 if (NILP (pointer
))
22679 pointer
= Fplist_get (XCDR (object
), QCpointer
);
22682 if (STRINGP (string
))
22684 pos
= make_number (charpos
);
22685 /* If we're on a string with `help-echo' text property, arrange
22686 for the help to be displayed. This is done by setting the
22687 global variable help_echo_string to the help string. */
22690 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
22693 help_echo_string
= help
;
22694 XSETWINDOW (help_echo_window
, w
);
22695 help_echo_object
= string
;
22696 help_echo_pos
= charpos
;
22700 if (NILP (pointer
))
22701 pointer
= Fget_text_property (pos
, Qpointer
, string
);
22703 /* Change the mouse pointer according to what is under X/Y. */
22704 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
22707 map
= Fget_text_property (pos
, Qlocal_map
, string
);
22708 if (!KEYMAPP (map
))
22709 map
= Fget_text_property (pos
, Qkeymap
, string
);
22710 if (!KEYMAPP (map
))
22711 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
22714 /* Change the mouse face according to what is under X/Y. */
22715 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
22716 if (!NILP (mouse_face
)
22717 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22722 struct glyph
* tmp_glyph
;
22726 int total_pixel_width
;
22731 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
22732 Qmouse_face
, string
, Qnil
);
22734 b
= make_number (0);
22736 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
22738 e
= make_number (SCHARS (string
));
22740 /* Calculate the position(glyph position: GPOS) of GLYPH in
22741 displayed string. GPOS is different from CHARPOS.
22743 CHARPOS is the position of glyph in internal string
22744 object. A mode line string format has structures which
22745 is converted to a flatten by emacs lisp interpreter.
22746 The internal string is an element of the structures.
22747 The displayed string is the flatten string. */
22749 if (glyph
> row_start_glyph
)
22751 tmp_glyph
= glyph
- 1;
22752 while (tmp_glyph
>= row_start_glyph
22753 && tmp_glyph
->charpos
>= XINT (b
)
22754 && EQ (tmp_glyph
->object
, glyph
->object
))
22761 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
22762 displayed string holding GLYPH.
22764 GSEQ_LENGTH is different from SCHARS (STRING).
22765 SCHARS (STRING) returns the length of the internal string. */
22766 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
22767 tmp_glyph
->charpos
< XINT (e
);
22768 tmp_glyph
++, gseq_length
++)
22770 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22774 total_pixel_width
= 0;
22775 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
22776 total_pixel_width
+= tmp_glyph
->pixel_width
;
22778 /* Pre calculation of re-rendering position */
22780 hpos
= (area
== ON_MODE_LINE
22781 ? (w
->current_matrix
)->nrows
- 1
22784 /* If the re-rendering position is included in the last
22785 re-rendering area, we should do nothing. */
22786 if ( EQ (window
, dpyinfo
->mouse_face_window
)
22787 && dpyinfo
->mouse_face_beg_col
<= vpos
22788 && vpos
< dpyinfo
->mouse_face_end_col
22789 && dpyinfo
->mouse_face_beg_row
== hpos
)
22792 if (clear_mouse_face (dpyinfo
))
22793 cursor
= No_Cursor
;
22795 dpyinfo
->mouse_face_beg_col
= vpos
;
22796 dpyinfo
->mouse_face_beg_row
= hpos
;
22798 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
22799 dpyinfo
->mouse_face_beg_y
= 0;
22801 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
22802 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
22804 dpyinfo
->mouse_face_end_x
= 0;
22805 dpyinfo
->mouse_face_end_y
= 0;
22807 dpyinfo
->mouse_face_past_end
= 0;
22808 dpyinfo
->mouse_face_window
= window
;
22810 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
22813 glyph
->face_id
, 1);
22814 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22816 if (NILP (pointer
))
22819 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22820 clear_mouse_face (dpyinfo
);
22822 define_frame_cursor1 (f
, cursor
, pointer
);
22827 Take proper action when the mouse has moved to position X, Y on
22828 frame F as regards highlighting characters that have mouse-face
22829 properties. Also de-highlighting chars where the mouse was before.
22830 X and Y can be negative or out of range. */
22833 note_mouse_highlight (f
, x
, y
)
22837 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22838 enum window_part part
;
22839 Lisp_Object window
;
22841 Cursor cursor
= No_Cursor
;
22842 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
22845 /* When a menu is active, don't highlight because this looks odd. */
22846 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (MAC_OS)
22847 if (popup_activated ())
22851 if (NILP (Vmouse_highlight
)
22852 || !f
->glyphs_initialized_p
)
22855 dpyinfo
->mouse_face_mouse_x
= x
;
22856 dpyinfo
->mouse_face_mouse_y
= y
;
22857 dpyinfo
->mouse_face_mouse_frame
= f
;
22859 if (dpyinfo
->mouse_face_defer
)
22862 if (gc_in_progress
)
22864 dpyinfo
->mouse_face_deferred_gc
= 1;
22868 /* Which window is that in? */
22869 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
22871 /* If we were displaying active text in another window, clear that.
22872 Also clear if we move out of text area in same window. */
22873 if (! EQ (window
, dpyinfo
->mouse_face_window
)
22874 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
22875 && !NILP (dpyinfo
->mouse_face_window
)))
22876 clear_mouse_face (dpyinfo
);
22878 /* Not on a window -> return. */
22879 if (!WINDOWP (window
))
22882 /* Reset help_echo_string. It will get recomputed below. */
22883 help_echo_string
= Qnil
;
22885 /* Convert to window-relative pixel coordinates. */
22886 w
= XWINDOW (window
);
22887 frame_to_window_pixel_xy (w
, &x
, &y
);
22889 /* Handle tool-bar window differently since it doesn't display a
22891 if (EQ (window
, f
->tool_bar_window
))
22893 note_tool_bar_highlight (f
, x
, y
);
22897 /* Mouse is on the mode, header line or margin? */
22898 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
22899 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
22901 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
22905 if (part
== ON_VERTICAL_BORDER
)
22907 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22908 help_echo_string
= build_string ("drag-mouse-1: resize");
22910 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
22911 || part
== ON_SCROLL_BAR
)
22912 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22914 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22916 /* Are we in a window whose display is up to date?
22917 And verify the buffer's text has not changed. */
22918 b
= XBUFFER (w
->buffer
);
22919 if (part
== ON_TEXT
22920 && EQ (w
->window_end_valid
, w
->buffer
)
22921 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
22922 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
22924 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
22925 struct glyph
*glyph
;
22926 Lisp_Object object
;
22927 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
22928 Lisp_Object
*overlay_vec
= NULL
;
22930 struct buffer
*obuf
;
22931 int obegv
, ozv
, same_region
;
22933 /* Find the glyph under X/Y. */
22934 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
22936 /* Look for :pointer property on image. */
22937 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22939 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22940 if (img
!= NULL
&& IMAGEP (img
->spec
))
22942 Lisp_Object image_map
, hotspot
;
22943 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
22945 && (hotspot
= find_hot_spot (image_map
,
22946 glyph
->slice
.x
+ dx
,
22947 glyph
->slice
.y
+ dy
),
22949 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22951 Lisp_Object area_id
, plist
;
22953 area_id
= XCAR (hotspot
);
22954 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22955 If so, we could look for mouse-enter, mouse-leave
22956 properties in PLIST (and do something...). */
22957 hotspot
= XCDR (hotspot
);
22958 if (CONSP (hotspot
)
22959 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22961 pointer
= Fplist_get (plist
, Qpointer
);
22962 if (NILP (pointer
))
22964 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
22965 if (!NILP (help_echo_string
))
22967 help_echo_window
= window
;
22968 help_echo_object
= glyph
->object
;
22969 help_echo_pos
= glyph
->charpos
;
22973 if (NILP (pointer
))
22974 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
22978 /* Clear mouse face if X/Y not over text. */
22980 || area
!= TEXT_AREA
22981 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
22983 if (clear_mouse_face (dpyinfo
))
22984 cursor
= No_Cursor
;
22985 if (NILP (pointer
))
22987 if (area
!= TEXT_AREA
)
22988 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22990 pointer
= Vvoid_text_area_pointer
;
22995 pos
= glyph
->charpos
;
22996 object
= glyph
->object
;
22997 if (!STRINGP (object
) && !BUFFERP (object
))
23000 /* If we get an out-of-range value, return now; avoid an error. */
23001 if (BUFFERP (object
) && pos
> BUF_Z (b
))
23004 /* Make the window's buffer temporarily current for
23005 overlays_at and compute_char_face. */
23006 obuf
= current_buffer
;
23007 current_buffer
= b
;
23013 /* Is this char mouse-active or does it have help-echo? */
23014 position
= make_number (pos
);
23016 if (BUFFERP (object
))
23018 /* Put all the overlays we want in a vector in overlay_vec. */
23019 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
23020 /* Sort overlays into increasing priority order. */
23021 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
23026 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
23027 && vpos
>= dpyinfo
->mouse_face_beg_row
23028 && vpos
<= dpyinfo
->mouse_face_end_row
23029 && (vpos
> dpyinfo
->mouse_face_beg_row
23030 || hpos
>= dpyinfo
->mouse_face_beg_col
)
23031 && (vpos
< dpyinfo
->mouse_face_end_row
23032 || hpos
< dpyinfo
->mouse_face_end_col
23033 || dpyinfo
->mouse_face_past_end
));
23036 cursor
= No_Cursor
;
23038 /* Check mouse-face highlighting. */
23040 /* If there exists an overlay with mouse-face overlapping
23041 the one we are currently highlighting, we have to
23042 check if we enter the overlapping overlay, and then
23043 highlight only that. */
23044 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
23045 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
23047 /* Find the highest priority overlay that has a mouse-face
23050 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
23052 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
23053 if (!NILP (mouse_face
))
23054 overlay
= overlay_vec
[i
];
23057 /* If we're actually highlighting the same overlay as
23058 before, there's no need to do that again. */
23059 if (!NILP (overlay
)
23060 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
23061 goto check_help_echo
;
23063 dpyinfo
->mouse_face_overlay
= overlay
;
23065 /* Clear the display of the old active region, if any. */
23066 if (clear_mouse_face (dpyinfo
))
23067 cursor
= No_Cursor
;
23069 /* If no overlay applies, get a text property. */
23070 if (NILP (overlay
))
23071 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
23073 /* Handle the overlay case. */
23074 if (!NILP (overlay
))
23076 /* Find the range of text around this char that
23077 should be active. */
23078 Lisp_Object before
, after
;
23081 before
= Foverlay_start (overlay
);
23082 after
= Foverlay_end (overlay
);
23083 /* Record this as the current active region. */
23084 fast_find_position (w
, XFASTINT (before
),
23085 &dpyinfo
->mouse_face_beg_col
,
23086 &dpyinfo
->mouse_face_beg_row
,
23087 &dpyinfo
->mouse_face_beg_x
,
23088 &dpyinfo
->mouse_face_beg_y
, Qnil
);
23090 dpyinfo
->mouse_face_past_end
23091 = !fast_find_position (w
, XFASTINT (after
),
23092 &dpyinfo
->mouse_face_end_col
,
23093 &dpyinfo
->mouse_face_end_row
,
23094 &dpyinfo
->mouse_face_end_x
,
23095 &dpyinfo
->mouse_face_end_y
, Qnil
);
23096 dpyinfo
->mouse_face_window
= window
;
23098 dpyinfo
->mouse_face_face_id
23099 = face_at_buffer_position (w
, pos
, 0, 0,
23101 !dpyinfo
->mouse_face_hidden
);
23103 /* Display it as active. */
23104 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23105 cursor
= No_Cursor
;
23107 /* Handle the text property case. */
23108 else if (!NILP (mouse_face
) && BUFFERP (object
))
23110 /* Find the range of text around this char that
23111 should be active. */
23112 Lisp_Object before
, after
, beginning
, end
;
23115 beginning
= Fmarker_position (w
->start
);
23116 end
= make_number (BUF_Z (XBUFFER (object
))
23117 - XFASTINT (w
->window_end_pos
));
23119 = Fprevious_single_property_change (make_number (pos
+ 1),
23121 object
, beginning
);
23123 = Fnext_single_property_change (position
, Qmouse_face
,
23126 /* Record this as the current active region. */
23127 fast_find_position (w
, XFASTINT (before
),
23128 &dpyinfo
->mouse_face_beg_col
,
23129 &dpyinfo
->mouse_face_beg_row
,
23130 &dpyinfo
->mouse_face_beg_x
,
23131 &dpyinfo
->mouse_face_beg_y
, Qnil
);
23132 dpyinfo
->mouse_face_past_end
23133 = !fast_find_position (w
, XFASTINT (after
),
23134 &dpyinfo
->mouse_face_end_col
,
23135 &dpyinfo
->mouse_face_end_row
,
23136 &dpyinfo
->mouse_face_end_x
,
23137 &dpyinfo
->mouse_face_end_y
, Qnil
);
23138 dpyinfo
->mouse_face_window
= window
;
23140 if (BUFFERP (object
))
23141 dpyinfo
->mouse_face_face_id
23142 = face_at_buffer_position (w
, pos
, 0, 0,
23144 !dpyinfo
->mouse_face_hidden
);
23146 /* Display it as active. */
23147 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23148 cursor
= No_Cursor
;
23150 else if (!NILP (mouse_face
) && STRINGP (object
))
23155 b
= Fprevious_single_property_change (make_number (pos
+ 1),
23158 e
= Fnext_single_property_change (position
, Qmouse_face
,
23161 b
= make_number (0);
23163 e
= make_number (SCHARS (object
) - 1);
23165 fast_find_string_pos (w
, XINT (b
), object
,
23166 &dpyinfo
->mouse_face_beg_col
,
23167 &dpyinfo
->mouse_face_beg_row
,
23168 &dpyinfo
->mouse_face_beg_x
,
23169 &dpyinfo
->mouse_face_beg_y
, 0);
23170 fast_find_string_pos (w
, XINT (e
), object
,
23171 &dpyinfo
->mouse_face_end_col
,
23172 &dpyinfo
->mouse_face_end_row
,
23173 &dpyinfo
->mouse_face_end_x
,
23174 &dpyinfo
->mouse_face_end_y
, 1);
23175 dpyinfo
->mouse_face_past_end
= 0;
23176 dpyinfo
->mouse_face_window
= window
;
23177 dpyinfo
->mouse_face_face_id
23178 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
23179 glyph
->face_id
, 1);
23180 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23181 cursor
= No_Cursor
;
23183 else if (STRINGP (object
) && NILP (mouse_face
))
23185 /* A string which doesn't have mouse-face, but
23186 the text ``under'' it might have. */
23187 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
23188 int start
= MATRIX_ROW_START_CHARPOS (r
);
23190 pos
= string_buffer_position (w
, object
, start
);
23192 mouse_face
= get_char_property_and_overlay (make_number (pos
),
23196 if (!NILP (mouse_face
) && !NILP (overlay
))
23198 Lisp_Object before
= Foverlay_start (overlay
);
23199 Lisp_Object after
= Foverlay_end (overlay
);
23202 /* Note that we might not be able to find position
23203 BEFORE in the glyph matrix if the overlay is
23204 entirely covered by a `display' property. In
23205 this case, we overshoot. So let's stop in
23206 the glyph matrix before glyphs for OBJECT. */
23207 fast_find_position (w
, XFASTINT (before
),
23208 &dpyinfo
->mouse_face_beg_col
,
23209 &dpyinfo
->mouse_face_beg_row
,
23210 &dpyinfo
->mouse_face_beg_x
,
23211 &dpyinfo
->mouse_face_beg_y
,
23214 dpyinfo
->mouse_face_past_end
23215 = !fast_find_position (w
, XFASTINT (after
),
23216 &dpyinfo
->mouse_face_end_col
,
23217 &dpyinfo
->mouse_face_end_row
,
23218 &dpyinfo
->mouse_face_end_x
,
23219 &dpyinfo
->mouse_face_end_y
,
23221 dpyinfo
->mouse_face_window
= window
;
23222 dpyinfo
->mouse_face_face_id
23223 = face_at_buffer_position (w
, pos
, 0, 0,
23225 !dpyinfo
->mouse_face_hidden
);
23227 /* Display it as active. */
23228 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23229 cursor
= No_Cursor
;
23236 /* Look for a `help-echo' property. */
23237 if (NILP (help_echo_string
)) {
23238 Lisp_Object help
, overlay
;
23240 /* Check overlays first. */
23241 help
= overlay
= Qnil
;
23242 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
23244 overlay
= overlay_vec
[i
];
23245 help
= Foverlay_get (overlay
, Qhelp_echo
);
23250 help_echo_string
= help
;
23251 help_echo_window
= window
;
23252 help_echo_object
= overlay
;
23253 help_echo_pos
= pos
;
23257 Lisp_Object object
= glyph
->object
;
23258 int charpos
= glyph
->charpos
;
23260 /* Try text properties. */
23261 if (STRINGP (object
)
23263 && charpos
< SCHARS (object
))
23265 help
= Fget_text_property (make_number (charpos
),
23266 Qhelp_echo
, object
);
23269 /* If the string itself doesn't specify a help-echo,
23270 see if the buffer text ``under'' it does. */
23271 struct glyph_row
*r
23272 = MATRIX_ROW (w
->current_matrix
, vpos
);
23273 int start
= MATRIX_ROW_START_CHARPOS (r
);
23274 int pos
= string_buffer_position (w
, object
, start
);
23277 help
= Fget_char_property (make_number (pos
),
23278 Qhelp_echo
, w
->buffer
);
23282 object
= w
->buffer
;
23287 else if (BUFFERP (object
)
23290 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
23295 help_echo_string
= help
;
23296 help_echo_window
= window
;
23297 help_echo_object
= object
;
23298 help_echo_pos
= charpos
;
23303 /* Look for a `pointer' property. */
23304 if (NILP (pointer
))
23306 /* Check overlays first. */
23307 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
23308 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
23310 if (NILP (pointer
))
23312 Lisp_Object object
= glyph
->object
;
23313 int charpos
= glyph
->charpos
;
23315 /* Try text properties. */
23316 if (STRINGP (object
)
23318 && charpos
< SCHARS (object
))
23320 pointer
= Fget_text_property (make_number (charpos
),
23322 if (NILP (pointer
))
23324 /* If the string itself doesn't specify a pointer,
23325 see if the buffer text ``under'' it does. */
23326 struct glyph_row
*r
23327 = MATRIX_ROW (w
->current_matrix
, vpos
);
23328 int start
= MATRIX_ROW_START_CHARPOS (r
);
23329 int pos
= string_buffer_position (w
, object
, start
);
23331 pointer
= Fget_char_property (make_number (pos
),
23332 Qpointer
, w
->buffer
);
23335 else if (BUFFERP (object
)
23338 pointer
= Fget_text_property (make_number (charpos
),
23345 current_buffer
= obuf
;
23350 define_frame_cursor1 (f
, cursor
, pointer
);
23355 Clear any mouse-face on window W. This function is part of the
23356 redisplay interface, and is called from try_window_id and similar
23357 functions to ensure the mouse-highlight is off. */
23360 x_clear_window_mouse_face (w
)
23363 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23364 Lisp_Object window
;
23367 XSETWINDOW (window
, w
);
23368 if (EQ (window
, dpyinfo
->mouse_face_window
))
23369 clear_mouse_face (dpyinfo
);
23375 Just discard the mouse face information for frame F, if any.
23376 This is used when the size of F is changed. */
23379 cancel_mouse_face (f
)
23382 Lisp_Object window
;
23383 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23385 window
= dpyinfo
->mouse_face_window
;
23386 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
23388 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
23389 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
23390 dpyinfo
->mouse_face_window
= Qnil
;
23395 #endif /* HAVE_WINDOW_SYSTEM */
23398 /***********************************************************************
23400 ***********************************************************************/
23402 #ifdef HAVE_WINDOW_SYSTEM
23404 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
23405 which intersects rectangle R. R is in window-relative coordinates. */
23408 expose_area (w
, row
, r
, area
)
23410 struct glyph_row
*row
;
23412 enum glyph_row_area area
;
23414 struct glyph
*first
= row
->glyphs
[area
];
23415 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
23416 struct glyph
*last
;
23417 int first_x
, start_x
, x
;
23419 if (area
== TEXT_AREA
&& row
->fill_line_p
)
23420 /* If row extends face to end of line write the whole line. */
23421 draw_glyphs (w
, 0, row
, area
,
23422 0, row
->used
[area
],
23423 DRAW_NORMAL_TEXT
, 0);
23426 /* Set START_X to the window-relative start position for drawing glyphs of
23427 AREA. The first glyph of the text area can be partially visible.
23428 The first glyphs of other areas cannot. */
23429 start_x
= window_box_left_offset (w
, area
);
23431 if (area
== TEXT_AREA
)
23434 /* Find the first glyph that must be redrawn. */
23436 && x
+ first
->pixel_width
< r
->x
)
23438 x
+= first
->pixel_width
;
23442 /* Find the last one. */
23446 && x
< r
->x
+ r
->width
)
23448 x
+= last
->pixel_width
;
23454 draw_glyphs (w
, first_x
- start_x
, row
, area
,
23455 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
23456 DRAW_NORMAL_TEXT
, 0);
23461 /* Redraw the parts of the glyph row ROW on window W intersecting
23462 rectangle R. R is in window-relative coordinates. Value is
23463 non-zero if mouse-face was overwritten. */
23466 expose_line (w
, row
, r
)
23468 struct glyph_row
*row
;
23471 xassert (row
->enabled_p
);
23473 if (row
->mode_line_p
|| w
->pseudo_window_p
)
23474 draw_glyphs (w
, 0, row
, TEXT_AREA
,
23475 0, row
->used
[TEXT_AREA
],
23476 DRAW_NORMAL_TEXT
, 0);
23479 if (row
->used
[LEFT_MARGIN_AREA
])
23480 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
23481 if (row
->used
[TEXT_AREA
])
23482 expose_area (w
, row
, r
, TEXT_AREA
);
23483 if (row
->used
[RIGHT_MARGIN_AREA
])
23484 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
23485 draw_row_fringe_bitmaps (w
, row
);
23488 return row
->mouse_face_p
;
23492 /* Redraw those parts of glyphs rows during expose event handling that
23493 overlap other rows. Redrawing of an exposed line writes over parts
23494 of lines overlapping that exposed line; this function fixes that.
23496 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
23497 row in W's current matrix that is exposed and overlaps other rows.
23498 LAST_OVERLAPPING_ROW is the last such row. */
23501 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
23503 struct glyph_row
*first_overlapping_row
;
23504 struct glyph_row
*last_overlapping_row
;
23506 struct glyph_row
*row
;
23508 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
23509 if (row
->overlapping_p
)
23511 xassert (row
->enabled_p
&& !row
->mode_line_p
);
23513 if (row
->used
[LEFT_MARGIN_AREA
])
23514 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
23516 if (row
->used
[TEXT_AREA
])
23517 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
23519 if (row
->used
[RIGHT_MARGIN_AREA
])
23520 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
23525 /* Return non-zero if W's cursor intersects rectangle R. */
23528 phys_cursor_in_rect_p (w
, r
)
23532 XRectangle cr
, result
;
23533 struct glyph
*cursor_glyph
;
23534 struct glyph_row
*row
;
23536 if (w
->phys_cursor
.vpos
>= 0
23537 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
23538 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
23540 && row
->cursor_in_fringe_p
)
23542 /* Cursor is in the fringe. */
23543 cr
.x
= window_box_right_offset (w
,
23544 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
23545 ? RIGHT_MARGIN_AREA
23548 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
23549 cr
.height
= row
->height
;
23550 return x_intersect_rectangles (&cr
, r
, &result
);
23553 cursor_glyph
= get_phys_cursor_glyph (w
);
23556 /* r is relative to W's box, but w->phys_cursor.x is relative
23557 to left edge of W's TEXT area. Adjust it. */
23558 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
23559 cr
.y
= w
->phys_cursor
.y
;
23560 cr
.width
= cursor_glyph
->pixel_width
;
23561 cr
.height
= w
->phys_cursor_height
;
23562 /* ++KFS: W32 version used W32-specific IntersectRect here, but
23563 I assume the effect is the same -- and this is portable. */
23564 return x_intersect_rectangles (&cr
, r
, &result
);
23566 /* If we don't understand the format, pretend we're not in the hot-spot. */
23572 Draw a vertical window border to the right of window W if W doesn't
23573 have vertical scroll bars. */
23576 x_draw_vertical_border (w
)
23579 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23581 /* We could do better, if we knew what type of scroll-bar the adjacent
23582 windows (on either side) have... But we don't :-(
23583 However, I think this works ok. ++KFS 2003-04-25 */
23585 /* Redraw borders between horizontally adjacent windows. Don't
23586 do it for frames with vertical scroll bars because either the
23587 right scroll bar of a window, or the left scroll bar of its
23588 neighbor will suffice as a border. */
23589 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
23592 if (!WINDOW_RIGHTMOST_P (w
)
23593 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
23595 int x0
, x1
, y0
, y1
;
23597 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23600 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23603 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
23605 else if (!WINDOW_LEFTMOST_P (w
)
23606 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
23608 int x0
, x1
, y0
, y1
;
23610 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23613 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23616 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
23621 /* Redraw the part of window W intersection rectangle FR. Pixel
23622 coordinates in FR are frame-relative. Call this function with
23623 input blocked. Value is non-zero if the exposure overwrites
23627 expose_window (w
, fr
)
23631 struct frame
*f
= XFRAME (w
->frame
);
23633 int mouse_face_overwritten_p
= 0;
23635 /* If window is not yet fully initialized, do nothing. This can
23636 happen when toolkit scroll bars are used and a window is split.
23637 Reconfiguring the scroll bar will generate an expose for a newly
23639 if (w
->current_matrix
== NULL
)
23642 /* When we're currently updating the window, display and current
23643 matrix usually don't agree. Arrange for a thorough display
23645 if (w
== updated_window
)
23647 SET_FRAME_GARBAGED (f
);
23651 /* Frame-relative pixel rectangle of W. */
23652 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
23653 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
23654 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
23655 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
23657 if (x_intersect_rectangles (fr
, &wr
, &r
))
23659 int yb
= window_text_bottom_y (w
);
23660 struct glyph_row
*row
;
23661 int cursor_cleared_p
;
23662 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
23664 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
23665 r
.x
, r
.y
, r
.width
, r
.height
));
23667 /* Convert to window coordinates. */
23668 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
23669 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
23671 /* Turn off the cursor. */
23672 if (!w
->pseudo_window_p
23673 && phys_cursor_in_rect_p (w
, &r
))
23675 x_clear_cursor (w
);
23676 cursor_cleared_p
= 1;
23679 cursor_cleared_p
= 0;
23681 /* Update lines intersecting rectangle R. */
23682 first_overlapping_row
= last_overlapping_row
= NULL
;
23683 for (row
= w
->current_matrix
->rows
;
23688 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
23690 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
23691 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
23692 || (r
.y
>= y0
&& r
.y
< y1
)
23693 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
23695 /* A header line may be overlapping, but there is no need
23696 to fix overlapping areas for them. KFS 2005-02-12 */
23697 if (row
->overlapping_p
&& !row
->mode_line_p
)
23699 if (first_overlapping_row
== NULL
)
23700 first_overlapping_row
= row
;
23701 last_overlapping_row
= row
;
23704 if (expose_line (w
, row
, &r
))
23705 mouse_face_overwritten_p
= 1;
23712 /* Display the mode line if there is one. */
23713 if (WINDOW_WANTS_MODELINE_P (w
)
23714 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
23716 && row
->y
< r
.y
+ r
.height
)
23718 if (expose_line (w
, row
, &r
))
23719 mouse_face_overwritten_p
= 1;
23722 if (!w
->pseudo_window_p
)
23724 /* Fix the display of overlapping rows. */
23725 if (first_overlapping_row
)
23726 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
23728 /* Draw border between windows. */
23729 x_draw_vertical_border (w
);
23731 /* Turn the cursor on again. */
23732 if (cursor_cleared_p
)
23733 update_window_cursor (w
, 1);
23737 return mouse_face_overwritten_p
;
23742 /* Redraw (parts) of all windows in the window tree rooted at W that
23743 intersect R. R contains frame pixel coordinates. Value is
23744 non-zero if the exposure overwrites mouse-face. */
23747 expose_window_tree (w
, r
)
23751 struct frame
*f
= XFRAME (w
->frame
);
23752 int mouse_face_overwritten_p
= 0;
23754 while (w
&& !FRAME_GARBAGED_P (f
))
23756 if (!NILP (w
->hchild
))
23757 mouse_face_overwritten_p
23758 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
23759 else if (!NILP (w
->vchild
))
23760 mouse_face_overwritten_p
23761 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
23763 mouse_face_overwritten_p
|= expose_window (w
, r
);
23765 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
23768 return mouse_face_overwritten_p
;
23773 Redisplay an exposed area of frame F. X and Y are the upper-left
23774 corner of the exposed rectangle. W and H are width and height of
23775 the exposed area. All are pixel values. W or H zero means redraw
23776 the entire frame. */
23779 expose_frame (f
, x
, y
, w
, h
)
23784 int mouse_face_overwritten_p
= 0;
23786 TRACE ((stderr
, "expose_frame "));
23788 /* No need to redraw if frame will be redrawn soon. */
23789 if (FRAME_GARBAGED_P (f
))
23791 TRACE ((stderr
, " garbaged\n"));
23795 /* If basic faces haven't been realized yet, there is no point in
23796 trying to redraw anything. This can happen when we get an expose
23797 event while Emacs is starting, e.g. by moving another window. */
23798 if (FRAME_FACE_CACHE (f
) == NULL
23799 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
23801 TRACE ((stderr
, " no faces\n"));
23805 if (w
== 0 || h
== 0)
23808 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
23809 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
23819 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
23820 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
23822 if (WINDOWP (f
->tool_bar_window
))
23823 mouse_face_overwritten_p
23824 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
23826 #ifdef HAVE_X_WINDOWS
23828 #ifndef USE_X_TOOLKIT
23829 if (WINDOWP (f
->menu_bar_window
))
23830 mouse_face_overwritten_p
23831 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
23832 #endif /* not USE_X_TOOLKIT */
23836 /* Some window managers support a focus-follows-mouse style with
23837 delayed raising of frames. Imagine a partially obscured frame,
23838 and moving the mouse into partially obscured mouse-face on that
23839 frame. The visible part of the mouse-face will be highlighted,
23840 then the WM raises the obscured frame. With at least one WM, KDE
23841 2.1, Emacs is not getting any event for the raising of the frame
23842 (even tried with SubstructureRedirectMask), only Expose events.
23843 These expose events will draw text normally, i.e. not
23844 highlighted. Which means we must redo the highlight here.
23845 Subsume it under ``we love X''. --gerd 2001-08-15 */
23846 /* Included in Windows version because Windows most likely does not
23847 do the right thing if any third party tool offers
23848 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
23849 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
23851 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23852 if (f
== dpyinfo
->mouse_face_mouse_frame
)
23854 int x
= dpyinfo
->mouse_face_mouse_x
;
23855 int y
= dpyinfo
->mouse_face_mouse_y
;
23856 clear_mouse_face (dpyinfo
);
23857 note_mouse_highlight (f
, x
, y
);
23864 Determine the intersection of two rectangles R1 and R2. Return
23865 the intersection in *RESULT. Value is non-zero if RESULT is not
23869 x_intersect_rectangles (r1
, r2
, result
)
23870 XRectangle
*r1
, *r2
, *result
;
23872 XRectangle
*left
, *right
;
23873 XRectangle
*upper
, *lower
;
23874 int intersection_p
= 0;
23876 /* Rearrange so that R1 is the left-most rectangle. */
23878 left
= r1
, right
= r2
;
23880 left
= r2
, right
= r1
;
23882 /* X0 of the intersection is right.x0, if this is inside R1,
23883 otherwise there is no intersection. */
23884 if (right
->x
<= left
->x
+ left
->width
)
23886 result
->x
= right
->x
;
23888 /* The right end of the intersection is the minimum of the
23889 the right ends of left and right. */
23890 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
23893 /* Same game for Y. */
23895 upper
= r1
, lower
= r2
;
23897 upper
= r2
, lower
= r1
;
23899 /* The upper end of the intersection is lower.y0, if this is inside
23900 of upper. Otherwise, there is no intersection. */
23901 if (lower
->y
<= upper
->y
+ upper
->height
)
23903 result
->y
= lower
->y
;
23905 /* The lower end of the intersection is the minimum of the lower
23906 ends of upper and lower. */
23907 result
->height
= (min (lower
->y
+ lower
->height
,
23908 upper
->y
+ upper
->height
)
23910 intersection_p
= 1;
23914 return intersection_p
;
23917 #endif /* HAVE_WINDOW_SYSTEM */
23920 /***********************************************************************
23922 ***********************************************************************/
23927 Vwith_echo_area_save_vector
= Qnil
;
23928 staticpro (&Vwith_echo_area_save_vector
);
23930 Vmessage_stack
= Qnil
;
23931 staticpro (&Vmessage_stack
);
23933 Qinhibit_redisplay
= intern ("inhibit-redisplay");
23934 staticpro (&Qinhibit_redisplay
);
23936 message_dolog_marker1
= Fmake_marker ();
23937 staticpro (&message_dolog_marker1
);
23938 message_dolog_marker2
= Fmake_marker ();
23939 staticpro (&message_dolog_marker2
);
23940 message_dolog_marker3
= Fmake_marker ();
23941 staticpro (&message_dolog_marker3
);
23944 defsubr (&Sdump_frame_glyph_matrix
);
23945 defsubr (&Sdump_glyph_matrix
);
23946 defsubr (&Sdump_glyph_row
);
23947 defsubr (&Sdump_tool_bar_row
);
23948 defsubr (&Strace_redisplay
);
23949 defsubr (&Strace_to_stderr
);
23951 #ifdef HAVE_WINDOW_SYSTEM
23952 defsubr (&Stool_bar_lines_needed
);
23953 defsubr (&Slookup_image_map
);
23955 defsubr (&Sformat_mode_line
);
23956 defsubr (&Sinvisible_p
);
23958 staticpro (&Qmenu_bar_update_hook
);
23959 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
23961 staticpro (&Qoverriding_terminal_local_map
);
23962 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
23964 staticpro (&Qoverriding_local_map
);
23965 Qoverriding_local_map
= intern ("overriding-local-map");
23967 staticpro (&Qwindow_scroll_functions
);
23968 Qwindow_scroll_functions
= intern ("window-scroll-functions");
23970 staticpro (&Qredisplay_end_trigger_functions
);
23971 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
23973 staticpro (&Qinhibit_point_motion_hooks
);
23974 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
23976 QCdata
= intern (":data");
23977 staticpro (&QCdata
);
23978 Qdisplay
= intern ("display");
23979 staticpro (&Qdisplay
);
23980 Qspace_width
= intern ("space-width");
23981 staticpro (&Qspace_width
);
23982 Qraise
= intern ("raise");
23983 staticpro (&Qraise
);
23984 Qslice
= intern ("slice");
23985 staticpro (&Qslice
);
23986 Qspace
= intern ("space");
23987 staticpro (&Qspace
);
23988 Qmargin
= intern ("margin");
23989 staticpro (&Qmargin
);
23990 Qpointer
= intern ("pointer");
23991 staticpro (&Qpointer
);
23992 Qleft_margin
= intern ("left-margin");
23993 staticpro (&Qleft_margin
);
23994 Qright_margin
= intern ("right-margin");
23995 staticpro (&Qright_margin
);
23996 Qcenter
= intern ("center");
23997 staticpro (&Qcenter
);
23998 Qline_height
= intern ("line-height");
23999 staticpro (&Qline_height
);
24000 QCalign_to
= intern (":align-to");
24001 staticpro (&QCalign_to
);
24002 QCrelative_width
= intern (":relative-width");
24003 staticpro (&QCrelative_width
);
24004 QCrelative_height
= intern (":relative-height");
24005 staticpro (&QCrelative_height
);
24006 QCeval
= intern (":eval");
24007 staticpro (&QCeval
);
24008 QCpropertize
= intern (":propertize");
24009 staticpro (&QCpropertize
);
24010 QCfile
= intern (":file");
24011 staticpro (&QCfile
);
24012 Qfontified
= intern ("fontified");
24013 staticpro (&Qfontified
);
24014 Qfontification_functions
= intern ("fontification-functions");
24015 staticpro (&Qfontification_functions
);
24016 Qtrailing_whitespace
= intern ("trailing-whitespace");
24017 staticpro (&Qtrailing_whitespace
);
24018 Qescape_glyph
= intern ("escape-glyph");
24019 staticpro (&Qescape_glyph
);
24020 Qnobreak_space
= intern ("nobreak-space");
24021 staticpro (&Qnobreak_space
);
24022 Qimage
= intern ("image");
24023 staticpro (&Qimage
);
24024 QCmap
= intern (":map");
24025 staticpro (&QCmap
);
24026 QCpointer
= intern (":pointer");
24027 staticpro (&QCpointer
);
24028 Qrect
= intern ("rect");
24029 staticpro (&Qrect
);
24030 Qcircle
= intern ("circle");
24031 staticpro (&Qcircle
);
24032 Qpoly
= intern ("poly");
24033 staticpro (&Qpoly
);
24034 Qmessage_truncate_lines
= intern ("message-truncate-lines");
24035 staticpro (&Qmessage_truncate_lines
);
24036 Qgrow_only
= intern ("grow-only");
24037 staticpro (&Qgrow_only
);
24038 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
24039 staticpro (&Qinhibit_menubar_update
);
24040 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
24041 staticpro (&Qinhibit_eval_during_redisplay
);
24042 Qposition
= intern ("position");
24043 staticpro (&Qposition
);
24044 Qbuffer_position
= intern ("buffer-position");
24045 staticpro (&Qbuffer_position
);
24046 Qobject
= intern ("object");
24047 staticpro (&Qobject
);
24048 Qbar
= intern ("bar");
24050 Qhbar
= intern ("hbar");
24051 staticpro (&Qhbar
);
24052 Qbox
= intern ("box");
24054 Qhollow
= intern ("hollow");
24055 staticpro (&Qhollow
);
24056 Qhand
= intern ("hand");
24057 staticpro (&Qhand
);
24058 Qarrow
= intern ("arrow");
24059 staticpro (&Qarrow
);
24060 Qtext
= intern ("text");
24061 staticpro (&Qtext
);
24062 Qrisky_local_variable
= intern ("risky-local-variable");
24063 staticpro (&Qrisky_local_variable
);
24064 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
24065 staticpro (&Qinhibit_free_realized_faces
);
24067 list_of_error
= Fcons (Fcons (intern ("error"),
24068 Fcons (intern ("void-variable"), Qnil
)),
24070 staticpro (&list_of_error
);
24072 Qlast_arrow_position
= intern ("last-arrow-position");
24073 staticpro (&Qlast_arrow_position
);
24074 Qlast_arrow_string
= intern ("last-arrow-string");
24075 staticpro (&Qlast_arrow_string
);
24077 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
24078 staticpro (&Qoverlay_arrow_string
);
24079 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
24080 staticpro (&Qoverlay_arrow_bitmap
);
24082 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
24083 staticpro (&echo_buffer
[0]);
24084 staticpro (&echo_buffer
[1]);
24086 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
24087 staticpro (&echo_area_buffer
[0]);
24088 staticpro (&echo_area_buffer
[1]);
24090 Vmessages_buffer_name
= build_string ("*Messages*");
24091 staticpro (&Vmessages_buffer_name
);
24093 mode_line_proptrans_alist
= Qnil
;
24094 staticpro (&mode_line_proptrans_alist
);
24095 mode_line_string_list
= Qnil
;
24096 staticpro (&mode_line_string_list
);
24097 mode_line_string_face
= Qnil
;
24098 staticpro (&mode_line_string_face
);
24099 mode_line_string_face_prop
= Qnil
;
24100 staticpro (&mode_line_string_face_prop
);
24101 Vmode_line_unwind_vector
= Qnil
;
24102 staticpro (&Vmode_line_unwind_vector
);
24104 help_echo_string
= Qnil
;
24105 staticpro (&help_echo_string
);
24106 help_echo_object
= Qnil
;
24107 staticpro (&help_echo_object
);
24108 help_echo_window
= Qnil
;
24109 staticpro (&help_echo_window
);
24110 previous_help_echo_string
= Qnil
;
24111 staticpro (&previous_help_echo_string
);
24112 help_echo_pos
= -1;
24114 #ifdef HAVE_WINDOW_SYSTEM
24115 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
24116 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
24117 For example, if a block cursor is over a tab, it will be drawn as
24118 wide as that tab on the display. */);
24119 x_stretch_cursor_p
= 0;
24122 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
24123 doc
: /* *Non-nil means highlight trailing whitespace.
24124 The face used for trailing whitespace is `trailing-whitespace'. */);
24125 Vshow_trailing_whitespace
= Qnil
;
24127 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
24128 doc
: /* *Control highlighting of nobreak space and soft hyphen.
24129 A value of t means highlight the character itself (for nobreak space,
24130 use face `nobreak-space').
24131 A value of nil means no highlighting.
24132 Other values mean display the escape glyph followed by an ordinary
24133 space or ordinary hyphen. */);
24134 Vnobreak_char_display
= Qt
;
24136 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
24137 doc
: /* *The pointer shape to show in void text areas.
24138 A value of nil means to show the text pointer. Other options are `arrow',
24139 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
24140 Vvoid_text_area_pointer
= Qarrow
;
24142 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
24143 doc
: /* Non-nil means don't actually do any redisplay.
24144 This is used for internal purposes. */);
24145 Vinhibit_redisplay
= Qnil
;
24147 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
24148 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
24149 Vglobal_mode_string
= Qnil
;
24151 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
24152 doc
: /* Marker for where to display an arrow on top of the buffer text.
24153 This must be the beginning of a line in order to work.
24154 See also `overlay-arrow-string'. */);
24155 Voverlay_arrow_position
= Qnil
;
24157 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
24158 doc
: /* String to display as an arrow in non-window frames.
24159 See also `overlay-arrow-position'. */);
24160 Voverlay_arrow_string
= build_string ("=>");
24162 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
24163 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
24164 The symbols on this list are examined during redisplay to determine
24165 where to display overlay arrows. */);
24166 Voverlay_arrow_variable_list
24167 = Fcons (intern ("overlay-arrow-position"), Qnil
);
24169 DEFVAR_INT ("scroll-step", &scroll_step
,
24170 doc
: /* *The number of lines to try scrolling a window by when point moves out.
24171 If that fails to bring point back on frame, point is centered instead.
24172 If this is zero, point is always centered after it moves off frame.
24173 If you want scrolling to always be a line at a time, you should set
24174 `scroll-conservatively' to a large value rather than set this to 1. */);
24176 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
24177 doc
: /* *Scroll up to this many lines, to bring point back on screen.
24178 If point moves off-screen, redisplay will scroll by up to
24179 `scroll-conservatively' lines in order to bring point just barely
24180 onto the screen again. If that cannot be done, then redisplay
24181 recenters point as usual.
24183 A value of zero means always recenter point if it moves off screen. */);
24184 scroll_conservatively
= 0;
24186 DEFVAR_INT ("scroll-margin", &scroll_margin
,
24187 doc
: /* *Number of lines of margin at the top and bottom of a window.
24188 Recenter the window whenever point gets within this many lines
24189 of the top or bottom of the window. */);
24192 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
24193 doc
: /* Pixels per inch value for non-window system displays.
24194 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
24195 Vdisplay_pixels_per_inch
= make_float (72.0);
24198 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
24201 DEFVAR_BOOL ("truncate-partial-width-windows",
24202 &truncate_partial_width_windows
,
24203 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
24204 truncate_partial_width_windows
= 1;
24206 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
24207 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
24208 Any other value means to use the appropriate face, `mode-line',
24209 `header-line', or `menu' respectively. */);
24210 mode_line_inverse_video
= 1;
24212 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
24213 doc
: /* *Maximum buffer size for which line number should be displayed.
24214 If the buffer is bigger than this, the line number does not appear
24215 in the mode line. A value of nil means no limit. */);
24216 Vline_number_display_limit
= Qnil
;
24218 DEFVAR_INT ("line-number-display-limit-width",
24219 &line_number_display_limit_width
,
24220 doc
: /* *Maximum line width (in characters) for line number display.
24221 If the average length of the lines near point is bigger than this, then the
24222 line number may be omitted from the mode line. */);
24223 line_number_display_limit_width
= 200;
24225 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
24226 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
24227 highlight_nonselected_windows
= 0;
24229 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
24230 doc
: /* Non-nil if more than one frame is visible on this display.
24231 Minibuffer-only frames don't count, but iconified frames do.
24232 This variable is not guaranteed to be accurate except while processing
24233 `frame-title-format' and `icon-title-format'. */);
24235 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
24236 doc
: /* Template for displaying the title bar of visible frames.
24237 \(Assuming the window manager supports this feature.)
24239 This variable has the same structure as `mode-line-format', except that
24240 the %c and %l constructs are ignored. It is used only on frames for
24241 which no explicit name has been set \(see `modify-frame-parameters'). */);
24243 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
24244 doc
: /* Template for displaying the title bar of an iconified frame.
24245 \(Assuming the window manager supports this feature.)
24246 This variable has the same structure as `mode-line-format' (which see),
24247 and is used only on frames for which no explicit name has been set
24248 \(see `modify-frame-parameters'). */);
24250 = Vframe_title_format
24251 = Fcons (intern ("multiple-frames"),
24252 Fcons (build_string ("%b"),
24253 Fcons (Fcons (empty_unibyte_string
,
24254 Fcons (intern ("invocation-name"),
24255 Fcons (build_string ("@"),
24256 Fcons (intern ("system-name"),
24260 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
24261 doc
: /* Maximum number of lines to keep in the message log buffer.
24262 If nil, disable message logging. If t, log messages but don't truncate
24263 the buffer when it becomes large. */);
24264 Vmessage_log_max
= make_number (100);
24266 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
24267 doc
: /* Functions called before redisplay, if window sizes have changed.
24268 The value should be a list of functions that take one argument.
24269 Just before redisplay, for each frame, if any of its windows have changed
24270 size since the last redisplay, or have been split or deleted,
24271 all the functions in the list are called, with the frame as argument. */);
24272 Vwindow_size_change_functions
= Qnil
;
24274 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
24275 doc
: /* List of functions to call before redisplaying a window with scrolling.
24276 Each function is called with two arguments, the window
24277 and its new display-start position. Note that the value of `window-end'
24278 is not valid when these functions are called. */);
24279 Vwindow_scroll_functions
= Qnil
;
24281 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
24282 doc
: /* Functions called when redisplay of a window reaches the end trigger.
24283 Each function is called with two arguments, the window and the end trigger value.
24284 See `set-window-redisplay-end-trigger'. */);
24285 Vredisplay_end_trigger_functions
= Qnil
;
24287 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
24288 doc
: /* *Non-nil means autoselect window with mouse pointer.
24289 If nil, do not autoselect windows.
24290 A positive number means delay autoselection by that many seconds: a
24291 window is autoselected only after the mouse has remained in that
24292 window for the duration of the delay.
24293 A negative number has a similar effect, but causes windows to be
24294 autoselected only after the mouse has stopped moving. \(Because of
24295 the way Emacs compares mouse events, you will occasionally wait twice
24296 that time before the window gets selected.\)
24297 Any other value means to autoselect window instantaneously when the
24298 mouse pointer enters it.
24300 Autoselection selects the minibuffer only if it is active, and never
24301 unselects the minibuffer if it is active.
24303 When customizing this variable make sure that the actual value of
24304 `focus-follows-mouse' matches the behavior of your window manager. */);
24305 Vmouse_autoselect_window
= Qnil
;
24307 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
24308 doc
: /* *Non-nil means automatically resize tool-bars.
24309 This dynamically changes the tool-bar's height to the minimum height
24310 that is needed to make all tool-bar items visible.
24311 If value is `grow-only', the tool-bar's height is only increased
24312 automatically; to decrease the tool-bar height, use \\[recenter]. */);
24313 Vauto_resize_tool_bars
= Qt
;
24315 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
24316 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
24317 auto_raise_tool_bar_buttons_p
= 1;
24319 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
24320 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
24321 make_cursor_line_fully_visible_p
= 1;
24323 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
24324 doc
: /* *Border below tool-bar in pixels.
24325 If an integer, use it as the height of the border.
24326 If it is one of `internal-border-width' or `border-width', use the
24327 value of the corresponding frame parameter.
24328 Otherwise, no border is added below the tool-bar. */);
24329 Vtool_bar_border
= Qinternal_border_width
;
24331 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
24332 doc
: /* *Margin around tool-bar buttons in pixels.
24333 If an integer, use that for both horizontal and vertical margins.
24334 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
24335 HORZ specifying the horizontal margin, and VERT specifying the
24336 vertical margin. */);
24337 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
24339 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
24340 doc
: /* *Relief thickness of tool-bar buttons. */);
24341 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
24343 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
24344 doc
: /* List of functions to call to fontify regions of text.
24345 Each function is called with one argument POS. Functions must
24346 fontify a region starting at POS in the current buffer, and give
24347 fontified regions the property `fontified'. */);
24348 Vfontification_functions
= Qnil
;
24349 Fmake_variable_buffer_local (Qfontification_functions
);
24351 DEFVAR_BOOL ("unibyte-display-via-language-environment",
24352 &unibyte_display_via_language_environment
,
24353 doc
: /* *Non-nil means display unibyte text according to language environment.
24354 Specifically this means that unibyte non-ASCII characters
24355 are displayed by converting them to the equivalent multibyte characters
24356 according to the current language environment. As a result, they are
24357 displayed according to the current fontset. */);
24358 unibyte_display_via_language_environment
= 0;
24360 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
24361 doc
: /* *Maximum height for resizing mini-windows.
24362 If a float, it specifies a fraction of the mini-window frame's height.
24363 If an integer, it specifies a number of lines. */);
24364 Vmax_mini_window_height
= make_float (0.25);
24366 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
24367 doc
: /* *How to resize mini-windows.
24368 A value of nil means don't automatically resize mini-windows.
24369 A value of t means resize them to fit the text displayed in them.
24370 A value of `grow-only', the default, means let mini-windows grow
24371 only, until their display becomes empty, at which point the windows
24372 go back to their normal size. */);
24373 Vresize_mini_windows
= Qgrow_only
;
24375 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
24376 doc
: /* Alist specifying how to blink the cursor off.
24377 Each element has the form (ON-STATE . OFF-STATE). Whenever the
24378 `cursor-type' frame-parameter or variable equals ON-STATE,
24379 comparing using `equal', Emacs uses OFF-STATE to specify
24380 how to blink it off. ON-STATE and OFF-STATE are values for
24381 the `cursor-type' frame parameter.
24383 If a frame's ON-STATE has no entry in this list,
24384 the frame's other specifications determine how to blink the cursor off. */);
24385 Vblink_cursor_alist
= Qnil
;
24387 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
24388 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
24389 automatic_hscrolling_p
= 1;
24391 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
24392 doc
: /* *How many columns away from the window edge point is allowed to get
24393 before automatic hscrolling will horizontally scroll the window. */);
24394 hscroll_margin
= 5;
24396 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
24397 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
24398 When point is less than `hscroll-margin' columns from the window
24399 edge, automatic hscrolling will scroll the window by the amount of columns
24400 determined by this variable. If its value is a positive integer, scroll that
24401 many columns. If it's a positive floating-point number, it specifies the
24402 fraction of the window's width to scroll. If it's nil or zero, point will be
24403 centered horizontally after the scroll. Any other value, including negative
24404 numbers, are treated as if the value were zero.
24406 Automatic hscrolling always moves point outside the scroll margin, so if
24407 point was more than scroll step columns inside the margin, the window will
24408 scroll more than the value given by the scroll step.
24410 Note that the lower bound for automatic hscrolling specified by `scroll-left'
24411 and `scroll-right' overrides this variable's effect. */);
24412 Vhscroll_step
= make_number (0);
24414 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
24415 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
24416 Bind this around calls to `message' to let it take effect. */);
24417 message_truncate_lines
= 0;
24419 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
24420 doc
: /* Normal hook run to update the menu bar definitions.
24421 Redisplay runs this hook before it redisplays the menu bar.
24422 This is used to update submenus such as Buffers,
24423 whose contents depend on various data. */);
24424 Vmenu_bar_update_hook
= Qnil
;
24426 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
24427 doc
: /* Frame for which we are updating a menu.
24428 The enable predicate for a menu binding should check this variable. */);
24429 Vmenu_updating_frame
= Qnil
;
24431 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
24432 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
24433 inhibit_menubar_update
= 0;
24435 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
24436 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
24437 inhibit_eval_during_redisplay
= 0;
24439 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
24440 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
24441 inhibit_free_realized_faces
= 0;
24444 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
24445 doc
: /* Inhibit try_window_id display optimization. */);
24446 inhibit_try_window_id
= 0;
24448 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
24449 doc
: /* Inhibit try_window_reusing display optimization. */);
24450 inhibit_try_window_reusing
= 0;
24452 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
24453 doc
: /* Inhibit try_cursor_movement display optimization. */);
24454 inhibit_try_cursor_movement
= 0;
24455 #endif /* GLYPH_DEBUG */
24457 DEFVAR_INT ("overline-margin", &overline_margin
,
24458 doc
: /* *Space between overline and text, in pixels.
24459 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
24460 margin to the caracter height. */);
24461 overline_margin
= 2;
24465 /* Initialize this module when Emacs starts. */
24470 Lisp_Object root_window
;
24471 struct window
*mini_w
;
24473 current_header_line_height
= current_mode_line_height
= -1;
24475 CHARPOS (this_line_start_pos
) = 0;
24477 mini_w
= XWINDOW (minibuf_window
);
24478 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
24480 if (!noninteractive
)
24482 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
24485 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
24486 set_window_height (root_window
,
24487 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
24489 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
24490 set_window_height (minibuf_window
, 1, 0);
24492 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
24493 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
24495 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
24496 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
24497 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
24499 /* The default ellipsis glyphs `...'. */
24500 for (i
= 0; i
< 3; ++i
)
24501 default_invis_vector
[i
] = make_number ('.');
24505 /* Allocate the buffer for frame titles.
24506 Also used for `format-mode-line'. */
24508 mode_line_noprop_buf
= (char *) xmalloc (size
);
24509 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
24510 mode_line_noprop_ptr
= mode_line_noprop_buf
;
24511 mode_line_target
= MODE_LINE_DISPLAY
;
24514 help_echo_showing_p
= 0;
24518 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
24519 (do not change this comment) */