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
))
9058 /* All frames on Mac OS share the same menubar. So only
9059 the selected frame should be allowed to set it. */
9060 if (f
== SELECTED_FRAME ())
9062 set_frame_menubar (f
, 0, 0);
9065 /* On a terminal screen, the menu bar is an ordinary screen
9066 line, and this makes it get updated. */
9067 w
->update_mode_line
= Qt
;
9068 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9069 /* In the non-toolkit version, the menu bar is an ordinary screen
9070 line, and this makes it get updated. */
9071 w
->update_mode_line
= Qt
;
9072 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9074 unbind_to (count
, Qnil
);
9075 set_buffer_internal_1 (prev
);
9082 /***********************************************************************
9084 ***********************************************************************/
9086 #ifdef HAVE_WINDOW_SYSTEM
9089 Nominal cursor position -- where to draw output.
9090 HPOS and VPOS are window relative glyph matrix coordinates.
9091 X and Y are window relative pixel coordinates. */
9093 struct cursor_pos output_cursor
;
9097 Set the global variable output_cursor to CURSOR. All cursor
9098 positions are relative to updated_window. */
9101 set_output_cursor (cursor
)
9102 struct cursor_pos
*cursor
;
9104 output_cursor
.hpos
= cursor
->hpos
;
9105 output_cursor
.vpos
= cursor
->vpos
;
9106 output_cursor
.x
= cursor
->x
;
9107 output_cursor
.y
= cursor
->y
;
9112 Set a nominal cursor position.
9114 HPOS and VPOS are column/row positions in a window glyph matrix. X
9115 and Y are window text area relative pixel positions.
9117 If this is done during an update, updated_window will contain the
9118 window that is being updated and the position is the future output
9119 cursor position for that window. If updated_window is null, use
9120 selected_window and display the cursor at the given position. */
9123 x_cursor_to (vpos
, hpos
, y
, x
)
9124 int vpos
, hpos
, y
, x
;
9128 /* If updated_window is not set, work on selected_window. */
9132 w
= XWINDOW (selected_window
);
9134 /* Set the output cursor. */
9135 output_cursor
.hpos
= hpos
;
9136 output_cursor
.vpos
= vpos
;
9137 output_cursor
.x
= x
;
9138 output_cursor
.y
= y
;
9140 /* If not called as part of an update, really display the cursor.
9141 This will also set the cursor position of W. */
9142 if (updated_window
== NULL
)
9145 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9146 if (rif
->flush_display_optional
)
9147 rif
->flush_display_optional (SELECTED_FRAME ());
9152 #endif /* HAVE_WINDOW_SYSTEM */
9155 /***********************************************************************
9157 ***********************************************************************/
9159 #ifdef HAVE_WINDOW_SYSTEM
9161 /* Where the mouse was last time we reported a mouse event. */
9163 FRAME_PTR last_mouse_frame
;
9165 /* Tool-bar item index of the item on which a mouse button was pressed
9168 int last_tool_bar_item
;
9171 /* Update the tool-bar item list for frame F. This has to be done
9172 before we start to fill in any display lines. Called from
9173 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9174 and restore it here. */
9177 update_tool_bar (f
, save_match_data
)
9179 int save_match_data
;
9182 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9184 int do_update
= WINDOWP (f
->tool_bar_window
)
9185 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9193 window
= FRAME_SELECTED_WINDOW (f
);
9194 w
= XWINDOW (window
);
9196 /* If the user has switched buffers or windows, we need to
9197 recompute to reflect the new bindings. But we'll
9198 recompute when update_mode_lines is set too; that means
9199 that people can use force-mode-line-update to request
9200 that the menu bar be recomputed. The adverse effect on
9201 the rest of the redisplay algorithm is about the same as
9202 windows_or_buffers_changed anyway. */
9203 if (windows_or_buffers_changed
9204 || !NILP (w
->update_mode_line
)
9205 || update_mode_lines
9206 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9207 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9208 != !NILP (w
->last_had_star
))
9209 || ((!NILP (Vtransient_mark_mode
)
9210 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9211 != !NILP (w
->region_showing
)))
9213 struct buffer
*prev
= current_buffer
;
9214 int count
= SPECPDL_INDEX ();
9215 Lisp_Object new_tool_bar
;
9217 struct gcpro gcpro1
;
9219 /* Set current_buffer to the buffer of the selected
9220 window of the frame, so that we get the right local
9222 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9224 /* Save match data, if we must. */
9225 if (save_match_data
)
9226 record_unwind_save_match_data ();
9228 /* Make sure that we don't accidentally use bogus keymaps. */
9229 if (NILP (Voverriding_local_map_menu_flag
))
9231 specbind (Qoverriding_terminal_local_map
, Qnil
);
9232 specbind (Qoverriding_local_map
, Qnil
);
9235 GCPRO1 (new_tool_bar
);
9237 /* Build desired tool-bar items from keymaps. */
9238 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9241 /* Redisplay the tool-bar if we changed it. */
9242 if (NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9244 /* Redisplay that happens asynchronously due to an expose event
9245 may access f->tool_bar_items. Make sure we update both
9246 variables within BLOCK_INPUT so no such event interrupts. */
9248 f
->tool_bar_items
= new_tool_bar
;
9249 f
->n_tool_bar_items
= new_n_tool_bar
;
9250 w
->update_mode_line
= Qt
;
9256 unbind_to (count
, Qnil
);
9257 set_buffer_internal_1 (prev
);
9263 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9264 F's desired tool-bar contents. F->tool_bar_items must have
9265 been set up previously by calling prepare_menu_bars. */
9268 build_desired_tool_bar_string (f
)
9271 int i
, size
, size_needed
;
9272 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9273 Lisp_Object image
, plist
, props
;
9275 image
= plist
= props
= Qnil
;
9276 GCPRO3 (image
, plist
, props
);
9278 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9279 Otherwise, make a new string. */
9281 /* The size of the string we might be able to reuse. */
9282 size
= (STRINGP (f
->desired_tool_bar_string
)
9283 ? SCHARS (f
->desired_tool_bar_string
)
9286 /* We need one space in the string for each image. */
9287 size_needed
= f
->n_tool_bar_items
;
9289 /* Reuse f->desired_tool_bar_string, if possible. */
9290 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9291 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9295 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9296 Fremove_text_properties (make_number (0), make_number (size
),
9297 props
, f
->desired_tool_bar_string
);
9300 /* Put a `display' property on the string for the images to display,
9301 put a `menu_item' property on tool-bar items with a value that
9302 is the index of the item in F's tool-bar item vector. */
9303 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9305 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9307 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9308 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9309 int hmargin
, vmargin
, relief
, idx
, end
;
9310 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9312 /* If image is a vector, choose the image according to the
9314 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9315 if (VECTORP (image
))
9319 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9320 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9323 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9324 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9326 xassert (ASIZE (image
) >= idx
);
9327 image
= AREF (image
, idx
);
9332 /* Ignore invalid image specifications. */
9333 if (!valid_image_p (image
))
9336 /* Display the tool-bar button pressed, or depressed. */
9337 plist
= Fcopy_sequence (XCDR (image
));
9339 /* Compute margin and relief to draw. */
9340 relief
= (tool_bar_button_relief
>= 0
9341 ? tool_bar_button_relief
9342 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9343 hmargin
= vmargin
= relief
;
9345 if (INTEGERP (Vtool_bar_button_margin
)
9346 && XINT (Vtool_bar_button_margin
) > 0)
9348 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9349 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9351 else if (CONSP (Vtool_bar_button_margin
))
9353 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9354 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9355 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9357 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9358 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9359 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9362 if (auto_raise_tool_bar_buttons_p
)
9364 /* Add a `:relief' property to the image spec if the item is
9368 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9375 /* If image is selected, display it pressed, i.e. with a
9376 negative relief. If it's not selected, display it with a
9378 plist
= Fplist_put (plist
, QCrelief
,
9380 ? make_number (-relief
)
9381 : make_number (relief
)));
9386 /* Put a margin around the image. */
9387 if (hmargin
|| vmargin
)
9389 if (hmargin
== vmargin
)
9390 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9392 plist
= Fplist_put (plist
, QCmargin
,
9393 Fcons (make_number (hmargin
),
9394 make_number (vmargin
)));
9397 /* If button is not enabled, and we don't have special images
9398 for the disabled state, make the image appear disabled by
9399 applying an appropriate algorithm to it. */
9400 if (!enabled_p
&& idx
< 0)
9401 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9403 /* Put a `display' text property on the string for the image to
9404 display. Put a `menu-item' property on the string that gives
9405 the start of this item's properties in the tool-bar items
9407 image
= Fcons (Qimage
, plist
);
9408 props
= list4 (Qdisplay
, image
,
9409 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9411 /* Let the last image hide all remaining spaces in the tool bar
9412 string. The string can be longer than needed when we reuse a
9414 if (i
+ 1 == f
->n_tool_bar_items
)
9415 end
= SCHARS (f
->desired_tool_bar_string
);
9418 Fadd_text_properties (make_number (i
), make_number (end
),
9419 props
, f
->desired_tool_bar_string
);
9427 /* Display one line of the tool-bar of frame IT->f. */
9430 display_tool_bar_line (it
)
9433 struct glyph_row
*row
= it
->glyph_row
;
9434 int max_x
= it
->last_visible_x
;
9437 prepare_desired_row (row
);
9438 row
->y
= it
->current_y
;
9440 /* Note that this isn't made use of if the face hasn't a box,
9441 so there's no need to check the face here. */
9442 it
->start_of_box_run_p
= 1;
9444 while (it
->current_x
< max_x
)
9446 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
9448 /* Get the next display element. */
9449 if (!get_next_display_element (it
))
9452 /* Produce glyphs. */
9453 x_before
= it
->current_x
;
9454 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
9455 PRODUCE_GLYPHS (it
);
9457 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
9462 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9464 if (x
+ glyph
->pixel_width
> max_x
)
9466 /* Glyph doesn't fit on line. */
9467 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
9473 x
+= glyph
->pixel_width
;
9477 /* Stop at line ends. */
9478 if (ITERATOR_AT_END_OF_LINE_P (it
))
9481 set_iterator_to_next (it
, 1);
9486 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9487 extend_face_to_end_of_line (it
);
9488 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9489 last
->right_box_line_p
= 1;
9490 if (last
== row
->glyphs
[TEXT_AREA
])
9491 last
->left_box_line_p
= 1;
9492 compute_line_metrics (it
);
9494 /* If line is empty, make it occupy the rest of the tool-bar. */
9495 if (!row
->displays_text_p
)
9497 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9498 row
->ascent
= row
->phys_ascent
= 0;
9499 row
->extra_line_spacing
= 0;
9502 row
->full_width_p
= 1;
9503 row
->continued_p
= 0;
9504 row
->truncated_on_left_p
= 0;
9505 row
->truncated_on_right_p
= 0;
9507 it
->current_x
= it
->hpos
= 0;
9508 it
->current_y
+= row
->height
;
9514 /* Value is the number of screen lines needed to make all tool-bar
9515 items of frame F visible. */
9518 tool_bar_lines_needed (f
)
9521 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9524 /* Initialize an iterator for iteration over
9525 F->desired_tool_bar_string in the tool-bar window of frame F. */
9526 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9527 it
.first_visible_x
= 0;
9528 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9529 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9531 while (!ITERATOR_AT_END_P (&it
))
9533 it
.glyph_row
= w
->desired_matrix
->rows
;
9534 clear_glyph_row (it
.glyph_row
);
9535 display_tool_bar_line (&it
);
9538 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9542 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9544 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9553 frame
= selected_frame
;
9555 CHECK_FRAME (frame
);
9558 if (WINDOWP (f
->tool_bar_window
)
9559 || (w
= XWINDOW (f
->tool_bar_window
),
9560 WINDOW_TOTAL_LINES (w
) > 0))
9562 update_tool_bar (f
, 1);
9563 if (f
->n_tool_bar_items
)
9565 build_desired_tool_bar_string (f
);
9566 nlines
= tool_bar_lines_needed (f
);
9570 return make_number (nlines
);
9574 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9575 height should be changed. */
9578 redisplay_tool_bar (f
)
9583 struct glyph_row
*row
;
9584 int change_height_p
= 0;
9587 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9588 update_frame_tool_bar (f
);
9592 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9593 do anything. This means you must start with tool-bar-lines
9594 non-zero to get the auto-sizing effect. Or in other words, you
9595 can turn off tool-bars by specifying tool-bar-lines zero. */
9596 if (!WINDOWP (f
->tool_bar_window
)
9597 || (w
= XWINDOW (f
->tool_bar_window
),
9598 WINDOW_TOTAL_LINES (w
) == 0))
9601 /* Set up an iterator for the tool-bar window. */
9602 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9603 it
.first_visible_x
= 0;
9604 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9607 /* Build a string that represents the contents of the tool-bar. */
9608 build_desired_tool_bar_string (f
);
9609 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9611 /* Display as many lines as needed to display all tool-bar items. */
9612 while (it
.current_y
< it
.last_visible_y
)
9613 display_tool_bar_line (&it
);
9615 /* It doesn't make much sense to try scrolling in the tool-bar
9616 window, so don't do it. */
9617 w
->desired_matrix
->no_scrolling_p
= 1;
9618 w
->must_be_updated_p
= 1;
9620 if (auto_resize_tool_bars_p
)
9624 /* If we couldn't display everything, change the tool-bar's
9626 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
9627 change_height_p
= 1;
9629 /* If there are blank lines at the end, except for a partially
9630 visible blank line at the end that is smaller than
9631 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9632 row
= it
.glyph_row
- 1;
9633 if (!row
->displays_text_p
9634 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9635 change_height_p
= 1;
9637 /* If row displays tool-bar items, but is partially visible,
9638 change the tool-bar's height. */
9639 if (row
->displays_text_p
9640 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
9641 change_height_p
= 1;
9643 /* Resize windows as needed by changing the `tool-bar-lines'
9646 && (nlines
= tool_bar_lines_needed (f
),
9647 nlines
!= WINDOW_TOTAL_LINES (w
)))
9649 extern Lisp_Object Qtool_bar_lines
;
9651 int old_height
= WINDOW_TOTAL_LINES (w
);
9653 XSETFRAME (frame
, f
);
9654 clear_glyph_matrix (w
->desired_matrix
);
9655 Fmodify_frame_parameters (frame
,
9656 Fcons (Fcons (Qtool_bar_lines
,
9657 make_number (nlines
)),
9659 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9660 fonts_changed_p
= 1;
9664 return change_height_p
;
9668 /* Get information about the tool-bar item which is displayed in GLYPH
9669 on frame F. Return in *PROP_IDX the index where tool-bar item
9670 properties start in F->tool_bar_items. Value is zero if
9671 GLYPH doesn't display a tool-bar item. */
9674 tool_bar_item_info (f
, glyph
, prop_idx
)
9676 struct glyph
*glyph
;
9683 /* This function can be called asynchronously, which means we must
9684 exclude any possibility that Fget_text_property signals an
9686 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
9687 charpos
= max (0, charpos
);
9689 /* Get the text property `menu-item' at pos. The value of that
9690 property is the start index of this item's properties in
9691 F->tool_bar_items. */
9692 prop
= Fget_text_property (make_number (charpos
),
9693 Qmenu_item
, f
->current_tool_bar_string
);
9694 if (INTEGERP (prop
))
9696 *prop_idx
= XINT (prop
);
9706 /* Get information about the tool-bar item at position X/Y on frame F.
9707 Return in *GLYPH a pointer to the glyph of the tool-bar item in
9708 the current matrix of the tool-bar window of F, or NULL if not
9709 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
9710 item in F->tool_bar_items. Value is
9712 -1 if X/Y is not on a tool-bar item
9713 0 if X/Y is on the same item that was highlighted before.
9717 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
9720 struct glyph
**glyph
;
9721 int *hpos
, *vpos
, *prop_idx
;
9723 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9724 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9727 /* Find the glyph under X/Y. */
9728 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
9732 /* Get the start of this tool-bar item's properties in
9733 f->tool_bar_items. */
9734 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
9737 /* Is mouse on the highlighted item? */
9738 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
9739 && *vpos
>= dpyinfo
->mouse_face_beg_row
9740 && *vpos
<= dpyinfo
->mouse_face_end_row
9741 && (*vpos
> dpyinfo
->mouse_face_beg_row
9742 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
9743 && (*vpos
< dpyinfo
->mouse_face_end_row
9744 || *hpos
< dpyinfo
->mouse_face_end_col
9745 || dpyinfo
->mouse_face_past_end
))
9753 Handle mouse button event on the tool-bar of frame F, at
9754 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
9755 0 for button release. MODIFIERS is event modifiers for button
9759 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
9762 unsigned int modifiers
;
9764 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9765 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9766 int hpos
, vpos
, prop_idx
;
9767 struct glyph
*glyph
;
9768 Lisp_Object enabled_p
;
9770 /* If not on the highlighted tool-bar item, return. */
9771 frame_to_window_pixel_xy (w
, &x
, &y
);
9772 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
9775 /* If item is disabled, do nothing. */
9776 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9777 if (NILP (enabled_p
))
9782 /* Show item in pressed state. */
9783 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
9784 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
9785 last_tool_bar_item
= prop_idx
;
9789 Lisp_Object key
, frame
;
9790 struct input_event event
;
9793 /* Show item in released state. */
9794 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
9795 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
9797 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
9799 XSETFRAME (frame
, f
);
9800 event
.kind
= TOOL_BAR_EVENT
;
9801 event
.frame_or_window
= frame
;
9803 kbd_buffer_store_event (&event
);
9805 event
.kind
= TOOL_BAR_EVENT
;
9806 event
.frame_or_window
= frame
;
9808 event
.modifiers
= modifiers
;
9809 kbd_buffer_store_event (&event
);
9810 last_tool_bar_item
= -1;
9815 /* Possibly highlight a tool-bar item on frame F when mouse moves to
9816 tool-bar window-relative coordinates X/Y. Called from
9817 note_mouse_highlight. */
9820 note_tool_bar_highlight (f
, x
, y
)
9824 Lisp_Object window
= f
->tool_bar_window
;
9825 struct window
*w
= XWINDOW (window
);
9826 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9828 struct glyph
*glyph
;
9829 struct glyph_row
*row
;
9831 Lisp_Object enabled_p
;
9833 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9834 int mouse_down_p
, rc
;
9836 /* Function note_mouse_highlight is called with negative x(y
9837 values when mouse moves outside of the frame. */
9838 if (x
<= 0 || y
<= 0)
9840 clear_mouse_face (dpyinfo
);
9844 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9847 /* Not on tool-bar item. */
9848 clear_mouse_face (dpyinfo
);
9852 /* On same tool-bar item as before. */
9855 clear_mouse_face (dpyinfo
);
9857 /* Mouse is down, but on different tool-bar item? */
9858 mouse_down_p
= (dpyinfo
->grabbed
9859 && f
== last_mouse_frame
9860 && FRAME_LIVE_P (f
));
9862 && last_tool_bar_item
!= prop_idx
)
9865 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9866 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9868 /* If tool-bar item is not enabled, don't highlight it. */
9869 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9870 if (!NILP (enabled_p
))
9872 /* Compute the x-position of the glyph. In front and past the
9873 image is a space. We include this in the highlighted area. */
9874 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
9875 for (i
= x
= 0; i
< hpos
; ++i
)
9876 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9878 /* Record this as the current active region. */
9879 dpyinfo
->mouse_face_beg_col
= hpos
;
9880 dpyinfo
->mouse_face_beg_row
= vpos
;
9881 dpyinfo
->mouse_face_beg_x
= x
;
9882 dpyinfo
->mouse_face_beg_y
= row
->y
;
9883 dpyinfo
->mouse_face_past_end
= 0;
9885 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9886 dpyinfo
->mouse_face_end_row
= vpos
;
9887 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9888 dpyinfo
->mouse_face_end_y
= row
->y
;
9889 dpyinfo
->mouse_face_window
= window
;
9890 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9892 /* Display it as active. */
9893 show_mouse_face (dpyinfo
, draw
);
9894 dpyinfo
->mouse_face_image_state
= draw
;
9899 /* Set help_echo_string to a help string to display for this tool-bar item.
9900 XTread_socket does the rest. */
9901 help_echo_object
= help_echo_window
= Qnil
;
9903 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9904 if (NILP (help_echo_string
))
9905 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9908 #endif /* HAVE_WINDOW_SYSTEM */
9912 /************************************************************************
9913 Horizontal scrolling
9914 ************************************************************************/
9916 static int hscroll_window_tree
P_ ((Lisp_Object
));
9917 static int hscroll_windows
P_ ((Lisp_Object
));
9919 /* For all leaf windows in the window tree rooted at WINDOW, set their
9920 hscroll value so that PT is (i) visible in the window, and (ii) so
9921 that it is not within a certain margin at the window's left and
9922 right border. Value is non-zero if any window's hscroll has been
9926 hscroll_window_tree (window
)
9929 int hscrolled_p
= 0;
9930 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9931 int hscroll_step_abs
= 0;
9932 double hscroll_step_rel
= 0;
9934 if (hscroll_relative_p
)
9936 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9937 if (hscroll_step_rel
< 0)
9939 hscroll_relative_p
= 0;
9940 hscroll_step_abs
= 0;
9943 else if (INTEGERP (Vhscroll_step
))
9945 hscroll_step_abs
= XINT (Vhscroll_step
);
9946 if (hscroll_step_abs
< 0)
9947 hscroll_step_abs
= 0;
9950 hscroll_step_abs
= 0;
9952 while (WINDOWP (window
))
9954 struct window
*w
= XWINDOW (window
);
9956 if (WINDOWP (w
->hchild
))
9957 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9958 else if (WINDOWP (w
->vchild
))
9959 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9960 else if (w
->cursor
.vpos
>= 0)
9963 int text_area_width
;
9964 struct glyph_row
*current_cursor_row
9965 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9966 struct glyph_row
*desired_cursor_row
9967 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9968 struct glyph_row
*cursor_row
9969 = (desired_cursor_row
->enabled_p
9970 ? desired_cursor_row
9971 : current_cursor_row
);
9973 text_area_width
= window_box_width (w
, TEXT_AREA
);
9975 /* Scroll when cursor is inside this scroll margin. */
9976 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9978 if ((XFASTINT (w
->hscroll
)
9979 && w
->cursor
.x
<= h_margin
)
9980 || (cursor_row
->enabled_p
9981 && cursor_row
->truncated_on_right_p
9982 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9986 struct buffer
*saved_current_buffer
;
9990 /* Find point in a display of infinite width. */
9991 saved_current_buffer
= current_buffer
;
9992 current_buffer
= XBUFFER (w
->buffer
);
9994 if (w
== XWINDOW (selected_window
))
9995 pt
= BUF_PT (current_buffer
);
9998 pt
= marker_position (w
->pointm
);
9999 pt
= max (BEGV
, pt
);
10003 /* Move iterator to pt starting at cursor_row->start in
10004 a line with infinite width. */
10005 init_to_row_start (&it
, w
, cursor_row
);
10006 it
.last_visible_x
= INFINITY
;
10007 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10008 current_buffer
= saved_current_buffer
;
10010 /* Position cursor in window. */
10011 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10012 hscroll
= max (0, (it
.current_x
10013 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10014 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10015 : (text_area_width
/ 2))))
10016 / FRAME_COLUMN_WIDTH (it
.f
);
10017 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10019 if (hscroll_relative_p
)
10020 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10023 wanted_x
= text_area_width
10024 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10027 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10031 if (hscroll_relative_p
)
10032 wanted_x
= text_area_width
* hscroll_step_rel
10035 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10038 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10040 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10042 /* Don't call Fset_window_hscroll if value hasn't
10043 changed because it will prevent redisplay
10045 if (XFASTINT (w
->hscroll
) != hscroll
)
10047 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10048 w
->hscroll
= make_number (hscroll
);
10057 /* Value is non-zero if hscroll of any leaf window has been changed. */
10058 return hscrolled_p
;
10062 /* Set hscroll so that cursor is visible and not inside horizontal
10063 scroll margins for all windows in the tree rooted at WINDOW. See
10064 also hscroll_window_tree above. Value is non-zero if any window's
10065 hscroll has been changed. If it has, desired matrices on the frame
10066 of WINDOW are cleared. */
10069 hscroll_windows (window
)
10070 Lisp_Object window
;
10074 if (automatic_hscrolling_p
)
10076 hscrolled_p
= hscroll_window_tree (window
);
10078 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10082 return hscrolled_p
;
10087 /************************************************************************
10089 ************************************************************************/
10091 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10092 to a non-zero value. This is sometimes handy to have in a debugger
10097 /* First and last unchanged row for try_window_id. */
10099 int debug_first_unchanged_at_end_vpos
;
10100 int debug_last_unchanged_at_beg_vpos
;
10102 /* Delta vpos and y. */
10104 int debug_dvpos
, debug_dy
;
10106 /* Delta in characters and bytes for try_window_id. */
10108 int debug_delta
, debug_delta_bytes
;
10110 /* Values of window_end_pos and window_end_vpos at the end of
10113 EMACS_INT debug_end_pos
, debug_end_vpos
;
10115 /* Append a string to W->desired_matrix->method. FMT is a printf
10116 format string. A1...A9 are a supplement for a variable-length
10117 argument list. If trace_redisplay_p is non-zero also printf the
10118 resulting string to stderr. */
10121 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10124 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10127 char *method
= w
->desired_matrix
->method
;
10128 int len
= strlen (method
);
10129 int size
= sizeof w
->desired_matrix
->method
;
10130 int remaining
= size
- len
- 1;
10132 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10133 if (len
&& remaining
)
10136 --remaining
, ++len
;
10139 strncpy (method
+ len
, buffer
, remaining
);
10141 if (trace_redisplay_p
)
10142 fprintf (stderr
, "%p (%s): %s\n",
10144 ((BUFFERP (w
->buffer
)
10145 && STRINGP (XBUFFER (w
->buffer
)->name
))
10146 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10151 #endif /* GLYPH_DEBUG */
10154 /* Value is non-zero if all changes in window W, which displays
10155 current_buffer, are in the text between START and END. START is a
10156 buffer position, END is given as a distance from Z. Used in
10157 redisplay_internal for display optimization. */
10160 text_outside_line_unchanged_p (w
, start
, end
)
10164 int unchanged_p
= 1;
10166 /* If text or overlays have changed, see where. */
10167 if (XFASTINT (w
->last_modified
) < MODIFF
10168 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10170 /* Gap in the line? */
10171 if (GPT
< start
|| Z
- GPT
< end
)
10174 /* Changes start in front of the line, or end after it? */
10176 && (BEG_UNCHANGED
< start
- 1
10177 || END_UNCHANGED
< end
))
10180 /* If selective display, can't optimize if changes start at the
10181 beginning of the line. */
10183 && INTEGERP (current_buffer
->selective_display
)
10184 && XINT (current_buffer
->selective_display
) > 0
10185 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10188 /* If there are overlays at the start or end of the line, these
10189 may have overlay strings with newlines in them. A change at
10190 START, for instance, may actually concern the display of such
10191 overlay strings as well, and they are displayed on different
10192 lines. So, quickly rule out this case. (For the future, it
10193 might be desirable to implement something more telling than
10194 just BEG/END_UNCHANGED.) */
10197 if (BEG
+ BEG_UNCHANGED
== start
10198 && overlay_touches_p (start
))
10200 if (END_UNCHANGED
== end
10201 && overlay_touches_p (Z
- end
))
10206 return unchanged_p
;
10210 /* Do a frame update, taking possible shortcuts into account. This is
10211 the main external entry point for redisplay.
10213 If the last redisplay displayed an echo area message and that message
10214 is no longer requested, we clear the echo area or bring back the
10215 mini-buffer if that is in use. */
10220 redisplay_internal (0);
10225 overlay_arrow_string_or_property (var
)
10230 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10233 return Voverlay_arrow_string
;
10236 /* Return 1 if there are any overlay-arrows in current_buffer. */
10238 overlay_arrow_in_current_buffer_p ()
10242 for (vlist
= Voverlay_arrow_variable_list
;
10244 vlist
= XCDR (vlist
))
10246 Lisp_Object var
= XCAR (vlist
);
10249 if (!SYMBOLP (var
))
10251 val
= find_symbol_value (var
);
10253 && current_buffer
== XMARKER (val
)->buffer
)
10260 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
10264 overlay_arrows_changed_p ()
10268 for (vlist
= Voverlay_arrow_variable_list
;
10270 vlist
= XCDR (vlist
))
10272 Lisp_Object var
= XCAR (vlist
);
10273 Lisp_Object val
, pstr
;
10275 if (!SYMBOLP (var
))
10277 val
= find_symbol_value (var
);
10278 if (!MARKERP (val
))
10280 if (! EQ (COERCE_MARKER (val
),
10281 Fget (var
, Qlast_arrow_position
))
10282 || ! (pstr
= overlay_arrow_string_or_property (var
),
10283 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
10289 /* Mark overlay arrows to be updated on next redisplay. */
10292 update_overlay_arrows (up_to_date
)
10297 for (vlist
= Voverlay_arrow_variable_list
;
10299 vlist
= XCDR (vlist
))
10301 Lisp_Object var
= XCAR (vlist
);
10303 if (!SYMBOLP (var
))
10306 if (up_to_date
> 0)
10308 Lisp_Object val
= find_symbol_value (var
);
10309 Fput (var
, Qlast_arrow_position
,
10310 COERCE_MARKER (val
));
10311 Fput (var
, Qlast_arrow_string
,
10312 overlay_arrow_string_or_property (var
));
10314 else if (up_to_date
< 0
10315 || !NILP (Fget (var
, Qlast_arrow_position
)))
10317 Fput (var
, Qlast_arrow_position
, Qt
);
10318 Fput (var
, Qlast_arrow_string
, Qt
);
10324 /* Return overlay arrow string to display at row.
10325 Return integer (bitmap number) for arrow bitmap in left fringe.
10326 Return nil if no overlay arrow. */
10329 overlay_arrow_at_row (it
, row
)
10331 struct glyph_row
*row
;
10335 for (vlist
= Voverlay_arrow_variable_list
;
10337 vlist
= XCDR (vlist
))
10339 Lisp_Object var
= XCAR (vlist
);
10342 if (!SYMBOLP (var
))
10345 val
= find_symbol_value (var
);
10348 && current_buffer
== XMARKER (val
)->buffer
10349 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10351 if (FRAME_WINDOW_P (it
->f
)
10352 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10354 #ifdef HAVE_WINDOW_SYSTEM
10355 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10358 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10359 return make_number (fringe_bitmap
);
10362 return make_number (-1); /* Use default arrow bitmap */
10364 return overlay_arrow_string_or_property (var
);
10371 /* Return 1 if point moved out of or into a composition. Otherwise
10372 return 0. PREV_BUF and PREV_PT are the last point buffer and
10373 position. BUF and PT are the current point buffer and position. */
10376 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10377 struct buffer
*prev_buf
, *buf
;
10382 Lisp_Object buffer
;
10384 XSETBUFFER (buffer
, buf
);
10385 /* Check a composition at the last point if point moved within the
10387 if (prev_buf
== buf
)
10390 /* Point didn't move. */
10393 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10394 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10395 && COMPOSITION_VALID_P (start
, end
, prop
)
10396 && start
< prev_pt
&& end
> prev_pt
)
10397 /* The last point was within the composition. Return 1 iff
10398 point moved out of the composition. */
10399 return (pt
<= start
|| pt
>= end
);
10402 /* Check a composition at the current point. */
10403 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10404 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10405 && COMPOSITION_VALID_P (start
, end
, prop
)
10406 && start
< pt
&& end
> pt
);
10410 /* Reconsider the setting of B->clip_changed which is displayed
10414 reconsider_clip_changes (w
, b
)
10418 if (b
->clip_changed
10419 && !NILP (w
->window_end_valid
)
10420 && w
->current_matrix
->buffer
== b
10421 && w
->current_matrix
->zv
== BUF_ZV (b
)
10422 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10423 b
->clip_changed
= 0;
10425 /* If display wasn't paused, and W is not a tool bar window, see if
10426 point has been moved into or out of a composition. In that case,
10427 we set b->clip_changed to 1 to force updating the screen. If
10428 b->clip_changed has already been set to 1, we can skip this
10430 if (!b
->clip_changed
10431 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10435 if (w
== XWINDOW (selected_window
))
10436 pt
= BUF_PT (current_buffer
);
10438 pt
= marker_position (w
->pointm
);
10440 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10441 || pt
!= XINT (w
->last_point
))
10442 && check_point_in_composition (w
->current_matrix
->buffer
,
10443 XINT (w
->last_point
),
10444 XBUFFER (w
->buffer
), pt
))
10445 b
->clip_changed
= 1;
10450 /* Select FRAME to forward the values of frame-local variables into C
10451 variables so that the redisplay routines can access those values
10455 select_frame_for_redisplay (frame
)
10458 Lisp_Object tail
, sym
, val
;
10459 Lisp_Object old
= selected_frame
;
10461 selected_frame
= frame
;
10463 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10464 if (CONSP (XCAR (tail
))
10465 && (sym
= XCAR (XCAR (tail
)),
10467 && (sym
= indirect_variable (sym
),
10468 val
= SYMBOL_VALUE (sym
),
10469 (BUFFER_LOCAL_VALUEP (val
)
10470 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10471 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10472 /* Use find_symbol_value rather than Fsymbol_value
10473 to avoid an error if it is void. */
10474 find_symbol_value (sym
);
10476 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10477 if (CONSP (XCAR (tail
))
10478 && (sym
= XCAR (XCAR (tail
)),
10480 && (sym
= indirect_variable (sym
),
10481 val
= SYMBOL_VALUE (sym
),
10482 (BUFFER_LOCAL_VALUEP (val
)
10483 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10484 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10485 find_symbol_value (sym
);
10489 #define STOP_POLLING \
10490 do { if (! polling_stopped_here) stop_polling (); \
10491 polling_stopped_here = 1; } while (0)
10493 #define RESUME_POLLING \
10494 do { if (polling_stopped_here) start_polling (); \
10495 polling_stopped_here = 0; } while (0)
10498 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10499 response to any user action; therefore, we should preserve the echo
10500 area. (Actually, our caller does that job.) Perhaps in the future
10501 avoid recentering windows if it is not necessary; currently that
10502 causes some problems. */
10505 redisplay_internal (preserve_echo_area
)
10506 int preserve_echo_area
;
10508 struct window
*w
= XWINDOW (selected_window
);
10509 struct frame
*f
= XFRAME (w
->frame
);
10511 int must_finish
= 0;
10512 struct text_pos tlbufpos
, tlendpos
;
10513 int number_of_visible_frames
;
10515 struct frame
*sf
= SELECTED_FRAME ();
10516 int polling_stopped_here
= 0;
10518 /* Non-zero means redisplay has to consider all windows on all
10519 frames. Zero means, only selected_window is considered. */
10520 int consider_all_windows_p
;
10522 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10524 /* No redisplay if running in batch mode or frame is not yet fully
10525 initialized, or redisplay is explicitly turned off by setting
10526 Vinhibit_redisplay. */
10528 || !NILP (Vinhibit_redisplay
)
10529 || !f
->glyphs_initialized_p
)
10532 /* The flag redisplay_performed_directly_p is set by
10533 direct_output_for_insert when it already did the whole screen
10534 update necessary. */
10535 if (redisplay_performed_directly_p
)
10537 redisplay_performed_directly_p
= 0;
10538 if (!hscroll_windows (selected_window
))
10542 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
10543 if (popup_activated ())
10547 /* I don't think this happens but let's be paranoid. */
10548 if (redisplaying_p
)
10551 /* Record a function that resets redisplaying_p to its old value
10552 when we leave this function. */
10553 count
= SPECPDL_INDEX ();
10554 record_unwind_protect (unwind_redisplay
,
10555 Fcons (make_number (redisplaying_p
), selected_frame
));
10557 specbind (Qinhibit_free_realized_faces
, Qnil
);
10560 Lisp_Object tail
, frame
;
10562 FOR_EACH_FRAME (tail
, frame
)
10564 struct frame
*f
= XFRAME (frame
);
10565 f
->already_hscrolled_p
= 0;
10571 reconsider_clip_changes (w
, current_buffer
);
10572 last_escape_glyph_frame
= NULL
;
10573 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
10575 /* If new fonts have been loaded that make a glyph matrix adjustment
10576 necessary, do it. */
10577 if (fonts_changed_p
)
10579 adjust_glyphs (NULL
);
10580 ++windows_or_buffers_changed
;
10581 fonts_changed_p
= 0;
10584 /* If face_change_count is non-zero, init_iterator will free all
10585 realized faces, which includes the faces referenced from current
10586 matrices. So, we can't reuse current matrices in this case. */
10587 if (face_change_count
)
10588 ++windows_or_buffers_changed
;
10590 if (! FRAME_WINDOW_P (sf
)
10591 && previous_terminal_frame
!= sf
)
10593 /* Since frames on an ASCII terminal share the same display
10594 area, displaying a different frame means redisplay the whole
10596 windows_or_buffers_changed
++;
10597 SET_FRAME_GARBAGED (sf
);
10598 XSETFRAME (Vterminal_frame
, sf
);
10600 previous_terminal_frame
= sf
;
10602 /* Set the visible flags for all frames. Do this before checking
10603 for resized or garbaged frames; they want to know if their frames
10604 are visible. See the comment in frame.h for
10605 FRAME_SAMPLE_VISIBILITY. */
10607 Lisp_Object tail
, frame
;
10609 number_of_visible_frames
= 0;
10611 FOR_EACH_FRAME (tail
, frame
)
10613 struct frame
*f
= XFRAME (frame
);
10615 FRAME_SAMPLE_VISIBILITY (f
);
10616 if (FRAME_VISIBLE_P (f
))
10617 ++number_of_visible_frames
;
10618 clear_desired_matrices (f
);
10622 /* Notice any pending interrupt request to change frame size. */
10623 do_pending_window_change (1);
10625 /* Clear frames marked as garbaged. */
10626 if (frame_garbaged
)
10627 clear_garbaged_frames ();
10629 /* Build menubar and tool-bar items. */
10630 if (NILP (Vmemory_full
))
10631 prepare_menu_bars ();
10633 if (windows_or_buffers_changed
)
10634 update_mode_lines
++;
10636 /* Detect case that we need to write or remove a star in the mode line. */
10637 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10639 w
->update_mode_line
= Qt
;
10640 if (buffer_shared
> 1)
10641 update_mode_lines
++;
10644 /* If %c is in the mode line, update it if needed. */
10645 if (!NILP (w
->column_number_displayed
)
10646 /* This alternative quickly identifies a common case
10647 where no change is needed. */
10648 && !(PT
== XFASTINT (w
->last_point
)
10649 && XFASTINT (w
->last_modified
) >= MODIFF
10650 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10651 && (XFASTINT (w
->column_number_displayed
)
10652 != (int) current_column ())) /* iftc */
10653 w
->update_mode_line
= Qt
;
10655 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10657 /* The variable buffer_shared is set in redisplay_window and
10658 indicates that we redisplay a buffer in different windows. See
10660 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
10661 || cursor_type_changed
);
10663 /* If specs for an arrow have changed, do thorough redisplay
10664 to ensure we remove any arrow that should no longer exist. */
10665 if (overlay_arrows_changed_p ())
10666 consider_all_windows_p
= windows_or_buffers_changed
= 1;
10668 /* Normally the message* functions will have already displayed and
10669 updated the echo area, but the frame may have been trashed, or
10670 the update may have been preempted, so display the echo area
10671 again here. Checking message_cleared_p captures the case that
10672 the echo area should be cleared. */
10673 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
10674 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
10675 || (message_cleared_p
10676 && minibuf_level
== 0
10677 /* If the mini-window is currently selected, this means the
10678 echo-area doesn't show through. */
10679 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
10681 int window_height_changed_p
= echo_area_display (0);
10684 /* If we don't display the current message, don't clear the
10685 message_cleared_p flag, because, if we did, we wouldn't clear
10686 the echo area in the next redisplay which doesn't preserve
10688 if (!display_last_displayed_message_p
)
10689 message_cleared_p
= 0;
10691 if (fonts_changed_p
)
10693 else if (window_height_changed_p
)
10695 consider_all_windows_p
= 1;
10696 ++update_mode_lines
;
10697 ++windows_or_buffers_changed
;
10699 /* If window configuration was changed, frames may have been
10700 marked garbaged. Clear them or we will experience
10701 surprises wrt scrolling. */
10702 if (frame_garbaged
)
10703 clear_garbaged_frames ();
10706 else if (EQ (selected_window
, minibuf_window
)
10707 && (current_buffer
->clip_changed
10708 || XFASTINT (w
->last_modified
) < MODIFF
10709 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10710 && resize_mini_window (w
, 0))
10712 /* Resized active mini-window to fit the size of what it is
10713 showing if its contents might have changed. */
10715 consider_all_windows_p
= 1;
10716 ++windows_or_buffers_changed
;
10717 ++update_mode_lines
;
10719 /* If window configuration was changed, frames may have been
10720 marked garbaged. Clear them or we will experience
10721 surprises wrt scrolling. */
10722 if (frame_garbaged
)
10723 clear_garbaged_frames ();
10727 /* If showing the region, and mark has changed, we must redisplay
10728 the whole window. The assignment to this_line_start_pos prevents
10729 the optimization directly below this if-statement. */
10730 if (((!NILP (Vtransient_mark_mode
)
10731 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10732 != !NILP (w
->region_showing
))
10733 || (!NILP (w
->region_showing
)
10734 && !EQ (w
->region_showing
,
10735 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
10736 CHARPOS (this_line_start_pos
) = 0;
10738 /* Optimize the case that only the line containing the cursor in the
10739 selected window has changed. Variables starting with this_ are
10740 set in display_line and record information about the line
10741 containing the cursor. */
10742 tlbufpos
= this_line_start_pos
;
10743 tlendpos
= this_line_end_pos
;
10744 if (!consider_all_windows_p
10745 && CHARPOS (tlbufpos
) > 0
10746 && NILP (w
->update_mode_line
)
10747 && !current_buffer
->clip_changed
10748 && !current_buffer
->prevent_redisplay_optimizations_p
10749 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
10750 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
10751 /* Make sure recorded data applies to current buffer, etc. */
10752 && this_line_buffer
== current_buffer
10753 && current_buffer
== XBUFFER (w
->buffer
)
10754 && NILP (w
->force_start
)
10755 && NILP (w
->optional_new_start
)
10756 /* Point must be on the line that we have info recorded about. */
10757 && PT
>= CHARPOS (tlbufpos
)
10758 && PT
<= Z
- CHARPOS (tlendpos
)
10759 /* All text outside that line, including its final newline,
10760 must be unchanged */
10761 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
10762 CHARPOS (tlendpos
)))
10764 if (CHARPOS (tlbufpos
) > BEGV
10765 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
10766 && (CHARPOS (tlbufpos
) == ZV
10767 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
10768 /* Former continuation line has disappeared by becoming empty */
10770 else if (XFASTINT (w
->last_modified
) < MODIFF
10771 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
10772 || MINI_WINDOW_P (w
))
10774 /* We have to handle the case of continuation around a
10775 wide-column character (See the comment in indent.c around
10778 For instance, in the following case:
10780 -------- Insert --------
10781 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
10782 J_I_ ==> J_I_ `^^' are cursors.
10786 As we have to redraw the line above, we should goto cancel. */
10789 int line_height_before
= this_line_pixel_height
;
10791 /* Note that start_display will handle the case that the
10792 line starting at tlbufpos is a continuation lines. */
10793 start_display (&it
, w
, tlbufpos
);
10795 /* Implementation note: It this still necessary? */
10796 if (it
.current_x
!= this_line_start_x
)
10799 TRACE ((stderr
, "trying display optimization 1\n"));
10800 w
->cursor
.vpos
= -1;
10801 overlay_arrow_seen
= 0;
10802 it
.vpos
= this_line_vpos
;
10803 it
.current_y
= this_line_y
;
10804 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
10805 display_line (&it
);
10807 /* If line contains point, is not continued,
10808 and ends at same distance from eob as before, we win */
10809 if (w
->cursor
.vpos
>= 0
10810 /* Line is not continued, otherwise this_line_start_pos
10811 would have been set to 0 in display_line. */
10812 && CHARPOS (this_line_start_pos
)
10813 /* Line ends as before. */
10814 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
10815 /* Line has same height as before. Otherwise other lines
10816 would have to be shifted up or down. */
10817 && this_line_pixel_height
== line_height_before
)
10819 /* If this is not the window's last line, we must adjust
10820 the charstarts of the lines below. */
10821 if (it
.current_y
< it
.last_visible_y
)
10823 struct glyph_row
*row
10824 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
10825 int delta
, delta_bytes
;
10827 if (Z
- CHARPOS (tlendpos
) == ZV
)
10829 /* This line ends at end of (accessible part of)
10830 buffer. There is no newline to count. */
10832 - CHARPOS (tlendpos
)
10833 - MATRIX_ROW_START_CHARPOS (row
));
10834 delta_bytes
= (Z_BYTE
10835 - BYTEPOS (tlendpos
)
10836 - MATRIX_ROW_START_BYTEPOS (row
));
10840 /* This line ends in a newline. Must take
10841 account of the newline and the rest of the
10842 text that follows. */
10844 - CHARPOS (tlendpos
)
10845 - MATRIX_ROW_START_CHARPOS (row
));
10846 delta_bytes
= (Z_BYTE
10847 - BYTEPOS (tlendpos
)
10848 - MATRIX_ROW_START_BYTEPOS (row
));
10851 increment_matrix_positions (w
->current_matrix
,
10852 this_line_vpos
+ 1,
10853 w
->current_matrix
->nrows
,
10854 delta
, delta_bytes
);
10857 /* If this row displays text now but previously didn't,
10858 or vice versa, w->window_end_vpos may have to be
10860 if ((it
.glyph_row
- 1)->displays_text_p
)
10862 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10863 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10865 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10866 && this_line_vpos
> 0)
10867 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10868 w
->window_end_valid
= Qnil
;
10870 /* Update hint: No need to try to scroll in update_window. */
10871 w
->desired_matrix
->no_scrolling_p
= 1;
10874 *w
->desired_matrix
->method
= 0;
10875 debug_method_add (w
, "optimization 1");
10877 #ifdef HAVE_WINDOW_SYSTEM
10878 update_window_fringes (w
, 0);
10885 else if (/* Cursor position hasn't changed. */
10886 PT
== XFASTINT (w
->last_point
)
10887 /* Make sure the cursor was last displayed
10888 in this window. Otherwise we have to reposition it. */
10889 && 0 <= w
->cursor
.vpos
10890 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
10894 do_pending_window_change (1);
10896 /* We used to always goto end_of_redisplay here, but this
10897 isn't enough if we have a blinking cursor. */
10898 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10899 goto end_of_redisplay
;
10903 /* If highlighting the region, or if the cursor is in the echo area,
10904 then we can't just move the cursor. */
10905 else if (! (!NILP (Vtransient_mark_mode
)
10906 && !NILP (current_buffer
->mark_active
))
10907 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10908 || highlight_nonselected_windows
)
10909 && NILP (w
->region_showing
)
10910 && NILP (Vshow_trailing_whitespace
)
10911 && !cursor_in_echo_area
)
10914 struct glyph_row
*row
;
10916 /* Skip from tlbufpos to PT and see where it is. Note that
10917 PT may be in invisible text. If so, we will end at the
10918 next visible position. */
10919 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10920 NULL
, DEFAULT_FACE_ID
);
10921 it
.current_x
= this_line_start_x
;
10922 it
.current_y
= this_line_y
;
10923 it
.vpos
= this_line_vpos
;
10925 /* The call to move_it_to stops in front of PT, but
10926 moves over before-strings. */
10927 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10929 if (it
.vpos
== this_line_vpos
10930 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10933 xassert (this_line_vpos
== it
.vpos
);
10934 xassert (this_line_y
== it
.current_y
);
10935 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10937 *w
->desired_matrix
->method
= 0;
10938 debug_method_add (w
, "optimization 3");
10947 /* Text changed drastically or point moved off of line. */
10948 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10951 CHARPOS (this_line_start_pos
) = 0;
10952 consider_all_windows_p
|= buffer_shared
> 1;
10953 ++clear_face_cache_count
;
10954 #ifdef HAVE_WINDOW_SYSTEM
10955 ++clear_image_cache_count
;
10958 /* Build desired matrices, and update the display. If
10959 consider_all_windows_p is non-zero, do it for all windows on all
10960 frames. Otherwise do it for selected_window, only. */
10962 if (consider_all_windows_p
)
10964 Lisp_Object tail
, frame
;
10966 FOR_EACH_FRAME (tail
, frame
)
10967 XFRAME (frame
)->updated_p
= 0;
10969 /* Recompute # windows showing selected buffer. This will be
10970 incremented each time such a window is displayed. */
10973 FOR_EACH_FRAME (tail
, frame
)
10975 struct frame
*f
= XFRAME (frame
);
10977 if (FRAME_WINDOW_P (f
) || f
== sf
)
10979 if (! EQ (frame
, selected_frame
))
10980 /* Select the frame, for the sake of frame-local
10982 select_frame_for_redisplay (frame
);
10984 /* Mark all the scroll bars to be removed; we'll redeem
10985 the ones we want when we redisplay their windows. */
10986 if (condemn_scroll_bars_hook
)
10987 condemn_scroll_bars_hook (f
);
10989 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10990 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10992 /* Any scroll bars which redisplay_windows should have
10993 nuked should now go away. */
10994 if (judge_scroll_bars_hook
)
10995 judge_scroll_bars_hook (f
);
10997 /* If fonts changed, display again. */
10998 /* ??? rms: I suspect it is a mistake to jump all the way
10999 back to retry here. It should just retry this frame. */
11000 if (fonts_changed_p
)
11003 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11005 /* See if we have to hscroll. */
11006 if (!f
->already_hscrolled_p
)
11008 f
->already_hscrolled_p
= 1;
11009 if (hscroll_windows (f
->root_window
))
11013 /* Prevent various kinds of signals during display
11014 update. stdio is not robust about handling
11015 signals, which can cause an apparent I/O
11017 if (interrupt_input
)
11018 unrequest_sigio ();
11021 /* Update the display. */
11022 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11023 pause
|= update_frame (f
, 0, 0);
11024 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
11036 /* Do the mark_window_display_accurate after all windows have
11037 been redisplayed because this call resets flags in buffers
11038 which are needed for proper redisplay. */
11039 FOR_EACH_FRAME (tail
, frame
)
11041 struct frame
*f
= XFRAME (frame
);
11044 mark_window_display_accurate (f
->root_window
, 1);
11045 if (frame_up_to_date_hook
)
11046 frame_up_to_date_hook (f
);
11051 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11053 Lisp_Object mini_window
;
11054 struct frame
*mini_frame
;
11056 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11057 /* Use list_of_error, not Qerror, so that
11058 we catch only errors and don't run the debugger. */
11059 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11061 redisplay_window_error
);
11063 /* Compare desired and current matrices, perform output. */
11066 /* If fonts changed, display again. */
11067 if (fonts_changed_p
)
11070 /* Prevent various kinds of signals during display update.
11071 stdio is not robust about handling signals,
11072 which can cause an apparent I/O error. */
11073 if (interrupt_input
)
11074 unrequest_sigio ();
11077 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11079 if (hscroll_windows (selected_window
))
11082 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11083 pause
= update_frame (sf
, 0, 0);
11086 /* We may have called echo_area_display at the top of this
11087 function. If the echo area is on another frame, that may
11088 have put text on a frame other than the selected one, so the
11089 above call to update_frame would not have caught it. Catch
11091 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11092 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11094 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11096 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11097 pause
|= update_frame (mini_frame
, 0, 0);
11098 if (!pause
&& hscroll_windows (mini_window
))
11103 /* If display was paused because of pending input, make sure we do a
11104 thorough update the next time. */
11107 /* Prevent the optimization at the beginning of
11108 redisplay_internal that tries a single-line update of the
11109 line containing the cursor in the selected window. */
11110 CHARPOS (this_line_start_pos
) = 0;
11112 /* Let the overlay arrow be updated the next time. */
11113 update_overlay_arrows (0);
11115 /* If we pause after scrolling, some rows in the current
11116 matrices of some windows are not valid. */
11117 if (!WINDOW_FULL_WIDTH_P (w
)
11118 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11119 update_mode_lines
= 1;
11123 if (!consider_all_windows_p
)
11125 /* This has already been done above if
11126 consider_all_windows_p is set. */
11127 mark_window_display_accurate_1 (w
, 1);
11129 /* Say overlay arrows are up to date. */
11130 update_overlay_arrows (1);
11132 if (frame_up_to_date_hook
!= 0)
11133 frame_up_to_date_hook (sf
);
11136 update_mode_lines
= 0;
11137 windows_or_buffers_changed
= 0;
11138 cursor_type_changed
= 0;
11141 /* Start SIGIO interrupts coming again. Having them off during the
11142 code above makes it less likely one will discard output, but not
11143 impossible, since there might be stuff in the system buffer here.
11144 But it is much hairier to try to do anything about that. */
11145 if (interrupt_input
)
11149 /* If a frame has become visible which was not before, redisplay
11150 again, so that we display it. Expose events for such a frame
11151 (which it gets when becoming visible) don't call the parts of
11152 redisplay constructing glyphs, so simply exposing a frame won't
11153 display anything in this case. So, we have to display these
11154 frames here explicitly. */
11157 Lisp_Object tail
, frame
;
11160 FOR_EACH_FRAME (tail
, frame
)
11162 int this_is_visible
= 0;
11164 if (XFRAME (frame
)->visible
)
11165 this_is_visible
= 1;
11166 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11167 if (XFRAME (frame
)->visible
)
11168 this_is_visible
= 1;
11170 if (this_is_visible
)
11174 if (new_count
!= number_of_visible_frames
)
11175 windows_or_buffers_changed
++;
11178 /* Change frame size now if a change is pending. */
11179 do_pending_window_change (1);
11181 /* If we just did a pending size change, or have additional
11182 visible frames, redisplay again. */
11183 if (windows_or_buffers_changed
&& !pause
)
11186 /* Clear the face cache eventually. */
11187 if (consider_all_windows_p
)
11189 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11191 clear_face_cache (0);
11192 clear_face_cache_count
= 0;
11194 #ifdef HAVE_WINDOW_SYSTEM
11195 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11197 Lisp_Object tail
, frame
;
11198 FOR_EACH_FRAME (tail
, frame
)
11200 struct frame
*f
= XFRAME (frame
);
11201 if (FRAME_WINDOW_P (f
))
11202 clear_image_cache (f
, 0);
11204 clear_image_cache_count
= 0;
11206 #endif /* HAVE_WINDOW_SYSTEM */
11210 unbind_to (count
, Qnil
);
11215 /* Redisplay, but leave alone any recent echo area message unless
11216 another message has been requested in its place.
11218 This is useful in situations where you need to redisplay but no
11219 user action has occurred, making it inappropriate for the message
11220 area to be cleared. See tracking_off and
11221 wait_reading_process_output for examples of these situations.
11223 FROM_WHERE is an integer saying from where this function was
11224 called. This is useful for debugging. */
11227 redisplay_preserve_echo_area (from_where
)
11230 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
11232 if (!NILP (echo_area_buffer
[1]))
11234 /* We have a previously displayed message, but no current
11235 message. Redisplay the previous message. */
11236 display_last_displayed_message_p
= 1;
11237 redisplay_internal (1);
11238 display_last_displayed_message_p
= 0;
11241 redisplay_internal (1);
11243 if (rif
!= NULL
&& rif
->flush_display_optional
)
11244 rif
->flush_display_optional (NULL
);
11248 /* Function registered with record_unwind_protect in
11249 redisplay_internal. Reset redisplaying_p to the value it had
11250 before redisplay_internal was called, and clear
11251 prevent_freeing_realized_faces_p. It also selects the previously
11255 unwind_redisplay (val
)
11258 Lisp_Object old_redisplaying_p
, old_frame
;
11260 old_redisplaying_p
= XCAR (val
);
11261 redisplaying_p
= XFASTINT (old_redisplaying_p
);
11262 old_frame
= XCDR (val
);
11263 if (! EQ (old_frame
, selected_frame
))
11264 select_frame_for_redisplay (old_frame
);
11269 /* Mark the display of window W as accurate or inaccurate. If
11270 ACCURATE_P is non-zero mark display of W as accurate. If
11271 ACCURATE_P is zero, arrange for W to be redisplayed the next time
11272 redisplay_internal is called. */
11275 mark_window_display_accurate_1 (w
, accurate_p
)
11279 if (BUFFERP (w
->buffer
))
11281 struct buffer
*b
= XBUFFER (w
->buffer
);
11284 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
11285 w
->last_overlay_modified
11286 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
11288 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
11292 b
->clip_changed
= 0;
11293 b
->prevent_redisplay_optimizations_p
= 0;
11295 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
11296 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
11297 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
11298 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
11300 w
->current_matrix
->buffer
= b
;
11301 w
->current_matrix
->begv
= BUF_BEGV (b
);
11302 w
->current_matrix
->zv
= BUF_ZV (b
);
11304 w
->last_cursor
= w
->cursor
;
11305 w
->last_cursor_off_p
= w
->cursor_off_p
;
11307 if (w
== XWINDOW (selected_window
))
11308 w
->last_point
= make_number (BUF_PT (b
));
11310 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
11316 w
->window_end_valid
= w
->buffer
;
11317 #if 0 /* This is incorrect with variable-height lines. */
11318 xassert (XINT (w
->window_end_vpos
)
11319 < (WINDOW_TOTAL_LINES (w
)
11320 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
11322 w
->update_mode_line
= Qnil
;
11327 /* Mark the display of windows in the window tree rooted at WINDOW as
11328 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
11329 windows as accurate. If ACCURATE_P is zero, arrange for windows to
11330 be redisplayed the next time redisplay_internal is called. */
11333 mark_window_display_accurate (window
, accurate_p
)
11334 Lisp_Object window
;
11339 for (; !NILP (window
); window
= w
->next
)
11341 w
= XWINDOW (window
);
11342 mark_window_display_accurate_1 (w
, accurate_p
);
11344 if (!NILP (w
->vchild
))
11345 mark_window_display_accurate (w
->vchild
, accurate_p
);
11346 if (!NILP (w
->hchild
))
11347 mark_window_display_accurate (w
->hchild
, accurate_p
);
11352 update_overlay_arrows (1);
11356 /* Force a thorough redisplay the next time by setting
11357 last_arrow_position and last_arrow_string to t, which is
11358 unequal to any useful value of Voverlay_arrow_... */
11359 update_overlay_arrows (-1);
11364 /* Return value in display table DP (Lisp_Char_Table *) for character
11365 C. Since a display table doesn't have any parent, we don't have to
11366 follow parent. Do not call this function directly but use the
11367 macro DISP_CHAR_VECTOR. */
11370 disp_char_vector (dp
, c
)
11371 struct Lisp_Char_Table
*dp
;
11377 if (SINGLE_BYTE_CHAR_P (c
))
11378 return (dp
->contents
[c
]);
11380 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
11383 else if (code
[2] < 32)
11386 /* Here, the possible range of code[0] (== charset ID) is
11387 128..max_charset. Since the top level char table contains data
11388 for multibyte characters after 256th element, we must increment
11389 code[0] by 128 to get a correct index. */
11391 code
[3] = -1; /* anchor */
11393 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
11395 val
= dp
->contents
[code
[i
]];
11396 if (!SUB_CHAR_TABLE_P (val
))
11397 return (NILP (val
) ? dp
->defalt
: val
);
11400 /* Here, val is a sub char table. We return the default value of
11402 return (dp
->defalt
);
11407 /***********************************************************************
11409 ***********************************************************************/
11411 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11414 redisplay_windows (window
)
11415 Lisp_Object window
;
11417 while (!NILP (window
))
11419 struct window
*w
= XWINDOW (window
);
11421 if (!NILP (w
->hchild
))
11422 redisplay_windows (w
->hchild
);
11423 else if (!NILP (w
->vchild
))
11424 redisplay_windows (w
->vchild
);
11427 displayed_buffer
= XBUFFER (w
->buffer
);
11428 /* Use list_of_error, not Qerror, so that
11429 we catch only errors and don't run the debugger. */
11430 internal_condition_case_1 (redisplay_window_0
, window
,
11432 redisplay_window_error
);
11440 redisplay_window_error ()
11442 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11447 redisplay_window_0 (window
)
11448 Lisp_Object window
;
11450 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11451 redisplay_window (window
, 0);
11456 redisplay_window_1 (window
)
11457 Lisp_Object window
;
11459 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11460 redisplay_window (window
, 1);
11465 /* Increment GLYPH until it reaches END or CONDITION fails while
11466 adding (GLYPH)->pixel_width to X. */
11468 #define SKIP_GLYPHS(glyph, end, x, condition) \
11471 (x) += (glyph)->pixel_width; \
11474 while ((glyph) < (end) && (condition))
11477 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11478 DELTA is the number of bytes by which positions recorded in ROW
11479 differ from current buffer positions. */
11482 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11484 struct glyph_row
*row
;
11485 struct glyph_matrix
*matrix
;
11486 int delta
, delta_bytes
, dy
, dvpos
;
11488 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11489 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11490 struct glyph
*cursor
= NULL
;
11491 /* The first glyph that starts a sequence of glyphs from string. */
11492 struct glyph
*string_start
;
11493 /* The X coordinate of string_start. */
11494 int string_start_x
;
11495 /* The last known character position. */
11496 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11497 /* The last known character position before string_start. */
11498 int string_before_pos
;
11501 int cursor_from_overlay_pos
= 0;
11502 int pt_old
= PT
- delta
;
11504 /* Skip over glyphs not having an object at the start of the row.
11505 These are special glyphs like truncation marks on terminal
11507 if (row
->displays_text_p
)
11509 && INTEGERP (glyph
->object
)
11510 && glyph
->charpos
< 0)
11512 x
+= glyph
->pixel_width
;
11516 string_start
= NULL
;
11518 && !INTEGERP (glyph
->object
)
11519 && (!BUFFERP (glyph
->object
)
11520 || (last_pos
= glyph
->charpos
) < pt_old
))
11522 if (! STRINGP (glyph
->object
))
11524 string_start
= NULL
;
11525 x
+= glyph
->pixel_width
;
11527 if (cursor_from_overlay_pos
11528 && last_pos
> cursor_from_overlay_pos
)
11530 cursor_from_overlay_pos
= 0;
11536 string_before_pos
= last_pos
;
11537 string_start
= glyph
;
11538 string_start_x
= x
;
11539 /* Skip all glyphs from string. */
11543 if ((cursor
== NULL
|| glyph
> cursor
)
11544 && !NILP (Fget_char_property (make_number ((glyph
)->charpos
),
11545 Qcursor
, (glyph
)->object
))
11546 && (pos
= string_buffer_position (w
, glyph
->object
,
11547 string_before_pos
),
11548 (pos
== 0 /* From overlay */
11549 || pos
== pt_old
)))
11551 /* Estimate overlay buffer position from the buffer
11552 positions of the glyphs before and after the overlay.
11553 Add 1 to last_pos so that if point corresponds to the
11554 glyph right after the overlay, we still use a 'cursor'
11555 property found in that overlay. */
11556 cursor_from_overlay_pos
= pos
== 0 ? last_pos
+1 : 0;
11560 x
+= glyph
->pixel_width
;
11563 while (glyph
< end
&& STRINGP (glyph
->object
));
11567 if (cursor
!= NULL
)
11572 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
11574 /* Scan back over the ellipsis glyphs, decrementing positions. */
11575 while (glyph
> row
->glyphs
[TEXT_AREA
]
11576 && (glyph
- 1)->charpos
== last_pos
)
11577 glyph
--, x
-= glyph
->pixel_width
;
11578 /* That loop always goes one position too far,
11579 including the glyph before the ellipsis.
11580 So scan forward over that one. */
11581 x
+= glyph
->pixel_width
;
11584 else if (string_start
11585 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
11587 /* We may have skipped over point because the previous glyphs
11588 are from string. As there's no easy way to know the
11589 character position of the current glyph, find the correct
11590 glyph on point by scanning from string_start again. */
11592 Lisp_Object string
;
11595 limit
= make_number (pt_old
+ 1);
11597 glyph
= string_start
;
11598 x
= string_start_x
;
11599 string
= glyph
->object
;
11600 pos
= string_buffer_position (w
, string
, string_before_pos
);
11601 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
11602 because we always put cursor after overlay strings. */
11603 while (pos
== 0 && glyph
< end
)
11605 string
= glyph
->object
;
11606 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11608 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
11611 while (glyph
< end
)
11613 pos
= XINT (Fnext_single_char_property_change
11614 (make_number (pos
), Qdisplay
, Qnil
, limit
));
11617 /* Skip glyphs from the same string. */
11618 string
= glyph
->object
;
11619 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11620 /* Skip glyphs from an overlay. */
11622 && ! string_buffer_position (w
, glyph
->object
, pos
))
11624 string
= glyph
->object
;
11625 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11630 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
11632 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
11633 w
->cursor
.y
= row
->y
+ dy
;
11635 if (w
== XWINDOW (selected_window
))
11637 if (!row
->continued_p
11638 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
11641 this_line_buffer
= XBUFFER (w
->buffer
);
11643 CHARPOS (this_line_start_pos
)
11644 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
11645 BYTEPOS (this_line_start_pos
)
11646 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
11648 CHARPOS (this_line_end_pos
)
11649 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
11650 BYTEPOS (this_line_end_pos
)
11651 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
11653 this_line_y
= w
->cursor
.y
;
11654 this_line_pixel_height
= row
->height
;
11655 this_line_vpos
= w
->cursor
.vpos
;
11656 this_line_start_x
= row
->x
;
11659 CHARPOS (this_line_start_pos
) = 0;
11664 /* Run window scroll functions, if any, for WINDOW with new window
11665 start STARTP. Sets the window start of WINDOW to that position.
11667 We assume that the window's buffer is really current. */
11669 static INLINE
struct text_pos
11670 run_window_scroll_functions (window
, startp
)
11671 Lisp_Object window
;
11672 struct text_pos startp
;
11674 struct window
*w
= XWINDOW (window
);
11675 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
11677 if (current_buffer
!= XBUFFER (w
->buffer
))
11680 if (!NILP (Vwindow_scroll_functions
))
11682 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
11683 make_number (CHARPOS (startp
)));
11684 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11685 /* In case the hook functions switch buffers. */
11686 if (current_buffer
!= XBUFFER (w
->buffer
))
11687 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11694 /* Make sure the line containing the cursor is fully visible.
11695 A value of 1 means there is nothing to be done.
11696 (Either the line is fully visible, or it cannot be made so,
11697 or we cannot tell.)
11699 If FORCE_P is non-zero, return 0 even if partial visible cursor row
11700 is higher than window.
11702 A value of 0 means the caller should do scrolling
11703 as if point had gone off the screen. */
11706 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
11709 int current_matrix_p
;
11711 struct glyph_matrix
*matrix
;
11712 struct glyph_row
*row
;
11715 if (!make_cursor_line_fully_visible_p
)
11718 /* It's not always possible to find the cursor, e.g, when a window
11719 is full of overlay strings. Don't do anything in that case. */
11720 if (w
->cursor
.vpos
< 0)
11723 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
11724 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
11726 /* If the cursor row is not partially visible, there's nothing to do. */
11727 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
11730 /* If the row the cursor is in is taller than the window's height,
11731 it's not clear what to do, so do nothing. */
11732 window_height
= window_box_height (w
);
11733 if (row
->height
>= window_height
)
11735 if (!force_p
|| MINI_WINDOW_P (w
) || w
->vscroll
)
11741 /* This code used to try to scroll the window just enough to make
11742 the line visible. It returned 0 to say that the caller should
11743 allocate larger glyph matrices. */
11745 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
11747 int dy
= row
->height
- row
->visible_height
;
11750 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11752 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
11754 int dy
= - (row
->height
- row
->visible_height
);
11757 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11760 /* When we change the cursor y-position of the selected window,
11761 change this_line_y as well so that the display optimization for
11762 the cursor line of the selected window in redisplay_internal uses
11763 the correct y-position. */
11764 if (w
== XWINDOW (selected_window
))
11765 this_line_y
= w
->cursor
.y
;
11767 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
11768 redisplay with larger matrices. */
11769 if (matrix
->nrows
< required_matrix_height (w
))
11771 fonts_changed_p
= 1;
11780 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
11781 non-zero means only WINDOW is redisplayed in redisplay_internal.
11782 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
11783 in redisplay_window to bring a partially visible line into view in
11784 the case that only the cursor has moved.
11786 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
11787 last screen line's vertical height extends past the end of the screen.
11791 1 if scrolling succeeded
11793 0 if scrolling didn't find point.
11795 -1 if new fonts have been loaded so that we must interrupt
11796 redisplay, adjust glyph matrices, and try again. */
11802 SCROLLING_NEED_LARGER_MATRICES
11806 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
11807 scroll_step
, temp_scroll_step
, last_line_misfit
)
11808 Lisp_Object window
;
11809 int just_this_one_p
;
11810 EMACS_INT scroll_conservatively
, scroll_step
;
11811 int temp_scroll_step
;
11812 int last_line_misfit
;
11814 struct window
*w
= XWINDOW (window
);
11815 struct frame
*f
= XFRAME (w
->frame
);
11816 struct text_pos scroll_margin_pos
;
11817 struct text_pos pos
;
11818 struct text_pos startp
;
11820 Lisp_Object window_end
;
11821 int this_scroll_margin
;
11825 int amount_to_scroll
= 0;
11826 Lisp_Object aggressive
;
11828 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
11831 debug_method_add (w
, "try_scrolling");
11834 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11836 /* Compute scroll margin height in pixels. We scroll when point is
11837 within this distance from the top or bottom of the window. */
11838 if (scroll_margin
> 0)
11840 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11841 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11844 this_scroll_margin
= 0;
11846 /* Force scroll_conservatively to have a reasonable value so it doesn't
11847 cause an overflow while computing how much to scroll. */
11848 if (scroll_conservatively
)
11849 scroll_conservatively
= min (scroll_conservatively
,
11850 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
11852 /* Compute how much we should try to scroll maximally to bring point
11854 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
11855 scroll_max
= max (scroll_step
,
11856 max (scroll_conservatively
, temp_scroll_step
));
11857 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
11858 || NUMBERP (current_buffer
->scroll_up_aggressively
))
11859 /* We're trying to scroll because of aggressive scrolling
11860 but no scroll_step is set. Choose an arbitrary one. Maybe
11861 there should be a variable for this. */
11865 scroll_max
*= FRAME_LINE_HEIGHT (f
);
11867 /* Decide whether we have to scroll down. Start at the window end
11868 and move this_scroll_margin up to find the position of the scroll
11870 window_end
= Fwindow_end (window
, Qt
);
11874 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
11875 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
11877 if (this_scroll_margin
|| extra_scroll_margin_lines
)
11879 start_display (&it
, w
, scroll_margin_pos
);
11880 if (this_scroll_margin
)
11881 move_it_vertically_backward (&it
, this_scroll_margin
);
11882 if (extra_scroll_margin_lines
)
11883 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
11884 scroll_margin_pos
= it
.current
.pos
;
11887 if (PT
>= CHARPOS (scroll_margin_pos
))
11891 /* Point is in the scroll margin at the bottom of the window, or
11892 below. Compute a new window start that makes point visible. */
11894 /* Compute the distance from the scroll margin to PT.
11895 Give up if the distance is greater than scroll_max. */
11896 start_display (&it
, w
, scroll_margin_pos
);
11898 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11899 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11901 /* To make point visible, we have to move the window start
11902 down so that the line the cursor is in is visible, which
11903 means we have to add in the height of the cursor line. */
11904 dy
= line_bottom_y (&it
) - y0
;
11906 if (dy
> scroll_max
)
11907 return SCROLLING_FAILED
;
11909 /* Move the window start down. If scrolling conservatively,
11910 move it just enough down to make point visible. If
11911 scroll_step is set, move it down by scroll_step. */
11912 start_display (&it
, w
, startp
);
11914 if (scroll_conservatively
)
11915 /* Set AMOUNT_TO_SCROLL to at least one line,
11916 and at most scroll_conservatively lines. */
11918 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
11919 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
11920 else if (scroll_step
|| temp_scroll_step
)
11921 amount_to_scroll
= scroll_max
;
11924 aggressive
= current_buffer
->scroll_up_aggressively
;
11925 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11926 if (NUMBERP (aggressive
))
11928 double float_amount
= XFLOATINT (aggressive
) * height
;
11929 amount_to_scroll
= float_amount
;
11930 if (amount_to_scroll
== 0 && float_amount
> 0)
11931 amount_to_scroll
= 1;
11935 if (amount_to_scroll
<= 0)
11936 return SCROLLING_FAILED
;
11938 /* If moving by amount_to_scroll leaves STARTP unchanged,
11939 move it down one screen line. */
11941 move_it_vertically (&it
, amount_to_scroll
);
11942 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
11943 move_it_by_lines (&it
, 1, 1);
11944 startp
= it
.current
.pos
;
11948 /* See if point is inside the scroll margin at the top of the
11950 scroll_margin_pos
= startp
;
11951 if (this_scroll_margin
)
11953 start_display (&it
, w
, startp
);
11954 move_it_vertically (&it
, this_scroll_margin
);
11955 scroll_margin_pos
= it
.current
.pos
;
11958 if (PT
< CHARPOS (scroll_margin_pos
))
11960 /* Point is in the scroll margin at the top of the window or
11961 above what is displayed in the window. */
11964 /* Compute the vertical distance from PT to the scroll
11965 margin position. Give up if distance is greater than
11967 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
11968 start_display (&it
, w
, pos
);
11970 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
11971 it
.last_visible_y
, -1,
11972 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11973 dy
= it
.current_y
- y0
;
11974 if (dy
> scroll_max
)
11975 return SCROLLING_FAILED
;
11977 /* Compute new window start. */
11978 start_display (&it
, w
, startp
);
11980 if (scroll_conservatively
)
11982 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11983 else if (scroll_step
|| temp_scroll_step
)
11984 amount_to_scroll
= scroll_max
;
11987 aggressive
= current_buffer
->scroll_down_aggressively
;
11988 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11989 if (NUMBERP (aggressive
))
11991 double float_amount
= XFLOATINT (aggressive
) * height
;
11992 amount_to_scroll
= float_amount
;
11993 if (amount_to_scroll
== 0 && float_amount
> 0)
11994 amount_to_scroll
= 1;
11998 if (amount_to_scroll
<= 0)
11999 return SCROLLING_FAILED
;
12001 move_it_vertically_backward (&it
, amount_to_scroll
);
12002 startp
= it
.current
.pos
;
12006 /* Run window scroll functions. */
12007 startp
= run_window_scroll_functions (window
, startp
);
12009 /* Display the window. Give up if new fonts are loaded, or if point
12011 if (!try_window (window
, startp
, 0))
12012 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12013 else if (w
->cursor
.vpos
< 0)
12015 clear_glyph_matrix (w
->desired_matrix
);
12016 rc
= SCROLLING_FAILED
;
12020 /* Maybe forget recorded base line for line number display. */
12021 if (!just_this_one_p
12022 || current_buffer
->clip_changed
12023 || BEG_UNCHANGED
< CHARPOS (startp
))
12024 w
->base_line_number
= Qnil
;
12026 /* If cursor ends up on a partially visible line,
12027 treat that as being off the bottom of the screen. */
12028 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12030 clear_glyph_matrix (w
->desired_matrix
);
12031 ++extra_scroll_margin_lines
;
12034 rc
= SCROLLING_SUCCESS
;
12041 /* Compute a suitable window start for window W if display of W starts
12042 on a continuation line. Value is non-zero if a new window start
12045 The new window start will be computed, based on W's width, starting
12046 from the start of the continued line. It is the start of the
12047 screen line with the minimum distance from the old start W->start. */
12050 compute_window_start_on_continuation_line (w
)
12053 struct text_pos pos
, start_pos
;
12054 int window_start_changed_p
= 0;
12056 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12058 /* If window start is on a continuation line... Window start may be
12059 < BEGV in case there's invisible text at the start of the
12060 buffer (M-x rmail, for example). */
12061 if (CHARPOS (start_pos
) > BEGV
12062 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12065 struct glyph_row
*row
;
12067 /* Handle the case that the window start is out of range. */
12068 if (CHARPOS (start_pos
) < BEGV
)
12069 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12070 else if (CHARPOS (start_pos
) > ZV
)
12071 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12073 /* Find the start of the continued line. This should be fast
12074 because scan_buffer is fast (newline cache). */
12075 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12076 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12077 row
, DEFAULT_FACE_ID
);
12078 reseat_at_previous_visible_line_start (&it
);
12080 /* If the line start is "too far" away from the window start,
12081 say it takes too much time to compute a new window start. */
12082 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12083 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12085 int min_distance
, distance
;
12087 /* Move forward by display lines to find the new window
12088 start. If window width was enlarged, the new start can
12089 be expected to be > the old start. If window width was
12090 decreased, the new window start will be < the old start.
12091 So, we're looking for the display line start with the
12092 minimum distance from the old window start. */
12093 pos
= it
.current
.pos
;
12094 min_distance
= INFINITY
;
12095 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12096 distance
< min_distance
)
12098 min_distance
= distance
;
12099 pos
= it
.current
.pos
;
12100 move_it_by_lines (&it
, 1, 0);
12103 /* Set the window start there. */
12104 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12105 window_start_changed_p
= 1;
12109 return window_start_changed_p
;
12113 /* Try cursor movement in case text has not changed in window WINDOW,
12114 with window start STARTP. Value is
12116 CURSOR_MOVEMENT_SUCCESS if successful
12118 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12120 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12121 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12122 we want to scroll as if scroll-step were set to 1. See the code.
12124 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12125 which case we have to abort this redisplay, and adjust matrices
12130 CURSOR_MOVEMENT_SUCCESS
,
12131 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12132 CURSOR_MOVEMENT_MUST_SCROLL
,
12133 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12137 try_cursor_movement (window
, startp
, scroll_step
)
12138 Lisp_Object window
;
12139 struct text_pos startp
;
12142 struct window
*w
= XWINDOW (window
);
12143 struct frame
*f
= XFRAME (w
->frame
);
12144 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12147 if (inhibit_try_cursor_movement
)
12151 /* Handle case where text has not changed, only point, and it has
12152 not moved off the frame. */
12153 if (/* Point may be in this window. */
12154 PT
>= CHARPOS (startp
)
12155 /* Selective display hasn't changed. */
12156 && !current_buffer
->clip_changed
12157 /* Function force-mode-line-update is used to force a thorough
12158 redisplay. It sets either windows_or_buffers_changed or
12159 update_mode_lines. So don't take a shortcut here for these
12161 && !update_mode_lines
12162 && !windows_or_buffers_changed
12163 && !cursor_type_changed
12164 /* Can't use this case if highlighting a region. When a
12165 region exists, cursor movement has to do more than just
12167 && !(!NILP (Vtransient_mark_mode
)
12168 && !NILP (current_buffer
->mark_active
))
12169 && NILP (w
->region_showing
)
12170 && NILP (Vshow_trailing_whitespace
)
12171 /* Right after splitting windows, last_point may be nil. */
12172 && INTEGERP (w
->last_point
)
12173 /* This code is not used for mini-buffer for the sake of the case
12174 of redisplaying to replace an echo area message; since in
12175 that case the mini-buffer contents per se are usually
12176 unchanged. This code is of no real use in the mini-buffer
12177 since the handling of this_line_start_pos, etc., in redisplay
12178 handles the same cases. */
12179 && !EQ (window
, minibuf_window
)
12180 /* When splitting windows or for new windows, it happens that
12181 redisplay is called with a nil window_end_vpos or one being
12182 larger than the window. This should really be fixed in
12183 window.c. I don't have this on my list, now, so we do
12184 approximately the same as the old redisplay code. --gerd. */
12185 && INTEGERP (w
->window_end_vpos
)
12186 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12187 && (FRAME_WINDOW_P (f
)
12188 || !overlay_arrow_in_current_buffer_p ()))
12190 int this_scroll_margin
, top_scroll_margin
;
12191 struct glyph_row
*row
= NULL
;
12194 debug_method_add (w
, "cursor movement");
12197 /* Scroll if point within this distance from the top or bottom
12198 of the window. This is a pixel value. */
12199 this_scroll_margin
= max (0, scroll_margin
);
12200 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12201 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12203 top_scroll_margin
= this_scroll_margin
;
12204 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12205 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12207 /* Start with the row the cursor was displayed during the last
12208 not paused redisplay. Give up if that row is not valid. */
12209 if (w
->last_cursor
.vpos
< 0
12210 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12211 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12214 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12215 if (row
->mode_line_p
)
12217 if (!row
->enabled_p
)
12218 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12221 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12224 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12226 if (PT
> XFASTINT (w
->last_point
))
12228 /* Point has moved forward. */
12229 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12230 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12232 xassert (row
->enabled_p
);
12236 /* The end position of a row equals the start position
12237 of the next row. If PT is there, we would rather
12238 display it in the next line. */
12239 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12240 && MATRIX_ROW_END_CHARPOS (row
) == PT
12241 && !cursor_row_p (w
, row
))
12244 /* If within the scroll margin, scroll. Note that
12245 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
12246 the next line would be drawn, and that
12247 this_scroll_margin can be zero. */
12248 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
12249 || PT
> MATRIX_ROW_END_CHARPOS (row
)
12250 /* Line is completely visible last line in window
12251 and PT is to be set in the next line. */
12252 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
12253 && PT
== MATRIX_ROW_END_CHARPOS (row
)
12254 && !row
->ends_at_zv_p
12255 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12258 else if (PT
< XFASTINT (w
->last_point
))
12260 /* Cursor has to be moved backward. Note that PT >=
12261 CHARPOS (startp) because of the outer if-statement. */
12262 while (!row
->mode_line_p
12263 && (MATRIX_ROW_START_CHARPOS (row
) > PT
12264 || (MATRIX_ROW_START_CHARPOS (row
) == PT
12265 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
12266 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
12267 row
> w
->current_matrix
->rows
12268 && (row
-1)->ends_in_newline_from_string_p
))))
12269 && (row
->y
> top_scroll_margin
12270 || CHARPOS (startp
) == BEGV
))
12272 xassert (row
->enabled_p
);
12276 /* Consider the following case: Window starts at BEGV,
12277 there is invisible, intangible text at BEGV, so that
12278 display starts at some point START > BEGV. It can
12279 happen that we are called with PT somewhere between
12280 BEGV and START. Try to handle that case. */
12281 if (row
< w
->current_matrix
->rows
12282 || row
->mode_line_p
)
12284 row
= w
->current_matrix
->rows
;
12285 if (row
->mode_line_p
)
12289 /* Due to newlines in overlay strings, we may have to
12290 skip forward over overlay strings. */
12291 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12292 && MATRIX_ROW_END_CHARPOS (row
) == PT
12293 && !cursor_row_p (w
, row
))
12296 /* If within the scroll margin, scroll. */
12297 if (row
->y
< top_scroll_margin
12298 && CHARPOS (startp
) != BEGV
)
12303 /* Cursor did not move. So don't scroll even if cursor line
12304 is partially visible, as it was so before. */
12305 rc
= CURSOR_MOVEMENT_SUCCESS
;
12308 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
12309 || PT
> MATRIX_ROW_END_CHARPOS (row
))
12311 /* if PT is not in the glyph row, give up. */
12312 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12314 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
12315 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
12316 && make_cursor_line_fully_visible_p
)
12318 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
12319 && !row
->ends_at_zv_p
12320 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12321 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12322 else if (row
->height
> window_box_height (w
))
12324 /* If we end up in a partially visible line, let's
12325 make it fully visible, except when it's taller
12326 than the window, in which case we can't do much
12329 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12333 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12334 if (!cursor_row_fully_visible_p (w
, 0, 1))
12335 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12337 rc
= CURSOR_MOVEMENT_SUCCESS
;
12341 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12344 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12345 rc
= CURSOR_MOVEMENT_SUCCESS
;
12354 set_vertical_scroll_bar (w
)
12357 int start
, end
, whole
;
12359 /* Calculate the start and end positions for the current window.
12360 At some point, it would be nice to choose between scrollbars
12361 which reflect the whole buffer size, with special markers
12362 indicating narrowing, and scrollbars which reflect only the
12365 Note that mini-buffers sometimes aren't displaying any text. */
12366 if (!MINI_WINDOW_P (w
)
12367 || (w
== XWINDOW (minibuf_window
)
12368 && NILP (echo_area_buffer
[0])))
12370 struct buffer
*buf
= XBUFFER (w
->buffer
);
12371 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12372 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12373 /* I don't think this is guaranteed to be right. For the
12374 moment, we'll pretend it is. */
12375 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12379 if (whole
< (end
- start
))
12380 whole
= end
- start
;
12383 start
= end
= whole
= 0;
12385 /* Indicate what this scroll bar ought to be displaying now. */
12386 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
12390 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
12391 selected_window is redisplayed.
12393 We can return without actually redisplaying the window if
12394 fonts_changed_p is nonzero. In that case, redisplay_internal will
12398 redisplay_window (window
, just_this_one_p
)
12399 Lisp_Object window
;
12400 int just_this_one_p
;
12402 struct window
*w
= XWINDOW (window
);
12403 struct frame
*f
= XFRAME (w
->frame
);
12404 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12405 struct buffer
*old
= current_buffer
;
12406 struct text_pos lpoint
, opoint
, startp
;
12407 int update_mode_line
;
12410 /* Record it now because it's overwritten. */
12411 int current_matrix_up_to_date_p
= 0;
12412 int used_current_matrix_p
= 0;
12413 /* This is less strict than current_matrix_up_to_date_p.
12414 It indictes that the buffer contents and narrowing are unchanged. */
12415 int buffer_unchanged_p
= 0;
12416 int temp_scroll_step
= 0;
12417 int count
= SPECPDL_INDEX ();
12419 int centering_position
= -1;
12420 int last_line_misfit
= 0;
12422 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12425 /* W must be a leaf window here. */
12426 xassert (!NILP (w
->buffer
));
12428 *w
->desired_matrix
->method
= 0;
12431 specbind (Qinhibit_point_motion_hooks
, Qt
);
12433 reconsider_clip_changes (w
, buffer
);
12435 /* Has the mode line to be updated? */
12436 update_mode_line
= (!NILP (w
->update_mode_line
)
12437 || update_mode_lines
12438 || buffer
->clip_changed
12439 || buffer
->prevent_redisplay_optimizations_p
);
12441 if (MINI_WINDOW_P (w
))
12443 if (w
== XWINDOW (echo_area_window
)
12444 && !NILP (echo_area_buffer
[0]))
12446 if (update_mode_line
)
12447 /* We may have to update a tty frame's menu bar or a
12448 tool-bar. Example `M-x C-h C-h C-g'. */
12449 goto finish_menu_bars
;
12451 /* We've already displayed the echo area glyphs in this window. */
12452 goto finish_scroll_bars
;
12454 else if ((w
!= XWINDOW (minibuf_window
)
12455 || minibuf_level
== 0)
12456 /* When buffer is nonempty, redisplay window normally. */
12457 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12458 /* Quail displays non-mini buffers in minibuffer window.
12459 In that case, redisplay the window normally. */
12460 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12462 /* W is a mini-buffer window, but it's not active, so clear
12464 int yb
= window_text_bottom_y (w
);
12465 struct glyph_row
*row
;
12468 for (y
= 0, row
= w
->desired_matrix
->rows
;
12470 y
+= row
->height
, ++row
)
12471 blank_row (w
, row
, y
);
12472 goto finish_scroll_bars
;
12475 clear_glyph_matrix (w
->desired_matrix
);
12478 /* Otherwise set up data on this window; select its buffer and point
12480 /* Really select the buffer, for the sake of buffer-local
12482 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12483 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12485 current_matrix_up_to_date_p
12486 = (!NILP (w
->window_end_valid
)
12487 && !current_buffer
->clip_changed
12488 && !current_buffer
->prevent_redisplay_optimizations_p
12489 && XFASTINT (w
->last_modified
) >= MODIFF
12490 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12493 = (!NILP (w
->window_end_valid
)
12494 && !current_buffer
->clip_changed
12495 && XFASTINT (w
->last_modified
) >= MODIFF
12496 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12498 /* When windows_or_buffers_changed is non-zero, we can't rely on
12499 the window end being valid, so set it to nil there. */
12500 if (windows_or_buffers_changed
)
12502 /* If window starts on a continuation line, maybe adjust the
12503 window start in case the window's width changed. */
12504 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12505 compute_window_start_on_continuation_line (w
);
12507 w
->window_end_valid
= Qnil
;
12510 /* Some sanity checks. */
12511 CHECK_WINDOW_END (w
);
12512 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12514 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12517 /* If %c is in mode line, update it if needed. */
12518 if (!NILP (w
->column_number_displayed
)
12519 /* This alternative quickly identifies a common case
12520 where no change is needed. */
12521 && !(PT
== XFASTINT (w
->last_point
)
12522 && XFASTINT (w
->last_modified
) >= MODIFF
12523 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12524 && (XFASTINT (w
->column_number_displayed
)
12525 != (int) current_column ())) /* iftc */
12526 update_mode_line
= 1;
12528 /* Count number of windows showing the selected buffer. An indirect
12529 buffer counts as its base buffer. */
12530 if (!just_this_one_p
)
12532 struct buffer
*current_base
, *window_base
;
12533 current_base
= current_buffer
;
12534 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12535 if (current_base
->base_buffer
)
12536 current_base
= current_base
->base_buffer
;
12537 if (window_base
->base_buffer
)
12538 window_base
= window_base
->base_buffer
;
12539 if (current_base
== window_base
)
12543 /* Point refers normally to the selected window. For any other
12544 window, set up appropriate value. */
12545 if (!EQ (window
, selected_window
))
12547 int new_pt
= XMARKER (w
->pointm
)->charpos
;
12548 int new_pt_byte
= marker_byte_position (w
->pointm
);
12552 new_pt_byte
= BEGV_BYTE
;
12553 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
12555 else if (new_pt
> (ZV
- 1))
12558 new_pt_byte
= ZV_BYTE
;
12559 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
12562 /* We don't use SET_PT so that the point-motion hooks don't run. */
12563 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
12566 /* If any of the character widths specified in the display table
12567 have changed, invalidate the width run cache. It's true that
12568 this may be a bit late to catch such changes, but the rest of
12569 redisplay goes (non-fatally) haywire when the display table is
12570 changed, so why should we worry about doing any better? */
12571 if (current_buffer
->width_run_cache
)
12573 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
12575 if (! disptab_matches_widthtab (disptab
,
12576 XVECTOR (current_buffer
->width_table
)))
12578 invalidate_region_cache (current_buffer
,
12579 current_buffer
->width_run_cache
,
12581 recompute_width_table (current_buffer
, disptab
);
12585 /* If window-start is screwed up, choose a new one. */
12586 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12589 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12591 /* If someone specified a new starting point but did not insist,
12592 check whether it can be used. */
12593 if (!NILP (w
->optional_new_start
)
12594 && CHARPOS (startp
) >= BEGV
12595 && CHARPOS (startp
) <= ZV
)
12597 w
->optional_new_start
= Qnil
;
12598 start_display (&it
, w
, startp
);
12599 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12600 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12601 if (IT_CHARPOS (it
) == PT
)
12602 w
->force_start
= Qt
;
12603 /* IT may overshoot PT if text at PT is invisible. */
12604 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12605 w
->force_start
= Qt
;
12610 /* Handle case where place to start displaying has been specified,
12611 unless the specified location is outside the accessible range. */
12612 if (!NILP (w
->force_start
)
12613 || w
->frozen_window_start_p
)
12615 /* We set this later on if we have to adjust point. */
12619 w
->force_start
= Qnil
;
12621 w
->window_end_valid
= Qnil
;
12623 /* Forget any recorded base line for line number display. */
12624 if (!buffer_unchanged_p
)
12625 w
->base_line_number
= Qnil
;
12627 /* Redisplay the mode line. Select the buffer properly for that.
12628 Also, run the hook window-scroll-functions
12629 because we have scrolled. */
12630 /* Note, we do this after clearing force_start because
12631 if there's an error, it is better to forget about force_start
12632 than to get into an infinite loop calling the hook functions
12633 and having them get more errors. */
12634 if (!update_mode_line
12635 || ! NILP (Vwindow_scroll_functions
))
12637 update_mode_line
= 1;
12638 w
->update_mode_line
= Qt
;
12639 startp
= run_window_scroll_functions (window
, startp
);
12642 w
->last_modified
= make_number (0);
12643 w
->last_overlay_modified
= make_number (0);
12644 if (CHARPOS (startp
) < BEGV
)
12645 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
12646 else if (CHARPOS (startp
) > ZV
)
12647 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
12649 /* Redisplay, then check if cursor has been set during the
12650 redisplay. Give up if new fonts were loaded. */
12651 val
= try_window (window
, startp
, 1);
12654 w
->force_start
= Qt
;
12655 clear_glyph_matrix (w
->desired_matrix
);
12656 goto need_larger_matrices
;
12658 /* Point was outside the scroll margins. */
12660 new_vpos
= window_box_height (w
) / 2;
12662 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
12664 /* If point does not appear, try to move point so it does
12665 appear. The desired matrix has been built above, so we
12666 can use it here. */
12667 new_vpos
= window_box_height (w
) / 2;
12670 if (!cursor_row_fully_visible_p (w
, 0, 0))
12672 /* Point does appear, but on a line partly visible at end of window.
12673 Move it back to a fully-visible line. */
12674 new_vpos
= window_box_height (w
);
12677 /* If we need to move point for either of the above reasons,
12678 now actually do it. */
12681 struct glyph_row
*row
;
12683 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
12684 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
12687 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
12688 MATRIX_ROW_START_BYTEPOS (row
));
12690 if (w
!= XWINDOW (selected_window
))
12691 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
12692 else if (current_buffer
== old
)
12693 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12695 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
12697 /* If we are highlighting the region, then we just changed
12698 the region, so redisplay to show it. */
12699 if (!NILP (Vtransient_mark_mode
)
12700 && !NILP (current_buffer
->mark_active
))
12702 clear_glyph_matrix (w
->desired_matrix
);
12703 if (!try_window (window
, startp
, 0))
12704 goto need_larger_matrices
;
12709 debug_method_add (w
, "forced window start");
12714 /* Handle case where text has not changed, only point, and it has
12715 not moved off the frame, and we are not retrying after hscroll.
12716 (current_matrix_up_to_date_p is nonzero when retrying.) */
12717 if (current_matrix_up_to_date_p
12718 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
12719 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
12723 case CURSOR_MOVEMENT_SUCCESS
:
12724 used_current_matrix_p
= 1;
12727 #if 0 /* try_cursor_movement never returns this value. */
12728 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
12729 goto need_larger_matrices
;
12732 case CURSOR_MOVEMENT_MUST_SCROLL
:
12733 goto try_to_scroll
;
12739 /* If current starting point was originally the beginning of a line
12740 but no longer is, find a new starting point. */
12741 else if (!NILP (w
->start_at_line_beg
)
12742 && !(CHARPOS (startp
) <= BEGV
12743 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
12746 debug_method_add (w
, "recenter 1");
12751 /* Try scrolling with try_window_id. Value is > 0 if update has
12752 been done, it is -1 if we know that the same window start will
12753 not work. It is 0 if unsuccessful for some other reason. */
12754 else if ((tem
= try_window_id (w
)) != 0)
12757 debug_method_add (w
, "try_window_id %d", tem
);
12760 if (fonts_changed_p
)
12761 goto need_larger_matrices
;
12765 /* Otherwise try_window_id has returned -1 which means that we
12766 don't want the alternative below this comment to execute. */
12768 else if (CHARPOS (startp
) >= BEGV
12769 && CHARPOS (startp
) <= ZV
12770 && PT
>= CHARPOS (startp
)
12771 && (CHARPOS (startp
) < ZV
12772 /* Avoid starting at end of buffer. */
12773 || CHARPOS (startp
) == BEGV
12774 || (XFASTINT (w
->last_modified
) >= MODIFF
12775 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
12778 debug_method_add (w
, "same window start");
12781 /* Try to redisplay starting at same place as before.
12782 If point has not moved off frame, accept the results. */
12783 if (!current_matrix_up_to_date_p
12784 /* Don't use try_window_reusing_current_matrix in this case
12785 because a window scroll function can have changed the
12787 || !NILP (Vwindow_scroll_functions
)
12788 || MINI_WINDOW_P (w
)
12789 || !(used_current_matrix_p
12790 = try_window_reusing_current_matrix (w
)))
12792 IF_DEBUG (debug_method_add (w
, "1"));
12793 if (try_window (window
, startp
, 1) < 0)
12794 /* -1 means we need to scroll.
12795 0 means we need new matrices, but fonts_changed_p
12796 is set in that case, so we will detect it below. */
12797 goto try_to_scroll
;
12800 if (fonts_changed_p
)
12801 goto need_larger_matrices
;
12803 if (w
->cursor
.vpos
>= 0)
12805 if (!just_this_one_p
12806 || current_buffer
->clip_changed
12807 || BEG_UNCHANGED
< CHARPOS (startp
))
12808 /* Forget any recorded base line for line number display. */
12809 w
->base_line_number
= Qnil
;
12811 if (!cursor_row_fully_visible_p (w
, 1, 0))
12813 clear_glyph_matrix (w
->desired_matrix
);
12814 last_line_misfit
= 1;
12816 /* Drop through and scroll. */
12821 clear_glyph_matrix (w
->desired_matrix
);
12826 w
->last_modified
= make_number (0);
12827 w
->last_overlay_modified
= make_number (0);
12829 /* Redisplay the mode line. Select the buffer properly for that. */
12830 if (!update_mode_line
)
12832 update_mode_line
= 1;
12833 w
->update_mode_line
= Qt
;
12836 /* Try to scroll by specified few lines. */
12837 if ((scroll_conservatively
12839 || temp_scroll_step
12840 || NUMBERP (current_buffer
->scroll_up_aggressively
)
12841 || NUMBERP (current_buffer
->scroll_down_aggressively
))
12842 && !current_buffer
->clip_changed
12843 && CHARPOS (startp
) >= BEGV
12844 && CHARPOS (startp
) <= ZV
)
12846 /* The function returns -1 if new fonts were loaded, 1 if
12847 successful, 0 if not successful. */
12848 int rc
= try_scrolling (window
, just_this_one_p
,
12849 scroll_conservatively
,
12851 temp_scroll_step
, last_line_misfit
);
12854 case SCROLLING_SUCCESS
:
12857 case SCROLLING_NEED_LARGER_MATRICES
:
12858 goto need_larger_matrices
;
12860 case SCROLLING_FAILED
:
12868 /* Finally, just choose place to start which centers point */
12871 if (centering_position
< 0)
12872 centering_position
= window_box_height (w
) / 2;
12875 debug_method_add (w
, "recenter");
12878 /* w->vscroll = 0; */
12880 /* Forget any previously recorded base line for line number display. */
12881 if (!buffer_unchanged_p
)
12882 w
->base_line_number
= Qnil
;
12884 /* Move backward half the height of the window. */
12885 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12886 it
.current_y
= it
.last_visible_y
;
12887 move_it_vertically_backward (&it
, centering_position
);
12888 xassert (IT_CHARPOS (it
) >= BEGV
);
12890 /* The function move_it_vertically_backward may move over more
12891 than the specified y-distance. If it->w is small, e.g. a
12892 mini-buffer window, we may end up in front of the window's
12893 display area. Start displaying at the start of the line
12894 containing PT in this case. */
12895 if (it
.current_y
<= 0)
12897 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12898 move_it_vertically_backward (&it
, 0);
12900 /* I think this assert is bogus if buffer contains
12901 invisible text or images. KFS. */
12902 xassert (IT_CHARPOS (it
) <= PT
);
12907 it
.current_x
= it
.hpos
= 0;
12909 /* Set startp here explicitly in case that helps avoid an infinite loop
12910 in case the window-scroll-functions functions get errors. */
12911 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
12913 /* Run scroll hooks. */
12914 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
12916 /* Redisplay the window. */
12917 if (!current_matrix_up_to_date_p
12918 || windows_or_buffers_changed
12919 || cursor_type_changed
12920 /* Don't use try_window_reusing_current_matrix in this case
12921 because it can have changed the buffer. */
12922 || !NILP (Vwindow_scroll_functions
)
12923 || !just_this_one_p
12924 || MINI_WINDOW_P (w
)
12925 || !(used_current_matrix_p
12926 = try_window_reusing_current_matrix (w
)))
12927 try_window (window
, startp
, 0);
12929 /* If new fonts have been loaded (due to fontsets), give up. We
12930 have to start a new redisplay since we need to re-adjust glyph
12932 if (fonts_changed_p
)
12933 goto need_larger_matrices
;
12935 /* If cursor did not appear assume that the middle of the window is
12936 in the first line of the window. Do it again with the next line.
12937 (Imagine a window of height 100, displaying two lines of height
12938 60. Moving back 50 from it->last_visible_y will end in the first
12940 if (w
->cursor
.vpos
< 0)
12942 if (!NILP (w
->window_end_valid
)
12943 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
12945 clear_glyph_matrix (w
->desired_matrix
);
12946 move_it_by_lines (&it
, 1, 0);
12947 try_window (window
, it
.current
.pos
, 0);
12949 else if (PT
< IT_CHARPOS (it
))
12951 clear_glyph_matrix (w
->desired_matrix
);
12952 move_it_by_lines (&it
, -1, 0);
12953 try_window (window
, it
.current
.pos
, 0);
12957 /* Not much we can do about it. */
12961 /* Consider the following case: Window starts at BEGV, there is
12962 invisible, intangible text at BEGV, so that display starts at
12963 some point START > BEGV. It can happen that we are called with
12964 PT somewhere between BEGV and START. Try to handle that case. */
12965 if (w
->cursor
.vpos
< 0)
12967 struct glyph_row
*row
= w
->current_matrix
->rows
;
12968 if (row
->mode_line_p
)
12970 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12973 if (!cursor_row_fully_visible_p (w
, 0, 0))
12975 /* If vscroll is enabled, disable it and try again. */
12979 clear_glyph_matrix (w
->desired_matrix
);
12983 /* If centering point failed to make the whole line visible,
12984 put point at the top instead. That has to make the whole line
12985 visible, if it can be done. */
12986 if (centering_position
== 0)
12989 clear_glyph_matrix (w
->desired_matrix
);
12990 centering_position
= 0;
12996 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12997 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
12998 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13001 /* Display the mode line, if we must. */
13002 if ((update_mode_line
13003 /* If window not full width, must redo its mode line
13004 if (a) the window to its side is being redone and
13005 (b) we do a frame-based redisplay. This is a consequence
13006 of how inverted lines are drawn in frame-based redisplay. */
13007 || (!just_this_one_p
13008 && !FRAME_WINDOW_P (f
)
13009 && !WINDOW_FULL_WIDTH_P (w
))
13010 /* Line number to display. */
13011 || INTEGERP (w
->base_line_pos
)
13012 /* Column number is displayed and different from the one displayed. */
13013 || (!NILP (w
->column_number_displayed
)
13014 && (XFASTINT (w
->column_number_displayed
)
13015 != (int) current_column ()))) /* iftc */
13016 /* This means that the window has a mode line. */
13017 && (WINDOW_WANTS_MODELINE_P (w
)
13018 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13020 display_mode_lines (w
);
13022 /* If mode line height has changed, arrange for a thorough
13023 immediate redisplay using the correct mode line height. */
13024 if (WINDOW_WANTS_MODELINE_P (w
)
13025 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13027 fonts_changed_p
= 1;
13028 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13029 = DESIRED_MODE_LINE_HEIGHT (w
);
13032 /* If top line height has changed, arrange for a thorough
13033 immediate redisplay using the correct mode line height. */
13034 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13035 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13037 fonts_changed_p
= 1;
13038 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13039 = DESIRED_HEADER_LINE_HEIGHT (w
);
13042 if (fonts_changed_p
)
13043 goto need_larger_matrices
;
13046 if (!line_number_displayed
13047 && !BUFFERP (w
->base_line_pos
))
13049 w
->base_line_pos
= Qnil
;
13050 w
->base_line_number
= Qnil
;
13055 /* When we reach a frame's selected window, redo the frame's menu bar. */
13056 if (update_mode_line
13057 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13059 int redisplay_menu_p
= 0;
13060 int redisplay_tool_bar_p
= 0;
13062 if (FRAME_WINDOW_P (f
))
13064 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
13065 || defined (USE_GTK)
13066 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13068 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13072 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13074 if (redisplay_menu_p
)
13075 display_menu_bar (w
);
13077 #ifdef HAVE_WINDOW_SYSTEM
13079 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13081 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13082 && (FRAME_TOOL_BAR_LINES (f
) > 0
13083 || auto_resize_tool_bars_p
);
13087 if (redisplay_tool_bar_p
)
13088 redisplay_tool_bar (f
);
13092 #ifdef HAVE_WINDOW_SYSTEM
13093 if (FRAME_WINDOW_P (f
)
13094 && update_window_fringes (w
, (just_this_one_p
13095 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13096 || w
->pseudo_window_p
)))
13100 if (draw_window_fringes (w
, 1))
13101 x_draw_vertical_border (w
);
13105 #endif /* HAVE_WINDOW_SYSTEM */
13107 /* We go to this label, with fonts_changed_p nonzero,
13108 if it is necessary to try again using larger glyph matrices.
13109 We have to redeem the scroll bar even in this case,
13110 because the loop in redisplay_internal expects that. */
13111 need_larger_matrices
:
13113 finish_scroll_bars
:
13115 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13117 /* Set the thumb's position and size. */
13118 set_vertical_scroll_bar (w
);
13120 /* Note that we actually used the scroll bar attached to this
13121 window, so it shouldn't be deleted at the end of redisplay. */
13122 redeem_scroll_bar_hook (w
);
13125 /* Restore current_buffer and value of point in it. */
13126 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13127 set_buffer_internal_1 (old
);
13128 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13130 unbind_to (count
, Qnil
);
13134 /* Build the complete desired matrix of WINDOW with a window start
13135 buffer position POS.
13137 Value is 1 if successful. It is zero if fonts were loaded during
13138 redisplay which makes re-adjusting glyph matrices necessary, and -1
13139 if point would appear in the scroll margins.
13140 (We check that only if CHECK_MARGINS is nonzero. */
13143 try_window (window
, pos
, check_margins
)
13144 Lisp_Object window
;
13145 struct text_pos pos
;
13148 struct window
*w
= XWINDOW (window
);
13150 struct glyph_row
*last_text_row
= NULL
;
13152 /* Make POS the new window start. */
13153 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13155 /* Mark cursor position as unknown. No overlay arrow seen. */
13156 w
->cursor
.vpos
= -1;
13157 overlay_arrow_seen
= 0;
13159 /* Initialize iterator and info to start at POS. */
13160 start_display (&it
, w
, pos
);
13162 /* Display all lines of W. */
13163 while (it
.current_y
< it
.last_visible_y
)
13165 if (display_line (&it
))
13166 last_text_row
= it
.glyph_row
- 1;
13167 if (fonts_changed_p
)
13171 /* Don't let the cursor end in the scroll margins. */
13173 && !MINI_WINDOW_P (w
))
13175 int this_scroll_margin
;
13177 this_scroll_margin
= max (0, scroll_margin
);
13178 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13179 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13181 if ((w
->cursor
.y
< this_scroll_margin
13182 && CHARPOS (pos
) > BEGV
13183 && IT_CHARPOS (it
) < ZV
)
13184 /* rms: considering make_cursor_line_fully_visible_p here
13185 seems to give wrong results. We don't want to recenter
13186 when the last line is partly visible, we want to allow
13187 that case to be handled in the usual way. */
13188 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
13190 w
->cursor
.vpos
= -1;
13191 clear_glyph_matrix (w
->desired_matrix
);
13196 /* If bottom moved off end of frame, change mode line percentage. */
13197 if (XFASTINT (w
->window_end_pos
) <= 0
13198 && Z
!= IT_CHARPOS (it
))
13199 w
->update_mode_line
= Qt
;
13201 /* Set window_end_pos to the offset of the last character displayed
13202 on the window from the end of current_buffer. Set
13203 window_end_vpos to its row number. */
13206 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
13207 w
->window_end_bytepos
13208 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13210 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13212 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13213 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
13214 ->displays_text_p
);
13218 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13219 w
->window_end_pos
= make_number (Z
- ZV
);
13220 w
->window_end_vpos
= make_number (0);
13223 /* But that is not valid info until redisplay finishes. */
13224 w
->window_end_valid
= Qnil
;
13230 /************************************************************************
13231 Window redisplay reusing current matrix when buffer has not changed
13232 ************************************************************************/
13234 /* Try redisplay of window W showing an unchanged buffer with a
13235 different window start than the last time it was displayed by
13236 reusing its current matrix. Value is non-zero if successful.
13237 W->start is the new window start. */
13240 try_window_reusing_current_matrix (w
)
13243 struct frame
*f
= XFRAME (w
->frame
);
13244 struct glyph_row
*row
, *bottom_row
;
13247 struct text_pos start
, new_start
;
13248 int nrows_scrolled
, i
;
13249 struct glyph_row
*last_text_row
;
13250 struct glyph_row
*last_reused_text_row
;
13251 struct glyph_row
*start_row
;
13252 int start_vpos
, min_y
, max_y
;
13255 if (inhibit_try_window_reusing
)
13259 if (/* This function doesn't handle terminal frames. */
13260 !FRAME_WINDOW_P (f
)
13261 /* Don't try to reuse the display if windows have been split
13263 || windows_or_buffers_changed
13264 || cursor_type_changed
)
13267 /* Can't do this if region may have changed. */
13268 if ((!NILP (Vtransient_mark_mode
)
13269 && !NILP (current_buffer
->mark_active
))
13270 || !NILP (w
->region_showing
)
13271 || !NILP (Vshow_trailing_whitespace
))
13274 /* If top-line visibility has changed, give up. */
13275 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13276 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
13279 /* Give up if old or new display is scrolled vertically. We could
13280 make this function handle this, but right now it doesn't. */
13281 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13282 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
13285 /* The variable new_start now holds the new window start. The old
13286 start `start' can be determined from the current matrix. */
13287 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
13288 start
= start_row
->start
.pos
;
13289 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13291 /* Clear the desired matrix for the display below. */
13292 clear_glyph_matrix (w
->desired_matrix
);
13294 if (CHARPOS (new_start
) <= CHARPOS (start
))
13298 /* Don't use this method if the display starts with an ellipsis
13299 displayed for invisible text. It's not easy to handle that case
13300 below, and it's certainly not worth the effort since this is
13301 not a frequent case. */
13302 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
13305 IF_DEBUG (debug_method_add (w
, "twu1"));
13307 /* Display up to a row that can be reused. The variable
13308 last_text_row is set to the last row displayed that displays
13309 text. Note that it.vpos == 0 if or if not there is a
13310 header-line; it's not the same as the MATRIX_ROW_VPOS! */
13311 start_display (&it
, w
, new_start
);
13312 first_row_y
= it
.current_y
;
13313 w
->cursor
.vpos
= -1;
13314 last_text_row
= last_reused_text_row
= NULL
;
13316 while (it
.current_y
< it
.last_visible_y
13317 && !fonts_changed_p
)
13319 /* If we have reached into the characters in the START row,
13320 that means the line boundaries have changed. So we
13321 can't start copying with the row START. Maybe it will
13322 work to start copying with the following row. */
13323 while (IT_CHARPOS (it
) > CHARPOS (start
))
13325 /* Advance to the next row as the "start". */
13327 start
= start_row
->start
.pos
;
13328 /* If there are no more rows to try, or just one, give up. */
13329 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
13330 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
13331 || CHARPOS (start
) == ZV
)
13333 clear_glyph_matrix (w
->desired_matrix
);
13337 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13339 /* If we have reached alignment,
13340 we can copy the rest of the rows. */
13341 if (IT_CHARPOS (it
) == CHARPOS (start
))
13344 if (display_line (&it
))
13345 last_text_row
= it
.glyph_row
- 1;
13348 /* A value of current_y < last_visible_y means that we stopped
13349 at the previous window start, which in turn means that we
13350 have at least one reusable row. */
13351 if (it
.current_y
< it
.last_visible_y
)
13353 /* IT.vpos always starts from 0; it counts text lines. */
13354 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
13356 /* Find PT if not already found in the lines displayed. */
13357 if (w
->cursor
.vpos
< 0)
13359 int dy
= it
.current_y
- start_row
->y
;
13361 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13362 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
13364 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
13365 dy
, nrows_scrolled
);
13368 clear_glyph_matrix (w
->desired_matrix
);
13373 /* Scroll the display. Do it before the current matrix is
13374 changed. The problem here is that update has not yet
13375 run, i.e. part of the current matrix is not up to date.
13376 scroll_run_hook will clear the cursor, and use the
13377 current matrix to get the height of the row the cursor is
13379 run
.current_y
= start_row
->y
;
13380 run
.desired_y
= it
.current_y
;
13381 run
.height
= it
.last_visible_y
- it
.current_y
;
13383 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
13386 rif
->update_window_begin_hook (w
);
13387 rif
->clear_window_mouse_face (w
);
13388 rif
->scroll_run_hook (w
, &run
);
13389 rif
->update_window_end_hook (w
, 0, 0);
13393 /* Shift current matrix down by nrows_scrolled lines. */
13394 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13395 rotate_matrix (w
->current_matrix
,
13397 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13400 /* Disable lines that must be updated. */
13401 for (i
= 0; i
< it
.vpos
; ++i
)
13402 (start_row
+ i
)->enabled_p
= 0;
13404 /* Re-compute Y positions. */
13405 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13406 max_y
= it
.last_visible_y
;
13407 for (row
= start_row
+ nrows_scrolled
;
13411 row
->y
= it
.current_y
;
13412 row
->visible_height
= row
->height
;
13414 if (row
->y
< min_y
)
13415 row
->visible_height
-= min_y
- row
->y
;
13416 if (row
->y
+ row
->height
> max_y
)
13417 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13418 row
->redraw_fringe_bitmaps_p
= 1;
13420 it
.current_y
+= row
->height
;
13422 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13423 last_reused_text_row
= row
;
13424 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13428 /* Disable lines in the current matrix which are now
13429 below the window. */
13430 for (++row
; row
< bottom_row
; ++row
)
13431 row
->enabled_p
= row
->mode_line_p
= 0;
13434 /* Update window_end_pos etc.; last_reused_text_row is the last
13435 reused row from the current matrix containing text, if any.
13436 The value of last_text_row is the last displayed line
13437 containing text. */
13438 if (last_reused_text_row
)
13440 w
->window_end_bytepos
13441 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13443 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13445 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13446 w
->current_matrix
));
13448 else if (last_text_row
)
13450 w
->window_end_bytepos
13451 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13453 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13455 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13459 /* This window must be completely empty. */
13460 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13461 w
->window_end_pos
= make_number (Z
- ZV
);
13462 w
->window_end_vpos
= make_number (0);
13464 w
->window_end_valid
= Qnil
;
13466 /* Update hint: don't try scrolling again in update_window. */
13467 w
->desired_matrix
->no_scrolling_p
= 1;
13470 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13474 else if (CHARPOS (new_start
) > CHARPOS (start
))
13476 struct glyph_row
*pt_row
, *row
;
13477 struct glyph_row
*first_reusable_row
;
13478 struct glyph_row
*first_row_to_display
;
13480 int yb
= window_text_bottom_y (w
);
13482 /* Find the row starting at new_start, if there is one. Don't
13483 reuse a partially visible line at the end. */
13484 first_reusable_row
= start_row
;
13485 while (first_reusable_row
->enabled_p
13486 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13487 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13488 < CHARPOS (new_start
)))
13489 ++first_reusable_row
;
13491 /* Give up if there is no row to reuse. */
13492 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13493 || !first_reusable_row
->enabled_p
13494 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13495 != CHARPOS (new_start
)))
13498 /* We can reuse fully visible rows beginning with
13499 first_reusable_row to the end of the window. Set
13500 first_row_to_display to the first row that cannot be reused.
13501 Set pt_row to the row containing point, if there is any. */
13503 for (first_row_to_display
= first_reusable_row
;
13504 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13505 ++first_row_to_display
)
13507 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
13508 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
13509 pt_row
= first_row_to_display
;
13512 /* Start displaying at the start of first_row_to_display. */
13513 xassert (first_row_to_display
->y
< yb
);
13514 init_to_row_start (&it
, w
, first_row_to_display
);
13516 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
13518 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
13520 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
13521 + WINDOW_HEADER_LINE_HEIGHT (w
));
13523 /* Display lines beginning with first_row_to_display in the
13524 desired matrix. Set last_text_row to the last row displayed
13525 that displays text. */
13526 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
13527 if (pt_row
== NULL
)
13528 w
->cursor
.vpos
= -1;
13529 last_text_row
= NULL
;
13530 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
13531 if (display_line (&it
))
13532 last_text_row
= it
.glyph_row
- 1;
13534 /* Give up If point isn't in a row displayed or reused. */
13535 if (w
->cursor
.vpos
< 0)
13537 clear_glyph_matrix (w
->desired_matrix
);
13541 /* If point is in a reused row, adjust y and vpos of the cursor
13545 w
->cursor
.vpos
-= nrows_scrolled
;
13546 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
13549 /* Scroll the display. */
13550 run
.current_y
= first_reusable_row
->y
;
13551 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13552 run
.height
= it
.last_visible_y
- run
.current_y
;
13553 dy
= run
.current_y
- run
.desired_y
;
13558 rif
->update_window_begin_hook (w
);
13559 rif
->clear_window_mouse_face (w
);
13560 rif
->scroll_run_hook (w
, &run
);
13561 rif
->update_window_end_hook (w
, 0, 0);
13565 /* Adjust Y positions of reused rows. */
13566 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13567 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13568 max_y
= it
.last_visible_y
;
13569 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
13572 row
->visible_height
= row
->height
;
13573 if (row
->y
< min_y
)
13574 row
->visible_height
-= min_y
- row
->y
;
13575 if (row
->y
+ row
->height
> max_y
)
13576 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13577 row
->redraw_fringe_bitmaps_p
= 1;
13580 /* Scroll the current matrix. */
13581 xassert (nrows_scrolled
> 0);
13582 rotate_matrix (w
->current_matrix
,
13584 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13587 /* Disable rows not reused. */
13588 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
13589 row
->enabled_p
= 0;
13591 /* Point may have moved to a different line, so we cannot assume that
13592 the previous cursor position is valid; locate the correct row. */
13595 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
13596 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
13600 w
->cursor
.y
= row
->y
;
13602 if (row
< bottom_row
)
13604 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
13605 while (glyph
->charpos
< PT
)
13608 w
->cursor
.x
+= glyph
->pixel_width
;
13614 /* Adjust window end. A null value of last_text_row means that
13615 the window end is in reused rows which in turn means that
13616 only its vpos can have changed. */
13619 w
->window_end_bytepos
13620 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13622 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13624 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13629 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
13632 w
->window_end_valid
= Qnil
;
13633 w
->desired_matrix
->no_scrolling_p
= 1;
13636 debug_method_add (w
, "try_window_reusing_current_matrix 2");
13646 /************************************************************************
13647 Window redisplay reusing current matrix when buffer has changed
13648 ************************************************************************/
13650 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
13651 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
13653 static struct glyph_row
*
13654 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
13655 struct glyph_row
*));
13658 /* Return the last row in MATRIX displaying text. If row START is
13659 non-null, start searching with that row. IT gives the dimensions
13660 of the display. Value is null if matrix is empty; otherwise it is
13661 a pointer to the row found. */
13663 static struct glyph_row
*
13664 find_last_row_displaying_text (matrix
, it
, start
)
13665 struct glyph_matrix
*matrix
;
13667 struct glyph_row
*start
;
13669 struct glyph_row
*row
, *row_found
;
13671 /* Set row_found to the last row in IT->w's current matrix
13672 displaying text. The loop looks funny but think of partially
13675 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
13676 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13678 xassert (row
->enabled_p
);
13680 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
13689 /* Return the last row in the current matrix of W that is not affected
13690 by changes at the start of current_buffer that occurred since W's
13691 current matrix was built. Value is null if no such row exists.
13693 BEG_UNCHANGED us the number of characters unchanged at the start of
13694 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
13695 first changed character in current_buffer. Characters at positions <
13696 BEG + BEG_UNCHANGED are at the same buffer positions as they were
13697 when the current matrix was built. */
13699 static struct glyph_row
*
13700 find_last_unchanged_at_beg_row (w
)
13703 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
13704 struct glyph_row
*row
;
13705 struct glyph_row
*row_found
= NULL
;
13706 int yb
= window_text_bottom_y (w
);
13708 /* Find the last row displaying unchanged text. */
13709 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13710 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13711 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
13713 if (/* If row ends before first_changed_pos, it is unchanged,
13714 except in some case. */
13715 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
13716 /* When row ends in ZV and we write at ZV it is not
13718 && !row
->ends_at_zv_p
13719 /* When first_changed_pos is the end of a continued line,
13720 row is not unchanged because it may be no longer
13722 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
13723 && (row
->continued_p
13724 || row
->exact_window_width_line_p
)))
13727 /* Stop if last visible row. */
13728 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
13738 /* Find the first glyph row in the current matrix of W that is not
13739 affected by changes at the end of current_buffer since the
13740 time W's current matrix was built.
13742 Return in *DELTA the number of chars by which buffer positions in
13743 unchanged text at the end of current_buffer must be adjusted.
13745 Return in *DELTA_BYTES the corresponding number of bytes.
13747 Value is null if no such row exists, i.e. all rows are affected by
13750 static struct glyph_row
*
13751 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
13753 int *delta
, *delta_bytes
;
13755 struct glyph_row
*row
;
13756 struct glyph_row
*row_found
= NULL
;
13758 *delta
= *delta_bytes
= 0;
13760 /* Display must not have been paused, otherwise the current matrix
13761 is not up to date. */
13762 if (NILP (w
->window_end_valid
))
13765 /* A value of window_end_pos >= END_UNCHANGED means that the window
13766 end is in the range of changed text. If so, there is no
13767 unchanged row at the end of W's current matrix. */
13768 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
13771 /* Set row to the last row in W's current matrix displaying text. */
13772 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13774 /* If matrix is entirely empty, no unchanged row exists. */
13775 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13777 /* The value of row is the last glyph row in the matrix having a
13778 meaningful buffer position in it. The end position of row
13779 corresponds to window_end_pos. This allows us to translate
13780 buffer positions in the current matrix to current buffer
13781 positions for characters not in changed text. */
13782 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13783 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13784 int last_unchanged_pos
, last_unchanged_pos_old
;
13785 struct glyph_row
*first_text_row
13786 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13788 *delta
= Z
- Z_old
;
13789 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13791 /* Set last_unchanged_pos to the buffer position of the last
13792 character in the buffer that has not been changed. Z is the
13793 index + 1 of the last character in current_buffer, i.e. by
13794 subtracting END_UNCHANGED we get the index of the last
13795 unchanged character, and we have to add BEG to get its buffer
13797 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
13798 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
13800 /* Search backward from ROW for a row displaying a line that
13801 starts at a minimum position >= last_unchanged_pos_old. */
13802 for (; row
> first_text_row
; --row
)
13804 /* This used to abort, but it can happen.
13805 It is ok to just stop the search instead here. KFS. */
13806 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13809 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
13814 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
13821 /* Make sure that glyph rows in the current matrix of window W
13822 reference the same glyph memory as corresponding rows in the
13823 frame's frame matrix. This function is called after scrolling W's
13824 current matrix on a terminal frame in try_window_id and
13825 try_window_reusing_current_matrix. */
13828 sync_frame_with_window_matrix_rows (w
)
13831 struct frame
*f
= XFRAME (w
->frame
);
13832 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
13834 /* Preconditions: W must be a leaf window and full-width. Its frame
13835 must have a frame matrix. */
13836 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
13837 xassert (WINDOW_FULL_WIDTH_P (w
));
13838 xassert (!FRAME_WINDOW_P (f
));
13840 /* If W is a full-width window, glyph pointers in W's current matrix
13841 have, by definition, to be the same as glyph pointers in the
13842 corresponding frame matrix. Note that frame matrices have no
13843 marginal areas (see build_frame_matrix). */
13844 window_row
= w
->current_matrix
->rows
;
13845 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
13846 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
13847 while (window_row
< window_row_end
)
13849 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
13850 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
13852 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
13853 frame_row
->glyphs
[TEXT_AREA
] = start
;
13854 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
13855 frame_row
->glyphs
[LAST_AREA
] = end
;
13857 /* Disable frame rows whose corresponding window rows have
13858 been disabled in try_window_id. */
13859 if (!window_row
->enabled_p
)
13860 frame_row
->enabled_p
= 0;
13862 ++window_row
, ++frame_row
;
13867 /* Find the glyph row in window W containing CHARPOS. Consider all
13868 rows between START and END (not inclusive). END null means search
13869 all rows to the end of the display area of W. Value is the row
13870 containing CHARPOS or null. */
13873 row_containing_pos (w
, charpos
, start
, end
, dy
)
13876 struct glyph_row
*start
, *end
;
13879 struct glyph_row
*row
= start
;
13882 /* If we happen to start on a header-line, skip that. */
13883 if (row
->mode_line_p
)
13886 if ((end
&& row
>= end
) || !row
->enabled_p
)
13889 last_y
= window_text_bottom_y (w
) - dy
;
13893 /* Give up if we have gone too far. */
13894 if (end
&& row
>= end
)
13896 /* This formerly returned if they were equal.
13897 I think that both quantities are of a "last plus one" type;
13898 if so, when they are equal, the row is within the screen. -- rms. */
13899 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
13902 /* If it is in this row, return this row. */
13903 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
13904 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
13905 /* The end position of a row equals the start
13906 position of the next row. If CHARPOS is there, we
13907 would rather display it in the next line, except
13908 when this line ends in ZV. */
13909 && !row
->ends_at_zv_p
13910 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13911 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
13918 /* Try to redisplay window W by reusing its existing display. W's
13919 current matrix must be up to date when this function is called,
13920 i.e. window_end_valid must not be nil.
13924 1 if display has been updated
13925 0 if otherwise unsuccessful
13926 -1 if redisplay with same window start is known not to succeed
13928 The following steps are performed:
13930 1. Find the last row in the current matrix of W that is not
13931 affected by changes at the start of current_buffer. If no such row
13934 2. Find the first row in W's current matrix that is not affected by
13935 changes at the end of current_buffer. Maybe there is no such row.
13937 3. Display lines beginning with the row + 1 found in step 1 to the
13938 row found in step 2 or, if step 2 didn't find a row, to the end of
13941 4. If cursor is not known to appear on the window, give up.
13943 5. If display stopped at the row found in step 2, scroll the
13944 display and current matrix as needed.
13946 6. Maybe display some lines at the end of W, if we must. This can
13947 happen under various circumstances, like a partially visible line
13948 becoming fully visible, or because newly displayed lines are displayed
13949 in smaller font sizes.
13951 7. Update W's window end information. */
13957 struct frame
*f
= XFRAME (w
->frame
);
13958 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
13959 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
13960 struct glyph_row
*last_unchanged_at_beg_row
;
13961 struct glyph_row
*first_unchanged_at_end_row
;
13962 struct glyph_row
*row
;
13963 struct glyph_row
*bottom_row
;
13966 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
13967 struct text_pos start_pos
;
13969 int first_unchanged_at_end_vpos
= 0;
13970 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
13971 struct text_pos start
;
13972 int first_changed_charpos
, last_changed_charpos
;
13975 if (inhibit_try_window_id
)
13979 /* This is handy for debugging. */
13981 #define GIVE_UP(X) \
13983 fprintf (stderr, "try_window_id give up %d\n", (X)); \
13987 #define GIVE_UP(X) return 0
13990 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
13992 /* Don't use this for mini-windows because these can show
13993 messages and mini-buffers, and we don't handle that here. */
13994 if (MINI_WINDOW_P (w
))
13997 /* This flag is used to prevent redisplay optimizations. */
13998 if (windows_or_buffers_changed
|| cursor_type_changed
)
14001 /* Verify that narrowing has not changed.
14002 Also verify that we were not told to prevent redisplay optimizations.
14003 It would be nice to further
14004 reduce the number of cases where this prevents try_window_id. */
14005 if (current_buffer
->clip_changed
14006 || current_buffer
->prevent_redisplay_optimizations_p
)
14009 /* Window must either use window-based redisplay or be full width. */
14010 if (!FRAME_WINDOW_P (f
)
14011 && (!line_ins_del_ok
14012 || !WINDOW_FULL_WIDTH_P (w
)))
14015 /* Give up if point is not known NOT to appear in W. */
14016 if (PT
< CHARPOS (start
))
14019 /* Another way to prevent redisplay optimizations. */
14020 if (XFASTINT (w
->last_modified
) == 0)
14023 /* Verify that window is not hscrolled. */
14024 if (XFASTINT (w
->hscroll
) != 0)
14027 /* Verify that display wasn't paused. */
14028 if (NILP (w
->window_end_valid
))
14031 /* Can't use this if highlighting a region because a cursor movement
14032 will do more than just set the cursor. */
14033 if (!NILP (Vtransient_mark_mode
)
14034 && !NILP (current_buffer
->mark_active
))
14037 /* Likewise if highlighting trailing whitespace. */
14038 if (!NILP (Vshow_trailing_whitespace
))
14041 /* Likewise if showing a region. */
14042 if (!NILP (w
->region_showing
))
14045 /* Can use this if overlay arrow position and or string have changed. */
14046 if (overlay_arrows_changed_p ())
14050 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14051 only if buffer has really changed. The reason is that the gap is
14052 initially at Z for freshly visited files. The code below would
14053 set end_unchanged to 0 in that case. */
14054 if (MODIFF
> SAVE_MODIFF
14055 /* This seems to happen sometimes after saving a buffer. */
14056 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14058 if (GPT
- BEG
< BEG_UNCHANGED
)
14059 BEG_UNCHANGED
= GPT
- BEG
;
14060 if (Z
- GPT
< END_UNCHANGED
)
14061 END_UNCHANGED
= Z
- GPT
;
14064 /* The position of the first and last character that has been changed. */
14065 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14066 last_changed_charpos
= Z
- END_UNCHANGED
;
14068 /* If window starts after a line end, and the last change is in
14069 front of that newline, then changes don't affect the display.
14070 This case happens with stealth-fontification. Note that although
14071 the display is unchanged, glyph positions in the matrix have to
14072 be adjusted, of course. */
14073 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14074 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14075 && ((last_changed_charpos
< CHARPOS (start
)
14076 && CHARPOS (start
) == BEGV
)
14077 || (last_changed_charpos
< CHARPOS (start
) - 1
14078 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14080 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14081 struct glyph_row
*r0
;
14083 /* Compute how many chars/bytes have been added to or removed
14084 from the buffer. */
14085 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14086 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14088 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14090 /* Give up if PT is not in the window. Note that it already has
14091 been checked at the start of try_window_id that PT is not in
14092 front of the window start. */
14093 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14096 /* If window start is unchanged, we can reuse the whole matrix
14097 as is, after adjusting glyph positions. No need to compute
14098 the window end again, since its offset from Z hasn't changed. */
14099 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14100 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14101 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14102 /* PT must not be in a partially visible line. */
14103 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14104 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14106 /* Adjust positions in the glyph matrix. */
14107 if (delta
|| delta_bytes
)
14109 struct glyph_row
*r1
14110 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14111 increment_matrix_positions (w
->current_matrix
,
14112 MATRIX_ROW_VPOS (r0
, current_matrix
),
14113 MATRIX_ROW_VPOS (r1
, current_matrix
),
14114 delta
, delta_bytes
);
14117 /* Set the cursor. */
14118 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14120 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14127 /* Handle the case that changes are all below what is displayed in
14128 the window, and that PT is in the window. This shortcut cannot
14129 be taken if ZV is visible in the window, and text has been added
14130 there that is visible in the window. */
14131 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14132 /* ZV is not visible in the window, or there are no
14133 changes at ZV, actually. */
14134 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14135 || first_changed_charpos
== last_changed_charpos
))
14137 struct glyph_row
*r0
;
14139 /* Give up if PT is not in the window. Note that it already has
14140 been checked at the start of try_window_id that PT is not in
14141 front of the window start. */
14142 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14145 /* If window start is unchanged, we can reuse the whole matrix
14146 as is, without changing glyph positions since no text has
14147 been added/removed in front of the window end. */
14148 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14149 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14150 /* PT must not be in a partially visible line. */
14151 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14152 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14154 /* We have to compute the window end anew since text
14155 can have been added/removed after it. */
14157 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14158 w
->window_end_bytepos
14159 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14161 /* Set the cursor. */
14162 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14164 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14171 /* Give up if window start is in the changed area.
14173 The condition used to read
14175 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
14177 but why that was tested escapes me at the moment. */
14178 if (CHARPOS (start
) >= first_changed_charpos
14179 && CHARPOS (start
) <= last_changed_charpos
)
14182 /* Check that window start agrees with the start of the first glyph
14183 row in its current matrix. Check this after we know the window
14184 start is not in changed text, otherwise positions would not be
14186 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14187 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
14190 /* Give up if the window ends in strings. Overlay strings
14191 at the end are difficult to handle, so don't try. */
14192 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
14193 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
14196 /* Compute the position at which we have to start displaying new
14197 lines. Some of the lines at the top of the window might be
14198 reusable because they are not displaying changed text. Find the
14199 last row in W's current matrix not affected by changes at the
14200 start of current_buffer. Value is null if changes start in the
14201 first line of window. */
14202 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
14203 if (last_unchanged_at_beg_row
)
14205 /* Avoid starting to display in the moddle of a character, a TAB
14206 for instance. This is easier than to set up the iterator
14207 exactly, and it's not a frequent case, so the additional
14208 effort wouldn't really pay off. */
14209 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
14210 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
14211 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
14212 --last_unchanged_at_beg_row
;
14214 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
14217 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
14219 start_pos
= it
.current
.pos
;
14221 /* Start displaying new lines in the desired matrix at the same
14222 vpos we would use in the current matrix, i.e. below
14223 last_unchanged_at_beg_row. */
14224 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
14226 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14227 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
14229 xassert (it
.hpos
== 0 && it
.current_x
== 0);
14233 /* There are no reusable lines at the start of the window.
14234 Start displaying in the first text line. */
14235 start_display (&it
, w
, start
);
14236 it
.vpos
= it
.first_vpos
;
14237 start_pos
= it
.current
.pos
;
14240 /* Find the first row that is not affected by changes at the end of
14241 the buffer. Value will be null if there is no unchanged row, in
14242 which case we must redisplay to the end of the window. delta
14243 will be set to the value by which buffer positions beginning with
14244 first_unchanged_at_end_row have to be adjusted due to text
14246 first_unchanged_at_end_row
14247 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
14248 IF_DEBUG (debug_delta
= delta
);
14249 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
14251 /* Set stop_pos to the buffer position up to which we will have to
14252 display new lines. If first_unchanged_at_end_row != NULL, this
14253 is the buffer position of the start of the line displayed in that
14254 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
14255 that we don't stop at a buffer position. */
14257 if (first_unchanged_at_end_row
)
14259 xassert (last_unchanged_at_beg_row
== NULL
14260 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
14262 /* If this is a continuation line, move forward to the next one
14263 that isn't. Changes in lines above affect this line.
14264 Caution: this may move first_unchanged_at_end_row to a row
14265 not displaying text. */
14266 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
14267 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14268 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14269 < it
.last_visible_y
))
14270 ++first_unchanged_at_end_row
;
14272 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14273 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14274 >= it
.last_visible_y
))
14275 first_unchanged_at_end_row
= NULL
;
14278 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
14280 first_unchanged_at_end_vpos
14281 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
14282 xassert (stop_pos
>= Z
- END_UNCHANGED
);
14285 else if (last_unchanged_at_beg_row
== NULL
)
14291 /* Either there is no unchanged row at the end, or the one we have
14292 now displays text. This is a necessary condition for the window
14293 end pos calculation at the end of this function. */
14294 xassert (first_unchanged_at_end_row
== NULL
14295 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
14297 debug_last_unchanged_at_beg_vpos
14298 = (last_unchanged_at_beg_row
14299 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
14301 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
14303 #endif /* GLYPH_DEBUG != 0 */
14306 /* Display new lines. Set last_text_row to the last new line
14307 displayed which has text on it, i.e. might end up as being the
14308 line where the window_end_vpos is. */
14309 w
->cursor
.vpos
= -1;
14310 last_text_row
= NULL
;
14311 overlay_arrow_seen
= 0;
14312 while (it
.current_y
< it
.last_visible_y
14313 && !fonts_changed_p
14314 && (first_unchanged_at_end_row
== NULL
14315 || IT_CHARPOS (it
) < stop_pos
))
14317 if (display_line (&it
))
14318 last_text_row
= it
.glyph_row
- 1;
14321 if (fonts_changed_p
)
14325 /* Compute differences in buffer positions, y-positions etc. for
14326 lines reused at the bottom of the window. Compute what we can
14328 if (first_unchanged_at_end_row
14329 /* No lines reused because we displayed everything up to the
14330 bottom of the window. */
14331 && it
.current_y
< it
.last_visible_y
)
14334 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
14336 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
14337 run
.current_y
= first_unchanged_at_end_row
->y
;
14338 run
.desired_y
= run
.current_y
+ dy
;
14339 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
14343 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
14344 first_unchanged_at_end_row
= NULL
;
14346 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
14349 /* Find the cursor if not already found. We have to decide whether
14350 PT will appear on this window (it sometimes doesn't, but this is
14351 not a very frequent case.) This decision has to be made before
14352 the current matrix is altered. A value of cursor.vpos < 0 means
14353 that PT is either in one of the lines beginning at
14354 first_unchanged_at_end_row or below the window. Don't care for
14355 lines that might be displayed later at the window end; as
14356 mentioned, this is not a frequent case. */
14357 if (w
->cursor
.vpos
< 0)
14359 /* Cursor in unchanged rows at the top? */
14360 if (PT
< CHARPOS (start_pos
)
14361 && last_unchanged_at_beg_row
)
14363 row
= row_containing_pos (w
, PT
,
14364 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
14365 last_unchanged_at_beg_row
+ 1, 0);
14367 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14370 /* Start from first_unchanged_at_end_row looking for PT. */
14371 else if (first_unchanged_at_end_row
)
14373 row
= row_containing_pos (w
, PT
- delta
,
14374 first_unchanged_at_end_row
, NULL
, 0);
14376 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
14377 delta_bytes
, dy
, dvpos
);
14380 /* Give up if cursor was not found. */
14381 if (w
->cursor
.vpos
< 0)
14383 clear_glyph_matrix (w
->desired_matrix
);
14388 /* Don't let the cursor end in the scroll margins. */
14390 int this_scroll_margin
, cursor_height
;
14392 this_scroll_margin
= max (0, scroll_margin
);
14393 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14394 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14395 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
14397 if ((w
->cursor
.y
< this_scroll_margin
14398 && CHARPOS (start
) > BEGV
)
14399 /* Old redisplay didn't take scroll margin into account at the bottom,
14400 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14401 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14402 ? cursor_height
+ this_scroll_margin
14403 : 1)) > it
.last_visible_y
)
14405 w
->cursor
.vpos
= -1;
14406 clear_glyph_matrix (w
->desired_matrix
);
14411 /* Scroll the display. Do it before changing the current matrix so
14412 that xterm.c doesn't get confused about where the cursor glyph is
14414 if (dy
&& run
.height
)
14418 if (FRAME_WINDOW_P (f
))
14420 rif
->update_window_begin_hook (w
);
14421 rif
->clear_window_mouse_face (w
);
14422 rif
->scroll_run_hook (w
, &run
);
14423 rif
->update_window_end_hook (w
, 0, 0);
14427 /* Terminal frame. In this case, dvpos gives the number of
14428 lines to scroll by; dvpos < 0 means scroll up. */
14429 int first_unchanged_at_end_vpos
14430 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14431 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14432 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14433 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14434 + window_internal_height (w
));
14436 /* Perform the operation on the screen. */
14439 /* Scroll last_unchanged_at_beg_row to the end of the
14440 window down dvpos lines. */
14441 set_terminal_window (end
);
14443 /* On dumb terminals delete dvpos lines at the end
14444 before inserting dvpos empty lines. */
14445 if (!scroll_region_ok
)
14446 ins_del_lines (end
- dvpos
, -dvpos
);
14448 /* Insert dvpos empty lines in front of
14449 last_unchanged_at_beg_row. */
14450 ins_del_lines (from
, dvpos
);
14452 else if (dvpos
< 0)
14454 /* Scroll up last_unchanged_at_beg_vpos to the end of
14455 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14456 set_terminal_window (end
);
14458 /* Delete dvpos lines in front of
14459 last_unchanged_at_beg_vpos. ins_del_lines will set
14460 the cursor to the given vpos and emit |dvpos| delete
14462 ins_del_lines (from
+ dvpos
, dvpos
);
14464 /* On a dumb terminal insert dvpos empty lines at the
14466 if (!scroll_region_ok
)
14467 ins_del_lines (end
+ dvpos
, -dvpos
);
14470 set_terminal_window (0);
14476 /* Shift reused rows of the current matrix to the right position.
14477 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14479 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14480 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14483 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14484 bottom_vpos
, dvpos
);
14485 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14488 else if (dvpos
> 0)
14490 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14491 bottom_vpos
, dvpos
);
14492 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14493 first_unchanged_at_end_vpos
+ dvpos
, 0);
14496 /* For frame-based redisplay, make sure that current frame and window
14497 matrix are in sync with respect to glyph memory. */
14498 if (!FRAME_WINDOW_P (f
))
14499 sync_frame_with_window_matrix_rows (w
);
14501 /* Adjust buffer positions in reused rows. */
14503 increment_matrix_positions (current_matrix
,
14504 first_unchanged_at_end_vpos
+ dvpos
,
14505 bottom_vpos
, delta
, delta_bytes
);
14507 /* Adjust Y positions. */
14509 shift_glyph_matrix (w
, current_matrix
,
14510 first_unchanged_at_end_vpos
+ dvpos
,
14513 if (first_unchanged_at_end_row
)
14515 first_unchanged_at_end_row
+= dvpos
;
14516 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
14517 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
14518 first_unchanged_at_end_row
= NULL
;
14521 /* If scrolling up, there may be some lines to display at the end of
14523 last_text_row_at_end
= NULL
;
14526 /* Scrolling up can leave for example a partially visible line
14527 at the end of the window to be redisplayed. */
14528 /* Set last_row to the glyph row in the current matrix where the
14529 window end line is found. It has been moved up or down in
14530 the matrix by dvpos. */
14531 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
14532 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
14534 /* If last_row is the window end line, it should display text. */
14535 xassert (last_row
->displays_text_p
);
14537 /* If window end line was partially visible before, begin
14538 displaying at that line. Otherwise begin displaying with the
14539 line following it. */
14540 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
14542 init_to_row_start (&it
, w
, last_row
);
14543 it
.vpos
= last_vpos
;
14544 it
.current_y
= last_row
->y
;
14548 init_to_row_end (&it
, w
, last_row
);
14549 it
.vpos
= 1 + last_vpos
;
14550 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
14554 /* We may start in a continuation line. If so, we have to
14555 get the right continuation_lines_width and current_x. */
14556 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
14557 it
.hpos
= it
.current_x
= 0;
14559 /* Display the rest of the lines at the window end. */
14560 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14561 while (it
.current_y
< it
.last_visible_y
14562 && !fonts_changed_p
)
14564 /* Is it always sure that the display agrees with lines in
14565 the current matrix? I don't think so, so we mark rows
14566 displayed invalid in the current matrix by setting their
14567 enabled_p flag to zero. */
14568 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
14569 if (display_line (&it
))
14570 last_text_row_at_end
= it
.glyph_row
- 1;
14574 /* Update window_end_pos and window_end_vpos. */
14575 if (first_unchanged_at_end_row
14576 && !last_text_row_at_end
)
14578 /* Window end line if one of the preserved rows from the current
14579 matrix. Set row to the last row displaying text in current
14580 matrix starting at first_unchanged_at_end_row, after
14582 xassert (first_unchanged_at_end_row
->displays_text_p
);
14583 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
14584 first_unchanged_at_end_row
);
14585 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
14587 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14588 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14590 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
14591 xassert (w
->window_end_bytepos
>= 0);
14592 IF_DEBUG (debug_method_add (w
, "A"));
14594 else if (last_text_row_at_end
)
14597 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
14598 w
->window_end_bytepos
14599 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
14601 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
14602 xassert (w
->window_end_bytepos
>= 0);
14603 IF_DEBUG (debug_method_add (w
, "B"));
14605 else if (last_text_row
)
14607 /* We have displayed either to the end of the window or at the
14608 end of the window, i.e. the last row with text is to be found
14609 in the desired matrix. */
14611 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14612 w
->window_end_bytepos
14613 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14615 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
14616 xassert (w
->window_end_bytepos
>= 0);
14618 else if (first_unchanged_at_end_row
== NULL
14619 && last_text_row
== NULL
14620 && last_text_row_at_end
== NULL
)
14622 /* Displayed to end of window, but no line containing text was
14623 displayed. Lines were deleted at the end of the window. */
14624 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
14625 int vpos
= XFASTINT (w
->window_end_vpos
);
14626 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
14627 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
14630 row
== NULL
&& vpos
>= first_vpos
;
14631 --vpos
, --current_row
, --desired_row
)
14633 if (desired_row
->enabled_p
)
14635 if (desired_row
->displays_text_p
)
14638 else if (current_row
->displays_text_p
)
14642 xassert (row
!= NULL
);
14643 w
->window_end_vpos
= make_number (vpos
+ 1);
14644 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14645 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14646 xassert (w
->window_end_bytepos
>= 0);
14647 IF_DEBUG (debug_method_add (w
, "C"));
14652 #if 0 /* This leads to problems, for instance when the cursor is
14653 at ZV, and the cursor line displays no text. */
14654 /* Disable rows below what's displayed in the window. This makes
14655 debugging easier. */
14656 enable_glyph_matrix_rows (current_matrix
,
14657 XFASTINT (w
->window_end_vpos
) + 1,
14661 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
14662 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
14664 /* Record that display has not been completed. */
14665 w
->window_end_valid
= Qnil
;
14666 w
->desired_matrix
->no_scrolling_p
= 1;
14674 /***********************************************************************
14675 More debugging support
14676 ***********************************************************************/
14680 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
14681 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
14682 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
14685 /* Dump the contents of glyph matrix MATRIX on stderr.
14687 GLYPHS 0 means don't show glyph contents.
14688 GLYPHS 1 means show glyphs in short form
14689 GLYPHS > 1 means show glyphs in long form. */
14692 dump_glyph_matrix (matrix
, glyphs
)
14693 struct glyph_matrix
*matrix
;
14697 for (i
= 0; i
< matrix
->nrows
; ++i
)
14698 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
14702 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
14703 the glyph row and area where the glyph comes from. */
14706 dump_glyph (row
, glyph
, area
)
14707 struct glyph_row
*row
;
14708 struct glyph
*glyph
;
14711 if (glyph
->type
== CHAR_GLYPH
)
14714 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14715 glyph
- row
->glyphs
[TEXT_AREA
],
14718 (BUFFERP (glyph
->object
)
14720 : (STRINGP (glyph
->object
)
14723 glyph
->pixel_width
,
14725 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
14729 glyph
->left_box_line_p
,
14730 glyph
->right_box_line_p
);
14732 else if (glyph
->type
== STRETCH_GLYPH
)
14735 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14736 glyph
- row
->glyphs
[TEXT_AREA
],
14739 (BUFFERP (glyph
->object
)
14741 : (STRINGP (glyph
->object
)
14744 glyph
->pixel_width
,
14748 glyph
->left_box_line_p
,
14749 glyph
->right_box_line_p
);
14751 else if (glyph
->type
== IMAGE_GLYPH
)
14754 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14755 glyph
- row
->glyphs
[TEXT_AREA
],
14758 (BUFFERP (glyph
->object
)
14760 : (STRINGP (glyph
->object
)
14763 glyph
->pixel_width
,
14767 glyph
->left_box_line_p
,
14768 glyph
->right_box_line_p
);
14773 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
14774 GLYPHS 0 means don't show glyph contents.
14775 GLYPHS 1 means show glyphs in short form
14776 GLYPHS > 1 means show glyphs in long form. */
14779 dump_glyph_row (row
, vpos
, glyphs
)
14780 struct glyph_row
*row
;
14785 fprintf (stderr
, "Row Start End Used oEI><\\CTZFesm X Y W H V A P\n");
14786 fprintf (stderr
, "======================================================================\n");
14788 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
14789 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
14791 MATRIX_ROW_START_CHARPOS (row
),
14792 MATRIX_ROW_END_CHARPOS (row
),
14793 row
->used
[TEXT_AREA
],
14794 row
->contains_overlapping_glyphs_p
,
14796 row
->truncated_on_left_p
,
14797 row
->truncated_on_right_p
,
14799 MATRIX_ROW_CONTINUATION_LINE_P (row
),
14800 row
->displays_text_p
,
14803 row
->ends_in_middle_of_char_p
,
14804 row
->starts_in_middle_of_char_p
,
14810 row
->visible_height
,
14813 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
14814 row
->end
.overlay_string_index
,
14815 row
->continuation_lines_width
);
14816 fprintf (stderr
, "%9d %5d\n",
14817 CHARPOS (row
->start
.string_pos
),
14818 CHARPOS (row
->end
.string_pos
));
14819 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
14820 row
->end
.dpvec_index
);
14827 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14829 struct glyph
*glyph
= row
->glyphs
[area
];
14830 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
14832 /* Glyph for a line end in text. */
14833 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
14836 if (glyph
< glyph_end
)
14837 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
14839 for (; glyph
< glyph_end
; ++glyph
)
14840 dump_glyph (row
, glyph
, area
);
14843 else if (glyphs
== 1)
14847 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14849 char *s
= (char *) alloca (row
->used
[area
] + 1);
14852 for (i
= 0; i
< row
->used
[area
]; ++i
)
14854 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
14855 if (glyph
->type
== CHAR_GLYPH
14856 && glyph
->u
.ch
< 0x80
14857 && glyph
->u
.ch
>= ' ')
14858 s
[i
] = glyph
->u
.ch
;
14864 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
14870 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
14871 Sdump_glyph_matrix
, 0, 1, "p",
14872 doc
: /* Dump the current matrix of the selected window to stderr.
14873 Shows contents of glyph row structures. With non-nil
14874 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
14875 glyphs in short form, otherwise show glyphs in long form. */)
14877 Lisp_Object glyphs
;
14879 struct window
*w
= XWINDOW (selected_window
);
14880 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14882 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
14883 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
14884 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
14885 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
14886 fprintf (stderr
, "=============================================\n");
14887 dump_glyph_matrix (w
->current_matrix
,
14888 NILP (glyphs
) ? 0 : XINT (glyphs
));
14893 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
14894 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
14897 struct frame
*f
= XFRAME (selected_frame
);
14898 dump_glyph_matrix (f
->current_matrix
, 1);
14903 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
14904 doc
: /* Dump glyph row ROW to stderr.
14905 GLYPH 0 means don't dump glyphs.
14906 GLYPH 1 means dump glyphs in short form.
14907 GLYPH > 1 or omitted means dump glyphs in long form. */)
14909 Lisp_Object row
, glyphs
;
14911 struct glyph_matrix
*matrix
;
14914 CHECK_NUMBER (row
);
14915 matrix
= XWINDOW (selected_window
)->current_matrix
;
14917 if (vpos
>= 0 && vpos
< matrix
->nrows
)
14918 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
14920 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14925 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
14926 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
14927 GLYPH 0 means don't dump glyphs.
14928 GLYPH 1 means dump glyphs in short form.
14929 GLYPH > 1 or omitted means dump glyphs in long form. */)
14931 Lisp_Object row
, glyphs
;
14933 struct frame
*sf
= SELECTED_FRAME ();
14934 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
14937 CHECK_NUMBER (row
);
14939 if (vpos
>= 0 && vpos
< m
->nrows
)
14940 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
14941 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14946 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
14947 doc
: /* Toggle tracing of redisplay.
14948 With ARG, turn tracing on if and only if ARG is positive. */)
14953 trace_redisplay_p
= !trace_redisplay_p
;
14956 arg
= Fprefix_numeric_value (arg
);
14957 trace_redisplay_p
= XINT (arg
) > 0;
14964 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
14965 doc
: /* Like `format', but print result to stderr.
14966 usage: (trace-to-stderr STRING &rest OBJECTS) */)
14971 Lisp_Object s
= Fformat (nargs
, args
);
14972 fprintf (stderr
, "%s", SDATA (s
));
14976 #endif /* GLYPH_DEBUG */
14980 /***********************************************************************
14981 Building Desired Matrix Rows
14982 ***********************************************************************/
14984 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
14985 Used for non-window-redisplay windows, and for windows w/o left fringe. */
14987 static struct glyph_row
*
14988 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
14990 Lisp_Object overlay_arrow_string
;
14992 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14993 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14994 struct buffer
*old
= current_buffer
;
14995 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
14996 int arrow_len
= SCHARS (overlay_arrow_string
);
14997 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
14998 const unsigned char *p
;
15001 int n_glyphs_before
;
15003 set_buffer_temp (buffer
);
15004 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15005 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15006 SET_TEXT_POS (it
.position
, 0, 0);
15008 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15010 while (p
< arrow_end
)
15012 Lisp_Object face
, ilisp
;
15014 /* Get the next character. */
15016 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15018 it
.c
= *p
, it
.len
= 1;
15021 /* Get its face. */
15022 ilisp
= make_number (p
- arrow_string
);
15023 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15024 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15026 /* Compute its width, get its glyphs. */
15027 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15028 SET_TEXT_POS (it
.position
, -1, -1);
15029 PRODUCE_GLYPHS (&it
);
15031 /* If this character doesn't fit any more in the line, we have
15032 to remove some glyphs. */
15033 if (it
.current_x
> it
.last_visible_x
)
15035 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15040 set_buffer_temp (old
);
15041 return it
.glyph_row
;
15045 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15046 glyphs are only inserted for terminal frames since we can't really
15047 win with truncation glyphs when partially visible glyphs are
15048 involved. Which glyphs to insert is determined by
15049 produce_special_glyphs. */
15052 insert_left_trunc_glyphs (it
)
15055 struct it truncate_it
;
15056 struct glyph
*from
, *end
, *to
, *toend
;
15058 xassert (!FRAME_WINDOW_P (it
->f
));
15060 /* Get the truncation glyphs. */
15062 truncate_it
.current_x
= 0;
15063 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15064 truncate_it
.glyph_row
= &scratch_glyph_row
;
15065 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15066 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15067 truncate_it
.object
= make_number (0);
15068 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15070 /* Overwrite glyphs from IT with truncation glyphs. */
15071 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15072 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15073 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15074 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15079 /* There may be padding glyphs left over. Overwrite them too. */
15080 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15082 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15088 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15092 /* Compute the pixel height and width of IT->glyph_row.
15094 Most of the time, ascent and height of a display line will be equal
15095 to the max_ascent and max_height values of the display iterator
15096 structure. This is not the case if
15098 1. We hit ZV without displaying anything. In this case, max_ascent
15099 and max_height will be zero.
15101 2. We have some glyphs that don't contribute to the line height.
15102 (The glyph row flag contributes_to_line_height_p is for future
15103 pixmap extensions).
15105 The first case is easily covered by using default values because in
15106 these cases, the line height does not really matter, except that it
15107 must not be zero. */
15110 compute_line_metrics (it
)
15113 struct glyph_row
*row
= it
->glyph_row
;
15116 if (FRAME_WINDOW_P (it
->f
))
15118 int i
, min_y
, max_y
;
15120 /* The line may consist of one space only, that was added to
15121 place the cursor on it. If so, the row's height hasn't been
15123 if (row
->height
== 0)
15125 if (it
->max_ascent
+ it
->max_descent
== 0)
15126 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15127 row
->ascent
= it
->max_ascent
;
15128 row
->height
= it
->max_ascent
+ it
->max_descent
;
15129 row
->phys_ascent
= it
->max_phys_ascent
;
15130 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15131 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15134 /* Compute the width of this line. */
15135 row
->pixel_width
= row
->x
;
15136 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15137 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15139 xassert (row
->pixel_width
>= 0);
15140 xassert (row
->ascent
>= 0 && row
->height
> 0);
15142 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15143 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15145 /* If first line's physical ascent is larger than its logical
15146 ascent, use the physical ascent, and make the row taller.
15147 This makes accented characters fully visible. */
15148 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
15149 && row
->phys_ascent
> row
->ascent
)
15151 row
->height
+= row
->phys_ascent
- row
->ascent
;
15152 row
->ascent
= row
->phys_ascent
;
15155 /* Compute how much of the line is visible. */
15156 row
->visible_height
= row
->height
;
15158 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
15159 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
15161 if (row
->y
< min_y
)
15162 row
->visible_height
-= min_y
- row
->y
;
15163 if (row
->y
+ row
->height
> max_y
)
15164 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15168 row
->pixel_width
= row
->used
[TEXT_AREA
];
15169 if (row
->continued_p
)
15170 row
->pixel_width
-= it
->continuation_pixel_width
;
15171 else if (row
->truncated_on_right_p
)
15172 row
->pixel_width
-= it
->truncation_pixel_width
;
15173 row
->ascent
= row
->phys_ascent
= 0;
15174 row
->height
= row
->phys_height
= row
->visible_height
= 1;
15175 row
->extra_line_spacing
= 0;
15178 /* Compute a hash code for this row. */
15180 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15181 for (i
= 0; i
< row
->used
[area
]; ++i
)
15182 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
15183 + row
->glyphs
[area
][i
].u
.val
15184 + row
->glyphs
[area
][i
].face_id
15185 + row
->glyphs
[area
][i
].padding_p
15186 + (row
->glyphs
[area
][i
].type
<< 2));
15188 it
->max_ascent
= it
->max_descent
= 0;
15189 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
15193 /* Append one space to the glyph row of iterator IT if doing a
15194 window-based redisplay. The space has the same face as
15195 IT->face_id. Value is non-zero if a space was added.
15197 This function is called to make sure that there is always one glyph
15198 at the end of a glyph row that the cursor can be set on under
15199 window-systems. (If there weren't such a glyph we would not know
15200 how wide and tall a box cursor should be displayed).
15202 At the same time this space let's a nicely handle clearing to the
15203 end of the line if the row ends in italic text. */
15206 append_space_for_newline (it
, default_face_p
)
15208 int default_face_p
;
15210 if (FRAME_WINDOW_P (it
->f
))
15212 int n
= it
->glyph_row
->used
[TEXT_AREA
];
15214 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
15215 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
15217 /* Save some values that must not be changed.
15218 Must save IT->c and IT->len because otherwise
15219 ITERATOR_AT_END_P wouldn't work anymore after
15220 append_space_for_newline has been called. */
15221 enum display_element_type saved_what
= it
->what
;
15222 int saved_c
= it
->c
, saved_len
= it
->len
;
15223 int saved_x
= it
->current_x
;
15224 int saved_face_id
= it
->face_id
;
15225 struct text_pos saved_pos
;
15226 Lisp_Object saved_object
;
15229 saved_object
= it
->object
;
15230 saved_pos
= it
->position
;
15232 it
->what
= IT_CHARACTER
;
15233 bzero (&it
->position
, sizeof it
->position
);
15234 it
->object
= make_number (0);
15238 if (default_face_p
)
15239 it
->face_id
= DEFAULT_FACE_ID
;
15240 else if (it
->face_before_selective_p
)
15241 it
->face_id
= it
->saved_face_id
;
15242 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15243 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
15245 PRODUCE_GLYPHS (it
);
15247 it
->override_ascent
= -1;
15248 it
->constrain_row_ascent_descent_p
= 0;
15249 it
->current_x
= saved_x
;
15250 it
->object
= saved_object
;
15251 it
->position
= saved_pos
;
15252 it
->what
= saved_what
;
15253 it
->face_id
= saved_face_id
;
15254 it
->len
= saved_len
;
15264 /* Extend the face of the last glyph in the text area of IT->glyph_row
15265 to the end of the display line. Called from display_line.
15266 If the glyph row is empty, add a space glyph to it so that we
15267 know the face to draw. Set the glyph row flag fill_line_p. */
15270 extend_face_to_end_of_line (it
)
15274 struct frame
*f
= it
->f
;
15276 /* If line is already filled, do nothing. */
15277 if (it
->current_x
>= it
->last_visible_x
)
15280 /* Face extension extends the background and box of IT->face_id
15281 to the end of the line. If the background equals the background
15282 of the frame, we don't have to do anything. */
15283 if (it
->face_before_selective_p
)
15284 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
15286 face
= FACE_FROM_ID (f
, it
->face_id
);
15288 if (FRAME_WINDOW_P (f
)
15289 && face
->box
== FACE_NO_BOX
15290 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
15294 /* Set the glyph row flag indicating that the face of the last glyph
15295 in the text area has to be drawn to the end of the text area. */
15296 it
->glyph_row
->fill_line_p
= 1;
15298 /* If current character of IT is not ASCII, make sure we have the
15299 ASCII face. This will be automatically undone the next time
15300 get_next_display_element returns a multibyte character. Note
15301 that the character will always be single byte in unibyte text. */
15302 if (!SINGLE_BYTE_CHAR_P (it
->c
))
15304 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
15307 if (FRAME_WINDOW_P (f
))
15309 /* If the row is empty, add a space with the current face of IT,
15310 so that we know which face to draw. */
15311 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
15313 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
15314 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
15315 it
->glyph_row
->used
[TEXT_AREA
] = 1;
15320 /* Save some values that must not be changed. */
15321 int saved_x
= it
->current_x
;
15322 struct text_pos saved_pos
;
15323 Lisp_Object saved_object
;
15324 enum display_element_type saved_what
= it
->what
;
15325 int saved_face_id
= it
->face_id
;
15327 saved_object
= it
->object
;
15328 saved_pos
= it
->position
;
15330 it
->what
= IT_CHARACTER
;
15331 bzero (&it
->position
, sizeof it
->position
);
15332 it
->object
= make_number (0);
15335 it
->face_id
= face
->id
;
15337 PRODUCE_GLYPHS (it
);
15339 while (it
->current_x
<= it
->last_visible_x
)
15340 PRODUCE_GLYPHS (it
);
15342 /* Don't count these blanks really. It would let us insert a left
15343 truncation glyph below and make us set the cursor on them, maybe. */
15344 it
->current_x
= saved_x
;
15345 it
->object
= saved_object
;
15346 it
->position
= saved_pos
;
15347 it
->what
= saved_what
;
15348 it
->face_id
= saved_face_id
;
15353 /* Value is non-zero if text starting at CHARPOS in current_buffer is
15354 trailing whitespace. */
15357 trailing_whitespace_p (charpos
)
15360 int bytepos
= CHAR_TO_BYTE (charpos
);
15363 while (bytepos
< ZV_BYTE
15364 && (c
= FETCH_CHAR (bytepos
),
15365 c
== ' ' || c
== '\t'))
15368 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
15370 if (bytepos
!= PT_BYTE
)
15377 /* Highlight trailing whitespace, if any, in ROW. */
15380 highlight_trailing_whitespace (f
, row
)
15382 struct glyph_row
*row
;
15384 int used
= row
->used
[TEXT_AREA
];
15388 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
15389 struct glyph
*glyph
= start
+ used
- 1;
15391 /* Skip over glyphs inserted to display the cursor at the
15392 end of a line, for extending the face of the last glyph
15393 to the end of the line on terminals, and for truncation
15394 and continuation glyphs. */
15395 while (glyph
>= start
15396 && glyph
->type
== CHAR_GLYPH
15397 && INTEGERP (glyph
->object
))
15400 /* If last glyph is a space or stretch, and it's trailing
15401 whitespace, set the face of all trailing whitespace glyphs in
15402 IT->glyph_row to `trailing-whitespace'. */
15404 && BUFFERP (glyph
->object
)
15405 && (glyph
->type
== STRETCH_GLYPH
15406 || (glyph
->type
== CHAR_GLYPH
15407 && glyph
->u
.ch
== ' '))
15408 && trailing_whitespace_p (glyph
->charpos
))
15410 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
15414 while (glyph
>= start
15415 && BUFFERP (glyph
->object
)
15416 && (glyph
->type
== STRETCH_GLYPH
15417 || (glyph
->type
== CHAR_GLYPH
15418 && glyph
->u
.ch
== ' ')))
15419 (glyph
--)->face_id
= face_id
;
15425 /* Value is non-zero if glyph row ROW in window W should be
15426 used to hold the cursor. */
15429 cursor_row_p (w
, row
)
15431 struct glyph_row
*row
;
15433 int cursor_row_p
= 1;
15435 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15437 /* If the row ends with a newline from a string, we don't want
15438 the cursor there, but we still want it at the start of the
15439 string if the string starts in this row.
15440 If the row is continued it doesn't end in a newline. */
15441 if (CHARPOS (row
->end
.string_pos
) >= 0)
15442 cursor_row_p
= (row
->continued_p
15443 || PT
>= MATRIX_ROW_START_CHARPOS (row
));
15444 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15446 /* If the row ends in middle of a real character,
15447 and the line is continued, we want the cursor here.
15448 That's because MATRIX_ROW_END_CHARPOS would equal
15449 PT if PT is before the character. */
15450 if (!row
->ends_in_ellipsis_p
)
15451 cursor_row_p
= row
->continued_p
;
15453 /* If the row ends in an ellipsis, then
15454 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15455 We want that position to be displayed after the ellipsis. */
15458 /* If the row ends at ZV, display the cursor at the end of that
15459 row instead of at the start of the row below. */
15460 else if (row
->ends_at_zv_p
)
15466 return cursor_row_p
;
15470 /* Construct the glyph row IT->glyph_row in the desired matrix of
15471 IT->w from text at the current position of IT. See dispextern.h
15472 for an overview of struct it. Value is non-zero if
15473 IT->glyph_row displays text, as opposed to a line displaying ZV
15480 struct glyph_row
*row
= it
->glyph_row
;
15481 Lisp_Object overlay_arrow_string
;
15483 /* We always start displaying at hpos zero even if hscrolled. */
15484 xassert (it
->hpos
== 0 && it
->current_x
== 0);
15486 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
15487 >= it
->w
->desired_matrix
->nrows
)
15489 it
->w
->nrows_scale_factor
++;
15490 fonts_changed_p
= 1;
15494 /* Is IT->w showing the region? */
15495 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
15497 /* Clear the result glyph row and enable it. */
15498 prepare_desired_row (row
);
15500 row
->y
= it
->current_y
;
15501 row
->start
= it
->start
;
15502 row
->continuation_lines_width
= it
->continuation_lines_width
;
15503 row
->displays_text_p
= 1;
15504 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
15505 it
->starts_in_middle_of_char_p
= 0;
15507 /* Arrange the overlays nicely for our purposes. Usually, we call
15508 display_line on only one line at a time, in which case this
15509 can't really hurt too much, or we call it on lines which appear
15510 one after another in the buffer, in which case all calls to
15511 recenter_overlay_lists but the first will be pretty cheap. */
15512 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
15514 /* Move over display elements that are not visible because we are
15515 hscrolled. This may stop at an x-position < IT->first_visible_x
15516 if the first glyph is partially visible or if we hit a line end. */
15517 if (it
->current_x
< it
->first_visible_x
)
15519 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
15520 MOVE_TO_POS
| MOVE_TO_X
);
15523 /* Get the initial row height. This is either the height of the
15524 text hscrolled, if there is any, or zero. */
15525 row
->ascent
= it
->max_ascent
;
15526 row
->height
= it
->max_ascent
+ it
->max_descent
;
15527 row
->phys_ascent
= it
->max_phys_ascent
;
15528 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15529 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15531 /* Loop generating characters. The loop is left with IT on the next
15532 character to display. */
15535 int n_glyphs_before
, hpos_before
, x_before
;
15537 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
15539 /* Retrieve the next thing to display. Value is zero if end of
15541 if (!get_next_display_element (it
))
15543 /* Maybe add a space at the end of this line that is used to
15544 display the cursor there under X. Set the charpos of the
15545 first glyph of blank lines not corresponding to any text
15547 #ifdef HAVE_WINDOW_SYSTEM
15548 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15549 row
->exact_window_width_line_p
= 1;
15551 #endif /* HAVE_WINDOW_SYSTEM */
15552 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
15553 || row
->used
[TEXT_AREA
] == 0)
15555 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
15556 row
->displays_text_p
= 0;
15558 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
15559 && (!MINI_WINDOW_P (it
->w
)
15560 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
15561 row
->indicate_empty_line_p
= 1;
15564 it
->continuation_lines_width
= 0;
15565 row
->ends_at_zv_p
= 1;
15569 /* Now, get the metrics of what we want to display. This also
15570 generates glyphs in `row' (which is IT->glyph_row). */
15571 n_glyphs_before
= row
->used
[TEXT_AREA
];
15574 /* Remember the line height so far in case the next element doesn't
15575 fit on the line. */
15576 if (!it
->truncate_lines_p
)
15578 ascent
= it
->max_ascent
;
15579 descent
= it
->max_descent
;
15580 phys_ascent
= it
->max_phys_ascent
;
15581 phys_descent
= it
->max_phys_descent
;
15584 PRODUCE_GLYPHS (it
);
15586 /* If this display element was in marginal areas, continue with
15588 if (it
->area
!= TEXT_AREA
)
15590 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15591 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15592 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15593 row
->phys_height
= max (row
->phys_height
,
15594 it
->max_phys_ascent
+ it
->max_phys_descent
);
15595 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15596 it
->max_extra_line_spacing
);
15597 set_iterator_to_next (it
, 1);
15601 /* Does the display element fit on the line? If we truncate
15602 lines, we should draw past the right edge of the window. If
15603 we don't truncate, we want to stop so that we can display the
15604 continuation glyph before the right margin. If lines are
15605 continued, there are two possible strategies for characters
15606 resulting in more than 1 glyph (e.g. tabs): Display as many
15607 glyphs as possible in this line and leave the rest for the
15608 continuation line, or display the whole element in the next
15609 line. Original redisplay did the former, so we do it also. */
15610 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
15611 hpos_before
= it
->hpos
;
15614 if (/* Not a newline. */
15616 /* Glyphs produced fit entirely in the line. */
15617 && it
->current_x
< it
->last_visible_x
)
15619 it
->hpos
+= nglyphs
;
15620 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15621 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15622 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15623 row
->phys_height
= max (row
->phys_height
,
15624 it
->max_phys_ascent
+ it
->max_phys_descent
);
15625 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15626 it
->max_extra_line_spacing
);
15627 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
15628 row
->x
= x
- it
->first_visible_x
;
15633 struct glyph
*glyph
;
15635 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
15637 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
15638 new_x
= x
+ glyph
->pixel_width
;
15640 if (/* Lines are continued. */
15641 !it
->truncate_lines_p
15642 && (/* Glyph doesn't fit on the line. */
15643 new_x
> it
->last_visible_x
15644 /* Or it fits exactly on a window system frame. */
15645 || (new_x
== it
->last_visible_x
15646 && FRAME_WINDOW_P (it
->f
))))
15648 /* End of a continued line. */
15651 || (new_x
== it
->last_visible_x
15652 && FRAME_WINDOW_P (it
->f
)))
15654 /* Current glyph is the only one on the line or
15655 fits exactly on the line. We must continue
15656 the line because we can't draw the cursor
15657 after the glyph. */
15658 row
->continued_p
= 1;
15659 it
->current_x
= new_x
;
15660 it
->continuation_lines_width
+= new_x
;
15662 if (i
== nglyphs
- 1)
15664 set_iterator_to_next (it
, 1);
15665 #ifdef HAVE_WINDOW_SYSTEM
15666 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15668 if (!get_next_display_element (it
))
15670 row
->exact_window_width_line_p
= 1;
15671 it
->continuation_lines_width
= 0;
15672 row
->continued_p
= 0;
15673 row
->ends_at_zv_p
= 1;
15675 else if (ITERATOR_AT_END_OF_LINE_P (it
))
15677 row
->continued_p
= 0;
15678 row
->exact_window_width_line_p
= 1;
15681 #endif /* HAVE_WINDOW_SYSTEM */
15684 else if (CHAR_GLYPH_PADDING_P (*glyph
)
15685 && !FRAME_WINDOW_P (it
->f
))
15687 /* A padding glyph that doesn't fit on this line.
15688 This means the whole character doesn't fit
15690 row
->used
[TEXT_AREA
] = n_glyphs_before
;
15692 /* Fill the rest of the row with continuation
15693 glyphs like in 20.x. */
15694 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
15695 < row
->glyphs
[1 + TEXT_AREA
])
15696 produce_special_glyphs (it
, IT_CONTINUATION
);
15698 row
->continued_p
= 1;
15699 it
->current_x
= x_before
;
15700 it
->continuation_lines_width
+= x_before
;
15702 /* Restore the height to what it was before the
15703 element not fitting on the line. */
15704 it
->max_ascent
= ascent
;
15705 it
->max_descent
= descent
;
15706 it
->max_phys_ascent
= phys_ascent
;
15707 it
->max_phys_descent
= phys_descent
;
15709 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
15711 /* A TAB that extends past the right edge of the
15712 window. This produces a single glyph on
15713 window system frames. We leave the glyph in
15714 this row and let it fill the row, but don't
15715 consume the TAB. */
15716 it
->continuation_lines_width
+= it
->last_visible_x
;
15717 row
->ends_in_middle_of_char_p
= 1;
15718 row
->continued_p
= 1;
15719 glyph
->pixel_width
= it
->last_visible_x
- x
;
15720 it
->starts_in_middle_of_char_p
= 1;
15724 /* Something other than a TAB that draws past
15725 the right edge of the window. Restore
15726 positions to values before the element. */
15727 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15729 /* Display continuation glyphs. */
15730 if (!FRAME_WINDOW_P (it
->f
))
15731 produce_special_glyphs (it
, IT_CONTINUATION
);
15732 row
->continued_p
= 1;
15734 it
->current_x
= x_before
;
15735 it
->continuation_lines_width
+= x
;
15736 extend_face_to_end_of_line (it
);
15738 if (nglyphs
> 1 && i
> 0)
15740 row
->ends_in_middle_of_char_p
= 1;
15741 it
->starts_in_middle_of_char_p
= 1;
15744 /* Restore the height to what it was before the
15745 element not fitting on the line. */
15746 it
->max_ascent
= ascent
;
15747 it
->max_descent
= descent
;
15748 it
->max_phys_ascent
= phys_ascent
;
15749 it
->max_phys_descent
= phys_descent
;
15754 else if (new_x
> it
->first_visible_x
)
15756 /* Increment number of glyphs actually displayed. */
15759 if (x
< it
->first_visible_x
)
15760 /* Glyph is partially visible, i.e. row starts at
15761 negative X position. */
15762 row
->x
= x
- it
->first_visible_x
;
15766 /* Glyph is completely off the left margin of the
15767 window. This should not happen because of the
15768 move_it_in_display_line at the start of this
15769 function, unless the text display area of the
15770 window is empty. */
15771 xassert (it
->first_visible_x
<= it
->last_visible_x
);
15775 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15776 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15777 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15778 row
->phys_height
= max (row
->phys_height
,
15779 it
->max_phys_ascent
+ it
->max_phys_descent
);
15780 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15781 it
->max_extra_line_spacing
);
15783 /* End of this display line if row is continued. */
15784 if (row
->continued_p
|| row
->ends_at_zv_p
)
15789 /* Is this a line end? If yes, we're also done, after making
15790 sure that a non-default face is extended up to the right
15791 margin of the window. */
15792 if (ITERATOR_AT_END_OF_LINE_P (it
))
15794 int used_before
= row
->used
[TEXT_AREA
];
15796 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
15798 #ifdef HAVE_WINDOW_SYSTEM
15799 /* Add a space at the end of the line that is used to
15800 display the cursor there. */
15801 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15802 append_space_for_newline (it
, 0);
15803 #endif /* HAVE_WINDOW_SYSTEM */
15805 /* Extend the face to the end of the line. */
15806 extend_face_to_end_of_line (it
);
15808 /* Make sure we have the position. */
15809 if (used_before
== 0)
15810 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
15812 /* Consume the line end. This skips over invisible lines. */
15813 set_iterator_to_next (it
, 1);
15814 it
->continuation_lines_width
= 0;
15818 /* Proceed with next display element. Note that this skips
15819 over lines invisible because of selective display. */
15820 set_iterator_to_next (it
, 1);
15822 /* If we truncate lines, we are done when the last displayed
15823 glyphs reach past the right margin of the window. */
15824 if (it
->truncate_lines_p
15825 && (FRAME_WINDOW_P (it
->f
)
15826 ? (it
->current_x
>= it
->last_visible_x
)
15827 : (it
->current_x
> it
->last_visible_x
)))
15829 /* Maybe add truncation glyphs. */
15830 if (!FRAME_WINDOW_P (it
->f
))
15834 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15835 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15838 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15840 row
->used
[TEXT_AREA
] = i
;
15841 produce_special_glyphs (it
, IT_TRUNCATION
);
15844 #ifdef HAVE_WINDOW_SYSTEM
15847 /* Don't truncate if we can overflow newline into fringe. */
15848 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15850 if (!get_next_display_element (it
))
15852 it
->continuation_lines_width
= 0;
15853 row
->ends_at_zv_p
= 1;
15854 row
->exact_window_width_line_p
= 1;
15857 if (ITERATOR_AT_END_OF_LINE_P (it
))
15859 row
->exact_window_width_line_p
= 1;
15860 goto at_end_of_line
;
15864 #endif /* HAVE_WINDOW_SYSTEM */
15866 row
->truncated_on_right_p
= 1;
15867 it
->continuation_lines_width
= 0;
15868 reseat_at_next_visible_line_start (it
, 0);
15869 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
15870 it
->hpos
= hpos_before
;
15871 it
->current_x
= x_before
;
15876 /* If line is not empty and hscrolled, maybe insert truncation glyphs
15877 at the left window margin. */
15878 if (it
->first_visible_x
15879 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
15881 if (!FRAME_WINDOW_P (it
->f
))
15882 insert_left_trunc_glyphs (it
);
15883 row
->truncated_on_left_p
= 1;
15886 /* If the start of this line is the overlay arrow-position, then
15887 mark this glyph row as the one containing the overlay arrow.
15888 This is clearly a mess with variable size fonts. It would be
15889 better to let it be displayed like cursors under X. */
15890 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
15891 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
15892 !NILP (overlay_arrow_string
)))
15894 /* Overlay arrow in window redisplay is a fringe bitmap. */
15895 if (STRINGP (overlay_arrow_string
))
15897 struct glyph_row
*arrow_row
15898 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
15899 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
15900 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
15901 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
15902 struct glyph
*p2
, *end
;
15904 /* Copy the arrow glyphs. */
15905 while (glyph
< arrow_end
)
15908 /* Throw away padding glyphs. */
15910 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15911 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
15917 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
15922 xassert (INTEGERP (overlay_arrow_string
));
15923 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
15925 overlay_arrow_seen
= 1;
15928 /* Compute pixel dimensions of this line. */
15929 compute_line_metrics (it
);
15931 /* Remember the position at which this line ends. */
15932 row
->end
= it
->current
;
15934 /* Record whether this row ends inside an ellipsis. */
15935 row
->ends_in_ellipsis_p
15936 = (it
->method
== GET_FROM_DISPLAY_VECTOR
15937 && it
->ellipsis_p
);
15939 /* Save fringe bitmaps in this row. */
15940 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
15941 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
15942 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
15943 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
15945 it
->left_user_fringe_bitmap
= 0;
15946 it
->left_user_fringe_face_id
= 0;
15947 it
->right_user_fringe_bitmap
= 0;
15948 it
->right_user_fringe_face_id
= 0;
15950 /* Maybe set the cursor. */
15951 if (it
->w
->cursor
.vpos
< 0
15952 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
15953 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15954 && cursor_row_p (it
->w
, row
))
15955 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
15957 /* Highlight trailing whitespace. */
15958 if (!NILP (Vshow_trailing_whitespace
))
15959 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
15961 /* Prepare for the next line. This line starts horizontally at (X
15962 HPOS) = (0 0). Vertical positions are incremented. As a
15963 convenience for the caller, IT->glyph_row is set to the next
15965 it
->current_x
= it
->hpos
= 0;
15966 it
->current_y
+= row
->height
;
15969 it
->start
= it
->current
;
15970 return row
->displays_text_p
;
15975 /***********************************************************************
15977 ***********************************************************************/
15979 /* Redisplay the menu bar in the frame for window W.
15981 The menu bar of X frames that don't have X toolkit support is
15982 displayed in a special window W->frame->menu_bar_window.
15984 The menu bar of terminal frames is treated specially as far as
15985 glyph matrices are concerned. Menu bar lines are not part of
15986 windows, so the update is done directly on the frame matrix rows
15987 for the menu bar. */
15990 display_menu_bar (w
)
15993 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15998 /* Don't do all this for graphical frames. */
16000 if (!NILP (Vwindow_system
))
16003 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
16008 if (FRAME_MAC_P (f
))
16012 #ifdef USE_X_TOOLKIT
16013 xassert (!FRAME_WINDOW_P (f
));
16014 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
16015 it
.first_visible_x
= 0;
16016 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16017 #else /* not USE_X_TOOLKIT */
16018 if (FRAME_WINDOW_P (f
))
16020 /* Menu bar lines are displayed in the desired matrix of the
16021 dummy window menu_bar_window. */
16022 struct window
*menu_w
;
16023 xassert (WINDOWP (f
->menu_bar_window
));
16024 menu_w
= XWINDOW (f
->menu_bar_window
);
16025 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
16027 it
.first_visible_x
= 0;
16028 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16032 /* This is a TTY frame, i.e. character hpos/vpos are used as
16034 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
16036 it
.first_visible_x
= 0;
16037 it
.last_visible_x
= FRAME_COLS (f
);
16039 #endif /* not USE_X_TOOLKIT */
16041 if (! mode_line_inverse_video
)
16042 /* Force the menu-bar to be displayed in the default face. */
16043 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16045 /* Clear all rows of the menu bar. */
16046 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
16048 struct glyph_row
*row
= it
.glyph_row
+ i
;
16049 clear_glyph_row (row
);
16050 row
->enabled_p
= 1;
16051 row
->full_width_p
= 1;
16054 /* Display all items of the menu bar. */
16055 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
16056 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
16058 Lisp_Object string
;
16060 /* Stop at nil string. */
16061 string
= AREF (items
, i
+ 1);
16065 /* Remember where item was displayed. */
16066 AREF (items
, i
+ 3) = make_number (it
.hpos
);
16068 /* Display the item, pad with one space. */
16069 if (it
.current_x
< it
.last_visible_x
)
16070 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
16071 SCHARS (string
) + 1, 0, 0, -1);
16074 /* Fill out the line with spaces. */
16075 if (it
.current_x
< it
.last_visible_x
)
16076 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
16078 /* Compute the total height of the lines. */
16079 compute_line_metrics (&it
);
16084 /***********************************************************************
16086 ***********************************************************************/
16088 /* Redisplay mode lines in the window tree whose root is WINDOW. If
16089 FORCE is non-zero, redisplay mode lines unconditionally.
16090 Otherwise, redisplay only mode lines that are garbaged. Value is
16091 the number of windows whose mode lines were redisplayed. */
16094 redisplay_mode_lines (window
, force
)
16095 Lisp_Object window
;
16100 while (!NILP (window
))
16102 struct window
*w
= XWINDOW (window
);
16104 if (WINDOWP (w
->hchild
))
16105 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
16106 else if (WINDOWP (w
->vchild
))
16107 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
16109 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
16110 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
16112 struct text_pos lpoint
;
16113 struct buffer
*old
= current_buffer
;
16115 /* Set the window's buffer for the mode line display. */
16116 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16117 set_buffer_internal_1 (XBUFFER (w
->buffer
));
16119 /* Point refers normally to the selected window. For any
16120 other window, set up appropriate value. */
16121 if (!EQ (window
, selected_window
))
16123 struct text_pos pt
;
16125 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
16126 if (CHARPOS (pt
) < BEGV
)
16127 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16128 else if (CHARPOS (pt
) > (ZV
- 1))
16129 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
16131 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
16134 /* Display mode lines. */
16135 clear_glyph_matrix (w
->desired_matrix
);
16136 if (display_mode_lines (w
))
16139 w
->must_be_updated_p
= 1;
16142 /* Restore old settings. */
16143 set_buffer_internal_1 (old
);
16144 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16154 /* Display the mode and/or top line of window W. Value is the number
16155 of mode lines displayed. */
16158 display_mode_lines (w
)
16161 Lisp_Object old_selected_window
, old_selected_frame
;
16164 old_selected_frame
= selected_frame
;
16165 selected_frame
= w
->frame
;
16166 old_selected_window
= selected_window
;
16167 XSETWINDOW (selected_window
, w
);
16169 /* These will be set while the mode line specs are processed. */
16170 line_number_displayed
= 0;
16171 w
->column_number_displayed
= Qnil
;
16173 if (WINDOW_WANTS_MODELINE_P (w
))
16175 struct window
*sel_w
= XWINDOW (old_selected_window
);
16177 /* Select mode line face based on the real selected window. */
16178 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
16179 current_buffer
->mode_line_format
);
16183 if (WINDOW_WANTS_HEADER_LINE_P (w
))
16185 display_mode_line (w
, HEADER_LINE_FACE_ID
,
16186 current_buffer
->header_line_format
);
16190 selected_frame
= old_selected_frame
;
16191 selected_window
= old_selected_window
;
16196 /* Display mode or top line of window W. FACE_ID specifies which line
16197 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
16198 FORMAT is the mode line format to display. Value is the pixel
16199 height of the mode line displayed. */
16202 display_mode_line (w
, face_id
, format
)
16204 enum face_id face_id
;
16205 Lisp_Object format
;
16209 int count
= SPECPDL_INDEX ();
16211 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16212 prepare_desired_row (it
.glyph_row
);
16214 it
.glyph_row
->mode_line_p
= 1;
16216 if (! mode_line_inverse_video
)
16217 /* Force the mode-line to be displayed in the default face. */
16218 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16220 record_unwind_protect (unwind_format_mode_line
,
16221 format_mode_line_unwind_data (NULL
, 0));
16223 mode_line_target
= MODE_LINE_DISPLAY
;
16225 /* Temporarily make frame's keyboard the current kboard so that
16226 kboard-local variables in the mode_line_format will get the right
16228 push_frame_kboard (it
.f
);
16229 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16230 pop_frame_kboard ();
16232 unbind_to (count
, Qnil
);
16234 /* Fill up with spaces. */
16235 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
16237 compute_line_metrics (&it
);
16238 it
.glyph_row
->full_width_p
= 1;
16239 it
.glyph_row
->continued_p
= 0;
16240 it
.glyph_row
->truncated_on_left_p
= 0;
16241 it
.glyph_row
->truncated_on_right_p
= 0;
16243 /* Make a 3D mode-line have a shadow at its right end. */
16244 face
= FACE_FROM_ID (it
.f
, face_id
);
16245 extend_face_to_end_of_line (&it
);
16246 if (face
->box
!= FACE_NO_BOX
)
16248 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
16249 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
16250 last
->right_box_line_p
= 1;
16253 return it
.glyph_row
->height
;
16256 /* Move element ELT in LIST to the front of LIST.
16257 Return the updated list. */
16260 move_elt_to_front (elt
, list
)
16261 Lisp_Object elt
, list
;
16263 register Lisp_Object tail
, prev
;
16264 register Lisp_Object tem
;
16268 while (CONSP (tail
))
16274 /* Splice out the link TAIL. */
16276 list
= XCDR (tail
);
16278 Fsetcdr (prev
, XCDR (tail
));
16280 /* Now make it the first. */
16281 Fsetcdr (tail
, list
);
16286 tail
= XCDR (tail
);
16290 /* Not found--return unchanged LIST. */
16294 /* Contribute ELT to the mode line for window IT->w. How it
16295 translates into text depends on its data type.
16297 IT describes the display environment in which we display, as usual.
16299 DEPTH is the depth in recursion. It is used to prevent
16300 infinite recursion here.
16302 FIELD_WIDTH is the number of characters the display of ELT should
16303 occupy in the mode line, and PRECISION is the maximum number of
16304 characters to display from ELT's representation. See
16305 display_string for details.
16307 Returns the hpos of the end of the text generated by ELT.
16309 PROPS is a property list to add to any string we encounter.
16311 If RISKY is nonzero, remove (disregard) any properties in any string
16312 we encounter, and ignore :eval and :propertize.
16314 The global variable `mode_line_target' determines whether the
16315 output is passed to `store_mode_line_noprop',
16316 `store_mode_line_string', or `display_string'. */
16319 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
16322 int field_width
, precision
;
16323 Lisp_Object elt
, props
;
16326 int n
= 0, field
, prec
;
16331 elt
= build_string ("*too-deep*");
16335 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
16339 /* A string: output it and check for %-constructs within it. */
16343 if (SCHARS (elt
) > 0
16344 && (!NILP (props
) || risky
))
16346 Lisp_Object oprops
, aelt
;
16347 oprops
= Ftext_properties_at (make_number (0), elt
);
16349 /* If the starting string's properties are not what
16350 we want, translate the string. Also, if the string
16351 is risky, do that anyway. */
16353 if (NILP (Fequal (props
, oprops
)) || risky
)
16355 /* If the starting string has properties,
16356 merge the specified ones onto the existing ones. */
16357 if (! NILP (oprops
) && !risky
)
16361 oprops
= Fcopy_sequence (oprops
);
16363 while (CONSP (tem
))
16365 oprops
= Fplist_put (oprops
, XCAR (tem
),
16366 XCAR (XCDR (tem
)));
16367 tem
= XCDR (XCDR (tem
));
16372 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
16373 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
16375 /* AELT is what we want. Move it to the front
16376 without consing. */
16378 mode_line_proptrans_alist
16379 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
16385 /* If AELT has the wrong props, it is useless.
16386 so get rid of it. */
16388 mode_line_proptrans_alist
16389 = Fdelq (aelt
, mode_line_proptrans_alist
);
16391 elt
= Fcopy_sequence (elt
);
16392 Fset_text_properties (make_number (0), Flength (elt
),
16394 /* Add this item to mode_line_proptrans_alist. */
16395 mode_line_proptrans_alist
16396 = Fcons (Fcons (elt
, props
),
16397 mode_line_proptrans_alist
);
16398 /* Truncate mode_line_proptrans_alist
16399 to at most 50 elements. */
16400 tem
= Fnthcdr (make_number (50),
16401 mode_line_proptrans_alist
);
16403 XSETCDR (tem
, Qnil
);
16412 prec
= precision
- n
;
16413 switch (mode_line_target
)
16415 case MODE_LINE_NOPROP
:
16416 case MODE_LINE_TITLE
:
16417 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
16419 case MODE_LINE_STRING
:
16420 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
16422 case MODE_LINE_DISPLAY
:
16423 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
16424 0, prec
, 0, STRING_MULTIBYTE (elt
));
16431 /* Handle the non-literal case. */
16433 while ((precision
<= 0 || n
< precision
)
16434 && SREF (elt
, offset
) != 0
16435 && (mode_line_target
!= MODE_LINE_DISPLAY
16436 || it
->current_x
< it
->last_visible_x
))
16438 int last_offset
= offset
;
16440 /* Advance to end of string or next format specifier. */
16441 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
16444 if (offset
- 1 != last_offset
)
16446 int nchars
, nbytes
;
16448 /* Output to end of string or up to '%'. Field width
16449 is length of string. Don't output more than
16450 PRECISION allows us. */
16453 prec
= c_string_width (SDATA (elt
) + last_offset
,
16454 offset
- last_offset
, precision
- n
,
16457 switch (mode_line_target
)
16459 case MODE_LINE_NOPROP
:
16460 case MODE_LINE_TITLE
:
16461 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
16463 case MODE_LINE_STRING
:
16465 int bytepos
= last_offset
;
16466 int charpos
= string_byte_to_char (elt
, bytepos
);
16467 int endpos
= (precision
<= 0
16468 ? string_byte_to_char (elt
, offset
)
16469 : charpos
+ nchars
);
16471 n
+= store_mode_line_string (NULL
,
16472 Fsubstring (elt
, make_number (charpos
),
16473 make_number (endpos
)),
16477 case MODE_LINE_DISPLAY
:
16479 int bytepos
= last_offset
;
16480 int charpos
= string_byte_to_char (elt
, bytepos
);
16482 if (precision
<= 0)
16483 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
16484 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
16486 STRING_MULTIBYTE (elt
));
16491 else /* c == '%' */
16493 int percent_position
= offset
;
16495 /* Get the specified minimum width. Zero means
16498 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
16499 field
= field
* 10 + c
- '0';
16501 /* Don't pad beyond the total padding allowed. */
16502 if (field_width
- n
> 0 && field
> field_width
- n
)
16503 field
= field_width
- n
;
16505 /* Note that either PRECISION <= 0 or N < PRECISION. */
16506 prec
= precision
- n
;
16509 n
+= display_mode_element (it
, depth
, field
, prec
,
16510 Vglobal_mode_string
, props
,
16515 int bytepos
, charpos
;
16516 unsigned char *spec
;
16518 bytepos
= percent_position
;
16519 charpos
= (STRING_MULTIBYTE (elt
)
16520 ? string_byte_to_char (elt
, bytepos
)
16524 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
16526 switch (mode_line_target
)
16528 case MODE_LINE_NOPROP
:
16529 case MODE_LINE_TITLE
:
16530 n
+= store_mode_line_noprop (spec
, field
, prec
);
16532 case MODE_LINE_STRING
:
16534 int len
= strlen (spec
);
16535 Lisp_Object tem
= make_string (spec
, len
);
16536 props
= Ftext_properties_at (make_number (charpos
), elt
);
16537 /* Should only keep face property in props */
16538 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
16541 case MODE_LINE_DISPLAY
:
16543 int nglyphs_before
, nwritten
;
16545 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16546 nwritten
= display_string (spec
, Qnil
, elt
,
16551 /* Assign to the glyphs written above the
16552 string where the `%x' came from, position
16556 struct glyph
*glyph
16557 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
16561 for (i
= 0; i
< nwritten
; ++i
)
16563 glyph
[i
].object
= elt
;
16564 glyph
[i
].charpos
= charpos
;
16581 /* A symbol: process the value of the symbol recursively
16582 as if it appeared here directly. Avoid error if symbol void.
16583 Special case: if value of symbol is a string, output the string
16586 register Lisp_Object tem
;
16588 /* If the variable is not marked as risky to set
16589 then its contents are risky to use. */
16590 if (NILP (Fget (elt
, Qrisky_local_variable
)))
16593 tem
= Fboundp (elt
);
16596 tem
= Fsymbol_value (elt
);
16597 /* If value is a string, output that string literally:
16598 don't check for % within it. */
16602 if (!EQ (tem
, elt
))
16604 /* Give up right away for nil or t. */
16614 register Lisp_Object car
, tem
;
16616 /* A cons cell: five distinct cases.
16617 If first element is :eval or :propertize, do something special.
16618 If first element is a string or a cons, process all the elements
16619 and effectively concatenate them.
16620 If first element is a negative number, truncate displaying cdr to
16621 at most that many characters. If positive, pad (with spaces)
16622 to at least that many characters.
16623 If first element is a symbol, process the cadr or caddr recursively
16624 according to whether the symbol's value is non-nil or nil. */
16626 if (EQ (car
, QCeval
))
16628 /* An element of the form (:eval FORM) means evaluate FORM
16629 and use the result as mode line elements. */
16634 if (CONSP (XCDR (elt
)))
16637 spec
= safe_eval (XCAR (XCDR (elt
)));
16638 n
+= display_mode_element (it
, depth
, field_width
- n
,
16639 precision
- n
, spec
, props
,
16643 else if (EQ (car
, QCpropertize
))
16645 /* An element of the form (:propertize ELT PROPS...)
16646 means display ELT but applying properties PROPS. */
16651 if (CONSP (XCDR (elt
)))
16652 n
+= display_mode_element (it
, depth
, field_width
- n
,
16653 precision
- n
, XCAR (XCDR (elt
)),
16654 XCDR (XCDR (elt
)), risky
);
16656 else if (SYMBOLP (car
))
16658 tem
= Fboundp (car
);
16662 /* elt is now the cdr, and we know it is a cons cell.
16663 Use its car if CAR has a non-nil value. */
16666 tem
= Fsymbol_value (car
);
16673 /* Symbol's value is nil (or symbol is unbound)
16674 Get the cddr of the original list
16675 and if possible find the caddr and use that. */
16679 else if (!CONSP (elt
))
16684 else if (INTEGERP (car
))
16686 register int lim
= XINT (car
);
16690 /* Negative int means reduce maximum width. */
16691 if (precision
<= 0)
16694 precision
= min (precision
, -lim
);
16698 /* Padding specified. Don't let it be more than
16699 current maximum. */
16701 lim
= min (precision
, lim
);
16703 /* If that's more padding than already wanted, queue it.
16704 But don't reduce padding already specified even if
16705 that is beyond the current truncation point. */
16706 field_width
= max (lim
, field_width
);
16710 else if (STRINGP (car
) || CONSP (car
))
16712 register int limit
= 50;
16713 /* Limit is to protect against circular lists. */
16716 && (precision
<= 0 || n
< precision
))
16718 n
+= display_mode_element (it
, depth
,
16719 /* Do padding only after the last
16720 element in the list. */
16721 (! CONSP (XCDR (elt
))
16724 precision
- n
, XCAR (elt
),
16734 elt
= build_string ("*invalid*");
16738 /* Pad to FIELD_WIDTH. */
16739 if (field_width
> 0 && n
< field_width
)
16741 switch (mode_line_target
)
16743 case MODE_LINE_NOPROP
:
16744 case MODE_LINE_TITLE
:
16745 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
16747 case MODE_LINE_STRING
:
16748 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
16750 case MODE_LINE_DISPLAY
:
16751 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
16760 /* Store a mode-line string element in mode_line_string_list.
16762 If STRING is non-null, display that C string. Otherwise, the Lisp
16763 string LISP_STRING is displayed.
16765 FIELD_WIDTH is the minimum number of output glyphs to produce.
16766 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16767 with spaces. FIELD_WIDTH <= 0 means don't pad.
16769 PRECISION is the maximum number of characters to output from
16770 STRING. PRECISION <= 0 means don't truncate the string.
16772 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
16773 properties to the string.
16775 PROPS are the properties to add to the string.
16776 The mode_line_string_face face property is always added to the string.
16780 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
16782 Lisp_Object lisp_string
;
16791 if (string
!= NULL
)
16793 len
= strlen (string
);
16794 if (precision
> 0 && len
> precision
)
16796 lisp_string
= make_string (string
, len
);
16798 props
= mode_line_string_face_prop
;
16799 else if (!NILP (mode_line_string_face
))
16801 Lisp_Object face
= Fplist_get (props
, Qface
);
16802 props
= Fcopy_sequence (props
);
16804 face
= mode_line_string_face
;
16806 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16807 props
= Fplist_put (props
, Qface
, face
);
16809 Fadd_text_properties (make_number (0), make_number (len
),
16810 props
, lisp_string
);
16814 len
= XFASTINT (Flength (lisp_string
));
16815 if (precision
> 0 && len
> precision
)
16818 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
16821 if (!NILP (mode_line_string_face
))
16825 props
= Ftext_properties_at (make_number (0), lisp_string
);
16826 face
= Fplist_get (props
, Qface
);
16828 face
= mode_line_string_face
;
16830 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16831 props
= Fcons (Qface
, Fcons (face
, Qnil
));
16833 lisp_string
= Fcopy_sequence (lisp_string
);
16836 Fadd_text_properties (make_number (0), make_number (len
),
16837 props
, lisp_string
);
16842 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16846 if (field_width
> len
)
16848 field_width
-= len
;
16849 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
16851 Fadd_text_properties (make_number (0), make_number (field_width
),
16852 props
, lisp_string
);
16853 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16861 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
16863 doc
: /* Format a string out of a mode line format specification.
16864 First arg FORMAT specifies the mode line format (see `mode-line-format'
16865 for details) to use.
16867 Optional second arg FACE specifies the face property to put
16868 on all characters for which no face is specified.
16869 t means whatever face the window's mode line currently uses
16870 \(either `mode-line' or `mode-line-inactive', depending).
16871 nil means the default is no face property.
16872 If FACE is an integer, the value string has no text properties.
16874 Optional third and fourth args WINDOW and BUFFER specify the window
16875 and buffer to use as the context for the formatting (defaults
16876 are the selected window and the window's buffer). */)
16877 (format
, face
, window
, buffer
)
16878 Lisp_Object format
, face
, window
, buffer
;
16883 struct buffer
*old_buffer
= NULL
;
16885 int no_props
= INTEGERP (face
);
16886 int count
= SPECPDL_INDEX ();
16888 int string_start
= 0;
16891 window
= selected_window
;
16892 CHECK_WINDOW (window
);
16893 w
= XWINDOW (window
);
16896 buffer
= w
->buffer
;
16897 CHECK_BUFFER (buffer
);
16900 return build_string ("");
16908 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
16909 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
16913 face_id
= DEFAULT_FACE_ID
;
16915 if (XBUFFER (buffer
) != current_buffer
)
16916 old_buffer
= current_buffer
;
16918 /* Save things including mode_line_proptrans_alist,
16919 and set that to nil so that we don't alter the outer value. */
16920 record_unwind_protect (unwind_format_mode_line
,
16921 format_mode_line_unwind_data (old_buffer
, 1));
16922 mode_line_proptrans_alist
= Qnil
;
16925 set_buffer_internal_1 (XBUFFER (buffer
));
16927 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16931 mode_line_target
= MODE_LINE_NOPROP
;
16932 mode_line_string_face_prop
= Qnil
;
16933 mode_line_string_list
= Qnil
;
16934 string_start
= MODE_LINE_NOPROP_LEN (0);
16938 mode_line_target
= MODE_LINE_STRING
;
16939 mode_line_string_list
= Qnil
;
16940 mode_line_string_face
= face
;
16941 mode_line_string_face_prop
16942 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
16945 push_frame_kboard (it
.f
);
16946 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16947 pop_frame_kboard ();
16951 len
= MODE_LINE_NOPROP_LEN (string_start
);
16952 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
16956 mode_line_string_list
= Fnreverse (mode_line_string_list
);
16957 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
16958 make_string ("", 0));
16961 unbind_to (count
, Qnil
);
16965 /* Write a null-terminated, right justified decimal representation of
16966 the positive integer D to BUF using a minimal field width WIDTH. */
16969 pint2str (buf
, width
, d
)
16970 register char *buf
;
16971 register int width
;
16974 register char *p
= buf
;
16982 *p
++ = d
% 10 + '0';
16987 for (width
-= (int) (p
- buf
); width
> 0; --width
)
16998 /* Write a null-terminated, right justified decimal and "human
16999 readable" representation of the nonnegative integer D to BUF using
17000 a minimal field width WIDTH. D should be smaller than 999.5e24. */
17002 static const char power_letter
[] =
17016 pint2hrstr (buf
, width
, d
)
17021 /* We aim to represent the nonnegative integer D as
17022 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
17025 /* -1 means: do not use TENTHS. */
17029 /* Length of QUOTIENT.TENTHS as a string. */
17035 if (1000 <= quotient
)
17037 /* Scale to the appropriate EXPONENT. */
17040 remainder
= quotient
% 1000;
17044 while (1000 <= quotient
);
17046 /* Round to nearest and decide whether to use TENTHS or not. */
17049 tenths
= remainder
/ 100;
17050 if (50 <= remainder
% 100)
17057 if (quotient
== 10)
17065 if (500 <= remainder
)
17067 if (quotient
< 999)
17078 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
17079 if (tenths
== -1 && quotient
<= 99)
17086 p
= psuffix
= buf
+ max (width
, length
);
17088 /* Print EXPONENT. */
17090 *psuffix
++ = power_letter
[exponent
];
17093 /* Print TENTHS. */
17096 *--p
= '0' + tenths
;
17100 /* Print QUOTIENT. */
17103 int digit
= quotient
% 10;
17104 *--p
= '0' + digit
;
17106 while ((quotient
/= 10) != 0);
17108 /* Print leading spaces. */
17113 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
17114 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
17115 type of CODING_SYSTEM. Return updated pointer into BUF. */
17117 static unsigned char invalid_eol_type
[] = "(*invalid*)";
17120 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
17121 Lisp_Object coding_system
;
17122 register char *buf
;
17126 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
17127 const unsigned char *eol_str
;
17129 /* The EOL conversion we are using. */
17130 Lisp_Object eoltype
;
17132 val
= Fget (coding_system
, Qcoding_system
);
17135 if (!VECTORP (val
)) /* Not yet decided. */
17140 eoltype
= eol_mnemonic_undecided
;
17141 /* Don't mention EOL conversion if it isn't decided. */
17145 Lisp_Object eolvalue
;
17147 eolvalue
= Fget (coding_system
, Qeol_type
);
17150 *buf
++ = XFASTINT (AREF (val
, 1));
17154 /* The EOL conversion that is normal on this system. */
17156 if (NILP (eolvalue
)) /* Not yet decided. */
17157 eoltype
= eol_mnemonic_undecided
;
17158 else if (VECTORP (eolvalue
)) /* Not yet decided. */
17159 eoltype
= eol_mnemonic_undecided
;
17160 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
17161 eoltype
= (XFASTINT (eolvalue
) == 0
17162 ? eol_mnemonic_unix
17163 : (XFASTINT (eolvalue
) == 1
17164 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
17170 /* Mention the EOL conversion if it is not the usual one. */
17171 if (STRINGP (eoltype
))
17173 eol_str
= SDATA (eoltype
);
17174 eol_str_len
= SBYTES (eoltype
);
17176 else if (INTEGERP (eoltype
)
17177 && CHAR_VALID_P (XINT (eoltype
), 0))
17179 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
17180 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
17185 eol_str
= invalid_eol_type
;
17186 eol_str_len
= sizeof (invalid_eol_type
) - 1;
17188 bcopy (eol_str
, buf
, eol_str_len
);
17189 buf
+= eol_str_len
;
17195 /* Return a string for the output of a mode line %-spec for window W,
17196 generated by character C. PRECISION >= 0 means don't return a
17197 string longer than that value. FIELD_WIDTH > 0 means pad the
17198 string returned with spaces to that value. Return 1 in *MULTIBYTE
17199 if the result is multibyte text.
17201 Note we operate on the current buffer for most purposes,
17202 the exception being w->base_line_pos. */
17204 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
17207 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
17210 int field_width
, precision
;
17214 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17215 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
17216 struct buffer
*b
= current_buffer
;
17224 if (!NILP (b
->read_only
))
17226 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17231 /* This differs from %* only for a modified read-only buffer. */
17232 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17234 if (!NILP (b
->read_only
))
17239 /* This differs from %* in ignoring read-only-ness. */
17240 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17252 if (command_loop_level
> 5)
17254 p
= decode_mode_spec_buf
;
17255 for (i
= 0; i
< command_loop_level
; i
++)
17258 return decode_mode_spec_buf
;
17266 if (command_loop_level
> 5)
17268 p
= decode_mode_spec_buf
;
17269 for (i
= 0; i
< command_loop_level
; i
++)
17272 return decode_mode_spec_buf
;
17279 /* Let lots_of_dashes be a string of infinite length. */
17280 if (mode_line_target
== MODE_LINE_NOPROP
||
17281 mode_line_target
== MODE_LINE_STRING
)
17283 if (field_width
<= 0
17284 || field_width
> sizeof (lots_of_dashes
))
17286 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
17287 decode_mode_spec_buf
[i
] = '-';
17288 decode_mode_spec_buf
[i
] = '\0';
17289 return decode_mode_spec_buf
;
17292 return lots_of_dashes
;
17301 int col
= (int) current_column (); /* iftc */
17302 w
->column_number_displayed
= make_number (col
);
17303 pint2str (decode_mode_spec_buf
, field_width
, col
);
17304 return decode_mode_spec_buf
;
17308 #ifndef SYSTEM_MALLOC
17310 if (NILP (Vmemory_full
))
17313 return "!MEM FULL! ";
17320 /* %F displays the frame name. */
17321 if (!NILP (f
->title
))
17322 return (char *) SDATA (f
->title
);
17323 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
17324 return (char *) SDATA (f
->name
);
17333 int size
= ZV
- BEGV
;
17334 pint2str (decode_mode_spec_buf
, field_width
, size
);
17335 return decode_mode_spec_buf
;
17340 int size
= ZV
- BEGV
;
17341 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
17342 return decode_mode_spec_buf
;
17347 int startpos
= XMARKER (w
->start
)->charpos
;
17348 int startpos_byte
= marker_byte_position (w
->start
);
17349 int line
, linepos
, linepos_byte
, topline
;
17351 int height
= WINDOW_TOTAL_LINES (w
);
17353 /* If we decided that this buffer isn't suitable for line numbers,
17354 don't forget that too fast. */
17355 if (EQ (w
->base_line_pos
, w
->buffer
))
17357 /* But do forget it, if the window shows a different buffer now. */
17358 else if (BUFFERP (w
->base_line_pos
))
17359 w
->base_line_pos
= Qnil
;
17361 /* If the buffer is very big, don't waste time. */
17362 if (INTEGERP (Vline_number_display_limit
)
17363 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
17365 w
->base_line_pos
= Qnil
;
17366 w
->base_line_number
= Qnil
;
17370 if (!NILP (w
->base_line_number
)
17371 && !NILP (w
->base_line_pos
)
17372 && XFASTINT (w
->base_line_pos
) <= startpos
)
17374 line
= XFASTINT (w
->base_line_number
);
17375 linepos
= XFASTINT (w
->base_line_pos
);
17376 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
17381 linepos
= BUF_BEGV (b
);
17382 linepos_byte
= BUF_BEGV_BYTE (b
);
17385 /* Count lines from base line to window start position. */
17386 nlines
= display_count_lines (linepos
, linepos_byte
,
17390 topline
= nlines
+ line
;
17392 /* Determine a new base line, if the old one is too close
17393 or too far away, or if we did not have one.
17394 "Too close" means it's plausible a scroll-down would
17395 go back past it. */
17396 if (startpos
== BUF_BEGV (b
))
17398 w
->base_line_number
= make_number (topline
);
17399 w
->base_line_pos
= make_number (BUF_BEGV (b
));
17401 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
17402 || linepos
== BUF_BEGV (b
))
17404 int limit
= BUF_BEGV (b
);
17405 int limit_byte
= BUF_BEGV_BYTE (b
);
17407 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
17409 if (startpos
- distance
> limit
)
17411 limit
= startpos
- distance
;
17412 limit_byte
= CHAR_TO_BYTE (limit
);
17415 nlines
= display_count_lines (startpos
, startpos_byte
,
17417 - (height
* 2 + 30),
17419 /* If we couldn't find the lines we wanted within
17420 line_number_display_limit_width chars per line,
17421 give up on line numbers for this window. */
17422 if (position
== limit_byte
&& limit
== startpos
- distance
)
17424 w
->base_line_pos
= w
->buffer
;
17425 w
->base_line_number
= Qnil
;
17429 w
->base_line_number
= make_number (topline
- nlines
);
17430 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
17433 /* Now count lines from the start pos to point. */
17434 nlines
= display_count_lines (startpos
, startpos_byte
,
17435 PT_BYTE
, PT
, &junk
);
17437 /* Record that we did display the line number. */
17438 line_number_displayed
= 1;
17440 /* Make the string to show. */
17441 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
17442 return decode_mode_spec_buf
;
17445 char* p
= decode_mode_spec_buf
;
17446 int pad
= field_width
- 2;
17452 return decode_mode_spec_buf
;
17458 obj
= b
->mode_name
;
17462 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
17468 int pos
= marker_position (w
->start
);
17469 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17471 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
17473 if (pos
<= BUF_BEGV (b
))
17478 else if (pos
<= BUF_BEGV (b
))
17482 if (total
> 1000000)
17483 /* Do it differently for a large value, to avoid overflow. */
17484 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17486 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17487 /* We can't normally display a 3-digit number,
17488 so get us a 2-digit number that is close. */
17491 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17492 return decode_mode_spec_buf
;
17496 /* Display percentage of size above the bottom of the screen. */
17499 int toppos
= marker_position (w
->start
);
17500 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
17501 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17503 if (botpos
>= BUF_ZV (b
))
17505 if (toppos
<= BUF_BEGV (b
))
17512 if (total
> 1000000)
17513 /* Do it differently for a large value, to avoid overflow. */
17514 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17516 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17517 /* We can't normally display a 3-digit number,
17518 so get us a 2-digit number that is close. */
17521 if (toppos
<= BUF_BEGV (b
))
17522 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
17524 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17525 return decode_mode_spec_buf
;
17530 /* status of process */
17531 obj
= Fget_buffer_process (Fcurrent_buffer ());
17533 return "no process";
17534 #ifdef subprocesses
17535 obj
= Fsymbol_name (Fprocess_status (obj
));
17539 case 't': /* indicate TEXT or BINARY */
17540 #ifdef MODE_LINE_BINARY_TEXT
17541 return MODE_LINE_BINARY_TEXT (b
);
17547 /* coding-system (not including end-of-line format) */
17549 /* coding-system (including end-of-line type) */
17551 int eol_flag
= (c
== 'Z');
17552 char *p
= decode_mode_spec_buf
;
17554 if (! FRAME_WINDOW_P (f
))
17556 /* No need to mention EOL here--the terminal never needs
17557 to do EOL conversion. */
17558 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
17559 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
17561 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
17564 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
17565 #ifdef subprocesses
17566 obj
= Fget_buffer_process (Fcurrent_buffer ());
17567 if (PROCESSP (obj
))
17569 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
17571 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
17574 #endif /* subprocesses */
17577 return decode_mode_spec_buf
;
17583 *multibyte
= STRING_MULTIBYTE (obj
);
17584 return (char *) SDATA (obj
);
17591 /* Count up to COUNT lines starting from START / START_BYTE.
17592 But don't go beyond LIMIT_BYTE.
17593 Return the number of lines thus found (always nonnegative).
17595 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
17598 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
17599 int start
, start_byte
, limit_byte
, count
;
17602 register unsigned char *cursor
;
17603 unsigned char *base
;
17605 register int ceiling
;
17606 register unsigned char *ceiling_addr
;
17607 int orig_count
= count
;
17609 /* If we are not in selective display mode,
17610 check only for newlines. */
17611 int selective_display
= (!NILP (current_buffer
->selective_display
)
17612 && !INTEGERP (current_buffer
->selective_display
));
17616 while (start_byte
< limit_byte
)
17618 ceiling
= BUFFER_CEILING_OF (start_byte
);
17619 ceiling
= min (limit_byte
- 1, ceiling
);
17620 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
17621 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
17624 if (selective_display
)
17625 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
17628 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
17631 if (cursor
!= ceiling_addr
)
17635 start_byte
+= cursor
- base
+ 1;
17636 *byte_pos_ptr
= start_byte
;
17640 if (++cursor
== ceiling_addr
)
17646 start_byte
+= cursor
- base
;
17651 while (start_byte
> limit_byte
)
17653 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
17654 ceiling
= max (limit_byte
, ceiling
);
17655 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
17656 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
17659 if (selective_display
)
17660 while (--cursor
!= ceiling_addr
17661 && *cursor
!= '\n' && *cursor
!= 015)
17664 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
17667 if (cursor
!= ceiling_addr
)
17671 start_byte
+= cursor
- base
+ 1;
17672 *byte_pos_ptr
= start_byte
;
17673 /* When scanning backwards, we should
17674 not count the newline posterior to which we stop. */
17675 return - orig_count
- 1;
17681 /* Here we add 1 to compensate for the last decrement
17682 of CURSOR, which took it past the valid range. */
17683 start_byte
+= cursor
- base
+ 1;
17687 *byte_pos_ptr
= limit_byte
;
17690 return - orig_count
+ count
;
17691 return orig_count
- count
;
17697 /***********************************************************************
17699 ***********************************************************************/
17701 /* Display a NUL-terminated string, starting with index START.
17703 If STRING is non-null, display that C string. Otherwise, the Lisp
17704 string LISP_STRING is displayed.
17706 If FACE_STRING is not nil, FACE_STRING_POS is a position in
17707 FACE_STRING. Display STRING or LISP_STRING with the face at
17708 FACE_STRING_POS in FACE_STRING:
17710 Display the string in the environment given by IT, but use the
17711 standard display table, temporarily.
17713 FIELD_WIDTH is the minimum number of output glyphs to produce.
17714 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17715 with spaces. If STRING has more characters, more than FIELD_WIDTH
17716 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
17718 PRECISION is the maximum number of characters to output from
17719 STRING. PRECISION < 0 means don't truncate the string.
17721 This is roughly equivalent to printf format specifiers:
17723 FIELD_WIDTH PRECISION PRINTF
17724 ----------------------------------------
17730 MULTIBYTE zero means do not display multibyte chars, > 0 means do
17731 display them, and < 0 means obey the current buffer's value of
17732 enable_multibyte_characters.
17734 Value is the number of columns displayed. */
17737 display_string (string
, lisp_string
, face_string
, face_string_pos
,
17738 start
, it
, field_width
, precision
, max_x
, multibyte
)
17739 unsigned char *string
;
17740 Lisp_Object lisp_string
;
17741 Lisp_Object face_string
;
17742 int face_string_pos
;
17745 int field_width
, precision
, max_x
;
17748 int hpos_at_start
= it
->hpos
;
17749 int saved_face_id
= it
->face_id
;
17750 struct glyph_row
*row
= it
->glyph_row
;
17752 /* Initialize the iterator IT for iteration over STRING beginning
17753 with index START. */
17754 reseat_to_string (it
, string
, lisp_string
, start
,
17755 precision
, field_width
, multibyte
);
17757 /* If displaying STRING, set up the face of the iterator
17758 from LISP_STRING, if that's given. */
17759 if (STRINGP (face_string
))
17765 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
17766 0, it
->region_beg_charpos
,
17767 it
->region_end_charpos
,
17768 &endptr
, it
->base_face_id
, 0);
17769 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17770 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
17773 /* Set max_x to the maximum allowed X position. Don't let it go
17774 beyond the right edge of the window. */
17776 max_x
= it
->last_visible_x
;
17778 max_x
= min (max_x
, it
->last_visible_x
);
17780 /* Skip over display elements that are not visible. because IT->w is
17782 if (it
->current_x
< it
->first_visible_x
)
17783 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
17784 MOVE_TO_POS
| MOVE_TO_X
);
17786 row
->ascent
= it
->max_ascent
;
17787 row
->height
= it
->max_ascent
+ it
->max_descent
;
17788 row
->phys_ascent
= it
->max_phys_ascent
;
17789 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17790 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17792 /* This condition is for the case that we are called with current_x
17793 past last_visible_x. */
17794 while (it
->current_x
< max_x
)
17796 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
17798 /* Get the next display element. */
17799 if (!get_next_display_element (it
))
17802 /* Produce glyphs. */
17803 x_before
= it
->current_x
;
17804 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17805 PRODUCE_GLYPHS (it
);
17807 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
17810 while (i
< nglyphs
)
17812 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17814 if (!it
->truncate_lines_p
17815 && x
+ glyph
->pixel_width
> max_x
)
17817 /* End of continued line or max_x reached. */
17818 if (CHAR_GLYPH_PADDING_P (*glyph
))
17820 /* A wide character is unbreakable. */
17821 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17822 it
->current_x
= x_before
;
17826 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17831 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
17833 /* Glyph is at least partially visible. */
17835 if (x
< it
->first_visible_x
)
17836 it
->glyph_row
->x
= x
- it
->first_visible_x
;
17840 /* Glyph is off the left margin of the display area.
17841 Should not happen. */
17845 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17846 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17847 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17848 row
->phys_height
= max (row
->phys_height
,
17849 it
->max_phys_ascent
+ it
->max_phys_descent
);
17850 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17851 it
->max_extra_line_spacing
);
17852 x
+= glyph
->pixel_width
;
17856 /* Stop if max_x reached. */
17860 /* Stop at line ends. */
17861 if (ITERATOR_AT_END_OF_LINE_P (it
))
17863 it
->continuation_lines_width
= 0;
17867 set_iterator_to_next (it
, 1);
17869 /* Stop if truncating at the right edge. */
17870 if (it
->truncate_lines_p
17871 && it
->current_x
>= it
->last_visible_x
)
17873 /* Add truncation mark, but don't do it if the line is
17874 truncated at a padding space. */
17875 if (IT_CHARPOS (*it
) < it
->string_nchars
)
17877 if (!FRAME_WINDOW_P (it
->f
))
17881 if (it
->current_x
> it
->last_visible_x
)
17883 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17884 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17886 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17888 row
->used
[TEXT_AREA
] = i
;
17889 produce_special_glyphs (it
, IT_TRUNCATION
);
17892 produce_special_glyphs (it
, IT_TRUNCATION
);
17894 it
->glyph_row
->truncated_on_right_p
= 1;
17900 /* Maybe insert a truncation at the left. */
17901 if (it
->first_visible_x
17902 && IT_CHARPOS (*it
) > 0)
17904 if (!FRAME_WINDOW_P (it
->f
))
17905 insert_left_trunc_glyphs (it
);
17906 it
->glyph_row
->truncated_on_left_p
= 1;
17909 it
->face_id
= saved_face_id
;
17911 /* Value is number of columns displayed. */
17912 return it
->hpos
- hpos_at_start
;
17917 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
17918 appears as an element of LIST or as the car of an element of LIST.
17919 If PROPVAL is a list, compare each element against LIST in that
17920 way, and return 1/2 if any element of PROPVAL is found in LIST.
17921 Otherwise return 0. This function cannot quit.
17922 The return value is 2 if the text is invisible but with an ellipsis
17923 and 1 if it's invisible and without an ellipsis. */
17926 invisible_p (propval
, list
)
17927 register Lisp_Object propval
;
17930 register Lisp_Object tail
, proptail
;
17932 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17934 register Lisp_Object tem
;
17936 if (EQ (propval
, tem
))
17938 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
17939 return NILP (XCDR (tem
)) ? 1 : 2;
17942 if (CONSP (propval
))
17944 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
17946 Lisp_Object propelt
;
17947 propelt
= XCAR (proptail
);
17948 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17950 register Lisp_Object tem
;
17952 if (EQ (propelt
, tem
))
17954 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
17955 return NILP (XCDR (tem
)) ? 1 : 2;
17963 /* Calculate a width or height in pixels from a specification using
17964 the following elements:
17967 NUM - a (fractional) multiple of the default font width/height
17968 (NUM) - specifies exactly NUM pixels
17969 UNIT - a fixed number of pixels, see below.
17970 ELEMENT - size of a display element in pixels, see below.
17971 (NUM . SPEC) - equals NUM * SPEC
17972 (+ SPEC SPEC ...) - add pixel values
17973 (- SPEC SPEC ...) - subtract pixel values
17974 (- SPEC) - negate pixel value
17977 INT or FLOAT - a number constant
17978 SYMBOL - use symbol's (buffer local) variable binding.
17981 in - pixels per inch *)
17982 mm - pixels per 1/1000 meter *)
17983 cm - pixels per 1/100 meter *)
17984 width - width of current font in pixels.
17985 height - height of current font in pixels.
17987 *) using the ratio(s) defined in display-pixels-per-inch.
17991 left-fringe - left fringe width in pixels
17992 right-fringe - right fringe width in pixels
17994 left-margin - left margin width in pixels
17995 right-margin - right margin width in pixels
17997 scroll-bar - scroll-bar area width in pixels
18001 Pixels corresponding to 5 inches:
18004 Total width of non-text areas on left side of window (if scroll-bar is on left):
18005 '(space :width (+ left-fringe left-margin scroll-bar))
18007 Align to first text column (in header line):
18008 '(space :align-to 0)
18010 Align to middle of text area minus half the width of variable `my-image'
18011 containing a loaded image:
18012 '(space :align-to (0.5 . (- text my-image)))
18014 Width of left margin minus width of 1 character in the default font:
18015 '(space :width (- left-margin 1))
18017 Width of left margin minus width of 2 characters in the current font:
18018 '(space :width (- left-margin (2 . width)))
18020 Center 1 character over left-margin (in header line):
18021 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
18023 Different ways to express width of left fringe plus left margin minus one pixel:
18024 '(space :width (- (+ left-fringe left-margin) (1)))
18025 '(space :width (+ left-fringe left-margin (- (1))))
18026 '(space :width (+ left-fringe left-margin (-1)))
18030 #define NUMVAL(X) \
18031 ((INTEGERP (X) || FLOATP (X)) \
18036 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
18041 int width_p
, *align_to
;
18045 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
18046 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
18049 return OK_PIXELS (0);
18051 if (SYMBOLP (prop
))
18053 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18055 char *unit
= SDATA (SYMBOL_NAME (prop
));
18057 if (unit
[0] == 'i' && unit
[1] == 'n')
18059 else if (unit
[0] == 'm' && unit
[1] == 'm')
18061 else if (unit
[0] == 'c' && unit
[1] == 'm')
18068 #ifdef HAVE_WINDOW_SYSTEM
18069 if (FRAME_WINDOW_P (it
->f
)
18071 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
18072 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
18074 return OK_PIXELS (ppi
/ pixels
);
18077 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18078 || (CONSP (Vdisplay_pixels_per_inch
)
18080 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18081 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18083 return OK_PIXELS (ppi
/ pixels
);
18089 #ifdef HAVE_WINDOW_SYSTEM
18090 if (EQ (prop
, Qheight
))
18091 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
18092 if (EQ (prop
, Qwidth
))
18093 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
18095 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
18096 return OK_PIXELS (1);
18099 if (EQ (prop
, Qtext
))
18100 return OK_PIXELS (width_p
18101 ? window_box_width (it
->w
, TEXT_AREA
)
18102 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
18104 if (align_to
&& *align_to
< 0)
18107 if (EQ (prop
, Qleft
))
18108 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
18109 if (EQ (prop
, Qright
))
18110 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
18111 if (EQ (prop
, Qcenter
))
18112 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
18113 + window_box_width (it
->w
, TEXT_AREA
) / 2);
18114 if (EQ (prop
, Qleft_fringe
))
18115 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18116 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
18117 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
18118 if (EQ (prop
, Qright_fringe
))
18119 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18120 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18121 : window_box_right_offset (it
->w
, TEXT_AREA
));
18122 if (EQ (prop
, Qleft_margin
))
18123 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
18124 if (EQ (prop
, Qright_margin
))
18125 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
18126 if (EQ (prop
, Qscroll_bar
))
18127 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18129 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18130 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18131 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18136 if (EQ (prop
, Qleft_fringe
))
18137 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18138 if (EQ (prop
, Qright_fringe
))
18139 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18140 if (EQ (prop
, Qleft_margin
))
18141 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18142 if (EQ (prop
, Qright_margin
))
18143 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18144 if (EQ (prop
, Qscroll_bar
))
18145 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18148 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18151 if (INTEGERP (prop
) || FLOATP (prop
))
18153 int base_unit
= (width_p
18154 ? FRAME_COLUMN_WIDTH (it
->f
)
18155 : FRAME_LINE_HEIGHT (it
->f
));
18156 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18161 Lisp_Object car
= XCAR (prop
);
18162 Lisp_Object cdr
= XCDR (prop
);
18166 #ifdef HAVE_WINDOW_SYSTEM
18167 if (valid_image_p (prop
))
18169 int id
= lookup_image (it
->f
, prop
);
18170 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
18172 return OK_PIXELS (width_p
? img
->width
: img
->height
);
18175 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18181 while (CONSP (cdr
))
18183 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
18184 font
, width_p
, align_to
))
18187 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18192 if (EQ (car
, Qminus
))
18194 return OK_PIXELS (pixels
);
18197 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18200 if (INTEGERP (car
) || FLOATP (car
))
18203 pixels
= XFLOATINT (car
);
18205 return OK_PIXELS (pixels
);
18206 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
18207 font
, width_p
, align_to
))
18208 return OK_PIXELS (pixels
* fact
);
18219 /***********************************************************************
18221 ***********************************************************************/
18223 #ifdef HAVE_WINDOW_SYSTEM
18228 dump_glyph_string (s
)
18229 struct glyph_string
*s
;
18231 fprintf (stderr
, "glyph string\n");
18232 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
18233 s
->x
, s
->y
, s
->width
, s
->height
);
18234 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
18235 fprintf (stderr
, " hl = %d\n", s
->hl
);
18236 fprintf (stderr
, " left overhang = %d, right = %d\n",
18237 s
->left_overhang
, s
->right_overhang
);
18238 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
18239 fprintf (stderr
, " extends to end of line = %d\n",
18240 s
->extends_to_end_of_line_p
);
18241 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
18242 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
18245 #endif /* GLYPH_DEBUG */
18247 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
18248 of XChar2b structures for S; it can't be allocated in
18249 init_glyph_string because it must be allocated via `alloca'. W
18250 is the window on which S is drawn. ROW and AREA are the glyph row
18251 and area within the row from which S is constructed. START is the
18252 index of the first glyph structure covered by S. HL is a
18253 face-override for drawing S. */
18256 #define OPTIONAL_HDC(hdc) hdc,
18257 #define DECLARE_HDC(hdc) HDC hdc;
18258 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
18259 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
18262 #ifndef OPTIONAL_HDC
18263 #define OPTIONAL_HDC(hdc)
18264 #define DECLARE_HDC(hdc)
18265 #define ALLOCATE_HDC(hdc, f)
18266 #define RELEASE_HDC(hdc, f)
18270 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
18271 struct glyph_string
*s
;
18275 struct glyph_row
*row
;
18276 enum glyph_row_area area
;
18278 enum draw_glyphs_face hl
;
18280 bzero (s
, sizeof *s
);
18282 s
->f
= XFRAME (w
->frame
);
18286 s
->display
= FRAME_X_DISPLAY (s
->f
);
18287 s
->window
= FRAME_X_WINDOW (s
->f
);
18288 s
->char2b
= char2b
;
18292 s
->first_glyph
= row
->glyphs
[area
] + start
;
18293 s
->height
= row
->height
;
18294 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
18296 /* Display the internal border below the tool-bar window. */
18297 if (WINDOWP (s
->f
->tool_bar_window
)
18298 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
18299 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
18301 s
->ybase
= s
->y
+ row
->ascent
;
18305 /* Append the list of glyph strings with head H and tail T to the list
18306 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
18309 append_glyph_string_lists (head
, tail
, h
, t
)
18310 struct glyph_string
**head
, **tail
;
18311 struct glyph_string
*h
, *t
;
18325 /* Prepend the list of glyph strings with head H and tail T to the
18326 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
18330 prepend_glyph_string_lists (head
, tail
, h
, t
)
18331 struct glyph_string
**head
, **tail
;
18332 struct glyph_string
*h
, *t
;
18346 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
18347 Set *HEAD and *TAIL to the resulting list. */
18350 append_glyph_string (head
, tail
, s
)
18351 struct glyph_string
**head
, **tail
;
18352 struct glyph_string
*s
;
18354 s
->next
= s
->prev
= NULL
;
18355 append_glyph_string_lists (head
, tail
, s
, s
);
18359 /* Get face and two-byte form of character glyph GLYPH on frame F.
18360 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
18361 a pointer to a realized face that is ready for display. */
18363 static INLINE
struct face
*
18364 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
18366 struct glyph
*glyph
;
18372 xassert (glyph
->type
== CHAR_GLYPH
);
18373 face
= FACE_FROM_ID (f
, glyph
->face_id
);
18378 if (!glyph
->multibyte_p
)
18380 /* Unibyte case. We don't have to encode, but we have to make
18381 sure to use a face suitable for unibyte. */
18382 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18384 else if (glyph
->u
.ch
< 128
18385 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
18387 /* Case of ASCII in a face known to fit ASCII. */
18388 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18392 int c1
, c2
, charset
;
18394 /* Split characters into bytes. If c2 is -1 afterwards, C is
18395 really a one-byte character so that byte1 is zero. */
18396 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
18398 STORE_XCHAR2B (char2b
, c1
, c2
);
18400 STORE_XCHAR2B (char2b
, 0, c1
);
18402 /* Maybe encode the character in *CHAR2B. */
18403 if (charset
!= CHARSET_ASCII
)
18405 struct font_info
*font_info
18406 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18409 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
18413 /* Make sure X resources of the face are allocated. */
18414 xassert (face
!= NULL
);
18415 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18420 /* Fill glyph string S with composition components specified by S->cmp.
18422 FACES is an array of faces for all components of this composition.
18423 S->gidx is the index of the first component for S.
18425 OVERLAPS non-zero means S should draw the foreground only, and use
18426 its physical height for clipping. See also draw_glyphs.
18428 Value is the index of a component not in S. */
18431 fill_composite_glyph_string (s
, faces
, overlaps
)
18432 struct glyph_string
*s
;
18433 struct face
**faces
;
18440 s
->for_overlaps
= overlaps
;
18442 s
->face
= faces
[s
->gidx
];
18443 s
->font
= s
->face
->font
;
18444 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18446 /* For all glyphs of this composition, starting at the offset
18447 S->gidx, until we reach the end of the definition or encounter a
18448 glyph that requires the different face, add it to S. */
18450 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
18453 /* All glyph strings for the same composition has the same width,
18454 i.e. the width set for the first component of the composition. */
18456 s
->width
= s
->first_glyph
->pixel_width
;
18458 /* If the specified font could not be loaded, use the frame's
18459 default font, but record the fact that we couldn't load it in
18460 the glyph string so that we can draw rectangles for the
18461 characters of the glyph string. */
18462 if (s
->font
== NULL
)
18464 s
->font_not_found_p
= 1;
18465 s
->font
= FRAME_FONT (s
->f
);
18468 /* Adjust base line for subscript/superscript text. */
18469 s
->ybase
+= s
->first_glyph
->voffset
;
18471 xassert (s
->face
&& s
->face
->gc
);
18473 /* This glyph string must always be drawn with 16-bit functions. */
18476 return s
->gidx
+ s
->nchars
;
18480 /* Fill glyph string S from a sequence of character glyphs.
18482 FACE_ID is the face id of the string. START is the index of the
18483 first glyph to consider, END is the index of the last + 1.
18484 OVERLAPS non-zero means S should draw the foreground only, and use
18485 its physical height for clipping. See also draw_glyphs.
18487 Value is the index of the first glyph not in S. */
18490 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
18491 struct glyph_string
*s
;
18493 int start
, end
, overlaps
;
18495 struct glyph
*glyph
, *last
;
18497 int glyph_not_available_p
;
18499 xassert (s
->f
== XFRAME (s
->w
->frame
));
18500 xassert (s
->nchars
== 0);
18501 xassert (start
>= 0 && end
> start
);
18503 s
->for_overlaps
= overlaps
,
18504 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18505 last
= s
->row
->glyphs
[s
->area
] + end
;
18506 voffset
= glyph
->voffset
;
18508 glyph_not_available_p
= glyph
->glyph_not_available_p
;
18510 while (glyph
< last
18511 && glyph
->type
== CHAR_GLYPH
18512 && glyph
->voffset
== voffset
18513 /* Same face id implies same font, nowadays. */
18514 && glyph
->face_id
== face_id
18515 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
18519 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
18520 s
->char2b
+ s
->nchars
,
18522 s
->two_byte_p
= two_byte_p
;
18524 xassert (s
->nchars
<= end
- start
);
18525 s
->width
+= glyph
->pixel_width
;
18529 s
->font
= s
->face
->font
;
18530 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18532 /* If the specified font could not be loaded, use the frame's font,
18533 but record the fact that we couldn't load it in
18534 S->font_not_found_p so that we can draw rectangles for the
18535 characters of the glyph string. */
18536 if (s
->font
== NULL
|| glyph_not_available_p
)
18538 s
->font_not_found_p
= 1;
18539 s
->font
= FRAME_FONT (s
->f
);
18542 /* Adjust base line for subscript/superscript text. */
18543 s
->ybase
+= voffset
;
18545 xassert (s
->face
&& s
->face
->gc
);
18546 return glyph
- s
->row
->glyphs
[s
->area
];
18550 /* Fill glyph string S from image glyph S->first_glyph. */
18553 fill_image_glyph_string (s
)
18554 struct glyph_string
*s
;
18556 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
18557 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
18559 s
->slice
= s
->first_glyph
->slice
;
18560 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
18561 s
->font
= s
->face
->font
;
18562 s
->width
= s
->first_glyph
->pixel_width
;
18564 /* Adjust base line for subscript/superscript text. */
18565 s
->ybase
+= s
->first_glyph
->voffset
;
18569 /* Fill glyph string S from a sequence of stretch glyphs.
18571 ROW is the glyph row in which the glyphs are found, AREA is the
18572 area within the row. START is the index of the first glyph to
18573 consider, END is the index of the last + 1.
18575 Value is the index of the first glyph not in S. */
18578 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
18579 struct glyph_string
*s
;
18580 struct glyph_row
*row
;
18581 enum glyph_row_area area
;
18584 struct glyph
*glyph
, *last
;
18585 int voffset
, face_id
;
18587 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
18589 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18590 last
= s
->row
->glyphs
[s
->area
] + end
;
18591 face_id
= glyph
->face_id
;
18592 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
18593 s
->font
= s
->face
->font
;
18594 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18595 s
->width
= glyph
->pixel_width
;
18596 voffset
= glyph
->voffset
;
18600 && glyph
->type
== STRETCH_GLYPH
18601 && glyph
->voffset
== voffset
18602 && glyph
->face_id
== face_id
);
18604 s
->width
+= glyph
->pixel_width
;
18606 /* Adjust base line for subscript/superscript text. */
18607 s
->ybase
+= voffset
;
18609 /* The case that face->gc == 0 is handled when drawing the glyph
18610 string by calling PREPARE_FACE_FOR_DISPLAY. */
18612 return glyph
- s
->row
->glyphs
[s
->area
];
18617 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
18618 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
18619 assumed to be zero. */
18622 x_get_glyph_overhangs (glyph
, f
, left
, right
)
18623 struct glyph
*glyph
;
18627 *left
= *right
= 0;
18629 if (glyph
->type
== CHAR_GLYPH
)
18633 struct font_info
*font_info
;
18637 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
18639 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18640 if (font
/* ++KFS: Should this be font_info ? */
18641 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
18643 if (pcm
->rbearing
> pcm
->width
)
18644 *right
= pcm
->rbearing
- pcm
->width
;
18645 if (pcm
->lbearing
< 0)
18646 *left
= -pcm
->lbearing
;
18652 /* Return the index of the first glyph preceding glyph string S that
18653 is overwritten by S because of S's left overhang. Value is -1
18654 if no glyphs are overwritten. */
18657 left_overwritten (s
)
18658 struct glyph_string
*s
;
18662 if (s
->left_overhang
)
18665 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18666 int first
= s
->first_glyph
- glyphs
;
18668 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
18669 x
-= glyphs
[i
].pixel_width
;
18680 /* Return the index of the first glyph preceding glyph string S that
18681 is overwriting S because of its right overhang. Value is -1 if no
18682 glyph in front of S overwrites S. */
18685 left_overwriting (s
)
18686 struct glyph_string
*s
;
18689 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18690 int first
= s
->first_glyph
- glyphs
;
18694 for (i
= first
- 1; i
>= 0; --i
)
18697 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18700 x
-= glyphs
[i
].pixel_width
;
18707 /* Return the index of the last glyph following glyph string S that is
18708 not overwritten by S because of S's right overhang. Value is -1 if
18709 no such glyph is found. */
18712 right_overwritten (s
)
18713 struct glyph_string
*s
;
18717 if (s
->right_overhang
)
18720 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18721 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18722 int end
= s
->row
->used
[s
->area
];
18724 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
18725 x
+= glyphs
[i
].pixel_width
;
18734 /* Return the index of the last glyph following glyph string S that
18735 overwrites S because of its left overhang. Value is negative
18736 if no such glyph is found. */
18739 right_overwriting (s
)
18740 struct glyph_string
*s
;
18743 int end
= s
->row
->used
[s
->area
];
18744 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18745 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18749 for (i
= first
; i
< end
; ++i
)
18752 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18755 x
+= glyphs
[i
].pixel_width
;
18762 /* Get face and two-byte form of character C in face FACE_ID on frame
18763 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
18764 means we want to display multibyte text. DISPLAY_P non-zero means
18765 make sure that X resources for the face returned are allocated.
18766 Value is a pointer to a realized face that is ready for display if
18767 DISPLAY_P is non-zero. */
18769 static INLINE
struct face
*
18770 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
18774 int multibyte_p
, display_p
;
18776 struct face
*face
= FACE_FROM_ID (f
, face_id
);
18780 /* Unibyte case. We don't have to encode, but we have to make
18781 sure to use a face suitable for unibyte. */
18782 STORE_XCHAR2B (char2b
, 0, c
);
18783 face_id
= FACE_FOR_CHAR (f
, face
, c
);
18784 face
= FACE_FROM_ID (f
, face_id
);
18786 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
18788 /* Case of ASCII in a face known to fit ASCII. */
18789 STORE_XCHAR2B (char2b
, 0, c
);
18793 int c1
, c2
, charset
;
18795 /* Split characters into bytes. If c2 is -1 afterwards, C is
18796 really a one-byte character so that byte1 is zero. */
18797 SPLIT_CHAR (c
, charset
, c1
, c2
);
18799 STORE_XCHAR2B (char2b
, c1
, c2
);
18801 STORE_XCHAR2B (char2b
, 0, c1
);
18803 /* Maybe encode the character in *CHAR2B. */
18804 if (face
->font
!= NULL
)
18806 struct font_info
*font_info
18807 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18809 rif
->encode_char (c
, char2b
, font_info
, 0);
18813 /* Make sure X resources of the face are allocated. */
18814 #ifdef HAVE_X_WINDOWS
18818 xassert (face
!= NULL
);
18819 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18826 /* Set background width of glyph string S. START is the index of the
18827 first glyph following S. LAST_X is the right-most x-position + 1
18828 in the drawing area. */
18831 set_glyph_string_background_width (s
, start
, last_x
)
18832 struct glyph_string
*s
;
18836 /* If the face of this glyph string has to be drawn to the end of
18837 the drawing area, set S->extends_to_end_of_line_p. */
18839 if (start
== s
->row
->used
[s
->area
]
18840 && s
->area
== TEXT_AREA
18841 && ((s
->row
->fill_line_p
18842 && (s
->hl
== DRAW_NORMAL_TEXT
18843 || s
->hl
== DRAW_IMAGE_RAISED
18844 || s
->hl
== DRAW_IMAGE_SUNKEN
))
18845 || s
->hl
== DRAW_MOUSE_FACE
))
18846 s
->extends_to_end_of_line_p
= 1;
18848 /* If S extends its face to the end of the line, set its
18849 background_width to the distance to the right edge of the drawing
18851 if (s
->extends_to_end_of_line_p
)
18852 s
->background_width
= last_x
- s
->x
+ 1;
18854 s
->background_width
= s
->width
;
18858 /* Compute overhangs and x-positions for glyph string S and its
18859 predecessors, or successors. X is the starting x-position for S.
18860 BACKWARD_P non-zero means process predecessors. */
18863 compute_overhangs_and_x (s
, x
, backward_p
)
18864 struct glyph_string
*s
;
18872 if (rif
->compute_glyph_string_overhangs
)
18873 rif
->compute_glyph_string_overhangs (s
);
18883 if (rif
->compute_glyph_string_overhangs
)
18884 rif
->compute_glyph_string_overhangs (s
);
18894 /* The following macros are only called from draw_glyphs below.
18895 They reference the following parameters of that function directly:
18896 `w', `row', `area', and `overlap_p'
18897 as well as the following local variables:
18898 `s', `f', and `hdc' (in W32) */
18901 /* On W32, silently add local `hdc' variable to argument list of
18902 init_glyph_string. */
18903 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18904 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
18906 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18907 init_glyph_string (s, char2b, w, row, area, start, hl)
18910 /* Add a glyph string for a stretch glyph to the list of strings
18911 between HEAD and TAIL. START is the index of the stretch glyph in
18912 row area AREA of glyph row ROW. END is the index of the last glyph
18913 in that glyph row area. X is the current output position assigned
18914 to the new glyph string constructed. HL overrides that face of the
18915 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18916 is the right-most x-position of the drawing area. */
18918 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
18919 and below -- keep them on one line. */
18920 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18923 s = (struct glyph_string *) alloca (sizeof *s); \
18924 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18925 START = fill_stretch_glyph_string (s, row, area, START, END); \
18926 append_glyph_string (&HEAD, &TAIL, s); \
18932 /* Add a glyph string for an image glyph to the list of strings
18933 between HEAD and TAIL. START is the index of the image glyph in
18934 row area AREA of glyph row ROW. END is the index of the last glyph
18935 in that glyph row area. X is the current output position assigned
18936 to the new glyph string constructed. HL overrides that face of the
18937 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18938 is the right-most x-position of the drawing area. */
18940 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18943 s = (struct glyph_string *) alloca (sizeof *s); \
18944 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18945 fill_image_glyph_string (s); \
18946 append_glyph_string (&HEAD, &TAIL, s); \
18953 /* Add a glyph string for a sequence of character glyphs to the list
18954 of strings between HEAD and TAIL. START is the index of the first
18955 glyph in row area AREA of glyph row ROW that is part of the new
18956 glyph string. END is the index of the last glyph in that glyph row
18957 area. X is the current output position assigned to the new glyph
18958 string constructed. HL overrides that face of the glyph; e.g. it
18959 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
18960 right-most x-position of the drawing area. */
18962 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18968 c = (row)->glyphs[area][START].u.ch; \
18969 face_id = (row)->glyphs[area][START].face_id; \
18971 s = (struct glyph_string *) alloca (sizeof *s); \
18972 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
18973 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
18974 append_glyph_string (&HEAD, &TAIL, s); \
18976 START = fill_glyph_string (s, face_id, START, END, overlaps); \
18981 /* Add a glyph string for a composite sequence to the list of strings
18982 between HEAD and TAIL. START is the index of the first glyph in
18983 row area AREA of glyph row ROW that is part of the new glyph
18984 string. END is the index of the last glyph in that glyph row area.
18985 X is the current output position assigned to the new glyph string
18986 constructed. HL overrides that face of the glyph; e.g. it is
18987 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
18988 x-position of the drawing area. */
18990 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18992 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
18993 int face_id = (row)->glyphs[area][START].face_id; \
18994 struct face *base_face = FACE_FROM_ID (f, face_id); \
18995 struct composition *cmp = composition_table[cmp_id]; \
18996 int glyph_len = cmp->glyph_len; \
18998 struct face **faces; \
18999 struct glyph_string *first_s = NULL; \
19002 base_face = base_face->ascii_face; \
19003 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
19004 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
19005 /* At first, fill in `char2b' and `faces'. */ \
19006 for (n = 0; n < glyph_len; n++) \
19008 int c = COMPOSITION_GLYPH (cmp, n); \
19009 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
19010 faces[n] = FACE_FROM_ID (f, this_face_id); \
19011 get_char_face_and_encoding (f, c, this_face_id, \
19012 char2b + n, 1, 1); \
19015 /* Make glyph_strings for each glyph sequence that is drawable by \
19016 the same face, and append them to HEAD/TAIL. */ \
19017 for (n = 0; n < cmp->glyph_len;) \
19019 s = (struct glyph_string *) alloca (sizeof *s); \
19020 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
19021 append_glyph_string (&(HEAD), &(TAIL), s); \
19029 n = fill_composite_glyph_string (s, faces, overlaps); \
19037 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
19038 of AREA of glyph row ROW on window W between indices START and END.
19039 HL overrides the face for drawing glyph strings, e.g. it is
19040 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
19041 x-positions of the drawing area.
19043 This is an ugly monster macro construct because we must use alloca
19044 to allocate glyph strings (because draw_glyphs can be called
19045 asynchronously). */
19047 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19050 HEAD = TAIL = NULL; \
19051 while (START < END) \
19053 struct glyph *first_glyph = (row)->glyphs[area] + START; \
19054 switch (first_glyph->type) \
19057 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
19061 case COMPOSITE_GLYPH: \
19062 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
19066 case STRETCH_GLYPH: \
19067 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
19071 case IMAGE_GLYPH: \
19072 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
19080 set_glyph_string_background_width (s, START, LAST_X); \
19087 /* Draw glyphs between START and END in AREA of ROW on window W,
19088 starting at x-position X. X is relative to AREA in W. HL is a
19089 face-override with the following meaning:
19091 DRAW_NORMAL_TEXT draw normally
19092 DRAW_CURSOR draw in cursor face
19093 DRAW_MOUSE_FACE draw in mouse face.
19094 DRAW_INVERSE_VIDEO draw in mode line face
19095 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
19096 DRAW_IMAGE_RAISED draw an image with a raised relief around it
19098 If OVERLAPS is non-zero, draw only the foreground of characters and
19099 clip to the physical height of ROW. Non-zero value also defines
19100 the overlapping part to be drawn:
19102 OVERLAPS_PRED overlap with preceding rows
19103 OVERLAPS_SUCC overlap with succeeding rows
19104 OVERLAPS_BOTH overlap with both preceding/succeeding rows
19105 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
19107 Value is the x-position reached, relative to AREA of W. */
19110 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
19113 struct glyph_row
*row
;
19114 enum glyph_row_area area
;
19116 enum draw_glyphs_face hl
;
19119 struct glyph_string
*head
, *tail
;
19120 struct glyph_string
*s
;
19121 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
19122 int last_x
, area_width
;
19125 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19128 ALLOCATE_HDC (hdc
, f
);
19130 /* Let's rather be paranoid than getting a SEGV. */
19131 end
= min (end
, row
->used
[area
]);
19132 start
= max (0, start
);
19133 start
= min (end
, start
);
19135 /* Translate X to frame coordinates. Set last_x to the right
19136 end of the drawing area. */
19137 if (row
->full_width_p
)
19139 /* X is relative to the left edge of W, without scroll bars
19141 x
+= WINDOW_LEFT_EDGE_X (w
);
19142 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
19146 int area_left
= window_box_left (w
, area
);
19148 area_width
= window_box_width (w
, area
);
19149 last_x
= area_left
+ area_width
;
19152 /* Build a doubly-linked list of glyph_string structures between
19153 head and tail from what we have to draw. Note that the macro
19154 BUILD_GLYPH_STRINGS will modify its start parameter. That's
19155 the reason we use a separate variable `i'. */
19157 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
19159 x_reached
= tail
->x
+ tail
->background_width
;
19163 /* If there are any glyphs with lbearing < 0 or rbearing > width in
19164 the row, redraw some glyphs in front or following the glyph
19165 strings built above. */
19166 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
19169 struct glyph_string
*h
, *t
;
19171 /* Compute overhangs for all glyph strings. */
19172 if (rif
->compute_glyph_string_overhangs
)
19173 for (s
= head
; s
; s
= s
->next
)
19174 rif
->compute_glyph_string_overhangs (s
);
19176 /* Prepend glyph strings for glyphs in front of the first glyph
19177 string that are overwritten because of the first glyph
19178 string's left overhang. The background of all strings
19179 prepended must be drawn because the first glyph string
19181 i
= left_overwritten (head
);
19185 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
19186 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19188 compute_overhangs_and_x (t
, head
->x
, 1);
19189 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19193 /* Prepend glyph strings for glyphs in front of the first glyph
19194 string that overwrite that glyph string because of their
19195 right overhang. For these strings, only the foreground must
19196 be drawn, because it draws over the glyph string at `head'.
19197 The background must not be drawn because this would overwrite
19198 right overhangs of preceding glyphs for which no glyph
19200 i
= left_overwriting (head
);
19204 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
19205 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19206 for (s
= h
; s
; s
= s
->next
)
19207 s
->background_filled_p
= 1;
19208 compute_overhangs_and_x (t
, head
->x
, 1);
19209 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19212 /* Append glyphs strings for glyphs following the last glyph
19213 string tail that are overwritten by tail. The background of
19214 these strings has to be drawn because tail's foreground draws
19216 i
= right_overwritten (tail
);
19219 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19220 DRAW_NORMAL_TEXT
, x
, last_x
);
19221 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19222 append_glyph_string_lists (&head
, &tail
, h
, t
);
19226 /* Append glyph strings for glyphs following the last glyph
19227 string tail that overwrite tail. The foreground of such
19228 glyphs has to be drawn because it writes into the background
19229 of tail. The background must not be drawn because it could
19230 paint over the foreground of following glyphs. */
19231 i
= right_overwriting (tail
);
19235 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19236 DRAW_NORMAL_TEXT
, x
, last_x
);
19237 for (s
= h
; s
; s
= s
->next
)
19238 s
->background_filled_p
= 1;
19239 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19240 append_glyph_string_lists (&head
, &tail
, h
, t
);
19242 if (clip_head
|| clip_tail
)
19243 for (s
= head
; s
; s
= s
->next
)
19245 s
->clip_head
= clip_head
;
19246 s
->clip_tail
= clip_tail
;
19250 /* Draw all strings. */
19251 for (s
= head
; s
; s
= s
->next
)
19252 rif
->draw_glyph_string (s
);
19254 if (area
== TEXT_AREA
19255 && !row
->full_width_p
19256 /* When drawing overlapping rows, only the glyph strings'
19257 foreground is drawn, which doesn't erase a cursor
19261 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
19262 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
19263 : (tail
? tail
->x
+ tail
->background_width
: x
));
19265 int text_left
= window_box_left (w
, TEXT_AREA
);
19269 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
19270 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
19273 /* Value is the x-position up to which drawn, relative to AREA of W.
19274 This doesn't include parts drawn because of overhangs. */
19275 if (row
->full_width_p
)
19276 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
19278 x_reached
-= window_box_left (w
, area
);
19280 RELEASE_HDC (hdc
, f
);
19285 /* Expand row matrix if too narrow. Don't expand if area
19288 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
19290 if (!fonts_changed_p \
19291 && (it->glyph_row->glyphs[area] \
19292 < it->glyph_row->glyphs[area + 1])) \
19294 it->w->ncols_scale_factor++; \
19295 fonts_changed_p = 1; \
19299 /* Store one glyph for IT->char_to_display in IT->glyph_row.
19300 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19306 struct glyph
*glyph
;
19307 enum glyph_row_area area
= it
->area
;
19309 xassert (it
->glyph_row
);
19310 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
19312 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19313 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19315 glyph
->charpos
= CHARPOS (it
->position
);
19316 glyph
->object
= it
->object
;
19317 glyph
->pixel_width
= it
->pixel_width
;
19318 glyph
->ascent
= it
->ascent
;
19319 glyph
->descent
= it
->descent
;
19320 glyph
->voffset
= it
->voffset
;
19321 glyph
->type
= CHAR_GLYPH
;
19322 glyph
->multibyte_p
= it
->multibyte_p
;
19323 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19324 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19325 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19326 || it
->phys_descent
> it
->descent
);
19327 glyph
->padding_p
= 0;
19328 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
19329 glyph
->face_id
= it
->face_id
;
19330 glyph
->u
.ch
= it
->char_to_display
;
19331 glyph
->slice
= null_glyph_slice
;
19332 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19333 ++it
->glyph_row
->used
[area
];
19336 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19339 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
19340 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19343 append_composite_glyph (it
)
19346 struct glyph
*glyph
;
19347 enum glyph_row_area area
= it
->area
;
19349 xassert (it
->glyph_row
);
19351 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19352 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19354 glyph
->charpos
= CHARPOS (it
->position
);
19355 glyph
->object
= it
->object
;
19356 glyph
->pixel_width
= it
->pixel_width
;
19357 glyph
->ascent
= it
->ascent
;
19358 glyph
->descent
= it
->descent
;
19359 glyph
->voffset
= it
->voffset
;
19360 glyph
->type
= COMPOSITE_GLYPH
;
19361 glyph
->multibyte_p
= it
->multibyte_p
;
19362 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19363 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19364 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19365 || it
->phys_descent
> it
->descent
);
19366 glyph
->padding_p
= 0;
19367 glyph
->glyph_not_available_p
= 0;
19368 glyph
->face_id
= it
->face_id
;
19369 glyph
->u
.cmp_id
= it
->cmp_id
;
19370 glyph
->slice
= null_glyph_slice
;
19371 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19372 ++it
->glyph_row
->used
[area
];
19375 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19379 /* Change IT->ascent and IT->height according to the setting of
19383 take_vertical_position_into_account (it
)
19388 if (it
->voffset
< 0)
19389 /* Increase the ascent so that we can display the text higher
19391 it
->ascent
-= it
->voffset
;
19393 /* Increase the descent so that we can display the text lower
19395 it
->descent
+= it
->voffset
;
19400 /* Produce glyphs/get display metrics for the image IT is loaded with.
19401 See the description of struct display_iterator in dispextern.h for
19402 an overview of struct display_iterator. */
19405 produce_image_glyph (it
)
19411 struct glyph_slice slice
;
19413 xassert (it
->what
== IT_IMAGE
);
19415 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19417 /* Make sure X resources of the face is loaded. */
19418 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19420 if (it
->image_id
< 0)
19422 /* Fringe bitmap. */
19423 it
->ascent
= it
->phys_ascent
= 0;
19424 it
->descent
= it
->phys_descent
= 0;
19425 it
->pixel_width
= 0;
19430 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
19432 /* Make sure X resources of the image is loaded. */
19433 prepare_image_for_display (it
->f
, img
);
19435 slice
.x
= slice
.y
= 0;
19436 slice
.width
= img
->width
;
19437 slice
.height
= img
->height
;
19439 if (INTEGERP (it
->slice
.x
))
19440 slice
.x
= XINT (it
->slice
.x
);
19441 else if (FLOATP (it
->slice
.x
))
19442 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
19444 if (INTEGERP (it
->slice
.y
))
19445 slice
.y
= XINT (it
->slice
.y
);
19446 else if (FLOATP (it
->slice
.y
))
19447 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
19449 if (INTEGERP (it
->slice
.width
))
19450 slice
.width
= XINT (it
->slice
.width
);
19451 else if (FLOATP (it
->slice
.width
))
19452 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
19454 if (INTEGERP (it
->slice
.height
))
19455 slice
.height
= XINT (it
->slice
.height
);
19456 else if (FLOATP (it
->slice
.height
))
19457 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
19459 if (slice
.x
>= img
->width
)
19460 slice
.x
= img
->width
;
19461 if (slice
.y
>= img
->height
)
19462 slice
.y
= img
->height
;
19463 if (slice
.x
+ slice
.width
>= img
->width
)
19464 slice
.width
= img
->width
- slice
.x
;
19465 if (slice
.y
+ slice
.height
> img
->height
)
19466 slice
.height
= img
->height
- slice
.y
;
19468 if (slice
.width
== 0 || slice
.height
== 0)
19471 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
19473 it
->descent
= slice
.height
- glyph_ascent
;
19475 it
->descent
+= img
->vmargin
;
19476 if (slice
.y
+ slice
.height
== img
->height
)
19477 it
->descent
+= img
->vmargin
;
19478 it
->phys_descent
= it
->descent
;
19480 it
->pixel_width
= slice
.width
;
19482 it
->pixel_width
+= img
->hmargin
;
19483 if (slice
.x
+ slice
.width
== img
->width
)
19484 it
->pixel_width
+= img
->hmargin
;
19486 /* It's quite possible for images to have an ascent greater than
19487 their height, so don't get confused in that case. */
19488 if (it
->descent
< 0)
19491 #if 0 /* this breaks image tiling */
19492 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
19493 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
19494 if (face_ascent
> it
->ascent
)
19495 it
->ascent
= it
->phys_ascent
= face_ascent
;
19500 if (face
->box
!= FACE_NO_BOX
)
19502 if (face
->box_line_width
> 0)
19505 it
->ascent
+= face
->box_line_width
;
19506 if (slice
.y
+ slice
.height
== img
->height
)
19507 it
->descent
+= face
->box_line_width
;
19510 if (it
->start_of_box_run_p
&& slice
.x
== 0)
19511 it
->pixel_width
+= abs (face
->box_line_width
);
19512 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
19513 it
->pixel_width
+= abs (face
->box_line_width
);
19516 take_vertical_position_into_account (it
);
19520 struct glyph
*glyph
;
19521 enum glyph_row_area area
= it
->area
;
19523 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19524 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19526 glyph
->charpos
= CHARPOS (it
->position
);
19527 glyph
->object
= it
->object
;
19528 glyph
->pixel_width
= it
->pixel_width
;
19529 glyph
->ascent
= glyph_ascent
;
19530 glyph
->descent
= it
->descent
;
19531 glyph
->voffset
= it
->voffset
;
19532 glyph
->type
= IMAGE_GLYPH
;
19533 glyph
->multibyte_p
= it
->multibyte_p
;
19534 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19535 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19536 glyph
->overlaps_vertically_p
= 0;
19537 glyph
->padding_p
= 0;
19538 glyph
->glyph_not_available_p
= 0;
19539 glyph
->face_id
= it
->face_id
;
19540 glyph
->u
.img_id
= img
->id
;
19541 glyph
->slice
= slice
;
19542 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19543 ++it
->glyph_row
->used
[area
];
19546 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19551 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
19552 of the glyph, WIDTH and HEIGHT are the width and height of the
19553 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
19556 append_stretch_glyph (it
, object
, width
, height
, ascent
)
19558 Lisp_Object object
;
19562 struct glyph
*glyph
;
19563 enum glyph_row_area area
= it
->area
;
19565 xassert (ascent
>= 0 && ascent
<= height
);
19567 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19568 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19570 glyph
->charpos
= CHARPOS (it
->position
);
19571 glyph
->object
= object
;
19572 glyph
->pixel_width
= width
;
19573 glyph
->ascent
= ascent
;
19574 glyph
->descent
= height
- ascent
;
19575 glyph
->voffset
= it
->voffset
;
19576 glyph
->type
= STRETCH_GLYPH
;
19577 glyph
->multibyte_p
= it
->multibyte_p
;
19578 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19579 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19580 glyph
->overlaps_vertically_p
= 0;
19581 glyph
->padding_p
= 0;
19582 glyph
->glyph_not_available_p
= 0;
19583 glyph
->face_id
= it
->face_id
;
19584 glyph
->u
.stretch
.ascent
= ascent
;
19585 glyph
->u
.stretch
.height
= height
;
19586 glyph
->slice
= null_glyph_slice
;
19587 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19588 ++it
->glyph_row
->used
[area
];
19591 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19595 /* Produce a stretch glyph for iterator IT. IT->object is the value
19596 of the glyph property displayed. The value must be a list
19597 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
19600 1. `:width WIDTH' specifies that the space should be WIDTH *
19601 canonical char width wide. WIDTH may be an integer or floating
19604 2. `:relative-width FACTOR' specifies that the width of the stretch
19605 should be computed from the width of the first character having the
19606 `glyph' property, and should be FACTOR times that width.
19608 3. `:align-to HPOS' specifies that the space should be wide enough
19609 to reach HPOS, a value in canonical character units.
19611 Exactly one of the above pairs must be present.
19613 4. `:height HEIGHT' specifies that the height of the stretch produced
19614 should be HEIGHT, measured in canonical character units.
19616 5. `:relative-height FACTOR' specifies that the height of the
19617 stretch should be FACTOR times the height of the characters having
19618 the glyph property.
19620 Either none or exactly one of 4 or 5 must be present.
19622 6. `:ascent ASCENT' specifies that ASCENT percent of the height
19623 of the stretch should be used for the ascent of the stretch.
19624 ASCENT must be in the range 0 <= ASCENT <= 100. */
19627 produce_stretch_glyph (it
)
19630 /* (space :width WIDTH :height HEIGHT ...) */
19631 Lisp_Object prop
, plist
;
19632 int width
= 0, height
= 0, align_to
= -1;
19633 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
19636 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19637 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
19639 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19641 /* List should start with `space'. */
19642 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
19643 plist
= XCDR (it
->object
);
19645 /* Compute the width of the stretch. */
19646 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
19647 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
19649 /* Absolute width `:width WIDTH' specified and valid. */
19650 zero_width_ok_p
= 1;
19653 else if (prop
= Fplist_get (plist
, QCrelative_width
),
19656 /* Relative width `:relative-width FACTOR' specified and valid.
19657 Compute the width of the characters having the `glyph'
19660 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
19663 if (it
->multibyte_p
)
19665 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
19666 - IT_BYTEPOS (*it
));
19667 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
19670 it2
.c
= *p
, it2
.len
= 1;
19672 it2
.glyph_row
= NULL
;
19673 it2
.what
= IT_CHARACTER
;
19674 x_produce_glyphs (&it2
);
19675 width
= NUMVAL (prop
) * it2
.pixel_width
;
19677 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
19678 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
19680 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
19681 align_to
= (align_to
< 0
19683 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
19684 else if (align_to
< 0)
19685 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
19686 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
19687 zero_width_ok_p
= 1;
19690 /* Nothing specified -> width defaults to canonical char width. */
19691 width
= FRAME_COLUMN_WIDTH (it
->f
);
19693 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
19696 /* Compute height. */
19697 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
19698 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19701 zero_height_ok_p
= 1;
19703 else if (prop
= Fplist_get (plist
, QCrelative_height
),
19705 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
19707 height
= FONT_HEIGHT (font
);
19709 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
19712 /* Compute percentage of height used for ascent. If
19713 `:ascent ASCENT' is present and valid, use that. Otherwise,
19714 derive the ascent from the font in use. */
19715 if (prop
= Fplist_get (plist
, QCascent
),
19716 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
19717 ascent
= height
* NUMVAL (prop
) / 100.0;
19718 else if (!NILP (prop
)
19719 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19720 ascent
= min (max (0, (int)tem
), height
);
19722 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
19724 if (width
> 0 && !it
->truncate_lines_p
19725 && it
->current_x
+ width
> it
->last_visible_x
)
19726 width
= it
->last_visible_x
- it
->current_x
- 1;
19728 if (width
> 0 && height
> 0 && it
->glyph_row
)
19730 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
19731 if (!STRINGP (object
))
19732 object
= it
->w
->buffer
;
19733 append_stretch_glyph (it
, object
, width
, height
, ascent
);
19736 it
->pixel_width
= width
;
19737 it
->ascent
= it
->phys_ascent
= ascent
;
19738 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
19739 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
19741 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
19743 if (face
->box_line_width
> 0)
19745 it
->ascent
+= face
->box_line_width
;
19746 it
->descent
+= face
->box_line_width
;
19749 if (it
->start_of_box_run_p
)
19750 it
->pixel_width
+= abs (face
->box_line_width
);
19751 if (it
->end_of_box_run_p
)
19752 it
->pixel_width
+= abs (face
->box_line_width
);
19755 take_vertical_position_into_account (it
);
19758 /* Get line-height and line-spacing property at point.
19759 If line-height has format (HEIGHT TOTAL), return TOTAL
19760 in TOTAL_HEIGHT. */
19763 get_line_height_property (it
, prop
)
19767 Lisp_Object position
;
19769 if (STRINGP (it
->object
))
19770 position
= make_number (IT_STRING_CHARPOS (*it
));
19771 else if (BUFFERP (it
->object
))
19772 position
= make_number (IT_CHARPOS (*it
));
19776 return Fget_char_property (position
, prop
, it
->object
);
19779 /* Calculate line-height and line-spacing properties.
19780 An integer value specifies explicit pixel value.
19781 A float value specifies relative value to current face height.
19782 A cons (float . face-name) specifies relative value to
19783 height of specified face font.
19785 Returns height in pixels, or nil. */
19789 calc_line_height_property (it
, val
, font
, boff
, override
)
19793 int boff
, override
;
19795 Lisp_Object face_name
= Qnil
;
19796 int ascent
, descent
, height
;
19798 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
19803 face_name
= XCAR (val
);
19805 if (!NUMBERP (val
))
19806 val
= make_number (1);
19807 if (NILP (face_name
))
19809 height
= it
->ascent
+ it
->descent
;
19814 if (NILP (face_name
))
19816 font
= FRAME_FONT (it
->f
);
19817 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19819 else if (EQ (face_name
, Qt
))
19827 struct font_info
*font_info
;
19829 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
19831 return make_number (-1);
19833 face
= FACE_FROM_ID (it
->f
, face_id
);
19836 return make_number (-1);
19838 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19839 boff
= font_info
->baseline_offset
;
19840 if (font_info
->vertical_centering
)
19841 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19844 ascent
= FONT_BASE (font
) + boff
;
19845 descent
= FONT_DESCENT (font
) - boff
;
19849 it
->override_ascent
= ascent
;
19850 it
->override_descent
= descent
;
19851 it
->override_boff
= boff
;
19854 height
= ascent
+ descent
;
19858 height
= (int)(XFLOAT_DATA (val
) * height
);
19859 else if (INTEGERP (val
))
19860 height
*= XINT (val
);
19862 return make_number (height
);
19867 Produce glyphs/get display metrics for the display element IT is
19868 loaded with. See the description of struct it in dispextern.h
19869 for an overview of struct it. */
19872 x_produce_glyphs (it
)
19875 int extra_line_spacing
= it
->extra_line_spacing
;
19877 it
->glyph_not_available_p
= 0;
19879 if (it
->what
== IT_CHARACTER
)
19883 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19885 int font_not_found_p
;
19886 struct font_info
*font_info
;
19887 int boff
; /* baseline offset */
19888 /* We may change it->multibyte_p upon unibyte<->multibyte
19889 conversion. So, save the current value now and restore it
19892 Note: It seems that we don't have to record multibyte_p in
19893 struct glyph because the character code itself tells if or
19894 not the character is multibyte. Thus, in the future, we must
19895 consider eliminating the field `multibyte_p' in the struct
19897 int saved_multibyte_p
= it
->multibyte_p
;
19899 /* Maybe translate single-byte characters to multibyte, or the
19901 it
->char_to_display
= it
->c
;
19902 if (!ASCII_BYTE_P (it
->c
))
19904 if (unibyte_display_via_language_environment
19905 && SINGLE_BYTE_CHAR_P (it
->c
)
19907 || !NILP (Vnonascii_translation_table
)))
19909 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19910 it
->multibyte_p
= 1;
19911 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19912 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19914 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
19915 && !it
->multibyte_p
)
19917 it
->multibyte_p
= 1;
19918 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19919 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19923 /* Get font to use. Encode IT->char_to_display. */
19924 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19925 &char2b
, it
->multibyte_p
, 0);
19928 /* When no suitable font found, use the default font. */
19929 font_not_found_p
= font
== NULL
;
19930 if (font_not_found_p
)
19932 font
= FRAME_FONT (it
->f
);
19933 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19938 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19939 boff
= font_info
->baseline_offset
;
19940 if (font_info
->vertical_centering
)
19941 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19944 if (it
->char_to_display
>= ' '
19945 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
19947 /* Either unibyte or ASCII. */
19952 pcm
= rif
->per_char_metric (font
, &char2b
,
19953 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
19955 if (it
->override_ascent
>= 0)
19957 it
->ascent
= it
->override_ascent
;
19958 it
->descent
= it
->override_descent
;
19959 boff
= it
->override_boff
;
19963 it
->ascent
= FONT_BASE (font
) + boff
;
19964 it
->descent
= FONT_DESCENT (font
) - boff
;
19969 it
->phys_ascent
= pcm
->ascent
+ boff
;
19970 it
->phys_descent
= pcm
->descent
- boff
;
19971 it
->pixel_width
= pcm
->width
;
19975 it
->glyph_not_available_p
= 1;
19976 it
->phys_ascent
= it
->ascent
;
19977 it
->phys_descent
= it
->descent
;
19978 it
->pixel_width
= FONT_WIDTH (font
);
19981 if (it
->constrain_row_ascent_descent_p
)
19983 if (it
->descent
> it
->max_descent
)
19985 it
->ascent
+= it
->descent
- it
->max_descent
;
19986 it
->descent
= it
->max_descent
;
19988 if (it
->ascent
> it
->max_ascent
)
19990 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19991 it
->ascent
= it
->max_ascent
;
19993 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19994 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19995 extra_line_spacing
= 0;
19998 /* If this is a space inside a region of text with
19999 `space-width' property, change its width. */
20000 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
20002 it
->pixel_width
*= XFLOATINT (it
->space_width
);
20004 /* If face has a box, add the box thickness to the character
20005 height. If character has a box line to the left and/or
20006 right, add the box line width to the character's width. */
20007 if (face
->box
!= FACE_NO_BOX
)
20009 int thick
= face
->box_line_width
;
20013 it
->ascent
+= thick
;
20014 it
->descent
+= thick
;
20019 if (it
->start_of_box_run_p
)
20020 it
->pixel_width
+= thick
;
20021 if (it
->end_of_box_run_p
)
20022 it
->pixel_width
+= thick
;
20025 /* If face has an overline, add the height of the overline
20026 (1 pixel) and a 1 pixel margin to the character height. */
20027 if (face
->overline_p
)
20030 if (it
->constrain_row_ascent_descent_p
)
20032 if (it
->ascent
> it
->max_ascent
)
20033 it
->ascent
= it
->max_ascent
;
20034 if (it
->descent
> it
->max_descent
)
20035 it
->descent
= it
->max_descent
;
20038 take_vertical_position_into_account (it
);
20040 /* If we have to actually produce glyphs, do it. */
20045 /* Translate a space with a `space-width' property
20046 into a stretch glyph. */
20047 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
20048 / FONT_HEIGHT (font
));
20049 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20050 it
->ascent
+ it
->descent
, ascent
);
20055 /* If characters with lbearing or rbearing are displayed
20056 in this line, record that fact in a flag of the
20057 glyph row. This is used to optimize X output code. */
20058 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
20059 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20062 else if (it
->char_to_display
== '\n')
20064 /* A newline has no width but we need the height of the line.
20065 But if previous part of the line set a height, don't
20066 increase that height */
20068 Lisp_Object height
;
20069 Lisp_Object total_height
= Qnil
;
20071 it
->override_ascent
= -1;
20072 it
->pixel_width
= 0;
20075 height
= get_line_height_property(it
, Qline_height
);
20076 /* Split (line-height total-height) list */
20078 && CONSP (XCDR (height
))
20079 && NILP (XCDR (XCDR (height
))))
20081 total_height
= XCAR (XCDR (height
));
20082 height
= XCAR (height
);
20084 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
20086 if (it
->override_ascent
>= 0)
20088 it
->ascent
= it
->override_ascent
;
20089 it
->descent
= it
->override_descent
;
20090 boff
= it
->override_boff
;
20094 it
->ascent
= FONT_BASE (font
) + boff
;
20095 it
->descent
= FONT_DESCENT (font
) - boff
;
20098 if (EQ (height
, Qt
))
20100 if (it
->descent
> it
->max_descent
)
20102 it
->ascent
+= it
->descent
- it
->max_descent
;
20103 it
->descent
= it
->max_descent
;
20105 if (it
->ascent
> it
->max_ascent
)
20107 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20108 it
->ascent
= it
->max_ascent
;
20110 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20111 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20112 it
->constrain_row_ascent_descent_p
= 1;
20113 extra_line_spacing
= 0;
20117 Lisp_Object spacing
;
20119 it
->phys_ascent
= it
->ascent
;
20120 it
->phys_descent
= it
->descent
;
20122 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
20123 && face
->box
!= FACE_NO_BOX
20124 && face
->box_line_width
> 0)
20126 it
->ascent
+= face
->box_line_width
;
20127 it
->descent
+= face
->box_line_width
;
20130 && XINT (height
) > it
->ascent
+ it
->descent
)
20131 it
->ascent
= XINT (height
) - it
->descent
;
20133 if (!NILP (total_height
))
20134 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
20137 spacing
= get_line_height_property(it
, Qline_spacing
);
20138 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
20140 if (INTEGERP (spacing
))
20142 extra_line_spacing
= XINT (spacing
);
20143 if (!NILP (total_height
))
20144 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
20148 else if (it
->char_to_display
== '\t')
20150 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
20151 int x
= it
->current_x
+ it
->continuation_lines_width
;
20152 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
20154 /* If the distance from the current position to the next tab
20155 stop is less than a space character width, use the
20156 tab stop after that. */
20157 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
20158 next_tab_x
+= tab_width
;
20160 it
->pixel_width
= next_tab_x
- x
;
20162 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
20163 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20167 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20168 it
->ascent
+ it
->descent
, it
->ascent
);
20173 /* A multi-byte character. Assume that the display width of the
20174 character is the width of the character multiplied by the
20175 width of the font. */
20177 /* If we found a font, this font should give us the right
20178 metrics. If we didn't find a font, use the frame's
20179 default font and calculate the width of the character
20180 from the charset width; this is what old redisplay code
20183 pcm
= rif
->per_char_metric (font
, &char2b
,
20184 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
20186 if (font_not_found_p
|| !pcm
)
20188 int charset
= CHAR_CHARSET (it
->char_to_display
);
20190 it
->glyph_not_available_p
= 1;
20191 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
20192 * CHARSET_WIDTH (charset
));
20193 it
->phys_ascent
= FONT_BASE (font
) + boff
;
20194 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20198 it
->pixel_width
= pcm
->width
;
20199 it
->phys_ascent
= pcm
->ascent
+ boff
;
20200 it
->phys_descent
= pcm
->descent
- boff
;
20202 && (pcm
->lbearing
< 0
20203 || pcm
->rbearing
> pcm
->width
))
20204 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20207 it
->ascent
= FONT_BASE (font
) + boff
;
20208 it
->descent
= FONT_DESCENT (font
) - boff
;
20209 if (face
->box
!= FACE_NO_BOX
)
20211 int thick
= face
->box_line_width
;
20215 it
->ascent
+= thick
;
20216 it
->descent
+= thick
;
20221 if (it
->start_of_box_run_p
)
20222 it
->pixel_width
+= thick
;
20223 if (it
->end_of_box_run_p
)
20224 it
->pixel_width
+= thick
;
20227 /* If face has an overline, add the height of the overline
20228 (1 pixel) and a 1 pixel margin to the character height. */
20229 if (face
->overline_p
)
20232 take_vertical_position_into_account (it
);
20237 it
->multibyte_p
= saved_multibyte_p
;
20239 else if (it
->what
== IT_COMPOSITION
)
20241 /* Note: A composition is represented as one glyph in the
20242 glyph matrix. There are no padding glyphs. */
20245 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20247 int font_not_found_p
;
20248 struct font_info
*font_info
;
20249 int boff
; /* baseline offset */
20250 struct composition
*cmp
= composition_table
[it
->cmp_id
];
20252 /* Maybe translate single-byte characters to multibyte. */
20253 it
->char_to_display
= it
->c
;
20254 if (unibyte_display_via_language_environment
20255 && SINGLE_BYTE_CHAR_P (it
->c
)
20258 && !NILP (Vnonascii_translation_table
))))
20260 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20263 /* Get face and font to use. Encode IT->char_to_display. */
20264 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20265 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20266 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20267 &char2b
, it
->multibyte_p
, 0);
20270 /* When no suitable font found, use the default font. */
20271 font_not_found_p
= font
== NULL
;
20272 if (font_not_found_p
)
20274 font
= FRAME_FONT (it
->f
);
20275 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20280 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20281 boff
= font_info
->baseline_offset
;
20282 if (font_info
->vertical_centering
)
20283 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20286 /* There are no padding glyphs, so there is only one glyph to
20287 produce for the composition. Important is that pixel_width,
20288 ascent and descent are the values of what is drawn by
20289 draw_glyphs (i.e. the values of the overall glyphs composed). */
20292 /* If we have not yet calculated pixel size data of glyphs of
20293 the composition for the current face font, calculate them
20294 now. Theoretically, we have to check all fonts for the
20295 glyphs, but that requires much time and memory space. So,
20296 here we check only the font of the first glyph. This leads
20297 to incorrect display very rarely, and C-l (recenter) can
20298 correct the display anyway. */
20299 if (cmp
->font
!= (void *) font
)
20301 /* Ascent and descent of the font of the first character of
20302 this composition (adjusted by baseline offset). Ascent
20303 and descent of overall glyphs should not be less than
20304 them respectively. */
20305 int font_ascent
= FONT_BASE (font
) + boff
;
20306 int font_descent
= FONT_DESCENT (font
) - boff
;
20307 /* Bounding box of the overall glyphs. */
20308 int leftmost
, rightmost
, lowest
, highest
;
20309 int i
, width
, ascent
, descent
;
20311 cmp
->font
= (void *) font
;
20313 /* Initialize the bounding box. */
20315 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20316 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
20318 width
= pcm
->width
;
20319 ascent
= pcm
->ascent
;
20320 descent
= pcm
->descent
;
20324 width
= FONT_WIDTH (font
);
20325 ascent
= FONT_BASE (font
);
20326 descent
= FONT_DESCENT (font
);
20330 lowest
= - descent
+ boff
;
20331 highest
= ascent
+ boff
;
20335 && font_info
->default_ascent
20336 && CHAR_TABLE_P (Vuse_default_ascent
)
20337 && !NILP (Faref (Vuse_default_ascent
,
20338 make_number (it
->char_to_display
))))
20339 highest
= font_info
->default_ascent
+ boff
;
20341 /* Draw the first glyph at the normal position. It may be
20342 shifted to right later if some other glyphs are drawn at
20344 cmp
->offsets
[0] = 0;
20345 cmp
->offsets
[1] = boff
;
20347 /* Set cmp->offsets for the remaining glyphs. */
20348 for (i
= 1; i
< cmp
->glyph_len
; i
++)
20350 int left
, right
, btm
, top
;
20351 int ch
= COMPOSITION_GLYPH (cmp
, i
);
20352 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
20354 face
= FACE_FROM_ID (it
->f
, face_id
);
20355 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
20356 &char2b
, it
->multibyte_p
, 0);
20360 font
= FRAME_FONT (it
->f
);
20361 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20367 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20368 boff
= font_info
->baseline_offset
;
20369 if (font_info
->vertical_centering
)
20370 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20374 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20375 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
20377 width
= pcm
->width
;
20378 ascent
= pcm
->ascent
;
20379 descent
= pcm
->descent
;
20383 width
= FONT_WIDTH (font
);
20388 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
20390 /* Relative composition with or without
20391 alternate chars. */
20392 left
= (leftmost
+ rightmost
- width
) / 2;
20393 btm
= - descent
+ boff
;
20394 if (font_info
&& font_info
->relative_compose
20395 && (! CHAR_TABLE_P (Vignore_relative_composition
)
20396 || NILP (Faref (Vignore_relative_composition
,
20397 make_number (ch
)))))
20400 if (- descent
>= font_info
->relative_compose
)
20401 /* One extra pixel between two glyphs. */
20403 else if (ascent
<= 0)
20404 /* One extra pixel between two glyphs. */
20405 btm
= lowest
- 1 - ascent
- descent
;
20410 /* A composition rule is specified by an integer
20411 value that encodes global and new reference
20412 points (GREF and NREF). GREF and NREF are
20413 specified by numbers as below:
20415 0---1---2 -- ascent
20419 9--10--11 -- center
20421 ---3---4---5--- baseline
20423 6---7---8 -- descent
20425 int rule
= COMPOSITION_RULE (cmp
, i
);
20426 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
20428 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
20429 grefx
= gref
% 3, nrefx
= nref
% 3;
20430 grefy
= gref
/ 3, nrefy
= nref
/ 3;
20433 + grefx
* (rightmost
- leftmost
) / 2
20434 - nrefx
* width
/ 2);
20435 btm
= ((grefy
== 0 ? highest
20437 : grefy
== 2 ? lowest
20438 : (highest
+ lowest
) / 2)
20439 - (nrefy
== 0 ? ascent
+ descent
20440 : nrefy
== 1 ? descent
- boff
20442 : (ascent
+ descent
) / 2));
20445 cmp
->offsets
[i
* 2] = left
;
20446 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
20448 /* Update the bounding box of the overall glyphs. */
20449 right
= left
+ width
;
20450 top
= btm
+ descent
+ ascent
;
20451 if (left
< leftmost
)
20453 if (right
> rightmost
)
20461 /* If there are glyphs whose x-offsets are negative,
20462 shift all glyphs to the right and make all x-offsets
20466 for (i
= 0; i
< cmp
->glyph_len
; i
++)
20467 cmp
->offsets
[i
* 2] -= leftmost
;
20468 rightmost
-= leftmost
;
20471 cmp
->pixel_width
= rightmost
;
20472 cmp
->ascent
= highest
;
20473 cmp
->descent
= - lowest
;
20474 if (cmp
->ascent
< font_ascent
)
20475 cmp
->ascent
= font_ascent
;
20476 if (cmp
->descent
< font_descent
)
20477 cmp
->descent
= font_descent
;
20480 it
->pixel_width
= cmp
->pixel_width
;
20481 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
20482 it
->descent
= it
->phys_descent
= cmp
->descent
;
20484 if (face
->box
!= FACE_NO_BOX
)
20486 int thick
= face
->box_line_width
;
20490 it
->ascent
+= thick
;
20491 it
->descent
+= thick
;
20496 if (it
->start_of_box_run_p
)
20497 it
->pixel_width
+= thick
;
20498 if (it
->end_of_box_run_p
)
20499 it
->pixel_width
+= thick
;
20502 /* If face has an overline, add the height of the overline
20503 (1 pixel) and a 1 pixel margin to the character height. */
20504 if (face
->overline_p
)
20507 take_vertical_position_into_account (it
);
20510 append_composite_glyph (it
);
20512 else if (it
->what
== IT_IMAGE
)
20513 produce_image_glyph (it
);
20514 else if (it
->what
== IT_STRETCH
)
20515 produce_stretch_glyph (it
);
20517 /* Accumulate dimensions. Note: can't assume that it->descent > 0
20518 because this isn't true for images with `:ascent 100'. */
20519 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
20520 if (it
->area
== TEXT_AREA
)
20521 it
->current_x
+= it
->pixel_width
;
20523 if (extra_line_spacing
> 0)
20525 it
->descent
+= extra_line_spacing
;
20526 if (extra_line_spacing
> it
->max_extra_line_spacing
)
20527 it
->max_extra_line_spacing
= extra_line_spacing
;
20530 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
20531 it
->max_descent
= max (it
->max_descent
, it
->descent
);
20532 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
20533 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
20537 Output LEN glyphs starting at START at the nominal cursor position.
20538 Advance the nominal cursor over the text. The global variable
20539 updated_window contains the window being updated, updated_row is
20540 the glyph row being updated, and updated_area is the area of that
20541 row being updated. */
20544 x_write_glyphs (start
, len
)
20545 struct glyph
*start
;
20550 xassert (updated_window
&& updated_row
);
20553 /* Write glyphs. */
20555 hpos
= start
- updated_row
->glyphs
[updated_area
];
20556 x
= draw_glyphs (updated_window
, output_cursor
.x
,
20557 updated_row
, updated_area
,
20559 DRAW_NORMAL_TEXT
, 0);
20561 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
20562 if (updated_area
== TEXT_AREA
20563 && updated_window
->phys_cursor_on_p
20564 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
20565 && updated_window
->phys_cursor
.hpos
>= hpos
20566 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
20567 updated_window
->phys_cursor_on_p
= 0;
20571 /* Advance the output cursor. */
20572 output_cursor
.hpos
+= len
;
20573 output_cursor
.x
= x
;
20578 Insert LEN glyphs from START at the nominal cursor position. */
20581 x_insert_glyphs (start
, len
)
20582 struct glyph
*start
;
20587 int line_height
, shift_by_width
, shifted_region_width
;
20588 struct glyph_row
*row
;
20589 struct glyph
*glyph
;
20590 int frame_x
, frame_y
, hpos
;
20592 xassert (updated_window
&& updated_row
);
20594 w
= updated_window
;
20595 f
= XFRAME (WINDOW_FRAME (w
));
20597 /* Get the height of the line we are in. */
20599 line_height
= row
->height
;
20601 /* Get the width of the glyphs to insert. */
20602 shift_by_width
= 0;
20603 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
20604 shift_by_width
+= glyph
->pixel_width
;
20606 /* Get the width of the region to shift right. */
20607 shifted_region_width
= (window_box_width (w
, updated_area
)
20612 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
20613 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
20615 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
20616 line_height
, shift_by_width
);
20618 /* Write the glyphs. */
20619 hpos
= start
- row
->glyphs
[updated_area
];
20620 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
20622 DRAW_NORMAL_TEXT
, 0);
20624 /* Advance the output cursor. */
20625 output_cursor
.hpos
+= len
;
20626 output_cursor
.x
+= shift_by_width
;
20632 Erase the current text line from the nominal cursor position
20633 (inclusive) to pixel column TO_X (exclusive). The idea is that
20634 everything from TO_X onward is already erased.
20636 TO_X is a pixel position relative to updated_area of
20637 updated_window. TO_X == -1 means clear to the end of this area. */
20640 x_clear_end_of_line (to_x
)
20644 struct window
*w
= updated_window
;
20645 int max_x
, min_y
, max_y
;
20646 int from_x
, from_y
, to_y
;
20648 xassert (updated_window
&& updated_row
);
20649 f
= XFRAME (w
->frame
);
20651 if (updated_row
->full_width_p
)
20652 max_x
= WINDOW_TOTAL_WIDTH (w
);
20654 max_x
= window_box_width (w
, updated_area
);
20655 max_y
= window_text_bottom_y (w
);
20657 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
20658 of window. For TO_X > 0, truncate to end of drawing area. */
20664 to_x
= min (to_x
, max_x
);
20666 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
20668 /* Notice if the cursor will be cleared by this operation. */
20669 if (!updated_row
->full_width_p
)
20670 notice_overwritten_cursor (w
, updated_area
,
20671 output_cursor
.x
, -1,
20673 MATRIX_ROW_BOTTOM_Y (updated_row
));
20675 from_x
= output_cursor
.x
;
20677 /* Translate to frame coordinates. */
20678 if (updated_row
->full_width_p
)
20680 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
20681 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
20685 int area_left
= window_box_left (w
, updated_area
);
20686 from_x
+= area_left
;
20690 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
20691 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
20692 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
20694 /* Prevent inadvertently clearing to end of the X window. */
20695 if (to_x
> from_x
&& to_y
> from_y
)
20698 rif
->clear_frame_area (f
, from_x
, from_y
,
20699 to_x
- from_x
, to_y
- from_y
);
20704 #endif /* HAVE_WINDOW_SYSTEM */
20708 /***********************************************************************
20710 ***********************************************************************/
20712 /* Value is the internal representation of the specified cursor type
20713 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
20714 of the bar cursor. */
20716 static enum text_cursor_kinds
20717 get_specified_cursor_type (arg
, width
)
20721 enum text_cursor_kinds type
;
20726 if (EQ (arg
, Qbox
))
20727 return FILLED_BOX_CURSOR
;
20729 if (EQ (arg
, Qhollow
))
20730 return HOLLOW_BOX_CURSOR
;
20732 if (EQ (arg
, Qbar
))
20739 && EQ (XCAR (arg
), Qbar
)
20740 && INTEGERP (XCDR (arg
))
20741 && XINT (XCDR (arg
)) >= 0)
20743 *width
= XINT (XCDR (arg
));
20747 if (EQ (arg
, Qhbar
))
20750 return HBAR_CURSOR
;
20754 && EQ (XCAR (arg
), Qhbar
)
20755 && INTEGERP (XCDR (arg
))
20756 && XINT (XCDR (arg
)) >= 0)
20758 *width
= XINT (XCDR (arg
));
20759 return HBAR_CURSOR
;
20762 /* Treat anything unknown as "hollow box cursor".
20763 It was bad to signal an error; people have trouble fixing
20764 .Xdefaults with Emacs, when it has something bad in it. */
20765 type
= HOLLOW_BOX_CURSOR
;
20770 /* Set the default cursor types for specified frame. */
20772 set_frame_cursor_types (f
, arg
)
20779 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
20780 FRAME_CURSOR_WIDTH (f
) = width
;
20782 /* By default, set up the blink-off state depending on the on-state. */
20784 tem
= Fassoc (arg
, Vblink_cursor_alist
);
20787 FRAME_BLINK_OFF_CURSOR (f
)
20788 = get_specified_cursor_type (XCDR (tem
), &width
);
20789 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
20792 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
20796 /* Return the cursor we want to be displayed in window W. Return
20797 width of bar/hbar cursor through WIDTH arg. Return with
20798 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
20799 (i.e. if the `system caret' should track this cursor).
20801 In a mini-buffer window, we want the cursor only to appear if we
20802 are reading input from this window. For the selected window, we
20803 want the cursor type given by the frame parameter or buffer local
20804 setting of cursor-type. If explicitly marked off, draw no cursor.
20805 In all other cases, we want a hollow box cursor. */
20807 static enum text_cursor_kinds
20808 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
20810 struct glyph
*glyph
;
20812 int *active_cursor
;
20814 struct frame
*f
= XFRAME (w
->frame
);
20815 struct buffer
*b
= XBUFFER (w
->buffer
);
20816 int cursor_type
= DEFAULT_CURSOR
;
20817 Lisp_Object alt_cursor
;
20818 int non_selected
= 0;
20820 *active_cursor
= 1;
20823 if (cursor_in_echo_area
20824 && FRAME_HAS_MINIBUF_P (f
)
20825 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
20827 if (w
== XWINDOW (echo_area_window
))
20829 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
20831 *width
= FRAME_CURSOR_WIDTH (f
);
20832 return FRAME_DESIRED_CURSOR (f
);
20835 return get_specified_cursor_type (b
->cursor_type
, width
);
20838 *active_cursor
= 0;
20842 /* Nonselected window or nonselected frame. */
20843 else if (w
!= XWINDOW (f
->selected_window
)
20844 #ifdef HAVE_WINDOW_SYSTEM
20845 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
20849 *active_cursor
= 0;
20851 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
20857 /* Never display a cursor in a window in which cursor-type is nil. */
20858 if (NILP (b
->cursor_type
))
20861 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
20864 alt_cursor
= b
->cursor_in_non_selected_windows
;
20865 return get_specified_cursor_type (alt_cursor
, width
);
20868 /* Get the normal cursor type for this window. */
20869 if (EQ (b
->cursor_type
, Qt
))
20871 cursor_type
= FRAME_DESIRED_CURSOR (f
);
20872 *width
= FRAME_CURSOR_WIDTH (f
);
20875 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
20877 /* Use normal cursor if not blinked off. */
20878 if (!w
->cursor_off_p
)
20880 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
20881 if (cursor_type
== FILLED_BOX_CURSOR
)
20882 cursor_type
= HOLLOW_BOX_CURSOR
;
20884 return cursor_type
;
20887 /* Cursor is blinked off, so determine how to "toggle" it. */
20889 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
20890 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
20891 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
20893 /* Then see if frame has specified a specific blink off cursor type. */
20894 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
20896 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
20897 return FRAME_BLINK_OFF_CURSOR (f
);
20901 /* Some people liked having a permanently visible blinking cursor,
20902 while others had very strong opinions against it. So it was
20903 decided to remove it. KFS 2003-09-03 */
20905 /* Finally perform built-in cursor blinking:
20906 filled box <-> hollow box
20907 wide [h]bar <-> narrow [h]bar
20908 narrow [h]bar <-> no cursor
20909 other type <-> no cursor */
20911 if (cursor_type
== FILLED_BOX_CURSOR
)
20912 return HOLLOW_BOX_CURSOR
;
20914 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
20917 return cursor_type
;
20925 #ifdef HAVE_WINDOW_SYSTEM
20927 /* Notice when the text cursor of window W has been completely
20928 overwritten by a drawing operation that outputs glyphs in AREA
20929 starting at X0 and ending at X1 in the line starting at Y0 and
20930 ending at Y1. X coordinates are area-relative. X1 < 0 means all
20931 the rest of the line after X0 has been written. Y coordinates
20932 are window-relative. */
20935 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
20937 enum glyph_row_area area
;
20938 int x0
, y0
, x1
, y1
;
20940 int cx0
, cx1
, cy0
, cy1
;
20941 struct glyph_row
*row
;
20943 if (!w
->phys_cursor_on_p
)
20945 if (area
!= TEXT_AREA
)
20948 if (w
->phys_cursor
.vpos
< 0
20949 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
20950 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
20951 !(row
->enabled_p
&& row
->displays_text_p
)))
20954 if (row
->cursor_in_fringe_p
)
20956 row
->cursor_in_fringe_p
= 0;
20957 draw_fringe_bitmap (w
, row
, 0);
20958 w
->phys_cursor_on_p
= 0;
20962 cx0
= w
->phys_cursor
.x
;
20963 cx1
= cx0
+ w
->phys_cursor_width
;
20964 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
20967 /* The cursor image will be completely removed from the
20968 screen if the output area intersects the cursor area in
20969 y-direction. When we draw in [y0 y1[, and some part of
20970 the cursor is at y < y0, that part must have been drawn
20971 before. When scrolling, the cursor is erased before
20972 actually scrolling, so we don't come here. When not
20973 scrolling, the rows above the old cursor row must have
20974 changed, and in this case these rows must have written
20975 over the cursor image.
20977 Likewise if part of the cursor is below y1, with the
20978 exception of the cursor being in the first blank row at
20979 the buffer and window end because update_text_area
20980 doesn't draw that row. (Except when it does, but
20981 that's handled in update_text_area.) */
20983 cy0
= w
->phys_cursor
.y
;
20984 cy1
= cy0
+ w
->phys_cursor_height
;
20985 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
20988 w
->phys_cursor_on_p
= 0;
20991 #endif /* HAVE_WINDOW_SYSTEM */
20994 /************************************************************************
20996 ************************************************************************/
20998 #ifdef HAVE_WINDOW_SYSTEM
21001 Fix the display of area AREA of overlapping row ROW in window W
21002 with respect to the overlapping part OVERLAPS. */
21005 x_fix_overlapping_area (w
, row
, area
, overlaps
)
21007 struct glyph_row
*row
;
21008 enum glyph_row_area area
;
21016 for (i
= 0; i
< row
->used
[area
];)
21018 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
21020 int start
= i
, start_x
= x
;
21024 x
+= row
->glyphs
[area
][i
].pixel_width
;
21027 while (i
< row
->used
[area
]
21028 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
21030 draw_glyphs (w
, start_x
, row
, area
,
21032 DRAW_NORMAL_TEXT
, overlaps
);
21036 x
+= row
->glyphs
[area
][i
].pixel_width
;
21046 Draw the cursor glyph of window W in glyph row ROW. See the
21047 comment of draw_glyphs for the meaning of HL. */
21050 draw_phys_cursor_glyph (w
, row
, hl
)
21052 struct glyph_row
*row
;
21053 enum draw_glyphs_face hl
;
21055 /* If cursor hpos is out of bounds, don't draw garbage. This can
21056 happen in mini-buffer windows when switching between echo area
21057 glyphs and mini-buffer. */
21058 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
21060 int on_p
= w
->phys_cursor_on_p
;
21062 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
21063 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
21065 w
->phys_cursor_on_p
= on_p
;
21067 if (hl
== DRAW_CURSOR
)
21068 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21069 /* When we erase the cursor, and ROW is overlapped by other
21070 rows, make sure that these overlapping parts of other rows
21072 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
21074 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21076 if (row
> w
->current_matrix
->rows
21077 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
21078 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
21079 OVERLAPS_ERASED_CURSOR
);
21081 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
21082 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
21083 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
21084 OVERLAPS_ERASED_CURSOR
);
21091 Erase the image of a cursor of window W from the screen. */
21094 erase_phys_cursor (w
)
21097 struct frame
*f
= XFRAME (w
->frame
);
21098 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21099 int hpos
= w
->phys_cursor
.hpos
;
21100 int vpos
= w
->phys_cursor
.vpos
;
21101 int mouse_face_here_p
= 0;
21102 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
21103 struct glyph_row
*cursor_row
;
21104 struct glyph
*cursor_glyph
;
21105 enum draw_glyphs_face hl
;
21107 /* No cursor displayed or row invalidated => nothing to do on the
21109 if (w
->phys_cursor_type
== NO_CURSOR
)
21110 goto mark_cursor_off
;
21112 /* VPOS >= active_glyphs->nrows means that window has been resized.
21113 Don't bother to erase the cursor. */
21114 if (vpos
>= active_glyphs
->nrows
)
21115 goto mark_cursor_off
;
21117 /* If row containing cursor is marked invalid, there is nothing we
21119 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
21120 if (!cursor_row
->enabled_p
)
21121 goto mark_cursor_off
;
21123 /* If line spacing is > 0, old cursor may only be partially visible in
21124 window after split-window. So adjust visible height. */
21125 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
21126 window_text_bottom_y (w
) - cursor_row
->y
);
21128 /* If row is completely invisible, don't attempt to delete a cursor which
21129 isn't there. This can happen if cursor is at top of a window, and
21130 we switch to a buffer with a header line in that window. */
21131 if (cursor_row
->visible_height
<= 0)
21132 goto mark_cursor_off
;
21134 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
21135 if (cursor_row
->cursor_in_fringe_p
)
21137 cursor_row
->cursor_in_fringe_p
= 0;
21138 draw_fringe_bitmap (w
, cursor_row
, 0);
21139 goto mark_cursor_off
;
21142 /* This can happen when the new row is shorter than the old one.
21143 In this case, either draw_glyphs or clear_end_of_line
21144 should have cleared the cursor. Note that we wouldn't be
21145 able to erase the cursor in this case because we don't have a
21146 cursor glyph at hand. */
21147 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
21148 goto mark_cursor_off
;
21150 /* If the cursor is in the mouse face area, redisplay that when
21151 we clear the cursor. */
21152 if (! NILP (dpyinfo
->mouse_face_window
)
21153 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
21154 && (vpos
> dpyinfo
->mouse_face_beg_row
21155 || (vpos
== dpyinfo
->mouse_face_beg_row
21156 && hpos
>= dpyinfo
->mouse_face_beg_col
))
21157 && (vpos
< dpyinfo
->mouse_face_end_row
21158 || (vpos
== dpyinfo
->mouse_face_end_row
21159 && hpos
< dpyinfo
->mouse_face_end_col
))
21160 /* Don't redraw the cursor's spot in mouse face if it is at the
21161 end of a line (on a newline). The cursor appears there, but
21162 mouse highlighting does not. */
21163 && cursor_row
->used
[TEXT_AREA
] > hpos
)
21164 mouse_face_here_p
= 1;
21166 /* Maybe clear the display under the cursor. */
21167 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
21170 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
21173 cursor_glyph
= get_phys_cursor_glyph (w
);
21174 if (cursor_glyph
== NULL
)
21175 goto mark_cursor_off
;
21177 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
21178 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
21179 width
= min (cursor_glyph
->pixel_width
,
21180 window_box_width (w
, TEXT_AREA
) - w
->phys_cursor
.x
);
21182 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
21185 /* Erase the cursor by redrawing the character underneath it. */
21186 if (mouse_face_here_p
)
21187 hl
= DRAW_MOUSE_FACE
;
21189 hl
= DRAW_NORMAL_TEXT
;
21190 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
21193 w
->phys_cursor_on_p
= 0;
21194 w
->phys_cursor_type
= NO_CURSOR
;
21199 Display or clear cursor of window W. If ON is zero, clear the
21200 cursor. If it is non-zero, display the cursor. If ON is nonzero,
21201 where to put the cursor is specified by HPOS, VPOS, X and Y. */
21204 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
21206 int on
, hpos
, vpos
, x
, y
;
21208 struct frame
*f
= XFRAME (w
->frame
);
21209 int new_cursor_type
;
21210 int new_cursor_width
;
21212 struct glyph_row
*glyph_row
;
21213 struct glyph
*glyph
;
21215 /* This is pointless on invisible frames, and dangerous on garbaged
21216 windows and frames; in the latter case, the frame or window may
21217 be in the midst of changing its size, and x and y may be off the
21219 if (! FRAME_VISIBLE_P (f
)
21220 || FRAME_GARBAGED_P (f
)
21221 || vpos
>= w
->current_matrix
->nrows
21222 || hpos
>= w
->current_matrix
->matrix_w
)
21225 /* If cursor is off and we want it off, return quickly. */
21226 if (!on
&& !w
->phys_cursor_on_p
)
21229 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
21230 /* If cursor row is not enabled, we don't really know where to
21231 display the cursor. */
21232 if (!glyph_row
->enabled_p
)
21234 w
->phys_cursor_on_p
= 0;
21239 if (!glyph_row
->exact_window_width_line_p
21240 || hpos
< glyph_row
->used
[TEXT_AREA
])
21241 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
21243 xassert (interrupt_input_blocked
);
21245 /* Set new_cursor_type to the cursor we want to be displayed. */
21246 new_cursor_type
= get_window_cursor_type (w
, glyph
,
21247 &new_cursor_width
, &active_cursor
);
21249 /* If cursor is currently being shown and we don't want it to be or
21250 it is in the wrong place, or the cursor type is not what we want,
21252 if (w
->phys_cursor_on_p
21254 || w
->phys_cursor
.x
!= x
21255 || w
->phys_cursor
.y
!= y
21256 || new_cursor_type
!= w
->phys_cursor_type
21257 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
21258 && new_cursor_width
!= w
->phys_cursor_width
)))
21259 erase_phys_cursor (w
);
21261 /* Don't check phys_cursor_on_p here because that flag is only set
21262 to zero in some cases where we know that the cursor has been
21263 completely erased, to avoid the extra work of erasing the cursor
21264 twice. In other words, phys_cursor_on_p can be 1 and the cursor
21265 still not be visible, or it has only been partly erased. */
21268 w
->phys_cursor_ascent
= glyph_row
->ascent
;
21269 w
->phys_cursor_height
= glyph_row
->height
;
21271 /* Set phys_cursor_.* before x_draw_.* is called because some
21272 of them may need the information. */
21273 w
->phys_cursor
.x
= x
;
21274 w
->phys_cursor
.y
= glyph_row
->y
;
21275 w
->phys_cursor
.hpos
= hpos
;
21276 w
->phys_cursor
.vpos
= vpos
;
21279 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
21280 new_cursor_type
, new_cursor_width
,
21281 on
, active_cursor
);
21285 /* Switch the display of W's cursor on or off, according to the value
21289 update_window_cursor (w
, on
)
21293 /* Don't update cursor in windows whose frame is in the process
21294 of being deleted. */
21295 if (w
->current_matrix
)
21298 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21299 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21305 /* Call update_window_cursor with parameter ON_P on all leaf windows
21306 in the window tree rooted at W. */
21309 update_cursor_in_window_tree (w
, on_p
)
21315 if (!NILP (w
->hchild
))
21316 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
21317 else if (!NILP (w
->vchild
))
21318 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
21320 update_window_cursor (w
, on_p
);
21322 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
21328 Display the cursor on window W, or clear it, according to ON_P.
21329 Don't change the cursor's position. */
21332 x_update_cursor (f
, on_p
)
21336 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
21341 Clear the cursor of window W to background color, and mark the
21342 cursor as not shown. This is used when the text where the cursor
21343 is is about to be rewritten. */
21349 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
21350 update_window_cursor (w
, 0);
21355 Display the active region described by mouse_face_* according to DRAW. */
21358 show_mouse_face (dpyinfo
, draw
)
21359 Display_Info
*dpyinfo
;
21360 enum draw_glyphs_face draw
;
21362 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
21363 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21365 if (/* If window is in the process of being destroyed, don't bother
21367 w
->current_matrix
!= NULL
21368 /* Don't update mouse highlight if hidden */
21369 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
21370 /* Recognize when we are called to operate on rows that don't exist
21371 anymore. This can happen when a window is split. */
21372 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
21374 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
21375 struct glyph_row
*row
, *first
, *last
;
21377 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
21378 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
21380 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
21382 int start_hpos
, end_hpos
, start_x
;
21384 /* For all but the first row, the highlight starts at column 0. */
21387 start_hpos
= dpyinfo
->mouse_face_beg_col
;
21388 start_x
= dpyinfo
->mouse_face_beg_x
;
21397 end_hpos
= dpyinfo
->mouse_face_end_col
;
21400 end_hpos
= row
->used
[TEXT_AREA
];
21401 if (draw
== DRAW_NORMAL_TEXT
)
21402 row
->fill_line_p
= 1; /* Clear to end of line */
21405 if (end_hpos
> start_hpos
)
21407 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
21408 start_hpos
, end_hpos
,
21412 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
21416 /* When we've written over the cursor, arrange for it to
21417 be displayed again. */
21418 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
21421 display_and_set_cursor (w
, 1,
21422 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21423 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21428 /* Change the mouse cursor. */
21429 if (draw
== DRAW_NORMAL_TEXT
)
21430 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
21431 else if (draw
== DRAW_MOUSE_FACE
)
21432 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
21434 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
21438 Clear out the mouse-highlighted active region.
21439 Redraw it un-highlighted first. Value is non-zero if mouse
21440 face was actually drawn unhighlighted. */
21443 clear_mouse_face (dpyinfo
)
21444 Display_Info
*dpyinfo
;
21448 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
21450 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
21454 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21455 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21456 dpyinfo
->mouse_face_window
= Qnil
;
21457 dpyinfo
->mouse_face_overlay
= Qnil
;
21463 Non-zero if physical cursor of window W is within mouse face. */
21466 cursor_in_mouse_face_p (w
)
21469 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21470 int in_mouse_face
= 0;
21472 if (WINDOWP (dpyinfo
->mouse_face_window
)
21473 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
21475 int hpos
= w
->phys_cursor
.hpos
;
21476 int vpos
= w
->phys_cursor
.vpos
;
21478 if (vpos
>= dpyinfo
->mouse_face_beg_row
21479 && vpos
<= dpyinfo
->mouse_face_end_row
21480 && (vpos
> dpyinfo
->mouse_face_beg_row
21481 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21482 && (vpos
< dpyinfo
->mouse_face_end_row
21483 || hpos
< dpyinfo
->mouse_face_end_col
21484 || dpyinfo
->mouse_face_past_end
))
21488 return in_mouse_face
;
21494 /* Find the glyph matrix position of buffer position CHARPOS in window
21495 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
21496 current glyphs must be up to date. If CHARPOS is above window
21497 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
21498 of last line in W. In the row containing CHARPOS, stop before glyphs
21499 having STOP as object. */
21501 #if 1 /* This is a version of fast_find_position that's more correct
21502 in the presence of hscrolling, for example. I didn't install
21503 it right away because the problem fixed is minor, it failed
21504 in 20.x as well, and I think it's too risky to install
21505 so near the release of 21.1. 2001-09-25 gerd. */
21508 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
21511 int *hpos
, *vpos
, *x
, *y
;
21514 struct glyph_row
*row
, *first
;
21515 struct glyph
*glyph
, *end
;
21518 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21519 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
21524 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
21528 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
21531 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
21535 /* If whole rows or last part of a row came from a display overlay,
21536 row_containing_pos will skip over such rows because their end pos
21537 equals the start pos of the overlay or interval.
21539 Move back if we have a STOP object and previous row's
21540 end glyph came from STOP. */
21543 struct glyph_row
*prev
;
21544 while ((prev
= row
- 1, prev
>= first
)
21545 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
21546 && prev
->used
[TEXT_AREA
] > 0)
21548 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
21549 glyph
= beg
+ prev
->used
[TEXT_AREA
];
21550 while (--glyph
>= beg
21551 && INTEGERP (glyph
->object
));
21553 || !EQ (stop
, glyph
->object
))
21561 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21563 glyph
= row
->glyphs
[TEXT_AREA
];
21564 end
= glyph
+ row
->used
[TEXT_AREA
];
21566 /* Skip over glyphs not having an object at the start of the row.
21567 These are special glyphs like truncation marks on terminal
21569 if (row
->displays_text_p
)
21571 && INTEGERP (glyph
->object
)
21572 && !EQ (stop
, glyph
->object
)
21573 && glyph
->charpos
< 0)
21575 *x
+= glyph
->pixel_width
;
21580 && !INTEGERP (glyph
->object
)
21581 && !EQ (stop
, glyph
->object
)
21582 && (!BUFFERP (glyph
->object
)
21583 || glyph
->charpos
< charpos
))
21585 *x
+= glyph
->pixel_width
;
21589 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
21596 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
21599 int *hpos
, *vpos
, *x
, *y
;
21604 int maybe_next_line_p
= 0;
21605 int line_start_position
;
21606 int yb
= window_text_bottom_y (w
);
21607 struct glyph_row
*row
, *best_row
;
21608 int row_vpos
, best_row_vpos
;
21611 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21612 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21614 while (row
->y
< yb
)
21616 if (row
->used
[TEXT_AREA
])
21617 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
21619 line_start_position
= 0;
21621 if (line_start_position
> pos
)
21623 /* If the position sought is the end of the buffer,
21624 don't include the blank lines at the bottom of the window. */
21625 else if (line_start_position
== pos
21626 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
21628 maybe_next_line_p
= 1;
21631 else if (line_start_position
> 0)
21634 best_row_vpos
= row_vpos
;
21637 if (row
->y
+ row
->height
>= yb
)
21644 /* Find the right column within BEST_ROW. */
21646 current_x
= best_row
->x
;
21647 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
21649 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
21650 int charpos
= glyph
->charpos
;
21652 if (BUFFERP (glyph
->object
))
21654 if (charpos
== pos
)
21657 *vpos
= best_row_vpos
;
21662 else if (charpos
> pos
)
21665 else if (EQ (glyph
->object
, stop
))
21670 current_x
+= glyph
->pixel_width
;
21673 /* If we're looking for the end of the buffer,
21674 and we didn't find it in the line we scanned,
21675 use the start of the following line. */
21676 if (maybe_next_line_p
)
21681 current_x
= best_row
->x
;
21684 *vpos
= best_row_vpos
;
21685 *hpos
= lastcol
+ 1;
21694 /* Find the position of the glyph for position POS in OBJECT in
21695 window W's current matrix, and return in *X, *Y the pixel
21696 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
21698 RIGHT_P non-zero means return the position of the right edge of the
21699 glyph, RIGHT_P zero means return the left edge position.
21701 If no glyph for POS exists in the matrix, return the position of
21702 the glyph with the next smaller position that is in the matrix, if
21703 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
21704 exists in the matrix, return the position of the glyph with the
21705 next larger position in OBJECT.
21707 Value is non-zero if a glyph was found. */
21710 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
21713 Lisp_Object object
;
21714 int *hpos
, *vpos
, *x
, *y
;
21717 int yb
= window_text_bottom_y (w
);
21718 struct glyph_row
*r
;
21719 struct glyph
*best_glyph
= NULL
;
21720 struct glyph_row
*best_row
= NULL
;
21723 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21724 r
->enabled_p
&& r
->y
< yb
;
21727 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
21728 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
21731 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
21732 if (EQ (g
->object
, object
))
21734 if (g
->charpos
== pos
)
21741 else if (best_glyph
== NULL
21742 || ((abs (g
->charpos
- pos
)
21743 < abs (best_glyph
->charpos
- pos
))
21746 : g
->charpos
> pos
)))
21760 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
21764 *x
+= best_glyph
->pixel_width
;
21769 *vpos
= best_row
- w
->current_matrix
->rows
;
21772 return best_glyph
!= NULL
;
21776 /* See if position X, Y is within a hot-spot of an image. */
21779 on_hot_spot_p (hot_spot
, x
, y
)
21780 Lisp_Object hot_spot
;
21783 if (!CONSP (hot_spot
))
21786 if (EQ (XCAR (hot_spot
), Qrect
))
21788 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
21789 Lisp_Object rect
= XCDR (hot_spot
);
21793 if (!CONSP (XCAR (rect
)))
21795 if (!CONSP (XCDR (rect
)))
21797 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
21799 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
21801 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
21803 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
21807 else if (EQ (XCAR (hot_spot
), Qcircle
))
21809 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
21810 Lisp_Object circ
= XCDR (hot_spot
);
21811 Lisp_Object lr
, lx0
, ly0
;
21813 && CONSP (XCAR (circ
))
21814 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
21815 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
21816 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
21818 double r
= XFLOATINT (lr
);
21819 double dx
= XINT (lx0
) - x
;
21820 double dy
= XINT (ly0
) - y
;
21821 return (dx
* dx
+ dy
* dy
<= r
* r
);
21824 else if (EQ (XCAR (hot_spot
), Qpoly
))
21826 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
21827 if (VECTORP (XCDR (hot_spot
)))
21829 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
21830 Lisp_Object
*poly
= v
->contents
;
21834 Lisp_Object lx
, ly
;
21837 /* Need an even number of coordinates, and at least 3 edges. */
21838 if (n
< 6 || n
& 1)
21841 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
21842 If count is odd, we are inside polygon. Pixels on edges
21843 may or may not be included depending on actual geometry of the
21845 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
21846 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
21848 x0
= XINT (lx
), y0
= XINT (ly
);
21849 for (i
= 0; i
< n
; i
+= 2)
21851 int x1
= x0
, y1
= y0
;
21852 if ((lx
= poly
[i
], !INTEGERP (lx
))
21853 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
21855 x0
= XINT (lx
), y0
= XINT (ly
);
21857 /* Does this segment cross the X line? */
21865 if (y
> y0
&& y
> y1
)
21867 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
21873 /* If we don't understand the format, pretend we're not in the hot-spot. */
21878 find_hot_spot (map
, x
, y
)
21882 while (CONSP (map
))
21884 if (CONSP (XCAR (map
))
21885 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
21893 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
21895 doc
: /* Lookup in image map MAP coordinates X and Y.
21896 An image map is an alist where each element has the format (AREA ID PLIST).
21897 An AREA is specified as either a rectangle, a circle, or a polygon:
21898 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
21899 pixel coordinates of the upper left and bottom right corners.
21900 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
21901 and the radius of the circle; r may be a float or integer.
21902 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
21903 vector describes one corner in the polygon.
21904 Returns the alist element for the first matching AREA in MAP. */)
21915 return find_hot_spot (map
, XINT (x
), XINT (y
));
21919 /* Display frame CURSOR, optionally using shape defined by POINTER. */
21921 define_frame_cursor1 (f
, cursor
, pointer
)
21924 Lisp_Object pointer
;
21926 /* Do not change cursor shape while dragging mouse. */
21927 if (!NILP (do_mouse_tracking
))
21930 if (!NILP (pointer
))
21932 if (EQ (pointer
, Qarrow
))
21933 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21934 else if (EQ (pointer
, Qhand
))
21935 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
21936 else if (EQ (pointer
, Qtext
))
21937 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21938 else if (EQ (pointer
, intern ("hdrag")))
21939 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21940 #ifdef HAVE_X_WINDOWS
21941 else if (EQ (pointer
, intern ("vdrag")))
21942 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
21944 else if (EQ (pointer
, intern ("hourglass")))
21945 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
21946 else if (EQ (pointer
, Qmodeline
))
21947 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
21949 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21952 if (cursor
!= No_Cursor
)
21953 rif
->define_frame_cursor (f
, cursor
);
21956 /* Take proper action when mouse has moved to the mode or header line
21957 or marginal area AREA of window W, x-position X and y-position Y.
21958 X is relative to the start of the text display area of W, so the
21959 width of bitmap areas and scroll bars must be subtracted to get a
21960 position relative to the start of the mode line. */
21963 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
21964 Lisp_Object window
;
21966 enum window_part area
;
21968 struct window
*w
= XWINDOW (window
);
21969 struct frame
*f
= XFRAME (w
->frame
);
21970 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21971 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21972 Lisp_Object pointer
= Qnil
;
21973 int charpos
, dx
, dy
, width
, height
;
21974 Lisp_Object string
, object
= Qnil
;
21975 Lisp_Object pos
, help
;
21977 Lisp_Object mouse_face
;
21978 int original_x_pixel
= x
;
21979 struct glyph
* glyph
= NULL
;
21980 struct glyph_row
*row
;
21982 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
21987 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
21988 &object
, &dx
, &dy
, &width
, &height
);
21990 row
= (area
== ON_MODE_LINE
21991 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
21992 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
21995 if (row
->mode_line_p
&& row
->enabled_p
)
21997 glyph
= row
->glyphs
[TEXT_AREA
];
21998 end
= glyph
+ row
->used
[TEXT_AREA
];
22000 for (x0
= original_x_pixel
;
22001 glyph
< end
&& x0
>= glyph
->pixel_width
;
22003 x0
-= glyph
->pixel_width
;
22011 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
22012 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
22013 &object
, &dx
, &dy
, &width
, &height
);
22018 if (IMAGEP (object
))
22020 Lisp_Object image_map
, hotspot
;
22021 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
22023 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
22025 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22027 Lisp_Object area_id
, plist
;
22029 area_id
= XCAR (hotspot
);
22030 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22031 If so, we could look for mouse-enter, mouse-leave
22032 properties in PLIST (and do something...). */
22033 hotspot
= XCDR (hotspot
);
22034 if (CONSP (hotspot
)
22035 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22037 pointer
= Fplist_get (plist
, Qpointer
);
22038 if (NILP (pointer
))
22040 help
= Fplist_get (plist
, Qhelp_echo
);
22043 help_echo_string
= help
;
22044 /* Is this correct? ++kfs */
22045 XSETWINDOW (help_echo_window
, w
);
22046 help_echo_object
= w
->buffer
;
22047 help_echo_pos
= charpos
;
22051 if (NILP (pointer
))
22052 pointer
= Fplist_get (XCDR (object
), QCpointer
);
22055 if (STRINGP (string
))
22057 pos
= make_number (charpos
);
22058 /* If we're on a string with `help-echo' text property, arrange
22059 for the help to be displayed. This is done by setting the
22060 global variable help_echo_string to the help string. */
22063 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
22066 help_echo_string
= help
;
22067 XSETWINDOW (help_echo_window
, w
);
22068 help_echo_object
= string
;
22069 help_echo_pos
= charpos
;
22073 if (NILP (pointer
))
22074 pointer
= Fget_text_property (pos
, Qpointer
, string
);
22076 /* Change the mouse pointer according to what is under X/Y. */
22077 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
22080 map
= Fget_text_property (pos
, Qlocal_map
, string
);
22081 if (!KEYMAPP (map
))
22082 map
= Fget_text_property (pos
, Qkeymap
, string
);
22083 if (!KEYMAPP (map
))
22084 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
22087 /* Change the mouse face according to what is under X/Y. */
22088 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
22089 if (!NILP (mouse_face
)
22090 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22095 struct glyph
* tmp_glyph
;
22099 int total_pixel_width
;
22104 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
22105 Qmouse_face
, string
, Qnil
);
22107 b
= make_number (0);
22109 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
22111 e
= make_number (SCHARS (string
));
22113 /* Calculate the position(glyph position: GPOS) of GLYPH in
22114 displayed string. GPOS is different from CHARPOS.
22116 CHARPOS is the position of glyph in internal string
22117 object. A mode line string format has structures which
22118 is converted to a flatten by emacs lisp interpreter.
22119 The internal string is an element of the structures.
22120 The displayed string is the flatten string. */
22121 for (tmp_glyph
= glyph
- 1, gpos
= 0;
22122 tmp_glyph
->charpos
>= XINT (b
);
22123 tmp_glyph
--, gpos
++)
22125 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22129 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
22130 displayed string holding GLYPH.
22132 GSEQ_LENGTH is different from SCHARS (STRING).
22133 SCHARS (STRING) returns the length of the internal string. */
22134 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
22135 tmp_glyph
->charpos
< XINT (e
);
22136 tmp_glyph
++, gseq_length
++)
22138 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22142 total_pixel_width
= 0;
22143 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
22144 total_pixel_width
+= tmp_glyph
->pixel_width
;
22146 /* Pre calculation of re-rendering position */
22148 hpos
= (area
== ON_MODE_LINE
22149 ? (w
->current_matrix
)->nrows
- 1
22152 /* If the re-rendering position is included in the last
22153 re-rendering area, we should do nothing. */
22154 if ( EQ (window
, dpyinfo
->mouse_face_window
)
22155 && dpyinfo
->mouse_face_beg_col
<= vpos
22156 && vpos
< dpyinfo
->mouse_face_end_col
22157 && dpyinfo
->mouse_face_beg_row
== hpos
)
22160 if (clear_mouse_face (dpyinfo
))
22161 cursor
= No_Cursor
;
22163 dpyinfo
->mouse_face_beg_col
= vpos
;
22164 dpyinfo
->mouse_face_beg_row
= hpos
;
22166 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
22167 dpyinfo
->mouse_face_beg_y
= 0;
22169 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
22170 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
22172 dpyinfo
->mouse_face_end_x
= 0;
22173 dpyinfo
->mouse_face_end_y
= 0;
22175 dpyinfo
->mouse_face_past_end
= 0;
22176 dpyinfo
->mouse_face_window
= window
;
22178 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
22181 glyph
->face_id
, 1);
22182 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22184 if (NILP (pointer
))
22187 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22188 clear_mouse_face (dpyinfo
);
22190 define_frame_cursor1 (f
, cursor
, pointer
);
22195 Take proper action when the mouse has moved to position X, Y on
22196 frame F as regards highlighting characters that have mouse-face
22197 properties. Also de-highlighting chars where the mouse was before.
22198 X and Y can be negative or out of range. */
22201 note_mouse_highlight (f
, x
, y
)
22205 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22206 enum window_part part
;
22207 Lisp_Object window
;
22209 Cursor cursor
= No_Cursor
;
22210 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
22213 /* When a menu is active, don't highlight because this looks odd. */
22214 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
22215 if (popup_activated ())
22219 if (NILP (Vmouse_highlight
)
22220 || !f
->glyphs_initialized_p
)
22223 dpyinfo
->mouse_face_mouse_x
= x
;
22224 dpyinfo
->mouse_face_mouse_y
= y
;
22225 dpyinfo
->mouse_face_mouse_frame
= f
;
22227 if (dpyinfo
->mouse_face_defer
)
22230 if (gc_in_progress
)
22232 dpyinfo
->mouse_face_deferred_gc
= 1;
22236 /* Which window is that in? */
22237 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
22239 /* If we were displaying active text in another window, clear that.
22240 Also clear if we move out of text area in same window. */
22241 if (! EQ (window
, dpyinfo
->mouse_face_window
)
22242 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
22243 && !NILP (dpyinfo
->mouse_face_window
)))
22244 clear_mouse_face (dpyinfo
);
22246 /* Not on a window -> return. */
22247 if (!WINDOWP (window
))
22250 /* Reset help_echo_string. It will get recomputed below. */
22251 help_echo_string
= Qnil
;
22253 /* Convert to window-relative pixel coordinates. */
22254 w
= XWINDOW (window
);
22255 frame_to_window_pixel_xy (w
, &x
, &y
);
22257 /* Handle tool-bar window differently since it doesn't display a
22259 if (EQ (window
, f
->tool_bar_window
))
22261 note_tool_bar_highlight (f
, x
, y
);
22265 /* Mouse is on the mode, header line or margin? */
22266 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
22267 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
22269 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
22273 if (part
== ON_VERTICAL_BORDER
)
22274 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22275 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
22276 || part
== ON_SCROLL_BAR
)
22277 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22279 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22281 /* Are we in a window whose display is up to date?
22282 And verify the buffer's text has not changed. */
22283 b
= XBUFFER (w
->buffer
);
22284 if (part
== ON_TEXT
22285 && EQ (w
->window_end_valid
, w
->buffer
)
22286 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
22287 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
22289 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
22290 struct glyph
*glyph
;
22291 Lisp_Object object
;
22292 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
22293 Lisp_Object
*overlay_vec
= NULL
;
22295 struct buffer
*obuf
;
22296 int obegv
, ozv
, same_region
;
22298 /* Find the glyph under X/Y. */
22299 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
22301 /* Look for :pointer property on image. */
22302 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22304 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22305 if (img
!= NULL
&& IMAGEP (img
->spec
))
22307 Lisp_Object image_map
, hotspot
;
22308 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
22310 && (hotspot
= find_hot_spot (image_map
,
22311 glyph
->slice
.x
+ dx
,
22312 glyph
->slice
.y
+ dy
),
22314 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22316 Lisp_Object area_id
, plist
;
22318 area_id
= XCAR (hotspot
);
22319 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22320 If so, we could look for mouse-enter, mouse-leave
22321 properties in PLIST (and do something...). */
22322 hotspot
= XCDR (hotspot
);
22323 if (CONSP (hotspot
)
22324 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22326 pointer
= Fplist_get (plist
, Qpointer
);
22327 if (NILP (pointer
))
22329 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
22330 if (!NILP (help_echo_string
))
22332 help_echo_window
= window
;
22333 help_echo_object
= glyph
->object
;
22334 help_echo_pos
= glyph
->charpos
;
22338 if (NILP (pointer
))
22339 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
22343 /* Clear mouse face if X/Y not over text. */
22345 || area
!= TEXT_AREA
22346 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
22348 if (clear_mouse_face (dpyinfo
))
22349 cursor
= No_Cursor
;
22350 if (NILP (pointer
))
22352 if (area
!= TEXT_AREA
)
22353 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22355 pointer
= Vvoid_text_area_pointer
;
22360 pos
= glyph
->charpos
;
22361 object
= glyph
->object
;
22362 if (!STRINGP (object
) && !BUFFERP (object
))
22365 /* If we get an out-of-range value, return now; avoid an error. */
22366 if (BUFFERP (object
) && pos
> BUF_Z (b
))
22369 /* Make the window's buffer temporarily current for
22370 overlays_at and compute_char_face. */
22371 obuf
= current_buffer
;
22372 current_buffer
= b
;
22378 /* Is this char mouse-active or does it have help-echo? */
22379 position
= make_number (pos
);
22381 if (BUFFERP (object
))
22383 /* Put all the overlays we want in a vector in overlay_vec. */
22384 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
22385 /* Sort overlays into increasing priority order. */
22386 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
22391 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
22392 && vpos
>= dpyinfo
->mouse_face_beg_row
22393 && vpos
<= dpyinfo
->mouse_face_end_row
22394 && (vpos
> dpyinfo
->mouse_face_beg_row
22395 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22396 && (vpos
< dpyinfo
->mouse_face_end_row
22397 || hpos
< dpyinfo
->mouse_face_end_col
22398 || dpyinfo
->mouse_face_past_end
));
22401 cursor
= No_Cursor
;
22403 /* Check mouse-face highlighting. */
22405 /* If there exists an overlay with mouse-face overlapping
22406 the one we are currently highlighting, we have to
22407 check if we enter the overlapping overlay, and then
22408 highlight only that. */
22409 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
22410 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
22412 /* Find the highest priority overlay that has a mouse-face
22415 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
22417 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
22418 if (!NILP (mouse_face
))
22419 overlay
= overlay_vec
[i
];
22422 /* If we're actually highlighting the same overlay as
22423 before, there's no need to do that again. */
22424 if (!NILP (overlay
)
22425 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
22426 goto check_help_echo
;
22428 dpyinfo
->mouse_face_overlay
= overlay
;
22430 /* Clear the display of the old active region, if any. */
22431 if (clear_mouse_face (dpyinfo
))
22432 cursor
= No_Cursor
;
22434 /* If no overlay applies, get a text property. */
22435 if (NILP (overlay
))
22436 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
22438 /* Handle the overlay case. */
22439 if (!NILP (overlay
))
22441 /* Find the range of text around this char that
22442 should be active. */
22443 Lisp_Object before
, after
;
22446 before
= Foverlay_start (overlay
);
22447 after
= Foverlay_end (overlay
);
22448 /* Record this as the current active region. */
22449 fast_find_position (w
, XFASTINT (before
),
22450 &dpyinfo
->mouse_face_beg_col
,
22451 &dpyinfo
->mouse_face_beg_row
,
22452 &dpyinfo
->mouse_face_beg_x
,
22453 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22455 dpyinfo
->mouse_face_past_end
22456 = !fast_find_position (w
, XFASTINT (after
),
22457 &dpyinfo
->mouse_face_end_col
,
22458 &dpyinfo
->mouse_face_end_row
,
22459 &dpyinfo
->mouse_face_end_x
,
22460 &dpyinfo
->mouse_face_end_y
, Qnil
);
22461 dpyinfo
->mouse_face_window
= window
;
22463 dpyinfo
->mouse_face_face_id
22464 = face_at_buffer_position (w
, pos
, 0, 0,
22466 !dpyinfo
->mouse_face_hidden
);
22468 /* Display it as active. */
22469 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22470 cursor
= No_Cursor
;
22472 /* Handle the text property case. */
22473 else if (!NILP (mouse_face
) && BUFFERP (object
))
22475 /* Find the range of text around this char that
22476 should be active. */
22477 Lisp_Object before
, after
, beginning
, end
;
22480 beginning
= Fmarker_position (w
->start
);
22481 end
= make_number (BUF_Z (XBUFFER (object
))
22482 - XFASTINT (w
->window_end_pos
));
22484 = Fprevious_single_property_change (make_number (pos
+ 1),
22486 object
, beginning
);
22488 = Fnext_single_property_change (position
, Qmouse_face
,
22491 /* Record this as the current active region. */
22492 fast_find_position (w
, XFASTINT (before
),
22493 &dpyinfo
->mouse_face_beg_col
,
22494 &dpyinfo
->mouse_face_beg_row
,
22495 &dpyinfo
->mouse_face_beg_x
,
22496 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22497 dpyinfo
->mouse_face_past_end
22498 = !fast_find_position (w
, XFASTINT (after
),
22499 &dpyinfo
->mouse_face_end_col
,
22500 &dpyinfo
->mouse_face_end_row
,
22501 &dpyinfo
->mouse_face_end_x
,
22502 &dpyinfo
->mouse_face_end_y
, Qnil
);
22503 dpyinfo
->mouse_face_window
= window
;
22505 if (BUFFERP (object
))
22506 dpyinfo
->mouse_face_face_id
22507 = face_at_buffer_position (w
, pos
, 0, 0,
22509 !dpyinfo
->mouse_face_hidden
);
22511 /* Display it as active. */
22512 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22513 cursor
= No_Cursor
;
22515 else if (!NILP (mouse_face
) && STRINGP (object
))
22520 b
= Fprevious_single_property_change (make_number (pos
+ 1),
22523 e
= Fnext_single_property_change (position
, Qmouse_face
,
22526 b
= make_number (0);
22528 e
= make_number (SCHARS (object
) - 1);
22530 fast_find_string_pos (w
, XINT (b
), object
,
22531 &dpyinfo
->mouse_face_beg_col
,
22532 &dpyinfo
->mouse_face_beg_row
,
22533 &dpyinfo
->mouse_face_beg_x
,
22534 &dpyinfo
->mouse_face_beg_y
, 0);
22535 fast_find_string_pos (w
, XINT (e
), object
,
22536 &dpyinfo
->mouse_face_end_col
,
22537 &dpyinfo
->mouse_face_end_row
,
22538 &dpyinfo
->mouse_face_end_x
,
22539 &dpyinfo
->mouse_face_end_y
, 1);
22540 dpyinfo
->mouse_face_past_end
= 0;
22541 dpyinfo
->mouse_face_window
= window
;
22542 dpyinfo
->mouse_face_face_id
22543 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
22544 glyph
->face_id
, 1);
22545 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22546 cursor
= No_Cursor
;
22548 else if (STRINGP (object
) && NILP (mouse_face
))
22550 /* A string which doesn't have mouse-face, but
22551 the text ``under'' it might have. */
22552 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
22553 int start
= MATRIX_ROW_START_CHARPOS (r
);
22555 pos
= string_buffer_position (w
, object
, start
);
22557 mouse_face
= get_char_property_and_overlay (make_number (pos
),
22561 if (!NILP (mouse_face
) && !NILP (overlay
))
22563 Lisp_Object before
= Foverlay_start (overlay
);
22564 Lisp_Object after
= Foverlay_end (overlay
);
22567 /* Note that we might not be able to find position
22568 BEFORE in the glyph matrix if the overlay is
22569 entirely covered by a `display' property. In
22570 this case, we overshoot. So let's stop in
22571 the glyph matrix before glyphs for OBJECT. */
22572 fast_find_position (w
, XFASTINT (before
),
22573 &dpyinfo
->mouse_face_beg_col
,
22574 &dpyinfo
->mouse_face_beg_row
,
22575 &dpyinfo
->mouse_face_beg_x
,
22576 &dpyinfo
->mouse_face_beg_y
,
22579 dpyinfo
->mouse_face_past_end
22580 = !fast_find_position (w
, XFASTINT (after
),
22581 &dpyinfo
->mouse_face_end_col
,
22582 &dpyinfo
->mouse_face_end_row
,
22583 &dpyinfo
->mouse_face_end_x
,
22584 &dpyinfo
->mouse_face_end_y
,
22586 dpyinfo
->mouse_face_window
= window
;
22587 dpyinfo
->mouse_face_face_id
22588 = face_at_buffer_position (w
, pos
, 0, 0,
22590 !dpyinfo
->mouse_face_hidden
);
22592 /* Display it as active. */
22593 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22594 cursor
= No_Cursor
;
22601 /* Look for a `help-echo' property. */
22602 if (NILP (help_echo_string
)) {
22603 Lisp_Object help
, overlay
;
22605 /* Check overlays first. */
22606 help
= overlay
= Qnil
;
22607 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
22609 overlay
= overlay_vec
[i
];
22610 help
= Foverlay_get (overlay
, Qhelp_echo
);
22615 help_echo_string
= help
;
22616 help_echo_window
= window
;
22617 help_echo_object
= overlay
;
22618 help_echo_pos
= pos
;
22622 Lisp_Object object
= glyph
->object
;
22623 int charpos
= glyph
->charpos
;
22625 /* Try text properties. */
22626 if (STRINGP (object
)
22628 && charpos
< SCHARS (object
))
22630 help
= Fget_text_property (make_number (charpos
),
22631 Qhelp_echo
, object
);
22634 /* If the string itself doesn't specify a help-echo,
22635 see if the buffer text ``under'' it does. */
22636 struct glyph_row
*r
22637 = MATRIX_ROW (w
->current_matrix
, vpos
);
22638 int start
= MATRIX_ROW_START_CHARPOS (r
);
22639 int pos
= string_buffer_position (w
, object
, start
);
22642 help
= Fget_char_property (make_number (pos
),
22643 Qhelp_echo
, w
->buffer
);
22647 object
= w
->buffer
;
22652 else if (BUFFERP (object
)
22655 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
22660 help_echo_string
= help
;
22661 help_echo_window
= window
;
22662 help_echo_object
= object
;
22663 help_echo_pos
= charpos
;
22668 /* Look for a `pointer' property. */
22669 if (NILP (pointer
))
22671 /* Check overlays first. */
22672 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
22673 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
22675 if (NILP (pointer
))
22677 Lisp_Object object
= glyph
->object
;
22678 int charpos
= glyph
->charpos
;
22680 /* Try text properties. */
22681 if (STRINGP (object
)
22683 && charpos
< SCHARS (object
))
22685 pointer
= Fget_text_property (make_number (charpos
),
22687 if (NILP (pointer
))
22689 /* If the string itself doesn't specify a pointer,
22690 see if the buffer text ``under'' it does. */
22691 struct glyph_row
*r
22692 = MATRIX_ROW (w
->current_matrix
, vpos
);
22693 int start
= MATRIX_ROW_START_CHARPOS (r
);
22694 int pos
= string_buffer_position (w
, object
, start
);
22696 pointer
= Fget_char_property (make_number (pos
),
22697 Qpointer
, w
->buffer
);
22700 else if (BUFFERP (object
)
22703 pointer
= Fget_text_property (make_number (charpos
),
22710 current_buffer
= obuf
;
22715 define_frame_cursor1 (f
, cursor
, pointer
);
22720 Clear any mouse-face on window W. This function is part of the
22721 redisplay interface, and is called from try_window_id and similar
22722 functions to ensure the mouse-highlight is off. */
22725 x_clear_window_mouse_face (w
)
22728 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22729 Lisp_Object window
;
22732 XSETWINDOW (window
, w
);
22733 if (EQ (window
, dpyinfo
->mouse_face_window
))
22734 clear_mouse_face (dpyinfo
);
22740 Just discard the mouse face information for frame F, if any.
22741 This is used when the size of F is changed. */
22744 cancel_mouse_face (f
)
22747 Lisp_Object window
;
22748 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22750 window
= dpyinfo
->mouse_face_window
;
22751 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
22753 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22754 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22755 dpyinfo
->mouse_face_window
= Qnil
;
22760 #endif /* HAVE_WINDOW_SYSTEM */
22763 /***********************************************************************
22765 ***********************************************************************/
22767 #ifdef HAVE_WINDOW_SYSTEM
22769 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
22770 which intersects rectangle R. R is in window-relative coordinates. */
22773 expose_area (w
, row
, r
, area
)
22775 struct glyph_row
*row
;
22777 enum glyph_row_area area
;
22779 struct glyph
*first
= row
->glyphs
[area
];
22780 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
22781 struct glyph
*last
;
22782 int first_x
, start_x
, x
;
22784 if (area
== TEXT_AREA
&& row
->fill_line_p
)
22785 /* If row extends face to end of line write the whole line. */
22786 draw_glyphs (w
, 0, row
, area
,
22787 0, row
->used
[area
],
22788 DRAW_NORMAL_TEXT
, 0);
22791 /* Set START_X to the window-relative start position for drawing glyphs of
22792 AREA. The first glyph of the text area can be partially visible.
22793 The first glyphs of other areas cannot. */
22794 start_x
= window_box_left_offset (w
, area
);
22796 if (area
== TEXT_AREA
)
22799 /* Find the first glyph that must be redrawn. */
22801 && x
+ first
->pixel_width
< r
->x
)
22803 x
+= first
->pixel_width
;
22807 /* Find the last one. */
22811 && x
< r
->x
+ r
->width
)
22813 x
+= last
->pixel_width
;
22819 draw_glyphs (w
, first_x
- start_x
, row
, area
,
22820 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
22821 DRAW_NORMAL_TEXT
, 0);
22826 /* Redraw the parts of the glyph row ROW on window W intersecting
22827 rectangle R. R is in window-relative coordinates. Value is
22828 non-zero if mouse-face was overwritten. */
22831 expose_line (w
, row
, r
)
22833 struct glyph_row
*row
;
22836 xassert (row
->enabled_p
);
22838 if (row
->mode_line_p
|| w
->pseudo_window_p
)
22839 draw_glyphs (w
, 0, row
, TEXT_AREA
,
22840 0, row
->used
[TEXT_AREA
],
22841 DRAW_NORMAL_TEXT
, 0);
22844 if (row
->used
[LEFT_MARGIN_AREA
])
22845 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
22846 if (row
->used
[TEXT_AREA
])
22847 expose_area (w
, row
, r
, TEXT_AREA
);
22848 if (row
->used
[RIGHT_MARGIN_AREA
])
22849 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
22850 draw_row_fringe_bitmaps (w
, row
);
22853 return row
->mouse_face_p
;
22857 /* Redraw those parts of glyphs rows during expose event handling that
22858 overlap other rows. Redrawing of an exposed line writes over parts
22859 of lines overlapping that exposed line; this function fixes that.
22861 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
22862 row in W's current matrix that is exposed and overlaps other rows.
22863 LAST_OVERLAPPING_ROW is the last such row. */
22866 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
22868 struct glyph_row
*first_overlapping_row
;
22869 struct glyph_row
*last_overlapping_row
;
22871 struct glyph_row
*row
;
22873 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
22874 if (row
->overlapping_p
)
22876 xassert (row
->enabled_p
&& !row
->mode_line_p
);
22878 if (row
->used
[LEFT_MARGIN_AREA
])
22879 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
22881 if (row
->used
[TEXT_AREA
])
22882 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
22884 if (row
->used
[RIGHT_MARGIN_AREA
])
22885 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
22890 /* Return non-zero if W's cursor intersects rectangle R. */
22893 phys_cursor_in_rect_p (w
, r
)
22897 XRectangle cr
, result
;
22898 struct glyph
*cursor_glyph
;
22900 cursor_glyph
= get_phys_cursor_glyph (w
);
22903 /* r is relative to W's box, but w->phys_cursor.x is relative
22904 to left edge of W's TEXT area. Adjust it. */
22905 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
22906 cr
.y
= w
->phys_cursor
.y
;
22907 cr
.width
= cursor_glyph
->pixel_width
;
22908 cr
.height
= w
->phys_cursor_height
;
22909 /* ++KFS: W32 version used W32-specific IntersectRect here, but
22910 I assume the effect is the same -- and this is portable. */
22911 return x_intersect_rectangles (&cr
, r
, &result
);
22919 Draw a vertical window border to the right of window W if W doesn't
22920 have vertical scroll bars. */
22923 x_draw_vertical_border (w
)
22926 /* We could do better, if we knew what type of scroll-bar the adjacent
22927 windows (on either side) have... But we don't :-(
22928 However, I think this works ok. ++KFS 2003-04-25 */
22930 /* Redraw borders between horizontally adjacent windows. Don't
22931 do it for frames with vertical scroll bars because either the
22932 right scroll bar of a window, or the left scroll bar of its
22933 neighbor will suffice as a border. */
22934 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
22937 if (!WINDOW_RIGHTMOST_P (w
)
22938 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
22940 int x0
, x1
, y0
, y1
;
22942 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22945 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22948 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
22950 else if (!WINDOW_LEFTMOST_P (w
)
22951 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
22953 int x0
, x1
, y0
, y1
;
22955 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22958 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22961 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
22966 /* Redraw the part of window W intersection rectangle FR. Pixel
22967 coordinates in FR are frame-relative. Call this function with
22968 input blocked. Value is non-zero if the exposure overwrites
22972 expose_window (w
, fr
)
22976 struct frame
*f
= XFRAME (w
->frame
);
22978 int mouse_face_overwritten_p
= 0;
22980 /* If window is not yet fully initialized, do nothing. This can
22981 happen when toolkit scroll bars are used and a window is split.
22982 Reconfiguring the scroll bar will generate an expose for a newly
22984 if (w
->current_matrix
== NULL
)
22987 /* When we're currently updating the window, display and current
22988 matrix usually don't agree. Arrange for a thorough display
22990 if (w
== updated_window
)
22992 SET_FRAME_GARBAGED (f
);
22996 /* Frame-relative pixel rectangle of W. */
22997 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
22998 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
22999 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
23000 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
23002 if (x_intersect_rectangles (fr
, &wr
, &r
))
23004 int yb
= window_text_bottom_y (w
);
23005 struct glyph_row
*row
;
23006 int cursor_cleared_p
;
23007 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
23009 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
23010 r
.x
, r
.y
, r
.width
, r
.height
));
23012 /* Convert to window coordinates. */
23013 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
23014 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
23016 /* Turn off the cursor. */
23017 if (!w
->pseudo_window_p
23018 && phys_cursor_in_rect_p (w
, &r
))
23020 x_clear_cursor (w
);
23021 cursor_cleared_p
= 1;
23024 cursor_cleared_p
= 0;
23026 /* Update lines intersecting rectangle R. */
23027 first_overlapping_row
= last_overlapping_row
= NULL
;
23028 for (row
= w
->current_matrix
->rows
;
23033 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
23035 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
23036 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
23037 || (r
.y
>= y0
&& r
.y
< y1
)
23038 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
23040 /* A header line may be overlapping, but there is no need
23041 to fix overlapping areas for them. KFS 2005-02-12 */
23042 if (row
->overlapping_p
&& !row
->mode_line_p
)
23044 if (first_overlapping_row
== NULL
)
23045 first_overlapping_row
= row
;
23046 last_overlapping_row
= row
;
23049 if (expose_line (w
, row
, &r
))
23050 mouse_face_overwritten_p
= 1;
23057 /* Display the mode line if there is one. */
23058 if (WINDOW_WANTS_MODELINE_P (w
)
23059 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
23061 && row
->y
< r
.y
+ r
.height
)
23063 if (expose_line (w
, row
, &r
))
23064 mouse_face_overwritten_p
= 1;
23067 if (!w
->pseudo_window_p
)
23069 /* Fix the display of overlapping rows. */
23070 if (first_overlapping_row
)
23071 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
23073 /* Draw border between windows. */
23074 x_draw_vertical_border (w
);
23076 /* Turn the cursor on again. */
23077 if (cursor_cleared_p
)
23078 update_window_cursor (w
, 1);
23082 return mouse_face_overwritten_p
;
23087 /* Redraw (parts) of all windows in the window tree rooted at W that
23088 intersect R. R contains frame pixel coordinates. Value is
23089 non-zero if the exposure overwrites mouse-face. */
23092 expose_window_tree (w
, r
)
23096 struct frame
*f
= XFRAME (w
->frame
);
23097 int mouse_face_overwritten_p
= 0;
23099 while (w
&& !FRAME_GARBAGED_P (f
))
23101 if (!NILP (w
->hchild
))
23102 mouse_face_overwritten_p
23103 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
23104 else if (!NILP (w
->vchild
))
23105 mouse_face_overwritten_p
23106 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
23108 mouse_face_overwritten_p
|= expose_window (w
, r
);
23110 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
23113 return mouse_face_overwritten_p
;
23118 Redisplay an exposed area of frame F. X and Y are the upper-left
23119 corner of the exposed rectangle. W and H are width and height of
23120 the exposed area. All are pixel values. W or H zero means redraw
23121 the entire frame. */
23124 expose_frame (f
, x
, y
, w
, h
)
23129 int mouse_face_overwritten_p
= 0;
23131 TRACE ((stderr
, "expose_frame "));
23133 /* No need to redraw if frame will be redrawn soon. */
23134 if (FRAME_GARBAGED_P (f
))
23136 TRACE ((stderr
, " garbaged\n"));
23140 /* If basic faces haven't been realized yet, there is no point in
23141 trying to redraw anything. This can happen when we get an expose
23142 event while Emacs is starting, e.g. by moving another window. */
23143 if (FRAME_FACE_CACHE (f
) == NULL
23144 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
23146 TRACE ((stderr
, " no faces\n"));
23150 if (w
== 0 || h
== 0)
23153 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
23154 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
23164 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
23165 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
23167 if (WINDOWP (f
->tool_bar_window
))
23168 mouse_face_overwritten_p
23169 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
23171 #ifdef HAVE_X_WINDOWS
23173 #ifndef USE_X_TOOLKIT
23174 if (WINDOWP (f
->menu_bar_window
))
23175 mouse_face_overwritten_p
23176 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
23177 #endif /* not USE_X_TOOLKIT */
23181 /* Some window managers support a focus-follows-mouse style with
23182 delayed raising of frames. Imagine a partially obscured frame,
23183 and moving the mouse into partially obscured mouse-face on that
23184 frame. The visible part of the mouse-face will be highlighted,
23185 then the WM raises the obscured frame. With at least one WM, KDE
23186 2.1, Emacs is not getting any event for the raising of the frame
23187 (even tried with SubstructureRedirectMask), only Expose events.
23188 These expose events will draw text normally, i.e. not
23189 highlighted. Which means we must redo the highlight here.
23190 Subsume it under ``we love X''. --gerd 2001-08-15 */
23191 /* Included in Windows version because Windows most likely does not
23192 do the right thing if any third party tool offers
23193 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
23194 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
23196 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23197 if (f
== dpyinfo
->mouse_face_mouse_frame
)
23199 int x
= dpyinfo
->mouse_face_mouse_x
;
23200 int y
= dpyinfo
->mouse_face_mouse_y
;
23201 clear_mouse_face (dpyinfo
);
23202 note_mouse_highlight (f
, x
, y
);
23209 Determine the intersection of two rectangles R1 and R2. Return
23210 the intersection in *RESULT. Value is non-zero if RESULT is not
23214 x_intersect_rectangles (r1
, r2
, result
)
23215 XRectangle
*r1
, *r2
, *result
;
23217 XRectangle
*left
, *right
;
23218 XRectangle
*upper
, *lower
;
23219 int intersection_p
= 0;
23221 /* Rearrange so that R1 is the left-most rectangle. */
23223 left
= r1
, right
= r2
;
23225 left
= r2
, right
= r1
;
23227 /* X0 of the intersection is right.x0, if this is inside R1,
23228 otherwise there is no intersection. */
23229 if (right
->x
<= left
->x
+ left
->width
)
23231 result
->x
= right
->x
;
23233 /* The right end of the intersection is the minimum of the
23234 the right ends of left and right. */
23235 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
23238 /* Same game for Y. */
23240 upper
= r1
, lower
= r2
;
23242 upper
= r2
, lower
= r1
;
23244 /* The upper end of the intersection is lower.y0, if this is inside
23245 of upper. Otherwise, there is no intersection. */
23246 if (lower
->y
<= upper
->y
+ upper
->height
)
23248 result
->y
= lower
->y
;
23250 /* The lower end of the intersection is the minimum of the lower
23251 ends of upper and lower. */
23252 result
->height
= (min (lower
->y
+ lower
->height
,
23253 upper
->y
+ upper
->height
)
23255 intersection_p
= 1;
23259 return intersection_p
;
23262 #endif /* HAVE_WINDOW_SYSTEM */
23265 /***********************************************************************
23267 ***********************************************************************/
23272 Vwith_echo_area_save_vector
= Qnil
;
23273 staticpro (&Vwith_echo_area_save_vector
);
23275 Vmessage_stack
= Qnil
;
23276 staticpro (&Vmessage_stack
);
23278 Qinhibit_redisplay
= intern ("inhibit-redisplay");
23279 staticpro (&Qinhibit_redisplay
);
23281 message_dolog_marker1
= Fmake_marker ();
23282 staticpro (&message_dolog_marker1
);
23283 message_dolog_marker2
= Fmake_marker ();
23284 staticpro (&message_dolog_marker2
);
23285 message_dolog_marker3
= Fmake_marker ();
23286 staticpro (&message_dolog_marker3
);
23289 defsubr (&Sdump_frame_glyph_matrix
);
23290 defsubr (&Sdump_glyph_matrix
);
23291 defsubr (&Sdump_glyph_row
);
23292 defsubr (&Sdump_tool_bar_row
);
23293 defsubr (&Strace_redisplay
);
23294 defsubr (&Strace_to_stderr
);
23296 #ifdef HAVE_WINDOW_SYSTEM
23297 defsubr (&Stool_bar_lines_needed
);
23298 defsubr (&Slookup_image_map
);
23300 defsubr (&Sformat_mode_line
);
23302 staticpro (&Qmenu_bar_update_hook
);
23303 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
23305 staticpro (&Qoverriding_terminal_local_map
);
23306 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
23308 staticpro (&Qoverriding_local_map
);
23309 Qoverriding_local_map
= intern ("overriding-local-map");
23311 staticpro (&Qwindow_scroll_functions
);
23312 Qwindow_scroll_functions
= intern ("window-scroll-functions");
23314 staticpro (&Qredisplay_end_trigger_functions
);
23315 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
23317 staticpro (&Qinhibit_point_motion_hooks
);
23318 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
23320 QCdata
= intern (":data");
23321 staticpro (&QCdata
);
23322 Qdisplay
= intern ("display");
23323 staticpro (&Qdisplay
);
23324 Qspace_width
= intern ("space-width");
23325 staticpro (&Qspace_width
);
23326 Qraise
= intern ("raise");
23327 staticpro (&Qraise
);
23328 Qslice
= intern ("slice");
23329 staticpro (&Qslice
);
23330 Qspace
= intern ("space");
23331 staticpro (&Qspace
);
23332 Qmargin
= intern ("margin");
23333 staticpro (&Qmargin
);
23334 Qpointer
= intern ("pointer");
23335 staticpro (&Qpointer
);
23336 Qleft_margin
= intern ("left-margin");
23337 staticpro (&Qleft_margin
);
23338 Qright_margin
= intern ("right-margin");
23339 staticpro (&Qright_margin
);
23340 Qcenter
= intern ("center");
23341 staticpro (&Qcenter
);
23342 Qline_height
= intern ("line-height");
23343 staticpro (&Qline_height
);
23344 QCalign_to
= intern (":align-to");
23345 staticpro (&QCalign_to
);
23346 QCrelative_width
= intern (":relative-width");
23347 staticpro (&QCrelative_width
);
23348 QCrelative_height
= intern (":relative-height");
23349 staticpro (&QCrelative_height
);
23350 QCeval
= intern (":eval");
23351 staticpro (&QCeval
);
23352 QCpropertize
= intern (":propertize");
23353 staticpro (&QCpropertize
);
23354 QCfile
= intern (":file");
23355 staticpro (&QCfile
);
23356 Qfontified
= intern ("fontified");
23357 staticpro (&Qfontified
);
23358 Qfontification_functions
= intern ("fontification-functions");
23359 staticpro (&Qfontification_functions
);
23360 Qtrailing_whitespace
= intern ("trailing-whitespace");
23361 staticpro (&Qtrailing_whitespace
);
23362 Qescape_glyph
= intern ("escape-glyph");
23363 staticpro (&Qescape_glyph
);
23364 Qnobreak_space
= intern ("nobreak-space");
23365 staticpro (&Qnobreak_space
);
23366 Qimage
= intern ("image");
23367 staticpro (&Qimage
);
23368 QCmap
= intern (":map");
23369 staticpro (&QCmap
);
23370 QCpointer
= intern (":pointer");
23371 staticpro (&QCpointer
);
23372 Qrect
= intern ("rect");
23373 staticpro (&Qrect
);
23374 Qcircle
= intern ("circle");
23375 staticpro (&Qcircle
);
23376 Qpoly
= intern ("poly");
23377 staticpro (&Qpoly
);
23378 Qmessage_truncate_lines
= intern ("message-truncate-lines");
23379 staticpro (&Qmessage_truncate_lines
);
23380 Qgrow_only
= intern ("grow-only");
23381 staticpro (&Qgrow_only
);
23382 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
23383 staticpro (&Qinhibit_menubar_update
);
23384 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
23385 staticpro (&Qinhibit_eval_during_redisplay
);
23386 Qposition
= intern ("position");
23387 staticpro (&Qposition
);
23388 Qbuffer_position
= intern ("buffer-position");
23389 staticpro (&Qbuffer_position
);
23390 Qobject
= intern ("object");
23391 staticpro (&Qobject
);
23392 Qbar
= intern ("bar");
23394 Qhbar
= intern ("hbar");
23395 staticpro (&Qhbar
);
23396 Qbox
= intern ("box");
23398 Qhollow
= intern ("hollow");
23399 staticpro (&Qhollow
);
23400 Qhand
= intern ("hand");
23401 staticpro (&Qhand
);
23402 Qarrow
= intern ("arrow");
23403 staticpro (&Qarrow
);
23404 Qtext
= intern ("text");
23405 staticpro (&Qtext
);
23406 Qrisky_local_variable
= intern ("risky-local-variable");
23407 staticpro (&Qrisky_local_variable
);
23408 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
23409 staticpro (&Qinhibit_free_realized_faces
);
23411 list_of_error
= Fcons (Fcons (intern ("error"),
23412 Fcons (intern ("void-variable"), Qnil
)),
23414 staticpro (&list_of_error
);
23416 Qlast_arrow_position
= intern ("last-arrow-position");
23417 staticpro (&Qlast_arrow_position
);
23418 Qlast_arrow_string
= intern ("last-arrow-string");
23419 staticpro (&Qlast_arrow_string
);
23421 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
23422 staticpro (&Qoverlay_arrow_string
);
23423 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
23424 staticpro (&Qoverlay_arrow_bitmap
);
23426 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
23427 staticpro (&echo_buffer
[0]);
23428 staticpro (&echo_buffer
[1]);
23430 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
23431 staticpro (&echo_area_buffer
[0]);
23432 staticpro (&echo_area_buffer
[1]);
23434 Vmessages_buffer_name
= build_string ("*Messages*");
23435 staticpro (&Vmessages_buffer_name
);
23437 mode_line_proptrans_alist
= Qnil
;
23438 staticpro (&mode_line_proptrans_alist
);
23439 mode_line_string_list
= Qnil
;
23440 staticpro (&mode_line_string_list
);
23441 mode_line_string_face
= Qnil
;
23442 staticpro (&mode_line_string_face
);
23443 mode_line_string_face_prop
= Qnil
;
23444 staticpro (&mode_line_string_face_prop
);
23445 Vmode_line_unwind_vector
= Qnil
;
23446 staticpro (&Vmode_line_unwind_vector
);
23448 help_echo_string
= Qnil
;
23449 staticpro (&help_echo_string
);
23450 help_echo_object
= Qnil
;
23451 staticpro (&help_echo_object
);
23452 help_echo_window
= Qnil
;
23453 staticpro (&help_echo_window
);
23454 previous_help_echo_string
= Qnil
;
23455 staticpro (&previous_help_echo_string
);
23456 help_echo_pos
= -1;
23458 #ifdef HAVE_WINDOW_SYSTEM
23459 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
23460 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
23461 For example, if a block cursor is over a tab, it will be drawn as
23462 wide as that tab on the display. */);
23463 x_stretch_cursor_p
= 0;
23466 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
23467 doc
: /* *Non-nil means highlight trailing whitespace.
23468 The face used for trailing whitespace is `trailing-whitespace'. */);
23469 Vshow_trailing_whitespace
= Qnil
;
23471 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
23472 doc
: /* *Control highlighting of nobreak space and soft hyphen.
23473 A value of t means highlight the character itself (for nobreak space,
23474 use face `nobreak-space').
23475 A value of nil means no highlighting.
23476 Other values mean display the escape glyph followed by an ordinary
23477 space or ordinary hyphen. */);
23478 Vnobreak_char_display
= Qt
;
23480 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
23481 doc
: /* *The pointer shape to show in void text areas.
23482 A value of nil means to show the text pointer. Other options are `arrow',
23483 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
23484 Vvoid_text_area_pointer
= Qarrow
;
23486 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
23487 doc
: /* Non-nil means don't actually do any redisplay.
23488 This is used for internal purposes. */);
23489 Vinhibit_redisplay
= Qnil
;
23491 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
23492 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
23493 Vglobal_mode_string
= Qnil
;
23495 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
23496 doc
: /* Marker for where to display an arrow on top of the buffer text.
23497 This must be the beginning of a line in order to work.
23498 See also `overlay-arrow-string'. */);
23499 Voverlay_arrow_position
= Qnil
;
23501 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
23502 doc
: /* String to display as an arrow in non-window frames.
23503 See also `overlay-arrow-position'. */);
23504 Voverlay_arrow_string
= build_string ("=>");
23506 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
23507 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
23508 The symbols on this list are examined during redisplay to determine
23509 where to display overlay arrows. */);
23510 Voverlay_arrow_variable_list
23511 = Fcons (intern ("overlay-arrow-position"), Qnil
);
23513 DEFVAR_INT ("scroll-step", &scroll_step
,
23514 doc
: /* *The number of lines to try scrolling a window by when point moves out.
23515 If that fails to bring point back on frame, point is centered instead.
23516 If this is zero, point is always centered after it moves off frame.
23517 If you want scrolling to always be a line at a time, you should set
23518 `scroll-conservatively' to a large value rather than set this to 1. */);
23520 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
23521 doc
: /* *Scroll up to this many lines, to bring point back on screen.
23522 A value of zero means to scroll the text to center point vertically
23523 in the window. */);
23524 scroll_conservatively
= 0;
23526 DEFVAR_INT ("scroll-margin", &scroll_margin
,
23527 doc
: /* *Number of lines of margin at the top and bottom of a window.
23528 Recenter the window whenever point gets within this many lines
23529 of the top or bottom of the window. */);
23532 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
23533 doc
: /* Pixels per inch value for non-window system displays.
23534 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
23535 Vdisplay_pixels_per_inch
= make_float (72.0);
23538 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
23541 DEFVAR_BOOL ("truncate-partial-width-windows",
23542 &truncate_partial_width_windows
,
23543 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
23544 truncate_partial_width_windows
= 1;
23546 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
23547 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
23548 Any other value means to use the appropriate face, `mode-line',
23549 `header-line', or `menu' respectively. */);
23550 mode_line_inverse_video
= 1;
23552 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
23553 doc
: /* *Maximum buffer size for which line number should be displayed.
23554 If the buffer is bigger than this, the line number does not appear
23555 in the mode line. A value of nil means no limit. */);
23556 Vline_number_display_limit
= Qnil
;
23558 DEFVAR_INT ("line-number-display-limit-width",
23559 &line_number_display_limit_width
,
23560 doc
: /* *Maximum line width (in characters) for line number display.
23561 If the average length of the lines near point is bigger than this, then the
23562 line number may be omitted from the mode line. */);
23563 line_number_display_limit_width
= 200;
23565 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
23566 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
23567 highlight_nonselected_windows
= 0;
23569 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
23570 doc
: /* Non-nil if more than one frame is visible on this display.
23571 Minibuffer-only frames don't count, but iconified frames do.
23572 This variable is not guaranteed to be accurate except while processing
23573 `frame-title-format' and `icon-title-format'. */);
23575 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
23576 doc
: /* Template for displaying the title bar of visible frames.
23577 \(Assuming the window manager supports this feature.)
23578 This variable has the same structure as `mode-line-format' (which see),
23579 and is used only on frames for which no explicit name has been set
23580 \(see `modify-frame-parameters'). */);
23582 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
23583 doc
: /* Template for displaying the title bar of an iconified frame.
23584 \(Assuming the window manager supports this feature.)
23585 This variable has the same structure as `mode-line-format' (which see),
23586 and is used only on frames for which no explicit name has been set
23587 \(see `modify-frame-parameters'). */);
23589 = Vframe_title_format
23590 = Fcons (intern ("multiple-frames"),
23591 Fcons (build_string ("%b"),
23592 Fcons (Fcons (empty_string
,
23593 Fcons (intern ("invocation-name"),
23594 Fcons (build_string ("@"),
23595 Fcons (intern ("system-name"),
23599 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
23600 doc
: /* Maximum number of lines to keep in the message log buffer.
23601 If nil, disable message logging. If t, log messages but don't truncate
23602 the buffer when it becomes large. */);
23603 Vmessage_log_max
= make_number (50);
23605 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
23606 doc
: /* Functions called before redisplay, if window sizes have changed.
23607 The value should be a list of functions that take one argument.
23608 Just before redisplay, for each frame, if any of its windows have changed
23609 size since the last redisplay, or have been split or deleted,
23610 all the functions in the list are called, with the frame as argument. */);
23611 Vwindow_size_change_functions
= Qnil
;
23613 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
23614 doc
: /* List of functions to call before redisplaying a window with scrolling.
23615 Each function is called with two arguments, the window
23616 and its new display-start position. Note that the value of `window-end'
23617 is not valid when these functions are called. */);
23618 Vwindow_scroll_functions
= Qnil
;
23620 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
23621 doc
: /* Functions called when redisplay of a window reaches the end trigger.
23622 Each function is called with two arguments, the window and the end trigger value.
23623 See `set-window-redisplay-end-trigger'. */);
23624 Vredisplay_end_trigger_functions
= Qnil
;
23626 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
23627 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
23628 mouse_autoselect_window
= 0;
23630 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
23631 doc
: /* *Non-nil means automatically resize tool-bars.
23632 This increases a tool-bar's height if not all tool-bar items are visible.
23633 It decreases a tool-bar's height when it would display blank lines
23635 auto_resize_tool_bars_p
= 1;
23637 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
23638 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
23639 auto_raise_tool_bar_buttons_p
= 1;
23641 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
23642 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
23643 make_cursor_line_fully_visible_p
= 1;
23645 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
23646 doc
: /* *Margin around tool-bar buttons in pixels.
23647 If an integer, use that for both horizontal and vertical margins.
23648 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
23649 HORZ specifying the horizontal margin, and VERT specifying the
23650 vertical margin. */);
23651 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
23653 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
23654 doc
: /* *Relief thickness of tool-bar buttons. */);
23655 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
23657 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
23658 doc
: /* List of functions to call to fontify regions of text.
23659 Each function is called with one argument POS. Functions must
23660 fontify a region starting at POS in the current buffer, and give
23661 fontified regions the property `fontified'. */);
23662 Vfontification_functions
= Qnil
;
23663 Fmake_variable_buffer_local (Qfontification_functions
);
23665 DEFVAR_BOOL ("unibyte-display-via-language-environment",
23666 &unibyte_display_via_language_environment
,
23667 doc
: /* *Non-nil means display unibyte text according to language environment.
23668 Specifically this means that unibyte non-ASCII characters
23669 are displayed by converting them to the equivalent multibyte characters
23670 according to the current language environment. As a result, they are
23671 displayed according to the current fontset. */);
23672 unibyte_display_via_language_environment
= 0;
23674 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
23675 doc
: /* *Maximum height for resizing mini-windows.
23676 If a float, it specifies a fraction of the mini-window frame's height.
23677 If an integer, it specifies a number of lines. */);
23678 Vmax_mini_window_height
= make_float (0.25);
23680 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
23681 doc
: /* *How to resize mini-windows.
23682 A value of nil means don't automatically resize mini-windows.
23683 A value of t means resize them to fit the text displayed in them.
23684 A value of `grow-only', the default, means let mini-windows grow
23685 only, until their display becomes empty, at which point the windows
23686 go back to their normal size. */);
23687 Vresize_mini_windows
= Qgrow_only
;
23689 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
23690 doc
: /* Alist specifying how to blink the cursor off.
23691 Each element has the form (ON-STATE . OFF-STATE). Whenever the
23692 `cursor-type' frame-parameter or variable equals ON-STATE,
23693 comparing using `equal', Emacs uses OFF-STATE to specify
23694 how to blink it off. ON-STATE and OFF-STATE are values for
23695 the `cursor-type' frame parameter.
23697 If a frame's ON-STATE has no entry in this list,
23698 the frame's other specifications determine how to blink the cursor off. */);
23699 Vblink_cursor_alist
= Qnil
;
23701 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
23702 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
23703 automatic_hscrolling_p
= 1;
23705 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
23706 doc
: /* *How many columns away from the window edge point is allowed to get
23707 before automatic hscrolling will horizontally scroll the window. */);
23708 hscroll_margin
= 5;
23710 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
23711 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
23712 When point is less than `automatic-hscroll-margin' columns from the window
23713 edge, automatic hscrolling will scroll the window by the amount of columns
23714 determined by this variable. If its value is a positive integer, scroll that
23715 many columns. If it's a positive floating-point number, it specifies the
23716 fraction of the window's width to scroll. If it's nil or zero, point will be
23717 centered horizontally after the scroll. Any other value, including negative
23718 numbers, are treated as if the value were zero.
23720 Automatic hscrolling always moves point outside the scroll margin, so if
23721 point was more than scroll step columns inside the margin, the window will
23722 scroll more than the value given by the scroll step.
23724 Note that the lower bound for automatic hscrolling specified by `scroll-left'
23725 and `scroll-right' overrides this variable's effect. */);
23726 Vhscroll_step
= make_number (0);
23728 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
23729 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
23730 Bind this around calls to `message' to let it take effect. */);
23731 message_truncate_lines
= 0;
23733 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
23734 doc
: /* Normal hook run to update the menu bar definitions.
23735 Redisplay runs this hook before it redisplays the menu bar.
23736 This is used to update submenus such as Buffers,
23737 whose contents depend on various data. */);
23738 Vmenu_bar_update_hook
= Qnil
;
23740 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
23741 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
23742 inhibit_menubar_update
= 0;
23744 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
23745 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
23746 inhibit_eval_during_redisplay
= 0;
23748 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
23749 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
23750 inhibit_free_realized_faces
= 0;
23753 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
23754 doc
: /* Inhibit try_window_id display optimization. */);
23755 inhibit_try_window_id
= 0;
23757 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
23758 doc
: /* Inhibit try_window_reusing display optimization. */);
23759 inhibit_try_window_reusing
= 0;
23761 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
23762 doc
: /* Inhibit try_cursor_movement display optimization. */);
23763 inhibit_try_cursor_movement
= 0;
23764 #endif /* GLYPH_DEBUG */
23768 /* Initialize this module when Emacs starts. */
23773 Lisp_Object root_window
;
23774 struct window
*mini_w
;
23776 current_header_line_height
= current_mode_line_height
= -1;
23778 CHARPOS (this_line_start_pos
) = 0;
23780 mini_w
= XWINDOW (minibuf_window
);
23781 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
23783 if (!noninteractive
)
23785 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
23788 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
23789 set_window_height (root_window
,
23790 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
23792 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
23793 set_window_height (minibuf_window
, 1, 0);
23795 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
23796 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
23798 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
23799 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
23800 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
23802 /* The default ellipsis glyphs `...'. */
23803 for (i
= 0; i
< 3; ++i
)
23804 default_invis_vector
[i
] = make_number ('.');
23808 /* Allocate the buffer for frame titles.
23809 Also used for `format-mode-line'. */
23811 mode_line_noprop_buf
= (char *) xmalloc (size
);
23812 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
23813 mode_line_noprop_ptr
= mode_line_noprop_buf
;
23814 mode_line_target
= MODE_LINE_DISPLAY
;
23817 help_echo_showing_p
= 0;
23821 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
23822 (do not change this comment) */