1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
3 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
27 Emacs separates the task of updating the display from code
28 modifying global state, e.g. buffer text. This way functions
29 operating on buffers don't also have to be concerned with updating
32 Updating the display is triggered by the Lisp interpreter when it
33 decides it's time to do it. This is done either automatically for
34 you as part of the interpreter's command loop or as the result of
35 calling Lisp functions like `sit-for'. The C function `redisplay'
36 in xdisp.c is the only entry into the inner redisplay code. (Or,
37 let's say almost---see the description of direct update
40 The following diagram shows how redisplay code is invoked. As you
41 can see, Lisp calls redisplay and vice versa. Under window systems
42 like X, some portions of the redisplay code are also called
43 asynchronously during mouse movement or expose events. It is very
44 important that these code parts do NOT use the C library (malloc,
45 free) because many C libraries under Unix are not reentrant. They
46 may also NOT call functions of the Lisp interpreter which could
47 change the interpreter's state. If you don't follow these rules,
48 you will encounter bugs which are very hard to explain.
50 (Direct functions, see below)
51 direct_output_for_insert,
52 direct_forward_char (dispnew.c)
53 +---------------------------------+
56 +--------------+ redisplay +----------------+
57 | Lisp machine |---------------->| Redisplay code |<--+
58 +--------------+ (xdisp.c) +----------------+ |
60 +----------------------------------+ |
61 Don't use this path when called |
64 expose_window (asynchronous) |
66 X expose events -----+
68 What does redisplay do? Obviously, it has to figure out somehow what
69 has been changed since the last time the display has been updated,
70 and to make these changes visible. Preferably it would do that in
71 a moderately intelligent way, i.e. fast.
73 Changes in buffer text can be deduced from window and buffer
74 structures, and from some global variables like `beg_unchanged' and
75 `end_unchanged'. The contents of the display are additionally
76 recorded in a `glyph matrix', a two-dimensional matrix of glyph
77 structures. Each row in such a matrix corresponds to a line on the
78 display, and each glyph in a row corresponds to a column displaying
79 a character, an image, or what else. This matrix is called the
80 `current glyph matrix' or `current matrix' in redisplay
83 For buffer parts that have been changed since the last update, a
84 second glyph matrix is constructed, the so called `desired glyph
85 matrix' or short `desired matrix'. Current and desired matrix are
86 then compared to find a cheap way to update the display, e.g. by
87 reusing part of the display by scrolling lines.
92 You will find a lot of redisplay optimizations when you start
93 looking at the innards of redisplay. The overall goal of all these
94 optimizations is to make redisplay fast because it is done
97 Two optimizations are not found in xdisp.c. These are the direct
98 operations mentioned above. As the name suggests they follow a
99 different principle than the rest of redisplay. Instead of
100 building a desired matrix and then comparing it with the current
101 display, they perform their actions directly on the display and on
104 One direct operation updates the display after one character has
105 been entered. The other one moves the cursor by one position
106 forward or backward. You find these functions under the names
107 `direct_output_for_insert' and `direct_output_forward_char' in
113 Desired matrices are always built per Emacs window. The function
114 `display_line' is the central function to look at if you are
115 interested. It constructs one row in a desired matrix given an
116 iterator structure containing both a buffer position and a
117 description of the environment in which the text is to be
118 displayed. But this is too early, read on.
120 Characters and pixmaps displayed for a range of buffer text depend
121 on various settings of buffers and windows, on overlays and text
122 properties, on display tables, on selective display. The good news
123 is that all this hairy stuff is hidden behind a small set of
124 interface functions taking an iterator structure (struct it)
127 Iteration over things to be displayed is then simple. It is
128 started by initializing an iterator with a call to init_iterator.
129 Calls to get_next_display_element fill the iterator structure with
130 relevant information about the next thing to display. Calls to
131 set_iterator_to_next move the iterator to the next thing.
133 Besides this, an iterator also contains information about the
134 display environment in which glyphs for display elements are to be
135 produced. It has fields for the width and height of the display,
136 the information whether long lines are truncated or continued, a
137 current X and Y position, and lots of other stuff you can better
140 Glyphs in a desired matrix are normally constructed in a loop
141 calling get_next_display_element and then produce_glyphs. The call
142 to produce_glyphs will fill the iterator structure with pixel
143 information about the element being displayed and at the same time
144 produce glyphs for it. If the display element fits on the line
145 being displayed, set_iterator_to_next is called next, otherwise the
146 glyphs produced are discarded.
151 That just couldn't be all, could it? What about terminal types not
152 supporting operations on sub-windows of the screen? To update the
153 display on such a terminal, window-based glyph matrices are not
154 well suited. To be able to reuse part of the display (scrolling
155 lines up and down), we must instead have a view of the whole
156 screen. This is what `frame matrices' are for. They are a trick.
158 Frames on terminals like above have a glyph pool. Windows on such
159 a frame sub-allocate their glyph memory from their frame's glyph
160 pool. The frame itself is given its own glyph matrices. By
161 coincidence---or maybe something else---rows in window glyph
162 matrices are slices of corresponding rows in frame matrices. Thus
163 writing to window matrices implicitly updates a frame matrix which
164 provides us with the view of the whole screen that we originally
165 wanted to have without having to move many bytes around. To be
166 honest, there is a little bit more done, but not much more. If you
167 plan to extend that code, take a look at dispnew.c. The function
168 build_frame_matrix is a good starting point. */
174 #include "keyboard.h"
177 #include "termchar.h"
178 #include "dispextern.h"
182 #include "commands.h"
186 #include "termhooks.h"
187 #include "intervals.h"
190 #include "region-cache.h"
192 #include "blockinput.h"
194 #ifdef HAVE_X_WINDOWS
204 #ifndef FRAME_X_OUTPUT
205 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
208 #define INFINITY 10000000
210 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
212 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
213 extern int pending_menu_activation
;
216 extern int interrupt_input
;
217 extern int command_loop_level
;
219 extern Lisp_Object do_mouse_tracking
;
221 extern int minibuffer_auto_raise
;
222 extern Lisp_Object Vminibuffer_list
;
224 extern Lisp_Object Qface
;
225 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
227 extern Lisp_Object Voverriding_local_map
;
228 extern Lisp_Object Voverriding_local_map_menu_flag
;
229 extern Lisp_Object Qmenu_item
;
230 extern Lisp_Object Qwhen
;
231 extern Lisp_Object Qhelp_echo
;
233 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
234 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
235 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
236 Lisp_Object Qinhibit_point_motion_hooks
;
237 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
238 Lisp_Object Qfontified
;
239 Lisp_Object Qgrow_only
;
240 Lisp_Object Qinhibit_eval_during_redisplay
;
241 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
244 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
247 Lisp_Object Qarrow
, Qhand
, Qtext
;
249 Lisp_Object Qrisky_local_variable
;
251 /* Holds the list (error). */
252 Lisp_Object list_of_error
;
254 /* Functions called to fontify regions of text. */
256 Lisp_Object Vfontification_functions
;
257 Lisp_Object Qfontification_functions
;
259 /* Non-zero means automatically select any window when the mouse
260 cursor moves into it. */
261 int mouse_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 around tool bar buttons in pixels. */
274 Lisp_Object Vtool_bar_button_margin
;
276 /* Thickness of shadow to draw around tool bar buttons. */
278 EMACS_INT tool_bar_button_relief
;
280 /* Non-zero means automatically resize tool-bars so that all tool-bar
281 items are visible, and no blank lines remain. */
283 int auto_resize_tool_bars_p
;
285 /* Non-zero means draw block and hollow cursor as wide as the glyph
286 under it. For example, if a block cursor is over a tab, it will be
287 drawn as wide as that tab on the display. */
289 int x_stretch_cursor_p
;
291 /* Non-nil means don't actually do any redisplay. */
293 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
295 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
297 int inhibit_eval_during_redisplay
;
299 /* Names of text properties relevant for redisplay. */
301 Lisp_Object Qdisplay
;
302 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
304 /* Symbols used in text property values. */
306 Lisp_Object Vdisplay_pixels_per_inch
;
307 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
308 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
311 Lisp_Object Qmargin
, Qpointer
;
312 Lisp_Object Qline_height
;
313 extern Lisp_Object Qheight
;
314 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
315 extern Lisp_Object Qscroll_bar
;
316 extern Lisp_Object Qcursor
;
318 /* Non-nil means highlight trailing whitespace. */
320 Lisp_Object Vshow_trailing_whitespace
;
322 /* Non-nil means escape non-break space and hyphens. */
324 Lisp_Object Vnobreak_char_display
;
326 #ifdef HAVE_WINDOW_SYSTEM
327 extern Lisp_Object Voverflow_newline_into_fringe
;
329 /* Test if overflow newline into fringe. Called with iterator IT
330 at or past right window margin, and with IT->current_x set. */
332 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
333 (!NILP (Voverflow_newline_into_fringe) \
334 && FRAME_WINDOW_P (it->f) \
335 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
336 && it->current_x == it->last_visible_x)
338 #endif /* HAVE_WINDOW_SYSTEM */
340 /* Non-nil means show the text cursor in void text areas
341 i.e. in blank areas after eol and eob. This used to be
342 the default in 21.3. */
344 Lisp_Object Vvoid_text_area_pointer
;
346 /* Name of the face used to highlight trailing whitespace. */
348 Lisp_Object Qtrailing_whitespace
;
350 /* Name and number of the face used to highlight escape glyphs. */
352 Lisp_Object Qescape_glyph
;
354 /* Name and number of the face used to highlight non-breaking spaces. */
356 Lisp_Object Qnobreak_space
;
358 /* The symbol `image' which is the car of the lists used to represent
363 /* The image map types. */
364 Lisp_Object QCmap
, QCpointer
;
365 Lisp_Object Qrect
, Qcircle
, Qpoly
;
367 /* Non-zero means print newline to stdout before next mini-buffer
370 int noninteractive_need_newline
;
372 /* Non-zero means print newline to message log before next message. */
374 static int message_log_need_newline
;
376 /* Three markers that message_dolog uses.
377 It could allocate them itself, but that causes trouble
378 in handling memory-full errors. */
379 static Lisp_Object message_dolog_marker1
;
380 static Lisp_Object message_dolog_marker2
;
381 static Lisp_Object message_dolog_marker3
;
383 /* The buffer position of the first character appearing entirely or
384 partially on the line of the selected window which contains the
385 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
386 redisplay optimization in redisplay_internal. */
388 static struct text_pos this_line_start_pos
;
390 /* Number of characters past the end of the line above, including the
391 terminating newline. */
393 static struct text_pos this_line_end_pos
;
395 /* The vertical positions and the height of this line. */
397 static int this_line_vpos
;
398 static int this_line_y
;
399 static int this_line_pixel_height
;
401 /* X position at which this display line starts. Usually zero;
402 negative if first character is partially visible. */
404 static int this_line_start_x
;
406 /* Buffer that this_line_.* variables are referring to. */
408 static struct buffer
*this_line_buffer
;
410 /* Nonzero means truncate lines in all windows less wide than the
413 int truncate_partial_width_windows
;
415 /* A flag to control how to display unibyte 8-bit character. */
417 int unibyte_display_via_language_environment
;
419 /* Nonzero means we have more than one non-mini-buffer-only frame.
420 Not guaranteed to be accurate except while parsing
421 frame-title-format. */
425 Lisp_Object Vglobal_mode_string
;
428 /* List of variables (symbols) which hold markers for overlay arrows.
429 The symbols on this list are examined during redisplay to determine
430 where to display overlay arrows. */
432 Lisp_Object Voverlay_arrow_variable_list
;
434 /* Marker for where to display an arrow on top of the buffer text. */
436 Lisp_Object Voverlay_arrow_position
;
438 /* String to display for the arrow. Only used on terminal frames. */
440 Lisp_Object Voverlay_arrow_string
;
442 /* Values of those variables at last redisplay are stored as
443 properties on `overlay-arrow-position' symbol. However, if
444 Voverlay_arrow_position is a marker, last-arrow-position is its
445 numerical position. */
447 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
449 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
450 properties on a symbol in overlay-arrow-variable-list. */
452 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
454 /* Like mode-line-format, but for the title bar on a visible frame. */
456 Lisp_Object Vframe_title_format
;
458 /* Like mode-line-format, but for the title bar on an iconified frame. */
460 Lisp_Object Vicon_title_format
;
462 /* List of functions to call when a window's size changes. These
463 functions get one arg, a frame on which one or more windows' sizes
466 static Lisp_Object Vwindow_size_change_functions
;
468 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
470 /* Nonzero if an overlay arrow has been displayed in this window. */
472 static int overlay_arrow_seen
;
474 /* Nonzero means highlight the region even in nonselected windows. */
476 int highlight_nonselected_windows
;
478 /* If cursor motion alone moves point off frame, try scrolling this
479 many lines up or down if that will bring it back. */
481 static EMACS_INT scroll_step
;
483 /* Nonzero means scroll just far enough to bring point back on the
484 screen, when appropriate. */
486 static EMACS_INT scroll_conservatively
;
488 /* Recenter the window whenever point gets within this many lines of
489 the top or bottom of the window. This value is translated into a
490 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
491 that there is really a fixed pixel height scroll margin. */
493 EMACS_INT scroll_margin
;
495 /* Number of windows showing the buffer of the selected window (or
496 another buffer with the same base buffer). keyboard.c refers to
501 /* Vector containing glyphs for an ellipsis `...'. */
503 static Lisp_Object default_invis_vector
[3];
505 /* Zero means display the mode-line/header-line/menu-bar in the default face
506 (this slightly odd definition is for compatibility with previous versions
507 of emacs), non-zero means display them using their respective faces.
509 This variable is deprecated. */
511 int mode_line_inverse_video
;
513 /* Prompt to display in front of the mini-buffer contents. */
515 Lisp_Object minibuf_prompt
;
517 /* Width of current mini-buffer prompt. Only set after display_line
518 of the line that contains the prompt. */
520 int minibuf_prompt_width
;
522 /* This is the window where the echo area message was displayed. It
523 is always a mini-buffer window, but it may not be the same window
524 currently active as a mini-buffer. */
526 Lisp_Object echo_area_window
;
528 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
529 pushes the current message and the value of
530 message_enable_multibyte on the stack, the function restore_message
531 pops the stack and displays MESSAGE again. */
533 Lisp_Object Vmessage_stack
;
535 /* Nonzero means multibyte characters were enabled when the echo area
536 message was specified. */
538 int message_enable_multibyte
;
540 /* Nonzero if we should redraw the mode lines on the next redisplay. */
542 int update_mode_lines
;
544 /* Nonzero if window sizes or contents have changed since last
545 redisplay that finished. */
547 int windows_or_buffers_changed
;
549 /* Nonzero means a frame's cursor type has been changed. */
551 int cursor_type_changed
;
553 /* Nonzero after display_mode_line if %l was used and it displayed a
556 int line_number_displayed
;
558 /* Maximum buffer size for which to display line numbers. */
560 Lisp_Object Vline_number_display_limit
;
562 /* Line width to consider when repositioning for line number display. */
564 static EMACS_INT line_number_display_limit_width
;
566 /* Number of lines to keep in the message log buffer. t means
567 infinite. nil means don't log at all. */
569 Lisp_Object Vmessage_log_max
;
571 /* The name of the *Messages* buffer, a string. */
573 static Lisp_Object Vmessages_buffer_name
;
575 /* Index 0 is the buffer that holds the current (desired) echo area message,
576 or nil if none is desired right now.
578 Index 1 is the buffer that holds the previously displayed echo area message,
579 or nil to indicate no message. This is normally what's on the screen now.
581 These two can point to the same buffer. That happens when the last
582 message output by the user (or made by echoing) has been displayed. */
584 Lisp_Object echo_area_buffer
[2];
586 /* Permanent pointers to the two buffers that are used for echo area
587 purposes. Once the two buffers are made, and their pointers are
588 placed here, these two slots remain unchanged unless those buffers
589 need to be created afresh. */
591 static Lisp_Object echo_buffer
[2];
593 /* A vector saved used in with_area_buffer to reduce consing. */
595 static Lisp_Object Vwith_echo_area_save_vector
;
597 /* Non-zero means display_echo_area should display the last echo area
598 message again. Set by redisplay_preserve_echo_area. */
600 static int display_last_displayed_message_p
;
602 /* Nonzero if echo area is being used by print; zero if being used by
605 int message_buf_print
;
607 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
609 Lisp_Object Qinhibit_menubar_update
;
610 int inhibit_menubar_update
;
612 /* Maximum height for resizing mini-windows. Either a float
613 specifying a fraction of the available height, or an integer
614 specifying a number of lines. */
616 Lisp_Object Vmax_mini_window_height
;
618 /* Non-zero means messages should be displayed with truncated
619 lines instead of being continued. */
621 int message_truncate_lines
;
622 Lisp_Object Qmessage_truncate_lines
;
624 /* Set to 1 in clear_message to make redisplay_internal aware
625 of an emptied echo area. */
627 static int message_cleared_p
;
629 /* How to blink the default frame cursor off. */
630 Lisp_Object Vblink_cursor_alist
;
632 /* A scratch glyph row with contents used for generating truncation
633 glyphs. Also used in direct_output_for_insert. */
635 #define MAX_SCRATCH_GLYPHS 100
636 struct glyph_row scratch_glyph_row
;
637 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
639 /* Ascent and height of the last line processed by move_it_to. */
641 static int last_max_ascent
, last_height
;
643 /* Non-zero if there's a help-echo in the echo area. */
645 int help_echo_showing_p
;
647 /* If >= 0, computed, exact values of mode-line and header-line height
648 to use in the macros CURRENT_MODE_LINE_HEIGHT and
649 CURRENT_HEADER_LINE_HEIGHT. */
651 int current_mode_line_height
, current_header_line_height
;
653 /* The maximum distance to look ahead for text properties. Values
654 that are too small let us call compute_char_face and similar
655 functions too often which is expensive. Values that are too large
656 let us call compute_char_face and alike too often because we
657 might not be interested in text properties that far away. */
659 #define TEXT_PROP_DISTANCE_LIMIT 100
663 /* Variables to turn off display optimizations from Lisp. */
665 int inhibit_try_window_id
, inhibit_try_window_reusing
;
666 int inhibit_try_cursor_movement
;
668 /* Non-zero means print traces of redisplay if compiled with
671 int trace_redisplay_p
;
673 #endif /* GLYPH_DEBUG */
675 #ifdef DEBUG_TRACE_MOVE
676 /* Non-zero means trace with TRACE_MOVE to stderr. */
679 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
681 #define TRACE_MOVE(x) (void) 0
684 /* Non-zero means automatically scroll windows horizontally to make
687 int automatic_hscrolling_p
;
689 /* How close to the margin can point get before the window is scrolled
691 EMACS_INT hscroll_margin
;
693 /* How much to scroll horizontally when point is inside the above margin. */
694 Lisp_Object Vhscroll_step
;
696 /* The variable `resize-mini-windows'. If nil, don't resize
697 mini-windows. If t, always resize them to fit the text they
698 display. If `grow-only', let mini-windows grow only until they
701 Lisp_Object Vresize_mini_windows
;
703 /* Buffer being redisplayed -- for redisplay_window_error. */
705 struct buffer
*displayed_buffer
;
707 /* Value returned from text property handlers (see below). */
712 HANDLED_RECOMPUTE_PROPS
,
713 HANDLED_OVERLAY_STRING_CONSUMED
,
717 /* A description of text properties that redisplay is interested
722 /* The name of the property. */
725 /* A unique index for the property. */
728 /* A handler function called to set up iterator IT from the property
729 at IT's current position. Value is used to steer handle_stop. */
730 enum prop_handled (*handler
) P_ ((struct it
*it
));
733 static enum prop_handled handle_face_prop
P_ ((struct it
*));
734 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
735 static enum prop_handled handle_display_prop
P_ ((struct it
*));
736 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
737 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
738 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
740 /* Properties handled by iterators. */
742 static struct props it_props
[] =
744 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
745 /* Handle `face' before `display' because some sub-properties of
746 `display' need to know the face. */
747 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
748 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
749 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
750 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
754 /* Value is the position described by X. If X is a marker, value is
755 the marker_position of X. Otherwise, value is X. */
757 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
759 /* Enumeration returned by some move_it_.* functions internally. */
763 /* Not used. Undefined value. */
766 /* Move ended at the requested buffer position or ZV. */
767 MOVE_POS_MATCH_OR_ZV
,
769 /* Move ended at the requested X pixel position. */
772 /* Move within a line ended at the end of a line that must be
776 /* Move within a line ended at the end of a line that would
777 be displayed truncated. */
780 /* Move within a line ended at a line end. */
784 /* This counter is used to clear the face cache every once in a while
785 in redisplay_internal. It is incremented for each redisplay.
786 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
789 #define CLEAR_FACE_CACHE_COUNT 500
790 static int clear_face_cache_count
;
792 /* Similarly for the image cache. */
794 #ifdef HAVE_WINDOW_SYSTEM
795 #define CLEAR_IMAGE_CACHE_COUNT 101
796 static int clear_image_cache_count
;
799 /* Record the previous terminal frame we displayed. */
801 static struct frame
*previous_terminal_frame
;
803 /* Non-zero while redisplay_internal is in progress. */
807 /* Non-zero means don't free realized faces. Bound while freeing
808 realized faces is dangerous because glyph matrices might still
811 int inhibit_free_realized_faces
;
812 Lisp_Object Qinhibit_free_realized_faces
;
814 /* If a string, XTread_socket generates an event to display that string.
815 (The display is done in read_char.) */
817 Lisp_Object help_echo_string
;
818 Lisp_Object help_echo_window
;
819 Lisp_Object help_echo_object
;
822 /* Temporary variable for XTread_socket. */
824 Lisp_Object previous_help_echo_string
;
826 /* Null glyph slice */
828 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
831 /* Function prototypes. */
833 static void setup_for_ellipsis
P_ ((struct it
*, int));
834 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
835 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
836 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
837 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
838 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
839 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
842 static int invisible_text_between_p
P_ ((struct it
*, int, int));
845 static void pint2str
P_ ((char *, int, int));
846 static void pint2hrstr
P_ ((char *, int, int));
847 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
849 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
850 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
851 static void store_mode_line_noprop_char
P_ ((char));
852 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
853 static void x_consider_frame_title
P_ ((Lisp_Object
));
854 static void handle_stop
P_ ((struct it
*));
855 static int tool_bar_lines_needed
P_ ((struct frame
*));
856 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
857 static void ensure_echo_area_buffers
P_ ((void));
858 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
859 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
860 static int with_echo_area_buffer
P_ ((struct window
*, int,
861 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
862 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
863 static void clear_garbaged_frames
P_ ((void));
864 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
865 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
866 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
867 static int display_echo_area
P_ ((struct window
*));
868 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
869 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
870 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
871 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
872 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
874 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
875 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
876 static void insert_left_trunc_glyphs
P_ ((struct it
*));
877 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
879 static void extend_face_to_end_of_line
P_ ((struct it
*));
880 static int append_space_for_newline
P_ ((struct it
*, int));
881 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
882 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
883 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
884 static int trailing_whitespace_p
P_ ((int));
885 static int message_log_check_duplicate
P_ ((int, int, int, int));
886 static void push_it
P_ ((struct it
*));
887 static void pop_it
P_ ((struct it
*));
888 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
889 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
890 static void redisplay_internal
P_ ((int));
891 static int echo_area_display
P_ ((int));
892 static void redisplay_windows
P_ ((Lisp_Object
));
893 static void redisplay_window
P_ ((Lisp_Object
, int));
894 static Lisp_Object
redisplay_window_error ();
895 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
896 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
897 static void update_menu_bar
P_ ((struct frame
*, int));
898 static int try_window_reusing_current_matrix
P_ ((struct window
*));
899 static int try_window_id
P_ ((struct window
*));
900 static int display_line
P_ ((struct it
*));
901 static int display_mode_lines
P_ ((struct window
*));
902 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
903 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
904 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
905 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
906 static void display_menu_bar
P_ ((struct window
*));
907 static int display_count_lines
P_ ((int, int, int, int, int *));
908 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
909 int, int, struct it
*, int, int, int, int));
910 static void compute_line_metrics
P_ ((struct it
*));
911 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
912 static int get_overlay_strings
P_ ((struct it
*, int));
913 static void next_overlay_string
P_ ((struct it
*));
914 static void reseat
P_ ((struct it
*, struct text_pos
, int));
915 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
916 static void back_to_previous_visible_line_start
P_ ((struct it
*));
917 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
918 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
919 static int next_element_from_ellipsis
P_ ((struct it
*));
920 static int next_element_from_display_vector
P_ ((struct it
*));
921 static int next_element_from_string
P_ ((struct it
*));
922 static int next_element_from_c_string
P_ ((struct it
*));
923 static int next_element_from_buffer
P_ ((struct it
*));
924 static int next_element_from_composition
P_ ((struct it
*));
925 static int next_element_from_image
P_ ((struct it
*));
926 static int next_element_from_stretch
P_ ((struct it
*));
927 static void load_overlay_strings
P_ ((struct it
*, int));
928 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
929 struct display_pos
*));
930 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
931 Lisp_Object
, int, int, int, int));
932 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
934 void move_it_vertically_backward
P_ ((struct it
*, int));
935 static void init_to_row_start
P_ ((struct it
*, struct window
*,
936 struct glyph_row
*));
937 static int init_to_row_end
P_ ((struct it
*, struct window
*,
938 struct glyph_row
*));
939 static void back_to_previous_line_start
P_ ((struct it
*));
940 static int forward_to_next_line_start
P_ ((struct it
*, int *));
941 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
943 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
944 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
945 static int number_of_chars
P_ ((unsigned char *, int));
946 static void compute_stop_pos
P_ ((struct it
*));
947 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
949 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
950 static int next_overlay_change
P_ ((int));
951 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
952 Lisp_Object
, struct text_pos
*,
954 static int underlying_face_id
P_ ((struct it
*));
955 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
958 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
959 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
961 #ifdef HAVE_WINDOW_SYSTEM
963 static void update_tool_bar
P_ ((struct frame
*, int));
964 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
965 static int redisplay_tool_bar
P_ ((struct frame
*));
966 static void display_tool_bar_line
P_ ((struct it
*));
967 static void notice_overwritten_cursor
P_ ((struct window
*,
969 int, int, int, int));
973 #endif /* HAVE_WINDOW_SYSTEM */
976 /***********************************************************************
977 Window display dimensions
978 ***********************************************************************/
980 /* Return the bottom boundary y-position for text lines in window W.
981 This is the first y position at which a line cannot start.
982 It is relative to the top of the window.
984 This is the height of W minus the height of a mode line, if any. */
987 window_text_bottom_y (w
)
990 int height
= WINDOW_TOTAL_HEIGHT (w
);
992 if (WINDOW_WANTS_MODELINE_P (w
))
993 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
997 /* Return the pixel width of display area AREA of window W. AREA < 0
998 means return the total width of W, not including fringes to
999 the left and right of the window. */
1002 window_box_width (w
, area
)
1006 int cols
= XFASTINT (w
->total_cols
);
1009 if (!w
->pseudo_window_p
)
1011 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1013 if (area
== TEXT_AREA
)
1015 if (INTEGERP (w
->left_margin_cols
))
1016 cols
-= XFASTINT (w
->left_margin_cols
);
1017 if (INTEGERP (w
->right_margin_cols
))
1018 cols
-= XFASTINT (w
->right_margin_cols
);
1019 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1021 else if (area
== LEFT_MARGIN_AREA
)
1023 cols
= (INTEGERP (w
->left_margin_cols
)
1024 ? XFASTINT (w
->left_margin_cols
) : 0);
1027 else if (area
== RIGHT_MARGIN_AREA
)
1029 cols
= (INTEGERP (w
->right_margin_cols
)
1030 ? XFASTINT (w
->right_margin_cols
) : 0);
1035 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1039 /* Return the pixel height of the display area of window W, not
1040 including mode lines of W, if any. */
1043 window_box_height (w
)
1046 struct frame
*f
= XFRAME (w
->frame
);
1047 int height
= WINDOW_TOTAL_HEIGHT (w
);
1049 xassert (height
>= 0);
1051 /* Note: the code below that determines the mode-line/header-line
1052 height is essentially the same as that contained in the macro
1053 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1054 the appropriate glyph row has its `mode_line_p' flag set,
1055 and if it doesn't, uses estimate_mode_line_height instead. */
1057 if (WINDOW_WANTS_MODELINE_P (w
))
1059 struct glyph_row
*ml_row
1060 = (w
->current_matrix
&& w
->current_matrix
->rows
1061 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1063 if (ml_row
&& ml_row
->mode_line_p
)
1064 height
-= ml_row
->height
;
1066 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1069 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1071 struct glyph_row
*hl_row
1072 = (w
->current_matrix
&& w
->current_matrix
->rows
1073 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1075 if (hl_row
&& hl_row
->mode_line_p
)
1076 height
-= hl_row
->height
;
1078 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1081 /* With a very small font and a mode-line that's taller than
1082 default, we might end up with a negative height. */
1083 return max (0, height
);
1086 /* Return the window-relative coordinate of the left edge of display
1087 area AREA of window W. AREA < 0 means return the left edge of the
1088 whole window, to the right of the left fringe of W. */
1091 window_box_left_offset (w
, area
)
1097 if (w
->pseudo_window_p
)
1100 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1102 if (area
== TEXT_AREA
)
1103 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1104 + window_box_width (w
, LEFT_MARGIN_AREA
));
1105 else if (area
== RIGHT_MARGIN_AREA
)
1106 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1107 + window_box_width (w
, LEFT_MARGIN_AREA
)
1108 + window_box_width (w
, TEXT_AREA
)
1109 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1111 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1112 else if (area
== LEFT_MARGIN_AREA
1113 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1114 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1120 /* Return the window-relative coordinate of the right edge of display
1121 area AREA of window W. AREA < 0 means return the left edge of the
1122 whole window, to the left of the right fringe of W. */
1125 window_box_right_offset (w
, area
)
1129 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1132 /* Return the frame-relative coordinate of the left edge of display
1133 area AREA of window W. AREA < 0 means return the left edge of the
1134 whole window, to the right of the left fringe of W. */
1137 window_box_left (w
, area
)
1141 struct frame
*f
= XFRAME (w
->frame
);
1144 if (w
->pseudo_window_p
)
1145 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1147 x
= (WINDOW_LEFT_EDGE_X (w
)
1148 + window_box_left_offset (w
, area
));
1154 /* Return the frame-relative coordinate of the right edge of display
1155 area AREA of window W. AREA < 0 means return the left edge of the
1156 whole window, to the left of the right fringe of W. */
1159 window_box_right (w
, area
)
1163 return window_box_left (w
, area
) + window_box_width (w
, area
);
1166 /* Get the bounding box of the display area AREA of window W, without
1167 mode lines, in frame-relative coordinates. AREA < 0 means the
1168 whole window, not including the left and right fringes of
1169 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1170 coordinates of the upper-left corner of the box. Return in
1171 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1174 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1177 int *box_x
, *box_y
, *box_width
, *box_height
;
1180 *box_width
= window_box_width (w
, area
);
1182 *box_height
= window_box_height (w
);
1184 *box_x
= window_box_left (w
, area
);
1187 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1188 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1189 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1194 /* Get the bounding box of the display area AREA of window W, without
1195 mode lines. AREA < 0 means the whole window, not including the
1196 left and right fringe of the window. Return in *TOP_LEFT_X
1197 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1198 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1199 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1203 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1204 bottom_right_x
, bottom_right_y
)
1207 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1209 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1211 *bottom_right_x
+= *top_left_x
;
1212 *bottom_right_y
+= *top_left_y
;
1217 /***********************************************************************
1219 ***********************************************************************/
1221 /* Return the bottom y-position of the line the iterator IT is in.
1222 This can modify IT's settings. */
1228 int line_height
= it
->max_ascent
+ it
->max_descent
;
1229 int line_top_y
= it
->current_y
;
1231 if (line_height
== 0)
1234 line_height
= last_height
;
1235 else if (IT_CHARPOS (*it
) < ZV
)
1237 move_it_by_lines (it
, 1, 1);
1238 line_height
= (it
->max_ascent
|| it
->max_descent
1239 ? it
->max_ascent
+ it
->max_descent
1244 struct glyph_row
*row
= it
->glyph_row
;
1246 /* Use the default character height. */
1247 it
->glyph_row
= NULL
;
1248 it
->what
= IT_CHARACTER
;
1251 PRODUCE_GLYPHS (it
);
1252 line_height
= it
->ascent
+ it
->descent
;
1253 it
->glyph_row
= row
;
1257 return line_top_y
+ line_height
;
1261 /* Return 1 if position CHARPOS is visible in window W.
1262 If visible, set *X and *Y to pixel coordinates of top left corner.
1263 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1264 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1265 and header-lines heights. */
1268 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, exact_mode_line_heights_p
)
1270 int charpos
, *x
, *y
, *rtop
, *rbot
, exact_mode_line_heights_p
;
1273 struct text_pos top
;
1275 struct buffer
*old_buffer
= NULL
;
1280 if (XBUFFER (w
->buffer
) != current_buffer
)
1282 old_buffer
= current_buffer
;
1283 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1286 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1288 /* Compute exact mode line heights, if requested. */
1289 if (exact_mode_line_heights_p
)
1291 if (WINDOW_WANTS_MODELINE_P (w
))
1292 current_mode_line_height
1293 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1294 current_buffer
->mode_line_format
);
1296 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1297 current_header_line_height
1298 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1299 current_buffer
->header_line_format
);
1302 start_display (&it
, w
, top
);
1303 move_it_to (&it
, charpos
, -1, it
.last_visible_y
, -1,
1304 MOVE_TO_POS
| MOVE_TO_Y
);
1306 /* Note that we may overshoot because of invisible text. */
1307 if (IT_CHARPOS (it
) >= charpos
)
1309 int top_x
= it
.current_x
;
1310 int top_y
= it
.current_y
;
1311 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1312 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1314 if (top_y
< window_top_y
)
1315 visible_p
= bottom_y
> window_top_y
;
1316 else if (top_y
< it
.last_visible_y
)
1321 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1322 *rtop
= max (0, window_top_y
- top_y
);
1323 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1331 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1332 move_it_by_lines (&it
, 1, 0);
1333 if (charpos
< IT_CHARPOS (it
))
1336 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1338 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1339 *rtop
= max (0, -it2
.current_y
);
1340 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1341 - it
.last_visible_y
));
1346 set_buffer_internal_1 (old_buffer
);
1348 current_header_line_height
= current_mode_line_height
= -1;
1350 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1351 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1357 /* Return the next character from STR which is MAXLEN bytes long.
1358 Return in *LEN the length of the character. This is like
1359 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1360 we find one, we return a `?', but with the length of the invalid
1364 string_char_and_length (str
, maxlen
, len
)
1365 const unsigned char *str
;
1370 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1371 if (!CHAR_VALID_P (c
, 1))
1372 /* We may not change the length here because other places in Emacs
1373 don't use this function, i.e. they silently accept invalid
1382 /* Given a position POS containing a valid character and byte position
1383 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1385 static struct text_pos
1386 string_pos_nchars_ahead (pos
, string
, nchars
)
1387 struct text_pos pos
;
1391 xassert (STRINGP (string
) && nchars
>= 0);
1393 if (STRING_MULTIBYTE (string
))
1395 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1396 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1401 string_char_and_length (p
, rest
, &len
);
1402 p
+= len
, rest
-= len
;
1403 xassert (rest
>= 0);
1405 BYTEPOS (pos
) += len
;
1409 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1415 /* Value is the text position, i.e. character and byte position,
1416 for character position CHARPOS in STRING. */
1418 static INLINE
struct text_pos
1419 string_pos (charpos
, string
)
1423 struct text_pos pos
;
1424 xassert (STRINGP (string
));
1425 xassert (charpos
>= 0);
1426 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1431 /* Value is a text position, i.e. character and byte position, for
1432 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1433 means recognize multibyte characters. */
1435 static struct text_pos
1436 c_string_pos (charpos
, s
, multibyte_p
)
1441 struct text_pos pos
;
1443 xassert (s
!= NULL
);
1444 xassert (charpos
>= 0);
1448 int rest
= strlen (s
), len
;
1450 SET_TEXT_POS (pos
, 0, 0);
1453 string_char_and_length (s
, rest
, &len
);
1454 s
+= len
, rest
-= len
;
1455 xassert (rest
>= 0);
1457 BYTEPOS (pos
) += len
;
1461 SET_TEXT_POS (pos
, charpos
, charpos
);
1467 /* Value is the number of characters in C string S. MULTIBYTE_P
1468 non-zero means recognize multibyte characters. */
1471 number_of_chars (s
, multibyte_p
)
1479 int rest
= strlen (s
), len
;
1480 unsigned char *p
= (unsigned char *) s
;
1482 for (nchars
= 0; rest
> 0; ++nchars
)
1484 string_char_and_length (p
, rest
, &len
);
1485 rest
-= len
, p
+= len
;
1489 nchars
= strlen (s
);
1495 /* Compute byte position NEWPOS->bytepos corresponding to
1496 NEWPOS->charpos. POS is a known position in string STRING.
1497 NEWPOS->charpos must be >= POS.charpos. */
1500 compute_string_pos (newpos
, pos
, string
)
1501 struct text_pos
*newpos
, pos
;
1504 xassert (STRINGP (string
));
1505 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1507 if (STRING_MULTIBYTE (string
))
1508 *newpos
= string_pos_nchars_ahead (pos
, string
,
1509 CHARPOS (*newpos
) - CHARPOS (pos
));
1511 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1515 Return an estimation of the pixel height of mode or top lines on
1516 frame F. FACE_ID specifies what line's height to estimate. */
1519 estimate_mode_line_height (f
, face_id
)
1521 enum face_id face_id
;
1523 #ifdef HAVE_WINDOW_SYSTEM
1524 if (FRAME_WINDOW_P (f
))
1526 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1528 /* This function is called so early when Emacs starts that the face
1529 cache and mode line face are not yet initialized. */
1530 if (FRAME_FACE_CACHE (f
))
1532 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1536 height
= FONT_HEIGHT (face
->font
);
1537 if (face
->box_line_width
> 0)
1538 height
+= 2 * face
->box_line_width
;
1549 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1550 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1551 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1552 not force the value into range. */
1555 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1557 register int pix_x
, pix_y
;
1559 NativeRectangle
*bounds
;
1563 #ifdef HAVE_WINDOW_SYSTEM
1564 if (FRAME_WINDOW_P (f
))
1566 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1567 even for negative values. */
1569 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1571 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1573 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1574 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1577 STORE_NATIVE_RECT (*bounds
,
1578 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1579 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1580 FRAME_COLUMN_WIDTH (f
) - 1,
1581 FRAME_LINE_HEIGHT (f
) - 1);
1587 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1588 pix_x
= FRAME_TOTAL_COLS (f
);
1592 else if (pix_y
> FRAME_LINES (f
))
1593 pix_y
= FRAME_LINES (f
);
1603 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1604 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1605 can't tell the positions because W's display is not up to date,
1609 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1612 int *frame_x
, *frame_y
;
1614 #ifdef HAVE_WINDOW_SYSTEM
1615 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1619 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1620 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1622 if (display_completed
)
1624 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1625 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1626 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1632 hpos
+= glyph
->pixel_width
;
1636 /* If first glyph is partially visible, its first visible position is still 0. */
1648 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1649 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1660 #ifdef HAVE_WINDOW_SYSTEM
1662 /* Find the glyph under window-relative coordinates X/Y in window W.
1663 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1664 strings. Return in *HPOS and *VPOS the row and column number of
1665 the glyph found. Return in *AREA the glyph area containing X.
1666 Value is a pointer to the glyph found or null if X/Y is not on
1667 text, or we can't tell because W's current matrix is not up to
1670 static struct glyph
*
1671 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1674 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1676 struct glyph
*glyph
, *end
;
1677 struct glyph_row
*row
= NULL
;
1680 /* Find row containing Y. Give up if some row is not enabled. */
1681 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1683 row
= MATRIX_ROW (w
->current_matrix
, i
);
1684 if (!row
->enabled_p
)
1686 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1693 /* Give up if Y is not in the window. */
1694 if (i
== w
->current_matrix
->nrows
)
1697 /* Get the glyph area containing X. */
1698 if (w
->pseudo_window_p
)
1705 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1707 *area
= LEFT_MARGIN_AREA
;
1708 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1710 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1713 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1717 *area
= RIGHT_MARGIN_AREA
;
1718 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1722 /* Find glyph containing X. */
1723 glyph
= row
->glyphs
[*area
];
1724 end
= glyph
+ row
->used
[*area
];
1726 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1728 x
-= glyph
->pixel_width
;
1738 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1741 *hpos
= glyph
- row
->glyphs
[*area
];
1747 Convert frame-relative x/y to coordinates relative to window W.
1748 Takes pseudo-windows into account. */
1751 frame_to_window_pixel_xy (w
, x
, y
)
1755 if (w
->pseudo_window_p
)
1757 /* A pseudo-window is always full-width, and starts at the
1758 left edge of the frame, plus a frame border. */
1759 struct frame
*f
= XFRAME (w
->frame
);
1760 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1761 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1765 *x
-= WINDOW_LEFT_EDGE_X (w
);
1766 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1771 Return in RECTS[] at most N clipping rectangles for glyph string S.
1772 Return the number of stored rectangles. */
1775 get_glyph_string_clip_rects (s
, rects
, n
)
1776 struct glyph_string
*s
;
1777 NativeRectangle
*rects
;
1785 if (s
->row
->full_width_p
)
1787 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1788 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1789 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1791 /* Unless displaying a mode or menu bar line, which are always
1792 fully visible, clip to the visible part of the row. */
1793 if (s
->w
->pseudo_window_p
)
1794 r
.height
= s
->row
->visible_height
;
1796 r
.height
= s
->height
;
1800 /* This is a text line that may be partially visible. */
1801 r
.x
= window_box_left (s
->w
, s
->area
);
1802 r
.width
= window_box_width (s
->w
, s
->area
);
1803 r
.height
= s
->row
->visible_height
;
1807 if (r
.x
< s
->clip_head
->x
)
1809 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1810 r
.width
-= s
->clip_head
->x
- r
.x
;
1813 r
.x
= s
->clip_head
->x
;
1816 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1818 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1819 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1824 /* If S draws overlapping rows, it's sufficient to use the top and
1825 bottom of the window for clipping because this glyph string
1826 intentionally draws over other lines. */
1827 if (s
->for_overlaps
)
1829 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1830 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1832 /* Alas, the above simple strategy does not work for the
1833 environments with anti-aliased text: if the same text is
1834 drawn onto the same place multiple times, it gets thicker.
1835 If the overlap we are processing is for the erased cursor, we
1836 take the intersection with the rectagle of the cursor. */
1837 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1839 XRectangle rc
, r_save
= r
;
1841 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1842 rc
.y
= s
->w
->phys_cursor
.y
;
1843 rc
.width
= s
->w
->phys_cursor_width
;
1844 rc
.height
= s
->w
->phys_cursor_height
;
1846 x_intersect_rectangles (&r_save
, &rc
, &r
);
1851 /* Don't use S->y for clipping because it doesn't take partially
1852 visible lines into account. For example, it can be negative for
1853 partially visible lines at the top of a window. */
1854 if (!s
->row
->full_width_p
1855 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1856 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1858 r
.y
= max (0, s
->row
->y
);
1860 /* If drawing a tool-bar window, draw it over the internal border
1861 at the top of the window. */
1862 if (WINDOWP (s
->f
->tool_bar_window
)
1863 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1864 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1867 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1869 /* If drawing the cursor, don't let glyph draw outside its
1870 advertised boundaries. Cleartype does this under some circumstances. */
1871 if (s
->hl
== DRAW_CURSOR
)
1873 struct glyph
*glyph
= s
->first_glyph
;
1878 r
.width
-= s
->x
- r
.x
;
1881 r
.width
= min (r
.width
, glyph
->pixel_width
);
1883 /* If r.y is below window bottom, ensure that we still see a cursor. */
1884 height
= min (glyph
->ascent
+ glyph
->descent
,
1885 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1886 max_y
= window_text_bottom_y (s
->w
) - height
;
1887 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1888 if (s
->ybase
- glyph
->ascent
> max_y
)
1895 /* Don't draw cursor glyph taller than our actual glyph. */
1896 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1897 if (height
< r
.height
)
1899 max_y
= r
.y
+ r
.height
;
1900 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1901 r
.height
= min (max_y
- r
.y
, height
);
1906 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1907 || (s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1)
1909 #ifdef CONVERT_FROM_XRECT
1910 CONVERT_FROM_XRECT (r
, *rects
);
1918 /* If we are processing overlapping and allowed to return
1919 multiple clipping rectangles, we exclude the row of the glyph
1920 string from the clipping rectangle. This is to avoid drawing
1921 the same text on the environment with anti-aliasing. */
1922 #ifdef CONVERT_FROM_XRECT
1925 XRectangle
*rs
= rects
;
1927 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
1929 if (s
->for_overlaps
& OVERLAPS_PRED
)
1932 if (r
.y
+ r
.height
> row_y
)
1934 rs
[i
].height
= row_y
- r
.y
;
1939 if (s
->for_overlaps
& OVERLAPS_SUCC
)
1942 if (r
.y
< row_y
+ s
->row
->visible_height
)
1943 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
1945 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
1946 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
1954 #ifdef CONVERT_FROM_XRECT
1955 for (i
= 0; i
< n
; i
++)
1956 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
1963 Return in *NR the clipping rectangle for glyph string S. */
1966 get_glyph_string_clip_rect (s
, nr
)
1967 struct glyph_string
*s
;
1968 NativeRectangle
*nr
;
1970 get_glyph_string_clip_rects (s
, nr
, 1);
1975 Return the position and height of the phys cursor in window W.
1976 Set w->phys_cursor_width to width of phys cursor.
1980 get_phys_cursor_geometry (w
, row
, glyph
, heightp
)
1982 struct glyph_row
*row
;
1983 struct glyph
*glyph
;
1986 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1987 int y
, wd
, h
, h0
, y0
;
1989 /* Compute the width of the rectangle to draw. If on a stretch
1990 glyph, and `x-stretch-block-cursor' is nil, don't draw a
1991 rectangle as wide as the glyph, but use a canonical character
1993 wd
= glyph
->pixel_width
- 1;
1997 if (glyph
->type
== STRETCH_GLYPH
1998 && !x_stretch_cursor_p
)
1999 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2000 w
->phys_cursor_width
= wd
;
2002 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2004 /* If y is below window bottom, ensure that we still see a cursor. */
2005 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2007 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2008 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2010 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2013 h
= max (h
- (y0
- y
) + 1, h0
);
2018 y0
= window_text_bottom_y (w
) - h0
;
2027 return WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2031 * Remember which glyph the mouse is over.
2035 remember_mouse_glyph (f
, gx
, gy
, rect
)
2038 NativeRectangle
*rect
;
2042 struct glyph_row
*r
, *gr
, *end_row
;
2043 enum window_part part
;
2044 enum glyph_row_area area
;
2045 int x
, y
, width
, height
;
2047 /* Try to determine frame pixel position and size of the glyph under
2048 frame pixel coordinates X/Y on frame F. */
2050 window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0);
2053 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2054 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2058 w
= XWINDOW (window
);
2059 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2060 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2062 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2063 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2065 if (w
->pseudo_window_p
)
2068 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2074 case ON_LEFT_MARGIN
:
2075 area
= LEFT_MARGIN_AREA
;
2078 case ON_RIGHT_MARGIN
:
2079 area
= RIGHT_MARGIN_AREA
;
2082 case ON_HEADER_LINE
:
2084 gr
= (part
== ON_HEADER_LINE
2085 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2086 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2089 goto text_glyph_row_found
;
2096 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2097 if (r
->y
+ r
->height
> y
)
2103 text_glyph_row_found
:
2106 struct glyph
*g
= gr
->glyphs
[area
];
2107 struct glyph
*end
= g
+ gr
->used
[area
];
2109 height
= gr
->height
;
2110 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2111 if (gx
+ g
->pixel_width
> x
)
2116 if (g
->type
== IMAGE_GLYPH
)
2118 /* Don't remember when mouse is over image, as
2119 image may have hot-spots. */
2120 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2123 width
= g
->pixel_width
;
2127 /* Use nominal char spacing at end of line. */
2129 gx
+= (x
/ width
) * width
;
2132 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2133 gx
+= window_box_left_offset (w
, area
);
2137 /* Use nominal line height at end of window. */
2138 gx
= (x
/ width
) * width
;
2140 gy
+= (y
/ height
) * height
;
2144 case ON_LEFT_FRINGE
:
2145 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2146 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2147 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2148 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2151 case ON_RIGHT_FRINGE
:
2152 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2153 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2154 : window_box_right_offset (w
, TEXT_AREA
));
2155 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2159 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2161 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2162 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2163 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2165 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2169 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2170 if (r
->y
+ r
->height
> y
)
2177 height
= gr
->height
;
2180 /* Use nominal line height at end of window. */
2182 gy
+= (y
/ height
) * height
;
2189 /* If there is no glyph under the mouse, then we divide the screen
2190 into a grid of the smallest glyph in the frame, and use that
2193 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2194 round down even for negative values. */
2200 gx
= (gx
/ width
) * width
;
2201 gy
= (gy
/ height
) * height
;
2206 gx
+= WINDOW_LEFT_EDGE_X (w
);
2207 gy
+= WINDOW_TOP_EDGE_Y (w
);
2210 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2212 /* Visible feedback for debugging. */
2215 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2216 f
->output_data
.x
->normal_gc
,
2217 gx
, gy
, width
, height
);
2223 #endif /* HAVE_WINDOW_SYSTEM */
2226 /***********************************************************************
2227 Lisp form evaluation
2228 ***********************************************************************/
2230 /* Error handler for safe_eval and safe_call. */
2233 safe_eval_handler (arg
)
2236 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2241 /* Evaluate SEXPR and return the result, or nil if something went
2242 wrong. Prevent redisplay during the evaluation. */
2250 if (inhibit_eval_during_redisplay
)
2254 int count
= SPECPDL_INDEX ();
2255 struct gcpro gcpro1
;
2258 specbind (Qinhibit_redisplay
, Qt
);
2259 /* Use Qt to ensure debugger does not run,
2260 so there is no possibility of wanting to redisplay. */
2261 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
2264 val
= unbind_to (count
, val
);
2271 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2272 Return the result, or nil if something went wrong. Prevent
2273 redisplay during the evaluation. */
2276 safe_call (nargs
, args
)
2282 if (inhibit_eval_during_redisplay
)
2286 int count
= SPECPDL_INDEX ();
2287 struct gcpro gcpro1
;
2290 gcpro1
.nvars
= nargs
;
2291 specbind (Qinhibit_redisplay
, Qt
);
2292 /* Use Qt to ensure debugger does not run,
2293 so there is no possibility of wanting to redisplay. */
2294 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2297 val
= unbind_to (count
, val
);
2304 /* Call function FN with one argument ARG.
2305 Return the result, or nil if something went wrong. */
2308 safe_call1 (fn
, arg
)
2309 Lisp_Object fn
, arg
;
2311 Lisp_Object args
[2];
2314 return safe_call (2, args
);
2319 /***********************************************************************
2321 ***********************************************************************/
2325 /* Define CHECK_IT to perform sanity checks on iterators.
2326 This is for debugging. It is too slow to do unconditionally. */
2332 if (it
->method
== GET_FROM_STRING
)
2334 xassert (STRINGP (it
->string
));
2335 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2339 xassert (IT_STRING_CHARPOS (*it
) < 0);
2340 if (it
->method
== GET_FROM_BUFFER
)
2342 /* Check that character and byte positions agree. */
2343 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2348 xassert (it
->current
.dpvec_index
>= 0);
2350 xassert (it
->current
.dpvec_index
< 0);
2353 #define CHECK_IT(IT) check_it ((IT))
2357 #define CHECK_IT(IT) (void) 0
2364 /* Check that the window end of window W is what we expect it
2365 to be---the last row in the current matrix displaying text. */
2368 check_window_end (w
)
2371 if (!MINI_WINDOW_P (w
)
2372 && !NILP (w
->window_end_valid
))
2374 struct glyph_row
*row
;
2375 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2376 XFASTINT (w
->window_end_vpos
)),
2378 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2379 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2383 #define CHECK_WINDOW_END(W) check_window_end ((W))
2385 #else /* not GLYPH_DEBUG */
2387 #define CHECK_WINDOW_END(W) (void) 0
2389 #endif /* not GLYPH_DEBUG */
2393 /***********************************************************************
2394 Iterator initialization
2395 ***********************************************************************/
2397 /* Initialize IT for displaying current_buffer in window W, starting
2398 at character position CHARPOS. CHARPOS < 0 means that no buffer
2399 position is specified which is useful when the iterator is assigned
2400 a position later. BYTEPOS is the byte position corresponding to
2401 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2403 If ROW is not null, calls to produce_glyphs with IT as parameter
2404 will produce glyphs in that row.
2406 BASE_FACE_ID is the id of a base face to use. It must be one of
2407 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2408 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2409 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2411 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2412 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2413 will be initialized to use the corresponding mode line glyph row of
2414 the desired matrix of W. */
2417 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2420 int charpos
, bytepos
;
2421 struct glyph_row
*row
;
2422 enum face_id base_face_id
;
2424 int highlight_region_p
;
2426 /* Some precondition checks. */
2427 xassert (w
!= NULL
&& it
!= NULL
);
2428 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2431 /* If face attributes have been changed since the last redisplay,
2432 free realized faces now because they depend on face definitions
2433 that might have changed. Don't free faces while there might be
2434 desired matrices pending which reference these faces. */
2435 if (face_change_count
&& !inhibit_free_realized_faces
)
2437 face_change_count
= 0;
2438 free_all_realized_faces (Qnil
);
2441 /* Use one of the mode line rows of W's desired matrix if
2445 if (base_face_id
== MODE_LINE_FACE_ID
2446 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2447 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2448 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2449 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2453 bzero (it
, sizeof *it
);
2454 it
->current
.overlay_string_index
= -1;
2455 it
->current
.dpvec_index
= -1;
2456 it
->base_face_id
= base_face_id
;
2458 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2460 /* The window in which we iterate over current_buffer: */
2461 XSETWINDOW (it
->window
, w
);
2463 it
->f
= XFRAME (w
->frame
);
2465 /* Extra space between lines (on window systems only). */
2466 if (base_face_id
== DEFAULT_FACE_ID
2467 && FRAME_WINDOW_P (it
->f
))
2469 if (NATNUMP (current_buffer
->extra_line_spacing
))
2470 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2471 else if (FLOATP (current_buffer
->extra_line_spacing
))
2472 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2473 * FRAME_LINE_HEIGHT (it
->f
));
2474 else if (it
->f
->extra_line_spacing
> 0)
2475 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2476 it
->max_extra_line_spacing
= 0;
2479 /* If realized faces have been removed, e.g. because of face
2480 attribute changes of named faces, recompute them. When running
2481 in batch mode, the face cache of Vterminal_frame is null. If
2482 we happen to get called, make a dummy face cache. */
2483 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2484 init_frame_faces (it
->f
);
2485 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2486 recompute_basic_faces (it
->f
);
2488 /* Current value of the `slice', `space-width', and 'height' properties. */
2489 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2490 it
->space_width
= Qnil
;
2491 it
->font_height
= Qnil
;
2492 it
->override_ascent
= -1;
2494 /* Are control characters displayed as `^C'? */
2495 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2497 /* -1 means everything between a CR and the following line end
2498 is invisible. >0 means lines indented more than this value are
2500 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2501 ? XFASTINT (current_buffer
->selective_display
)
2502 : (!NILP (current_buffer
->selective_display
)
2504 it
->selective_display_ellipsis_p
2505 = !NILP (current_buffer
->selective_display_ellipses
);
2507 /* Display table to use. */
2508 it
->dp
= window_display_table (w
);
2510 /* Are multibyte characters enabled in current_buffer? */
2511 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2513 /* Non-zero if we should highlight the region. */
2515 = (!NILP (Vtransient_mark_mode
)
2516 && !NILP (current_buffer
->mark_active
)
2517 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2519 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2520 start and end of a visible region in window IT->w. Set both to
2521 -1 to indicate no region. */
2522 if (highlight_region_p
2523 /* Maybe highlight only in selected window. */
2524 && (/* Either show region everywhere. */
2525 highlight_nonselected_windows
2526 /* Or show region in the selected window. */
2527 || w
== XWINDOW (selected_window
)
2528 /* Or show the region if we are in the mini-buffer and W is
2529 the window the mini-buffer refers to. */
2530 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2531 && WINDOWP (minibuf_selected_window
)
2532 && w
== XWINDOW (minibuf_selected_window
))))
2534 int charpos
= marker_position (current_buffer
->mark
);
2535 it
->region_beg_charpos
= min (PT
, charpos
);
2536 it
->region_end_charpos
= max (PT
, charpos
);
2539 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2541 /* Get the position at which the redisplay_end_trigger hook should
2542 be run, if it is to be run at all. */
2543 if (MARKERP (w
->redisplay_end_trigger
)
2544 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2545 it
->redisplay_end_trigger_charpos
2546 = marker_position (w
->redisplay_end_trigger
);
2547 else if (INTEGERP (w
->redisplay_end_trigger
))
2548 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2550 /* Correct bogus values of tab_width. */
2551 it
->tab_width
= XINT (current_buffer
->tab_width
);
2552 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2555 /* Are lines in the display truncated? */
2556 it
->truncate_lines_p
2557 = (base_face_id
!= DEFAULT_FACE_ID
2558 || XINT (it
->w
->hscroll
)
2559 || (truncate_partial_width_windows
2560 && !WINDOW_FULL_WIDTH_P (it
->w
))
2561 || !NILP (current_buffer
->truncate_lines
));
2563 /* Get dimensions of truncation and continuation glyphs. These are
2564 displayed as fringe bitmaps under X, so we don't need them for such
2566 if (!FRAME_WINDOW_P (it
->f
))
2568 if (it
->truncate_lines_p
)
2570 /* We will need the truncation glyph. */
2571 xassert (it
->glyph_row
== NULL
);
2572 produce_special_glyphs (it
, IT_TRUNCATION
);
2573 it
->truncation_pixel_width
= it
->pixel_width
;
2577 /* We will need the continuation glyph. */
2578 xassert (it
->glyph_row
== NULL
);
2579 produce_special_glyphs (it
, IT_CONTINUATION
);
2580 it
->continuation_pixel_width
= it
->pixel_width
;
2583 /* Reset these values to zero because the produce_special_glyphs
2584 above has changed them. */
2585 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2586 it
->phys_ascent
= it
->phys_descent
= 0;
2589 /* Set this after getting the dimensions of truncation and
2590 continuation glyphs, so that we don't produce glyphs when calling
2591 produce_special_glyphs, above. */
2592 it
->glyph_row
= row
;
2593 it
->area
= TEXT_AREA
;
2595 /* Get the dimensions of the display area. The display area
2596 consists of the visible window area plus a horizontally scrolled
2597 part to the left of the window. All x-values are relative to the
2598 start of this total display area. */
2599 if (base_face_id
!= DEFAULT_FACE_ID
)
2601 /* Mode lines, menu bar in terminal frames. */
2602 it
->first_visible_x
= 0;
2603 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2608 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2609 it
->last_visible_x
= (it
->first_visible_x
2610 + window_box_width (w
, TEXT_AREA
));
2612 /* If we truncate lines, leave room for the truncator glyph(s) at
2613 the right margin. Otherwise, leave room for the continuation
2614 glyph(s). Truncation and continuation glyphs are not inserted
2615 for window-based redisplay. */
2616 if (!FRAME_WINDOW_P (it
->f
))
2618 if (it
->truncate_lines_p
)
2619 it
->last_visible_x
-= it
->truncation_pixel_width
;
2621 it
->last_visible_x
-= it
->continuation_pixel_width
;
2624 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2625 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2628 /* Leave room for a border glyph. */
2629 if (!FRAME_WINDOW_P (it
->f
)
2630 && !WINDOW_RIGHTMOST_P (it
->w
))
2631 it
->last_visible_x
-= 1;
2633 it
->last_visible_y
= window_text_bottom_y (w
);
2635 /* For mode lines and alike, arrange for the first glyph having a
2636 left box line if the face specifies a box. */
2637 if (base_face_id
!= DEFAULT_FACE_ID
)
2641 it
->face_id
= base_face_id
;
2643 /* If we have a boxed mode line, make the first character appear
2644 with a left box line. */
2645 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2646 if (face
->box
!= FACE_NO_BOX
)
2647 it
->start_of_box_run_p
= 1;
2650 /* If a buffer position was specified, set the iterator there,
2651 getting overlays and face properties from that position. */
2652 if (charpos
>= BUF_BEG (current_buffer
))
2654 it
->end_charpos
= ZV
;
2656 IT_CHARPOS (*it
) = charpos
;
2658 /* Compute byte position if not specified. */
2659 if (bytepos
< charpos
)
2660 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2662 IT_BYTEPOS (*it
) = bytepos
;
2664 it
->start
= it
->current
;
2666 /* Compute faces etc. */
2667 reseat (it
, it
->current
.pos
, 1);
2674 /* Initialize IT for the display of window W with window start POS. */
2677 start_display (it
, w
, pos
)
2680 struct text_pos pos
;
2682 struct glyph_row
*row
;
2683 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2685 row
= w
->desired_matrix
->rows
+ first_vpos
;
2686 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2687 it
->first_vpos
= first_vpos
;
2689 /* Don't reseat to previous visible line start if current start
2690 position is in a string or image. */
2691 if (it
->method
== GET_FROM_BUFFER
&& !it
->truncate_lines_p
)
2693 int start_at_line_beg_p
;
2694 int first_y
= it
->current_y
;
2696 /* If window start is not at a line start, skip forward to POS to
2697 get the correct continuation lines width. */
2698 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2699 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2700 if (!start_at_line_beg_p
)
2704 reseat_at_previous_visible_line_start (it
);
2705 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2707 new_x
= it
->current_x
+ it
->pixel_width
;
2709 /* If lines are continued, this line may end in the middle
2710 of a multi-glyph character (e.g. a control character
2711 displayed as \003, or in the middle of an overlay
2712 string). In this case move_it_to above will not have
2713 taken us to the start of the continuation line but to the
2714 end of the continued line. */
2715 if (it
->current_x
> 0
2716 && !it
->truncate_lines_p
/* Lines are continued. */
2717 && (/* And glyph doesn't fit on the line. */
2718 new_x
> it
->last_visible_x
2719 /* Or it fits exactly and we're on a window
2721 || (new_x
== it
->last_visible_x
2722 && FRAME_WINDOW_P (it
->f
))))
2724 if (it
->current
.dpvec_index
>= 0
2725 || it
->current
.overlay_string_index
>= 0)
2727 set_iterator_to_next (it
, 1);
2728 move_it_in_display_line_to (it
, -1, -1, 0);
2731 it
->continuation_lines_width
+= it
->current_x
;
2734 /* We're starting a new display line, not affected by the
2735 height of the continued line, so clear the appropriate
2736 fields in the iterator structure. */
2737 it
->max_ascent
= it
->max_descent
= 0;
2738 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2740 it
->current_y
= first_y
;
2742 it
->current_x
= it
->hpos
= 0;
2746 #if 0 /* Don't assert the following because start_display is sometimes
2747 called intentionally with a window start that is not at a
2748 line start. Please leave this code in as a comment. */
2750 /* Window start should be on a line start, now. */
2751 xassert (it
->continuation_lines_width
2752 || IT_CHARPOS (it
) == BEGV
2753 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2758 /* Return 1 if POS is a position in ellipses displayed for invisible
2759 text. W is the window we display, for text property lookup. */
2762 in_ellipses_for_invisible_text_p (pos
, w
)
2763 struct display_pos
*pos
;
2766 Lisp_Object prop
, window
;
2768 int charpos
= CHARPOS (pos
->pos
);
2770 /* If POS specifies a position in a display vector, this might
2771 be for an ellipsis displayed for invisible text. We won't
2772 get the iterator set up for delivering that ellipsis unless
2773 we make sure that it gets aware of the invisible text. */
2774 if (pos
->dpvec_index
>= 0
2775 && pos
->overlay_string_index
< 0
2776 && CHARPOS (pos
->string_pos
) < 0
2778 && (XSETWINDOW (window
, w
),
2779 prop
= Fget_char_property (make_number (charpos
),
2780 Qinvisible
, window
),
2781 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2783 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2785 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2792 /* Initialize IT for stepping through current_buffer in window W,
2793 starting at position POS that includes overlay string and display
2794 vector/ control character translation position information. Value
2795 is zero if there are overlay strings with newlines at POS. */
2798 init_from_display_pos (it
, w
, pos
)
2801 struct display_pos
*pos
;
2803 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2804 int i
, overlay_strings_with_newlines
= 0;
2806 /* If POS specifies a position in a display vector, this might
2807 be for an ellipsis displayed for invisible text. We won't
2808 get the iterator set up for delivering that ellipsis unless
2809 we make sure that it gets aware of the invisible text. */
2810 if (in_ellipses_for_invisible_text_p (pos
, w
))
2816 /* Keep in mind: the call to reseat in init_iterator skips invisible
2817 text, so we might end up at a position different from POS. This
2818 is only a problem when POS is a row start after a newline and an
2819 overlay starts there with an after-string, and the overlay has an
2820 invisible property. Since we don't skip invisible text in
2821 display_line and elsewhere immediately after consuming the
2822 newline before the row start, such a POS will not be in a string,
2823 but the call to init_iterator below will move us to the
2825 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2827 /* This only scans the current chunk -- it should scan all chunks.
2828 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2829 to 16 in 22.1 to make this a lesser problem. */
2830 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2832 const char *s
= SDATA (it
->overlay_strings
[i
]);
2833 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2835 while (s
< e
&& *s
!= '\n')
2840 overlay_strings_with_newlines
= 1;
2845 /* If position is within an overlay string, set up IT to the right
2847 if (pos
->overlay_string_index
>= 0)
2851 /* If the first overlay string happens to have a `display'
2852 property for an image, the iterator will be set up for that
2853 image, and we have to undo that setup first before we can
2854 correct the overlay string index. */
2855 if (it
->method
== GET_FROM_IMAGE
)
2858 /* We already have the first chunk of overlay strings in
2859 IT->overlay_strings. Load more until the one for
2860 pos->overlay_string_index is in IT->overlay_strings. */
2861 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2863 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2864 it
->current
.overlay_string_index
= 0;
2867 load_overlay_strings (it
, 0);
2868 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2872 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2873 relative_index
= (it
->current
.overlay_string_index
2874 % OVERLAY_STRING_CHUNK_SIZE
);
2875 it
->string
= it
->overlay_strings
[relative_index
];
2876 xassert (STRINGP (it
->string
));
2877 it
->current
.string_pos
= pos
->string_pos
;
2878 it
->method
= GET_FROM_STRING
;
2881 #if 0 /* This is bogus because POS not having an overlay string
2882 position does not mean it's after the string. Example: A
2883 line starting with a before-string and initialization of IT
2884 to the previous row's end position. */
2885 else if (it
->current
.overlay_string_index
>= 0)
2887 /* If POS says we're already after an overlay string ending at
2888 POS, make sure to pop the iterator because it will be in
2889 front of that overlay string. When POS is ZV, we've thereby
2890 also ``processed'' overlay strings at ZV. */
2893 it
->current
.overlay_string_index
= -1;
2894 it
->method
= GET_FROM_BUFFER
;
2895 if (CHARPOS (pos
->pos
) == ZV
)
2896 it
->overlay_strings_at_end_processed_p
= 1;
2900 if (CHARPOS (pos
->string_pos
) >= 0)
2902 /* Recorded position is not in an overlay string, but in another
2903 string. This can only be a string from a `display' property.
2904 IT should already be filled with that string. */
2905 it
->current
.string_pos
= pos
->string_pos
;
2906 xassert (STRINGP (it
->string
));
2909 /* Restore position in display vector translations, control
2910 character translations or ellipses. */
2911 if (pos
->dpvec_index
>= 0)
2913 if (it
->dpvec
== NULL
)
2914 get_next_display_element (it
);
2915 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2916 it
->current
.dpvec_index
= pos
->dpvec_index
;
2920 return !overlay_strings_with_newlines
;
2924 /* Initialize IT for stepping through current_buffer in window W
2925 starting at ROW->start. */
2928 init_to_row_start (it
, w
, row
)
2931 struct glyph_row
*row
;
2933 init_from_display_pos (it
, w
, &row
->start
);
2934 it
->start
= row
->start
;
2935 it
->continuation_lines_width
= row
->continuation_lines_width
;
2940 /* Initialize IT for stepping through current_buffer in window W
2941 starting in the line following ROW, i.e. starting at ROW->end.
2942 Value is zero if there are overlay strings with newlines at ROW's
2946 init_to_row_end (it
, w
, row
)
2949 struct glyph_row
*row
;
2953 if (init_from_display_pos (it
, w
, &row
->end
))
2955 if (row
->continued_p
)
2956 it
->continuation_lines_width
2957 = row
->continuation_lines_width
+ row
->pixel_width
;
2968 /***********************************************************************
2970 ***********************************************************************/
2972 /* Called when IT reaches IT->stop_charpos. Handle text property and
2973 overlay changes. Set IT->stop_charpos to the next position where
2980 enum prop_handled handled
;
2981 int handle_overlay_change_p
;
2985 it
->current
.dpvec_index
= -1;
2986 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
2987 it
->ignore_overlay_strings_at_pos_p
= 0;
2989 /* Use face of preceding text for ellipsis (if invisible) */
2990 if (it
->selective_display_ellipsis_p
)
2991 it
->saved_face_id
= it
->face_id
;
2995 handled
= HANDLED_NORMALLY
;
2997 /* Call text property handlers. */
2998 for (p
= it_props
; p
->handler
; ++p
)
3000 handled
= p
->handler (it
);
3002 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3004 else if (handled
== HANDLED_RETURN
)
3006 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3007 handle_overlay_change_p
= 0;
3010 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3012 /* Don't check for overlay strings below when set to deliver
3013 characters from a display vector. */
3014 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3015 handle_overlay_change_p
= 0;
3017 /* Handle overlay changes. */
3018 if (handle_overlay_change_p
)
3019 handled
= handle_overlay_change (it
);
3021 /* Determine where to stop next. */
3022 if (handled
== HANDLED_NORMALLY
)
3023 compute_stop_pos (it
);
3026 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3030 /* Compute IT->stop_charpos from text property and overlay change
3031 information for IT's current position. */
3034 compute_stop_pos (it
)
3037 register INTERVAL iv
, next_iv
;
3038 Lisp_Object object
, limit
, position
;
3040 /* If nowhere else, stop at the end. */
3041 it
->stop_charpos
= it
->end_charpos
;
3043 if (STRINGP (it
->string
))
3045 /* Strings are usually short, so don't limit the search for
3047 object
= it
->string
;
3049 position
= make_number (IT_STRING_CHARPOS (*it
));
3055 /* If next overlay change is in front of the current stop pos
3056 (which is IT->end_charpos), stop there. Note: value of
3057 next_overlay_change is point-max if no overlay change
3059 charpos
= next_overlay_change (IT_CHARPOS (*it
));
3060 if (charpos
< it
->stop_charpos
)
3061 it
->stop_charpos
= charpos
;
3063 /* If showing the region, we have to stop at the region
3064 start or end because the face might change there. */
3065 if (it
->region_beg_charpos
> 0)
3067 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3068 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3069 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3070 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3073 /* Set up variables for computing the stop position from text
3074 property changes. */
3075 XSETBUFFER (object
, current_buffer
);
3076 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3077 position
= make_number (IT_CHARPOS (*it
));
3081 /* Get the interval containing IT's position. Value is a null
3082 interval if there isn't such an interval. */
3083 iv
= validate_interval_range (object
, &position
, &position
, 0);
3084 if (!NULL_INTERVAL_P (iv
))
3086 Lisp_Object values_here
[LAST_PROP_IDX
];
3089 /* Get properties here. */
3090 for (p
= it_props
; p
->handler
; ++p
)
3091 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3093 /* Look for an interval following iv that has different
3095 for (next_iv
= next_interval (iv
);
3096 (!NULL_INTERVAL_P (next_iv
)
3098 || XFASTINT (limit
) > next_iv
->position
));
3099 next_iv
= next_interval (next_iv
))
3101 for (p
= it_props
; p
->handler
; ++p
)
3103 Lisp_Object new_value
;
3105 new_value
= textget (next_iv
->plist
, *p
->name
);
3106 if (!EQ (values_here
[p
->idx
], new_value
))
3114 if (!NULL_INTERVAL_P (next_iv
))
3116 if (INTEGERP (limit
)
3117 && next_iv
->position
>= XFASTINT (limit
))
3118 /* No text property change up to limit. */
3119 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3121 /* Text properties change in next_iv. */
3122 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3126 xassert (STRINGP (it
->string
)
3127 || (it
->stop_charpos
>= BEGV
3128 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3132 /* Return the position of the next overlay change after POS in
3133 current_buffer. Value is point-max if no overlay change
3134 follows. This is like `next-overlay-change' but doesn't use
3138 next_overlay_change (pos
)
3143 Lisp_Object
*overlays
;
3146 /* Get all overlays at the given position. */
3147 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3149 /* If any of these overlays ends before endpos,
3150 use its ending point instead. */
3151 for (i
= 0; i
< noverlays
; ++i
)
3156 oend
= OVERLAY_END (overlays
[i
]);
3157 oendpos
= OVERLAY_POSITION (oend
);
3158 endpos
= min (endpos
, oendpos
);
3166 /***********************************************************************
3168 ***********************************************************************/
3170 /* Handle changes in the `fontified' property of the current buffer by
3171 calling hook functions from Qfontification_functions to fontify
3174 static enum prop_handled
3175 handle_fontified_prop (it
)
3178 Lisp_Object prop
, pos
;
3179 enum prop_handled handled
= HANDLED_NORMALLY
;
3181 if (!NILP (Vmemory_full
))
3184 /* Get the value of the `fontified' property at IT's current buffer
3185 position. (The `fontified' property doesn't have a special
3186 meaning in strings.) If the value is nil, call functions from
3187 Qfontification_functions. */
3188 if (!STRINGP (it
->string
)
3190 && !NILP (Vfontification_functions
)
3191 && !NILP (Vrun_hooks
)
3192 && (pos
= make_number (IT_CHARPOS (*it
)),
3193 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3196 int count
= SPECPDL_INDEX ();
3199 val
= Vfontification_functions
;
3200 specbind (Qfontification_functions
, Qnil
);
3202 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3203 safe_call1 (val
, pos
);
3206 Lisp_Object globals
, fn
;
3207 struct gcpro gcpro1
, gcpro2
;
3210 GCPRO2 (val
, globals
);
3212 for (; CONSP (val
); val
= XCDR (val
))
3218 /* A value of t indicates this hook has a local
3219 binding; it means to run the global binding too.
3220 In a global value, t should not occur. If it
3221 does, we must ignore it to avoid an endless
3223 for (globals
= Fdefault_value (Qfontification_functions
);
3225 globals
= XCDR (globals
))
3227 fn
= XCAR (globals
);
3229 safe_call1 (fn
, pos
);
3233 safe_call1 (fn
, pos
);
3239 unbind_to (count
, Qnil
);
3241 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3242 something. This avoids an endless loop if they failed to
3243 fontify the text for which reason ever. */
3244 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3245 handled
= HANDLED_RECOMPUTE_PROPS
;
3253 /***********************************************************************
3255 ***********************************************************************/
3257 /* Set up iterator IT from face properties at its current position.
3258 Called from handle_stop. */
3260 static enum prop_handled
3261 handle_face_prop (it
)
3264 int new_face_id
, next_stop
;
3266 if (!STRINGP (it
->string
))
3269 = face_at_buffer_position (it
->w
,
3271 it
->region_beg_charpos
,
3272 it
->region_end_charpos
,
3275 + TEXT_PROP_DISTANCE_LIMIT
),
3278 /* Is this a start of a run of characters with box face?
3279 Caveat: this can be called for a freshly initialized
3280 iterator; face_id is -1 in this case. We know that the new
3281 face will not change until limit, i.e. if the new face has a
3282 box, all characters up to limit will have one. But, as
3283 usual, we don't know whether limit is really the end. */
3284 if (new_face_id
!= it
->face_id
)
3286 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3288 /* If new face has a box but old face has not, this is
3289 the start of a run of characters with box, i.e. it has
3290 a shadow on the left side. The value of face_id of the
3291 iterator will be -1 if this is the initial call that gets
3292 the face. In this case, we have to look in front of IT's
3293 position and see whether there is a face != new_face_id. */
3294 it
->start_of_box_run_p
3295 = (new_face
->box
!= FACE_NO_BOX
3296 && (it
->face_id
>= 0
3297 || IT_CHARPOS (*it
) == BEG
3298 || new_face_id
!= face_before_it_pos (it
)));
3299 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3304 int base_face_id
, bufpos
;
3306 if (it
->current
.overlay_string_index
>= 0)
3307 bufpos
= IT_CHARPOS (*it
);
3311 /* For strings from a buffer, i.e. overlay strings or strings
3312 from a `display' property, use the face at IT's current
3313 buffer position as the base face to merge with, so that
3314 overlay strings appear in the same face as surrounding
3315 text, unless they specify their own faces. */
3316 base_face_id
= underlying_face_id (it
);
3318 new_face_id
= face_at_string_position (it
->w
,
3320 IT_STRING_CHARPOS (*it
),
3322 it
->region_beg_charpos
,
3323 it
->region_end_charpos
,
3327 #if 0 /* This shouldn't be neccessary. Let's check it. */
3328 /* If IT is used to display a mode line we would really like to
3329 use the mode line face instead of the frame's default face. */
3330 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3331 && new_face_id
== DEFAULT_FACE_ID
)
3332 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3335 /* Is this a start of a run of characters with box? Caveat:
3336 this can be called for a freshly allocated iterator; face_id
3337 is -1 is this case. We know that the new face will not
3338 change until the next check pos, i.e. if the new face has a
3339 box, all characters up to that position will have a
3340 box. But, as usual, we don't know whether that position
3341 is really the end. */
3342 if (new_face_id
!= it
->face_id
)
3344 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3345 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3347 /* If new face has a box but old face hasn't, this is the
3348 start of a run of characters with box, i.e. it has a
3349 shadow on the left side. */
3350 it
->start_of_box_run_p
3351 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3352 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3356 it
->face_id
= new_face_id
;
3357 return HANDLED_NORMALLY
;
3361 /* Return the ID of the face ``underlying'' IT's current position,
3362 which is in a string. If the iterator is associated with a
3363 buffer, return the face at IT's current buffer position.
3364 Otherwise, use the iterator's base_face_id. */
3367 underlying_face_id (it
)
3370 int face_id
= it
->base_face_id
, i
;
3372 xassert (STRINGP (it
->string
));
3374 for (i
= it
->sp
- 1; i
>= 0; --i
)
3375 if (NILP (it
->stack
[i
].string
))
3376 face_id
= it
->stack
[i
].face_id
;
3382 /* Compute the face one character before or after the current position
3383 of IT. BEFORE_P non-zero means get the face in front of IT's
3384 position. Value is the id of the face. */
3387 face_before_or_after_it_pos (it
, before_p
)
3392 int next_check_charpos
;
3393 struct text_pos pos
;
3395 xassert (it
->s
== NULL
);
3397 if (STRINGP (it
->string
))
3399 int bufpos
, base_face_id
;
3401 /* No face change past the end of the string (for the case
3402 we are padding with spaces). No face change before the
3404 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3405 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3408 /* Set pos to the position before or after IT's current position. */
3410 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3412 /* For composition, we must check the character after the
3414 pos
= (it
->what
== IT_COMPOSITION
3415 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3416 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3418 if (it
->current
.overlay_string_index
>= 0)
3419 bufpos
= IT_CHARPOS (*it
);
3423 base_face_id
= underlying_face_id (it
);
3425 /* Get the face for ASCII, or unibyte. */
3426 face_id
= face_at_string_position (it
->w
,
3430 it
->region_beg_charpos
,
3431 it
->region_end_charpos
,
3432 &next_check_charpos
,
3435 /* Correct the face for charsets different from ASCII. Do it
3436 for the multibyte case only. The face returned above is
3437 suitable for unibyte text if IT->string is unibyte. */
3438 if (STRING_MULTIBYTE (it
->string
))
3440 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3441 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3443 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3445 c
= string_char_and_length (p
, rest
, &len
);
3446 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3451 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3452 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3455 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3456 pos
= it
->current
.pos
;
3459 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3462 if (it
->what
== IT_COMPOSITION
)
3463 /* For composition, we must check the position after the
3465 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3467 INC_TEXT_POS (pos
, it
->multibyte_p
);
3470 /* Determine face for CHARSET_ASCII, or unibyte. */
3471 face_id
= face_at_buffer_position (it
->w
,
3473 it
->region_beg_charpos
,
3474 it
->region_end_charpos
,
3475 &next_check_charpos
,
3478 /* Correct the face for charsets different from ASCII. Do it
3479 for the multibyte case only. The face returned above is
3480 suitable for unibyte text if current_buffer is unibyte. */
3481 if (it
->multibyte_p
)
3483 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3484 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3485 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3494 /***********************************************************************
3496 ***********************************************************************/
3498 /* Set up iterator IT from invisible properties at its current
3499 position. Called from handle_stop. */
3501 static enum prop_handled
3502 handle_invisible_prop (it
)
3505 enum prop_handled handled
= HANDLED_NORMALLY
;
3507 if (STRINGP (it
->string
))
3509 extern Lisp_Object Qinvisible
;
3510 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3512 /* Get the value of the invisible text property at the
3513 current position. Value will be nil if there is no such
3515 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3516 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3519 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3521 handled
= HANDLED_RECOMPUTE_PROPS
;
3523 /* Get the position at which the next change of the
3524 invisible text property can be found in IT->string.
3525 Value will be nil if the property value is the same for
3526 all the rest of IT->string. */
3527 XSETINT (limit
, SCHARS (it
->string
));
3528 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3531 /* Text at current position is invisible. The next
3532 change in the property is at position end_charpos.
3533 Move IT's current position to that position. */
3534 if (INTEGERP (end_charpos
)
3535 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3537 struct text_pos old
;
3538 old
= it
->current
.string_pos
;
3539 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3540 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3544 /* The rest of the string is invisible. If this is an
3545 overlay string, proceed with the next overlay string
3546 or whatever comes and return a character from there. */
3547 if (it
->current
.overlay_string_index
>= 0)
3549 next_overlay_string (it
);
3550 /* Don't check for overlay strings when we just
3551 finished processing them. */
3552 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3556 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3557 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3564 int invis_p
, newpos
, next_stop
, start_charpos
;
3565 Lisp_Object pos
, prop
, overlay
;
3567 /* First of all, is there invisible text at this position? */
3568 start_charpos
= IT_CHARPOS (*it
);
3569 pos
= make_number (IT_CHARPOS (*it
));
3570 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3572 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3574 /* If we are on invisible text, skip over it. */
3575 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3577 /* Record whether we have to display an ellipsis for the
3579 int display_ellipsis_p
= invis_p
== 2;
3581 handled
= HANDLED_RECOMPUTE_PROPS
;
3583 /* Loop skipping over invisible text. The loop is left at
3584 ZV or with IT on the first char being visible again. */
3587 /* Try to skip some invisible text. Return value is the
3588 position reached which can be equal to IT's position
3589 if there is nothing invisible here. This skips both
3590 over invisible text properties and overlays with
3591 invisible property. */
3592 newpos
= skip_invisible (IT_CHARPOS (*it
),
3593 &next_stop
, ZV
, it
->window
);
3595 /* If we skipped nothing at all we weren't at invisible
3596 text in the first place. If everything to the end of
3597 the buffer was skipped, end the loop. */
3598 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3602 /* We skipped some characters but not necessarily
3603 all there are. Check if we ended up on visible
3604 text. Fget_char_property returns the property of
3605 the char before the given position, i.e. if we
3606 get invis_p = 0, this means that the char at
3607 newpos is visible. */
3608 pos
= make_number (newpos
);
3609 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3610 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3613 /* If we ended up on invisible text, proceed to
3614 skip starting with next_stop. */
3616 IT_CHARPOS (*it
) = next_stop
;
3618 /* If there are adjacent invisible texts, don't lose the
3619 second one's ellipsis. */
3621 display_ellipsis_p
= 1;
3625 /* The position newpos is now either ZV or on visible text. */
3626 IT_CHARPOS (*it
) = newpos
;
3627 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3629 /* If there are before-strings at the start of invisible
3630 text, and the text is invisible because of a text
3631 property, arrange to show before-strings because 20.x did
3632 it that way. (If the text is invisible because of an
3633 overlay property instead of a text property, this is
3634 already handled in the overlay code.) */
3636 && get_overlay_strings (it
, start_charpos
))
3638 handled
= HANDLED_RECOMPUTE_PROPS
;
3639 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3641 else if (display_ellipsis_p
)
3643 /* Make sure that the glyphs of the ellipsis will get
3644 correct `charpos' values. If we would not update
3645 it->position here, the glyphs would belong to the
3646 last visible character _before_ the invisible
3647 text, which confuses `set_cursor_from_row'.
3649 We use the last invisible position instead of the
3650 first because this way the cursor is always drawn on
3651 the first "." of the ellipsis, whenever PT is inside
3652 the invisible text. Otherwise the cursor would be
3653 placed _after_ the ellipsis when the point is after the
3654 first invisible character. */
3655 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3656 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3657 setup_for_ellipsis (it
, 0);
3666 /* Make iterator IT return `...' next.
3667 Replaces LEN characters from buffer. */
3670 setup_for_ellipsis (it
, len
)
3674 /* Use the display table definition for `...'. Invalid glyphs
3675 will be handled by the method returning elements from dpvec. */
3676 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3678 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3679 it
->dpvec
= v
->contents
;
3680 it
->dpend
= v
->contents
+ v
->size
;
3684 /* Default `...'. */
3685 it
->dpvec
= default_invis_vector
;
3686 it
->dpend
= default_invis_vector
+ 3;
3689 it
->dpvec_char_len
= len
;
3690 it
->current
.dpvec_index
= 0;
3691 it
->dpvec_face_id
= -1;
3693 /* Remember the current face id in case glyphs specify faces.
3694 IT's face is restored in set_iterator_to_next.
3695 saved_face_id was set to preceding char's face in handle_stop. */
3696 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3697 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3699 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3705 /***********************************************************************
3707 ***********************************************************************/
3709 /* Set up iterator IT from `display' property at its current position.
3710 Called from handle_stop.
3711 We return HANDLED_RETURN if some part of the display property
3712 overrides the display of the buffer text itself.
3713 Otherwise we return HANDLED_NORMALLY. */
3715 static enum prop_handled
3716 handle_display_prop (it
)
3719 Lisp_Object prop
, object
;
3720 struct text_pos
*position
;
3721 /* Nonzero if some property replaces the display of the text itself. */
3722 int display_replaced_p
= 0;
3724 if (STRINGP (it
->string
))
3726 object
= it
->string
;
3727 position
= &it
->current
.string_pos
;
3731 XSETWINDOW (object
, it
->w
);
3732 position
= &it
->current
.pos
;
3735 /* Reset those iterator values set from display property values. */
3736 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3737 it
->space_width
= Qnil
;
3738 it
->font_height
= Qnil
;
3741 /* We don't support recursive `display' properties, i.e. string
3742 values that have a string `display' property, that have a string
3743 `display' property etc. */
3744 if (!it
->string_from_display_prop_p
)
3745 it
->area
= TEXT_AREA
;
3747 prop
= Fget_char_property (make_number (position
->charpos
),
3750 return HANDLED_NORMALLY
;
3752 if (!STRINGP (it
->string
))
3753 object
= it
->w
->buffer
;
3756 /* Simple properties. */
3757 && !EQ (XCAR (prop
), Qimage
)
3758 && !EQ (XCAR (prop
), Qspace
)
3759 && !EQ (XCAR (prop
), Qwhen
)
3760 && !EQ (XCAR (prop
), Qslice
)
3761 && !EQ (XCAR (prop
), Qspace_width
)
3762 && !EQ (XCAR (prop
), Qheight
)
3763 && !EQ (XCAR (prop
), Qraise
)
3764 /* Marginal area specifications. */
3765 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3766 && !EQ (XCAR (prop
), Qleft_fringe
)
3767 && !EQ (XCAR (prop
), Qright_fringe
)
3768 && !NILP (XCAR (prop
)))
3770 for (; CONSP (prop
); prop
= XCDR (prop
))
3772 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3773 position
, display_replaced_p
))
3774 display_replaced_p
= 1;
3777 else if (VECTORP (prop
))
3780 for (i
= 0; i
< ASIZE (prop
); ++i
)
3781 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3782 position
, display_replaced_p
))
3783 display_replaced_p
= 1;
3787 int ret
= handle_single_display_spec (it
, prop
, object
, position
, 0);
3788 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3789 return HANDLED_RECOMPUTE_PROPS
;
3791 display_replaced_p
= 1;
3794 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3798 /* Value is the position of the end of the `display' property starting
3799 at START_POS in OBJECT. */
3801 static struct text_pos
3802 display_prop_end (it
, object
, start_pos
)
3805 struct text_pos start_pos
;
3808 struct text_pos end_pos
;
3810 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3811 Qdisplay
, object
, Qnil
);
3812 CHARPOS (end_pos
) = XFASTINT (end
);
3813 if (STRINGP (object
))
3814 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3816 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3822 /* Set up IT from a single `display' specification PROP. OBJECT
3823 is the object in which the `display' property was found. *POSITION
3824 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3825 means that we previously saw a display specification which already
3826 replaced text display with something else, for example an image;
3827 we ignore such properties after the first one has been processed.
3829 If PROP is a `space' or `image' specification, and in some other
3830 cases too, set *POSITION to the position where the `display'
3833 Value is non-zero if something was found which replaces the display
3834 of buffer or string text. Specifically, the value is -1 if that
3835 "something" is "nothing". */
3838 handle_single_display_spec (it
, spec
, object
, position
,
3839 display_replaced_before_p
)
3843 struct text_pos
*position
;
3844 int display_replaced_before_p
;
3847 Lisp_Object location
, value
;
3848 struct text_pos start_pos
;
3851 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3852 If the result is non-nil, use VALUE instead of SPEC. */
3854 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3863 if (!NILP (form
) && !EQ (form
, Qt
))
3865 int count
= SPECPDL_INDEX ();
3866 struct gcpro gcpro1
;
3868 /* Bind `object' to the object having the `display' property, a
3869 buffer or string. Bind `position' to the position in the
3870 object where the property was found, and `buffer-position'
3871 to the current position in the buffer. */
3872 specbind (Qobject
, object
);
3873 specbind (Qposition
, make_number (CHARPOS (*position
)));
3874 specbind (Qbuffer_position
,
3875 make_number (STRINGP (object
)
3876 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3878 form
= safe_eval (form
);
3880 unbind_to (count
, Qnil
);
3886 /* Handle `(height HEIGHT)' specifications. */
3888 && EQ (XCAR (spec
), Qheight
)
3889 && CONSP (XCDR (spec
)))
3891 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3894 it
->font_height
= XCAR (XCDR (spec
));
3895 if (!NILP (it
->font_height
))
3897 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3898 int new_height
= -1;
3900 if (CONSP (it
->font_height
)
3901 && (EQ (XCAR (it
->font_height
), Qplus
)
3902 || EQ (XCAR (it
->font_height
), Qminus
))
3903 && CONSP (XCDR (it
->font_height
))
3904 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3906 /* `(+ N)' or `(- N)' where N is an integer. */
3907 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3908 if (EQ (XCAR (it
->font_height
), Qplus
))
3910 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3912 else if (FUNCTIONP (it
->font_height
))
3914 /* Call function with current height as argument.
3915 Value is the new height. */
3917 height
= safe_call1 (it
->font_height
,
3918 face
->lface
[LFACE_HEIGHT_INDEX
]);
3919 if (NUMBERP (height
))
3920 new_height
= XFLOATINT (height
);
3922 else if (NUMBERP (it
->font_height
))
3924 /* Value is a multiple of the canonical char height. */
3927 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3928 new_height
= (XFLOATINT (it
->font_height
)
3929 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3933 /* Evaluate IT->font_height with `height' bound to the
3934 current specified height to get the new height. */
3935 int count
= SPECPDL_INDEX ();
3937 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3938 value
= safe_eval (it
->font_height
);
3939 unbind_to (count
, Qnil
);
3941 if (NUMBERP (value
))
3942 new_height
= XFLOATINT (value
);
3946 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3952 /* Handle `(space_width WIDTH)'. */
3954 && EQ (XCAR (spec
), Qspace_width
)
3955 && CONSP (XCDR (spec
)))
3957 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3960 value
= XCAR (XCDR (spec
));
3961 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3962 it
->space_width
= value
;
3967 /* Handle `(slice X Y WIDTH HEIGHT)'. */
3969 && EQ (XCAR (spec
), Qslice
))
3973 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3976 if (tem
= XCDR (spec
), CONSP (tem
))
3978 it
->slice
.x
= XCAR (tem
);
3979 if (tem
= XCDR (tem
), CONSP (tem
))
3981 it
->slice
.y
= XCAR (tem
);
3982 if (tem
= XCDR (tem
), CONSP (tem
))
3984 it
->slice
.width
= XCAR (tem
);
3985 if (tem
= XCDR (tem
), CONSP (tem
))
3986 it
->slice
.height
= XCAR (tem
);
3994 /* Handle `(raise FACTOR)'. */
3996 && EQ (XCAR (spec
), Qraise
)
3997 && CONSP (XCDR (spec
)))
3999 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4002 #ifdef HAVE_WINDOW_SYSTEM
4003 value
= XCAR (XCDR (spec
));
4004 if (NUMBERP (value
))
4006 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4007 it
->voffset
= - (XFLOATINT (value
)
4008 * (FONT_HEIGHT (face
->font
)));
4010 #endif /* HAVE_WINDOW_SYSTEM */
4015 /* Don't handle the other kinds of display specifications
4016 inside a string that we got from a `display' property. */
4017 if (it
->string_from_display_prop_p
)
4020 /* Characters having this form of property are not displayed, so
4021 we have to find the end of the property. */
4022 start_pos
= *position
;
4023 *position
= display_prop_end (it
, object
, start_pos
);
4026 /* Stop the scan at that end position--we assume that all
4027 text properties change there. */
4028 it
->stop_charpos
= position
->charpos
;
4030 /* Handle `(left-fringe BITMAP [FACE])'
4031 and `(right-fringe BITMAP [FACE])'. */
4033 && (EQ (XCAR (spec
), Qleft_fringe
)
4034 || EQ (XCAR (spec
), Qright_fringe
))
4035 && CONSP (XCDR (spec
)))
4037 int face_id
= DEFAULT_FACE_ID
;
4040 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4041 /* If we return here, POSITION has been advanced
4042 across the text with this property. */
4045 #ifdef HAVE_WINDOW_SYSTEM
4046 value
= XCAR (XCDR (spec
));
4047 if (!SYMBOLP (value
)
4048 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4049 /* If we return here, POSITION has been advanced
4050 across the text with this property. */
4053 if (CONSP (XCDR (XCDR (spec
))))
4055 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4056 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4057 'A', FRINGE_FACE_ID
, 0);
4062 /* Save current settings of IT so that we can restore them
4063 when we are finished with the glyph property value. */
4067 it
->area
= TEXT_AREA
;
4068 it
->what
= IT_IMAGE
;
4069 it
->image_id
= -1; /* no image */
4070 it
->position
= start_pos
;
4071 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4072 it
->method
= GET_FROM_IMAGE
;
4073 it
->face_id
= face_id
;
4075 /* Say that we haven't consumed the characters with
4076 `display' property yet. The call to pop_it in
4077 set_iterator_to_next will clean this up. */
4078 *position
= start_pos
;
4080 if (EQ (XCAR (spec
), Qleft_fringe
))
4082 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4083 it
->left_user_fringe_face_id
= face_id
;
4087 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4088 it
->right_user_fringe_face_id
= face_id
;
4090 #endif /* HAVE_WINDOW_SYSTEM */
4094 /* Prepare to handle `((margin left-margin) ...)',
4095 `((margin right-margin) ...)' and `((margin nil) ...)'
4096 prefixes for display specifications. */
4097 location
= Qunbound
;
4098 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4102 value
= XCDR (spec
);
4104 value
= XCAR (value
);
4107 if (EQ (XCAR (tem
), Qmargin
)
4108 && (tem
= XCDR (tem
),
4109 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4111 || EQ (tem
, Qleft_margin
)
4112 || EQ (tem
, Qright_margin
))))
4116 if (EQ (location
, Qunbound
))
4122 /* After this point, VALUE is the property after any
4123 margin prefix has been stripped. It must be a string,
4124 an image specification, or `(space ...)'.
4126 LOCATION specifies where to display: `left-margin',
4127 `right-margin' or nil. */
4129 valid_p
= (STRINGP (value
)
4130 #ifdef HAVE_WINDOW_SYSTEM
4131 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
4132 #endif /* not HAVE_WINDOW_SYSTEM */
4133 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4135 if (valid_p
&& !display_replaced_before_p
)
4137 /* Save current settings of IT so that we can restore them
4138 when we are finished with the glyph property value. */
4141 if (NILP (location
))
4142 it
->area
= TEXT_AREA
;
4143 else if (EQ (location
, Qleft_margin
))
4144 it
->area
= LEFT_MARGIN_AREA
;
4146 it
->area
= RIGHT_MARGIN_AREA
;
4148 if (STRINGP (value
))
4150 if (SCHARS (value
) == 0)
4153 return -1; /* Replaced by "", i.e. nothing. */
4156 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4157 it
->current
.overlay_string_index
= -1;
4158 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4159 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4160 it
->method
= GET_FROM_STRING
;
4161 it
->stop_charpos
= 0;
4162 it
->string_from_display_prop_p
= 1;
4163 /* Say that we haven't consumed the characters with
4164 `display' property yet. The call to pop_it in
4165 set_iterator_to_next will clean this up. */
4166 *position
= start_pos
;
4168 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4170 it
->method
= GET_FROM_STRETCH
;
4172 *position
= it
->position
= start_pos
;
4174 #ifdef HAVE_WINDOW_SYSTEM
4177 it
->what
= IT_IMAGE
;
4178 it
->image_id
= lookup_image (it
->f
, value
);
4179 it
->position
= start_pos
;
4180 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4181 it
->method
= GET_FROM_IMAGE
;
4183 /* Say that we haven't consumed the characters with
4184 `display' property yet. The call to pop_it in
4185 set_iterator_to_next will clean this up. */
4186 *position
= start_pos
;
4188 #endif /* HAVE_WINDOW_SYSTEM */
4193 /* Invalid property or property not supported. Restore
4194 POSITION to what it was before. */
4195 *position
= start_pos
;
4200 /* Check if SPEC is a display specification value whose text should be
4201 treated as intangible. */
4204 single_display_spec_intangible_p (prop
)
4207 /* Skip over `when FORM'. */
4208 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4222 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4223 we don't need to treat text as intangible. */
4224 if (EQ (XCAR (prop
), Qmargin
))
4232 || EQ (XCAR (prop
), Qleft_margin
)
4233 || EQ (XCAR (prop
), Qright_margin
))
4237 return (CONSP (prop
)
4238 && (EQ (XCAR (prop
), Qimage
)
4239 || EQ (XCAR (prop
), Qspace
)));
4243 /* Check if PROP is a display property value whose text should be
4244 treated as intangible. */
4247 display_prop_intangible_p (prop
)
4251 && CONSP (XCAR (prop
))
4252 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4254 /* A list of sub-properties. */
4255 while (CONSP (prop
))
4257 if (single_display_spec_intangible_p (XCAR (prop
)))
4262 else if (VECTORP (prop
))
4264 /* A vector of sub-properties. */
4266 for (i
= 0; i
< ASIZE (prop
); ++i
)
4267 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4271 return single_display_spec_intangible_p (prop
);
4277 /* Return 1 if PROP is a display sub-property value containing STRING. */
4280 single_display_spec_string_p (prop
, string
)
4281 Lisp_Object prop
, string
;
4283 if (EQ (string
, prop
))
4286 /* Skip over `when FORM'. */
4287 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4296 /* Skip over `margin LOCATION'. */
4297 if (EQ (XCAR (prop
), Qmargin
))
4308 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4312 /* Return 1 if STRING appears in the `display' property PROP. */
4315 display_prop_string_p (prop
, string
)
4316 Lisp_Object prop
, string
;
4319 && CONSP (XCAR (prop
))
4320 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4322 /* A list of sub-properties. */
4323 while (CONSP (prop
))
4325 if (single_display_spec_string_p (XCAR (prop
), string
))
4330 else if (VECTORP (prop
))
4332 /* A vector of sub-properties. */
4334 for (i
= 0; i
< ASIZE (prop
); ++i
)
4335 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4339 return single_display_spec_string_p (prop
, string
);
4345 /* Determine from which buffer position in W's buffer STRING comes
4346 from. AROUND_CHARPOS is an approximate position where it could
4347 be from. Value is the buffer position or 0 if it couldn't be
4350 W's buffer must be current.
4352 This function is necessary because we don't record buffer positions
4353 in glyphs generated from strings (to keep struct glyph small).
4354 This function may only use code that doesn't eval because it is
4355 called asynchronously from note_mouse_highlight. */
4358 string_buffer_position (w
, string
, around_charpos
)
4363 Lisp_Object limit
, prop
, pos
;
4364 const int MAX_DISTANCE
= 1000;
4367 pos
= make_number (around_charpos
);
4368 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4369 while (!found
&& !EQ (pos
, limit
))
4371 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4372 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4375 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4380 pos
= make_number (around_charpos
);
4381 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4382 while (!found
&& !EQ (pos
, limit
))
4384 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4385 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4388 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4393 return found
? XINT (pos
) : 0;
4398 /***********************************************************************
4399 `composition' property
4400 ***********************************************************************/
4402 /* Set up iterator IT from `composition' property at its current
4403 position. Called from handle_stop. */
4405 static enum prop_handled
4406 handle_composition_prop (it
)
4409 Lisp_Object prop
, string
;
4410 int pos
, pos_byte
, end
;
4411 enum prop_handled handled
= HANDLED_NORMALLY
;
4413 if (STRINGP (it
->string
))
4415 pos
= IT_STRING_CHARPOS (*it
);
4416 pos_byte
= IT_STRING_BYTEPOS (*it
);
4417 string
= it
->string
;
4421 pos
= IT_CHARPOS (*it
);
4422 pos_byte
= IT_BYTEPOS (*it
);
4426 /* If there's a valid composition and point is not inside of the
4427 composition (in the case that the composition is from the current
4428 buffer), draw a glyph composed from the composition components. */
4429 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
4430 && COMPOSITION_VALID_P (pos
, end
, prop
)
4431 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
4433 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4437 it
->method
= GET_FROM_COMPOSITION
;
4439 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4440 /* For a terminal, draw only the first character of the
4442 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4443 it
->len
= (STRINGP (it
->string
)
4444 ? string_char_to_byte (it
->string
, end
)
4445 : CHAR_TO_BYTE (end
)) - pos_byte
;
4446 it
->stop_charpos
= end
;
4447 handled
= HANDLED_RETURN
;
4456 /***********************************************************************
4458 ***********************************************************************/
4460 /* The following structure is used to record overlay strings for
4461 later sorting in load_overlay_strings. */
4463 struct overlay_entry
4465 Lisp_Object overlay
;
4472 /* Set up iterator IT from overlay strings at its current position.
4473 Called from handle_stop. */
4475 static enum prop_handled
4476 handle_overlay_change (it
)
4479 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4480 return HANDLED_RECOMPUTE_PROPS
;
4482 return HANDLED_NORMALLY
;
4486 /* Set up the next overlay string for delivery by IT, if there is an
4487 overlay string to deliver. Called by set_iterator_to_next when the
4488 end of the current overlay string is reached. If there are more
4489 overlay strings to display, IT->string and
4490 IT->current.overlay_string_index are set appropriately here.
4491 Otherwise IT->string is set to nil. */
4494 next_overlay_string (it
)
4497 ++it
->current
.overlay_string_index
;
4498 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4500 /* No more overlay strings. Restore IT's settings to what
4501 they were before overlay strings were processed, and
4502 continue to deliver from current_buffer. */
4503 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4506 xassert (it
->stop_charpos
>= BEGV
4507 && it
->stop_charpos
<= it
->end_charpos
);
4509 it
->current
.overlay_string_index
= -1;
4510 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4511 it
->n_overlay_strings
= 0;
4512 it
->method
= GET_FROM_BUFFER
;
4514 /* If we're at the end of the buffer, record that we have
4515 processed the overlay strings there already, so that
4516 next_element_from_buffer doesn't try it again. */
4517 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4518 it
->overlay_strings_at_end_processed_p
= 1;
4520 /* If we have to display `...' for invisible text, set
4521 the iterator up for that. */
4522 if (display_ellipsis_p
)
4523 setup_for_ellipsis (it
, 0);
4527 /* There are more overlay strings to process. If
4528 IT->current.overlay_string_index has advanced to a position
4529 where we must load IT->overlay_strings with more strings, do
4531 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4533 if (it
->current
.overlay_string_index
&& i
== 0)
4534 load_overlay_strings (it
, 0);
4536 /* Initialize IT to deliver display elements from the overlay
4538 it
->string
= it
->overlay_strings
[i
];
4539 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4540 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4541 it
->method
= GET_FROM_STRING
;
4542 it
->stop_charpos
= 0;
4549 /* Compare two overlay_entry structures E1 and E2. Used as a
4550 comparison function for qsort in load_overlay_strings. Overlay
4551 strings for the same position are sorted so that
4553 1. All after-strings come in front of before-strings, except
4554 when they come from the same overlay.
4556 2. Within after-strings, strings are sorted so that overlay strings
4557 from overlays with higher priorities come first.
4559 2. Within before-strings, strings are sorted so that overlay
4560 strings from overlays with higher priorities come last.
4562 Value is analogous to strcmp. */
4566 compare_overlay_entries (e1
, e2
)
4569 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4570 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4573 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4575 /* Let after-strings appear in front of before-strings if
4576 they come from different overlays. */
4577 if (EQ (entry1
->overlay
, entry2
->overlay
))
4578 result
= entry1
->after_string_p
? 1 : -1;
4580 result
= entry1
->after_string_p
? -1 : 1;
4582 else if (entry1
->after_string_p
)
4583 /* After-strings sorted in order of decreasing priority. */
4584 result
= entry2
->priority
- entry1
->priority
;
4586 /* Before-strings sorted in order of increasing priority. */
4587 result
= entry1
->priority
- entry2
->priority
;
4593 /* Load the vector IT->overlay_strings with overlay strings from IT's
4594 current buffer position, or from CHARPOS if that is > 0. Set
4595 IT->n_overlays to the total number of overlay strings found.
4597 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4598 a time. On entry into load_overlay_strings,
4599 IT->current.overlay_string_index gives the number of overlay
4600 strings that have already been loaded by previous calls to this
4603 IT->add_overlay_start contains an additional overlay start
4604 position to consider for taking overlay strings from, if non-zero.
4605 This position comes into play when the overlay has an `invisible'
4606 property, and both before and after-strings. When we've skipped to
4607 the end of the overlay, because of its `invisible' property, we
4608 nevertheless want its before-string to appear.
4609 IT->add_overlay_start will contain the overlay start position
4612 Overlay strings are sorted so that after-string strings come in
4613 front of before-string strings. Within before and after-strings,
4614 strings are sorted by overlay priority. See also function
4615 compare_overlay_entries. */
4618 load_overlay_strings (it
, charpos
)
4622 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4623 Lisp_Object overlay
, window
, str
, invisible
;
4624 struct Lisp_Overlay
*ov
;
4627 int n
= 0, i
, j
, invis_p
;
4628 struct overlay_entry
*entries
4629 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4632 charpos
= IT_CHARPOS (*it
);
4634 /* Append the overlay string STRING of overlay OVERLAY to vector
4635 `entries' which has size `size' and currently contains `n'
4636 elements. AFTER_P non-zero means STRING is an after-string of
4638 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4641 Lisp_Object priority; \
4645 int new_size = 2 * size; \
4646 struct overlay_entry *old = entries; \
4648 (struct overlay_entry *) alloca (new_size \
4649 * sizeof *entries); \
4650 bcopy (old, entries, size * sizeof *entries); \
4654 entries[n].string = (STRING); \
4655 entries[n].overlay = (OVERLAY); \
4656 priority = Foverlay_get ((OVERLAY), Qpriority); \
4657 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4658 entries[n].after_string_p = (AFTER_P); \
4663 /* Process overlay before the overlay center. */
4664 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4666 XSETMISC (overlay
, ov
);
4667 xassert (OVERLAYP (overlay
));
4668 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4669 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4674 /* Skip this overlay if it doesn't start or end at IT's current
4676 if (end
!= charpos
&& start
!= charpos
)
4679 /* Skip this overlay if it doesn't apply to IT->w. */
4680 window
= Foverlay_get (overlay
, Qwindow
);
4681 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4684 /* If the text ``under'' the overlay is invisible, both before-
4685 and after-strings from this overlay are visible; start and
4686 end position are indistinguishable. */
4687 invisible
= Foverlay_get (overlay
, Qinvisible
);
4688 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4690 /* If overlay has a non-empty before-string, record it. */
4691 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4692 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4694 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4696 /* If overlay has a non-empty after-string, record it. */
4697 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4698 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4700 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4703 /* Process overlays after the overlay center. */
4704 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4706 XSETMISC (overlay
, ov
);
4707 xassert (OVERLAYP (overlay
));
4708 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4709 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4711 if (start
> charpos
)
4714 /* Skip this overlay if it doesn't start or end at IT's current
4716 if (end
!= charpos
&& start
!= charpos
)
4719 /* Skip this overlay if it doesn't apply to IT->w. */
4720 window
= Foverlay_get (overlay
, Qwindow
);
4721 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4724 /* If the text ``under'' the overlay is invisible, it has a zero
4725 dimension, and both before- and after-strings apply. */
4726 invisible
= Foverlay_get (overlay
, Qinvisible
);
4727 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4729 /* If overlay has a non-empty before-string, record it. */
4730 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4731 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4733 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4735 /* If overlay has a non-empty after-string, record it. */
4736 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4737 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4739 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4742 #undef RECORD_OVERLAY_STRING
4746 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4748 /* Record the total number of strings to process. */
4749 it
->n_overlay_strings
= n
;
4751 /* IT->current.overlay_string_index is the number of overlay strings
4752 that have already been consumed by IT. Copy some of the
4753 remaining overlay strings to IT->overlay_strings. */
4755 j
= it
->current
.overlay_string_index
;
4756 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4757 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4763 /* Get the first chunk of overlay strings at IT's current buffer
4764 position, or at CHARPOS if that is > 0. Value is non-zero if at
4765 least one overlay string was found. */
4768 get_overlay_strings (it
, charpos
)
4772 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4773 process. This fills IT->overlay_strings with strings, and sets
4774 IT->n_overlay_strings to the total number of strings to process.
4775 IT->pos.overlay_string_index has to be set temporarily to zero
4776 because load_overlay_strings needs this; it must be set to -1
4777 when no overlay strings are found because a zero value would
4778 indicate a position in the first overlay string. */
4779 it
->current
.overlay_string_index
= 0;
4780 load_overlay_strings (it
, charpos
);
4782 /* If we found overlay strings, set up IT to deliver display
4783 elements from the first one. Otherwise set up IT to deliver
4784 from current_buffer. */
4785 if (it
->n_overlay_strings
)
4787 /* Make sure we know settings in current_buffer, so that we can
4788 restore meaningful values when we're done with the overlay
4790 compute_stop_pos (it
);
4791 xassert (it
->face_id
>= 0);
4793 /* Save IT's settings. They are restored after all overlay
4794 strings have been processed. */
4795 xassert (it
->sp
== 0);
4798 /* Set up IT to deliver display elements from the first overlay
4800 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4801 it
->string
= it
->overlay_strings
[0];
4802 it
->stop_charpos
= 0;
4803 xassert (STRINGP (it
->string
));
4804 it
->end_charpos
= SCHARS (it
->string
);
4805 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4806 it
->method
= GET_FROM_STRING
;
4811 it
->current
.overlay_string_index
= -1;
4812 it
->method
= GET_FROM_BUFFER
;
4817 /* Value is non-zero if we found at least one overlay string. */
4818 return STRINGP (it
->string
);
4823 /***********************************************************************
4824 Saving and restoring state
4825 ***********************************************************************/
4827 /* Save current settings of IT on IT->stack. Called, for example,
4828 before setting up IT for an overlay string, to be able to restore
4829 IT's settings to what they were after the overlay string has been
4836 struct iterator_stack_entry
*p
;
4838 xassert (it
->sp
< 2);
4839 p
= it
->stack
+ it
->sp
;
4841 p
->stop_charpos
= it
->stop_charpos
;
4842 xassert (it
->face_id
>= 0);
4843 p
->face_id
= it
->face_id
;
4844 p
->string
= it
->string
;
4845 p
->pos
= it
->current
;
4846 p
->end_charpos
= it
->end_charpos
;
4847 p
->string_nchars
= it
->string_nchars
;
4849 p
->multibyte_p
= it
->multibyte_p
;
4850 p
->slice
= it
->slice
;
4851 p
->space_width
= it
->space_width
;
4852 p
->font_height
= it
->font_height
;
4853 p
->voffset
= it
->voffset
;
4854 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4855 p
->display_ellipsis_p
= 0;
4860 /* Restore IT's settings from IT->stack. Called, for example, when no
4861 more overlay strings must be processed, and we return to delivering
4862 display elements from a buffer, or when the end of a string from a
4863 `display' property is reached and we return to delivering display
4864 elements from an overlay string, or from a buffer. */
4870 struct iterator_stack_entry
*p
;
4872 xassert (it
->sp
> 0);
4874 p
= it
->stack
+ it
->sp
;
4875 it
->stop_charpos
= p
->stop_charpos
;
4876 it
->face_id
= p
->face_id
;
4877 it
->string
= p
->string
;
4878 it
->current
= p
->pos
;
4879 it
->end_charpos
= p
->end_charpos
;
4880 it
->string_nchars
= p
->string_nchars
;
4882 it
->multibyte_p
= p
->multibyte_p
;
4883 it
->slice
= p
->slice
;
4884 it
->space_width
= p
->space_width
;
4885 it
->font_height
= p
->font_height
;
4886 it
->voffset
= p
->voffset
;
4887 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4892 /***********************************************************************
4894 ***********************************************************************/
4896 /* Set IT's current position to the previous line start. */
4899 back_to_previous_line_start (it
)
4902 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4903 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4907 /* Move IT to the next line start.
4909 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4910 we skipped over part of the text (as opposed to moving the iterator
4911 continuously over the text). Otherwise, don't change the value
4914 Newlines may come from buffer text, overlay strings, or strings
4915 displayed via the `display' property. That's the reason we can't
4916 simply use find_next_newline_no_quit.
4918 Note that this function may not skip over invisible text that is so
4919 because of text properties and immediately follows a newline. If
4920 it would, function reseat_at_next_visible_line_start, when called
4921 from set_iterator_to_next, would effectively make invisible
4922 characters following a newline part of the wrong glyph row, which
4923 leads to wrong cursor motion. */
4926 forward_to_next_line_start (it
, skipped_p
)
4930 int old_selective
, newline_found_p
, n
;
4931 const int MAX_NEWLINE_DISTANCE
= 500;
4933 /* If already on a newline, just consume it to avoid unintended
4934 skipping over invisible text below. */
4935 if (it
->what
== IT_CHARACTER
4937 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4939 set_iterator_to_next (it
, 0);
4944 /* Don't handle selective display in the following. It's (a)
4945 unnecessary because it's done by the caller, and (b) leads to an
4946 infinite recursion because next_element_from_ellipsis indirectly
4947 calls this function. */
4948 old_selective
= it
->selective
;
4951 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4952 from buffer text. */
4953 for (n
= newline_found_p
= 0;
4954 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4955 n
+= STRINGP (it
->string
) ? 0 : 1)
4957 if (!get_next_display_element (it
))
4959 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4960 set_iterator_to_next (it
, 0);
4963 /* If we didn't find a newline near enough, see if we can use a
4965 if (!newline_found_p
)
4967 int start
= IT_CHARPOS (*it
);
4968 int limit
= find_next_newline_no_quit (start
, 1);
4971 xassert (!STRINGP (it
->string
));
4973 /* If there isn't any `display' property in sight, and no
4974 overlays, we can just use the position of the newline in
4976 if (it
->stop_charpos
>= limit
4977 || ((pos
= Fnext_single_property_change (make_number (start
),
4979 Qnil
, make_number (limit
)),
4981 && next_overlay_change (start
) == ZV
))
4983 IT_CHARPOS (*it
) = limit
;
4984 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4985 *skipped_p
= newline_found_p
= 1;
4989 while (get_next_display_element (it
)
4990 && !newline_found_p
)
4992 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4993 set_iterator_to_next (it
, 0);
4998 it
->selective
= old_selective
;
4999 return newline_found_p
;
5003 /* Set IT's current position to the previous visible line start. Skip
5004 invisible text that is so either due to text properties or due to
5005 selective display. Caution: this does not change IT->current_x and
5009 back_to_previous_visible_line_start (it
)
5012 while (IT_CHARPOS (*it
) > BEGV
)
5014 back_to_previous_line_start (it
);
5015 if (IT_CHARPOS (*it
) <= BEGV
)
5018 /* If selective > 0, then lines indented more than that values
5020 if (it
->selective
> 0
5021 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5022 (double) it
->selective
)) /* iftc */
5025 /* Check the newline before point for invisibility. */
5028 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5029 Qinvisible
, it
->window
);
5030 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5034 /* If newline has a display property that replaces the newline with something
5035 else (image or text), find start of overlay or interval and continue search
5037 if (IT_CHARPOS (*it
) > BEGV
)
5039 struct it it2
= *it
;
5042 Lisp_Object val
, overlay
;
5044 pos
= --IT_CHARPOS (it2
);
5047 if (handle_display_prop (&it2
) == HANDLED_RETURN
5048 && !NILP (val
= get_char_property_and_overlay
5049 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5050 && (OVERLAYP (overlay
)
5051 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5052 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5056 IT_CHARPOS (*it
) = beg
;
5057 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5065 xassert (IT_CHARPOS (*it
) >= BEGV
);
5066 xassert (IT_CHARPOS (*it
) == BEGV
5067 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5072 /* Reseat iterator IT at the previous visible line start. Skip
5073 invisible text that is so either due to text properties or due to
5074 selective display. At the end, update IT's overlay information,
5075 face information etc. */
5078 reseat_at_previous_visible_line_start (it
)
5081 back_to_previous_visible_line_start (it
);
5082 reseat (it
, it
->current
.pos
, 1);
5087 /* Reseat iterator IT on the next visible line start in the current
5088 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5089 preceding the line start. Skip over invisible text that is so
5090 because of selective display. Compute faces, overlays etc at the
5091 new position. Note that this function does not skip over text that
5092 is invisible because of text properties. */
5095 reseat_at_next_visible_line_start (it
, on_newline_p
)
5099 int newline_found_p
, skipped_p
= 0;
5101 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5103 /* Skip over lines that are invisible because they are indented
5104 more than the value of IT->selective. */
5105 if (it
->selective
> 0)
5106 while (IT_CHARPOS (*it
) < ZV
5107 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5108 (double) it
->selective
)) /* iftc */
5110 xassert (IT_BYTEPOS (*it
) == BEGV
5111 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5112 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5115 /* Position on the newline if that's what's requested. */
5116 if (on_newline_p
&& newline_found_p
)
5118 if (STRINGP (it
->string
))
5120 if (IT_STRING_CHARPOS (*it
) > 0)
5122 --IT_STRING_CHARPOS (*it
);
5123 --IT_STRING_BYTEPOS (*it
);
5126 else if (IT_CHARPOS (*it
) > BEGV
)
5130 reseat (it
, it
->current
.pos
, 0);
5134 reseat (it
, it
->current
.pos
, 0);
5141 /***********************************************************************
5142 Changing an iterator's position
5143 ***********************************************************************/
5145 /* Change IT's current position to POS in current_buffer. If FORCE_P
5146 is non-zero, always check for text properties at the new position.
5147 Otherwise, text properties are only looked up if POS >=
5148 IT->check_charpos of a property. */
5151 reseat (it
, pos
, force_p
)
5153 struct text_pos pos
;
5156 int original_pos
= IT_CHARPOS (*it
);
5158 reseat_1 (it
, pos
, 0);
5160 /* Determine where to check text properties. Avoid doing it
5161 where possible because text property lookup is very expensive. */
5163 || CHARPOS (pos
) > it
->stop_charpos
5164 || CHARPOS (pos
) < original_pos
)
5171 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5172 IT->stop_pos to POS, also. */
5175 reseat_1 (it
, pos
, set_stop_p
)
5177 struct text_pos pos
;
5180 /* Don't call this function when scanning a C string. */
5181 xassert (it
->s
== NULL
);
5183 /* POS must be a reasonable value. */
5184 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5186 it
->current
.pos
= it
->position
= pos
;
5187 XSETBUFFER (it
->object
, current_buffer
);
5188 it
->end_charpos
= ZV
;
5190 it
->current
.dpvec_index
= -1;
5191 it
->current
.overlay_string_index
= -1;
5192 IT_STRING_CHARPOS (*it
) = -1;
5193 IT_STRING_BYTEPOS (*it
) = -1;
5195 it
->method
= GET_FROM_BUFFER
;
5196 /* RMS: I added this to fix a bug in move_it_vertically_backward
5197 where it->area continued to relate to the starting point
5198 for the backward motion. Bug report from
5199 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
5200 However, I am not sure whether reseat still does the right thing
5201 in general after this change. */
5202 it
->area
= TEXT_AREA
;
5203 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5205 it
->face_before_selective_p
= 0;
5208 it
->stop_charpos
= CHARPOS (pos
);
5212 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5213 If S is non-null, it is a C string to iterate over. Otherwise,
5214 STRING gives a Lisp string to iterate over.
5216 If PRECISION > 0, don't return more then PRECISION number of
5217 characters from the string.
5219 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5220 characters have been returned. FIELD_WIDTH < 0 means an infinite
5223 MULTIBYTE = 0 means disable processing of multibyte characters,
5224 MULTIBYTE > 0 means enable it,
5225 MULTIBYTE < 0 means use IT->multibyte_p.
5227 IT must be initialized via a prior call to init_iterator before
5228 calling this function. */
5231 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5236 int precision
, field_width
, multibyte
;
5238 /* No region in strings. */
5239 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5241 /* No text property checks performed by default, but see below. */
5242 it
->stop_charpos
= -1;
5244 /* Set iterator position and end position. */
5245 bzero (&it
->current
, sizeof it
->current
);
5246 it
->current
.overlay_string_index
= -1;
5247 it
->current
.dpvec_index
= -1;
5248 xassert (charpos
>= 0);
5250 /* If STRING is specified, use its multibyteness, otherwise use the
5251 setting of MULTIBYTE, if specified. */
5253 it
->multibyte_p
= multibyte
> 0;
5257 xassert (STRINGP (string
));
5258 it
->string
= string
;
5260 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5261 it
->method
= GET_FROM_STRING
;
5262 it
->current
.string_pos
= string_pos (charpos
, string
);
5269 /* Note that we use IT->current.pos, not it->current.string_pos,
5270 for displaying C strings. */
5271 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5272 if (it
->multibyte_p
)
5274 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5275 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5279 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5280 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5283 it
->method
= GET_FROM_C_STRING
;
5286 /* PRECISION > 0 means don't return more than PRECISION characters
5288 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5289 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5291 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5292 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5293 FIELD_WIDTH < 0 means infinite field width. This is useful for
5294 padding with `-' at the end of a mode line. */
5295 if (field_width
< 0)
5296 field_width
= INFINITY
;
5297 if (field_width
> it
->end_charpos
- charpos
)
5298 it
->end_charpos
= charpos
+ field_width
;
5300 /* Use the standard display table for displaying strings. */
5301 if (DISP_TABLE_P (Vstandard_display_table
))
5302 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5304 it
->stop_charpos
= charpos
;
5310 /***********************************************************************
5312 ***********************************************************************/
5314 /* Map enum it_method value to corresponding next_element_from_* function. */
5316 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5318 next_element_from_buffer
,
5319 next_element_from_display_vector
,
5320 next_element_from_composition
,
5321 next_element_from_string
,
5322 next_element_from_c_string
,
5323 next_element_from_image
,
5324 next_element_from_stretch
5328 /* Load IT's display element fields with information about the next
5329 display element from the current position of IT. Value is zero if
5330 end of buffer (or C string) is reached. */
5332 static struct frame
*last_escape_glyph_frame
= NULL
;
5333 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5334 static int last_escape_glyph_merged_face_id
= 0;
5337 get_next_display_element (it
)
5340 /* Non-zero means that we found a display element. Zero means that
5341 we hit the end of what we iterate over. Performance note: the
5342 function pointer `method' used here turns out to be faster than
5343 using a sequence of if-statements. */
5347 success_p
= (*get_next_element
[it
->method
]) (it
);
5349 if (it
->what
== IT_CHARACTER
)
5351 /* Map via display table or translate control characters.
5352 IT->c, IT->len etc. have been set to the next character by
5353 the function call above. If we have a display table, and it
5354 contains an entry for IT->c, translate it. Don't do this if
5355 IT->c itself comes from a display table, otherwise we could
5356 end up in an infinite recursion. (An alternative could be to
5357 count the recursion depth of this function and signal an
5358 error when a certain maximum depth is reached.) Is it worth
5360 if (success_p
&& it
->dpvec
== NULL
)
5365 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5368 struct Lisp_Vector
*v
= XVECTOR (dv
);
5370 /* Return the first character from the display table
5371 entry, if not empty. If empty, don't display the
5372 current character. */
5375 it
->dpvec_char_len
= it
->len
;
5376 it
->dpvec
= v
->contents
;
5377 it
->dpend
= v
->contents
+ v
->size
;
5378 it
->current
.dpvec_index
= 0;
5379 it
->dpvec_face_id
= -1;
5380 it
->saved_face_id
= it
->face_id
;
5381 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5386 set_iterator_to_next (it
, 0);
5391 /* Translate control characters into `\003' or `^C' form.
5392 Control characters coming from a display table entry are
5393 currently not translated because we use IT->dpvec to hold
5394 the translation. This could easily be changed but I
5395 don't believe that it is worth doing.
5397 If it->multibyte_p is nonzero, eight-bit characters and
5398 non-printable multibyte characters are also translated to
5401 If it->multibyte_p is zero, eight-bit characters that
5402 don't have corresponding multibyte char code are also
5403 translated to octal form. */
5404 else if ((it
->c
< ' '
5405 && (it
->area
!= TEXT_AREA
5406 /* In mode line, treat \n like other crl chars. */
5408 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5409 || (it
->c
!= '\n' && it
->c
!= '\t')))
5413 || !CHAR_PRINTABLE_P (it
->c
)
5414 || (!NILP (Vnobreak_char_display
)
5415 && (it
->c
== 0x8a0 || it
->c
== 0x8ad
5416 || it
->c
== 0x920 || it
->c
== 0x92d
5417 || it
->c
== 0xe20 || it
->c
== 0xe2d
5418 || it
->c
== 0xf20 || it
->c
== 0xf2d)))
5420 && (!unibyte_display_via_language_environment
5421 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
5423 /* IT->c is a control character which must be displayed
5424 either as '\003' or as `^C' where the '\\' and '^'
5425 can be defined in the display table. Fill
5426 IT->ctl_chars with glyphs for what we have to
5427 display. Then, set IT->dpvec to these glyphs. */
5430 int face_id
, lface_id
= 0 ;
5433 /* Handle control characters with ^. */
5435 if (it
->c
< 128 && it
->ctl_arrow_p
)
5437 g
= '^'; /* default glyph for Control */
5438 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5440 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5441 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5443 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5444 lface_id
= FAST_GLYPH_FACE (g
);
5448 g
= FAST_GLYPH_CHAR (g
);
5449 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5452 else if (it
->f
== last_escape_glyph_frame
5453 && it
->face_id
== last_escape_glyph_face_id
)
5455 face_id
= last_escape_glyph_merged_face_id
;
5459 /* Merge the escape-glyph face into the current face. */
5460 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5462 last_escape_glyph_frame
= it
->f
;
5463 last_escape_glyph_face_id
= it
->face_id
;
5464 last_escape_glyph_merged_face_id
= face_id
;
5467 XSETINT (it
->ctl_chars
[0], g
);
5469 XSETINT (it
->ctl_chars
[1], g
);
5471 goto display_control
;
5474 /* Handle non-break space in the mode where it only gets
5477 if (EQ (Vnobreak_char_display
, Qt
)
5478 && (it
->c
== 0x8a0 || it
->c
== 0x920
5479 || it
->c
== 0xe20 || it
->c
== 0xf20))
5481 /* Merge the no-break-space face into the current face. */
5482 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5486 XSETINT (it
->ctl_chars
[0], g
);
5488 goto display_control
;
5491 /* Handle sequences that start with the "escape glyph". */
5493 /* the default escape glyph is \. */
5494 escape_glyph
= '\\';
5497 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5498 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5500 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5501 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5505 /* The display table specified a face.
5506 Merge it into face_id and also into escape_glyph. */
5507 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5508 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5511 else if (it
->f
== last_escape_glyph_frame
5512 && it
->face_id
== last_escape_glyph_face_id
)
5514 face_id
= last_escape_glyph_merged_face_id
;
5518 /* Merge the escape-glyph face into the current face. */
5519 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5521 last_escape_glyph_frame
= it
->f
;
5522 last_escape_glyph_face_id
= it
->face_id
;
5523 last_escape_glyph_merged_face_id
= face_id
;
5526 /* Handle soft hyphens in the mode where they only get
5529 if (EQ (Vnobreak_char_display
, Qt
)
5530 && (it
->c
== 0x8ad || it
->c
== 0x92d
5531 || it
->c
== 0xe2d || it
->c
== 0xf2d))
5534 XSETINT (it
->ctl_chars
[0], g
);
5536 goto display_control
;
5539 /* Handle non-break space and soft hyphen
5540 with the escape glyph. */
5542 if (it
->c
== 0x8a0 || it
->c
== 0x8ad
5543 || it
->c
== 0x920 || it
->c
== 0x92d
5544 || it
->c
== 0xe20 || it
->c
== 0xe2d
5545 || it
->c
== 0xf20 || it
->c
== 0xf2d)
5547 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5548 g
= it
->c
= ((it
->c
& 0xf) == 0 ? ' ' : '-');
5549 XSETINT (it
->ctl_chars
[1], g
);
5551 goto display_control
;
5555 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5559 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5560 if (SINGLE_BYTE_CHAR_P (it
->c
))
5561 str
[0] = it
->c
, len
= 1;
5564 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5567 /* It's an invalid character, which shouldn't
5568 happen actually, but due to bugs it may
5569 happen. Let's print the char as is, there's
5570 not much meaningful we can do with it. */
5572 str
[1] = it
->c
>> 8;
5573 str
[2] = it
->c
>> 16;
5574 str
[3] = it
->c
>> 24;
5579 for (i
= 0; i
< len
; i
++)
5581 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5582 /* Insert three more glyphs into IT->ctl_chars for
5583 the octal display of the character. */
5584 g
= ((str
[i
] >> 6) & 7) + '0';
5585 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5586 g
= ((str
[i
] >> 3) & 7) + '0';
5587 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5588 g
= (str
[i
] & 7) + '0';
5589 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5595 /* Set up IT->dpvec and return first character from it. */
5596 it
->dpvec_char_len
= it
->len
;
5597 it
->dpvec
= it
->ctl_chars
;
5598 it
->dpend
= it
->dpvec
+ ctl_len
;
5599 it
->current
.dpvec_index
= 0;
5600 it
->dpvec_face_id
= face_id
;
5601 it
->saved_face_id
= it
->face_id
;
5602 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5608 /* Adjust face id for a multibyte character. There are no
5609 multibyte character in unibyte text. */
5612 && FRAME_WINDOW_P (it
->f
))
5614 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5615 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5619 /* Is this character the last one of a run of characters with
5620 box? If yes, set IT->end_of_box_run_p to 1. */
5627 it
->end_of_box_run_p
5628 = ((face_id
= face_after_it_pos (it
),
5629 face_id
!= it
->face_id
)
5630 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5631 face
->box
== FACE_NO_BOX
));
5634 /* Value is 0 if end of buffer or string reached. */
5639 /* Move IT to the next display element.
5641 RESEAT_P non-zero means if called on a newline in buffer text,
5642 skip to the next visible line start.
5644 Functions get_next_display_element and set_iterator_to_next are
5645 separate because I find this arrangement easier to handle than a
5646 get_next_display_element function that also increments IT's
5647 position. The way it is we can first look at an iterator's current
5648 display element, decide whether it fits on a line, and if it does,
5649 increment the iterator position. The other way around we probably
5650 would either need a flag indicating whether the iterator has to be
5651 incremented the next time, or we would have to implement a
5652 decrement position function which would not be easy to write. */
5655 set_iterator_to_next (it
, reseat_p
)
5659 /* Reset flags indicating start and end of a sequence of characters
5660 with box. Reset them at the start of this function because
5661 moving the iterator to a new position might set them. */
5662 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5666 case GET_FROM_BUFFER
:
5667 /* The current display element of IT is a character from
5668 current_buffer. Advance in the buffer, and maybe skip over
5669 invisible lines that are so because of selective display. */
5670 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5671 reseat_at_next_visible_line_start (it
, 0);
5674 xassert (it
->len
!= 0);
5675 IT_BYTEPOS (*it
) += it
->len
;
5676 IT_CHARPOS (*it
) += 1;
5677 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5681 case GET_FROM_COMPOSITION
:
5682 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5683 if (STRINGP (it
->string
))
5685 IT_STRING_BYTEPOS (*it
) += it
->len
;
5686 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5687 it
->method
= GET_FROM_STRING
;
5688 goto consider_string_end
;
5692 IT_BYTEPOS (*it
) += it
->len
;
5693 IT_CHARPOS (*it
) += it
->cmp_len
;
5694 it
->method
= GET_FROM_BUFFER
;
5698 case GET_FROM_C_STRING
:
5699 /* Current display element of IT is from a C string. */
5700 IT_BYTEPOS (*it
) += it
->len
;
5701 IT_CHARPOS (*it
) += 1;
5704 case GET_FROM_DISPLAY_VECTOR
:
5705 /* Current display element of IT is from a display table entry.
5706 Advance in the display table definition. Reset it to null if
5707 end reached, and continue with characters from buffers/
5709 ++it
->current
.dpvec_index
;
5711 /* Restore face of the iterator to what they were before the
5712 display vector entry (these entries may contain faces). */
5713 it
->face_id
= it
->saved_face_id
;
5715 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5717 int recheck_faces
= it
->ellipsis_p
;
5720 it
->method
= GET_FROM_C_STRING
;
5721 else if (STRINGP (it
->string
))
5722 it
->method
= GET_FROM_STRING
;
5724 it
->method
= GET_FROM_BUFFER
;
5727 it
->current
.dpvec_index
= -1;
5729 /* Skip over characters which were displayed via IT->dpvec. */
5730 if (it
->dpvec_char_len
< 0)
5731 reseat_at_next_visible_line_start (it
, 1);
5732 else if (it
->dpvec_char_len
> 0)
5734 if (it
->method
== GET_FROM_STRING
5735 && it
->n_overlay_strings
> 0)
5736 it
->ignore_overlay_strings_at_pos_p
= 1;
5737 it
->len
= it
->dpvec_char_len
;
5738 set_iterator_to_next (it
, reseat_p
);
5741 /* Maybe recheck faces after display vector */
5743 it
->stop_charpos
= IT_CHARPOS (*it
);
5747 case GET_FROM_STRING
:
5748 /* Current display element is a character from a Lisp string. */
5749 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5750 IT_STRING_BYTEPOS (*it
) += it
->len
;
5751 IT_STRING_CHARPOS (*it
) += 1;
5753 consider_string_end
:
5755 if (it
->current
.overlay_string_index
>= 0)
5757 /* IT->string is an overlay string. Advance to the
5758 next, if there is one. */
5759 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5760 next_overlay_string (it
);
5764 /* IT->string is not an overlay string. If we reached
5765 its end, and there is something on IT->stack, proceed
5766 with what is on the stack. This can be either another
5767 string, this time an overlay string, or a buffer. */
5768 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5772 if (STRINGP (it
->string
))
5773 goto consider_string_end
;
5774 it
->method
= GET_FROM_BUFFER
;
5779 case GET_FROM_IMAGE
:
5780 case GET_FROM_STRETCH
:
5781 /* The position etc with which we have to proceed are on
5782 the stack. The position may be at the end of a string,
5783 if the `display' property takes up the whole string. */
5784 xassert (it
->sp
> 0);
5787 if (STRINGP (it
->string
))
5789 it
->method
= GET_FROM_STRING
;
5790 goto consider_string_end
;
5792 it
->method
= GET_FROM_BUFFER
;
5796 /* There are no other methods defined, so this should be a bug. */
5800 xassert (it
->method
!= GET_FROM_STRING
5801 || (STRINGP (it
->string
)
5802 && IT_STRING_CHARPOS (*it
) >= 0));
5805 /* Load IT's display element fields with information about the next
5806 display element which comes from a display table entry or from the
5807 result of translating a control character to one of the forms `^C'
5810 IT->dpvec holds the glyphs to return as characters.
5811 IT->saved_face_id holds the face id before the display vector--
5812 it is restored into IT->face_idin set_iterator_to_next. */
5815 next_element_from_display_vector (it
)
5819 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5821 it
->face_id
= it
->saved_face_id
;
5823 if (INTEGERP (*it
->dpvec
)
5824 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5828 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5829 it
->c
= FAST_GLYPH_CHAR (g
);
5830 it
->len
= CHAR_BYTES (it
->c
);
5832 /* The entry may contain a face id to use. Such a face id is
5833 the id of a Lisp face, not a realized face. A face id of
5834 zero means no face is specified. */
5835 if (it
->dpvec_face_id
>= 0)
5836 it
->face_id
= it
->dpvec_face_id
;
5839 int lface_id
= FAST_GLYPH_FACE (g
);
5841 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5846 /* Display table entry is invalid. Return a space. */
5847 it
->c
= ' ', it
->len
= 1;
5849 /* Don't change position and object of the iterator here. They are
5850 still the values of the character that had this display table
5851 entry or was translated, and that's what we want. */
5852 it
->what
= IT_CHARACTER
;
5857 /* Load IT with the next display element from Lisp string IT->string.
5858 IT->current.string_pos is the current position within the string.
5859 If IT->current.overlay_string_index >= 0, the Lisp string is an
5863 next_element_from_string (it
)
5866 struct text_pos position
;
5868 xassert (STRINGP (it
->string
));
5869 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5870 position
= it
->current
.string_pos
;
5872 /* Time to check for invisible text? */
5873 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5874 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5878 /* Since a handler may have changed IT->method, we must
5880 return get_next_display_element (it
);
5883 if (it
->current
.overlay_string_index
>= 0)
5885 /* Get the next character from an overlay string. In overlay
5886 strings, There is no field width or padding with spaces to
5888 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5893 else if (STRING_MULTIBYTE (it
->string
))
5895 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5896 const unsigned char *s
= (SDATA (it
->string
)
5897 + IT_STRING_BYTEPOS (*it
));
5898 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5902 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5908 /* Get the next character from a Lisp string that is not an
5909 overlay string. Such strings come from the mode line, for
5910 example. We may have to pad with spaces, or truncate the
5911 string. See also next_element_from_c_string. */
5912 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5917 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5919 /* Pad with spaces. */
5920 it
->c
= ' ', it
->len
= 1;
5921 CHARPOS (position
) = BYTEPOS (position
) = -1;
5923 else if (STRING_MULTIBYTE (it
->string
))
5925 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5926 const unsigned char *s
= (SDATA (it
->string
)
5927 + IT_STRING_BYTEPOS (*it
));
5928 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5932 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5937 /* Record what we have and where it came from. Note that we store a
5938 buffer position in IT->position although it could arguably be a
5940 it
->what
= IT_CHARACTER
;
5941 it
->object
= it
->string
;
5942 it
->position
= position
;
5947 /* Load IT with next display element from C string IT->s.
5948 IT->string_nchars is the maximum number of characters to return
5949 from the string. IT->end_charpos may be greater than
5950 IT->string_nchars when this function is called, in which case we
5951 may have to return padding spaces. Value is zero if end of string
5952 reached, including padding spaces. */
5955 next_element_from_c_string (it
)
5961 it
->what
= IT_CHARACTER
;
5962 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5965 /* IT's position can be greater IT->string_nchars in case a field
5966 width or precision has been specified when the iterator was
5968 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5970 /* End of the game. */
5974 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5976 /* Pad with spaces. */
5977 it
->c
= ' ', it
->len
= 1;
5978 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5980 else if (it
->multibyte_p
)
5982 /* Implementation note: The calls to strlen apparently aren't a
5983 performance problem because there is no noticeable performance
5984 difference between Emacs running in unibyte or multibyte mode. */
5985 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5986 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5990 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5996 /* Set up IT to return characters from an ellipsis, if appropriate.
5997 The definition of the ellipsis glyphs may come from a display table
5998 entry. This function Fills IT with the first glyph from the
5999 ellipsis if an ellipsis is to be displayed. */
6002 next_element_from_ellipsis (it
)
6005 if (it
->selective_display_ellipsis_p
)
6006 setup_for_ellipsis (it
, it
->len
);
6009 /* The face at the current position may be different from the
6010 face we find after the invisible text. Remember what it
6011 was in IT->saved_face_id, and signal that it's there by
6012 setting face_before_selective_p. */
6013 it
->saved_face_id
= it
->face_id
;
6014 it
->method
= GET_FROM_BUFFER
;
6015 reseat_at_next_visible_line_start (it
, 1);
6016 it
->face_before_selective_p
= 1;
6019 return get_next_display_element (it
);
6023 /* Deliver an image display element. The iterator IT is already
6024 filled with image information (done in handle_display_prop). Value
6029 next_element_from_image (it
)
6032 it
->what
= IT_IMAGE
;
6037 /* Fill iterator IT with next display element from a stretch glyph
6038 property. IT->object is the value of the text property. Value is
6042 next_element_from_stretch (it
)
6045 it
->what
= IT_STRETCH
;
6050 /* Load IT with the next display element from current_buffer. Value
6051 is zero if end of buffer reached. IT->stop_charpos is the next
6052 position at which to stop and check for text properties or buffer
6056 next_element_from_buffer (it
)
6061 /* Check this assumption, otherwise, we would never enter the
6062 if-statement, below. */
6063 xassert (IT_CHARPOS (*it
) >= BEGV
6064 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
6066 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6068 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6070 int overlay_strings_follow_p
;
6072 /* End of the game, except when overlay strings follow that
6073 haven't been returned yet. */
6074 if (it
->overlay_strings_at_end_processed_p
)
6075 overlay_strings_follow_p
= 0;
6078 it
->overlay_strings_at_end_processed_p
= 1;
6079 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6082 if (overlay_strings_follow_p
)
6083 success_p
= get_next_display_element (it
);
6087 it
->position
= it
->current
.pos
;
6094 return get_next_display_element (it
);
6099 /* No face changes, overlays etc. in sight, so just return a
6100 character from current_buffer. */
6103 /* Maybe run the redisplay end trigger hook. Performance note:
6104 This doesn't seem to cost measurable time. */
6105 if (it
->redisplay_end_trigger_charpos
6107 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6108 run_redisplay_end_trigger_hook (it
);
6110 /* Get the next character, maybe multibyte. */
6111 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6112 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6114 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
6115 - IT_BYTEPOS (*it
));
6116 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
6119 it
->c
= *p
, it
->len
= 1;
6121 /* Record what we have and where it came from. */
6122 it
->what
= IT_CHARACTER
;;
6123 it
->object
= it
->w
->buffer
;
6124 it
->position
= it
->current
.pos
;
6126 /* Normally we return the character found above, except when we
6127 really want to return an ellipsis for selective display. */
6132 /* A value of selective > 0 means hide lines indented more
6133 than that number of columns. */
6134 if (it
->selective
> 0
6135 && IT_CHARPOS (*it
) + 1 < ZV
6136 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6137 IT_BYTEPOS (*it
) + 1,
6138 (double) it
->selective
)) /* iftc */
6140 success_p
= next_element_from_ellipsis (it
);
6141 it
->dpvec_char_len
= -1;
6144 else if (it
->c
== '\r' && it
->selective
== -1)
6146 /* A value of selective == -1 means that everything from the
6147 CR to the end of the line is invisible, with maybe an
6148 ellipsis displayed for it. */
6149 success_p
= next_element_from_ellipsis (it
);
6150 it
->dpvec_char_len
= -1;
6155 /* Value is zero if end of buffer reached. */
6156 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6161 /* Run the redisplay end trigger hook for IT. */
6164 run_redisplay_end_trigger_hook (it
)
6167 Lisp_Object args
[3];
6169 /* IT->glyph_row should be non-null, i.e. we should be actually
6170 displaying something, or otherwise we should not run the hook. */
6171 xassert (it
->glyph_row
);
6173 /* Set up hook arguments. */
6174 args
[0] = Qredisplay_end_trigger_functions
;
6175 args
[1] = it
->window
;
6176 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6177 it
->redisplay_end_trigger_charpos
= 0;
6179 /* Since we are *trying* to run these functions, don't try to run
6180 them again, even if they get an error. */
6181 it
->w
->redisplay_end_trigger
= Qnil
;
6182 Frun_hook_with_args (3, args
);
6184 /* Notice if it changed the face of the character we are on. */
6185 handle_face_prop (it
);
6189 /* Deliver a composition display element. The iterator IT is already
6190 filled with composition information (done in
6191 handle_composition_prop). Value is always 1. */
6194 next_element_from_composition (it
)
6197 it
->what
= IT_COMPOSITION
;
6198 it
->position
= (STRINGP (it
->string
)
6199 ? it
->current
.string_pos
6206 /***********************************************************************
6207 Moving an iterator without producing glyphs
6208 ***********************************************************************/
6210 /* Check if iterator is at a position corresponding to a valid buffer
6211 position after some move_it_ call. */
6213 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6214 ((it)->method == GET_FROM_STRING \
6215 ? IT_STRING_CHARPOS (*it) == 0 \
6219 /* Move iterator IT to a specified buffer or X position within one
6220 line on the display without producing glyphs.
6222 OP should be a bit mask including some or all of these bits:
6223 MOVE_TO_X: Stop on reaching x-position TO_X.
6224 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6225 Regardless of OP's value, stop in reaching the end of the display line.
6227 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6228 This means, in particular, that TO_X includes window's horizontal
6231 The return value has several possible values that
6232 say what condition caused the scan to stop:
6234 MOVE_POS_MATCH_OR_ZV
6235 - when TO_POS or ZV was reached.
6238 -when TO_X was reached before TO_POS or ZV were reached.
6241 - when we reached the end of the display area and the line must
6245 - when we reached the end of the display area and the line is
6249 - when we stopped at a line end, i.e. a newline or a CR and selective
6252 static enum move_it_result
6253 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
6255 int to_charpos
, to_x
, op
;
6257 enum move_it_result result
= MOVE_UNDEFINED
;
6258 struct glyph_row
*saved_glyph_row
;
6260 /* Don't produce glyphs in produce_glyphs. */
6261 saved_glyph_row
= it
->glyph_row
;
6262 it
->glyph_row
= NULL
;
6264 #define BUFFER_POS_REACHED_P() \
6265 ((op & MOVE_TO_POS) != 0 \
6266 && BUFFERP (it->object) \
6267 && IT_CHARPOS (*it) >= to_charpos \
6268 && (it->method == GET_FROM_BUFFER \
6269 || (it->method == GET_FROM_DISPLAY_VECTOR \
6270 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6275 int x
, i
, ascent
= 0, descent
= 0;
6277 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
6278 if ((op
& MOVE_TO_POS
) != 0
6279 && BUFFERP (it
->object
)
6280 && it
->method
== GET_FROM_BUFFER
6281 && IT_CHARPOS (*it
) > to_charpos
)
6283 result
= MOVE_POS_MATCH_OR_ZV
;
6287 /* Stop when ZV reached.
6288 We used to stop here when TO_CHARPOS reached as well, but that is
6289 too soon if this glyph does not fit on this line. So we handle it
6290 explicitly below. */
6291 if (!get_next_display_element (it
)
6292 || (it
->truncate_lines_p
6293 && BUFFER_POS_REACHED_P ()))
6295 result
= MOVE_POS_MATCH_OR_ZV
;
6299 /* The call to produce_glyphs will get the metrics of the
6300 display element IT is loaded with. We record in x the
6301 x-position before this display element in case it does not
6305 /* Remember the line height so far in case the next element doesn't
6307 if (!it
->truncate_lines_p
)
6309 ascent
= it
->max_ascent
;
6310 descent
= it
->max_descent
;
6313 PRODUCE_GLYPHS (it
);
6315 if (it
->area
!= TEXT_AREA
)
6317 set_iterator_to_next (it
, 1);
6321 /* The number of glyphs we get back in IT->nglyphs will normally
6322 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6323 character on a terminal frame, or (iii) a line end. For the
6324 second case, IT->nglyphs - 1 padding glyphs will be present
6325 (on X frames, there is only one glyph produced for a
6326 composite character.
6328 The behavior implemented below means, for continuation lines,
6329 that as many spaces of a TAB as fit on the current line are
6330 displayed there. For terminal frames, as many glyphs of a
6331 multi-glyph character are displayed in the current line, too.
6332 This is what the old redisplay code did, and we keep it that
6333 way. Under X, the whole shape of a complex character must
6334 fit on the line or it will be completely displayed in the
6337 Note that both for tabs and padding glyphs, all glyphs have
6341 /* More than one glyph or glyph doesn't fit on line. All
6342 glyphs have the same width. */
6343 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6345 int x_before_this_char
= x
;
6346 int hpos_before_this_char
= it
->hpos
;
6348 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6350 new_x
= x
+ single_glyph_width
;
6352 /* We want to leave anything reaching TO_X to the caller. */
6353 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6355 if (BUFFER_POS_REACHED_P ())
6356 goto buffer_pos_reached
;
6358 result
= MOVE_X_REACHED
;
6361 else if (/* Lines are continued. */
6362 !it
->truncate_lines_p
6363 && (/* And glyph doesn't fit on the line. */
6364 new_x
> it
->last_visible_x
6365 /* Or it fits exactly and we're on a window
6367 || (new_x
== it
->last_visible_x
6368 && FRAME_WINDOW_P (it
->f
))))
6370 if (/* IT->hpos == 0 means the very first glyph
6371 doesn't fit on the line, e.g. a wide image. */
6373 || (new_x
== it
->last_visible_x
6374 && FRAME_WINDOW_P (it
->f
)))
6377 it
->current_x
= new_x
;
6379 /* The character's last glyph just barely fits
6381 if (i
== it
->nglyphs
- 1)
6383 /* If this is the destination position,
6384 return a position *before* it in this row,
6385 now that we know it fits in this row. */
6386 if (BUFFER_POS_REACHED_P ())
6388 it
->hpos
= hpos_before_this_char
;
6389 it
->current_x
= x_before_this_char
;
6390 result
= MOVE_POS_MATCH_OR_ZV
;
6394 set_iterator_to_next (it
, 1);
6395 #ifdef HAVE_WINDOW_SYSTEM
6396 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6398 if (!get_next_display_element (it
))
6400 result
= MOVE_POS_MATCH_OR_ZV
;
6403 if (BUFFER_POS_REACHED_P ())
6405 if (ITERATOR_AT_END_OF_LINE_P (it
))
6406 result
= MOVE_POS_MATCH_OR_ZV
;
6408 result
= MOVE_LINE_CONTINUED
;
6411 if (ITERATOR_AT_END_OF_LINE_P (it
))
6413 result
= MOVE_NEWLINE_OR_CR
;
6417 #endif /* HAVE_WINDOW_SYSTEM */
6423 it
->max_ascent
= ascent
;
6424 it
->max_descent
= descent
;
6427 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6429 result
= MOVE_LINE_CONTINUED
;
6432 else if (BUFFER_POS_REACHED_P ())
6433 goto buffer_pos_reached
;
6434 else if (new_x
> it
->first_visible_x
)
6436 /* Glyph is visible. Increment number of glyphs that
6437 would be displayed. */
6442 /* Glyph is completely off the left margin of the display
6443 area. Nothing to do. */
6447 if (result
!= MOVE_UNDEFINED
)
6450 else if (BUFFER_POS_REACHED_P ())
6454 it
->max_ascent
= ascent
;
6455 it
->max_descent
= descent
;
6456 result
= MOVE_POS_MATCH_OR_ZV
;
6459 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6461 /* Stop when TO_X specified and reached. This check is
6462 necessary here because of lines consisting of a line end,
6463 only. The line end will not produce any glyphs and we
6464 would never get MOVE_X_REACHED. */
6465 xassert (it
->nglyphs
== 0);
6466 result
= MOVE_X_REACHED
;
6470 /* Is this a line end? If yes, we're done. */
6471 if (ITERATOR_AT_END_OF_LINE_P (it
))
6473 result
= MOVE_NEWLINE_OR_CR
;
6477 /* The current display element has been consumed. Advance
6479 set_iterator_to_next (it
, 1);
6481 /* Stop if lines are truncated and IT's current x-position is
6482 past the right edge of the window now. */
6483 if (it
->truncate_lines_p
6484 && it
->current_x
>= it
->last_visible_x
)
6486 #ifdef HAVE_WINDOW_SYSTEM
6487 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6489 if (!get_next_display_element (it
)
6490 || BUFFER_POS_REACHED_P ())
6492 result
= MOVE_POS_MATCH_OR_ZV
;
6495 if (ITERATOR_AT_END_OF_LINE_P (it
))
6497 result
= MOVE_NEWLINE_OR_CR
;
6501 #endif /* HAVE_WINDOW_SYSTEM */
6502 result
= MOVE_LINE_TRUNCATED
;
6507 #undef BUFFER_POS_REACHED_P
6509 /* Restore the iterator settings altered at the beginning of this
6511 it
->glyph_row
= saved_glyph_row
;
6516 /* Move IT forward until it satisfies one or more of the criteria in
6517 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6519 OP is a bit-mask that specifies where to stop, and in particular,
6520 which of those four position arguments makes a difference. See the
6521 description of enum move_operation_enum.
6523 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6524 screen line, this function will set IT to the next position >
6528 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6530 int to_charpos
, to_x
, to_y
, to_vpos
;
6533 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6539 if (op
& MOVE_TO_VPOS
)
6541 /* If no TO_CHARPOS and no TO_X specified, stop at the
6542 start of the line TO_VPOS. */
6543 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6545 if (it
->vpos
== to_vpos
)
6551 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6555 /* TO_VPOS >= 0 means stop at TO_X in the line at
6556 TO_VPOS, or at TO_POS, whichever comes first. */
6557 if (it
->vpos
== to_vpos
)
6563 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6565 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6570 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6572 /* We have reached TO_X but not in the line we want. */
6573 skip
= move_it_in_display_line_to (it
, to_charpos
,
6575 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6583 else if (op
& MOVE_TO_Y
)
6585 struct it it_backup
;
6587 /* TO_Y specified means stop at TO_X in the line containing
6588 TO_Y---or at TO_CHARPOS if this is reached first. The
6589 problem is that we can't really tell whether the line
6590 contains TO_Y before we have completely scanned it, and
6591 this may skip past TO_X. What we do is to first scan to
6594 If TO_X is not specified, use a TO_X of zero. The reason
6595 is to make the outcome of this function more predictable.
6596 If we didn't use TO_X == 0, we would stop at the end of
6597 the line which is probably not what a caller would expect
6599 skip
= move_it_in_display_line_to (it
, to_charpos
,
6603 | (op
& MOVE_TO_POS
)));
6605 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6606 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6612 /* If TO_X was reached, we would like to know whether TO_Y
6613 is in the line. This can only be said if we know the
6614 total line height which requires us to scan the rest of
6616 if (skip
== MOVE_X_REACHED
)
6619 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6620 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6622 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6625 /* Now, decide whether TO_Y is in this line. */
6626 line_height
= it
->max_ascent
+ it
->max_descent
;
6627 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6629 if (to_y
>= it
->current_y
6630 && to_y
< it
->current_y
+ line_height
)
6632 if (skip
== MOVE_X_REACHED
)
6633 /* If TO_Y is in this line and TO_X was reached above,
6634 we scanned too far. We have to restore IT's settings
6635 to the ones before skipping. */
6639 else if (skip
== MOVE_X_REACHED
)
6642 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6650 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6654 case MOVE_POS_MATCH_OR_ZV
:
6658 case MOVE_NEWLINE_OR_CR
:
6659 set_iterator_to_next (it
, 1);
6660 it
->continuation_lines_width
= 0;
6663 case MOVE_LINE_TRUNCATED
:
6664 it
->continuation_lines_width
= 0;
6665 reseat_at_next_visible_line_start (it
, 0);
6666 if ((op
& MOVE_TO_POS
) != 0
6667 && IT_CHARPOS (*it
) > to_charpos
)
6674 case MOVE_LINE_CONTINUED
:
6675 it
->continuation_lines_width
+= it
->current_x
;
6682 /* Reset/increment for the next run. */
6683 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6684 it
->current_x
= it
->hpos
= 0;
6685 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6687 last_height
= it
->max_ascent
+ it
->max_descent
;
6688 last_max_ascent
= it
->max_ascent
;
6689 it
->max_ascent
= it
->max_descent
= 0;
6694 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6698 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6700 If DY > 0, move IT backward at least that many pixels. DY = 0
6701 means move IT backward to the preceding line start or BEGV. This
6702 function may move over more than DY pixels if IT->current_y - DY
6703 ends up in the middle of a line; in this case IT->current_y will be
6704 set to the top of the line moved to. */
6707 move_it_vertically_backward (it
, dy
)
6718 start_pos
= IT_CHARPOS (*it
);
6720 /* Estimate how many newlines we must move back. */
6721 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6723 /* Set the iterator's position that many lines back. */
6724 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6725 back_to_previous_visible_line_start (it
);
6727 /* Reseat the iterator here. When moving backward, we don't want
6728 reseat to skip forward over invisible text, set up the iterator
6729 to deliver from overlay strings at the new position etc. So,
6730 use reseat_1 here. */
6731 reseat_1 (it
, it
->current
.pos
, 1);
6733 /* We are now surely at a line start. */
6734 it
->current_x
= it
->hpos
= 0;
6735 it
->continuation_lines_width
= 0;
6737 /* Move forward and see what y-distance we moved. First move to the
6738 start of the next line so that we get its height. We need this
6739 height to be able to tell whether we reached the specified
6742 it2
.max_ascent
= it2
.max_descent
= 0;
6745 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6746 MOVE_TO_POS
| MOVE_TO_VPOS
);
6748 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
6749 xassert (IT_CHARPOS (*it
) >= BEGV
);
6752 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6753 xassert (IT_CHARPOS (*it
) >= BEGV
);
6754 /* H is the actual vertical distance from the position in *IT
6755 and the starting position. */
6756 h
= it2
.current_y
- it
->current_y
;
6757 /* NLINES is the distance in number of lines. */
6758 nlines
= it2
.vpos
- it
->vpos
;
6760 /* Correct IT's y and vpos position
6761 so that they are relative to the starting point. */
6767 /* DY == 0 means move to the start of the screen line. The
6768 value of nlines is > 0 if continuation lines were involved. */
6770 move_it_by_lines (it
, nlines
, 1);
6772 /* I think this assert is bogus if buffer contains
6773 invisible text or images. KFS. */
6774 xassert (IT_CHARPOS (*it
) <= start_pos
);
6779 /* The y-position we try to reach, relative to *IT.
6780 Note that H has been subtracted in front of the if-statement. */
6781 int target_y
= it
->current_y
+ h
- dy
;
6782 int y0
= it3
.current_y
;
6783 int y1
= line_bottom_y (&it3
);
6784 int line_height
= y1
- y0
;
6786 /* If we did not reach target_y, try to move further backward if
6787 we can. If we moved too far backward, try to move forward. */
6788 if (target_y
< it
->current_y
6789 /* This is heuristic. In a window that's 3 lines high, with
6790 a line height of 13 pixels each, recentering with point
6791 on the bottom line will try to move -39/2 = 19 pixels
6792 backward. Try to avoid moving into the first line. */
6793 && (it
->current_y
- target_y
6794 > min (window_box_height (it
->w
), line_height
* 2 / 3))
6795 && IT_CHARPOS (*it
) > BEGV
)
6797 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6798 target_y
- it
->current_y
));
6799 dy
= it
->current_y
- target_y
;
6800 goto move_further_back
;
6802 else if (target_y
>= it
->current_y
+ line_height
6803 && IT_CHARPOS (*it
) < ZV
)
6805 /* Should move forward by at least one line, maybe more.
6807 Note: Calling move_it_by_lines can be expensive on
6808 terminal frames, where compute_motion is used (via
6809 vmotion) to do the job, when there are very long lines
6810 and truncate-lines is nil. That's the reason for
6811 treating terminal frames specially here. */
6813 if (!FRAME_WINDOW_P (it
->f
))
6814 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6819 move_it_by_lines (it
, 1, 1);
6821 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6825 /* I think this assert is bogus if buffer contains
6826 invisible text or images. KFS. */
6827 xassert (IT_CHARPOS (*it
) >= BEGV
);
6834 /* Move IT by a specified amount of pixel lines DY. DY negative means
6835 move backwards. DY = 0 means move to start of screen line. At the
6836 end, IT will be on the start of a screen line. */
6839 move_it_vertically (it
, dy
)
6844 move_it_vertically_backward (it
, -dy
);
6847 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6848 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6849 MOVE_TO_POS
| MOVE_TO_Y
);
6850 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6852 /* If buffer ends in ZV without a newline, move to the start of
6853 the line to satisfy the post-condition. */
6854 if (IT_CHARPOS (*it
) == ZV
6856 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6857 move_it_by_lines (it
, 0, 0);
6862 /* Move iterator IT past the end of the text line it is in. */
6865 move_it_past_eol (it
)
6868 enum move_it_result rc
;
6870 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6871 if (rc
== MOVE_NEWLINE_OR_CR
)
6872 set_iterator_to_next (it
, 0);
6876 #if 0 /* Currently not used. */
6878 /* Return non-zero if some text between buffer positions START_CHARPOS
6879 and END_CHARPOS is invisible. IT->window is the window for text
6883 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6885 int start_charpos
, end_charpos
;
6887 Lisp_Object prop
, limit
;
6888 int invisible_found_p
;
6890 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6892 /* Is text at START invisible? */
6893 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6895 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6896 invisible_found_p
= 1;
6899 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6901 make_number (end_charpos
));
6902 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6905 return invisible_found_p
;
6911 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6912 negative means move up. DVPOS == 0 means move to the start of the
6913 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6914 NEED_Y_P is zero, IT->current_y will be left unchanged.
6916 Further optimization ideas: If we would know that IT->f doesn't use
6917 a face with proportional font, we could be faster for
6918 truncate-lines nil. */
6921 move_it_by_lines (it
, dvpos
, need_y_p
)
6923 int dvpos
, need_y_p
;
6925 struct position pos
;
6927 if (!FRAME_WINDOW_P (it
->f
))
6929 struct text_pos textpos
;
6931 /* We can use vmotion on frames without proportional fonts. */
6932 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6933 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6934 reseat (it
, textpos
, 1);
6935 it
->vpos
+= pos
.vpos
;
6936 it
->current_y
+= pos
.vpos
;
6938 else if (dvpos
== 0)
6940 /* DVPOS == 0 means move to the start of the screen line. */
6941 move_it_vertically_backward (it
, 0);
6942 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6943 /* Let next call to line_bottom_y calculate real line height */
6948 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6949 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
6950 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
6955 int start_charpos
, i
;
6957 /* Start at the beginning of the screen line containing IT's
6958 position. This may actually move vertically backwards,
6959 in case of overlays, so adjust dvpos accordingly. */
6961 move_it_vertically_backward (it
, 0);
6964 /* Go back -DVPOS visible lines and reseat the iterator there. */
6965 start_charpos
= IT_CHARPOS (*it
);
6966 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
6967 back_to_previous_visible_line_start (it
);
6968 reseat (it
, it
->current
.pos
, 1);
6970 /* Move further back if we end up in a string or an image. */
6971 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
6973 /* First try to move to start of display line. */
6975 move_it_vertically_backward (it
, 0);
6977 if (IT_POS_VALID_AFTER_MOVE_P (it
))
6979 /* If start of line is still in string or image,
6980 move further back. */
6981 back_to_previous_visible_line_start (it
);
6982 reseat (it
, it
->current
.pos
, 1);
6986 it
->current_x
= it
->hpos
= 0;
6988 /* Above call may have moved too far if continuation lines
6989 are involved. Scan forward and see if it did. */
6991 it2
.vpos
= it2
.current_y
= 0;
6992 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6993 it
->vpos
-= it2
.vpos
;
6994 it
->current_y
-= it2
.current_y
;
6995 it
->current_x
= it
->hpos
= 0;
6997 /* If we moved too far back, move IT some lines forward. */
6998 if (it2
.vpos
> -dvpos
)
7000 int delta
= it2
.vpos
+ dvpos
;
7002 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7003 /* Move back again if we got too far ahead. */
7004 if (IT_CHARPOS (*it
) >= start_charpos
)
7010 /* Return 1 if IT points into the middle of a display vector. */
7013 in_display_vector_p (it
)
7016 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7017 && it
->current
.dpvec_index
> 0
7018 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7022 /***********************************************************************
7024 ***********************************************************************/
7027 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7031 add_to_log (format
, arg1
, arg2
)
7033 Lisp_Object arg1
, arg2
;
7035 Lisp_Object args
[3];
7036 Lisp_Object msg
, fmt
;
7039 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7042 /* Do nothing if called asynchronously. Inserting text into
7043 a buffer may call after-change-functions and alike and
7044 that would means running Lisp asynchronously. */
7045 if (handling_signal
)
7049 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7051 args
[0] = fmt
= build_string (format
);
7054 msg
= Fformat (3, args
);
7056 len
= SBYTES (msg
) + 1;
7057 SAFE_ALLOCA (buffer
, char *, len
);
7058 bcopy (SDATA (msg
), buffer
, len
);
7060 message_dolog (buffer
, len
- 1, 1, 0);
7067 /* Output a newline in the *Messages* buffer if "needs" one. */
7070 message_log_maybe_newline ()
7072 if (message_log_need_newline
)
7073 message_dolog ("", 0, 1, 0);
7077 /* Add a string M of length NBYTES to the message log, optionally
7078 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7079 nonzero, means interpret the contents of M as multibyte. This
7080 function calls low-level routines in order to bypass text property
7081 hooks, etc. which might not be safe to run.
7083 This may GC (insert may run before/after change hooks),
7084 so the buffer M must NOT point to a Lisp string. */
7087 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7089 int nbytes
, nlflag
, multibyte
;
7091 if (!NILP (Vmemory_full
))
7094 if (!NILP (Vmessage_log_max
))
7096 struct buffer
*oldbuf
;
7097 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7098 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7099 int point_at_end
= 0;
7101 Lisp_Object old_deactivate_mark
, tem
;
7102 struct gcpro gcpro1
;
7104 old_deactivate_mark
= Vdeactivate_mark
;
7105 oldbuf
= current_buffer
;
7106 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7107 current_buffer
->undo_list
= Qt
;
7109 oldpoint
= message_dolog_marker1
;
7110 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7111 oldbegv
= message_dolog_marker2
;
7112 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7113 oldzv
= message_dolog_marker3
;
7114 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7115 GCPRO1 (old_deactivate_mark
);
7123 BEGV_BYTE
= BEG_BYTE
;
7126 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7128 /* Insert the string--maybe converting multibyte to single byte
7129 or vice versa, so that all the text fits the buffer. */
7131 && NILP (current_buffer
->enable_multibyte_characters
))
7133 int i
, c
, char_bytes
;
7134 unsigned char work
[1];
7136 /* Convert a multibyte string to single-byte
7137 for the *Message* buffer. */
7138 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7140 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7141 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7143 : multibyte_char_to_unibyte (c
, Qnil
));
7144 insert_1_both (work
, 1, 1, 1, 0, 0);
7147 else if (! multibyte
7148 && ! NILP (current_buffer
->enable_multibyte_characters
))
7150 int i
, c
, char_bytes
;
7151 unsigned char *msg
= (unsigned char *) m
;
7152 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7153 /* Convert a single-byte string to multibyte
7154 for the *Message* buffer. */
7155 for (i
= 0; i
< nbytes
; i
++)
7157 c
= unibyte_char_to_multibyte (msg
[i
]);
7158 char_bytes
= CHAR_STRING (c
, str
);
7159 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7163 insert_1 (m
, nbytes
, 1, 0, 0);
7167 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7168 insert_1 ("\n", 1, 1, 0, 0);
7170 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7172 this_bol_byte
= PT_BYTE
;
7174 /* See if this line duplicates the previous one.
7175 If so, combine duplicates. */
7178 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7180 prev_bol_byte
= PT_BYTE
;
7182 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7183 this_bol
, this_bol_byte
);
7186 del_range_both (prev_bol
, prev_bol_byte
,
7187 this_bol
, this_bol_byte
, 0);
7193 /* If you change this format, don't forget to also
7194 change message_log_check_duplicate. */
7195 sprintf (dupstr
, " [%d times]", dup
);
7196 duplen
= strlen (dupstr
);
7197 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7198 insert_1 (dupstr
, duplen
, 1, 0, 1);
7203 /* If we have more than the desired maximum number of lines
7204 in the *Messages* buffer now, delete the oldest ones.
7205 This is safe because we don't have undo in this buffer. */
7207 if (NATNUMP (Vmessage_log_max
))
7209 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7210 -XFASTINT (Vmessage_log_max
) - 1, 0);
7211 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7214 BEGV
= XMARKER (oldbegv
)->charpos
;
7215 BEGV_BYTE
= marker_byte_position (oldbegv
);
7224 ZV
= XMARKER (oldzv
)->charpos
;
7225 ZV_BYTE
= marker_byte_position (oldzv
);
7229 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7231 /* We can't do Fgoto_char (oldpoint) because it will run some
7233 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7234 XMARKER (oldpoint
)->bytepos
);
7237 unchain_marker (XMARKER (oldpoint
));
7238 unchain_marker (XMARKER (oldbegv
));
7239 unchain_marker (XMARKER (oldzv
));
7241 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7242 set_buffer_internal (oldbuf
);
7244 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7245 message_log_need_newline
= !nlflag
;
7246 Vdeactivate_mark
= old_deactivate_mark
;
7251 /* We are at the end of the buffer after just having inserted a newline.
7252 (Note: We depend on the fact we won't be crossing the gap.)
7253 Check to see if the most recent message looks a lot like the previous one.
7254 Return 0 if different, 1 if the new one should just replace it, or a
7255 value N > 1 if we should also append " [N times]". */
7258 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7259 int prev_bol
, this_bol
;
7260 int prev_bol_byte
, this_bol_byte
;
7263 int len
= Z_BYTE
- 1 - this_bol_byte
;
7265 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7266 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7268 for (i
= 0; i
< len
; i
++)
7270 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7278 if (*p1
++ == ' ' && *p1
++ == '[')
7281 while (*p1
>= '0' && *p1
<= '9')
7282 n
= n
* 10 + *p1
++ - '0';
7283 if (strncmp (p1
, " times]\n", 8) == 0)
7290 /* Display an echo area message M with a specified length of NBYTES
7291 bytes. The string may include null characters. If M is 0, clear
7292 out any existing message, and let the mini-buffer text show
7295 This may GC, so the buffer M must NOT point to a Lisp string. */
7298 message2 (m
, nbytes
, multibyte
)
7303 /* First flush out any partial line written with print. */
7304 message_log_maybe_newline ();
7306 message_dolog (m
, nbytes
, 1, multibyte
);
7307 message2_nolog (m
, nbytes
, multibyte
);
7311 /* The non-logging counterpart of message2. */
7314 message2_nolog (m
, nbytes
, multibyte
)
7316 int nbytes
, multibyte
;
7318 struct frame
*sf
= SELECTED_FRAME ();
7319 message_enable_multibyte
= multibyte
;
7323 if (noninteractive_need_newline
)
7324 putc ('\n', stderr
);
7325 noninteractive_need_newline
= 0;
7327 fwrite (m
, nbytes
, 1, stderr
);
7328 if (cursor_in_echo_area
== 0)
7329 fprintf (stderr
, "\n");
7332 /* A null message buffer means that the frame hasn't really been
7333 initialized yet. Error messages get reported properly by
7334 cmd_error, so this must be just an informative message; toss it. */
7335 else if (INTERACTIVE
7336 && sf
->glyphs_initialized_p
7337 && FRAME_MESSAGE_BUF (sf
))
7339 Lisp_Object mini_window
;
7342 /* Get the frame containing the mini-buffer
7343 that the selected frame is using. */
7344 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7345 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7347 FRAME_SAMPLE_VISIBILITY (f
);
7348 if (FRAME_VISIBLE_P (sf
)
7349 && ! FRAME_VISIBLE_P (f
))
7350 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7354 set_message (m
, Qnil
, nbytes
, multibyte
);
7355 if (minibuffer_auto_raise
)
7356 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7359 clear_message (1, 1);
7361 do_pending_window_change (0);
7362 echo_area_display (1);
7363 do_pending_window_change (0);
7364 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7365 (*frame_up_to_date_hook
) (f
);
7370 /* Display an echo area message M with a specified length of NBYTES
7371 bytes. The string may include null characters. If M is not a
7372 string, clear out any existing message, and let the mini-buffer
7375 This function cancels echoing. */
7378 message3 (m
, nbytes
, multibyte
)
7383 struct gcpro gcpro1
;
7386 clear_message (1,1);
7389 /* First flush out any partial line written with print. */
7390 message_log_maybe_newline ();
7396 SAFE_ALLOCA (buffer
, char *, nbytes
);
7397 bcopy (SDATA (m
), buffer
, nbytes
);
7398 message_dolog (buffer
, nbytes
, 1, multibyte
);
7401 message3_nolog (m
, nbytes
, multibyte
);
7407 /* The non-logging version of message3.
7408 This does not cancel echoing, because it is used for echoing.
7409 Perhaps we need to make a separate function for echoing
7410 and make this cancel echoing. */
7413 message3_nolog (m
, nbytes
, multibyte
)
7415 int nbytes
, multibyte
;
7417 struct frame
*sf
= SELECTED_FRAME ();
7418 message_enable_multibyte
= multibyte
;
7422 if (noninteractive_need_newline
)
7423 putc ('\n', stderr
);
7424 noninteractive_need_newline
= 0;
7426 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7427 if (cursor_in_echo_area
== 0)
7428 fprintf (stderr
, "\n");
7431 /* A null message buffer means that the frame hasn't really been
7432 initialized yet. Error messages get reported properly by
7433 cmd_error, so this must be just an informative message; toss it. */
7434 else if (INTERACTIVE
7435 && sf
->glyphs_initialized_p
7436 && FRAME_MESSAGE_BUF (sf
))
7438 Lisp_Object mini_window
;
7442 /* Get the frame containing the mini-buffer
7443 that the selected frame is using. */
7444 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7445 frame
= XWINDOW (mini_window
)->frame
;
7448 FRAME_SAMPLE_VISIBILITY (f
);
7449 if (FRAME_VISIBLE_P (sf
)
7450 && !FRAME_VISIBLE_P (f
))
7451 Fmake_frame_visible (frame
);
7453 if (STRINGP (m
) && SCHARS (m
) > 0)
7455 set_message (NULL
, m
, nbytes
, multibyte
);
7456 if (minibuffer_auto_raise
)
7457 Fraise_frame (frame
);
7458 /* Assume we are not echoing.
7459 (If we are, echo_now will override this.) */
7460 echo_message_buffer
= Qnil
;
7463 clear_message (1, 1);
7465 do_pending_window_change (0);
7466 echo_area_display (1);
7467 do_pending_window_change (0);
7468 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7469 (*frame_up_to_date_hook
) (f
);
7474 /* Display a null-terminated echo area message M. If M is 0, clear
7475 out any existing message, and let the mini-buffer text show through.
7477 The buffer M must continue to exist until after the echo area gets
7478 cleared or some other message gets displayed there. Do not pass
7479 text that is stored in a Lisp string. Do not pass text in a buffer
7480 that was alloca'd. */
7486 message2 (m
, (m
? strlen (m
) : 0), 0);
7490 /* The non-logging counterpart of message1. */
7496 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7499 /* Display a message M which contains a single %s
7500 which gets replaced with STRING. */
7503 message_with_string (m
, string
, log
)
7508 CHECK_STRING (string
);
7514 if (noninteractive_need_newline
)
7515 putc ('\n', stderr
);
7516 noninteractive_need_newline
= 0;
7517 fprintf (stderr
, m
, SDATA (string
));
7518 if (cursor_in_echo_area
== 0)
7519 fprintf (stderr
, "\n");
7523 else if (INTERACTIVE
)
7525 /* The frame whose minibuffer we're going to display the message on.
7526 It may be larger than the selected frame, so we need
7527 to use its buffer, not the selected frame's buffer. */
7528 Lisp_Object mini_window
;
7529 struct frame
*f
, *sf
= SELECTED_FRAME ();
7531 /* Get the frame containing the minibuffer
7532 that the selected frame is using. */
7533 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7534 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7536 /* A null message buffer means that the frame hasn't really been
7537 initialized yet. Error messages get reported properly by
7538 cmd_error, so this must be just an informative message; toss it. */
7539 if (FRAME_MESSAGE_BUF (f
))
7541 Lisp_Object args
[2], message
;
7542 struct gcpro gcpro1
, gcpro2
;
7544 args
[0] = build_string (m
);
7545 args
[1] = message
= string
;
7546 GCPRO2 (args
[0], message
);
7549 message
= Fformat (2, args
);
7552 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7554 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7558 /* Print should start at the beginning of the message
7559 buffer next time. */
7560 message_buf_print
= 0;
7566 /* Dump an informative message to the minibuf. If M is 0, clear out
7567 any existing message, and let the mini-buffer text show through. */
7571 message (m
, a1
, a2
, a3
)
7573 EMACS_INT a1
, a2
, a3
;
7579 if (noninteractive_need_newline
)
7580 putc ('\n', stderr
);
7581 noninteractive_need_newline
= 0;
7582 fprintf (stderr
, m
, a1
, a2
, a3
);
7583 if (cursor_in_echo_area
== 0)
7584 fprintf (stderr
, "\n");
7588 else if (INTERACTIVE
)
7590 /* The frame whose mini-buffer we're going to display the message
7591 on. It may be larger than the selected frame, so we need to
7592 use its buffer, not the selected frame's buffer. */
7593 Lisp_Object mini_window
;
7594 struct frame
*f
, *sf
= SELECTED_FRAME ();
7596 /* Get the frame containing the mini-buffer
7597 that the selected frame is using. */
7598 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7599 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7601 /* A null message buffer means that the frame hasn't really been
7602 initialized yet. Error messages get reported properly by
7603 cmd_error, so this must be just an informative message; toss
7605 if (FRAME_MESSAGE_BUF (f
))
7616 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7617 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7619 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7620 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7622 #endif /* NO_ARG_ARRAY */
7624 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7629 /* Print should start at the beginning of the message
7630 buffer next time. */
7631 message_buf_print
= 0;
7637 /* The non-logging version of message. */
7640 message_nolog (m
, a1
, a2
, a3
)
7642 EMACS_INT a1
, a2
, a3
;
7644 Lisp_Object old_log_max
;
7645 old_log_max
= Vmessage_log_max
;
7646 Vmessage_log_max
= Qnil
;
7647 message (m
, a1
, a2
, a3
);
7648 Vmessage_log_max
= old_log_max
;
7652 /* Display the current message in the current mini-buffer. This is
7653 only called from error handlers in process.c, and is not time
7659 if (!NILP (echo_area_buffer
[0]))
7662 string
= Fcurrent_message ();
7663 message3 (string
, SBYTES (string
),
7664 !NILP (current_buffer
->enable_multibyte_characters
));
7669 /* Make sure echo area buffers in `echo_buffers' are live.
7670 If they aren't, make new ones. */
7673 ensure_echo_area_buffers ()
7677 for (i
= 0; i
< 2; ++i
)
7678 if (!BUFFERP (echo_buffer
[i
])
7679 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7682 Lisp_Object old_buffer
;
7685 old_buffer
= echo_buffer
[i
];
7686 sprintf (name
, " *Echo Area %d*", i
);
7687 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7688 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7690 for (j
= 0; j
< 2; ++j
)
7691 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7692 echo_area_buffer
[j
] = echo_buffer
[i
];
7697 /* Call FN with args A1..A4 with either the current or last displayed
7698 echo_area_buffer as current buffer.
7700 WHICH zero means use the current message buffer
7701 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7702 from echo_buffer[] and clear it.
7704 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7705 suitable buffer from echo_buffer[] and clear it.
7707 Value is what FN returns. */
7710 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7713 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7719 int this_one
, the_other
, clear_buffer_p
, rc
;
7720 int count
= SPECPDL_INDEX ();
7722 /* If buffers aren't live, make new ones. */
7723 ensure_echo_area_buffers ();
7728 this_one
= 0, the_other
= 1;
7730 this_one
= 1, the_other
= 0;
7732 /* Choose a suitable buffer from echo_buffer[] is we don't
7734 if (NILP (echo_area_buffer
[this_one
]))
7736 echo_area_buffer
[this_one
]
7737 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7738 ? echo_buffer
[the_other
]
7739 : echo_buffer
[this_one
]);
7743 buffer
= echo_area_buffer
[this_one
];
7745 /* Don't get confused by reusing the buffer used for echoing
7746 for a different purpose. */
7747 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7750 record_unwind_protect (unwind_with_echo_area_buffer
,
7751 with_echo_area_buffer_unwind_data (w
));
7753 /* Make the echo area buffer current. Note that for display
7754 purposes, it is not necessary that the displayed window's buffer
7755 == current_buffer, except for text property lookup. So, let's
7756 only set that buffer temporarily here without doing a full
7757 Fset_window_buffer. We must also change w->pointm, though,
7758 because otherwise an assertions in unshow_buffer fails, and Emacs
7760 set_buffer_internal_1 (XBUFFER (buffer
));
7764 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7767 current_buffer
->undo_list
= Qt
;
7768 current_buffer
->read_only
= Qnil
;
7769 specbind (Qinhibit_read_only
, Qt
);
7770 specbind (Qinhibit_modification_hooks
, Qt
);
7772 if (clear_buffer_p
&& Z
> BEG
)
7775 xassert (BEGV
>= BEG
);
7776 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7778 rc
= fn (a1
, a2
, a3
, a4
);
7780 xassert (BEGV
>= BEG
);
7781 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7783 unbind_to (count
, Qnil
);
7788 /* Save state that should be preserved around the call to the function
7789 FN called in with_echo_area_buffer. */
7792 with_echo_area_buffer_unwind_data (w
)
7798 /* Reduce consing by keeping one vector in
7799 Vwith_echo_area_save_vector. */
7800 vector
= Vwith_echo_area_save_vector
;
7801 Vwith_echo_area_save_vector
= Qnil
;
7804 vector
= Fmake_vector (make_number (7), Qnil
);
7806 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7807 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7808 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7812 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7813 AREF (vector
, i
) = w
->buffer
; ++i
;
7814 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7815 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7820 for (; i
< end
; ++i
)
7821 AREF (vector
, i
) = Qnil
;
7824 xassert (i
== ASIZE (vector
));
7829 /* Restore global state from VECTOR which was created by
7830 with_echo_area_buffer_unwind_data. */
7833 unwind_with_echo_area_buffer (vector
)
7836 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7837 Vdeactivate_mark
= AREF (vector
, 1);
7838 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7840 if (WINDOWP (AREF (vector
, 3)))
7843 Lisp_Object buffer
, charpos
, bytepos
;
7845 w
= XWINDOW (AREF (vector
, 3));
7846 buffer
= AREF (vector
, 4);
7847 charpos
= AREF (vector
, 5);
7848 bytepos
= AREF (vector
, 6);
7851 set_marker_both (w
->pointm
, buffer
,
7852 XFASTINT (charpos
), XFASTINT (bytepos
));
7855 Vwith_echo_area_save_vector
= vector
;
7860 /* Set up the echo area for use by print functions. MULTIBYTE_P
7861 non-zero means we will print multibyte. */
7864 setup_echo_area_for_printing (multibyte_p
)
7867 /* If we can't find an echo area any more, exit. */
7868 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7871 ensure_echo_area_buffers ();
7873 if (!message_buf_print
)
7875 /* A message has been output since the last time we printed.
7876 Choose a fresh echo area buffer. */
7877 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7878 echo_area_buffer
[0] = echo_buffer
[1];
7880 echo_area_buffer
[0] = echo_buffer
[0];
7882 /* Switch to that buffer and clear it. */
7883 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7884 current_buffer
->truncate_lines
= Qnil
;
7888 int count
= SPECPDL_INDEX ();
7889 specbind (Qinhibit_read_only
, Qt
);
7890 /* Note that undo recording is always disabled. */
7892 unbind_to (count
, Qnil
);
7894 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7896 /* Set up the buffer for the multibyteness we need. */
7898 != !NILP (current_buffer
->enable_multibyte_characters
))
7899 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7901 /* Raise the frame containing the echo area. */
7902 if (minibuffer_auto_raise
)
7904 struct frame
*sf
= SELECTED_FRAME ();
7905 Lisp_Object mini_window
;
7906 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7907 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7910 message_log_maybe_newline ();
7911 message_buf_print
= 1;
7915 if (NILP (echo_area_buffer
[0]))
7917 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7918 echo_area_buffer
[0] = echo_buffer
[1];
7920 echo_area_buffer
[0] = echo_buffer
[0];
7923 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7925 /* Someone switched buffers between print requests. */
7926 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7927 current_buffer
->truncate_lines
= Qnil
;
7933 /* Display an echo area message in window W. Value is non-zero if W's
7934 height is changed. If display_last_displayed_message_p is
7935 non-zero, display the message that was last displayed, otherwise
7936 display the current message. */
7939 display_echo_area (w
)
7942 int i
, no_message_p
, window_height_changed_p
, count
;
7944 /* Temporarily disable garbage collections while displaying the echo
7945 area. This is done because a GC can print a message itself.
7946 That message would modify the echo area buffer's contents while a
7947 redisplay of the buffer is going on, and seriously confuse
7949 count
= inhibit_garbage_collection ();
7951 /* If there is no message, we must call display_echo_area_1
7952 nevertheless because it resizes the window. But we will have to
7953 reset the echo_area_buffer in question to nil at the end because
7954 with_echo_area_buffer will sets it to an empty buffer. */
7955 i
= display_last_displayed_message_p
? 1 : 0;
7956 no_message_p
= NILP (echo_area_buffer
[i
]);
7958 window_height_changed_p
7959 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7960 display_echo_area_1
,
7961 (EMACS_INT
) w
, Qnil
, 0, 0);
7964 echo_area_buffer
[i
] = Qnil
;
7966 unbind_to (count
, Qnil
);
7967 return window_height_changed_p
;
7971 /* Helper for display_echo_area. Display the current buffer which
7972 contains the current echo area message in window W, a mini-window,
7973 a pointer to which is passed in A1. A2..A4 are currently not used.
7974 Change the height of W so that all of the message is displayed.
7975 Value is non-zero if height of W was changed. */
7978 display_echo_area_1 (a1
, a2
, a3
, a4
)
7983 struct window
*w
= (struct window
*) a1
;
7985 struct text_pos start
;
7986 int window_height_changed_p
= 0;
7988 /* Do this before displaying, so that we have a large enough glyph
7989 matrix for the display. If we can't get enough space for the
7990 whole text, display the last N lines. That works by setting w->start. */
7991 window_height_changed_p
= resize_mini_window (w
, 0);
7993 /* Use the starting position chosen by resize_mini_window. */
7994 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
7997 clear_glyph_matrix (w
->desired_matrix
);
7998 XSETWINDOW (window
, w
);
7999 try_window (window
, start
, 0);
8001 return window_height_changed_p
;
8005 /* Resize the echo area window to exactly the size needed for the
8006 currently displayed message, if there is one. If a mini-buffer
8007 is active, don't shrink it. */
8010 resize_echo_area_exactly ()
8012 if (BUFFERP (echo_area_buffer
[0])
8013 && WINDOWP (echo_area_window
))
8015 struct window
*w
= XWINDOW (echo_area_window
);
8017 Lisp_Object resize_exactly
;
8019 if (minibuf_level
== 0)
8020 resize_exactly
= Qt
;
8022 resize_exactly
= Qnil
;
8024 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8025 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8028 ++windows_or_buffers_changed
;
8029 ++update_mode_lines
;
8030 redisplay_internal (0);
8036 /* Callback function for with_echo_area_buffer, when used from
8037 resize_echo_area_exactly. A1 contains a pointer to the window to
8038 resize, EXACTLY non-nil means resize the mini-window exactly to the
8039 size of the text displayed. A3 and A4 are not used. Value is what
8040 resize_mini_window returns. */
8043 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8045 Lisp_Object exactly
;
8048 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8052 /* Resize mini-window W to fit the size of its contents. EXACT:P
8053 means size the window exactly to the size needed. Otherwise, it's
8054 only enlarged until W's buffer is empty.
8056 Set W->start to the right place to begin display. If the whole
8057 contents fit, start at the beginning. Otherwise, start so as
8058 to make the end of the contents appear. This is particularly
8059 important for y-or-n-p, but seems desirable generally.
8061 Value is non-zero if the window height has been changed. */
8064 resize_mini_window (w
, exact_p
)
8068 struct frame
*f
= XFRAME (w
->frame
);
8069 int window_height_changed_p
= 0;
8071 xassert (MINI_WINDOW_P (w
));
8073 /* By default, start display at the beginning. */
8074 set_marker_both (w
->start
, w
->buffer
,
8075 BUF_BEGV (XBUFFER (w
->buffer
)),
8076 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8078 /* Don't resize windows while redisplaying a window; it would
8079 confuse redisplay functions when the size of the window they are
8080 displaying changes from under them. Such a resizing can happen,
8081 for instance, when which-func prints a long message while
8082 we are running fontification-functions. We're running these
8083 functions with safe_call which binds inhibit-redisplay to t. */
8084 if (!NILP (Vinhibit_redisplay
))
8087 /* Nil means don't try to resize. */
8088 if (NILP (Vresize_mini_windows
)
8089 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8092 if (!FRAME_MINIBUF_ONLY_P (f
))
8095 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8096 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8097 int height
, max_height
;
8098 int unit
= FRAME_LINE_HEIGHT (f
);
8099 struct text_pos start
;
8100 struct buffer
*old_current_buffer
= NULL
;
8102 if (current_buffer
!= XBUFFER (w
->buffer
))
8104 old_current_buffer
= current_buffer
;
8105 set_buffer_internal (XBUFFER (w
->buffer
));
8108 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8110 /* Compute the max. number of lines specified by the user. */
8111 if (FLOATP (Vmax_mini_window_height
))
8112 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8113 else if (INTEGERP (Vmax_mini_window_height
))
8114 max_height
= XINT (Vmax_mini_window_height
);
8116 max_height
= total_height
/ 4;
8118 /* Correct that max. height if it's bogus. */
8119 max_height
= max (1, max_height
);
8120 max_height
= min (total_height
, max_height
);
8122 /* Find out the height of the text in the window. */
8123 if (it
.truncate_lines_p
)
8128 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8129 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8130 height
= it
.current_y
+ last_height
;
8132 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8133 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8134 height
= (height
+ unit
- 1) / unit
;
8137 /* Compute a suitable window start. */
8138 if (height
> max_height
)
8140 height
= max_height
;
8141 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8142 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8143 start
= it
.current
.pos
;
8146 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8147 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8149 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8151 /* Let it grow only, until we display an empty message, in which
8152 case the window shrinks again. */
8153 if (height
> WINDOW_TOTAL_LINES (w
))
8155 int old_height
= WINDOW_TOTAL_LINES (w
);
8156 freeze_window_starts (f
, 1);
8157 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8158 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8160 else if (height
< WINDOW_TOTAL_LINES (w
)
8161 && (exact_p
|| BEGV
== ZV
))
8163 int old_height
= WINDOW_TOTAL_LINES (w
);
8164 freeze_window_starts (f
, 0);
8165 shrink_mini_window (w
);
8166 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8171 /* Always resize to exact size needed. */
8172 if (height
> WINDOW_TOTAL_LINES (w
))
8174 int old_height
= WINDOW_TOTAL_LINES (w
);
8175 freeze_window_starts (f
, 1);
8176 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8177 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8179 else if (height
< WINDOW_TOTAL_LINES (w
))
8181 int old_height
= WINDOW_TOTAL_LINES (w
);
8182 freeze_window_starts (f
, 0);
8183 shrink_mini_window (w
);
8187 freeze_window_starts (f
, 1);
8188 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8191 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8195 if (old_current_buffer
)
8196 set_buffer_internal (old_current_buffer
);
8199 return window_height_changed_p
;
8203 /* Value is the current message, a string, or nil if there is no
8211 if (NILP (echo_area_buffer
[0]))
8215 with_echo_area_buffer (0, 0, current_message_1
,
8216 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8218 echo_area_buffer
[0] = Qnil
;
8226 current_message_1 (a1
, a2
, a3
, a4
)
8231 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8234 *msg
= make_buffer_string (BEG
, Z
, 1);
8241 /* Push the current message on Vmessage_stack for later restauration
8242 by restore_message. Value is non-zero if the current message isn't
8243 empty. This is a relatively infrequent operation, so it's not
8244 worth optimizing. */
8250 msg
= current_message ();
8251 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8252 return STRINGP (msg
);
8256 /* Restore message display from the top of Vmessage_stack. */
8263 xassert (CONSP (Vmessage_stack
));
8264 msg
= XCAR (Vmessage_stack
);
8266 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8268 message3_nolog (msg
, 0, 0);
8272 /* Handler for record_unwind_protect calling pop_message. */
8275 pop_message_unwind (dummy
)
8282 /* Pop the top-most entry off Vmessage_stack. */
8287 xassert (CONSP (Vmessage_stack
));
8288 Vmessage_stack
= XCDR (Vmessage_stack
);
8292 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8293 exits. If the stack is not empty, we have a missing pop_message
8297 check_message_stack ()
8299 if (!NILP (Vmessage_stack
))
8304 /* Truncate to NCHARS what will be displayed in the echo area the next
8305 time we display it---but don't redisplay it now. */
8308 truncate_echo_area (nchars
)
8312 echo_area_buffer
[0] = Qnil
;
8313 /* A null message buffer means that the frame hasn't really been
8314 initialized yet. Error messages get reported properly by
8315 cmd_error, so this must be just an informative message; toss it. */
8316 else if (!noninteractive
8318 && !NILP (echo_area_buffer
[0]))
8320 struct frame
*sf
= SELECTED_FRAME ();
8321 if (FRAME_MESSAGE_BUF (sf
))
8322 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8327 /* Helper function for truncate_echo_area. Truncate the current
8328 message to at most NCHARS characters. */
8331 truncate_message_1 (nchars
, a2
, a3
, a4
)
8336 if (BEG
+ nchars
< Z
)
8337 del_range (BEG
+ nchars
, Z
);
8339 echo_area_buffer
[0] = Qnil
;
8344 /* Set the current message to a substring of S or STRING.
8346 If STRING is a Lisp string, set the message to the first NBYTES
8347 bytes from STRING. NBYTES zero means use the whole string. If
8348 STRING is multibyte, the message will be displayed multibyte.
8350 If S is not null, set the message to the first LEN bytes of S. LEN
8351 zero means use the whole string. MULTIBYTE_P non-zero means S is
8352 multibyte. Display the message multibyte in that case.
8354 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8355 to t before calling set_message_1 (which calls insert).
8359 set_message (s
, string
, nbytes
, multibyte_p
)
8362 int nbytes
, multibyte_p
;
8364 message_enable_multibyte
8365 = ((s
&& multibyte_p
)
8366 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8368 with_echo_area_buffer (0, 0, set_message_1
,
8369 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8370 message_buf_print
= 0;
8371 help_echo_showing_p
= 0;
8375 /* Helper function for set_message. Arguments have the same meaning
8376 as there, with A1 corresponding to S and A2 corresponding to STRING
8377 This function is called with the echo area buffer being
8381 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8384 EMACS_INT nbytes
, multibyte_p
;
8386 const char *s
= (const char *) a1
;
8387 Lisp_Object string
= a2
;
8389 /* Change multibyteness of the echo buffer appropriately. */
8390 if (message_enable_multibyte
8391 != !NILP (current_buffer
->enable_multibyte_characters
))
8392 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8394 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8396 /* Insert new message at BEG. */
8397 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8400 if (STRINGP (string
))
8405 nbytes
= SBYTES (string
);
8406 nchars
= string_byte_to_char (string
, nbytes
);
8408 /* This function takes care of single/multibyte conversion. We
8409 just have to ensure that the echo area buffer has the right
8410 setting of enable_multibyte_characters. */
8411 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8416 nbytes
= strlen (s
);
8418 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8420 /* Convert from multi-byte to single-byte. */
8422 unsigned char work
[1];
8424 /* Convert a multibyte string to single-byte. */
8425 for (i
= 0; i
< nbytes
; i
+= n
)
8427 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8428 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
8430 : multibyte_char_to_unibyte (c
, Qnil
));
8431 insert_1_both (work
, 1, 1, 1, 0, 0);
8434 else if (!multibyte_p
8435 && !NILP (current_buffer
->enable_multibyte_characters
))
8437 /* Convert from single-byte to multi-byte. */
8439 const unsigned char *msg
= (const unsigned char *) s
;
8440 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8442 /* Convert a single-byte string to multibyte. */
8443 for (i
= 0; i
< nbytes
; i
++)
8445 c
= unibyte_char_to_multibyte (msg
[i
]);
8446 n
= CHAR_STRING (c
, str
);
8447 insert_1_both (str
, 1, n
, 1, 0, 0);
8451 insert_1 (s
, nbytes
, 1, 0, 0);
8458 /* Clear messages. CURRENT_P non-zero means clear the current
8459 message. LAST_DISPLAYED_P non-zero means clear the message
8463 clear_message (current_p
, last_displayed_p
)
8464 int current_p
, last_displayed_p
;
8468 echo_area_buffer
[0] = Qnil
;
8469 message_cleared_p
= 1;
8472 if (last_displayed_p
)
8473 echo_area_buffer
[1] = Qnil
;
8475 message_buf_print
= 0;
8478 /* Clear garbaged frames.
8480 This function is used where the old redisplay called
8481 redraw_garbaged_frames which in turn called redraw_frame which in
8482 turn called clear_frame. The call to clear_frame was a source of
8483 flickering. I believe a clear_frame is not necessary. It should
8484 suffice in the new redisplay to invalidate all current matrices,
8485 and ensure a complete redisplay of all windows. */
8488 clear_garbaged_frames ()
8492 Lisp_Object tail
, frame
;
8493 int changed_count
= 0;
8495 FOR_EACH_FRAME (tail
, frame
)
8497 struct frame
*f
= XFRAME (frame
);
8499 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8503 Fredraw_frame (frame
);
8504 f
->force_flush_display_p
= 1;
8506 clear_current_matrices (f
);
8515 ++windows_or_buffers_changed
;
8520 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8521 is non-zero update selected_frame. Value is non-zero if the
8522 mini-windows height has been changed. */
8525 echo_area_display (update_frame_p
)
8528 Lisp_Object mini_window
;
8531 int window_height_changed_p
= 0;
8532 struct frame
*sf
= SELECTED_FRAME ();
8534 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8535 w
= XWINDOW (mini_window
);
8536 f
= XFRAME (WINDOW_FRAME (w
));
8538 /* Don't display if frame is invisible or not yet initialized. */
8539 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8542 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8544 #ifdef HAVE_WINDOW_SYSTEM
8545 /* When Emacs starts, selected_frame may be a visible terminal
8546 frame, even if we run under a window system. If we let this
8547 through, a message would be displayed on the terminal. */
8548 if (EQ (selected_frame
, Vterminal_frame
)
8549 && !NILP (Vwindow_system
))
8551 #endif /* HAVE_WINDOW_SYSTEM */
8554 /* Redraw garbaged frames. */
8556 clear_garbaged_frames ();
8558 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8560 echo_area_window
= mini_window
;
8561 window_height_changed_p
= display_echo_area (w
);
8562 w
->must_be_updated_p
= 1;
8564 /* Update the display, unless called from redisplay_internal.
8565 Also don't update the screen during redisplay itself. The
8566 update will happen at the end of redisplay, and an update
8567 here could cause confusion. */
8568 if (update_frame_p
&& !redisplaying_p
)
8572 /* If the display update has been interrupted by pending
8573 input, update mode lines in the frame. Due to the
8574 pending input, it might have been that redisplay hasn't
8575 been called, so that mode lines above the echo area are
8576 garbaged. This looks odd, so we prevent it here. */
8577 if (!display_completed
)
8578 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8580 if (window_height_changed_p
8581 /* Don't do this if Emacs is shutting down. Redisplay
8582 needs to run hooks. */
8583 && !NILP (Vrun_hooks
))
8585 /* Must update other windows. Likewise as in other
8586 cases, don't let this update be interrupted by
8588 int count
= SPECPDL_INDEX ();
8589 specbind (Qredisplay_dont_pause
, Qt
);
8590 windows_or_buffers_changed
= 1;
8591 redisplay_internal (0);
8592 unbind_to (count
, Qnil
);
8594 else if (FRAME_WINDOW_P (f
) && n
== 0)
8596 /* Window configuration is the same as before.
8597 Can do with a display update of the echo area,
8598 unless we displayed some mode lines. */
8599 update_single_window (w
, 1);
8600 rif
->flush_display (f
);
8603 update_frame (f
, 1, 1);
8605 /* If cursor is in the echo area, make sure that the next
8606 redisplay displays the minibuffer, so that the cursor will
8607 be replaced with what the minibuffer wants. */
8608 if (cursor_in_echo_area
)
8609 ++windows_or_buffers_changed
;
8612 else if (!EQ (mini_window
, selected_window
))
8613 windows_or_buffers_changed
++;
8615 /* The current message is now also the last one displayed. */
8616 echo_area_buffer
[1] = echo_area_buffer
[0];
8618 /* Prevent redisplay optimization in redisplay_internal by resetting
8619 this_line_start_pos. This is done because the mini-buffer now
8620 displays the message instead of its buffer text. */
8621 if (EQ (mini_window
, selected_window
))
8622 CHARPOS (this_line_start_pos
) = 0;
8624 return window_height_changed_p
;
8629 /***********************************************************************
8630 Mode Lines and Frame Titles
8631 ***********************************************************************/
8633 /* A buffer for constructing non-propertized mode-line strings and
8634 frame titles in it; allocated from the heap in init_xdisp and
8635 resized as needed in store_mode_line_noprop_char. */
8637 static char *mode_line_noprop_buf
;
8639 /* The buffer's end, and a current output position in it. */
8641 static char *mode_line_noprop_buf_end
;
8642 static char *mode_line_noprop_ptr
;
8644 #define MODE_LINE_NOPROP_LEN(start) \
8645 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8648 MODE_LINE_DISPLAY
= 0,
8654 /* Alist that caches the results of :propertize.
8655 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8656 static Lisp_Object mode_line_proptrans_alist
;
8658 /* List of strings making up the mode-line. */
8659 static Lisp_Object mode_line_string_list
;
8661 /* Base face property when building propertized mode line string. */
8662 static Lisp_Object mode_line_string_face
;
8663 static Lisp_Object mode_line_string_face_prop
;
8666 /* Unwind data for mode line strings */
8668 static Lisp_Object Vmode_line_unwind_vector
;
8671 format_mode_line_unwind_data (obuf
, save_proptrans
)
8672 struct buffer
*obuf
;
8676 /* Reduce consing by keeping one vector in
8677 Vwith_echo_area_save_vector. */
8678 vector
= Vmode_line_unwind_vector
;
8679 Vmode_line_unwind_vector
= Qnil
;
8682 vector
= Fmake_vector (make_number (7), Qnil
);
8684 AREF (vector
, 0) = make_number (mode_line_target
);
8685 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8686 AREF (vector
, 2) = mode_line_string_list
;
8687 AREF (vector
, 3) = (save_proptrans
? mode_line_proptrans_alist
: Qt
);
8688 AREF (vector
, 4) = mode_line_string_face
;
8689 AREF (vector
, 5) = mode_line_string_face_prop
;
8692 XSETBUFFER (AREF (vector
, 6), obuf
);
8694 AREF (vector
, 6) = Qnil
;
8700 unwind_format_mode_line (vector
)
8703 mode_line_target
= XINT (AREF (vector
, 0));
8704 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8705 mode_line_string_list
= AREF (vector
, 2);
8706 if (! EQ (AREF (vector
, 3), Qt
))
8707 mode_line_proptrans_alist
= AREF (vector
, 3);
8708 mode_line_string_face
= AREF (vector
, 4);
8709 mode_line_string_face_prop
= AREF (vector
, 5);
8711 if (!NILP (AREF (vector
, 6)))
8713 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8714 AREF (vector
, 6) = Qnil
;
8717 Vmode_line_unwind_vector
= vector
;
8722 /* Store a single character C for the frame title in mode_line_noprop_buf.
8723 Re-allocate mode_line_noprop_buf if necessary. */
8727 store_mode_line_noprop_char (char c
)
8729 store_mode_line_noprop_char (c
)
8733 /* If output position has reached the end of the allocated buffer,
8734 double the buffer's size. */
8735 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8737 int len
= MODE_LINE_NOPROP_LEN (0);
8738 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8739 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8740 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8741 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8744 *mode_line_noprop_ptr
++ = c
;
8748 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8749 mode_line_noprop_ptr. STR is the string to store. Do not copy
8750 characters that yield more columns than PRECISION; PRECISION <= 0
8751 means copy the whole string. Pad with spaces until FIELD_WIDTH
8752 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8753 pad. Called from display_mode_element when it is used to build a
8757 store_mode_line_noprop (str
, field_width
, precision
)
8758 const unsigned char *str
;
8759 int field_width
, precision
;
8764 /* Copy at most PRECISION chars from STR. */
8765 nbytes
= strlen (str
);
8766 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8768 store_mode_line_noprop_char (*str
++);
8770 /* Fill up with spaces until FIELD_WIDTH reached. */
8771 while (field_width
> 0
8774 store_mode_line_noprop_char (' ');
8781 /***********************************************************************
8783 ***********************************************************************/
8785 #ifdef HAVE_WINDOW_SYSTEM
8787 /* Set the title of FRAME, if it has changed. The title format is
8788 Vicon_title_format if FRAME is iconified, otherwise it is
8789 frame_title_format. */
8792 x_consider_frame_title (frame
)
8795 struct frame
*f
= XFRAME (frame
);
8797 if (FRAME_WINDOW_P (f
)
8798 || FRAME_MINIBUF_ONLY_P (f
)
8799 || f
->explicit_name
)
8801 /* Do we have more than one visible frame on this X display? */
8808 int count
= SPECPDL_INDEX ();
8810 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8812 Lisp_Object other_frame
= XCAR (tail
);
8813 struct frame
*tf
= XFRAME (other_frame
);
8816 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8817 && !FRAME_MINIBUF_ONLY_P (tf
)
8818 && !EQ (other_frame
, tip_frame
)
8819 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8823 /* Set global variable indicating that multiple frames exist. */
8824 multiple_frames
= CONSP (tail
);
8826 /* Switch to the buffer of selected window of the frame. Set up
8827 mode_line_target so that display_mode_element will output into
8828 mode_line_noprop_buf; then display the title. */
8829 record_unwind_protect (unwind_format_mode_line
,
8830 format_mode_line_unwind_data (current_buffer
, 0));
8832 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8833 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8835 mode_line_target
= MODE_LINE_TITLE
;
8836 title_start
= MODE_LINE_NOPROP_LEN (0);
8837 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8838 NULL
, DEFAULT_FACE_ID
);
8839 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8840 len
= MODE_LINE_NOPROP_LEN (title_start
);
8841 title
= mode_line_noprop_buf
+ title_start
;
8842 unbind_to (count
, Qnil
);
8844 /* Set the title only if it's changed. This avoids consing in
8845 the common case where it hasn't. (If it turns out that we've
8846 already wasted too much time by walking through the list with
8847 display_mode_element, then we might need to optimize at a
8848 higher level than this.) */
8849 if (! STRINGP (f
->name
)
8850 || SBYTES (f
->name
) != len
8851 || bcmp (title
, SDATA (f
->name
), len
) != 0)
8852 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
8856 #endif /* not HAVE_WINDOW_SYSTEM */
8861 /***********************************************************************
8863 ***********************************************************************/
8866 /* Prepare for redisplay by updating menu-bar item lists when
8867 appropriate. This can call eval. */
8870 prepare_menu_bars ()
8873 struct gcpro gcpro1
, gcpro2
;
8875 Lisp_Object tooltip_frame
;
8877 #ifdef HAVE_WINDOW_SYSTEM
8878 tooltip_frame
= tip_frame
;
8880 tooltip_frame
= Qnil
;
8883 /* Update all frame titles based on their buffer names, etc. We do
8884 this before the menu bars so that the buffer-menu will show the
8885 up-to-date frame titles. */
8886 #ifdef HAVE_WINDOW_SYSTEM
8887 if (windows_or_buffers_changed
|| update_mode_lines
)
8889 Lisp_Object tail
, frame
;
8891 FOR_EACH_FRAME (tail
, frame
)
8894 if (!EQ (frame
, tooltip_frame
)
8895 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8896 x_consider_frame_title (frame
);
8899 #endif /* HAVE_WINDOW_SYSTEM */
8901 /* Update the menu bar item lists, if appropriate. This has to be
8902 done before any actual redisplay or generation of display lines. */
8903 all_windows
= (update_mode_lines
8904 || buffer_shared
> 1
8905 || windows_or_buffers_changed
);
8908 Lisp_Object tail
, frame
;
8909 int count
= SPECPDL_INDEX ();
8911 record_unwind_save_match_data ();
8913 FOR_EACH_FRAME (tail
, frame
)
8917 /* Ignore tooltip frame. */
8918 if (EQ (frame
, tooltip_frame
))
8921 /* If a window on this frame changed size, report that to
8922 the user and clear the size-change flag. */
8923 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8925 Lisp_Object functions
;
8927 /* Clear flag first in case we get an error below. */
8928 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8929 functions
= Vwindow_size_change_functions
;
8930 GCPRO2 (tail
, functions
);
8932 while (CONSP (functions
))
8934 call1 (XCAR (functions
), frame
);
8935 functions
= XCDR (functions
);
8941 update_menu_bar (f
, 0);
8942 #ifdef HAVE_WINDOW_SYSTEM
8943 update_tool_bar (f
, 0);
8948 unbind_to (count
, Qnil
);
8952 struct frame
*sf
= SELECTED_FRAME ();
8953 update_menu_bar (sf
, 1);
8954 #ifdef HAVE_WINDOW_SYSTEM
8955 update_tool_bar (sf
, 1);
8959 /* Motif needs this. See comment in xmenu.c. Turn it off when
8960 pending_menu_activation is not defined. */
8961 #ifdef USE_X_TOOLKIT
8962 pending_menu_activation
= 0;
8967 /* Update the menu bar item list for frame F. This has to be done
8968 before we start to fill in any display lines, because it can call
8971 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8974 update_menu_bar (f
, save_match_data
)
8976 int save_match_data
;
8979 register struct window
*w
;
8981 /* If called recursively during a menu update, do nothing. This can
8982 happen when, for instance, an activate-menubar-hook causes a
8984 if (inhibit_menubar_update
)
8987 window
= FRAME_SELECTED_WINDOW (f
);
8988 w
= XWINDOW (window
);
8990 #if 0 /* The if statement below this if statement used to include the
8991 condition !NILP (w->update_mode_line), rather than using
8992 update_mode_lines directly, and this if statement may have
8993 been added to make that condition work. Now the if
8994 statement below matches its comment, this isn't needed. */
8995 if (update_mode_lines
)
8996 w
->update_mode_line
= Qt
;
8999 if (FRAME_WINDOW_P (f
)
9001 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9002 || defined (USE_GTK)
9003 FRAME_EXTERNAL_MENU_BAR (f
)
9005 FRAME_MENU_BAR_LINES (f
) > 0
9007 : FRAME_MENU_BAR_LINES (f
) > 0)
9009 /* If the user has switched buffers or windows, we need to
9010 recompute to reflect the new bindings. But we'll
9011 recompute when update_mode_lines is set too; that means
9012 that people can use force-mode-line-update to request
9013 that the menu bar be recomputed. The adverse effect on
9014 the rest of the redisplay algorithm is about the same as
9015 windows_or_buffers_changed anyway. */
9016 if (windows_or_buffers_changed
9017 /* This used to test w->update_mode_line, but we believe
9018 there is no need to recompute the menu in that case. */
9019 || update_mode_lines
9020 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9021 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9022 != !NILP (w
->last_had_star
))
9023 || ((!NILP (Vtransient_mark_mode
)
9024 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9025 != !NILP (w
->region_showing
)))
9027 struct buffer
*prev
= current_buffer
;
9028 int count
= SPECPDL_INDEX ();
9030 specbind (Qinhibit_menubar_update
, Qt
);
9032 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9033 if (save_match_data
)
9034 record_unwind_save_match_data ();
9035 if (NILP (Voverriding_local_map_menu_flag
))
9037 specbind (Qoverriding_terminal_local_map
, Qnil
);
9038 specbind (Qoverriding_local_map
, Qnil
);
9041 /* Run the Lucid hook. */
9042 safe_run_hooks (Qactivate_menubar_hook
);
9044 /* If it has changed current-menubar from previous value,
9045 really recompute the menu-bar from the value. */
9046 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9047 call0 (Qrecompute_lucid_menubar
);
9049 safe_run_hooks (Qmenu_bar_update_hook
);
9050 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9052 /* Redisplay the menu bar in case we changed it. */
9053 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9054 || defined (USE_GTK)
9055 if (FRAME_WINDOW_P (f
)
9056 #if defined (MAC_OS)
9057 /* All frames on Mac OS share the same menubar. So only the
9058 selected frame should be allowed to set it. */
9059 && f
== SELECTED_FRAME ()
9062 set_frame_menubar (f
, 0, 0);
9064 /* On a terminal screen, the menu bar is an ordinary screen
9065 line, and this makes it get updated. */
9066 w
->update_mode_line
= Qt
;
9067 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9068 /* In the non-toolkit version, the menu bar is an ordinary screen
9069 line, and this makes it get updated. */
9070 w
->update_mode_line
= Qt
;
9071 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9073 unbind_to (count
, Qnil
);
9074 set_buffer_internal_1 (prev
);
9081 /***********************************************************************
9083 ***********************************************************************/
9085 #ifdef HAVE_WINDOW_SYSTEM
9088 Nominal cursor position -- where to draw output.
9089 HPOS and VPOS are window relative glyph matrix coordinates.
9090 X and Y are window relative pixel coordinates. */
9092 struct cursor_pos output_cursor
;
9096 Set the global variable output_cursor to CURSOR. All cursor
9097 positions are relative to updated_window. */
9100 set_output_cursor (cursor
)
9101 struct cursor_pos
*cursor
;
9103 output_cursor
.hpos
= cursor
->hpos
;
9104 output_cursor
.vpos
= cursor
->vpos
;
9105 output_cursor
.x
= cursor
->x
;
9106 output_cursor
.y
= cursor
->y
;
9111 Set a nominal cursor position.
9113 HPOS and VPOS are column/row positions in a window glyph matrix. X
9114 and Y are window text area relative pixel positions.
9116 If this is done during an update, updated_window will contain the
9117 window that is being updated and the position is the future output
9118 cursor position for that window. If updated_window is null, use
9119 selected_window and display the cursor at the given position. */
9122 x_cursor_to (vpos
, hpos
, y
, x
)
9123 int vpos
, hpos
, y
, x
;
9127 /* If updated_window is not set, work on selected_window. */
9131 w
= XWINDOW (selected_window
);
9133 /* Set the output cursor. */
9134 output_cursor
.hpos
= hpos
;
9135 output_cursor
.vpos
= vpos
;
9136 output_cursor
.x
= x
;
9137 output_cursor
.y
= y
;
9139 /* If not called as part of an update, really display the cursor.
9140 This will also set the cursor position of W. */
9141 if (updated_window
== NULL
)
9144 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9145 if (rif
->flush_display_optional
)
9146 rif
->flush_display_optional (SELECTED_FRAME ());
9151 #endif /* HAVE_WINDOW_SYSTEM */
9154 /***********************************************************************
9156 ***********************************************************************/
9158 #ifdef HAVE_WINDOW_SYSTEM
9160 /* Where the mouse was last time we reported a mouse event. */
9162 FRAME_PTR last_mouse_frame
;
9164 /* Tool-bar item index of the item on which a mouse button was pressed
9167 int last_tool_bar_item
;
9170 /* Update the tool-bar item list for frame F. This has to be done
9171 before we start to fill in any display lines. Called from
9172 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9173 and restore it here. */
9176 update_tool_bar (f
, save_match_data
)
9178 int save_match_data
;
9181 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9183 int do_update
= WINDOWP (f
->tool_bar_window
)
9184 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9192 window
= FRAME_SELECTED_WINDOW (f
);
9193 w
= XWINDOW (window
);
9195 /* If the user has switched buffers or windows, we need to
9196 recompute to reflect the new bindings. But we'll
9197 recompute when update_mode_lines is set too; that means
9198 that people can use force-mode-line-update to request
9199 that the menu bar be recomputed. The adverse effect on
9200 the rest of the redisplay algorithm is about the same as
9201 windows_or_buffers_changed anyway. */
9202 if (windows_or_buffers_changed
9203 || !NILP (w
->update_mode_line
)
9204 || update_mode_lines
9205 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9206 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9207 != !NILP (w
->last_had_star
))
9208 || ((!NILP (Vtransient_mark_mode
)
9209 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9210 != !NILP (w
->region_showing
)))
9212 struct buffer
*prev
= current_buffer
;
9213 int count
= SPECPDL_INDEX ();
9214 Lisp_Object new_tool_bar
;
9216 struct gcpro gcpro1
;
9218 /* Set current_buffer to the buffer of the selected
9219 window of the frame, so that we get the right local
9221 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9223 /* Save match data, if we must. */
9224 if (save_match_data
)
9225 record_unwind_save_match_data ();
9227 /* Make sure that we don't accidentally use bogus keymaps. */
9228 if (NILP (Voverriding_local_map_menu_flag
))
9230 specbind (Qoverriding_terminal_local_map
, Qnil
);
9231 specbind (Qoverriding_local_map
, Qnil
);
9234 GCPRO1 (new_tool_bar
);
9236 /* Build desired tool-bar items from keymaps. */
9237 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9240 /* Redisplay the tool-bar if we changed it. */
9241 if (NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9243 /* Redisplay that happens asynchronously due to an expose event
9244 may access f->tool_bar_items. Make sure we update both
9245 variables within BLOCK_INPUT so no such event interrupts. */
9247 f
->tool_bar_items
= new_tool_bar
;
9248 f
->n_tool_bar_items
= new_n_tool_bar
;
9249 w
->update_mode_line
= Qt
;
9255 unbind_to (count
, Qnil
);
9256 set_buffer_internal_1 (prev
);
9262 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9263 F's desired tool-bar contents. F->tool_bar_items must have
9264 been set up previously by calling prepare_menu_bars. */
9267 build_desired_tool_bar_string (f
)
9270 int i
, size
, size_needed
;
9271 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9272 Lisp_Object image
, plist
, props
;
9274 image
= plist
= props
= Qnil
;
9275 GCPRO3 (image
, plist
, props
);
9277 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9278 Otherwise, make a new string. */
9280 /* The size of the string we might be able to reuse. */
9281 size
= (STRINGP (f
->desired_tool_bar_string
)
9282 ? SCHARS (f
->desired_tool_bar_string
)
9285 /* We need one space in the string for each image. */
9286 size_needed
= f
->n_tool_bar_items
;
9288 /* Reuse f->desired_tool_bar_string, if possible. */
9289 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9290 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9294 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9295 Fremove_text_properties (make_number (0), make_number (size
),
9296 props
, f
->desired_tool_bar_string
);
9299 /* Put a `display' property on the string for the images to display,
9300 put a `menu_item' property on tool-bar items with a value that
9301 is the index of the item in F's tool-bar item vector. */
9302 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9304 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9306 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9307 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9308 int hmargin
, vmargin
, relief
, idx
, end
;
9309 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9311 /* If image is a vector, choose the image according to the
9313 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9314 if (VECTORP (image
))
9318 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9319 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9322 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9323 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9325 xassert (ASIZE (image
) >= idx
);
9326 image
= AREF (image
, idx
);
9331 /* Ignore invalid image specifications. */
9332 if (!valid_image_p (image
))
9335 /* Display the tool-bar button pressed, or depressed. */
9336 plist
= Fcopy_sequence (XCDR (image
));
9338 /* Compute margin and relief to draw. */
9339 relief
= (tool_bar_button_relief
>= 0
9340 ? tool_bar_button_relief
9341 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9342 hmargin
= vmargin
= relief
;
9344 if (INTEGERP (Vtool_bar_button_margin
)
9345 && XINT (Vtool_bar_button_margin
) > 0)
9347 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9348 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9350 else if (CONSP (Vtool_bar_button_margin
))
9352 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9353 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9354 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9356 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9357 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9358 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9361 if (auto_raise_tool_bar_buttons_p
)
9363 /* Add a `:relief' property to the image spec if the item is
9367 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9374 /* If image is selected, display it pressed, i.e. with a
9375 negative relief. If it's not selected, display it with a
9377 plist
= Fplist_put (plist
, QCrelief
,
9379 ? make_number (-relief
)
9380 : make_number (relief
)));
9385 /* Put a margin around the image. */
9386 if (hmargin
|| vmargin
)
9388 if (hmargin
== vmargin
)
9389 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9391 plist
= Fplist_put (plist
, QCmargin
,
9392 Fcons (make_number (hmargin
),
9393 make_number (vmargin
)));
9396 /* If button is not enabled, and we don't have special images
9397 for the disabled state, make the image appear disabled by
9398 applying an appropriate algorithm to it. */
9399 if (!enabled_p
&& idx
< 0)
9400 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9402 /* Put a `display' text property on the string for the image to
9403 display. Put a `menu-item' property on the string that gives
9404 the start of this item's properties in the tool-bar items
9406 image
= Fcons (Qimage
, plist
);
9407 props
= list4 (Qdisplay
, image
,
9408 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9410 /* Let the last image hide all remaining spaces in the tool bar
9411 string. The string can be longer than needed when we reuse a
9413 if (i
+ 1 == f
->n_tool_bar_items
)
9414 end
= SCHARS (f
->desired_tool_bar_string
);
9417 Fadd_text_properties (make_number (i
), make_number (end
),
9418 props
, f
->desired_tool_bar_string
);
9426 /* Display one line of the tool-bar of frame IT->f. */
9429 display_tool_bar_line (it
)
9432 struct glyph_row
*row
= it
->glyph_row
;
9433 int max_x
= it
->last_visible_x
;
9436 prepare_desired_row (row
);
9437 row
->y
= it
->current_y
;
9439 /* Note that this isn't made use of if the face hasn't a box,
9440 so there's no need to check the face here. */
9441 it
->start_of_box_run_p
= 1;
9443 while (it
->current_x
< max_x
)
9445 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
9447 /* Get the next display element. */
9448 if (!get_next_display_element (it
))
9451 /* Produce glyphs. */
9452 x_before
= it
->current_x
;
9453 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
9454 PRODUCE_GLYPHS (it
);
9456 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
9461 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9463 if (x
+ glyph
->pixel_width
> max_x
)
9465 /* Glyph doesn't fit on line. */
9466 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
9472 x
+= glyph
->pixel_width
;
9476 /* Stop at line ends. */
9477 if (ITERATOR_AT_END_OF_LINE_P (it
))
9480 set_iterator_to_next (it
, 1);
9485 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9486 extend_face_to_end_of_line (it
);
9487 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9488 last
->right_box_line_p
= 1;
9489 if (last
== row
->glyphs
[TEXT_AREA
])
9490 last
->left_box_line_p
= 1;
9491 compute_line_metrics (it
);
9493 /* If line is empty, make it occupy the rest of the tool-bar. */
9494 if (!row
->displays_text_p
)
9496 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9497 row
->ascent
= row
->phys_ascent
= 0;
9498 row
->extra_line_spacing
= 0;
9501 row
->full_width_p
= 1;
9502 row
->continued_p
= 0;
9503 row
->truncated_on_left_p
= 0;
9504 row
->truncated_on_right_p
= 0;
9506 it
->current_x
= it
->hpos
= 0;
9507 it
->current_y
+= row
->height
;
9513 /* Value is the number of screen lines needed to make all tool-bar
9514 items of frame F visible. */
9517 tool_bar_lines_needed (f
)
9520 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9523 /* Initialize an iterator for iteration over
9524 F->desired_tool_bar_string in the tool-bar window of frame F. */
9525 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9526 it
.first_visible_x
= 0;
9527 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9528 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9530 while (!ITERATOR_AT_END_P (&it
))
9532 it
.glyph_row
= w
->desired_matrix
->rows
;
9533 clear_glyph_row (it
.glyph_row
);
9534 display_tool_bar_line (&it
);
9537 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9541 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9543 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9552 frame
= selected_frame
;
9554 CHECK_FRAME (frame
);
9557 if (WINDOWP (f
->tool_bar_window
)
9558 || (w
= XWINDOW (f
->tool_bar_window
),
9559 WINDOW_TOTAL_LINES (w
) > 0))
9561 update_tool_bar (f
, 1);
9562 if (f
->n_tool_bar_items
)
9564 build_desired_tool_bar_string (f
);
9565 nlines
= tool_bar_lines_needed (f
);
9569 return make_number (nlines
);
9573 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9574 height should be changed. */
9577 redisplay_tool_bar (f
)
9582 struct glyph_row
*row
;
9583 int change_height_p
= 0;
9586 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9587 update_frame_tool_bar (f
);
9591 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9592 do anything. This means you must start with tool-bar-lines
9593 non-zero to get the auto-sizing effect. Or in other words, you
9594 can turn off tool-bars by specifying tool-bar-lines zero. */
9595 if (!WINDOWP (f
->tool_bar_window
)
9596 || (w
= XWINDOW (f
->tool_bar_window
),
9597 WINDOW_TOTAL_LINES (w
) == 0))
9600 /* Set up an iterator for the tool-bar window. */
9601 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9602 it
.first_visible_x
= 0;
9603 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9606 /* Build a string that represents the contents of the tool-bar. */
9607 build_desired_tool_bar_string (f
);
9608 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9610 /* Display as many lines as needed to display all tool-bar items. */
9611 while (it
.current_y
< it
.last_visible_y
)
9612 display_tool_bar_line (&it
);
9614 /* It doesn't make much sense to try scrolling in the tool-bar
9615 window, so don't do it. */
9616 w
->desired_matrix
->no_scrolling_p
= 1;
9617 w
->must_be_updated_p
= 1;
9619 if (auto_resize_tool_bars_p
)
9623 /* If we couldn't display everything, change the tool-bar's
9625 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
9626 change_height_p
= 1;
9628 /* If there are blank lines at the end, except for a partially
9629 visible blank line at the end that is smaller than
9630 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9631 row
= it
.glyph_row
- 1;
9632 if (!row
->displays_text_p
9633 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9634 change_height_p
= 1;
9636 /* If row displays tool-bar items, but is partially visible,
9637 change the tool-bar's height. */
9638 if (row
->displays_text_p
9639 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
9640 change_height_p
= 1;
9642 /* Resize windows as needed by changing the `tool-bar-lines'
9645 && (nlines
= tool_bar_lines_needed (f
),
9646 nlines
!= WINDOW_TOTAL_LINES (w
)))
9648 extern Lisp_Object Qtool_bar_lines
;
9650 int old_height
= WINDOW_TOTAL_LINES (w
);
9652 XSETFRAME (frame
, f
);
9653 clear_glyph_matrix (w
->desired_matrix
);
9654 Fmodify_frame_parameters (frame
,
9655 Fcons (Fcons (Qtool_bar_lines
,
9656 make_number (nlines
)),
9658 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9659 fonts_changed_p
= 1;
9663 return change_height_p
;
9667 /* Get information about the tool-bar item which is displayed in GLYPH
9668 on frame F. Return in *PROP_IDX the index where tool-bar item
9669 properties start in F->tool_bar_items. Value is zero if
9670 GLYPH doesn't display a tool-bar item. */
9673 tool_bar_item_info (f
, glyph
, prop_idx
)
9675 struct glyph
*glyph
;
9682 /* This function can be called asynchronously, which means we must
9683 exclude any possibility that Fget_text_property signals an
9685 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
9686 charpos
= max (0, charpos
);
9688 /* Get the text property `menu-item' at pos. The value of that
9689 property is the start index of this item's properties in
9690 F->tool_bar_items. */
9691 prop
= Fget_text_property (make_number (charpos
),
9692 Qmenu_item
, f
->current_tool_bar_string
);
9693 if (INTEGERP (prop
))
9695 *prop_idx
= XINT (prop
);
9705 /* Get information about the tool-bar item at position X/Y on frame F.
9706 Return in *GLYPH a pointer to the glyph of the tool-bar item in
9707 the current matrix of the tool-bar window of F, or NULL if not
9708 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
9709 item in F->tool_bar_items. Value is
9711 -1 if X/Y is not on a tool-bar item
9712 0 if X/Y is on the same item that was highlighted before.
9716 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
9719 struct glyph
**glyph
;
9720 int *hpos
, *vpos
, *prop_idx
;
9722 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9723 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9726 /* Find the glyph under X/Y. */
9727 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
9731 /* Get the start of this tool-bar item's properties in
9732 f->tool_bar_items. */
9733 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
9736 /* Is mouse on the highlighted item? */
9737 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
9738 && *vpos
>= dpyinfo
->mouse_face_beg_row
9739 && *vpos
<= dpyinfo
->mouse_face_end_row
9740 && (*vpos
> dpyinfo
->mouse_face_beg_row
9741 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
9742 && (*vpos
< dpyinfo
->mouse_face_end_row
9743 || *hpos
< dpyinfo
->mouse_face_end_col
9744 || dpyinfo
->mouse_face_past_end
))
9752 Handle mouse button event on the tool-bar of frame F, at
9753 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
9754 0 for button release. MODIFIERS is event modifiers for button
9758 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
9761 unsigned int modifiers
;
9763 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9764 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9765 int hpos
, vpos
, prop_idx
;
9766 struct glyph
*glyph
;
9767 Lisp_Object enabled_p
;
9769 /* If not on the highlighted tool-bar item, return. */
9770 frame_to_window_pixel_xy (w
, &x
, &y
);
9771 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
9774 /* If item is disabled, do nothing. */
9775 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9776 if (NILP (enabled_p
))
9781 /* Show item in pressed state. */
9782 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
9783 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
9784 last_tool_bar_item
= prop_idx
;
9788 Lisp_Object key
, frame
;
9789 struct input_event event
;
9792 /* Show item in released state. */
9793 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
9794 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
9796 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
9798 XSETFRAME (frame
, f
);
9799 event
.kind
= TOOL_BAR_EVENT
;
9800 event
.frame_or_window
= frame
;
9802 kbd_buffer_store_event (&event
);
9804 event
.kind
= TOOL_BAR_EVENT
;
9805 event
.frame_or_window
= frame
;
9807 event
.modifiers
= modifiers
;
9808 kbd_buffer_store_event (&event
);
9809 last_tool_bar_item
= -1;
9814 /* Possibly highlight a tool-bar item on frame F when mouse moves to
9815 tool-bar window-relative coordinates X/Y. Called from
9816 note_mouse_highlight. */
9819 note_tool_bar_highlight (f
, x
, y
)
9823 Lisp_Object window
= f
->tool_bar_window
;
9824 struct window
*w
= XWINDOW (window
);
9825 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9827 struct glyph
*glyph
;
9828 struct glyph_row
*row
;
9830 Lisp_Object enabled_p
;
9832 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9833 int mouse_down_p
, rc
;
9835 /* Function note_mouse_highlight is called with negative x(y
9836 values when mouse moves outside of the frame. */
9837 if (x
<= 0 || y
<= 0)
9839 clear_mouse_face (dpyinfo
);
9843 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9846 /* Not on tool-bar item. */
9847 clear_mouse_face (dpyinfo
);
9851 /* On same tool-bar item as before. */
9854 clear_mouse_face (dpyinfo
);
9856 /* Mouse is down, but on different tool-bar item? */
9857 mouse_down_p
= (dpyinfo
->grabbed
9858 && f
== last_mouse_frame
9859 && FRAME_LIVE_P (f
));
9861 && last_tool_bar_item
!= prop_idx
)
9864 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9865 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9867 /* If tool-bar item is not enabled, don't highlight it. */
9868 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9869 if (!NILP (enabled_p
))
9871 /* Compute the x-position of the glyph. In front and past the
9872 image is a space. We include this in the highlighted area. */
9873 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
9874 for (i
= x
= 0; i
< hpos
; ++i
)
9875 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9877 /* Record this as the current active region. */
9878 dpyinfo
->mouse_face_beg_col
= hpos
;
9879 dpyinfo
->mouse_face_beg_row
= vpos
;
9880 dpyinfo
->mouse_face_beg_x
= x
;
9881 dpyinfo
->mouse_face_beg_y
= row
->y
;
9882 dpyinfo
->mouse_face_past_end
= 0;
9884 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9885 dpyinfo
->mouse_face_end_row
= vpos
;
9886 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9887 dpyinfo
->mouse_face_end_y
= row
->y
;
9888 dpyinfo
->mouse_face_window
= window
;
9889 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9891 /* Display it as active. */
9892 show_mouse_face (dpyinfo
, draw
);
9893 dpyinfo
->mouse_face_image_state
= draw
;
9898 /* Set help_echo_string to a help string to display for this tool-bar item.
9899 XTread_socket does the rest. */
9900 help_echo_object
= help_echo_window
= Qnil
;
9902 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9903 if (NILP (help_echo_string
))
9904 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9907 #endif /* HAVE_WINDOW_SYSTEM */
9911 /************************************************************************
9912 Horizontal scrolling
9913 ************************************************************************/
9915 static int hscroll_window_tree
P_ ((Lisp_Object
));
9916 static int hscroll_windows
P_ ((Lisp_Object
));
9918 /* For all leaf windows in the window tree rooted at WINDOW, set their
9919 hscroll value so that PT is (i) visible in the window, and (ii) so
9920 that it is not within a certain margin at the window's left and
9921 right border. Value is non-zero if any window's hscroll has been
9925 hscroll_window_tree (window
)
9928 int hscrolled_p
= 0;
9929 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9930 int hscroll_step_abs
= 0;
9931 double hscroll_step_rel
= 0;
9933 if (hscroll_relative_p
)
9935 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9936 if (hscroll_step_rel
< 0)
9938 hscroll_relative_p
= 0;
9939 hscroll_step_abs
= 0;
9942 else if (INTEGERP (Vhscroll_step
))
9944 hscroll_step_abs
= XINT (Vhscroll_step
);
9945 if (hscroll_step_abs
< 0)
9946 hscroll_step_abs
= 0;
9949 hscroll_step_abs
= 0;
9951 while (WINDOWP (window
))
9953 struct window
*w
= XWINDOW (window
);
9955 if (WINDOWP (w
->hchild
))
9956 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9957 else if (WINDOWP (w
->vchild
))
9958 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9959 else if (w
->cursor
.vpos
>= 0)
9962 int text_area_width
;
9963 struct glyph_row
*current_cursor_row
9964 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9965 struct glyph_row
*desired_cursor_row
9966 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9967 struct glyph_row
*cursor_row
9968 = (desired_cursor_row
->enabled_p
9969 ? desired_cursor_row
9970 : current_cursor_row
);
9972 text_area_width
= window_box_width (w
, TEXT_AREA
);
9974 /* Scroll when cursor is inside this scroll margin. */
9975 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9977 if ((XFASTINT (w
->hscroll
)
9978 && w
->cursor
.x
<= h_margin
)
9979 || (cursor_row
->enabled_p
9980 && cursor_row
->truncated_on_right_p
9981 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9985 struct buffer
*saved_current_buffer
;
9989 /* Find point in a display of infinite width. */
9990 saved_current_buffer
= current_buffer
;
9991 current_buffer
= XBUFFER (w
->buffer
);
9993 if (w
== XWINDOW (selected_window
))
9994 pt
= BUF_PT (current_buffer
);
9997 pt
= marker_position (w
->pointm
);
9998 pt
= max (BEGV
, pt
);
10002 /* Move iterator to pt starting at cursor_row->start in
10003 a line with infinite width. */
10004 init_to_row_start (&it
, w
, cursor_row
);
10005 it
.last_visible_x
= INFINITY
;
10006 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10007 current_buffer
= saved_current_buffer
;
10009 /* Position cursor in window. */
10010 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10011 hscroll
= max (0, (it
.current_x
10012 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10013 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10014 : (text_area_width
/ 2))))
10015 / FRAME_COLUMN_WIDTH (it
.f
);
10016 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10018 if (hscroll_relative_p
)
10019 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10022 wanted_x
= text_area_width
10023 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10026 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10030 if (hscroll_relative_p
)
10031 wanted_x
= text_area_width
* hscroll_step_rel
10034 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10037 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10039 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10041 /* Don't call Fset_window_hscroll if value hasn't
10042 changed because it will prevent redisplay
10044 if (XFASTINT (w
->hscroll
) != hscroll
)
10046 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10047 w
->hscroll
= make_number (hscroll
);
10056 /* Value is non-zero if hscroll of any leaf window has been changed. */
10057 return hscrolled_p
;
10061 /* Set hscroll so that cursor is visible and not inside horizontal
10062 scroll margins for all windows in the tree rooted at WINDOW. See
10063 also hscroll_window_tree above. Value is non-zero if any window's
10064 hscroll has been changed. If it has, desired matrices on the frame
10065 of WINDOW are cleared. */
10068 hscroll_windows (window
)
10069 Lisp_Object window
;
10073 if (automatic_hscrolling_p
)
10075 hscrolled_p
= hscroll_window_tree (window
);
10077 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10081 return hscrolled_p
;
10086 /************************************************************************
10088 ************************************************************************/
10090 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10091 to a non-zero value. This is sometimes handy to have in a debugger
10096 /* First and last unchanged row for try_window_id. */
10098 int debug_first_unchanged_at_end_vpos
;
10099 int debug_last_unchanged_at_beg_vpos
;
10101 /* Delta vpos and y. */
10103 int debug_dvpos
, debug_dy
;
10105 /* Delta in characters and bytes for try_window_id. */
10107 int debug_delta
, debug_delta_bytes
;
10109 /* Values of window_end_pos and window_end_vpos at the end of
10112 EMACS_INT debug_end_pos
, debug_end_vpos
;
10114 /* Append a string to W->desired_matrix->method. FMT is a printf
10115 format string. A1...A9 are a supplement for a variable-length
10116 argument list. If trace_redisplay_p is non-zero also printf the
10117 resulting string to stderr. */
10120 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10123 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10126 char *method
= w
->desired_matrix
->method
;
10127 int len
= strlen (method
);
10128 int size
= sizeof w
->desired_matrix
->method
;
10129 int remaining
= size
- len
- 1;
10131 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10132 if (len
&& remaining
)
10135 --remaining
, ++len
;
10138 strncpy (method
+ len
, buffer
, remaining
);
10140 if (trace_redisplay_p
)
10141 fprintf (stderr
, "%p (%s): %s\n",
10143 ((BUFFERP (w
->buffer
)
10144 && STRINGP (XBUFFER (w
->buffer
)->name
))
10145 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10150 #endif /* GLYPH_DEBUG */
10153 /* Value is non-zero if all changes in window W, which displays
10154 current_buffer, are in the text between START and END. START is a
10155 buffer position, END is given as a distance from Z. Used in
10156 redisplay_internal for display optimization. */
10159 text_outside_line_unchanged_p (w
, start
, end
)
10163 int unchanged_p
= 1;
10165 /* If text or overlays have changed, see where. */
10166 if (XFASTINT (w
->last_modified
) < MODIFF
10167 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10169 /* Gap in the line? */
10170 if (GPT
< start
|| Z
- GPT
< end
)
10173 /* Changes start in front of the line, or end after it? */
10175 && (BEG_UNCHANGED
< start
- 1
10176 || END_UNCHANGED
< end
))
10179 /* If selective display, can't optimize if changes start at the
10180 beginning of the line. */
10182 && INTEGERP (current_buffer
->selective_display
)
10183 && XINT (current_buffer
->selective_display
) > 0
10184 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10187 /* If there are overlays at the start or end of the line, these
10188 may have overlay strings with newlines in them. A change at
10189 START, for instance, may actually concern the display of such
10190 overlay strings as well, and they are displayed on different
10191 lines. So, quickly rule out this case. (For the future, it
10192 might be desirable to implement something more telling than
10193 just BEG/END_UNCHANGED.) */
10196 if (BEG
+ BEG_UNCHANGED
== start
10197 && overlay_touches_p (start
))
10199 if (END_UNCHANGED
== end
10200 && overlay_touches_p (Z
- end
))
10205 return unchanged_p
;
10209 /* Do a frame update, taking possible shortcuts into account. This is
10210 the main external entry point for redisplay.
10212 If the last redisplay displayed an echo area message and that message
10213 is no longer requested, we clear the echo area or bring back the
10214 mini-buffer if that is in use. */
10219 redisplay_internal (0);
10224 overlay_arrow_string_or_property (var
)
10229 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10232 return Voverlay_arrow_string
;
10235 /* Return 1 if there are any overlay-arrows in current_buffer. */
10237 overlay_arrow_in_current_buffer_p ()
10241 for (vlist
= Voverlay_arrow_variable_list
;
10243 vlist
= XCDR (vlist
))
10245 Lisp_Object var
= XCAR (vlist
);
10248 if (!SYMBOLP (var
))
10250 val
= find_symbol_value (var
);
10252 && current_buffer
== XMARKER (val
)->buffer
)
10259 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
10263 overlay_arrows_changed_p ()
10267 for (vlist
= Voverlay_arrow_variable_list
;
10269 vlist
= XCDR (vlist
))
10271 Lisp_Object var
= XCAR (vlist
);
10272 Lisp_Object val
, pstr
;
10274 if (!SYMBOLP (var
))
10276 val
= find_symbol_value (var
);
10277 if (!MARKERP (val
))
10279 if (! EQ (COERCE_MARKER (val
),
10280 Fget (var
, Qlast_arrow_position
))
10281 || ! (pstr
= overlay_arrow_string_or_property (var
),
10282 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
10288 /* Mark overlay arrows to be updated on next redisplay. */
10291 update_overlay_arrows (up_to_date
)
10296 for (vlist
= Voverlay_arrow_variable_list
;
10298 vlist
= XCDR (vlist
))
10300 Lisp_Object var
= XCAR (vlist
);
10302 if (!SYMBOLP (var
))
10305 if (up_to_date
> 0)
10307 Lisp_Object val
= find_symbol_value (var
);
10308 Fput (var
, Qlast_arrow_position
,
10309 COERCE_MARKER (val
));
10310 Fput (var
, Qlast_arrow_string
,
10311 overlay_arrow_string_or_property (var
));
10313 else if (up_to_date
< 0
10314 || !NILP (Fget (var
, Qlast_arrow_position
)))
10316 Fput (var
, Qlast_arrow_position
, Qt
);
10317 Fput (var
, Qlast_arrow_string
, Qt
);
10323 /* Return overlay arrow string to display at row.
10324 Return integer (bitmap number) for arrow bitmap in left fringe.
10325 Return nil if no overlay arrow. */
10328 overlay_arrow_at_row (it
, row
)
10330 struct glyph_row
*row
;
10334 for (vlist
= Voverlay_arrow_variable_list
;
10336 vlist
= XCDR (vlist
))
10338 Lisp_Object var
= XCAR (vlist
);
10341 if (!SYMBOLP (var
))
10344 val
= find_symbol_value (var
);
10347 && current_buffer
== XMARKER (val
)->buffer
10348 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10350 if (FRAME_WINDOW_P (it
->f
)
10351 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10353 #ifdef HAVE_WINDOW_SYSTEM
10354 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10357 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10358 return make_number (fringe_bitmap
);
10361 return make_number (-1); /* Use default arrow bitmap */
10363 return overlay_arrow_string_or_property (var
);
10370 /* Return 1 if point moved out of or into a composition. Otherwise
10371 return 0. PREV_BUF and PREV_PT are the last point buffer and
10372 position. BUF and PT are the current point buffer and position. */
10375 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10376 struct buffer
*prev_buf
, *buf
;
10381 Lisp_Object buffer
;
10383 XSETBUFFER (buffer
, buf
);
10384 /* Check a composition at the last point if point moved within the
10386 if (prev_buf
== buf
)
10389 /* Point didn't move. */
10392 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10393 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10394 && COMPOSITION_VALID_P (start
, end
, prop
)
10395 && start
< prev_pt
&& end
> prev_pt
)
10396 /* The last point was within the composition. Return 1 iff
10397 point moved out of the composition. */
10398 return (pt
<= start
|| pt
>= end
);
10401 /* Check a composition at the current point. */
10402 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10403 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10404 && COMPOSITION_VALID_P (start
, end
, prop
)
10405 && start
< pt
&& end
> pt
);
10409 /* Reconsider the setting of B->clip_changed which is displayed
10413 reconsider_clip_changes (w
, b
)
10417 if (b
->clip_changed
10418 && !NILP (w
->window_end_valid
)
10419 && w
->current_matrix
->buffer
== b
10420 && w
->current_matrix
->zv
== BUF_ZV (b
)
10421 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10422 b
->clip_changed
= 0;
10424 /* If display wasn't paused, and W is not a tool bar window, see if
10425 point has been moved into or out of a composition. In that case,
10426 we set b->clip_changed to 1 to force updating the screen. If
10427 b->clip_changed has already been set to 1, we can skip this
10429 if (!b
->clip_changed
10430 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10434 if (w
== XWINDOW (selected_window
))
10435 pt
= BUF_PT (current_buffer
);
10437 pt
= marker_position (w
->pointm
);
10439 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10440 || pt
!= XINT (w
->last_point
))
10441 && check_point_in_composition (w
->current_matrix
->buffer
,
10442 XINT (w
->last_point
),
10443 XBUFFER (w
->buffer
), pt
))
10444 b
->clip_changed
= 1;
10449 /* Select FRAME to forward the values of frame-local variables into C
10450 variables so that the redisplay routines can access those values
10454 select_frame_for_redisplay (frame
)
10457 Lisp_Object tail
, sym
, val
;
10458 Lisp_Object old
= selected_frame
;
10460 selected_frame
= frame
;
10462 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10463 if (CONSP (XCAR (tail
))
10464 && (sym
= XCAR (XCAR (tail
)),
10466 && (sym
= indirect_variable (sym
),
10467 val
= SYMBOL_VALUE (sym
),
10468 (BUFFER_LOCAL_VALUEP (val
)
10469 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10470 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10471 /* Use find_symbol_value rather than Fsymbol_value
10472 to avoid an error if it is void. */
10473 find_symbol_value (sym
);
10475 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10476 if (CONSP (XCAR (tail
))
10477 && (sym
= XCAR (XCAR (tail
)),
10479 && (sym
= indirect_variable (sym
),
10480 val
= SYMBOL_VALUE (sym
),
10481 (BUFFER_LOCAL_VALUEP (val
)
10482 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10483 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10484 find_symbol_value (sym
);
10488 #define STOP_POLLING \
10489 do { if (! polling_stopped_here) stop_polling (); \
10490 polling_stopped_here = 1; } while (0)
10492 #define RESUME_POLLING \
10493 do { if (polling_stopped_here) start_polling (); \
10494 polling_stopped_here = 0; } while (0)
10497 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10498 response to any user action; therefore, we should preserve the echo
10499 area. (Actually, our caller does that job.) Perhaps in the future
10500 avoid recentering windows if it is not necessary; currently that
10501 causes some problems. */
10504 redisplay_internal (preserve_echo_area
)
10505 int preserve_echo_area
;
10507 struct window
*w
= XWINDOW (selected_window
);
10508 struct frame
*f
= XFRAME (w
->frame
);
10510 int must_finish
= 0;
10511 struct text_pos tlbufpos
, tlendpos
;
10512 int number_of_visible_frames
;
10514 struct frame
*sf
= SELECTED_FRAME ();
10515 int polling_stopped_here
= 0;
10517 /* Non-zero means redisplay has to consider all windows on all
10518 frames. Zero means, only selected_window is considered. */
10519 int consider_all_windows_p
;
10521 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10523 /* No redisplay if running in batch mode or frame is not yet fully
10524 initialized, or redisplay is explicitly turned off by setting
10525 Vinhibit_redisplay. */
10527 || !NILP (Vinhibit_redisplay
)
10528 || !f
->glyphs_initialized_p
)
10531 /* The flag redisplay_performed_directly_p is set by
10532 direct_output_for_insert when it already did the whole screen
10533 update necessary. */
10534 if (redisplay_performed_directly_p
)
10536 redisplay_performed_directly_p
= 0;
10537 if (!hscroll_windows (selected_window
))
10541 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
10542 if (popup_activated ())
10546 /* I don't think this happens but let's be paranoid. */
10547 if (redisplaying_p
)
10550 /* Record a function that resets redisplaying_p to its old value
10551 when we leave this function. */
10552 count
= SPECPDL_INDEX ();
10553 record_unwind_protect (unwind_redisplay
,
10554 Fcons (make_number (redisplaying_p
), selected_frame
));
10556 specbind (Qinhibit_free_realized_faces
, Qnil
);
10559 Lisp_Object tail
, frame
;
10561 FOR_EACH_FRAME (tail
, frame
)
10563 struct frame
*f
= XFRAME (frame
);
10564 f
->already_hscrolled_p
= 0;
10570 reconsider_clip_changes (w
, current_buffer
);
10571 last_escape_glyph_frame
= NULL
;
10572 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
10574 /* If new fonts have been loaded that make a glyph matrix adjustment
10575 necessary, do it. */
10576 if (fonts_changed_p
)
10578 adjust_glyphs (NULL
);
10579 ++windows_or_buffers_changed
;
10580 fonts_changed_p
= 0;
10583 /* If face_change_count is non-zero, init_iterator will free all
10584 realized faces, which includes the faces referenced from current
10585 matrices. So, we can't reuse current matrices in this case. */
10586 if (face_change_count
)
10587 ++windows_or_buffers_changed
;
10589 if (! FRAME_WINDOW_P (sf
)
10590 && previous_terminal_frame
!= sf
)
10592 /* Since frames on an ASCII terminal share the same display
10593 area, displaying a different frame means redisplay the whole
10595 windows_or_buffers_changed
++;
10596 SET_FRAME_GARBAGED (sf
);
10597 XSETFRAME (Vterminal_frame
, sf
);
10599 previous_terminal_frame
= sf
;
10601 /* Set the visible flags for all frames. Do this before checking
10602 for resized or garbaged frames; they want to know if their frames
10603 are visible. See the comment in frame.h for
10604 FRAME_SAMPLE_VISIBILITY. */
10606 Lisp_Object tail
, frame
;
10608 number_of_visible_frames
= 0;
10610 FOR_EACH_FRAME (tail
, frame
)
10612 struct frame
*f
= XFRAME (frame
);
10614 FRAME_SAMPLE_VISIBILITY (f
);
10615 if (FRAME_VISIBLE_P (f
))
10616 ++number_of_visible_frames
;
10617 clear_desired_matrices (f
);
10621 /* Notice any pending interrupt request to change frame size. */
10622 do_pending_window_change (1);
10624 /* Clear frames marked as garbaged. */
10625 if (frame_garbaged
)
10626 clear_garbaged_frames ();
10628 /* Build menubar and tool-bar items. */
10629 if (NILP (Vmemory_full
))
10630 prepare_menu_bars ();
10632 if (windows_or_buffers_changed
)
10633 update_mode_lines
++;
10635 /* Detect case that we need to write or remove a star in the mode line. */
10636 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10638 w
->update_mode_line
= Qt
;
10639 if (buffer_shared
> 1)
10640 update_mode_lines
++;
10643 /* If %c is in the mode line, update it if needed. */
10644 if (!NILP (w
->column_number_displayed
)
10645 /* This alternative quickly identifies a common case
10646 where no change is needed. */
10647 && !(PT
== XFASTINT (w
->last_point
)
10648 && XFASTINT (w
->last_modified
) >= MODIFF
10649 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10650 && (XFASTINT (w
->column_number_displayed
)
10651 != (int) current_column ())) /* iftc */
10652 w
->update_mode_line
= Qt
;
10654 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10656 /* The variable buffer_shared is set in redisplay_window and
10657 indicates that we redisplay a buffer in different windows. See
10659 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
10660 || cursor_type_changed
);
10662 /* If specs for an arrow have changed, do thorough redisplay
10663 to ensure we remove any arrow that should no longer exist. */
10664 if (overlay_arrows_changed_p ())
10665 consider_all_windows_p
= windows_or_buffers_changed
= 1;
10667 /* Normally the message* functions will have already displayed and
10668 updated the echo area, but the frame may have been trashed, or
10669 the update may have been preempted, so display the echo area
10670 again here. Checking message_cleared_p captures the case that
10671 the echo area should be cleared. */
10672 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
10673 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
10674 || (message_cleared_p
10675 && minibuf_level
== 0
10676 /* If the mini-window is currently selected, this means the
10677 echo-area doesn't show through. */
10678 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
10680 int window_height_changed_p
= echo_area_display (0);
10683 /* If we don't display the current message, don't clear the
10684 message_cleared_p flag, because, if we did, we wouldn't clear
10685 the echo area in the next redisplay which doesn't preserve
10687 if (!display_last_displayed_message_p
)
10688 message_cleared_p
= 0;
10690 if (fonts_changed_p
)
10692 else if (window_height_changed_p
)
10694 consider_all_windows_p
= 1;
10695 ++update_mode_lines
;
10696 ++windows_or_buffers_changed
;
10698 /* If window configuration was changed, frames may have been
10699 marked garbaged. Clear them or we will experience
10700 surprises wrt scrolling. */
10701 if (frame_garbaged
)
10702 clear_garbaged_frames ();
10705 else if (EQ (selected_window
, minibuf_window
)
10706 && (current_buffer
->clip_changed
10707 || XFASTINT (w
->last_modified
) < MODIFF
10708 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10709 && resize_mini_window (w
, 0))
10711 /* Resized active mini-window to fit the size of what it is
10712 showing if its contents might have changed. */
10714 consider_all_windows_p
= 1;
10715 ++windows_or_buffers_changed
;
10716 ++update_mode_lines
;
10718 /* If window configuration was changed, frames may have been
10719 marked garbaged. Clear them or we will experience
10720 surprises wrt scrolling. */
10721 if (frame_garbaged
)
10722 clear_garbaged_frames ();
10726 /* If showing the region, and mark has changed, we must redisplay
10727 the whole window. The assignment to this_line_start_pos prevents
10728 the optimization directly below this if-statement. */
10729 if (((!NILP (Vtransient_mark_mode
)
10730 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10731 != !NILP (w
->region_showing
))
10732 || (!NILP (w
->region_showing
)
10733 && !EQ (w
->region_showing
,
10734 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
10735 CHARPOS (this_line_start_pos
) = 0;
10737 /* Optimize the case that only the line containing the cursor in the
10738 selected window has changed. Variables starting with this_ are
10739 set in display_line and record information about the line
10740 containing the cursor. */
10741 tlbufpos
= this_line_start_pos
;
10742 tlendpos
= this_line_end_pos
;
10743 if (!consider_all_windows_p
10744 && CHARPOS (tlbufpos
) > 0
10745 && NILP (w
->update_mode_line
)
10746 && !current_buffer
->clip_changed
10747 && !current_buffer
->prevent_redisplay_optimizations_p
10748 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
10749 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
10750 /* Make sure recorded data applies to current buffer, etc. */
10751 && this_line_buffer
== current_buffer
10752 && current_buffer
== XBUFFER (w
->buffer
)
10753 && NILP (w
->force_start
)
10754 && NILP (w
->optional_new_start
)
10755 /* Point must be on the line that we have info recorded about. */
10756 && PT
>= CHARPOS (tlbufpos
)
10757 && PT
<= Z
- CHARPOS (tlendpos
)
10758 /* All text outside that line, including its final newline,
10759 must be unchanged */
10760 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
10761 CHARPOS (tlendpos
)))
10763 if (CHARPOS (tlbufpos
) > BEGV
10764 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
10765 && (CHARPOS (tlbufpos
) == ZV
10766 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
10767 /* Former continuation line has disappeared by becoming empty */
10769 else if (XFASTINT (w
->last_modified
) < MODIFF
10770 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
10771 || MINI_WINDOW_P (w
))
10773 /* We have to handle the case of continuation around a
10774 wide-column character (See the comment in indent.c around
10777 For instance, in the following case:
10779 -------- Insert --------
10780 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
10781 J_I_ ==> J_I_ `^^' are cursors.
10785 As we have to redraw the line above, we should goto cancel. */
10788 int line_height_before
= this_line_pixel_height
;
10790 /* Note that start_display will handle the case that the
10791 line starting at tlbufpos is a continuation lines. */
10792 start_display (&it
, w
, tlbufpos
);
10794 /* Implementation note: It this still necessary? */
10795 if (it
.current_x
!= this_line_start_x
)
10798 TRACE ((stderr
, "trying display optimization 1\n"));
10799 w
->cursor
.vpos
= -1;
10800 overlay_arrow_seen
= 0;
10801 it
.vpos
= this_line_vpos
;
10802 it
.current_y
= this_line_y
;
10803 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
10804 display_line (&it
);
10806 /* If line contains point, is not continued,
10807 and ends at same distance from eob as before, we win */
10808 if (w
->cursor
.vpos
>= 0
10809 /* Line is not continued, otherwise this_line_start_pos
10810 would have been set to 0 in display_line. */
10811 && CHARPOS (this_line_start_pos
)
10812 /* Line ends as before. */
10813 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
10814 /* Line has same height as before. Otherwise other lines
10815 would have to be shifted up or down. */
10816 && this_line_pixel_height
== line_height_before
)
10818 /* If this is not the window's last line, we must adjust
10819 the charstarts of the lines below. */
10820 if (it
.current_y
< it
.last_visible_y
)
10822 struct glyph_row
*row
10823 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
10824 int delta
, delta_bytes
;
10826 if (Z
- CHARPOS (tlendpos
) == ZV
)
10828 /* This line ends at end of (accessible part of)
10829 buffer. There is no newline to count. */
10831 - CHARPOS (tlendpos
)
10832 - MATRIX_ROW_START_CHARPOS (row
));
10833 delta_bytes
= (Z_BYTE
10834 - BYTEPOS (tlendpos
)
10835 - MATRIX_ROW_START_BYTEPOS (row
));
10839 /* This line ends in a newline. Must take
10840 account of the newline and the rest of the
10841 text that follows. */
10843 - CHARPOS (tlendpos
)
10844 - MATRIX_ROW_START_CHARPOS (row
));
10845 delta_bytes
= (Z_BYTE
10846 - BYTEPOS (tlendpos
)
10847 - MATRIX_ROW_START_BYTEPOS (row
));
10850 increment_matrix_positions (w
->current_matrix
,
10851 this_line_vpos
+ 1,
10852 w
->current_matrix
->nrows
,
10853 delta
, delta_bytes
);
10856 /* If this row displays text now but previously didn't,
10857 or vice versa, w->window_end_vpos may have to be
10859 if ((it
.glyph_row
- 1)->displays_text_p
)
10861 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10862 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10864 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10865 && this_line_vpos
> 0)
10866 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10867 w
->window_end_valid
= Qnil
;
10869 /* Update hint: No need to try to scroll in update_window. */
10870 w
->desired_matrix
->no_scrolling_p
= 1;
10873 *w
->desired_matrix
->method
= 0;
10874 debug_method_add (w
, "optimization 1");
10876 #ifdef HAVE_WINDOW_SYSTEM
10877 update_window_fringes (w
, 0);
10884 else if (/* Cursor position hasn't changed. */
10885 PT
== XFASTINT (w
->last_point
)
10886 /* Make sure the cursor was last displayed
10887 in this window. Otherwise we have to reposition it. */
10888 && 0 <= w
->cursor
.vpos
10889 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
10893 do_pending_window_change (1);
10895 /* We used to always goto end_of_redisplay here, but this
10896 isn't enough if we have a blinking cursor. */
10897 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10898 goto end_of_redisplay
;
10902 /* If highlighting the region, or if the cursor is in the echo area,
10903 then we can't just move the cursor. */
10904 else if (! (!NILP (Vtransient_mark_mode
)
10905 && !NILP (current_buffer
->mark_active
))
10906 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10907 || highlight_nonselected_windows
)
10908 && NILP (w
->region_showing
)
10909 && NILP (Vshow_trailing_whitespace
)
10910 && !cursor_in_echo_area
)
10913 struct glyph_row
*row
;
10915 /* Skip from tlbufpos to PT and see where it is. Note that
10916 PT may be in invisible text. If so, we will end at the
10917 next visible position. */
10918 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10919 NULL
, DEFAULT_FACE_ID
);
10920 it
.current_x
= this_line_start_x
;
10921 it
.current_y
= this_line_y
;
10922 it
.vpos
= this_line_vpos
;
10924 /* The call to move_it_to stops in front of PT, but
10925 moves over before-strings. */
10926 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10928 if (it
.vpos
== this_line_vpos
10929 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10932 xassert (this_line_vpos
== it
.vpos
);
10933 xassert (this_line_y
== it
.current_y
);
10934 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10936 *w
->desired_matrix
->method
= 0;
10937 debug_method_add (w
, "optimization 3");
10946 /* Text changed drastically or point moved off of line. */
10947 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10950 CHARPOS (this_line_start_pos
) = 0;
10951 consider_all_windows_p
|= buffer_shared
> 1;
10952 ++clear_face_cache_count
;
10953 #ifdef HAVE_WINDOW_SYSTEM
10954 ++clear_image_cache_count
;
10957 /* Build desired matrices, and update the display. If
10958 consider_all_windows_p is non-zero, do it for all windows on all
10959 frames. Otherwise do it for selected_window, only. */
10961 if (consider_all_windows_p
)
10963 Lisp_Object tail
, frame
;
10965 FOR_EACH_FRAME (tail
, frame
)
10966 XFRAME (frame
)->updated_p
= 0;
10968 /* Recompute # windows showing selected buffer. This will be
10969 incremented each time such a window is displayed. */
10972 FOR_EACH_FRAME (tail
, frame
)
10974 struct frame
*f
= XFRAME (frame
);
10976 if (FRAME_WINDOW_P (f
) || f
== sf
)
10978 if (! EQ (frame
, selected_frame
))
10979 /* Select the frame, for the sake of frame-local
10981 select_frame_for_redisplay (frame
);
10983 /* Mark all the scroll bars to be removed; we'll redeem
10984 the ones we want when we redisplay their windows. */
10985 if (condemn_scroll_bars_hook
)
10986 condemn_scroll_bars_hook (f
);
10988 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10989 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10991 /* Any scroll bars which redisplay_windows should have
10992 nuked should now go away. */
10993 if (judge_scroll_bars_hook
)
10994 judge_scroll_bars_hook (f
);
10996 /* If fonts changed, display again. */
10997 /* ??? rms: I suspect it is a mistake to jump all the way
10998 back to retry here. It should just retry this frame. */
10999 if (fonts_changed_p
)
11002 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11004 /* See if we have to hscroll. */
11005 if (!f
->already_hscrolled_p
)
11007 f
->already_hscrolled_p
= 1;
11008 if (hscroll_windows (f
->root_window
))
11012 /* Prevent various kinds of signals during display
11013 update. stdio is not robust about handling
11014 signals, which can cause an apparent I/O
11016 if (interrupt_input
)
11017 unrequest_sigio ();
11020 /* Update the display. */
11021 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11022 pause
|= update_frame (f
, 0, 0);
11023 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
11035 /* Do the mark_window_display_accurate after all windows have
11036 been redisplayed because this call resets flags in buffers
11037 which are needed for proper redisplay. */
11038 FOR_EACH_FRAME (tail
, frame
)
11040 struct frame
*f
= XFRAME (frame
);
11043 mark_window_display_accurate (f
->root_window
, 1);
11044 if (frame_up_to_date_hook
)
11045 frame_up_to_date_hook (f
);
11050 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11052 Lisp_Object mini_window
;
11053 struct frame
*mini_frame
;
11055 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11056 /* Use list_of_error, not Qerror, so that
11057 we catch only errors and don't run the debugger. */
11058 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11060 redisplay_window_error
);
11062 /* Compare desired and current matrices, perform output. */
11065 /* If fonts changed, display again. */
11066 if (fonts_changed_p
)
11069 /* Prevent various kinds of signals during display update.
11070 stdio is not robust about handling signals,
11071 which can cause an apparent I/O error. */
11072 if (interrupt_input
)
11073 unrequest_sigio ();
11076 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11078 if (hscroll_windows (selected_window
))
11081 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11082 pause
= update_frame (sf
, 0, 0);
11085 /* We may have called echo_area_display at the top of this
11086 function. If the echo area is on another frame, that may
11087 have put text on a frame other than the selected one, so the
11088 above call to update_frame would not have caught it. Catch
11090 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11091 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11093 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11095 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11096 pause
|= update_frame (mini_frame
, 0, 0);
11097 if (!pause
&& hscroll_windows (mini_window
))
11102 /* If display was paused because of pending input, make sure we do a
11103 thorough update the next time. */
11106 /* Prevent the optimization at the beginning of
11107 redisplay_internal that tries a single-line update of the
11108 line containing the cursor in the selected window. */
11109 CHARPOS (this_line_start_pos
) = 0;
11111 /* Let the overlay arrow be updated the next time. */
11112 update_overlay_arrows (0);
11114 /* If we pause after scrolling, some rows in the current
11115 matrices of some windows are not valid. */
11116 if (!WINDOW_FULL_WIDTH_P (w
)
11117 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11118 update_mode_lines
= 1;
11122 if (!consider_all_windows_p
)
11124 /* This has already been done above if
11125 consider_all_windows_p is set. */
11126 mark_window_display_accurate_1 (w
, 1);
11128 /* Say overlay arrows are up to date. */
11129 update_overlay_arrows (1);
11131 if (frame_up_to_date_hook
!= 0)
11132 frame_up_to_date_hook (sf
);
11135 update_mode_lines
= 0;
11136 windows_or_buffers_changed
= 0;
11137 cursor_type_changed
= 0;
11140 /* Start SIGIO interrupts coming again. Having them off during the
11141 code above makes it less likely one will discard output, but not
11142 impossible, since there might be stuff in the system buffer here.
11143 But it is much hairier to try to do anything about that. */
11144 if (interrupt_input
)
11148 /* If a frame has become visible which was not before, redisplay
11149 again, so that we display it. Expose events for such a frame
11150 (which it gets when becoming visible) don't call the parts of
11151 redisplay constructing glyphs, so simply exposing a frame won't
11152 display anything in this case. So, we have to display these
11153 frames here explicitly. */
11156 Lisp_Object tail
, frame
;
11159 FOR_EACH_FRAME (tail
, frame
)
11161 int this_is_visible
= 0;
11163 if (XFRAME (frame
)->visible
)
11164 this_is_visible
= 1;
11165 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11166 if (XFRAME (frame
)->visible
)
11167 this_is_visible
= 1;
11169 if (this_is_visible
)
11173 if (new_count
!= number_of_visible_frames
)
11174 windows_or_buffers_changed
++;
11177 /* Change frame size now if a change is pending. */
11178 do_pending_window_change (1);
11180 /* If we just did a pending size change, or have additional
11181 visible frames, redisplay again. */
11182 if (windows_or_buffers_changed
&& !pause
)
11185 /* Clear the face cache eventually. */
11186 if (consider_all_windows_p
)
11188 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11190 clear_face_cache (0);
11191 clear_face_cache_count
= 0;
11193 #ifdef HAVE_WINDOW_SYSTEM
11194 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11196 Lisp_Object tail
, frame
;
11197 FOR_EACH_FRAME (tail
, frame
)
11199 struct frame
*f
= XFRAME (frame
);
11200 if (FRAME_WINDOW_P (f
))
11201 clear_image_cache (f
, 0);
11203 clear_image_cache_count
= 0;
11205 #endif /* HAVE_WINDOW_SYSTEM */
11209 unbind_to (count
, Qnil
);
11214 /* Redisplay, but leave alone any recent echo area message unless
11215 another message has been requested in its place.
11217 This is useful in situations where you need to redisplay but no
11218 user action has occurred, making it inappropriate for the message
11219 area to be cleared. See tracking_off and
11220 wait_reading_process_output for examples of these situations.
11222 FROM_WHERE is an integer saying from where this function was
11223 called. This is useful for debugging. */
11226 redisplay_preserve_echo_area (from_where
)
11229 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
11231 if (!NILP (echo_area_buffer
[1]))
11233 /* We have a previously displayed message, but no current
11234 message. Redisplay the previous message. */
11235 display_last_displayed_message_p
= 1;
11236 redisplay_internal (1);
11237 display_last_displayed_message_p
= 0;
11240 redisplay_internal (1);
11242 if (rif
!= NULL
&& rif
->flush_display_optional
)
11243 rif
->flush_display_optional (NULL
);
11247 /* Function registered with record_unwind_protect in
11248 redisplay_internal. Reset redisplaying_p to the value it had
11249 before redisplay_internal was called, and clear
11250 prevent_freeing_realized_faces_p. It also selects the previously
11254 unwind_redisplay (val
)
11257 Lisp_Object old_redisplaying_p
, old_frame
;
11259 old_redisplaying_p
= XCAR (val
);
11260 redisplaying_p
= XFASTINT (old_redisplaying_p
);
11261 old_frame
= XCDR (val
);
11262 if (! EQ (old_frame
, selected_frame
))
11263 select_frame_for_redisplay (old_frame
);
11268 /* Mark the display of window W as accurate or inaccurate. If
11269 ACCURATE_P is non-zero mark display of W as accurate. If
11270 ACCURATE_P is zero, arrange for W to be redisplayed the next time
11271 redisplay_internal is called. */
11274 mark_window_display_accurate_1 (w
, accurate_p
)
11278 if (BUFFERP (w
->buffer
))
11280 struct buffer
*b
= XBUFFER (w
->buffer
);
11283 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
11284 w
->last_overlay_modified
11285 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
11287 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
11291 b
->clip_changed
= 0;
11292 b
->prevent_redisplay_optimizations_p
= 0;
11294 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
11295 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
11296 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
11297 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
11299 w
->current_matrix
->buffer
= b
;
11300 w
->current_matrix
->begv
= BUF_BEGV (b
);
11301 w
->current_matrix
->zv
= BUF_ZV (b
);
11303 w
->last_cursor
= w
->cursor
;
11304 w
->last_cursor_off_p
= w
->cursor_off_p
;
11306 if (w
== XWINDOW (selected_window
))
11307 w
->last_point
= make_number (BUF_PT (b
));
11309 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
11315 w
->window_end_valid
= w
->buffer
;
11316 #if 0 /* This is incorrect with variable-height lines. */
11317 xassert (XINT (w
->window_end_vpos
)
11318 < (WINDOW_TOTAL_LINES (w
)
11319 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
11321 w
->update_mode_line
= Qnil
;
11326 /* Mark the display of windows in the window tree rooted at WINDOW as
11327 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
11328 windows as accurate. If ACCURATE_P is zero, arrange for windows to
11329 be redisplayed the next time redisplay_internal is called. */
11332 mark_window_display_accurate (window
, accurate_p
)
11333 Lisp_Object window
;
11338 for (; !NILP (window
); window
= w
->next
)
11340 w
= XWINDOW (window
);
11341 mark_window_display_accurate_1 (w
, accurate_p
);
11343 if (!NILP (w
->vchild
))
11344 mark_window_display_accurate (w
->vchild
, accurate_p
);
11345 if (!NILP (w
->hchild
))
11346 mark_window_display_accurate (w
->hchild
, accurate_p
);
11351 update_overlay_arrows (1);
11355 /* Force a thorough redisplay the next time by setting
11356 last_arrow_position and last_arrow_string to t, which is
11357 unequal to any useful value of Voverlay_arrow_... */
11358 update_overlay_arrows (-1);
11363 /* Return value in display table DP (Lisp_Char_Table *) for character
11364 C. Since a display table doesn't have any parent, we don't have to
11365 follow parent. Do not call this function directly but use the
11366 macro DISP_CHAR_VECTOR. */
11369 disp_char_vector (dp
, c
)
11370 struct Lisp_Char_Table
*dp
;
11376 if (SINGLE_BYTE_CHAR_P (c
))
11377 return (dp
->contents
[c
]);
11379 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
11382 else if (code
[2] < 32)
11385 /* Here, the possible range of code[0] (== charset ID) is
11386 128..max_charset. Since the top level char table contains data
11387 for multibyte characters after 256th element, we must increment
11388 code[0] by 128 to get a correct index. */
11390 code
[3] = -1; /* anchor */
11392 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
11394 val
= dp
->contents
[code
[i
]];
11395 if (!SUB_CHAR_TABLE_P (val
))
11396 return (NILP (val
) ? dp
->defalt
: val
);
11399 /* Here, val is a sub char table. We return the default value of
11401 return (dp
->defalt
);
11406 /***********************************************************************
11408 ***********************************************************************/
11410 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11413 redisplay_windows (window
)
11414 Lisp_Object window
;
11416 while (!NILP (window
))
11418 struct window
*w
= XWINDOW (window
);
11420 if (!NILP (w
->hchild
))
11421 redisplay_windows (w
->hchild
);
11422 else if (!NILP (w
->vchild
))
11423 redisplay_windows (w
->vchild
);
11426 displayed_buffer
= XBUFFER (w
->buffer
);
11427 /* Use list_of_error, not Qerror, so that
11428 we catch only errors and don't run the debugger. */
11429 internal_condition_case_1 (redisplay_window_0
, window
,
11431 redisplay_window_error
);
11439 redisplay_window_error ()
11441 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11446 redisplay_window_0 (window
)
11447 Lisp_Object window
;
11449 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11450 redisplay_window (window
, 0);
11455 redisplay_window_1 (window
)
11456 Lisp_Object window
;
11458 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11459 redisplay_window (window
, 1);
11464 /* Increment GLYPH until it reaches END or CONDITION fails while
11465 adding (GLYPH)->pixel_width to X. */
11467 #define SKIP_GLYPHS(glyph, end, x, condition) \
11470 (x) += (glyph)->pixel_width; \
11473 while ((glyph) < (end) && (condition))
11476 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11477 DELTA is the number of bytes by which positions recorded in ROW
11478 differ from current buffer positions. */
11481 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11483 struct glyph_row
*row
;
11484 struct glyph_matrix
*matrix
;
11485 int delta
, delta_bytes
, dy
, dvpos
;
11487 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11488 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11489 struct glyph
*cursor
= NULL
;
11490 /* The first glyph that starts a sequence of glyphs from string. */
11491 struct glyph
*string_start
;
11492 /* The X coordinate of string_start. */
11493 int string_start_x
;
11494 /* The last known character position. */
11495 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11496 /* The last known character position before string_start. */
11497 int string_before_pos
;
11500 int cursor_from_overlay_pos
= 0;
11501 int pt_old
= PT
- delta
;
11503 /* Skip over glyphs not having an object at the start of the row.
11504 These are special glyphs like truncation marks on terminal
11506 if (row
->displays_text_p
)
11508 && INTEGERP (glyph
->object
)
11509 && glyph
->charpos
< 0)
11511 x
+= glyph
->pixel_width
;
11515 string_start
= NULL
;
11517 && !INTEGERP (glyph
->object
)
11518 && (!BUFFERP (glyph
->object
)
11519 || (last_pos
= glyph
->charpos
) < pt_old
))
11521 if (! STRINGP (glyph
->object
))
11523 string_start
= NULL
;
11524 x
+= glyph
->pixel_width
;
11526 if (cursor_from_overlay_pos
11527 && last_pos
> cursor_from_overlay_pos
)
11529 cursor_from_overlay_pos
= 0;
11535 string_before_pos
= last_pos
;
11536 string_start
= glyph
;
11537 string_start_x
= x
;
11538 /* Skip all glyphs from string. */
11542 if ((cursor
== NULL
|| glyph
> cursor
)
11543 && !NILP (Fget_char_property (make_number ((glyph
)->charpos
),
11544 Qcursor
, (glyph
)->object
))
11545 && (pos
= string_buffer_position (w
, glyph
->object
,
11546 string_before_pos
),
11547 (pos
== 0 /* From overlay */
11548 || pos
== pt_old
)))
11550 /* Estimate overlay buffer position from the buffer
11551 positions of the glyphs before and after the overlay.
11552 Add 1 to last_pos so that if point corresponds to the
11553 glyph right after the overlay, we still use a 'cursor'
11554 property found in that overlay. */
11555 cursor_from_overlay_pos
= pos
== 0 ? last_pos
+1 : 0;
11559 x
+= glyph
->pixel_width
;
11562 while (glyph
< end
&& STRINGP (glyph
->object
));
11566 if (cursor
!= NULL
)
11571 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
11573 /* Scan back over the ellipsis glyphs, decrementing positions. */
11574 while (glyph
> row
->glyphs
[TEXT_AREA
]
11575 && (glyph
- 1)->charpos
== last_pos
)
11576 glyph
--, x
-= glyph
->pixel_width
;
11577 /* That loop always goes one position too far,
11578 including the glyph before the ellipsis.
11579 So scan forward over that one. */
11580 x
+= glyph
->pixel_width
;
11583 else if (string_start
11584 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
11586 /* We may have skipped over point because the previous glyphs
11587 are from string. As there's no easy way to know the
11588 character position of the current glyph, find the correct
11589 glyph on point by scanning from string_start again. */
11591 Lisp_Object string
;
11594 limit
= make_number (pt_old
+ 1);
11596 glyph
= string_start
;
11597 x
= string_start_x
;
11598 string
= glyph
->object
;
11599 pos
= string_buffer_position (w
, string
, string_before_pos
);
11600 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
11601 because we always put cursor after overlay strings. */
11602 while (pos
== 0 && glyph
< end
)
11604 string
= glyph
->object
;
11605 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11607 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
11610 while (glyph
< end
)
11612 pos
= XINT (Fnext_single_char_property_change
11613 (make_number (pos
), Qdisplay
, Qnil
, limit
));
11616 /* Skip glyphs from the same string. */
11617 string
= glyph
->object
;
11618 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11619 /* Skip glyphs from an overlay. */
11621 && ! string_buffer_position (w
, glyph
->object
, pos
))
11623 string
= glyph
->object
;
11624 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11629 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
11631 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
11632 w
->cursor
.y
= row
->y
+ dy
;
11634 if (w
== XWINDOW (selected_window
))
11636 if (!row
->continued_p
11637 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
11640 this_line_buffer
= XBUFFER (w
->buffer
);
11642 CHARPOS (this_line_start_pos
)
11643 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
11644 BYTEPOS (this_line_start_pos
)
11645 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
11647 CHARPOS (this_line_end_pos
)
11648 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
11649 BYTEPOS (this_line_end_pos
)
11650 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
11652 this_line_y
= w
->cursor
.y
;
11653 this_line_pixel_height
= row
->height
;
11654 this_line_vpos
= w
->cursor
.vpos
;
11655 this_line_start_x
= row
->x
;
11658 CHARPOS (this_line_start_pos
) = 0;
11663 /* Run window scroll functions, if any, for WINDOW with new window
11664 start STARTP. Sets the window start of WINDOW to that position.
11666 We assume that the window's buffer is really current. */
11668 static INLINE
struct text_pos
11669 run_window_scroll_functions (window
, startp
)
11670 Lisp_Object window
;
11671 struct text_pos startp
;
11673 struct window
*w
= XWINDOW (window
);
11674 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
11676 if (current_buffer
!= XBUFFER (w
->buffer
))
11679 if (!NILP (Vwindow_scroll_functions
))
11681 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
11682 make_number (CHARPOS (startp
)));
11683 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11684 /* In case the hook functions switch buffers. */
11685 if (current_buffer
!= XBUFFER (w
->buffer
))
11686 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11693 /* Make sure the line containing the cursor is fully visible.
11694 A value of 1 means there is nothing to be done.
11695 (Either the line is fully visible, or it cannot be made so,
11696 or we cannot tell.)
11698 If FORCE_P is non-zero, return 0 even if partial visible cursor row
11699 is higher than window.
11701 A value of 0 means the caller should do scrolling
11702 as if point had gone off the screen. */
11705 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
11708 int current_matrix_p
;
11710 struct glyph_matrix
*matrix
;
11711 struct glyph_row
*row
;
11714 if (!make_cursor_line_fully_visible_p
)
11717 /* It's not always possible to find the cursor, e.g, when a window
11718 is full of overlay strings. Don't do anything in that case. */
11719 if (w
->cursor
.vpos
< 0)
11722 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
11723 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
11725 /* If the cursor row is not partially visible, there's nothing to do. */
11726 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
11729 /* If the row the cursor is in is taller than the window's height,
11730 it's not clear what to do, so do nothing. */
11731 window_height
= window_box_height (w
);
11732 if (row
->height
>= window_height
)
11734 if (!force_p
|| MINI_WINDOW_P (w
) || w
->vscroll
)
11740 /* This code used to try to scroll the window just enough to make
11741 the line visible. It returned 0 to say that the caller should
11742 allocate larger glyph matrices. */
11744 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
11746 int dy
= row
->height
- row
->visible_height
;
11749 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11751 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
11753 int dy
= - (row
->height
- row
->visible_height
);
11756 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11759 /* When we change the cursor y-position of the selected window,
11760 change this_line_y as well so that the display optimization for
11761 the cursor line of the selected window in redisplay_internal uses
11762 the correct y-position. */
11763 if (w
== XWINDOW (selected_window
))
11764 this_line_y
= w
->cursor
.y
;
11766 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
11767 redisplay with larger matrices. */
11768 if (matrix
->nrows
< required_matrix_height (w
))
11770 fonts_changed_p
= 1;
11779 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
11780 non-zero means only WINDOW is redisplayed in redisplay_internal.
11781 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
11782 in redisplay_window to bring a partially visible line into view in
11783 the case that only the cursor has moved.
11785 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
11786 last screen line's vertical height extends past the end of the screen.
11790 1 if scrolling succeeded
11792 0 if scrolling didn't find point.
11794 -1 if new fonts have been loaded so that we must interrupt
11795 redisplay, adjust glyph matrices, and try again. */
11801 SCROLLING_NEED_LARGER_MATRICES
11805 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
11806 scroll_step
, temp_scroll_step
, last_line_misfit
)
11807 Lisp_Object window
;
11808 int just_this_one_p
;
11809 EMACS_INT scroll_conservatively
, scroll_step
;
11810 int temp_scroll_step
;
11811 int last_line_misfit
;
11813 struct window
*w
= XWINDOW (window
);
11814 struct frame
*f
= XFRAME (w
->frame
);
11815 struct text_pos scroll_margin_pos
;
11816 struct text_pos pos
;
11817 struct text_pos startp
;
11819 Lisp_Object window_end
;
11820 int this_scroll_margin
;
11824 int amount_to_scroll
= 0;
11825 Lisp_Object aggressive
;
11827 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
11830 debug_method_add (w
, "try_scrolling");
11833 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11835 /* Compute scroll margin height in pixels. We scroll when point is
11836 within this distance from the top or bottom of the window. */
11837 if (scroll_margin
> 0)
11839 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11840 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11843 this_scroll_margin
= 0;
11845 /* Force scroll_conservatively to have a reasonable value so it doesn't
11846 cause an overflow while computing how much to scroll. */
11847 if (scroll_conservatively
)
11848 scroll_conservatively
= min (scroll_conservatively
,
11849 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
11851 /* Compute how much we should try to scroll maximally to bring point
11853 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
11854 scroll_max
= max (scroll_step
,
11855 max (scroll_conservatively
, temp_scroll_step
));
11856 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
11857 || NUMBERP (current_buffer
->scroll_up_aggressively
))
11858 /* We're trying to scroll because of aggressive scrolling
11859 but no scroll_step is set. Choose an arbitrary one. Maybe
11860 there should be a variable for this. */
11864 scroll_max
*= FRAME_LINE_HEIGHT (f
);
11866 /* Decide whether we have to scroll down. Start at the window end
11867 and move this_scroll_margin up to find the position of the scroll
11869 window_end
= Fwindow_end (window
, Qt
);
11873 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
11874 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
11876 if (this_scroll_margin
|| extra_scroll_margin_lines
)
11878 start_display (&it
, w
, scroll_margin_pos
);
11879 if (this_scroll_margin
)
11880 move_it_vertically_backward (&it
, this_scroll_margin
);
11881 if (extra_scroll_margin_lines
)
11882 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
11883 scroll_margin_pos
= it
.current
.pos
;
11886 if (PT
>= CHARPOS (scroll_margin_pos
))
11890 /* Point is in the scroll margin at the bottom of the window, or
11891 below. Compute a new window start that makes point visible. */
11893 /* Compute the distance from the scroll margin to PT.
11894 Give up if the distance is greater than scroll_max. */
11895 start_display (&it
, w
, scroll_margin_pos
);
11897 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11898 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11900 /* To make point visible, we have to move the window start
11901 down so that the line the cursor is in is visible, which
11902 means we have to add in the height of the cursor line. */
11903 dy
= line_bottom_y (&it
) - y0
;
11905 if (dy
> scroll_max
)
11906 return SCROLLING_FAILED
;
11908 /* Move the window start down. If scrolling conservatively,
11909 move it just enough down to make point visible. If
11910 scroll_step is set, move it down by scroll_step. */
11911 start_display (&it
, w
, startp
);
11913 if (scroll_conservatively
)
11914 /* Set AMOUNT_TO_SCROLL to at least one line,
11915 and at most scroll_conservatively lines. */
11917 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
11918 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
11919 else if (scroll_step
|| temp_scroll_step
)
11920 amount_to_scroll
= scroll_max
;
11923 aggressive
= current_buffer
->scroll_up_aggressively
;
11924 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11925 if (NUMBERP (aggressive
))
11927 double float_amount
= XFLOATINT (aggressive
) * height
;
11928 amount_to_scroll
= float_amount
;
11929 if (amount_to_scroll
== 0 && float_amount
> 0)
11930 amount_to_scroll
= 1;
11934 if (amount_to_scroll
<= 0)
11935 return SCROLLING_FAILED
;
11937 /* If moving by amount_to_scroll leaves STARTP unchanged,
11938 move it down one screen line. */
11940 move_it_vertically (&it
, amount_to_scroll
);
11941 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
11942 move_it_by_lines (&it
, 1, 1);
11943 startp
= it
.current
.pos
;
11947 /* See if point is inside the scroll margin at the top of the
11949 scroll_margin_pos
= startp
;
11950 if (this_scroll_margin
)
11952 start_display (&it
, w
, startp
);
11953 move_it_vertically (&it
, this_scroll_margin
);
11954 scroll_margin_pos
= it
.current
.pos
;
11957 if (PT
< CHARPOS (scroll_margin_pos
))
11959 /* Point is in the scroll margin at the top of the window or
11960 above what is displayed in the window. */
11963 /* Compute the vertical distance from PT to the scroll
11964 margin position. Give up if distance is greater than
11966 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
11967 start_display (&it
, w
, pos
);
11969 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
11970 it
.last_visible_y
, -1,
11971 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11972 dy
= it
.current_y
- y0
;
11973 if (dy
> scroll_max
)
11974 return SCROLLING_FAILED
;
11976 /* Compute new window start. */
11977 start_display (&it
, w
, startp
);
11979 if (scroll_conservatively
)
11981 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11982 else if (scroll_step
|| temp_scroll_step
)
11983 amount_to_scroll
= scroll_max
;
11986 aggressive
= current_buffer
->scroll_down_aggressively
;
11987 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11988 if (NUMBERP (aggressive
))
11990 double float_amount
= XFLOATINT (aggressive
) * height
;
11991 amount_to_scroll
= float_amount
;
11992 if (amount_to_scroll
== 0 && float_amount
> 0)
11993 amount_to_scroll
= 1;
11997 if (amount_to_scroll
<= 0)
11998 return SCROLLING_FAILED
;
12000 move_it_vertically_backward (&it
, amount_to_scroll
);
12001 startp
= it
.current
.pos
;
12005 /* Run window scroll functions. */
12006 startp
= run_window_scroll_functions (window
, startp
);
12008 /* Display the window. Give up if new fonts are loaded, or if point
12010 if (!try_window (window
, startp
, 0))
12011 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12012 else if (w
->cursor
.vpos
< 0)
12014 clear_glyph_matrix (w
->desired_matrix
);
12015 rc
= SCROLLING_FAILED
;
12019 /* Maybe forget recorded base line for line number display. */
12020 if (!just_this_one_p
12021 || current_buffer
->clip_changed
12022 || BEG_UNCHANGED
< CHARPOS (startp
))
12023 w
->base_line_number
= Qnil
;
12025 /* If cursor ends up on a partially visible line,
12026 treat that as being off the bottom of the screen. */
12027 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12029 clear_glyph_matrix (w
->desired_matrix
);
12030 ++extra_scroll_margin_lines
;
12033 rc
= SCROLLING_SUCCESS
;
12040 /* Compute a suitable window start for window W if display of W starts
12041 on a continuation line. Value is non-zero if a new window start
12044 The new window start will be computed, based on W's width, starting
12045 from the start of the continued line. It is the start of the
12046 screen line with the minimum distance from the old start W->start. */
12049 compute_window_start_on_continuation_line (w
)
12052 struct text_pos pos
, start_pos
;
12053 int window_start_changed_p
= 0;
12055 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12057 /* If window start is on a continuation line... Window start may be
12058 < BEGV in case there's invisible text at the start of the
12059 buffer (M-x rmail, for example). */
12060 if (CHARPOS (start_pos
) > BEGV
12061 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12064 struct glyph_row
*row
;
12066 /* Handle the case that the window start is out of range. */
12067 if (CHARPOS (start_pos
) < BEGV
)
12068 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12069 else if (CHARPOS (start_pos
) > ZV
)
12070 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12072 /* Find the start of the continued line. This should be fast
12073 because scan_buffer is fast (newline cache). */
12074 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12075 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12076 row
, DEFAULT_FACE_ID
);
12077 reseat_at_previous_visible_line_start (&it
);
12079 /* If the line start is "too far" away from the window start,
12080 say it takes too much time to compute a new window start. */
12081 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12082 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12084 int min_distance
, distance
;
12086 /* Move forward by display lines to find the new window
12087 start. If window width was enlarged, the new start can
12088 be expected to be > the old start. If window width was
12089 decreased, the new window start will be < the old start.
12090 So, we're looking for the display line start with the
12091 minimum distance from the old window start. */
12092 pos
= it
.current
.pos
;
12093 min_distance
= INFINITY
;
12094 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12095 distance
< min_distance
)
12097 min_distance
= distance
;
12098 pos
= it
.current
.pos
;
12099 move_it_by_lines (&it
, 1, 0);
12102 /* Set the window start there. */
12103 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12104 window_start_changed_p
= 1;
12108 return window_start_changed_p
;
12112 /* Try cursor movement in case text has not changed in window WINDOW,
12113 with window start STARTP. Value is
12115 CURSOR_MOVEMENT_SUCCESS if successful
12117 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12119 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12120 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12121 we want to scroll as if scroll-step were set to 1. See the code.
12123 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12124 which case we have to abort this redisplay, and adjust matrices
12129 CURSOR_MOVEMENT_SUCCESS
,
12130 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12131 CURSOR_MOVEMENT_MUST_SCROLL
,
12132 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12136 try_cursor_movement (window
, startp
, scroll_step
)
12137 Lisp_Object window
;
12138 struct text_pos startp
;
12141 struct window
*w
= XWINDOW (window
);
12142 struct frame
*f
= XFRAME (w
->frame
);
12143 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12146 if (inhibit_try_cursor_movement
)
12150 /* Handle case where text has not changed, only point, and it has
12151 not moved off the frame. */
12152 if (/* Point may be in this window. */
12153 PT
>= CHARPOS (startp
)
12154 /* Selective display hasn't changed. */
12155 && !current_buffer
->clip_changed
12156 /* Function force-mode-line-update is used to force a thorough
12157 redisplay. It sets either windows_or_buffers_changed or
12158 update_mode_lines. So don't take a shortcut here for these
12160 && !update_mode_lines
12161 && !windows_or_buffers_changed
12162 && !cursor_type_changed
12163 /* Can't use this case if highlighting a region. When a
12164 region exists, cursor movement has to do more than just
12166 && !(!NILP (Vtransient_mark_mode
)
12167 && !NILP (current_buffer
->mark_active
))
12168 && NILP (w
->region_showing
)
12169 && NILP (Vshow_trailing_whitespace
)
12170 /* Right after splitting windows, last_point may be nil. */
12171 && INTEGERP (w
->last_point
)
12172 /* This code is not used for mini-buffer for the sake of the case
12173 of redisplaying to replace an echo area message; since in
12174 that case the mini-buffer contents per se are usually
12175 unchanged. This code is of no real use in the mini-buffer
12176 since the handling of this_line_start_pos, etc., in redisplay
12177 handles the same cases. */
12178 && !EQ (window
, minibuf_window
)
12179 /* When splitting windows or for new windows, it happens that
12180 redisplay is called with a nil window_end_vpos or one being
12181 larger than the window. This should really be fixed in
12182 window.c. I don't have this on my list, now, so we do
12183 approximately the same as the old redisplay code. --gerd. */
12184 && INTEGERP (w
->window_end_vpos
)
12185 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12186 && (FRAME_WINDOW_P (f
)
12187 || !overlay_arrow_in_current_buffer_p ()))
12189 int this_scroll_margin
, top_scroll_margin
;
12190 struct glyph_row
*row
= NULL
;
12193 debug_method_add (w
, "cursor movement");
12196 /* Scroll if point within this distance from the top or bottom
12197 of the window. This is a pixel value. */
12198 this_scroll_margin
= max (0, scroll_margin
);
12199 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12200 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12202 top_scroll_margin
= this_scroll_margin
;
12203 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12204 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12206 /* Start with the row the cursor was displayed during the last
12207 not paused redisplay. Give up if that row is not valid. */
12208 if (w
->last_cursor
.vpos
< 0
12209 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12210 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12213 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12214 if (row
->mode_line_p
)
12216 if (!row
->enabled_p
)
12217 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12220 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12223 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12225 if (PT
> XFASTINT (w
->last_point
))
12227 /* Point has moved forward. */
12228 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12229 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12231 xassert (row
->enabled_p
);
12235 /* The end position of a row equals the start position
12236 of the next row. If PT is there, we would rather
12237 display it in the next line. */
12238 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12239 && MATRIX_ROW_END_CHARPOS (row
) == PT
12240 && !cursor_row_p (w
, row
))
12243 /* If within the scroll margin, scroll. Note that
12244 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
12245 the next line would be drawn, and that
12246 this_scroll_margin can be zero. */
12247 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
12248 || PT
> MATRIX_ROW_END_CHARPOS (row
)
12249 /* Line is completely visible last line in window
12250 and PT is to be set in the next line. */
12251 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
12252 && PT
== MATRIX_ROW_END_CHARPOS (row
)
12253 && !row
->ends_at_zv_p
12254 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12257 else if (PT
< XFASTINT (w
->last_point
))
12259 /* Cursor has to be moved backward. Note that PT >=
12260 CHARPOS (startp) because of the outer if-statement. */
12261 while (!row
->mode_line_p
12262 && (MATRIX_ROW_START_CHARPOS (row
) > PT
12263 || (MATRIX_ROW_START_CHARPOS (row
) == PT
12264 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
12265 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
12266 row
> w
->current_matrix
->rows
12267 && (row
-1)->ends_in_newline_from_string_p
))))
12268 && (row
->y
> top_scroll_margin
12269 || CHARPOS (startp
) == BEGV
))
12271 xassert (row
->enabled_p
);
12275 /* Consider the following case: Window starts at BEGV,
12276 there is invisible, intangible text at BEGV, so that
12277 display starts at some point START > BEGV. It can
12278 happen that we are called with PT somewhere between
12279 BEGV and START. Try to handle that case. */
12280 if (row
< w
->current_matrix
->rows
12281 || row
->mode_line_p
)
12283 row
= w
->current_matrix
->rows
;
12284 if (row
->mode_line_p
)
12288 /* Due to newlines in overlay strings, we may have to
12289 skip forward over overlay strings. */
12290 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12291 && MATRIX_ROW_END_CHARPOS (row
) == PT
12292 && !cursor_row_p (w
, row
))
12295 /* If within the scroll margin, scroll. */
12296 if (row
->y
< top_scroll_margin
12297 && CHARPOS (startp
) != BEGV
)
12302 /* Cursor did not move. So don't scroll even if cursor line
12303 is partially visible, as it was so before. */
12304 rc
= CURSOR_MOVEMENT_SUCCESS
;
12307 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
12308 || PT
> MATRIX_ROW_END_CHARPOS (row
))
12310 /* if PT is not in the glyph row, give up. */
12311 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12313 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
12314 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
12315 && make_cursor_line_fully_visible_p
)
12317 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
12318 && !row
->ends_at_zv_p
12319 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12320 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12321 else if (row
->height
> window_box_height (w
))
12323 /* If we end up in a partially visible line, let's
12324 make it fully visible, except when it's taller
12325 than the window, in which case we can't do much
12328 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12332 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12333 if (!cursor_row_fully_visible_p (w
, 0, 1))
12334 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12336 rc
= CURSOR_MOVEMENT_SUCCESS
;
12340 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12343 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12344 rc
= CURSOR_MOVEMENT_SUCCESS
;
12353 set_vertical_scroll_bar (w
)
12356 int start
, end
, whole
;
12358 /* Calculate the start and end positions for the current window.
12359 At some point, it would be nice to choose between scrollbars
12360 which reflect the whole buffer size, with special markers
12361 indicating narrowing, and scrollbars which reflect only the
12364 Note that mini-buffers sometimes aren't displaying any text. */
12365 if (!MINI_WINDOW_P (w
)
12366 || (w
== XWINDOW (minibuf_window
)
12367 && NILP (echo_area_buffer
[0])))
12369 struct buffer
*buf
= XBUFFER (w
->buffer
);
12370 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12371 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12372 /* I don't think this is guaranteed to be right. For the
12373 moment, we'll pretend it is. */
12374 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12378 if (whole
< (end
- start
))
12379 whole
= end
- start
;
12382 start
= end
= whole
= 0;
12384 /* Indicate what this scroll bar ought to be displaying now. */
12385 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
12389 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
12390 selected_window is redisplayed.
12392 We can return without actually redisplaying the window if
12393 fonts_changed_p is nonzero. In that case, redisplay_internal will
12397 redisplay_window (window
, just_this_one_p
)
12398 Lisp_Object window
;
12399 int just_this_one_p
;
12401 struct window
*w
= XWINDOW (window
);
12402 struct frame
*f
= XFRAME (w
->frame
);
12403 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12404 struct buffer
*old
= current_buffer
;
12405 struct text_pos lpoint
, opoint
, startp
;
12406 int update_mode_line
;
12409 /* Record it now because it's overwritten. */
12410 int current_matrix_up_to_date_p
= 0;
12411 int used_current_matrix_p
= 0;
12412 /* This is less strict than current_matrix_up_to_date_p.
12413 It indictes that the buffer contents and narrowing are unchanged. */
12414 int buffer_unchanged_p
= 0;
12415 int temp_scroll_step
= 0;
12416 int count
= SPECPDL_INDEX ();
12418 int centering_position
= -1;
12419 int last_line_misfit
= 0;
12421 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12424 /* W must be a leaf window here. */
12425 xassert (!NILP (w
->buffer
));
12427 *w
->desired_matrix
->method
= 0;
12430 specbind (Qinhibit_point_motion_hooks
, Qt
);
12432 reconsider_clip_changes (w
, buffer
);
12434 /* Has the mode line to be updated? */
12435 update_mode_line
= (!NILP (w
->update_mode_line
)
12436 || update_mode_lines
12437 || buffer
->clip_changed
12438 || buffer
->prevent_redisplay_optimizations_p
);
12440 if (MINI_WINDOW_P (w
))
12442 if (w
== XWINDOW (echo_area_window
)
12443 && !NILP (echo_area_buffer
[0]))
12445 if (update_mode_line
)
12446 /* We may have to update a tty frame's menu bar or a
12447 tool-bar. Example `M-x C-h C-h C-g'. */
12448 goto finish_menu_bars
;
12450 /* We've already displayed the echo area glyphs in this window. */
12451 goto finish_scroll_bars
;
12453 else if ((w
!= XWINDOW (minibuf_window
)
12454 || minibuf_level
== 0)
12455 /* When buffer is nonempty, redisplay window normally. */
12456 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12457 /* Quail displays non-mini buffers in minibuffer window.
12458 In that case, redisplay the window normally. */
12459 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12461 /* W is a mini-buffer window, but it's not active, so clear
12463 int yb
= window_text_bottom_y (w
);
12464 struct glyph_row
*row
;
12467 for (y
= 0, row
= w
->desired_matrix
->rows
;
12469 y
+= row
->height
, ++row
)
12470 blank_row (w
, row
, y
);
12471 goto finish_scroll_bars
;
12474 clear_glyph_matrix (w
->desired_matrix
);
12477 /* Otherwise set up data on this window; select its buffer and point
12479 /* Really select the buffer, for the sake of buffer-local
12481 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12482 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12484 current_matrix_up_to_date_p
12485 = (!NILP (w
->window_end_valid
)
12486 && !current_buffer
->clip_changed
12487 && !current_buffer
->prevent_redisplay_optimizations_p
12488 && XFASTINT (w
->last_modified
) >= MODIFF
12489 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12492 = (!NILP (w
->window_end_valid
)
12493 && !current_buffer
->clip_changed
12494 && XFASTINT (w
->last_modified
) >= MODIFF
12495 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12497 /* When windows_or_buffers_changed is non-zero, we can't rely on
12498 the window end being valid, so set it to nil there. */
12499 if (windows_or_buffers_changed
)
12501 /* If window starts on a continuation line, maybe adjust the
12502 window start in case the window's width changed. */
12503 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12504 compute_window_start_on_continuation_line (w
);
12506 w
->window_end_valid
= Qnil
;
12509 /* Some sanity checks. */
12510 CHECK_WINDOW_END (w
);
12511 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12513 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12516 /* If %c is in mode line, update it if needed. */
12517 if (!NILP (w
->column_number_displayed
)
12518 /* This alternative quickly identifies a common case
12519 where no change is needed. */
12520 && !(PT
== XFASTINT (w
->last_point
)
12521 && XFASTINT (w
->last_modified
) >= MODIFF
12522 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12523 && (XFASTINT (w
->column_number_displayed
)
12524 != (int) current_column ())) /* iftc */
12525 update_mode_line
= 1;
12527 /* Count number of windows showing the selected buffer. An indirect
12528 buffer counts as its base buffer. */
12529 if (!just_this_one_p
)
12531 struct buffer
*current_base
, *window_base
;
12532 current_base
= current_buffer
;
12533 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12534 if (current_base
->base_buffer
)
12535 current_base
= current_base
->base_buffer
;
12536 if (window_base
->base_buffer
)
12537 window_base
= window_base
->base_buffer
;
12538 if (current_base
== window_base
)
12542 /* Point refers normally to the selected window. For any other
12543 window, set up appropriate value. */
12544 if (!EQ (window
, selected_window
))
12546 int new_pt
= XMARKER (w
->pointm
)->charpos
;
12547 int new_pt_byte
= marker_byte_position (w
->pointm
);
12551 new_pt_byte
= BEGV_BYTE
;
12552 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
12554 else if (new_pt
> (ZV
- 1))
12557 new_pt_byte
= ZV_BYTE
;
12558 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
12561 /* We don't use SET_PT so that the point-motion hooks don't run. */
12562 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
12565 /* If any of the character widths specified in the display table
12566 have changed, invalidate the width run cache. It's true that
12567 this may be a bit late to catch such changes, but the rest of
12568 redisplay goes (non-fatally) haywire when the display table is
12569 changed, so why should we worry about doing any better? */
12570 if (current_buffer
->width_run_cache
)
12572 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
12574 if (! disptab_matches_widthtab (disptab
,
12575 XVECTOR (current_buffer
->width_table
)))
12577 invalidate_region_cache (current_buffer
,
12578 current_buffer
->width_run_cache
,
12580 recompute_width_table (current_buffer
, disptab
);
12584 /* If window-start is screwed up, choose a new one. */
12585 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12588 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12590 /* If someone specified a new starting point but did not insist,
12591 check whether it can be used. */
12592 if (!NILP (w
->optional_new_start
)
12593 && CHARPOS (startp
) >= BEGV
12594 && CHARPOS (startp
) <= ZV
)
12596 w
->optional_new_start
= Qnil
;
12597 start_display (&it
, w
, startp
);
12598 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12599 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12600 if (IT_CHARPOS (it
) == PT
)
12601 w
->force_start
= Qt
;
12602 /* IT may overshoot PT if text at PT is invisible. */
12603 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12604 w
->force_start
= Qt
;
12609 /* Handle case where place to start displaying has been specified,
12610 unless the specified location is outside the accessible range. */
12611 if (!NILP (w
->force_start
)
12612 || w
->frozen_window_start_p
)
12614 /* We set this later on if we have to adjust point. */
12618 w
->force_start
= Qnil
;
12620 w
->window_end_valid
= Qnil
;
12622 /* Forget any recorded base line for line number display. */
12623 if (!buffer_unchanged_p
)
12624 w
->base_line_number
= Qnil
;
12626 /* Redisplay the mode line. Select the buffer properly for that.
12627 Also, run the hook window-scroll-functions
12628 because we have scrolled. */
12629 /* Note, we do this after clearing force_start because
12630 if there's an error, it is better to forget about force_start
12631 than to get into an infinite loop calling the hook functions
12632 and having them get more errors. */
12633 if (!update_mode_line
12634 || ! NILP (Vwindow_scroll_functions
))
12636 update_mode_line
= 1;
12637 w
->update_mode_line
= Qt
;
12638 startp
= run_window_scroll_functions (window
, startp
);
12641 w
->last_modified
= make_number (0);
12642 w
->last_overlay_modified
= make_number (0);
12643 if (CHARPOS (startp
) < BEGV
)
12644 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
12645 else if (CHARPOS (startp
) > ZV
)
12646 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
12648 /* Redisplay, then check if cursor has been set during the
12649 redisplay. Give up if new fonts were loaded. */
12650 val
= try_window (window
, startp
, 1);
12653 w
->force_start
= Qt
;
12654 clear_glyph_matrix (w
->desired_matrix
);
12655 goto need_larger_matrices
;
12657 /* Point was outside the scroll margins. */
12659 new_vpos
= window_box_height (w
) / 2;
12661 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
12663 /* If point does not appear, try to move point so it does
12664 appear. The desired matrix has been built above, so we
12665 can use it here. */
12666 new_vpos
= window_box_height (w
) / 2;
12669 if (!cursor_row_fully_visible_p (w
, 0, 0))
12671 /* Point does appear, but on a line partly visible at end of window.
12672 Move it back to a fully-visible line. */
12673 new_vpos
= window_box_height (w
);
12676 /* If we need to move point for either of the above reasons,
12677 now actually do it. */
12680 struct glyph_row
*row
;
12682 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
12683 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
12686 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
12687 MATRIX_ROW_START_BYTEPOS (row
));
12689 if (w
!= XWINDOW (selected_window
))
12690 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
12691 else if (current_buffer
== old
)
12692 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12694 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
12696 /* If we are highlighting the region, then we just changed
12697 the region, so redisplay to show it. */
12698 if (!NILP (Vtransient_mark_mode
)
12699 && !NILP (current_buffer
->mark_active
))
12701 clear_glyph_matrix (w
->desired_matrix
);
12702 if (!try_window (window
, startp
, 0))
12703 goto need_larger_matrices
;
12708 debug_method_add (w
, "forced window start");
12713 /* Handle case where text has not changed, only point, and it has
12714 not moved off the frame, and we are not retrying after hscroll.
12715 (current_matrix_up_to_date_p is nonzero when retrying.) */
12716 if (current_matrix_up_to_date_p
12717 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
12718 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
12722 case CURSOR_MOVEMENT_SUCCESS
:
12723 used_current_matrix_p
= 1;
12726 #if 0 /* try_cursor_movement never returns this value. */
12727 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
12728 goto need_larger_matrices
;
12731 case CURSOR_MOVEMENT_MUST_SCROLL
:
12732 goto try_to_scroll
;
12738 /* If current starting point was originally the beginning of a line
12739 but no longer is, find a new starting point. */
12740 else if (!NILP (w
->start_at_line_beg
)
12741 && !(CHARPOS (startp
) <= BEGV
12742 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
12745 debug_method_add (w
, "recenter 1");
12750 /* Try scrolling with try_window_id. Value is > 0 if update has
12751 been done, it is -1 if we know that the same window start will
12752 not work. It is 0 if unsuccessful for some other reason. */
12753 else if ((tem
= try_window_id (w
)) != 0)
12756 debug_method_add (w
, "try_window_id %d", tem
);
12759 if (fonts_changed_p
)
12760 goto need_larger_matrices
;
12764 /* Otherwise try_window_id has returned -1 which means that we
12765 don't want the alternative below this comment to execute. */
12767 else if (CHARPOS (startp
) >= BEGV
12768 && CHARPOS (startp
) <= ZV
12769 && PT
>= CHARPOS (startp
)
12770 && (CHARPOS (startp
) < ZV
12771 /* Avoid starting at end of buffer. */
12772 || CHARPOS (startp
) == BEGV
12773 || (XFASTINT (w
->last_modified
) >= MODIFF
12774 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
12777 debug_method_add (w
, "same window start");
12780 /* Try to redisplay starting at same place as before.
12781 If point has not moved off frame, accept the results. */
12782 if (!current_matrix_up_to_date_p
12783 /* Don't use try_window_reusing_current_matrix in this case
12784 because a window scroll function can have changed the
12786 || !NILP (Vwindow_scroll_functions
)
12787 || MINI_WINDOW_P (w
)
12788 || !(used_current_matrix_p
12789 = try_window_reusing_current_matrix (w
)))
12791 IF_DEBUG (debug_method_add (w
, "1"));
12792 if (try_window (window
, startp
, 1) < 0)
12793 /* -1 means we need to scroll.
12794 0 means we need new matrices, but fonts_changed_p
12795 is set in that case, so we will detect it below. */
12796 goto try_to_scroll
;
12799 if (fonts_changed_p
)
12800 goto need_larger_matrices
;
12802 if (w
->cursor
.vpos
>= 0)
12804 if (!just_this_one_p
12805 || current_buffer
->clip_changed
12806 || BEG_UNCHANGED
< CHARPOS (startp
))
12807 /* Forget any recorded base line for line number display. */
12808 w
->base_line_number
= Qnil
;
12810 if (!cursor_row_fully_visible_p (w
, 1, 0))
12812 clear_glyph_matrix (w
->desired_matrix
);
12813 last_line_misfit
= 1;
12815 /* Drop through and scroll. */
12820 clear_glyph_matrix (w
->desired_matrix
);
12825 w
->last_modified
= make_number (0);
12826 w
->last_overlay_modified
= make_number (0);
12828 /* Redisplay the mode line. Select the buffer properly for that. */
12829 if (!update_mode_line
)
12831 update_mode_line
= 1;
12832 w
->update_mode_line
= Qt
;
12835 /* Try to scroll by specified few lines. */
12836 if ((scroll_conservatively
12838 || temp_scroll_step
12839 || NUMBERP (current_buffer
->scroll_up_aggressively
)
12840 || NUMBERP (current_buffer
->scroll_down_aggressively
))
12841 && !current_buffer
->clip_changed
12842 && CHARPOS (startp
) >= BEGV
12843 && CHARPOS (startp
) <= ZV
)
12845 /* The function returns -1 if new fonts were loaded, 1 if
12846 successful, 0 if not successful. */
12847 int rc
= try_scrolling (window
, just_this_one_p
,
12848 scroll_conservatively
,
12850 temp_scroll_step
, last_line_misfit
);
12853 case SCROLLING_SUCCESS
:
12856 case SCROLLING_NEED_LARGER_MATRICES
:
12857 goto need_larger_matrices
;
12859 case SCROLLING_FAILED
:
12867 /* Finally, just choose place to start which centers point */
12870 if (centering_position
< 0)
12871 centering_position
= window_box_height (w
) / 2;
12874 debug_method_add (w
, "recenter");
12877 /* w->vscroll = 0; */
12879 /* Forget any previously recorded base line for line number display. */
12880 if (!buffer_unchanged_p
)
12881 w
->base_line_number
= Qnil
;
12883 /* Move backward half the height of the window. */
12884 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12885 it
.current_y
= it
.last_visible_y
;
12886 move_it_vertically_backward (&it
, centering_position
);
12887 xassert (IT_CHARPOS (it
) >= BEGV
);
12889 /* The function move_it_vertically_backward may move over more
12890 than the specified y-distance. If it->w is small, e.g. a
12891 mini-buffer window, we may end up in front of the window's
12892 display area. Start displaying at the start of the line
12893 containing PT in this case. */
12894 if (it
.current_y
<= 0)
12896 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12897 move_it_vertically_backward (&it
, 0);
12899 /* I think this assert is bogus if buffer contains
12900 invisible text or images. KFS. */
12901 xassert (IT_CHARPOS (it
) <= PT
);
12906 it
.current_x
= it
.hpos
= 0;
12908 /* Set startp here explicitly in case that helps avoid an infinite loop
12909 in case the window-scroll-functions functions get errors. */
12910 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
12912 /* Run scroll hooks. */
12913 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
12915 /* Redisplay the window. */
12916 if (!current_matrix_up_to_date_p
12917 || windows_or_buffers_changed
12918 || cursor_type_changed
12919 /* Don't use try_window_reusing_current_matrix in this case
12920 because it can have changed the buffer. */
12921 || !NILP (Vwindow_scroll_functions
)
12922 || !just_this_one_p
12923 || MINI_WINDOW_P (w
)
12924 || !(used_current_matrix_p
12925 = try_window_reusing_current_matrix (w
)))
12926 try_window (window
, startp
, 0);
12928 /* If new fonts have been loaded (due to fontsets), give up. We
12929 have to start a new redisplay since we need to re-adjust glyph
12931 if (fonts_changed_p
)
12932 goto need_larger_matrices
;
12934 /* If cursor did not appear assume that the middle of the window is
12935 in the first line of the window. Do it again with the next line.
12936 (Imagine a window of height 100, displaying two lines of height
12937 60. Moving back 50 from it->last_visible_y will end in the first
12939 if (w
->cursor
.vpos
< 0)
12941 if (!NILP (w
->window_end_valid
)
12942 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
12944 clear_glyph_matrix (w
->desired_matrix
);
12945 move_it_by_lines (&it
, 1, 0);
12946 try_window (window
, it
.current
.pos
, 0);
12948 else if (PT
< IT_CHARPOS (it
))
12950 clear_glyph_matrix (w
->desired_matrix
);
12951 move_it_by_lines (&it
, -1, 0);
12952 try_window (window
, it
.current
.pos
, 0);
12956 /* Not much we can do about it. */
12960 /* Consider the following case: Window starts at BEGV, there is
12961 invisible, intangible text at BEGV, so that display starts at
12962 some point START > BEGV. It can happen that we are called with
12963 PT somewhere between BEGV and START. Try to handle that case. */
12964 if (w
->cursor
.vpos
< 0)
12966 struct glyph_row
*row
= w
->current_matrix
->rows
;
12967 if (row
->mode_line_p
)
12969 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12972 if (!cursor_row_fully_visible_p (w
, 0, 0))
12974 /* If vscroll is enabled, disable it and try again. */
12978 clear_glyph_matrix (w
->desired_matrix
);
12982 /* If centering point failed to make the whole line visible,
12983 put point at the top instead. That has to make the whole line
12984 visible, if it can be done. */
12985 if (centering_position
== 0)
12988 clear_glyph_matrix (w
->desired_matrix
);
12989 centering_position
= 0;
12995 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12996 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
12997 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13000 /* Display the mode line, if we must. */
13001 if ((update_mode_line
13002 /* If window not full width, must redo its mode line
13003 if (a) the window to its side is being redone and
13004 (b) we do a frame-based redisplay. This is a consequence
13005 of how inverted lines are drawn in frame-based redisplay. */
13006 || (!just_this_one_p
13007 && !FRAME_WINDOW_P (f
)
13008 && !WINDOW_FULL_WIDTH_P (w
))
13009 /* Line number to display. */
13010 || INTEGERP (w
->base_line_pos
)
13011 /* Column number is displayed and different from the one displayed. */
13012 || (!NILP (w
->column_number_displayed
)
13013 && (XFASTINT (w
->column_number_displayed
)
13014 != (int) current_column ()))) /* iftc */
13015 /* This means that the window has a mode line. */
13016 && (WINDOW_WANTS_MODELINE_P (w
)
13017 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13019 display_mode_lines (w
);
13021 /* If mode line height has changed, arrange for a thorough
13022 immediate redisplay using the correct mode line height. */
13023 if (WINDOW_WANTS_MODELINE_P (w
)
13024 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13026 fonts_changed_p
= 1;
13027 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13028 = DESIRED_MODE_LINE_HEIGHT (w
);
13031 /* If top line height has changed, arrange for a thorough
13032 immediate redisplay using the correct mode line height. */
13033 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13034 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13036 fonts_changed_p
= 1;
13037 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13038 = DESIRED_HEADER_LINE_HEIGHT (w
);
13041 if (fonts_changed_p
)
13042 goto need_larger_matrices
;
13045 if (!line_number_displayed
13046 && !BUFFERP (w
->base_line_pos
))
13048 w
->base_line_pos
= Qnil
;
13049 w
->base_line_number
= Qnil
;
13054 /* When we reach a frame's selected window, redo the frame's menu bar. */
13055 if (update_mode_line
13056 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13058 int redisplay_menu_p
= 0;
13059 int redisplay_tool_bar_p
= 0;
13061 if (FRAME_WINDOW_P (f
))
13063 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
13064 || defined (USE_GTK)
13065 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13067 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13071 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13073 if (redisplay_menu_p
)
13074 display_menu_bar (w
);
13076 #ifdef HAVE_WINDOW_SYSTEM
13078 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13080 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13081 && (FRAME_TOOL_BAR_LINES (f
) > 0
13082 || auto_resize_tool_bars_p
);
13086 if (redisplay_tool_bar_p
)
13087 redisplay_tool_bar (f
);
13091 #ifdef HAVE_WINDOW_SYSTEM
13092 if (FRAME_WINDOW_P (f
)
13093 && update_window_fringes (w
, (just_this_one_p
13094 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13095 || w
->pseudo_window_p
)))
13099 if (draw_window_fringes (w
, 1))
13100 x_draw_vertical_border (w
);
13104 #endif /* HAVE_WINDOW_SYSTEM */
13106 /* We go to this label, with fonts_changed_p nonzero,
13107 if it is necessary to try again using larger glyph matrices.
13108 We have to redeem the scroll bar even in this case,
13109 because the loop in redisplay_internal expects that. */
13110 need_larger_matrices
:
13112 finish_scroll_bars
:
13114 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13116 /* Set the thumb's position and size. */
13117 set_vertical_scroll_bar (w
);
13119 /* Note that we actually used the scroll bar attached to this
13120 window, so it shouldn't be deleted at the end of redisplay. */
13121 redeem_scroll_bar_hook (w
);
13124 /* Restore current_buffer and value of point in it. */
13125 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13126 set_buffer_internal_1 (old
);
13127 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13129 unbind_to (count
, Qnil
);
13133 /* Build the complete desired matrix of WINDOW with a window start
13134 buffer position POS.
13136 Value is 1 if successful. It is zero if fonts were loaded during
13137 redisplay which makes re-adjusting glyph matrices necessary, and -1
13138 if point would appear in the scroll margins.
13139 (We check that only if CHECK_MARGINS is nonzero. */
13142 try_window (window
, pos
, check_margins
)
13143 Lisp_Object window
;
13144 struct text_pos pos
;
13147 struct window
*w
= XWINDOW (window
);
13149 struct glyph_row
*last_text_row
= NULL
;
13151 /* Make POS the new window start. */
13152 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13154 /* Mark cursor position as unknown. No overlay arrow seen. */
13155 w
->cursor
.vpos
= -1;
13156 overlay_arrow_seen
= 0;
13158 /* Initialize iterator and info to start at POS. */
13159 start_display (&it
, w
, pos
);
13161 /* Display all lines of W. */
13162 while (it
.current_y
< it
.last_visible_y
)
13164 if (display_line (&it
))
13165 last_text_row
= it
.glyph_row
- 1;
13166 if (fonts_changed_p
)
13170 /* Don't let the cursor end in the scroll margins. */
13172 && !MINI_WINDOW_P (w
))
13174 int this_scroll_margin
;
13176 this_scroll_margin
= max (0, scroll_margin
);
13177 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13178 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13180 if ((w
->cursor
.y
< this_scroll_margin
13181 && CHARPOS (pos
) > BEGV
13182 && IT_CHARPOS (it
) < ZV
)
13183 /* rms: considering make_cursor_line_fully_visible_p here
13184 seems to give wrong results. We don't want to recenter
13185 when the last line is partly visible, we want to allow
13186 that case to be handled in the usual way. */
13187 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
13189 w
->cursor
.vpos
= -1;
13190 clear_glyph_matrix (w
->desired_matrix
);
13195 /* If bottom moved off end of frame, change mode line percentage. */
13196 if (XFASTINT (w
->window_end_pos
) <= 0
13197 && Z
!= IT_CHARPOS (it
))
13198 w
->update_mode_line
= Qt
;
13200 /* Set window_end_pos to the offset of the last character displayed
13201 on the window from the end of current_buffer. Set
13202 window_end_vpos to its row number. */
13205 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
13206 w
->window_end_bytepos
13207 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13209 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13211 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13212 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
13213 ->displays_text_p
);
13217 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13218 w
->window_end_pos
= make_number (Z
- ZV
);
13219 w
->window_end_vpos
= make_number (0);
13222 /* But that is not valid info until redisplay finishes. */
13223 w
->window_end_valid
= Qnil
;
13229 /************************************************************************
13230 Window redisplay reusing current matrix when buffer has not changed
13231 ************************************************************************/
13233 /* Try redisplay of window W showing an unchanged buffer with a
13234 different window start than the last time it was displayed by
13235 reusing its current matrix. Value is non-zero if successful.
13236 W->start is the new window start. */
13239 try_window_reusing_current_matrix (w
)
13242 struct frame
*f
= XFRAME (w
->frame
);
13243 struct glyph_row
*row
, *bottom_row
;
13246 struct text_pos start
, new_start
;
13247 int nrows_scrolled
, i
;
13248 struct glyph_row
*last_text_row
;
13249 struct glyph_row
*last_reused_text_row
;
13250 struct glyph_row
*start_row
;
13251 int start_vpos
, min_y
, max_y
;
13254 if (inhibit_try_window_reusing
)
13258 if (/* This function doesn't handle terminal frames. */
13259 !FRAME_WINDOW_P (f
)
13260 /* Don't try to reuse the display if windows have been split
13262 || windows_or_buffers_changed
13263 || cursor_type_changed
)
13266 /* Can't do this if region may have changed. */
13267 if ((!NILP (Vtransient_mark_mode
)
13268 && !NILP (current_buffer
->mark_active
))
13269 || !NILP (w
->region_showing
)
13270 || !NILP (Vshow_trailing_whitespace
))
13273 /* If top-line visibility has changed, give up. */
13274 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13275 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
13278 /* Give up if old or new display is scrolled vertically. We could
13279 make this function handle this, but right now it doesn't. */
13280 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13281 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
13284 /* The variable new_start now holds the new window start. The old
13285 start `start' can be determined from the current matrix. */
13286 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
13287 start
= start_row
->start
.pos
;
13288 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13290 /* Clear the desired matrix for the display below. */
13291 clear_glyph_matrix (w
->desired_matrix
);
13293 if (CHARPOS (new_start
) <= CHARPOS (start
))
13297 /* Don't use this method if the display starts with an ellipsis
13298 displayed for invisible text. It's not easy to handle that case
13299 below, and it's certainly not worth the effort since this is
13300 not a frequent case. */
13301 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
13304 IF_DEBUG (debug_method_add (w
, "twu1"));
13306 /* Display up to a row that can be reused. The variable
13307 last_text_row is set to the last row displayed that displays
13308 text. Note that it.vpos == 0 if or if not there is a
13309 header-line; it's not the same as the MATRIX_ROW_VPOS! */
13310 start_display (&it
, w
, new_start
);
13311 first_row_y
= it
.current_y
;
13312 w
->cursor
.vpos
= -1;
13313 last_text_row
= last_reused_text_row
= NULL
;
13315 while (it
.current_y
< it
.last_visible_y
13316 && !fonts_changed_p
)
13318 /* If we have reached into the characters in the START row,
13319 that means the line boundaries have changed. So we
13320 can't start copying with the row START. Maybe it will
13321 work to start copying with the following row. */
13322 while (IT_CHARPOS (it
) > CHARPOS (start
))
13324 /* Advance to the next row as the "start". */
13326 start
= start_row
->start
.pos
;
13327 /* If there are no more rows to try, or just one, give up. */
13328 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
13329 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
13330 || CHARPOS (start
) == ZV
)
13332 clear_glyph_matrix (w
->desired_matrix
);
13336 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13338 /* If we have reached alignment,
13339 we can copy the rest of the rows. */
13340 if (IT_CHARPOS (it
) == CHARPOS (start
))
13343 if (display_line (&it
))
13344 last_text_row
= it
.glyph_row
- 1;
13347 /* A value of current_y < last_visible_y means that we stopped
13348 at the previous window start, which in turn means that we
13349 have at least one reusable row. */
13350 if (it
.current_y
< it
.last_visible_y
)
13352 /* IT.vpos always starts from 0; it counts text lines. */
13353 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
13355 /* Find PT if not already found in the lines displayed. */
13356 if (w
->cursor
.vpos
< 0)
13358 int dy
= it
.current_y
- start_row
->y
;
13360 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13361 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
13363 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
13364 dy
, nrows_scrolled
);
13367 clear_glyph_matrix (w
->desired_matrix
);
13372 /* Scroll the display. Do it before the current matrix is
13373 changed. The problem here is that update has not yet
13374 run, i.e. part of the current matrix is not up to date.
13375 scroll_run_hook will clear the cursor, and use the
13376 current matrix to get the height of the row the cursor is
13378 run
.current_y
= start_row
->y
;
13379 run
.desired_y
= it
.current_y
;
13380 run
.height
= it
.last_visible_y
- it
.current_y
;
13382 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
13385 rif
->update_window_begin_hook (w
);
13386 rif
->clear_window_mouse_face (w
);
13387 rif
->scroll_run_hook (w
, &run
);
13388 rif
->update_window_end_hook (w
, 0, 0);
13392 /* Shift current matrix down by nrows_scrolled lines. */
13393 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13394 rotate_matrix (w
->current_matrix
,
13396 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13399 /* Disable lines that must be updated. */
13400 for (i
= 0; i
< it
.vpos
; ++i
)
13401 (start_row
+ i
)->enabled_p
= 0;
13403 /* Re-compute Y positions. */
13404 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13405 max_y
= it
.last_visible_y
;
13406 for (row
= start_row
+ nrows_scrolled
;
13410 row
->y
= it
.current_y
;
13411 row
->visible_height
= row
->height
;
13413 if (row
->y
< min_y
)
13414 row
->visible_height
-= min_y
- row
->y
;
13415 if (row
->y
+ row
->height
> max_y
)
13416 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13417 row
->redraw_fringe_bitmaps_p
= 1;
13419 it
.current_y
+= row
->height
;
13421 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13422 last_reused_text_row
= row
;
13423 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13427 /* Disable lines in the current matrix which are now
13428 below the window. */
13429 for (++row
; row
< bottom_row
; ++row
)
13430 row
->enabled_p
= row
->mode_line_p
= 0;
13433 /* Update window_end_pos etc.; last_reused_text_row is the last
13434 reused row from the current matrix containing text, if any.
13435 The value of last_text_row is the last displayed line
13436 containing text. */
13437 if (last_reused_text_row
)
13439 w
->window_end_bytepos
13440 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13442 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13444 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13445 w
->current_matrix
));
13447 else if (last_text_row
)
13449 w
->window_end_bytepos
13450 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13452 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13454 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13458 /* This window must be completely empty. */
13459 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13460 w
->window_end_pos
= make_number (Z
- ZV
);
13461 w
->window_end_vpos
= make_number (0);
13463 w
->window_end_valid
= Qnil
;
13465 /* Update hint: don't try scrolling again in update_window. */
13466 w
->desired_matrix
->no_scrolling_p
= 1;
13469 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13473 else if (CHARPOS (new_start
) > CHARPOS (start
))
13475 struct glyph_row
*pt_row
, *row
;
13476 struct glyph_row
*first_reusable_row
;
13477 struct glyph_row
*first_row_to_display
;
13479 int yb
= window_text_bottom_y (w
);
13481 /* Find the row starting at new_start, if there is one. Don't
13482 reuse a partially visible line at the end. */
13483 first_reusable_row
= start_row
;
13484 while (first_reusable_row
->enabled_p
13485 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13486 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13487 < CHARPOS (new_start
)))
13488 ++first_reusable_row
;
13490 /* Give up if there is no row to reuse. */
13491 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13492 || !first_reusable_row
->enabled_p
13493 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13494 != CHARPOS (new_start
)))
13497 /* We can reuse fully visible rows beginning with
13498 first_reusable_row to the end of the window. Set
13499 first_row_to_display to the first row that cannot be reused.
13500 Set pt_row to the row containing point, if there is any. */
13502 for (first_row_to_display
= first_reusable_row
;
13503 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13504 ++first_row_to_display
)
13506 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
13507 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
13508 pt_row
= first_row_to_display
;
13511 /* Start displaying at the start of first_row_to_display. */
13512 xassert (first_row_to_display
->y
< yb
);
13513 init_to_row_start (&it
, w
, first_row_to_display
);
13515 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
13517 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
13519 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
13520 + WINDOW_HEADER_LINE_HEIGHT (w
));
13522 /* Display lines beginning with first_row_to_display in the
13523 desired matrix. Set last_text_row to the last row displayed
13524 that displays text. */
13525 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
13526 if (pt_row
== NULL
)
13527 w
->cursor
.vpos
= -1;
13528 last_text_row
= NULL
;
13529 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
13530 if (display_line (&it
))
13531 last_text_row
= it
.glyph_row
- 1;
13533 /* Give up If point isn't in a row displayed or reused. */
13534 if (w
->cursor
.vpos
< 0)
13536 clear_glyph_matrix (w
->desired_matrix
);
13540 /* If point is in a reused row, adjust y and vpos of the cursor
13544 w
->cursor
.vpos
-= nrows_scrolled
;
13545 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
13548 /* Scroll the display. */
13549 run
.current_y
= first_reusable_row
->y
;
13550 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13551 run
.height
= it
.last_visible_y
- run
.current_y
;
13552 dy
= run
.current_y
- run
.desired_y
;
13557 rif
->update_window_begin_hook (w
);
13558 rif
->clear_window_mouse_face (w
);
13559 rif
->scroll_run_hook (w
, &run
);
13560 rif
->update_window_end_hook (w
, 0, 0);
13564 /* Adjust Y positions of reused rows. */
13565 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13566 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13567 max_y
= it
.last_visible_y
;
13568 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
13571 row
->visible_height
= row
->height
;
13572 if (row
->y
< min_y
)
13573 row
->visible_height
-= min_y
- row
->y
;
13574 if (row
->y
+ row
->height
> max_y
)
13575 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13576 row
->redraw_fringe_bitmaps_p
= 1;
13579 /* Scroll the current matrix. */
13580 xassert (nrows_scrolled
> 0);
13581 rotate_matrix (w
->current_matrix
,
13583 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13586 /* Disable rows not reused. */
13587 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
13588 row
->enabled_p
= 0;
13590 /* Point may have moved to a different line, so we cannot assume that
13591 the previous cursor position is valid; locate the correct row. */
13594 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
13595 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
13599 w
->cursor
.y
= row
->y
;
13601 if (row
< bottom_row
)
13603 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
13604 while (glyph
->charpos
< PT
)
13607 w
->cursor
.x
+= glyph
->pixel_width
;
13613 /* Adjust window end. A null value of last_text_row means that
13614 the window end is in reused rows which in turn means that
13615 only its vpos can have changed. */
13618 w
->window_end_bytepos
13619 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13621 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13623 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13628 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
13631 w
->window_end_valid
= Qnil
;
13632 w
->desired_matrix
->no_scrolling_p
= 1;
13635 debug_method_add (w
, "try_window_reusing_current_matrix 2");
13645 /************************************************************************
13646 Window redisplay reusing current matrix when buffer has changed
13647 ************************************************************************/
13649 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
13650 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
13652 static struct glyph_row
*
13653 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
13654 struct glyph_row
*));
13657 /* Return the last row in MATRIX displaying text. If row START is
13658 non-null, start searching with that row. IT gives the dimensions
13659 of the display. Value is null if matrix is empty; otherwise it is
13660 a pointer to the row found. */
13662 static struct glyph_row
*
13663 find_last_row_displaying_text (matrix
, it
, start
)
13664 struct glyph_matrix
*matrix
;
13666 struct glyph_row
*start
;
13668 struct glyph_row
*row
, *row_found
;
13670 /* Set row_found to the last row in IT->w's current matrix
13671 displaying text. The loop looks funny but think of partially
13674 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
13675 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13677 xassert (row
->enabled_p
);
13679 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
13688 /* Return the last row in the current matrix of W that is not affected
13689 by changes at the start of current_buffer that occurred since W's
13690 current matrix was built. Value is null if no such row exists.
13692 BEG_UNCHANGED us the number of characters unchanged at the start of
13693 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
13694 first changed character in current_buffer. Characters at positions <
13695 BEG + BEG_UNCHANGED are at the same buffer positions as they were
13696 when the current matrix was built. */
13698 static struct glyph_row
*
13699 find_last_unchanged_at_beg_row (w
)
13702 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
13703 struct glyph_row
*row
;
13704 struct glyph_row
*row_found
= NULL
;
13705 int yb
= window_text_bottom_y (w
);
13707 /* Find the last row displaying unchanged text. */
13708 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13709 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13710 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
13712 if (/* If row ends before first_changed_pos, it is unchanged,
13713 except in some case. */
13714 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
13715 /* When row ends in ZV and we write at ZV it is not
13717 && !row
->ends_at_zv_p
13718 /* When first_changed_pos is the end of a continued line,
13719 row is not unchanged because it may be no longer
13721 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
13722 && (row
->continued_p
13723 || row
->exact_window_width_line_p
)))
13726 /* Stop if last visible row. */
13727 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
13737 /* Find the first glyph row in the current matrix of W that is not
13738 affected by changes at the end of current_buffer since the
13739 time W's current matrix was built.
13741 Return in *DELTA the number of chars by which buffer positions in
13742 unchanged text at the end of current_buffer must be adjusted.
13744 Return in *DELTA_BYTES the corresponding number of bytes.
13746 Value is null if no such row exists, i.e. all rows are affected by
13749 static struct glyph_row
*
13750 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
13752 int *delta
, *delta_bytes
;
13754 struct glyph_row
*row
;
13755 struct glyph_row
*row_found
= NULL
;
13757 *delta
= *delta_bytes
= 0;
13759 /* Display must not have been paused, otherwise the current matrix
13760 is not up to date. */
13761 if (NILP (w
->window_end_valid
))
13764 /* A value of window_end_pos >= END_UNCHANGED means that the window
13765 end is in the range of changed text. If so, there is no
13766 unchanged row at the end of W's current matrix. */
13767 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
13770 /* Set row to the last row in W's current matrix displaying text. */
13771 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13773 /* If matrix is entirely empty, no unchanged row exists. */
13774 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13776 /* The value of row is the last glyph row in the matrix having a
13777 meaningful buffer position in it. The end position of row
13778 corresponds to window_end_pos. This allows us to translate
13779 buffer positions in the current matrix to current buffer
13780 positions for characters not in changed text. */
13781 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13782 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13783 int last_unchanged_pos
, last_unchanged_pos_old
;
13784 struct glyph_row
*first_text_row
13785 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13787 *delta
= Z
- Z_old
;
13788 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13790 /* Set last_unchanged_pos to the buffer position of the last
13791 character in the buffer that has not been changed. Z is the
13792 index + 1 of the last character in current_buffer, i.e. by
13793 subtracting END_UNCHANGED we get the index of the last
13794 unchanged character, and we have to add BEG to get its buffer
13796 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
13797 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
13799 /* Search backward from ROW for a row displaying a line that
13800 starts at a minimum position >= last_unchanged_pos_old. */
13801 for (; row
> first_text_row
; --row
)
13803 /* This used to abort, but it can happen.
13804 It is ok to just stop the search instead here. KFS. */
13805 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13808 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
13813 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
13820 /* Make sure that glyph rows in the current matrix of window W
13821 reference the same glyph memory as corresponding rows in the
13822 frame's frame matrix. This function is called after scrolling W's
13823 current matrix on a terminal frame in try_window_id and
13824 try_window_reusing_current_matrix. */
13827 sync_frame_with_window_matrix_rows (w
)
13830 struct frame
*f
= XFRAME (w
->frame
);
13831 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
13833 /* Preconditions: W must be a leaf window and full-width. Its frame
13834 must have a frame matrix. */
13835 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
13836 xassert (WINDOW_FULL_WIDTH_P (w
));
13837 xassert (!FRAME_WINDOW_P (f
));
13839 /* If W is a full-width window, glyph pointers in W's current matrix
13840 have, by definition, to be the same as glyph pointers in the
13841 corresponding frame matrix. Note that frame matrices have no
13842 marginal areas (see build_frame_matrix). */
13843 window_row
= w
->current_matrix
->rows
;
13844 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
13845 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
13846 while (window_row
< window_row_end
)
13848 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
13849 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
13851 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
13852 frame_row
->glyphs
[TEXT_AREA
] = start
;
13853 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
13854 frame_row
->glyphs
[LAST_AREA
] = end
;
13856 /* Disable frame rows whose corresponding window rows have
13857 been disabled in try_window_id. */
13858 if (!window_row
->enabled_p
)
13859 frame_row
->enabled_p
= 0;
13861 ++window_row
, ++frame_row
;
13866 /* Find the glyph row in window W containing CHARPOS. Consider all
13867 rows between START and END (not inclusive). END null means search
13868 all rows to the end of the display area of W. Value is the row
13869 containing CHARPOS or null. */
13872 row_containing_pos (w
, charpos
, start
, end
, dy
)
13875 struct glyph_row
*start
, *end
;
13878 struct glyph_row
*row
= start
;
13881 /* If we happen to start on a header-line, skip that. */
13882 if (row
->mode_line_p
)
13885 if ((end
&& row
>= end
) || !row
->enabled_p
)
13888 last_y
= window_text_bottom_y (w
) - dy
;
13892 /* Give up if we have gone too far. */
13893 if (end
&& row
>= end
)
13895 /* This formerly returned if they were equal.
13896 I think that both quantities are of a "last plus one" type;
13897 if so, when they are equal, the row is within the screen. -- rms. */
13898 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
13901 /* If it is in this row, return this row. */
13902 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
13903 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
13904 /* The end position of a row equals the start
13905 position of the next row. If CHARPOS is there, we
13906 would rather display it in the next line, except
13907 when this line ends in ZV. */
13908 && !row
->ends_at_zv_p
13909 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13910 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
13917 /* Try to redisplay window W by reusing its existing display. W's
13918 current matrix must be up to date when this function is called,
13919 i.e. window_end_valid must not be nil.
13923 1 if display has been updated
13924 0 if otherwise unsuccessful
13925 -1 if redisplay with same window start is known not to succeed
13927 The following steps are performed:
13929 1. Find the last row in the current matrix of W that is not
13930 affected by changes at the start of current_buffer. If no such row
13933 2. Find the first row in W's current matrix that is not affected by
13934 changes at the end of current_buffer. Maybe there is no such row.
13936 3. Display lines beginning with the row + 1 found in step 1 to the
13937 row found in step 2 or, if step 2 didn't find a row, to the end of
13940 4. If cursor is not known to appear on the window, give up.
13942 5. If display stopped at the row found in step 2, scroll the
13943 display and current matrix as needed.
13945 6. Maybe display some lines at the end of W, if we must. This can
13946 happen under various circumstances, like a partially visible line
13947 becoming fully visible, or because newly displayed lines are displayed
13948 in smaller font sizes.
13950 7. Update W's window end information. */
13956 struct frame
*f
= XFRAME (w
->frame
);
13957 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
13958 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
13959 struct glyph_row
*last_unchanged_at_beg_row
;
13960 struct glyph_row
*first_unchanged_at_end_row
;
13961 struct glyph_row
*row
;
13962 struct glyph_row
*bottom_row
;
13965 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
13966 struct text_pos start_pos
;
13968 int first_unchanged_at_end_vpos
= 0;
13969 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
13970 struct text_pos start
;
13971 int first_changed_charpos
, last_changed_charpos
;
13974 if (inhibit_try_window_id
)
13978 /* This is handy for debugging. */
13980 #define GIVE_UP(X) \
13982 fprintf (stderr, "try_window_id give up %d\n", (X)); \
13986 #define GIVE_UP(X) return 0
13989 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
13991 /* Don't use this for mini-windows because these can show
13992 messages and mini-buffers, and we don't handle that here. */
13993 if (MINI_WINDOW_P (w
))
13996 /* This flag is used to prevent redisplay optimizations. */
13997 if (windows_or_buffers_changed
|| cursor_type_changed
)
14000 /* Verify that narrowing has not changed.
14001 Also verify that we were not told to prevent redisplay optimizations.
14002 It would be nice to further
14003 reduce the number of cases where this prevents try_window_id. */
14004 if (current_buffer
->clip_changed
14005 || current_buffer
->prevent_redisplay_optimizations_p
)
14008 /* Window must either use window-based redisplay or be full width. */
14009 if (!FRAME_WINDOW_P (f
)
14010 && (!line_ins_del_ok
14011 || !WINDOW_FULL_WIDTH_P (w
)))
14014 /* Give up if point is not known NOT to appear in W. */
14015 if (PT
< CHARPOS (start
))
14018 /* Another way to prevent redisplay optimizations. */
14019 if (XFASTINT (w
->last_modified
) == 0)
14022 /* Verify that window is not hscrolled. */
14023 if (XFASTINT (w
->hscroll
) != 0)
14026 /* Verify that display wasn't paused. */
14027 if (NILP (w
->window_end_valid
))
14030 /* Can't use this if highlighting a region because a cursor movement
14031 will do more than just set the cursor. */
14032 if (!NILP (Vtransient_mark_mode
)
14033 && !NILP (current_buffer
->mark_active
))
14036 /* Likewise if highlighting trailing whitespace. */
14037 if (!NILP (Vshow_trailing_whitespace
))
14040 /* Likewise if showing a region. */
14041 if (!NILP (w
->region_showing
))
14044 /* Can use this if overlay arrow position and or string have changed. */
14045 if (overlay_arrows_changed_p ())
14049 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14050 only if buffer has really changed. The reason is that the gap is
14051 initially at Z for freshly visited files. The code below would
14052 set end_unchanged to 0 in that case. */
14053 if (MODIFF
> SAVE_MODIFF
14054 /* This seems to happen sometimes after saving a buffer. */
14055 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14057 if (GPT
- BEG
< BEG_UNCHANGED
)
14058 BEG_UNCHANGED
= GPT
- BEG
;
14059 if (Z
- GPT
< END_UNCHANGED
)
14060 END_UNCHANGED
= Z
- GPT
;
14063 /* The position of the first and last character that has been changed. */
14064 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14065 last_changed_charpos
= Z
- END_UNCHANGED
;
14067 /* If window starts after a line end, and the last change is in
14068 front of that newline, then changes don't affect the display.
14069 This case happens with stealth-fontification. Note that although
14070 the display is unchanged, glyph positions in the matrix have to
14071 be adjusted, of course. */
14072 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14073 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14074 && ((last_changed_charpos
< CHARPOS (start
)
14075 && CHARPOS (start
) == BEGV
)
14076 || (last_changed_charpos
< CHARPOS (start
) - 1
14077 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14079 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14080 struct glyph_row
*r0
;
14082 /* Compute how many chars/bytes have been added to or removed
14083 from the buffer. */
14084 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14085 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14087 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14089 /* Give up if PT is not in the window. Note that it already has
14090 been checked at the start of try_window_id that PT is not in
14091 front of the window start. */
14092 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14095 /* If window start is unchanged, we can reuse the whole matrix
14096 as is, after adjusting glyph positions. No need to compute
14097 the window end again, since its offset from Z hasn't changed. */
14098 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14099 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14100 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14101 /* PT must not be in a partially visible line. */
14102 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14103 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14105 /* Adjust positions in the glyph matrix. */
14106 if (delta
|| delta_bytes
)
14108 struct glyph_row
*r1
14109 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14110 increment_matrix_positions (w
->current_matrix
,
14111 MATRIX_ROW_VPOS (r0
, current_matrix
),
14112 MATRIX_ROW_VPOS (r1
, current_matrix
),
14113 delta
, delta_bytes
);
14116 /* Set the cursor. */
14117 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14119 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14126 /* Handle the case that changes are all below what is displayed in
14127 the window, and that PT is in the window. This shortcut cannot
14128 be taken if ZV is visible in the window, and text has been added
14129 there that is visible in the window. */
14130 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14131 /* ZV is not visible in the window, or there are no
14132 changes at ZV, actually. */
14133 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14134 || first_changed_charpos
== last_changed_charpos
))
14136 struct glyph_row
*r0
;
14138 /* Give up if PT is not in the window. Note that it already has
14139 been checked at the start of try_window_id that PT is not in
14140 front of the window start. */
14141 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14144 /* If window start is unchanged, we can reuse the whole matrix
14145 as is, without changing glyph positions since no text has
14146 been added/removed in front of the window end. */
14147 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14148 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14149 /* PT must not be in a partially visible line. */
14150 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14151 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14153 /* We have to compute the window end anew since text
14154 can have been added/removed after it. */
14156 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14157 w
->window_end_bytepos
14158 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14160 /* Set the cursor. */
14161 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14163 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14170 /* Give up if window start is in the changed area.
14172 The condition used to read
14174 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
14176 but why that was tested escapes me at the moment. */
14177 if (CHARPOS (start
) >= first_changed_charpos
14178 && CHARPOS (start
) <= last_changed_charpos
)
14181 /* Check that window start agrees with the start of the first glyph
14182 row in its current matrix. Check this after we know the window
14183 start is not in changed text, otherwise positions would not be
14185 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14186 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
14189 /* Give up if the window ends in strings. Overlay strings
14190 at the end are difficult to handle, so don't try. */
14191 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
14192 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
14195 /* Compute the position at which we have to start displaying new
14196 lines. Some of the lines at the top of the window might be
14197 reusable because they are not displaying changed text. Find the
14198 last row in W's current matrix not affected by changes at the
14199 start of current_buffer. Value is null if changes start in the
14200 first line of window. */
14201 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
14202 if (last_unchanged_at_beg_row
)
14204 /* Avoid starting to display in the moddle of a character, a TAB
14205 for instance. This is easier than to set up the iterator
14206 exactly, and it's not a frequent case, so the additional
14207 effort wouldn't really pay off. */
14208 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
14209 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
14210 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
14211 --last_unchanged_at_beg_row
;
14213 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
14216 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
14218 start_pos
= it
.current
.pos
;
14220 /* Start displaying new lines in the desired matrix at the same
14221 vpos we would use in the current matrix, i.e. below
14222 last_unchanged_at_beg_row. */
14223 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
14225 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14226 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
14228 xassert (it
.hpos
== 0 && it
.current_x
== 0);
14232 /* There are no reusable lines at the start of the window.
14233 Start displaying in the first text line. */
14234 start_display (&it
, w
, start
);
14235 it
.vpos
= it
.first_vpos
;
14236 start_pos
= it
.current
.pos
;
14239 /* Find the first row that is not affected by changes at the end of
14240 the buffer. Value will be null if there is no unchanged row, in
14241 which case we must redisplay to the end of the window. delta
14242 will be set to the value by which buffer positions beginning with
14243 first_unchanged_at_end_row have to be adjusted due to text
14245 first_unchanged_at_end_row
14246 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
14247 IF_DEBUG (debug_delta
= delta
);
14248 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
14250 /* Set stop_pos to the buffer position up to which we will have to
14251 display new lines. If first_unchanged_at_end_row != NULL, this
14252 is the buffer position of the start of the line displayed in that
14253 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
14254 that we don't stop at a buffer position. */
14256 if (first_unchanged_at_end_row
)
14258 xassert (last_unchanged_at_beg_row
== NULL
14259 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
14261 /* If this is a continuation line, move forward to the next one
14262 that isn't. Changes in lines above affect this line.
14263 Caution: this may move first_unchanged_at_end_row to a row
14264 not displaying text. */
14265 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
14266 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14267 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14268 < it
.last_visible_y
))
14269 ++first_unchanged_at_end_row
;
14271 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14272 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14273 >= it
.last_visible_y
))
14274 first_unchanged_at_end_row
= NULL
;
14277 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
14279 first_unchanged_at_end_vpos
14280 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
14281 xassert (stop_pos
>= Z
- END_UNCHANGED
);
14284 else if (last_unchanged_at_beg_row
== NULL
)
14290 /* Either there is no unchanged row at the end, or the one we have
14291 now displays text. This is a necessary condition for the window
14292 end pos calculation at the end of this function. */
14293 xassert (first_unchanged_at_end_row
== NULL
14294 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
14296 debug_last_unchanged_at_beg_vpos
14297 = (last_unchanged_at_beg_row
14298 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
14300 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
14302 #endif /* GLYPH_DEBUG != 0 */
14305 /* Display new lines. Set last_text_row to the last new line
14306 displayed which has text on it, i.e. might end up as being the
14307 line where the window_end_vpos is. */
14308 w
->cursor
.vpos
= -1;
14309 last_text_row
= NULL
;
14310 overlay_arrow_seen
= 0;
14311 while (it
.current_y
< it
.last_visible_y
14312 && !fonts_changed_p
14313 && (first_unchanged_at_end_row
== NULL
14314 || IT_CHARPOS (it
) < stop_pos
))
14316 if (display_line (&it
))
14317 last_text_row
= it
.glyph_row
- 1;
14320 if (fonts_changed_p
)
14324 /* Compute differences in buffer positions, y-positions etc. for
14325 lines reused at the bottom of the window. Compute what we can
14327 if (first_unchanged_at_end_row
14328 /* No lines reused because we displayed everything up to the
14329 bottom of the window. */
14330 && it
.current_y
< it
.last_visible_y
)
14333 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
14335 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
14336 run
.current_y
= first_unchanged_at_end_row
->y
;
14337 run
.desired_y
= run
.current_y
+ dy
;
14338 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
14342 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
14343 first_unchanged_at_end_row
= NULL
;
14345 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
14348 /* Find the cursor if not already found. We have to decide whether
14349 PT will appear on this window (it sometimes doesn't, but this is
14350 not a very frequent case.) This decision has to be made before
14351 the current matrix is altered. A value of cursor.vpos < 0 means
14352 that PT is either in one of the lines beginning at
14353 first_unchanged_at_end_row or below the window. Don't care for
14354 lines that might be displayed later at the window end; as
14355 mentioned, this is not a frequent case. */
14356 if (w
->cursor
.vpos
< 0)
14358 /* Cursor in unchanged rows at the top? */
14359 if (PT
< CHARPOS (start_pos
)
14360 && last_unchanged_at_beg_row
)
14362 row
= row_containing_pos (w
, PT
,
14363 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
14364 last_unchanged_at_beg_row
+ 1, 0);
14366 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14369 /* Start from first_unchanged_at_end_row looking for PT. */
14370 else if (first_unchanged_at_end_row
)
14372 row
= row_containing_pos (w
, PT
- delta
,
14373 first_unchanged_at_end_row
, NULL
, 0);
14375 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
14376 delta_bytes
, dy
, dvpos
);
14379 /* Give up if cursor was not found. */
14380 if (w
->cursor
.vpos
< 0)
14382 clear_glyph_matrix (w
->desired_matrix
);
14387 /* Don't let the cursor end in the scroll margins. */
14389 int this_scroll_margin
, cursor_height
;
14391 this_scroll_margin
= max (0, scroll_margin
);
14392 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14393 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14394 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
14396 if ((w
->cursor
.y
< this_scroll_margin
14397 && CHARPOS (start
) > BEGV
)
14398 /* Old redisplay didn't take scroll margin into account at the bottom,
14399 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14400 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14401 ? cursor_height
+ this_scroll_margin
14402 : 1)) > it
.last_visible_y
)
14404 w
->cursor
.vpos
= -1;
14405 clear_glyph_matrix (w
->desired_matrix
);
14410 /* Scroll the display. Do it before changing the current matrix so
14411 that xterm.c doesn't get confused about where the cursor glyph is
14413 if (dy
&& run
.height
)
14417 if (FRAME_WINDOW_P (f
))
14419 rif
->update_window_begin_hook (w
);
14420 rif
->clear_window_mouse_face (w
);
14421 rif
->scroll_run_hook (w
, &run
);
14422 rif
->update_window_end_hook (w
, 0, 0);
14426 /* Terminal frame. In this case, dvpos gives the number of
14427 lines to scroll by; dvpos < 0 means scroll up. */
14428 int first_unchanged_at_end_vpos
14429 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14430 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14431 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14432 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14433 + window_internal_height (w
));
14435 /* Perform the operation on the screen. */
14438 /* Scroll last_unchanged_at_beg_row to the end of the
14439 window down dvpos lines. */
14440 set_terminal_window (end
);
14442 /* On dumb terminals delete dvpos lines at the end
14443 before inserting dvpos empty lines. */
14444 if (!scroll_region_ok
)
14445 ins_del_lines (end
- dvpos
, -dvpos
);
14447 /* Insert dvpos empty lines in front of
14448 last_unchanged_at_beg_row. */
14449 ins_del_lines (from
, dvpos
);
14451 else if (dvpos
< 0)
14453 /* Scroll up last_unchanged_at_beg_vpos to the end of
14454 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14455 set_terminal_window (end
);
14457 /* Delete dvpos lines in front of
14458 last_unchanged_at_beg_vpos. ins_del_lines will set
14459 the cursor to the given vpos and emit |dvpos| delete
14461 ins_del_lines (from
+ dvpos
, dvpos
);
14463 /* On a dumb terminal insert dvpos empty lines at the
14465 if (!scroll_region_ok
)
14466 ins_del_lines (end
+ dvpos
, -dvpos
);
14469 set_terminal_window (0);
14475 /* Shift reused rows of the current matrix to the right position.
14476 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14478 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14479 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14482 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14483 bottom_vpos
, dvpos
);
14484 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14487 else if (dvpos
> 0)
14489 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14490 bottom_vpos
, dvpos
);
14491 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14492 first_unchanged_at_end_vpos
+ dvpos
, 0);
14495 /* For frame-based redisplay, make sure that current frame and window
14496 matrix are in sync with respect to glyph memory. */
14497 if (!FRAME_WINDOW_P (f
))
14498 sync_frame_with_window_matrix_rows (w
);
14500 /* Adjust buffer positions in reused rows. */
14502 increment_matrix_positions (current_matrix
,
14503 first_unchanged_at_end_vpos
+ dvpos
,
14504 bottom_vpos
, delta
, delta_bytes
);
14506 /* Adjust Y positions. */
14508 shift_glyph_matrix (w
, current_matrix
,
14509 first_unchanged_at_end_vpos
+ dvpos
,
14512 if (first_unchanged_at_end_row
)
14514 first_unchanged_at_end_row
+= dvpos
;
14515 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
14516 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
14517 first_unchanged_at_end_row
= NULL
;
14520 /* If scrolling up, there may be some lines to display at the end of
14522 last_text_row_at_end
= NULL
;
14525 /* Scrolling up can leave for example a partially visible line
14526 at the end of the window to be redisplayed. */
14527 /* Set last_row to the glyph row in the current matrix where the
14528 window end line is found. It has been moved up or down in
14529 the matrix by dvpos. */
14530 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
14531 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
14533 /* If last_row is the window end line, it should display text. */
14534 xassert (last_row
->displays_text_p
);
14536 /* If window end line was partially visible before, begin
14537 displaying at that line. Otherwise begin displaying with the
14538 line following it. */
14539 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
14541 init_to_row_start (&it
, w
, last_row
);
14542 it
.vpos
= last_vpos
;
14543 it
.current_y
= last_row
->y
;
14547 init_to_row_end (&it
, w
, last_row
);
14548 it
.vpos
= 1 + last_vpos
;
14549 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
14553 /* We may start in a continuation line. If so, we have to
14554 get the right continuation_lines_width and current_x. */
14555 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
14556 it
.hpos
= it
.current_x
= 0;
14558 /* Display the rest of the lines at the window end. */
14559 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14560 while (it
.current_y
< it
.last_visible_y
14561 && !fonts_changed_p
)
14563 /* Is it always sure that the display agrees with lines in
14564 the current matrix? I don't think so, so we mark rows
14565 displayed invalid in the current matrix by setting their
14566 enabled_p flag to zero. */
14567 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
14568 if (display_line (&it
))
14569 last_text_row_at_end
= it
.glyph_row
- 1;
14573 /* Update window_end_pos and window_end_vpos. */
14574 if (first_unchanged_at_end_row
14575 && !last_text_row_at_end
)
14577 /* Window end line if one of the preserved rows from the current
14578 matrix. Set row to the last row displaying text in current
14579 matrix starting at first_unchanged_at_end_row, after
14581 xassert (first_unchanged_at_end_row
->displays_text_p
);
14582 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
14583 first_unchanged_at_end_row
);
14584 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
14586 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14587 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14589 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
14590 xassert (w
->window_end_bytepos
>= 0);
14591 IF_DEBUG (debug_method_add (w
, "A"));
14593 else if (last_text_row_at_end
)
14596 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
14597 w
->window_end_bytepos
14598 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
14600 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
14601 xassert (w
->window_end_bytepos
>= 0);
14602 IF_DEBUG (debug_method_add (w
, "B"));
14604 else if (last_text_row
)
14606 /* We have displayed either to the end of the window or at the
14607 end of the window, i.e. the last row with text is to be found
14608 in the desired matrix. */
14610 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14611 w
->window_end_bytepos
14612 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14614 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
14615 xassert (w
->window_end_bytepos
>= 0);
14617 else if (first_unchanged_at_end_row
== NULL
14618 && last_text_row
== NULL
14619 && last_text_row_at_end
== NULL
)
14621 /* Displayed to end of window, but no line containing text was
14622 displayed. Lines were deleted at the end of the window. */
14623 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
14624 int vpos
= XFASTINT (w
->window_end_vpos
);
14625 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
14626 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
14629 row
== NULL
&& vpos
>= first_vpos
;
14630 --vpos
, --current_row
, --desired_row
)
14632 if (desired_row
->enabled_p
)
14634 if (desired_row
->displays_text_p
)
14637 else if (current_row
->displays_text_p
)
14641 xassert (row
!= NULL
);
14642 w
->window_end_vpos
= make_number (vpos
+ 1);
14643 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14644 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14645 xassert (w
->window_end_bytepos
>= 0);
14646 IF_DEBUG (debug_method_add (w
, "C"));
14651 #if 0 /* This leads to problems, for instance when the cursor is
14652 at ZV, and the cursor line displays no text. */
14653 /* Disable rows below what's displayed in the window. This makes
14654 debugging easier. */
14655 enable_glyph_matrix_rows (current_matrix
,
14656 XFASTINT (w
->window_end_vpos
) + 1,
14660 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
14661 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
14663 /* Record that display has not been completed. */
14664 w
->window_end_valid
= Qnil
;
14665 w
->desired_matrix
->no_scrolling_p
= 1;
14673 /***********************************************************************
14674 More debugging support
14675 ***********************************************************************/
14679 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
14680 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
14681 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
14684 /* Dump the contents of glyph matrix MATRIX on stderr.
14686 GLYPHS 0 means don't show glyph contents.
14687 GLYPHS 1 means show glyphs in short form
14688 GLYPHS > 1 means show glyphs in long form. */
14691 dump_glyph_matrix (matrix
, glyphs
)
14692 struct glyph_matrix
*matrix
;
14696 for (i
= 0; i
< matrix
->nrows
; ++i
)
14697 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
14701 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
14702 the glyph row and area where the glyph comes from. */
14705 dump_glyph (row
, glyph
, area
)
14706 struct glyph_row
*row
;
14707 struct glyph
*glyph
;
14710 if (glyph
->type
== CHAR_GLYPH
)
14713 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14714 glyph
- row
->glyphs
[TEXT_AREA
],
14717 (BUFFERP (glyph
->object
)
14719 : (STRINGP (glyph
->object
)
14722 glyph
->pixel_width
,
14724 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
14728 glyph
->left_box_line_p
,
14729 glyph
->right_box_line_p
);
14731 else if (glyph
->type
== STRETCH_GLYPH
)
14734 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14735 glyph
- row
->glyphs
[TEXT_AREA
],
14738 (BUFFERP (glyph
->object
)
14740 : (STRINGP (glyph
->object
)
14743 glyph
->pixel_width
,
14747 glyph
->left_box_line_p
,
14748 glyph
->right_box_line_p
);
14750 else if (glyph
->type
== IMAGE_GLYPH
)
14753 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14754 glyph
- row
->glyphs
[TEXT_AREA
],
14757 (BUFFERP (glyph
->object
)
14759 : (STRINGP (glyph
->object
)
14762 glyph
->pixel_width
,
14766 glyph
->left_box_line_p
,
14767 glyph
->right_box_line_p
);
14772 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
14773 GLYPHS 0 means don't show glyph contents.
14774 GLYPHS 1 means show glyphs in short form
14775 GLYPHS > 1 means show glyphs in long form. */
14778 dump_glyph_row (row
, vpos
, glyphs
)
14779 struct glyph_row
*row
;
14784 fprintf (stderr
, "Row Start End Used oEI><\\CTZFesm X Y W H V A P\n");
14785 fprintf (stderr
, "======================================================================\n");
14787 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
14788 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
14790 MATRIX_ROW_START_CHARPOS (row
),
14791 MATRIX_ROW_END_CHARPOS (row
),
14792 row
->used
[TEXT_AREA
],
14793 row
->contains_overlapping_glyphs_p
,
14795 row
->truncated_on_left_p
,
14796 row
->truncated_on_right_p
,
14798 MATRIX_ROW_CONTINUATION_LINE_P (row
),
14799 row
->displays_text_p
,
14802 row
->ends_in_middle_of_char_p
,
14803 row
->starts_in_middle_of_char_p
,
14809 row
->visible_height
,
14812 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
14813 row
->end
.overlay_string_index
,
14814 row
->continuation_lines_width
);
14815 fprintf (stderr
, "%9d %5d\n",
14816 CHARPOS (row
->start
.string_pos
),
14817 CHARPOS (row
->end
.string_pos
));
14818 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
14819 row
->end
.dpvec_index
);
14826 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14828 struct glyph
*glyph
= row
->glyphs
[area
];
14829 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
14831 /* Glyph for a line end in text. */
14832 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
14835 if (glyph
< glyph_end
)
14836 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
14838 for (; glyph
< glyph_end
; ++glyph
)
14839 dump_glyph (row
, glyph
, area
);
14842 else if (glyphs
== 1)
14846 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14848 char *s
= (char *) alloca (row
->used
[area
] + 1);
14851 for (i
= 0; i
< row
->used
[area
]; ++i
)
14853 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
14854 if (glyph
->type
== CHAR_GLYPH
14855 && glyph
->u
.ch
< 0x80
14856 && glyph
->u
.ch
>= ' ')
14857 s
[i
] = glyph
->u
.ch
;
14863 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
14869 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
14870 Sdump_glyph_matrix
, 0, 1, "p",
14871 doc
: /* Dump the current matrix of the selected window to stderr.
14872 Shows contents of glyph row structures. With non-nil
14873 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
14874 glyphs in short form, otherwise show glyphs in long form. */)
14876 Lisp_Object glyphs
;
14878 struct window
*w
= XWINDOW (selected_window
);
14879 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14881 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
14882 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
14883 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
14884 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
14885 fprintf (stderr
, "=============================================\n");
14886 dump_glyph_matrix (w
->current_matrix
,
14887 NILP (glyphs
) ? 0 : XINT (glyphs
));
14892 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
14893 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
14896 struct frame
*f
= XFRAME (selected_frame
);
14897 dump_glyph_matrix (f
->current_matrix
, 1);
14902 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
14903 doc
: /* Dump glyph row ROW to stderr.
14904 GLYPH 0 means don't dump glyphs.
14905 GLYPH 1 means dump glyphs in short form.
14906 GLYPH > 1 or omitted means dump glyphs in long form. */)
14908 Lisp_Object row
, glyphs
;
14910 struct glyph_matrix
*matrix
;
14913 CHECK_NUMBER (row
);
14914 matrix
= XWINDOW (selected_window
)->current_matrix
;
14916 if (vpos
>= 0 && vpos
< matrix
->nrows
)
14917 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
14919 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14924 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
14925 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
14926 GLYPH 0 means don't dump glyphs.
14927 GLYPH 1 means dump glyphs in short form.
14928 GLYPH > 1 or omitted means dump glyphs in long form. */)
14930 Lisp_Object row
, glyphs
;
14932 struct frame
*sf
= SELECTED_FRAME ();
14933 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
14936 CHECK_NUMBER (row
);
14938 if (vpos
>= 0 && vpos
< m
->nrows
)
14939 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
14940 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14945 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
14946 doc
: /* Toggle tracing of redisplay.
14947 With ARG, turn tracing on if and only if ARG is positive. */)
14952 trace_redisplay_p
= !trace_redisplay_p
;
14955 arg
= Fprefix_numeric_value (arg
);
14956 trace_redisplay_p
= XINT (arg
) > 0;
14963 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
14964 doc
: /* Like `format', but print result to stderr.
14965 usage: (trace-to-stderr STRING &rest OBJECTS) */)
14970 Lisp_Object s
= Fformat (nargs
, args
);
14971 fprintf (stderr
, "%s", SDATA (s
));
14975 #endif /* GLYPH_DEBUG */
14979 /***********************************************************************
14980 Building Desired Matrix Rows
14981 ***********************************************************************/
14983 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
14984 Used for non-window-redisplay windows, and for windows w/o left fringe. */
14986 static struct glyph_row
*
14987 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
14989 Lisp_Object overlay_arrow_string
;
14991 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14992 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14993 struct buffer
*old
= current_buffer
;
14994 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
14995 int arrow_len
= SCHARS (overlay_arrow_string
);
14996 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
14997 const unsigned char *p
;
15000 int n_glyphs_before
;
15002 set_buffer_temp (buffer
);
15003 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15004 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15005 SET_TEXT_POS (it
.position
, 0, 0);
15007 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15009 while (p
< arrow_end
)
15011 Lisp_Object face
, ilisp
;
15013 /* Get the next character. */
15015 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15017 it
.c
= *p
, it
.len
= 1;
15020 /* Get its face. */
15021 ilisp
= make_number (p
- arrow_string
);
15022 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15023 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15025 /* Compute its width, get its glyphs. */
15026 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15027 SET_TEXT_POS (it
.position
, -1, -1);
15028 PRODUCE_GLYPHS (&it
);
15030 /* If this character doesn't fit any more in the line, we have
15031 to remove some glyphs. */
15032 if (it
.current_x
> it
.last_visible_x
)
15034 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15039 set_buffer_temp (old
);
15040 return it
.glyph_row
;
15044 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15045 glyphs are only inserted for terminal frames since we can't really
15046 win with truncation glyphs when partially visible glyphs are
15047 involved. Which glyphs to insert is determined by
15048 produce_special_glyphs. */
15051 insert_left_trunc_glyphs (it
)
15054 struct it truncate_it
;
15055 struct glyph
*from
, *end
, *to
, *toend
;
15057 xassert (!FRAME_WINDOW_P (it
->f
));
15059 /* Get the truncation glyphs. */
15061 truncate_it
.current_x
= 0;
15062 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15063 truncate_it
.glyph_row
= &scratch_glyph_row
;
15064 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15065 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15066 truncate_it
.object
= make_number (0);
15067 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15069 /* Overwrite glyphs from IT with truncation glyphs. */
15070 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15071 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15072 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15073 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15078 /* There may be padding glyphs left over. Overwrite them too. */
15079 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15081 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15087 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15091 /* Compute the pixel height and width of IT->glyph_row.
15093 Most of the time, ascent and height of a display line will be equal
15094 to the max_ascent and max_height values of the display iterator
15095 structure. This is not the case if
15097 1. We hit ZV without displaying anything. In this case, max_ascent
15098 and max_height will be zero.
15100 2. We have some glyphs that don't contribute to the line height.
15101 (The glyph row flag contributes_to_line_height_p is for future
15102 pixmap extensions).
15104 The first case is easily covered by using default values because in
15105 these cases, the line height does not really matter, except that it
15106 must not be zero. */
15109 compute_line_metrics (it
)
15112 struct glyph_row
*row
= it
->glyph_row
;
15115 if (FRAME_WINDOW_P (it
->f
))
15117 int i
, min_y
, max_y
;
15119 /* The line may consist of one space only, that was added to
15120 place the cursor on it. If so, the row's height hasn't been
15122 if (row
->height
== 0)
15124 if (it
->max_ascent
+ it
->max_descent
== 0)
15125 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15126 row
->ascent
= it
->max_ascent
;
15127 row
->height
= it
->max_ascent
+ it
->max_descent
;
15128 row
->phys_ascent
= it
->max_phys_ascent
;
15129 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15130 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15133 /* Compute the width of this line. */
15134 row
->pixel_width
= row
->x
;
15135 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15136 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15138 xassert (row
->pixel_width
>= 0);
15139 xassert (row
->ascent
>= 0 && row
->height
> 0);
15141 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15142 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15144 /* If first line's physical ascent is larger than its logical
15145 ascent, use the physical ascent, and make the row taller.
15146 This makes accented characters fully visible. */
15147 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
15148 && row
->phys_ascent
> row
->ascent
)
15150 row
->height
+= row
->phys_ascent
- row
->ascent
;
15151 row
->ascent
= row
->phys_ascent
;
15154 /* Compute how much of the line is visible. */
15155 row
->visible_height
= row
->height
;
15157 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
15158 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
15160 if (row
->y
< min_y
)
15161 row
->visible_height
-= min_y
- row
->y
;
15162 if (row
->y
+ row
->height
> max_y
)
15163 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15167 row
->pixel_width
= row
->used
[TEXT_AREA
];
15168 if (row
->continued_p
)
15169 row
->pixel_width
-= it
->continuation_pixel_width
;
15170 else if (row
->truncated_on_right_p
)
15171 row
->pixel_width
-= it
->truncation_pixel_width
;
15172 row
->ascent
= row
->phys_ascent
= 0;
15173 row
->height
= row
->phys_height
= row
->visible_height
= 1;
15174 row
->extra_line_spacing
= 0;
15177 /* Compute a hash code for this row. */
15179 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15180 for (i
= 0; i
< row
->used
[area
]; ++i
)
15181 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
15182 + row
->glyphs
[area
][i
].u
.val
15183 + row
->glyphs
[area
][i
].face_id
15184 + row
->glyphs
[area
][i
].padding_p
15185 + (row
->glyphs
[area
][i
].type
<< 2));
15187 it
->max_ascent
= it
->max_descent
= 0;
15188 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
15192 /* Append one space to the glyph row of iterator IT if doing a
15193 window-based redisplay. The space has the same face as
15194 IT->face_id. Value is non-zero if a space was added.
15196 This function is called to make sure that there is always one glyph
15197 at the end of a glyph row that the cursor can be set on under
15198 window-systems. (If there weren't such a glyph we would not know
15199 how wide and tall a box cursor should be displayed).
15201 At the same time this space let's a nicely handle clearing to the
15202 end of the line if the row ends in italic text. */
15205 append_space_for_newline (it
, default_face_p
)
15207 int default_face_p
;
15209 if (FRAME_WINDOW_P (it
->f
))
15211 int n
= it
->glyph_row
->used
[TEXT_AREA
];
15213 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
15214 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
15216 /* Save some values that must not be changed.
15217 Must save IT->c and IT->len because otherwise
15218 ITERATOR_AT_END_P wouldn't work anymore after
15219 append_space_for_newline has been called. */
15220 enum display_element_type saved_what
= it
->what
;
15221 int saved_c
= it
->c
, saved_len
= it
->len
;
15222 int saved_x
= it
->current_x
;
15223 int saved_face_id
= it
->face_id
;
15224 struct text_pos saved_pos
;
15225 Lisp_Object saved_object
;
15228 saved_object
= it
->object
;
15229 saved_pos
= it
->position
;
15231 it
->what
= IT_CHARACTER
;
15232 bzero (&it
->position
, sizeof it
->position
);
15233 it
->object
= make_number (0);
15237 if (default_face_p
)
15238 it
->face_id
= DEFAULT_FACE_ID
;
15239 else if (it
->face_before_selective_p
)
15240 it
->face_id
= it
->saved_face_id
;
15241 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15242 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
15244 PRODUCE_GLYPHS (it
);
15246 it
->override_ascent
= -1;
15247 it
->constrain_row_ascent_descent_p
= 0;
15248 it
->current_x
= saved_x
;
15249 it
->object
= saved_object
;
15250 it
->position
= saved_pos
;
15251 it
->what
= saved_what
;
15252 it
->face_id
= saved_face_id
;
15253 it
->len
= saved_len
;
15263 /* Extend the face of the last glyph in the text area of IT->glyph_row
15264 to the end of the display line. Called from display_line.
15265 If the glyph row is empty, add a space glyph to it so that we
15266 know the face to draw. Set the glyph row flag fill_line_p. */
15269 extend_face_to_end_of_line (it
)
15273 struct frame
*f
= it
->f
;
15275 /* If line is already filled, do nothing. */
15276 if (it
->current_x
>= it
->last_visible_x
)
15279 /* Face extension extends the background and box of IT->face_id
15280 to the end of the line. If the background equals the background
15281 of the frame, we don't have to do anything. */
15282 if (it
->face_before_selective_p
)
15283 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
15285 face
= FACE_FROM_ID (f
, it
->face_id
);
15287 if (FRAME_WINDOW_P (f
)
15288 && face
->box
== FACE_NO_BOX
15289 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
15293 /* Set the glyph row flag indicating that the face of the last glyph
15294 in the text area has to be drawn to the end of the text area. */
15295 it
->glyph_row
->fill_line_p
= 1;
15297 /* If current character of IT is not ASCII, make sure we have the
15298 ASCII face. This will be automatically undone the next time
15299 get_next_display_element returns a multibyte character. Note
15300 that the character will always be single byte in unibyte text. */
15301 if (!SINGLE_BYTE_CHAR_P (it
->c
))
15303 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
15306 if (FRAME_WINDOW_P (f
))
15308 /* If the row is empty, add a space with the current face of IT,
15309 so that we know which face to draw. */
15310 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
15312 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
15313 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
15314 it
->glyph_row
->used
[TEXT_AREA
] = 1;
15319 /* Save some values that must not be changed. */
15320 int saved_x
= it
->current_x
;
15321 struct text_pos saved_pos
;
15322 Lisp_Object saved_object
;
15323 enum display_element_type saved_what
= it
->what
;
15324 int saved_face_id
= it
->face_id
;
15326 saved_object
= it
->object
;
15327 saved_pos
= it
->position
;
15329 it
->what
= IT_CHARACTER
;
15330 bzero (&it
->position
, sizeof it
->position
);
15331 it
->object
= make_number (0);
15334 it
->face_id
= face
->id
;
15336 PRODUCE_GLYPHS (it
);
15338 while (it
->current_x
<= it
->last_visible_x
)
15339 PRODUCE_GLYPHS (it
);
15341 /* Don't count these blanks really. It would let us insert a left
15342 truncation glyph below and make us set the cursor on them, maybe. */
15343 it
->current_x
= saved_x
;
15344 it
->object
= saved_object
;
15345 it
->position
= saved_pos
;
15346 it
->what
= saved_what
;
15347 it
->face_id
= saved_face_id
;
15352 /* Value is non-zero if text starting at CHARPOS in current_buffer is
15353 trailing whitespace. */
15356 trailing_whitespace_p (charpos
)
15359 int bytepos
= CHAR_TO_BYTE (charpos
);
15362 while (bytepos
< ZV_BYTE
15363 && (c
= FETCH_CHAR (bytepos
),
15364 c
== ' ' || c
== '\t'))
15367 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
15369 if (bytepos
!= PT_BYTE
)
15376 /* Highlight trailing whitespace, if any, in ROW. */
15379 highlight_trailing_whitespace (f
, row
)
15381 struct glyph_row
*row
;
15383 int used
= row
->used
[TEXT_AREA
];
15387 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
15388 struct glyph
*glyph
= start
+ used
- 1;
15390 /* Skip over glyphs inserted to display the cursor at the
15391 end of a line, for extending the face of the last glyph
15392 to the end of the line on terminals, and for truncation
15393 and continuation glyphs. */
15394 while (glyph
>= start
15395 && glyph
->type
== CHAR_GLYPH
15396 && INTEGERP (glyph
->object
))
15399 /* If last glyph is a space or stretch, and it's trailing
15400 whitespace, set the face of all trailing whitespace glyphs in
15401 IT->glyph_row to `trailing-whitespace'. */
15403 && BUFFERP (glyph
->object
)
15404 && (glyph
->type
== STRETCH_GLYPH
15405 || (glyph
->type
== CHAR_GLYPH
15406 && glyph
->u
.ch
== ' '))
15407 && trailing_whitespace_p (glyph
->charpos
))
15409 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
15413 while (glyph
>= start
15414 && BUFFERP (glyph
->object
)
15415 && (glyph
->type
== STRETCH_GLYPH
15416 || (glyph
->type
== CHAR_GLYPH
15417 && glyph
->u
.ch
== ' ')))
15418 (glyph
--)->face_id
= face_id
;
15424 /* Value is non-zero if glyph row ROW in window W should be
15425 used to hold the cursor. */
15428 cursor_row_p (w
, row
)
15430 struct glyph_row
*row
;
15432 int cursor_row_p
= 1;
15434 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15436 /* If the row ends with a newline from a string, we don't want
15437 the cursor there, but we still want it at the start of the
15438 string if the string starts in this row.
15439 If the row is continued it doesn't end in a newline. */
15440 if (CHARPOS (row
->end
.string_pos
) >= 0)
15441 cursor_row_p
= (row
->continued_p
15442 || PT
>= MATRIX_ROW_START_CHARPOS (row
));
15443 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15445 /* If the row ends in middle of a real character,
15446 and the line is continued, we want the cursor here.
15447 That's because MATRIX_ROW_END_CHARPOS would equal
15448 PT if PT is before the character. */
15449 if (!row
->ends_in_ellipsis_p
)
15450 cursor_row_p
= row
->continued_p
;
15452 /* If the row ends in an ellipsis, then
15453 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15454 We want that position to be displayed after the ellipsis. */
15457 /* If the row ends at ZV, display the cursor at the end of that
15458 row instead of at the start of the row below. */
15459 else if (row
->ends_at_zv_p
)
15465 return cursor_row_p
;
15469 /* Construct the glyph row IT->glyph_row in the desired matrix of
15470 IT->w from text at the current position of IT. See dispextern.h
15471 for an overview of struct it. Value is non-zero if
15472 IT->glyph_row displays text, as opposed to a line displaying ZV
15479 struct glyph_row
*row
= it
->glyph_row
;
15480 Lisp_Object overlay_arrow_string
;
15482 /* We always start displaying at hpos zero even if hscrolled. */
15483 xassert (it
->hpos
== 0 && it
->current_x
== 0);
15485 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
15486 >= it
->w
->desired_matrix
->nrows
)
15488 it
->w
->nrows_scale_factor
++;
15489 fonts_changed_p
= 1;
15493 /* Is IT->w showing the region? */
15494 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
15496 /* Clear the result glyph row and enable it. */
15497 prepare_desired_row (row
);
15499 row
->y
= it
->current_y
;
15500 row
->start
= it
->start
;
15501 row
->continuation_lines_width
= it
->continuation_lines_width
;
15502 row
->displays_text_p
= 1;
15503 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
15504 it
->starts_in_middle_of_char_p
= 0;
15506 /* Arrange the overlays nicely for our purposes. Usually, we call
15507 display_line on only one line at a time, in which case this
15508 can't really hurt too much, or we call it on lines which appear
15509 one after another in the buffer, in which case all calls to
15510 recenter_overlay_lists but the first will be pretty cheap. */
15511 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
15513 /* Move over display elements that are not visible because we are
15514 hscrolled. This may stop at an x-position < IT->first_visible_x
15515 if the first glyph is partially visible or if we hit a line end. */
15516 if (it
->current_x
< it
->first_visible_x
)
15518 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
15519 MOVE_TO_POS
| MOVE_TO_X
);
15522 /* Get the initial row height. This is either the height of the
15523 text hscrolled, if there is any, or zero. */
15524 row
->ascent
= it
->max_ascent
;
15525 row
->height
= it
->max_ascent
+ it
->max_descent
;
15526 row
->phys_ascent
= it
->max_phys_ascent
;
15527 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15528 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15530 /* Loop generating characters. The loop is left with IT on the next
15531 character to display. */
15534 int n_glyphs_before
, hpos_before
, x_before
;
15536 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
15538 /* Retrieve the next thing to display. Value is zero if end of
15540 if (!get_next_display_element (it
))
15542 /* Maybe add a space at the end of this line that is used to
15543 display the cursor there under X. Set the charpos of the
15544 first glyph of blank lines not corresponding to any text
15546 #ifdef HAVE_WINDOW_SYSTEM
15547 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15548 row
->exact_window_width_line_p
= 1;
15550 #endif /* HAVE_WINDOW_SYSTEM */
15551 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
15552 || row
->used
[TEXT_AREA
] == 0)
15554 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
15555 row
->displays_text_p
= 0;
15557 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
15558 && (!MINI_WINDOW_P (it
->w
)
15559 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
15560 row
->indicate_empty_line_p
= 1;
15563 it
->continuation_lines_width
= 0;
15564 row
->ends_at_zv_p
= 1;
15568 /* Now, get the metrics of what we want to display. This also
15569 generates glyphs in `row' (which is IT->glyph_row). */
15570 n_glyphs_before
= row
->used
[TEXT_AREA
];
15573 /* Remember the line height so far in case the next element doesn't
15574 fit on the line. */
15575 if (!it
->truncate_lines_p
)
15577 ascent
= it
->max_ascent
;
15578 descent
= it
->max_descent
;
15579 phys_ascent
= it
->max_phys_ascent
;
15580 phys_descent
= it
->max_phys_descent
;
15583 PRODUCE_GLYPHS (it
);
15585 /* If this display element was in marginal areas, continue with
15587 if (it
->area
!= TEXT_AREA
)
15589 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15590 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15591 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15592 row
->phys_height
= max (row
->phys_height
,
15593 it
->max_phys_ascent
+ it
->max_phys_descent
);
15594 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15595 it
->max_extra_line_spacing
);
15596 set_iterator_to_next (it
, 1);
15600 /* Does the display element fit on the line? If we truncate
15601 lines, we should draw past the right edge of the window. If
15602 we don't truncate, we want to stop so that we can display the
15603 continuation glyph before the right margin. If lines are
15604 continued, there are two possible strategies for characters
15605 resulting in more than 1 glyph (e.g. tabs): Display as many
15606 glyphs as possible in this line and leave the rest for the
15607 continuation line, or display the whole element in the next
15608 line. Original redisplay did the former, so we do it also. */
15609 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
15610 hpos_before
= it
->hpos
;
15613 if (/* Not a newline. */
15615 /* Glyphs produced fit entirely in the line. */
15616 && it
->current_x
< it
->last_visible_x
)
15618 it
->hpos
+= nglyphs
;
15619 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15620 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15621 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15622 row
->phys_height
= max (row
->phys_height
,
15623 it
->max_phys_ascent
+ it
->max_phys_descent
);
15624 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15625 it
->max_extra_line_spacing
);
15626 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
15627 row
->x
= x
- it
->first_visible_x
;
15632 struct glyph
*glyph
;
15634 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
15636 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
15637 new_x
= x
+ glyph
->pixel_width
;
15639 if (/* Lines are continued. */
15640 !it
->truncate_lines_p
15641 && (/* Glyph doesn't fit on the line. */
15642 new_x
> it
->last_visible_x
15643 /* Or it fits exactly on a window system frame. */
15644 || (new_x
== it
->last_visible_x
15645 && FRAME_WINDOW_P (it
->f
))))
15647 /* End of a continued line. */
15650 || (new_x
== it
->last_visible_x
15651 && FRAME_WINDOW_P (it
->f
)))
15653 /* Current glyph is the only one on the line or
15654 fits exactly on the line. We must continue
15655 the line because we can't draw the cursor
15656 after the glyph. */
15657 row
->continued_p
= 1;
15658 it
->current_x
= new_x
;
15659 it
->continuation_lines_width
+= new_x
;
15661 if (i
== nglyphs
- 1)
15663 set_iterator_to_next (it
, 1);
15664 #ifdef HAVE_WINDOW_SYSTEM
15665 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15667 if (!get_next_display_element (it
))
15669 row
->exact_window_width_line_p
= 1;
15670 it
->continuation_lines_width
= 0;
15671 row
->continued_p
= 0;
15672 row
->ends_at_zv_p
= 1;
15674 else if (ITERATOR_AT_END_OF_LINE_P (it
))
15676 row
->continued_p
= 0;
15677 row
->exact_window_width_line_p
= 1;
15680 #endif /* HAVE_WINDOW_SYSTEM */
15683 else if (CHAR_GLYPH_PADDING_P (*glyph
)
15684 && !FRAME_WINDOW_P (it
->f
))
15686 /* A padding glyph that doesn't fit on this line.
15687 This means the whole character doesn't fit
15689 row
->used
[TEXT_AREA
] = n_glyphs_before
;
15691 /* Fill the rest of the row with continuation
15692 glyphs like in 20.x. */
15693 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
15694 < row
->glyphs
[1 + TEXT_AREA
])
15695 produce_special_glyphs (it
, IT_CONTINUATION
);
15697 row
->continued_p
= 1;
15698 it
->current_x
= x_before
;
15699 it
->continuation_lines_width
+= x_before
;
15701 /* Restore the height to what it was before the
15702 element not fitting on the line. */
15703 it
->max_ascent
= ascent
;
15704 it
->max_descent
= descent
;
15705 it
->max_phys_ascent
= phys_ascent
;
15706 it
->max_phys_descent
= phys_descent
;
15708 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
15710 /* A TAB that extends past the right edge of the
15711 window. This produces a single glyph on
15712 window system frames. We leave the glyph in
15713 this row and let it fill the row, but don't
15714 consume the TAB. */
15715 it
->continuation_lines_width
+= it
->last_visible_x
;
15716 row
->ends_in_middle_of_char_p
= 1;
15717 row
->continued_p
= 1;
15718 glyph
->pixel_width
= it
->last_visible_x
- x
;
15719 it
->starts_in_middle_of_char_p
= 1;
15723 /* Something other than a TAB that draws past
15724 the right edge of the window. Restore
15725 positions to values before the element. */
15726 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15728 /* Display continuation glyphs. */
15729 if (!FRAME_WINDOW_P (it
->f
))
15730 produce_special_glyphs (it
, IT_CONTINUATION
);
15731 row
->continued_p
= 1;
15733 it
->current_x
= x_before
;
15734 it
->continuation_lines_width
+= x
;
15735 extend_face_to_end_of_line (it
);
15737 if (nglyphs
> 1 && i
> 0)
15739 row
->ends_in_middle_of_char_p
= 1;
15740 it
->starts_in_middle_of_char_p
= 1;
15743 /* Restore the height to what it was before the
15744 element not fitting on the line. */
15745 it
->max_ascent
= ascent
;
15746 it
->max_descent
= descent
;
15747 it
->max_phys_ascent
= phys_ascent
;
15748 it
->max_phys_descent
= phys_descent
;
15753 else if (new_x
> it
->first_visible_x
)
15755 /* Increment number of glyphs actually displayed. */
15758 if (x
< it
->first_visible_x
)
15759 /* Glyph is partially visible, i.e. row starts at
15760 negative X position. */
15761 row
->x
= x
- it
->first_visible_x
;
15765 /* Glyph is completely off the left margin of the
15766 window. This should not happen because of the
15767 move_it_in_display_line at the start of this
15768 function, unless the text display area of the
15769 window is empty. */
15770 xassert (it
->first_visible_x
<= it
->last_visible_x
);
15774 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15775 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15776 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15777 row
->phys_height
= max (row
->phys_height
,
15778 it
->max_phys_ascent
+ it
->max_phys_descent
);
15779 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15780 it
->max_extra_line_spacing
);
15782 /* End of this display line if row is continued. */
15783 if (row
->continued_p
|| row
->ends_at_zv_p
)
15788 /* Is this a line end? If yes, we're also done, after making
15789 sure that a non-default face is extended up to the right
15790 margin of the window. */
15791 if (ITERATOR_AT_END_OF_LINE_P (it
))
15793 int used_before
= row
->used
[TEXT_AREA
];
15795 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
15797 #ifdef HAVE_WINDOW_SYSTEM
15798 /* Add a space at the end of the line that is used to
15799 display the cursor there. */
15800 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15801 append_space_for_newline (it
, 0);
15802 #endif /* HAVE_WINDOW_SYSTEM */
15804 /* Extend the face to the end of the line. */
15805 extend_face_to_end_of_line (it
);
15807 /* Make sure we have the position. */
15808 if (used_before
== 0)
15809 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
15811 /* Consume the line end. This skips over invisible lines. */
15812 set_iterator_to_next (it
, 1);
15813 it
->continuation_lines_width
= 0;
15817 /* Proceed with next display element. Note that this skips
15818 over lines invisible because of selective display. */
15819 set_iterator_to_next (it
, 1);
15821 /* If we truncate lines, we are done when the last displayed
15822 glyphs reach past the right margin of the window. */
15823 if (it
->truncate_lines_p
15824 && (FRAME_WINDOW_P (it
->f
)
15825 ? (it
->current_x
>= it
->last_visible_x
)
15826 : (it
->current_x
> it
->last_visible_x
)))
15828 /* Maybe add truncation glyphs. */
15829 if (!FRAME_WINDOW_P (it
->f
))
15833 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15834 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15837 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15839 row
->used
[TEXT_AREA
] = i
;
15840 produce_special_glyphs (it
, IT_TRUNCATION
);
15843 #ifdef HAVE_WINDOW_SYSTEM
15846 /* Don't truncate if we can overflow newline into fringe. */
15847 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15849 if (!get_next_display_element (it
))
15851 it
->continuation_lines_width
= 0;
15852 row
->ends_at_zv_p
= 1;
15853 row
->exact_window_width_line_p
= 1;
15856 if (ITERATOR_AT_END_OF_LINE_P (it
))
15858 row
->exact_window_width_line_p
= 1;
15859 goto at_end_of_line
;
15863 #endif /* HAVE_WINDOW_SYSTEM */
15865 row
->truncated_on_right_p
= 1;
15866 it
->continuation_lines_width
= 0;
15867 reseat_at_next_visible_line_start (it
, 0);
15868 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
15869 it
->hpos
= hpos_before
;
15870 it
->current_x
= x_before
;
15875 /* If line is not empty and hscrolled, maybe insert truncation glyphs
15876 at the left window margin. */
15877 if (it
->first_visible_x
15878 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
15880 if (!FRAME_WINDOW_P (it
->f
))
15881 insert_left_trunc_glyphs (it
);
15882 row
->truncated_on_left_p
= 1;
15885 /* If the start of this line is the overlay arrow-position, then
15886 mark this glyph row as the one containing the overlay arrow.
15887 This is clearly a mess with variable size fonts. It would be
15888 better to let it be displayed like cursors under X. */
15889 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
15890 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
15891 !NILP (overlay_arrow_string
)))
15893 /* Overlay arrow in window redisplay is a fringe bitmap. */
15894 if (STRINGP (overlay_arrow_string
))
15896 struct glyph_row
*arrow_row
15897 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
15898 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
15899 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
15900 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
15901 struct glyph
*p2
, *end
;
15903 /* Copy the arrow glyphs. */
15904 while (glyph
< arrow_end
)
15907 /* Throw away padding glyphs. */
15909 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15910 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
15916 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
15921 xassert (INTEGERP (overlay_arrow_string
));
15922 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
15924 overlay_arrow_seen
= 1;
15927 /* Compute pixel dimensions of this line. */
15928 compute_line_metrics (it
);
15930 /* Remember the position at which this line ends. */
15931 row
->end
= it
->current
;
15933 /* Record whether this row ends inside an ellipsis. */
15934 row
->ends_in_ellipsis_p
15935 = (it
->method
== GET_FROM_DISPLAY_VECTOR
15936 && it
->ellipsis_p
);
15938 /* Save fringe bitmaps in this row. */
15939 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
15940 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
15941 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
15942 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
15944 it
->left_user_fringe_bitmap
= 0;
15945 it
->left_user_fringe_face_id
= 0;
15946 it
->right_user_fringe_bitmap
= 0;
15947 it
->right_user_fringe_face_id
= 0;
15949 /* Maybe set the cursor. */
15950 if (it
->w
->cursor
.vpos
< 0
15951 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
15952 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15953 && cursor_row_p (it
->w
, row
))
15954 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
15956 /* Highlight trailing whitespace. */
15957 if (!NILP (Vshow_trailing_whitespace
))
15958 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
15960 /* Prepare for the next line. This line starts horizontally at (X
15961 HPOS) = (0 0). Vertical positions are incremented. As a
15962 convenience for the caller, IT->glyph_row is set to the next
15964 it
->current_x
= it
->hpos
= 0;
15965 it
->current_y
+= row
->height
;
15968 it
->start
= it
->current
;
15969 return row
->displays_text_p
;
15974 /***********************************************************************
15976 ***********************************************************************/
15978 /* Redisplay the menu bar in the frame for window W.
15980 The menu bar of X frames that don't have X toolkit support is
15981 displayed in a special window W->frame->menu_bar_window.
15983 The menu bar of terminal frames is treated specially as far as
15984 glyph matrices are concerned. Menu bar lines are not part of
15985 windows, so the update is done directly on the frame matrix rows
15986 for the menu bar. */
15989 display_menu_bar (w
)
15992 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15997 /* Don't do all this for graphical frames. */
15999 if (!NILP (Vwindow_system
))
16002 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
16007 if (FRAME_MAC_P (f
))
16011 #ifdef USE_X_TOOLKIT
16012 xassert (!FRAME_WINDOW_P (f
));
16013 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
16014 it
.first_visible_x
= 0;
16015 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16016 #else /* not USE_X_TOOLKIT */
16017 if (FRAME_WINDOW_P (f
))
16019 /* Menu bar lines are displayed in the desired matrix of the
16020 dummy window menu_bar_window. */
16021 struct window
*menu_w
;
16022 xassert (WINDOWP (f
->menu_bar_window
));
16023 menu_w
= XWINDOW (f
->menu_bar_window
);
16024 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
16026 it
.first_visible_x
= 0;
16027 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16031 /* This is a TTY frame, i.e. character hpos/vpos are used as
16033 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
16035 it
.first_visible_x
= 0;
16036 it
.last_visible_x
= FRAME_COLS (f
);
16038 #endif /* not USE_X_TOOLKIT */
16040 if (! mode_line_inverse_video
)
16041 /* Force the menu-bar to be displayed in the default face. */
16042 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16044 /* Clear all rows of the menu bar. */
16045 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
16047 struct glyph_row
*row
= it
.glyph_row
+ i
;
16048 clear_glyph_row (row
);
16049 row
->enabled_p
= 1;
16050 row
->full_width_p
= 1;
16053 /* Display all items of the menu bar. */
16054 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
16055 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
16057 Lisp_Object string
;
16059 /* Stop at nil string. */
16060 string
= AREF (items
, i
+ 1);
16064 /* Remember where item was displayed. */
16065 AREF (items
, i
+ 3) = make_number (it
.hpos
);
16067 /* Display the item, pad with one space. */
16068 if (it
.current_x
< it
.last_visible_x
)
16069 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
16070 SCHARS (string
) + 1, 0, 0, -1);
16073 /* Fill out the line with spaces. */
16074 if (it
.current_x
< it
.last_visible_x
)
16075 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
16077 /* Compute the total height of the lines. */
16078 compute_line_metrics (&it
);
16083 /***********************************************************************
16085 ***********************************************************************/
16087 /* Redisplay mode lines in the window tree whose root is WINDOW. If
16088 FORCE is non-zero, redisplay mode lines unconditionally.
16089 Otherwise, redisplay only mode lines that are garbaged. Value is
16090 the number of windows whose mode lines were redisplayed. */
16093 redisplay_mode_lines (window
, force
)
16094 Lisp_Object window
;
16099 while (!NILP (window
))
16101 struct window
*w
= XWINDOW (window
);
16103 if (WINDOWP (w
->hchild
))
16104 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
16105 else if (WINDOWP (w
->vchild
))
16106 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
16108 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
16109 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
16111 struct text_pos lpoint
;
16112 struct buffer
*old
= current_buffer
;
16114 /* Set the window's buffer for the mode line display. */
16115 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16116 set_buffer_internal_1 (XBUFFER (w
->buffer
));
16118 /* Point refers normally to the selected window. For any
16119 other window, set up appropriate value. */
16120 if (!EQ (window
, selected_window
))
16122 struct text_pos pt
;
16124 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
16125 if (CHARPOS (pt
) < BEGV
)
16126 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16127 else if (CHARPOS (pt
) > (ZV
- 1))
16128 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
16130 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
16133 /* Display mode lines. */
16134 clear_glyph_matrix (w
->desired_matrix
);
16135 if (display_mode_lines (w
))
16138 w
->must_be_updated_p
= 1;
16141 /* Restore old settings. */
16142 set_buffer_internal_1 (old
);
16143 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16153 /* Display the mode and/or top line of window W. Value is the number
16154 of mode lines displayed. */
16157 display_mode_lines (w
)
16160 Lisp_Object old_selected_window
, old_selected_frame
;
16163 old_selected_frame
= selected_frame
;
16164 selected_frame
= w
->frame
;
16165 old_selected_window
= selected_window
;
16166 XSETWINDOW (selected_window
, w
);
16168 /* These will be set while the mode line specs are processed. */
16169 line_number_displayed
= 0;
16170 w
->column_number_displayed
= Qnil
;
16172 if (WINDOW_WANTS_MODELINE_P (w
))
16174 struct window
*sel_w
= XWINDOW (old_selected_window
);
16176 /* Select mode line face based on the real selected window. */
16177 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
16178 current_buffer
->mode_line_format
);
16182 if (WINDOW_WANTS_HEADER_LINE_P (w
))
16184 display_mode_line (w
, HEADER_LINE_FACE_ID
,
16185 current_buffer
->header_line_format
);
16189 selected_frame
= old_selected_frame
;
16190 selected_window
= old_selected_window
;
16195 /* Display mode or top line of window W. FACE_ID specifies which line
16196 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
16197 FORMAT is the mode line format to display. Value is the pixel
16198 height of the mode line displayed. */
16201 display_mode_line (w
, face_id
, format
)
16203 enum face_id face_id
;
16204 Lisp_Object format
;
16208 int count
= SPECPDL_INDEX ();
16210 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16211 prepare_desired_row (it
.glyph_row
);
16213 it
.glyph_row
->mode_line_p
= 1;
16215 if (! mode_line_inverse_video
)
16216 /* Force the mode-line to be displayed in the default face. */
16217 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16219 record_unwind_protect (unwind_format_mode_line
,
16220 format_mode_line_unwind_data (NULL
, 0));
16222 mode_line_target
= MODE_LINE_DISPLAY
;
16224 /* Temporarily make frame's keyboard the current kboard so that
16225 kboard-local variables in the mode_line_format will get the right
16227 push_frame_kboard (it
.f
);
16228 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16229 pop_frame_kboard ();
16231 unbind_to (count
, Qnil
);
16233 /* Fill up with spaces. */
16234 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
16236 compute_line_metrics (&it
);
16237 it
.glyph_row
->full_width_p
= 1;
16238 it
.glyph_row
->continued_p
= 0;
16239 it
.glyph_row
->truncated_on_left_p
= 0;
16240 it
.glyph_row
->truncated_on_right_p
= 0;
16242 /* Make a 3D mode-line have a shadow at its right end. */
16243 face
= FACE_FROM_ID (it
.f
, face_id
);
16244 extend_face_to_end_of_line (&it
);
16245 if (face
->box
!= FACE_NO_BOX
)
16247 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
16248 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
16249 last
->right_box_line_p
= 1;
16252 return it
.glyph_row
->height
;
16255 /* Move element ELT in LIST to the front of LIST.
16256 Return the updated list. */
16259 move_elt_to_front (elt
, list
)
16260 Lisp_Object elt
, list
;
16262 register Lisp_Object tail
, prev
;
16263 register Lisp_Object tem
;
16267 while (CONSP (tail
))
16273 /* Splice out the link TAIL. */
16275 list
= XCDR (tail
);
16277 Fsetcdr (prev
, XCDR (tail
));
16279 /* Now make it the first. */
16280 Fsetcdr (tail
, list
);
16285 tail
= XCDR (tail
);
16289 /* Not found--return unchanged LIST. */
16293 /* Contribute ELT to the mode line for window IT->w. How it
16294 translates into text depends on its data type.
16296 IT describes the display environment in which we display, as usual.
16298 DEPTH is the depth in recursion. It is used to prevent
16299 infinite recursion here.
16301 FIELD_WIDTH is the number of characters the display of ELT should
16302 occupy in the mode line, and PRECISION is the maximum number of
16303 characters to display from ELT's representation. See
16304 display_string for details.
16306 Returns the hpos of the end of the text generated by ELT.
16308 PROPS is a property list to add to any string we encounter.
16310 If RISKY is nonzero, remove (disregard) any properties in any string
16311 we encounter, and ignore :eval and :propertize.
16313 The global variable `mode_line_target' determines whether the
16314 output is passed to `store_mode_line_noprop',
16315 `store_mode_line_string', or `display_string'. */
16318 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
16321 int field_width
, precision
;
16322 Lisp_Object elt
, props
;
16325 int n
= 0, field
, prec
;
16330 elt
= build_string ("*too-deep*");
16334 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
16338 /* A string: output it and check for %-constructs within it. */
16342 if (SCHARS (elt
) > 0
16343 && (!NILP (props
) || risky
))
16345 Lisp_Object oprops
, aelt
;
16346 oprops
= Ftext_properties_at (make_number (0), elt
);
16348 /* If the starting string's properties are not what
16349 we want, translate the string. Also, if the string
16350 is risky, do that anyway. */
16352 if (NILP (Fequal (props
, oprops
)) || risky
)
16354 /* If the starting string has properties,
16355 merge the specified ones onto the existing ones. */
16356 if (! NILP (oprops
) && !risky
)
16360 oprops
= Fcopy_sequence (oprops
);
16362 while (CONSP (tem
))
16364 oprops
= Fplist_put (oprops
, XCAR (tem
),
16365 XCAR (XCDR (tem
)));
16366 tem
= XCDR (XCDR (tem
));
16371 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
16372 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
16374 /* AELT is what we want. Move it to the front
16375 without consing. */
16377 mode_line_proptrans_alist
16378 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
16384 /* If AELT has the wrong props, it is useless.
16385 so get rid of it. */
16387 mode_line_proptrans_alist
16388 = Fdelq (aelt
, mode_line_proptrans_alist
);
16390 elt
= Fcopy_sequence (elt
);
16391 Fset_text_properties (make_number (0), Flength (elt
),
16393 /* Add this item to mode_line_proptrans_alist. */
16394 mode_line_proptrans_alist
16395 = Fcons (Fcons (elt
, props
),
16396 mode_line_proptrans_alist
);
16397 /* Truncate mode_line_proptrans_alist
16398 to at most 50 elements. */
16399 tem
= Fnthcdr (make_number (50),
16400 mode_line_proptrans_alist
);
16402 XSETCDR (tem
, Qnil
);
16411 prec
= precision
- n
;
16412 switch (mode_line_target
)
16414 case MODE_LINE_NOPROP
:
16415 case MODE_LINE_TITLE
:
16416 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
16418 case MODE_LINE_STRING
:
16419 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
16421 case MODE_LINE_DISPLAY
:
16422 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
16423 0, prec
, 0, STRING_MULTIBYTE (elt
));
16430 /* Handle the non-literal case. */
16432 while ((precision
<= 0 || n
< precision
)
16433 && SREF (elt
, offset
) != 0
16434 && (mode_line_target
!= MODE_LINE_DISPLAY
16435 || it
->current_x
< it
->last_visible_x
))
16437 int last_offset
= offset
;
16439 /* Advance to end of string or next format specifier. */
16440 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
16443 if (offset
- 1 != last_offset
)
16445 int nchars
, nbytes
;
16447 /* Output to end of string or up to '%'. Field width
16448 is length of string. Don't output more than
16449 PRECISION allows us. */
16452 prec
= c_string_width (SDATA (elt
) + last_offset
,
16453 offset
- last_offset
, precision
- n
,
16456 switch (mode_line_target
)
16458 case MODE_LINE_NOPROP
:
16459 case MODE_LINE_TITLE
:
16460 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
16462 case MODE_LINE_STRING
:
16464 int bytepos
= last_offset
;
16465 int charpos
= string_byte_to_char (elt
, bytepos
);
16466 int endpos
= (precision
<= 0
16467 ? string_byte_to_char (elt
, offset
)
16468 : charpos
+ nchars
);
16470 n
+= store_mode_line_string (NULL
,
16471 Fsubstring (elt
, make_number (charpos
),
16472 make_number (endpos
)),
16476 case MODE_LINE_DISPLAY
:
16478 int bytepos
= last_offset
;
16479 int charpos
= string_byte_to_char (elt
, bytepos
);
16481 if (precision
<= 0)
16482 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
16483 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
16485 STRING_MULTIBYTE (elt
));
16490 else /* c == '%' */
16492 int percent_position
= offset
;
16494 /* Get the specified minimum width. Zero means
16497 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
16498 field
= field
* 10 + c
- '0';
16500 /* Don't pad beyond the total padding allowed. */
16501 if (field_width
- n
> 0 && field
> field_width
- n
)
16502 field
= field_width
- n
;
16504 /* Note that either PRECISION <= 0 or N < PRECISION. */
16505 prec
= precision
- n
;
16508 n
+= display_mode_element (it
, depth
, field
, prec
,
16509 Vglobal_mode_string
, props
,
16514 int bytepos
, charpos
;
16515 unsigned char *spec
;
16517 bytepos
= percent_position
;
16518 charpos
= (STRING_MULTIBYTE (elt
)
16519 ? string_byte_to_char (elt
, bytepos
)
16523 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
16525 switch (mode_line_target
)
16527 case MODE_LINE_NOPROP
:
16528 case MODE_LINE_TITLE
:
16529 n
+= store_mode_line_noprop (spec
, field
, prec
);
16531 case MODE_LINE_STRING
:
16533 int len
= strlen (spec
);
16534 Lisp_Object tem
= make_string (spec
, len
);
16535 props
= Ftext_properties_at (make_number (charpos
), elt
);
16536 /* Should only keep face property in props */
16537 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
16540 case MODE_LINE_DISPLAY
:
16542 int nglyphs_before
, nwritten
;
16544 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16545 nwritten
= display_string (spec
, Qnil
, elt
,
16550 /* Assign to the glyphs written above the
16551 string where the `%x' came from, position
16555 struct glyph
*glyph
16556 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
16560 for (i
= 0; i
< nwritten
; ++i
)
16562 glyph
[i
].object
= elt
;
16563 glyph
[i
].charpos
= charpos
;
16580 /* A symbol: process the value of the symbol recursively
16581 as if it appeared here directly. Avoid error if symbol void.
16582 Special case: if value of symbol is a string, output the string
16585 register Lisp_Object tem
;
16587 /* If the variable is not marked as risky to set
16588 then its contents are risky to use. */
16589 if (NILP (Fget (elt
, Qrisky_local_variable
)))
16592 tem
= Fboundp (elt
);
16595 tem
= Fsymbol_value (elt
);
16596 /* If value is a string, output that string literally:
16597 don't check for % within it. */
16601 if (!EQ (tem
, elt
))
16603 /* Give up right away for nil or t. */
16613 register Lisp_Object car
, tem
;
16615 /* A cons cell: five distinct cases.
16616 If first element is :eval or :propertize, do something special.
16617 If first element is a string or a cons, process all the elements
16618 and effectively concatenate them.
16619 If first element is a negative number, truncate displaying cdr to
16620 at most that many characters. If positive, pad (with spaces)
16621 to at least that many characters.
16622 If first element is a symbol, process the cadr or caddr recursively
16623 according to whether the symbol's value is non-nil or nil. */
16625 if (EQ (car
, QCeval
))
16627 /* An element of the form (:eval FORM) means evaluate FORM
16628 and use the result as mode line elements. */
16633 if (CONSP (XCDR (elt
)))
16636 spec
= safe_eval (XCAR (XCDR (elt
)));
16637 n
+= display_mode_element (it
, depth
, field_width
- n
,
16638 precision
- n
, spec
, props
,
16642 else if (EQ (car
, QCpropertize
))
16644 /* An element of the form (:propertize ELT PROPS...)
16645 means display ELT but applying properties PROPS. */
16650 if (CONSP (XCDR (elt
)))
16651 n
+= display_mode_element (it
, depth
, field_width
- n
,
16652 precision
- n
, XCAR (XCDR (elt
)),
16653 XCDR (XCDR (elt
)), risky
);
16655 else if (SYMBOLP (car
))
16657 tem
= Fboundp (car
);
16661 /* elt is now the cdr, and we know it is a cons cell.
16662 Use its car if CAR has a non-nil value. */
16665 tem
= Fsymbol_value (car
);
16672 /* Symbol's value is nil (or symbol is unbound)
16673 Get the cddr of the original list
16674 and if possible find the caddr and use that. */
16678 else if (!CONSP (elt
))
16683 else if (INTEGERP (car
))
16685 register int lim
= XINT (car
);
16689 /* Negative int means reduce maximum width. */
16690 if (precision
<= 0)
16693 precision
= min (precision
, -lim
);
16697 /* Padding specified. Don't let it be more than
16698 current maximum. */
16700 lim
= min (precision
, lim
);
16702 /* If that's more padding than already wanted, queue it.
16703 But don't reduce padding already specified even if
16704 that is beyond the current truncation point. */
16705 field_width
= max (lim
, field_width
);
16709 else if (STRINGP (car
) || CONSP (car
))
16711 register int limit
= 50;
16712 /* Limit is to protect against circular lists. */
16715 && (precision
<= 0 || n
< precision
))
16717 n
+= display_mode_element (it
, depth
,
16718 /* Do padding only after the last
16719 element in the list. */
16720 (! CONSP (XCDR (elt
))
16723 precision
- n
, XCAR (elt
),
16733 elt
= build_string ("*invalid*");
16737 /* Pad to FIELD_WIDTH. */
16738 if (field_width
> 0 && n
< field_width
)
16740 switch (mode_line_target
)
16742 case MODE_LINE_NOPROP
:
16743 case MODE_LINE_TITLE
:
16744 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
16746 case MODE_LINE_STRING
:
16747 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
16749 case MODE_LINE_DISPLAY
:
16750 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
16759 /* Store a mode-line string element in mode_line_string_list.
16761 If STRING is non-null, display that C string. Otherwise, the Lisp
16762 string LISP_STRING is displayed.
16764 FIELD_WIDTH is the minimum number of output glyphs to produce.
16765 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16766 with spaces. FIELD_WIDTH <= 0 means don't pad.
16768 PRECISION is the maximum number of characters to output from
16769 STRING. PRECISION <= 0 means don't truncate the string.
16771 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
16772 properties to the string.
16774 PROPS are the properties to add to the string.
16775 The mode_line_string_face face property is always added to the string.
16779 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
16781 Lisp_Object lisp_string
;
16790 if (string
!= NULL
)
16792 len
= strlen (string
);
16793 if (precision
> 0 && len
> precision
)
16795 lisp_string
= make_string (string
, len
);
16797 props
= mode_line_string_face_prop
;
16798 else if (!NILP (mode_line_string_face
))
16800 Lisp_Object face
= Fplist_get (props
, Qface
);
16801 props
= Fcopy_sequence (props
);
16803 face
= mode_line_string_face
;
16805 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16806 props
= Fplist_put (props
, Qface
, face
);
16808 Fadd_text_properties (make_number (0), make_number (len
),
16809 props
, lisp_string
);
16813 len
= XFASTINT (Flength (lisp_string
));
16814 if (precision
> 0 && len
> precision
)
16817 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
16820 if (!NILP (mode_line_string_face
))
16824 props
= Ftext_properties_at (make_number (0), lisp_string
);
16825 face
= Fplist_get (props
, Qface
);
16827 face
= mode_line_string_face
;
16829 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16830 props
= Fcons (Qface
, Fcons (face
, Qnil
));
16832 lisp_string
= Fcopy_sequence (lisp_string
);
16835 Fadd_text_properties (make_number (0), make_number (len
),
16836 props
, lisp_string
);
16841 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16845 if (field_width
> len
)
16847 field_width
-= len
;
16848 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
16850 Fadd_text_properties (make_number (0), make_number (field_width
),
16851 props
, lisp_string
);
16852 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16860 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
16862 doc
: /* Format a string out of a mode line format specification.
16863 First arg FORMAT specifies the mode line format (see `mode-line-format'
16864 for details) to use.
16866 Optional second arg FACE specifies the face property to put
16867 on all characters for which no face is specified.
16868 t means whatever face the window's mode line currently uses
16869 \(either `mode-line' or `mode-line-inactive', depending).
16870 nil means the default is no face property.
16871 If FACE is an integer, the value string has no text properties.
16873 Optional third and fourth args WINDOW and BUFFER specify the window
16874 and buffer to use as the context for the formatting (defaults
16875 are the selected window and the window's buffer). */)
16876 (format
, face
, window
, buffer
)
16877 Lisp_Object format
, face
, window
, buffer
;
16882 struct buffer
*old_buffer
= NULL
;
16884 int no_props
= INTEGERP (face
);
16885 int count
= SPECPDL_INDEX ();
16887 int string_start
= 0;
16890 window
= selected_window
;
16891 CHECK_WINDOW (window
);
16892 w
= XWINDOW (window
);
16895 buffer
= w
->buffer
;
16896 CHECK_BUFFER (buffer
);
16899 return build_string ("");
16907 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
16908 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
16912 face_id
= DEFAULT_FACE_ID
;
16914 if (XBUFFER (buffer
) != current_buffer
)
16915 old_buffer
= current_buffer
;
16917 /* Save things including mode_line_proptrans_alist,
16918 and set that to nil so that we don't alter the outer value. */
16919 record_unwind_protect (unwind_format_mode_line
,
16920 format_mode_line_unwind_data (old_buffer
, 1));
16921 mode_line_proptrans_alist
= Qnil
;
16924 set_buffer_internal_1 (XBUFFER (buffer
));
16926 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16930 mode_line_target
= MODE_LINE_NOPROP
;
16931 mode_line_string_face_prop
= Qnil
;
16932 mode_line_string_list
= Qnil
;
16933 string_start
= MODE_LINE_NOPROP_LEN (0);
16937 mode_line_target
= MODE_LINE_STRING
;
16938 mode_line_string_list
= Qnil
;
16939 mode_line_string_face
= face
;
16940 mode_line_string_face_prop
16941 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
16944 push_frame_kboard (it
.f
);
16945 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16946 pop_frame_kboard ();
16950 len
= MODE_LINE_NOPROP_LEN (string_start
);
16951 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
16955 mode_line_string_list
= Fnreverse (mode_line_string_list
);
16956 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
16957 make_string ("", 0));
16960 unbind_to (count
, Qnil
);
16964 /* Write a null-terminated, right justified decimal representation of
16965 the positive integer D to BUF using a minimal field width WIDTH. */
16968 pint2str (buf
, width
, d
)
16969 register char *buf
;
16970 register int width
;
16973 register char *p
= buf
;
16981 *p
++ = d
% 10 + '0';
16986 for (width
-= (int) (p
- buf
); width
> 0; --width
)
16997 /* Write a null-terminated, right justified decimal and "human
16998 readable" representation of the nonnegative integer D to BUF using
16999 a minimal field width WIDTH. D should be smaller than 999.5e24. */
17001 static const char power_letter
[] =
17015 pint2hrstr (buf
, width
, d
)
17020 /* We aim to represent the nonnegative integer D as
17021 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
17024 /* -1 means: do not use TENTHS. */
17028 /* Length of QUOTIENT.TENTHS as a string. */
17034 if (1000 <= quotient
)
17036 /* Scale to the appropriate EXPONENT. */
17039 remainder
= quotient
% 1000;
17043 while (1000 <= quotient
);
17045 /* Round to nearest and decide whether to use TENTHS or not. */
17048 tenths
= remainder
/ 100;
17049 if (50 <= remainder
% 100)
17056 if (quotient
== 10)
17064 if (500 <= remainder
)
17066 if (quotient
< 999)
17077 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
17078 if (tenths
== -1 && quotient
<= 99)
17085 p
= psuffix
= buf
+ max (width
, length
);
17087 /* Print EXPONENT. */
17089 *psuffix
++ = power_letter
[exponent
];
17092 /* Print TENTHS. */
17095 *--p
= '0' + tenths
;
17099 /* Print QUOTIENT. */
17102 int digit
= quotient
% 10;
17103 *--p
= '0' + digit
;
17105 while ((quotient
/= 10) != 0);
17107 /* Print leading spaces. */
17112 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
17113 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
17114 type of CODING_SYSTEM. Return updated pointer into BUF. */
17116 static unsigned char invalid_eol_type
[] = "(*invalid*)";
17119 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
17120 Lisp_Object coding_system
;
17121 register char *buf
;
17125 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
17126 const unsigned char *eol_str
;
17128 /* The EOL conversion we are using. */
17129 Lisp_Object eoltype
;
17131 val
= Fget (coding_system
, Qcoding_system
);
17134 if (!VECTORP (val
)) /* Not yet decided. */
17139 eoltype
= eol_mnemonic_undecided
;
17140 /* Don't mention EOL conversion if it isn't decided. */
17144 Lisp_Object eolvalue
;
17146 eolvalue
= Fget (coding_system
, Qeol_type
);
17149 *buf
++ = XFASTINT (AREF (val
, 1));
17153 /* The EOL conversion that is normal on this system. */
17155 if (NILP (eolvalue
)) /* Not yet decided. */
17156 eoltype
= eol_mnemonic_undecided
;
17157 else if (VECTORP (eolvalue
)) /* Not yet decided. */
17158 eoltype
= eol_mnemonic_undecided
;
17159 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
17160 eoltype
= (XFASTINT (eolvalue
) == 0
17161 ? eol_mnemonic_unix
17162 : (XFASTINT (eolvalue
) == 1
17163 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
17169 /* Mention the EOL conversion if it is not the usual one. */
17170 if (STRINGP (eoltype
))
17172 eol_str
= SDATA (eoltype
);
17173 eol_str_len
= SBYTES (eoltype
);
17175 else if (INTEGERP (eoltype
)
17176 && CHAR_VALID_P (XINT (eoltype
), 0))
17178 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
17179 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
17184 eol_str
= invalid_eol_type
;
17185 eol_str_len
= sizeof (invalid_eol_type
) - 1;
17187 bcopy (eol_str
, buf
, eol_str_len
);
17188 buf
+= eol_str_len
;
17194 /* Return a string for the output of a mode line %-spec for window W,
17195 generated by character C. PRECISION >= 0 means don't return a
17196 string longer than that value. FIELD_WIDTH > 0 means pad the
17197 string returned with spaces to that value. Return 1 in *MULTIBYTE
17198 if the result is multibyte text.
17200 Note we operate on the current buffer for most purposes,
17201 the exception being w->base_line_pos. */
17203 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
17206 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
17209 int field_width
, precision
;
17213 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17214 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
17215 struct buffer
*b
= current_buffer
;
17223 if (!NILP (b
->read_only
))
17225 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17230 /* This differs from %* only for a modified read-only buffer. */
17231 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17233 if (!NILP (b
->read_only
))
17238 /* This differs from %* in ignoring read-only-ness. */
17239 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17251 if (command_loop_level
> 5)
17253 p
= decode_mode_spec_buf
;
17254 for (i
= 0; i
< command_loop_level
; i
++)
17257 return decode_mode_spec_buf
;
17265 if (command_loop_level
> 5)
17267 p
= decode_mode_spec_buf
;
17268 for (i
= 0; i
< command_loop_level
; i
++)
17271 return decode_mode_spec_buf
;
17278 /* Let lots_of_dashes be a string of infinite length. */
17279 if (mode_line_target
== MODE_LINE_NOPROP
||
17280 mode_line_target
== MODE_LINE_STRING
)
17282 if (field_width
<= 0
17283 || field_width
> sizeof (lots_of_dashes
))
17285 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
17286 decode_mode_spec_buf
[i
] = '-';
17287 decode_mode_spec_buf
[i
] = '\0';
17288 return decode_mode_spec_buf
;
17291 return lots_of_dashes
;
17300 int col
= (int) current_column (); /* iftc */
17301 w
->column_number_displayed
= make_number (col
);
17302 pint2str (decode_mode_spec_buf
, field_width
, col
);
17303 return decode_mode_spec_buf
;
17307 #ifndef SYSTEM_MALLOC
17309 if (NILP (Vmemory_full
))
17312 return "!MEM FULL! ";
17319 /* %F displays the frame name. */
17320 if (!NILP (f
->title
))
17321 return (char *) SDATA (f
->title
);
17322 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
17323 return (char *) SDATA (f
->name
);
17332 int size
= ZV
- BEGV
;
17333 pint2str (decode_mode_spec_buf
, field_width
, size
);
17334 return decode_mode_spec_buf
;
17339 int size
= ZV
- BEGV
;
17340 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
17341 return decode_mode_spec_buf
;
17346 int startpos
= XMARKER (w
->start
)->charpos
;
17347 int startpos_byte
= marker_byte_position (w
->start
);
17348 int line
, linepos
, linepos_byte
, topline
;
17350 int height
= WINDOW_TOTAL_LINES (w
);
17352 /* If we decided that this buffer isn't suitable for line numbers,
17353 don't forget that too fast. */
17354 if (EQ (w
->base_line_pos
, w
->buffer
))
17356 /* But do forget it, if the window shows a different buffer now. */
17357 else if (BUFFERP (w
->base_line_pos
))
17358 w
->base_line_pos
= Qnil
;
17360 /* If the buffer is very big, don't waste time. */
17361 if (INTEGERP (Vline_number_display_limit
)
17362 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
17364 w
->base_line_pos
= Qnil
;
17365 w
->base_line_number
= Qnil
;
17369 if (!NILP (w
->base_line_number
)
17370 && !NILP (w
->base_line_pos
)
17371 && XFASTINT (w
->base_line_pos
) <= startpos
)
17373 line
= XFASTINT (w
->base_line_number
);
17374 linepos
= XFASTINT (w
->base_line_pos
);
17375 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
17380 linepos
= BUF_BEGV (b
);
17381 linepos_byte
= BUF_BEGV_BYTE (b
);
17384 /* Count lines from base line to window start position. */
17385 nlines
= display_count_lines (linepos
, linepos_byte
,
17389 topline
= nlines
+ line
;
17391 /* Determine a new base line, if the old one is too close
17392 or too far away, or if we did not have one.
17393 "Too close" means it's plausible a scroll-down would
17394 go back past it. */
17395 if (startpos
== BUF_BEGV (b
))
17397 w
->base_line_number
= make_number (topline
);
17398 w
->base_line_pos
= make_number (BUF_BEGV (b
));
17400 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
17401 || linepos
== BUF_BEGV (b
))
17403 int limit
= BUF_BEGV (b
);
17404 int limit_byte
= BUF_BEGV_BYTE (b
);
17406 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
17408 if (startpos
- distance
> limit
)
17410 limit
= startpos
- distance
;
17411 limit_byte
= CHAR_TO_BYTE (limit
);
17414 nlines
= display_count_lines (startpos
, startpos_byte
,
17416 - (height
* 2 + 30),
17418 /* If we couldn't find the lines we wanted within
17419 line_number_display_limit_width chars per line,
17420 give up on line numbers for this window. */
17421 if (position
== limit_byte
&& limit
== startpos
- distance
)
17423 w
->base_line_pos
= w
->buffer
;
17424 w
->base_line_number
= Qnil
;
17428 w
->base_line_number
= make_number (topline
- nlines
);
17429 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
17432 /* Now count lines from the start pos to point. */
17433 nlines
= display_count_lines (startpos
, startpos_byte
,
17434 PT_BYTE
, PT
, &junk
);
17436 /* Record that we did display the line number. */
17437 line_number_displayed
= 1;
17439 /* Make the string to show. */
17440 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
17441 return decode_mode_spec_buf
;
17444 char* p
= decode_mode_spec_buf
;
17445 int pad
= field_width
- 2;
17451 return decode_mode_spec_buf
;
17457 obj
= b
->mode_name
;
17461 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
17467 int pos
= marker_position (w
->start
);
17468 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17470 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
17472 if (pos
<= BUF_BEGV (b
))
17477 else if (pos
<= BUF_BEGV (b
))
17481 if (total
> 1000000)
17482 /* Do it differently for a large value, to avoid overflow. */
17483 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17485 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17486 /* We can't normally display a 3-digit number,
17487 so get us a 2-digit number that is close. */
17490 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17491 return decode_mode_spec_buf
;
17495 /* Display percentage of size above the bottom of the screen. */
17498 int toppos
= marker_position (w
->start
);
17499 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
17500 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17502 if (botpos
>= BUF_ZV (b
))
17504 if (toppos
<= BUF_BEGV (b
))
17511 if (total
> 1000000)
17512 /* Do it differently for a large value, to avoid overflow. */
17513 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17515 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17516 /* We can't normally display a 3-digit number,
17517 so get us a 2-digit number that is close. */
17520 if (toppos
<= BUF_BEGV (b
))
17521 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
17523 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17524 return decode_mode_spec_buf
;
17529 /* status of process */
17530 obj
= Fget_buffer_process (Fcurrent_buffer ());
17532 return "no process";
17533 #ifdef subprocesses
17534 obj
= Fsymbol_name (Fprocess_status (obj
));
17538 case 't': /* indicate TEXT or BINARY */
17539 #ifdef MODE_LINE_BINARY_TEXT
17540 return MODE_LINE_BINARY_TEXT (b
);
17546 /* coding-system (not including end-of-line format) */
17548 /* coding-system (including end-of-line type) */
17550 int eol_flag
= (c
== 'Z');
17551 char *p
= decode_mode_spec_buf
;
17553 if (! FRAME_WINDOW_P (f
))
17555 /* No need to mention EOL here--the terminal never needs
17556 to do EOL conversion. */
17557 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
17558 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
17560 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
17563 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
17564 #ifdef subprocesses
17565 obj
= Fget_buffer_process (Fcurrent_buffer ());
17566 if (PROCESSP (obj
))
17568 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
17570 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
17573 #endif /* subprocesses */
17576 return decode_mode_spec_buf
;
17582 *multibyte
= STRING_MULTIBYTE (obj
);
17583 return (char *) SDATA (obj
);
17590 /* Count up to COUNT lines starting from START / START_BYTE.
17591 But don't go beyond LIMIT_BYTE.
17592 Return the number of lines thus found (always nonnegative).
17594 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
17597 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
17598 int start
, start_byte
, limit_byte
, count
;
17601 register unsigned char *cursor
;
17602 unsigned char *base
;
17604 register int ceiling
;
17605 register unsigned char *ceiling_addr
;
17606 int orig_count
= count
;
17608 /* If we are not in selective display mode,
17609 check only for newlines. */
17610 int selective_display
= (!NILP (current_buffer
->selective_display
)
17611 && !INTEGERP (current_buffer
->selective_display
));
17615 while (start_byte
< limit_byte
)
17617 ceiling
= BUFFER_CEILING_OF (start_byte
);
17618 ceiling
= min (limit_byte
- 1, ceiling
);
17619 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
17620 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
17623 if (selective_display
)
17624 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
17627 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
17630 if (cursor
!= ceiling_addr
)
17634 start_byte
+= cursor
- base
+ 1;
17635 *byte_pos_ptr
= start_byte
;
17639 if (++cursor
== ceiling_addr
)
17645 start_byte
+= cursor
- base
;
17650 while (start_byte
> limit_byte
)
17652 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
17653 ceiling
= max (limit_byte
, ceiling
);
17654 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
17655 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
17658 if (selective_display
)
17659 while (--cursor
!= ceiling_addr
17660 && *cursor
!= '\n' && *cursor
!= 015)
17663 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
17666 if (cursor
!= ceiling_addr
)
17670 start_byte
+= cursor
- base
+ 1;
17671 *byte_pos_ptr
= start_byte
;
17672 /* When scanning backwards, we should
17673 not count the newline posterior to which we stop. */
17674 return - orig_count
- 1;
17680 /* Here we add 1 to compensate for the last decrement
17681 of CURSOR, which took it past the valid range. */
17682 start_byte
+= cursor
- base
+ 1;
17686 *byte_pos_ptr
= limit_byte
;
17689 return - orig_count
+ count
;
17690 return orig_count
- count
;
17696 /***********************************************************************
17698 ***********************************************************************/
17700 /* Display a NUL-terminated string, starting with index START.
17702 If STRING is non-null, display that C string. Otherwise, the Lisp
17703 string LISP_STRING is displayed.
17705 If FACE_STRING is not nil, FACE_STRING_POS is a position in
17706 FACE_STRING. Display STRING or LISP_STRING with the face at
17707 FACE_STRING_POS in FACE_STRING:
17709 Display the string in the environment given by IT, but use the
17710 standard display table, temporarily.
17712 FIELD_WIDTH is the minimum number of output glyphs to produce.
17713 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17714 with spaces. If STRING has more characters, more than FIELD_WIDTH
17715 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
17717 PRECISION is the maximum number of characters to output from
17718 STRING. PRECISION < 0 means don't truncate the string.
17720 This is roughly equivalent to printf format specifiers:
17722 FIELD_WIDTH PRECISION PRINTF
17723 ----------------------------------------
17729 MULTIBYTE zero means do not display multibyte chars, > 0 means do
17730 display them, and < 0 means obey the current buffer's value of
17731 enable_multibyte_characters.
17733 Value is the number of columns displayed. */
17736 display_string (string
, lisp_string
, face_string
, face_string_pos
,
17737 start
, it
, field_width
, precision
, max_x
, multibyte
)
17738 unsigned char *string
;
17739 Lisp_Object lisp_string
;
17740 Lisp_Object face_string
;
17741 int face_string_pos
;
17744 int field_width
, precision
, max_x
;
17747 int hpos_at_start
= it
->hpos
;
17748 int saved_face_id
= it
->face_id
;
17749 struct glyph_row
*row
= it
->glyph_row
;
17751 /* Initialize the iterator IT for iteration over STRING beginning
17752 with index START. */
17753 reseat_to_string (it
, string
, lisp_string
, start
,
17754 precision
, field_width
, multibyte
);
17756 /* If displaying STRING, set up the face of the iterator
17757 from LISP_STRING, if that's given. */
17758 if (STRINGP (face_string
))
17764 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
17765 0, it
->region_beg_charpos
,
17766 it
->region_end_charpos
,
17767 &endptr
, it
->base_face_id
, 0);
17768 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17769 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
17772 /* Set max_x to the maximum allowed X position. Don't let it go
17773 beyond the right edge of the window. */
17775 max_x
= it
->last_visible_x
;
17777 max_x
= min (max_x
, it
->last_visible_x
);
17779 /* Skip over display elements that are not visible. because IT->w is
17781 if (it
->current_x
< it
->first_visible_x
)
17782 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
17783 MOVE_TO_POS
| MOVE_TO_X
);
17785 row
->ascent
= it
->max_ascent
;
17786 row
->height
= it
->max_ascent
+ it
->max_descent
;
17787 row
->phys_ascent
= it
->max_phys_ascent
;
17788 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17789 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17791 /* This condition is for the case that we are called with current_x
17792 past last_visible_x. */
17793 while (it
->current_x
< max_x
)
17795 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
17797 /* Get the next display element. */
17798 if (!get_next_display_element (it
))
17801 /* Produce glyphs. */
17802 x_before
= it
->current_x
;
17803 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17804 PRODUCE_GLYPHS (it
);
17806 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
17809 while (i
< nglyphs
)
17811 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17813 if (!it
->truncate_lines_p
17814 && x
+ glyph
->pixel_width
> max_x
)
17816 /* End of continued line or max_x reached. */
17817 if (CHAR_GLYPH_PADDING_P (*glyph
))
17819 /* A wide character is unbreakable. */
17820 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17821 it
->current_x
= x_before
;
17825 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17830 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
17832 /* Glyph is at least partially visible. */
17834 if (x
< it
->first_visible_x
)
17835 it
->glyph_row
->x
= x
- it
->first_visible_x
;
17839 /* Glyph is off the left margin of the display area.
17840 Should not happen. */
17844 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17845 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17846 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17847 row
->phys_height
= max (row
->phys_height
,
17848 it
->max_phys_ascent
+ it
->max_phys_descent
);
17849 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17850 it
->max_extra_line_spacing
);
17851 x
+= glyph
->pixel_width
;
17855 /* Stop if max_x reached. */
17859 /* Stop at line ends. */
17860 if (ITERATOR_AT_END_OF_LINE_P (it
))
17862 it
->continuation_lines_width
= 0;
17866 set_iterator_to_next (it
, 1);
17868 /* Stop if truncating at the right edge. */
17869 if (it
->truncate_lines_p
17870 && it
->current_x
>= it
->last_visible_x
)
17872 /* Add truncation mark, but don't do it if the line is
17873 truncated at a padding space. */
17874 if (IT_CHARPOS (*it
) < it
->string_nchars
)
17876 if (!FRAME_WINDOW_P (it
->f
))
17880 if (it
->current_x
> it
->last_visible_x
)
17882 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17883 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17885 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17887 row
->used
[TEXT_AREA
] = i
;
17888 produce_special_glyphs (it
, IT_TRUNCATION
);
17891 produce_special_glyphs (it
, IT_TRUNCATION
);
17893 it
->glyph_row
->truncated_on_right_p
= 1;
17899 /* Maybe insert a truncation at the left. */
17900 if (it
->first_visible_x
17901 && IT_CHARPOS (*it
) > 0)
17903 if (!FRAME_WINDOW_P (it
->f
))
17904 insert_left_trunc_glyphs (it
);
17905 it
->glyph_row
->truncated_on_left_p
= 1;
17908 it
->face_id
= saved_face_id
;
17910 /* Value is number of columns displayed. */
17911 return it
->hpos
- hpos_at_start
;
17916 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
17917 appears as an element of LIST or as the car of an element of LIST.
17918 If PROPVAL is a list, compare each element against LIST in that
17919 way, and return 1/2 if any element of PROPVAL is found in LIST.
17920 Otherwise return 0. This function cannot quit.
17921 The return value is 2 if the text is invisible but with an ellipsis
17922 and 1 if it's invisible and without an ellipsis. */
17925 invisible_p (propval
, list
)
17926 register Lisp_Object propval
;
17929 register Lisp_Object tail
, proptail
;
17931 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17933 register Lisp_Object tem
;
17935 if (EQ (propval
, tem
))
17937 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
17938 return NILP (XCDR (tem
)) ? 1 : 2;
17941 if (CONSP (propval
))
17943 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
17945 Lisp_Object propelt
;
17946 propelt
= XCAR (proptail
);
17947 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17949 register Lisp_Object tem
;
17951 if (EQ (propelt
, tem
))
17953 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
17954 return NILP (XCDR (tem
)) ? 1 : 2;
17962 /* Calculate a width or height in pixels from a specification using
17963 the following elements:
17966 NUM - a (fractional) multiple of the default font width/height
17967 (NUM) - specifies exactly NUM pixels
17968 UNIT - a fixed number of pixels, see below.
17969 ELEMENT - size of a display element in pixels, see below.
17970 (NUM . SPEC) - equals NUM * SPEC
17971 (+ SPEC SPEC ...) - add pixel values
17972 (- SPEC SPEC ...) - subtract pixel values
17973 (- SPEC) - negate pixel value
17976 INT or FLOAT - a number constant
17977 SYMBOL - use symbol's (buffer local) variable binding.
17980 in - pixels per inch *)
17981 mm - pixels per 1/1000 meter *)
17982 cm - pixels per 1/100 meter *)
17983 width - width of current font in pixels.
17984 height - height of current font in pixels.
17986 *) using the ratio(s) defined in display-pixels-per-inch.
17990 left-fringe - left fringe width in pixels
17991 right-fringe - right fringe width in pixels
17993 left-margin - left margin width in pixels
17994 right-margin - right margin width in pixels
17996 scroll-bar - scroll-bar area width in pixels
18000 Pixels corresponding to 5 inches:
18003 Total width of non-text areas on left side of window (if scroll-bar is on left):
18004 '(space :width (+ left-fringe left-margin scroll-bar))
18006 Align to first text column (in header line):
18007 '(space :align-to 0)
18009 Align to middle of text area minus half the width of variable `my-image'
18010 containing a loaded image:
18011 '(space :align-to (0.5 . (- text my-image)))
18013 Width of left margin minus width of 1 character in the default font:
18014 '(space :width (- left-margin 1))
18016 Width of left margin minus width of 2 characters in the current font:
18017 '(space :width (- left-margin (2 . width)))
18019 Center 1 character over left-margin (in header line):
18020 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
18022 Different ways to express width of left fringe plus left margin minus one pixel:
18023 '(space :width (- (+ left-fringe left-margin) (1)))
18024 '(space :width (+ left-fringe left-margin (- (1))))
18025 '(space :width (+ left-fringe left-margin (-1)))
18029 #define NUMVAL(X) \
18030 ((INTEGERP (X) || FLOATP (X)) \
18035 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
18040 int width_p
, *align_to
;
18044 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
18045 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
18048 return OK_PIXELS (0);
18050 if (SYMBOLP (prop
))
18052 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18054 char *unit
= SDATA (SYMBOL_NAME (prop
));
18056 if (unit
[0] == 'i' && unit
[1] == 'n')
18058 else if (unit
[0] == 'm' && unit
[1] == 'm')
18060 else if (unit
[0] == 'c' && unit
[1] == 'm')
18067 #ifdef HAVE_WINDOW_SYSTEM
18068 if (FRAME_WINDOW_P (it
->f
)
18070 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
18071 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
18073 return OK_PIXELS (ppi
/ pixels
);
18076 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18077 || (CONSP (Vdisplay_pixels_per_inch
)
18079 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18080 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18082 return OK_PIXELS (ppi
/ pixels
);
18088 #ifdef HAVE_WINDOW_SYSTEM
18089 if (EQ (prop
, Qheight
))
18090 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
18091 if (EQ (prop
, Qwidth
))
18092 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
18094 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
18095 return OK_PIXELS (1);
18098 if (EQ (prop
, Qtext
))
18099 return OK_PIXELS (width_p
18100 ? window_box_width (it
->w
, TEXT_AREA
)
18101 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
18103 if (align_to
&& *align_to
< 0)
18106 if (EQ (prop
, Qleft
))
18107 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
18108 if (EQ (prop
, Qright
))
18109 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
18110 if (EQ (prop
, Qcenter
))
18111 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
18112 + window_box_width (it
->w
, TEXT_AREA
) / 2);
18113 if (EQ (prop
, Qleft_fringe
))
18114 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18115 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
18116 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
18117 if (EQ (prop
, Qright_fringe
))
18118 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18119 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18120 : window_box_right_offset (it
->w
, TEXT_AREA
));
18121 if (EQ (prop
, Qleft_margin
))
18122 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
18123 if (EQ (prop
, Qright_margin
))
18124 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
18125 if (EQ (prop
, Qscroll_bar
))
18126 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18128 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18129 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18130 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18135 if (EQ (prop
, Qleft_fringe
))
18136 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18137 if (EQ (prop
, Qright_fringe
))
18138 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18139 if (EQ (prop
, Qleft_margin
))
18140 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18141 if (EQ (prop
, Qright_margin
))
18142 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18143 if (EQ (prop
, Qscroll_bar
))
18144 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18147 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18150 if (INTEGERP (prop
) || FLOATP (prop
))
18152 int base_unit
= (width_p
18153 ? FRAME_COLUMN_WIDTH (it
->f
)
18154 : FRAME_LINE_HEIGHT (it
->f
));
18155 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18160 Lisp_Object car
= XCAR (prop
);
18161 Lisp_Object cdr
= XCDR (prop
);
18165 #ifdef HAVE_WINDOW_SYSTEM
18166 if (valid_image_p (prop
))
18168 int id
= lookup_image (it
->f
, prop
);
18169 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
18171 return OK_PIXELS (width_p
? img
->width
: img
->height
);
18174 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18180 while (CONSP (cdr
))
18182 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
18183 font
, width_p
, align_to
))
18186 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18191 if (EQ (car
, Qminus
))
18193 return OK_PIXELS (pixels
);
18196 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18199 if (INTEGERP (car
) || FLOATP (car
))
18202 pixels
= XFLOATINT (car
);
18204 return OK_PIXELS (pixels
);
18205 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
18206 font
, width_p
, align_to
))
18207 return OK_PIXELS (pixels
* fact
);
18218 /***********************************************************************
18220 ***********************************************************************/
18222 #ifdef HAVE_WINDOW_SYSTEM
18227 dump_glyph_string (s
)
18228 struct glyph_string
*s
;
18230 fprintf (stderr
, "glyph string\n");
18231 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
18232 s
->x
, s
->y
, s
->width
, s
->height
);
18233 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
18234 fprintf (stderr
, " hl = %d\n", s
->hl
);
18235 fprintf (stderr
, " left overhang = %d, right = %d\n",
18236 s
->left_overhang
, s
->right_overhang
);
18237 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
18238 fprintf (stderr
, " extends to end of line = %d\n",
18239 s
->extends_to_end_of_line_p
);
18240 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
18241 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
18244 #endif /* GLYPH_DEBUG */
18246 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
18247 of XChar2b structures for S; it can't be allocated in
18248 init_glyph_string because it must be allocated via `alloca'. W
18249 is the window on which S is drawn. ROW and AREA are the glyph row
18250 and area within the row from which S is constructed. START is the
18251 index of the first glyph structure covered by S. HL is a
18252 face-override for drawing S. */
18255 #define OPTIONAL_HDC(hdc) hdc,
18256 #define DECLARE_HDC(hdc) HDC hdc;
18257 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
18258 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
18261 #ifndef OPTIONAL_HDC
18262 #define OPTIONAL_HDC(hdc)
18263 #define DECLARE_HDC(hdc)
18264 #define ALLOCATE_HDC(hdc, f)
18265 #define RELEASE_HDC(hdc, f)
18269 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
18270 struct glyph_string
*s
;
18274 struct glyph_row
*row
;
18275 enum glyph_row_area area
;
18277 enum draw_glyphs_face hl
;
18279 bzero (s
, sizeof *s
);
18281 s
->f
= XFRAME (w
->frame
);
18285 s
->display
= FRAME_X_DISPLAY (s
->f
);
18286 s
->window
= FRAME_X_WINDOW (s
->f
);
18287 s
->char2b
= char2b
;
18291 s
->first_glyph
= row
->glyphs
[area
] + start
;
18292 s
->height
= row
->height
;
18293 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
18295 /* Display the internal border below the tool-bar window. */
18296 if (WINDOWP (s
->f
->tool_bar_window
)
18297 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
18298 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
18300 s
->ybase
= s
->y
+ row
->ascent
;
18304 /* Append the list of glyph strings with head H and tail T to the list
18305 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
18308 append_glyph_string_lists (head
, tail
, h
, t
)
18309 struct glyph_string
**head
, **tail
;
18310 struct glyph_string
*h
, *t
;
18324 /* Prepend the list of glyph strings with head H and tail T to the
18325 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
18329 prepend_glyph_string_lists (head
, tail
, h
, t
)
18330 struct glyph_string
**head
, **tail
;
18331 struct glyph_string
*h
, *t
;
18345 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
18346 Set *HEAD and *TAIL to the resulting list. */
18349 append_glyph_string (head
, tail
, s
)
18350 struct glyph_string
**head
, **tail
;
18351 struct glyph_string
*s
;
18353 s
->next
= s
->prev
= NULL
;
18354 append_glyph_string_lists (head
, tail
, s
, s
);
18358 /* Get face and two-byte form of character glyph GLYPH on frame F.
18359 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
18360 a pointer to a realized face that is ready for display. */
18362 static INLINE
struct face
*
18363 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
18365 struct glyph
*glyph
;
18371 xassert (glyph
->type
== CHAR_GLYPH
);
18372 face
= FACE_FROM_ID (f
, glyph
->face_id
);
18377 if (!glyph
->multibyte_p
)
18379 /* Unibyte case. We don't have to encode, but we have to make
18380 sure to use a face suitable for unibyte. */
18381 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18383 else if (glyph
->u
.ch
< 128
18384 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
18386 /* Case of ASCII in a face known to fit ASCII. */
18387 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18391 int c1
, c2
, charset
;
18393 /* Split characters into bytes. If c2 is -1 afterwards, C is
18394 really a one-byte character so that byte1 is zero. */
18395 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
18397 STORE_XCHAR2B (char2b
, c1
, c2
);
18399 STORE_XCHAR2B (char2b
, 0, c1
);
18401 /* Maybe encode the character in *CHAR2B. */
18402 if (charset
!= CHARSET_ASCII
)
18404 struct font_info
*font_info
18405 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18408 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
18412 /* Make sure X resources of the face are allocated. */
18413 xassert (face
!= NULL
);
18414 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18419 /* Fill glyph string S with composition components specified by S->cmp.
18421 FACES is an array of faces for all components of this composition.
18422 S->gidx is the index of the first component for S.
18424 OVERLAPS non-zero means S should draw the foreground only, and use
18425 its physical height for clipping. See also draw_glyphs.
18427 Value is the index of a component not in S. */
18430 fill_composite_glyph_string (s
, faces
, overlaps
)
18431 struct glyph_string
*s
;
18432 struct face
**faces
;
18439 s
->for_overlaps
= overlaps
;
18441 s
->face
= faces
[s
->gidx
];
18442 s
->font
= s
->face
->font
;
18443 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18445 /* For all glyphs of this composition, starting at the offset
18446 S->gidx, until we reach the end of the definition or encounter a
18447 glyph that requires the different face, add it to S. */
18449 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
18452 /* All glyph strings for the same composition has the same width,
18453 i.e. the width set for the first component of the composition. */
18455 s
->width
= s
->first_glyph
->pixel_width
;
18457 /* If the specified font could not be loaded, use the frame's
18458 default font, but record the fact that we couldn't load it in
18459 the glyph string so that we can draw rectangles for the
18460 characters of the glyph string. */
18461 if (s
->font
== NULL
)
18463 s
->font_not_found_p
= 1;
18464 s
->font
= FRAME_FONT (s
->f
);
18467 /* Adjust base line for subscript/superscript text. */
18468 s
->ybase
+= s
->first_glyph
->voffset
;
18470 xassert (s
->face
&& s
->face
->gc
);
18472 /* This glyph string must always be drawn with 16-bit functions. */
18475 return s
->gidx
+ s
->nchars
;
18479 /* Fill glyph string S from a sequence of character glyphs.
18481 FACE_ID is the face id of the string. START is the index of the
18482 first glyph to consider, END is the index of the last + 1.
18483 OVERLAPS non-zero means S should draw the foreground only, and use
18484 its physical height for clipping. See also draw_glyphs.
18486 Value is the index of the first glyph not in S. */
18489 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
18490 struct glyph_string
*s
;
18492 int start
, end
, overlaps
;
18494 struct glyph
*glyph
, *last
;
18496 int glyph_not_available_p
;
18498 xassert (s
->f
== XFRAME (s
->w
->frame
));
18499 xassert (s
->nchars
== 0);
18500 xassert (start
>= 0 && end
> start
);
18502 s
->for_overlaps
= overlaps
,
18503 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18504 last
= s
->row
->glyphs
[s
->area
] + end
;
18505 voffset
= glyph
->voffset
;
18507 glyph_not_available_p
= glyph
->glyph_not_available_p
;
18509 while (glyph
< last
18510 && glyph
->type
== CHAR_GLYPH
18511 && glyph
->voffset
== voffset
18512 /* Same face id implies same font, nowadays. */
18513 && glyph
->face_id
== face_id
18514 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
18518 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
18519 s
->char2b
+ s
->nchars
,
18521 s
->two_byte_p
= two_byte_p
;
18523 xassert (s
->nchars
<= end
- start
);
18524 s
->width
+= glyph
->pixel_width
;
18528 s
->font
= s
->face
->font
;
18529 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18531 /* If the specified font could not be loaded, use the frame's font,
18532 but record the fact that we couldn't load it in
18533 S->font_not_found_p so that we can draw rectangles for the
18534 characters of the glyph string. */
18535 if (s
->font
== NULL
|| glyph_not_available_p
)
18537 s
->font_not_found_p
= 1;
18538 s
->font
= FRAME_FONT (s
->f
);
18541 /* Adjust base line for subscript/superscript text. */
18542 s
->ybase
+= voffset
;
18544 xassert (s
->face
&& s
->face
->gc
);
18545 return glyph
- s
->row
->glyphs
[s
->area
];
18549 /* Fill glyph string S from image glyph S->first_glyph. */
18552 fill_image_glyph_string (s
)
18553 struct glyph_string
*s
;
18555 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
18556 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
18558 s
->slice
= s
->first_glyph
->slice
;
18559 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
18560 s
->font
= s
->face
->font
;
18561 s
->width
= s
->first_glyph
->pixel_width
;
18563 /* Adjust base line for subscript/superscript text. */
18564 s
->ybase
+= s
->first_glyph
->voffset
;
18568 /* Fill glyph string S from a sequence of stretch glyphs.
18570 ROW is the glyph row in which the glyphs are found, AREA is the
18571 area within the row. START is the index of the first glyph to
18572 consider, END is the index of the last + 1.
18574 Value is the index of the first glyph not in S. */
18577 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
18578 struct glyph_string
*s
;
18579 struct glyph_row
*row
;
18580 enum glyph_row_area area
;
18583 struct glyph
*glyph
, *last
;
18584 int voffset
, face_id
;
18586 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
18588 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18589 last
= s
->row
->glyphs
[s
->area
] + end
;
18590 face_id
= glyph
->face_id
;
18591 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
18592 s
->font
= s
->face
->font
;
18593 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18594 s
->width
= glyph
->pixel_width
;
18595 voffset
= glyph
->voffset
;
18599 && glyph
->type
== STRETCH_GLYPH
18600 && glyph
->voffset
== voffset
18601 && glyph
->face_id
== face_id
);
18603 s
->width
+= glyph
->pixel_width
;
18605 /* Adjust base line for subscript/superscript text. */
18606 s
->ybase
+= voffset
;
18608 /* The case that face->gc == 0 is handled when drawing the glyph
18609 string by calling PREPARE_FACE_FOR_DISPLAY. */
18611 return glyph
- s
->row
->glyphs
[s
->area
];
18616 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
18617 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
18618 assumed to be zero. */
18621 x_get_glyph_overhangs (glyph
, f
, left
, right
)
18622 struct glyph
*glyph
;
18626 *left
= *right
= 0;
18628 if (glyph
->type
== CHAR_GLYPH
)
18632 struct font_info
*font_info
;
18636 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
18638 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18639 if (font
/* ++KFS: Should this be font_info ? */
18640 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
18642 if (pcm
->rbearing
> pcm
->width
)
18643 *right
= pcm
->rbearing
- pcm
->width
;
18644 if (pcm
->lbearing
< 0)
18645 *left
= -pcm
->lbearing
;
18651 /* Return the index of the first glyph preceding glyph string S that
18652 is overwritten by S because of S's left overhang. Value is -1
18653 if no glyphs are overwritten. */
18656 left_overwritten (s
)
18657 struct glyph_string
*s
;
18661 if (s
->left_overhang
)
18664 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18665 int first
= s
->first_glyph
- glyphs
;
18667 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
18668 x
-= glyphs
[i
].pixel_width
;
18679 /* Return the index of the first glyph preceding glyph string S that
18680 is overwriting S because of its right overhang. Value is -1 if no
18681 glyph in front of S overwrites S. */
18684 left_overwriting (s
)
18685 struct glyph_string
*s
;
18688 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18689 int first
= s
->first_glyph
- glyphs
;
18693 for (i
= first
- 1; i
>= 0; --i
)
18696 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18699 x
-= glyphs
[i
].pixel_width
;
18706 /* Return the index of the last glyph following glyph string S that is
18707 not overwritten by S because of S's right overhang. Value is -1 if
18708 no such glyph is found. */
18711 right_overwritten (s
)
18712 struct glyph_string
*s
;
18716 if (s
->right_overhang
)
18719 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18720 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18721 int end
= s
->row
->used
[s
->area
];
18723 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
18724 x
+= glyphs
[i
].pixel_width
;
18733 /* Return the index of the last glyph following glyph string S that
18734 overwrites S because of its left overhang. Value is negative
18735 if no such glyph is found. */
18738 right_overwriting (s
)
18739 struct glyph_string
*s
;
18742 int end
= s
->row
->used
[s
->area
];
18743 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18744 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18748 for (i
= first
; i
< end
; ++i
)
18751 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18754 x
+= glyphs
[i
].pixel_width
;
18761 /* Get face and two-byte form of character C in face FACE_ID on frame
18762 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
18763 means we want to display multibyte text. DISPLAY_P non-zero means
18764 make sure that X resources for the face returned are allocated.
18765 Value is a pointer to a realized face that is ready for display if
18766 DISPLAY_P is non-zero. */
18768 static INLINE
struct face
*
18769 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
18773 int multibyte_p
, display_p
;
18775 struct face
*face
= FACE_FROM_ID (f
, face_id
);
18779 /* Unibyte case. We don't have to encode, but we have to make
18780 sure to use a face suitable for unibyte. */
18781 STORE_XCHAR2B (char2b
, 0, c
);
18782 face_id
= FACE_FOR_CHAR (f
, face
, c
);
18783 face
= FACE_FROM_ID (f
, face_id
);
18785 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
18787 /* Case of ASCII in a face known to fit ASCII. */
18788 STORE_XCHAR2B (char2b
, 0, c
);
18792 int c1
, c2
, charset
;
18794 /* Split characters into bytes. If c2 is -1 afterwards, C is
18795 really a one-byte character so that byte1 is zero. */
18796 SPLIT_CHAR (c
, charset
, c1
, c2
);
18798 STORE_XCHAR2B (char2b
, c1
, c2
);
18800 STORE_XCHAR2B (char2b
, 0, c1
);
18802 /* Maybe encode the character in *CHAR2B. */
18803 if (face
->font
!= NULL
)
18805 struct font_info
*font_info
18806 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18808 rif
->encode_char (c
, char2b
, font_info
, 0);
18812 /* Make sure X resources of the face are allocated. */
18813 #ifdef HAVE_X_WINDOWS
18817 xassert (face
!= NULL
);
18818 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18825 /* Set background width of glyph string S. START is the index of the
18826 first glyph following S. LAST_X is the right-most x-position + 1
18827 in the drawing area. */
18830 set_glyph_string_background_width (s
, start
, last_x
)
18831 struct glyph_string
*s
;
18835 /* If the face of this glyph string has to be drawn to the end of
18836 the drawing area, set S->extends_to_end_of_line_p. */
18838 if (start
== s
->row
->used
[s
->area
]
18839 && s
->area
== TEXT_AREA
18840 && ((s
->row
->fill_line_p
18841 && (s
->hl
== DRAW_NORMAL_TEXT
18842 || s
->hl
== DRAW_IMAGE_RAISED
18843 || s
->hl
== DRAW_IMAGE_SUNKEN
))
18844 || s
->hl
== DRAW_MOUSE_FACE
))
18845 s
->extends_to_end_of_line_p
= 1;
18847 /* If S extends its face to the end of the line, set its
18848 background_width to the distance to the right edge of the drawing
18850 if (s
->extends_to_end_of_line_p
)
18851 s
->background_width
= last_x
- s
->x
+ 1;
18853 s
->background_width
= s
->width
;
18857 /* Compute overhangs and x-positions for glyph string S and its
18858 predecessors, or successors. X is the starting x-position for S.
18859 BACKWARD_P non-zero means process predecessors. */
18862 compute_overhangs_and_x (s
, x
, backward_p
)
18863 struct glyph_string
*s
;
18871 if (rif
->compute_glyph_string_overhangs
)
18872 rif
->compute_glyph_string_overhangs (s
);
18882 if (rif
->compute_glyph_string_overhangs
)
18883 rif
->compute_glyph_string_overhangs (s
);
18893 /* The following macros are only called from draw_glyphs below.
18894 They reference the following parameters of that function directly:
18895 `w', `row', `area', and `overlap_p'
18896 as well as the following local variables:
18897 `s', `f', and `hdc' (in W32) */
18900 /* On W32, silently add local `hdc' variable to argument list of
18901 init_glyph_string. */
18902 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18903 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
18905 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18906 init_glyph_string (s, char2b, w, row, area, start, hl)
18909 /* Add a glyph string for a stretch glyph to the list of strings
18910 between HEAD and TAIL. START is the index of the stretch glyph in
18911 row area AREA of glyph row ROW. END is the index of the last glyph
18912 in that glyph row area. X is the current output position assigned
18913 to the new glyph string constructed. HL overrides that face of the
18914 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18915 is the right-most x-position of the drawing area. */
18917 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
18918 and below -- keep them on one line. */
18919 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18922 s = (struct glyph_string *) alloca (sizeof *s); \
18923 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18924 START = fill_stretch_glyph_string (s, row, area, START, END); \
18925 append_glyph_string (&HEAD, &TAIL, s); \
18931 /* Add a glyph string for an image glyph to the list of strings
18932 between HEAD and TAIL. START is the index of the image glyph in
18933 row area AREA of glyph row ROW. END is the index of the last glyph
18934 in that glyph row area. X is the current output position assigned
18935 to the new glyph string constructed. HL overrides that face of the
18936 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18937 is the right-most x-position of the drawing area. */
18939 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18942 s = (struct glyph_string *) alloca (sizeof *s); \
18943 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18944 fill_image_glyph_string (s); \
18945 append_glyph_string (&HEAD, &TAIL, s); \
18952 /* Add a glyph string for a sequence of character glyphs to the list
18953 of strings between HEAD and TAIL. START is the index of the first
18954 glyph in row area AREA of glyph row ROW that is part of the new
18955 glyph string. END is the index of the last glyph in that glyph row
18956 area. X is the current output position assigned to the new glyph
18957 string constructed. HL overrides that face of the glyph; e.g. it
18958 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
18959 right-most x-position of the drawing area. */
18961 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18967 c = (row)->glyphs[area][START].u.ch; \
18968 face_id = (row)->glyphs[area][START].face_id; \
18970 s = (struct glyph_string *) alloca (sizeof *s); \
18971 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
18972 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
18973 append_glyph_string (&HEAD, &TAIL, s); \
18975 START = fill_glyph_string (s, face_id, START, END, overlaps); \
18980 /* Add a glyph string for a composite sequence to the list of strings
18981 between HEAD and TAIL. START is the index of the first glyph in
18982 row area AREA of glyph row ROW that is part of the new glyph
18983 string. END is the index of the last glyph in that glyph row area.
18984 X is the current output position assigned to the new glyph string
18985 constructed. HL overrides that face of the glyph; e.g. it is
18986 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
18987 x-position of the drawing area. */
18989 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18991 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
18992 int face_id = (row)->glyphs[area][START].face_id; \
18993 struct face *base_face = FACE_FROM_ID (f, face_id); \
18994 struct composition *cmp = composition_table[cmp_id]; \
18995 int glyph_len = cmp->glyph_len; \
18997 struct face **faces; \
18998 struct glyph_string *first_s = NULL; \
19001 base_face = base_face->ascii_face; \
19002 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
19003 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
19004 /* At first, fill in `char2b' and `faces'. */ \
19005 for (n = 0; n < glyph_len; n++) \
19007 int c = COMPOSITION_GLYPH (cmp, n); \
19008 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
19009 faces[n] = FACE_FROM_ID (f, this_face_id); \
19010 get_char_face_and_encoding (f, c, this_face_id, \
19011 char2b + n, 1, 1); \
19014 /* Make glyph_strings for each glyph sequence that is drawable by \
19015 the same face, and append them to HEAD/TAIL. */ \
19016 for (n = 0; n < cmp->glyph_len;) \
19018 s = (struct glyph_string *) alloca (sizeof *s); \
19019 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
19020 append_glyph_string (&(HEAD), &(TAIL), s); \
19028 n = fill_composite_glyph_string (s, faces, overlaps); \
19036 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
19037 of AREA of glyph row ROW on window W between indices START and END.
19038 HL overrides the face for drawing glyph strings, e.g. it is
19039 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
19040 x-positions of the drawing area.
19042 This is an ugly monster macro construct because we must use alloca
19043 to allocate glyph strings (because draw_glyphs can be called
19044 asynchronously). */
19046 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19049 HEAD = TAIL = NULL; \
19050 while (START < END) \
19052 struct glyph *first_glyph = (row)->glyphs[area] + START; \
19053 switch (first_glyph->type) \
19056 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
19060 case COMPOSITE_GLYPH: \
19061 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
19065 case STRETCH_GLYPH: \
19066 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
19070 case IMAGE_GLYPH: \
19071 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
19079 set_glyph_string_background_width (s, START, LAST_X); \
19086 /* Draw glyphs between START and END in AREA of ROW on window W,
19087 starting at x-position X. X is relative to AREA in W. HL is a
19088 face-override with the following meaning:
19090 DRAW_NORMAL_TEXT draw normally
19091 DRAW_CURSOR draw in cursor face
19092 DRAW_MOUSE_FACE draw in mouse face.
19093 DRAW_INVERSE_VIDEO draw in mode line face
19094 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
19095 DRAW_IMAGE_RAISED draw an image with a raised relief around it
19097 If OVERLAPS is non-zero, draw only the foreground of characters and
19098 clip to the physical height of ROW. Non-zero value also defines
19099 the overlapping part to be drawn:
19101 OVERLAPS_PRED overlap with preceding rows
19102 OVERLAPS_SUCC overlap with succeeding rows
19103 OVERLAPS_BOTH overlap with both preceding/succeeding rows
19104 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
19106 Value is the x-position reached, relative to AREA of W. */
19109 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
19112 struct glyph_row
*row
;
19113 enum glyph_row_area area
;
19115 enum draw_glyphs_face hl
;
19118 struct glyph_string
*head
, *tail
;
19119 struct glyph_string
*s
;
19120 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
19121 int last_x
, area_width
;
19124 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19127 ALLOCATE_HDC (hdc
, f
);
19129 /* Let's rather be paranoid than getting a SEGV. */
19130 end
= min (end
, row
->used
[area
]);
19131 start
= max (0, start
);
19132 start
= min (end
, start
);
19134 /* Translate X to frame coordinates. Set last_x to the right
19135 end of the drawing area. */
19136 if (row
->full_width_p
)
19138 /* X is relative to the left edge of W, without scroll bars
19140 x
+= WINDOW_LEFT_EDGE_X (w
);
19141 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
19145 int area_left
= window_box_left (w
, area
);
19147 area_width
= window_box_width (w
, area
);
19148 last_x
= area_left
+ area_width
;
19151 /* Build a doubly-linked list of glyph_string structures between
19152 head and tail from what we have to draw. Note that the macro
19153 BUILD_GLYPH_STRINGS will modify its start parameter. That's
19154 the reason we use a separate variable `i'. */
19156 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
19158 x_reached
= tail
->x
+ tail
->background_width
;
19162 /* If there are any glyphs with lbearing < 0 or rbearing > width in
19163 the row, redraw some glyphs in front or following the glyph
19164 strings built above. */
19165 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
19168 struct glyph_string
*h
, *t
;
19170 /* Compute overhangs for all glyph strings. */
19171 if (rif
->compute_glyph_string_overhangs
)
19172 for (s
= head
; s
; s
= s
->next
)
19173 rif
->compute_glyph_string_overhangs (s
);
19175 /* Prepend glyph strings for glyphs in front of the first glyph
19176 string that are overwritten because of the first glyph
19177 string's left overhang. The background of all strings
19178 prepended must be drawn because the first glyph string
19180 i
= left_overwritten (head
);
19184 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
19185 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19187 compute_overhangs_and_x (t
, head
->x
, 1);
19188 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19192 /* Prepend glyph strings for glyphs in front of the first glyph
19193 string that overwrite that glyph string because of their
19194 right overhang. For these strings, only the foreground must
19195 be drawn, because it draws over the glyph string at `head'.
19196 The background must not be drawn because this would overwrite
19197 right overhangs of preceding glyphs for which no glyph
19199 i
= left_overwriting (head
);
19203 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
19204 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19205 for (s
= h
; s
; s
= s
->next
)
19206 s
->background_filled_p
= 1;
19207 compute_overhangs_and_x (t
, head
->x
, 1);
19208 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19211 /* Append glyphs strings for glyphs following the last glyph
19212 string tail that are overwritten by tail. The background of
19213 these strings has to be drawn because tail's foreground draws
19215 i
= right_overwritten (tail
);
19218 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19219 DRAW_NORMAL_TEXT
, x
, last_x
);
19220 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19221 append_glyph_string_lists (&head
, &tail
, h
, t
);
19225 /* Append glyph strings for glyphs following the last glyph
19226 string tail that overwrite tail. The foreground of such
19227 glyphs has to be drawn because it writes into the background
19228 of tail. The background must not be drawn because it could
19229 paint over the foreground of following glyphs. */
19230 i
= right_overwriting (tail
);
19234 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19235 DRAW_NORMAL_TEXT
, x
, last_x
);
19236 for (s
= h
; s
; s
= s
->next
)
19237 s
->background_filled_p
= 1;
19238 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19239 append_glyph_string_lists (&head
, &tail
, h
, t
);
19241 if (clip_head
|| clip_tail
)
19242 for (s
= head
; s
; s
= s
->next
)
19244 s
->clip_head
= clip_head
;
19245 s
->clip_tail
= clip_tail
;
19249 /* Draw all strings. */
19250 for (s
= head
; s
; s
= s
->next
)
19251 rif
->draw_glyph_string (s
);
19253 if (area
== TEXT_AREA
19254 && !row
->full_width_p
19255 /* When drawing overlapping rows, only the glyph strings'
19256 foreground is drawn, which doesn't erase a cursor
19260 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
19261 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
19262 : (tail
? tail
->x
+ tail
->background_width
: x
));
19264 int text_left
= window_box_left (w
, TEXT_AREA
);
19268 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
19269 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
19272 /* Value is the x-position up to which drawn, relative to AREA of W.
19273 This doesn't include parts drawn because of overhangs. */
19274 if (row
->full_width_p
)
19275 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
19277 x_reached
-= window_box_left (w
, area
);
19279 RELEASE_HDC (hdc
, f
);
19284 /* Expand row matrix if too narrow. Don't expand if area
19287 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
19289 if (!fonts_changed_p \
19290 && (it->glyph_row->glyphs[area] \
19291 < it->glyph_row->glyphs[area + 1])) \
19293 it->w->ncols_scale_factor++; \
19294 fonts_changed_p = 1; \
19298 /* Store one glyph for IT->char_to_display in IT->glyph_row.
19299 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19305 struct glyph
*glyph
;
19306 enum glyph_row_area area
= it
->area
;
19308 xassert (it
->glyph_row
);
19309 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
19311 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19312 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19314 glyph
->charpos
= CHARPOS (it
->position
);
19315 glyph
->object
= it
->object
;
19316 glyph
->pixel_width
= it
->pixel_width
;
19317 glyph
->ascent
= it
->ascent
;
19318 glyph
->descent
= it
->descent
;
19319 glyph
->voffset
= it
->voffset
;
19320 glyph
->type
= CHAR_GLYPH
;
19321 glyph
->multibyte_p
= it
->multibyte_p
;
19322 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19323 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19324 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19325 || it
->phys_descent
> it
->descent
);
19326 glyph
->padding_p
= 0;
19327 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
19328 glyph
->face_id
= it
->face_id
;
19329 glyph
->u
.ch
= it
->char_to_display
;
19330 glyph
->slice
= null_glyph_slice
;
19331 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19332 ++it
->glyph_row
->used
[area
];
19335 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19338 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
19339 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19342 append_composite_glyph (it
)
19345 struct glyph
*glyph
;
19346 enum glyph_row_area area
= it
->area
;
19348 xassert (it
->glyph_row
);
19350 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19351 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19353 glyph
->charpos
= CHARPOS (it
->position
);
19354 glyph
->object
= it
->object
;
19355 glyph
->pixel_width
= it
->pixel_width
;
19356 glyph
->ascent
= it
->ascent
;
19357 glyph
->descent
= it
->descent
;
19358 glyph
->voffset
= it
->voffset
;
19359 glyph
->type
= COMPOSITE_GLYPH
;
19360 glyph
->multibyte_p
= it
->multibyte_p
;
19361 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19362 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19363 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19364 || it
->phys_descent
> it
->descent
);
19365 glyph
->padding_p
= 0;
19366 glyph
->glyph_not_available_p
= 0;
19367 glyph
->face_id
= it
->face_id
;
19368 glyph
->u
.cmp_id
= it
->cmp_id
;
19369 glyph
->slice
= null_glyph_slice
;
19370 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19371 ++it
->glyph_row
->used
[area
];
19374 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19378 /* Change IT->ascent and IT->height according to the setting of
19382 take_vertical_position_into_account (it
)
19387 if (it
->voffset
< 0)
19388 /* Increase the ascent so that we can display the text higher
19390 it
->ascent
-= it
->voffset
;
19392 /* Increase the descent so that we can display the text lower
19394 it
->descent
+= it
->voffset
;
19399 /* Produce glyphs/get display metrics for the image IT is loaded with.
19400 See the description of struct display_iterator in dispextern.h for
19401 an overview of struct display_iterator. */
19404 produce_image_glyph (it
)
19410 struct glyph_slice slice
;
19412 xassert (it
->what
== IT_IMAGE
);
19414 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19416 /* Make sure X resources of the face is loaded. */
19417 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19419 if (it
->image_id
< 0)
19421 /* Fringe bitmap. */
19422 it
->ascent
= it
->phys_ascent
= 0;
19423 it
->descent
= it
->phys_descent
= 0;
19424 it
->pixel_width
= 0;
19429 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
19431 /* Make sure X resources of the image is loaded. */
19432 prepare_image_for_display (it
->f
, img
);
19434 slice
.x
= slice
.y
= 0;
19435 slice
.width
= img
->width
;
19436 slice
.height
= img
->height
;
19438 if (INTEGERP (it
->slice
.x
))
19439 slice
.x
= XINT (it
->slice
.x
);
19440 else if (FLOATP (it
->slice
.x
))
19441 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
19443 if (INTEGERP (it
->slice
.y
))
19444 slice
.y
= XINT (it
->slice
.y
);
19445 else if (FLOATP (it
->slice
.y
))
19446 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
19448 if (INTEGERP (it
->slice
.width
))
19449 slice
.width
= XINT (it
->slice
.width
);
19450 else if (FLOATP (it
->slice
.width
))
19451 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
19453 if (INTEGERP (it
->slice
.height
))
19454 slice
.height
= XINT (it
->slice
.height
);
19455 else if (FLOATP (it
->slice
.height
))
19456 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
19458 if (slice
.x
>= img
->width
)
19459 slice
.x
= img
->width
;
19460 if (slice
.y
>= img
->height
)
19461 slice
.y
= img
->height
;
19462 if (slice
.x
+ slice
.width
>= img
->width
)
19463 slice
.width
= img
->width
- slice
.x
;
19464 if (slice
.y
+ slice
.height
> img
->height
)
19465 slice
.height
= img
->height
- slice
.y
;
19467 if (slice
.width
== 0 || slice
.height
== 0)
19470 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
19472 it
->descent
= slice
.height
- glyph_ascent
;
19474 it
->descent
+= img
->vmargin
;
19475 if (slice
.y
+ slice
.height
== img
->height
)
19476 it
->descent
+= img
->vmargin
;
19477 it
->phys_descent
= it
->descent
;
19479 it
->pixel_width
= slice
.width
;
19481 it
->pixel_width
+= img
->hmargin
;
19482 if (slice
.x
+ slice
.width
== img
->width
)
19483 it
->pixel_width
+= img
->hmargin
;
19485 /* It's quite possible for images to have an ascent greater than
19486 their height, so don't get confused in that case. */
19487 if (it
->descent
< 0)
19490 #if 0 /* this breaks image tiling */
19491 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
19492 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
19493 if (face_ascent
> it
->ascent
)
19494 it
->ascent
= it
->phys_ascent
= face_ascent
;
19499 if (face
->box
!= FACE_NO_BOX
)
19501 if (face
->box_line_width
> 0)
19504 it
->ascent
+= face
->box_line_width
;
19505 if (slice
.y
+ slice
.height
== img
->height
)
19506 it
->descent
+= face
->box_line_width
;
19509 if (it
->start_of_box_run_p
&& slice
.x
== 0)
19510 it
->pixel_width
+= abs (face
->box_line_width
);
19511 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
19512 it
->pixel_width
+= abs (face
->box_line_width
);
19515 take_vertical_position_into_account (it
);
19519 struct glyph
*glyph
;
19520 enum glyph_row_area area
= it
->area
;
19522 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19523 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19525 glyph
->charpos
= CHARPOS (it
->position
);
19526 glyph
->object
= it
->object
;
19527 glyph
->pixel_width
= it
->pixel_width
;
19528 glyph
->ascent
= glyph_ascent
;
19529 glyph
->descent
= it
->descent
;
19530 glyph
->voffset
= it
->voffset
;
19531 glyph
->type
= IMAGE_GLYPH
;
19532 glyph
->multibyte_p
= it
->multibyte_p
;
19533 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19534 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19535 glyph
->overlaps_vertically_p
= 0;
19536 glyph
->padding_p
= 0;
19537 glyph
->glyph_not_available_p
= 0;
19538 glyph
->face_id
= it
->face_id
;
19539 glyph
->u
.img_id
= img
->id
;
19540 glyph
->slice
= slice
;
19541 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19542 ++it
->glyph_row
->used
[area
];
19545 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19550 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
19551 of the glyph, WIDTH and HEIGHT are the width and height of the
19552 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
19555 append_stretch_glyph (it
, object
, width
, height
, ascent
)
19557 Lisp_Object object
;
19561 struct glyph
*glyph
;
19562 enum glyph_row_area area
= it
->area
;
19564 xassert (ascent
>= 0 && ascent
<= height
);
19566 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19567 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19569 glyph
->charpos
= CHARPOS (it
->position
);
19570 glyph
->object
= object
;
19571 glyph
->pixel_width
= width
;
19572 glyph
->ascent
= ascent
;
19573 glyph
->descent
= height
- ascent
;
19574 glyph
->voffset
= it
->voffset
;
19575 glyph
->type
= STRETCH_GLYPH
;
19576 glyph
->multibyte_p
= it
->multibyte_p
;
19577 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19578 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19579 glyph
->overlaps_vertically_p
= 0;
19580 glyph
->padding_p
= 0;
19581 glyph
->glyph_not_available_p
= 0;
19582 glyph
->face_id
= it
->face_id
;
19583 glyph
->u
.stretch
.ascent
= ascent
;
19584 glyph
->u
.stretch
.height
= height
;
19585 glyph
->slice
= null_glyph_slice
;
19586 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19587 ++it
->glyph_row
->used
[area
];
19590 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19594 /* Produce a stretch glyph for iterator IT. IT->object is the value
19595 of the glyph property displayed. The value must be a list
19596 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
19599 1. `:width WIDTH' specifies that the space should be WIDTH *
19600 canonical char width wide. WIDTH may be an integer or floating
19603 2. `:relative-width FACTOR' specifies that the width of the stretch
19604 should be computed from the width of the first character having the
19605 `glyph' property, and should be FACTOR times that width.
19607 3. `:align-to HPOS' specifies that the space should be wide enough
19608 to reach HPOS, a value in canonical character units.
19610 Exactly one of the above pairs must be present.
19612 4. `:height HEIGHT' specifies that the height of the stretch produced
19613 should be HEIGHT, measured in canonical character units.
19615 5. `:relative-height FACTOR' specifies that the height of the
19616 stretch should be FACTOR times the height of the characters having
19617 the glyph property.
19619 Either none or exactly one of 4 or 5 must be present.
19621 6. `:ascent ASCENT' specifies that ASCENT percent of the height
19622 of the stretch should be used for the ascent of the stretch.
19623 ASCENT must be in the range 0 <= ASCENT <= 100. */
19626 produce_stretch_glyph (it
)
19629 /* (space :width WIDTH :height HEIGHT ...) */
19630 Lisp_Object prop
, plist
;
19631 int width
= 0, height
= 0, align_to
= -1;
19632 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
19635 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19636 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
19638 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19640 /* List should start with `space'. */
19641 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
19642 plist
= XCDR (it
->object
);
19644 /* Compute the width of the stretch. */
19645 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
19646 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
19648 /* Absolute width `:width WIDTH' specified and valid. */
19649 zero_width_ok_p
= 1;
19652 else if (prop
= Fplist_get (plist
, QCrelative_width
),
19655 /* Relative width `:relative-width FACTOR' specified and valid.
19656 Compute the width of the characters having the `glyph'
19659 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
19662 if (it
->multibyte_p
)
19664 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
19665 - IT_BYTEPOS (*it
));
19666 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
19669 it2
.c
= *p
, it2
.len
= 1;
19671 it2
.glyph_row
= NULL
;
19672 it2
.what
= IT_CHARACTER
;
19673 x_produce_glyphs (&it2
);
19674 width
= NUMVAL (prop
) * it2
.pixel_width
;
19676 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
19677 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
19679 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
19680 align_to
= (align_to
< 0
19682 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
19683 else if (align_to
< 0)
19684 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
19685 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
19686 zero_width_ok_p
= 1;
19689 /* Nothing specified -> width defaults to canonical char width. */
19690 width
= FRAME_COLUMN_WIDTH (it
->f
);
19692 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
19695 /* Compute height. */
19696 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
19697 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19700 zero_height_ok_p
= 1;
19702 else if (prop
= Fplist_get (plist
, QCrelative_height
),
19704 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
19706 height
= FONT_HEIGHT (font
);
19708 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
19711 /* Compute percentage of height used for ascent. If
19712 `:ascent ASCENT' is present and valid, use that. Otherwise,
19713 derive the ascent from the font in use. */
19714 if (prop
= Fplist_get (plist
, QCascent
),
19715 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
19716 ascent
= height
* NUMVAL (prop
) / 100.0;
19717 else if (!NILP (prop
)
19718 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19719 ascent
= min (max (0, (int)tem
), height
);
19721 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
19723 if (width
> 0 && !it
->truncate_lines_p
19724 && it
->current_x
+ width
> it
->last_visible_x
)
19725 width
= it
->last_visible_x
- it
->current_x
- 1;
19727 if (width
> 0 && height
> 0 && it
->glyph_row
)
19729 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
19730 if (!STRINGP (object
))
19731 object
= it
->w
->buffer
;
19732 append_stretch_glyph (it
, object
, width
, height
, ascent
);
19735 it
->pixel_width
= width
;
19736 it
->ascent
= it
->phys_ascent
= ascent
;
19737 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
19738 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
19740 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
19742 if (face
->box_line_width
> 0)
19744 it
->ascent
+= face
->box_line_width
;
19745 it
->descent
+= face
->box_line_width
;
19748 if (it
->start_of_box_run_p
)
19749 it
->pixel_width
+= abs (face
->box_line_width
);
19750 if (it
->end_of_box_run_p
)
19751 it
->pixel_width
+= abs (face
->box_line_width
);
19754 take_vertical_position_into_account (it
);
19757 /* Get line-height and line-spacing property at point.
19758 If line-height has format (HEIGHT TOTAL), return TOTAL
19759 in TOTAL_HEIGHT. */
19762 get_line_height_property (it
, prop
)
19766 Lisp_Object position
;
19768 if (STRINGP (it
->object
))
19769 position
= make_number (IT_STRING_CHARPOS (*it
));
19770 else if (BUFFERP (it
->object
))
19771 position
= make_number (IT_CHARPOS (*it
));
19775 return Fget_char_property (position
, prop
, it
->object
);
19778 /* Calculate line-height and line-spacing properties.
19779 An integer value specifies explicit pixel value.
19780 A float value specifies relative value to current face height.
19781 A cons (float . face-name) specifies relative value to
19782 height of specified face font.
19784 Returns height in pixels, or nil. */
19788 calc_line_height_property (it
, val
, font
, boff
, override
)
19792 int boff
, override
;
19794 Lisp_Object face_name
= Qnil
;
19795 int ascent
, descent
, height
;
19797 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
19802 face_name
= XCAR (val
);
19804 if (!NUMBERP (val
))
19805 val
= make_number (1);
19806 if (NILP (face_name
))
19808 height
= it
->ascent
+ it
->descent
;
19813 if (NILP (face_name
))
19815 font
= FRAME_FONT (it
->f
);
19816 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19818 else if (EQ (face_name
, Qt
))
19826 struct font_info
*font_info
;
19828 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
19830 return make_number (-1);
19832 face
= FACE_FROM_ID (it
->f
, face_id
);
19835 return make_number (-1);
19837 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19838 boff
= font_info
->baseline_offset
;
19839 if (font_info
->vertical_centering
)
19840 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19843 ascent
= FONT_BASE (font
) + boff
;
19844 descent
= FONT_DESCENT (font
) - boff
;
19848 it
->override_ascent
= ascent
;
19849 it
->override_descent
= descent
;
19850 it
->override_boff
= boff
;
19853 height
= ascent
+ descent
;
19857 height
= (int)(XFLOAT_DATA (val
) * height
);
19858 else if (INTEGERP (val
))
19859 height
*= XINT (val
);
19861 return make_number (height
);
19866 Produce glyphs/get display metrics for the display element IT is
19867 loaded with. See the description of struct it in dispextern.h
19868 for an overview of struct it. */
19871 x_produce_glyphs (it
)
19874 int extra_line_spacing
= it
->extra_line_spacing
;
19876 it
->glyph_not_available_p
= 0;
19878 if (it
->what
== IT_CHARACTER
)
19882 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19884 int font_not_found_p
;
19885 struct font_info
*font_info
;
19886 int boff
; /* baseline offset */
19887 /* We may change it->multibyte_p upon unibyte<->multibyte
19888 conversion. So, save the current value now and restore it
19891 Note: It seems that we don't have to record multibyte_p in
19892 struct glyph because the character code itself tells if or
19893 not the character is multibyte. Thus, in the future, we must
19894 consider eliminating the field `multibyte_p' in the struct
19896 int saved_multibyte_p
= it
->multibyte_p
;
19898 /* Maybe translate single-byte characters to multibyte, or the
19900 it
->char_to_display
= it
->c
;
19901 if (!ASCII_BYTE_P (it
->c
))
19903 if (unibyte_display_via_language_environment
19904 && SINGLE_BYTE_CHAR_P (it
->c
)
19906 || !NILP (Vnonascii_translation_table
)))
19908 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19909 it
->multibyte_p
= 1;
19910 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19911 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19913 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
19914 && !it
->multibyte_p
)
19916 it
->multibyte_p
= 1;
19917 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19918 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19922 /* Get font to use. Encode IT->char_to_display. */
19923 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19924 &char2b
, it
->multibyte_p
, 0);
19927 /* When no suitable font found, use the default font. */
19928 font_not_found_p
= font
== NULL
;
19929 if (font_not_found_p
)
19931 font
= FRAME_FONT (it
->f
);
19932 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19937 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19938 boff
= font_info
->baseline_offset
;
19939 if (font_info
->vertical_centering
)
19940 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19943 if (it
->char_to_display
>= ' '
19944 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
19946 /* Either unibyte or ASCII. */
19951 pcm
= rif
->per_char_metric (font
, &char2b
,
19952 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
19954 if (it
->override_ascent
>= 0)
19956 it
->ascent
= it
->override_ascent
;
19957 it
->descent
= it
->override_descent
;
19958 boff
= it
->override_boff
;
19962 it
->ascent
= FONT_BASE (font
) + boff
;
19963 it
->descent
= FONT_DESCENT (font
) - boff
;
19968 it
->phys_ascent
= pcm
->ascent
+ boff
;
19969 it
->phys_descent
= pcm
->descent
- boff
;
19970 it
->pixel_width
= pcm
->width
;
19974 it
->glyph_not_available_p
= 1;
19975 it
->phys_ascent
= it
->ascent
;
19976 it
->phys_descent
= it
->descent
;
19977 it
->pixel_width
= FONT_WIDTH (font
);
19980 if (it
->constrain_row_ascent_descent_p
)
19982 if (it
->descent
> it
->max_descent
)
19984 it
->ascent
+= it
->descent
- it
->max_descent
;
19985 it
->descent
= it
->max_descent
;
19987 if (it
->ascent
> it
->max_ascent
)
19989 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19990 it
->ascent
= it
->max_ascent
;
19992 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19993 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19994 extra_line_spacing
= 0;
19997 /* If this is a space inside a region of text with
19998 `space-width' property, change its width. */
19999 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
20001 it
->pixel_width
*= XFLOATINT (it
->space_width
);
20003 /* If face has a box, add the box thickness to the character
20004 height. If character has a box line to the left and/or
20005 right, add the box line width to the character's width. */
20006 if (face
->box
!= FACE_NO_BOX
)
20008 int thick
= face
->box_line_width
;
20012 it
->ascent
+= thick
;
20013 it
->descent
+= thick
;
20018 if (it
->start_of_box_run_p
)
20019 it
->pixel_width
+= thick
;
20020 if (it
->end_of_box_run_p
)
20021 it
->pixel_width
+= thick
;
20024 /* If face has an overline, add the height of the overline
20025 (1 pixel) and a 1 pixel margin to the character height. */
20026 if (face
->overline_p
)
20029 if (it
->constrain_row_ascent_descent_p
)
20031 if (it
->ascent
> it
->max_ascent
)
20032 it
->ascent
= it
->max_ascent
;
20033 if (it
->descent
> it
->max_descent
)
20034 it
->descent
= it
->max_descent
;
20037 take_vertical_position_into_account (it
);
20039 /* If we have to actually produce glyphs, do it. */
20044 /* Translate a space with a `space-width' property
20045 into a stretch glyph. */
20046 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
20047 / FONT_HEIGHT (font
));
20048 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20049 it
->ascent
+ it
->descent
, ascent
);
20054 /* If characters with lbearing or rbearing are displayed
20055 in this line, record that fact in a flag of the
20056 glyph row. This is used to optimize X output code. */
20057 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
20058 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20061 else if (it
->char_to_display
== '\n')
20063 /* A newline has no width but we need the height of the line.
20064 But if previous part of the line set a height, don't
20065 increase that height */
20067 Lisp_Object height
;
20068 Lisp_Object total_height
= Qnil
;
20070 it
->override_ascent
= -1;
20071 it
->pixel_width
= 0;
20074 height
= get_line_height_property(it
, Qline_height
);
20075 /* Split (line-height total-height) list */
20077 && CONSP (XCDR (height
))
20078 && NILP (XCDR (XCDR (height
))))
20080 total_height
= XCAR (XCDR (height
));
20081 height
= XCAR (height
);
20083 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
20085 if (it
->override_ascent
>= 0)
20087 it
->ascent
= it
->override_ascent
;
20088 it
->descent
= it
->override_descent
;
20089 boff
= it
->override_boff
;
20093 it
->ascent
= FONT_BASE (font
) + boff
;
20094 it
->descent
= FONT_DESCENT (font
) - boff
;
20097 if (EQ (height
, Qt
))
20099 if (it
->descent
> it
->max_descent
)
20101 it
->ascent
+= it
->descent
- it
->max_descent
;
20102 it
->descent
= it
->max_descent
;
20104 if (it
->ascent
> it
->max_ascent
)
20106 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20107 it
->ascent
= it
->max_ascent
;
20109 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20110 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20111 it
->constrain_row_ascent_descent_p
= 1;
20112 extra_line_spacing
= 0;
20116 Lisp_Object spacing
;
20118 it
->phys_ascent
= it
->ascent
;
20119 it
->phys_descent
= it
->descent
;
20121 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
20122 && face
->box
!= FACE_NO_BOX
20123 && face
->box_line_width
> 0)
20125 it
->ascent
+= face
->box_line_width
;
20126 it
->descent
+= face
->box_line_width
;
20129 && XINT (height
) > it
->ascent
+ it
->descent
)
20130 it
->ascent
= XINT (height
) - it
->descent
;
20132 if (!NILP (total_height
))
20133 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
20136 spacing
= get_line_height_property(it
, Qline_spacing
);
20137 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
20139 if (INTEGERP (spacing
))
20141 extra_line_spacing
= XINT (spacing
);
20142 if (!NILP (total_height
))
20143 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
20147 else if (it
->char_to_display
== '\t')
20149 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
20150 int x
= it
->current_x
+ it
->continuation_lines_width
;
20151 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
20153 /* If the distance from the current position to the next tab
20154 stop is less than a space character width, use the
20155 tab stop after that. */
20156 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
20157 next_tab_x
+= tab_width
;
20159 it
->pixel_width
= next_tab_x
- x
;
20161 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
20162 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20166 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20167 it
->ascent
+ it
->descent
, it
->ascent
);
20172 /* A multi-byte character. Assume that the display width of the
20173 character is the width of the character multiplied by the
20174 width of the font. */
20176 /* If we found a font, this font should give us the right
20177 metrics. If we didn't find a font, use the frame's
20178 default font and calculate the width of the character
20179 from the charset width; this is what old redisplay code
20182 pcm
= rif
->per_char_metric (font
, &char2b
,
20183 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
20185 if (font_not_found_p
|| !pcm
)
20187 int charset
= CHAR_CHARSET (it
->char_to_display
);
20189 it
->glyph_not_available_p
= 1;
20190 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
20191 * CHARSET_WIDTH (charset
));
20192 it
->phys_ascent
= FONT_BASE (font
) + boff
;
20193 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20197 it
->pixel_width
= pcm
->width
;
20198 it
->phys_ascent
= pcm
->ascent
+ boff
;
20199 it
->phys_descent
= pcm
->descent
- boff
;
20201 && (pcm
->lbearing
< 0
20202 || pcm
->rbearing
> pcm
->width
))
20203 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20206 it
->ascent
= FONT_BASE (font
) + boff
;
20207 it
->descent
= FONT_DESCENT (font
) - boff
;
20208 if (face
->box
!= FACE_NO_BOX
)
20210 int thick
= face
->box_line_width
;
20214 it
->ascent
+= thick
;
20215 it
->descent
+= thick
;
20220 if (it
->start_of_box_run_p
)
20221 it
->pixel_width
+= thick
;
20222 if (it
->end_of_box_run_p
)
20223 it
->pixel_width
+= thick
;
20226 /* If face has an overline, add the height of the overline
20227 (1 pixel) and a 1 pixel margin to the character height. */
20228 if (face
->overline_p
)
20231 take_vertical_position_into_account (it
);
20236 it
->multibyte_p
= saved_multibyte_p
;
20238 else if (it
->what
== IT_COMPOSITION
)
20240 /* Note: A composition is represented as one glyph in the
20241 glyph matrix. There are no padding glyphs. */
20244 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20246 int font_not_found_p
;
20247 struct font_info
*font_info
;
20248 int boff
; /* baseline offset */
20249 struct composition
*cmp
= composition_table
[it
->cmp_id
];
20251 /* Maybe translate single-byte characters to multibyte. */
20252 it
->char_to_display
= it
->c
;
20253 if (unibyte_display_via_language_environment
20254 && SINGLE_BYTE_CHAR_P (it
->c
)
20257 && !NILP (Vnonascii_translation_table
))))
20259 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20262 /* Get face and font to use. Encode IT->char_to_display. */
20263 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20264 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20265 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20266 &char2b
, it
->multibyte_p
, 0);
20269 /* When no suitable font found, use the default font. */
20270 font_not_found_p
= font
== NULL
;
20271 if (font_not_found_p
)
20273 font
= FRAME_FONT (it
->f
);
20274 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20279 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20280 boff
= font_info
->baseline_offset
;
20281 if (font_info
->vertical_centering
)
20282 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20285 /* There are no padding glyphs, so there is only one glyph to
20286 produce for the composition. Important is that pixel_width,
20287 ascent and descent are the values of what is drawn by
20288 draw_glyphs (i.e. the values of the overall glyphs composed). */
20291 /* If we have not yet calculated pixel size data of glyphs of
20292 the composition for the current face font, calculate them
20293 now. Theoretically, we have to check all fonts for the
20294 glyphs, but that requires much time and memory space. So,
20295 here we check only the font of the first glyph. This leads
20296 to incorrect display very rarely, and C-l (recenter) can
20297 correct the display anyway. */
20298 if (cmp
->font
!= (void *) font
)
20300 /* Ascent and descent of the font of the first character of
20301 this composition (adjusted by baseline offset). Ascent
20302 and descent of overall glyphs should not be less than
20303 them respectively. */
20304 int font_ascent
= FONT_BASE (font
) + boff
;
20305 int font_descent
= FONT_DESCENT (font
) - boff
;
20306 /* Bounding box of the overall glyphs. */
20307 int leftmost
, rightmost
, lowest
, highest
;
20308 int i
, width
, ascent
, descent
;
20310 cmp
->font
= (void *) font
;
20312 /* Initialize the bounding box. */
20314 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20315 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
20317 width
= pcm
->width
;
20318 ascent
= pcm
->ascent
;
20319 descent
= pcm
->descent
;
20323 width
= FONT_WIDTH (font
);
20324 ascent
= FONT_BASE (font
);
20325 descent
= FONT_DESCENT (font
);
20329 lowest
= - descent
+ boff
;
20330 highest
= ascent
+ boff
;
20334 && font_info
->default_ascent
20335 && CHAR_TABLE_P (Vuse_default_ascent
)
20336 && !NILP (Faref (Vuse_default_ascent
,
20337 make_number (it
->char_to_display
))))
20338 highest
= font_info
->default_ascent
+ boff
;
20340 /* Draw the first glyph at the normal position. It may be
20341 shifted to right later if some other glyphs are drawn at
20343 cmp
->offsets
[0] = 0;
20344 cmp
->offsets
[1] = boff
;
20346 /* Set cmp->offsets for the remaining glyphs. */
20347 for (i
= 1; i
< cmp
->glyph_len
; i
++)
20349 int left
, right
, btm
, top
;
20350 int ch
= COMPOSITION_GLYPH (cmp
, i
);
20351 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
20353 face
= FACE_FROM_ID (it
->f
, face_id
);
20354 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
20355 &char2b
, it
->multibyte_p
, 0);
20359 font
= FRAME_FONT (it
->f
);
20360 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20366 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20367 boff
= font_info
->baseline_offset
;
20368 if (font_info
->vertical_centering
)
20369 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20373 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20374 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
20376 width
= pcm
->width
;
20377 ascent
= pcm
->ascent
;
20378 descent
= pcm
->descent
;
20382 width
= FONT_WIDTH (font
);
20387 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
20389 /* Relative composition with or without
20390 alternate chars. */
20391 left
= (leftmost
+ rightmost
- width
) / 2;
20392 btm
= - descent
+ boff
;
20393 if (font_info
&& font_info
->relative_compose
20394 && (! CHAR_TABLE_P (Vignore_relative_composition
)
20395 || NILP (Faref (Vignore_relative_composition
,
20396 make_number (ch
)))))
20399 if (- descent
>= font_info
->relative_compose
)
20400 /* One extra pixel between two glyphs. */
20402 else if (ascent
<= 0)
20403 /* One extra pixel between two glyphs. */
20404 btm
= lowest
- 1 - ascent
- descent
;
20409 /* A composition rule is specified by an integer
20410 value that encodes global and new reference
20411 points (GREF and NREF). GREF and NREF are
20412 specified by numbers as below:
20414 0---1---2 -- ascent
20418 9--10--11 -- center
20420 ---3---4---5--- baseline
20422 6---7---8 -- descent
20424 int rule
= COMPOSITION_RULE (cmp
, i
);
20425 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
20427 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
20428 grefx
= gref
% 3, nrefx
= nref
% 3;
20429 grefy
= gref
/ 3, nrefy
= nref
/ 3;
20432 + grefx
* (rightmost
- leftmost
) / 2
20433 - nrefx
* width
/ 2);
20434 btm
= ((grefy
== 0 ? highest
20436 : grefy
== 2 ? lowest
20437 : (highest
+ lowest
) / 2)
20438 - (nrefy
== 0 ? ascent
+ descent
20439 : nrefy
== 1 ? descent
- boff
20441 : (ascent
+ descent
) / 2));
20444 cmp
->offsets
[i
* 2] = left
;
20445 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
20447 /* Update the bounding box of the overall glyphs. */
20448 right
= left
+ width
;
20449 top
= btm
+ descent
+ ascent
;
20450 if (left
< leftmost
)
20452 if (right
> rightmost
)
20460 /* If there are glyphs whose x-offsets are negative,
20461 shift all glyphs to the right and make all x-offsets
20465 for (i
= 0; i
< cmp
->glyph_len
; i
++)
20466 cmp
->offsets
[i
* 2] -= leftmost
;
20467 rightmost
-= leftmost
;
20470 cmp
->pixel_width
= rightmost
;
20471 cmp
->ascent
= highest
;
20472 cmp
->descent
= - lowest
;
20473 if (cmp
->ascent
< font_ascent
)
20474 cmp
->ascent
= font_ascent
;
20475 if (cmp
->descent
< font_descent
)
20476 cmp
->descent
= font_descent
;
20479 it
->pixel_width
= cmp
->pixel_width
;
20480 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
20481 it
->descent
= it
->phys_descent
= cmp
->descent
;
20483 if (face
->box
!= FACE_NO_BOX
)
20485 int thick
= face
->box_line_width
;
20489 it
->ascent
+= thick
;
20490 it
->descent
+= thick
;
20495 if (it
->start_of_box_run_p
)
20496 it
->pixel_width
+= thick
;
20497 if (it
->end_of_box_run_p
)
20498 it
->pixel_width
+= thick
;
20501 /* If face has an overline, add the height of the overline
20502 (1 pixel) and a 1 pixel margin to the character height. */
20503 if (face
->overline_p
)
20506 take_vertical_position_into_account (it
);
20509 append_composite_glyph (it
);
20511 else if (it
->what
== IT_IMAGE
)
20512 produce_image_glyph (it
);
20513 else if (it
->what
== IT_STRETCH
)
20514 produce_stretch_glyph (it
);
20516 /* Accumulate dimensions. Note: can't assume that it->descent > 0
20517 because this isn't true for images with `:ascent 100'. */
20518 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
20519 if (it
->area
== TEXT_AREA
)
20520 it
->current_x
+= it
->pixel_width
;
20522 if (extra_line_spacing
> 0)
20524 it
->descent
+= extra_line_spacing
;
20525 if (extra_line_spacing
> it
->max_extra_line_spacing
)
20526 it
->max_extra_line_spacing
= extra_line_spacing
;
20529 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
20530 it
->max_descent
= max (it
->max_descent
, it
->descent
);
20531 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
20532 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
20536 Output LEN glyphs starting at START at the nominal cursor position.
20537 Advance the nominal cursor over the text. The global variable
20538 updated_window contains the window being updated, updated_row is
20539 the glyph row being updated, and updated_area is the area of that
20540 row being updated. */
20543 x_write_glyphs (start
, len
)
20544 struct glyph
*start
;
20549 xassert (updated_window
&& updated_row
);
20552 /* Write glyphs. */
20554 hpos
= start
- updated_row
->glyphs
[updated_area
];
20555 x
= draw_glyphs (updated_window
, output_cursor
.x
,
20556 updated_row
, updated_area
,
20558 DRAW_NORMAL_TEXT
, 0);
20560 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
20561 if (updated_area
== TEXT_AREA
20562 && updated_window
->phys_cursor_on_p
20563 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
20564 && updated_window
->phys_cursor
.hpos
>= hpos
20565 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
20566 updated_window
->phys_cursor_on_p
= 0;
20570 /* Advance the output cursor. */
20571 output_cursor
.hpos
+= len
;
20572 output_cursor
.x
= x
;
20577 Insert LEN glyphs from START at the nominal cursor position. */
20580 x_insert_glyphs (start
, len
)
20581 struct glyph
*start
;
20586 int line_height
, shift_by_width
, shifted_region_width
;
20587 struct glyph_row
*row
;
20588 struct glyph
*glyph
;
20589 int frame_x
, frame_y
, hpos
;
20591 xassert (updated_window
&& updated_row
);
20593 w
= updated_window
;
20594 f
= XFRAME (WINDOW_FRAME (w
));
20596 /* Get the height of the line we are in. */
20598 line_height
= row
->height
;
20600 /* Get the width of the glyphs to insert. */
20601 shift_by_width
= 0;
20602 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
20603 shift_by_width
+= glyph
->pixel_width
;
20605 /* Get the width of the region to shift right. */
20606 shifted_region_width
= (window_box_width (w
, updated_area
)
20611 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
20612 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
20614 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
20615 line_height
, shift_by_width
);
20617 /* Write the glyphs. */
20618 hpos
= start
- row
->glyphs
[updated_area
];
20619 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
20621 DRAW_NORMAL_TEXT
, 0);
20623 /* Advance the output cursor. */
20624 output_cursor
.hpos
+= len
;
20625 output_cursor
.x
+= shift_by_width
;
20631 Erase the current text line from the nominal cursor position
20632 (inclusive) to pixel column TO_X (exclusive). The idea is that
20633 everything from TO_X onward is already erased.
20635 TO_X is a pixel position relative to updated_area of
20636 updated_window. TO_X == -1 means clear to the end of this area. */
20639 x_clear_end_of_line (to_x
)
20643 struct window
*w
= updated_window
;
20644 int max_x
, min_y
, max_y
;
20645 int from_x
, from_y
, to_y
;
20647 xassert (updated_window
&& updated_row
);
20648 f
= XFRAME (w
->frame
);
20650 if (updated_row
->full_width_p
)
20651 max_x
= WINDOW_TOTAL_WIDTH (w
);
20653 max_x
= window_box_width (w
, updated_area
);
20654 max_y
= window_text_bottom_y (w
);
20656 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
20657 of window. For TO_X > 0, truncate to end of drawing area. */
20663 to_x
= min (to_x
, max_x
);
20665 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
20667 /* Notice if the cursor will be cleared by this operation. */
20668 if (!updated_row
->full_width_p
)
20669 notice_overwritten_cursor (w
, updated_area
,
20670 output_cursor
.x
, -1,
20672 MATRIX_ROW_BOTTOM_Y (updated_row
));
20674 from_x
= output_cursor
.x
;
20676 /* Translate to frame coordinates. */
20677 if (updated_row
->full_width_p
)
20679 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
20680 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
20684 int area_left
= window_box_left (w
, updated_area
);
20685 from_x
+= area_left
;
20689 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
20690 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
20691 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
20693 /* Prevent inadvertently clearing to end of the X window. */
20694 if (to_x
> from_x
&& to_y
> from_y
)
20697 rif
->clear_frame_area (f
, from_x
, from_y
,
20698 to_x
- from_x
, to_y
- from_y
);
20703 #endif /* HAVE_WINDOW_SYSTEM */
20707 /***********************************************************************
20709 ***********************************************************************/
20711 /* Value is the internal representation of the specified cursor type
20712 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
20713 of the bar cursor. */
20715 static enum text_cursor_kinds
20716 get_specified_cursor_type (arg
, width
)
20720 enum text_cursor_kinds type
;
20725 if (EQ (arg
, Qbox
))
20726 return FILLED_BOX_CURSOR
;
20728 if (EQ (arg
, Qhollow
))
20729 return HOLLOW_BOX_CURSOR
;
20731 if (EQ (arg
, Qbar
))
20738 && EQ (XCAR (arg
), Qbar
)
20739 && INTEGERP (XCDR (arg
))
20740 && XINT (XCDR (arg
)) >= 0)
20742 *width
= XINT (XCDR (arg
));
20746 if (EQ (arg
, Qhbar
))
20749 return HBAR_CURSOR
;
20753 && EQ (XCAR (arg
), Qhbar
)
20754 && INTEGERP (XCDR (arg
))
20755 && XINT (XCDR (arg
)) >= 0)
20757 *width
= XINT (XCDR (arg
));
20758 return HBAR_CURSOR
;
20761 /* Treat anything unknown as "hollow box cursor".
20762 It was bad to signal an error; people have trouble fixing
20763 .Xdefaults with Emacs, when it has something bad in it. */
20764 type
= HOLLOW_BOX_CURSOR
;
20769 /* Set the default cursor types for specified frame. */
20771 set_frame_cursor_types (f
, arg
)
20778 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
20779 FRAME_CURSOR_WIDTH (f
) = width
;
20781 /* By default, set up the blink-off state depending on the on-state. */
20783 tem
= Fassoc (arg
, Vblink_cursor_alist
);
20786 FRAME_BLINK_OFF_CURSOR (f
)
20787 = get_specified_cursor_type (XCDR (tem
), &width
);
20788 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
20791 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
20795 /* Return the cursor we want to be displayed in window W. Return
20796 width of bar/hbar cursor through WIDTH arg. Return with
20797 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
20798 (i.e. if the `system caret' should track this cursor).
20800 In a mini-buffer window, we want the cursor only to appear if we
20801 are reading input from this window. For the selected window, we
20802 want the cursor type given by the frame parameter or buffer local
20803 setting of cursor-type. If explicitly marked off, draw no cursor.
20804 In all other cases, we want a hollow box cursor. */
20806 static enum text_cursor_kinds
20807 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
20809 struct glyph
*glyph
;
20811 int *active_cursor
;
20813 struct frame
*f
= XFRAME (w
->frame
);
20814 struct buffer
*b
= XBUFFER (w
->buffer
);
20815 int cursor_type
= DEFAULT_CURSOR
;
20816 Lisp_Object alt_cursor
;
20817 int non_selected
= 0;
20819 *active_cursor
= 1;
20822 if (cursor_in_echo_area
20823 && FRAME_HAS_MINIBUF_P (f
)
20824 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
20826 if (w
== XWINDOW (echo_area_window
))
20828 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
20830 *width
= FRAME_CURSOR_WIDTH (f
);
20831 return FRAME_DESIRED_CURSOR (f
);
20834 return get_specified_cursor_type (b
->cursor_type
, width
);
20837 *active_cursor
= 0;
20841 /* Nonselected window or nonselected frame. */
20842 else if (w
!= XWINDOW (f
->selected_window
)
20843 #ifdef HAVE_WINDOW_SYSTEM
20844 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
20848 *active_cursor
= 0;
20850 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
20856 /* Never display a cursor in a window in which cursor-type is nil. */
20857 if (NILP (b
->cursor_type
))
20860 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
20863 alt_cursor
= b
->cursor_in_non_selected_windows
;
20864 return get_specified_cursor_type (alt_cursor
, width
);
20867 /* Get the normal cursor type for this window. */
20868 if (EQ (b
->cursor_type
, Qt
))
20870 cursor_type
= FRAME_DESIRED_CURSOR (f
);
20871 *width
= FRAME_CURSOR_WIDTH (f
);
20874 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
20876 /* Use normal cursor if not blinked off. */
20877 if (!w
->cursor_off_p
)
20879 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
20880 if (cursor_type
== FILLED_BOX_CURSOR
)
20881 cursor_type
= HOLLOW_BOX_CURSOR
;
20883 return cursor_type
;
20886 /* Cursor is blinked off, so determine how to "toggle" it. */
20888 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
20889 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
20890 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
20892 /* Then see if frame has specified a specific blink off cursor type. */
20893 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
20895 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
20896 return FRAME_BLINK_OFF_CURSOR (f
);
20900 /* Some people liked having a permanently visible blinking cursor,
20901 while others had very strong opinions against it. So it was
20902 decided to remove it. KFS 2003-09-03 */
20904 /* Finally perform built-in cursor blinking:
20905 filled box <-> hollow box
20906 wide [h]bar <-> narrow [h]bar
20907 narrow [h]bar <-> no cursor
20908 other type <-> no cursor */
20910 if (cursor_type
== FILLED_BOX_CURSOR
)
20911 return HOLLOW_BOX_CURSOR
;
20913 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
20916 return cursor_type
;
20924 #ifdef HAVE_WINDOW_SYSTEM
20926 /* Notice when the text cursor of window W has been completely
20927 overwritten by a drawing operation that outputs glyphs in AREA
20928 starting at X0 and ending at X1 in the line starting at Y0 and
20929 ending at Y1. X coordinates are area-relative. X1 < 0 means all
20930 the rest of the line after X0 has been written. Y coordinates
20931 are window-relative. */
20934 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
20936 enum glyph_row_area area
;
20937 int x0
, y0
, x1
, y1
;
20939 int cx0
, cx1
, cy0
, cy1
;
20940 struct glyph_row
*row
;
20942 if (!w
->phys_cursor_on_p
)
20944 if (area
!= TEXT_AREA
)
20947 if (w
->phys_cursor
.vpos
< 0
20948 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
20949 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
20950 !(row
->enabled_p
&& row
->displays_text_p
)))
20953 if (row
->cursor_in_fringe_p
)
20955 row
->cursor_in_fringe_p
= 0;
20956 draw_fringe_bitmap (w
, row
, 0);
20957 w
->phys_cursor_on_p
= 0;
20961 cx0
= w
->phys_cursor
.x
;
20962 cx1
= cx0
+ w
->phys_cursor_width
;
20963 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
20966 /* The cursor image will be completely removed from the
20967 screen if the output area intersects the cursor area in
20968 y-direction. When we draw in [y0 y1[, and some part of
20969 the cursor is at y < y0, that part must have been drawn
20970 before. When scrolling, the cursor is erased before
20971 actually scrolling, so we don't come here. When not
20972 scrolling, the rows above the old cursor row must have
20973 changed, and in this case these rows must have written
20974 over the cursor image.
20976 Likewise if part of the cursor is below y1, with the
20977 exception of the cursor being in the first blank row at
20978 the buffer and window end because update_text_area
20979 doesn't draw that row. (Except when it does, but
20980 that's handled in update_text_area.) */
20982 cy0
= w
->phys_cursor
.y
;
20983 cy1
= cy0
+ w
->phys_cursor_height
;
20984 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
20987 w
->phys_cursor_on_p
= 0;
20990 #endif /* HAVE_WINDOW_SYSTEM */
20993 /************************************************************************
20995 ************************************************************************/
20997 #ifdef HAVE_WINDOW_SYSTEM
21000 Fix the display of area AREA of overlapping row ROW in window W
21001 with respect to the overlapping part OVERLAPS. */
21004 x_fix_overlapping_area (w
, row
, area
, overlaps
)
21006 struct glyph_row
*row
;
21007 enum glyph_row_area area
;
21015 for (i
= 0; i
< row
->used
[area
];)
21017 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
21019 int start
= i
, start_x
= x
;
21023 x
+= row
->glyphs
[area
][i
].pixel_width
;
21026 while (i
< row
->used
[area
]
21027 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
21029 draw_glyphs (w
, start_x
, row
, area
,
21031 DRAW_NORMAL_TEXT
, overlaps
);
21035 x
+= row
->glyphs
[area
][i
].pixel_width
;
21045 Draw the cursor glyph of window W in glyph row ROW. See the
21046 comment of draw_glyphs for the meaning of HL. */
21049 draw_phys_cursor_glyph (w
, row
, hl
)
21051 struct glyph_row
*row
;
21052 enum draw_glyphs_face hl
;
21054 /* If cursor hpos is out of bounds, don't draw garbage. This can
21055 happen in mini-buffer windows when switching between echo area
21056 glyphs and mini-buffer. */
21057 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
21059 int on_p
= w
->phys_cursor_on_p
;
21061 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
21062 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
21064 w
->phys_cursor_on_p
= on_p
;
21066 if (hl
== DRAW_CURSOR
)
21067 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21068 /* When we erase the cursor, and ROW is overlapped by other
21069 rows, make sure that these overlapping parts of other rows
21071 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
21073 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21075 if (row
> w
->current_matrix
->rows
21076 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
21077 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
21078 OVERLAPS_ERASED_CURSOR
);
21080 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
21081 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
21082 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
21083 OVERLAPS_ERASED_CURSOR
);
21090 Erase the image of a cursor of window W from the screen. */
21093 erase_phys_cursor (w
)
21096 struct frame
*f
= XFRAME (w
->frame
);
21097 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21098 int hpos
= w
->phys_cursor
.hpos
;
21099 int vpos
= w
->phys_cursor
.vpos
;
21100 int mouse_face_here_p
= 0;
21101 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
21102 struct glyph_row
*cursor_row
;
21103 struct glyph
*cursor_glyph
;
21104 enum draw_glyphs_face hl
;
21106 /* No cursor displayed or row invalidated => nothing to do on the
21108 if (w
->phys_cursor_type
== NO_CURSOR
)
21109 goto mark_cursor_off
;
21111 /* VPOS >= active_glyphs->nrows means that window has been resized.
21112 Don't bother to erase the cursor. */
21113 if (vpos
>= active_glyphs
->nrows
)
21114 goto mark_cursor_off
;
21116 /* If row containing cursor is marked invalid, there is nothing we
21118 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
21119 if (!cursor_row
->enabled_p
)
21120 goto mark_cursor_off
;
21122 /* If line spacing is > 0, old cursor may only be partially visible in
21123 window after split-window. So adjust visible height. */
21124 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
21125 window_text_bottom_y (w
) - cursor_row
->y
);
21127 /* If row is completely invisible, don't attempt to delete a cursor which
21128 isn't there. This can happen if cursor is at top of a window, and
21129 we switch to a buffer with a header line in that window. */
21130 if (cursor_row
->visible_height
<= 0)
21131 goto mark_cursor_off
;
21133 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
21134 if (cursor_row
->cursor_in_fringe_p
)
21136 cursor_row
->cursor_in_fringe_p
= 0;
21137 draw_fringe_bitmap (w
, cursor_row
, 0);
21138 goto mark_cursor_off
;
21141 /* This can happen when the new row is shorter than the old one.
21142 In this case, either draw_glyphs or clear_end_of_line
21143 should have cleared the cursor. Note that we wouldn't be
21144 able to erase the cursor in this case because we don't have a
21145 cursor glyph at hand. */
21146 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
21147 goto mark_cursor_off
;
21149 /* If the cursor is in the mouse face area, redisplay that when
21150 we clear the cursor. */
21151 if (! NILP (dpyinfo
->mouse_face_window
)
21152 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
21153 && (vpos
> dpyinfo
->mouse_face_beg_row
21154 || (vpos
== dpyinfo
->mouse_face_beg_row
21155 && hpos
>= dpyinfo
->mouse_face_beg_col
))
21156 && (vpos
< dpyinfo
->mouse_face_end_row
21157 || (vpos
== dpyinfo
->mouse_face_end_row
21158 && hpos
< dpyinfo
->mouse_face_end_col
))
21159 /* Don't redraw the cursor's spot in mouse face if it is at the
21160 end of a line (on a newline). The cursor appears there, but
21161 mouse highlighting does not. */
21162 && cursor_row
->used
[TEXT_AREA
] > hpos
)
21163 mouse_face_here_p
= 1;
21165 /* Maybe clear the display under the cursor. */
21166 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
21169 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
21172 cursor_glyph
= get_phys_cursor_glyph (w
);
21173 if (cursor_glyph
== NULL
)
21174 goto mark_cursor_off
;
21176 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
21177 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
21178 width
= min (cursor_glyph
->pixel_width
,
21179 window_box_width (w
, TEXT_AREA
) - w
->phys_cursor
.x
);
21181 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
21184 /* Erase the cursor by redrawing the character underneath it. */
21185 if (mouse_face_here_p
)
21186 hl
= DRAW_MOUSE_FACE
;
21188 hl
= DRAW_NORMAL_TEXT
;
21189 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
21192 w
->phys_cursor_on_p
= 0;
21193 w
->phys_cursor_type
= NO_CURSOR
;
21198 Display or clear cursor of window W. If ON is zero, clear the
21199 cursor. If it is non-zero, display the cursor. If ON is nonzero,
21200 where to put the cursor is specified by HPOS, VPOS, X and Y. */
21203 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
21205 int on
, hpos
, vpos
, x
, y
;
21207 struct frame
*f
= XFRAME (w
->frame
);
21208 int new_cursor_type
;
21209 int new_cursor_width
;
21211 struct glyph_row
*glyph_row
;
21212 struct glyph
*glyph
;
21214 /* This is pointless on invisible frames, and dangerous on garbaged
21215 windows and frames; in the latter case, the frame or window may
21216 be in the midst of changing its size, and x and y may be off the
21218 if (! FRAME_VISIBLE_P (f
)
21219 || FRAME_GARBAGED_P (f
)
21220 || vpos
>= w
->current_matrix
->nrows
21221 || hpos
>= w
->current_matrix
->matrix_w
)
21224 /* If cursor is off and we want it off, return quickly. */
21225 if (!on
&& !w
->phys_cursor_on_p
)
21228 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
21229 /* If cursor row is not enabled, we don't really know where to
21230 display the cursor. */
21231 if (!glyph_row
->enabled_p
)
21233 w
->phys_cursor_on_p
= 0;
21238 if (!glyph_row
->exact_window_width_line_p
21239 || hpos
< glyph_row
->used
[TEXT_AREA
])
21240 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
21242 xassert (interrupt_input_blocked
);
21244 /* Set new_cursor_type to the cursor we want to be displayed. */
21245 new_cursor_type
= get_window_cursor_type (w
, glyph
,
21246 &new_cursor_width
, &active_cursor
);
21248 /* If cursor is currently being shown and we don't want it to be or
21249 it is in the wrong place, or the cursor type is not what we want,
21251 if (w
->phys_cursor_on_p
21253 || w
->phys_cursor
.x
!= x
21254 || w
->phys_cursor
.y
!= y
21255 || new_cursor_type
!= w
->phys_cursor_type
21256 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
21257 && new_cursor_width
!= w
->phys_cursor_width
)))
21258 erase_phys_cursor (w
);
21260 /* Don't check phys_cursor_on_p here because that flag is only set
21261 to zero in some cases where we know that the cursor has been
21262 completely erased, to avoid the extra work of erasing the cursor
21263 twice. In other words, phys_cursor_on_p can be 1 and the cursor
21264 still not be visible, or it has only been partly erased. */
21267 w
->phys_cursor_ascent
= glyph_row
->ascent
;
21268 w
->phys_cursor_height
= glyph_row
->height
;
21270 /* Set phys_cursor_.* before x_draw_.* is called because some
21271 of them may need the information. */
21272 w
->phys_cursor
.x
= x
;
21273 w
->phys_cursor
.y
= glyph_row
->y
;
21274 w
->phys_cursor
.hpos
= hpos
;
21275 w
->phys_cursor
.vpos
= vpos
;
21278 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
21279 new_cursor_type
, new_cursor_width
,
21280 on
, active_cursor
);
21284 /* Switch the display of W's cursor on or off, according to the value
21288 update_window_cursor (w
, on
)
21292 /* Don't update cursor in windows whose frame is in the process
21293 of being deleted. */
21294 if (w
->current_matrix
)
21297 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21298 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21304 /* Call update_window_cursor with parameter ON_P on all leaf windows
21305 in the window tree rooted at W. */
21308 update_cursor_in_window_tree (w
, on_p
)
21314 if (!NILP (w
->hchild
))
21315 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
21316 else if (!NILP (w
->vchild
))
21317 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
21319 update_window_cursor (w
, on_p
);
21321 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
21327 Display the cursor on window W, or clear it, according to ON_P.
21328 Don't change the cursor's position. */
21331 x_update_cursor (f
, on_p
)
21335 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
21340 Clear the cursor of window W to background color, and mark the
21341 cursor as not shown. This is used when the text where the cursor
21342 is is about to be rewritten. */
21348 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
21349 update_window_cursor (w
, 0);
21354 Display the active region described by mouse_face_* according to DRAW. */
21357 show_mouse_face (dpyinfo
, draw
)
21358 Display_Info
*dpyinfo
;
21359 enum draw_glyphs_face draw
;
21361 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
21362 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21364 if (/* If window is in the process of being destroyed, don't bother
21366 w
->current_matrix
!= NULL
21367 /* Don't update mouse highlight if hidden */
21368 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
21369 /* Recognize when we are called to operate on rows that don't exist
21370 anymore. This can happen when a window is split. */
21371 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
21373 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
21374 struct glyph_row
*row
, *first
, *last
;
21376 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
21377 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
21379 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
21381 int start_hpos
, end_hpos
, start_x
;
21383 /* For all but the first row, the highlight starts at column 0. */
21386 start_hpos
= dpyinfo
->mouse_face_beg_col
;
21387 start_x
= dpyinfo
->mouse_face_beg_x
;
21396 end_hpos
= dpyinfo
->mouse_face_end_col
;
21399 end_hpos
= row
->used
[TEXT_AREA
];
21400 if (draw
== DRAW_NORMAL_TEXT
)
21401 row
->fill_line_p
= 1; /* Clear to end of line */
21404 if (end_hpos
> start_hpos
)
21406 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
21407 start_hpos
, end_hpos
,
21411 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
21415 /* When we've written over the cursor, arrange for it to
21416 be displayed again. */
21417 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
21420 display_and_set_cursor (w
, 1,
21421 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21422 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21427 /* Change the mouse cursor. */
21428 if (draw
== DRAW_NORMAL_TEXT
)
21429 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
21430 else if (draw
== DRAW_MOUSE_FACE
)
21431 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
21433 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
21437 Clear out the mouse-highlighted active region.
21438 Redraw it un-highlighted first. Value is non-zero if mouse
21439 face was actually drawn unhighlighted. */
21442 clear_mouse_face (dpyinfo
)
21443 Display_Info
*dpyinfo
;
21447 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
21449 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
21453 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21454 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21455 dpyinfo
->mouse_face_window
= Qnil
;
21456 dpyinfo
->mouse_face_overlay
= Qnil
;
21462 Non-zero if physical cursor of window W is within mouse face. */
21465 cursor_in_mouse_face_p (w
)
21468 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21469 int in_mouse_face
= 0;
21471 if (WINDOWP (dpyinfo
->mouse_face_window
)
21472 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
21474 int hpos
= w
->phys_cursor
.hpos
;
21475 int vpos
= w
->phys_cursor
.vpos
;
21477 if (vpos
>= dpyinfo
->mouse_face_beg_row
21478 && vpos
<= dpyinfo
->mouse_face_end_row
21479 && (vpos
> dpyinfo
->mouse_face_beg_row
21480 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21481 && (vpos
< dpyinfo
->mouse_face_end_row
21482 || hpos
< dpyinfo
->mouse_face_end_col
21483 || dpyinfo
->mouse_face_past_end
))
21487 return in_mouse_face
;
21493 /* Find the glyph matrix position of buffer position CHARPOS in window
21494 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
21495 current glyphs must be up to date. If CHARPOS is above window
21496 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
21497 of last line in W. In the row containing CHARPOS, stop before glyphs
21498 having STOP as object. */
21500 #if 1 /* This is a version of fast_find_position that's more correct
21501 in the presence of hscrolling, for example. I didn't install
21502 it right away because the problem fixed is minor, it failed
21503 in 20.x as well, and I think it's too risky to install
21504 so near the release of 21.1. 2001-09-25 gerd. */
21507 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
21510 int *hpos
, *vpos
, *x
, *y
;
21513 struct glyph_row
*row
, *first
;
21514 struct glyph
*glyph
, *end
;
21517 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21518 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
21523 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
21527 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
21530 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
21534 /* If whole rows or last part of a row came from a display overlay,
21535 row_containing_pos will skip over such rows because their end pos
21536 equals the start pos of the overlay or interval.
21538 Move back if we have a STOP object and previous row's
21539 end glyph came from STOP. */
21542 struct glyph_row
*prev
;
21543 while ((prev
= row
- 1, prev
>= first
)
21544 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
21545 && prev
->used
[TEXT_AREA
] > 0)
21547 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
21548 glyph
= beg
+ prev
->used
[TEXT_AREA
];
21549 while (--glyph
>= beg
21550 && INTEGERP (glyph
->object
));
21552 || !EQ (stop
, glyph
->object
))
21560 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21562 glyph
= row
->glyphs
[TEXT_AREA
];
21563 end
= glyph
+ row
->used
[TEXT_AREA
];
21565 /* Skip over glyphs not having an object at the start of the row.
21566 These are special glyphs like truncation marks on terminal
21568 if (row
->displays_text_p
)
21570 && INTEGERP (glyph
->object
)
21571 && !EQ (stop
, glyph
->object
)
21572 && glyph
->charpos
< 0)
21574 *x
+= glyph
->pixel_width
;
21579 && !INTEGERP (glyph
->object
)
21580 && !EQ (stop
, glyph
->object
)
21581 && (!BUFFERP (glyph
->object
)
21582 || glyph
->charpos
< charpos
))
21584 *x
+= glyph
->pixel_width
;
21588 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
21595 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
21598 int *hpos
, *vpos
, *x
, *y
;
21603 int maybe_next_line_p
= 0;
21604 int line_start_position
;
21605 int yb
= window_text_bottom_y (w
);
21606 struct glyph_row
*row
, *best_row
;
21607 int row_vpos
, best_row_vpos
;
21610 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21611 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21613 while (row
->y
< yb
)
21615 if (row
->used
[TEXT_AREA
])
21616 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
21618 line_start_position
= 0;
21620 if (line_start_position
> pos
)
21622 /* If the position sought is the end of the buffer,
21623 don't include the blank lines at the bottom of the window. */
21624 else if (line_start_position
== pos
21625 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
21627 maybe_next_line_p
= 1;
21630 else if (line_start_position
> 0)
21633 best_row_vpos
= row_vpos
;
21636 if (row
->y
+ row
->height
>= yb
)
21643 /* Find the right column within BEST_ROW. */
21645 current_x
= best_row
->x
;
21646 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
21648 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
21649 int charpos
= glyph
->charpos
;
21651 if (BUFFERP (glyph
->object
))
21653 if (charpos
== pos
)
21656 *vpos
= best_row_vpos
;
21661 else if (charpos
> pos
)
21664 else if (EQ (glyph
->object
, stop
))
21669 current_x
+= glyph
->pixel_width
;
21672 /* If we're looking for the end of the buffer,
21673 and we didn't find it in the line we scanned,
21674 use the start of the following line. */
21675 if (maybe_next_line_p
)
21680 current_x
= best_row
->x
;
21683 *vpos
= best_row_vpos
;
21684 *hpos
= lastcol
+ 1;
21693 /* Find the position of the glyph for position POS in OBJECT in
21694 window W's current matrix, and return in *X, *Y the pixel
21695 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
21697 RIGHT_P non-zero means return the position of the right edge of the
21698 glyph, RIGHT_P zero means return the left edge position.
21700 If no glyph for POS exists in the matrix, return the position of
21701 the glyph with the next smaller position that is in the matrix, if
21702 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
21703 exists in the matrix, return the position of the glyph with the
21704 next larger position in OBJECT.
21706 Value is non-zero if a glyph was found. */
21709 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
21712 Lisp_Object object
;
21713 int *hpos
, *vpos
, *x
, *y
;
21716 int yb
= window_text_bottom_y (w
);
21717 struct glyph_row
*r
;
21718 struct glyph
*best_glyph
= NULL
;
21719 struct glyph_row
*best_row
= NULL
;
21722 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21723 r
->enabled_p
&& r
->y
< yb
;
21726 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
21727 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
21730 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
21731 if (EQ (g
->object
, object
))
21733 if (g
->charpos
== pos
)
21740 else if (best_glyph
== NULL
21741 || ((abs (g
->charpos
- pos
)
21742 < abs (best_glyph
->charpos
- pos
))
21745 : g
->charpos
> pos
)))
21759 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
21763 *x
+= best_glyph
->pixel_width
;
21768 *vpos
= best_row
- w
->current_matrix
->rows
;
21771 return best_glyph
!= NULL
;
21775 /* See if position X, Y is within a hot-spot of an image. */
21778 on_hot_spot_p (hot_spot
, x
, y
)
21779 Lisp_Object hot_spot
;
21782 if (!CONSP (hot_spot
))
21785 if (EQ (XCAR (hot_spot
), Qrect
))
21787 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
21788 Lisp_Object rect
= XCDR (hot_spot
);
21792 if (!CONSP (XCAR (rect
)))
21794 if (!CONSP (XCDR (rect
)))
21796 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
21798 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
21800 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
21802 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
21806 else if (EQ (XCAR (hot_spot
), Qcircle
))
21808 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
21809 Lisp_Object circ
= XCDR (hot_spot
);
21810 Lisp_Object lr
, lx0
, ly0
;
21812 && CONSP (XCAR (circ
))
21813 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
21814 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
21815 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
21817 double r
= XFLOATINT (lr
);
21818 double dx
= XINT (lx0
) - x
;
21819 double dy
= XINT (ly0
) - y
;
21820 return (dx
* dx
+ dy
* dy
<= r
* r
);
21823 else if (EQ (XCAR (hot_spot
), Qpoly
))
21825 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
21826 if (VECTORP (XCDR (hot_spot
)))
21828 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
21829 Lisp_Object
*poly
= v
->contents
;
21833 Lisp_Object lx
, ly
;
21836 /* Need an even number of coordinates, and at least 3 edges. */
21837 if (n
< 6 || n
& 1)
21840 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
21841 If count is odd, we are inside polygon. Pixels on edges
21842 may or may not be included depending on actual geometry of the
21844 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
21845 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
21847 x0
= XINT (lx
), y0
= XINT (ly
);
21848 for (i
= 0; i
< n
; i
+= 2)
21850 int x1
= x0
, y1
= y0
;
21851 if ((lx
= poly
[i
], !INTEGERP (lx
))
21852 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
21854 x0
= XINT (lx
), y0
= XINT (ly
);
21856 /* Does this segment cross the X line? */
21864 if (y
> y0
&& y
> y1
)
21866 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
21872 /* If we don't understand the format, pretend we're not in the hot-spot. */
21877 find_hot_spot (map
, x
, y
)
21881 while (CONSP (map
))
21883 if (CONSP (XCAR (map
))
21884 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
21892 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
21894 doc
: /* Lookup in image map MAP coordinates X and Y.
21895 An image map is an alist where each element has the format (AREA ID PLIST).
21896 An AREA is specified as either a rectangle, a circle, or a polygon:
21897 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
21898 pixel coordinates of the upper left and bottom right corners.
21899 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
21900 and the radius of the circle; r may be a float or integer.
21901 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
21902 vector describes one corner in the polygon.
21903 Returns the alist element for the first matching AREA in MAP. */)
21914 return find_hot_spot (map
, XINT (x
), XINT (y
));
21918 /* Display frame CURSOR, optionally using shape defined by POINTER. */
21920 define_frame_cursor1 (f
, cursor
, pointer
)
21923 Lisp_Object pointer
;
21925 /* Do not change cursor shape while dragging mouse. */
21926 if (!NILP (do_mouse_tracking
))
21929 if (!NILP (pointer
))
21931 if (EQ (pointer
, Qarrow
))
21932 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21933 else if (EQ (pointer
, Qhand
))
21934 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
21935 else if (EQ (pointer
, Qtext
))
21936 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21937 else if (EQ (pointer
, intern ("hdrag")))
21938 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21939 #ifdef HAVE_X_WINDOWS
21940 else if (EQ (pointer
, intern ("vdrag")))
21941 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
21943 else if (EQ (pointer
, intern ("hourglass")))
21944 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
21945 else if (EQ (pointer
, Qmodeline
))
21946 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
21948 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21951 if (cursor
!= No_Cursor
)
21952 rif
->define_frame_cursor (f
, cursor
);
21955 /* Take proper action when mouse has moved to the mode or header line
21956 or marginal area AREA of window W, x-position X and y-position Y.
21957 X is relative to the start of the text display area of W, so the
21958 width of bitmap areas and scroll bars must be subtracted to get a
21959 position relative to the start of the mode line. */
21962 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
21963 Lisp_Object window
;
21965 enum window_part area
;
21967 struct window
*w
= XWINDOW (window
);
21968 struct frame
*f
= XFRAME (w
->frame
);
21969 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21970 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21971 Lisp_Object pointer
= Qnil
;
21972 int charpos
, dx
, dy
, width
, height
;
21973 Lisp_Object string
, object
= Qnil
;
21974 Lisp_Object pos
, help
;
21976 Lisp_Object mouse_face
;
21977 int original_x_pixel
= x
;
21978 struct glyph
* glyph
= NULL
;
21979 struct glyph_row
*row
;
21981 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
21986 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
21987 &object
, &dx
, &dy
, &width
, &height
);
21989 row
= (area
== ON_MODE_LINE
21990 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
21991 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
21994 if (row
->mode_line_p
&& row
->enabled_p
)
21996 glyph
= row
->glyphs
[TEXT_AREA
];
21997 end
= glyph
+ row
->used
[TEXT_AREA
];
21999 for (x0
= original_x_pixel
;
22000 glyph
< end
&& x0
>= glyph
->pixel_width
;
22002 x0
-= glyph
->pixel_width
;
22010 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
22011 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
22012 &object
, &dx
, &dy
, &width
, &height
);
22017 if (IMAGEP (object
))
22019 Lisp_Object image_map
, hotspot
;
22020 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
22022 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
22024 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22026 Lisp_Object area_id
, plist
;
22028 area_id
= XCAR (hotspot
);
22029 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22030 If so, we could look for mouse-enter, mouse-leave
22031 properties in PLIST (and do something...). */
22032 hotspot
= XCDR (hotspot
);
22033 if (CONSP (hotspot
)
22034 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22036 pointer
= Fplist_get (plist
, Qpointer
);
22037 if (NILP (pointer
))
22039 help
= Fplist_get (plist
, Qhelp_echo
);
22042 help_echo_string
= help
;
22043 /* Is this correct? ++kfs */
22044 XSETWINDOW (help_echo_window
, w
);
22045 help_echo_object
= w
->buffer
;
22046 help_echo_pos
= charpos
;
22050 if (NILP (pointer
))
22051 pointer
= Fplist_get (XCDR (object
), QCpointer
);
22054 if (STRINGP (string
))
22056 pos
= make_number (charpos
);
22057 /* If we're on a string with `help-echo' text property, arrange
22058 for the help to be displayed. This is done by setting the
22059 global variable help_echo_string to the help string. */
22062 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
22065 help_echo_string
= help
;
22066 XSETWINDOW (help_echo_window
, w
);
22067 help_echo_object
= string
;
22068 help_echo_pos
= charpos
;
22072 if (NILP (pointer
))
22073 pointer
= Fget_text_property (pos
, Qpointer
, string
);
22075 /* Change the mouse pointer according to what is under X/Y. */
22076 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
22079 map
= Fget_text_property (pos
, Qlocal_map
, string
);
22080 if (!KEYMAPP (map
))
22081 map
= Fget_text_property (pos
, Qkeymap
, string
);
22082 if (!KEYMAPP (map
))
22083 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
22086 /* Change the mouse face according to what is under X/Y. */
22087 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
22088 if (!NILP (mouse_face
)
22089 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22094 struct glyph
* tmp_glyph
;
22098 int total_pixel_width
;
22103 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
22104 Qmouse_face
, string
, Qnil
);
22106 b
= make_number (0);
22108 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
22110 e
= make_number (SCHARS (string
));
22112 /* Calculate the position(glyph position: GPOS) of GLYPH in
22113 displayed string. GPOS is different from CHARPOS.
22115 CHARPOS is the position of glyph in internal string
22116 object. A mode line string format has structures which
22117 is converted to a flatten by emacs lisp interpreter.
22118 The internal string is an element of the structures.
22119 The displayed string is the flatten string. */
22120 for (tmp_glyph
= glyph
- 1, gpos
= 0;
22121 tmp_glyph
->charpos
>= XINT (b
);
22122 tmp_glyph
--, gpos
++)
22124 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22128 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
22129 displayed string holding GLYPH.
22131 GSEQ_LENGTH is different from SCHARS (STRING).
22132 SCHARS (STRING) returns the length of the internal string. */
22133 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
22134 tmp_glyph
->charpos
< XINT (e
);
22135 tmp_glyph
++, gseq_length
++)
22137 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22141 total_pixel_width
= 0;
22142 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
22143 total_pixel_width
+= tmp_glyph
->pixel_width
;
22145 /* Pre calculation of re-rendering position */
22147 hpos
= (area
== ON_MODE_LINE
22148 ? (w
->current_matrix
)->nrows
- 1
22151 /* If the re-rendering position is included in the last
22152 re-rendering area, we should do nothing. */
22153 if ( EQ (window
, dpyinfo
->mouse_face_window
)
22154 && dpyinfo
->mouse_face_beg_col
<= vpos
22155 && vpos
< dpyinfo
->mouse_face_end_col
22156 && dpyinfo
->mouse_face_beg_row
== hpos
)
22159 if (clear_mouse_face (dpyinfo
))
22160 cursor
= No_Cursor
;
22162 dpyinfo
->mouse_face_beg_col
= vpos
;
22163 dpyinfo
->mouse_face_beg_row
= hpos
;
22165 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
22166 dpyinfo
->mouse_face_beg_y
= 0;
22168 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
22169 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
22171 dpyinfo
->mouse_face_end_x
= 0;
22172 dpyinfo
->mouse_face_end_y
= 0;
22174 dpyinfo
->mouse_face_past_end
= 0;
22175 dpyinfo
->mouse_face_window
= window
;
22177 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
22180 glyph
->face_id
, 1);
22181 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22183 if (NILP (pointer
))
22186 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22187 clear_mouse_face (dpyinfo
);
22189 define_frame_cursor1 (f
, cursor
, pointer
);
22194 Take proper action when the mouse has moved to position X, Y on
22195 frame F as regards highlighting characters that have mouse-face
22196 properties. Also de-highlighting chars where the mouse was before.
22197 X and Y can be negative or out of range. */
22200 note_mouse_highlight (f
, x
, y
)
22204 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22205 enum window_part part
;
22206 Lisp_Object window
;
22208 Cursor cursor
= No_Cursor
;
22209 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
22212 /* When a menu is active, don't highlight because this looks odd. */
22213 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
22214 if (popup_activated ())
22218 if (NILP (Vmouse_highlight
)
22219 || !f
->glyphs_initialized_p
)
22222 dpyinfo
->mouse_face_mouse_x
= x
;
22223 dpyinfo
->mouse_face_mouse_y
= y
;
22224 dpyinfo
->mouse_face_mouse_frame
= f
;
22226 if (dpyinfo
->mouse_face_defer
)
22229 if (gc_in_progress
)
22231 dpyinfo
->mouse_face_deferred_gc
= 1;
22235 /* Which window is that in? */
22236 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
22238 /* If we were displaying active text in another window, clear that.
22239 Also clear if we move out of text area in same window. */
22240 if (! EQ (window
, dpyinfo
->mouse_face_window
)
22241 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
22242 && !NILP (dpyinfo
->mouse_face_window
)))
22243 clear_mouse_face (dpyinfo
);
22245 /* Not on a window -> return. */
22246 if (!WINDOWP (window
))
22249 /* Reset help_echo_string. It will get recomputed below. */
22250 help_echo_string
= Qnil
;
22252 /* Convert to window-relative pixel coordinates. */
22253 w
= XWINDOW (window
);
22254 frame_to_window_pixel_xy (w
, &x
, &y
);
22256 /* Handle tool-bar window differently since it doesn't display a
22258 if (EQ (window
, f
->tool_bar_window
))
22260 note_tool_bar_highlight (f
, x
, y
);
22264 /* Mouse is on the mode, header line or margin? */
22265 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
22266 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
22268 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
22272 if (part
== ON_VERTICAL_BORDER
)
22273 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22274 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
22275 || part
== ON_SCROLL_BAR
)
22276 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22278 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22280 /* Are we in a window whose display is up to date?
22281 And verify the buffer's text has not changed. */
22282 b
= XBUFFER (w
->buffer
);
22283 if (part
== ON_TEXT
22284 && EQ (w
->window_end_valid
, w
->buffer
)
22285 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
22286 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
22288 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
22289 struct glyph
*glyph
;
22290 Lisp_Object object
;
22291 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
22292 Lisp_Object
*overlay_vec
= NULL
;
22294 struct buffer
*obuf
;
22295 int obegv
, ozv
, same_region
;
22297 /* Find the glyph under X/Y. */
22298 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
22300 /* Look for :pointer property on image. */
22301 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22303 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22304 if (img
!= NULL
&& IMAGEP (img
->spec
))
22306 Lisp_Object image_map
, hotspot
;
22307 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
22309 && (hotspot
= find_hot_spot (image_map
,
22310 glyph
->slice
.x
+ dx
,
22311 glyph
->slice
.y
+ dy
),
22313 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22315 Lisp_Object area_id
, plist
;
22317 area_id
= XCAR (hotspot
);
22318 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22319 If so, we could look for mouse-enter, mouse-leave
22320 properties in PLIST (and do something...). */
22321 hotspot
= XCDR (hotspot
);
22322 if (CONSP (hotspot
)
22323 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22325 pointer
= Fplist_get (plist
, Qpointer
);
22326 if (NILP (pointer
))
22328 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
22329 if (!NILP (help_echo_string
))
22331 help_echo_window
= window
;
22332 help_echo_object
= glyph
->object
;
22333 help_echo_pos
= glyph
->charpos
;
22337 if (NILP (pointer
))
22338 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
22342 /* Clear mouse face if X/Y not over text. */
22344 || area
!= TEXT_AREA
22345 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
22347 if (clear_mouse_face (dpyinfo
))
22348 cursor
= No_Cursor
;
22349 if (NILP (pointer
))
22351 if (area
!= TEXT_AREA
)
22352 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22354 pointer
= Vvoid_text_area_pointer
;
22359 pos
= glyph
->charpos
;
22360 object
= glyph
->object
;
22361 if (!STRINGP (object
) && !BUFFERP (object
))
22364 /* If we get an out-of-range value, return now; avoid an error. */
22365 if (BUFFERP (object
) && pos
> BUF_Z (b
))
22368 /* Make the window's buffer temporarily current for
22369 overlays_at and compute_char_face. */
22370 obuf
= current_buffer
;
22371 current_buffer
= b
;
22377 /* Is this char mouse-active or does it have help-echo? */
22378 position
= make_number (pos
);
22380 if (BUFFERP (object
))
22382 /* Put all the overlays we want in a vector in overlay_vec. */
22383 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
22384 /* Sort overlays into increasing priority order. */
22385 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
22390 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
22391 && vpos
>= dpyinfo
->mouse_face_beg_row
22392 && vpos
<= dpyinfo
->mouse_face_end_row
22393 && (vpos
> dpyinfo
->mouse_face_beg_row
22394 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22395 && (vpos
< dpyinfo
->mouse_face_end_row
22396 || hpos
< dpyinfo
->mouse_face_end_col
22397 || dpyinfo
->mouse_face_past_end
));
22400 cursor
= No_Cursor
;
22402 /* Check mouse-face highlighting. */
22404 /* If there exists an overlay with mouse-face overlapping
22405 the one we are currently highlighting, we have to
22406 check if we enter the overlapping overlay, and then
22407 highlight only that. */
22408 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
22409 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
22411 /* Find the highest priority overlay that has a mouse-face
22414 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
22416 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
22417 if (!NILP (mouse_face
))
22418 overlay
= overlay_vec
[i
];
22421 /* If we're actually highlighting the same overlay as
22422 before, there's no need to do that again. */
22423 if (!NILP (overlay
)
22424 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
22425 goto check_help_echo
;
22427 dpyinfo
->mouse_face_overlay
= overlay
;
22429 /* Clear the display of the old active region, if any. */
22430 if (clear_mouse_face (dpyinfo
))
22431 cursor
= No_Cursor
;
22433 /* If no overlay applies, get a text property. */
22434 if (NILP (overlay
))
22435 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
22437 /* Handle the overlay case. */
22438 if (!NILP (overlay
))
22440 /* Find the range of text around this char that
22441 should be active. */
22442 Lisp_Object before
, after
;
22445 before
= Foverlay_start (overlay
);
22446 after
= Foverlay_end (overlay
);
22447 /* Record this as the current active region. */
22448 fast_find_position (w
, XFASTINT (before
),
22449 &dpyinfo
->mouse_face_beg_col
,
22450 &dpyinfo
->mouse_face_beg_row
,
22451 &dpyinfo
->mouse_face_beg_x
,
22452 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22454 dpyinfo
->mouse_face_past_end
22455 = !fast_find_position (w
, XFASTINT (after
),
22456 &dpyinfo
->mouse_face_end_col
,
22457 &dpyinfo
->mouse_face_end_row
,
22458 &dpyinfo
->mouse_face_end_x
,
22459 &dpyinfo
->mouse_face_end_y
, Qnil
);
22460 dpyinfo
->mouse_face_window
= window
;
22462 dpyinfo
->mouse_face_face_id
22463 = face_at_buffer_position (w
, pos
, 0, 0,
22465 !dpyinfo
->mouse_face_hidden
);
22467 /* Display it as active. */
22468 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22469 cursor
= No_Cursor
;
22471 /* Handle the text property case. */
22472 else if (!NILP (mouse_face
) && BUFFERP (object
))
22474 /* Find the range of text around this char that
22475 should be active. */
22476 Lisp_Object before
, after
, beginning
, end
;
22479 beginning
= Fmarker_position (w
->start
);
22480 end
= make_number (BUF_Z (XBUFFER (object
))
22481 - XFASTINT (w
->window_end_pos
));
22483 = Fprevious_single_property_change (make_number (pos
+ 1),
22485 object
, beginning
);
22487 = Fnext_single_property_change (position
, Qmouse_face
,
22490 /* Record this as the current active region. */
22491 fast_find_position (w
, XFASTINT (before
),
22492 &dpyinfo
->mouse_face_beg_col
,
22493 &dpyinfo
->mouse_face_beg_row
,
22494 &dpyinfo
->mouse_face_beg_x
,
22495 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22496 dpyinfo
->mouse_face_past_end
22497 = !fast_find_position (w
, XFASTINT (after
),
22498 &dpyinfo
->mouse_face_end_col
,
22499 &dpyinfo
->mouse_face_end_row
,
22500 &dpyinfo
->mouse_face_end_x
,
22501 &dpyinfo
->mouse_face_end_y
, Qnil
);
22502 dpyinfo
->mouse_face_window
= window
;
22504 if (BUFFERP (object
))
22505 dpyinfo
->mouse_face_face_id
22506 = face_at_buffer_position (w
, pos
, 0, 0,
22508 !dpyinfo
->mouse_face_hidden
);
22510 /* Display it as active. */
22511 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22512 cursor
= No_Cursor
;
22514 else if (!NILP (mouse_face
) && STRINGP (object
))
22519 b
= Fprevious_single_property_change (make_number (pos
+ 1),
22522 e
= Fnext_single_property_change (position
, Qmouse_face
,
22525 b
= make_number (0);
22527 e
= make_number (SCHARS (object
) - 1);
22529 fast_find_string_pos (w
, XINT (b
), object
,
22530 &dpyinfo
->mouse_face_beg_col
,
22531 &dpyinfo
->mouse_face_beg_row
,
22532 &dpyinfo
->mouse_face_beg_x
,
22533 &dpyinfo
->mouse_face_beg_y
, 0);
22534 fast_find_string_pos (w
, XINT (e
), object
,
22535 &dpyinfo
->mouse_face_end_col
,
22536 &dpyinfo
->mouse_face_end_row
,
22537 &dpyinfo
->mouse_face_end_x
,
22538 &dpyinfo
->mouse_face_end_y
, 1);
22539 dpyinfo
->mouse_face_past_end
= 0;
22540 dpyinfo
->mouse_face_window
= window
;
22541 dpyinfo
->mouse_face_face_id
22542 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
22543 glyph
->face_id
, 1);
22544 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22545 cursor
= No_Cursor
;
22547 else if (STRINGP (object
) && NILP (mouse_face
))
22549 /* A string which doesn't have mouse-face, but
22550 the text ``under'' it might have. */
22551 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
22552 int start
= MATRIX_ROW_START_CHARPOS (r
);
22554 pos
= string_buffer_position (w
, object
, start
);
22556 mouse_face
= get_char_property_and_overlay (make_number (pos
),
22560 if (!NILP (mouse_face
) && !NILP (overlay
))
22562 Lisp_Object before
= Foverlay_start (overlay
);
22563 Lisp_Object after
= Foverlay_end (overlay
);
22566 /* Note that we might not be able to find position
22567 BEFORE in the glyph matrix if the overlay is
22568 entirely covered by a `display' property. In
22569 this case, we overshoot. So let's stop in
22570 the glyph matrix before glyphs for OBJECT. */
22571 fast_find_position (w
, XFASTINT (before
),
22572 &dpyinfo
->mouse_face_beg_col
,
22573 &dpyinfo
->mouse_face_beg_row
,
22574 &dpyinfo
->mouse_face_beg_x
,
22575 &dpyinfo
->mouse_face_beg_y
,
22578 dpyinfo
->mouse_face_past_end
22579 = !fast_find_position (w
, XFASTINT (after
),
22580 &dpyinfo
->mouse_face_end_col
,
22581 &dpyinfo
->mouse_face_end_row
,
22582 &dpyinfo
->mouse_face_end_x
,
22583 &dpyinfo
->mouse_face_end_y
,
22585 dpyinfo
->mouse_face_window
= window
;
22586 dpyinfo
->mouse_face_face_id
22587 = face_at_buffer_position (w
, pos
, 0, 0,
22589 !dpyinfo
->mouse_face_hidden
);
22591 /* Display it as active. */
22592 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22593 cursor
= No_Cursor
;
22600 /* Look for a `help-echo' property. */
22601 if (NILP (help_echo_string
)) {
22602 Lisp_Object help
, overlay
;
22604 /* Check overlays first. */
22605 help
= overlay
= Qnil
;
22606 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
22608 overlay
= overlay_vec
[i
];
22609 help
= Foverlay_get (overlay
, Qhelp_echo
);
22614 help_echo_string
= help
;
22615 help_echo_window
= window
;
22616 help_echo_object
= overlay
;
22617 help_echo_pos
= pos
;
22621 Lisp_Object object
= glyph
->object
;
22622 int charpos
= glyph
->charpos
;
22624 /* Try text properties. */
22625 if (STRINGP (object
)
22627 && charpos
< SCHARS (object
))
22629 help
= Fget_text_property (make_number (charpos
),
22630 Qhelp_echo
, object
);
22633 /* If the string itself doesn't specify a help-echo,
22634 see if the buffer text ``under'' it does. */
22635 struct glyph_row
*r
22636 = MATRIX_ROW (w
->current_matrix
, vpos
);
22637 int start
= MATRIX_ROW_START_CHARPOS (r
);
22638 int pos
= string_buffer_position (w
, object
, start
);
22641 help
= Fget_char_property (make_number (pos
),
22642 Qhelp_echo
, w
->buffer
);
22646 object
= w
->buffer
;
22651 else if (BUFFERP (object
)
22654 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
22659 help_echo_string
= help
;
22660 help_echo_window
= window
;
22661 help_echo_object
= object
;
22662 help_echo_pos
= charpos
;
22667 /* Look for a `pointer' property. */
22668 if (NILP (pointer
))
22670 /* Check overlays first. */
22671 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
22672 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
22674 if (NILP (pointer
))
22676 Lisp_Object object
= glyph
->object
;
22677 int charpos
= glyph
->charpos
;
22679 /* Try text properties. */
22680 if (STRINGP (object
)
22682 && charpos
< SCHARS (object
))
22684 pointer
= Fget_text_property (make_number (charpos
),
22686 if (NILP (pointer
))
22688 /* If the string itself doesn't specify a pointer,
22689 see if the buffer text ``under'' it does. */
22690 struct glyph_row
*r
22691 = MATRIX_ROW (w
->current_matrix
, vpos
);
22692 int start
= MATRIX_ROW_START_CHARPOS (r
);
22693 int pos
= string_buffer_position (w
, object
, start
);
22695 pointer
= Fget_char_property (make_number (pos
),
22696 Qpointer
, w
->buffer
);
22699 else if (BUFFERP (object
)
22702 pointer
= Fget_text_property (make_number (charpos
),
22709 current_buffer
= obuf
;
22714 define_frame_cursor1 (f
, cursor
, pointer
);
22719 Clear any mouse-face on window W. This function is part of the
22720 redisplay interface, and is called from try_window_id and similar
22721 functions to ensure the mouse-highlight is off. */
22724 x_clear_window_mouse_face (w
)
22727 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22728 Lisp_Object window
;
22731 XSETWINDOW (window
, w
);
22732 if (EQ (window
, dpyinfo
->mouse_face_window
))
22733 clear_mouse_face (dpyinfo
);
22739 Just discard the mouse face information for frame F, if any.
22740 This is used when the size of F is changed. */
22743 cancel_mouse_face (f
)
22746 Lisp_Object window
;
22747 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22749 window
= dpyinfo
->mouse_face_window
;
22750 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
22752 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22753 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22754 dpyinfo
->mouse_face_window
= Qnil
;
22759 #endif /* HAVE_WINDOW_SYSTEM */
22762 /***********************************************************************
22764 ***********************************************************************/
22766 #ifdef HAVE_WINDOW_SYSTEM
22768 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
22769 which intersects rectangle R. R is in window-relative coordinates. */
22772 expose_area (w
, row
, r
, area
)
22774 struct glyph_row
*row
;
22776 enum glyph_row_area area
;
22778 struct glyph
*first
= row
->glyphs
[area
];
22779 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
22780 struct glyph
*last
;
22781 int first_x
, start_x
, x
;
22783 if (area
== TEXT_AREA
&& row
->fill_line_p
)
22784 /* If row extends face to end of line write the whole line. */
22785 draw_glyphs (w
, 0, row
, area
,
22786 0, row
->used
[area
],
22787 DRAW_NORMAL_TEXT
, 0);
22790 /* Set START_X to the window-relative start position for drawing glyphs of
22791 AREA. The first glyph of the text area can be partially visible.
22792 The first glyphs of other areas cannot. */
22793 start_x
= window_box_left_offset (w
, area
);
22795 if (area
== TEXT_AREA
)
22798 /* Find the first glyph that must be redrawn. */
22800 && x
+ first
->pixel_width
< r
->x
)
22802 x
+= first
->pixel_width
;
22806 /* Find the last one. */
22810 && x
< r
->x
+ r
->width
)
22812 x
+= last
->pixel_width
;
22818 draw_glyphs (w
, first_x
- start_x
, row
, area
,
22819 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
22820 DRAW_NORMAL_TEXT
, 0);
22825 /* Redraw the parts of the glyph row ROW on window W intersecting
22826 rectangle R. R is in window-relative coordinates. Value is
22827 non-zero if mouse-face was overwritten. */
22830 expose_line (w
, row
, r
)
22832 struct glyph_row
*row
;
22835 xassert (row
->enabled_p
);
22837 if (row
->mode_line_p
|| w
->pseudo_window_p
)
22838 draw_glyphs (w
, 0, row
, TEXT_AREA
,
22839 0, row
->used
[TEXT_AREA
],
22840 DRAW_NORMAL_TEXT
, 0);
22843 if (row
->used
[LEFT_MARGIN_AREA
])
22844 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
22845 if (row
->used
[TEXT_AREA
])
22846 expose_area (w
, row
, r
, TEXT_AREA
);
22847 if (row
->used
[RIGHT_MARGIN_AREA
])
22848 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
22849 draw_row_fringe_bitmaps (w
, row
);
22852 return row
->mouse_face_p
;
22856 /* Redraw those parts of glyphs rows during expose event handling that
22857 overlap other rows. Redrawing of an exposed line writes over parts
22858 of lines overlapping that exposed line; this function fixes that.
22860 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
22861 row in W's current matrix that is exposed and overlaps other rows.
22862 LAST_OVERLAPPING_ROW is the last such row. */
22865 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
22867 struct glyph_row
*first_overlapping_row
;
22868 struct glyph_row
*last_overlapping_row
;
22870 struct glyph_row
*row
;
22872 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
22873 if (row
->overlapping_p
)
22875 xassert (row
->enabled_p
&& !row
->mode_line_p
);
22877 if (row
->used
[LEFT_MARGIN_AREA
])
22878 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
22880 if (row
->used
[TEXT_AREA
])
22881 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
22883 if (row
->used
[RIGHT_MARGIN_AREA
])
22884 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
22889 /* Return non-zero if W's cursor intersects rectangle R. */
22892 phys_cursor_in_rect_p (w
, r
)
22896 XRectangle cr
, result
;
22897 struct glyph
*cursor_glyph
;
22899 cursor_glyph
= get_phys_cursor_glyph (w
);
22902 /* r is relative to W's box, but w->phys_cursor.x is relative
22903 to left edge of W's TEXT area. Adjust it. */
22904 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
22905 cr
.y
= w
->phys_cursor
.y
;
22906 cr
.width
= cursor_glyph
->pixel_width
;
22907 cr
.height
= w
->phys_cursor_height
;
22908 /* ++KFS: W32 version used W32-specific IntersectRect here, but
22909 I assume the effect is the same -- and this is portable. */
22910 return x_intersect_rectangles (&cr
, r
, &result
);
22918 Draw a vertical window border to the right of window W if W doesn't
22919 have vertical scroll bars. */
22922 x_draw_vertical_border (w
)
22925 /* We could do better, if we knew what type of scroll-bar the adjacent
22926 windows (on either side) have... But we don't :-(
22927 However, I think this works ok. ++KFS 2003-04-25 */
22929 /* Redraw borders between horizontally adjacent windows. Don't
22930 do it for frames with vertical scroll bars because either the
22931 right scroll bar of a window, or the left scroll bar of its
22932 neighbor will suffice as a border. */
22933 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
22936 if (!WINDOW_RIGHTMOST_P (w
)
22937 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
22939 int x0
, x1
, y0
, y1
;
22941 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22944 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22947 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
22949 else if (!WINDOW_LEFTMOST_P (w
)
22950 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
22952 int x0
, x1
, y0
, y1
;
22954 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22957 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22960 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
22965 /* Redraw the part of window W intersection rectangle FR. Pixel
22966 coordinates in FR are frame-relative. Call this function with
22967 input blocked. Value is non-zero if the exposure overwrites
22971 expose_window (w
, fr
)
22975 struct frame
*f
= XFRAME (w
->frame
);
22977 int mouse_face_overwritten_p
= 0;
22979 /* If window is not yet fully initialized, do nothing. This can
22980 happen when toolkit scroll bars are used and a window is split.
22981 Reconfiguring the scroll bar will generate an expose for a newly
22983 if (w
->current_matrix
== NULL
)
22986 /* When we're currently updating the window, display and current
22987 matrix usually don't agree. Arrange for a thorough display
22989 if (w
== updated_window
)
22991 SET_FRAME_GARBAGED (f
);
22995 /* Frame-relative pixel rectangle of W. */
22996 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
22997 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
22998 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
22999 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
23001 if (x_intersect_rectangles (fr
, &wr
, &r
))
23003 int yb
= window_text_bottom_y (w
);
23004 struct glyph_row
*row
;
23005 int cursor_cleared_p
;
23006 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
23008 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
23009 r
.x
, r
.y
, r
.width
, r
.height
));
23011 /* Convert to window coordinates. */
23012 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
23013 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
23015 /* Turn off the cursor. */
23016 if (!w
->pseudo_window_p
23017 && phys_cursor_in_rect_p (w
, &r
))
23019 x_clear_cursor (w
);
23020 cursor_cleared_p
= 1;
23023 cursor_cleared_p
= 0;
23025 /* Update lines intersecting rectangle R. */
23026 first_overlapping_row
= last_overlapping_row
= NULL
;
23027 for (row
= w
->current_matrix
->rows
;
23032 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
23034 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
23035 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
23036 || (r
.y
>= y0
&& r
.y
< y1
)
23037 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
23039 /* A header line may be overlapping, but there is no need
23040 to fix overlapping areas for them. KFS 2005-02-12 */
23041 if (row
->overlapping_p
&& !row
->mode_line_p
)
23043 if (first_overlapping_row
== NULL
)
23044 first_overlapping_row
= row
;
23045 last_overlapping_row
= row
;
23048 if (expose_line (w
, row
, &r
))
23049 mouse_face_overwritten_p
= 1;
23056 /* Display the mode line if there is one. */
23057 if (WINDOW_WANTS_MODELINE_P (w
)
23058 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
23060 && row
->y
< r
.y
+ r
.height
)
23062 if (expose_line (w
, row
, &r
))
23063 mouse_face_overwritten_p
= 1;
23066 if (!w
->pseudo_window_p
)
23068 /* Fix the display of overlapping rows. */
23069 if (first_overlapping_row
)
23070 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
23072 /* Draw border between windows. */
23073 x_draw_vertical_border (w
);
23075 /* Turn the cursor on again. */
23076 if (cursor_cleared_p
)
23077 update_window_cursor (w
, 1);
23081 return mouse_face_overwritten_p
;
23086 /* Redraw (parts) of all windows in the window tree rooted at W that
23087 intersect R. R contains frame pixel coordinates. Value is
23088 non-zero if the exposure overwrites mouse-face. */
23091 expose_window_tree (w
, r
)
23095 struct frame
*f
= XFRAME (w
->frame
);
23096 int mouse_face_overwritten_p
= 0;
23098 while (w
&& !FRAME_GARBAGED_P (f
))
23100 if (!NILP (w
->hchild
))
23101 mouse_face_overwritten_p
23102 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
23103 else if (!NILP (w
->vchild
))
23104 mouse_face_overwritten_p
23105 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
23107 mouse_face_overwritten_p
|= expose_window (w
, r
);
23109 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
23112 return mouse_face_overwritten_p
;
23117 Redisplay an exposed area of frame F. X and Y are the upper-left
23118 corner of the exposed rectangle. W and H are width and height of
23119 the exposed area. All are pixel values. W or H zero means redraw
23120 the entire frame. */
23123 expose_frame (f
, x
, y
, w
, h
)
23128 int mouse_face_overwritten_p
= 0;
23130 TRACE ((stderr
, "expose_frame "));
23132 /* No need to redraw if frame will be redrawn soon. */
23133 if (FRAME_GARBAGED_P (f
))
23135 TRACE ((stderr
, " garbaged\n"));
23139 /* If basic faces haven't been realized yet, there is no point in
23140 trying to redraw anything. This can happen when we get an expose
23141 event while Emacs is starting, e.g. by moving another window. */
23142 if (FRAME_FACE_CACHE (f
) == NULL
23143 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
23145 TRACE ((stderr
, " no faces\n"));
23149 if (w
== 0 || h
== 0)
23152 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
23153 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
23163 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
23164 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
23166 if (WINDOWP (f
->tool_bar_window
))
23167 mouse_face_overwritten_p
23168 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
23170 #ifdef HAVE_X_WINDOWS
23172 #ifndef USE_X_TOOLKIT
23173 if (WINDOWP (f
->menu_bar_window
))
23174 mouse_face_overwritten_p
23175 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
23176 #endif /* not USE_X_TOOLKIT */
23180 /* Some window managers support a focus-follows-mouse style with
23181 delayed raising of frames. Imagine a partially obscured frame,
23182 and moving the mouse into partially obscured mouse-face on that
23183 frame. The visible part of the mouse-face will be highlighted,
23184 then the WM raises the obscured frame. With at least one WM, KDE
23185 2.1, Emacs is not getting any event for the raising of the frame
23186 (even tried with SubstructureRedirectMask), only Expose events.
23187 These expose events will draw text normally, i.e. not
23188 highlighted. Which means we must redo the highlight here.
23189 Subsume it under ``we love X''. --gerd 2001-08-15 */
23190 /* Included in Windows version because Windows most likely does not
23191 do the right thing if any third party tool offers
23192 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
23193 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
23195 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23196 if (f
== dpyinfo
->mouse_face_mouse_frame
)
23198 int x
= dpyinfo
->mouse_face_mouse_x
;
23199 int y
= dpyinfo
->mouse_face_mouse_y
;
23200 clear_mouse_face (dpyinfo
);
23201 note_mouse_highlight (f
, x
, y
);
23208 Determine the intersection of two rectangles R1 and R2. Return
23209 the intersection in *RESULT. Value is non-zero if RESULT is not
23213 x_intersect_rectangles (r1
, r2
, result
)
23214 XRectangle
*r1
, *r2
, *result
;
23216 XRectangle
*left
, *right
;
23217 XRectangle
*upper
, *lower
;
23218 int intersection_p
= 0;
23220 /* Rearrange so that R1 is the left-most rectangle. */
23222 left
= r1
, right
= r2
;
23224 left
= r2
, right
= r1
;
23226 /* X0 of the intersection is right.x0, if this is inside R1,
23227 otherwise there is no intersection. */
23228 if (right
->x
<= left
->x
+ left
->width
)
23230 result
->x
= right
->x
;
23232 /* The right end of the intersection is the minimum of the
23233 the right ends of left and right. */
23234 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
23237 /* Same game for Y. */
23239 upper
= r1
, lower
= r2
;
23241 upper
= r2
, lower
= r1
;
23243 /* The upper end of the intersection is lower.y0, if this is inside
23244 of upper. Otherwise, there is no intersection. */
23245 if (lower
->y
<= upper
->y
+ upper
->height
)
23247 result
->y
= lower
->y
;
23249 /* The lower end of the intersection is the minimum of the lower
23250 ends of upper and lower. */
23251 result
->height
= (min (lower
->y
+ lower
->height
,
23252 upper
->y
+ upper
->height
)
23254 intersection_p
= 1;
23258 return intersection_p
;
23261 #endif /* HAVE_WINDOW_SYSTEM */
23264 /***********************************************************************
23266 ***********************************************************************/
23271 Vwith_echo_area_save_vector
= Qnil
;
23272 staticpro (&Vwith_echo_area_save_vector
);
23274 Vmessage_stack
= Qnil
;
23275 staticpro (&Vmessage_stack
);
23277 Qinhibit_redisplay
= intern ("inhibit-redisplay");
23278 staticpro (&Qinhibit_redisplay
);
23280 message_dolog_marker1
= Fmake_marker ();
23281 staticpro (&message_dolog_marker1
);
23282 message_dolog_marker2
= Fmake_marker ();
23283 staticpro (&message_dolog_marker2
);
23284 message_dolog_marker3
= Fmake_marker ();
23285 staticpro (&message_dolog_marker3
);
23288 defsubr (&Sdump_frame_glyph_matrix
);
23289 defsubr (&Sdump_glyph_matrix
);
23290 defsubr (&Sdump_glyph_row
);
23291 defsubr (&Sdump_tool_bar_row
);
23292 defsubr (&Strace_redisplay
);
23293 defsubr (&Strace_to_stderr
);
23295 #ifdef HAVE_WINDOW_SYSTEM
23296 defsubr (&Stool_bar_lines_needed
);
23297 defsubr (&Slookup_image_map
);
23299 defsubr (&Sformat_mode_line
);
23301 staticpro (&Qmenu_bar_update_hook
);
23302 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
23304 staticpro (&Qoverriding_terminal_local_map
);
23305 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
23307 staticpro (&Qoverriding_local_map
);
23308 Qoverriding_local_map
= intern ("overriding-local-map");
23310 staticpro (&Qwindow_scroll_functions
);
23311 Qwindow_scroll_functions
= intern ("window-scroll-functions");
23313 staticpro (&Qredisplay_end_trigger_functions
);
23314 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
23316 staticpro (&Qinhibit_point_motion_hooks
);
23317 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
23319 QCdata
= intern (":data");
23320 staticpro (&QCdata
);
23321 Qdisplay
= intern ("display");
23322 staticpro (&Qdisplay
);
23323 Qspace_width
= intern ("space-width");
23324 staticpro (&Qspace_width
);
23325 Qraise
= intern ("raise");
23326 staticpro (&Qraise
);
23327 Qslice
= intern ("slice");
23328 staticpro (&Qslice
);
23329 Qspace
= intern ("space");
23330 staticpro (&Qspace
);
23331 Qmargin
= intern ("margin");
23332 staticpro (&Qmargin
);
23333 Qpointer
= intern ("pointer");
23334 staticpro (&Qpointer
);
23335 Qleft_margin
= intern ("left-margin");
23336 staticpro (&Qleft_margin
);
23337 Qright_margin
= intern ("right-margin");
23338 staticpro (&Qright_margin
);
23339 Qcenter
= intern ("center");
23340 staticpro (&Qcenter
);
23341 Qline_height
= intern ("line-height");
23342 staticpro (&Qline_height
);
23343 QCalign_to
= intern (":align-to");
23344 staticpro (&QCalign_to
);
23345 QCrelative_width
= intern (":relative-width");
23346 staticpro (&QCrelative_width
);
23347 QCrelative_height
= intern (":relative-height");
23348 staticpro (&QCrelative_height
);
23349 QCeval
= intern (":eval");
23350 staticpro (&QCeval
);
23351 QCpropertize
= intern (":propertize");
23352 staticpro (&QCpropertize
);
23353 QCfile
= intern (":file");
23354 staticpro (&QCfile
);
23355 Qfontified
= intern ("fontified");
23356 staticpro (&Qfontified
);
23357 Qfontification_functions
= intern ("fontification-functions");
23358 staticpro (&Qfontification_functions
);
23359 Qtrailing_whitespace
= intern ("trailing-whitespace");
23360 staticpro (&Qtrailing_whitespace
);
23361 Qescape_glyph
= intern ("escape-glyph");
23362 staticpro (&Qescape_glyph
);
23363 Qnobreak_space
= intern ("nobreak-space");
23364 staticpro (&Qnobreak_space
);
23365 Qimage
= intern ("image");
23366 staticpro (&Qimage
);
23367 QCmap
= intern (":map");
23368 staticpro (&QCmap
);
23369 QCpointer
= intern (":pointer");
23370 staticpro (&QCpointer
);
23371 Qrect
= intern ("rect");
23372 staticpro (&Qrect
);
23373 Qcircle
= intern ("circle");
23374 staticpro (&Qcircle
);
23375 Qpoly
= intern ("poly");
23376 staticpro (&Qpoly
);
23377 Qmessage_truncate_lines
= intern ("message-truncate-lines");
23378 staticpro (&Qmessage_truncate_lines
);
23379 Qgrow_only
= intern ("grow-only");
23380 staticpro (&Qgrow_only
);
23381 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
23382 staticpro (&Qinhibit_menubar_update
);
23383 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
23384 staticpro (&Qinhibit_eval_during_redisplay
);
23385 Qposition
= intern ("position");
23386 staticpro (&Qposition
);
23387 Qbuffer_position
= intern ("buffer-position");
23388 staticpro (&Qbuffer_position
);
23389 Qobject
= intern ("object");
23390 staticpro (&Qobject
);
23391 Qbar
= intern ("bar");
23393 Qhbar
= intern ("hbar");
23394 staticpro (&Qhbar
);
23395 Qbox
= intern ("box");
23397 Qhollow
= intern ("hollow");
23398 staticpro (&Qhollow
);
23399 Qhand
= intern ("hand");
23400 staticpro (&Qhand
);
23401 Qarrow
= intern ("arrow");
23402 staticpro (&Qarrow
);
23403 Qtext
= intern ("text");
23404 staticpro (&Qtext
);
23405 Qrisky_local_variable
= intern ("risky-local-variable");
23406 staticpro (&Qrisky_local_variable
);
23407 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
23408 staticpro (&Qinhibit_free_realized_faces
);
23410 list_of_error
= Fcons (Fcons (intern ("error"),
23411 Fcons (intern ("void-variable"), Qnil
)),
23413 staticpro (&list_of_error
);
23415 Qlast_arrow_position
= intern ("last-arrow-position");
23416 staticpro (&Qlast_arrow_position
);
23417 Qlast_arrow_string
= intern ("last-arrow-string");
23418 staticpro (&Qlast_arrow_string
);
23420 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
23421 staticpro (&Qoverlay_arrow_string
);
23422 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
23423 staticpro (&Qoverlay_arrow_bitmap
);
23425 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
23426 staticpro (&echo_buffer
[0]);
23427 staticpro (&echo_buffer
[1]);
23429 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
23430 staticpro (&echo_area_buffer
[0]);
23431 staticpro (&echo_area_buffer
[1]);
23433 Vmessages_buffer_name
= build_string ("*Messages*");
23434 staticpro (&Vmessages_buffer_name
);
23436 mode_line_proptrans_alist
= Qnil
;
23437 staticpro (&mode_line_proptrans_alist
);
23438 mode_line_string_list
= Qnil
;
23439 staticpro (&mode_line_string_list
);
23440 mode_line_string_face
= Qnil
;
23441 staticpro (&mode_line_string_face
);
23442 mode_line_string_face_prop
= Qnil
;
23443 staticpro (&mode_line_string_face_prop
);
23444 Vmode_line_unwind_vector
= Qnil
;
23445 staticpro (&Vmode_line_unwind_vector
);
23447 help_echo_string
= Qnil
;
23448 staticpro (&help_echo_string
);
23449 help_echo_object
= Qnil
;
23450 staticpro (&help_echo_object
);
23451 help_echo_window
= Qnil
;
23452 staticpro (&help_echo_window
);
23453 previous_help_echo_string
= Qnil
;
23454 staticpro (&previous_help_echo_string
);
23455 help_echo_pos
= -1;
23457 #ifdef HAVE_WINDOW_SYSTEM
23458 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
23459 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
23460 For example, if a block cursor is over a tab, it will be drawn as
23461 wide as that tab on the display. */);
23462 x_stretch_cursor_p
= 0;
23465 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
23466 doc
: /* *Non-nil means highlight trailing whitespace.
23467 The face used for trailing whitespace is `trailing-whitespace'. */);
23468 Vshow_trailing_whitespace
= Qnil
;
23470 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
23471 doc
: /* *Control highlighting of nobreak space and soft hyphen.
23472 A value of t means highlight the character itself (for nobreak space,
23473 use face `nobreak-space').
23474 A value of nil means no highlighting.
23475 Other values mean display the escape glyph followed by an ordinary
23476 space or ordinary hyphen. */);
23477 Vnobreak_char_display
= Qt
;
23479 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
23480 doc
: /* *The pointer shape to show in void text areas.
23481 A value of nil means to show the text pointer. Other options are `arrow',
23482 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
23483 Vvoid_text_area_pointer
= Qarrow
;
23485 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
23486 doc
: /* Non-nil means don't actually do any redisplay.
23487 This is used for internal purposes. */);
23488 Vinhibit_redisplay
= Qnil
;
23490 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
23491 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
23492 Vglobal_mode_string
= Qnil
;
23494 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
23495 doc
: /* Marker for where to display an arrow on top of the buffer text.
23496 This must be the beginning of a line in order to work.
23497 See also `overlay-arrow-string'. */);
23498 Voverlay_arrow_position
= Qnil
;
23500 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
23501 doc
: /* String to display as an arrow in non-window frames.
23502 See also `overlay-arrow-position'. */);
23503 Voverlay_arrow_string
= build_string ("=>");
23505 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
23506 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
23507 The symbols on this list are examined during redisplay to determine
23508 where to display overlay arrows. */);
23509 Voverlay_arrow_variable_list
23510 = Fcons (intern ("overlay-arrow-position"), Qnil
);
23512 DEFVAR_INT ("scroll-step", &scroll_step
,
23513 doc
: /* *The number of lines to try scrolling a window by when point moves out.
23514 If that fails to bring point back on frame, point is centered instead.
23515 If this is zero, point is always centered after it moves off frame.
23516 If you want scrolling to always be a line at a time, you should set
23517 `scroll-conservatively' to a large value rather than set this to 1. */);
23519 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
23520 doc
: /* *Scroll up to this many lines, to bring point back on screen.
23521 A value of zero means to scroll the text to center point vertically
23522 in the window. */);
23523 scroll_conservatively
= 0;
23525 DEFVAR_INT ("scroll-margin", &scroll_margin
,
23526 doc
: /* *Number of lines of margin at the top and bottom of a window.
23527 Recenter the window whenever point gets within this many lines
23528 of the top or bottom of the window. */);
23531 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
23532 doc
: /* Pixels per inch value for non-window system displays.
23533 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
23534 Vdisplay_pixels_per_inch
= make_float (72.0);
23537 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
23540 DEFVAR_BOOL ("truncate-partial-width-windows",
23541 &truncate_partial_width_windows
,
23542 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
23543 truncate_partial_width_windows
= 1;
23545 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
23546 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
23547 Any other value means to use the appropriate face, `mode-line',
23548 `header-line', or `menu' respectively. */);
23549 mode_line_inverse_video
= 1;
23551 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
23552 doc
: /* *Maximum buffer size for which line number should be displayed.
23553 If the buffer is bigger than this, the line number does not appear
23554 in the mode line. A value of nil means no limit. */);
23555 Vline_number_display_limit
= Qnil
;
23557 DEFVAR_INT ("line-number-display-limit-width",
23558 &line_number_display_limit_width
,
23559 doc
: /* *Maximum line width (in characters) for line number display.
23560 If the average length of the lines near point is bigger than this, then the
23561 line number may be omitted from the mode line. */);
23562 line_number_display_limit_width
= 200;
23564 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
23565 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
23566 highlight_nonselected_windows
= 0;
23568 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
23569 doc
: /* Non-nil if more than one frame is visible on this display.
23570 Minibuffer-only frames don't count, but iconified frames do.
23571 This variable is not guaranteed to be accurate except while processing
23572 `frame-title-format' and `icon-title-format'. */);
23574 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
23575 doc
: /* Template for displaying the title bar of visible frames.
23576 \(Assuming the window manager supports this feature.)
23577 This variable has the same structure as `mode-line-format' (which see),
23578 and is used only on frames for which no explicit name has been set
23579 \(see `modify-frame-parameters'). */);
23581 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
23582 doc
: /* Template for displaying the title bar of an iconified frame.
23583 \(Assuming the window manager supports this feature.)
23584 This variable has the same structure as `mode-line-format' (which see),
23585 and is used only on frames for which no explicit name has been set
23586 \(see `modify-frame-parameters'). */);
23588 = Vframe_title_format
23589 = Fcons (intern ("multiple-frames"),
23590 Fcons (build_string ("%b"),
23591 Fcons (Fcons (empty_string
,
23592 Fcons (intern ("invocation-name"),
23593 Fcons (build_string ("@"),
23594 Fcons (intern ("system-name"),
23598 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
23599 doc
: /* Maximum number of lines to keep in the message log buffer.
23600 If nil, disable message logging. If t, log messages but don't truncate
23601 the buffer when it becomes large. */);
23602 Vmessage_log_max
= make_number (50);
23604 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
23605 doc
: /* Functions called before redisplay, if window sizes have changed.
23606 The value should be a list of functions that take one argument.
23607 Just before redisplay, for each frame, if any of its windows have changed
23608 size since the last redisplay, or have been split or deleted,
23609 all the functions in the list are called, with the frame as argument. */);
23610 Vwindow_size_change_functions
= Qnil
;
23612 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
23613 doc
: /* List of functions to call before redisplaying a window with scrolling.
23614 Each function is called with two arguments, the window
23615 and its new display-start position. Note that the value of `window-end'
23616 is not valid when these functions are called. */);
23617 Vwindow_scroll_functions
= Qnil
;
23619 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
23620 doc
: /* Functions called when redisplay of a window reaches the end trigger.
23621 Each function is called with two arguments, the window and the end trigger value.
23622 See `set-window-redisplay-end-trigger'. */);
23623 Vredisplay_end_trigger_functions
= Qnil
;
23625 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
23626 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
23627 mouse_autoselect_window
= 0;
23629 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
23630 doc
: /* *Non-nil means automatically resize tool-bars.
23631 This increases a tool-bar's height if not all tool-bar items are visible.
23632 It decreases a tool-bar's height when it would display blank lines
23634 auto_resize_tool_bars_p
= 1;
23636 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
23637 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
23638 auto_raise_tool_bar_buttons_p
= 1;
23640 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
23641 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
23642 make_cursor_line_fully_visible_p
= 1;
23644 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
23645 doc
: /* *Margin around tool-bar buttons in pixels.
23646 If an integer, use that for both horizontal and vertical margins.
23647 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
23648 HORZ specifying the horizontal margin, and VERT specifying the
23649 vertical margin. */);
23650 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
23652 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
23653 doc
: /* *Relief thickness of tool-bar buttons. */);
23654 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
23656 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
23657 doc
: /* List of functions to call to fontify regions of text.
23658 Each function is called with one argument POS. Functions must
23659 fontify a region starting at POS in the current buffer, and give
23660 fontified regions the property `fontified'. */);
23661 Vfontification_functions
= Qnil
;
23662 Fmake_variable_buffer_local (Qfontification_functions
);
23664 DEFVAR_BOOL ("unibyte-display-via-language-environment",
23665 &unibyte_display_via_language_environment
,
23666 doc
: /* *Non-nil means display unibyte text according to language environment.
23667 Specifically this means that unibyte non-ASCII characters
23668 are displayed by converting them to the equivalent multibyte characters
23669 according to the current language environment. As a result, they are
23670 displayed according to the current fontset. */);
23671 unibyte_display_via_language_environment
= 0;
23673 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
23674 doc
: /* *Maximum height for resizing mini-windows.
23675 If a float, it specifies a fraction of the mini-window frame's height.
23676 If an integer, it specifies a number of lines. */);
23677 Vmax_mini_window_height
= make_float (0.25);
23679 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
23680 doc
: /* *How to resize mini-windows.
23681 A value of nil means don't automatically resize mini-windows.
23682 A value of t means resize them to fit the text displayed in them.
23683 A value of `grow-only', the default, means let mini-windows grow
23684 only, until their display becomes empty, at which point the windows
23685 go back to their normal size. */);
23686 Vresize_mini_windows
= Qgrow_only
;
23688 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
23689 doc
: /* Alist specifying how to blink the cursor off.
23690 Each element has the form (ON-STATE . OFF-STATE). Whenever the
23691 `cursor-type' frame-parameter or variable equals ON-STATE,
23692 comparing using `equal', Emacs uses OFF-STATE to specify
23693 how to blink it off. ON-STATE and OFF-STATE are values for
23694 the `cursor-type' frame parameter.
23696 If a frame's ON-STATE has no entry in this list,
23697 the frame's other specifications determine how to blink the cursor off. */);
23698 Vblink_cursor_alist
= Qnil
;
23700 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
23701 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
23702 automatic_hscrolling_p
= 1;
23704 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
23705 doc
: /* *How many columns away from the window edge point is allowed to get
23706 before automatic hscrolling will horizontally scroll the window. */);
23707 hscroll_margin
= 5;
23709 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
23710 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
23711 When point is less than `automatic-hscroll-margin' columns from the window
23712 edge, automatic hscrolling will scroll the window by the amount of columns
23713 determined by this variable. If its value is a positive integer, scroll that
23714 many columns. If it's a positive floating-point number, it specifies the
23715 fraction of the window's width to scroll. If it's nil or zero, point will be
23716 centered horizontally after the scroll. Any other value, including negative
23717 numbers, are treated as if the value were zero.
23719 Automatic hscrolling always moves point outside the scroll margin, so if
23720 point was more than scroll step columns inside the margin, the window will
23721 scroll more than the value given by the scroll step.
23723 Note that the lower bound for automatic hscrolling specified by `scroll-left'
23724 and `scroll-right' overrides this variable's effect. */);
23725 Vhscroll_step
= make_number (0);
23727 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
23728 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
23729 Bind this around calls to `message' to let it take effect. */);
23730 message_truncate_lines
= 0;
23732 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
23733 doc
: /* Normal hook run to update the menu bar definitions.
23734 Redisplay runs this hook before it redisplays the menu bar.
23735 This is used to update submenus such as Buffers,
23736 whose contents depend on various data. */);
23737 Vmenu_bar_update_hook
= Qnil
;
23739 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
23740 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
23741 inhibit_menubar_update
= 0;
23743 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
23744 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
23745 inhibit_eval_during_redisplay
= 0;
23747 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
23748 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
23749 inhibit_free_realized_faces
= 0;
23752 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
23753 doc
: /* Inhibit try_window_id display optimization. */);
23754 inhibit_try_window_id
= 0;
23756 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
23757 doc
: /* Inhibit try_window_reusing display optimization. */);
23758 inhibit_try_window_reusing
= 0;
23760 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
23761 doc
: /* Inhibit try_cursor_movement display optimization. */);
23762 inhibit_try_cursor_movement
= 0;
23763 #endif /* GLYPH_DEBUG */
23767 /* Initialize this module when Emacs starts. */
23772 Lisp_Object root_window
;
23773 struct window
*mini_w
;
23775 current_header_line_height
= current_mode_line_height
= -1;
23777 CHARPOS (this_line_start_pos
) = 0;
23779 mini_w
= XWINDOW (minibuf_window
);
23780 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
23782 if (!noninteractive
)
23784 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
23787 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
23788 set_window_height (root_window
,
23789 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
23791 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
23792 set_window_height (minibuf_window
, 1, 0);
23794 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
23795 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
23797 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
23798 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
23799 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
23801 /* The default ellipsis glyphs `...'. */
23802 for (i
= 0; i
< 3; ++i
)
23803 default_invis_vector
[i
] = make_number ('.');
23807 /* Allocate the buffer for frame titles.
23808 Also used for `format-mode-line'. */
23810 mode_line_noprop_buf
= (char *) xmalloc (size
);
23811 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
23812 mode_line_noprop_ptr
= mode_line_noprop_buf
;
23813 mode_line_target
= MODE_LINE_DISPLAY
;
23816 help_echo_showing_p
= 0;
23820 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
23821 (do not change this comment) */