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 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
= 1;
2985 it
->current
.dpvec_index
= -1;
2987 /* Use face of preceding text for ellipsis (if invisible) */
2988 if (it
->selective_display_ellipsis_p
)
2989 it
->saved_face_id
= it
->face_id
;
2993 handled
= HANDLED_NORMALLY
;
2995 /* Call text property handlers. */
2996 for (p
= it_props
; p
->handler
; ++p
)
2998 handled
= p
->handler (it
);
3000 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3002 else if (handled
== HANDLED_RETURN
)
3004 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3005 handle_overlay_change_p
= 0;
3008 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3010 /* Don't check for overlay strings below when set to deliver
3011 characters from a display vector. */
3012 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3013 handle_overlay_change_p
= 0;
3015 /* Handle overlay changes. */
3016 if (handle_overlay_change_p
)
3017 handled
= handle_overlay_change (it
);
3019 /* Determine where to stop next. */
3020 if (handled
== HANDLED_NORMALLY
)
3021 compute_stop_pos (it
);
3024 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3028 /* Compute IT->stop_charpos from text property and overlay change
3029 information for IT's current position. */
3032 compute_stop_pos (it
)
3035 register INTERVAL iv
, next_iv
;
3036 Lisp_Object object
, limit
, position
;
3038 /* If nowhere else, stop at the end. */
3039 it
->stop_charpos
= it
->end_charpos
;
3041 if (STRINGP (it
->string
))
3043 /* Strings are usually short, so don't limit the search for
3045 object
= it
->string
;
3047 position
= make_number (IT_STRING_CHARPOS (*it
));
3053 /* If next overlay change is in front of the current stop pos
3054 (which is IT->end_charpos), stop there. Note: value of
3055 next_overlay_change is point-max if no overlay change
3057 charpos
= next_overlay_change (IT_CHARPOS (*it
));
3058 if (charpos
< it
->stop_charpos
)
3059 it
->stop_charpos
= charpos
;
3061 /* If showing the region, we have to stop at the region
3062 start or end because the face might change there. */
3063 if (it
->region_beg_charpos
> 0)
3065 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3066 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3067 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3068 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3071 /* Set up variables for computing the stop position from text
3072 property changes. */
3073 XSETBUFFER (object
, current_buffer
);
3074 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3075 position
= make_number (IT_CHARPOS (*it
));
3079 /* Get the interval containing IT's position. Value is a null
3080 interval if there isn't such an interval. */
3081 iv
= validate_interval_range (object
, &position
, &position
, 0);
3082 if (!NULL_INTERVAL_P (iv
))
3084 Lisp_Object values_here
[LAST_PROP_IDX
];
3087 /* Get properties here. */
3088 for (p
= it_props
; p
->handler
; ++p
)
3089 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3091 /* Look for an interval following iv that has different
3093 for (next_iv
= next_interval (iv
);
3094 (!NULL_INTERVAL_P (next_iv
)
3096 || XFASTINT (limit
) > next_iv
->position
));
3097 next_iv
= next_interval (next_iv
))
3099 for (p
= it_props
; p
->handler
; ++p
)
3101 Lisp_Object new_value
;
3103 new_value
= textget (next_iv
->plist
, *p
->name
);
3104 if (!EQ (values_here
[p
->idx
], new_value
))
3112 if (!NULL_INTERVAL_P (next_iv
))
3114 if (INTEGERP (limit
)
3115 && next_iv
->position
>= XFASTINT (limit
))
3116 /* No text property change up to limit. */
3117 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3119 /* Text properties change in next_iv. */
3120 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3124 xassert (STRINGP (it
->string
)
3125 || (it
->stop_charpos
>= BEGV
3126 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3130 /* Return the position of the next overlay change after POS in
3131 current_buffer. Value is point-max if no overlay change
3132 follows. This is like `next-overlay-change' but doesn't use
3136 next_overlay_change (pos
)
3141 Lisp_Object
*overlays
;
3144 /* Get all overlays at the given position. */
3145 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3147 /* If any of these overlays ends before endpos,
3148 use its ending point instead. */
3149 for (i
= 0; i
< noverlays
; ++i
)
3154 oend
= OVERLAY_END (overlays
[i
]);
3155 oendpos
= OVERLAY_POSITION (oend
);
3156 endpos
= min (endpos
, oendpos
);
3164 /***********************************************************************
3166 ***********************************************************************/
3168 /* Handle changes in the `fontified' property of the current buffer by
3169 calling hook functions from Qfontification_functions to fontify
3172 static enum prop_handled
3173 handle_fontified_prop (it
)
3176 Lisp_Object prop
, pos
;
3177 enum prop_handled handled
= HANDLED_NORMALLY
;
3179 if (!NILP (Vmemory_full
))
3182 /* Get the value of the `fontified' property at IT's current buffer
3183 position. (The `fontified' property doesn't have a special
3184 meaning in strings.) If the value is nil, call functions from
3185 Qfontification_functions. */
3186 if (!STRINGP (it
->string
)
3188 && !NILP (Vfontification_functions
)
3189 && !NILP (Vrun_hooks
)
3190 && (pos
= make_number (IT_CHARPOS (*it
)),
3191 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3194 int count
= SPECPDL_INDEX ();
3197 val
= Vfontification_functions
;
3198 specbind (Qfontification_functions
, Qnil
);
3200 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3201 safe_call1 (val
, pos
);
3204 Lisp_Object globals
, fn
;
3205 struct gcpro gcpro1
, gcpro2
;
3208 GCPRO2 (val
, globals
);
3210 for (; CONSP (val
); val
= XCDR (val
))
3216 /* A value of t indicates this hook has a local
3217 binding; it means to run the global binding too.
3218 In a global value, t should not occur. If it
3219 does, we must ignore it to avoid an endless
3221 for (globals
= Fdefault_value (Qfontification_functions
);
3223 globals
= XCDR (globals
))
3225 fn
= XCAR (globals
);
3227 safe_call1 (fn
, pos
);
3231 safe_call1 (fn
, pos
);
3237 unbind_to (count
, Qnil
);
3239 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3240 something. This avoids an endless loop if they failed to
3241 fontify the text for which reason ever. */
3242 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3243 handled
= HANDLED_RECOMPUTE_PROPS
;
3251 /***********************************************************************
3253 ***********************************************************************/
3255 /* Set up iterator IT from face properties at its current position.
3256 Called from handle_stop. */
3258 static enum prop_handled
3259 handle_face_prop (it
)
3262 int new_face_id
, next_stop
;
3264 if (!STRINGP (it
->string
))
3267 = face_at_buffer_position (it
->w
,
3269 it
->region_beg_charpos
,
3270 it
->region_end_charpos
,
3273 + TEXT_PROP_DISTANCE_LIMIT
),
3276 /* Is this a start of a run of characters with box face?
3277 Caveat: this can be called for a freshly initialized
3278 iterator; face_id is -1 in this case. We know that the new
3279 face will not change until limit, i.e. if the new face has a
3280 box, all characters up to limit will have one. But, as
3281 usual, we don't know whether limit is really the end. */
3282 if (new_face_id
!= it
->face_id
)
3284 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3286 /* If new face has a box but old face has not, this is
3287 the start of a run of characters with box, i.e. it has
3288 a shadow on the left side. The value of face_id of the
3289 iterator will be -1 if this is the initial call that gets
3290 the face. In this case, we have to look in front of IT's
3291 position and see whether there is a face != new_face_id. */
3292 it
->start_of_box_run_p
3293 = (new_face
->box
!= FACE_NO_BOX
3294 && (it
->face_id
>= 0
3295 || IT_CHARPOS (*it
) == BEG
3296 || new_face_id
!= face_before_it_pos (it
)));
3297 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3302 int base_face_id
, bufpos
;
3304 if (it
->current
.overlay_string_index
>= 0)
3305 bufpos
= IT_CHARPOS (*it
);
3309 /* For strings from a buffer, i.e. overlay strings or strings
3310 from a `display' property, use the face at IT's current
3311 buffer position as the base face to merge with, so that
3312 overlay strings appear in the same face as surrounding
3313 text, unless they specify their own faces. */
3314 base_face_id
= underlying_face_id (it
);
3316 new_face_id
= face_at_string_position (it
->w
,
3318 IT_STRING_CHARPOS (*it
),
3320 it
->region_beg_charpos
,
3321 it
->region_end_charpos
,
3325 #if 0 /* This shouldn't be neccessary. Let's check it. */
3326 /* If IT is used to display a mode line we would really like to
3327 use the mode line face instead of the frame's default face. */
3328 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3329 && new_face_id
== DEFAULT_FACE_ID
)
3330 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3333 /* Is this a start of a run of characters with box? Caveat:
3334 this can be called for a freshly allocated iterator; face_id
3335 is -1 is this case. We know that the new face will not
3336 change until the next check pos, i.e. if the new face has a
3337 box, all characters up to that position will have a
3338 box. But, as usual, we don't know whether that position
3339 is really the end. */
3340 if (new_face_id
!= it
->face_id
)
3342 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3343 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3345 /* If new face has a box but old face hasn't, this is the
3346 start of a run of characters with box, i.e. it has a
3347 shadow on the left side. */
3348 it
->start_of_box_run_p
3349 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3350 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3354 it
->face_id
= new_face_id
;
3355 return HANDLED_NORMALLY
;
3359 /* Return the ID of the face ``underlying'' IT's current position,
3360 which is in a string. If the iterator is associated with a
3361 buffer, return the face at IT's current buffer position.
3362 Otherwise, use the iterator's base_face_id. */
3365 underlying_face_id (it
)
3368 int face_id
= it
->base_face_id
, i
;
3370 xassert (STRINGP (it
->string
));
3372 for (i
= it
->sp
- 1; i
>= 0; --i
)
3373 if (NILP (it
->stack
[i
].string
))
3374 face_id
= it
->stack
[i
].face_id
;
3380 /* Compute the face one character before or after the current position
3381 of IT. BEFORE_P non-zero means get the face in front of IT's
3382 position. Value is the id of the face. */
3385 face_before_or_after_it_pos (it
, before_p
)
3390 int next_check_charpos
;
3391 struct text_pos pos
;
3393 xassert (it
->s
== NULL
);
3395 if (STRINGP (it
->string
))
3397 int bufpos
, base_face_id
;
3399 /* No face change past the end of the string (for the case
3400 we are padding with spaces). No face change before the
3402 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3403 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3406 /* Set pos to the position before or after IT's current position. */
3408 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3410 /* For composition, we must check the character after the
3412 pos
= (it
->what
== IT_COMPOSITION
3413 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3414 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3416 if (it
->current
.overlay_string_index
>= 0)
3417 bufpos
= IT_CHARPOS (*it
);
3421 base_face_id
= underlying_face_id (it
);
3423 /* Get the face for ASCII, or unibyte. */
3424 face_id
= face_at_string_position (it
->w
,
3428 it
->region_beg_charpos
,
3429 it
->region_end_charpos
,
3430 &next_check_charpos
,
3433 /* Correct the face for charsets different from ASCII. Do it
3434 for the multibyte case only. The face returned above is
3435 suitable for unibyte text if IT->string is unibyte. */
3436 if (STRING_MULTIBYTE (it
->string
))
3438 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3439 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3441 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3443 c
= string_char_and_length (p
, rest
, &len
);
3444 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3449 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3450 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3453 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3454 pos
= it
->current
.pos
;
3457 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3460 if (it
->what
== IT_COMPOSITION
)
3461 /* For composition, we must check the position after the
3463 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3465 INC_TEXT_POS (pos
, it
->multibyte_p
);
3468 /* Determine face for CHARSET_ASCII, or unibyte. */
3469 face_id
= face_at_buffer_position (it
->w
,
3471 it
->region_beg_charpos
,
3472 it
->region_end_charpos
,
3473 &next_check_charpos
,
3476 /* Correct the face for charsets different from ASCII. Do it
3477 for the multibyte case only. The face returned above is
3478 suitable for unibyte text if current_buffer is unibyte. */
3479 if (it
->multibyte_p
)
3481 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3482 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3483 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3492 /***********************************************************************
3494 ***********************************************************************/
3496 /* Set up iterator IT from invisible properties at its current
3497 position. Called from handle_stop. */
3499 static enum prop_handled
3500 handle_invisible_prop (it
)
3503 enum prop_handled handled
= HANDLED_NORMALLY
;
3505 if (STRINGP (it
->string
))
3507 extern Lisp_Object Qinvisible
;
3508 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3510 /* Get the value of the invisible text property at the
3511 current position. Value will be nil if there is no such
3513 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3514 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3517 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3519 handled
= HANDLED_RECOMPUTE_PROPS
;
3521 /* Get the position at which the next change of the
3522 invisible text property can be found in IT->string.
3523 Value will be nil if the property value is the same for
3524 all the rest of IT->string. */
3525 XSETINT (limit
, SCHARS (it
->string
));
3526 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3529 /* Text at current position is invisible. The next
3530 change in the property is at position end_charpos.
3531 Move IT's current position to that position. */
3532 if (INTEGERP (end_charpos
)
3533 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3535 struct text_pos old
;
3536 old
= it
->current
.string_pos
;
3537 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3538 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3542 /* The rest of the string is invisible. If this is an
3543 overlay string, proceed with the next overlay string
3544 or whatever comes and return a character from there. */
3545 if (it
->current
.overlay_string_index
>= 0)
3547 next_overlay_string (it
);
3548 /* Don't check for overlay strings when we just
3549 finished processing them. */
3550 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3554 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3555 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3562 int invis_p
, newpos
, next_stop
, start_charpos
;
3563 Lisp_Object pos
, prop
, overlay
;
3565 /* First of all, is there invisible text at this position? */
3566 start_charpos
= IT_CHARPOS (*it
);
3567 pos
= make_number (IT_CHARPOS (*it
));
3568 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3570 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3572 /* If we are on invisible text, skip over it. */
3573 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3575 /* Record whether we have to display an ellipsis for the
3577 int display_ellipsis_p
= invis_p
== 2;
3579 handled
= HANDLED_RECOMPUTE_PROPS
;
3581 /* Loop skipping over invisible text. The loop is left at
3582 ZV or with IT on the first char being visible again. */
3585 /* Try to skip some invisible text. Return value is the
3586 position reached which can be equal to IT's position
3587 if there is nothing invisible here. This skips both
3588 over invisible text properties and overlays with
3589 invisible property. */
3590 newpos
= skip_invisible (IT_CHARPOS (*it
),
3591 &next_stop
, ZV
, it
->window
);
3593 /* If we skipped nothing at all we weren't at invisible
3594 text in the first place. If everything to the end of
3595 the buffer was skipped, end the loop. */
3596 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3600 /* We skipped some characters but not necessarily
3601 all there are. Check if we ended up on visible
3602 text. Fget_char_property returns the property of
3603 the char before the given position, i.e. if we
3604 get invis_p = 0, this means that the char at
3605 newpos is visible. */
3606 pos
= make_number (newpos
);
3607 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3608 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3611 /* If we ended up on invisible text, proceed to
3612 skip starting with next_stop. */
3614 IT_CHARPOS (*it
) = next_stop
;
3618 /* The position newpos is now either ZV or on visible text. */
3619 IT_CHARPOS (*it
) = newpos
;
3620 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3622 /* If there are before-strings at the start of invisible
3623 text, and the text is invisible because of a text
3624 property, arrange to show before-strings because 20.x did
3625 it that way. (If the text is invisible because of an
3626 overlay property instead of a text property, this is
3627 already handled in the overlay code.) */
3629 && get_overlay_strings (it
, start_charpos
))
3631 handled
= HANDLED_RECOMPUTE_PROPS
;
3632 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3634 else if (display_ellipsis_p
)
3635 setup_for_ellipsis (it
, 0);
3643 /* Make iterator IT return `...' next.
3644 Replaces LEN characters from buffer. */
3647 setup_for_ellipsis (it
, len
)
3651 /* Use the display table definition for `...'. Invalid glyphs
3652 will be handled by the method returning elements from dpvec. */
3653 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3655 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3656 it
->dpvec
= v
->contents
;
3657 it
->dpend
= v
->contents
+ v
->size
;
3661 /* Default `...'. */
3662 it
->dpvec
= default_invis_vector
;
3663 it
->dpend
= default_invis_vector
+ 3;
3666 it
->dpvec_char_len
= len
;
3667 it
->current
.dpvec_index
= 0;
3668 it
->dpvec_face_id
= -1;
3670 /* Remember the current face id in case glyphs specify faces.
3671 IT's face is restored in set_iterator_to_next.
3672 saved_face_id was set to preceding char's face in handle_stop. */
3673 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3674 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3676 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3682 /***********************************************************************
3684 ***********************************************************************/
3686 /* Set up iterator IT from `display' property at its current position.
3687 Called from handle_stop.
3688 We return HANDLED_RETURN if some part of the display property
3689 overrides the display of the buffer text itself.
3690 Otherwise we return HANDLED_NORMALLY. */
3692 static enum prop_handled
3693 handle_display_prop (it
)
3696 Lisp_Object prop
, object
;
3697 struct text_pos
*position
;
3698 /* Nonzero if some property replaces the display of the text itself. */
3699 int display_replaced_p
= 0;
3701 if (STRINGP (it
->string
))
3703 object
= it
->string
;
3704 position
= &it
->current
.string_pos
;
3708 XSETWINDOW (object
, it
->w
);
3709 position
= &it
->current
.pos
;
3712 /* Reset those iterator values set from display property values. */
3713 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3714 it
->space_width
= Qnil
;
3715 it
->font_height
= Qnil
;
3718 /* We don't support recursive `display' properties, i.e. string
3719 values that have a string `display' property, that have a string
3720 `display' property etc. */
3721 if (!it
->string_from_display_prop_p
)
3722 it
->area
= TEXT_AREA
;
3724 prop
= Fget_char_property (make_number (position
->charpos
),
3727 return HANDLED_NORMALLY
;
3729 if (!STRINGP (it
->string
))
3730 object
= it
->w
->buffer
;
3733 /* Simple properties. */
3734 && !EQ (XCAR (prop
), Qimage
)
3735 && !EQ (XCAR (prop
), Qspace
)
3736 && !EQ (XCAR (prop
), Qwhen
)
3737 && !EQ (XCAR (prop
), Qslice
)
3738 && !EQ (XCAR (prop
), Qspace_width
)
3739 && !EQ (XCAR (prop
), Qheight
)
3740 && !EQ (XCAR (prop
), Qraise
)
3741 /* Marginal area specifications. */
3742 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3743 && !EQ (XCAR (prop
), Qleft_fringe
)
3744 && !EQ (XCAR (prop
), Qright_fringe
)
3745 && !NILP (XCAR (prop
)))
3747 for (; CONSP (prop
); prop
= XCDR (prop
))
3749 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3750 position
, display_replaced_p
))
3751 display_replaced_p
= 1;
3754 else if (VECTORP (prop
))
3757 for (i
= 0; i
< ASIZE (prop
); ++i
)
3758 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3759 position
, display_replaced_p
))
3760 display_replaced_p
= 1;
3764 int ret
= handle_single_display_spec (it
, prop
, object
, position
, 0);
3765 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3766 return HANDLED_RECOMPUTE_PROPS
;
3768 display_replaced_p
= 1;
3771 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3775 /* Value is the position of the end of the `display' property starting
3776 at START_POS in OBJECT. */
3778 static struct text_pos
3779 display_prop_end (it
, object
, start_pos
)
3782 struct text_pos start_pos
;
3785 struct text_pos end_pos
;
3787 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3788 Qdisplay
, object
, Qnil
);
3789 CHARPOS (end_pos
) = XFASTINT (end
);
3790 if (STRINGP (object
))
3791 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3793 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3799 /* Set up IT from a single `display' specification PROP. OBJECT
3800 is the object in which the `display' property was found. *POSITION
3801 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3802 means that we previously saw a display specification which already
3803 replaced text display with something else, for example an image;
3804 we ignore such properties after the first one has been processed.
3806 If PROP is a `space' or `image' specification, and in some other
3807 cases too, set *POSITION to the position where the `display'
3810 Value is non-zero if something was found which replaces the display
3811 of buffer or string text. Specifically, the value is -1 if that
3812 "something" is "nothing". */
3815 handle_single_display_spec (it
, spec
, object
, position
,
3816 display_replaced_before_p
)
3820 struct text_pos
*position
;
3821 int display_replaced_before_p
;
3824 Lisp_Object location
, value
;
3825 struct text_pos start_pos
;
3828 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3829 If the result is non-nil, use VALUE instead of SPEC. */
3831 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3840 if (!NILP (form
) && !EQ (form
, Qt
))
3842 int count
= SPECPDL_INDEX ();
3843 struct gcpro gcpro1
;
3845 /* Bind `object' to the object having the `display' property, a
3846 buffer or string. Bind `position' to the position in the
3847 object where the property was found, and `buffer-position'
3848 to the current position in the buffer. */
3849 specbind (Qobject
, object
);
3850 specbind (Qposition
, make_number (CHARPOS (*position
)));
3851 specbind (Qbuffer_position
,
3852 make_number (STRINGP (object
)
3853 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3855 form
= safe_eval (form
);
3857 unbind_to (count
, Qnil
);
3863 /* Handle `(height HEIGHT)' specifications. */
3865 && EQ (XCAR (spec
), Qheight
)
3866 && CONSP (XCDR (spec
)))
3868 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3871 it
->font_height
= XCAR (XCDR (spec
));
3872 if (!NILP (it
->font_height
))
3874 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3875 int new_height
= -1;
3877 if (CONSP (it
->font_height
)
3878 && (EQ (XCAR (it
->font_height
), Qplus
)
3879 || EQ (XCAR (it
->font_height
), Qminus
))
3880 && CONSP (XCDR (it
->font_height
))
3881 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3883 /* `(+ N)' or `(- N)' where N is an integer. */
3884 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3885 if (EQ (XCAR (it
->font_height
), Qplus
))
3887 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3889 else if (FUNCTIONP (it
->font_height
))
3891 /* Call function with current height as argument.
3892 Value is the new height. */
3894 height
= safe_call1 (it
->font_height
,
3895 face
->lface
[LFACE_HEIGHT_INDEX
]);
3896 if (NUMBERP (height
))
3897 new_height
= XFLOATINT (height
);
3899 else if (NUMBERP (it
->font_height
))
3901 /* Value is a multiple of the canonical char height. */
3904 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3905 new_height
= (XFLOATINT (it
->font_height
)
3906 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3910 /* Evaluate IT->font_height with `height' bound to the
3911 current specified height to get the new height. */
3912 int count
= SPECPDL_INDEX ();
3914 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3915 value
= safe_eval (it
->font_height
);
3916 unbind_to (count
, Qnil
);
3918 if (NUMBERP (value
))
3919 new_height
= XFLOATINT (value
);
3923 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3929 /* Handle `(space_width WIDTH)'. */
3931 && EQ (XCAR (spec
), Qspace_width
)
3932 && CONSP (XCDR (spec
)))
3934 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3937 value
= XCAR (XCDR (spec
));
3938 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3939 it
->space_width
= value
;
3944 /* Handle `(slice X Y WIDTH HEIGHT)'. */
3946 && EQ (XCAR (spec
), Qslice
))
3950 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3953 if (tem
= XCDR (spec
), CONSP (tem
))
3955 it
->slice
.x
= XCAR (tem
);
3956 if (tem
= XCDR (tem
), CONSP (tem
))
3958 it
->slice
.y
= XCAR (tem
);
3959 if (tem
= XCDR (tem
), CONSP (tem
))
3961 it
->slice
.width
= XCAR (tem
);
3962 if (tem
= XCDR (tem
), CONSP (tem
))
3963 it
->slice
.height
= XCAR (tem
);
3971 /* Handle `(raise FACTOR)'. */
3973 && EQ (XCAR (spec
), Qraise
)
3974 && CONSP (XCDR (spec
)))
3976 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3979 #ifdef HAVE_WINDOW_SYSTEM
3980 value
= XCAR (XCDR (spec
));
3981 if (NUMBERP (value
))
3983 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3984 it
->voffset
= - (XFLOATINT (value
)
3985 * (FONT_HEIGHT (face
->font
)));
3987 #endif /* HAVE_WINDOW_SYSTEM */
3992 /* Don't handle the other kinds of display specifications
3993 inside a string that we got from a `display' property. */
3994 if (it
->string_from_display_prop_p
)
3997 /* Characters having this form of property are not displayed, so
3998 we have to find the end of the property. */
3999 start_pos
= *position
;
4000 *position
= display_prop_end (it
, object
, start_pos
);
4003 /* Stop the scan at that end position--we assume that all
4004 text properties change there. */
4005 it
->stop_charpos
= position
->charpos
;
4007 /* Handle `(left-fringe BITMAP [FACE])'
4008 and `(right-fringe BITMAP [FACE])'. */
4010 && (EQ (XCAR (spec
), Qleft_fringe
)
4011 || EQ (XCAR (spec
), Qright_fringe
))
4012 && CONSP (XCDR (spec
)))
4014 int face_id
= DEFAULT_FACE_ID
;
4017 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4018 /* If we return here, POSITION has been advanced
4019 across the text with this property. */
4022 #ifdef HAVE_WINDOW_SYSTEM
4023 value
= XCAR (XCDR (spec
));
4024 if (!SYMBOLP (value
)
4025 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4026 /* If we return here, POSITION has been advanced
4027 across the text with this property. */
4030 if (CONSP (XCDR (XCDR (spec
))))
4032 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4033 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4034 'A', FRINGE_FACE_ID
, 0);
4039 /* Save current settings of IT so that we can restore them
4040 when we are finished with the glyph property value. */
4044 it
->area
= TEXT_AREA
;
4045 it
->what
= IT_IMAGE
;
4046 it
->image_id
= -1; /* no image */
4047 it
->position
= start_pos
;
4048 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4049 it
->method
= GET_FROM_IMAGE
;
4050 it
->face_id
= face_id
;
4052 /* Say that we haven't consumed the characters with
4053 `display' property yet. The call to pop_it in
4054 set_iterator_to_next will clean this up. */
4055 *position
= start_pos
;
4057 if (EQ (XCAR (spec
), Qleft_fringe
))
4059 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4060 it
->left_user_fringe_face_id
= face_id
;
4064 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4065 it
->right_user_fringe_face_id
= face_id
;
4067 #endif /* HAVE_WINDOW_SYSTEM */
4071 /* Prepare to handle `((margin left-margin) ...)',
4072 `((margin right-margin) ...)' and `((margin nil) ...)'
4073 prefixes for display specifications. */
4074 location
= Qunbound
;
4075 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4079 value
= XCDR (spec
);
4081 value
= XCAR (value
);
4084 if (EQ (XCAR (tem
), Qmargin
)
4085 && (tem
= XCDR (tem
),
4086 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4088 || EQ (tem
, Qleft_margin
)
4089 || EQ (tem
, Qright_margin
))))
4093 if (EQ (location
, Qunbound
))
4099 /* After this point, VALUE is the property after any
4100 margin prefix has been stripped. It must be a string,
4101 an image specification, or `(space ...)'.
4103 LOCATION specifies where to display: `left-margin',
4104 `right-margin' or nil. */
4106 valid_p
= (STRINGP (value
)
4107 #ifdef HAVE_WINDOW_SYSTEM
4108 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
4109 #endif /* not HAVE_WINDOW_SYSTEM */
4110 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4112 if (valid_p
&& !display_replaced_before_p
)
4114 /* Save current settings of IT so that we can restore them
4115 when we are finished with the glyph property value. */
4118 if (NILP (location
))
4119 it
->area
= TEXT_AREA
;
4120 else if (EQ (location
, Qleft_margin
))
4121 it
->area
= LEFT_MARGIN_AREA
;
4123 it
->area
= RIGHT_MARGIN_AREA
;
4125 if (STRINGP (value
))
4127 if (SCHARS (value
) == 0)
4130 return -1; /* Replaced by "", i.e. nothing. */
4133 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4134 it
->current
.overlay_string_index
= -1;
4135 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4136 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4137 it
->method
= GET_FROM_STRING
;
4138 it
->stop_charpos
= 0;
4139 it
->string_from_display_prop_p
= 1;
4140 /* Say that we haven't consumed the characters with
4141 `display' property yet. The call to pop_it in
4142 set_iterator_to_next will clean this up. */
4143 *position
= start_pos
;
4145 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4147 it
->method
= GET_FROM_STRETCH
;
4149 it
->current
.pos
= it
->position
= start_pos
;
4151 #ifdef HAVE_WINDOW_SYSTEM
4154 it
->what
= IT_IMAGE
;
4155 it
->image_id
= lookup_image (it
->f
, value
);
4156 it
->position
= start_pos
;
4157 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4158 it
->method
= GET_FROM_IMAGE
;
4160 /* Say that we haven't consumed the characters with
4161 `display' property yet. The call to pop_it in
4162 set_iterator_to_next will clean this up. */
4163 *position
= start_pos
;
4165 #endif /* HAVE_WINDOW_SYSTEM */
4170 /* Invalid property or property not supported. Restore
4171 POSITION to what it was before. */
4172 *position
= start_pos
;
4177 /* Check if SPEC is a display specification value whose text should be
4178 treated as intangible. */
4181 single_display_spec_intangible_p (prop
)
4184 /* Skip over `when FORM'. */
4185 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4199 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4200 we don't need to treat text as intangible. */
4201 if (EQ (XCAR (prop
), Qmargin
))
4209 || EQ (XCAR (prop
), Qleft_margin
)
4210 || EQ (XCAR (prop
), Qright_margin
))
4214 return (CONSP (prop
)
4215 && (EQ (XCAR (prop
), Qimage
)
4216 || EQ (XCAR (prop
), Qspace
)));
4220 /* Check if PROP is a display property value whose text should be
4221 treated as intangible. */
4224 display_prop_intangible_p (prop
)
4228 && CONSP (XCAR (prop
))
4229 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4231 /* A list of sub-properties. */
4232 while (CONSP (prop
))
4234 if (single_display_spec_intangible_p (XCAR (prop
)))
4239 else if (VECTORP (prop
))
4241 /* A vector of sub-properties. */
4243 for (i
= 0; i
< ASIZE (prop
); ++i
)
4244 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4248 return single_display_spec_intangible_p (prop
);
4254 /* Return 1 if PROP is a display sub-property value containing STRING. */
4257 single_display_spec_string_p (prop
, string
)
4258 Lisp_Object prop
, string
;
4260 if (EQ (string
, prop
))
4263 /* Skip over `when FORM'. */
4264 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4273 /* Skip over `margin LOCATION'. */
4274 if (EQ (XCAR (prop
), Qmargin
))
4285 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4289 /* Return 1 if STRING appears in the `display' property PROP. */
4292 display_prop_string_p (prop
, string
)
4293 Lisp_Object prop
, string
;
4296 && CONSP (XCAR (prop
))
4297 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4299 /* A list of sub-properties. */
4300 while (CONSP (prop
))
4302 if (single_display_spec_string_p (XCAR (prop
), string
))
4307 else if (VECTORP (prop
))
4309 /* A vector of sub-properties. */
4311 for (i
= 0; i
< ASIZE (prop
); ++i
)
4312 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4316 return single_display_spec_string_p (prop
, string
);
4322 /* Determine from which buffer position in W's buffer STRING comes
4323 from. AROUND_CHARPOS is an approximate position where it could
4324 be from. Value is the buffer position or 0 if it couldn't be
4327 W's buffer must be current.
4329 This function is necessary because we don't record buffer positions
4330 in glyphs generated from strings (to keep struct glyph small).
4331 This function may only use code that doesn't eval because it is
4332 called asynchronously from note_mouse_highlight. */
4335 string_buffer_position (w
, string
, around_charpos
)
4340 Lisp_Object limit
, prop
, pos
;
4341 const int MAX_DISTANCE
= 1000;
4344 pos
= make_number (around_charpos
);
4345 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4346 while (!found
&& !EQ (pos
, limit
))
4348 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4349 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4352 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4357 pos
= make_number (around_charpos
);
4358 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4359 while (!found
&& !EQ (pos
, limit
))
4361 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4362 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4365 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4370 return found
? XINT (pos
) : 0;
4375 /***********************************************************************
4376 `composition' property
4377 ***********************************************************************/
4379 /* Set up iterator IT from `composition' property at its current
4380 position. Called from handle_stop. */
4382 static enum prop_handled
4383 handle_composition_prop (it
)
4386 Lisp_Object prop
, string
;
4387 int pos
, pos_byte
, end
;
4388 enum prop_handled handled
= HANDLED_NORMALLY
;
4390 if (STRINGP (it
->string
))
4392 pos
= IT_STRING_CHARPOS (*it
);
4393 pos_byte
= IT_STRING_BYTEPOS (*it
);
4394 string
= it
->string
;
4398 pos
= IT_CHARPOS (*it
);
4399 pos_byte
= IT_BYTEPOS (*it
);
4403 /* If there's a valid composition and point is not inside of the
4404 composition (in the case that the composition is from the current
4405 buffer), draw a glyph composed from the composition components. */
4406 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
4407 && COMPOSITION_VALID_P (pos
, end
, prop
)
4408 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
4410 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4414 it
->method
= GET_FROM_COMPOSITION
;
4416 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4417 /* For a terminal, draw only the first character of the
4419 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4420 it
->len
= (STRINGP (it
->string
)
4421 ? string_char_to_byte (it
->string
, end
)
4422 : CHAR_TO_BYTE (end
)) - pos_byte
;
4423 it
->stop_charpos
= end
;
4424 handled
= HANDLED_RETURN
;
4433 /***********************************************************************
4435 ***********************************************************************/
4437 /* The following structure is used to record overlay strings for
4438 later sorting in load_overlay_strings. */
4440 struct overlay_entry
4442 Lisp_Object overlay
;
4449 /* Set up iterator IT from overlay strings at its current position.
4450 Called from handle_stop. */
4452 static enum prop_handled
4453 handle_overlay_change (it
)
4456 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4457 return HANDLED_RECOMPUTE_PROPS
;
4459 return HANDLED_NORMALLY
;
4463 /* Set up the next overlay string for delivery by IT, if there is an
4464 overlay string to deliver. Called by set_iterator_to_next when the
4465 end of the current overlay string is reached. If there are more
4466 overlay strings to display, IT->string and
4467 IT->current.overlay_string_index are set appropriately here.
4468 Otherwise IT->string is set to nil. */
4471 next_overlay_string (it
)
4474 ++it
->current
.overlay_string_index
;
4475 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4477 /* No more overlay strings. Restore IT's settings to what
4478 they were before overlay strings were processed, and
4479 continue to deliver from current_buffer. */
4480 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4483 xassert (it
->stop_charpos
>= BEGV
4484 && it
->stop_charpos
<= it
->end_charpos
);
4486 it
->current
.overlay_string_index
= -1;
4487 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4488 it
->n_overlay_strings
= 0;
4489 it
->method
= GET_FROM_BUFFER
;
4491 /* If we're at the end of the buffer, record that we have
4492 processed the overlay strings there already, so that
4493 next_element_from_buffer doesn't try it again. */
4494 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4495 it
->overlay_strings_at_end_processed_p
= 1;
4497 /* If we have to display `...' for invisible text, set
4498 the iterator up for that. */
4499 if (display_ellipsis_p
)
4500 setup_for_ellipsis (it
, 0);
4504 /* There are more overlay strings to process. If
4505 IT->current.overlay_string_index has advanced to a position
4506 where we must load IT->overlay_strings with more strings, do
4508 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4510 if (it
->current
.overlay_string_index
&& i
== 0)
4511 load_overlay_strings (it
, 0);
4513 /* Initialize IT to deliver display elements from the overlay
4515 it
->string
= it
->overlay_strings
[i
];
4516 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4517 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4518 it
->method
= GET_FROM_STRING
;
4519 it
->stop_charpos
= 0;
4526 /* Compare two overlay_entry structures E1 and E2. Used as a
4527 comparison function for qsort in load_overlay_strings. Overlay
4528 strings for the same position are sorted so that
4530 1. All after-strings come in front of before-strings, except
4531 when they come from the same overlay.
4533 2. Within after-strings, strings are sorted so that overlay strings
4534 from overlays with higher priorities come first.
4536 2. Within before-strings, strings are sorted so that overlay
4537 strings from overlays with higher priorities come last.
4539 Value is analogous to strcmp. */
4543 compare_overlay_entries (e1
, e2
)
4546 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4547 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4550 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4552 /* Let after-strings appear in front of before-strings if
4553 they come from different overlays. */
4554 if (EQ (entry1
->overlay
, entry2
->overlay
))
4555 result
= entry1
->after_string_p
? 1 : -1;
4557 result
= entry1
->after_string_p
? -1 : 1;
4559 else if (entry1
->after_string_p
)
4560 /* After-strings sorted in order of decreasing priority. */
4561 result
= entry2
->priority
- entry1
->priority
;
4563 /* Before-strings sorted in order of increasing priority. */
4564 result
= entry1
->priority
- entry2
->priority
;
4570 /* Load the vector IT->overlay_strings with overlay strings from IT's
4571 current buffer position, or from CHARPOS if that is > 0. Set
4572 IT->n_overlays to the total number of overlay strings found.
4574 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4575 a time. On entry into load_overlay_strings,
4576 IT->current.overlay_string_index gives the number of overlay
4577 strings that have already been loaded by previous calls to this
4580 IT->add_overlay_start contains an additional overlay start
4581 position to consider for taking overlay strings from, if non-zero.
4582 This position comes into play when the overlay has an `invisible'
4583 property, and both before and after-strings. When we've skipped to
4584 the end of the overlay, because of its `invisible' property, we
4585 nevertheless want its before-string to appear.
4586 IT->add_overlay_start will contain the overlay start position
4589 Overlay strings are sorted so that after-string strings come in
4590 front of before-string strings. Within before and after-strings,
4591 strings are sorted by overlay priority. See also function
4592 compare_overlay_entries. */
4595 load_overlay_strings (it
, charpos
)
4599 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4600 Lisp_Object overlay
, window
, str
, invisible
;
4601 struct Lisp_Overlay
*ov
;
4604 int n
= 0, i
, j
, invis_p
;
4605 struct overlay_entry
*entries
4606 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4609 charpos
= IT_CHARPOS (*it
);
4611 /* Append the overlay string STRING of overlay OVERLAY to vector
4612 `entries' which has size `size' and currently contains `n'
4613 elements. AFTER_P non-zero means STRING is an after-string of
4615 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4618 Lisp_Object priority; \
4622 int new_size = 2 * size; \
4623 struct overlay_entry *old = entries; \
4625 (struct overlay_entry *) alloca (new_size \
4626 * sizeof *entries); \
4627 bcopy (old, entries, size * sizeof *entries); \
4631 entries[n].string = (STRING); \
4632 entries[n].overlay = (OVERLAY); \
4633 priority = Foverlay_get ((OVERLAY), Qpriority); \
4634 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4635 entries[n].after_string_p = (AFTER_P); \
4640 /* Process overlay before the overlay center. */
4641 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4643 XSETMISC (overlay
, ov
);
4644 xassert (OVERLAYP (overlay
));
4645 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4646 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4651 /* Skip this overlay if it doesn't start or end at IT's current
4653 if (end
!= charpos
&& start
!= charpos
)
4656 /* Skip this overlay if it doesn't apply to IT->w. */
4657 window
= Foverlay_get (overlay
, Qwindow
);
4658 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4661 /* If the text ``under'' the overlay is invisible, both before-
4662 and after-strings from this overlay are visible; start and
4663 end position are indistinguishable. */
4664 invisible
= Foverlay_get (overlay
, Qinvisible
);
4665 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4667 /* If overlay has a non-empty before-string, record it. */
4668 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4669 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4671 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4673 /* If overlay has a non-empty after-string, record it. */
4674 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4675 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4677 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4680 /* Process overlays after the overlay center. */
4681 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4683 XSETMISC (overlay
, ov
);
4684 xassert (OVERLAYP (overlay
));
4685 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4686 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4688 if (start
> charpos
)
4691 /* Skip this overlay if it doesn't start or end at IT's current
4693 if (end
!= charpos
&& start
!= charpos
)
4696 /* Skip this overlay if it doesn't apply to IT->w. */
4697 window
= Foverlay_get (overlay
, Qwindow
);
4698 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4701 /* If the text ``under'' the overlay is invisible, it has a zero
4702 dimension, and both before- and after-strings apply. */
4703 invisible
= Foverlay_get (overlay
, Qinvisible
);
4704 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4706 /* If overlay has a non-empty before-string, record it. */
4707 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4708 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4710 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4712 /* If overlay has a non-empty after-string, record it. */
4713 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4714 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4716 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4719 #undef RECORD_OVERLAY_STRING
4723 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4725 /* Record the total number of strings to process. */
4726 it
->n_overlay_strings
= n
;
4728 /* IT->current.overlay_string_index is the number of overlay strings
4729 that have already been consumed by IT. Copy some of the
4730 remaining overlay strings to IT->overlay_strings. */
4732 j
= it
->current
.overlay_string_index
;
4733 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4734 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4740 /* Get the first chunk of overlay strings at IT's current buffer
4741 position, or at CHARPOS if that is > 0. Value is non-zero if at
4742 least one overlay string was found. */
4745 get_overlay_strings (it
, charpos
)
4749 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4750 process. This fills IT->overlay_strings with strings, and sets
4751 IT->n_overlay_strings to the total number of strings to process.
4752 IT->pos.overlay_string_index has to be set temporarily to zero
4753 because load_overlay_strings needs this; it must be set to -1
4754 when no overlay strings are found because a zero value would
4755 indicate a position in the first overlay string. */
4756 it
->current
.overlay_string_index
= 0;
4757 load_overlay_strings (it
, charpos
);
4759 /* If we found overlay strings, set up IT to deliver display
4760 elements from the first one. Otherwise set up IT to deliver
4761 from current_buffer. */
4762 if (it
->n_overlay_strings
)
4764 /* Make sure we know settings in current_buffer, so that we can
4765 restore meaningful values when we're done with the overlay
4767 compute_stop_pos (it
);
4768 xassert (it
->face_id
>= 0);
4770 /* Save IT's settings. They are restored after all overlay
4771 strings have been processed. */
4772 xassert (it
->sp
== 0);
4775 /* Set up IT to deliver display elements from the first overlay
4777 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4778 it
->string
= it
->overlay_strings
[0];
4779 it
->stop_charpos
= 0;
4780 xassert (STRINGP (it
->string
));
4781 it
->end_charpos
= SCHARS (it
->string
);
4782 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4783 it
->method
= GET_FROM_STRING
;
4788 it
->current
.overlay_string_index
= -1;
4789 it
->method
= GET_FROM_BUFFER
;
4794 /* Value is non-zero if we found at least one overlay string. */
4795 return STRINGP (it
->string
);
4800 /***********************************************************************
4801 Saving and restoring state
4802 ***********************************************************************/
4804 /* Save current settings of IT on IT->stack. Called, for example,
4805 before setting up IT for an overlay string, to be able to restore
4806 IT's settings to what they were after the overlay string has been
4813 struct iterator_stack_entry
*p
;
4815 xassert (it
->sp
< 2);
4816 p
= it
->stack
+ it
->sp
;
4818 p
->stop_charpos
= it
->stop_charpos
;
4819 xassert (it
->face_id
>= 0);
4820 p
->face_id
= it
->face_id
;
4821 p
->string
= it
->string
;
4822 p
->pos
= it
->current
;
4823 p
->end_charpos
= it
->end_charpos
;
4824 p
->string_nchars
= it
->string_nchars
;
4826 p
->multibyte_p
= it
->multibyte_p
;
4827 p
->slice
= it
->slice
;
4828 p
->space_width
= it
->space_width
;
4829 p
->font_height
= it
->font_height
;
4830 p
->voffset
= it
->voffset
;
4831 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4832 p
->display_ellipsis_p
= 0;
4837 /* Restore IT's settings from IT->stack. Called, for example, when no
4838 more overlay strings must be processed, and we return to delivering
4839 display elements from a buffer, or when the end of a string from a
4840 `display' property is reached and we return to delivering display
4841 elements from an overlay string, or from a buffer. */
4847 struct iterator_stack_entry
*p
;
4849 xassert (it
->sp
> 0);
4851 p
= it
->stack
+ it
->sp
;
4852 it
->stop_charpos
= p
->stop_charpos
;
4853 it
->face_id
= p
->face_id
;
4854 it
->string
= p
->string
;
4855 it
->current
= p
->pos
;
4856 it
->end_charpos
= p
->end_charpos
;
4857 it
->string_nchars
= p
->string_nchars
;
4859 it
->multibyte_p
= p
->multibyte_p
;
4860 it
->slice
= p
->slice
;
4861 it
->space_width
= p
->space_width
;
4862 it
->font_height
= p
->font_height
;
4863 it
->voffset
= p
->voffset
;
4864 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4869 /***********************************************************************
4871 ***********************************************************************/
4873 /* Set IT's current position to the previous line start. */
4876 back_to_previous_line_start (it
)
4879 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4880 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4884 /* Move IT to the next line start.
4886 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4887 we skipped over part of the text (as opposed to moving the iterator
4888 continuously over the text). Otherwise, don't change the value
4891 Newlines may come from buffer text, overlay strings, or strings
4892 displayed via the `display' property. That's the reason we can't
4893 simply use find_next_newline_no_quit.
4895 Note that this function may not skip over invisible text that is so
4896 because of text properties and immediately follows a newline. If
4897 it would, function reseat_at_next_visible_line_start, when called
4898 from set_iterator_to_next, would effectively make invisible
4899 characters following a newline part of the wrong glyph row, which
4900 leads to wrong cursor motion. */
4903 forward_to_next_line_start (it
, skipped_p
)
4907 int old_selective
, newline_found_p
, n
;
4908 const int MAX_NEWLINE_DISTANCE
= 500;
4910 /* If already on a newline, just consume it to avoid unintended
4911 skipping over invisible text below. */
4912 if (it
->what
== IT_CHARACTER
4914 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4916 set_iterator_to_next (it
, 0);
4921 /* Don't handle selective display in the following. It's (a)
4922 unnecessary because it's done by the caller, and (b) leads to an
4923 infinite recursion because next_element_from_ellipsis indirectly
4924 calls this function. */
4925 old_selective
= it
->selective
;
4928 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4929 from buffer text. */
4930 for (n
= newline_found_p
= 0;
4931 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4932 n
+= STRINGP (it
->string
) ? 0 : 1)
4934 if (!get_next_display_element (it
))
4936 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4937 set_iterator_to_next (it
, 0);
4940 /* If we didn't find a newline near enough, see if we can use a
4942 if (!newline_found_p
)
4944 int start
= IT_CHARPOS (*it
);
4945 int limit
= find_next_newline_no_quit (start
, 1);
4948 xassert (!STRINGP (it
->string
));
4950 /* If there isn't any `display' property in sight, and no
4951 overlays, we can just use the position of the newline in
4953 if (it
->stop_charpos
>= limit
4954 || ((pos
= Fnext_single_property_change (make_number (start
),
4956 Qnil
, make_number (limit
)),
4958 && next_overlay_change (start
) == ZV
))
4960 IT_CHARPOS (*it
) = limit
;
4961 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4962 *skipped_p
= newline_found_p
= 1;
4966 while (get_next_display_element (it
)
4967 && !newline_found_p
)
4969 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4970 set_iterator_to_next (it
, 0);
4975 it
->selective
= old_selective
;
4976 return newline_found_p
;
4980 /* Set IT's current position to the previous visible line start. Skip
4981 invisible text that is so either due to text properties or due to
4982 selective display. Caution: this does not change IT->current_x and
4986 back_to_previous_visible_line_start (it
)
4989 while (IT_CHARPOS (*it
) > BEGV
)
4991 back_to_previous_line_start (it
);
4992 if (IT_CHARPOS (*it
) <= BEGV
)
4995 /* If selective > 0, then lines indented more than that values
4997 if (it
->selective
> 0
4998 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4999 (double) it
->selective
)) /* iftc */
5002 /* Check the newline before point for invisibility. */
5005 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5006 Qinvisible
, it
->window
);
5007 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5011 /* If newline has a display property that replaces the newline with something
5012 else (image or text), find start of overlay or interval and continue search
5014 if (IT_CHARPOS (*it
) > BEGV
)
5016 struct it it2
= *it
;
5019 Lisp_Object val
, overlay
;
5021 pos
= --IT_CHARPOS (it2
);
5024 if (handle_display_prop (&it2
) == HANDLED_RETURN
5025 && !NILP (val
= get_char_property_and_overlay
5026 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5027 && (OVERLAYP (overlay
)
5028 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5029 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5033 IT_CHARPOS (*it
) = beg
;
5034 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5042 xassert (IT_CHARPOS (*it
) >= BEGV
);
5043 xassert (IT_CHARPOS (*it
) == BEGV
5044 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5049 /* Reseat iterator IT at the previous visible line start. Skip
5050 invisible text that is so either due to text properties or due to
5051 selective display. At the end, update IT's overlay information,
5052 face information etc. */
5055 reseat_at_previous_visible_line_start (it
)
5058 back_to_previous_visible_line_start (it
);
5059 reseat (it
, it
->current
.pos
, 1);
5064 /* Reseat iterator IT on the next visible line start in the current
5065 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5066 preceding the line start. Skip over invisible text that is so
5067 because of selective display. Compute faces, overlays etc at the
5068 new position. Note that this function does not skip over text that
5069 is invisible because of text properties. */
5072 reseat_at_next_visible_line_start (it
, on_newline_p
)
5076 int newline_found_p
, skipped_p
= 0;
5078 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5080 /* Skip over lines that are invisible because they are indented
5081 more than the value of IT->selective. */
5082 if (it
->selective
> 0)
5083 while (IT_CHARPOS (*it
) < ZV
5084 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5085 (double) it
->selective
)) /* iftc */
5087 xassert (IT_BYTEPOS (*it
) == BEGV
5088 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5089 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5092 /* Position on the newline if that's what's requested. */
5093 if (on_newline_p
&& newline_found_p
)
5095 if (STRINGP (it
->string
))
5097 if (IT_STRING_CHARPOS (*it
) > 0)
5099 --IT_STRING_CHARPOS (*it
);
5100 --IT_STRING_BYTEPOS (*it
);
5103 else if (IT_CHARPOS (*it
) > BEGV
)
5107 reseat (it
, it
->current
.pos
, 0);
5111 reseat (it
, it
->current
.pos
, 0);
5118 /***********************************************************************
5119 Changing an iterator's position
5120 ***********************************************************************/
5122 /* Change IT's current position to POS in current_buffer. If FORCE_P
5123 is non-zero, always check for text properties at the new position.
5124 Otherwise, text properties are only looked up if POS >=
5125 IT->check_charpos of a property. */
5128 reseat (it
, pos
, force_p
)
5130 struct text_pos pos
;
5133 int original_pos
= IT_CHARPOS (*it
);
5135 reseat_1 (it
, pos
, 0);
5137 /* Determine where to check text properties. Avoid doing it
5138 where possible because text property lookup is very expensive. */
5140 || CHARPOS (pos
) > it
->stop_charpos
5141 || CHARPOS (pos
) < original_pos
)
5148 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5149 IT->stop_pos to POS, also. */
5152 reseat_1 (it
, pos
, set_stop_p
)
5154 struct text_pos pos
;
5157 /* Don't call this function when scanning a C string. */
5158 xassert (it
->s
== NULL
);
5160 /* POS must be a reasonable value. */
5161 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5163 it
->current
.pos
= it
->position
= pos
;
5164 XSETBUFFER (it
->object
, current_buffer
);
5165 it
->end_charpos
= ZV
;
5167 it
->current
.dpvec_index
= -1;
5168 it
->current
.overlay_string_index
= -1;
5169 IT_STRING_CHARPOS (*it
) = -1;
5170 IT_STRING_BYTEPOS (*it
) = -1;
5172 it
->method
= GET_FROM_BUFFER
;
5173 /* RMS: I added this to fix a bug in move_it_vertically_backward
5174 where it->area continued to relate to the starting point
5175 for the backward motion. Bug report from
5176 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
5177 However, I am not sure whether reseat still does the right thing
5178 in general after this change. */
5179 it
->area
= TEXT_AREA
;
5180 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5182 it
->face_before_selective_p
= 0;
5185 it
->stop_charpos
= CHARPOS (pos
);
5189 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5190 If S is non-null, it is a C string to iterate over. Otherwise,
5191 STRING gives a Lisp string to iterate over.
5193 If PRECISION > 0, don't return more then PRECISION number of
5194 characters from the string.
5196 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5197 characters have been returned. FIELD_WIDTH < 0 means an infinite
5200 MULTIBYTE = 0 means disable processing of multibyte characters,
5201 MULTIBYTE > 0 means enable it,
5202 MULTIBYTE < 0 means use IT->multibyte_p.
5204 IT must be initialized via a prior call to init_iterator before
5205 calling this function. */
5208 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5213 int precision
, field_width
, multibyte
;
5215 /* No region in strings. */
5216 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5218 /* No text property checks performed by default, but see below. */
5219 it
->stop_charpos
= -1;
5221 /* Set iterator position and end position. */
5222 bzero (&it
->current
, sizeof it
->current
);
5223 it
->current
.overlay_string_index
= -1;
5224 it
->current
.dpvec_index
= -1;
5225 xassert (charpos
>= 0);
5227 /* If STRING is specified, use its multibyteness, otherwise use the
5228 setting of MULTIBYTE, if specified. */
5230 it
->multibyte_p
= multibyte
> 0;
5234 xassert (STRINGP (string
));
5235 it
->string
= string
;
5237 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5238 it
->method
= GET_FROM_STRING
;
5239 it
->current
.string_pos
= string_pos (charpos
, string
);
5246 /* Note that we use IT->current.pos, not it->current.string_pos,
5247 for displaying C strings. */
5248 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5249 if (it
->multibyte_p
)
5251 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5252 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5256 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5257 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5260 it
->method
= GET_FROM_C_STRING
;
5263 /* PRECISION > 0 means don't return more than PRECISION characters
5265 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5266 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5268 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5269 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5270 FIELD_WIDTH < 0 means infinite field width. This is useful for
5271 padding with `-' at the end of a mode line. */
5272 if (field_width
< 0)
5273 field_width
= INFINITY
;
5274 if (field_width
> it
->end_charpos
- charpos
)
5275 it
->end_charpos
= charpos
+ field_width
;
5277 /* Use the standard display table for displaying strings. */
5278 if (DISP_TABLE_P (Vstandard_display_table
))
5279 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5281 it
->stop_charpos
= charpos
;
5287 /***********************************************************************
5289 ***********************************************************************/
5291 /* Map enum it_method value to corresponding next_element_from_* function. */
5293 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5295 next_element_from_buffer
,
5296 next_element_from_display_vector
,
5297 next_element_from_composition
,
5298 next_element_from_string
,
5299 next_element_from_c_string
,
5300 next_element_from_image
,
5301 next_element_from_stretch
5305 /* Load IT's display element fields with information about the next
5306 display element from the current position of IT. Value is zero if
5307 end of buffer (or C string) is reached. */
5310 get_next_display_element (it
)
5313 /* Non-zero means that we found a display element. Zero means that
5314 we hit the end of what we iterate over. Performance note: the
5315 function pointer `method' used here turns out to be faster than
5316 using a sequence of if-statements. */
5320 success_p
= (*get_next_element
[it
->method
]) (it
);
5322 if (it
->what
== IT_CHARACTER
)
5324 /* Map via display table or translate control characters.
5325 IT->c, IT->len etc. have been set to the next character by
5326 the function call above. If we have a display table, and it
5327 contains an entry for IT->c, translate it. Don't do this if
5328 IT->c itself comes from a display table, otherwise we could
5329 end up in an infinite recursion. (An alternative could be to
5330 count the recursion depth of this function and signal an
5331 error when a certain maximum depth is reached.) Is it worth
5333 if (success_p
&& it
->dpvec
== NULL
)
5338 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5341 struct Lisp_Vector
*v
= XVECTOR (dv
);
5343 /* Return the first character from the display table
5344 entry, if not empty. If empty, don't display the
5345 current character. */
5348 it
->dpvec_char_len
= it
->len
;
5349 it
->dpvec
= v
->contents
;
5350 it
->dpend
= v
->contents
+ v
->size
;
5351 it
->current
.dpvec_index
= 0;
5352 it
->dpvec_face_id
= -1;
5353 it
->saved_face_id
= it
->face_id
;
5354 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5359 set_iterator_to_next (it
, 0);
5364 /* Translate control characters into `\003' or `^C' form.
5365 Control characters coming from a display table entry are
5366 currently not translated because we use IT->dpvec to hold
5367 the translation. This could easily be changed but I
5368 don't believe that it is worth doing.
5370 If it->multibyte_p is nonzero, eight-bit characters and
5371 non-printable multibyte characters are also translated to
5374 If it->multibyte_p is zero, eight-bit characters that
5375 don't have corresponding multibyte char code are also
5376 translated to octal form. */
5377 else if ((it
->c
< ' '
5378 && (it
->area
!= TEXT_AREA
5379 /* In mode line, treat \n like other crl chars. */
5381 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5382 || (it
->c
!= '\n' && it
->c
!= '\t')))
5386 || !CHAR_PRINTABLE_P (it
->c
)
5387 || (!NILP (Vnobreak_char_display
)
5388 && (it
->c
== 0x8a0 || it
->c
== 0x8ad
5389 || it
->c
== 0x920 || it
->c
== 0x92d
5390 || it
->c
== 0xe20 || it
->c
== 0xe2d
5391 || it
->c
== 0xf20 || it
->c
== 0xf2d)))
5393 && (!unibyte_display_via_language_environment
5394 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
5396 /* IT->c is a control character which must be displayed
5397 either as '\003' or as `^C' where the '\\' and '^'
5398 can be defined in the display table. Fill
5399 IT->ctl_chars with glyphs for what we have to
5400 display. Then, set IT->dpvec to these glyphs. */
5403 int face_id
, lface_id
= 0 ;
5406 /* Handle control characters with ^. */
5408 if (it
->c
< 128 && it
->ctl_arrow_p
)
5410 g
= '^'; /* default glyph for Control */
5411 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5413 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5414 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5416 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5417 lface_id
= FAST_GLYPH_FACE (g
);
5421 g
= FAST_GLYPH_CHAR (g
);
5422 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5427 /* Merge the escape-glyph face into the current face. */
5428 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5432 XSETINT (it
->ctl_chars
[0], g
);
5434 XSETINT (it
->ctl_chars
[1], g
);
5436 goto display_control
;
5439 /* Handle non-break space in the mode where it only gets
5442 if (EQ (Vnobreak_char_display
, Qt
)
5443 && (it
->c
== 0x8a0 || it
->c
== 0x920
5444 || it
->c
== 0xe20 || it
->c
== 0xf20))
5446 /* Merge the no-break-space face into the current face. */
5447 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5451 XSETINT (it
->ctl_chars
[0], g
);
5453 goto display_control
;
5456 /* Handle sequences that start with the "escape glyph". */
5458 /* the default escape glyph is \. */
5459 escape_glyph
= '\\';
5462 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5463 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5465 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5466 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5470 /* The display table specified a face.
5471 Merge it into face_id and also into escape_glyph. */
5472 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5473 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5478 /* Merge the escape-glyph face into the current face. */
5479 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5483 /* Handle soft hyphens in the mode where they only get
5486 if (EQ (Vnobreak_char_display
, Qt
)
5487 && (it
->c
== 0x8ad || it
->c
== 0x92d
5488 || it
->c
== 0xe2d || it
->c
== 0xf2d))
5491 XSETINT (it
->ctl_chars
[0], g
);
5493 goto display_control
;
5496 /* Handle non-break space and soft hyphen
5497 with the escape glyph. */
5499 if (it
->c
== 0x8a0 || it
->c
== 0x8ad
5500 || it
->c
== 0x920 || it
->c
== 0x92d
5501 || it
->c
== 0xe20 || it
->c
== 0xe2d
5502 || it
->c
== 0xf20 || it
->c
== 0xf2d)
5504 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5505 g
= it
->c
= ((it
->c
& 0xf) == 0 ? ' ' : '-');
5506 XSETINT (it
->ctl_chars
[1], g
);
5508 goto display_control
;
5512 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5516 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5517 if (SINGLE_BYTE_CHAR_P (it
->c
))
5518 str
[0] = it
->c
, len
= 1;
5521 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5524 /* It's an invalid character, which shouldn't
5525 happen actually, but due to bugs it may
5526 happen. Let's print the char as is, there's
5527 not much meaningful we can do with it. */
5529 str
[1] = it
->c
>> 8;
5530 str
[2] = it
->c
>> 16;
5531 str
[3] = it
->c
>> 24;
5536 for (i
= 0; i
< len
; i
++)
5538 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5539 /* Insert three more glyphs into IT->ctl_chars for
5540 the octal display of the character. */
5541 g
= ((str
[i
] >> 6) & 7) + '0';
5542 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5543 g
= ((str
[i
] >> 3) & 7) + '0';
5544 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5545 g
= (str
[i
] & 7) + '0';
5546 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5552 /* Set up IT->dpvec and return first character from it. */
5553 it
->dpvec_char_len
= it
->len
;
5554 it
->dpvec
= it
->ctl_chars
;
5555 it
->dpend
= it
->dpvec
+ ctl_len
;
5556 it
->current
.dpvec_index
= 0;
5557 it
->dpvec_face_id
= face_id
;
5558 it
->saved_face_id
= it
->face_id
;
5559 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5565 /* Adjust face id for a multibyte character. There are no
5566 multibyte character in unibyte text. */
5569 && FRAME_WINDOW_P (it
->f
))
5571 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5572 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5576 /* Is this character the last one of a run of characters with
5577 box? If yes, set IT->end_of_box_run_p to 1. */
5584 it
->end_of_box_run_p
5585 = ((face_id
= face_after_it_pos (it
),
5586 face_id
!= it
->face_id
)
5587 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5588 face
->box
== FACE_NO_BOX
));
5591 /* Value is 0 if end of buffer or string reached. */
5596 /* Move IT to the next display element.
5598 RESEAT_P non-zero means if called on a newline in buffer text,
5599 skip to the next visible line start.
5601 Functions get_next_display_element and set_iterator_to_next are
5602 separate because I find this arrangement easier to handle than a
5603 get_next_display_element function that also increments IT's
5604 position. The way it is we can first look at an iterator's current
5605 display element, decide whether it fits on a line, and if it does,
5606 increment the iterator position. The other way around we probably
5607 would either need a flag indicating whether the iterator has to be
5608 incremented the next time, or we would have to implement a
5609 decrement position function which would not be easy to write. */
5612 set_iterator_to_next (it
, reseat_p
)
5616 /* Reset flags indicating start and end of a sequence of characters
5617 with box. Reset them at the start of this function because
5618 moving the iterator to a new position might set them. */
5619 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5623 case GET_FROM_BUFFER
:
5624 /* The current display element of IT is a character from
5625 current_buffer. Advance in the buffer, and maybe skip over
5626 invisible lines that are so because of selective display. */
5627 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5628 reseat_at_next_visible_line_start (it
, 0);
5631 xassert (it
->len
!= 0);
5632 IT_BYTEPOS (*it
) += it
->len
;
5633 IT_CHARPOS (*it
) += 1;
5634 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5638 case GET_FROM_COMPOSITION
:
5639 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5640 if (STRINGP (it
->string
))
5642 IT_STRING_BYTEPOS (*it
) += it
->len
;
5643 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5644 it
->method
= GET_FROM_STRING
;
5645 goto consider_string_end
;
5649 IT_BYTEPOS (*it
) += it
->len
;
5650 IT_CHARPOS (*it
) += it
->cmp_len
;
5651 it
->method
= GET_FROM_BUFFER
;
5655 case GET_FROM_C_STRING
:
5656 /* Current display element of IT is from a C string. */
5657 IT_BYTEPOS (*it
) += it
->len
;
5658 IT_CHARPOS (*it
) += 1;
5661 case GET_FROM_DISPLAY_VECTOR
:
5662 /* Current display element of IT is from a display table entry.
5663 Advance in the display table definition. Reset it to null if
5664 end reached, and continue with characters from buffers/
5666 ++it
->current
.dpvec_index
;
5668 /* Restore face of the iterator to what they were before the
5669 display vector entry (these entries may contain faces). */
5670 it
->face_id
= it
->saved_face_id
;
5672 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5675 it
->method
= GET_FROM_C_STRING
;
5676 else if (STRINGP (it
->string
))
5677 it
->method
= GET_FROM_STRING
;
5679 it
->method
= GET_FROM_BUFFER
;
5682 it
->current
.dpvec_index
= -1;
5684 /* Skip over characters which were displayed via IT->dpvec. */
5685 if (it
->dpvec_char_len
< 0)
5686 reseat_at_next_visible_line_start (it
, 1);
5687 else if (it
->dpvec_char_len
> 0)
5689 it
->len
= it
->dpvec_char_len
;
5690 set_iterator_to_next (it
, reseat_p
);
5693 /* Recheck faces after display vector */
5694 it
->stop_charpos
= IT_CHARPOS (*it
);
5698 case GET_FROM_STRING
:
5699 /* Current display element is a character from a Lisp string. */
5700 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5701 IT_STRING_BYTEPOS (*it
) += it
->len
;
5702 IT_STRING_CHARPOS (*it
) += 1;
5704 consider_string_end
:
5706 if (it
->current
.overlay_string_index
>= 0)
5708 /* IT->string is an overlay string. Advance to the
5709 next, if there is one. */
5710 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5711 next_overlay_string (it
);
5715 /* IT->string is not an overlay string. If we reached
5716 its end, and there is something on IT->stack, proceed
5717 with what is on the stack. This can be either another
5718 string, this time an overlay string, or a buffer. */
5719 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5723 if (STRINGP (it
->string
))
5724 goto consider_string_end
;
5725 it
->method
= GET_FROM_BUFFER
;
5730 case GET_FROM_IMAGE
:
5731 case GET_FROM_STRETCH
:
5732 /* The position etc with which we have to proceed are on
5733 the stack. The position may be at the end of a string,
5734 if the `display' property takes up the whole string. */
5735 xassert (it
->sp
> 0);
5738 if (STRINGP (it
->string
))
5740 it
->method
= GET_FROM_STRING
;
5741 goto consider_string_end
;
5743 it
->method
= GET_FROM_BUFFER
;
5747 /* There are no other methods defined, so this should be a bug. */
5751 xassert (it
->method
!= GET_FROM_STRING
5752 || (STRINGP (it
->string
)
5753 && IT_STRING_CHARPOS (*it
) >= 0));
5756 /* Load IT's display element fields with information about the next
5757 display element which comes from a display table entry or from the
5758 result of translating a control character to one of the forms `^C'
5761 IT->dpvec holds the glyphs to return as characters.
5762 IT->saved_face_id holds the face id before the display vector--
5763 it is restored into IT->face_idin set_iterator_to_next. */
5766 next_element_from_display_vector (it
)
5770 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5772 it
->face_id
= it
->saved_face_id
;
5774 if (INTEGERP (*it
->dpvec
)
5775 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5779 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5780 it
->c
= FAST_GLYPH_CHAR (g
);
5781 it
->len
= CHAR_BYTES (it
->c
);
5783 /* The entry may contain a face id to use. Such a face id is
5784 the id of a Lisp face, not a realized face. A face id of
5785 zero means no face is specified. */
5786 if (it
->dpvec_face_id
>= 0)
5787 it
->face_id
= it
->dpvec_face_id
;
5790 int lface_id
= FAST_GLYPH_FACE (g
);
5792 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5797 /* Display table entry is invalid. Return a space. */
5798 it
->c
= ' ', it
->len
= 1;
5800 /* Don't change position and object of the iterator here. They are
5801 still the values of the character that had this display table
5802 entry or was translated, and that's what we want. */
5803 it
->what
= IT_CHARACTER
;
5808 /* Load IT with the next display element from Lisp string IT->string.
5809 IT->current.string_pos is the current position within the string.
5810 If IT->current.overlay_string_index >= 0, the Lisp string is an
5814 next_element_from_string (it
)
5817 struct text_pos position
;
5819 xassert (STRINGP (it
->string
));
5820 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5821 position
= it
->current
.string_pos
;
5823 /* Time to check for invisible text? */
5824 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5825 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5829 /* Since a handler may have changed IT->method, we must
5831 return get_next_display_element (it
);
5834 if (it
->current
.overlay_string_index
>= 0)
5836 /* Get the next character from an overlay string. In overlay
5837 strings, There is no field width or padding with spaces to
5839 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5844 else if (STRING_MULTIBYTE (it
->string
))
5846 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5847 const unsigned char *s
= (SDATA (it
->string
)
5848 + IT_STRING_BYTEPOS (*it
));
5849 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5853 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5859 /* Get the next character from a Lisp string that is not an
5860 overlay string. Such strings come from the mode line, for
5861 example. We may have to pad with spaces, or truncate the
5862 string. See also next_element_from_c_string. */
5863 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5868 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5870 /* Pad with spaces. */
5871 it
->c
= ' ', it
->len
= 1;
5872 CHARPOS (position
) = BYTEPOS (position
) = -1;
5874 else if (STRING_MULTIBYTE (it
->string
))
5876 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5877 const unsigned char *s
= (SDATA (it
->string
)
5878 + IT_STRING_BYTEPOS (*it
));
5879 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5883 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5888 /* Record what we have and where it came from. Note that we store a
5889 buffer position in IT->position although it could arguably be a
5891 it
->what
= IT_CHARACTER
;
5892 it
->object
= it
->string
;
5893 it
->position
= position
;
5898 /* Load IT with next display element from C string IT->s.
5899 IT->string_nchars is the maximum number of characters to return
5900 from the string. IT->end_charpos may be greater than
5901 IT->string_nchars when this function is called, in which case we
5902 may have to return padding spaces. Value is zero if end of string
5903 reached, including padding spaces. */
5906 next_element_from_c_string (it
)
5912 it
->what
= IT_CHARACTER
;
5913 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5916 /* IT's position can be greater IT->string_nchars in case a field
5917 width or precision has been specified when the iterator was
5919 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5921 /* End of the game. */
5925 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5927 /* Pad with spaces. */
5928 it
->c
= ' ', it
->len
= 1;
5929 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5931 else if (it
->multibyte_p
)
5933 /* Implementation note: The calls to strlen apparently aren't a
5934 performance problem because there is no noticeable performance
5935 difference between Emacs running in unibyte or multibyte mode. */
5936 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5937 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5941 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5947 /* Set up IT to return characters from an ellipsis, if appropriate.
5948 The definition of the ellipsis glyphs may come from a display table
5949 entry. This function Fills IT with the first glyph from the
5950 ellipsis if an ellipsis is to be displayed. */
5953 next_element_from_ellipsis (it
)
5956 if (it
->selective_display_ellipsis_p
)
5957 setup_for_ellipsis (it
, it
->len
);
5960 /* The face at the current position may be different from the
5961 face we find after the invisible text. Remember what it
5962 was in IT->saved_face_id, and signal that it's there by
5963 setting face_before_selective_p. */
5964 it
->saved_face_id
= it
->face_id
;
5965 it
->method
= GET_FROM_BUFFER
;
5966 reseat_at_next_visible_line_start (it
, 1);
5967 it
->face_before_selective_p
= 1;
5970 return get_next_display_element (it
);
5974 /* Deliver an image display element. The iterator IT is already
5975 filled with image information (done in handle_display_prop). Value
5980 next_element_from_image (it
)
5983 it
->what
= IT_IMAGE
;
5988 /* Fill iterator IT with next display element from a stretch glyph
5989 property. IT->object is the value of the text property. Value is
5993 next_element_from_stretch (it
)
5996 it
->what
= IT_STRETCH
;
6001 /* Load IT with the next display element from current_buffer. Value
6002 is zero if end of buffer reached. IT->stop_charpos is the next
6003 position at which to stop and check for text properties or buffer
6007 next_element_from_buffer (it
)
6012 /* Check this assumption, otherwise, we would never enter the
6013 if-statement, below. */
6014 xassert (IT_CHARPOS (*it
) >= BEGV
6015 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
6017 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6019 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6021 int overlay_strings_follow_p
;
6023 /* End of the game, except when overlay strings follow that
6024 haven't been returned yet. */
6025 if (it
->overlay_strings_at_end_processed_p
)
6026 overlay_strings_follow_p
= 0;
6029 it
->overlay_strings_at_end_processed_p
= 1;
6030 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6033 if (overlay_strings_follow_p
)
6034 success_p
= get_next_display_element (it
);
6038 it
->position
= it
->current
.pos
;
6045 return get_next_display_element (it
);
6050 /* No face changes, overlays etc. in sight, so just return a
6051 character from current_buffer. */
6054 /* Maybe run the redisplay end trigger hook. Performance note:
6055 This doesn't seem to cost measurable time. */
6056 if (it
->redisplay_end_trigger_charpos
6058 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6059 run_redisplay_end_trigger_hook (it
);
6061 /* Get the next character, maybe multibyte. */
6062 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6063 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6065 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
6066 - IT_BYTEPOS (*it
));
6067 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
6070 it
->c
= *p
, it
->len
= 1;
6072 /* Record what we have and where it came from. */
6073 it
->what
= IT_CHARACTER
;;
6074 it
->object
= it
->w
->buffer
;
6075 it
->position
= it
->current
.pos
;
6077 /* Normally we return the character found above, except when we
6078 really want to return an ellipsis for selective display. */
6083 /* A value of selective > 0 means hide lines indented more
6084 than that number of columns. */
6085 if (it
->selective
> 0
6086 && IT_CHARPOS (*it
) + 1 < ZV
6087 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6088 IT_BYTEPOS (*it
) + 1,
6089 (double) it
->selective
)) /* iftc */
6091 success_p
= next_element_from_ellipsis (it
);
6092 it
->dpvec_char_len
= -1;
6095 else if (it
->c
== '\r' && it
->selective
== -1)
6097 /* A value of selective == -1 means that everything from the
6098 CR to the end of the line is invisible, with maybe an
6099 ellipsis displayed for it. */
6100 success_p
= next_element_from_ellipsis (it
);
6101 it
->dpvec_char_len
= -1;
6106 /* Value is zero if end of buffer reached. */
6107 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6112 /* Run the redisplay end trigger hook for IT. */
6115 run_redisplay_end_trigger_hook (it
)
6118 Lisp_Object args
[3];
6120 /* IT->glyph_row should be non-null, i.e. we should be actually
6121 displaying something, or otherwise we should not run the hook. */
6122 xassert (it
->glyph_row
);
6124 /* Set up hook arguments. */
6125 args
[0] = Qredisplay_end_trigger_functions
;
6126 args
[1] = it
->window
;
6127 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6128 it
->redisplay_end_trigger_charpos
= 0;
6130 /* Since we are *trying* to run these functions, don't try to run
6131 them again, even if they get an error. */
6132 it
->w
->redisplay_end_trigger
= Qnil
;
6133 Frun_hook_with_args (3, args
);
6135 /* Notice if it changed the face of the character we are on. */
6136 handle_face_prop (it
);
6140 /* Deliver a composition display element. The iterator IT is already
6141 filled with composition information (done in
6142 handle_composition_prop). Value is always 1. */
6145 next_element_from_composition (it
)
6148 it
->what
= IT_COMPOSITION
;
6149 it
->position
= (STRINGP (it
->string
)
6150 ? it
->current
.string_pos
6157 /***********************************************************************
6158 Moving an iterator without producing glyphs
6159 ***********************************************************************/
6161 /* Check if iterator is at a position corresponding to a valid buffer
6162 position after some move_it_ call. */
6164 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6165 ((it)->method == GET_FROM_STRING \
6166 ? IT_STRING_CHARPOS (*it) == 0 \
6170 /* Move iterator IT to a specified buffer or X position within one
6171 line on the display without producing glyphs.
6173 OP should be a bit mask including some or all of these bits:
6174 MOVE_TO_X: Stop on reaching x-position TO_X.
6175 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6176 Regardless of OP's value, stop in reaching the end of the display line.
6178 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6179 This means, in particular, that TO_X includes window's horizontal
6182 The return value has several possible values that
6183 say what condition caused the scan to stop:
6185 MOVE_POS_MATCH_OR_ZV
6186 - when TO_POS or ZV was reached.
6189 -when TO_X was reached before TO_POS or ZV were reached.
6192 - when we reached the end of the display area and the line must
6196 - when we reached the end of the display area and the line is
6200 - when we stopped at a line end, i.e. a newline or a CR and selective
6203 static enum move_it_result
6204 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
6206 int to_charpos
, to_x
, op
;
6208 enum move_it_result result
= MOVE_UNDEFINED
;
6209 struct glyph_row
*saved_glyph_row
;
6211 /* Don't produce glyphs in produce_glyphs. */
6212 saved_glyph_row
= it
->glyph_row
;
6213 it
->glyph_row
= NULL
;
6215 #define BUFFER_POS_REACHED_P() \
6216 ((op & MOVE_TO_POS) != 0 \
6217 && BUFFERP (it->object) \
6218 && IT_CHARPOS (*it) >= to_charpos \
6219 && (it->method == GET_FROM_BUFFER \
6220 || (it->method == GET_FROM_DISPLAY_VECTOR \
6221 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6226 int x
, i
, ascent
= 0, descent
= 0;
6228 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
6229 if ((op
& MOVE_TO_POS
) != 0
6230 && BUFFERP (it
->object
)
6231 && it
->method
== GET_FROM_BUFFER
6232 && IT_CHARPOS (*it
) > to_charpos
)
6234 result
= MOVE_POS_MATCH_OR_ZV
;
6238 /* Stop when ZV reached.
6239 We used to stop here when TO_CHARPOS reached as well, but that is
6240 too soon if this glyph does not fit on this line. So we handle it
6241 explicitly below. */
6242 if (!get_next_display_element (it
)
6243 || (it
->truncate_lines_p
6244 && BUFFER_POS_REACHED_P ()))
6246 result
= MOVE_POS_MATCH_OR_ZV
;
6250 /* The call to produce_glyphs will get the metrics of the
6251 display element IT is loaded with. We record in x the
6252 x-position before this display element in case it does not
6256 /* Remember the line height so far in case the next element doesn't
6258 if (!it
->truncate_lines_p
)
6260 ascent
= it
->max_ascent
;
6261 descent
= it
->max_descent
;
6264 PRODUCE_GLYPHS (it
);
6266 if (it
->area
!= TEXT_AREA
)
6268 set_iterator_to_next (it
, 1);
6272 /* The number of glyphs we get back in IT->nglyphs will normally
6273 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6274 character on a terminal frame, or (iii) a line end. For the
6275 second case, IT->nglyphs - 1 padding glyphs will be present
6276 (on X frames, there is only one glyph produced for a
6277 composite character.
6279 The behavior implemented below means, for continuation lines,
6280 that as many spaces of a TAB as fit on the current line are
6281 displayed there. For terminal frames, as many glyphs of a
6282 multi-glyph character are displayed in the current line, too.
6283 This is what the old redisplay code did, and we keep it that
6284 way. Under X, the whole shape of a complex character must
6285 fit on the line or it will be completely displayed in the
6288 Note that both for tabs and padding glyphs, all glyphs have
6292 /* More than one glyph or glyph doesn't fit on line. All
6293 glyphs have the same width. */
6294 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6296 int x_before_this_char
= x
;
6297 int hpos_before_this_char
= it
->hpos
;
6299 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6301 new_x
= x
+ single_glyph_width
;
6303 /* We want to leave anything reaching TO_X to the caller. */
6304 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6306 if (BUFFER_POS_REACHED_P ())
6307 goto buffer_pos_reached
;
6309 result
= MOVE_X_REACHED
;
6312 else if (/* Lines are continued. */
6313 !it
->truncate_lines_p
6314 && (/* And glyph doesn't fit on the line. */
6315 new_x
> it
->last_visible_x
6316 /* Or it fits exactly and we're on a window
6318 || (new_x
== it
->last_visible_x
6319 && FRAME_WINDOW_P (it
->f
))))
6321 if (/* IT->hpos == 0 means the very first glyph
6322 doesn't fit on the line, e.g. a wide image. */
6324 || (new_x
== it
->last_visible_x
6325 && FRAME_WINDOW_P (it
->f
)))
6328 it
->current_x
= new_x
;
6330 /* The character's last glyph just barely fits
6332 if (i
== it
->nglyphs
- 1)
6334 /* If this is the destination position,
6335 return a position *before* it in this row,
6336 now that we know it fits in this row. */
6337 if (BUFFER_POS_REACHED_P ())
6339 it
->hpos
= hpos_before_this_char
;
6340 it
->current_x
= x_before_this_char
;
6341 result
= MOVE_POS_MATCH_OR_ZV
;
6345 set_iterator_to_next (it
, 1);
6346 #ifdef HAVE_WINDOW_SYSTEM
6347 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6349 if (!get_next_display_element (it
))
6351 result
= MOVE_POS_MATCH_OR_ZV
;
6354 if (BUFFER_POS_REACHED_P ())
6356 if (ITERATOR_AT_END_OF_LINE_P (it
))
6357 result
= MOVE_POS_MATCH_OR_ZV
;
6359 result
= MOVE_LINE_CONTINUED
;
6362 if (ITERATOR_AT_END_OF_LINE_P (it
))
6364 result
= MOVE_NEWLINE_OR_CR
;
6368 #endif /* HAVE_WINDOW_SYSTEM */
6374 it
->max_ascent
= ascent
;
6375 it
->max_descent
= descent
;
6378 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6380 result
= MOVE_LINE_CONTINUED
;
6383 else if (BUFFER_POS_REACHED_P ())
6384 goto buffer_pos_reached
;
6385 else if (new_x
> it
->first_visible_x
)
6387 /* Glyph is visible. Increment number of glyphs that
6388 would be displayed. */
6393 /* Glyph is completely off the left margin of the display
6394 area. Nothing to do. */
6398 if (result
!= MOVE_UNDEFINED
)
6401 else if (BUFFER_POS_REACHED_P ())
6405 it
->max_ascent
= ascent
;
6406 it
->max_descent
= descent
;
6407 result
= MOVE_POS_MATCH_OR_ZV
;
6410 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6412 /* Stop when TO_X specified and reached. This check is
6413 necessary here because of lines consisting of a line end,
6414 only. The line end will not produce any glyphs and we
6415 would never get MOVE_X_REACHED. */
6416 xassert (it
->nglyphs
== 0);
6417 result
= MOVE_X_REACHED
;
6421 /* Is this a line end? If yes, we're done. */
6422 if (ITERATOR_AT_END_OF_LINE_P (it
))
6424 result
= MOVE_NEWLINE_OR_CR
;
6428 /* The current display element has been consumed. Advance
6430 set_iterator_to_next (it
, 1);
6432 /* Stop if lines are truncated and IT's current x-position is
6433 past the right edge of the window now. */
6434 if (it
->truncate_lines_p
6435 && it
->current_x
>= it
->last_visible_x
)
6437 #ifdef HAVE_WINDOW_SYSTEM
6438 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6440 if (!get_next_display_element (it
)
6441 || BUFFER_POS_REACHED_P ())
6443 result
= MOVE_POS_MATCH_OR_ZV
;
6446 if (ITERATOR_AT_END_OF_LINE_P (it
))
6448 result
= MOVE_NEWLINE_OR_CR
;
6452 #endif /* HAVE_WINDOW_SYSTEM */
6453 result
= MOVE_LINE_TRUNCATED
;
6458 #undef BUFFER_POS_REACHED_P
6460 /* Restore the iterator settings altered at the beginning of this
6462 it
->glyph_row
= saved_glyph_row
;
6467 /* Move IT forward until it satisfies one or more of the criteria in
6468 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6470 OP is a bit-mask that specifies where to stop, and in particular,
6471 which of those four position arguments makes a difference. See the
6472 description of enum move_operation_enum.
6474 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6475 screen line, this function will set IT to the next position >
6479 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6481 int to_charpos
, to_x
, to_y
, to_vpos
;
6484 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6490 if (op
& MOVE_TO_VPOS
)
6492 /* If no TO_CHARPOS and no TO_X specified, stop at the
6493 start of the line TO_VPOS. */
6494 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6496 if (it
->vpos
== to_vpos
)
6502 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6506 /* TO_VPOS >= 0 means stop at TO_X in the line at
6507 TO_VPOS, or at TO_POS, whichever comes first. */
6508 if (it
->vpos
== to_vpos
)
6514 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6516 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6521 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6523 /* We have reached TO_X but not in the line we want. */
6524 skip
= move_it_in_display_line_to (it
, to_charpos
,
6526 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6534 else if (op
& MOVE_TO_Y
)
6536 struct it it_backup
;
6538 /* TO_Y specified means stop at TO_X in the line containing
6539 TO_Y---or at TO_CHARPOS if this is reached first. The
6540 problem is that we can't really tell whether the line
6541 contains TO_Y before we have completely scanned it, and
6542 this may skip past TO_X. What we do is to first scan to
6545 If TO_X is not specified, use a TO_X of zero. The reason
6546 is to make the outcome of this function more predictable.
6547 If we didn't use TO_X == 0, we would stop at the end of
6548 the line which is probably not what a caller would expect
6550 skip
= move_it_in_display_line_to (it
, to_charpos
,
6554 | (op
& MOVE_TO_POS
)));
6556 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6557 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6563 /* If TO_X was reached, we would like to know whether TO_Y
6564 is in the line. This can only be said if we know the
6565 total line height which requires us to scan the rest of
6567 if (skip
== MOVE_X_REACHED
)
6570 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6571 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6573 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6576 /* Now, decide whether TO_Y is in this line. */
6577 line_height
= it
->max_ascent
+ it
->max_descent
;
6578 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6580 if (to_y
>= it
->current_y
6581 && to_y
< it
->current_y
+ line_height
)
6583 if (skip
== MOVE_X_REACHED
)
6584 /* If TO_Y is in this line and TO_X was reached above,
6585 we scanned too far. We have to restore IT's settings
6586 to the ones before skipping. */
6590 else if (skip
== MOVE_X_REACHED
)
6593 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6601 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6605 case MOVE_POS_MATCH_OR_ZV
:
6609 case MOVE_NEWLINE_OR_CR
:
6610 set_iterator_to_next (it
, 1);
6611 it
->continuation_lines_width
= 0;
6614 case MOVE_LINE_TRUNCATED
:
6615 it
->continuation_lines_width
= 0;
6616 reseat_at_next_visible_line_start (it
, 0);
6617 if ((op
& MOVE_TO_POS
) != 0
6618 && IT_CHARPOS (*it
) > to_charpos
)
6625 case MOVE_LINE_CONTINUED
:
6626 it
->continuation_lines_width
+= it
->current_x
;
6633 /* Reset/increment for the next run. */
6634 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6635 it
->current_x
= it
->hpos
= 0;
6636 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6638 last_height
= it
->max_ascent
+ it
->max_descent
;
6639 last_max_ascent
= it
->max_ascent
;
6640 it
->max_ascent
= it
->max_descent
= 0;
6645 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6649 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6651 If DY > 0, move IT backward at least that many pixels. DY = 0
6652 means move IT backward to the preceding line start or BEGV. This
6653 function may move over more than DY pixels if IT->current_y - DY
6654 ends up in the middle of a line; in this case IT->current_y will be
6655 set to the top of the line moved to. */
6658 move_it_vertically_backward (it
, dy
)
6669 start_pos
= IT_CHARPOS (*it
);
6671 /* Estimate how many newlines we must move back. */
6672 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6674 /* Set the iterator's position that many lines back. */
6675 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6676 back_to_previous_visible_line_start (it
);
6678 /* Reseat the iterator here. When moving backward, we don't want
6679 reseat to skip forward over invisible text, set up the iterator
6680 to deliver from overlay strings at the new position etc. So,
6681 use reseat_1 here. */
6682 reseat_1 (it
, it
->current
.pos
, 1);
6684 /* We are now surely at a line start. */
6685 it
->current_x
= it
->hpos
= 0;
6686 it
->continuation_lines_width
= 0;
6688 /* Move forward and see what y-distance we moved. First move to the
6689 start of the next line so that we get its height. We need this
6690 height to be able to tell whether we reached the specified
6693 it2
.max_ascent
= it2
.max_descent
= 0;
6696 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6697 MOVE_TO_POS
| MOVE_TO_VPOS
);
6699 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
6700 xassert (IT_CHARPOS (*it
) >= BEGV
);
6703 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6704 xassert (IT_CHARPOS (*it
) >= BEGV
);
6705 /* H is the actual vertical distance from the position in *IT
6706 and the starting position. */
6707 h
= it2
.current_y
- it
->current_y
;
6708 /* NLINES is the distance in number of lines. */
6709 nlines
= it2
.vpos
- it
->vpos
;
6711 /* Correct IT's y and vpos position
6712 so that they are relative to the starting point. */
6718 /* DY == 0 means move to the start of the screen line. The
6719 value of nlines is > 0 if continuation lines were involved. */
6721 move_it_by_lines (it
, nlines
, 1);
6723 /* I think this assert is bogus if buffer contains
6724 invisible text or images. KFS. */
6725 xassert (IT_CHARPOS (*it
) <= start_pos
);
6730 /* The y-position we try to reach, relative to *IT.
6731 Note that H has been subtracted in front of the if-statement. */
6732 int target_y
= it
->current_y
+ h
- dy
;
6733 int y0
= it3
.current_y
;
6734 int y1
= line_bottom_y (&it3
);
6735 int line_height
= y1
- y0
;
6737 /* If we did not reach target_y, try to move further backward if
6738 we can. If we moved too far backward, try to move forward. */
6739 if (target_y
< it
->current_y
6740 /* This is heuristic. In a window that's 3 lines high, with
6741 a line height of 13 pixels each, recentering with point
6742 on the bottom line will try to move -39/2 = 19 pixels
6743 backward. Try to avoid moving into the first line. */
6744 && (it
->current_y
- target_y
6745 > min (window_box_height (it
->w
), line_height
* 2 / 3))
6746 && IT_CHARPOS (*it
) > BEGV
)
6748 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6749 target_y
- it
->current_y
));
6750 dy
= it
->current_y
- target_y
;
6751 goto move_further_back
;
6753 else if (target_y
>= it
->current_y
+ line_height
6754 && IT_CHARPOS (*it
) < ZV
)
6756 /* Should move forward by at least one line, maybe more.
6758 Note: Calling move_it_by_lines can be expensive on
6759 terminal frames, where compute_motion is used (via
6760 vmotion) to do the job, when there are very long lines
6761 and truncate-lines is nil. That's the reason for
6762 treating terminal frames specially here. */
6764 if (!FRAME_WINDOW_P (it
->f
))
6765 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6770 move_it_by_lines (it
, 1, 1);
6772 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6776 /* I think this assert is bogus if buffer contains
6777 invisible text or images. KFS. */
6778 xassert (IT_CHARPOS (*it
) >= BEGV
);
6785 /* Move IT by a specified amount of pixel lines DY. DY negative means
6786 move backwards. DY = 0 means move to start of screen line. At the
6787 end, IT will be on the start of a screen line. */
6790 move_it_vertically (it
, dy
)
6795 move_it_vertically_backward (it
, -dy
);
6798 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6799 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6800 MOVE_TO_POS
| MOVE_TO_Y
);
6801 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6803 /* If buffer ends in ZV without a newline, move to the start of
6804 the line to satisfy the post-condition. */
6805 if (IT_CHARPOS (*it
) == ZV
6807 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6808 move_it_by_lines (it
, 0, 0);
6813 /* Move iterator IT past the end of the text line it is in. */
6816 move_it_past_eol (it
)
6819 enum move_it_result rc
;
6821 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6822 if (rc
== MOVE_NEWLINE_OR_CR
)
6823 set_iterator_to_next (it
, 0);
6827 #if 0 /* Currently not used. */
6829 /* Return non-zero if some text between buffer positions START_CHARPOS
6830 and END_CHARPOS is invisible. IT->window is the window for text
6834 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6836 int start_charpos
, end_charpos
;
6838 Lisp_Object prop
, limit
;
6839 int invisible_found_p
;
6841 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6843 /* Is text at START invisible? */
6844 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6846 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6847 invisible_found_p
= 1;
6850 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6852 make_number (end_charpos
));
6853 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6856 return invisible_found_p
;
6862 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6863 negative means move up. DVPOS == 0 means move to the start of the
6864 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6865 NEED_Y_P is zero, IT->current_y will be left unchanged.
6867 Further optimization ideas: If we would know that IT->f doesn't use
6868 a face with proportional font, we could be faster for
6869 truncate-lines nil. */
6872 move_it_by_lines (it
, dvpos
, need_y_p
)
6874 int dvpos
, need_y_p
;
6876 struct position pos
;
6878 if (!FRAME_WINDOW_P (it
->f
))
6880 struct text_pos textpos
;
6882 /* We can use vmotion on frames without proportional fonts. */
6883 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6884 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6885 reseat (it
, textpos
, 1);
6886 it
->vpos
+= pos
.vpos
;
6887 it
->current_y
+= pos
.vpos
;
6889 else if (dvpos
== 0)
6891 /* DVPOS == 0 means move to the start of the screen line. */
6892 move_it_vertically_backward (it
, 0);
6893 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6894 /* Let next call to line_bottom_y calculate real line height */
6899 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6900 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
6901 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
6906 int start_charpos
, i
;
6908 /* Start at the beginning of the screen line containing IT's
6909 position. This may actually move vertically backwards,
6910 in case of overlays, so adjust dvpos accordingly. */
6912 move_it_vertically_backward (it
, 0);
6915 /* Go back -DVPOS visible lines and reseat the iterator there. */
6916 start_charpos
= IT_CHARPOS (*it
);
6917 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
6918 back_to_previous_visible_line_start (it
);
6919 reseat (it
, it
->current
.pos
, 1);
6921 /* Move further back if we end up in a string or an image. */
6922 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
6924 /* First try to move to start of display line. */
6926 move_it_vertically_backward (it
, 0);
6928 if (IT_POS_VALID_AFTER_MOVE_P (it
))
6930 /* If start of line is still in string or image,
6931 move further back. */
6932 back_to_previous_visible_line_start (it
);
6933 reseat (it
, it
->current
.pos
, 1);
6937 it
->current_x
= it
->hpos
= 0;
6939 /* Above call may have moved too far if continuation lines
6940 are involved. Scan forward and see if it did. */
6942 it2
.vpos
= it2
.current_y
= 0;
6943 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6944 it
->vpos
-= it2
.vpos
;
6945 it
->current_y
-= it2
.current_y
;
6946 it
->current_x
= it
->hpos
= 0;
6948 /* If we moved too far back, move IT some lines forward. */
6949 if (it2
.vpos
> -dvpos
)
6951 int delta
= it2
.vpos
+ dvpos
;
6953 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6954 /* Move back again if we got too far ahead. */
6955 if (IT_CHARPOS (*it
) >= start_charpos
)
6961 /* Return 1 if IT points into the middle of a display vector. */
6964 in_display_vector_p (it
)
6967 return (it
->method
== GET_FROM_DISPLAY_VECTOR
6968 && it
->current
.dpvec_index
> 0
6969 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
6973 /***********************************************************************
6975 ***********************************************************************/
6978 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
6982 add_to_log (format
, arg1
, arg2
)
6984 Lisp_Object arg1
, arg2
;
6986 Lisp_Object args
[3];
6987 Lisp_Object msg
, fmt
;
6990 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6993 /* Do nothing if called asynchronously. Inserting text into
6994 a buffer may call after-change-functions and alike and
6995 that would means running Lisp asynchronously. */
6996 if (handling_signal
)
7000 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7002 args
[0] = fmt
= build_string (format
);
7005 msg
= Fformat (3, args
);
7007 len
= SBYTES (msg
) + 1;
7008 SAFE_ALLOCA (buffer
, char *, len
);
7009 bcopy (SDATA (msg
), buffer
, len
);
7011 message_dolog (buffer
, len
- 1, 1, 0);
7018 /* Output a newline in the *Messages* buffer if "needs" one. */
7021 message_log_maybe_newline ()
7023 if (message_log_need_newline
)
7024 message_dolog ("", 0, 1, 0);
7028 /* Add a string M of length NBYTES to the message log, optionally
7029 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7030 nonzero, means interpret the contents of M as multibyte. This
7031 function calls low-level routines in order to bypass text property
7032 hooks, etc. which might not be safe to run.
7034 This may GC (insert may run before/after change hooks),
7035 so the buffer M must NOT point to a Lisp string. */
7038 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7040 int nbytes
, nlflag
, multibyte
;
7042 if (!NILP (Vmemory_full
))
7045 if (!NILP (Vmessage_log_max
))
7047 struct buffer
*oldbuf
;
7048 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7049 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7050 int point_at_end
= 0;
7052 Lisp_Object old_deactivate_mark
, tem
;
7053 struct gcpro gcpro1
;
7055 old_deactivate_mark
= Vdeactivate_mark
;
7056 oldbuf
= current_buffer
;
7057 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7058 current_buffer
->undo_list
= Qt
;
7060 oldpoint
= message_dolog_marker1
;
7061 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7062 oldbegv
= message_dolog_marker2
;
7063 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7064 oldzv
= message_dolog_marker3
;
7065 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7066 GCPRO1 (old_deactivate_mark
);
7074 BEGV_BYTE
= BEG_BYTE
;
7077 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7079 /* Insert the string--maybe converting multibyte to single byte
7080 or vice versa, so that all the text fits the buffer. */
7082 && NILP (current_buffer
->enable_multibyte_characters
))
7084 int i
, c
, char_bytes
;
7085 unsigned char work
[1];
7087 /* Convert a multibyte string to single-byte
7088 for the *Message* buffer. */
7089 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7091 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7092 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
7094 : multibyte_char_to_unibyte (c
, Qnil
));
7095 insert_1_both (work
, 1, 1, 1, 0, 0);
7098 else if (! multibyte
7099 && ! NILP (current_buffer
->enable_multibyte_characters
))
7101 int i
, c
, char_bytes
;
7102 unsigned char *msg
= (unsigned char *) m
;
7103 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7104 /* Convert a single-byte string to multibyte
7105 for the *Message* buffer. */
7106 for (i
= 0; i
< nbytes
; i
++)
7108 c
= unibyte_char_to_multibyte (msg
[i
]);
7109 char_bytes
= CHAR_STRING (c
, str
);
7110 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7114 insert_1 (m
, nbytes
, 1, 0, 0);
7118 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7119 insert_1 ("\n", 1, 1, 0, 0);
7121 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7123 this_bol_byte
= PT_BYTE
;
7125 /* See if this line duplicates the previous one.
7126 If so, combine duplicates. */
7129 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7131 prev_bol_byte
= PT_BYTE
;
7133 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7134 this_bol
, this_bol_byte
);
7137 del_range_both (prev_bol
, prev_bol_byte
,
7138 this_bol
, this_bol_byte
, 0);
7144 /* If you change this format, don't forget to also
7145 change message_log_check_duplicate. */
7146 sprintf (dupstr
, " [%d times]", dup
);
7147 duplen
= strlen (dupstr
);
7148 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7149 insert_1 (dupstr
, duplen
, 1, 0, 1);
7154 /* If we have more than the desired maximum number of lines
7155 in the *Messages* buffer now, delete the oldest ones.
7156 This is safe because we don't have undo in this buffer. */
7158 if (NATNUMP (Vmessage_log_max
))
7160 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7161 -XFASTINT (Vmessage_log_max
) - 1, 0);
7162 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7165 BEGV
= XMARKER (oldbegv
)->charpos
;
7166 BEGV_BYTE
= marker_byte_position (oldbegv
);
7175 ZV
= XMARKER (oldzv
)->charpos
;
7176 ZV_BYTE
= marker_byte_position (oldzv
);
7180 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7182 /* We can't do Fgoto_char (oldpoint) because it will run some
7184 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7185 XMARKER (oldpoint
)->bytepos
);
7188 unchain_marker (XMARKER (oldpoint
));
7189 unchain_marker (XMARKER (oldbegv
));
7190 unchain_marker (XMARKER (oldzv
));
7192 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7193 set_buffer_internal (oldbuf
);
7195 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7196 message_log_need_newline
= !nlflag
;
7197 Vdeactivate_mark
= old_deactivate_mark
;
7202 /* We are at the end of the buffer after just having inserted a newline.
7203 (Note: We depend on the fact we won't be crossing the gap.)
7204 Check to see if the most recent message looks a lot like the previous one.
7205 Return 0 if different, 1 if the new one should just replace it, or a
7206 value N > 1 if we should also append " [N times]". */
7209 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7210 int prev_bol
, this_bol
;
7211 int prev_bol_byte
, this_bol_byte
;
7214 int len
= Z_BYTE
- 1 - this_bol_byte
;
7216 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7217 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7219 for (i
= 0; i
< len
; i
++)
7221 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7229 if (*p1
++ == ' ' && *p1
++ == '[')
7232 while (*p1
>= '0' && *p1
<= '9')
7233 n
= n
* 10 + *p1
++ - '0';
7234 if (strncmp (p1
, " times]\n", 8) == 0)
7241 /* Display an echo area message M with a specified length of NBYTES
7242 bytes. The string may include null characters. If M is 0, clear
7243 out any existing message, and let the mini-buffer text show
7246 This may GC, so the buffer M must NOT point to a Lisp string. */
7249 message2 (m
, nbytes
, multibyte
)
7254 /* First flush out any partial line written with print. */
7255 message_log_maybe_newline ();
7257 message_dolog (m
, nbytes
, 1, multibyte
);
7258 message2_nolog (m
, nbytes
, multibyte
);
7262 /* The non-logging counterpart of message2. */
7265 message2_nolog (m
, nbytes
, multibyte
)
7267 int nbytes
, multibyte
;
7269 struct frame
*sf
= SELECTED_FRAME ();
7270 message_enable_multibyte
= multibyte
;
7274 if (noninteractive_need_newline
)
7275 putc ('\n', stderr
);
7276 noninteractive_need_newline
= 0;
7278 fwrite (m
, nbytes
, 1, stderr
);
7279 if (cursor_in_echo_area
== 0)
7280 fprintf (stderr
, "\n");
7283 /* A null message buffer means that the frame hasn't really been
7284 initialized yet. Error messages get reported properly by
7285 cmd_error, so this must be just an informative message; toss it. */
7286 else if (INTERACTIVE
7287 && sf
->glyphs_initialized_p
7288 && FRAME_MESSAGE_BUF (sf
))
7290 Lisp_Object mini_window
;
7293 /* Get the frame containing the mini-buffer
7294 that the selected frame is using. */
7295 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7296 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7298 FRAME_SAMPLE_VISIBILITY (f
);
7299 if (FRAME_VISIBLE_P (sf
)
7300 && ! FRAME_VISIBLE_P (f
))
7301 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7305 set_message (m
, Qnil
, nbytes
, multibyte
);
7306 if (minibuffer_auto_raise
)
7307 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7310 clear_message (1, 1);
7312 do_pending_window_change (0);
7313 echo_area_display (1);
7314 do_pending_window_change (0);
7315 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7316 (*frame_up_to_date_hook
) (f
);
7321 /* Display an echo area message M with a specified length of NBYTES
7322 bytes. The string may include null characters. If M is not a
7323 string, clear out any existing message, and let the mini-buffer
7326 This function cancels echoing. */
7329 message3 (m
, nbytes
, multibyte
)
7334 struct gcpro gcpro1
;
7337 clear_message (1,1);
7340 /* First flush out any partial line written with print. */
7341 message_log_maybe_newline ();
7347 SAFE_ALLOCA (buffer
, char *, nbytes
);
7348 bcopy (SDATA (m
), buffer
, nbytes
);
7349 message_dolog (buffer
, nbytes
, 1, multibyte
);
7352 message3_nolog (m
, nbytes
, multibyte
);
7358 /* The non-logging version of message3.
7359 This does not cancel echoing, because it is used for echoing.
7360 Perhaps we need to make a separate function for echoing
7361 and make this cancel echoing. */
7364 message3_nolog (m
, nbytes
, multibyte
)
7366 int nbytes
, multibyte
;
7368 struct frame
*sf
= SELECTED_FRAME ();
7369 message_enable_multibyte
= multibyte
;
7373 if (noninteractive_need_newline
)
7374 putc ('\n', stderr
);
7375 noninteractive_need_newline
= 0;
7377 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7378 if (cursor_in_echo_area
== 0)
7379 fprintf (stderr
, "\n");
7382 /* A null message buffer means that the frame hasn't really been
7383 initialized yet. Error messages get reported properly by
7384 cmd_error, so this must be just an informative message; toss it. */
7385 else if (INTERACTIVE
7386 && sf
->glyphs_initialized_p
7387 && FRAME_MESSAGE_BUF (sf
))
7389 Lisp_Object mini_window
;
7393 /* Get the frame containing the mini-buffer
7394 that the selected frame is using. */
7395 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7396 frame
= XWINDOW (mini_window
)->frame
;
7399 FRAME_SAMPLE_VISIBILITY (f
);
7400 if (FRAME_VISIBLE_P (sf
)
7401 && !FRAME_VISIBLE_P (f
))
7402 Fmake_frame_visible (frame
);
7404 if (STRINGP (m
) && SCHARS (m
) > 0)
7406 set_message (NULL
, m
, nbytes
, multibyte
);
7407 if (minibuffer_auto_raise
)
7408 Fraise_frame (frame
);
7409 /* Assume we are not echoing.
7410 (If we are, echo_now will override this.) */
7411 echo_message_buffer
= Qnil
;
7414 clear_message (1, 1);
7416 do_pending_window_change (0);
7417 echo_area_display (1);
7418 do_pending_window_change (0);
7419 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7420 (*frame_up_to_date_hook
) (f
);
7425 /* Display a null-terminated echo area message M. If M is 0, clear
7426 out any existing message, and let the mini-buffer text show through.
7428 The buffer M must continue to exist until after the echo area gets
7429 cleared or some other message gets displayed there. Do not pass
7430 text that is stored in a Lisp string. Do not pass text in a buffer
7431 that was alloca'd. */
7437 message2 (m
, (m
? strlen (m
) : 0), 0);
7441 /* The non-logging counterpart of message1. */
7447 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7450 /* Display a message M which contains a single %s
7451 which gets replaced with STRING. */
7454 message_with_string (m
, string
, log
)
7459 CHECK_STRING (string
);
7465 if (noninteractive_need_newline
)
7466 putc ('\n', stderr
);
7467 noninteractive_need_newline
= 0;
7468 fprintf (stderr
, m
, SDATA (string
));
7469 if (cursor_in_echo_area
== 0)
7470 fprintf (stderr
, "\n");
7474 else if (INTERACTIVE
)
7476 /* The frame whose minibuffer we're going to display the message on.
7477 It may be larger than the selected frame, so we need
7478 to use its buffer, not the selected frame's buffer. */
7479 Lisp_Object mini_window
;
7480 struct frame
*f
, *sf
= SELECTED_FRAME ();
7482 /* Get the frame containing the minibuffer
7483 that the selected frame is using. */
7484 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7485 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7487 /* A null message buffer means that the frame hasn't really been
7488 initialized yet. Error messages get reported properly by
7489 cmd_error, so this must be just an informative message; toss it. */
7490 if (FRAME_MESSAGE_BUF (f
))
7492 Lisp_Object args
[2], message
;
7493 struct gcpro gcpro1
, gcpro2
;
7495 args
[0] = build_string (m
);
7496 args
[1] = message
= string
;
7497 GCPRO2 (args
[0], message
);
7500 message
= Fformat (2, args
);
7503 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7505 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7509 /* Print should start at the beginning of the message
7510 buffer next time. */
7511 message_buf_print
= 0;
7517 /* Dump an informative message to the minibuf. If M is 0, clear out
7518 any existing message, and let the mini-buffer text show through. */
7522 message (m
, a1
, a2
, a3
)
7524 EMACS_INT a1
, a2
, a3
;
7530 if (noninteractive_need_newline
)
7531 putc ('\n', stderr
);
7532 noninteractive_need_newline
= 0;
7533 fprintf (stderr
, m
, a1
, a2
, a3
);
7534 if (cursor_in_echo_area
== 0)
7535 fprintf (stderr
, "\n");
7539 else if (INTERACTIVE
)
7541 /* The frame whose mini-buffer we're going to display the message
7542 on. It may be larger than the selected frame, so we need to
7543 use its buffer, not the selected frame's buffer. */
7544 Lisp_Object mini_window
;
7545 struct frame
*f
, *sf
= SELECTED_FRAME ();
7547 /* Get the frame containing the mini-buffer
7548 that the selected frame is using. */
7549 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7550 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7552 /* A null message buffer means that the frame hasn't really been
7553 initialized yet. Error messages get reported properly by
7554 cmd_error, so this must be just an informative message; toss
7556 if (FRAME_MESSAGE_BUF (f
))
7567 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7568 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7570 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7571 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7573 #endif /* NO_ARG_ARRAY */
7575 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7580 /* Print should start at the beginning of the message
7581 buffer next time. */
7582 message_buf_print
= 0;
7588 /* The non-logging version of message. */
7591 message_nolog (m
, a1
, a2
, a3
)
7593 EMACS_INT a1
, a2
, a3
;
7595 Lisp_Object old_log_max
;
7596 old_log_max
= Vmessage_log_max
;
7597 Vmessage_log_max
= Qnil
;
7598 message (m
, a1
, a2
, a3
);
7599 Vmessage_log_max
= old_log_max
;
7603 /* Display the current message in the current mini-buffer. This is
7604 only called from error handlers in process.c, and is not time
7610 if (!NILP (echo_area_buffer
[0]))
7613 string
= Fcurrent_message ();
7614 message3 (string
, SBYTES (string
),
7615 !NILP (current_buffer
->enable_multibyte_characters
));
7620 /* Make sure echo area buffers in `echo_buffers' are live.
7621 If they aren't, make new ones. */
7624 ensure_echo_area_buffers ()
7628 for (i
= 0; i
< 2; ++i
)
7629 if (!BUFFERP (echo_buffer
[i
])
7630 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7633 Lisp_Object old_buffer
;
7636 old_buffer
= echo_buffer
[i
];
7637 sprintf (name
, " *Echo Area %d*", i
);
7638 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7639 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7641 for (j
= 0; j
< 2; ++j
)
7642 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7643 echo_area_buffer
[j
] = echo_buffer
[i
];
7648 /* Call FN with args A1..A4 with either the current or last displayed
7649 echo_area_buffer as current buffer.
7651 WHICH zero means use the current message buffer
7652 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7653 from echo_buffer[] and clear it.
7655 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7656 suitable buffer from echo_buffer[] and clear it.
7658 Value is what FN returns. */
7661 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7664 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7670 int this_one
, the_other
, clear_buffer_p
, rc
;
7671 int count
= SPECPDL_INDEX ();
7673 /* If buffers aren't live, make new ones. */
7674 ensure_echo_area_buffers ();
7679 this_one
= 0, the_other
= 1;
7681 this_one
= 1, the_other
= 0;
7683 /* Choose a suitable buffer from echo_buffer[] is we don't
7685 if (NILP (echo_area_buffer
[this_one
]))
7687 echo_area_buffer
[this_one
]
7688 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7689 ? echo_buffer
[the_other
]
7690 : echo_buffer
[this_one
]);
7694 buffer
= echo_area_buffer
[this_one
];
7696 /* Don't get confused by reusing the buffer used for echoing
7697 for a different purpose. */
7698 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7701 record_unwind_protect (unwind_with_echo_area_buffer
,
7702 with_echo_area_buffer_unwind_data (w
));
7704 /* Make the echo area buffer current. Note that for display
7705 purposes, it is not necessary that the displayed window's buffer
7706 == current_buffer, except for text property lookup. So, let's
7707 only set that buffer temporarily here without doing a full
7708 Fset_window_buffer. We must also change w->pointm, though,
7709 because otherwise an assertions in unshow_buffer fails, and Emacs
7711 set_buffer_internal_1 (XBUFFER (buffer
));
7715 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7718 current_buffer
->undo_list
= Qt
;
7719 current_buffer
->read_only
= Qnil
;
7720 specbind (Qinhibit_read_only
, Qt
);
7721 specbind (Qinhibit_modification_hooks
, Qt
);
7723 if (clear_buffer_p
&& Z
> BEG
)
7726 xassert (BEGV
>= BEG
);
7727 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7729 rc
= fn (a1
, a2
, a3
, a4
);
7731 xassert (BEGV
>= BEG
);
7732 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7734 unbind_to (count
, Qnil
);
7739 /* Save state that should be preserved around the call to the function
7740 FN called in with_echo_area_buffer. */
7743 with_echo_area_buffer_unwind_data (w
)
7749 /* Reduce consing by keeping one vector in
7750 Vwith_echo_area_save_vector. */
7751 vector
= Vwith_echo_area_save_vector
;
7752 Vwith_echo_area_save_vector
= Qnil
;
7755 vector
= Fmake_vector (make_number (7), Qnil
);
7757 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7758 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7759 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7763 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7764 AREF (vector
, i
) = w
->buffer
; ++i
;
7765 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7766 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7771 for (; i
< end
; ++i
)
7772 AREF (vector
, i
) = Qnil
;
7775 xassert (i
== ASIZE (vector
));
7780 /* Restore global state from VECTOR which was created by
7781 with_echo_area_buffer_unwind_data. */
7784 unwind_with_echo_area_buffer (vector
)
7787 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7788 Vdeactivate_mark
= AREF (vector
, 1);
7789 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7791 if (WINDOWP (AREF (vector
, 3)))
7794 Lisp_Object buffer
, charpos
, bytepos
;
7796 w
= XWINDOW (AREF (vector
, 3));
7797 buffer
= AREF (vector
, 4);
7798 charpos
= AREF (vector
, 5);
7799 bytepos
= AREF (vector
, 6);
7802 set_marker_both (w
->pointm
, buffer
,
7803 XFASTINT (charpos
), XFASTINT (bytepos
));
7806 Vwith_echo_area_save_vector
= vector
;
7811 /* Set up the echo area for use by print functions. MULTIBYTE_P
7812 non-zero means we will print multibyte. */
7815 setup_echo_area_for_printing (multibyte_p
)
7818 /* If we can't find an echo area any more, exit. */
7819 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7822 ensure_echo_area_buffers ();
7824 if (!message_buf_print
)
7826 /* A message has been output since the last time we printed.
7827 Choose a fresh echo area buffer. */
7828 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7829 echo_area_buffer
[0] = echo_buffer
[1];
7831 echo_area_buffer
[0] = echo_buffer
[0];
7833 /* Switch to that buffer and clear it. */
7834 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7835 current_buffer
->truncate_lines
= Qnil
;
7839 int count
= SPECPDL_INDEX ();
7840 specbind (Qinhibit_read_only
, Qt
);
7841 /* Note that undo recording is always disabled. */
7843 unbind_to (count
, Qnil
);
7845 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7847 /* Set up the buffer for the multibyteness we need. */
7849 != !NILP (current_buffer
->enable_multibyte_characters
))
7850 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7852 /* Raise the frame containing the echo area. */
7853 if (minibuffer_auto_raise
)
7855 struct frame
*sf
= SELECTED_FRAME ();
7856 Lisp_Object mini_window
;
7857 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7858 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7861 message_log_maybe_newline ();
7862 message_buf_print
= 1;
7866 if (NILP (echo_area_buffer
[0]))
7868 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7869 echo_area_buffer
[0] = echo_buffer
[1];
7871 echo_area_buffer
[0] = echo_buffer
[0];
7874 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7876 /* Someone switched buffers between print requests. */
7877 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7878 current_buffer
->truncate_lines
= Qnil
;
7884 /* Display an echo area message in window W. Value is non-zero if W's
7885 height is changed. If display_last_displayed_message_p is
7886 non-zero, display the message that was last displayed, otherwise
7887 display the current message. */
7890 display_echo_area (w
)
7893 int i
, no_message_p
, window_height_changed_p
, count
;
7895 /* Temporarily disable garbage collections while displaying the echo
7896 area. This is done because a GC can print a message itself.
7897 That message would modify the echo area buffer's contents while a
7898 redisplay of the buffer is going on, and seriously confuse
7900 count
= inhibit_garbage_collection ();
7902 /* If there is no message, we must call display_echo_area_1
7903 nevertheless because it resizes the window. But we will have to
7904 reset the echo_area_buffer in question to nil at the end because
7905 with_echo_area_buffer will sets it to an empty buffer. */
7906 i
= display_last_displayed_message_p
? 1 : 0;
7907 no_message_p
= NILP (echo_area_buffer
[i
]);
7909 window_height_changed_p
7910 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7911 display_echo_area_1
,
7912 (EMACS_INT
) w
, Qnil
, 0, 0);
7915 echo_area_buffer
[i
] = Qnil
;
7917 unbind_to (count
, Qnil
);
7918 return window_height_changed_p
;
7922 /* Helper for display_echo_area. Display the current buffer which
7923 contains the current echo area message in window W, a mini-window,
7924 a pointer to which is passed in A1. A2..A4 are currently not used.
7925 Change the height of W so that all of the message is displayed.
7926 Value is non-zero if height of W was changed. */
7929 display_echo_area_1 (a1
, a2
, a3
, a4
)
7934 struct window
*w
= (struct window
*) a1
;
7936 struct text_pos start
;
7937 int window_height_changed_p
= 0;
7939 /* Do this before displaying, so that we have a large enough glyph
7940 matrix for the display. If we can't get enough space for the
7941 whole text, display the last N lines. That works by setting w->start. */
7942 window_height_changed_p
= resize_mini_window (w
, 0);
7944 /* Use the starting position chosen by resize_mini_window. */
7945 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
7948 clear_glyph_matrix (w
->desired_matrix
);
7949 XSETWINDOW (window
, w
);
7950 try_window (window
, start
, 0);
7952 return window_height_changed_p
;
7956 /* Resize the echo area window to exactly the size needed for the
7957 currently displayed message, if there is one. If a mini-buffer
7958 is active, don't shrink it. */
7961 resize_echo_area_exactly ()
7963 if (BUFFERP (echo_area_buffer
[0])
7964 && WINDOWP (echo_area_window
))
7966 struct window
*w
= XWINDOW (echo_area_window
);
7968 Lisp_Object resize_exactly
;
7970 if (minibuf_level
== 0)
7971 resize_exactly
= Qt
;
7973 resize_exactly
= Qnil
;
7975 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
7976 (EMACS_INT
) w
, resize_exactly
, 0, 0);
7979 ++windows_or_buffers_changed
;
7980 ++update_mode_lines
;
7981 redisplay_internal (0);
7987 /* Callback function for with_echo_area_buffer, when used from
7988 resize_echo_area_exactly. A1 contains a pointer to the window to
7989 resize, EXACTLY non-nil means resize the mini-window exactly to the
7990 size of the text displayed. A3 and A4 are not used. Value is what
7991 resize_mini_window returns. */
7994 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
7996 Lisp_Object exactly
;
7999 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8003 /* Resize mini-window W to fit the size of its contents. EXACT:P
8004 means size the window exactly to the size needed. Otherwise, it's
8005 only enlarged until W's buffer is empty.
8007 Set W->start to the right place to begin display. If the whole
8008 contents fit, start at the beginning. Otherwise, start so as
8009 to make the end of the contents appear. This is particularly
8010 important for y-or-n-p, but seems desirable generally.
8012 Value is non-zero if the window height has been changed. */
8015 resize_mini_window (w
, exact_p
)
8019 struct frame
*f
= XFRAME (w
->frame
);
8020 int window_height_changed_p
= 0;
8022 xassert (MINI_WINDOW_P (w
));
8024 /* By default, start display at the beginning. */
8025 set_marker_both (w
->start
, w
->buffer
,
8026 BUF_BEGV (XBUFFER (w
->buffer
)),
8027 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8029 /* Don't resize windows while redisplaying a window; it would
8030 confuse redisplay functions when the size of the window they are
8031 displaying changes from under them. Such a resizing can happen,
8032 for instance, when which-func prints a long message while
8033 we are running fontification-functions. We're running these
8034 functions with safe_call which binds inhibit-redisplay to t. */
8035 if (!NILP (Vinhibit_redisplay
))
8038 /* Nil means don't try to resize. */
8039 if (NILP (Vresize_mini_windows
)
8040 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8043 if (!FRAME_MINIBUF_ONLY_P (f
))
8046 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8047 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8048 int height
, max_height
;
8049 int unit
= FRAME_LINE_HEIGHT (f
);
8050 struct text_pos start
;
8051 struct buffer
*old_current_buffer
= NULL
;
8053 if (current_buffer
!= XBUFFER (w
->buffer
))
8055 old_current_buffer
= current_buffer
;
8056 set_buffer_internal (XBUFFER (w
->buffer
));
8059 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8061 /* Compute the max. number of lines specified by the user. */
8062 if (FLOATP (Vmax_mini_window_height
))
8063 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8064 else if (INTEGERP (Vmax_mini_window_height
))
8065 max_height
= XINT (Vmax_mini_window_height
);
8067 max_height
= total_height
/ 4;
8069 /* Correct that max. height if it's bogus. */
8070 max_height
= max (1, max_height
);
8071 max_height
= min (total_height
, max_height
);
8073 /* Find out the height of the text in the window. */
8074 if (it
.truncate_lines_p
)
8079 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8080 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8081 height
= it
.current_y
+ last_height
;
8083 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8084 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8085 height
= (height
+ unit
- 1) / unit
;
8088 /* Compute a suitable window start. */
8089 if (height
> max_height
)
8091 height
= max_height
;
8092 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8093 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8094 start
= it
.current
.pos
;
8097 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8098 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8100 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8102 /* Let it grow only, until we display an empty message, in which
8103 case the window shrinks again. */
8104 if (height
> WINDOW_TOTAL_LINES (w
))
8106 int old_height
= WINDOW_TOTAL_LINES (w
);
8107 freeze_window_starts (f
, 1);
8108 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8109 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8111 else if (height
< WINDOW_TOTAL_LINES (w
)
8112 && (exact_p
|| BEGV
== ZV
))
8114 int old_height
= WINDOW_TOTAL_LINES (w
);
8115 freeze_window_starts (f
, 0);
8116 shrink_mini_window (w
);
8117 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8122 /* Always resize to exact size needed. */
8123 if (height
> WINDOW_TOTAL_LINES (w
))
8125 int old_height
= WINDOW_TOTAL_LINES (w
);
8126 freeze_window_starts (f
, 1);
8127 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8128 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8130 else if (height
< WINDOW_TOTAL_LINES (w
))
8132 int old_height
= WINDOW_TOTAL_LINES (w
);
8133 freeze_window_starts (f
, 0);
8134 shrink_mini_window (w
);
8138 freeze_window_starts (f
, 1);
8139 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8142 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8146 if (old_current_buffer
)
8147 set_buffer_internal (old_current_buffer
);
8150 return window_height_changed_p
;
8154 /* Value is the current message, a string, or nil if there is no
8162 if (NILP (echo_area_buffer
[0]))
8166 with_echo_area_buffer (0, 0, current_message_1
,
8167 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8169 echo_area_buffer
[0] = Qnil
;
8177 current_message_1 (a1
, a2
, a3
, a4
)
8182 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8185 *msg
= make_buffer_string (BEG
, Z
, 1);
8192 /* Push the current message on Vmessage_stack for later restauration
8193 by restore_message. Value is non-zero if the current message isn't
8194 empty. This is a relatively infrequent operation, so it's not
8195 worth optimizing. */
8201 msg
= current_message ();
8202 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8203 return STRINGP (msg
);
8207 /* Restore message display from the top of Vmessage_stack. */
8214 xassert (CONSP (Vmessage_stack
));
8215 msg
= XCAR (Vmessage_stack
);
8217 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8219 message3_nolog (msg
, 0, 0);
8223 /* Handler for record_unwind_protect calling pop_message. */
8226 pop_message_unwind (dummy
)
8233 /* Pop the top-most entry off Vmessage_stack. */
8238 xassert (CONSP (Vmessage_stack
));
8239 Vmessage_stack
= XCDR (Vmessage_stack
);
8243 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8244 exits. If the stack is not empty, we have a missing pop_message
8248 check_message_stack ()
8250 if (!NILP (Vmessage_stack
))
8255 /* Truncate to NCHARS what will be displayed in the echo area the next
8256 time we display it---but don't redisplay it now. */
8259 truncate_echo_area (nchars
)
8263 echo_area_buffer
[0] = Qnil
;
8264 /* A null message buffer means that the frame hasn't really been
8265 initialized yet. Error messages get reported properly by
8266 cmd_error, so this must be just an informative message; toss it. */
8267 else if (!noninteractive
8269 && !NILP (echo_area_buffer
[0]))
8271 struct frame
*sf
= SELECTED_FRAME ();
8272 if (FRAME_MESSAGE_BUF (sf
))
8273 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8278 /* Helper function for truncate_echo_area. Truncate the current
8279 message to at most NCHARS characters. */
8282 truncate_message_1 (nchars
, a2
, a3
, a4
)
8287 if (BEG
+ nchars
< Z
)
8288 del_range (BEG
+ nchars
, Z
);
8290 echo_area_buffer
[0] = Qnil
;
8295 /* Set the current message to a substring of S or STRING.
8297 If STRING is a Lisp string, set the message to the first NBYTES
8298 bytes from STRING. NBYTES zero means use the whole string. If
8299 STRING is multibyte, the message will be displayed multibyte.
8301 If S is not null, set the message to the first LEN bytes of S. LEN
8302 zero means use the whole string. MULTIBYTE_P non-zero means S is
8303 multibyte. Display the message multibyte in that case.
8305 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8306 to t before calling set_message_1 (which calls insert).
8310 set_message (s
, string
, nbytes
, multibyte_p
)
8313 int nbytes
, multibyte_p
;
8315 message_enable_multibyte
8316 = ((s
&& multibyte_p
)
8317 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8319 with_echo_area_buffer (0, 0, set_message_1
,
8320 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8321 message_buf_print
= 0;
8322 help_echo_showing_p
= 0;
8326 /* Helper function for set_message. Arguments have the same meaning
8327 as there, with A1 corresponding to S and A2 corresponding to STRING
8328 This function is called with the echo area buffer being
8332 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8335 EMACS_INT nbytes
, multibyte_p
;
8337 const char *s
= (const char *) a1
;
8338 Lisp_Object string
= a2
;
8340 /* Change multibyteness of the echo buffer appropriately. */
8341 if (message_enable_multibyte
8342 != !NILP (current_buffer
->enable_multibyte_characters
))
8343 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8345 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8347 /* Insert new message at BEG. */
8348 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8351 if (STRINGP (string
))
8356 nbytes
= SBYTES (string
);
8357 nchars
= string_byte_to_char (string
, nbytes
);
8359 /* This function takes care of single/multibyte conversion. We
8360 just have to ensure that the echo area buffer has the right
8361 setting of enable_multibyte_characters. */
8362 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8367 nbytes
= strlen (s
);
8369 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8371 /* Convert from multi-byte to single-byte. */
8373 unsigned char work
[1];
8375 /* Convert a multibyte string to single-byte. */
8376 for (i
= 0; i
< nbytes
; i
+= n
)
8378 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8379 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
8381 : multibyte_char_to_unibyte (c
, Qnil
));
8382 insert_1_both (work
, 1, 1, 1, 0, 0);
8385 else if (!multibyte_p
8386 && !NILP (current_buffer
->enable_multibyte_characters
))
8388 /* Convert from single-byte to multi-byte. */
8390 const unsigned char *msg
= (const unsigned char *) s
;
8391 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8393 /* Convert a single-byte string to multibyte. */
8394 for (i
= 0; i
< nbytes
; i
++)
8396 c
= unibyte_char_to_multibyte (msg
[i
]);
8397 n
= CHAR_STRING (c
, str
);
8398 insert_1_both (str
, 1, n
, 1, 0, 0);
8402 insert_1 (s
, nbytes
, 1, 0, 0);
8409 /* Clear messages. CURRENT_P non-zero means clear the current
8410 message. LAST_DISPLAYED_P non-zero means clear the message
8414 clear_message (current_p
, last_displayed_p
)
8415 int current_p
, last_displayed_p
;
8419 echo_area_buffer
[0] = Qnil
;
8420 message_cleared_p
= 1;
8423 if (last_displayed_p
)
8424 echo_area_buffer
[1] = Qnil
;
8426 message_buf_print
= 0;
8429 /* Clear garbaged frames.
8431 This function is used where the old redisplay called
8432 redraw_garbaged_frames which in turn called redraw_frame which in
8433 turn called clear_frame. The call to clear_frame was a source of
8434 flickering. I believe a clear_frame is not necessary. It should
8435 suffice in the new redisplay to invalidate all current matrices,
8436 and ensure a complete redisplay of all windows. */
8439 clear_garbaged_frames ()
8443 Lisp_Object tail
, frame
;
8444 int changed_count
= 0;
8446 FOR_EACH_FRAME (tail
, frame
)
8448 struct frame
*f
= XFRAME (frame
);
8450 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8454 Fredraw_frame (frame
);
8455 f
->force_flush_display_p
= 1;
8457 clear_current_matrices (f
);
8466 ++windows_or_buffers_changed
;
8471 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8472 is non-zero update selected_frame. Value is non-zero if the
8473 mini-windows height has been changed. */
8476 echo_area_display (update_frame_p
)
8479 Lisp_Object mini_window
;
8482 int window_height_changed_p
= 0;
8483 struct frame
*sf
= SELECTED_FRAME ();
8485 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8486 w
= XWINDOW (mini_window
);
8487 f
= XFRAME (WINDOW_FRAME (w
));
8489 /* Don't display if frame is invisible or not yet initialized. */
8490 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8493 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8495 #ifdef HAVE_WINDOW_SYSTEM
8496 /* When Emacs starts, selected_frame may be a visible terminal
8497 frame, even if we run under a window system. If we let this
8498 through, a message would be displayed on the terminal. */
8499 if (EQ (selected_frame
, Vterminal_frame
)
8500 && !NILP (Vwindow_system
))
8502 #endif /* HAVE_WINDOW_SYSTEM */
8505 /* Redraw garbaged frames. */
8507 clear_garbaged_frames ();
8509 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8511 echo_area_window
= mini_window
;
8512 window_height_changed_p
= display_echo_area (w
);
8513 w
->must_be_updated_p
= 1;
8515 /* Update the display, unless called from redisplay_internal.
8516 Also don't update the screen during redisplay itself. The
8517 update will happen at the end of redisplay, and an update
8518 here could cause confusion. */
8519 if (update_frame_p
&& !redisplaying_p
)
8523 /* If the display update has been interrupted by pending
8524 input, update mode lines in the frame. Due to the
8525 pending input, it might have been that redisplay hasn't
8526 been called, so that mode lines above the echo area are
8527 garbaged. This looks odd, so we prevent it here. */
8528 if (!display_completed
)
8529 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8531 if (window_height_changed_p
8532 /* Don't do this if Emacs is shutting down. Redisplay
8533 needs to run hooks. */
8534 && !NILP (Vrun_hooks
))
8536 /* Must update other windows. Likewise as in other
8537 cases, don't let this update be interrupted by
8539 int count
= SPECPDL_INDEX ();
8540 specbind (Qredisplay_dont_pause
, Qt
);
8541 windows_or_buffers_changed
= 1;
8542 redisplay_internal (0);
8543 unbind_to (count
, Qnil
);
8545 else if (FRAME_WINDOW_P (f
) && n
== 0)
8547 /* Window configuration is the same as before.
8548 Can do with a display update of the echo area,
8549 unless we displayed some mode lines. */
8550 update_single_window (w
, 1);
8551 rif
->flush_display (f
);
8554 update_frame (f
, 1, 1);
8556 /* If cursor is in the echo area, make sure that the next
8557 redisplay displays the minibuffer, so that the cursor will
8558 be replaced with what the minibuffer wants. */
8559 if (cursor_in_echo_area
)
8560 ++windows_or_buffers_changed
;
8563 else if (!EQ (mini_window
, selected_window
))
8564 windows_or_buffers_changed
++;
8566 /* The current message is now also the last one displayed. */
8567 echo_area_buffer
[1] = echo_area_buffer
[0];
8569 /* Prevent redisplay optimization in redisplay_internal by resetting
8570 this_line_start_pos. This is done because the mini-buffer now
8571 displays the message instead of its buffer text. */
8572 if (EQ (mini_window
, selected_window
))
8573 CHARPOS (this_line_start_pos
) = 0;
8575 return window_height_changed_p
;
8580 /***********************************************************************
8581 Mode Lines and Frame Titles
8582 ***********************************************************************/
8584 /* A buffer for constructing non-propertized mode-line strings and
8585 frame titles in it; allocated from the heap in init_xdisp and
8586 resized as needed in store_mode_line_noprop_char. */
8588 static char *mode_line_noprop_buf
;
8590 /* The buffer's end, and a current output position in it. */
8592 static char *mode_line_noprop_buf_end
;
8593 static char *mode_line_noprop_ptr
;
8595 #define MODE_LINE_NOPROP_LEN(start) \
8596 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8599 MODE_LINE_DISPLAY
= 0,
8605 /* Alist that caches the results of :propertize.
8606 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8607 static Lisp_Object mode_line_proptrans_alist
;
8609 /* List of strings making up the mode-line. */
8610 static Lisp_Object mode_line_string_list
;
8612 /* Base face property when building propertized mode line string. */
8613 static Lisp_Object mode_line_string_face
;
8614 static Lisp_Object mode_line_string_face_prop
;
8617 /* Unwind data for mode line strings */
8619 static Lisp_Object Vmode_line_unwind_vector
;
8622 format_mode_line_unwind_data (obuf
, save_proptrans
)
8623 struct buffer
*obuf
;
8627 /* Reduce consing by keeping one vector in
8628 Vwith_echo_area_save_vector. */
8629 vector
= Vmode_line_unwind_vector
;
8630 Vmode_line_unwind_vector
= Qnil
;
8633 vector
= Fmake_vector (make_number (7), Qnil
);
8635 AREF (vector
, 0) = make_number (mode_line_target
);
8636 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8637 AREF (vector
, 2) = mode_line_string_list
;
8638 AREF (vector
, 3) = (save_proptrans
? mode_line_proptrans_alist
: Qt
);
8639 AREF (vector
, 4) = mode_line_string_face
;
8640 AREF (vector
, 5) = mode_line_string_face_prop
;
8643 XSETBUFFER (AREF (vector
, 6), obuf
);
8645 AREF (vector
, 6) = Qnil
;
8651 unwind_format_mode_line (vector
)
8654 mode_line_target
= XINT (AREF (vector
, 0));
8655 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8656 mode_line_string_list
= AREF (vector
, 2);
8657 if (! EQ (AREF (vector
, 3), Qt
))
8658 mode_line_proptrans_alist
= AREF (vector
, 3);
8659 mode_line_string_face
= AREF (vector
, 4);
8660 mode_line_string_face_prop
= AREF (vector
, 5);
8662 if (!NILP (AREF (vector
, 6)))
8664 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8665 AREF (vector
, 6) = Qnil
;
8668 Vmode_line_unwind_vector
= vector
;
8673 /* Store a single character C for the frame title in mode_line_noprop_buf.
8674 Re-allocate mode_line_noprop_buf if necessary. */
8678 store_mode_line_noprop_char (char c
)
8680 store_mode_line_noprop_char (c
)
8684 /* If output position has reached the end of the allocated buffer,
8685 double the buffer's size. */
8686 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8688 int len
= MODE_LINE_NOPROP_LEN (0);
8689 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8690 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8691 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8692 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8695 *mode_line_noprop_ptr
++ = c
;
8699 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8700 mode_line_noprop_ptr. STR is the string to store. Do not copy
8701 characters that yield more columns than PRECISION; PRECISION <= 0
8702 means copy the whole string. Pad with spaces until FIELD_WIDTH
8703 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8704 pad. Called from display_mode_element when it is used to build a
8708 store_mode_line_noprop (str
, field_width
, precision
)
8709 const unsigned char *str
;
8710 int field_width
, precision
;
8715 /* Copy at most PRECISION chars from STR. */
8716 nbytes
= strlen (str
);
8717 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8719 store_mode_line_noprop_char (*str
++);
8721 /* Fill up with spaces until FIELD_WIDTH reached. */
8722 while (field_width
> 0
8725 store_mode_line_noprop_char (' ');
8732 /***********************************************************************
8734 ***********************************************************************/
8736 #ifdef HAVE_WINDOW_SYSTEM
8738 /* Set the title of FRAME, if it has changed. The title format is
8739 Vicon_title_format if FRAME is iconified, otherwise it is
8740 frame_title_format. */
8743 x_consider_frame_title (frame
)
8746 struct frame
*f
= XFRAME (frame
);
8748 if (FRAME_WINDOW_P (f
)
8749 || FRAME_MINIBUF_ONLY_P (f
)
8750 || f
->explicit_name
)
8752 /* Do we have more than one visible frame on this X display? */
8759 int count
= SPECPDL_INDEX ();
8761 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8763 Lisp_Object other_frame
= XCAR (tail
);
8764 struct frame
*tf
= XFRAME (other_frame
);
8767 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8768 && !FRAME_MINIBUF_ONLY_P (tf
)
8769 && !EQ (other_frame
, tip_frame
)
8770 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8774 /* Set global variable indicating that multiple frames exist. */
8775 multiple_frames
= CONSP (tail
);
8777 /* Switch to the buffer of selected window of the frame. Set up
8778 mode_line_target so that display_mode_element will output into
8779 mode_line_noprop_buf; then display the title. */
8780 record_unwind_protect (unwind_format_mode_line
,
8781 format_mode_line_unwind_data (current_buffer
, 0));
8783 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8784 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8786 mode_line_target
= MODE_LINE_TITLE
;
8787 title_start
= MODE_LINE_NOPROP_LEN (0);
8788 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8789 NULL
, DEFAULT_FACE_ID
);
8790 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8791 len
= MODE_LINE_NOPROP_LEN (title_start
);
8792 title
= mode_line_noprop_buf
+ title_start
;
8793 unbind_to (count
, Qnil
);
8795 /* Set the title only if it's changed. This avoids consing in
8796 the common case where it hasn't. (If it turns out that we've
8797 already wasted too much time by walking through the list with
8798 display_mode_element, then we might need to optimize at a
8799 higher level than this.) */
8800 if (! STRINGP (f
->name
)
8801 || SBYTES (f
->name
) != len
8802 || bcmp (title
, SDATA (f
->name
), len
) != 0)
8803 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
8807 #endif /* not HAVE_WINDOW_SYSTEM */
8812 /***********************************************************************
8814 ***********************************************************************/
8817 /* Prepare for redisplay by updating menu-bar item lists when
8818 appropriate. This can call eval. */
8821 prepare_menu_bars ()
8824 struct gcpro gcpro1
, gcpro2
;
8826 Lisp_Object tooltip_frame
;
8828 #ifdef HAVE_WINDOW_SYSTEM
8829 tooltip_frame
= tip_frame
;
8831 tooltip_frame
= Qnil
;
8834 /* Update all frame titles based on their buffer names, etc. We do
8835 this before the menu bars so that the buffer-menu will show the
8836 up-to-date frame titles. */
8837 #ifdef HAVE_WINDOW_SYSTEM
8838 if (windows_or_buffers_changed
|| update_mode_lines
)
8840 Lisp_Object tail
, frame
;
8842 FOR_EACH_FRAME (tail
, frame
)
8845 if (!EQ (frame
, tooltip_frame
)
8846 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8847 x_consider_frame_title (frame
);
8850 #endif /* HAVE_WINDOW_SYSTEM */
8852 /* Update the menu bar item lists, if appropriate. This has to be
8853 done before any actual redisplay or generation of display lines. */
8854 all_windows
= (update_mode_lines
8855 || buffer_shared
> 1
8856 || windows_or_buffers_changed
);
8859 Lisp_Object tail
, frame
;
8860 int count
= SPECPDL_INDEX ();
8862 record_unwind_save_match_data ();
8864 FOR_EACH_FRAME (tail
, frame
)
8868 /* Ignore tooltip frame. */
8869 if (EQ (frame
, tooltip_frame
))
8872 /* If a window on this frame changed size, report that to
8873 the user and clear the size-change flag. */
8874 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8876 Lisp_Object functions
;
8878 /* Clear flag first in case we get an error below. */
8879 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8880 functions
= Vwindow_size_change_functions
;
8881 GCPRO2 (tail
, functions
);
8883 while (CONSP (functions
))
8885 call1 (XCAR (functions
), frame
);
8886 functions
= XCDR (functions
);
8892 update_menu_bar (f
, 0);
8893 #ifdef HAVE_WINDOW_SYSTEM
8894 update_tool_bar (f
, 0);
8899 unbind_to (count
, Qnil
);
8903 struct frame
*sf
= SELECTED_FRAME ();
8904 update_menu_bar (sf
, 1);
8905 #ifdef HAVE_WINDOW_SYSTEM
8906 update_tool_bar (sf
, 1);
8910 /* Motif needs this. See comment in xmenu.c. Turn it off when
8911 pending_menu_activation is not defined. */
8912 #ifdef USE_X_TOOLKIT
8913 pending_menu_activation
= 0;
8918 /* Update the menu bar item list for frame F. This has to be done
8919 before we start to fill in any display lines, because it can call
8922 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8925 update_menu_bar (f
, save_match_data
)
8927 int save_match_data
;
8930 register struct window
*w
;
8932 /* If called recursively during a menu update, do nothing. This can
8933 happen when, for instance, an activate-menubar-hook causes a
8935 if (inhibit_menubar_update
)
8938 window
= FRAME_SELECTED_WINDOW (f
);
8939 w
= XWINDOW (window
);
8941 #if 0 /* The if statement below this if statement used to include the
8942 condition !NILP (w->update_mode_line), rather than using
8943 update_mode_lines directly, and this if statement may have
8944 been added to make that condition work. Now the if
8945 statement below matches its comment, this isn't needed. */
8946 if (update_mode_lines
)
8947 w
->update_mode_line
= Qt
;
8950 if (FRAME_WINDOW_P (f
)
8952 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8953 || defined (USE_GTK)
8954 FRAME_EXTERNAL_MENU_BAR (f
)
8956 FRAME_MENU_BAR_LINES (f
) > 0
8958 : FRAME_MENU_BAR_LINES (f
) > 0)
8960 /* If the user has switched buffers or windows, we need to
8961 recompute to reflect the new bindings. But we'll
8962 recompute when update_mode_lines is set too; that means
8963 that people can use force-mode-line-update to request
8964 that the menu bar be recomputed. The adverse effect on
8965 the rest of the redisplay algorithm is about the same as
8966 windows_or_buffers_changed anyway. */
8967 if (windows_or_buffers_changed
8968 /* This used to test w->update_mode_line, but we believe
8969 there is no need to recompute the menu in that case. */
8970 || update_mode_lines
8971 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8972 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8973 != !NILP (w
->last_had_star
))
8974 || ((!NILP (Vtransient_mark_mode
)
8975 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8976 != !NILP (w
->region_showing
)))
8978 struct buffer
*prev
= current_buffer
;
8979 int count
= SPECPDL_INDEX ();
8981 specbind (Qinhibit_menubar_update
, Qt
);
8983 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8984 if (save_match_data
)
8985 record_unwind_save_match_data ();
8986 if (NILP (Voverriding_local_map_menu_flag
))
8988 specbind (Qoverriding_terminal_local_map
, Qnil
);
8989 specbind (Qoverriding_local_map
, Qnil
);
8992 /* Run the Lucid hook. */
8993 safe_run_hooks (Qactivate_menubar_hook
);
8995 /* If it has changed current-menubar from previous value,
8996 really recompute the menu-bar from the value. */
8997 if (! NILP (Vlucid_menu_bar_dirty_flag
))
8998 call0 (Qrecompute_lucid_menubar
);
9000 safe_run_hooks (Qmenu_bar_update_hook
);
9001 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9003 /* Redisplay the menu bar in case we changed it. */
9004 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9005 || defined (USE_GTK)
9006 if (FRAME_WINDOW_P (f
)
9007 #if defined (MAC_OS)
9008 /* All frames on Mac OS share the same menubar. So only the
9009 selected frame should be allowed to set it. */
9010 && f
== SELECTED_FRAME ()
9013 set_frame_menubar (f
, 0, 0);
9015 /* On a terminal screen, the menu bar is an ordinary screen
9016 line, and this makes it get updated. */
9017 w
->update_mode_line
= Qt
;
9018 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9019 /* In the non-toolkit version, the menu bar is an ordinary screen
9020 line, and this makes it get updated. */
9021 w
->update_mode_line
= Qt
;
9022 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9024 unbind_to (count
, Qnil
);
9025 set_buffer_internal_1 (prev
);
9032 /***********************************************************************
9034 ***********************************************************************/
9036 #ifdef HAVE_WINDOW_SYSTEM
9039 Nominal cursor position -- where to draw output.
9040 HPOS and VPOS are window relative glyph matrix coordinates.
9041 X and Y are window relative pixel coordinates. */
9043 struct cursor_pos output_cursor
;
9047 Set the global variable output_cursor to CURSOR. All cursor
9048 positions are relative to updated_window. */
9051 set_output_cursor (cursor
)
9052 struct cursor_pos
*cursor
;
9054 output_cursor
.hpos
= cursor
->hpos
;
9055 output_cursor
.vpos
= cursor
->vpos
;
9056 output_cursor
.x
= cursor
->x
;
9057 output_cursor
.y
= cursor
->y
;
9062 Set a nominal cursor position.
9064 HPOS and VPOS are column/row positions in a window glyph matrix. X
9065 and Y are window text area relative pixel positions.
9067 If this is done during an update, updated_window will contain the
9068 window that is being updated and the position is the future output
9069 cursor position for that window. If updated_window is null, use
9070 selected_window and display the cursor at the given position. */
9073 x_cursor_to (vpos
, hpos
, y
, x
)
9074 int vpos
, hpos
, y
, x
;
9078 /* If updated_window is not set, work on selected_window. */
9082 w
= XWINDOW (selected_window
);
9084 /* Set the output cursor. */
9085 output_cursor
.hpos
= hpos
;
9086 output_cursor
.vpos
= vpos
;
9087 output_cursor
.x
= x
;
9088 output_cursor
.y
= y
;
9090 /* If not called as part of an update, really display the cursor.
9091 This will also set the cursor position of W. */
9092 if (updated_window
== NULL
)
9095 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9096 if (rif
->flush_display_optional
)
9097 rif
->flush_display_optional (SELECTED_FRAME ());
9102 #endif /* HAVE_WINDOW_SYSTEM */
9105 /***********************************************************************
9107 ***********************************************************************/
9109 #ifdef HAVE_WINDOW_SYSTEM
9111 /* Where the mouse was last time we reported a mouse event. */
9113 FRAME_PTR last_mouse_frame
;
9115 /* Tool-bar item index of the item on which a mouse button was pressed
9118 int last_tool_bar_item
;
9121 /* Update the tool-bar item list for frame F. This has to be done
9122 before we start to fill in any display lines. Called from
9123 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9124 and restore it here. */
9127 update_tool_bar (f
, save_match_data
)
9129 int save_match_data
;
9132 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9134 int do_update
= WINDOWP (f
->tool_bar_window
)
9135 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9143 window
= FRAME_SELECTED_WINDOW (f
);
9144 w
= XWINDOW (window
);
9146 /* If the user has switched buffers or windows, we need to
9147 recompute to reflect the new bindings. But we'll
9148 recompute when update_mode_lines is set too; that means
9149 that people can use force-mode-line-update to request
9150 that the menu bar be recomputed. The adverse effect on
9151 the rest of the redisplay algorithm is about the same as
9152 windows_or_buffers_changed anyway. */
9153 if (windows_or_buffers_changed
9154 || !NILP (w
->update_mode_line
)
9155 || update_mode_lines
9156 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9157 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9158 != !NILP (w
->last_had_star
))
9159 || ((!NILP (Vtransient_mark_mode
)
9160 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9161 != !NILP (w
->region_showing
)))
9163 struct buffer
*prev
= current_buffer
;
9164 int count
= SPECPDL_INDEX ();
9165 Lisp_Object new_tool_bar
;
9167 struct gcpro gcpro1
;
9169 /* Set current_buffer to the buffer of the selected
9170 window of the frame, so that we get the right local
9172 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9174 /* Save match data, if we must. */
9175 if (save_match_data
)
9176 record_unwind_save_match_data ();
9178 /* Make sure that we don't accidentally use bogus keymaps. */
9179 if (NILP (Voverriding_local_map_menu_flag
))
9181 specbind (Qoverriding_terminal_local_map
, Qnil
);
9182 specbind (Qoverriding_local_map
, Qnil
);
9185 GCPRO1 (new_tool_bar
);
9187 /* Build desired tool-bar items from keymaps. */
9188 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9191 /* Redisplay the tool-bar if we changed it. */
9192 if (NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9194 /* Redisplay that happens asynchronously due to an expose event
9195 may access f->tool_bar_items. Make sure we update both
9196 variables within BLOCK_INPUT so no such event interrupts. */
9198 f
->tool_bar_items
= new_tool_bar
;
9199 f
->n_tool_bar_items
= new_n_tool_bar
;
9200 w
->update_mode_line
= Qt
;
9206 unbind_to (count
, Qnil
);
9207 set_buffer_internal_1 (prev
);
9213 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9214 F's desired tool-bar contents. F->tool_bar_items must have
9215 been set up previously by calling prepare_menu_bars. */
9218 build_desired_tool_bar_string (f
)
9221 int i
, size
, size_needed
;
9222 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9223 Lisp_Object image
, plist
, props
;
9225 image
= plist
= props
= Qnil
;
9226 GCPRO3 (image
, plist
, props
);
9228 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9229 Otherwise, make a new string. */
9231 /* The size of the string we might be able to reuse. */
9232 size
= (STRINGP (f
->desired_tool_bar_string
)
9233 ? SCHARS (f
->desired_tool_bar_string
)
9236 /* We need one space in the string for each image. */
9237 size_needed
= f
->n_tool_bar_items
;
9239 /* Reuse f->desired_tool_bar_string, if possible. */
9240 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9241 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9245 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9246 Fremove_text_properties (make_number (0), make_number (size
),
9247 props
, f
->desired_tool_bar_string
);
9250 /* Put a `display' property on the string for the images to display,
9251 put a `menu_item' property on tool-bar items with a value that
9252 is the index of the item in F's tool-bar item vector. */
9253 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9255 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9257 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9258 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9259 int hmargin
, vmargin
, relief
, idx
, end
;
9260 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9262 /* If image is a vector, choose the image according to the
9264 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9265 if (VECTORP (image
))
9269 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9270 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9273 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9274 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9276 xassert (ASIZE (image
) >= idx
);
9277 image
= AREF (image
, idx
);
9282 /* Ignore invalid image specifications. */
9283 if (!valid_image_p (image
))
9286 /* Display the tool-bar button pressed, or depressed. */
9287 plist
= Fcopy_sequence (XCDR (image
));
9289 /* Compute margin and relief to draw. */
9290 relief
= (tool_bar_button_relief
>= 0
9291 ? tool_bar_button_relief
9292 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9293 hmargin
= vmargin
= relief
;
9295 if (INTEGERP (Vtool_bar_button_margin
)
9296 && XINT (Vtool_bar_button_margin
) > 0)
9298 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9299 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9301 else if (CONSP (Vtool_bar_button_margin
))
9303 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9304 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9305 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9307 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9308 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9309 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9312 if (auto_raise_tool_bar_buttons_p
)
9314 /* Add a `:relief' property to the image spec if the item is
9318 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9325 /* If image is selected, display it pressed, i.e. with a
9326 negative relief. If it's not selected, display it with a
9328 plist
= Fplist_put (plist
, QCrelief
,
9330 ? make_number (-relief
)
9331 : make_number (relief
)));
9336 /* Put a margin around the image. */
9337 if (hmargin
|| vmargin
)
9339 if (hmargin
== vmargin
)
9340 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9342 plist
= Fplist_put (plist
, QCmargin
,
9343 Fcons (make_number (hmargin
),
9344 make_number (vmargin
)));
9347 /* If button is not enabled, and we don't have special images
9348 for the disabled state, make the image appear disabled by
9349 applying an appropriate algorithm to it. */
9350 if (!enabled_p
&& idx
< 0)
9351 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9353 /* Put a `display' text property on the string for the image to
9354 display. Put a `menu-item' property on the string that gives
9355 the start of this item's properties in the tool-bar items
9357 image
= Fcons (Qimage
, plist
);
9358 props
= list4 (Qdisplay
, image
,
9359 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9361 /* Let the last image hide all remaining spaces in the tool bar
9362 string. The string can be longer than needed when we reuse a
9364 if (i
+ 1 == f
->n_tool_bar_items
)
9365 end
= SCHARS (f
->desired_tool_bar_string
);
9368 Fadd_text_properties (make_number (i
), make_number (end
),
9369 props
, f
->desired_tool_bar_string
);
9377 /* Display one line of the tool-bar of frame IT->f. */
9380 display_tool_bar_line (it
)
9383 struct glyph_row
*row
= it
->glyph_row
;
9384 int max_x
= it
->last_visible_x
;
9387 prepare_desired_row (row
);
9388 row
->y
= it
->current_y
;
9390 /* Note that this isn't made use of if the face hasn't a box,
9391 so there's no need to check the face here. */
9392 it
->start_of_box_run_p
= 1;
9394 while (it
->current_x
< max_x
)
9396 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
9398 /* Get the next display element. */
9399 if (!get_next_display_element (it
))
9402 /* Produce glyphs. */
9403 x_before
= it
->current_x
;
9404 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
9405 PRODUCE_GLYPHS (it
);
9407 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
9412 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9414 if (x
+ glyph
->pixel_width
> max_x
)
9416 /* Glyph doesn't fit on line. */
9417 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
9423 x
+= glyph
->pixel_width
;
9427 /* Stop at line ends. */
9428 if (ITERATOR_AT_END_OF_LINE_P (it
))
9431 set_iterator_to_next (it
, 1);
9436 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9437 extend_face_to_end_of_line (it
);
9438 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9439 last
->right_box_line_p
= 1;
9440 if (last
== row
->glyphs
[TEXT_AREA
])
9441 last
->left_box_line_p
= 1;
9442 compute_line_metrics (it
);
9444 /* If line is empty, make it occupy the rest of the tool-bar. */
9445 if (!row
->displays_text_p
)
9447 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9448 row
->ascent
= row
->phys_ascent
= 0;
9449 row
->extra_line_spacing
= 0;
9452 row
->full_width_p
= 1;
9453 row
->continued_p
= 0;
9454 row
->truncated_on_left_p
= 0;
9455 row
->truncated_on_right_p
= 0;
9457 it
->current_x
= it
->hpos
= 0;
9458 it
->current_y
+= row
->height
;
9464 /* Value is the number of screen lines needed to make all tool-bar
9465 items of frame F visible. */
9468 tool_bar_lines_needed (f
)
9471 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9474 /* Initialize an iterator for iteration over
9475 F->desired_tool_bar_string in the tool-bar window of frame F. */
9476 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9477 it
.first_visible_x
= 0;
9478 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9479 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9481 while (!ITERATOR_AT_END_P (&it
))
9483 it
.glyph_row
= w
->desired_matrix
->rows
;
9484 clear_glyph_row (it
.glyph_row
);
9485 display_tool_bar_line (&it
);
9488 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9492 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9494 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9503 frame
= selected_frame
;
9505 CHECK_FRAME (frame
);
9508 if (WINDOWP (f
->tool_bar_window
)
9509 || (w
= XWINDOW (f
->tool_bar_window
),
9510 WINDOW_TOTAL_LINES (w
) > 0))
9512 update_tool_bar (f
, 1);
9513 if (f
->n_tool_bar_items
)
9515 build_desired_tool_bar_string (f
);
9516 nlines
= tool_bar_lines_needed (f
);
9520 return make_number (nlines
);
9524 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9525 height should be changed. */
9528 redisplay_tool_bar (f
)
9533 struct glyph_row
*row
;
9534 int change_height_p
= 0;
9537 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9538 update_frame_tool_bar (f
);
9542 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9543 do anything. This means you must start with tool-bar-lines
9544 non-zero to get the auto-sizing effect. Or in other words, you
9545 can turn off tool-bars by specifying tool-bar-lines zero. */
9546 if (!WINDOWP (f
->tool_bar_window
)
9547 || (w
= XWINDOW (f
->tool_bar_window
),
9548 WINDOW_TOTAL_LINES (w
) == 0))
9551 /* Set up an iterator for the tool-bar window. */
9552 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9553 it
.first_visible_x
= 0;
9554 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9557 /* Build a string that represents the contents of the tool-bar. */
9558 build_desired_tool_bar_string (f
);
9559 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9561 /* Display as many lines as needed to display all tool-bar items. */
9562 while (it
.current_y
< it
.last_visible_y
)
9563 display_tool_bar_line (&it
);
9565 /* It doesn't make much sense to try scrolling in the tool-bar
9566 window, so don't do it. */
9567 w
->desired_matrix
->no_scrolling_p
= 1;
9568 w
->must_be_updated_p
= 1;
9570 if (auto_resize_tool_bars_p
)
9574 /* If we couldn't display everything, change the tool-bar's
9576 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
9577 change_height_p
= 1;
9579 /* If there are blank lines at the end, except for a partially
9580 visible blank line at the end that is smaller than
9581 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9582 row
= it
.glyph_row
- 1;
9583 if (!row
->displays_text_p
9584 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9585 change_height_p
= 1;
9587 /* If row displays tool-bar items, but is partially visible,
9588 change the tool-bar's height. */
9589 if (row
->displays_text_p
9590 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
9591 change_height_p
= 1;
9593 /* Resize windows as needed by changing the `tool-bar-lines'
9596 && (nlines
= tool_bar_lines_needed (f
),
9597 nlines
!= WINDOW_TOTAL_LINES (w
)))
9599 extern Lisp_Object Qtool_bar_lines
;
9601 int old_height
= WINDOW_TOTAL_LINES (w
);
9603 XSETFRAME (frame
, f
);
9604 clear_glyph_matrix (w
->desired_matrix
);
9605 Fmodify_frame_parameters (frame
,
9606 Fcons (Fcons (Qtool_bar_lines
,
9607 make_number (nlines
)),
9609 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9610 fonts_changed_p
= 1;
9614 return change_height_p
;
9618 /* Get information about the tool-bar item which is displayed in GLYPH
9619 on frame F. Return in *PROP_IDX the index where tool-bar item
9620 properties start in F->tool_bar_items. Value is zero if
9621 GLYPH doesn't display a tool-bar item. */
9624 tool_bar_item_info (f
, glyph
, prop_idx
)
9626 struct glyph
*glyph
;
9633 /* This function can be called asynchronously, which means we must
9634 exclude any possibility that Fget_text_property signals an
9636 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
9637 charpos
= max (0, charpos
);
9639 /* Get the text property `menu-item' at pos. The value of that
9640 property is the start index of this item's properties in
9641 F->tool_bar_items. */
9642 prop
= Fget_text_property (make_number (charpos
),
9643 Qmenu_item
, f
->current_tool_bar_string
);
9644 if (INTEGERP (prop
))
9646 *prop_idx
= XINT (prop
);
9656 /* Get information about the tool-bar item at position X/Y on frame F.
9657 Return in *GLYPH a pointer to the glyph of the tool-bar item in
9658 the current matrix of the tool-bar window of F, or NULL if not
9659 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
9660 item in F->tool_bar_items. Value is
9662 -1 if X/Y is not on a tool-bar item
9663 0 if X/Y is on the same item that was highlighted before.
9667 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
9670 struct glyph
**glyph
;
9671 int *hpos
, *vpos
, *prop_idx
;
9673 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9674 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9677 /* Find the glyph under X/Y. */
9678 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
9682 /* Get the start of this tool-bar item's properties in
9683 f->tool_bar_items. */
9684 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
9687 /* Is mouse on the highlighted item? */
9688 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
9689 && *vpos
>= dpyinfo
->mouse_face_beg_row
9690 && *vpos
<= dpyinfo
->mouse_face_end_row
9691 && (*vpos
> dpyinfo
->mouse_face_beg_row
9692 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
9693 && (*vpos
< dpyinfo
->mouse_face_end_row
9694 || *hpos
< dpyinfo
->mouse_face_end_col
9695 || dpyinfo
->mouse_face_past_end
))
9703 Handle mouse button event on the tool-bar of frame F, at
9704 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
9705 0 for button release. MODIFIERS is event modifiers for button
9709 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
9712 unsigned int modifiers
;
9714 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9715 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9716 int hpos
, vpos
, prop_idx
;
9717 struct glyph
*glyph
;
9718 Lisp_Object enabled_p
;
9720 /* If not on the highlighted tool-bar item, return. */
9721 frame_to_window_pixel_xy (w
, &x
, &y
);
9722 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
9725 /* If item is disabled, do nothing. */
9726 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9727 if (NILP (enabled_p
))
9732 /* Show item in pressed state. */
9733 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
9734 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
9735 last_tool_bar_item
= prop_idx
;
9739 Lisp_Object key
, frame
;
9740 struct input_event event
;
9743 /* Show item in released state. */
9744 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
9745 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
9747 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
9749 XSETFRAME (frame
, f
);
9750 event
.kind
= TOOL_BAR_EVENT
;
9751 event
.frame_or_window
= frame
;
9753 kbd_buffer_store_event (&event
);
9755 event
.kind
= TOOL_BAR_EVENT
;
9756 event
.frame_or_window
= frame
;
9758 event
.modifiers
= modifiers
;
9759 kbd_buffer_store_event (&event
);
9760 last_tool_bar_item
= -1;
9765 /* Possibly highlight a tool-bar item on frame F when mouse moves to
9766 tool-bar window-relative coordinates X/Y. Called from
9767 note_mouse_highlight. */
9770 note_tool_bar_highlight (f
, x
, y
)
9774 Lisp_Object window
= f
->tool_bar_window
;
9775 struct window
*w
= XWINDOW (window
);
9776 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9778 struct glyph
*glyph
;
9779 struct glyph_row
*row
;
9781 Lisp_Object enabled_p
;
9783 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9784 int mouse_down_p
, rc
;
9786 /* Function note_mouse_highlight is called with negative x(y
9787 values when mouse moves outside of the frame. */
9788 if (x
<= 0 || y
<= 0)
9790 clear_mouse_face (dpyinfo
);
9794 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9797 /* Not on tool-bar item. */
9798 clear_mouse_face (dpyinfo
);
9802 /* On same tool-bar item as before. */
9805 clear_mouse_face (dpyinfo
);
9807 /* Mouse is down, but on different tool-bar item? */
9808 mouse_down_p
= (dpyinfo
->grabbed
9809 && f
== last_mouse_frame
9810 && FRAME_LIVE_P (f
));
9812 && last_tool_bar_item
!= prop_idx
)
9815 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9816 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9818 /* If tool-bar item is not enabled, don't highlight it. */
9819 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9820 if (!NILP (enabled_p
))
9822 /* Compute the x-position of the glyph. In front and past the
9823 image is a space. We include this in the highlighted area. */
9824 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
9825 for (i
= x
= 0; i
< hpos
; ++i
)
9826 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9828 /* Record this as the current active region. */
9829 dpyinfo
->mouse_face_beg_col
= hpos
;
9830 dpyinfo
->mouse_face_beg_row
= vpos
;
9831 dpyinfo
->mouse_face_beg_x
= x
;
9832 dpyinfo
->mouse_face_beg_y
= row
->y
;
9833 dpyinfo
->mouse_face_past_end
= 0;
9835 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9836 dpyinfo
->mouse_face_end_row
= vpos
;
9837 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9838 dpyinfo
->mouse_face_end_y
= row
->y
;
9839 dpyinfo
->mouse_face_window
= window
;
9840 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9842 /* Display it as active. */
9843 show_mouse_face (dpyinfo
, draw
);
9844 dpyinfo
->mouse_face_image_state
= draw
;
9849 /* Set help_echo_string to a help string to display for this tool-bar item.
9850 XTread_socket does the rest. */
9851 help_echo_object
= help_echo_window
= Qnil
;
9853 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9854 if (NILP (help_echo_string
))
9855 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9858 #endif /* HAVE_WINDOW_SYSTEM */
9862 /************************************************************************
9863 Horizontal scrolling
9864 ************************************************************************/
9866 static int hscroll_window_tree
P_ ((Lisp_Object
));
9867 static int hscroll_windows
P_ ((Lisp_Object
));
9869 /* For all leaf windows in the window tree rooted at WINDOW, set their
9870 hscroll value so that PT is (i) visible in the window, and (ii) so
9871 that it is not within a certain margin at the window's left and
9872 right border. Value is non-zero if any window's hscroll has been
9876 hscroll_window_tree (window
)
9879 int hscrolled_p
= 0;
9880 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9881 int hscroll_step_abs
= 0;
9882 double hscroll_step_rel
= 0;
9884 if (hscroll_relative_p
)
9886 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9887 if (hscroll_step_rel
< 0)
9889 hscroll_relative_p
= 0;
9890 hscroll_step_abs
= 0;
9893 else if (INTEGERP (Vhscroll_step
))
9895 hscroll_step_abs
= XINT (Vhscroll_step
);
9896 if (hscroll_step_abs
< 0)
9897 hscroll_step_abs
= 0;
9900 hscroll_step_abs
= 0;
9902 while (WINDOWP (window
))
9904 struct window
*w
= XWINDOW (window
);
9906 if (WINDOWP (w
->hchild
))
9907 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9908 else if (WINDOWP (w
->vchild
))
9909 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9910 else if (w
->cursor
.vpos
>= 0)
9913 int text_area_width
;
9914 struct glyph_row
*current_cursor_row
9915 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9916 struct glyph_row
*desired_cursor_row
9917 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9918 struct glyph_row
*cursor_row
9919 = (desired_cursor_row
->enabled_p
9920 ? desired_cursor_row
9921 : current_cursor_row
);
9923 text_area_width
= window_box_width (w
, TEXT_AREA
);
9925 /* Scroll when cursor is inside this scroll margin. */
9926 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9928 if ((XFASTINT (w
->hscroll
)
9929 && w
->cursor
.x
<= h_margin
)
9930 || (cursor_row
->enabled_p
9931 && cursor_row
->truncated_on_right_p
9932 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9936 struct buffer
*saved_current_buffer
;
9940 /* Find point in a display of infinite width. */
9941 saved_current_buffer
= current_buffer
;
9942 current_buffer
= XBUFFER (w
->buffer
);
9944 if (w
== XWINDOW (selected_window
))
9945 pt
= BUF_PT (current_buffer
);
9948 pt
= marker_position (w
->pointm
);
9949 pt
= max (BEGV
, pt
);
9953 /* Move iterator to pt starting at cursor_row->start in
9954 a line with infinite width. */
9955 init_to_row_start (&it
, w
, cursor_row
);
9956 it
.last_visible_x
= INFINITY
;
9957 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9958 current_buffer
= saved_current_buffer
;
9960 /* Position cursor in window. */
9961 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9962 hscroll
= max (0, (it
.current_x
9963 - (ITERATOR_AT_END_OF_LINE_P (&it
)
9964 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
9965 : (text_area_width
/ 2))))
9966 / FRAME_COLUMN_WIDTH (it
.f
);
9967 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9969 if (hscroll_relative_p
)
9970 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9973 wanted_x
= text_area_width
9974 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9977 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9981 if (hscroll_relative_p
)
9982 wanted_x
= text_area_width
* hscroll_step_rel
9985 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9988 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9990 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9992 /* Don't call Fset_window_hscroll if value hasn't
9993 changed because it will prevent redisplay
9995 if (XFASTINT (w
->hscroll
) != hscroll
)
9997 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9998 w
->hscroll
= make_number (hscroll
);
10007 /* Value is non-zero if hscroll of any leaf window has been changed. */
10008 return hscrolled_p
;
10012 /* Set hscroll so that cursor is visible and not inside horizontal
10013 scroll margins for all windows in the tree rooted at WINDOW. See
10014 also hscroll_window_tree above. Value is non-zero if any window's
10015 hscroll has been changed. If it has, desired matrices on the frame
10016 of WINDOW are cleared. */
10019 hscroll_windows (window
)
10020 Lisp_Object window
;
10024 if (automatic_hscrolling_p
)
10026 hscrolled_p
= hscroll_window_tree (window
);
10028 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10032 return hscrolled_p
;
10037 /************************************************************************
10039 ************************************************************************/
10041 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10042 to a non-zero value. This is sometimes handy to have in a debugger
10047 /* First and last unchanged row for try_window_id. */
10049 int debug_first_unchanged_at_end_vpos
;
10050 int debug_last_unchanged_at_beg_vpos
;
10052 /* Delta vpos and y. */
10054 int debug_dvpos
, debug_dy
;
10056 /* Delta in characters and bytes for try_window_id. */
10058 int debug_delta
, debug_delta_bytes
;
10060 /* Values of window_end_pos and window_end_vpos at the end of
10063 EMACS_INT debug_end_pos
, debug_end_vpos
;
10065 /* Append a string to W->desired_matrix->method. FMT is a printf
10066 format string. A1...A9 are a supplement for a variable-length
10067 argument list. If trace_redisplay_p is non-zero also printf the
10068 resulting string to stderr. */
10071 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10074 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10077 char *method
= w
->desired_matrix
->method
;
10078 int len
= strlen (method
);
10079 int size
= sizeof w
->desired_matrix
->method
;
10080 int remaining
= size
- len
- 1;
10082 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10083 if (len
&& remaining
)
10086 --remaining
, ++len
;
10089 strncpy (method
+ len
, buffer
, remaining
);
10091 if (trace_redisplay_p
)
10092 fprintf (stderr
, "%p (%s): %s\n",
10094 ((BUFFERP (w
->buffer
)
10095 && STRINGP (XBUFFER (w
->buffer
)->name
))
10096 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10101 #endif /* GLYPH_DEBUG */
10104 /* Value is non-zero if all changes in window W, which displays
10105 current_buffer, are in the text between START and END. START is a
10106 buffer position, END is given as a distance from Z. Used in
10107 redisplay_internal for display optimization. */
10110 text_outside_line_unchanged_p (w
, start
, end
)
10114 int unchanged_p
= 1;
10116 /* If text or overlays have changed, see where. */
10117 if (XFASTINT (w
->last_modified
) < MODIFF
10118 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10120 /* Gap in the line? */
10121 if (GPT
< start
|| Z
- GPT
< end
)
10124 /* Changes start in front of the line, or end after it? */
10126 && (BEG_UNCHANGED
< start
- 1
10127 || END_UNCHANGED
< end
))
10130 /* If selective display, can't optimize if changes start at the
10131 beginning of the line. */
10133 && INTEGERP (current_buffer
->selective_display
)
10134 && XINT (current_buffer
->selective_display
) > 0
10135 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10138 /* If there are overlays at the start or end of the line, these
10139 may have overlay strings with newlines in them. A change at
10140 START, for instance, may actually concern the display of such
10141 overlay strings as well, and they are displayed on different
10142 lines. So, quickly rule out this case. (For the future, it
10143 might be desirable to implement something more telling than
10144 just BEG/END_UNCHANGED.) */
10147 if (BEG
+ BEG_UNCHANGED
== start
10148 && overlay_touches_p (start
))
10150 if (END_UNCHANGED
== end
10151 && overlay_touches_p (Z
- end
))
10156 return unchanged_p
;
10160 /* Do a frame update, taking possible shortcuts into account. This is
10161 the main external entry point for redisplay.
10163 If the last redisplay displayed an echo area message and that message
10164 is no longer requested, we clear the echo area or bring back the
10165 mini-buffer if that is in use. */
10170 redisplay_internal (0);
10175 overlay_arrow_string_or_property (var
)
10180 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10183 return Voverlay_arrow_string
;
10186 /* Return 1 if there are any overlay-arrows in current_buffer. */
10188 overlay_arrow_in_current_buffer_p ()
10192 for (vlist
= Voverlay_arrow_variable_list
;
10194 vlist
= XCDR (vlist
))
10196 Lisp_Object var
= XCAR (vlist
);
10199 if (!SYMBOLP (var
))
10201 val
= find_symbol_value (var
);
10203 && current_buffer
== XMARKER (val
)->buffer
)
10210 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
10214 overlay_arrows_changed_p ()
10218 for (vlist
= Voverlay_arrow_variable_list
;
10220 vlist
= XCDR (vlist
))
10222 Lisp_Object var
= XCAR (vlist
);
10223 Lisp_Object val
, pstr
;
10225 if (!SYMBOLP (var
))
10227 val
= find_symbol_value (var
);
10228 if (!MARKERP (val
))
10230 if (! EQ (COERCE_MARKER (val
),
10231 Fget (var
, Qlast_arrow_position
))
10232 || ! (pstr
= overlay_arrow_string_or_property (var
),
10233 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
10239 /* Mark overlay arrows to be updated on next redisplay. */
10242 update_overlay_arrows (up_to_date
)
10247 for (vlist
= Voverlay_arrow_variable_list
;
10249 vlist
= XCDR (vlist
))
10251 Lisp_Object var
= XCAR (vlist
);
10253 if (!SYMBOLP (var
))
10256 if (up_to_date
> 0)
10258 Lisp_Object val
= find_symbol_value (var
);
10259 Fput (var
, Qlast_arrow_position
,
10260 COERCE_MARKER (val
));
10261 Fput (var
, Qlast_arrow_string
,
10262 overlay_arrow_string_or_property (var
));
10264 else if (up_to_date
< 0
10265 || !NILP (Fget (var
, Qlast_arrow_position
)))
10267 Fput (var
, Qlast_arrow_position
, Qt
);
10268 Fput (var
, Qlast_arrow_string
, Qt
);
10274 /* Return overlay arrow string to display at row.
10275 Return integer (bitmap number) for arrow bitmap in left fringe.
10276 Return nil if no overlay arrow. */
10279 overlay_arrow_at_row (it
, row
)
10281 struct glyph_row
*row
;
10285 for (vlist
= Voverlay_arrow_variable_list
;
10287 vlist
= XCDR (vlist
))
10289 Lisp_Object var
= XCAR (vlist
);
10292 if (!SYMBOLP (var
))
10295 val
= find_symbol_value (var
);
10298 && current_buffer
== XMARKER (val
)->buffer
10299 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10301 if (FRAME_WINDOW_P (it
->f
)
10302 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10304 #ifdef HAVE_WINDOW_SYSTEM
10305 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10308 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10309 return make_number (fringe_bitmap
);
10312 return make_number (-1); /* Use default arrow bitmap */
10314 return overlay_arrow_string_or_property (var
);
10321 /* Return 1 if point moved out of or into a composition. Otherwise
10322 return 0. PREV_BUF and PREV_PT are the last point buffer and
10323 position. BUF and PT are the current point buffer and position. */
10326 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10327 struct buffer
*prev_buf
, *buf
;
10332 Lisp_Object buffer
;
10334 XSETBUFFER (buffer
, buf
);
10335 /* Check a composition at the last point if point moved within the
10337 if (prev_buf
== buf
)
10340 /* Point didn't move. */
10343 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10344 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10345 && COMPOSITION_VALID_P (start
, end
, prop
)
10346 && start
< prev_pt
&& end
> prev_pt
)
10347 /* The last point was within the composition. Return 1 iff
10348 point moved out of the composition. */
10349 return (pt
<= start
|| pt
>= end
);
10352 /* Check a composition at the current point. */
10353 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10354 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10355 && COMPOSITION_VALID_P (start
, end
, prop
)
10356 && start
< pt
&& end
> pt
);
10360 /* Reconsider the setting of B->clip_changed which is displayed
10364 reconsider_clip_changes (w
, b
)
10368 if (b
->clip_changed
10369 && !NILP (w
->window_end_valid
)
10370 && w
->current_matrix
->buffer
== b
10371 && w
->current_matrix
->zv
== BUF_ZV (b
)
10372 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10373 b
->clip_changed
= 0;
10375 /* If display wasn't paused, and W is not a tool bar window, see if
10376 point has been moved into or out of a composition. In that case,
10377 we set b->clip_changed to 1 to force updating the screen. If
10378 b->clip_changed has already been set to 1, we can skip this
10380 if (!b
->clip_changed
10381 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10385 if (w
== XWINDOW (selected_window
))
10386 pt
= BUF_PT (current_buffer
);
10388 pt
= marker_position (w
->pointm
);
10390 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10391 || pt
!= XINT (w
->last_point
))
10392 && check_point_in_composition (w
->current_matrix
->buffer
,
10393 XINT (w
->last_point
),
10394 XBUFFER (w
->buffer
), pt
))
10395 b
->clip_changed
= 1;
10400 /* Select FRAME to forward the values of frame-local variables into C
10401 variables so that the redisplay routines can access those values
10405 select_frame_for_redisplay (frame
)
10408 Lisp_Object tail
, sym
, val
;
10409 Lisp_Object old
= selected_frame
;
10411 selected_frame
= frame
;
10413 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10414 if (CONSP (XCAR (tail
))
10415 && (sym
= XCAR (XCAR (tail
)),
10417 && (sym
= indirect_variable (sym
),
10418 val
= SYMBOL_VALUE (sym
),
10419 (BUFFER_LOCAL_VALUEP (val
)
10420 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10421 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10422 /* Use find_symbol_value rather than Fsymbol_value
10423 to avoid an error if it is void. */
10424 find_symbol_value (sym
);
10426 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10427 if (CONSP (XCAR (tail
))
10428 && (sym
= XCAR (XCAR (tail
)),
10430 && (sym
= indirect_variable (sym
),
10431 val
= SYMBOL_VALUE (sym
),
10432 (BUFFER_LOCAL_VALUEP (val
)
10433 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10434 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10435 find_symbol_value (sym
);
10439 #define STOP_POLLING \
10440 do { if (! polling_stopped_here) stop_polling (); \
10441 polling_stopped_here = 1; } while (0)
10443 #define RESUME_POLLING \
10444 do { if (polling_stopped_here) start_polling (); \
10445 polling_stopped_here = 0; } while (0)
10448 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10449 response to any user action; therefore, we should preserve the echo
10450 area. (Actually, our caller does that job.) Perhaps in the future
10451 avoid recentering windows if it is not necessary; currently that
10452 causes some problems. */
10455 redisplay_internal (preserve_echo_area
)
10456 int preserve_echo_area
;
10458 struct window
*w
= XWINDOW (selected_window
);
10459 struct frame
*f
= XFRAME (w
->frame
);
10461 int must_finish
= 0;
10462 struct text_pos tlbufpos
, tlendpos
;
10463 int number_of_visible_frames
;
10465 struct frame
*sf
= SELECTED_FRAME ();
10466 int polling_stopped_here
= 0;
10468 /* Non-zero means redisplay has to consider all windows on all
10469 frames. Zero means, only selected_window is considered. */
10470 int consider_all_windows_p
;
10472 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10474 /* No redisplay if running in batch mode or frame is not yet fully
10475 initialized, or redisplay is explicitly turned off by setting
10476 Vinhibit_redisplay. */
10478 || !NILP (Vinhibit_redisplay
)
10479 || !f
->glyphs_initialized_p
)
10482 /* The flag redisplay_performed_directly_p is set by
10483 direct_output_for_insert when it already did the whole screen
10484 update necessary. */
10485 if (redisplay_performed_directly_p
)
10487 redisplay_performed_directly_p
= 0;
10488 if (!hscroll_windows (selected_window
))
10492 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
10493 if (popup_activated ())
10497 /* I don't think this happens but let's be paranoid. */
10498 if (redisplaying_p
)
10501 /* Record a function that resets redisplaying_p to its old value
10502 when we leave this function. */
10503 count
= SPECPDL_INDEX ();
10504 record_unwind_protect (unwind_redisplay
,
10505 Fcons (make_number (redisplaying_p
), selected_frame
));
10507 specbind (Qinhibit_free_realized_faces
, Qnil
);
10510 Lisp_Object tail
, frame
;
10512 FOR_EACH_FRAME (tail
, frame
)
10514 struct frame
*f
= XFRAME (frame
);
10515 f
->already_hscrolled_p
= 0;
10521 reconsider_clip_changes (w
, current_buffer
);
10523 /* If new fonts have been loaded that make a glyph matrix adjustment
10524 necessary, do it. */
10525 if (fonts_changed_p
)
10527 adjust_glyphs (NULL
);
10528 ++windows_or_buffers_changed
;
10529 fonts_changed_p
= 0;
10532 /* If face_change_count is non-zero, init_iterator will free all
10533 realized faces, which includes the faces referenced from current
10534 matrices. So, we can't reuse current matrices in this case. */
10535 if (face_change_count
)
10536 ++windows_or_buffers_changed
;
10538 if (! FRAME_WINDOW_P (sf
)
10539 && previous_terminal_frame
!= sf
)
10541 /* Since frames on an ASCII terminal share the same display
10542 area, displaying a different frame means redisplay the whole
10544 windows_or_buffers_changed
++;
10545 SET_FRAME_GARBAGED (sf
);
10546 XSETFRAME (Vterminal_frame
, sf
);
10548 previous_terminal_frame
= sf
;
10550 /* Set the visible flags for all frames. Do this before checking
10551 for resized or garbaged frames; they want to know if their frames
10552 are visible. See the comment in frame.h for
10553 FRAME_SAMPLE_VISIBILITY. */
10555 Lisp_Object tail
, frame
;
10557 number_of_visible_frames
= 0;
10559 FOR_EACH_FRAME (tail
, frame
)
10561 struct frame
*f
= XFRAME (frame
);
10563 FRAME_SAMPLE_VISIBILITY (f
);
10564 if (FRAME_VISIBLE_P (f
))
10565 ++number_of_visible_frames
;
10566 clear_desired_matrices (f
);
10570 /* Notice any pending interrupt request to change frame size. */
10571 do_pending_window_change (1);
10573 /* Clear frames marked as garbaged. */
10574 if (frame_garbaged
)
10575 clear_garbaged_frames ();
10577 /* Build menubar and tool-bar items. */
10578 if (NILP (Vmemory_full
))
10579 prepare_menu_bars ();
10581 if (windows_or_buffers_changed
)
10582 update_mode_lines
++;
10584 /* Detect case that we need to write or remove a star in the mode line. */
10585 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10587 w
->update_mode_line
= Qt
;
10588 if (buffer_shared
> 1)
10589 update_mode_lines
++;
10592 /* If %c is in the mode line, update it if needed. */
10593 if (!NILP (w
->column_number_displayed
)
10594 /* This alternative quickly identifies a common case
10595 where no change is needed. */
10596 && !(PT
== XFASTINT (w
->last_point
)
10597 && XFASTINT (w
->last_modified
) >= MODIFF
10598 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10599 && (XFASTINT (w
->column_number_displayed
)
10600 != (int) current_column ())) /* iftc */
10601 w
->update_mode_line
= Qt
;
10603 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10605 /* The variable buffer_shared is set in redisplay_window and
10606 indicates that we redisplay a buffer in different windows. See
10608 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
10609 || cursor_type_changed
);
10611 /* If specs for an arrow have changed, do thorough redisplay
10612 to ensure we remove any arrow that should no longer exist. */
10613 if (overlay_arrows_changed_p ())
10614 consider_all_windows_p
= windows_or_buffers_changed
= 1;
10616 /* Normally the message* functions will have already displayed and
10617 updated the echo area, but the frame may have been trashed, or
10618 the update may have been preempted, so display the echo area
10619 again here. Checking message_cleared_p captures the case that
10620 the echo area should be cleared. */
10621 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
10622 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
10623 || (message_cleared_p
10624 && minibuf_level
== 0
10625 /* If the mini-window is currently selected, this means the
10626 echo-area doesn't show through. */
10627 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
10629 int window_height_changed_p
= echo_area_display (0);
10632 /* If we don't display the current message, don't clear the
10633 message_cleared_p flag, because, if we did, we wouldn't clear
10634 the echo area in the next redisplay which doesn't preserve
10636 if (!display_last_displayed_message_p
)
10637 message_cleared_p
= 0;
10639 if (fonts_changed_p
)
10641 else if (window_height_changed_p
)
10643 consider_all_windows_p
= 1;
10644 ++update_mode_lines
;
10645 ++windows_or_buffers_changed
;
10647 /* If window configuration was changed, frames may have been
10648 marked garbaged. Clear them or we will experience
10649 surprises wrt scrolling. */
10650 if (frame_garbaged
)
10651 clear_garbaged_frames ();
10654 else if (EQ (selected_window
, minibuf_window
)
10655 && (current_buffer
->clip_changed
10656 || XFASTINT (w
->last_modified
) < MODIFF
10657 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10658 && resize_mini_window (w
, 0))
10660 /* Resized active mini-window to fit the size of what it is
10661 showing if its contents might have changed. */
10663 consider_all_windows_p
= 1;
10664 ++windows_or_buffers_changed
;
10665 ++update_mode_lines
;
10667 /* If window configuration was changed, frames may have been
10668 marked garbaged. Clear them or we will experience
10669 surprises wrt scrolling. */
10670 if (frame_garbaged
)
10671 clear_garbaged_frames ();
10675 /* If showing the region, and mark has changed, we must redisplay
10676 the whole window. The assignment to this_line_start_pos prevents
10677 the optimization directly below this if-statement. */
10678 if (((!NILP (Vtransient_mark_mode
)
10679 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10680 != !NILP (w
->region_showing
))
10681 || (!NILP (w
->region_showing
)
10682 && !EQ (w
->region_showing
,
10683 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
10684 CHARPOS (this_line_start_pos
) = 0;
10686 /* Optimize the case that only the line containing the cursor in the
10687 selected window has changed. Variables starting with this_ are
10688 set in display_line and record information about the line
10689 containing the cursor. */
10690 tlbufpos
= this_line_start_pos
;
10691 tlendpos
= this_line_end_pos
;
10692 if (!consider_all_windows_p
10693 && CHARPOS (tlbufpos
) > 0
10694 && NILP (w
->update_mode_line
)
10695 && !current_buffer
->clip_changed
10696 && !current_buffer
->prevent_redisplay_optimizations_p
10697 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
10698 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
10699 /* Make sure recorded data applies to current buffer, etc. */
10700 && this_line_buffer
== current_buffer
10701 && current_buffer
== XBUFFER (w
->buffer
)
10702 && NILP (w
->force_start
)
10703 && NILP (w
->optional_new_start
)
10704 /* Point must be on the line that we have info recorded about. */
10705 && PT
>= CHARPOS (tlbufpos
)
10706 && PT
<= Z
- CHARPOS (tlendpos
)
10707 /* All text outside that line, including its final newline,
10708 must be unchanged */
10709 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
10710 CHARPOS (tlendpos
)))
10712 if (CHARPOS (tlbufpos
) > BEGV
10713 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
10714 && (CHARPOS (tlbufpos
) == ZV
10715 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
10716 /* Former continuation line has disappeared by becoming empty */
10718 else if (XFASTINT (w
->last_modified
) < MODIFF
10719 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
10720 || MINI_WINDOW_P (w
))
10722 /* We have to handle the case of continuation around a
10723 wide-column character (See the comment in indent.c around
10726 For instance, in the following case:
10728 -------- Insert --------
10729 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
10730 J_I_ ==> J_I_ `^^' are cursors.
10734 As we have to redraw the line above, we should goto cancel. */
10737 int line_height_before
= this_line_pixel_height
;
10739 /* Note that start_display will handle the case that the
10740 line starting at tlbufpos is a continuation lines. */
10741 start_display (&it
, w
, tlbufpos
);
10743 /* Implementation note: It this still necessary? */
10744 if (it
.current_x
!= this_line_start_x
)
10747 TRACE ((stderr
, "trying display optimization 1\n"));
10748 w
->cursor
.vpos
= -1;
10749 overlay_arrow_seen
= 0;
10750 it
.vpos
= this_line_vpos
;
10751 it
.current_y
= this_line_y
;
10752 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
10753 display_line (&it
);
10755 /* If line contains point, is not continued,
10756 and ends at same distance from eob as before, we win */
10757 if (w
->cursor
.vpos
>= 0
10758 /* Line is not continued, otherwise this_line_start_pos
10759 would have been set to 0 in display_line. */
10760 && CHARPOS (this_line_start_pos
)
10761 /* Line ends as before. */
10762 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
10763 /* Line has same height as before. Otherwise other lines
10764 would have to be shifted up or down. */
10765 && this_line_pixel_height
== line_height_before
)
10767 /* If this is not the window's last line, we must adjust
10768 the charstarts of the lines below. */
10769 if (it
.current_y
< it
.last_visible_y
)
10771 struct glyph_row
*row
10772 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
10773 int delta
, delta_bytes
;
10775 if (Z
- CHARPOS (tlendpos
) == ZV
)
10777 /* This line ends at end of (accessible part of)
10778 buffer. There is no newline to count. */
10780 - CHARPOS (tlendpos
)
10781 - MATRIX_ROW_START_CHARPOS (row
));
10782 delta_bytes
= (Z_BYTE
10783 - BYTEPOS (tlendpos
)
10784 - MATRIX_ROW_START_BYTEPOS (row
));
10788 /* This line ends in a newline. Must take
10789 account of the newline and the rest of the
10790 text that follows. */
10792 - CHARPOS (tlendpos
)
10793 - MATRIX_ROW_START_CHARPOS (row
));
10794 delta_bytes
= (Z_BYTE
10795 - BYTEPOS (tlendpos
)
10796 - MATRIX_ROW_START_BYTEPOS (row
));
10799 increment_matrix_positions (w
->current_matrix
,
10800 this_line_vpos
+ 1,
10801 w
->current_matrix
->nrows
,
10802 delta
, delta_bytes
);
10805 /* If this row displays text now but previously didn't,
10806 or vice versa, w->window_end_vpos may have to be
10808 if ((it
.glyph_row
- 1)->displays_text_p
)
10810 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10811 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10813 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10814 && this_line_vpos
> 0)
10815 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10816 w
->window_end_valid
= Qnil
;
10818 /* Update hint: No need to try to scroll in update_window. */
10819 w
->desired_matrix
->no_scrolling_p
= 1;
10822 *w
->desired_matrix
->method
= 0;
10823 debug_method_add (w
, "optimization 1");
10825 #ifdef HAVE_WINDOW_SYSTEM
10826 update_window_fringes (w
, 0);
10833 else if (/* Cursor position hasn't changed. */
10834 PT
== XFASTINT (w
->last_point
)
10835 /* Make sure the cursor was last displayed
10836 in this window. Otherwise we have to reposition it. */
10837 && 0 <= w
->cursor
.vpos
10838 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
10842 do_pending_window_change (1);
10844 /* We used to always goto end_of_redisplay here, but this
10845 isn't enough if we have a blinking cursor. */
10846 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10847 goto end_of_redisplay
;
10851 /* If highlighting the region, or if the cursor is in the echo area,
10852 then we can't just move the cursor. */
10853 else if (! (!NILP (Vtransient_mark_mode
)
10854 && !NILP (current_buffer
->mark_active
))
10855 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10856 || highlight_nonselected_windows
)
10857 && NILP (w
->region_showing
)
10858 && NILP (Vshow_trailing_whitespace
)
10859 && !cursor_in_echo_area
)
10862 struct glyph_row
*row
;
10864 /* Skip from tlbufpos to PT and see where it is. Note that
10865 PT may be in invisible text. If so, we will end at the
10866 next visible position. */
10867 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10868 NULL
, DEFAULT_FACE_ID
);
10869 it
.current_x
= this_line_start_x
;
10870 it
.current_y
= this_line_y
;
10871 it
.vpos
= this_line_vpos
;
10873 /* The call to move_it_to stops in front of PT, but
10874 moves over before-strings. */
10875 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10877 if (it
.vpos
== this_line_vpos
10878 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10881 xassert (this_line_vpos
== it
.vpos
);
10882 xassert (this_line_y
== it
.current_y
);
10883 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10885 *w
->desired_matrix
->method
= 0;
10886 debug_method_add (w
, "optimization 3");
10895 /* Text changed drastically or point moved off of line. */
10896 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10899 CHARPOS (this_line_start_pos
) = 0;
10900 consider_all_windows_p
|= buffer_shared
> 1;
10901 ++clear_face_cache_count
;
10902 #ifdef HAVE_WINDOW_SYSTEM
10903 ++clear_image_cache_count
;
10906 /* Build desired matrices, and update the display. If
10907 consider_all_windows_p is non-zero, do it for all windows on all
10908 frames. Otherwise do it for selected_window, only. */
10910 if (consider_all_windows_p
)
10912 Lisp_Object tail
, frame
;
10914 FOR_EACH_FRAME (tail
, frame
)
10915 XFRAME (frame
)->updated_p
= 0;
10917 /* Recompute # windows showing selected buffer. This will be
10918 incremented each time such a window is displayed. */
10921 FOR_EACH_FRAME (tail
, frame
)
10923 struct frame
*f
= XFRAME (frame
);
10925 if (FRAME_WINDOW_P (f
) || f
== sf
)
10927 if (! EQ (frame
, selected_frame
))
10928 /* Select the frame, for the sake of frame-local
10930 select_frame_for_redisplay (frame
);
10932 /* Mark all the scroll bars to be removed; we'll redeem
10933 the ones we want when we redisplay their windows. */
10934 if (condemn_scroll_bars_hook
)
10935 condemn_scroll_bars_hook (f
);
10937 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10938 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10940 /* Any scroll bars which redisplay_windows should have
10941 nuked should now go away. */
10942 if (judge_scroll_bars_hook
)
10943 judge_scroll_bars_hook (f
);
10945 /* If fonts changed, display again. */
10946 /* ??? rms: I suspect it is a mistake to jump all the way
10947 back to retry here. It should just retry this frame. */
10948 if (fonts_changed_p
)
10951 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10953 /* See if we have to hscroll. */
10954 if (!f
->already_hscrolled_p
)
10956 f
->already_hscrolled_p
= 1;
10957 if (hscroll_windows (f
->root_window
))
10961 /* Prevent various kinds of signals during display
10962 update. stdio is not robust about handling
10963 signals, which can cause an apparent I/O
10965 if (interrupt_input
)
10966 unrequest_sigio ();
10969 /* Update the display. */
10970 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10971 pause
|= update_frame (f
, 0, 0);
10972 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10984 /* Do the mark_window_display_accurate after all windows have
10985 been redisplayed because this call resets flags in buffers
10986 which are needed for proper redisplay. */
10987 FOR_EACH_FRAME (tail
, frame
)
10989 struct frame
*f
= XFRAME (frame
);
10992 mark_window_display_accurate (f
->root_window
, 1);
10993 if (frame_up_to_date_hook
)
10994 frame_up_to_date_hook (f
);
10999 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11001 Lisp_Object mini_window
;
11002 struct frame
*mini_frame
;
11004 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11005 /* Use list_of_error, not Qerror, so that
11006 we catch only errors and don't run the debugger. */
11007 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11009 redisplay_window_error
);
11011 /* Compare desired and current matrices, perform output. */
11014 /* If fonts changed, display again. */
11015 if (fonts_changed_p
)
11018 /* Prevent various kinds of signals during display update.
11019 stdio is not robust about handling signals,
11020 which can cause an apparent I/O error. */
11021 if (interrupt_input
)
11022 unrequest_sigio ();
11025 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11027 if (hscroll_windows (selected_window
))
11030 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11031 pause
= update_frame (sf
, 0, 0);
11034 /* We may have called echo_area_display at the top of this
11035 function. If the echo area is on another frame, that may
11036 have put text on a frame other than the selected one, so the
11037 above call to update_frame would not have caught it. Catch
11039 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11040 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11042 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11044 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11045 pause
|= update_frame (mini_frame
, 0, 0);
11046 if (!pause
&& hscroll_windows (mini_window
))
11051 /* If display was paused because of pending input, make sure we do a
11052 thorough update the next time. */
11055 /* Prevent the optimization at the beginning of
11056 redisplay_internal that tries a single-line update of the
11057 line containing the cursor in the selected window. */
11058 CHARPOS (this_line_start_pos
) = 0;
11060 /* Let the overlay arrow be updated the next time. */
11061 update_overlay_arrows (0);
11063 /* If we pause after scrolling, some rows in the current
11064 matrices of some windows are not valid. */
11065 if (!WINDOW_FULL_WIDTH_P (w
)
11066 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11067 update_mode_lines
= 1;
11071 if (!consider_all_windows_p
)
11073 /* This has already been done above if
11074 consider_all_windows_p is set. */
11075 mark_window_display_accurate_1 (w
, 1);
11077 /* Say overlay arrows are up to date. */
11078 update_overlay_arrows (1);
11080 if (frame_up_to_date_hook
!= 0)
11081 frame_up_to_date_hook (sf
);
11084 update_mode_lines
= 0;
11085 windows_or_buffers_changed
= 0;
11086 cursor_type_changed
= 0;
11089 /* Start SIGIO interrupts coming again. Having them off during the
11090 code above makes it less likely one will discard output, but not
11091 impossible, since there might be stuff in the system buffer here.
11092 But it is much hairier to try to do anything about that. */
11093 if (interrupt_input
)
11097 /* If a frame has become visible which was not before, redisplay
11098 again, so that we display it. Expose events for such a frame
11099 (which it gets when becoming visible) don't call the parts of
11100 redisplay constructing glyphs, so simply exposing a frame won't
11101 display anything in this case. So, we have to display these
11102 frames here explicitly. */
11105 Lisp_Object tail
, frame
;
11108 FOR_EACH_FRAME (tail
, frame
)
11110 int this_is_visible
= 0;
11112 if (XFRAME (frame
)->visible
)
11113 this_is_visible
= 1;
11114 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11115 if (XFRAME (frame
)->visible
)
11116 this_is_visible
= 1;
11118 if (this_is_visible
)
11122 if (new_count
!= number_of_visible_frames
)
11123 windows_or_buffers_changed
++;
11126 /* Change frame size now if a change is pending. */
11127 do_pending_window_change (1);
11129 /* If we just did a pending size change, or have additional
11130 visible frames, redisplay again. */
11131 if (windows_or_buffers_changed
&& !pause
)
11134 /* Clear the face cache eventually. */
11135 if (consider_all_windows_p
)
11137 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11139 clear_face_cache (0);
11140 clear_face_cache_count
= 0;
11142 #ifdef HAVE_WINDOW_SYSTEM
11143 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11145 Lisp_Object tail
, frame
;
11146 FOR_EACH_FRAME (tail
, frame
)
11148 struct frame
*f
= XFRAME (frame
);
11149 if (FRAME_WINDOW_P (f
))
11150 clear_image_cache (f
, 0);
11152 clear_image_cache_count
= 0;
11154 #endif /* HAVE_WINDOW_SYSTEM */
11158 unbind_to (count
, Qnil
);
11163 /* Redisplay, but leave alone any recent echo area message unless
11164 another message has been requested in its place.
11166 This is useful in situations where you need to redisplay but no
11167 user action has occurred, making it inappropriate for the message
11168 area to be cleared. See tracking_off and
11169 wait_reading_process_output for examples of these situations.
11171 FROM_WHERE is an integer saying from where this function was
11172 called. This is useful for debugging. */
11175 redisplay_preserve_echo_area (from_where
)
11178 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
11180 if (!NILP (echo_area_buffer
[1]))
11182 /* We have a previously displayed message, but no current
11183 message. Redisplay the previous message. */
11184 display_last_displayed_message_p
= 1;
11185 redisplay_internal (1);
11186 display_last_displayed_message_p
= 0;
11189 redisplay_internal (1);
11191 if (rif
!= NULL
&& rif
->flush_display_optional
)
11192 rif
->flush_display_optional (NULL
);
11196 /* Function registered with record_unwind_protect in
11197 redisplay_internal. Reset redisplaying_p to the value it had
11198 before redisplay_internal was called, and clear
11199 prevent_freeing_realized_faces_p. It also selects the previously
11203 unwind_redisplay (val
)
11206 Lisp_Object old_redisplaying_p
, old_frame
;
11208 old_redisplaying_p
= XCAR (val
);
11209 redisplaying_p
= XFASTINT (old_redisplaying_p
);
11210 old_frame
= XCDR (val
);
11211 if (! EQ (old_frame
, selected_frame
))
11212 select_frame_for_redisplay (old_frame
);
11217 /* Mark the display of window W as accurate or inaccurate. If
11218 ACCURATE_P is non-zero mark display of W as accurate. If
11219 ACCURATE_P is zero, arrange for W to be redisplayed the next time
11220 redisplay_internal is called. */
11223 mark_window_display_accurate_1 (w
, accurate_p
)
11227 if (BUFFERP (w
->buffer
))
11229 struct buffer
*b
= XBUFFER (w
->buffer
);
11232 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
11233 w
->last_overlay_modified
11234 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
11236 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
11240 b
->clip_changed
= 0;
11241 b
->prevent_redisplay_optimizations_p
= 0;
11243 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
11244 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
11245 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
11246 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
11248 w
->current_matrix
->buffer
= b
;
11249 w
->current_matrix
->begv
= BUF_BEGV (b
);
11250 w
->current_matrix
->zv
= BUF_ZV (b
);
11252 w
->last_cursor
= w
->cursor
;
11253 w
->last_cursor_off_p
= w
->cursor_off_p
;
11255 if (w
== XWINDOW (selected_window
))
11256 w
->last_point
= make_number (BUF_PT (b
));
11258 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
11264 w
->window_end_valid
= w
->buffer
;
11265 #if 0 /* This is incorrect with variable-height lines. */
11266 xassert (XINT (w
->window_end_vpos
)
11267 < (WINDOW_TOTAL_LINES (w
)
11268 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
11270 w
->update_mode_line
= Qnil
;
11275 /* Mark the display of windows in the window tree rooted at WINDOW as
11276 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
11277 windows as accurate. If ACCURATE_P is zero, arrange for windows to
11278 be redisplayed the next time redisplay_internal is called. */
11281 mark_window_display_accurate (window
, accurate_p
)
11282 Lisp_Object window
;
11287 for (; !NILP (window
); window
= w
->next
)
11289 w
= XWINDOW (window
);
11290 mark_window_display_accurate_1 (w
, accurate_p
);
11292 if (!NILP (w
->vchild
))
11293 mark_window_display_accurate (w
->vchild
, accurate_p
);
11294 if (!NILP (w
->hchild
))
11295 mark_window_display_accurate (w
->hchild
, accurate_p
);
11300 update_overlay_arrows (1);
11304 /* Force a thorough redisplay the next time by setting
11305 last_arrow_position and last_arrow_string to t, which is
11306 unequal to any useful value of Voverlay_arrow_... */
11307 update_overlay_arrows (-1);
11312 /* Return value in display table DP (Lisp_Char_Table *) for character
11313 C. Since a display table doesn't have any parent, we don't have to
11314 follow parent. Do not call this function directly but use the
11315 macro DISP_CHAR_VECTOR. */
11318 disp_char_vector (dp
, c
)
11319 struct Lisp_Char_Table
*dp
;
11325 if (SINGLE_BYTE_CHAR_P (c
))
11326 return (dp
->contents
[c
]);
11328 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
11331 else if (code
[2] < 32)
11334 /* Here, the possible range of code[0] (== charset ID) is
11335 128..max_charset. Since the top level char table contains data
11336 for multibyte characters after 256th element, we must increment
11337 code[0] by 128 to get a correct index. */
11339 code
[3] = -1; /* anchor */
11341 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
11343 val
= dp
->contents
[code
[i
]];
11344 if (!SUB_CHAR_TABLE_P (val
))
11345 return (NILP (val
) ? dp
->defalt
: val
);
11348 /* Here, val is a sub char table. We return the default value of
11350 return (dp
->defalt
);
11355 /***********************************************************************
11357 ***********************************************************************/
11359 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11362 redisplay_windows (window
)
11363 Lisp_Object window
;
11365 while (!NILP (window
))
11367 struct window
*w
= XWINDOW (window
);
11369 if (!NILP (w
->hchild
))
11370 redisplay_windows (w
->hchild
);
11371 else if (!NILP (w
->vchild
))
11372 redisplay_windows (w
->vchild
);
11375 displayed_buffer
= XBUFFER (w
->buffer
);
11376 /* Use list_of_error, not Qerror, so that
11377 we catch only errors and don't run the debugger. */
11378 internal_condition_case_1 (redisplay_window_0
, window
,
11380 redisplay_window_error
);
11388 redisplay_window_error ()
11390 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11395 redisplay_window_0 (window
)
11396 Lisp_Object window
;
11398 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11399 redisplay_window (window
, 0);
11404 redisplay_window_1 (window
)
11405 Lisp_Object window
;
11407 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11408 redisplay_window (window
, 1);
11413 /* Increment GLYPH until it reaches END or CONDITION fails while
11414 adding (GLYPH)->pixel_width to X. */
11416 #define SKIP_GLYPHS(glyph, end, x, condition) \
11419 (x) += (glyph)->pixel_width; \
11422 while ((glyph) < (end) && (condition))
11425 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11426 DELTA is the number of bytes by which positions recorded in ROW
11427 differ from current buffer positions. */
11430 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11432 struct glyph_row
*row
;
11433 struct glyph_matrix
*matrix
;
11434 int delta
, delta_bytes
, dy
, dvpos
;
11436 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11437 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11438 struct glyph
*cursor
= NULL
;
11439 /* The first glyph that starts a sequence of glyphs from string. */
11440 struct glyph
*string_start
;
11441 /* The X coordinate of string_start. */
11442 int string_start_x
;
11443 /* The last known character position. */
11444 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11445 /* The last known character position before string_start. */
11446 int string_before_pos
;
11449 int cursor_from_overlay_pos
= 0;
11450 int pt_old
= PT
- delta
;
11452 /* Skip over glyphs not having an object at the start of the row.
11453 These are special glyphs like truncation marks on terminal
11455 if (row
->displays_text_p
)
11457 && INTEGERP (glyph
->object
)
11458 && glyph
->charpos
< 0)
11460 x
+= glyph
->pixel_width
;
11464 string_start
= NULL
;
11466 && !INTEGERP (glyph
->object
)
11467 && (!BUFFERP (glyph
->object
)
11468 || (last_pos
= glyph
->charpos
) < pt_old
))
11470 if (! STRINGP (glyph
->object
))
11472 string_start
= NULL
;
11473 x
+= glyph
->pixel_width
;
11475 if (cursor_from_overlay_pos
11476 && last_pos
> cursor_from_overlay_pos
)
11478 cursor_from_overlay_pos
= 0;
11484 string_before_pos
= last_pos
;
11485 string_start
= glyph
;
11486 string_start_x
= x
;
11487 /* Skip all glyphs from string. */
11491 if ((cursor
== NULL
|| glyph
> cursor
)
11492 && !NILP (Fget_char_property (make_number ((glyph
)->charpos
),
11493 Qcursor
, (glyph
)->object
))
11494 && (pos
= string_buffer_position (w
, glyph
->object
,
11495 string_before_pos
),
11496 (pos
== 0 /* From overlay */
11497 || pos
== pt_old
)))
11499 /* Estimate overlay buffer position from the buffer
11500 positions of the glyphs before and after the overlay.
11501 Add 1 to last_pos so that if point corresponds to the
11502 glyph right after the overlay, we still use a 'cursor'
11503 property found in that overlay. */
11504 cursor_from_overlay_pos
= pos
== 0 ? last_pos
+1 : 0;
11508 x
+= glyph
->pixel_width
;
11511 while (glyph
< end
&& STRINGP (glyph
->object
));
11515 if (cursor
!= NULL
)
11520 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
11522 /* Scan back over the ellipsis glyphs, decrementing positions. */
11523 while (glyph
> row
->glyphs
[TEXT_AREA
]
11524 && (glyph
- 1)->charpos
== last_pos
)
11525 glyph
--, x
-= glyph
->pixel_width
;
11526 /* That loop always goes one position too far,
11527 including the glyph before the ellipsis.
11528 So scan forward over that one. */
11529 x
+= glyph
->pixel_width
;
11532 else if (string_start
11533 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
11535 /* We may have skipped over point because the previous glyphs
11536 are from string. As there's no easy way to know the
11537 character position of the current glyph, find the correct
11538 glyph on point by scanning from string_start again. */
11540 Lisp_Object string
;
11543 limit
= make_number (pt_old
+ 1);
11545 glyph
= string_start
;
11546 x
= string_start_x
;
11547 string
= glyph
->object
;
11548 pos
= string_buffer_position (w
, string
, string_before_pos
);
11549 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
11550 because we always put cursor after overlay strings. */
11551 while (pos
== 0 && glyph
< end
)
11553 string
= glyph
->object
;
11554 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11556 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
11559 while (glyph
< end
)
11561 pos
= XINT (Fnext_single_char_property_change
11562 (make_number (pos
), Qdisplay
, Qnil
, limit
));
11565 /* Skip glyphs from the same string. */
11566 string
= glyph
->object
;
11567 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11568 /* Skip glyphs from an overlay. */
11570 && ! string_buffer_position (w
, glyph
->object
, pos
))
11572 string
= glyph
->object
;
11573 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11578 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
11580 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
11581 w
->cursor
.y
= row
->y
+ dy
;
11583 if (w
== XWINDOW (selected_window
))
11585 if (!row
->continued_p
11586 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
11589 this_line_buffer
= XBUFFER (w
->buffer
);
11591 CHARPOS (this_line_start_pos
)
11592 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
11593 BYTEPOS (this_line_start_pos
)
11594 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
11596 CHARPOS (this_line_end_pos
)
11597 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
11598 BYTEPOS (this_line_end_pos
)
11599 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
11601 this_line_y
= w
->cursor
.y
;
11602 this_line_pixel_height
= row
->height
;
11603 this_line_vpos
= w
->cursor
.vpos
;
11604 this_line_start_x
= row
->x
;
11607 CHARPOS (this_line_start_pos
) = 0;
11612 /* Run window scroll functions, if any, for WINDOW with new window
11613 start STARTP. Sets the window start of WINDOW to that position.
11615 We assume that the window's buffer is really current. */
11617 static INLINE
struct text_pos
11618 run_window_scroll_functions (window
, startp
)
11619 Lisp_Object window
;
11620 struct text_pos startp
;
11622 struct window
*w
= XWINDOW (window
);
11623 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
11625 if (current_buffer
!= XBUFFER (w
->buffer
))
11628 if (!NILP (Vwindow_scroll_functions
))
11630 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
11631 make_number (CHARPOS (startp
)));
11632 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11633 /* In case the hook functions switch buffers. */
11634 if (current_buffer
!= XBUFFER (w
->buffer
))
11635 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11642 /* Make sure the line containing the cursor is fully visible.
11643 A value of 1 means there is nothing to be done.
11644 (Either the line is fully visible, or it cannot be made so,
11645 or we cannot tell.)
11647 If FORCE_P is non-zero, return 0 even if partial visible cursor row
11648 is higher than window.
11650 A value of 0 means the caller should do scrolling
11651 as if point had gone off the screen. */
11654 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
11657 int current_matrix_p
;
11659 struct glyph_matrix
*matrix
;
11660 struct glyph_row
*row
;
11663 if (!make_cursor_line_fully_visible_p
)
11666 /* It's not always possible to find the cursor, e.g, when a window
11667 is full of overlay strings. Don't do anything in that case. */
11668 if (w
->cursor
.vpos
< 0)
11671 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
11672 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
11674 /* If the cursor row is not partially visible, there's nothing to do. */
11675 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
11678 /* If the row the cursor is in is taller than the window's height,
11679 it's not clear what to do, so do nothing. */
11680 window_height
= window_box_height (w
);
11681 if (row
->height
>= window_height
)
11683 if (!force_p
|| MINI_WINDOW_P (w
) || w
->vscroll
)
11689 /* This code used to try to scroll the window just enough to make
11690 the line visible. It returned 0 to say that the caller should
11691 allocate larger glyph matrices. */
11693 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
11695 int dy
= row
->height
- row
->visible_height
;
11698 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11700 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
11702 int dy
= - (row
->height
- row
->visible_height
);
11705 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11708 /* When we change the cursor y-position of the selected window,
11709 change this_line_y as well so that the display optimization for
11710 the cursor line of the selected window in redisplay_internal uses
11711 the correct y-position. */
11712 if (w
== XWINDOW (selected_window
))
11713 this_line_y
= w
->cursor
.y
;
11715 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
11716 redisplay with larger matrices. */
11717 if (matrix
->nrows
< required_matrix_height (w
))
11719 fonts_changed_p
= 1;
11728 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
11729 non-zero means only WINDOW is redisplayed in redisplay_internal.
11730 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
11731 in redisplay_window to bring a partially visible line into view in
11732 the case that only the cursor has moved.
11734 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
11735 last screen line's vertical height extends past the end of the screen.
11739 1 if scrolling succeeded
11741 0 if scrolling didn't find point.
11743 -1 if new fonts have been loaded so that we must interrupt
11744 redisplay, adjust glyph matrices, and try again. */
11750 SCROLLING_NEED_LARGER_MATRICES
11754 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
11755 scroll_step
, temp_scroll_step
, last_line_misfit
)
11756 Lisp_Object window
;
11757 int just_this_one_p
;
11758 EMACS_INT scroll_conservatively
, scroll_step
;
11759 int temp_scroll_step
;
11760 int last_line_misfit
;
11762 struct window
*w
= XWINDOW (window
);
11763 struct frame
*f
= XFRAME (w
->frame
);
11764 struct text_pos scroll_margin_pos
;
11765 struct text_pos pos
;
11766 struct text_pos startp
;
11768 Lisp_Object window_end
;
11769 int this_scroll_margin
;
11773 int amount_to_scroll
= 0;
11774 Lisp_Object aggressive
;
11776 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
11779 debug_method_add (w
, "try_scrolling");
11782 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11784 /* Compute scroll margin height in pixels. We scroll when point is
11785 within this distance from the top or bottom of the window. */
11786 if (scroll_margin
> 0)
11788 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11789 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11792 this_scroll_margin
= 0;
11794 /* Force scroll_conservatively to have a reasonable value so it doesn't
11795 cause an overflow while computing how much to scroll. */
11796 if (scroll_conservatively
)
11797 scroll_conservatively
= min (scroll_conservatively
,
11798 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
11800 /* Compute how much we should try to scroll maximally to bring point
11802 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
11803 scroll_max
= max (scroll_step
,
11804 max (scroll_conservatively
, temp_scroll_step
));
11805 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
11806 || NUMBERP (current_buffer
->scroll_up_aggressively
))
11807 /* We're trying to scroll because of aggressive scrolling
11808 but no scroll_step is set. Choose an arbitrary one. Maybe
11809 there should be a variable for this. */
11813 scroll_max
*= FRAME_LINE_HEIGHT (f
);
11815 /* Decide whether we have to scroll down. Start at the window end
11816 and move this_scroll_margin up to find the position of the scroll
11818 window_end
= Fwindow_end (window
, Qt
);
11822 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
11823 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
11825 if (this_scroll_margin
|| extra_scroll_margin_lines
)
11827 start_display (&it
, w
, scroll_margin_pos
);
11828 if (this_scroll_margin
)
11829 move_it_vertically_backward (&it
, this_scroll_margin
);
11830 if (extra_scroll_margin_lines
)
11831 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
11832 scroll_margin_pos
= it
.current
.pos
;
11835 if (PT
>= CHARPOS (scroll_margin_pos
))
11839 /* Point is in the scroll margin at the bottom of the window, or
11840 below. Compute a new window start that makes point visible. */
11842 /* Compute the distance from the scroll margin to PT.
11843 Give up if the distance is greater than scroll_max. */
11844 start_display (&it
, w
, scroll_margin_pos
);
11846 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11847 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11849 /* To make point visible, we have to move the window start
11850 down so that the line the cursor is in is visible, which
11851 means we have to add in the height of the cursor line. */
11852 dy
= line_bottom_y (&it
) - y0
;
11854 if (dy
> scroll_max
)
11855 return SCROLLING_FAILED
;
11857 /* Move the window start down. If scrolling conservatively,
11858 move it just enough down to make point visible. If
11859 scroll_step is set, move it down by scroll_step. */
11860 start_display (&it
, w
, startp
);
11862 if (scroll_conservatively
)
11863 /* Set AMOUNT_TO_SCROLL to at least one line,
11864 and at most scroll_conservatively lines. */
11866 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
11867 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
11868 else if (scroll_step
|| temp_scroll_step
)
11869 amount_to_scroll
= scroll_max
;
11872 aggressive
= current_buffer
->scroll_up_aggressively
;
11873 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11874 if (NUMBERP (aggressive
))
11876 double float_amount
= XFLOATINT (aggressive
) * height
;
11877 amount_to_scroll
= float_amount
;
11878 if (amount_to_scroll
== 0 && float_amount
> 0)
11879 amount_to_scroll
= 1;
11883 if (amount_to_scroll
<= 0)
11884 return SCROLLING_FAILED
;
11886 /* If moving by amount_to_scroll leaves STARTP unchanged,
11887 move it down one screen line. */
11889 move_it_vertically (&it
, amount_to_scroll
);
11890 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
11891 move_it_by_lines (&it
, 1, 1);
11892 startp
= it
.current
.pos
;
11896 /* See if point is inside the scroll margin at the top of the
11898 scroll_margin_pos
= startp
;
11899 if (this_scroll_margin
)
11901 start_display (&it
, w
, startp
);
11902 move_it_vertically (&it
, this_scroll_margin
);
11903 scroll_margin_pos
= it
.current
.pos
;
11906 if (PT
< CHARPOS (scroll_margin_pos
))
11908 /* Point is in the scroll margin at the top of the window or
11909 above what is displayed in the window. */
11912 /* Compute the vertical distance from PT to the scroll
11913 margin position. Give up if distance is greater than
11915 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
11916 start_display (&it
, w
, pos
);
11918 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
11919 it
.last_visible_y
, -1,
11920 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11921 dy
= it
.current_y
- y0
;
11922 if (dy
> scroll_max
)
11923 return SCROLLING_FAILED
;
11925 /* Compute new window start. */
11926 start_display (&it
, w
, startp
);
11928 if (scroll_conservatively
)
11930 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11931 else if (scroll_step
|| temp_scroll_step
)
11932 amount_to_scroll
= scroll_max
;
11935 aggressive
= current_buffer
->scroll_down_aggressively
;
11936 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11937 if (NUMBERP (aggressive
))
11939 double float_amount
= XFLOATINT (aggressive
) * height
;
11940 amount_to_scroll
= float_amount
;
11941 if (amount_to_scroll
== 0 && float_amount
> 0)
11942 amount_to_scroll
= 1;
11946 if (amount_to_scroll
<= 0)
11947 return SCROLLING_FAILED
;
11949 move_it_vertically_backward (&it
, amount_to_scroll
);
11950 startp
= it
.current
.pos
;
11954 /* Run window scroll functions. */
11955 startp
= run_window_scroll_functions (window
, startp
);
11957 /* Display the window. Give up if new fonts are loaded, or if point
11959 if (!try_window (window
, startp
, 0))
11960 rc
= SCROLLING_NEED_LARGER_MATRICES
;
11961 else if (w
->cursor
.vpos
< 0)
11963 clear_glyph_matrix (w
->desired_matrix
);
11964 rc
= SCROLLING_FAILED
;
11968 /* Maybe forget recorded base line for line number display. */
11969 if (!just_this_one_p
11970 || current_buffer
->clip_changed
11971 || BEG_UNCHANGED
< CHARPOS (startp
))
11972 w
->base_line_number
= Qnil
;
11974 /* If cursor ends up on a partially visible line,
11975 treat that as being off the bottom of the screen. */
11976 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
11978 clear_glyph_matrix (w
->desired_matrix
);
11979 ++extra_scroll_margin_lines
;
11982 rc
= SCROLLING_SUCCESS
;
11989 /* Compute a suitable window start for window W if display of W starts
11990 on a continuation line. Value is non-zero if a new window start
11993 The new window start will be computed, based on W's width, starting
11994 from the start of the continued line. It is the start of the
11995 screen line with the minimum distance from the old start W->start. */
11998 compute_window_start_on_continuation_line (w
)
12001 struct text_pos pos
, start_pos
;
12002 int window_start_changed_p
= 0;
12004 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12006 /* If window start is on a continuation line... Window start may be
12007 < BEGV in case there's invisible text at the start of the
12008 buffer (M-x rmail, for example). */
12009 if (CHARPOS (start_pos
) > BEGV
12010 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12013 struct glyph_row
*row
;
12015 /* Handle the case that the window start is out of range. */
12016 if (CHARPOS (start_pos
) < BEGV
)
12017 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12018 else if (CHARPOS (start_pos
) > ZV
)
12019 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12021 /* Find the start of the continued line. This should be fast
12022 because scan_buffer is fast (newline cache). */
12023 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12024 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12025 row
, DEFAULT_FACE_ID
);
12026 reseat_at_previous_visible_line_start (&it
);
12028 /* If the line start is "too far" away from the window start,
12029 say it takes too much time to compute a new window start. */
12030 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12031 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12033 int min_distance
, distance
;
12035 /* Move forward by display lines to find the new window
12036 start. If window width was enlarged, the new start can
12037 be expected to be > the old start. If window width was
12038 decreased, the new window start will be < the old start.
12039 So, we're looking for the display line start with the
12040 minimum distance from the old window start. */
12041 pos
= it
.current
.pos
;
12042 min_distance
= INFINITY
;
12043 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12044 distance
< min_distance
)
12046 min_distance
= distance
;
12047 pos
= it
.current
.pos
;
12048 move_it_by_lines (&it
, 1, 0);
12051 /* Set the window start there. */
12052 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12053 window_start_changed_p
= 1;
12057 return window_start_changed_p
;
12061 /* Try cursor movement in case text has not changed in window WINDOW,
12062 with window start STARTP. Value is
12064 CURSOR_MOVEMENT_SUCCESS if successful
12066 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12068 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12069 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12070 we want to scroll as if scroll-step were set to 1. See the code.
12072 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12073 which case we have to abort this redisplay, and adjust matrices
12078 CURSOR_MOVEMENT_SUCCESS
,
12079 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12080 CURSOR_MOVEMENT_MUST_SCROLL
,
12081 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12085 try_cursor_movement (window
, startp
, scroll_step
)
12086 Lisp_Object window
;
12087 struct text_pos startp
;
12090 struct window
*w
= XWINDOW (window
);
12091 struct frame
*f
= XFRAME (w
->frame
);
12092 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12095 if (inhibit_try_cursor_movement
)
12099 /* Handle case where text has not changed, only point, and it has
12100 not moved off the frame. */
12101 if (/* Point may be in this window. */
12102 PT
>= CHARPOS (startp
)
12103 /* Selective display hasn't changed. */
12104 && !current_buffer
->clip_changed
12105 /* Function force-mode-line-update is used to force a thorough
12106 redisplay. It sets either windows_or_buffers_changed or
12107 update_mode_lines. So don't take a shortcut here for these
12109 && !update_mode_lines
12110 && !windows_or_buffers_changed
12111 && !cursor_type_changed
12112 /* Can't use this case if highlighting a region. When a
12113 region exists, cursor movement has to do more than just
12115 && !(!NILP (Vtransient_mark_mode
)
12116 && !NILP (current_buffer
->mark_active
))
12117 && NILP (w
->region_showing
)
12118 && NILP (Vshow_trailing_whitespace
)
12119 /* Right after splitting windows, last_point may be nil. */
12120 && INTEGERP (w
->last_point
)
12121 /* This code is not used for mini-buffer for the sake of the case
12122 of redisplaying to replace an echo area message; since in
12123 that case the mini-buffer contents per se are usually
12124 unchanged. This code is of no real use in the mini-buffer
12125 since the handling of this_line_start_pos, etc., in redisplay
12126 handles the same cases. */
12127 && !EQ (window
, minibuf_window
)
12128 /* When splitting windows or for new windows, it happens that
12129 redisplay is called with a nil window_end_vpos or one being
12130 larger than the window. This should really be fixed in
12131 window.c. I don't have this on my list, now, so we do
12132 approximately the same as the old redisplay code. --gerd. */
12133 && INTEGERP (w
->window_end_vpos
)
12134 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12135 && (FRAME_WINDOW_P (f
)
12136 || !overlay_arrow_in_current_buffer_p ()))
12138 int this_scroll_margin
, top_scroll_margin
;
12139 struct glyph_row
*row
= NULL
;
12142 debug_method_add (w
, "cursor movement");
12145 /* Scroll if point within this distance from the top or bottom
12146 of the window. This is a pixel value. */
12147 this_scroll_margin
= max (0, scroll_margin
);
12148 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12149 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12151 top_scroll_margin
= this_scroll_margin
;
12152 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12153 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12155 /* Start with the row the cursor was displayed during the last
12156 not paused redisplay. Give up if that row is not valid. */
12157 if (w
->last_cursor
.vpos
< 0
12158 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12159 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12162 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12163 if (row
->mode_line_p
)
12165 if (!row
->enabled_p
)
12166 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12169 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12172 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12174 if (PT
> XFASTINT (w
->last_point
))
12176 /* Point has moved forward. */
12177 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12178 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12180 xassert (row
->enabled_p
);
12184 /* The end position of a row equals the start position
12185 of the next row. If PT is there, we would rather
12186 display it in the next line. */
12187 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12188 && MATRIX_ROW_END_CHARPOS (row
) == PT
12189 && !cursor_row_p (w
, row
))
12192 /* If within the scroll margin, scroll. Note that
12193 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
12194 the next line would be drawn, and that
12195 this_scroll_margin can be zero. */
12196 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
12197 || PT
> MATRIX_ROW_END_CHARPOS (row
)
12198 /* Line is completely visible last line in window
12199 and PT is to be set in the next line. */
12200 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
12201 && PT
== MATRIX_ROW_END_CHARPOS (row
)
12202 && !row
->ends_at_zv_p
12203 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12206 else if (PT
< XFASTINT (w
->last_point
))
12208 /* Cursor has to be moved backward. Note that PT >=
12209 CHARPOS (startp) because of the outer if-statement. */
12210 while (!row
->mode_line_p
12211 && (MATRIX_ROW_START_CHARPOS (row
) > PT
12212 || (MATRIX_ROW_START_CHARPOS (row
) == PT
12213 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
12214 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
12215 row
> w
->current_matrix
->rows
12216 && (row
-1)->ends_in_newline_from_string_p
))))
12217 && (row
->y
> top_scroll_margin
12218 || CHARPOS (startp
) == BEGV
))
12220 xassert (row
->enabled_p
);
12224 /* Consider the following case: Window starts at BEGV,
12225 there is invisible, intangible text at BEGV, so that
12226 display starts at some point START > BEGV. It can
12227 happen that we are called with PT somewhere between
12228 BEGV and START. Try to handle that case. */
12229 if (row
< w
->current_matrix
->rows
12230 || row
->mode_line_p
)
12232 row
= w
->current_matrix
->rows
;
12233 if (row
->mode_line_p
)
12237 /* Due to newlines in overlay strings, we may have to
12238 skip forward over overlay strings. */
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. */
12245 if (row
->y
< top_scroll_margin
12246 && CHARPOS (startp
) != BEGV
)
12251 /* Cursor did not move. So don't scroll even if cursor line
12252 is partially visible, as it was so before. */
12253 rc
= CURSOR_MOVEMENT_SUCCESS
;
12256 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
12257 || PT
> MATRIX_ROW_END_CHARPOS (row
))
12259 /* if PT is not in the glyph row, give up. */
12260 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12262 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
12263 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
12264 && make_cursor_line_fully_visible_p
)
12266 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
12267 && !row
->ends_at_zv_p
12268 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12269 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12270 else if (row
->height
> window_box_height (w
))
12272 /* If we end up in a partially visible line, let's
12273 make it fully visible, except when it's taller
12274 than the window, in which case we can't do much
12277 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12281 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12282 if (!cursor_row_fully_visible_p (w
, 0, 1))
12283 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12285 rc
= CURSOR_MOVEMENT_SUCCESS
;
12289 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12292 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12293 rc
= CURSOR_MOVEMENT_SUCCESS
;
12302 set_vertical_scroll_bar (w
)
12305 int start
, end
, whole
;
12307 /* Calculate the start and end positions for the current window.
12308 At some point, it would be nice to choose between scrollbars
12309 which reflect the whole buffer size, with special markers
12310 indicating narrowing, and scrollbars which reflect only the
12313 Note that mini-buffers sometimes aren't displaying any text. */
12314 if (!MINI_WINDOW_P (w
)
12315 || (w
== XWINDOW (minibuf_window
)
12316 && NILP (echo_area_buffer
[0])))
12318 struct buffer
*buf
= XBUFFER (w
->buffer
);
12319 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12320 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12321 /* I don't think this is guaranteed to be right. For the
12322 moment, we'll pretend it is. */
12323 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12327 if (whole
< (end
- start
))
12328 whole
= end
- start
;
12331 start
= end
= whole
= 0;
12333 /* Indicate what this scroll bar ought to be displaying now. */
12334 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
12338 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
12339 selected_window is redisplayed.
12341 We can return without actually redisplaying the window if
12342 fonts_changed_p is nonzero. In that case, redisplay_internal will
12346 redisplay_window (window
, just_this_one_p
)
12347 Lisp_Object window
;
12348 int just_this_one_p
;
12350 struct window
*w
= XWINDOW (window
);
12351 struct frame
*f
= XFRAME (w
->frame
);
12352 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12353 struct buffer
*old
= current_buffer
;
12354 struct text_pos lpoint
, opoint
, startp
;
12355 int update_mode_line
;
12358 /* Record it now because it's overwritten. */
12359 int current_matrix_up_to_date_p
= 0;
12360 int used_current_matrix_p
= 0;
12361 /* This is less strict than current_matrix_up_to_date_p.
12362 It indictes that the buffer contents and narrowing are unchanged. */
12363 int buffer_unchanged_p
= 0;
12364 int temp_scroll_step
= 0;
12365 int count
= SPECPDL_INDEX ();
12367 int centering_position
= -1;
12368 int last_line_misfit
= 0;
12370 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12373 /* W must be a leaf window here. */
12374 xassert (!NILP (w
->buffer
));
12376 *w
->desired_matrix
->method
= 0;
12379 specbind (Qinhibit_point_motion_hooks
, Qt
);
12381 reconsider_clip_changes (w
, buffer
);
12383 /* Has the mode line to be updated? */
12384 update_mode_line
= (!NILP (w
->update_mode_line
)
12385 || update_mode_lines
12386 || buffer
->clip_changed
12387 || buffer
->prevent_redisplay_optimizations_p
);
12389 if (MINI_WINDOW_P (w
))
12391 if (w
== XWINDOW (echo_area_window
)
12392 && !NILP (echo_area_buffer
[0]))
12394 if (update_mode_line
)
12395 /* We may have to update a tty frame's menu bar or a
12396 tool-bar. Example `M-x C-h C-h C-g'. */
12397 goto finish_menu_bars
;
12399 /* We've already displayed the echo area glyphs in this window. */
12400 goto finish_scroll_bars
;
12402 else if ((w
!= XWINDOW (minibuf_window
)
12403 || minibuf_level
== 0)
12404 /* When buffer is nonempty, redisplay window normally. */
12405 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12406 /* Quail displays non-mini buffers in minibuffer window.
12407 In that case, redisplay the window normally. */
12408 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12410 /* W is a mini-buffer window, but it's not active, so clear
12412 int yb
= window_text_bottom_y (w
);
12413 struct glyph_row
*row
;
12416 for (y
= 0, row
= w
->desired_matrix
->rows
;
12418 y
+= row
->height
, ++row
)
12419 blank_row (w
, row
, y
);
12420 goto finish_scroll_bars
;
12423 clear_glyph_matrix (w
->desired_matrix
);
12426 /* Otherwise set up data on this window; select its buffer and point
12428 /* Really select the buffer, for the sake of buffer-local
12430 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12431 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12433 current_matrix_up_to_date_p
12434 = (!NILP (w
->window_end_valid
)
12435 && !current_buffer
->clip_changed
12436 && !current_buffer
->prevent_redisplay_optimizations_p
12437 && XFASTINT (w
->last_modified
) >= MODIFF
12438 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12441 = (!NILP (w
->window_end_valid
)
12442 && !current_buffer
->clip_changed
12443 && XFASTINT (w
->last_modified
) >= MODIFF
12444 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12446 /* When windows_or_buffers_changed is non-zero, we can't rely on
12447 the window end being valid, so set it to nil there. */
12448 if (windows_or_buffers_changed
)
12450 /* If window starts on a continuation line, maybe adjust the
12451 window start in case the window's width changed. */
12452 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12453 compute_window_start_on_continuation_line (w
);
12455 w
->window_end_valid
= Qnil
;
12458 /* Some sanity checks. */
12459 CHECK_WINDOW_END (w
);
12460 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12462 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12465 /* If %c is in mode line, update it if needed. */
12466 if (!NILP (w
->column_number_displayed
)
12467 /* This alternative quickly identifies a common case
12468 where no change is needed. */
12469 && !(PT
== XFASTINT (w
->last_point
)
12470 && XFASTINT (w
->last_modified
) >= MODIFF
12471 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12472 && (XFASTINT (w
->column_number_displayed
)
12473 != (int) current_column ())) /* iftc */
12474 update_mode_line
= 1;
12476 /* Count number of windows showing the selected buffer. An indirect
12477 buffer counts as its base buffer. */
12478 if (!just_this_one_p
)
12480 struct buffer
*current_base
, *window_base
;
12481 current_base
= current_buffer
;
12482 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12483 if (current_base
->base_buffer
)
12484 current_base
= current_base
->base_buffer
;
12485 if (window_base
->base_buffer
)
12486 window_base
= window_base
->base_buffer
;
12487 if (current_base
== window_base
)
12491 /* Point refers normally to the selected window. For any other
12492 window, set up appropriate value. */
12493 if (!EQ (window
, selected_window
))
12495 int new_pt
= XMARKER (w
->pointm
)->charpos
;
12496 int new_pt_byte
= marker_byte_position (w
->pointm
);
12500 new_pt_byte
= BEGV_BYTE
;
12501 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
12503 else if (new_pt
> (ZV
- 1))
12506 new_pt_byte
= ZV_BYTE
;
12507 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
12510 /* We don't use SET_PT so that the point-motion hooks don't run. */
12511 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
12514 /* If any of the character widths specified in the display table
12515 have changed, invalidate the width run cache. It's true that
12516 this may be a bit late to catch such changes, but the rest of
12517 redisplay goes (non-fatally) haywire when the display table is
12518 changed, so why should we worry about doing any better? */
12519 if (current_buffer
->width_run_cache
)
12521 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
12523 if (! disptab_matches_widthtab (disptab
,
12524 XVECTOR (current_buffer
->width_table
)))
12526 invalidate_region_cache (current_buffer
,
12527 current_buffer
->width_run_cache
,
12529 recompute_width_table (current_buffer
, disptab
);
12533 /* If window-start is screwed up, choose a new one. */
12534 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12537 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12539 /* If someone specified a new starting point but did not insist,
12540 check whether it can be used. */
12541 if (!NILP (w
->optional_new_start
)
12542 && CHARPOS (startp
) >= BEGV
12543 && CHARPOS (startp
) <= ZV
)
12545 w
->optional_new_start
= Qnil
;
12546 start_display (&it
, w
, startp
);
12547 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12548 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12549 if (IT_CHARPOS (it
) == PT
)
12550 w
->force_start
= Qt
;
12551 /* IT may overshoot PT if text at PT is invisible. */
12552 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12553 w
->force_start
= Qt
;
12558 /* Handle case where place to start displaying has been specified,
12559 unless the specified location is outside the accessible range. */
12560 if (!NILP (w
->force_start
)
12561 || w
->frozen_window_start_p
)
12563 /* We set this later on if we have to adjust point. */
12567 w
->force_start
= Qnil
;
12569 w
->window_end_valid
= Qnil
;
12571 /* Forget any recorded base line for line number display. */
12572 if (!buffer_unchanged_p
)
12573 w
->base_line_number
= Qnil
;
12575 /* Redisplay the mode line. Select the buffer properly for that.
12576 Also, run the hook window-scroll-functions
12577 because we have scrolled. */
12578 /* Note, we do this after clearing force_start because
12579 if there's an error, it is better to forget about force_start
12580 than to get into an infinite loop calling the hook functions
12581 and having them get more errors. */
12582 if (!update_mode_line
12583 || ! NILP (Vwindow_scroll_functions
))
12585 update_mode_line
= 1;
12586 w
->update_mode_line
= Qt
;
12587 startp
= run_window_scroll_functions (window
, startp
);
12590 w
->last_modified
= make_number (0);
12591 w
->last_overlay_modified
= make_number (0);
12592 if (CHARPOS (startp
) < BEGV
)
12593 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
12594 else if (CHARPOS (startp
) > ZV
)
12595 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
12597 /* Redisplay, then check if cursor has been set during the
12598 redisplay. Give up if new fonts were loaded. */
12599 val
= try_window (window
, startp
, 1);
12602 w
->force_start
= Qt
;
12603 clear_glyph_matrix (w
->desired_matrix
);
12604 goto need_larger_matrices
;
12606 /* Point was outside the scroll margins. */
12608 new_vpos
= window_box_height (w
) / 2;
12610 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
12612 /* If point does not appear, try to move point so it does
12613 appear. The desired matrix has been built above, so we
12614 can use it here. */
12615 new_vpos
= window_box_height (w
) / 2;
12618 if (!cursor_row_fully_visible_p (w
, 0, 0))
12620 /* Point does appear, but on a line partly visible at end of window.
12621 Move it back to a fully-visible line. */
12622 new_vpos
= window_box_height (w
);
12625 /* If we need to move point for either of the above reasons,
12626 now actually do it. */
12629 struct glyph_row
*row
;
12631 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
12632 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
12635 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
12636 MATRIX_ROW_START_BYTEPOS (row
));
12638 if (w
!= XWINDOW (selected_window
))
12639 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
12640 else if (current_buffer
== old
)
12641 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12643 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
12645 /* If we are highlighting the region, then we just changed
12646 the region, so redisplay to show it. */
12647 if (!NILP (Vtransient_mark_mode
)
12648 && !NILP (current_buffer
->mark_active
))
12650 clear_glyph_matrix (w
->desired_matrix
);
12651 if (!try_window (window
, startp
, 0))
12652 goto need_larger_matrices
;
12657 debug_method_add (w
, "forced window start");
12662 /* Handle case where text has not changed, only point, and it has
12663 not moved off the frame, and we are not retrying after hscroll.
12664 (current_matrix_up_to_date_p is nonzero when retrying.) */
12665 if (current_matrix_up_to_date_p
12666 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
12667 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
12671 case CURSOR_MOVEMENT_SUCCESS
:
12672 used_current_matrix_p
= 1;
12675 #if 0 /* try_cursor_movement never returns this value. */
12676 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
12677 goto need_larger_matrices
;
12680 case CURSOR_MOVEMENT_MUST_SCROLL
:
12681 goto try_to_scroll
;
12687 /* If current starting point was originally the beginning of a line
12688 but no longer is, find a new starting point. */
12689 else if (!NILP (w
->start_at_line_beg
)
12690 && !(CHARPOS (startp
) <= BEGV
12691 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
12694 debug_method_add (w
, "recenter 1");
12699 /* Try scrolling with try_window_id. Value is > 0 if update has
12700 been done, it is -1 if we know that the same window start will
12701 not work. It is 0 if unsuccessful for some other reason. */
12702 else if ((tem
= try_window_id (w
)) != 0)
12705 debug_method_add (w
, "try_window_id %d", tem
);
12708 if (fonts_changed_p
)
12709 goto need_larger_matrices
;
12713 /* Otherwise try_window_id has returned -1 which means that we
12714 don't want the alternative below this comment to execute. */
12716 else if (CHARPOS (startp
) >= BEGV
12717 && CHARPOS (startp
) <= ZV
12718 && PT
>= CHARPOS (startp
)
12719 && (CHARPOS (startp
) < ZV
12720 /* Avoid starting at end of buffer. */
12721 || CHARPOS (startp
) == BEGV
12722 || (XFASTINT (w
->last_modified
) >= MODIFF
12723 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
12726 debug_method_add (w
, "same window start");
12729 /* Try to redisplay starting at same place as before.
12730 If point has not moved off frame, accept the results. */
12731 if (!current_matrix_up_to_date_p
12732 /* Don't use try_window_reusing_current_matrix in this case
12733 because a window scroll function can have changed the
12735 || !NILP (Vwindow_scroll_functions
)
12736 || MINI_WINDOW_P (w
)
12737 || !(used_current_matrix_p
12738 = try_window_reusing_current_matrix (w
)))
12740 IF_DEBUG (debug_method_add (w
, "1"));
12741 if (try_window (window
, startp
, 1) < 0)
12742 /* -1 means we need to scroll.
12743 0 means we need new matrices, but fonts_changed_p
12744 is set in that case, so we will detect it below. */
12745 goto try_to_scroll
;
12748 if (fonts_changed_p
)
12749 goto need_larger_matrices
;
12751 if (w
->cursor
.vpos
>= 0)
12753 if (!just_this_one_p
12754 || current_buffer
->clip_changed
12755 || BEG_UNCHANGED
< CHARPOS (startp
))
12756 /* Forget any recorded base line for line number display. */
12757 w
->base_line_number
= Qnil
;
12759 if (!cursor_row_fully_visible_p (w
, 1, 0))
12761 clear_glyph_matrix (w
->desired_matrix
);
12762 last_line_misfit
= 1;
12764 /* Drop through and scroll. */
12769 clear_glyph_matrix (w
->desired_matrix
);
12774 w
->last_modified
= make_number (0);
12775 w
->last_overlay_modified
= make_number (0);
12777 /* Redisplay the mode line. Select the buffer properly for that. */
12778 if (!update_mode_line
)
12780 update_mode_line
= 1;
12781 w
->update_mode_line
= Qt
;
12784 /* Try to scroll by specified few lines. */
12785 if ((scroll_conservatively
12787 || temp_scroll_step
12788 || NUMBERP (current_buffer
->scroll_up_aggressively
)
12789 || NUMBERP (current_buffer
->scroll_down_aggressively
))
12790 && !current_buffer
->clip_changed
12791 && CHARPOS (startp
) >= BEGV
12792 && CHARPOS (startp
) <= ZV
)
12794 /* The function returns -1 if new fonts were loaded, 1 if
12795 successful, 0 if not successful. */
12796 int rc
= try_scrolling (window
, just_this_one_p
,
12797 scroll_conservatively
,
12799 temp_scroll_step
, last_line_misfit
);
12802 case SCROLLING_SUCCESS
:
12805 case SCROLLING_NEED_LARGER_MATRICES
:
12806 goto need_larger_matrices
;
12808 case SCROLLING_FAILED
:
12816 /* Finally, just choose place to start which centers point */
12819 if (centering_position
< 0)
12820 centering_position
= window_box_height (w
) / 2;
12823 debug_method_add (w
, "recenter");
12826 /* w->vscroll = 0; */
12828 /* Forget any previously recorded base line for line number display. */
12829 if (!buffer_unchanged_p
)
12830 w
->base_line_number
= Qnil
;
12832 /* Move backward half the height of the window. */
12833 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12834 it
.current_y
= it
.last_visible_y
;
12835 move_it_vertically_backward (&it
, centering_position
);
12836 xassert (IT_CHARPOS (it
) >= BEGV
);
12838 /* The function move_it_vertically_backward may move over more
12839 than the specified y-distance. If it->w is small, e.g. a
12840 mini-buffer window, we may end up in front of the window's
12841 display area. Start displaying at the start of the line
12842 containing PT in this case. */
12843 if (it
.current_y
<= 0)
12845 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12846 move_it_vertically_backward (&it
, 0);
12848 /* I think this assert is bogus if buffer contains
12849 invisible text or images. KFS. */
12850 xassert (IT_CHARPOS (it
) <= PT
);
12855 it
.current_x
= it
.hpos
= 0;
12857 /* Set startp here explicitly in case that helps avoid an infinite loop
12858 in case the window-scroll-functions functions get errors. */
12859 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
12861 /* Run scroll hooks. */
12862 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
12864 /* Redisplay the window. */
12865 if (!current_matrix_up_to_date_p
12866 || windows_or_buffers_changed
12867 || cursor_type_changed
12868 /* Don't use try_window_reusing_current_matrix in this case
12869 because it can have changed the buffer. */
12870 || !NILP (Vwindow_scroll_functions
)
12871 || !just_this_one_p
12872 || MINI_WINDOW_P (w
)
12873 || !(used_current_matrix_p
12874 = try_window_reusing_current_matrix (w
)))
12875 try_window (window
, startp
, 0);
12877 /* If new fonts have been loaded (due to fontsets), give up. We
12878 have to start a new redisplay since we need to re-adjust glyph
12880 if (fonts_changed_p
)
12881 goto need_larger_matrices
;
12883 /* If cursor did not appear assume that the middle of the window is
12884 in the first line of the window. Do it again with the next line.
12885 (Imagine a window of height 100, displaying two lines of height
12886 60. Moving back 50 from it->last_visible_y will end in the first
12888 if (w
->cursor
.vpos
< 0)
12890 if (!NILP (w
->window_end_valid
)
12891 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
12893 clear_glyph_matrix (w
->desired_matrix
);
12894 move_it_by_lines (&it
, 1, 0);
12895 try_window (window
, it
.current
.pos
, 0);
12897 else if (PT
< IT_CHARPOS (it
))
12899 clear_glyph_matrix (w
->desired_matrix
);
12900 move_it_by_lines (&it
, -1, 0);
12901 try_window (window
, it
.current
.pos
, 0);
12905 /* Not much we can do about it. */
12909 /* Consider the following case: Window starts at BEGV, there is
12910 invisible, intangible text at BEGV, so that display starts at
12911 some point START > BEGV. It can happen that we are called with
12912 PT somewhere between BEGV and START. Try to handle that case. */
12913 if (w
->cursor
.vpos
< 0)
12915 struct glyph_row
*row
= w
->current_matrix
->rows
;
12916 if (row
->mode_line_p
)
12918 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12921 if (!cursor_row_fully_visible_p (w
, 0, 0))
12923 /* If vscroll is enabled, disable it and try again. */
12927 clear_glyph_matrix (w
->desired_matrix
);
12931 /* If centering point failed to make the whole line visible,
12932 put point at the top instead. That has to make the whole line
12933 visible, if it can be done. */
12934 if (centering_position
== 0)
12937 clear_glyph_matrix (w
->desired_matrix
);
12938 centering_position
= 0;
12944 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12945 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
12946 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
12949 /* Display the mode line, if we must. */
12950 if ((update_mode_line
12951 /* If window not full width, must redo its mode line
12952 if (a) the window to its side is being redone and
12953 (b) we do a frame-based redisplay. This is a consequence
12954 of how inverted lines are drawn in frame-based redisplay. */
12955 || (!just_this_one_p
12956 && !FRAME_WINDOW_P (f
)
12957 && !WINDOW_FULL_WIDTH_P (w
))
12958 /* Line number to display. */
12959 || INTEGERP (w
->base_line_pos
)
12960 /* Column number is displayed and different from the one displayed. */
12961 || (!NILP (w
->column_number_displayed
)
12962 && (XFASTINT (w
->column_number_displayed
)
12963 != (int) current_column ()))) /* iftc */
12964 /* This means that the window has a mode line. */
12965 && (WINDOW_WANTS_MODELINE_P (w
)
12966 || WINDOW_WANTS_HEADER_LINE_P (w
)))
12968 display_mode_lines (w
);
12970 /* If mode line height has changed, arrange for a thorough
12971 immediate redisplay using the correct mode line height. */
12972 if (WINDOW_WANTS_MODELINE_P (w
)
12973 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
12975 fonts_changed_p
= 1;
12976 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
12977 = DESIRED_MODE_LINE_HEIGHT (w
);
12980 /* If top line height has changed, arrange for a thorough
12981 immediate redisplay using the correct mode line height. */
12982 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12983 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
12985 fonts_changed_p
= 1;
12986 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
12987 = DESIRED_HEADER_LINE_HEIGHT (w
);
12990 if (fonts_changed_p
)
12991 goto need_larger_matrices
;
12994 if (!line_number_displayed
12995 && !BUFFERP (w
->base_line_pos
))
12997 w
->base_line_pos
= Qnil
;
12998 w
->base_line_number
= Qnil
;
13003 /* When we reach a frame's selected window, redo the frame's menu bar. */
13004 if (update_mode_line
13005 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13007 int redisplay_menu_p
= 0;
13008 int redisplay_tool_bar_p
= 0;
13010 if (FRAME_WINDOW_P (f
))
13012 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
13013 || defined (USE_GTK)
13014 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13016 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13020 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13022 if (redisplay_menu_p
)
13023 display_menu_bar (w
);
13025 #ifdef HAVE_WINDOW_SYSTEM
13027 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13029 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13030 && (FRAME_TOOL_BAR_LINES (f
) > 0
13031 || auto_resize_tool_bars_p
);
13035 if (redisplay_tool_bar_p
)
13036 redisplay_tool_bar (f
);
13040 #ifdef HAVE_WINDOW_SYSTEM
13041 if (FRAME_WINDOW_P (f
)
13042 && update_window_fringes (w
, (just_this_one_p
13043 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13044 || w
->pseudo_window_p
)))
13048 if (draw_window_fringes (w
, 1))
13049 x_draw_vertical_border (w
);
13053 #endif /* HAVE_WINDOW_SYSTEM */
13055 /* We go to this label, with fonts_changed_p nonzero,
13056 if it is necessary to try again using larger glyph matrices.
13057 We have to redeem the scroll bar even in this case,
13058 because the loop in redisplay_internal expects that. */
13059 need_larger_matrices
:
13061 finish_scroll_bars
:
13063 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13065 /* Set the thumb's position and size. */
13066 set_vertical_scroll_bar (w
);
13068 /* Note that we actually used the scroll bar attached to this
13069 window, so it shouldn't be deleted at the end of redisplay. */
13070 redeem_scroll_bar_hook (w
);
13073 /* Restore current_buffer and value of point in it. */
13074 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13075 set_buffer_internal_1 (old
);
13076 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13078 unbind_to (count
, Qnil
);
13082 /* Build the complete desired matrix of WINDOW with a window start
13083 buffer position POS.
13085 Value is 1 if successful. It is zero if fonts were loaded during
13086 redisplay which makes re-adjusting glyph matrices necessary, and -1
13087 if point would appear in the scroll margins.
13088 (We check that only if CHECK_MARGINS is nonzero. */
13091 try_window (window
, pos
, check_margins
)
13092 Lisp_Object window
;
13093 struct text_pos pos
;
13096 struct window
*w
= XWINDOW (window
);
13098 struct glyph_row
*last_text_row
= NULL
;
13100 /* Make POS the new window start. */
13101 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13103 /* Mark cursor position as unknown. No overlay arrow seen. */
13104 w
->cursor
.vpos
= -1;
13105 overlay_arrow_seen
= 0;
13107 /* Initialize iterator and info to start at POS. */
13108 start_display (&it
, w
, pos
);
13110 /* Display all lines of W. */
13111 while (it
.current_y
< it
.last_visible_y
)
13113 if (display_line (&it
))
13114 last_text_row
= it
.glyph_row
- 1;
13115 if (fonts_changed_p
)
13119 /* Don't let the cursor end in the scroll margins. */
13121 && !MINI_WINDOW_P (w
))
13123 int this_scroll_margin
;
13125 this_scroll_margin
= max (0, scroll_margin
);
13126 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13127 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13129 if ((w
->cursor
.y
< this_scroll_margin
13130 && CHARPOS (pos
) > BEGV
13131 && IT_CHARPOS (it
) < ZV
)
13132 /* rms: considering make_cursor_line_fully_visible_p here
13133 seems to give wrong results. We don't want to recenter
13134 when the last line is partly visible, we want to allow
13135 that case to be handled in the usual way. */
13136 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
13138 w
->cursor
.vpos
= -1;
13139 clear_glyph_matrix (w
->desired_matrix
);
13144 /* If bottom moved off end of frame, change mode line percentage. */
13145 if (XFASTINT (w
->window_end_pos
) <= 0
13146 && Z
!= IT_CHARPOS (it
))
13147 w
->update_mode_line
= Qt
;
13149 /* Set window_end_pos to the offset of the last character displayed
13150 on the window from the end of current_buffer. Set
13151 window_end_vpos to its row number. */
13154 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
13155 w
->window_end_bytepos
13156 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13158 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13160 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13161 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
13162 ->displays_text_p
);
13166 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13167 w
->window_end_pos
= make_number (Z
- ZV
);
13168 w
->window_end_vpos
= make_number (0);
13171 /* But that is not valid info until redisplay finishes. */
13172 w
->window_end_valid
= Qnil
;
13178 /************************************************************************
13179 Window redisplay reusing current matrix when buffer has not changed
13180 ************************************************************************/
13182 /* Try redisplay of window W showing an unchanged buffer with a
13183 different window start than the last time it was displayed by
13184 reusing its current matrix. Value is non-zero if successful.
13185 W->start is the new window start. */
13188 try_window_reusing_current_matrix (w
)
13191 struct frame
*f
= XFRAME (w
->frame
);
13192 struct glyph_row
*row
, *bottom_row
;
13195 struct text_pos start
, new_start
;
13196 int nrows_scrolled
, i
;
13197 struct glyph_row
*last_text_row
;
13198 struct glyph_row
*last_reused_text_row
;
13199 struct glyph_row
*start_row
;
13200 int start_vpos
, min_y
, max_y
;
13203 if (inhibit_try_window_reusing
)
13207 if (/* This function doesn't handle terminal frames. */
13208 !FRAME_WINDOW_P (f
)
13209 /* Don't try to reuse the display if windows have been split
13211 || windows_or_buffers_changed
13212 || cursor_type_changed
)
13215 /* Can't do this if region may have changed. */
13216 if ((!NILP (Vtransient_mark_mode
)
13217 && !NILP (current_buffer
->mark_active
))
13218 || !NILP (w
->region_showing
)
13219 || !NILP (Vshow_trailing_whitespace
))
13222 /* If top-line visibility has changed, give up. */
13223 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13224 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
13227 /* Give up if old or new display is scrolled vertically. We could
13228 make this function handle this, but right now it doesn't. */
13229 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13230 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
13233 /* The variable new_start now holds the new window start. The old
13234 start `start' can be determined from the current matrix. */
13235 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
13236 start
= start_row
->start
.pos
;
13237 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13239 /* Clear the desired matrix for the display below. */
13240 clear_glyph_matrix (w
->desired_matrix
);
13242 if (CHARPOS (new_start
) <= CHARPOS (start
))
13246 /* Don't use this method if the display starts with an ellipsis
13247 displayed for invisible text. It's not easy to handle that case
13248 below, and it's certainly not worth the effort since this is
13249 not a frequent case. */
13250 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
13253 IF_DEBUG (debug_method_add (w
, "twu1"));
13255 /* Display up to a row that can be reused. The variable
13256 last_text_row is set to the last row displayed that displays
13257 text. Note that it.vpos == 0 if or if not there is a
13258 header-line; it's not the same as the MATRIX_ROW_VPOS! */
13259 start_display (&it
, w
, new_start
);
13260 first_row_y
= it
.current_y
;
13261 w
->cursor
.vpos
= -1;
13262 last_text_row
= last_reused_text_row
= NULL
;
13264 while (it
.current_y
< it
.last_visible_y
13265 && !fonts_changed_p
)
13267 /* If we have reached into the characters in the START row,
13268 that means the line boundaries have changed. So we
13269 can't start copying with the row START. Maybe it will
13270 work to start copying with the following row. */
13271 while (IT_CHARPOS (it
) > CHARPOS (start
))
13273 /* Advance to the next row as the "start". */
13275 start
= start_row
->start
.pos
;
13276 /* If there are no more rows to try, or just one, give up. */
13277 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
13278 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
13279 || CHARPOS (start
) == ZV
)
13281 clear_glyph_matrix (w
->desired_matrix
);
13285 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13287 /* If we have reached alignment,
13288 we can copy the rest of the rows. */
13289 if (IT_CHARPOS (it
) == CHARPOS (start
))
13292 if (display_line (&it
))
13293 last_text_row
= it
.glyph_row
- 1;
13296 /* A value of current_y < last_visible_y means that we stopped
13297 at the previous window start, which in turn means that we
13298 have at least one reusable row. */
13299 if (it
.current_y
< it
.last_visible_y
)
13301 /* IT.vpos always starts from 0; it counts text lines. */
13302 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
13304 /* Find PT if not already found in the lines displayed. */
13305 if (w
->cursor
.vpos
< 0)
13307 int dy
= it
.current_y
- start_row
->y
;
13309 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13310 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
13312 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
13313 dy
, nrows_scrolled
);
13316 clear_glyph_matrix (w
->desired_matrix
);
13321 /* Scroll the display. Do it before the current matrix is
13322 changed. The problem here is that update has not yet
13323 run, i.e. part of the current matrix is not up to date.
13324 scroll_run_hook will clear the cursor, and use the
13325 current matrix to get the height of the row the cursor is
13327 run
.current_y
= start_row
->y
;
13328 run
.desired_y
= it
.current_y
;
13329 run
.height
= it
.last_visible_y
- it
.current_y
;
13331 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
13334 rif
->update_window_begin_hook (w
);
13335 rif
->clear_window_mouse_face (w
);
13336 rif
->scroll_run_hook (w
, &run
);
13337 rif
->update_window_end_hook (w
, 0, 0);
13341 /* Shift current matrix down by nrows_scrolled lines. */
13342 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13343 rotate_matrix (w
->current_matrix
,
13345 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13348 /* Disable lines that must be updated. */
13349 for (i
= 0; i
< it
.vpos
; ++i
)
13350 (start_row
+ i
)->enabled_p
= 0;
13352 /* Re-compute Y positions. */
13353 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13354 max_y
= it
.last_visible_y
;
13355 for (row
= start_row
+ nrows_scrolled
;
13359 row
->y
= it
.current_y
;
13360 row
->visible_height
= row
->height
;
13362 if (row
->y
< min_y
)
13363 row
->visible_height
-= min_y
- row
->y
;
13364 if (row
->y
+ row
->height
> max_y
)
13365 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13366 row
->redraw_fringe_bitmaps_p
= 1;
13368 it
.current_y
+= row
->height
;
13370 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13371 last_reused_text_row
= row
;
13372 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13376 /* Disable lines in the current matrix which are now
13377 below the window. */
13378 for (++row
; row
< bottom_row
; ++row
)
13379 row
->enabled_p
= row
->mode_line_p
= 0;
13382 /* Update window_end_pos etc.; last_reused_text_row is the last
13383 reused row from the current matrix containing text, if any.
13384 The value of last_text_row is the last displayed line
13385 containing text. */
13386 if (last_reused_text_row
)
13388 w
->window_end_bytepos
13389 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13391 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13393 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13394 w
->current_matrix
));
13396 else if (last_text_row
)
13398 w
->window_end_bytepos
13399 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13401 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13403 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13407 /* This window must be completely empty. */
13408 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13409 w
->window_end_pos
= make_number (Z
- ZV
);
13410 w
->window_end_vpos
= make_number (0);
13412 w
->window_end_valid
= Qnil
;
13414 /* Update hint: don't try scrolling again in update_window. */
13415 w
->desired_matrix
->no_scrolling_p
= 1;
13418 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13422 else if (CHARPOS (new_start
) > CHARPOS (start
))
13424 struct glyph_row
*pt_row
, *row
;
13425 struct glyph_row
*first_reusable_row
;
13426 struct glyph_row
*first_row_to_display
;
13428 int yb
= window_text_bottom_y (w
);
13430 /* Find the row starting at new_start, if there is one. Don't
13431 reuse a partially visible line at the end. */
13432 first_reusable_row
= start_row
;
13433 while (first_reusable_row
->enabled_p
13434 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13435 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13436 < CHARPOS (new_start
)))
13437 ++first_reusable_row
;
13439 /* Give up if there is no row to reuse. */
13440 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13441 || !first_reusable_row
->enabled_p
13442 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13443 != CHARPOS (new_start
)))
13446 /* We can reuse fully visible rows beginning with
13447 first_reusable_row to the end of the window. Set
13448 first_row_to_display to the first row that cannot be reused.
13449 Set pt_row to the row containing point, if there is any. */
13451 for (first_row_to_display
= first_reusable_row
;
13452 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13453 ++first_row_to_display
)
13455 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
13456 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
13457 pt_row
= first_row_to_display
;
13460 /* Start displaying at the start of first_row_to_display. */
13461 xassert (first_row_to_display
->y
< yb
);
13462 init_to_row_start (&it
, w
, first_row_to_display
);
13464 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
13466 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
13468 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
13469 + WINDOW_HEADER_LINE_HEIGHT (w
));
13471 /* Display lines beginning with first_row_to_display in the
13472 desired matrix. Set last_text_row to the last row displayed
13473 that displays text. */
13474 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
13475 if (pt_row
== NULL
)
13476 w
->cursor
.vpos
= -1;
13477 last_text_row
= NULL
;
13478 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
13479 if (display_line (&it
))
13480 last_text_row
= it
.glyph_row
- 1;
13482 /* Give up If point isn't in a row displayed or reused. */
13483 if (w
->cursor
.vpos
< 0)
13485 clear_glyph_matrix (w
->desired_matrix
);
13489 /* If point is in a reused row, adjust y and vpos of the cursor
13493 w
->cursor
.vpos
-= nrows_scrolled
;
13494 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
13497 /* Scroll the display. */
13498 run
.current_y
= first_reusable_row
->y
;
13499 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13500 run
.height
= it
.last_visible_y
- run
.current_y
;
13501 dy
= run
.current_y
- run
.desired_y
;
13506 rif
->update_window_begin_hook (w
);
13507 rif
->clear_window_mouse_face (w
);
13508 rif
->scroll_run_hook (w
, &run
);
13509 rif
->update_window_end_hook (w
, 0, 0);
13513 /* Adjust Y positions of reused rows. */
13514 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13515 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13516 max_y
= it
.last_visible_y
;
13517 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
13520 row
->visible_height
= row
->height
;
13521 if (row
->y
< min_y
)
13522 row
->visible_height
-= min_y
- row
->y
;
13523 if (row
->y
+ row
->height
> max_y
)
13524 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13525 row
->redraw_fringe_bitmaps_p
= 1;
13528 /* Scroll the current matrix. */
13529 xassert (nrows_scrolled
> 0);
13530 rotate_matrix (w
->current_matrix
,
13532 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13535 /* Disable rows not reused. */
13536 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
13537 row
->enabled_p
= 0;
13539 /* Point may have moved to a different line, so we cannot assume that
13540 the previous cursor position is valid; locate the correct row. */
13543 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
13544 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
13548 w
->cursor
.y
= row
->y
;
13550 if (row
< bottom_row
)
13552 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
13553 while (glyph
->charpos
< PT
)
13556 w
->cursor
.x
+= glyph
->pixel_width
;
13562 /* Adjust window end. A null value of last_text_row means that
13563 the window end is in reused rows which in turn means that
13564 only its vpos can have changed. */
13567 w
->window_end_bytepos
13568 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13570 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13572 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13577 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
13580 w
->window_end_valid
= Qnil
;
13581 w
->desired_matrix
->no_scrolling_p
= 1;
13584 debug_method_add (w
, "try_window_reusing_current_matrix 2");
13594 /************************************************************************
13595 Window redisplay reusing current matrix when buffer has changed
13596 ************************************************************************/
13598 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
13599 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
13601 static struct glyph_row
*
13602 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
13603 struct glyph_row
*));
13606 /* Return the last row in MATRIX displaying text. If row START is
13607 non-null, start searching with that row. IT gives the dimensions
13608 of the display. Value is null if matrix is empty; otherwise it is
13609 a pointer to the row found. */
13611 static struct glyph_row
*
13612 find_last_row_displaying_text (matrix
, it
, start
)
13613 struct glyph_matrix
*matrix
;
13615 struct glyph_row
*start
;
13617 struct glyph_row
*row
, *row_found
;
13619 /* Set row_found to the last row in IT->w's current matrix
13620 displaying text. The loop looks funny but think of partially
13623 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
13624 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13626 xassert (row
->enabled_p
);
13628 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
13637 /* Return the last row in the current matrix of W that is not affected
13638 by changes at the start of current_buffer that occurred since W's
13639 current matrix was built. Value is null if no such row exists.
13641 BEG_UNCHANGED us the number of characters unchanged at the start of
13642 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
13643 first changed character in current_buffer. Characters at positions <
13644 BEG + BEG_UNCHANGED are at the same buffer positions as they were
13645 when the current matrix was built. */
13647 static struct glyph_row
*
13648 find_last_unchanged_at_beg_row (w
)
13651 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
13652 struct glyph_row
*row
;
13653 struct glyph_row
*row_found
= NULL
;
13654 int yb
= window_text_bottom_y (w
);
13656 /* Find the last row displaying unchanged text. */
13657 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13658 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13659 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
13661 if (/* If row ends before first_changed_pos, it is unchanged,
13662 except in some case. */
13663 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
13664 /* When row ends in ZV and we write at ZV it is not
13666 && !row
->ends_at_zv_p
13667 /* When first_changed_pos is the end of a continued line,
13668 row is not unchanged because it may be no longer
13670 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
13671 && (row
->continued_p
13672 || row
->exact_window_width_line_p
)))
13675 /* Stop if last visible row. */
13676 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
13686 /* Find the first glyph row in the current matrix of W that is not
13687 affected by changes at the end of current_buffer since the
13688 time W's current matrix was built.
13690 Return in *DELTA the number of chars by which buffer positions in
13691 unchanged text at the end of current_buffer must be adjusted.
13693 Return in *DELTA_BYTES the corresponding number of bytes.
13695 Value is null if no such row exists, i.e. all rows are affected by
13698 static struct glyph_row
*
13699 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
13701 int *delta
, *delta_bytes
;
13703 struct glyph_row
*row
;
13704 struct glyph_row
*row_found
= NULL
;
13706 *delta
= *delta_bytes
= 0;
13708 /* Display must not have been paused, otherwise the current matrix
13709 is not up to date. */
13710 if (NILP (w
->window_end_valid
))
13713 /* A value of window_end_pos >= END_UNCHANGED means that the window
13714 end is in the range of changed text. If so, there is no
13715 unchanged row at the end of W's current matrix. */
13716 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
13719 /* Set row to the last row in W's current matrix displaying text. */
13720 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13722 /* If matrix is entirely empty, no unchanged row exists. */
13723 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13725 /* The value of row is the last glyph row in the matrix having a
13726 meaningful buffer position in it. The end position of row
13727 corresponds to window_end_pos. This allows us to translate
13728 buffer positions in the current matrix to current buffer
13729 positions for characters not in changed text. */
13730 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13731 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13732 int last_unchanged_pos
, last_unchanged_pos_old
;
13733 struct glyph_row
*first_text_row
13734 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13736 *delta
= Z
- Z_old
;
13737 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13739 /* Set last_unchanged_pos to the buffer position of the last
13740 character in the buffer that has not been changed. Z is the
13741 index + 1 of the last character in current_buffer, i.e. by
13742 subtracting END_UNCHANGED we get the index of the last
13743 unchanged character, and we have to add BEG to get its buffer
13745 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
13746 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
13748 /* Search backward from ROW for a row displaying a line that
13749 starts at a minimum position >= last_unchanged_pos_old. */
13750 for (; row
> first_text_row
; --row
)
13752 /* This used to abort, but it can happen.
13753 It is ok to just stop the search instead here. KFS. */
13754 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13757 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
13762 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
13769 /* Make sure that glyph rows in the current matrix of window W
13770 reference the same glyph memory as corresponding rows in the
13771 frame's frame matrix. This function is called after scrolling W's
13772 current matrix on a terminal frame in try_window_id and
13773 try_window_reusing_current_matrix. */
13776 sync_frame_with_window_matrix_rows (w
)
13779 struct frame
*f
= XFRAME (w
->frame
);
13780 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
13782 /* Preconditions: W must be a leaf window and full-width. Its frame
13783 must have a frame matrix. */
13784 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
13785 xassert (WINDOW_FULL_WIDTH_P (w
));
13786 xassert (!FRAME_WINDOW_P (f
));
13788 /* If W is a full-width window, glyph pointers in W's current matrix
13789 have, by definition, to be the same as glyph pointers in the
13790 corresponding frame matrix. Note that frame matrices have no
13791 marginal areas (see build_frame_matrix). */
13792 window_row
= w
->current_matrix
->rows
;
13793 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
13794 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
13795 while (window_row
< window_row_end
)
13797 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
13798 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
13800 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
13801 frame_row
->glyphs
[TEXT_AREA
] = start
;
13802 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
13803 frame_row
->glyphs
[LAST_AREA
] = end
;
13805 /* Disable frame rows whose corresponding window rows have
13806 been disabled in try_window_id. */
13807 if (!window_row
->enabled_p
)
13808 frame_row
->enabled_p
= 0;
13810 ++window_row
, ++frame_row
;
13815 /* Find the glyph row in window W containing CHARPOS. Consider all
13816 rows between START and END (not inclusive). END null means search
13817 all rows to the end of the display area of W. Value is the row
13818 containing CHARPOS or null. */
13821 row_containing_pos (w
, charpos
, start
, end
, dy
)
13824 struct glyph_row
*start
, *end
;
13827 struct glyph_row
*row
= start
;
13830 /* If we happen to start on a header-line, skip that. */
13831 if (row
->mode_line_p
)
13834 if ((end
&& row
>= end
) || !row
->enabled_p
)
13837 last_y
= window_text_bottom_y (w
) - dy
;
13841 /* Give up if we have gone too far. */
13842 if (end
&& row
>= end
)
13844 /* This formerly returned if they were equal.
13845 I think that both quantities are of a "last plus one" type;
13846 if so, when they are equal, the row is within the screen. -- rms. */
13847 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
13850 /* If it is in this row, return this row. */
13851 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
13852 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
13853 /* The end position of a row equals the start
13854 position of the next row. If CHARPOS is there, we
13855 would rather display it in the next line, except
13856 when this line ends in ZV. */
13857 && !row
->ends_at_zv_p
13858 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13859 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
13866 /* Try to redisplay window W by reusing its existing display. W's
13867 current matrix must be up to date when this function is called,
13868 i.e. window_end_valid must not be nil.
13872 1 if display has been updated
13873 0 if otherwise unsuccessful
13874 -1 if redisplay with same window start is known not to succeed
13876 The following steps are performed:
13878 1. Find the last row in the current matrix of W that is not
13879 affected by changes at the start of current_buffer. If no such row
13882 2. Find the first row in W's current matrix that is not affected by
13883 changes at the end of current_buffer. Maybe there is no such row.
13885 3. Display lines beginning with the row + 1 found in step 1 to the
13886 row found in step 2 or, if step 2 didn't find a row, to the end of
13889 4. If cursor is not known to appear on the window, give up.
13891 5. If display stopped at the row found in step 2, scroll the
13892 display and current matrix as needed.
13894 6. Maybe display some lines at the end of W, if we must. This can
13895 happen under various circumstances, like a partially visible line
13896 becoming fully visible, or because newly displayed lines are displayed
13897 in smaller font sizes.
13899 7. Update W's window end information. */
13905 struct frame
*f
= XFRAME (w
->frame
);
13906 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
13907 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
13908 struct glyph_row
*last_unchanged_at_beg_row
;
13909 struct glyph_row
*first_unchanged_at_end_row
;
13910 struct glyph_row
*row
;
13911 struct glyph_row
*bottom_row
;
13914 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
13915 struct text_pos start_pos
;
13917 int first_unchanged_at_end_vpos
= 0;
13918 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
13919 struct text_pos start
;
13920 int first_changed_charpos
, last_changed_charpos
;
13923 if (inhibit_try_window_id
)
13927 /* This is handy for debugging. */
13929 #define GIVE_UP(X) \
13931 fprintf (stderr, "try_window_id give up %d\n", (X)); \
13935 #define GIVE_UP(X) return 0
13938 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
13940 /* Don't use this for mini-windows because these can show
13941 messages and mini-buffers, and we don't handle that here. */
13942 if (MINI_WINDOW_P (w
))
13945 /* This flag is used to prevent redisplay optimizations. */
13946 if (windows_or_buffers_changed
|| cursor_type_changed
)
13949 /* Verify that narrowing has not changed.
13950 Also verify that we were not told to prevent redisplay optimizations.
13951 It would be nice to further
13952 reduce the number of cases where this prevents try_window_id. */
13953 if (current_buffer
->clip_changed
13954 || current_buffer
->prevent_redisplay_optimizations_p
)
13957 /* Window must either use window-based redisplay or be full width. */
13958 if (!FRAME_WINDOW_P (f
)
13959 && (!line_ins_del_ok
13960 || !WINDOW_FULL_WIDTH_P (w
)))
13963 /* Give up if point is not known NOT to appear in W. */
13964 if (PT
< CHARPOS (start
))
13967 /* Another way to prevent redisplay optimizations. */
13968 if (XFASTINT (w
->last_modified
) == 0)
13971 /* Verify that window is not hscrolled. */
13972 if (XFASTINT (w
->hscroll
) != 0)
13975 /* Verify that display wasn't paused. */
13976 if (NILP (w
->window_end_valid
))
13979 /* Can't use this if highlighting a region because a cursor movement
13980 will do more than just set the cursor. */
13981 if (!NILP (Vtransient_mark_mode
)
13982 && !NILP (current_buffer
->mark_active
))
13985 /* Likewise if highlighting trailing whitespace. */
13986 if (!NILP (Vshow_trailing_whitespace
))
13989 /* Likewise if showing a region. */
13990 if (!NILP (w
->region_showing
))
13993 /* Can use this if overlay arrow position and or string have changed. */
13994 if (overlay_arrows_changed_p ())
13998 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
13999 only if buffer has really changed. The reason is that the gap is
14000 initially at Z for freshly visited files. The code below would
14001 set end_unchanged to 0 in that case. */
14002 if (MODIFF
> SAVE_MODIFF
14003 /* This seems to happen sometimes after saving a buffer. */
14004 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14006 if (GPT
- BEG
< BEG_UNCHANGED
)
14007 BEG_UNCHANGED
= GPT
- BEG
;
14008 if (Z
- GPT
< END_UNCHANGED
)
14009 END_UNCHANGED
= Z
- GPT
;
14012 /* The position of the first and last character that has been changed. */
14013 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14014 last_changed_charpos
= Z
- END_UNCHANGED
;
14016 /* If window starts after a line end, and the last change is in
14017 front of that newline, then changes don't affect the display.
14018 This case happens with stealth-fontification. Note that although
14019 the display is unchanged, glyph positions in the matrix have to
14020 be adjusted, of course. */
14021 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14022 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14023 && ((last_changed_charpos
< CHARPOS (start
)
14024 && CHARPOS (start
) == BEGV
)
14025 || (last_changed_charpos
< CHARPOS (start
) - 1
14026 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14028 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14029 struct glyph_row
*r0
;
14031 /* Compute how many chars/bytes have been added to or removed
14032 from the buffer. */
14033 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14034 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14036 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14038 /* Give up if PT is not in the window. Note that it already has
14039 been checked at the start of try_window_id that PT is not in
14040 front of the window start. */
14041 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14044 /* If window start is unchanged, we can reuse the whole matrix
14045 as is, after adjusting glyph positions. No need to compute
14046 the window end again, since its offset from Z hasn't changed. */
14047 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14048 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14049 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14050 /* PT must not be in a partially visible line. */
14051 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14052 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14054 /* Adjust positions in the glyph matrix. */
14055 if (delta
|| delta_bytes
)
14057 struct glyph_row
*r1
14058 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14059 increment_matrix_positions (w
->current_matrix
,
14060 MATRIX_ROW_VPOS (r0
, current_matrix
),
14061 MATRIX_ROW_VPOS (r1
, current_matrix
),
14062 delta
, delta_bytes
);
14065 /* Set the cursor. */
14066 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14068 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14075 /* Handle the case that changes are all below what is displayed in
14076 the window, and that PT is in the window. This shortcut cannot
14077 be taken if ZV is visible in the window, and text has been added
14078 there that is visible in the window. */
14079 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14080 /* ZV is not visible in the window, or there are no
14081 changes at ZV, actually. */
14082 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14083 || first_changed_charpos
== last_changed_charpos
))
14085 struct glyph_row
*r0
;
14087 /* Give up if PT is not in the window. Note that it already has
14088 been checked at the start of try_window_id that PT is not in
14089 front of the window start. */
14090 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14093 /* If window start is unchanged, we can reuse the whole matrix
14094 as is, without changing glyph positions since no text has
14095 been added/removed in front of the window end. */
14096 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14097 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14098 /* PT must not be in a partially visible line. */
14099 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14100 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14102 /* We have to compute the window end anew since text
14103 can have been added/removed after it. */
14105 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14106 w
->window_end_bytepos
14107 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14109 /* Set the cursor. */
14110 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14112 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14119 /* Give up if window start is in the changed area.
14121 The condition used to read
14123 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
14125 but why that was tested escapes me at the moment. */
14126 if (CHARPOS (start
) >= first_changed_charpos
14127 && CHARPOS (start
) <= last_changed_charpos
)
14130 /* Check that window start agrees with the start of the first glyph
14131 row in its current matrix. Check this after we know the window
14132 start is not in changed text, otherwise positions would not be
14134 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14135 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
14138 /* Give up if the window ends in strings. Overlay strings
14139 at the end are difficult to handle, so don't try. */
14140 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
14141 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
14144 /* Compute the position at which we have to start displaying new
14145 lines. Some of the lines at the top of the window might be
14146 reusable because they are not displaying changed text. Find the
14147 last row in W's current matrix not affected by changes at the
14148 start of current_buffer. Value is null if changes start in the
14149 first line of window. */
14150 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
14151 if (last_unchanged_at_beg_row
)
14153 /* Avoid starting to display in the moddle of a character, a TAB
14154 for instance. This is easier than to set up the iterator
14155 exactly, and it's not a frequent case, so the additional
14156 effort wouldn't really pay off. */
14157 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
14158 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
14159 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
14160 --last_unchanged_at_beg_row
;
14162 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
14165 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
14167 start_pos
= it
.current
.pos
;
14169 /* Start displaying new lines in the desired matrix at the same
14170 vpos we would use in the current matrix, i.e. below
14171 last_unchanged_at_beg_row. */
14172 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
14174 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14175 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
14177 xassert (it
.hpos
== 0 && it
.current_x
== 0);
14181 /* There are no reusable lines at the start of the window.
14182 Start displaying in the first text line. */
14183 start_display (&it
, w
, start
);
14184 it
.vpos
= it
.first_vpos
;
14185 start_pos
= it
.current
.pos
;
14188 /* Find the first row that is not affected by changes at the end of
14189 the buffer. Value will be null if there is no unchanged row, in
14190 which case we must redisplay to the end of the window. delta
14191 will be set to the value by which buffer positions beginning with
14192 first_unchanged_at_end_row have to be adjusted due to text
14194 first_unchanged_at_end_row
14195 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
14196 IF_DEBUG (debug_delta
= delta
);
14197 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
14199 /* Set stop_pos to the buffer position up to which we will have to
14200 display new lines. If first_unchanged_at_end_row != NULL, this
14201 is the buffer position of the start of the line displayed in that
14202 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
14203 that we don't stop at a buffer position. */
14205 if (first_unchanged_at_end_row
)
14207 xassert (last_unchanged_at_beg_row
== NULL
14208 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
14210 /* If this is a continuation line, move forward to the next one
14211 that isn't. Changes in lines above affect this line.
14212 Caution: this may move first_unchanged_at_end_row to a row
14213 not displaying text. */
14214 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
14215 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14216 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14217 < it
.last_visible_y
))
14218 ++first_unchanged_at_end_row
;
14220 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14221 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14222 >= it
.last_visible_y
))
14223 first_unchanged_at_end_row
= NULL
;
14226 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
14228 first_unchanged_at_end_vpos
14229 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
14230 xassert (stop_pos
>= Z
- END_UNCHANGED
);
14233 else if (last_unchanged_at_beg_row
== NULL
)
14239 /* Either there is no unchanged row at the end, or the one we have
14240 now displays text. This is a necessary condition for the window
14241 end pos calculation at the end of this function. */
14242 xassert (first_unchanged_at_end_row
== NULL
14243 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
14245 debug_last_unchanged_at_beg_vpos
14246 = (last_unchanged_at_beg_row
14247 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
14249 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
14251 #endif /* GLYPH_DEBUG != 0 */
14254 /* Display new lines. Set last_text_row to the last new line
14255 displayed which has text on it, i.e. might end up as being the
14256 line where the window_end_vpos is. */
14257 w
->cursor
.vpos
= -1;
14258 last_text_row
= NULL
;
14259 overlay_arrow_seen
= 0;
14260 while (it
.current_y
< it
.last_visible_y
14261 && !fonts_changed_p
14262 && (first_unchanged_at_end_row
== NULL
14263 || IT_CHARPOS (it
) < stop_pos
))
14265 if (display_line (&it
))
14266 last_text_row
= it
.glyph_row
- 1;
14269 if (fonts_changed_p
)
14273 /* Compute differences in buffer positions, y-positions etc. for
14274 lines reused at the bottom of the window. Compute what we can
14276 if (first_unchanged_at_end_row
14277 /* No lines reused because we displayed everything up to the
14278 bottom of the window. */
14279 && it
.current_y
< it
.last_visible_y
)
14282 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
14284 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
14285 run
.current_y
= first_unchanged_at_end_row
->y
;
14286 run
.desired_y
= run
.current_y
+ dy
;
14287 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
14291 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
14292 first_unchanged_at_end_row
= NULL
;
14294 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
14297 /* Find the cursor if not already found. We have to decide whether
14298 PT will appear on this window (it sometimes doesn't, but this is
14299 not a very frequent case.) This decision has to be made before
14300 the current matrix is altered. A value of cursor.vpos < 0 means
14301 that PT is either in one of the lines beginning at
14302 first_unchanged_at_end_row or below the window. Don't care for
14303 lines that might be displayed later at the window end; as
14304 mentioned, this is not a frequent case. */
14305 if (w
->cursor
.vpos
< 0)
14307 /* Cursor in unchanged rows at the top? */
14308 if (PT
< CHARPOS (start_pos
)
14309 && last_unchanged_at_beg_row
)
14311 row
= row_containing_pos (w
, PT
,
14312 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
14313 last_unchanged_at_beg_row
+ 1, 0);
14315 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14318 /* Start from first_unchanged_at_end_row looking for PT. */
14319 else if (first_unchanged_at_end_row
)
14321 row
= row_containing_pos (w
, PT
- delta
,
14322 first_unchanged_at_end_row
, NULL
, 0);
14324 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
14325 delta_bytes
, dy
, dvpos
);
14328 /* Give up if cursor was not found. */
14329 if (w
->cursor
.vpos
< 0)
14331 clear_glyph_matrix (w
->desired_matrix
);
14336 /* Don't let the cursor end in the scroll margins. */
14338 int this_scroll_margin
, cursor_height
;
14340 this_scroll_margin
= max (0, scroll_margin
);
14341 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14342 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14343 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
14345 if ((w
->cursor
.y
< this_scroll_margin
14346 && CHARPOS (start
) > BEGV
)
14347 /* Old redisplay didn't take scroll margin into account at the bottom,
14348 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14349 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14350 ? cursor_height
+ this_scroll_margin
14351 : 1)) > it
.last_visible_y
)
14353 w
->cursor
.vpos
= -1;
14354 clear_glyph_matrix (w
->desired_matrix
);
14359 /* Scroll the display. Do it before changing the current matrix so
14360 that xterm.c doesn't get confused about where the cursor glyph is
14362 if (dy
&& run
.height
)
14366 if (FRAME_WINDOW_P (f
))
14368 rif
->update_window_begin_hook (w
);
14369 rif
->clear_window_mouse_face (w
);
14370 rif
->scroll_run_hook (w
, &run
);
14371 rif
->update_window_end_hook (w
, 0, 0);
14375 /* Terminal frame. In this case, dvpos gives the number of
14376 lines to scroll by; dvpos < 0 means scroll up. */
14377 int first_unchanged_at_end_vpos
14378 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14379 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14380 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14381 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14382 + window_internal_height (w
));
14384 /* Perform the operation on the screen. */
14387 /* Scroll last_unchanged_at_beg_row to the end of the
14388 window down dvpos lines. */
14389 set_terminal_window (end
);
14391 /* On dumb terminals delete dvpos lines at the end
14392 before inserting dvpos empty lines. */
14393 if (!scroll_region_ok
)
14394 ins_del_lines (end
- dvpos
, -dvpos
);
14396 /* Insert dvpos empty lines in front of
14397 last_unchanged_at_beg_row. */
14398 ins_del_lines (from
, dvpos
);
14400 else if (dvpos
< 0)
14402 /* Scroll up last_unchanged_at_beg_vpos to the end of
14403 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14404 set_terminal_window (end
);
14406 /* Delete dvpos lines in front of
14407 last_unchanged_at_beg_vpos. ins_del_lines will set
14408 the cursor to the given vpos and emit |dvpos| delete
14410 ins_del_lines (from
+ dvpos
, dvpos
);
14412 /* On a dumb terminal insert dvpos empty lines at the
14414 if (!scroll_region_ok
)
14415 ins_del_lines (end
+ dvpos
, -dvpos
);
14418 set_terminal_window (0);
14424 /* Shift reused rows of the current matrix to the right position.
14425 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14427 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14428 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14431 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14432 bottom_vpos
, dvpos
);
14433 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14436 else if (dvpos
> 0)
14438 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14439 bottom_vpos
, dvpos
);
14440 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14441 first_unchanged_at_end_vpos
+ dvpos
, 0);
14444 /* For frame-based redisplay, make sure that current frame and window
14445 matrix are in sync with respect to glyph memory. */
14446 if (!FRAME_WINDOW_P (f
))
14447 sync_frame_with_window_matrix_rows (w
);
14449 /* Adjust buffer positions in reused rows. */
14451 increment_matrix_positions (current_matrix
,
14452 first_unchanged_at_end_vpos
+ dvpos
,
14453 bottom_vpos
, delta
, delta_bytes
);
14455 /* Adjust Y positions. */
14457 shift_glyph_matrix (w
, current_matrix
,
14458 first_unchanged_at_end_vpos
+ dvpos
,
14461 if (first_unchanged_at_end_row
)
14463 first_unchanged_at_end_row
+= dvpos
;
14464 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
14465 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
14466 first_unchanged_at_end_row
= NULL
;
14469 /* If scrolling up, there may be some lines to display at the end of
14471 last_text_row_at_end
= NULL
;
14474 /* Scrolling up can leave for example a partially visible line
14475 at the end of the window to be redisplayed. */
14476 /* Set last_row to the glyph row in the current matrix where the
14477 window end line is found. It has been moved up or down in
14478 the matrix by dvpos. */
14479 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
14480 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
14482 /* If last_row is the window end line, it should display text. */
14483 xassert (last_row
->displays_text_p
);
14485 /* If window end line was partially visible before, begin
14486 displaying at that line. Otherwise begin displaying with the
14487 line following it. */
14488 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
14490 init_to_row_start (&it
, w
, last_row
);
14491 it
.vpos
= last_vpos
;
14492 it
.current_y
= last_row
->y
;
14496 init_to_row_end (&it
, w
, last_row
);
14497 it
.vpos
= 1 + last_vpos
;
14498 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
14502 /* We may start in a continuation line. If so, we have to
14503 get the right continuation_lines_width and current_x. */
14504 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
14505 it
.hpos
= it
.current_x
= 0;
14507 /* Display the rest of the lines at the window end. */
14508 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14509 while (it
.current_y
< it
.last_visible_y
14510 && !fonts_changed_p
)
14512 /* Is it always sure that the display agrees with lines in
14513 the current matrix? I don't think so, so we mark rows
14514 displayed invalid in the current matrix by setting their
14515 enabled_p flag to zero. */
14516 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
14517 if (display_line (&it
))
14518 last_text_row_at_end
= it
.glyph_row
- 1;
14522 /* Update window_end_pos and window_end_vpos. */
14523 if (first_unchanged_at_end_row
14524 && !last_text_row_at_end
)
14526 /* Window end line if one of the preserved rows from the current
14527 matrix. Set row to the last row displaying text in current
14528 matrix starting at first_unchanged_at_end_row, after
14530 xassert (first_unchanged_at_end_row
->displays_text_p
);
14531 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
14532 first_unchanged_at_end_row
);
14533 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
14535 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14536 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14538 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
14539 xassert (w
->window_end_bytepos
>= 0);
14540 IF_DEBUG (debug_method_add (w
, "A"));
14542 else if (last_text_row_at_end
)
14545 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
14546 w
->window_end_bytepos
14547 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
14549 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
14550 xassert (w
->window_end_bytepos
>= 0);
14551 IF_DEBUG (debug_method_add (w
, "B"));
14553 else if (last_text_row
)
14555 /* We have displayed either to the end of the window or at the
14556 end of the window, i.e. the last row with text is to be found
14557 in the desired matrix. */
14559 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14560 w
->window_end_bytepos
14561 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14563 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
14564 xassert (w
->window_end_bytepos
>= 0);
14566 else if (first_unchanged_at_end_row
== NULL
14567 && last_text_row
== NULL
14568 && last_text_row_at_end
== NULL
)
14570 /* Displayed to end of window, but no line containing text was
14571 displayed. Lines were deleted at the end of the window. */
14572 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
14573 int vpos
= XFASTINT (w
->window_end_vpos
);
14574 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
14575 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
14578 row
== NULL
&& vpos
>= first_vpos
;
14579 --vpos
, --current_row
, --desired_row
)
14581 if (desired_row
->enabled_p
)
14583 if (desired_row
->displays_text_p
)
14586 else if (current_row
->displays_text_p
)
14590 xassert (row
!= NULL
);
14591 w
->window_end_vpos
= make_number (vpos
+ 1);
14592 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14593 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14594 xassert (w
->window_end_bytepos
>= 0);
14595 IF_DEBUG (debug_method_add (w
, "C"));
14600 #if 0 /* This leads to problems, for instance when the cursor is
14601 at ZV, and the cursor line displays no text. */
14602 /* Disable rows below what's displayed in the window. This makes
14603 debugging easier. */
14604 enable_glyph_matrix_rows (current_matrix
,
14605 XFASTINT (w
->window_end_vpos
) + 1,
14609 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
14610 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
14612 /* Record that display has not been completed. */
14613 w
->window_end_valid
= Qnil
;
14614 w
->desired_matrix
->no_scrolling_p
= 1;
14622 /***********************************************************************
14623 More debugging support
14624 ***********************************************************************/
14628 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
14629 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
14630 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
14633 /* Dump the contents of glyph matrix MATRIX on stderr.
14635 GLYPHS 0 means don't show glyph contents.
14636 GLYPHS 1 means show glyphs in short form
14637 GLYPHS > 1 means show glyphs in long form. */
14640 dump_glyph_matrix (matrix
, glyphs
)
14641 struct glyph_matrix
*matrix
;
14645 for (i
= 0; i
< matrix
->nrows
; ++i
)
14646 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
14650 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
14651 the glyph row and area where the glyph comes from. */
14654 dump_glyph (row
, glyph
, area
)
14655 struct glyph_row
*row
;
14656 struct glyph
*glyph
;
14659 if (glyph
->type
== CHAR_GLYPH
)
14662 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14663 glyph
- row
->glyphs
[TEXT_AREA
],
14666 (BUFFERP (glyph
->object
)
14668 : (STRINGP (glyph
->object
)
14671 glyph
->pixel_width
,
14673 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
14677 glyph
->left_box_line_p
,
14678 glyph
->right_box_line_p
);
14680 else if (glyph
->type
== STRETCH_GLYPH
)
14683 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14684 glyph
- row
->glyphs
[TEXT_AREA
],
14687 (BUFFERP (glyph
->object
)
14689 : (STRINGP (glyph
->object
)
14692 glyph
->pixel_width
,
14696 glyph
->left_box_line_p
,
14697 glyph
->right_box_line_p
);
14699 else if (glyph
->type
== IMAGE_GLYPH
)
14702 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14703 glyph
- row
->glyphs
[TEXT_AREA
],
14706 (BUFFERP (glyph
->object
)
14708 : (STRINGP (glyph
->object
)
14711 glyph
->pixel_width
,
14715 glyph
->left_box_line_p
,
14716 glyph
->right_box_line_p
);
14721 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
14722 GLYPHS 0 means don't show glyph contents.
14723 GLYPHS 1 means show glyphs in short form
14724 GLYPHS > 1 means show glyphs in long form. */
14727 dump_glyph_row (row
, vpos
, glyphs
)
14728 struct glyph_row
*row
;
14733 fprintf (stderr
, "Row Start End Used oEI><\\CTZFesm X Y W H V A P\n");
14734 fprintf (stderr
, "======================================================================\n");
14736 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
14737 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
14739 MATRIX_ROW_START_CHARPOS (row
),
14740 MATRIX_ROW_END_CHARPOS (row
),
14741 row
->used
[TEXT_AREA
],
14742 row
->contains_overlapping_glyphs_p
,
14744 row
->truncated_on_left_p
,
14745 row
->truncated_on_right_p
,
14747 MATRIX_ROW_CONTINUATION_LINE_P (row
),
14748 row
->displays_text_p
,
14751 row
->ends_in_middle_of_char_p
,
14752 row
->starts_in_middle_of_char_p
,
14758 row
->visible_height
,
14761 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
14762 row
->end
.overlay_string_index
,
14763 row
->continuation_lines_width
);
14764 fprintf (stderr
, "%9d %5d\n",
14765 CHARPOS (row
->start
.string_pos
),
14766 CHARPOS (row
->end
.string_pos
));
14767 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
14768 row
->end
.dpvec_index
);
14775 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14777 struct glyph
*glyph
= row
->glyphs
[area
];
14778 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
14780 /* Glyph for a line end in text. */
14781 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
14784 if (glyph
< glyph_end
)
14785 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
14787 for (; glyph
< glyph_end
; ++glyph
)
14788 dump_glyph (row
, glyph
, area
);
14791 else if (glyphs
== 1)
14795 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14797 char *s
= (char *) alloca (row
->used
[area
] + 1);
14800 for (i
= 0; i
< row
->used
[area
]; ++i
)
14802 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
14803 if (glyph
->type
== CHAR_GLYPH
14804 && glyph
->u
.ch
< 0x80
14805 && glyph
->u
.ch
>= ' ')
14806 s
[i
] = glyph
->u
.ch
;
14812 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
14818 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
14819 Sdump_glyph_matrix
, 0, 1, "p",
14820 doc
: /* Dump the current matrix of the selected window to stderr.
14821 Shows contents of glyph row structures. With non-nil
14822 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
14823 glyphs in short form, otherwise show glyphs in long form. */)
14825 Lisp_Object glyphs
;
14827 struct window
*w
= XWINDOW (selected_window
);
14828 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14830 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
14831 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
14832 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
14833 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
14834 fprintf (stderr
, "=============================================\n");
14835 dump_glyph_matrix (w
->current_matrix
,
14836 NILP (glyphs
) ? 0 : XINT (glyphs
));
14841 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
14842 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
14845 struct frame
*f
= XFRAME (selected_frame
);
14846 dump_glyph_matrix (f
->current_matrix
, 1);
14851 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
14852 doc
: /* Dump glyph row ROW to stderr.
14853 GLYPH 0 means don't dump glyphs.
14854 GLYPH 1 means dump glyphs in short form.
14855 GLYPH > 1 or omitted means dump glyphs in long form. */)
14857 Lisp_Object row
, glyphs
;
14859 struct glyph_matrix
*matrix
;
14862 CHECK_NUMBER (row
);
14863 matrix
= XWINDOW (selected_window
)->current_matrix
;
14865 if (vpos
>= 0 && vpos
< matrix
->nrows
)
14866 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
14868 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14873 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
14874 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
14875 GLYPH 0 means don't dump glyphs.
14876 GLYPH 1 means dump glyphs in short form.
14877 GLYPH > 1 or omitted means dump glyphs in long form. */)
14879 Lisp_Object row
, glyphs
;
14881 struct frame
*sf
= SELECTED_FRAME ();
14882 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
14885 CHECK_NUMBER (row
);
14887 if (vpos
>= 0 && vpos
< m
->nrows
)
14888 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
14889 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14894 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
14895 doc
: /* Toggle tracing of redisplay.
14896 With ARG, turn tracing on if and only if ARG is positive. */)
14901 trace_redisplay_p
= !trace_redisplay_p
;
14904 arg
= Fprefix_numeric_value (arg
);
14905 trace_redisplay_p
= XINT (arg
) > 0;
14912 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
14913 doc
: /* Like `format', but print result to stderr.
14914 usage: (trace-to-stderr STRING &rest OBJECTS) */)
14919 Lisp_Object s
= Fformat (nargs
, args
);
14920 fprintf (stderr
, "%s", SDATA (s
));
14924 #endif /* GLYPH_DEBUG */
14928 /***********************************************************************
14929 Building Desired Matrix Rows
14930 ***********************************************************************/
14932 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
14933 Used for non-window-redisplay windows, and for windows w/o left fringe. */
14935 static struct glyph_row
*
14936 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
14938 Lisp_Object overlay_arrow_string
;
14940 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14941 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14942 struct buffer
*old
= current_buffer
;
14943 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
14944 int arrow_len
= SCHARS (overlay_arrow_string
);
14945 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
14946 const unsigned char *p
;
14949 int n_glyphs_before
;
14951 set_buffer_temp (buffer
);
14952 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
14953 it
.glyph_row
->used
[TEXT_AREA
] = 0;
14954 SET_TEXT_POS (it
.position
, 0, 0);
14956 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
14958 while (p
< arrow_end
)
14960 Lisp_Object face
, ilisp
;
14962 /* Get the next character. */
14964 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
14966 it
.c
= *p
, it
.len
= 1;
14969 /* Get its face. */
14970 ilisp
= make_number (p
- arrow_string
);
14971 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
14972 it
.face_id
= compute_char_face (f
, it
.c
, face
);
14974 /* Compute its width, get its glyphs. */
14975 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
14976 SET_TEXT_POS (it
.position
, -1, -1);
14977 PRODUCE_GLYPHS (&it
);
14979 /* If this character doesn't fit any more in the line, we have
14980 to remove some glyphs. */
14981 if (it
.current_x
> it
.last_visible_x
)
14983 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14988 set_buffer_temp (old
);
14989 return it
.glyph_row
;
14993 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
14994 glyphs are only inserted for terminal frames since we can't really
14995 win with truncation glyphs when partially visible glyphs are
14996 involved. Which glyphs to insert is determined by
14997 produce_special_glyphs. */
15000 insert_left_trunc_glyphs (it
)
15003 struct it truncate_it
;
15004 struct glyph
*from
, *end
, *to
, *toend
;
15006 xassert (!FRAME_WINDOW_P (it
->f
));
15008 /* Get the truncation glyphs. */
15010 truncate_it
.current_x
= 0;
15011 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15012 truncate_it
.glyph_row
= &scratch_glyph_row
;
15013 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15014 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15015 truncate_it
.object
= make_number (0);
15016 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15018 /* Overwrite glyphs from IT with truncation glyphs. */
15019 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15020 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15021 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15022 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15027 /* There may be padding glyphs left over. Overwrite them too. */
15028 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15030 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15036 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15040 /* Compute the pixel height and width of IT->glyph_row.
15042 Most of the time, ascent and height of a display line will be equal
15043 to the max_ascent and max_height values of the display iterator
15044 structure. This is not the case if
15046 1. We hit ZV without displaying anything. In this case, max_ascent
15047 and max_height will be zero.
15049 2. We have some glyphs that don't contribute to the line height.
15050 (The glyph row flag contributes_to_line_height_p is for future
15051 pixmap extensions).
15053 The first case is easily covered by using default values because in
15054 these cases, the line height does not really matter, except that it
15055 must not be zero. */
15058 compute_line_metrics (it
)
15061 struct glyph_row
*row
= it
->glyph_row
;
15064 if (FRAME_WINDOW_P (it
->f
))
15066 int i
, min_y
, max_y
;
15068 /* The line may consist of one space only, that was added to
15069 place the cursor on it. If so, the row's height hasn't been
15071 if (row
->height
== 0)
15073 if (it
->max_ascent
+ it
->max_descent
== 0)
15074 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15075 row
->ascent
= it
->max_ascent
;
15076 row
->height
= it
->max_ascent
+ it
->max_descent
;
15077 row
->phys_ascent
= it
->max_phys_ascent
;
15078 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15079 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15082 /* Compute the width of this line. */
15083 row
->pixel_width
= row
->x
;
15084 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15085 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15087 xassert (row
->pixel_width
>= 0);
15088 xassert (row
->ascent
>= 0 && row
->height
> 0);
15090 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15091 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15093 /* If first line's physical ascent is larger than its logical
15094 ascent, use the physical ascent, and make the row taller.
15095 This makes accented characters fully visible. */
15096 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
15097 && row
->phys_ascent
> row
->ascent
)
15099 row
->height
+= row
->phys_ascent
- row
->ascent
;
15100 row
->ascent
= row
->phys_ascent
;
15103 /* Compute how much of the line is visible. */
15104 row
->visible_height
= row
->height
;
15106 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
15107 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
15109 if (row
->y
< min_y
)
15110 row
->visible_height
-= min_y
- row
->y
;
15111 if (row
->y
+ row
->height
> max_y
)
15112 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15116 row
->pixel_width
= row
->used
[TEXT_AREA
];
15117 if (row
->continued_p
)
15118 row
->pixel_width
-= it
->continuation_pixel_width
;
15119 else if (row
->truncated_on_right_p
)
15120 row
->pixel_width
-= it
->truncation_pixel_width
;
15121 row
->ascent
= row
->phys_ascent
= 0;
15122 row
->height
= row
->phys_height
= row
->visible_height
= 1;
15123 row
->extra_line_spacing
= 0;
15126 /* Compute a hash code for this row. */
15128 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15129 for (i
= 0; i
< row
->used
[area
]; ++i
)
15130 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
15131 + row
->glyphs
[area
][i
].u
.val
15132 + row
->glyphs
[area
][i
].face_id
15133 + row
->glyphs
[area
][i
].padding_p
15134 + (row
->glyphs
[area
][i
].type
<< 2));
15136 it
->max_ascent
= it
->max_descent
= 0;
15137 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
15141 /* Append one space to the glyph row of iterator IT if doing a
15142 window-based redisplay. The space has the same face as
15143 IT->face_id. Value is non-zero if a space was added.
15145 This function is called to make sure that there is always one glyph
15146 at the end of a glyph row that the cursor can be set on under
15147 window-systems. (If there weren't such a glyph we would not know
15148 how wide and tall a box cursor should be displayed).
15150 At the same time this space let's a nicely handle clearing to the
15151 end of the line if the row ends in italic text. */
15154 append_space_for_newline (it
, default_face_p
)
15156 int default_face_p
;
15158 if (FRAME_WINDOW_P (it
->f
))
15160 int n
= it
->glyph_row
->used
[TEXT_AREA
];
15162 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
15163 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
15165 /* Save some values that must not be changed.
15166 Must save IT->c and IT->len because otherwise
15167 ITERATOR_AT_END_P wouldn't work anymore after
15168 append_space_for_newline has been called. */
15169 enum display_element_type saved_what
= it
->what
;
15170 int saved_c
= it
->c
, saved_len
= it
->len
;
15171 int saved_x
= it
->current_x
;
15172 int saved_face_id
= it
->face_id
;
15173 struct text_pos saved_pos
;
15174 Lisp_Object saved_object
;
15177 saved_object
= it
->object
;
15178 saved_pos
= it
->position
;
15180 it
->what
= IT_CHARACTER
;
15181 bzero (&it
->position
, sizeof it
->position
);
15182 it
->object
= make_number (0);
15186 if (default_face_p
)
15187 it
->face_id
= DEFAULT_FACE_ID
;
15188 else if (it
->face_before_selective_p
)
15189 it
->face_id
= it
->saved_face_id
;
15190 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15191 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
15193 PRODUCE_GLYPHS (it
);
15195 it
->override_ascent
= -1;
15196 it
->constrain_row_ascent_descent_p
= 0;
15197 it
->current_x
= saved_x
;
15198 it
->object
= saved_object
;
15199 it
->position
= saved_pos
;
15200 it
->what
= saved_what
;
15201 it
->face_id
= saved_face_id
;
15202 it
->len
= saved_len
;
15212 /* Extend the face of the last glyph in the text area of IT->glyph_row
15213 to the end of the display line. Called from display_line.
15214 If the glyph row is empty, add a space glyph to it so that we
15215 know the face to draw. Set the glyph row flag fill_line_p. */
15218 extend_face_to_end_of_line (it
)
15222 struct frame
*f
= it
->f
;
15224 /* If line is already filled, do nothing. */
15225 if (it
->current_x
>= it
->last_visible_x
)
15228 /* Face extension extends the background and box of IT->face_id
15229 to the end of the line. If the background equals the background
15230 of the frame, we don't have to do anything. */
15231 if (it
->face_before_selective_p
)
15232 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
15234 face
= FACE_FROM_ID (f
, it
->face_id
);
15236 if (FRAME_WINDOW_P (f
)
15237 && face
->box
== FACE_NO_BOX
15238 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
15242 /* Set the glyph row flag indicating that the face of the last glyph
15243 in the text area has to be drawn to the end of the text area. */
15244 it
->glyph_row
->fill_line_p
= 1;
15246 /* If current character of IT is not ASCII, make sure we have the
15247 ASCII face. This will be automatically undone the next time
15248 get_next_display_element returns a multibyte character. Note
15249 that the character will always be single byte in unibyte text. */
15250 if (!SINGLE_BYTE_CHAR_P (it
->c
))
15252 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
15255 if (FRAME_WINDOW_P (f
))
15257 /* If the row is empty, add a space with the current face of IT,
15258 so that we know which face to draw. */
15259 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
15261 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
15262 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
15263 it
->glyph_row
->used
[TEXT_AREA
] = 1;
15268 /* Save some values that must not be changed. */
15269 int saved_x
= it
->current_x
;
15270 struct text_pos saved_pos
;
15271 Lisp_Object saved_object
;
15272 enum display_element_type saved_what
= it
->what
;
15273 int saved_face_id
= it
->face_id
;
15275 saved_object
= it
->object
;
15276 saved_pos
= it
->position
;
15278 it
->what
= IT_CHARACTER
;
15279 bzero (&it
->position
, sizeof it
->position
);
15280 it
->object
= make_number (0);
15283 it
->face_id
= face
->id
;
15285 PRODUCE_GLYPHS (it
);
15287 while (it
->current_x
<= it
->last_visible_x
)
15288 PRODUCE_GLYPHS (it
);
15290 /* Don't count these blanks really. It would let us insert a left
15291 truncation glyph below and make us set the cursor on them, maybe. */
15292 it
->current_x
= saved_x
;
15293 it
->object
= saved_object
;
15294 it
->position
= saved_pos
;
15295 it
->what
= saved_what
;
15296 it
->face_id
= saved_face_id
;
15301 /* Value is non-zero if text starting at CHARPOS in current_buffer is
15302 trailing whitespace. */
15305 trailing_whitespace_p (charpos
)
15308 int bytepos
= CHAR_TO_BYTE (charpos
);
15311 while (bytepos
< ZV_BYTE
15312 && (c
= FETCH_CHAR (bytepos
),
15313 c
== ' ' || c
== '\t'))
15316 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
15318 if (bytepos
!= PT_BYTE
)
15325 /* Highlight trailing whitespace, if any, in ROW. */
15328 highlight_trailing_whitespace (f
, row
)
15330 struct glyph_row
*row
;
15332 int used
= row
->used
[TEXT_AREA
];
15336 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
15337 struct glyph
*glyph
= start
+ used
- 1;
15339 /* Skip over glyphs inserted to display the cursor at the
15340 end of a line, for extending the face of the last glyph
15341 to the end of the line on terminals, and for truncation
15342 and continuation glyphs. */
15343 while (glyph
>= start
15344 && glyph
->type
== CHAR_GLYPH
15345 && INTEGERP (glyph
->object
))
15348 /* If last glyph is a space or stretch, and it's trailing
15349 whitespace, set the face of all trailing whitespace glyphs in
15350 IT->glyph_row to `trailing-whitespace'. */
15352 && BUFFERP (glyph
->object
)
15353 && (glyph
->type
== STRETCH_GLYPH
15354 || (glyph
->type
== CHAR_GLYPH
15355 && glyph
->u
.ch
== ' '))
15356 && trailing_whitespace_p (glyph
->charpos
))
15358 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
15362 while (glyph
>= start
15363 && BUFFERP (glyph
->object
)
15364 && (glyph
->type
== STRETCH_GLYPH
15365 || (glyph
->type
== CHAR_GLYPH
15366 && glyph
->u
.ch
== ' ')))
15367 (glyph
--)->face_id
= face_id
;
15373 /* Value is non-zero if glyph row ROW in window W should be
15374 used to hold the cursor. */
15377 cursor_row_p (w
, row
)
15379 struct glyph_row
*row
;
15381 int cursor_row_p
= 1;
15383 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15385 /* If the row ends with a newline from a string, we don't want
15386 the cursor there, but we still want it at the start of the
15387 string if the string starts in this row.
15388 If the row is continued it doesn't end in a newline. */
15389 if (CHARPOS (row
->end
.string_pos
) >= 0)
15390 cursor_row_p
= (row
->continued_p
15391 || PT
>= MATRIX_ROW_START_CHARPOS (row
));
15392 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15394 /* If the row ends in middle of a real character,
15395 and the line is continued, we want the cursor here.
15396 That's because MATRIX_ROW_END_CHARPOS would equal
15397 PT if PT is before the character. */
15398 if (!row
->ends_in_ellipsis_p
)
15399 cursor_row_p
= row
->continued_p
;
15401 /* If the row ends in an ellipsis, then
15402 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15403 We want that position to be displayed after the ellipsis. */
15406 /* If the row ends at ZV, display the cursor at the end of that
15407 row instead of at the start of the row below. */
15408 else if (row
->ends_at_zv_p
)
15414 return cursor_row_p
;
15418 /* Construct the glyph row IT->glyph_row in the desired matrix of
15419 IT->w from text at the current position of IT. See dispextern.h
15420 for an overview of struct it. Value is non-zero if
15421 IT->glyph_row displays text, as opposed to a line displaying ZV
15428 struct glyph_row
*row
= it
->glyph_row
;
15429 Lisp_Object overlay_arrow_string
;
15431 /* We always start displaying at hpos zero even if hscrolled. */
15432 xassert (it
->hpos
== 0 && it
->current_x
== 0);
15434 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
15435 >= it
->w
->desired_matrix
->nrows
)
15437 it
->w
->nrows_scale_factor
++;
15438 fonts_changed_p
= 1;
15442 /* Is IT->w showing the region? */
15443 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
15445 /* Clear the result glyph row and enable it. */
15446 prepare_desired_row (row
);
15448 row
->y
= it
->current_y
;
15449 row
->start
= it
->start
;
15450 row
->continuation_lines_width
= it
->continuation_lines_width
;
15451 row
->displays_text_p
= 1;
15452 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
15453 it
->starts_in_middle_of_char_p
= 0;
15455 /* Arrange the overlays nicely for our purposes. Usually, we call
15456 display_line on only one line at a time, in which case this
15457 can't really hurt too much, or we call it on lines which appear
15458 one after another in the buffer, in which case all calls to
15459 recenter_overlay_lists but the first will be pretty cheap. */
15460 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
15462 /* Move over display elements that are not visible because we are
15463 hscrolled. This may stop at an x-position < IT->first_visible_x
15464 if the first glyph is partially visible or if we hit a line end. */
15465 if (it
->current_x
< it
->first_visible_x
)
15467 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
15468 MOVE_TO_POS
| MOVE_TO_X
);
15471 /* Get the initial row height. This is either the height of the
15472 text hscrolled, if there is any, or zero. */
15473 row
->ascent
= it
->max_ascent
;
15474 row
->height
= it
->max_ascent
+ it
->max_descent
;
15475 row
->phys_ascent
= it
->max_phys_ascent
;
15476 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15477 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15479 /* Loop generating characters. The loop is left with IT on the next
15480 character to display. */
15483 int n_glyphs_before
, hpos_before
, x_before
;
15485 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
15487 /* Retrieve the next thing to display. Value is zero if end of
15489 if (!get_next_display_element (it
))
15491 /* Maybe add a space at the end of this line that is used to
15492 display the cursor there under X. Set the charpos of the
15493 first glyph of blank lines not corresponding to any text
15495 #ifdef HAVE_WINDOW_SYSTEM
15496 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15497 row
->exact_window_width_line_p
= 1;
15499 #endif /* HAVE_WINDOW_SYSTEM */
15500 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
15501 || row
->used
[TEXT_AREA
] == 0)
15503 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
15504 row
->displays_text_p
= 0;
15506 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
15507 && (!MINI_WINDOW_P (it
->w
)
15508 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
15509 row
->indicate_empty_line_p
= 1;
15512 it
->continuation_lines_width
= 0;
15513 row
->ends_at_zv_p
= 1;
15517 /* Now, get the metrics of what we want to display. This also
15518 generates glyphs in `row' (which is IT->glyph_row). */
15519 n_glyphs_before
= row
->used
[TEXT_AREA
];
15522 /* Remember the line height so far in case the next element doesn't
15523 fit on the line. */
15524 if (!it
->truncate_lines_p
)
15526 ascent
= it
->max_ascent
;
15527 descent
= it
->max_descent
;
15528 phys_ascent
= it
->max_phys_ascent
;
15529 phys_descent
= it
->max_phys_descent
;
15532 PRODUCE_GLYPHS (it
);
15534 /* If this display element was in marginal areas, continue with
15536 if (it
->area
!= TEXT_AREA
)
15538 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15539 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15540 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15541 row
->phys_height
= max (row
->phys_height
,
15542 it
->max_phys_ascent
+ it
->max_phys_descent
);
15543 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15544 it
->max_extra_line_spacing
);
15545 set_iterator_to_next (it
, 1);
15549 /* Does the display element fit on the line? If we truncate
15550 lines, we should draw past the right edge of the window. If
15551 we don't truncate, we want to stop so that we can display the
15552 continuation glyph before the right margin. If lines are
15553 continued, there are two possible strategies for characters
15554 resulting in more than 1 glyph (e.g. tabs): Display as many
15555 glyphs as possible in this line and leave the rest for the
15556 continuation line, or display the whole element in the next
15557 line. Original redisplay did the former, so we do it also. */
15558 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
15559 hpos_before
= it
->hpos
;
15562 if (/* Not a newline. */
15564 /* Glyphs produced fit entirely in the line. */
15565 && it
->current_x
< it
->last_visible_x
)
15567 it
->hpos
+= nglyphs
;
15568 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15569 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15570 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15571 row
->phys_height
= max (row
->phys_height
,
15572 it
->max_phys_ascent
+ it
->max_phys_descent
);
15573 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15574 it
->max_extra_line_spacing
);
15575 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
15576 row
->x
= x
- it
->first_visible_x
;
15581 struct glyph
*glyph
;
15583 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
15585 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
15586 new_x
= x
+ glyph
->pixel_width
;
15588 if (/* Lines are continued. */
15589 !it
->truncate_lines_p
15590 && (/* Glyph doesn't fit on the line. */
15591 new_x
> it
->last_visible_x
15592 /* Or it fits exactly on a window system frame. */
15593 || (new_x
== it
->last_visible_x
15594 && FRAME_WINDOW_P (it
->f
))))
15596 /* End of a continued line. */
15599 || (new_x
== it
->last_visible_x
15600 && FRAME_WINDOW_P (it
->f
)))
15602 /* Current glyph is the only one on the line or
15603 fits exactly on the line. We must continue
15604 the line because we can't draw the cursor
15605 after the glyph. */
15606 row
->continued_p
= 1;
15607 it
->current_x
= new_x
;
15608 it
->continuation_lines_width
+= new_x
;
15610 if (i
== nglyphs
- 1)
15612 set_iterator_to_next (it
, 1);
15613 #ifdef HAVE_WINDOW_SYSTEM
15614 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15616 if (!get_next_display_element (it
))
15618 row
->exact_window_width_line_p
= 1;
15619 it
->continuation_lines_width
= 0;
15620 row
->continued_p
= 0;
15621 row
->ends_at_zv_p
= 1;
15623 else if (ITERATOR_AT_END_OF_LINE_P (it
))
15625 row
->continued_p
= 0;
15626 row
->exact_window_width_line_p
= 1;
15629 #endif /* HAVE_WINDOW_SYSTEM */
15632 else if (CHAR_GLYPH_PADDING_P (*glyph
)
15633 && !FRAME_WINDOW_P (it
->f
))
15635 /* A padding glyph that doesn't fit on this line.
15636 This means the whole character doesn't fit
15638 row
->used
[TEXT_AREA
] = n_glyphs_before
;
15640 /* Fill the rest of the row with continuation
15641 glyphs like in 20.x. */
15642 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
15643 < row
->glyphs
[1 + TEXT_AREA
])
15644 produce_special_glyphs (it
, IT_CONTINUATION
);
15646 row
->continued_p
= 1;
15647 it
->current_x
= x_before
;
15648 it
->continuation_lines_width
+= x_before
;
15650 /* Restore the height to what it was before the
15651 element not fitting on the line. */
15652 it
->max_ascent
= ascent
;
15653 it
->max_descent
= descent
;
15654 it
->max_phys_ascent
= phys_ascent
;
15655 it
->max_phys_descent
= phys_descent
;
15657 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
15659 /* A TAB that extends past the right edge of the
15660 window. This produces a single glyph on
15661 window system frames. We leave the glyph in
15662 this row and let it fill the row, but don't
15663 consume the TAB. */
15664 it
->continuation_lines_width
+= it
->last_visible_x
;
15665 row
->ends_in_middle_of_char_p
= 1;
15666 row
->continued_p
= 1;
15667 glyph
->pixel_width
= it
->last_visible_x
- x
;
15668 it
->starts_in_middle_of_char_p
= 1;
15672 /* Something other than a TAB that draws past
15673 the right edge of the window. Restore
15674 positions to values before the element. */
15675 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15677 /* Display continuation glyphs. */
15678 if (!FRAME_WINDOW_P (it
->f
))
15679 produce_special_glyphs (it
, IT_CONTINUATION
);
15680 row
->continued_p
= 1;
15682 it
->current_x
= x_before
;
15683 it
->continuation_lines_width
+= x
;
15684 extend_face_to_end_of_line (it
);
15686 if (nglyphs
> 1 && i
> 0)
15688 row
->ends_in_middle_of_char_p
= 1;
15689 it
->starts_in_middle_of_char_p
= 1;
15692 /* Restore the height to what it was before the
15693 element not fitting on the line. */
15694 it
->max_ascent
= ascent
;
15695 it
->max_descent
= descent
;
15696 it
->max_phys_ascent
= phys_ascent
;
15697 it
->max_phys_descent
= phys_descent
;
15702 else if (new_x
> it
->first_visible_x
)
15704 /* Increment number of glyphs actually displayed. */
15707 if (x
< it
->first_visible_x
)
15708 /* Glyph is partially visible, i.e. row starts at
15709 negative X position. */
15710 row
->x
= x
- it
->first_visible_x
;
15714 /* Glyph is completely off the left margin of the
15715 window. This should not happen because of the
15716 move_it_in_display_line at the start of this
15717 function, unless the text display area of the
15718 window is empty. */
15719 xassert (it
->first_visible_x
<= it
->last_visible_x
);
15723 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15724 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15725 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15726 row
->phys_height
= max (row
->phys_height
,
15727 it
->max_phys_ascent
+ it
->max_phys_descent
);
15728 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15729 it
->max_extra_line_spacing
);
15731 /* End of this display line if row is continued. */
15732 if (row
->continued_p
|| row
->ends_at_zv_p
)
15737 /* Is this a line end? If yes, we're also done, after making
15738 sure that a non-default face is extended up to the right
15739 margin of the window. */
15740 if (ITERATOR_AT_END_OF_LINE_P (it
))
15742 int used_before
= row
->used
[TEXT_AREA
];
15744 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
15746 #ifdef HAVE_WINDOW_SYSTEM
15747 /* Add a space at the end of the line that is used to
15748 display the cursor there. */
15749 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15750 append_space_for_newline (it
, 0);
15751 #endif /* HAVE_WINDOW_SYSTEM */
15753 /* Extend the face to the end of the line. */
15754 extend_face_to_end_of_line (it
);
15756 /* Make sure we have the position. */
15757 if (used_before
== 0)
15758 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
15760 /* Consume the line end. This skips over invisible lines. */
15761 set_iterator_to_next (it
, 1);
15762 it
->continuation_lines_width
= 0;
15766 /* Proceed with next display element. Note that this skips
15767 over lines invisible because of selective display. */
15768 set_iterator_to_next (it
, 1);
15770 /* If we truncate lines, we are done when the last displayed
15771 glyphs reach past the right margin of the window. */
15772 if (it
->truncate_lines_p
15773 && (FRAME_WINDOW_P (it
->f
)
15774 ? (it
->current_x
>= it
->last_visible_x
)
15775 : (it
->current_x
> it
->last_visible_x
)))
15777 /* Maybe add truncation glyphs. */
15778 if (!FRAME_WINDOW_P (it
->f
))
15782 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15783 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15786 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15788 row
->used
[TEXT_AREA
] = i
;
15789 produce_special_glyphs (it
, IT_TRUNCATION
);
15792 #ifdef HAVE_WINDOW_SYSTEM
15795 /* Don't truncate if we can overflow newline into fringe. */
15796 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15798 if (!get_next_display_element (it
))
15800 it
->continuation_lines_width
= 0;
15801 row
->ends_at_zv_p
= 1;
15802 row
->exact_window_width_line_p
= 1;
15805 if (ITERATOR_AT_END_OF_LINE_P (it
))
15807 row
->exact_window_width_line_p
= 1;
15808 goto at_end_of_line
;
15812 #endif /* HAVE_WINDOW_SYSTEM */
15814 row
->truncated_on_right_p
= 1;
15815 it
->continuation_lines_width
= 0;
15816 reseat_at_next_visible_line_start (it
, 0);
15817 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
15818 it
->hpos
= hpos_before
;
15819 it
->current_x
= x_before
;
15824 /* If line is not empty and hscrolled, maybe insert truncation glyphs
15825 at the left window margin. */
15826 if (it
->first_visible_x
15827 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
15829 if (!FRAME_WINDOW_P (it
->f
))
15830 insert_left_trunc_glyphs (it
);
15831 row
->truncated_on_left_p
= 1;
15834 /* If the start of this line is the overlay arrow-position, then
15835 mark this glyph row as the one containing the overlay arrow.
15836 This is clearly a mess with variable size fonts. It would be
15837 better to let it be displayed like cursors under X. */
15838 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
15839 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
15840 !NILP (overlay_arrow_string
)))
15842 /* Overlay arrow in window redisplay is a fringe bitmap. */
15843 if (STRINGP (overlay_arrow_string
))
15845 struct glyph_row
*arrow_row
15846 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
15847 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
15848 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
15849 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
15850 struct glyph
*p2
, *end
;
15852 /* Copy the arrow glyphs. */
15853 while (glyph
< arrow_end
)
15856 /* Throw away padding glyphs. */
15858 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15859 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
15865 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
15870 xassert (INTEGERP (overlay_arrow_string
));
15871 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
15873 overlay_arrow_seen
= 1;
15876 /* Compute pixel dimensions of this line. */
15877 compute_line_metrics (it
);
15879 /* Remember the position at which this line ends. */
15880 row
->end
= it
->current
;
15882 /* Record whether this row ends inside an ellipsis. */
15883 row
->ends_in_ellipsis_p
15884 = (it
->method
== GET_FROM_DISPLAY_VECTOR
15885 && it
->ellipsis_p
);
15887 /* Save fringe bitmaps in this row. */
15888 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
15889 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
15890 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
15891 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
15893 it
->left_user_fringe_bitmap
= 0;
15894 it
->left_user_fringe_face_id
= 0;
15895 it
->right_user_fringe_bitmap
= 0;
15896 it
->right_user_fringe_face_id
= 0;
15898 /* Maybe set the cursor. */
15899 if (it
->w
->cursor
.vpos
< 0
15900 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
15901 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15902 && cursor_row_p (it
->w
, row
))
15903 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
15905 /* Highlight trailing whitespace. */
15906 if (!NILP (Vshow_trailing_whitespace
))
15907 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
15909 /* Prepare for the next line. This line starts horizontally at (X
15910 HPOS) = (0 0). Vertical positions are incremented. As a
15911 convenience for the caller, IT->glyph_row is set to the next
15913 it
->current_x
= it
->hpos
= 0;
15914 it
->current_y
+= row
->height
;
15917 it
->start
= it
->current
;
15918 return row
->displays_text_p
;
15923 /***********************************************************************
15925 ***********************************************************************/
15927 /* Redisplay the menu bar in the frame for window W.
15929 The menu bar of X frames that don't have X toolkit support is
15930 displayed in a special window W->frame->menu_bar_window.
15932 The menu bar of terminal frames is treated specially as far as
15933 glyph matrices are concerned. Menu bar lines are not part of
15934 windows, so the update is done directly on the frame matrix rows
15935 for the menu bar. */
15938 display_menu_bar (w
)
15941 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15946 /* Don't do all this for graphical frames. */
15948 if (!NILP (Vwindow_system
))
15951 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
15956 if (FRAME_MAC_P (f
))
15960 #ifdef USE_X_TOOLKIT
15961 xassert (!FRAME_WINDOW_P (f
));
15962 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
15963 it
.first_visible_x
= 0;
15964 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15965 #else /* not USE_X_TOOLKIT */
15966 if (FRAME_WINDOW_P (f
))
15968 /* Menu bar lines are displayed in the desired matrix of the
15969 dummy window menu_bar_window. */
15970 struct window
*menu_w
;
15971 xassert (WINDOWP (f
->menu_bar_window
));
15972 menu_w
= XWINDOW (f
->menu_bar_window
);
15973 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
15975 it
.first_visible_x
= 0;
15976 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15980 /* This is a TTY frame, i.e. character hpos/vpos are used as
15982 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
15984 it
.first_visible_x
= 0;
15985 it
.last_visible_x
= FRAME_COLS (f
);
15987 #endif /* not USE_X_TOOLKIT */
15989 if (! mode_line_inverse_video
)
15990 /* Force the menu-bar to be displayed in the default face. */
15991 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15993 /* Clear all rows of the menu bar. */
15994 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
15996 struct glyph_row
*row
= it
.glyph_row
+ i
;
15997 clear_glyph_row (row
);
15998 row
->enabled_p
= 1;
15999 row
->full_width_p
= 1;
16002 /* Display all items of the menu bar. */
16003 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
16004 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
16006 Lisp_Object string
;
16008 /* Stop at nil string. */
16009 string
= AREF (items
, i
+ 1);
16013 /* Remember where item was displayed. */
16014 AREF (items
, i
+ 3) = make_number (it
.hpos
);
16016 /* Display the item, pad with one space. */
16017 if (it
.current_x
< it
.last_visible_x
)
16018 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
16019 SCHARS (string
) + 1, 0, 0, -1);
16022 /* Fill out the line with spaces. */
16023 if (it
.current_x
< it
.last_visible_x
)
16024 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
16026 /* Compute the total height of the lines. */
16027 compute_line_metrics (&it
);
16032 /***********************************************************************
16034 ***********************************************************************/
16036 /* Redisplay mode lines in the window tree whose root is WINDOW. If
16037 FORCE is non-zero, redisplay mode lines unconditionally.
16038 Otherwise, redisplay only mode lines that are garbaged. Value is
16039 the number of windows whose mode lines were redisplayed. */
16042 redisplay_mode_lines (window
, force
)
16043 Lisp_Object window
;
16048 while (!NILP (window
))
16050 struct window
*w
= XWINDOW (window
);
16052 if (WINDOWP (w
->hchild
))
16053 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
16054 else if (WINDOWP (w
->vchild
))
16055 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
16057 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
16058 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
16060 struct text_pos lpoint
;
16061 struct buffer
*old
= current_buffer
;
16063 /* Set the window's buffer for the mode line display. */
16064 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16065 set_buffer_internal_1 (XBUFFER (w
->buffer
));
16067 /* Point refers normally to the selected window. For any
16068 other window, set up appropriate value. */
16069 if (!EQ (window
, selected_window
))
16071 struct text_pos pt
;
16073 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
16074 if (CHARPOS (pt
) < BEGV
)
16075 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16076 else if (CHARPOS (pt
) > (ZV
- 1))
16077 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
16079 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
16082 /* Display mode lines. */
16083 clear_glyph_matrix (w
->desired_matrix
);
16084 if (display_mode_lines (w
))
16087 w
->must_be_updated_p
= 1;
16090 /* Restore old settings. */
16091 set_buffer_internal_1 (old
);
16092 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16102 /* Display the mode and/or top line of window W. Value is the number
16103 of mode lines displayed. */
16106 display_mode_lines (w
)
16109 Lisp_Object old_selected_window
, old_selected_frame
;
16112 old_selected_frame
= selected_frame
;
16113 selected_frame
= w
->frame
;
16114 old_selected_window
= selected_window
;
16115 XSETWINDOW (selected_window
, w
);
16117 /* These will be set while the mode line specs are processed. */
16118 line_number_displayed
= 0;
16119 w
->column_number_displayed
= Qnil
;
16121 if (WINDOW_WANTS_MODELINE_P (w
))
16123 struct window
*sel_w
= XWINDOW (old_selected_window
);
16125 /* Select mode line face based on the real selected window. */
16126 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
16127 current_buffer
->mode_line_format
);
16131 if (WINDOW_WANTS_HEADER_LINE_P (w
))
16133 display_mode_line (w
, HEADER_LINE_FACE_ID
,
16134 current_buffer
->header_line_format
);
16138 selected_frame
= old_selected_frame
;
16139 selected_window
= old_selected_window
;
16144 /* Display mode or top line of window W. FACE_ID specifies which line
16145 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
16146 FORMAT is the mode line format to display. Value is the pixel
16147 height of the mode line displayed. */
16150 display_mode_line (w
, face_id
, format
)
16152 enum face_id face_id
;
16153 Lisp_Object format
;
16157 int count
= SPECPDL_INDEX ();
16159 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16160 prepare_desired_row (it
.glyph_row
);
16162 it
.glyph_row
->mode_line_p
= 1;
16164 if (! mode_line_inverse_video
)
16165 /* Force the mode-line to be displayed in the default face. */
16166 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16168 record_unwind_protect (unwind_format_mode_line
,
16169 format_mode_line_unwind_data (NULL
, 0));
16171 mode_line_target
= MODE_LINE_DISPLAY
;
16173 /* Temporarily make frame's keyboard the current kboard so that
16174 kboard-local variables in the mode_line_format will get the right
16176 push_frame_kboard (it
.f
);
16177 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16178 pop_frame_kboard ();
16180 unbind_to (count
, Qnil
);
16182 /* Fill up with spaces. */
16183 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
16185 compute_line_metrics (&it
);
16186 it
.glyph_row
->full_width_p
= 1;
16187 it
.glyph_row
->continued_p
= 0;
16188 it
.glyph_row
->truncated_on_left_p
= 0;
16189 it
.glyph_row
->truncated_on_right_p
= 0;
16191 /* Make a 3D mode-line have a shadow at its right end. */
16192 face
= FACE_FROM_ID (it
.f
, face_id
);
16193 extend_face_to_end_of_line (&it
);
16194 if (face
->box
!= FACE_NO_BOX
)
16196 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
16197 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
16198 last
->right_box_line_p
= 1;
16201 return it
.glyph_row
->height
;
16204 /* Move element ELT in LIST to the front of LIST.
16205 Return the updated list. */
16208 move_elt_to_front (elt
, list
)
16209 Lisp_Object elt
, list
;
16211 register Lisp_Object tail
, prev
;
16212 register Lisp_Object tem
;
16216 while (CONSP (tail
))
16222 /* Splice out the link TAIL. */
16224 list
= XCDR (tail
);
16226 Fsetcdr (prev
, XCDR (tail
));
16228 /* Now make it the first. */
16229 Fsetcdr (tail
, list
);
16234 tail
= XCDR (tail
);
16238 /* Not found--return unchanged LIST. */
16242 /* Contribute ELT to the mode line for window IT->w. How it
16243 translates into text depends on its data type.
16245 IT describes the display environment in which we display, as usual.
16247 DEPTH is the depth in recursion. It is used to prevent
16248 infinite recursion here.
16250 FIELD_WIDTH is the number of characters the display of ELT should
16251 occupy in the mode line, and PRECISION is the maximum number of
16252 characters to display from ELT's representation. See
16253 display_string for details.
16255 Returns the hpos of the end of the text generated by ELT.
16257 PROPS is a property list to add to any string we encounter.
16259 If RISKY is nonzero, remove (disregard) any properties in any string
16260 we encounter, and ignore :eval and :propertize.
16262 The global variable `mode_line_target' determines whether the
16263 output is passed to `store_mode_line_noprop',
16264 `store_mode_line_string', or `display_string'. */
16267 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
16270 int field_width
, precision
;
16271 Lisp_Object elt
, props
;
16274 int n
= 0, field
, prec
;
16279 elt
= build_string ("*too-deep*");
16283 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
16287 /* A string: output it and check for %-constructs within it. */
16291 if (SCHARS (elt
) > 0
16292 && (!NILP (props
) || risky
))
16294 Lisp_Object oprops
, aelt
;
16295 oprops
= Ftext_properties_at (make_number (0), elt
);
16297 /* If the starting string's properties are not what
16298 we want, translate the string. Also, if the string
16299 is risky, do that anyway. */
16301 if (NILP (Fequal (props
, oprops
)) || risky
)
16303 /* If the starting string has properties,
16304 merge the specified ones onto the existing ones. */
16305 if (! NILP (oprops
) && !risky
)
16309 oprops
= Fcopy_sequence (oprops
);
16311 while (CONSP (tem
))
16313 oprops
= Fplist_put (oprops
, XCAR (tem
),
16314 XCAR (XCDR (tem
)));
16315 tem
= XCDR (XCDR (tem
));
16320 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
16321 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
16323 /* AELT is what we want. Move it to the front
16324 without consing. */
16326 mode_line_proptrans_alist
16327 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
16333 /* If AELT has the wrong props, it is useless.
16334 so get rid of it. */
16336 mode_line_proptrans_alist
16337 = Fdelq (aelt
, mode_line_proptrans_alist
);
16339 elt
= Fcopy_sequence (elt
);
16340 Fset_text_properties (make_number (0), Flength (elt
),
16342 /* Add this item to mode_line_proptrans_alist. */
16343 mode_line_proptrans_alist
16344 = Fcons (Fcons (elt
, props
),
16345 mode_line_proptrans_alist
);
16346 /* Truncate mode_line_proptrans_alist
16347 to at most 50 elements. */
16348 tem
= Fnthcdr (make_number (50),
16349 mode_line_proptrans_alist
);
16351 XSETCDR (tem
, Qnil
);
16360 prec
= precision
- n
;
16361 switch (mode_line_target
)
16363 case MODE_LINE_NOPROP
:
16364 case MODE_LINE_TITLE
:
16365 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
16367 case MODE_LINE_STRING
:
16368 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
16370 case MODE_LINE_DISPLAY
:
16371 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
16372 0, prec
, 0, STRING_MULTIBYTE (elt
));
16379 /* Handle the non-literal case. */
16381 while ((precision
<= 0 || n
< precision
)
16382 && SREF (elt
, offset
) != 0
16383 && (mode_line_target
!= MODE_LINE_DISPLAY
16384 || it
->current_x
< it
->last_visible_x
))
16386 int last_offset
= offset
;
16388 /* Advance to end of string or next format specifier. */
16389 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
16392 if (offset
- 1 != last_offset
)
16394 int nchars
, nbytes
;
16396 /* Output to end of string or up to '%'. Field width
16397 is length of string. Don't output more than
16398 PRECISION allows us. */
16401 prec
= c_string_width (SDATA (elt
) + last_offset
,
16402 offset
- last_offset
, precision
- n
,
16405 switch (mode_line_target
)
16407 case MODE_LINE_NOPROP
:
16408 case MODE_LINE_TITLE
:
16409 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
16411 case MODE_LINE_STRING
:
16413 int bytepos
= last_offset
;
16414 int charpos
= string_byte_to_char (elt
, bytepos
);
16415 int endpos
= (precision
<= 0
16416 ? string_byte_to_char (elt
, offset
)
16417 : charpos
+ nchars
);
16419 n
+= store_mode_line_string (NULL
,
16420 Fsubstring (elt
, make_number (charpos
),
16421 make_number (endpos
)),
16425 case MODE_LINE_DISPLAY
:
16427 int bytepos
= last_offset
;
16428 int charpos
= string_byte_to_char (elt
, bytepos
);
16429 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
16431 STRING_MULTIBYTE (elt
));
16436 else /* c == '%' */
16438 int percent_position
= offset
;
16440 /* Get the specified minimum width. Zero means
16443 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
16444 field
= field
* 10 + c
- '0';
16446 /* Don't pad beyond the total padding allowed. */
16447 if (field_width
- n
> 0 && field
> field_width
- n
)
16448 field
= field_width
- n
;
16450 /* Note that either PRECISION <= 0 or N < PRECISION. */
16451 prec
= precision
- n
;
16454 n
+= display_mode_element (it
, depth
, field
, prec
,
16455 Vglobal_mode_string
, props
,
16460 int bytepos
, charpos
;
16461 unsigned char *spec
;
16463 bytepos
= percent_position
;
16464 charpos
= (STRING_MULTIBYTE (elt
)
16465 ? string_byte_to_char (elt
, bytepos
)
16469 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
16471 switch (mode_line_target
)
16473 case MODE_LINE_NOPROP
:
16474 case MODE_LINE_TITLE
:
16475 n
+= store_mode_line_noprop (spec
, field
, prec
);
16477 case MODE_LINE_STRING
:
16479 int len
= strlen (spec
);
16480 Lisp_Object tem
= make_string (spec
, len
);
16481 props
= Ftext_properties_at (make_number (charpos
), elt
);
16482 /* Should only keep face property in props */
16483 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
16486 case MODE_LINE_DISPLAY
:
16488 int nglyphs_before
, nwritten
;
16490 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16491 nwritten
= display_string (spec
, Qnil
, elt
,
16496 /* Assign to the glyphs written above the
16497 string where the `%x' came from, position
16501 struct glyph
*glyph
16502 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
16506 for (i
= 0; i
< nwritten
; ++i
)
16508 glyph
[i
].object
= elt
;
16509 glyph
[i
].charpos
= charpos
;
16526 /* A symbol: process the value of the symbol recursively
16527 as if it appeared here directly. Avoid error if symbol void.
16528 Special case: if value of symbol is a string, output the string
16531 register Lisp_Object tem
;
16533 /* If the variable is not marked as risky to set
16534 then its contents are risky to use. */
16535 if (NILP (Fget (elt
, Qrisky_local_variable
)))
16538 tem
= Fboundp (elt
);
16541 tem
= Fsymbol_value (elt
);
16542 /* If value is a string, output that string literally:
16543 don't check for % within it. */
16547 if (!EQ (tem
, elt
))
16549 /* Give up right away for nil or t. */
16559 register Lisp_Object car
, tem
;
16561 /* A cons cell: five distinct cases.
16562 If first element is :eval or :propertize, do something special.
16563 If first element is a string or a cons, process all the elements
16564 and effectively concatenate them.
16565 If first element is a negative number, truncate displaying cdr to
16566 at most that many characters. If positive, pad (with spaces)
16567 to at least that many characters.
16568 If first element is a symbol, process the cadr or caddr recursively
16569 according to whether the symbol's value is non-nil or nil. */
16571 if (EQ (car
, QCeval
))
16573 /* An element of the form (:eval FORM) means evaluate FORM
16574 and use the result as mode line elements. */
16579 if (CONSP (XCDR (elt
)))
16582 spec
= safe_eval (XCAR (XCDR (elt
)));
16583 n
+= display_mode_element (it
, depth
, field_width
- n
,
16584 precision
- n
, spec
, props
,
16588 else if (EQ (car
, QCpropertize
))
16590 /* An element of the form (:propertize ELT PROPS...)
16591 means display ELT but applying properties PROPS. */
16596 if (CONSP (XCDR (elt
)))
16597 n
+= display_mode_element (it
, depth
, field_width
- n
,
16598 precision
- n
, XCAR (XCDR (elt
)),
16599 XCDR (XCDR (elt
)), risky
);
16601 else if (SYMBOLP (car
))
16603 tem
= Fboundp (car
);
16607 /* elt is now the cdr, and we know it is a cons cell.
16608 Use its car if CAR has a non-nil value. */
16611 tem
= Fsymbol_value (car
);
16618 /* Symbol's value is nil (or symbol is unbound)
16619 Get the cddr of the original list
16620 and if possible find the caddr and use that. */
16624 else if (!CONSP (elt
))
16629 else if (INTEGERP (car
))
16631 register int lim
= XINT (car
);
16635 /* Negative int means reduce maximum width. */
16636 if (precision
<= 0)
16639 precision
= min (precision
, -lim
);
16643 /* Padding specified. Don't let it be more than
16644 current maximum. */
16646 lim
= min (precision
, lim
);
16648 /* If that's more padding than already wanted, queue it.
16649 But don't reduce padding already specified even if
16650 that is beyond the current truncation point. */
16651 field_width
= max (lim
, field_width
);
16655 else if (STRINGP (car
) || CONSP (car
))
16657 register int limit
= 50;
16658 /* Limit is to protect against circular lists. */
16661 && (precision
<= 0 || n
< precision
))
16663 n
+= display_mode_element (it
, depth
,
16664 /* Do padding only after the last
16665 element in the list. */
16666 (! CONSP (XCDR (elt
))
16669 precision
- n
, XCAR (elt
),
16679 elt
= build_string ("*invalid*");
16683 /* Pad to FIELD_WIDTH. */
16684 if (field_width
> 0 && n
< field_width
)
16686 switch (mode_line_target
)
16688 case MODE_LINE_NOPROP
:
16689 case MODE_LINE_TITLE
:
16690 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
16692 case MODE_LINE_STRING
:
16693 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
16695 case MODE_LINE_DISPLAY
:
16696 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
16705 /* Store a mode-line string element in mode_line_string_list.
16707 If STRING is non-null, display that C string. Otherwise, the Lisp
16708 string LISP_STRING is displayed.
16710 FIELD_WIDTH is the minimum number of output glyphs to produce.
16711 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16712 with spaces. FIELD_WIDTH <= 0 means don't pad.
16714 PRECISION is the maximum number of characters to output from
16715 STRING. PRECISION <= 0 means don't truncate the string.
16717 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
16718 properties to the string.
16720 PROPS are the properties to add to the string.
16721 The mode_line_string_face face property is always added to the string.
16725 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
16727 Lisp_Object lisp_string
;
16736 if (string
!= NULL
)
16738 len
= strlen (string
);
16739 if (precision
> 0 && len
> precision
)
16741 lisp_string
= make_string (string
, len
);
16743 props
= mode_line_string_face_prop
;
16744 else if (!NILP (mode_line_string_face
))
16746 Lisp_Object face
= Fplist_get (props
, Qface
);
16747 props
= Fcopy_sequence (props
);
16749 face
= mode_line_string_face
;
16751 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16752 props
= Fplist_put (props
, Qface
, face
);
16754 Fadd_text_properties (make_number (0), make_number (len
),
16755 props
, lisp_string
);
16759 len
= XFASTINT (Flength (lisp_string
));
16760 if (precision
> 0 && len
> precision
)
16763 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
16766 if (!NILP (mode_line_string_face
))
16770 props
= Ftext_properties_at (make_number (0), lisp_string
);
16771 face
= Fplist_get (props
, Qface
);
16773 face
= mode_line_string_face
;
16775 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16776 props
= Fcons (Qface
, Fcons (face
, Qnil
));
16778 lisp_string
= Fcopy_sequence (lisp_string
);
16781 Fadd_text_properties (make_number (0), make_number (len
),
16782 props
, lisp_string
);
16787 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16791 if (field_width
> len
)
16793 field_width
-= len
;
16794 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
16796 Fadd_text_properties (make_number (0), make_number (field_width
),
16797 props
, lisp_string
);
16798 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16806 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
16808 doc
: /* Format a string out of a mode line format specification.
16809 First arg FORMAT specifies the mode line format (see `mode-line-format'
16810 for details) to use.
16812 Optional second arg FACE specifies the face property to put
16813 on all characters for which no face is specified.
16814 t means whatever face the window's mode line currently uses
16815 \(either `mode-line' or `mode-line-inactive', depending).
16816 nil means the default is no face property.
16817 If FACE is an integer, the value string has no text properties.
16819 Optional third and fourth args WINDOW and BUFFER specify the window
16820 and buffer to use as the context for the formatting (defaults
16821 are the selected window and the window's buffer). */)
16822 (format
, face
, window
, buffer
)
16823 Lisp_Object format
, face
, window
, buffer
;
16828 struct buffer
*old_buffer
= NULL
;
16830 int no_props
= INTEGERP (face
);
16831 int count
= SPECPDL_INDEX ();
16833 int string_start
= 0;
16836 window
= selected_window
;
16837 CHECK_WINDOW (window
);
16838 w
= XWINDOW (window
);
16841 buffer
= w
->buffer
;
16842 CHECK_BUFFER (buffer
);
16845 return build_string ("");
16853 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
16854 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
16858 face_id
= DEFAULT_FACE_ID
;
16860 if (XBUFFER (buffer
) != current_buffer
)
16861 old_buffer
= current_buffer
;
16863 /* Save things including mode_line_proptrans_alist,
16864 and set that to nil so that we don't alter the outer value. */
16865 record_unwind_protect (unwind_format_mode_line
,
16866 format_mode_line_unwind_data (old_buffer
, 1));
16867 mode_line_proptrans_alist
= Qnil
;
16870 set_buffer_internal_1 (XBUFFER (buffer
));
16872 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16876 mode_line_target
= MODE_LINE_NOPROP
;
16877 mode_line_string_face_prop
= Qnil
;
16878 mode_line_string_list
= Qnil
;
16879 string_start
= MODE_LINE_NOPROP_LEN (0);
16883 mode_line_target
= MODE_LINE_STRING
;
16884 mode_line_string_list
= Qnil
;
16885 mode_line_string_face
= face
;
16886 mode_line_string_face_prop
16887 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
16890 push_frame_kboard (it
.f
);
16891 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16892 pop_frame_kboard ();
16896 len
= MODE_LINE_NOPROP_LEN (string_start
);
16897 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
16901 mode_line_string_list
= Fnreverse (mode_line_string_list
);
16902 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
16903 make_string ("", 0));
16906 unbind_to (count
, Qnil
);
16910 /* Write a null-terminated, right justified decimal representation of
16911 the positive integer D to BUF using a minimal field width WIDTH. */
16914 pint2str (buf
, width
, d
)
16915 register char *buf
;
16916 register int width
;
16919 register char *p
= buf
;
16927 *p
++ = d
% 10 + '0';
16932 for (width
-= (int) (p
- buf
); width
> 0; --width
)
16943 /* Write a null-terminated, right justified decimal and "human
16944 readable" representation of the nonnegative integer D to BUF using
16945 a minimal field width WIDTH. D should be smaller than 999.5e24. */
16947 static const char power_letter
[] =
16961 pint2hrstr (buf
, width
, d
)
16966 /* We aim to represent the nonnegative integer D as
16967 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
16970 /* -1 means: do not use TENTHS. */
16974 /* Length of QUOTIENT.TENTHS as a string. */
16980 if (1000 <= quotient
)
16982 /* Scale to the appropriate EXPONENT. */
16985 remainder
= quotient
% 1000;
16989 while (1000 <= quotient
);
16991 /* Round to nearest and decide whether to use TENTHS or not. */
16994 tenths
= remainder
/ 100;
16995 if (50 <= remainder
% 100)
17002 if (quotient
== 10)
17010 if (500 <= remainder
)
17012 if (quotient
< 999)
17023 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
17024 if (tenths
== -1 && quotient
<= 99)
17031 p
= psuffix
= buf
+ max (width
, length
);
17033 /* Print EXPONENT. */
17035 *psuffix
++ = power_letter
[exponent
];
17038 /* Print TENTHS. */
17041 *--p
= '0' + tenths
;
17045 /* Print QUOTIENT. */
17048 int digit
= quotient
% 10;
17049 *--p
= '0' + digit
;
17051 while ((quotient
/= 10) != 0);
17053 /* Print leading spaces. */
17058 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
17059 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
17060 type of CODING_SYSTEM. Return updated pointer into BUF. */
17062 static unsigned char invalid_eol_type
[] = "(*invalid*)";
17065 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
17066 Lisp_Object coding_system
;
17067 register char *buf
;
17071 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
17072 const unsigned char *eol_str
;
17074 /* The EOL conversion we are using. */
17075 Lisp_Object eoltype
;
17077 val
= Fget (coding_system
, Qcoding_system
);
17080 if (!VECTORP (val
)) /* Not yet decided. */
17085 eoltype
= eol_mnemonic_undecided
;
17086 /* Don't mention EOL conversion if it isn't decided. */
17090 Lisp_Object eolvalue
;
17092 eolvalue
= Fget (coding_system
, Qeol_type
);
17095 *buf
++ = XFASTINT (AREF (val
, 1));
17099 /* The EOL conversion that is normal on this system. */
17101 if (NILP (eolvalue
)) /* Not yet decided. */
17102 eoltype
= eol_mnemonic_undecided
;
17103 else if (VECTORP (eolvalue
)) /* Not yet decided. */
17104 eoltype
= eol_mnemonic_undecided
;
17105 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
17106 eoltype
= (XFASTINT (eolvalue
) == 0
17107 ? eol_mnemonic_unix
17108 : (XFASTINT (eolvalue
) == 1
17109 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
17115 /* Mention the EOL conversion if it is not the usual one. */
17116 if (STRINGP (eoltype
))
17118 eol_str
= SDATA (eoltype
);
17119 eol_str_len
= SBYTES (eoltype
);
17121 else if (INTEGERP (eoltype
)
17122 && CHAR_VALID_P (XINT (eoltype
), 0))
17124 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
17125 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
17130 eol_str
= invalid_eol_type
;
17131 eol_str_len
= sizeof (invalid_eol_type
) - 1;
17133 bcopy (eol_str
, buf
, eol_str_len
);
17134 buf
+= eol_str_len
;
17140 /* Return a string for the output of a mode line %-spec for window W,
17141 generated by character C. PRECISION >= 0 means don't return a
17142 string longer than that value. FIELD_WIDTH > 0 means pad the
17143 string returned with spaces to that value. Return 1 in *MULTIBYTE
17144 if the result is multibyte text.
17146 Note we operate on the current buffer for most purposes,
17147 the exception being w->base_line_pos. */
17149 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
17152 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
17155 int field_width
, precision
;
17159 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17160 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
17161 struct buffer
*b
= current_buffer
;
17169 if (!NILP (b
->read_only
))
17171 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17176 /* This differs from %* only for a modified read-only buffer. */
17177 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17179 if (!NILP (b
->read_only
))
17184 /* This differs from %* in ignoring read-only-ness. */
17185 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17197 if (command_loop_level
> 5)
17199 p
= decode_mode_spec_buf
;
17200 for (i
= 0; i
< command_loop_level
; i
++)
17203 return decode_mode_spec_buf
;
17211 if (command_loop_level
> 5)
17213 p
= decode_mode_spec_buf
;
17214 for (i
= 0; i
< command_loop_level
; i
++)
17217 return decode_mode_spec_buf
;
17224 /* Let lots_of_dashes be a string of infinite length. */
17225 if (mode_line_target
== MODE_LINE_NOPROP
||
17226 mode_line_target
== MODE_LINE_STRING
)
17228 if (field_width
<= 0
17229 || field_width
> sizeof (lots_of_dashes
))
17231 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
17232 decode_mode_spec_buf
[i
] = '-';
17233 decode_mode_spec_buf
[i
] = '\0';
17234 return decode_mode_spec_buf
;
17237 return lots_of_dashes
;
17246 int col
= (int) current_column (); /* iftc */
17247 w
->column_number_displayed
= make_number (col
);
17248 pint2str (decode_mode_spec_buf
, field_width
, col
);
17249 return decode_mode_spec_buf
;
17253 #ifndef SYSTEM_MALLOC
17255 if (NILP (Vmemory_full
))
17258 return "!MEM FULL! ";
17265 /* %F displays the frame name. */
17266 if (!NILP (f
->title
))
17267 return (char *) SDATA (f
->title
);
17268 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
17269 return (char *) SDATA (f
->name
);
17278 int size
= ZV
- BEGV
;
17279 pint2str (decode_mode_spec_buf
, field_width
, size
);
17280 return decode_mode_spec_buf
;
17285 int size
= ZV
- BEGV
;
17286 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
17287 return decode_mode_spec_buf
;
17292 int startpos
= XMARKER (w
->start
)->charpos
;
17293 int startpos_byte
= marker_byte_position (w
->start
);
17294 int line
, linepos
, linepos_byte
, topline
;
17296 int height
= WINDOW_TOTAL_LINES (w
);
17298 /* If we decided that this buffer isn't suitable for line numbers,
17299 don't forget that too fast. */
17300 if (EQ (w
->base_line_pos
, w
->buffer
))
17302 /* But do forget it, if the window shows a different buffer now. */
17303 else if (BUFFERP (w
->base_line_pos
))
17304 w
->base_line_pos
= Qnil
;
17306 /* If the buffer is very big, don't waste time. */
17307 if (INTEGERP (Vline_number_display_limit
)
17308 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
17310 w
->base_line_pos
= Qnil
;
17311 w
->base_line_number
= Qnil
;
17315 if (!NILP (w
->base_line_number
)
17316 && !NILP (w
->base_line_pos
)
17317 && XFASTINT (w
->base_line_pos
) <= startpos
)
17319 line
= XFASTINT (w
->base_line_number
);
17320 linepos
= XFASTINT (w
->base_line_pos
);
17321 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
17326 linepos
= BUF_BEGV (b
);
17327 linepos_byte
= BUF_BEGV_BYTE (b
);
17330 /* Count lines from base line to window start position. */
17331 nlines
= display_count_lines (linepos
, linepos_byte
,
17335 topline
= nlines
+ line
;
17337 /* Determine a new base line, if the old one is too close
17338 or too far away, or if we did not have one.
17339 "Too close" means it's plausible a scroll-down would
17340 go back past it. */
17341 if (startpos
== BUF_BEGV (b
))
17343 w
->base_line_number
= make_number (topline
);
17344 w
->base_line_pos
= make_number (BUF_BEGV (b
));
17346 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
17347 || linepos
== BUF_BEGV (b
))
17349 int limit
= BUF_BEGV (b
);
17350 int limit_byte
= BUF_BEGV_BYTE (b
);
17352 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
17354 if (startpos
- distance
> limit
)
17356 limit
= startpos
- distance
;
17357 limit_byte
= CHAR_TO_BYTE (limit
);
17360 nlines
= display_count_lines (startpos
, startpos_byte
,
17362 - (height
* 2 + 30),
17364 /* If we couldn't find the lines we wanted within
17365 line_number_display_limit_width chars per line,
17366 give up on line numbers for this window. */
17367 if (position
== limit_byte
&& limit
== startpos
- distance
)
17369 w
->base_line_pos
= w
->buffer
;
17370 w
->base_line_number
= Qnil
;
17374 w
->base_line_number
= make_number (topline
- nlines
);
17375 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
17378 /* Now count lines from the start pos to point. */
17379 nlines
= display_count_lines (startpos
, startpos_byte
,
17380 PT_BYTE
, PT
, &junk
);
17382 /* Record that we did display the line number. */
17383 line_number_displayed
= 1;
17385 /* Make the string to show. */
17386 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
17387 return decode_mode_spec_buf
;
17390 char* p
= decode_mode_spec_buf
;
17391 int pad
= field_width
- 2;
17397 return decode_mode_spec_buf
;
17403 obj
= b
->mode_name
;
17407 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
17413 int pos
= marker_position (w
->start
);
17414 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17416 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
17418 if (pos
<= BUF_BEGV (b
))
17423 else if (pos
<= BUF_BEGV (b
))
17427 if (total
> 1000000)
17428 /* Do it differently for a large value, to avoid overflow. */
17429 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17431 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17432 /* We can't normally display a 3-digit number,
17433 so get us a 2-digit number that is close. */
17436 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17437 return decode_mode_spec_buf
;
17441 /* Display percentage of size above the bottom of the screen. */
17444 int toppos
= marker_position (w
->start
);
17445 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
17446 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17448 if (botpos
>= BUF_ZV (b
))
17450 if (toppos
<= BUF_BEGV (b
))
17457 if (total
> 1000000)
17458 /* Do it differently for a large value, to avoid overflow. */
17459 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17461 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17462 /* We can't normally display a 3-digit number,
17463 so get us a 2-digit number that is close. */
17466 if (toppos
<= BUF_BEGV (b
))
17467 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
17469 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17470 return decode_mode_spec_buf
;
17475 /* status of process */
17476 obj
= Fget_buffer_process (Fcurrent_buffer ());
17478 return "no process";
17479 #ifdef subprocesses
17480 obj
= Fsymbol_name (Fprocess_status (obj
));
17484 case 't': /* indicate TEXT or BINARY */
17485 #ifdef MODE_LINE_BINARY_TEXT
17486 return MODE_LINE_BINARY_TEXT (b
);
17492 /* coding-system (not including end-of-line format) */
17494 /* coding-system (including end-of-line type) */
17496 int eol_flag
= (c
== 'Z');
17497 char *p
= decode_mode_spec_buf
;
17499 if (! FRAME_WINDOW_P (f
))
17501 /* No need to mention EOL here--the terminal never needs
17502 to do EOL conversion. */
17503 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
17504 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
17506 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
17509 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
17510 #ifdef subprocesses
17511 obj
= Fget_buffer_process (Fcurrent_buffer ());
17512 if (PROCESSP (obj
))
17514 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
17516 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
17519 #endif /* subprocesses */
17522 return decode_mode_spec_buf
;
17528 *multibyte
= STRING_MULTIBYTE (obj
);
17529 return (char *) SDATA (obj
);
17536 /* Count up to COUNT lines starting from START / START_BYTE.
17537 But don't go beyond LIMIT_BYTE.
17538 Return the number of lines thus found (always nonnegative).
17540 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
17543 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
17544 int start
, start_byte
, limit_byte
, count
;
17547 register unsigned char *cursor
;
17548 unsigned char *base
;
17550 register int ceiling
;
17551 register unsigned char *ceiling_addr
;
17552 int orig_count
= count
;
17554 /* If we are not in selective display mode,
17555 check only for newlines. */
17556 int selective_display
= (!NILP (current_buffer
->selective_display
)
17557 && !INTEGERP (current_buffer
->selective_display
));
17561 while (start_byte
< limit_byte
)
17563 ceiling
= BUFFER_CEILING_OF (start_byte
);
17564 ceiling
= min (limit_byte
- 1, ceiling
);
17565 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
17566 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
17569 if (selective_display
)
17570 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
17573 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
17576 if (cursor
!= ceiling_addr
)
17580 start_byte
+= cursor
- base
+ 1;
17581 *byte_pos_ptr
= start_byte
;
17585 if (++cursor
== ceiling_addr
)
17591 start_byte
+= cursor
- base
;
17596 while (start_byte
> limit_byte
)
17598 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
17599 ceiling
= max (limit_byte
, ceiling
);
17600 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
17601 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
17604 if (selective_display
)
17605 while (--cursor
!= ceiling_addr
17606 && *cursor
!= '\n' && *cursor
!= 015)
17609 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
17612 if (cursor
!= ceiling_addr
)
17616 start_byte
+= cursor
- base
+ 1;
17617 *byte_pos_ptr
= start_byte
;
17618 /* When scanning backwards, we should
17619 not count the newline posterior to which we stop. */
17620 return - orig_count
- 1;
17626 /* Here we add 1 to compensate for the last decrement
17627 of CURSOR, which took it past the valid range. */
17628 start_byte
+= cursor
- base
+ 1;
17632 *byte_pos_ptr
= limit_byte
;
17635 return - orig_count
+ count
;
17636 return orig_count
- count
;
17642 /***********************************************************************
17644 ***********************************************************************/
17646 /* Display a NUL-terminated string, starting with index START.
17648 If STRING is non-null, display that C string. Otherwise, the Lisp
17649 string LISP_STRING is displayed.
17651 If FACE_STRING is not nil, FACE_STRING_POS is a position in
17652 FACE_STRING. Display STRING or LISP_STRING with the face at
17653 FACE_STRING_POS in FACE_STRING:
17655 Display the string in the environment given by IT, but use the
17656 standard display table, temporarily.
17658 FIELD_WIDTH is the minimum number of output glyphs to produce.
17659 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17660 with spaces. If STRING has more characters, more than FIELD_WIDTH
17661 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
17663 PRECISION is the maximum number of characters to output from
17664 STRING. PRECISION < 0 means don't truncate the string.
17666 This is roughly equivalent to printf format specifiers:
17668 FIELD_WIDTH PRECISION PRINTF
17669 ----------------------------------------
17675 MULTIBYTE zero means do not display multibyte chars, > 0 means do
17676 display them, and < 0 means obey the current buffer's value of
17677 enable_multibyte_characters.
17679 Value is the number of glyphs produced. */
17682 display_string (string
, lisp_string
, face_string
, face_string_pos
,
17683 start
, it
, field_width
, precision
, max_x
, multibyte
)
17684 unsigned char *string
;
17685 Lisp_Object lisp_string
;
17686 Lisp_Object face_string
;
17687 int face_string_pos
;
17690 int field_width
, precision
, max_x
;
17693 int hpos_at_start
= it
->hpos
;
17694 int saved_face_id
= it
->face_id
;
17695 struct glyph_row
*row
= it
->glyph_row
;
17697 /* Initialize the iterator IT for iteration over STRING beginning
17698 with index START. */
17699 reseat_to_string (it
, string
, lisp_string
, start
,
17700 precision
, field_width
, multibyte
);
17702 /* If displaying STRING, set up the face of the iterator
17703 from LISP_STRING, if that's given. */
17704 if (STRINGP (face_string
))
17710 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
17711 0, it
->region_beg_charpos
,
17712 it
->region_end_charpos
,
17713 &endptr
, it
->base_face_id
, 0);
17714 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17715 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
17718 /* Set max_x to the maximum allowed X position. Don't let it go
17719 beyond the right edge of the window. */
17721 max_x
= it
->last_visible_x
;
17723 max_x
= min (max_x
, it
->last_visible_x
);
17725 /* Skip over display elements that are not visible. because IT->w is
17727 if (it
->current_x
< it
->first_visible_x
)
17728 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
17729 MOVE_TO_POS
| MOVE_TO_X
);
17731 row
->ascent
= it
->max_ascent
;
17732 row
->height
= it
->max_ascent
+ it
->max_descent
;
17733 row
->phys_ascent
= it
->max_phys_ascent
;
17734 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17735 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17737 /* This condition is for the case that we are called with current_x
17738 past last_visible_x. */
17739 while (it
->current_x
< max_x
)
17741 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
17743 /* Get the next display element. */
17744 if (!get_next_display_element (it
))
17747 /* Produce glyphs. */
17748 x_before
= it
->current_x
;
17749 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17750 PRODUCE_GLYPHS (it
);
17752 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
17755 while (i
< nglyphs
)
17757 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17759 if (!it
->truncate_lines_p
17760 && x
+ glyph
->pixel_width
> max_x
)
17762 /* End of continued line or max_x reached. */
17763 if (CHAR_GLYPH_PADDING_P (*glyph
))
17765 /* A wide character is unbreakable. */
17766 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17767 it
->current_x
= x_before
;
17771 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17776 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
17778 /* Glyph is at least partially visible. */
17780 if (x
< it
->first_visible_x
)
17781 it
->glyph_row
->x
= x
- it
->first_visible_x
;
17785 /* Glyph is off the left margin of the display area.
17786 Should not happen. */
17790 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17791 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17792 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17793 row
->phys_height
= max (row
->phys_height
,
17794 it
->max_phys_ascent
+ it
->max_phys_descent
);
17795 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17796 it
->max_extra_line_spacing
);
17797 x
+= glyph
->pixel_width
;
17801 /* Stop if max_x reached. */
17805 /* Stop at line ends. */
17806 if (ITERATOR_AT_END_OF_LINE_P (it
))
17808 it
->continuation_lines_width
= 0;
17812 set_iterator_to_next (it
, 1);
17814 /* Stop if truncating at the right edge. */
17815 if (it
->truncate_lines_p
17816 && it
->current_x
>= it
->last_visible_x
)
17818 /* Add truncation mark, but don't do it if the line is
17819 truncated at a padding space. */
17820 if (IT_CHARPOS (*it
) < it
->string_nchars
)
17822 if (!FRAME_WINDOW_P (it
->f
))
17826 if (it
->current_x
> it
->last_visible_x
)
17828 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17829 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17831 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17833 row
->used
[TEXT_AREA
] = i
;
17834 produce_special_glyphs (it
, IT_TRUNCATION
);
17837 produce_special_glyphs (it
, IT_TRUNCATION
);
17839 it
->glyph_row
->truncated_on_right_p
= 1;
17845 /* Maybe insert a truncation at the left. */
17846 if (it
->first_visible_x
17847 && IT_CHARPOS (*it
) > 0)
17849 if (!FRAME_WINDOW_P (it
->f
))
17850 insert_left_trunc_glyphs (it
);
17851 it
->glyph_row
->truncated_on_left_p
= 1;
17854 it
->face_id
= saved_face_id
;
17856 /* Value is number of columns displayed. */
17857 return it
->hpos
- hpos_at_start
;
17862 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
17863 appears as an element of LIST or as the car of an element of LIST.
17864 If PROPVAL is a list, compare each element against LIST in that
17865 way, and return 1/2 if any element of PROPVAL is found in LIST.
17866 Otherwise return 0. This function cannot quit.
17867 The return value is 2 if the text is invisible but with an ellipsis
17868 and 1 if it's invisible and without an ellipsis. */
17871 invisible_p (propval
, list
)
17872 register Lisp_Object propval
;
17875 register Lisp_Object tail
, proptail
;
17877 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17879 register Lisp_Object tem
;
17881 if (EQ (propval
, tem
))
17883 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
17884 return NILP (XCDR (tem
)) ? 1 : 2;
17887 if (CONSP (propval
))
17889 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
17891 Lisp_Object propelt
;
17892 propelt
= XCAR (proptail
);
17893 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17895 register Lisp_Object tem
;
17897 if (EQ (propelt
, tem
))
17899 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
17900 return NILP (XCDR (tem
)) ? 1 : 2;
17908 /* Calculate a width or height in pixels from a specification using
17909 the following elements:
17912 NUM - a (fractional) multiple of the default font width/height
17913 (NUM) - specifies exactly NUM pixels
17914 UNIT - a fixed number of pixels, see below.
17915 ELEMENT - size of a display element in pixels, see below.
17916 (NUM . SPEC) - equals NUM * SPEC
17917 (+ SPEC SPEC ...) - add pixel values
17918 (- SPEC SPEC ...) - subtract pixel values
17919 (- SPEC) - negate pixel value
17922 INT or FLOAT - a number constant
17923 SYMBOL - use symbol's (buffer local) variable binding.
17926 in - pixels per inch *)
17927 mm - pixels per 1/1000 meter *)
17928 cm - pixels per 1/100 meter *)
17929 width - width of current font in pixels.
17930 height - height of current font in pixels.
17932 *) using the ratio(s) defined in display-pixels-per-inch.
17936 left-fringe - left fringe width in pixels
17937 right-fringe - right fringe width in pixels
17939 left-margin - left margin width in pixels
17940 right-margin - right margin width in pixels
17942 scroll-bar - scroll-bar area width in pixels
17946 Pixels corresponding to 5 inches:
17949 Total width of non-text areas on left side of window (if scroll-bar is on left):
17950 '(space :width (+ left-fringe left-margin scroll-bar))
17952 Align to first text column (in header line):
17953 '(space :align-to 0)
17955 Align to middle of text area minus half the width of variable `my-image'
17956 containing a loaded image:
17957 '(space :align-to (0.5 . (- text my-image)))
17959 Width of left margin minus width of 1 character in the default font:
17960 '(space :width (- left-margin 1))
17962 Width of left margin minus width of 2 characters in the current font:
17963 '(space :width (- left-margin (2 . width)))
17965 Center 1 character over left-margin (in header line):
17966 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
17968 Different ways to express width of left fringe plus left margin minus one pixel:
17969 '(space :width (- (+ left-fringe left-margin) (1)))
17970 '(space :width (+ left-fringe left-margin (- (1))))
17971 '(space :width (+ left-fringe left-margin (-1)))
17975 #define NUMVAL(X) \
17976 ((INTEGERP (X) || FLOATP (X)) \
17981 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
17986 int width_p
, *align_to
;
17990 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
17991 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
17994 return OK_PIXELS (0);
17996 if (SYMBOLP (prop
))
17998 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18000 char *unit
= SDATA (SYMBOL_NAME (prop
));
18002 if (unit
[0] == 'i' && unit
[1] == 'n')
18004 else if (unit
[0] == 'm' && unit
[1] == 'm')
18006 else if (unit
[0] == 'c' && unit
[1] == 'm')
18013 #ifdef HAVE_WINDOW_SYSTEM
18014 if (FRAME_WINDOW_P (it
->f
)
18016 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
18017 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
18019 return OK_PIXELS (ppi
/ pixels
);
18022 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18023 || (CONSP (Vdisplay_pixels_per_inch
)
18025 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18026 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18028 return OK_PIXELS (ppi
/ pixels
);
18034 #ifdef HAVE_WINDOW_SYSTEM
18035 if (EQ (prop
, Qheight
))
18036 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
18037 if (EQ (prop
, Qwidth
))
18038 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
18040 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
18041 return OK_PIXELS (1);
18044 if (EQ (prop
, Qtext
))
18045 return OK_PIXELS (width_p
18046 ? window_box_width (it
->w
, TEXT_AREA
)
18047 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
18049 if (align_to
&& *align_to
< 0)
18052 if (EQ (prop
, Qleft
))
18053 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
18054 if (EQ (prop
, Qright
))
18055 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
18056 if (EQ (prop
, Qcenter
))
18057 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
18058 + window_box_width (it
->w
, TEXT_AREA
) / 2);
18059 if (EQ (prop
, Qleft_fringe
))
18060 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18061 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
18062 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
18063 if (EQ (prop
, Qright_fringe
))
18064 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18065 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18066 : window_box_right_offset (it
->w
, TEXT_AREA
));
18067 if (EQ (prop
, Qleft_margin
))
18068 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
18069 if (EQ (prop
, Qright_margin
))
18070 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
18071 if (EQ (prop
, Qscroll_bar
))
18072 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18074 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18075 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18076 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18081 if (EQ (prop
, Qleft_fringe
))
18082 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18083 if (EQ (prop
, Qright_fringe
))
18084 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18085 if (EQ (prop
, Qleft_margin
))
18086 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18087 if (EQ (prop
, Qright_margin
))
18088 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18089 if (EQ (prop
, Qscroll_bar
))
18090 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18093 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18096 if (INTEGERP (prop
) || FLOATP (prop
))
18098 int base_unit
= (width_p
18099 ? FRAME_COLUMN_WIDTH (it
->f
)
18100 : FRAME_LINE_HEIGHT (it
->f
));
18101 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18106 Lisp_Object car
= XCAR (prop
);
18107 Lisp_Object cdr
= XCDR (prop
);
18111 #ifdef HAVE_WINDOW_SYSTEM
18112 if (valid_image_p (prop
))
18114 int id
= lookup_image (it
->f
, prop
);
18115 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
18117 return OK_PIXELS (width_p
? img
->width
: img
->height
);
18120 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18126 while (CONSP (cdr
))
18128 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
18129 font
, width_p
, align_to
))
18132 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18137 if (EQ (car
, Qminus
))
18139 return OK_PIXELS (pixels
);
18142 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18145 if (INTEGERP (car
) || FLOATP (car
))
18148 pixels
= XFLOATINT (car
);
18150 return OK_PIXELS (pixels
);
18151 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
18152 font
, width_p
, align_to
))
18153 return OK_PIXELS (pixels
* fact
);
18164 /***********************************************************************
18166 ***********************************************************************/
18168 #ifdef HAVE_WINDOW_SYSTEM
18173 dump_glyph_string (s
)
18174 struct glyph_string
*s
;
18176 fprintf (stderr
, "glyph string\n");
18177 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
18178 s
->x
, s
->y
, s
->width
, s
->height
);
18179 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
18180 fprintf (stderr
, " hl = %d\n", s
->hl
);
18181 fprintf (stderr
, " left overhang = %d, right = %d\n",
18182 s
->left_overhang
, s
->right_overhang
);
18183 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
18184 fprintf (stderr
, " extends to end of line = %d\n",
18185 s
->extends_to_end_of_line_p
);
18186 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
18187 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
18190 #endif /* GLYPH_DEBUG */
18192 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
18193 of XChar2b structures for S; it can't be allocated in
18194 init_glyph_string because it must be allocated via `alloca'. W
18195 is the window on which S is drawn. ROW and AREA are the glyph row
18196 and area within the row from which S is constructed. START is the
18197 index of the first glyph structure covered by S. HL is a
18198 face-override for drawing S. */
18201 #define OPTIONAL_HDC(hdc) hdc,
18202 #define DECLARE_HDC(hdc) HDC hdc;
18203 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
18204 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
18207 #ifndef OPTIONAL_HDC
18208 #define OPTIONAL_HDC(hdc)
18209 #define DECLARE_HDC(hdc)
18210 #define ALLOCATE_HDC(hdc, f)
18211 #define RELEASE_HDC(hdc, f)
18215 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
18216 struct glyph_string
*s
;
18220 struct glyph_row
*row
;
18221 enum glyph_row_area area
;
18223 enum draw_glyphs_face hl
;
18225 bzero (s
, sizeof *s
);
18227 s
->f
= XFRAME (w
->frame
);
18231 s
->display
= FRAME_X_DISPLAY (s
->f
);
18232 s
->window
= FRAME_X_WINDOW (s
->f
);
18233 s
->char2b
= char2b
;
18237 s
->first_glyph
= row
->glyphs
[area
] + start
;
18238 s
->height
= row
->height
;
18239 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
18241 /* Display the internal border below the tool-bar window. */
18242 if (WINDOWP (s
->f
->tool_bar_window
)
18243 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
18244 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
18246 s
->ybase
= s
->y
+ row
->ascent
;
18250 /* Append the list of glyph strings with head H and tail T to the list
18251 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
18254 append_glyph_string_lists (head
, tail
, h
, t
)
18255 struct glyph_string
**head
, **tail
;
18256 struct glyph_string
*h
, *t
;
18270 /* Prepend the list of glyph strings with head H and tail T to the
18271 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
18275 prepend_glyph_string_lists (head
, tail
, h
, t
)
18276 struct glyph_string
**head
, **tail
;
18277 struct glyph_string
*h
, *t
;
18291 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
18292 Set *HEAD and *TAIL to the resulting list. */
18295 append_glyph_string (head
, tail
, s
)
18296 struct glyph_string
**head
, **tail
;
18297 struct glyph_string
*s
;
18299 s
->next
= s
->prev
= NULL
;
18300 append_glyph_string_lists (head
, tail
, s
, s
);
18304 /* Get face and two-byte form of character glyph GLYPH on frame F.
18305 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
18306 a pointer to a realized face that is ready for display. */
18308 static INLINE
struct face
*
18309 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
18311 struct glyph
*glyph
;
18317 xassert (glyph
->type
== CHAR_GLYPH
);
18318 face
= FACE_FROM_ID (f
, glyph
->face_id
);
18323 if (!glyph
->multibyte_p
)
18325 /* Unibyte case. We don't have to encode, but we have to make
18326 sure to use a face suitable for unibyte. */
18327 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18329 else if (glyph
->u
.ch
< 128
18330 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
18332 /* Case of ASCII in a face known to fit ASCII. */
18333 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
18337 int c1
, c2
, charset
;
18339 /* Split characters into bytes. If c2 is -1 afterwards, C is
18340 really a one-byte character so that byte1 is zero. */
18341 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
18343 STORE_XCHAR2B (char2b
, c1
, c2
);
18345 STORE_XCHAR2B (char2b
, 0, c1
);
18347 /* Maybe encode the character in *CHAR2B. */
18348 if (charset
!= CHARSET_ASCII
)
18350 struct font_info
*font_info
18351 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18354 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
18358 /* Make sure X resources of the face are allocated. */
18359 xassert (face
!= NULL
);
18360 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18365 /* Fill glyph string S with composition components specified by S->cmp.
18367 FACES is an array of faces for all components of this composition.
18368 S->gidx is the index of the first component for S.
18370 OVERLAPS non-zero means S should draw the foreground only, and use
18371 its physical height for clipping. See also draw_glyphs.
18373 Value is the index of a component not in S. */
18376 fill_composite_glyph_string (s
, faces
, overlaps
)
18377 struct glyph_string
*s
;
18378 struct face
**faces
;
18385 s
->for_overlaps
= overlaps
;
18387 s
->face
= faces
[s
->gidx
];
18388 s
->font
= s
->face
->font
;
18389 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18391 /* For all glyphs of this composition, starting at the offset
18392 S->gidx, until we reach the end of the definition or encounter a
18393 glyph that requires the different face, add it to S. */
18395 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
18398 /* All glyph strings for the same composition has the same width,
18399 i.e. the width set for the first component of the composition. */
18401 s
->width
= s
->first_glyph
->pixel_width
;
18403 /* If the specified font could not be loaded, use the frame's
18404 default font, but record the fact that we couldn't load it in
18405 the glyph string so that we can draw rectangles for the
18406 characters of the glyph string. */
18407 if (s
->font
== NULL
)
18409 s
->font_not_found_p
= 1;
18410 s
->font
= FRAME_FONT (s
->f
);
18413 /* Adjust base line for subscript/superscript text. */
18414 s
->ybase
+= s
->first_glyph
->voffset
;
18416 xassert (s
->face
&& s
->face
->gc
);
18418 /* This glyph string must always be drawn with 16-bit functions. */
18421 return s
->gidx
+ s
->nchars
;
18425 /* Fill glyph string S from a sequence of character glyphs.
18427 FACE_ID is the face id of the string. START is the index of the
18428 first glyph to consider, END is the index of the last + 1.
18429 OVERLAPS non-zero means S should draw the foreground only, and use
18430 its physical height for clipping. See also draw_glyphs.
18432 Value is the index of the first glyph not in S. */
18435 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
18436 struct glyph_string
*s
;
18438 int start
, end
, overlaps
;
18440 struct glyph
*glyph
, *last
;
18442 int glyph_not_available_p
;
18444 xassert (s
->f
== XFRAME (s
->w
->frame
));
18445 xassert (s
->nchars
== 0);
18446 xassert (start
>= 0 && end
> start
);
18448 s
->for_overlaps
= overlaps
,
18449 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18450 last
= s
->row
->glyphs
[s
->area
] + end
;
18451 voffset
= glyph
->voffset
;
18453 glyph_not_available_p
= glyph
->glyph_not_available_p
;
18455 while (glyph
< last
18456 && glyph
->type
== CHAR_GLYPH
18457 && glyph
->voffset
== voffset
18458 /* Same face id implies same font, nowadays. */
18459 && glyph
->face_id
== face_id
18460 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
18464 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
18465 s
->char2b
+ s
->nchars
,
18467 s
->two_byte_p
= two_byte_p
;
18469 xassert (s
->nchars
<= end
- start
);
18470 s
->width
+= glyph
->pixel_width
;
18474 s
->font
= s
->face
->font
;
18475 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18477 /* If the specified font could not be loaded, use the frame's font,
18478 but record the fact that we couldn't load it in
18479 S->font_not_found_p so that we can draw rectangles for the
18480 characters of the glyph string. */
18481 if (s
->font
== NULL
|| glyph_not_available_p
)
18483 s
->font_not_found_p
= 1;
18484 s
->font
= FRAME_FONT (s
->f
);
18487 /* Adjust base line for subscript/superscript text. */
18488 s
->ybase
+= voffset
;
18490 xassert (s
->face
&& s
->face
->gc
);
18491 return glyph
- s
->row
->glyphs
[s
->area
];
18495 /* Fill glyph string S from image glyph S->first_glyph. */
18498 fill_image_glyph_string (s
)
18499 struct glyph_string
*s
;
18501 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
18502 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
18504 s
->slice
= s
->first_glyph
->slice
;
18505 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
18506 s
->font
= s
->face
->font
;
18507 s
->width
= s
->first_glyph
->pixel_width
;
18509 /* Adjust base line for subscript/superscript text. */
18510 s
->ybase
+= s
->first_glyph
->voffset
;
18514 /* Fill glyph string S from a sequence of stretch glyphs.
18516 ROW is the glyph row in which the glyphs are found, AREA is the
18517 area within the row. START is the index of the first glyph to
18518 consider, END is the index of the last + 1.
18520 Value is the index of the first glyph not in S. */
18523 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
18524 struct glyph_string
*s
;
18525 struct glyph_row
*row
;
18526 enum glyph_row_area area
;
18529 struct glyph
*glyph
, *last
;
18530 int voffset
, face_id
;
18532 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
18534 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18535 last
= s
->row
->glyphs
[s
->area
] + end
;
18536 face_id
= glyph
->face_id
;
18537 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
18538 s
->font
= s
->face
->font
;
18539 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18540 s
->width
= glyph
->pixel_width
;
18541 voffset
= glyph
->voffset
;
18545 && glyph
->type
== STRETCH_GLYPH
18546 && glyph
->voffset
== voffset
18547 && glyph
->face_id
== face_id
);
18549 s
->width
+= glyph
->pixel_width
;
18551 /* Adjust base line for subscript/superscript text. */
18552 s
->ybase
+= voffset
;
18554 /* The case that face->gc == 0 is handled when drawing the glyph
18555 string by calling PREPARE_FACE_FOR_DISPLAY. */
18557 return glyph
- s
->row
->glyphs
[s
->area
];
18562 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
18563 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
18564 assumed to be zero. */
18567 x_get_glyph_overhangs (glyph
, f
, left
, right
)
18568 struct glyph
*glyph
;
18572 *left
= *right
= 0;
18574 if (glyph
->type
== CHAR_GLYPH
)
18578 struct font_info
*font_info
;
18582 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
18584 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18585 if (font
/* ++KFS: Should this be font_info ? */
18586 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
18588 if (pcm
->rbearing
> pcm
->width
)
18589 *right
= pcm
->rbearing
- pcm
->width
;
18590 if (pcm
->lbearing
< 0)
18591 *left
= -pcm
->lbearing
;
18597 /* Return the index of the first glyph preceding glyph string S that
18598 is overwritten by S because of S's left overhang. Value is -1
18599 if no glyphs are overwritten. */
18602 left_overwritten (s
)
18603 struct glyph_string
*s
;
18607 if (s
->left_overhang
)
18610 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18611 int first
= s
->first_glyph
- glyphs
;
18613 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
18614 x
-= glyphs
[i
].pixel_width
;
18625 /* Return the index of the first glyph preceding glyph string S that
18626 is overwriting S because of its right overhang. Value is -1 if no
18627 glyph in front of S overwrites S. */
18630 left_overwriting (s
)
18631 struct glyph_string
*s
;
18634 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18635 int first
= s
->first_glyph
- glyphs
;
18639 for (i
= first
- 1; i
>= 0; --i
)
18642 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18645 x
-= glyphs
[i
].pixel_width
;
18652 /* Return the index of the last glyph following glyph string S that is
18653 not overwritten by S because of S's right overhang. Value is -1 if
18654 no such glyph is found. */
18657 right_overwritten (s
)
18658 struct glyph_string
*s
;
18662 if (s
->right_overhang
)
18665 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18666 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18667 int end
= s
->row
->used
[s
->area
];
18669 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
18670 x
+= glyphs
[i
].pixel_width
;
18679 /* Return the index of the last glyph following glyph string S that
18680 overwrites S because of its left overhang. Value is negative
18681 if no such glyph is found. */
18684 right_overwriting (s
)
18685 struct glyph_string
*s
;
18688 int end
= s
->row
->used
[s
->area
];
18689 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18690 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18694 for (i
= first
; i
< end
; ++i
)
18697 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18700 x
+= glyphs
[i
].pixel_width
;
18707 /* Get face and two-byte form of character C in face FACE_ID on frame
18708 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
18709 means we want to display multibyte text. DISPLAY_P non-zero means
18710 make sure that X resources for the face returned are allocated.
18711 Value is a pointer to a realized face that is ready for display if
18712 DISPLAY_P is non-zero. */
18714 static INLINE
struct face
*
18715 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
18719 int multibyte_p
, display_p
;
18721 struct face
*face
= FACE_FROM_ID (f
, face_id
);
18725 /* Unibyte case. We don't have to encode, but we have to make
18726 sure to use a face suitable for unibyte. */
18727 STORE_XCHAR2B (char2b
, 0, c
);
18728 face_id
= FACE_FOR_CHAR (f
, face
, c
);
18729 face
= FACE_FROM_ID (f
, face_id
);
18731 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
18733 /* Case of ASCII in a face known to fit ASCII. */
18734 STORE_XCHAR2B (char2b
, 0, c
);
18738 int c1
, c2
, charset
;
18740 /* Split characters into bytes. If c2 is -1 afterwards, C is
18741 really a one-byte character so that byte1 is zero. */
18742 SPLIT_CHAR (c
, charset
, c1
, c2
);
18744 STORE_XCHAR2B (char2b
, c1
, c2
);
18746 STORE_XCHAR2B (char2b
, 0, c1
);
18748 /* Maybe encode the character in *CHAR2B. */
18749 if (face
->font
!= NULL
)
18751 struct font_info
*font_info
18752 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18754 rif
->encode_char (c
, char2b
, font_info
, 0);
18758 /* Make sure X resources of the face are allocated. */
18759 #ifdef HAVE_X_WINDOWS
18763 xassert (face
!= NULL
);
18764 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18771 /* Set background width of glyph string S. START is the index of the
18772 first glyph following S. LAST_X is the right-most x-position + 1
18773 in the drawing area. */
18776 set_glyph_string_background_width (s
, start
, last_x
)
18777 struct glyph_string
*s
;
18781 /* If the face of this glyph string has to be drawn to the end of
18782 the drawing area, set S->extends_to_end_of_line_p. */
18784 if (start
== s
->row
->used
[s
->area
]
18785 && s
->area
== TEXT_AREA
18786 && ((s
->row
->fill_line_p
18787 && (s
->hl
== DRAW_NORMAL_TEXT
18788 || s
->hl
== DRAW_IMAGE_RAISED
18789 || s
->hl
== DRAW_IMAGE_SUNKEN
))
18790 || s
->hl
== DRAW_MOUSE_FACE
))
18791 s
->extends_to_end_of_line_p
= 1;
18793 /* If S extends its face to the end of the line, set its
18794 background_width to the distance to the right edge of the drawing
18796 if (s
->extends_to_end_of_line_p
)
18797 s
->background_width
= last_x
- s
->x
+ 1;
18799 s
->background_width
= s
->width
;
18803 /* Compute overhangs and x-positions for glyph string S and its
18804 predecessors, or successors. X is the starting x-position for S.
18805 BACKWARD_P non-zero means process predecessors. */
18808 compute_overhangs_and_x (s
, x
, backward_p
)
18809 struct glyph_string
*s
;
18817 if (rif
->compute_glyph_string_overhangs
)
18818 rif
->compute_glyph_string_overhangs (s
);
18828 if (rif
->compute_glyph_string_overhangs
)
18829 rif
->compute_glyph_string_overhangs (s
);
18839 /* The following macros are only called from draw_glyphs below.
18840 They reference the following parameters of that function directly:
18841 `w', `row', `area', and `overlap_p'
18842 as well as the following local variables:
18843 `s', `f', and `hdc' (in W32) */
18846 /* On W32, silently add local `hdc' variable to argument list of
18847 init_glyph_string. */
18848 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18849 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
18851 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18852 init_glyph_string (s, char2b, w, row, area, start, hl)
18855 /* Add a glyph string for a stretch glyph to the list of strings
18856 between HEAD and TAIL. START is the index of the stretch glyph in
18857 row area AREA of glyph row ROW. END is the index of the last glyph
18858 in that glyph row area. X is the current output position assigned
18859 to the new glyph string constructed. HL overrides that face of the
18860 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18861 is the right-most x-position of the drawing area. */
18863 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
18864 and below -- keep them on one line. */
18865 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18868 s = (struct glyph_string *) alloca (sizeof *s); \
18869 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18870 START = fill_stretch_glyph_string (s, row, area, START, END); \
18871 append_glyph_string (&HEAD, &TAIL, s); \
18877 /* Add a glyph string for an image glyph to the list of strings
18878 between HEAD and TAIL. START is the index of the image glyph in
18879 row area AREA of glyph row ROW. END is the index of the last glyph
18880 in that glyph row area. X is the current output position assigned
18881 to the new glyph string constructed. HL overrides that face of the
18882 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18883 is the right-most x-position of the drawing area. */
18885 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18888 s = (struct glyph_string *) alloca (sizeof *s); \
18889 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18890 fill_image_glyph_string (s); \
18891 append_glyph_string (&HEAD, &TAIL, s); \
18898 /* Add a glyph string for a sequence of character glyphs to the list
18899 of strings between HEAD and TAIL. START is the index of the first
18900 glyph in row area AREA of glyph row ROW that is part of the new
18901 glyph string. END is the index of the last glyph in that glyph row
18902 area. X is the current output position assigned to the new glyph
18903 string constructed. HL overrides that face of the glyph; e.g. it
18904 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
18905 right-most x-position of the drawing area. */
18907 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18913 c = (row)->glyphs[area][START].u.ch; \
18914 face_id = (row)->glyphs[area][START].face_id; \
18916 s = (struct glyph_string *) alloca (sizeof *s); \
18917 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
18918 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
18919 append_glyph_string (&HEAD, &TAIL, s); \
18921 START = fill_glyph_string (s, face_id, START, END, overlaps); \
18926 /* Add a glyph string for a composite sequence to the list of strings
18927 between HEAD and TAIL. START is the index of the first glyph in
18928 row area AREA of glyph row ROW that is part of the new glyph
18929 string. END is the index of the last glyph in that glyph row area.
18930 X is the current output position assigned to the new glyph string
18931 constructed. HL overrides that face of the glyph; e.g. it is
18932 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
18933 x-position of the drawing area. */
18935 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18937 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
18938 int face_id = (row)->glyphs[area][START].face_id; \
18939 struct face *base_face = FACE_FROM_ID (f, face_id); \
18940 struct composition *cmp = composition_table[cmp_id]; \
18941 int glyph_len = cmp->glyph_len; \
18943 struct face **faces; \
18944 struct glyph_string *first_s = NULL; \
18947 base_face = base_face->ascii_face; \
18948 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
18949 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
18950 /* At first, fill in `char2b' and `faces'. */ \
18951 for (n = 0; n < glyph_len; n++) \
18953 int c = COMPOSITION_GLYPH (cmp, n); \
18954 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
18955 faces[n] = FACE_FROM_ID (f, this_face_id); \
18956 get_char_face_and_encoding (f, c, this_face_id, \
18957 char2b + n, 1, 1); \
18960 /* Make glyph_strings for each glyph sequence that is drawable by \
18961 the same face, and append them to HEAD/TAIL. */ \
18962 for (n = 0; n < cmp->glyph_len;) \
18964 s = (struct glyph_string *) alloca (sizeof *s); \
18965 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
18966 append_glyph_string (&(HEAD), &(TAIL), s); \
18974 n = fill_composite_glyph_string (s, faces, overlaps); \
18982 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
18983 of AREA of glyph row ROW on window W between indices START and END.
18984 HL overrides the face for drawing glyph strings, e.g. it is
18985 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
18986 x-positions of the drawing area.
18988 This is an ugly monster macro construct because we must use alloca
18989 to allocate glyph strings (because draw_glyphs can be called
18990 asynchronously). */
18992 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18995 HEAD = TAIL = NULL; \
18996 while (START < END) \
18998 struct glyph *first_glyph = (row)->glyphs[area] + START; \
18999 switch (first_glyph->type) \
19002 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
19006 case COMPOSITE_GLYPH: \
19007 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
19011 case STRETCH_GLYPH: \
19012 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
19016 case IMAGE_GLYPH: \
19017 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
19025 set_glyph_string_background_width (s, START, LAST_X); \
19032 /* Draw glyphs between START and END in AREA of ROW on window W,
19033 starting at x-position X. X is relative to AREA in W. HL is a
19034 face-override with the following meaning:
19036 DRAW_NORMAL_TEXT draw normally
19037 DRAW_CURSOR draw in cursor face
19038 DRAW_MOUSE_FACE draw in mouse face.
19039 DRAW_INVERSE_VIDEO draw in mode line face
19040 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
19041 DRAW_IMAGE_RAISED draw an image with a raised relief around it
19043 If OVERLAPS is non-zero, draw only the foreground of characters and
19044 clip to the physical height of ROW. Non-zero value also defines
19045 the overlapping part to be drawn:
19047 OVERLAPS_PRED overlap with preceding rows
19048 OVERLAPS_SUCC overlap with succeeding rows
19049 OVERLAPS_BOTH overlap with both preceding/succeeding rows
19050 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
19052 Value is the x-position reached, relative to AREA of W. */
19055 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
19058 struct glyph_row
*row
;
19059 enum glyph_row_area area
;
19061 enum draw_glyphs_face hl
;
19064 struct glyph_string
*head
, *tail
;
19065 struct glyph_string
*s
;
19066 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
19067 int last_x
, area_width
;
19070 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19073 ALLOCATE_HDC (hdc
, f
);
19075 /* Let's rather be paranoid than getting a SEGV. */
19076 end
= min (end
, row
->used
[area
]);
19077 start
= max (0, start
);
19078 start
= min (end
, start
);
19080 /* Translate X to frame coordinates. Set last_x to the right
19081 end of the drawing area. */
19082 if (row
->full_width_p
)
19084 /* X is relative to the left edge of W, without scroll bars
19086 x
+= WINDOW_LEFT_EDGE_X (w
);
19087 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
19091 int area_left
= window_box_left (w
, area
);
19093 area_width
= window_box_width (w
, area
);
19094 last_x
= area_left
+ area_width
;
19097 /* Build a doubly-linked list of glyph_string structures between
19098 head and tail from what we have to draw. Note that the macro
19099 BUILD_GLYPH_STRINGS will modify its start parameter. That's
19100 the reason we use a separate variable `i'. */
19102 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
19104 x_reached
= tail
->x
+ tail
->background_width
;
19108 /* If there are any glyphs with lbearing < 0 or rbearing > width in
19109 the row, redraw some glyphs in front or following the glyph
19110 strings built above. */
19111 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
19114 struct glyph_string
*h
, *t
;
19116 /* Compute overhangs for all glyph strings. */
19117 if (rif
->compute_glyph_string_overhangs
)
19118 for (s
= head
; s
; s
= s
->next
)
19119 rif
->compute_glyph_string_overhangs (s
);
19121 /* Prepend glyph strings for glyphs in front of the first glyph
19122 string that are overwritten because of the first glyph
19123 string's left overhang. The background of all strings
19124 prepended must be drawn because the first glyph string
19126 i
= left_overwritten (head
);
19130 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
19131 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19133 compute_overhangs_and_x (t
, head
->x
, 1);
19134 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19138 /* Prepend glyph strings for glyphs in front of the first glyph
19139 string that overwrite that glyph string because of their
19140 right overhang. For these strings, only the foreground must
19141 be drawn, because it draws over the glyph string at `head'.
19142 The background must not be drawn because this would overwrite
19143 right overhangs of preceding glyphs for which no glyph
19145 i
= left_overwriting (head
);
19149 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
19150 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19151 for (s
= h
; s
; s
= s
->next
)
19152 s
->background_filled_p
= 1;
19153 compute_overhangs_and_x (t
, head
->x
, 1);
19154 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19157 /* Append glyphs strings for glyphs following the last glyph
19158 string tail that are overwritten by tail. The background of
19159 these strings has to be drawn because tail's foreground draws
19161 i
= right_overwritten (tail
);
19164 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19165 DRAW_NORMAL_TEXT
, x
, last_x
);
19166 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19167 append_glyph_string_lists (&head
, &tail
, h
, t
);
19171 /* Append glyph strings for glyphs following the last glyph
19172 string tail that overwrite tail. The foreground of such
19173 glyphs has to be drawn because it writes into the background
19174 of tail. The background must not be drawn because it could
19175 paint over the foreground of following glyphs. */
19176 i
= right_overwriting (tail
);
19180 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19181 DRAW_NORMAL_TEXT
, x
, last_x
);
19182 for (s
= h
; s
; s
= s
->next
)
19183 s
->background_filled_p
= 1;
19184 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19185 append_glyph_string_lists (&head
, &tail
, h
, t
);
19187 if (clip_head
|| clip_tail
)
19188 for (s
= head
; s
; s
= s
->next
)
19190 s
->clip_head
= clip_head
;
19191 s
->clip_tail
= clip_tail
;
19195 /* Draw all strings. */
19196 for (s
= head
; s
; s
= s
->next
)
19197 rif
->draw_glyph_string (s
);
19199 if (area
== TEXT_AREA
19200 && !row
->full_width_p
19201 /* When drawing overlapping rows, only the glyph strings'
19202 foreground is drawn, which doesn't erase a cursor
19206 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
19207 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
19208 : (tail
? tail
->x
+ tail
->background_width
: x
));
19210 int text_left
= window_box_left (w
, TEXT_AREA
);
19214 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
19215 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
19218 /* Value is the x-position up to which drawn, relative to AREA of W.
19219 This doesn't include parts drawn because of overhangs. */
19220 if (row
->full_width_p
)
19221 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
19223 x_reached
-= window_box_left (w
, area
);
19225 RELEASE_HDC (hdc
, f
);
19230 /* Expand row matrix if too narrow. Don't expand if area
19233 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
19235 if (!fonts_changed_p \
19236 && (it->glyph_row->glyphs[area] \
19237 < it->glyph_row->glyphs[area + 1])) \
19239 it->w->ncols_scale_factor++; \
19240 fonts_changed_p = 1; \
19244 /* Store one glyph for IT->char_to_display in IT->glyph_row.
19245 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19251 struct glyph
*glyph
;
19252 enum glyph_row_area area
= it
->area
;
19254 xassert (it
->glyph_row
);
19255 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
19257 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19258 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19260 glyph
->charpos
= CHARPOS (it
->position
);
19261 glyph
->object
= it
->object
;
19262 glyph
->pixel_width
= it
->pixel_width
;
19263 glyph
->ascent
= it
->ascent
;
19264 glyph
->descent
= it
->descent
;
19265 glyph
->voffset
= it
->voffset
;
19266 glyph
->type
= CHAR_GLYPH
;
19267 glyph
->multibyte_p
= it
->multibyte_p
;
19268 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19269 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19270 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19271 || it
->phys_descent
> it
->descent
);
19272 glyph
->padding_p
= 0;
19273 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
19274 glyph
->face_id
= it
->face_id
;
19275 glyph
->u
.ch
= it
->char_to_display
;
19276 glyph
->slice
= null_glyph_slice
;
19277 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19278 ++it
->glyph_row
->used
[area
];
19281 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19284 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
19285 Called from x_produce_glyphs when IT->glyph_row is non-null. */
19288 append_composite_glyph (it
)
19291 struct glyph
*glyph
;
19292 enum glyph_row_area area
= it
->area
;
19294 xassert (it
->glyph_row
);
19296 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19297 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19299 glyph
->charpos
= CHARPOS (it
->position
);
19300 glyph
->object
= it
->object
;
19301 glyph
->pixel_width
= it
->pixel_width
;
19302 glyph
->ascent
= it
->ascent
;
19303 glyph
->descent
= it
->descent
;
19304 glyph
->voffset
= it
->voffset
;
19305 glyph
->type
= COMPOSITE_GLYPH
;
19306 glyph
->multibyte_p
= it
->multibyte_p
;
19307 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19308 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19309 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
19310 || it
->phys_descent
> it
->descent
);
19311 glyph
->padding_p
= 0;
19312 glyph
->glyph_not_available_p
= 0;
19313 glyph
->face_id
= it
->face_id
;
19314 glyph
->u
.cmp_id
= it
->cmp_id
;
19315 glyph
->slice
= null_glyph_slice
;
19316 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19317 ++it
->glyph_row
->used
[area
];
19320 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19324 /* Change IT->ascent and IT->height according to the setting of
19328 take_vertical_position_into_account (it
)
19333 if (it
->voffset
< 0)
19334 /* Increase the ascent so that we can display the text higher
19336 it
->ascent
-= it
->voffset
;
19338 /* Increase the descent so that we can display the text lower
19340 it
->descent
+= it
->voffset
;
19345 /* Produce glyphs/get display metrics for the image IT is loaded with.
19346 See the description of struct display_iterator in dispextern.h for
19347 an overview of struct display_iterator. */
19350 produce_image_glyph (it
)
19356 struct glyph_slice slice
;
19358 xassert (it
->what
== IT_IMAGE
);
19360 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19362 /* Make sure X resources of the face is loaded. */
19363 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19365 if (it
->image_id
< 0)
19367 /* Fringe bitmap. */
19368 it
->ascent
= it
->phys_ascent
= 0;
19369 it
->descent
= it
->phys_descent
= 0;
19370 it
->pixel_width
= 0;
19375 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
19377 /* Make sure X resources of the image is loaded. */
19378 prepare_image_for_display (it
->f
, img
);
19380 slice
.x
= slice
.y
= 0;
19381 slice
.width
= img
->width
;
19382 slice
.height
= img
->height
;
19384 if (INTEGERP (it
->slice
.x
))
19385 slice
.x
= XINT (it
->slice
.x
);
19386 else if (FLOATP (it
->slice
.x
))
19387 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
19389 if (INTEGERP (it
->slice
.y
))
19390 slice
.y
= XINT (it
->slice
.y
);
19391 else if (FLOATP (it
->slice
.y
))
19392 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
19394 if (INTEGERP (it
->slice
.width
))
19395 slice
.width
= XINT (it
->slice
.width
);
19396 else if (FLOATP (it
->slice
.width
))
19397 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
19399 if (INTEGERP (it
->slice
.height
))
19400 slice
.height
= XINT (it
->slice
.height
);
19401 else if (FLOATP (it
->slice
.height
))
19402 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
19404 if (slice
.x
>= img
->width
)
19405 slice
.x
= img
->width
;
19406 if (slice
.y
>= img
->height
)
19407 slice
.y
= img
->height
;
19408 if (slice
.x
+ slice
.width
>= img
->width
)
19409 slice
.width
= img
->width
- slice
.x
;
19410 if (slice
.y
+ slice
.height
> img
->height
)
19411 slice
.height
= img
->height
- slice
.y
;
19413 if (slice
.width
== 0 || slice
.height
== 0)
19416 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
19418 it
->descent
= slice
.height
- glyph_ascent
;
19420 it
->descent
+= img
->vmargin
;
19421 if (slice
.y
+ slice
.height
== img
->height
)
19422 it
->descent
+= img
->vmargin
;
19423 it
->phys_descent
= it
->descent
;
19425 it
->pixel_width
= slice
.width
;
19427 it
->pixel_width
+= img
->hmargin
;
19428 if (slice
.x
+ slice
.width
== img
->width
)
19429 it
->pixel_width
+= img
->hmargin
;
19431 /* It's quite possible for images to have an ascent greater than
19432 their height, so don't get confused in that case. */
19433 if (it
->descent
< 0)
19436 #if 0 /* this breaks image tiling */
19437 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
19438 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
19439 if (face_ascent
> it
->ascent
)
19440 it
->ascent
= it
->phys_ascent
= face_ascent
;
19445 if (face
->box
!= FACE_NO_BOX
)
19447 if (face
->box_line_width
> 0)
19450 it
->ascent
+= face
->box_line_width
;
19451 if (slice
.y
+ slice
.height
== img
->height
)
19452 it
->descent
+= face
->box_line_width
;
19455 if (it
->start_of_box_run_p
&& slice
.x
== 0)
19456 it
->pixel_width
+= abs (face
->box_line_width
);
19457 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
19458 it
->pixel_width
+= abs (face
->box_line_width
);
19461 take_vertical_position_into_account (it
);
19465 struct glyph
*glyph
;
19466 enum glyph_row_area area
= it
->area
;
19468 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19469 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19471 glyph
->charpos
= CHARPOS (it
->position
);
19472 glyph
->object
= it
->object
;
19473 glyph
->pixel_width
= it
->pixel_width
;
19474 glyph
->ascent
= glyph_ascent
;
19475 glyph
->descent
= it
->descent
;
19476 glyph
->voffset
= it
->voffset
;
19477 glyph
->type
= IMAGE_GLYPH
;
19478 glyph
->multibyte_p
= it
->multibyte_p
;
19479 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19480 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19481 glyph
->overlaps_vertically_p
= 0;
19482 glyph
->padding_p
= 0;
19483 glyph
->glyph_not_available_p
= 0;
19484 glyph
->face_id
= it
->face_id
;
19485 glyph
->u
.img_id
= img
->id
;
19486 glyph
->slice
= slice
;
19487 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19488 ++it
->glyph_row
->used
[area
];
19491 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19496 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
19497 of the glyph, WIDTH and HEIGHT are the width and height of the
19498 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
19501 append_stretch_glyph (it
, object
, width
, height
, ascent
)
19503 Lisp_Object object
;
19507 struct glyph
*glyph
;
19508 enum glyph_row_area area
= it
->area
;
19510 xassert (ascent
>= 0 && ascent
<= height
);
19512 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19513 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19515 glyph
->charpos
= CHARPOS (it
->position
);
19516 glyph
->object
= object
;
19517 glyph
->pixel_width
= width
;
19518 glyph
->ascent
= ascent
;
19519 glyph
->descent
= height
- ascent
;
19520 glyph
->voffset
= it
->voffset
;
19521 glyph
->type
= STRETCH_GLYPH
;
19522 glyph
->multibyte_p
= it
->multibyte_p
;
19523 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19524 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19525 glyph
->overlaps_vertically_p
= 0;
19526 glyph
->padding_p
= 0;
19527 glyph
->glyph_not_available_p
= 0;
19528 glyph
->face_id
= it
->face_id
;
19529 glyph
->u
.stretch
.ascent
= ascent
;
19530 glyph
->u
.stretch
.height
= height
;
19531 glyph
->slice
= null_glyph_slice
;
19532 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19533 ++it
->glyph_row
->used
[area
];
19536 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19540 /* Produce a stretch glyph for iterator IT. IT->object is the value
19541 of the glyph property displayed. The value must be a list
19542 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
19545 1. `:width WIDTH' specifies that the space should be WIDTH *
19546 canonical char width wide. WIDTH may be an integer or floating
19549 2. `:relative-width FACTOR' specifies that the width of the stretch
19550 should be computed from the width of the first character having the
19551 `glyph' property, and should be FACTOR times that width.
19553 3. `:align-to HPOS' specifies that the space should be wide enough
19554 to reach HPOS, a value in canonical character units.
19556 Exactly one of the above pairs must be present.
19558 4. `:height HEIGHT' specifies that the height of the stretch produced
19559 should be HEIGHT, measured in canonical character units.
19561 5. `:relative-height FACTOR' specifies that the height of the
19562 stretch should be FACTOR times the height of the characters having
19563 the glyph property.
19565 Either none or exactly one of 4 or 5 must be present.
19567 6. `:ascent ASCENT' specifies that ASCENT percent of the height
19568 of the stretch should be used for the ascent of the stretch.
19569 ASCENT must be in the range 0 <= ASCENT <= 100. */
19572 produce_stretch_glyph (it
)
19575 /* (space :width WIDTH :height HEIGHT ...) */
19576 Lisp_Object prop
, plist
;
19577 int width
= 0, height
= 0, align_to
= -1;
19578 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
19581 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19582 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
19584 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19586 /* List should start with `space'. */
19587 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
19588 plist
= XCDR (it
->object
);
19590 /* Compute the width of the stretch. */
19591 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
19592 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
19594 /* Absolute width `:width WIDTH' specified and valid. */
19595 zero_width_ok_p
= 1;
19598 else if (prop
= Fplist_get (plist
, QCrelative_width
),
19601 /* Relative width `:relative-width FACTOR' specified and valid.
19602 Compute the width of the characters having the `glyph'
19605 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
19608 if (it
->multibyte_p
)
19610 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
19611 - IT_BYTEPOS (*it
));
19612 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
19615 it2
.c
= *p
, it2
.len
= 1;
19617 it2
.glyph_row
= NULL
;
19618 it2
.what
= IT_CHARACTER
;
19619 x_produce_glyphs (&it2
);
19620 width
= NUMVAL (prop
) * it2
.pixel_width
;
19622 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
19623 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
19625 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
19626 align_to
= (align_to
< 0
19628 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
19629 else if (align_to
< 0)
19630 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
19631 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
19632 zero_width_ok_p
= 1;
19635 /* Nothing specified -> width defaults to canonical char width. */
19636 width
= FRAME_COLUMN_WIDTH (it
->f
);
19638 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
19641 /* Compute height. */
19642 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
19643 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19646 zero_height_ok_p
= 1;
19648 else if (prop
= Fplist_get (plist
, QCrelative_height
),
19650 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
19652 height
= FONT_HEIGHT (font
);
19654 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
19657 /* Compute percentage of height used for ascent. If
19658 `:ascent ASCENT' is present and valid, use that. Otherwise,
19659 derive the ascent from the font in use. */
19660 if (prop
= Fplist_get (plist
, QCascent
),
19661 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
19662 ascent
= height
* NUMVAL (prop
) / 100.0;
19663 else if (!NILP (prop
)
19664 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19665 ascent
= min (max (0, (int)tem
), height
);
19667 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
19669 if (width
> 0 && height
> 0 && it
->glyph_row
)
19671 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
19672 if (!STRINGP (object
))
19673 object
= it
->w
->buffer
;
19674 append_stretch_glyph (it
, object
, width
, height
, ascent
);
19677 it
->pixel_width
= width
;
19678 it
->ascent
= it
->phys_ascent
= ascent
;
19679 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
19680 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
19682 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
19684 if (face
->box_line_width
> 0)
19686 it
->ascent
+= face
->box_line_width
;
19687 it
->descent
+= face
->box_line_width
;
19690 if (it
->start_of_box_run_p
)
19691 it
->pixel_width
+= abs (face
->box_line_width
);
19692 if (it
->end_of_box_run_p
)
19693 it
->pixel_width
+= abs (face
->box_line_width
);
19696 take_vertical_position_into_account (it
);
19699 /* Get line-height and line-spacing property at point.
19700 If line-height has format (HEIGHT TOTAL), return TOTAL
19701 in TOTAL_HEIGHT. */
19704 get_line_height_property (it
, prop
)
19708 Lisp_Object position
;
19710 if (STRINGP (it
->object
))
19711 position
= make_number (IT_STRING_CHARPOS (*it
));
19712 else if (BUFFERP (it
->object
))
19713 position
= make_number (IT_CHARPOS (*it
));
19717 return Fget_char_property (position
, prop
, it
->object
);
19720 /* Calculate line-height and line-spacing properties.
19721 An integer value specifies explicit pixel value.
19722 A float value specifies relative value to current face height.
19723 A cons (float . face-name) specifies relative value to
19724 height of specified face font.
19726 Returns height in pixels, or nil. */
19730 calc_line_height_property (it
, val
, font
, boff
, override
)
19734 int boff
, override
;
19736 Lisp_Object face_name
= Qnil
;
19737 int ascent
, descent
, height
;
19739 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
19744 face_name
= XCAR (val
);
19746 if (!NUMBERP (val
))
19747 val
= make_number (1);
19748 if (NILP (face_name
))
19750 height
= it
->ascent
+ it
->descent
;
19755 if (NILP (face_name
))
19757 font
= FRAME_FONT (it
->f
);
19758 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19760 else if (EQ (face_name
, Qt
))
19768 struct font_info
*font_info
;
19770 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
19772 return make_number (-1);
19774 face
= FACE_FROM_ID (it
->f
, face_id
);
19777 return make_number (-1);
19779 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19780 boff
= font_info
->baseline_offset
;
19781 if (font_info
->vertical_centering
)
19782 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19785 ascent
= FONT_BASE (font
) + boff
;
19786 descent
= FONT_DESCENT (font
) - boff
;
19790 it
->override_ascent
= ascent
;
19791 it
->override_descent
= descent
;
19792 it
->override_boff
= boff
;
19795 height
= ascent
+ descent
;
19799 height
= (int)(XFLOAT_DATA (val
) * height
);
19800 else if (INTEGERP (val
))
19801 height
*= XINT (val
);
19803 return make_number (height
);
19808 Produce glyphs/get display metrics for the display element IT is
19809 loaded with. See the description of struct display_iterator in
19810 dispextern.h for an overview of struct display_iterator. */
19813 x_produce_glyphs (it
)
19816 int extra_line_spacing
= it
->extra_line_spacing
;
19818 it
->glyph_not_available_p
= 0;
19820 if (it
->what
== IT_CHARACTER
)
19824 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19826 int font_not_found_p
;
19827 struct font_info
*font_info
;
19828 int boff
; /* baseline offset */
19829 /* We may change it->multibyte_p upon unibyte<->multibyte
19830 conversion. So, save the current value now and restore it
19833 Note: It seems that we don't have to record multibyte_p in
19834 struct glyph because the character code itself tells if or
19835 not the character is multibyte. Thus, in the future, we must
19836 consider eliminating the field `multibyte_p' in the struct
19838 int saved_multibyte_p
= it
->multibyte_p
;
19840 /* Maybe translate single-byte characters to multibyte, or the
19842 it
->char_to_display
= it
->c
;
19843 if (!ASCII_BYTE_P (it
->c
))
19845 if (unibyte_display_via_language_environment
19846 && SINGLE_BYTE_CHAR_P (it
->c
)
19848 || !NILP (Vnonascii_translation_table
)))
19850 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19851 it
->multibyte_p
= 1;
19852 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19853 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19855 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
19856 && !it
->multibyte_p
)
19858 it
->multibyte_p
= 1;
19859 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19860 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19864 /* Get font to use. Encode IT->char_to_display. */
19865 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19866 &char2b
, it
->multibyte_p
, 0);
19869 /* When no suitable font found, use the default font. */
19870 font_not_found_p
= font
== NULL
;
19871 if (font_not_found_p
)
19873 font
= FRAME_FONT (it
->f
);
19874 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19879 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19880 boff
= font_info
->baseline_offset
;
19881 if (font_info
->vertical_centering
)
19882 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19885 if (it
->char_to_display
>= ' '
19886 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
19888 /* Either unibyte or ASCII. */
19893 pcm
= rif
->per_char_metric (font
, &char2b
,
19894 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
19896 if (it
->override_ascent
>= 0)
19898 it
->ascent
= it
->override_ascent
;
19899 it
->descent
= it
->override_descent
;
19900 boff
= it
->override_boff
;
19904 it
->ascent
= FONT_BASE (font
) + boff
;
19905 it
->descent
= FONT_DESCENT (font
) - boff
;
19910 it
->phys_ascent
= pcm
->ascent
+ boff
;
19911 it
->phys_descent
= pcm
->descent
- boff
;
19912 it
->pixel_width
= pcm
->width
;
19916 it
->glyph_not_available_p
= 1;
19917 it
->phys_ascent
= it
->ascent
;
19918 it
->phys_descent
= it
->descent
;
19919 it
->pixel_width
= FONT_WIDTH (font
);
19922 if (it
->constrain_row_ascent_descent_p
)
19924 if (it
->descent
> it
->max_descent
)
19926 it
->ascent
+= it
->descent
- it
->max_descent
;
19927 it
->descent
= it
->max_descent
;
19929 if (it
->ascent
> it
->max_ascent
)
19931 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19932 it
->ascent
= it
->max_ascent
;
19934 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19935 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19936 extra_line_spacing
= 0;
19939 /* If this is a space inside a region of text with
19940 `space-width' property, change its width. */
19941 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
19943 it
->pixel_width
*= XFLOATINT (it
->space_width
);
19945 /* If face has a box, add the box thickness to the character
19946 height. If character has a box line to the left and/or
19947 right, add the box line width to the character's width. */
19948 if (face
->box
!= FACE_NO_BOX
)
19950 int thick
= face
->box_line_width
;
19954 it
->ascent
+= thick
;
19955 it
->descent
+= thick
;
19960 if (it
->start_of_box_run_p
)
19961 it
->pixel_width
+= thick
;
19962 if (it
->end_of_box_run_p
)
19963 it
->pixel_width
+= thick
;
19966 /* If face has an overline, add the height of the overline
19967 (1 pixel) and a 1 pixel margin to the character height. */
19968 if (face
->overline_p
)
19971 if (it
->constrain_row_ascent_descent_p
)
19973 if (it
->ascent
> it
->max_ascent
)
19974 it
->ascent
= it
->max_ascent
;
19975 if (it
->descent
> it
->max_descent
)
19976 it
->descent
= it
->max_descent
;
19979 take_vertical_position_into_account (it
);
19981 /* If we have to actually produce glyphs, do it. */
19986 /* Translate a space with a `space-width' property
19987 into a stretch glyph. */
19988 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
19989 / FONT_HEIGHT (font
));
19990 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19991 it
->ascent
+ it
->descent
, ascent
);
19996 /* If characters with lbearing or rbearing are displayed
19997 in this line, record that fact in a flag of the
19998 glyph row. This is used to optimize X output code. */
19999 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
20000 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20003 else if (it
->char_to_display
== '\n')
20005 /* A newline has no width but we need the height of the line.
20006 But if previous part of the line set a height, don't
20007 increase that height */
20009 Lisp_Object height
;
20010 Lisp_Object total_height
= Qnil
;
20012 it
->override_ascent
= -1;
20013 it
->pixel_width
= 0;
20016 height
= get_line_height_property(it
, Qline_height
);
20017 /* Split (line-height total-height) list */
20019 && CONSP (XCDR (height
))
20020 && NILP (XCDR (XCDR (height
))))
20022 total_height
= XCAR (XCDR (height
));
20023 height
= XCAR (height
);
20025 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
20027 if (it
->override_ascent
>= 0)
20029 it
->ascent
= it
->override_ascent
;
20030 it
->descent
= it
->override_descent
;
20031 boff
= it
->override_boff
;
20035 it
->ascent
= FONT_BASE (font
) + boff
;
20036 it
->descent
= FONT_DESCENT (font
) - boff
;
20039 if (EQ (height
, Qt
))
20041 if (it
->descent
> it
->max_descent
)
20043 it
->ascent
+= it
->descent
- it
->max_descent
;
20044 it
->descent
= it
->max_descent
;
20046 if (it
->ascent
> it
->max_ascent
)
20048 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20049 it
->ascent
= it
->max_ascent
;
20051 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20052 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20053 it
->constrain_row_ascent_descent_p
= 1;
20054 extra_line_spacing
= 0;
20058 Lisp_Object spacing
;
20060 it
->phys_ascent
= it
->ascent
;
20061 it
->phys_descent
= it
->descent
;
20063 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
20064 && face
->box
!= FACE_NO_BOX
20065 && face
->box_line_width
> 0)
20067 it
->ascent
+= face
->box_line_width
;
20068 it
->descent
+= face
->box_line_width
;
20071 && XINT (height
) > it
->ascent
+ it
->descent
)
20072 it
->ascent
= XINT (height
) - it
->descent
;
20074 if (!NILP (total_height
))
20075 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
20078 spacing
= get_line_height_property(it
, Qline_spacing
);
20079 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
20081 if (INTEGERP (spacing
))
20083 extra_line_spacing
= XINT (spacing
);
20084 if (!NILP (total_height
))
20085 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
20089 else if (it
->char_to_display
== '\t')
20091 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
20092 int x
= it
->current_x
+ it
->continuation_lines_width
;
20093 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
20095 /* If the distance from the current position to the next tab
20096 stop is less than a space character width, use the
20097 tab stop after that. */
20098 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
20099 next_tab_x
+= tab_width
;
20101 it
->pixel_width
= next_tab_x
- x
;
20103 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
20104 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20108 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20109 it
->ascent
+ it
->descent
, it
->ascent
);
20114 /* A multi-byte character. Assume that the display width of the
20115 character is the width of the character multiplied by the
20116 width of the font. */
20118 /* If we found a font, this font should give us the right
20119 metrics. If we didn't find a font, use the frame's
20120 default font and calculate the width of the character
20121 from the charset width; this is what old redisplay code
20124 pcm
= rif
->per_char_metric (font
, &char2b
,
20125 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
20127 if (font_not_found_p
|| !pcm
)
20129 int charset
= CHAR_CHARSET (it
->char_to_display
);
20131 it
->glyph_not_available_p
= 1;
20132 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
20133 * CHARSET_WIDTH (charset
));
20134 it
->phys_ascent
= FONT_BASE (font
) + boff
;
20135 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20139 it
->pixel_width
= pcm
->width
;
20140 it
->phys_ascent
= pcm
->ascent
+ boff
;
20141 it
->phys_descent
= pcm
->descent
- boff
;
20143 && (pcm
->lbearing
< 0
20144 || pcm
->rbearing
> pcm
->width
))
20145 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20148 it
->ascent
= FONT_BASE (font
) + boff
;
20149 it
->descent
= FONT_DESCENT (font
) - boff
;
20150 if (face
->box
!= FACE_NO_BOX
)
20152 int thick
= face
->box_line_width
;
20156 it
->ascent
+= thick
;
20157 it
->descent
+= thick
;
20162 if (it
->start_of_box_run_p
)
20163 it
->pixel_width
+= thick
;
20164 if (it
->end_of_box_run_p
)
20165 it
->pixel_width
+= thick
;
20168 /* If face has an overline, add the height of the overline
20169 (1 pixel) and a 1 pixel margin to the character height. */
20170 if (face
->overline_p
)
20173 take_vertical_position_into_account (it
);
20178 it
->multibyte_p
= saved_multibyte_p
;
20180 else if (it
->what
== IT_COMPOSITION
)
20182 /* Note: A composition is represented as one glyph in the
20183 glyph matrix. There are no padding glyphs. */
20186 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20188 int font_not_found_p
;
20189 struct font_info
*font_info
;
20190 int boff
; /* baseline offset */
20191 struct composition
*cmp
= composition_table
[it
->cmp_id
];
20193 /* Maybe translate single-byte characters to multibyte. */
20194 it
->char_to_display
= it
->c
;
20195 if (unibyte_display_via_language_environment
20196 && SINGLE_BYTE_CHAR_P (it
->c
)
20199 && !NILP (Vnonascii_translation_table
))))
20201 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20204 /* Get face and font to use. Encode IT->char_to_display. */
20205 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
20206 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20207 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20208 &char2b
, it
->multibyte_p
, 0);
20211 /* When no suitable font found, use the default font. */
20212 font_not_found_p
= font
== NULL
;
20213 if (font_not_found_p
)
20215 font
= FRAME_FONT (it
->f
);
20216 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20221 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20222 boff
= font_info
->baseline_offset
;
20223 if (font_info
->vertical_centering
)
20224 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20227 /* There are no padding glyphs, so there is only one glyph to
20228 produce for the composition. Important is that pixel_width,
20229 ascent and descent are the values of what is drawn by
20230 draw_glyphs (i.e. the values of the overall glyphs composed). */
20233 /* If we have not yet calculated pixel size data of glyphs of
20234 the composition for the current face font, calculate them
20235 now. Theoretically, we have to check all fonts for the
20236 glyphs, but that requires much time and memory space. So,
20237 here we check only the font of the first glyph. This leads
20238 to incorrect display very rarely, and C-l (recenter) can
20239 correct the display anyway. */
20240 if (cmp
->font
!= (void *) font
)
20242 /* Ascent and descent of the font of the first character of
20243 this composition (adjusted by baseline offset). Ascent
20244 and descent of overall glyphs should not be less than
20245 them respectively. */
20246 int font_ascent
= FONT_BASE (font
) + boff
;
20247 int font_descent
= FONT_DESCENT (font
) - boff
;
20248 /* Bounding box of the overall glyphs. */
20249 int leftmost
, rightmost
, lowest
, highest
;
20250 int i
, width
, ascent
, descent
;
20252 cmp
->font
= (void *) font
;
20254 /* Initialize the bounding box. */
20256 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20257 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
20259 width
= pcm
->width
;
20260 ascent
= pcm
->ascent
;
20261 descent
= pcm
->descent
;
20265 width
= FONT_WIDTH (font
);
20266 ascent
= FONT_BASE (font
);
20267 descent
= FONT_DESCENT (font
);
20271 lowest
= - descent
+ boff
;
20272 highest
= ascent
+ boff
;
20276 && font_info
->default_ascent
20277 && CHAR_TABLE_P (Vuse_default_ascent
)
20278 && !NILP (Faref (Vuse_default_ascent
,
20279 make_number (it
->char_to_display
))))
20280 highest
= font_info
->default_ascent
+ boff
;
20282 /* Draw the first glyph at the normal position. It may be
20283 shifted to right later if some other glyphs are drawn at
20285 cmp
->offsets
[0] = 0;
20286 cmp
->offsets
[1] = boff
;
20288 /* Set cmp->offsets for the remaining glyphs. */
20289 for (i
= 1; i
< cmp
->glyph_len
; i
++)
20291 int left
, right
, btm
, top
;
20292 int ch
= COMPOSITION_GLYPH (cmp
, i
);
20293 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
20295 face
= FACE_FROM_ID (it
->f
, face_id
);
20296 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
20297 &char2b
, it
->multibyte_p
, 0);
20301 font
= FRAME_FONT (it
->f
);
20302 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20308 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
20309 boff
= font_info
->baseline_offset
;
20310 if (font_info
->vertical_centering
)
20311 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20315 && (pcm
= rif
->per_char_metric (font
, &char2b
,
20316 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
20318 width
= pcm
->width
;
20319 ascent
= pcm
->ascent
;
20320 descent
= pcm
->descent
;
20324 width
= FONT_WIDTH (font
);
20329 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
20331 /* Relative composition with or without
20332 alternate chars. */
20333 left
= (leftmost
+ rightmost
- width
) / 2;
20334 btm
= - descent
+ boff
;
20335 if (font_info
&& font_info
->relative_compose
20336 && (! CHAR_TABLE_P (Vignore_relative_composition
)
20337 || NILP (Faref (Vignore_relative_composition
,
20338 make_number (ch
)))))
20341 if (- descent
>= font_info
->relative_compose
)
20342 /* One extra pixel between two glyphs. */
20344 else if (ascent
<= 0)
20345 /* One extra pixel between two glyphs. */
20346 btm
= lowest
- 1 - ascent
- descent
;
20351 /* A composition rule is specified by an integer
20352 value that encodes global and new reference
20353 points (GREF and NREF). GREF and NREF are
20354 specified by numbers as below:
20356 0---1---2 -- ascent
20360 9--10--11 -- center
20362 ---3---4---5--- baseline
20364 6---7---8 -- descent
20366 int rule
= COMPOSITION_RULE (cmp
, i
);
20367 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
20369 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
20370 grefx
= gref
% 3, nrefx
= nref
% 3;
20371 grefy
= gref
/ 3, nrefy
= nref
/ 3;
20374 + grefx
* (rightmost
- leftmost
) / 2
20375 - nrefx
* width
/ 2);
20376 btm
= ((grefy
== 0 ? highest
20378 : grefy
== 2 ? lowest
20379 : (highest
+ lowest
) / 2)
20380 - (nrefy
== 0 ? ascent
+ descent
20381 : nrefy
== 1 ? descent
- boff
20383 : (ascent
+ descent
) / 2));
20386 cmp
->offsets
[i
* 2] = left
;
20387 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
20389 /* Update the bounding box of the overall glyphs. */
20390 right
= left
+ width
;
20391 top
= btm
+ descent
+ ascent
;
20392 if (left
< leftmost
)
20394 if (right
> rightmost
)
20402 /* If there are glyphs whose x-offsets are negative,
20403 shift all glyphs to the right and make all x-offsets
20407 for (i
= 0; i
< cmp
->glyph_len
; i
++)
20408 cmp
->offsets
[i
* 2] -= leftmost
;
20409 rightmost
-= leftmost
;
20412 cmp
->pixel_width
= rightmost
;
20413 cmp
->ascent
= highest
;
20414 cmp
->descent
= - lowest
;
20415 if (cmp
->ascent
< font_ascent
)
20416 cmp
->ascent
= font_ascent
;
20417 if (cmp
->descent
< font_descent
)
20418 cmp
->descent
= font_descent
;
20421 it
->pixel_width
= cmp
->pixel_width
;
20422 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
20423 it
->descent
= it
->phys_descent
= cmp
->descent
;
20425 if (face
->box
!= FACE_NO_BOX
)
20427 int thick
= face
->box_line_width
;
20431 it
->ascent
+= thick
;
20432 it
->descent
+= thick
;
20437 if (it
->start_of_box_run_p
)
20438 it
->pixel_width
+= thick
;
20439 if (it
->end_of_box_run_p
)
20440 it
->pixel_width
+= thick
;
20443 /* If face has an overline, add the height of the overline
20444 (1 pixel) and a 1 pixel margin to the character height. */
20445 if (face
->overline_p
)
20448 take_vertical_position_into_account (it
);
20451 append_composite_glyph (it
);
20453 else if (it
->what
== IT_IMAGE
)
20454 produce_image_glyph (it
);
20455 else if (it
->what
== IT_STRETCH
)
20456 produce_stretch_glyph (it
);
20458 /* Accumulate dimensions. Note: can't assume that it->descent > 0
20459 because this isn't true for images with `:ascent 100'. */
20460 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
20461 if (it
->area
== TEXT_AREA
)
20462 it
->current_x
+= it
->pixel_width
;
20464 if (extra_line_spacing
> 0)
20466 it
->descent
+= extra_line_spacing
;
20467 if (extra_line_spacing
> it
->max_extra_line_spacing
)
20468 it
->max_extra_line_spacing
= extra_line_spacing
;
20471 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
20472 it
->max_descent
= max (it
->max_descent
, it
->descent
);
20473 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
20474 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
20478 Output LEN glyphs starting at START at the nominal cursor position.
20479 Advance the nominal cursor over the text. The global variable
20480 updated_window contains the window being updated, updated_row is
20481 the glyph row being updated, and updated_area is the area of that
20482 row being updated. */
20485 x_write_glyphs (start
, len
)
20486 struct glyph
*start
;
20491 xassert (updated_window
&& updated_row
);
20494 /* Write glyphs. */
20496 hpos
= start
- updated_row
->glyphs
[updated_area
];
20497 x
= draw_glyphs (updated_window
, output_cursor
.x
,
20498 updated_row
, updated_area
,
20500 DRAW_NORMAL_TEXT
, 0);
20502 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
20503 if (updated_area
== TEXT_AREA
20504 && updated_window
->phys_cursor_on_p
20505 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
20506 && updated_window
->phys_cursor
.hpos
>= hpos
20507 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
20508 updated_window
->phys_cursor_on_p
= 0;
20512 /* Advance the output cursor. */
20513 output_cursor
.hpos
+= len
;
20514 output_cursor
.x
= x
;
20519 Insert LEN glyphs from START at the nominal cursor position. */
20522 x_insert_glyphs (start
, len
)
20523 struct glyph
*start
;
20528 int line_height
, shift_by_width
, shifted_region_width
;
20529 struct glyph_row
*row
;
20530 struct glyph
*glyph
;
20531 int frame_x
, frame_y
, hpos
;
20533 xassert (updated_window
&& updated_row
);
20535 w
= updated_window
;
20536 f
= XFRAME (WINDOW_FRAME (w
));
20538 /* Get the height of the line we are in. */
20540 line_height
= row
->height
;
20542 /* Get the width of the glyphs to insert. */
20543 shift_by_width
= 0;
20544 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
20545 shift_by_width
+= glyph
->pixel_width
;
20547 /* Get the width of the region to shift right. */
20548 shifted_region_width
= (window_box_width (w
, updated_area
)
20553 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
20554 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
20556 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
20557 line_height
, shift_by_width
);
20559 /* Write the glyphs. */
20560 hpos
= start
- row
->glyphs
[updated_area
];
20561 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
20563 DRAW_NORMAL_TEXT
, 0);
20565 /* Advance the output cursor. */
20566 output_cursor
.hpos
+= len
;
20567 output_cursor
.x
+= shift_by_width
;
20573 Erase the current text line from the nominal cursor position
20574 (inclusive) to pixel column TO_X (exclusive). The idea is that
20575 everything from TO_X onward is already erased.
20577 TO_X is a pixel position relative to updated_area of
20578 updated_window. TO_X == -1 means clear to the end of this area. */
20581 x_clear_end_of_line (to_x
)
20585 struct window
*w
= updated_window
;
20586 int max_x
, min_y
, max_y
;
20587 int from_x
, from_y
, to_y
;
20589 xassert (updated_window
&& updated_row
);
20590 f
= XFRAME (w
->frame
);
20592 if (updated_row
->full_width_p
)
20593 max_x
= WINDOW_TOTAL_WIDTH (w
);
20595 max_x
= window_box_width (w
, updated_area
);
20596 max_y
= window_text_bottom_y (w
);
20598 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
20599 of window. For TO_X > 0, truncate to end of drawing area. */
20605 to_x
= min (to_x
, max_x
);
20607 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
20609 /* Notice if the cursor will be cleared by this operation. */
20610 if (!updated_row
->full_width_p
)
20611 notice_overwritten_cursor (w
, updated_area
,
20612 output_cursor
.x
, -1,
20614 MATRIX_ROW_BOTTOM_Y (updated_row
));
20616 from_x
= output_cursor
.x
;
20618 /* Translate to frame coordinates. */
20619 if (updated_row
->full_width_p
)
20621 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
20622 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
20626 int area_left
= window_box_left (w
, updated_area
);
20627 from_x
+= area_left
;
20631 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
20632 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
20633 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
20635 /* Prevent inadvertently clearing to end of the X window. */
20636 if (to_x
> from_x
&& to_y
> from_y
)
20639 rif
->clear_frame_area (f
, from_x
, from_y
,
20640 to_x
- from_x
, to_y
- from_y
);
20645 #endif /* HAVE_WINDOW_SYSTEM */
20649 /***********************************************************************
20651 ***********************************************************************/
20653 /* Value is the internal representation of the specified cursor type
20654 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
20655 of the bar cursor. */
20657 static enum text_cursor_kinds
20658 get_specified_cursor_type (arg
, width
)
20662 enum text_cursor_kinds type
;
20667 if (EQ (arg
, Qbox
))
20668 return FILLED_BOX_CURSOR
;
20670 if (EQ (arg
, Qhollow
))
20671 return HOLLOW_BOX_CURSOR
;
20673 if (EQ (arg
, Qbar
))
20680 && EQ (XCAR (arg
), Qbar
)
20681 && INTEGERP (XCDR (arg
))
20682 && XINT (XCDR (arg
)) >= 0)
20684 *width
= XINT (XCDR (arg
));
20688 if (EQ (arg
, Qhbar
))
20691 return HBAR_CURSOR
;
20695 && EQ (XCAR (arg
), Qhbar
)
20696 && INTEGERP (XCDR (arg
))
20697 && XINT (XCDR (arg
)) >= 0)
20699 *width
= XINT (XCDR (arg
));
20700 return HBAR_CURSOR
;
20703 /* Treat anything unknown as "hollow box cursor".
20704 It was bad to signal an error; people have trouble fixing
20705 .Xdefaults with Emacs, when it has something bad in it. */
20706 type
= HOLLOW_BOX_CURSOR
;
20711 /* Set the default cursor types for specified frame. */
20713 set_frame_cursor_types (f
, arg
)
20720 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
20721 FRAME_CURSOR_WIDTH (f
) = width
;
20723 /* By default, set up the blink-off state depending on the on-state. */
20725 tem
= Fassoc (arg
, Vblink_cursor_alist
);
20728 FRAME_BLINK_OFF_CURSOR (f
)
20729 = get_specified_cursor_type (XCDR (tem
), &width
);
20730 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
20733 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
20737 /* Return the cursor we want to be displayed in window W. Return
20738 width of bar/hbar cursor through WIDTH arg. Return with
20739 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
20740 (i.e. if the `system caret' should track this cursor).
20742 In a mini-buffer window, we want the cursor only to appear if we
20743 are reading input from this window. For the selected window, we
20744 want the cursor type given by the frame parameter or buffer local
20745 setting of cursor-type. If explicitly marked off, draw no cursor.
20746 In all other cases, we want a hollow box cursor. */
20748 static enum text_cursor_kinds
20749 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
20751 struct glyph
*glyph
;
20753 int *active_cursor
;
20755 struct frame
*f
= XFRAME (w
->frame
);
20756 struct buffer
*b
= XBUFFER (w
->buffer
);
20757 int cursor_type
= DEFAULT_CURSOR
;
20758 Lisp_Object alt_cursor
;
20759 int non_selected
= 0;
20761 *active_cursor
= 1;
20764 if (cursor_in_echo_area
20765 && FRAME_HAS_MINIBUF_P (f
)
20766 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
20768 if (w
== XWINDOW (echo_area_window
))
20770 *width
= FRAME_CURSOR_WIDTH (f
);
20771 return FRAME_DESIRED_CURSOR (f
);
20774 *active_cursor
= 0;
20778 /* Nonselected window or nonselected frame. */
20779 else if (w
!= XWINDOW (f
->selected_window
)
20780 #ifdef HAVE_WINDOW_SYSTEM
20781 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
20785 *active_cursor
= 0;
20787 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
20793 /* Never display a cursor in a window in which cursor-type is nil. */
20794 if (NILP (b
->cursor_type
))
20797 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
20800 alt_cursor
= b
->cursor_in_non_selected_windows
;
20801 return get_specified_cursor_type (alt_cursor
, width
);
20804 /* Get the normal cursor type for this window. */
20805 if (EQ (b
->cursor_type
, Qt
))
20807 cursor_type
= FRAME_DESIRED_CURSOR (f
);
20808 *width
= FRAME_CURSOR_WIDTH (f
);
20811 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
20813 /* Use normal cursor if not blinked off. */
20814 if (!w
->cursor_off_p
)
20816 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
20817 if (cursor_type
== FILLED_BOX_CURSOR
)
20818 cursor_type
= HOLLOW_BOX_CURSOR
;
20820 return cursor_type
;
20823 /* Cursor is blinked off, so determine how to "toggle" it. */
20825 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
20826 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
20827 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
20829 /* Then see if frame has specified a specific blink off cursor type. */
20830 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
20832 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
20833 return FRAME_BLINK_OFF_CURSOR (f
);
20837 /* Some people liked having a permanently visible blinking cursor,
20838 while others had very strong opinions against it. So it was
20839 decided to remove it. KFS 2003-09-03 */
20841 /* Finally perform built-in cursor blinking:
20842 filled box <-> hollow box
20843 wide [h]bar <-> narrow [h]bar
20844 narrow [h]bar <-> no cursor
20845 other type <-> no cursor */
20847 if (cursor_type
== FILLED_BOX_CURSOR
)
20848 return HOLLOW_BOX_CURSOR
;
20850 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
20853 return cursor_type
;
20861 #ifdef HAVE_WINDOW_SYSTEM
20863 /* Notice when the text cursor of window W has been completely
20864 overwritten by a drawing operation that outputs glyphs in AREA
20865 starting at X0 and ending at X1 in the line starting at Y0 and
20866 ending at Y1. X coordinates are area-relative. X1 < 0 means all
20867 the rest of the line after X0 has been written. Y coordinates
20868 are window-relative. */
20871 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
20873 enum glyph_row_area area
;
20874 int x0
, y0
, x1
, y1
;
20876 int cx0
, cx1
, cy0
, cy1
;
20877 struct glyph_row
*row
;
20879 if (!w
->phys_cursor_on_p
)
20881 if (area
!= TEXT_AREA
)
20884 if (w
->phys_cursor
.vpos
< 0
20885 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
20886 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
20887 !(row
->enabled_p
&& row
->displays_text_p
)))
20890 if (row
->cursor_in_fringe_p
)
20892 row
->cursor_in_fringe_p
= 0;
20893 draw_fringe_bitmap (w
, row
, 0);
20894 w
->phys_cursor_on_p
= 0;
20898 cx0
= w
->phys_cursor
.x
;
20899 cx1
= cx0
+ w
->phys_cursor_width
;
20900 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
20903 /* The cursor image will be completely removed from the
20904 screen if the output area intersects the cursor area in
20905 y-direction. When we draw in [y0 y1[, and some part of
20906 the cursor is at y < y0, that part must have been drawn
20907 before. When scrolling, the cursor is erased before
20908 actually scrolling, so we don't come here. When not
20909 scrolling, the rows above the old cursor row must have
20910 changed, and in this case these rows must have written
20911 over the cursor image.
20913 Likewise if part of the cursor is below y1, with the
20914 exception of the cursor being in the first blank row at
20915 the buffer and window end because update_text_area
20916 doesn't draw that row. (Except when it does, but
20917 that's handled in update_text_area.) */
20919 cy0
= w
->phys_cursor
.y
;
20920 cy1
= cy0
+ w
->phys_cursor_height
;
20921 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
20924 w
->phys_cursor_on_p
= 0;
20927 #endif /* HAVE_WINDOW_SYSTEM */
20930 /************************************************************************
20932 ************************************************************************/
20934 #ifdef HAVE_WINDOW_SYSTEM
20937 Fix the display of area AREA of overlapping row ROW in window W
20938 with respect to the overlapping part OVERLAPS. */
20941 x_fix_overlapping_area (w
, row
, area
, overlaps
)
20943 struct glyph_row
*row
;
20944 enum glyph_row_area area
;
20952 for (i
= 0; i
< row
->used
[area
];)
20954 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
20956 int start
= i
, start_x
= x
;
20960 x
+= row
->glyphs
[area
][i
].pixel_width
;
20963 while (i
< row
->used
[area
]
20964 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
20966 draw_glyphs (w
, start_x
, row
, area
,
20968 DRAW_NORMAL_TEXT
, overlaps
);
20972 x
+= row
->glyphs
[area
][i
].pixel_width
;
20982 Draw the cursor glyph of window W in glyph row ROW. See the
20983 comment of draw_glyphs for the meaning of HL. */
20986 draw_phys_cursor_glyph (w
, row
, hl
)
20988 struct glyph_row
*row
;
20989 enum draw_glyphs_face hl
;
20991 /* If cursor hpos is out of bounds, don't draw garbage. This can
20992 happen in mini-buffer windows when switching between echo area
20993 glyphs and mini-buffer. */
20994 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
20996 int on_p
= w
->phys_cursor_on_p
;
20998 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
20999 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
21001 w
->phys_cursor_on_p
= on_p
;
21003 if (hl
== DRAW_CURSOR
)
21004 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21005 /* When we erase the cursor, and ROW is overlapped by other
21006 rows, make sure that these overlapping parts of other rows
21008 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
21010 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21012 if (row
> w
->current_matrix
->rows
21013 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
21014 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
21015 OVERLAPS_ERASED_CURSOR
);
21017 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
21018 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
21019 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
21020 OVERLAPS_ERASED_CURSOR
);
21027 Erase the image of a cursor of window W from the screen. */
21030 erase_phys_cursor (w
)
21033 struct frame
*f
= XFRAME (w
->frame
);
21034 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21035 int hpos
= w
->phys_cursor
.hpos
;
21036 int vpos
= w
->phys_cursor
.vpos
;
21037 int mouse_face_here_p
= 0;
21038 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
21039 struct glyph_row
*cursor_row
;
21040 struct glyph
*cursor_glyph
;
21041 enum draw_glyphs_face hl
;
21043 /* No cursor displayed or row invalidated => nothing to do on the
21045 if (w
->phys_cursor_type
== NO_CURSOR
)
21046 goto mark_cursor_off
;
21048 /* VPOS >= active_glyphs->nrows means that window has been resized.
21049 Don't bother to erase the cursor. */
21050 if (vpos
>= active_glyphs
->nrows
)
21051 goto mark_cursor_off
;
21053 /* If row containing cursor is marked invalid, there is nothing we
21055 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
21056 if (!cursor_row
->enabled_p
)
21057 goto mark_cursor_off
;
21059 /* If line spacing is > 0, old cursor may only be partially visible in
21060 window after split-window. So adjust visible height. */
21061 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
21062 window_text_bottom_y (w
) - cursor_row
->y
);
21064 /* If row is completely invisible, don't attempt to delete a cursor which
21065 isn't there. This can happen if cursor is at top of a window, and
21066 we switch to a buffer with a header line in that window. */
21067 if (cursor_row
->visible_height
<= 0)
21068 goto mark_cursor_off
;
21070 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
21071 if (cursor_row
->cursor_in_fringe_p
)
21073 cursor_row
->cursor_in_fringe_p
= 0;
21074 draw_fringe_bitmap (w
, cursor_row
, 0);
21075 goto mark_cursor_off
;
21078 /* This can happen when the new row is shorter than the old one.
21079 In this case, either draw_glyphs or clear_end_of_line
21080 should have cleared the cursor. Note that we wouldn't be
21081 able to erase the cursor in this case because we don't have a
21082 cursor glyph at hand. */
21083 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
21084 goto mark_cursor_off
;
21086 /* If the cursor is in the mouse face area, redisplay that when
21087 we clear the cursor. */
21088 if (! NILP (dpyinfo
->mouse_face_window
)
21089 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
21090 && (vpos
> dpyinfo
->mouse_face_beg_row
21091 || (vpos
== dpyinfo
->mouse_face_beg_row
21092 && hpos
>= dpyinfo
->mouse_face_beg_col
))
21093 && (vpos
< dpyinfo
->mouse_face_end_row
21094 || (vpos
== dpyinfo
->mouse_face_end_row
21095 && hpos
< dpyinfo
->mouse_face_end_col
))
21096 /* Don't redraw the cursor's spot in mouse face if it is at the
21097 end of a line (on a newline). The cursor appears there, but
21098 mouse highlighting does not. */
21099 && cursor_row
->used
[TEXT_AREA
] > hpos
)
21100 mouse_face_here_p
= 1;
21102 /* Maybe clear the display under the cursor. */
21103 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
21106 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
21109 cursor_glyph
= get_phys_cursor_glyph (w
);
21110 if (cursor_glyph
== NULL
)
21111 goto mark_cursor_off
;
21113 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
21114 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
21115 width
= min (cursor_glyph
->pixel_width
,
21116 window_box_width (w
, TEXT_AREA
) - w
->phys_cursor
.x
);
21118 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
21121 /* Erase the cursor by redrawing the character underneath it. */
21122 if (mouse_face_here_p
)
21123 hl
= DRAW_MOUSE_FACE
;
21125 hl
= DRAW_NORMAL_TEXT
;
21126 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
21129 w
->phys_cursor_on_p
= 0;
21130 w
->phys_cursor_type
= NO_CURSOR
;
21135 Display or clear cursor of window W. If ON is zero, clear the
21136 cursor. If it is non-zero, display the cursor. If ON is nonzero,
21137 where to put the cursor is specified by HPOS, VPOS, X and Y. */
21140 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
21142 int on
, hpos
, vpos
, x
, y
;
21144 struct frame
*f
= XFRAME (w
->frame
);
21145 int new_cursor_type
;
21146 int new_cursor_width
;
21148 struct glyph_row
*glyph_row
;
21149 struct glyph
*glyph
;
21151 /* This is pointless on invisible frames, and dangerous on garbaged
21152 windows and frames; in the latter case, the frame or window may
21153 be in the midst of changing its size, and x and y may be off the
21155 if (! FRAME_VISIBLE_P (f
)
21156 || FRAME_GARBAGED_P (f
)
21157 || vpos
>= w
->current_matrix
->nrows
21158 || hpos
>= w
->current_matrix
->matrix_w
)
21161 /* If cursor is off and we want it off, return quickly. */
21162 if (!on
&& !w
->phys_cursor_on_p
)
21165 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
21166 /* If cursor row is not enabled, we don't really know where to
21167 display the cursor. */
21168 if (!glyph_row
->enabled_p
)
21170 w
->phys_cursor_on_p
= 0;
21175 if (!glyph_row
->exact_window_width_line_p
21176 || hpos
< glyph_row
->used
[TEXT_AREA
])
21177 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
21179 xassert (interrupt_input_blocked
);
21181 /* Set new_cursor_type to the cursor we want to be displayed. */
21182 new_cursor_type
= get_window_cursor_type (w
, glyph
,
21183 &new_cursor_width
, &active_cursor
);
21185 /* If cursor is currently being shown and we don't want it to be or
21186 it is in the wrong place, or the cursor type is not what we want,
21188 if (w
->phys_cursor_on_p
21190 || w
->phys_cursor
.x
!= x
21191 || w
->phys_cursor
.y
!= y
21192 || new_cursor_type
!= w
->phys_cursor_type
21193 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
21194 && new_cursor_width
!= w
->phys_cursor_width
)))
21195 erase_phys_cursor (w
);
21197 /* Don't check phys_cursor_on_p here because that flag is only set
21198 to zero in some cases where we know that the cursor has been
21199 completely erased, to avoid the extra work of erasing the cursor
21200 twice. In other words, phys_cursor_on_p can be 1 and the cursor
21201 still not be visible, or it has only been partly erased. */
21204 w
->phys_cursor_ascent
= glyph_row
->ascent
;
21205 w
->phys_cursor_height
= glyph_row
->height
;
21207 /* Set phys_cursor_.* before x_draw_.* is called because some
21208 of them may need the information. */
21209 w
->phys_cursor
.x
= x
;
21210 w
->phys_cursor
.y
= glyph_row
->y
;
21211 w
->phys_cursor
.hpos
= hpos
;
21212 w
->phys_cursor
.vpos
= vpos
;
21215 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
21216 new_cursor_type
, new_cursor_width
,
21217 on
, active_cursor
);
21221 /* Switch the display of W's cursor on or off, according to the value
21225 update_window_cursor (w
, on
)
21229 /* Don't update cursor in windows whose frame is in the process
21230 of being deleted. */
21231 if (w
->current_matrix
)
21234 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21235 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21241 /* Call update_window_cursor with parameter ON_P on all leaf windows
21242 in the window tree rooted at W. */
21245 update_cursor_in_window_tree (w
, on_p
)
21251 if (!NILP (w
->hchild
))
21252 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
21253 else if (!NILP (w
->vchild
))
21254 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
21256 update_window_cursor (w
, on_p
);
21258 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
21264 Display the cursor on window W, or clear it, according to ON_P.
21265 Don't change the cursor's position. */
21268 x_update_cursor (f
, on_p
)
21272 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
21277 Clear the cursor of window W to background color, and mark the
21278 cursor as not shown. This is used when the text where the cursor
21279 is is about to be rewritten. */
21285 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
21286 update_window_cursor (w
, 0);
21291 Display the active region described by mouse_face_* according to DRAW. */
21294 show_mouse_face (dpyinfo
, draw
)
21295 Display_Info
*dpyinfo
;
21296 enum draw_glyphs_face draw
;
21298 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
21299 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21301 if (/* If window is in the process of being destroyed, don't bother
21303 w
->current_matrix
!= NULL
21304 /* Don't update mouse highlight if hidden */
21305 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
21306 /* Recognize when we are called to operate on rows that don't exist
21307 anymore. This can happen when a window is split. */
21308 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
21310 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
21311 struct glyph_row
*row
, *first
, *last
;
21313 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
21314 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
21316 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
21318 int start_hpos
, end_hpos
, start_x
;
21320 /* For all but the first row, the highlight starts at column 0. */
21323 start_hpos
= dpyinfo
->mouse_face_beg_col
;
21324 start_x
= dpyinfo
->mouse_face_beg_x
;
21333 end_hpos
= dpyinfo
->mouse_face_end_col
;
21336 end_hpos
= row
->used
[TEXT_AREA
];
21337 if (draw
== DRAW_NORMAL_TEXT
)
21338 row
->fill_line_p
= 1; /* Clear to end of line */
21341 if (end_hpos
> start_hpos
)
21343 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
21344 start_hpos
, end_hpos
,
21348 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
21352 /* When we've written over the cursor, arrange for it to
21353 be displayed again. */
21354 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
21357 display_and_set_cursor (w
, 1,
21358 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21359 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21364 /* Change the mouse cursor. */
21365 if (draw
== DRAW_NORMAL_TEXT
)
21366 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
21367 else if (draw
== DRAW_MOUSE_FACE
)
21368 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
21370 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
21374 Clear out the mouse-highlighted active region.
21375 Redraw it un-highlighted first. Value is non-zero if mouse
21376 face was actually drawn unhighlighted. */
21379 clear_mouse_face (dpyinfo
)
21380 Display_Info
*dpyinfo
;
21384 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
21386 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
21390 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21391 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21392 dpyinfo
->mouse_face_window
= Qnil
;
21393 dpyinfo
->mouse_face_overlay
= Qnil
;
21399 Non-zero if physical cursor of window W is within mouse face. */
21402 cursor_in_mouse_face_p (w
)
21405 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21406 int in_mouse_face
= 0;
21408 if (WINDOWP (dpyinfo
->mouse_face_window
)
21409 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
21411 int hpos
= w
->phys_cursor
.hpos
;
21412 int vpos
= w
->phys_cursor
.vpos
;
21414 if (vpos
>= dpyinfo
->mouse_face_beg_row
21415 && vpos
<= dpyinfo
->mouse_face_end_row
21416 && (vpos
> dpyinfo
->mouse_face_beg_row
21417 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21418 && (vpos
< dpyinfo
->mouse_face_end_row
21419 || hpos
< dpyinfo
->mouse_face_end_col
21420 || dpyinfo
->mouse_face_past_end
))
21424 return in_mouse_face
;
21430 /* Find the glyph matrix position of buffer position CHARPOS in window
21431 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
21432 current glyphs must be up to date. If CHARPOS is above window
21433 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
21434 of last line in W. In the row containing CHARPOS, stop before glyphs
21435 having STOP as object. */
21437 #if 1 /* This is a version of fast_find_position that's more correct
21438 in the presence of hscrolling, for example. I didn't install
21439 it right away because the problem fixed is minor, it failed
21440 in 20.x as well, and I think it's too risky to install
21441 so near the release of 21.1. 2001-09-25 gerd. */
21444 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
21447 int *hpos
, *vpos
, *x
, *y
;
21450 struct glyph_row
*row
, *first
;
21451 struct glyph
*glyph
, *end
;
21454 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21455 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
21460 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
21464 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
21467 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
21471 /* If whole rows or last part of a row came from a display overlay,
21472 row_containing_pos will skip over such rows because their end pos
21473 equals the start pos of the overlay or interval.
21475 Move back if we have a STOP object and previous row's
21476 end glyph came from STOP. */
21479 struct glyph_row
*prev
;
21480 while ((prev
= row
- 1, prev
>= first
)
21481 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
21482 && prev
->used
[TEXT_AREA
] > 0)
21484 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
21485 glyph
= beg
+ prev
->used
[TEXT_AREA
];
21486 while (--glyph
>= beg
21487 && INTEGERP (glyph
->object
));
21489 || !EQ (stop
, glyph
->object
))
21497 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21499 glyph
= row
->glyphs
[TEXT_AREA
];
21500 end
= glyph
+ row
->used
[TEXT_AREA
];
21502 /* Skip over glyphs not having an object at the start of the row.
21503 These are special glyphs like truncation marks on terminal
21505 if (row
->displays_text_p
)
21507 && INTEGERP (glyph
->object
)
21508 && !EQ (stop
, glyph
->object
)
21509 && glyph
->charpos
< 0)
21511 *x
+= glyph
->pixel_width
;
21516 && !INTEGERP (glyph
->object
)
21517 && !EQ (stop
, glyph
->object
)
21518 && (!BUFFERP (glyph
->object
)
21519 || glyph
->charpos
< charpos
))
21521 *x
+= glyph
->pixel_width
;
21525 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
21532 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
21535 int *hpos
, *vpos
, *x
, *y
;
21540 int maybe_next_line_p
= 0;
21541 int line_start_position
;
21542 int yb
= window_text_bottom_y (w
);
21543 struct glyph_row
*row
, *best_row
;
21544 int row_vpos
, best_row_vpos
;
21547 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21548 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21550 while (row
->y
< yb
)
21552 if (row
->used
[TEXT_AREA
])
21553 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
21555 line_start_position
= 0;
21557 if (line_start_position
> pos
)
21559 /* If the position sought is the end of the buffer,
21560 don't include the blank lines at the bottom of the window. */
21561 else if (line_start_position
== pos
21562 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
21564 maybe_next_line_p
= 1;
21567 else if (line_start_position
> 0)
21570 best_row_vpos
= row_vpos
;
21573 if (row
->y
+ row
->height
>= yb
)
21580 /* Find the right column within BEST_ROW. */
21582 current_x
= best_row
->x
;
21583 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
21585 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
21586 int charpos
= glyph
->charpos
;
21588 if (BUFFERP (glyph
->object
))
21590 if (charpos
== pos
)
21593 *vpos
= best_row_vpos
;
21598 else if (charpos
> pos
)
21601 else if (EQ (glyph
->object
, stop
))
21606 current_x
+= glyph
->pixel_width
;
21609 /* If we're looking for the end of the buffer,
21610 and we didn't find it in the line we scanned,
21611 use the start of the following line. */
21612 if (maybe_next_line_p
)
21617 current_x
= best_row
->x
;
21620 *vpos
= best_row_vpos
;
21621 *hpos
= lastcol
+ 1;
21630 /* Find the position of the glyph for position POS in OBJECT in
21631 window W's current matrix, and return in *X, *Y the pixel
21632 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
21634 RIGHT_P non-zero means return the position of the right edge of the
21635 glyph, RIGHT_P zero means return the left edge position.
21637 If no glyph for POS exists in the matrix, return the position of
21638 the glyph with the next smaller position that is in the matrix, if
21639 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
21640 exists in the matrix, return the position of the glyph with the
21641 next larger position in OBJECT.
21643 Value is non-zero if a glyph was found. */
21646 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
21649 Lisp_Object object
;
21650 int *hpos
, *vpos
, *x
, *y
;
21653 int yb
= window_text_bottom_y (w
);
21654 struct glyph_row
*r
;
21655 struct glyph
*best_glyph
= NULL
;
21656 struct glyph_row
*best_row
= NULL
;
21659 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21660 r
->enabled_p
&& r
->y
< yb
;
21663 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
21664 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
21667 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
21668 if (EQ (g
->object
, object
))
21670 if (g
->charpos
== pos
)
21677 else if (best_glyph
== NULL
21678 || ((abs (g
->charpos
- pos
)
21679 < abs (best_glyph
->charpos
- pos
))
21682 : g
->charpos
> pos
)))
21696 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
21700 *x
+= best_glyph
->pixel_width
;
21705 *vpos
= best_row
- w
->current_matrix
->rows
;
21708 return best_glyph
!= NULL
;
21712 /* See if position X, Y is within a hot-spot of an image. */
21715 on_hot_spot_p (hot_spot
, x
, y
)
21716 Lisp_Object hot_spot
;
21719 if (!CONSP (hot_spot
))
21722 if (EQ (XCAR (hot_spot
), Qrect
))
21724 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
21725 Lisp_Object rect
= XCDR (hot_spot
);
21729 if (!CONSP (XCAR (rect
)))
21731 if (!CONSP (XCDR (rect
)))
21733 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
21735 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
21737 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
21739 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
21743 else if (EQ (XCAR (hot_spot
), Qcircle
))
21745 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
21746 Lisp_Object circ
= XCDR (hot_spot
);
21747 Lisp_Object lr
, lx0
, ly0
;
21749 && CONSP (XCAR (circ
))
21750 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
21751 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
21752 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
21754 double r
= XFLOATINT (lr
);
21755 double dx
= XINT (lx0
) - x
;
21756 double dy
= XINT (ly0
) - y
;
21757 return (dx
* dx
+ dy
* dy
<= r
* r
);
21760 else if (EQ (XCAR (hot_spot
), Qpoly
))
21762 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
21763 if (VECTORP (XCDR (hot_spot
)))
21765 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
21766 Lisp_Object
*poly
= v
->contents
;
21770 Lisp_Object lx
, ly
;
21773 /* Need an even number of coordinates, and at least 3 edges. */
21774 if (n
< 6 || n
& 1)
21777 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
21778 If count is odd, we are inside polygon. Pixels on edges
21779 may or may not be included depending on actual geometry of the
21781 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
21782 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
21784 x0
= XINT (lx
), y0
= XINT (ly
);
21785 for (i
= 0; i
< n
; i
+= 2)
21787 int x1
= x0
, y1
= y0
;
21788 if ((lx
= poly
[i
], !INTEGERP (lx
))
21789 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
21791 x0
= XINT (lx
), y0
= XINT (ly
);
21793 /* Does this segment cross the X line? */
21801 if (y
> y0
&& y
> y1
)
21803 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
21809 /* If we don't understand the format, pretend we're not in the hot-spot. */
21814 find_hot_spot (map
, x
, y
)
21818 while (CONSP (map
))
21820 if (CONSP (XCAR (map
))
21821 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
21829 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
21831 doc
: /* Lookup in image map MAP coordinates X and Y.
21832 An image map is an alist where each element has the format (AREA ID PLIST).
21833 An AREA is specified as either a rectangle, a circle, or a polygon:
21834 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
21835 pixel coordinates of the upper left and bottom right corners.
21836 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
21837 and the radius of the circle; r may be a float or integer.
21838 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
21839 vector describes one corner in the polygon.
21840 Returns the alist element for the first matching AREA in MAP. */)
21851 return find_hot_spot (map
, XINT (x
), XINT (y
));
21855 /* Display frame CURSOR, optionally using shape defined by POINTER. */
21857 define_frame_cursor1 (f
, cursor
, pointer
)
21860 Lisp_Object pointer
;
21862 /* Do not change cursor shape while dragging mouse. */
21863 if (!NILP (do_mouse_tracking
))
21866 if (!NILP (pointer
))
21868 if (EQ (pointer
, Qarrow
))
21869 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21870 else if (EQ (pointer
, Qhand
))
21871 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
21872 else if (EQ (pointer
, Qtext
))
21873 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21874 else if (EQ (pointer
, intern ("hdrag")))
21875 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21876 #ifdef HAVE_X_WINDOWS
21877 else if (EQ (pointer
, intern ("vdrag")))
21878 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
21880 else if (EQ (pointer
, intern ("hourglass")))
21881 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
21882 else if (EQ (pointer
, Qmodeline
))
21883 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
21885 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21888 if (cursor
!= No_Cursor
)
21889 rif
->define_frame_cursor (f
, cursor
);
21892 /* Take proper action when mouse has moved to the mode or header line
21893 or marginal area AREA of window W, x-position X and y-position Y.
21894 X is relative to the start of the text display area of W, so the
21895 width of bitmap areas and scroll bars must be subtracted to get a
21896 position relative to the start of the mode line. */
21899 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
21900 Lisp_Object window
;
21902 enum window_part area
;
21904 struct window
*w
= XWINDOW (window
);
21905 struct frame
*f
= XFRAME (w
->frame
);
21906 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21907 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21908 Lisp_Object pointer
= Qnil
;
21909 int charpos
, dx
, dy
, width
, height
;
21910 Lisp_Object string
, object
= Qnil
;
21911 Lisp_Object pos
, help
;
21913 Lisp_Object mouse_face
;
21914 int original_x_pixel
= x
;
21915 struct glyph
* glyph
= NULL
;
21916 struct glyph_row
*row
;
21918 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
21923 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
21924 &object
, &dx
, &dy
, &width
, &height
);
21926 row
= (area
== ON_MODE_LINE
21927 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
21928 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
21931 if (row
->mode_line_p
&& row
->enabled_p
)
21933 glyph
= row
->glyphs
[TEXT_AREA
];
21934 end
= glyph
+ row
->used
[TEXT_AREA
];
21936 for (x0
= original_x_pixel
;
21937 glyph
< end
&& x0
>= glyph
->pixel_width
;
21939 x0
-= glyph
->pixel_width
;
21947 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
21948 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
21949 &object
, &dx
, &dy
, &width
, &height
);
21954 if (IMAGEP (object
))
21956 Lisp_Object image_map
, hotspot
;
21957 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
21959 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
21961 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21963 Lisp_Object area_id
, plist
;
21965 area_id
= XCAR (hotspot
);
21966 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21967 If so, we could look for mouse-enter, mouse-leave
21968 properties in PLIST (and do something...). */
21969 hotspot
= XCDR (hotspot
);
21970 if (CONSP (hotspot
)
21971 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21973 pointer
= Fplist_get (plist
, Qpointer
);
21974 if (NILP (pointer
))
21976 help
= Fplist_get (plist
, Qhelp_echo
);
21979 help_echo_string
= help
;
21980 /* Is this correct? ++kfs */
21981 XSETWINDOW (help_echo_window
, w
);
21982 help_echo_object
= w
->buffer
;
21983 help_echo_pos
= charpos
;
21987 if (NILP (pointer
))
21988 pointer
= Fplist_get (XCDR (object
), QCpointer
);
21991 if (STRINGP (string
))
21993 pos
= make_number (charpos
);
21994 /* If we're on a string with `help-echo' text property, arrange
21995 for the help to be displayed. This is done by setting the
21996 global variable help_echo_string to the help string. */
21999 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
22002 help_echo_string
= help
;
22003 XSETWINDOW (help_echo_window
, w
);
22004 help_echo_object
= string
;
22005 help_echo_pos
= charpos
;
22009 if (NILP (pointer
))
22010 pointer
= Fget_text_property (pos
, Qpointer
, string
);
22012 /* Change the mouse pointer according to what is under X/Y. */
22013 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
22016 map
= Fget_text_property (pos
, Qlocal_map
, string
);
22017 if (!KEYMAPP (map
))
22018 map
= Fget_text_property (pos
, Qkeymap
, string
);
22019 if (!KEYMAPP (map
))
22020 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
22023 /* Change the mouse face according to what is under X/Y. */
22024 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
22025 if (!NILP (mouse_face
)
22026 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22031 struct glyph
* tmp_glyph
;
22035 int total_pixel_width
;
22040 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
22041 Qmouse_face
, string
, Qnil
);
22043 b
= make_number (0);
22045 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
22047 e
= make_number (SCHARS (string
));
22049 /* Calculate the position(glyph position: GPOS) of GLYPH in
22050 displayed string. GPOS is different from CHARPOS.
22052 CHARPOS is the position of glyph in internal string
22053 object. A mode line string format has structures which
22054 is converted to a flatten by emacs lisp interpreter.
22055 The internal string is an element of the structures.
22056 The displayed string is the flatten string. */
22057 for (tmp_glyph
= glyph
- 1, gpos
= 0;
22058 tmp_glyph
->charpos
>= XINT (b
);
22059 tmp_glyph
--, gpos
++)
22061 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22065 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
22066 displayed string holding GLYPH.
22068 GSEQ_LENGTH is different from SCHARS (STRING).
22069 SCHARS (STRING) returns the length of the internal string. */
22070 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
22071 tmp_glyph
->charpos
< XINT (e
);
22072 tmp_glyph
++, gseq_length
++)
22074 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22078 total_pixel_width
= 0;
22079 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
22080 total_pixel_width
+= tmp_glyph
->pixel_width
;
22082 /* Pre calculation of re-rendering position */
22084 hpos
= (area
== ON_MODE_LINE
22085 ? (w
->current_matrix
)->nrows
- 1
22088 /* If the re-rendering position is included in the last
22089 re-rendering area, we should do nothing. */
22090 if ( EQ (window
, dpyinfo
->mouse_face_window
)
22091 && dpyinfo
->mouse_face_beg_col
<= vpos
22092 && vpos
< dpyinfo
->mouse_face_end_col
22093 && dpyinfo
->mouse_face_beg_row
== hpos
)
22096 if (clear_mouse_face (dpyinfo
))
22097 cursor
= No_Cursor
;
22099 dpyinfo
->mouse_face_beg_col
= vpos
;
22100 dpyinfo
->mouse_face_beg_row
= hpos
;
22102 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
22103 dpyinfo
->mouse_face_beg_y
= 0;
22105 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
22106 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
22108 dpyinfo
->mouse_face_end_x
= 0;
22109 dpyinfo
->mouse_face_end_y
= 0;
22111 dpyinfo
->mouse_face_past_end
= 0;
22112 dpyinfo
->mouse_face_window
= window
;
22114 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
22117 glyph
->face_id
, 1);
22118 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22120 if (NILP (pointer
))
22123 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22124 clear_mouse_face (dpyinfo
);
22126 define_frame_cursor1 (f
, cursor
, pointer
);
22131 Take proper action when the mouse has moved to position X, Y on
22132 frame F as regards highlighting characters that have mouse-face
22133 properties. Also de-highlighting chars where the mouse was before.
22134 X and Y can be negative or out of range. */
22137 note_mouse_highlight (f
, x
, y
)
22141 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22142 enum window_part part
;
22143 Lisp_Object window
;
22145 Cursor cursor
= No_Cursor
;
22146 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
22149 /* When a menu is active, don't highlight because this looks odd. */
22150 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
22151 if (popup_activated ())
22155 if (NILP (Vmouse_highlight
)
22156 || !f
->glyphs_initialized_p
)
22159 dpyinfo
->mouse_face_mouse_x
= x
;
22160 dpyinfo
->mouse_face_mouse_y
= y
;
22161 dpyinfo
->mouse_face_mouse_frame
= f
;
22163 if (dpyinfo
->mouse_face_defer
)
22166 if (gc_in_progress
)
22168 dpyinfo
->mouse_face_deferred_gc
= 1;
22172 /* Which window is that in? */
22173 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
22175 /* If we were displaying active text in another window, clear that.
22176 Also clear if we move out of text area in same window. */
22177 if (! EQ (window
, dpyinfo
->mouse_face_window
)
22178 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
22179 && !NILP (dpyinfo
->mouse_face_window
)))
22180 clear_mouse_face (dpyinfo
);
22182 /* Not on a window -> return. */
22183 if (!WINDOWP (window
))
22186 /* Reset help_echo_string. It will get recomputed below. */
22187 help_echo_string
= Qnil
;
22189 /* Convert to window-relative pixel coordinates. */
22190 w
= XWINDOW (window
);
22191 frame_to_window_pixel_xy (w
, &x
, &y
);
22193 /* Handle tool-bar window differently since it doesn't display a
22195 if (EQ (window
, f
->tool_bar_window
))
22197 note_tool_bar_highlight (f
, x
, y
);
22201 /* Mouse is on the mode, header line or margin? */
22202 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
22203 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
22205 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
22209 if (part
== ON_VERTICAL_BORDER
)
22210 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22211 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
22212 || part
== ON_SCROLL_BAR
)
22213 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22215 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22217 /* Are we in a window whose display is up to date?
22218 And verify the buffer's text has not changed. */
22219 b
= XBUFFER (w
->buffer
);
22220 if (part
== ON_TEXT
22221 && EQ (w
->window_end_valid
, w
->buffer
)
22222 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
22223 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
22225 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
22226 struct glyph
*glyph
;
22227 Lisp_Object object
;
22228 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
22229 Lisp_Object
*overlay_vec
= NULL
;
22231 struct buffer
*obuf
;
22232 int obegv
, ozv
, same_region
;
22234 /* Find the glyph under X/Y. */
22235 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
22237 /* Look for :pointer property on image. */
22238 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22240 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22241 if (img
!= NULL
&& IMAGEP (img
->spec
))
22243 Lisp_Object image_map
, hotspot
;
22244 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
22246 && (hotspot
= find_hot_spot (image_map
,
22247 glyph
->slice
.x
+ dx
,
22248 glyph
->slice
.y
+ dy
),
22250 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22252 Lisp_Object area_id
, plist
;
22254 area_id
= XCAR (hotspot
);
22255 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22256 If so, we could look for mouse-enter, mouse-leave
22257 properties in PLIST (and do something...). */
22258 hotspot
= XCDR (hotspot
);
22259 if (CONSP (hotspot
)
22260 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22262 pointer
= Fplist_get (plist
, Qpointer
);
22263 if (NILP (pointer
))
22265 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
22266 if (!NILP (help_echo_string
))
22268 help_echo_window
= window
;
22269 help_echo_object
= glyph
->object
;
22270 help_echo_pos
= glyph
->charpos
;
22274 if (NILP (pointer
))
22275 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
22279 /* Clear mouse face if X/Y not over text. */
22281 || area
!= TEXT_AREA
22282 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
22284 if (clear_mouse_face (dpyinfo
))
22285 cursor
= No_Cursor
;
22286 if (NILP (pointer
))
22288 if (area
!= TEXT_AREA
)
22289 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22291 pointer
= Vvoid_text_area_pointer
;
22296 pos
= glyph
->charpos
;
22297 object
= glyph
->object
;
22298 if (!STRINGP (object
) && !BUFFERP (object
))
22301 /* If we get an out-of-range value, return now; avoid an error. */
22302 if (BUFFERP (object
) && pos
> BUF_Z (b
))
22305 /* Make the window's buffer temporarily current for
22306 overlays_at and compute_char_face. */
22307 obuf
= current_buffer
;
22308 current_buffer
= b
;
22314 /* Is this char mouse-active or does it have help-echo? */
22315 position
= make_number (pos
);
22317 if (BUFFERP (object
))
22319 /* Put all the overlays we want in a vector in overlay_vec. */
22320 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
22321 /* Sort overlays into increasing priority order. */
22322 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
22327 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
22328 && vpos
>= dpyinfo
->mouse_face_beg_row
22329 && vpos
<= dpyinfo
->mouse_face_end_row
22330 && (vpos
> dpyinfo
->mouse_face_beg_row
22331 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22332 && (vpos
< dpyinfo
->mouse_face_end_row
22333 || hpos
< dpyinfo
->mouse_face_end_col
22334 || dpyinfo
->mouse_face_past_end
));
22337 cursor
= No_Cursor
;
22339 /* Check mouse-face highlighting. */
22341 /* If there exists an overlay with mouse-face overlapping
22342 the one we are currently highlighting, we have to
22343 check if we enter the overlapping overlay, and then
22344 highlight only that. */
22345 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
22346 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
22348 /* Find the highest priority overlay that has a mouse-face
22351 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
22353 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
22354 if (!NILP (mouse_face
))
22355 overlay
= overlay_vec
[i
];
22358 /* If we're actually highlighting the same overlay as
22359 before, there's no need to do that again. */
22360 if (!NILP (overlay
)
22361 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
22362 goto check_help_echo
;
22364 dpyinfo
->mouse_face_overlay
= overlay
;
22366 /* Clear the display of the old active region, if any. */
22367 if (clear_mouse_face (dpyinfo
))
22368 cursor
= No_Cursor
;
22370 /* If no overlay applies, get a text property. */
22371 if (NILP (overlay
))
22372 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
22374 /* Handle the overlay case. */
22375 if (!NILP (overlay
))
22377 /* Find the range of text around this char that
22378 should be active. */
22379 Lisp_Object before
, after
;
22382 before
= Foverlay_start (overlay
);
22383 after
= Foverlay_end (overlay
);
22384 /* Record this as the current active region. */
22385 fast_find_position (w
, XFASTINT (before
),
22386 &dpyinfo
->mouse_face_beg_col
,
22387 &dpyinfo
->mouse_face_beg_row
,
22388 &dpyinfo
->mouse_face_beg_x
,
22389 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22391 dpyinfo
->mouse_face_past_end
22392 = !fast_find_position (w
, XFASTINT (after
),
22393 &dpyinfo
->mouse_face_end_col
,
22394 &dpyinfo
->mouse_face_end_row
,
22395 &dpyinfo
->mouse_face_end_x
,
22396 &dpyinfo
->mouse_face_end_y
, Qnil
);
22397 dpyinfo
->mouse_face_window
= window
;
22399 dpyinfo
->mouse_face_face_id
22400 = face_at_buffer_position (w
, pos
, 0, 0,
22402 !dpyinfo
->mouse_face_hidden
);
22404 /* Display it as active. */
22405 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22406 cursor
= No_Cursor
;
22408 /* Handle the text property case. */
22409 else if (!NILP (mouse_face
) && BUFFERP (object
))
22411 /* Find the range of text around this char that
22412 should be active. */
22413 Lisp_Object before
, after
, beginning
, end
;
22416 beginning
= Fmarker_position (w
->start
);
22417 end
= make_number (BUF_Z (XBUFFER (object
))
22418 - XFASTINT (w
->window_end_pos
));
22420 = Fprevious_single_property_change (make_number (pos
+ 1),
22422 object
, beginning
);
22424 = Fnext_single_property_change (position
, Qmouse_face
,
22427 /* Record this as the current active region. */
22428 fast_find_position (w
, XFASTINT (before
),
22429 &dpyinfo
->mouse_face_beg_col
,
22430 &dpyinfo
->mouse_face_beg_row
,
22431 &dpyinfo
->mouse_face_beg_x
,
22432 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22433 dpyinfo
->mouse_face_past_end
22434 = !fast_find_position (w
, XFASTINT (after
),
22435 &dpyinfo
->mouse_face_end_col
,
22436 &dpyinfo
->mouse_face_end_row
,
22437 &dpyinfo
->mouse_face_end_x
,
22438 &dpyinfo
->mouse_face_end_y
, Qnil
);
22439 dpyinfo
->mouse_face_window
= window
;
22441 if (BUFFERP (object
))
22442 dpyinfo
->mouse_face_face_id
22443 = face_at_buffer_position (w
, pos
, 0, 0,
22445 !dpyinfo
->mouse_face_hidden
);
22447 /* Display it as active. */
22448 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22449 cursor
= No_Cursor
;
22451 else if (!NILP (mouse_face
) && STRINGP (object
))
22456 b
= Fprevious_single_property_change (make_number (pos
+ 1),
22459 e
= Fnext_single_property_change (position
, Qmouse_face
,
22462 b
= make_number (0);
22464 e
= make_number (SCHARS (object
) - 1);
22466 fast_find_string_pos (w
, XINT (b
), object
,
22467 &dpyinfo
->mouse_face_beg_col
,
22468 &dpyinfo
->mouse_face_beg_row
,
22469 &dpyinfo
->mouse_face_beg_x
,
22470 &dpyinfo
->mouse_face_beg_y
, 0);
22471 fast_find_string_pos (w
, XINT (e
), object
,
22472 &dpyinfo
->mouse_face_end_col
,
22473 &dpyinfo
->mouse_face_end_row
,
22474 &dpyinfo
->mouse_face_end_x
,
22475 &dpyinfo
->mouse_face_end_y
, 1);
22476 dpyinfo
->mouse_face_past_end
= 0;
22477 dpyinfo
->mouse_face_window
= window
;
22478 dpyinfo
->mouse_face_face_id
22479 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
22480 glyph
->face_id
, 1);
22481 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22482 cursor
= No_Cursor
;
22484 else if (STRINGP (object
) && NILP (mouse_face
))
22486 /* A string which doesn't have mouse-face, but
22487 the text ``under'' it might have. */
22488 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
22489 int start
= MATRIX_ROW_START_CHARPOS (r
);
22491 pos
= string_buffer_position (w
, object
, start
);
22493 mouse_face
= get_char_property_and_overlay (make_number (pos
),
22497 if (!NILP (mouse_face
) && !NILP (overlay
))
22499 Lisp_Object before
= Foverlay_start (overlay
);
22500 Lisp_Object after
= Foverlay_end (overlay
);
22503 /* Note that we might not be able to find position
22504 BEFORE in the glyph matrix if the overlay is
22505 entirely covered by a `display' property. In
22506 this case, we overshoot. So let's stop in
22507 the glyph matrix before glyphs for OBJECT. */
22508 fast_find_position (w
, XFASTINT (before
),
22509 &dpyinfo
->mouse_face_beg_col
,
22510 &dpyinfo
->mouse_face_beg_row
,
22511 &dpyinfo
->mouse_face_beg_x
,
22512 &dpyinfo
->mouse_face_beg_y
,
22515 dpyinfo
->mouse_face_past_end
22516 = !fast_find_position (w
, XFASTINT (after
),
22517 &dpyinfo
->mouse_face_end_col
,
22518 &dpyinfo
->mouse_face_end_row
,
22519 &dpyinfo
->mouse_face_end_x
,
22520 &dpyinfo
->mouse_face_end_y
,
22522 dpyinfo
->mouse_face_window
= window
;
22523 dpyinfo
->mouse_face_face_id
22524 = face_at_buffer_position (w
, pos
, 0, 0,
22526 !dpyinfo
->mouse_face_hidden
);
22528 /* Display it as active. */
22529 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22530 cursor
= No_Cursor
;
22537 /* Look for a `help-echo' property. */
22538 if (NILP (help_echo_string
)) {
22539 Lisp_Object help
, overlay
;
22541 /* Check overlays first. */
22542 help
= overlay
= Qnil
;
22543 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
22545 overlay
= overlay_vec
[i
];
22546 help
= Foverlay_get (overlay
, Qhelp_echo
);
22551 help_echo_string
= help
;
22552 help_echo_window
= window
;
22553 help_echo_object
= overlay
;
22554 help_echo_pos
= pos
;
22558 Lisp_Object object
= glyph
->object
;
22559 int charpos
= glyph
->charpos
;
22561 /* Try text properties. */
22562 if (STRINGP (object
)
22564 && charpos
< SCHARS (object
))
22566 help
= Fget_text_property (make_number (charpos
),
22567 Qhelp_echo
, object
);
22570 /* If the string itself doesn't specify a help-echo,
22571 see if the buffer text ``under'' it does. */
22572 struct glyph_row
*r
22573 = MATRIX_ROW (w
->current_matrix
, vpos
);
22574 int start
= MATRIX_ROW_START_CHARPOS (r
);
22575 int pos
= string_buffer_position (w
, object
, start
);
22578 help
= Fget_char_property (make_number (pos
),
22579 Qhelp_echo
, w
->buffer
);
22583 object
= w
->buffer
;
22588 else if (BUFFERP (object
)
22591 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
22596 help_echo_string
= help
;
22597 help_echo_window
= window
;
22598 help_echo_object
= object
;
22599 help_echo_pos
= charpos
;
22604 /* Look for a `pointer' property. */
22605 if (NILP (pointer
))
22607 /* Check overlays first. */
22608 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
22609 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
22611 if (NILP (pointer
))
22613 Lisp_Object object
= glyph
->object
;
22614 int charpos
= glyph
->charpos
;
22616 /* Try text properties. */
22617 if (STRINGP (object
)
22619 && charpos
< SCHARS (object
))
22621 pointer
= Fget_text_property (make_number (charpos
),
22623 if (NILP (pointer
))
22625 /* If the string itself doesn't specify a pointer,
22626 see if the buffer text ``under'' it does. */
22627 struct glyph_row
*r
22628 = MATRIX_ROW (w
->current_matrix
, vpos
);
22629 int start
= MATRIX_ROW_START_CHARPOS (r
);
22630 int pos
= string_buffer_position (w
, object
, start
);
22632 pointer
= Fget_char_property (make_number (pos
),
22633 Qpointer
, w
->buffer
);
22636 else if (BUFFERP (object
)
22639 pointer
= Fget_text_property (make_number (charpos
),
22646 current_buffer
= obuf
;
22651 define_frame_cursor1 (f
, cursor
, pointer
);
22656 Clear any mouse-face on window W. This function is part of the
22657 redisplay interface, and is called from try_window_id and similar
22658 functions to ensure the mouse-highlight is off. */
22661 x_clear_window_mouse_face (w
)
22664 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22665 Lisp_Object window
;
22668 XSETWINDOW (window
, w
);
22669 if (EQ (window
, dpyinfo
->mouse_face_window
))
22670 clear_mouse_face (dpyinfo
);
22676 Just discard the mouse face information for frame F, if any.
22677 This is used when the size of F is changed. */
22680 cancel_mouse_face (f
)
22683 Lisp_Object window
;
22684 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22686 window
= dpyinfo
->mouse_face_window
;
22687 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
22689 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22690 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22691 dpyinfo
->mouse_face_window
= Qnil
;
22696 #endif /* HAVE_WINDOW_SYSTEM */
22699 /***********************************************************************
22701 ***********************************************************************/
22703 #ifdef HAVE_WINDOW_SYSTEM
22705 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
22706 which intersects rectangle R. R is in window-relative coordinates. */
22709 expose_area (w
, row
, r
, area
)
22711 struct glyph_row
*row
;
22713 enum glyph_row_area area
;
22715 struct glyph
*first
= row
->glyphs
[area
];
22716 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
22717 struct glyph
*last
;
22718 int first_x
, start_x
, x
;
22720 if (area
== TEXT_AREA
&& row
->fill_line_p
)
22721 /* If row extends face to end of line write the whole line. */
22722 draw_glyphs (w
, 0, row
, area
,
22723 0, row
->used
[area
],
22724 DRAW_NORMAL_TEXT
, 0);
22727 /* Set START_X to the window-relative start position for drawing glyphs of
22728 AREA. The first glyph of the text area can be partially visible.
22729 The first glyphs of other areas cannot. */
22730 start_x
= window_box_left_offset (w
, area
);
22732 if (area
== TEXT_AREA
)
22735 /* Find the first glyph that must be redrawn. */
22737 && x
+ first
->pixel_width
< r
->x
)
22739 x
+= first
->pixel_width
;
22743 /* Find the last one. */
22747 && x
< r
->x
+ r
->width
)
22749 x
+= last
->pixel_width
;
22755 draw_glyphs (w
, first_x
- start_x
, row
, area
,
22756 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
22757 DRAW_NORMAL_TEXT
, 0);
22762 /* Redraw the parts of the glyph row ROW on window W intersecting
22763 rectangle R. R is in window-relative coordinates. Value is
22764 non-zero if mouse-face was overwritten. */
22767 expose_line (w
, row
, r
)
22769 struct glyph_row
*row
;
22772 xassert (row
->enabled_p
);
22774 if (row
->mode_line_p
|| w
->pseudo_window_p
)
22775 draw_glyphs (w
, 0, row
, TEXT_AREA
,
22776 0, row
->used
[TEXT_AREA
],
22777 DRAW_NORMAL_TEXT
, 0);
22780 if (row
->used
[LEFT_MARGIN_AREA
])
22781 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
22782 if (row
->used
[TEXT_AREA
])
22783 expose_area (w
, row
, r
, TEXT_AREA
);
22784 if (row
->used
[RIGHT_MARGIN_AREA
])
22785 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
22786 draw_row_fringe_bitmaps (w
, row
);
22789 return row
->mouse_face_p
;
22793 /* Redraw those parts of glyphs rows during expose event handling that
22794 overlap other rows. Redrawing of an exposed line writes over parts
22795 of lines overlapping that exposed line; this function fixes that.
22797 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
22798 row in W's current matrix that is exposed and overlaps other rows.
22799 LAST_OVERLAPPING_ROW is the last such row. */
22802 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
22804 struct glyph_row
*first_overlapping_row
;
22805 struct glyph_row
*last_overlapping_row
;
22807 struct glyph_row
*row
;
22809 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
22810 if (row
->overlapping_p
)
22812 xassert (row
->enabled_p
&& !row
->mode_line_p
);
22814 if (row
->used
[LEFT_MARGIN_AREA
])
22815 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
22817 if (row
->used
[TEXT_AREA
])
22818 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
22820 if (row
->used
[RIGHT_MARGIN_AREA
])
22821 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
22826 /* Return non-zero if W's cursor intersects rectangle R. */
22829 phys_cursor_in_rect_p (w
, r
)
22833 XRectangle cr
, result
;
22834 struct glyph
*cursor_glyph
;
22836 cursor_glyph
= get_phys_cursor_glyph (w
);
22839 /* r is relative to W's box, but w->phys_cursor.x is relative
22840 to left edge of W's TEXT area. Adjust it. */
22841 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
22842 cr
.y
= w
->phys_cursor
.y
;
22843 cr
.width
= cursor_glyph
->pixel_width
;
22844 cr
.height
= w
->phys_cursor_height
;
22845 /* ++KFS: W32 version used W32-specific IntersectRect here, but
22846 I assume the effect is the same -- and this is portable. */
22847 return x_intersect_rectangles (&cr
, r
, &result
);
22855 Draw a vertical window border to the right of window W if W doesn't
22856 have vertical scroll bars. */
22859 x_draw_vertical_border (w
)
22862 /* We could do better, if we knew what type of scroll-bar the adjacent
22863 windows (on either side) have... But we don't :-(
22864 However, I think this works ok. ++KFS 2003-04-25 */
22866 /* Redraw borders between horizontally adjacent windows. Don't
22867 do it for frames with vertical scroll bars because either the
22868 right scroll bar of a window, or the left scroll bar of its
22869 neighbor will suffice as a border. */
22870 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
22873 if (!WINDOW_RIGHTMOST_P (w
)
22874 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
22876 int x0
, x1
, y0
, y1
;
22878 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22881 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22884 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
22886 else if (!WINDOW_LEFTMOST_P (w
)
22887 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
22889 int x0
, x1
, y0
, y1
;
22891 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22894 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22897 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
22902 /* Redraw the part of window W intersection rectangle FR. Pixel
22903 coordinates in FR are frame-relative. Call this function with
22904 input blocked. Value is non-zero if the exposure overwrites
22908 expose_window (w
, fr
)
22912 struct frame
*f
= XFRAME (w
->frame
);
22914 int mouse_face_overwritten_p
= 0;
22916 /* If window is not yet fully initialized, do nothing. This can
22917 happen when toolkit scroll bars are used and a window is split.
22918 Reconfiguring the scroll bar will generate an expose for a newly
22920 if (w
->current_matrix
== NULL
)
22923 /* When we're currently updating the window, display and current
22924 matrix usually don't agree. Arrange for a thorough display
22926 if (w
== updated_window
)
22928 SET_FRAME_GARBAGED (f
);
22932 /* Frame-relative pixel rectangle of W. */
22933 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
22934 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
22935 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
22936 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
22938 if (x_intersect_rectangles (fr
, &wr
, &r
))
22940 int yb
= window_text_bottom_y (w
);
22941 struct glyph_row
*row
;
22942 int cursor_cleared_p
;
22943 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
22945 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
22946 r
.x
, r
.y
, r
.width
, r
.height
));
22948 /* Convert to window coordinates. */
22949 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
22950 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
22952 /* Turn off the cursor. */
22953 if (!w
->pseudo_window_p
22954 && phys_cursor_in_rect_p (w
, &r
))
22956 x_clear_cursor (w
);
22957 cursor_cleared_p
= 1;
22960 cursor_cleared_p
= 0;
22962 /* Update lines intersecting rectangle R. */
22963 first_overlapping_row
= last_overlapping_row
= NULL
;
22964 for (row
= w
->current_matrix
->rows
;
22969 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
22971 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
22972 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
22973 || (r
.y
>= y0
&& r
.y
< y1
)
22974 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
22976 /* A header line may be overlapping, but there is no need
22977 to fix overlapping areas for them. KFS 2005-02-12 */
22978 if (row
->overlapping_p
&& !row
->mode_line_p
)
22980 if (first_overlapping_row
== NULL
)
22981 first_overlapping_row
= row
;
22982 last_overlapping_row
= row
;
22985 if (expose_line (w
, row
, &r
))
22986 mouse_face_overwritten_p
= 1;
22993 /* Display the mode line if there is one. */
22994 if (WINDOW_WANTS_MODELINE_P (w
)
22995 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
22997 && row
->y
< r
.y
+ r
.height
)
22999 if (expose_line (w
, row
, &r
))
23000 mouse_face_overwritten_p
= 1;
23003 if (!w
->pseudo_window_p
)
23005 /* Fix the display of overlapping rows. */
23006 if (first_overlapping_row
)
23007 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
23009 /* Draw border between windows. */
23010 x_draw_vertical_border (w
);
23012 /* Turn the cursor on again. */
23013 if (cursor_cleared_p
)
23014 update_window_cursor (w
, 1);
23018 return mouse_face_overwritten_p
;
23023 /* Redraw (parts) of all windows in the window tree rooted at W that
23024 intersect R. R contains frame pixel coordinates. Value is
23025 non-zero if the exposure overwrites mouse-face. */
23028 expose_window_tree (w
, r
)
23032 struct frame
*f
= XFRAME (w
->frame
);
23033 int mouse_face_overwritten_p
= 0;
23035 while (w
&& !FRAME_GARBAGED_P (f
))
23037 if (!NILP (w
->hchild
))
23038 mouse_face_overwritten_p
23039 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
23040 else if (!NILP (w
->vchild
))
23041 mouse_face_overwritten_p
23042 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
23044 mouse_face_overwritten_p
|= expose_window (w
, r
);
23046 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
23049 return mouse_face_overwritten_p
;
23054 Redisplay an exposed area of frame F. X and Y are the upper-left
23055 corner of the exposed rectangle. W and H are width and height of
23056 the exposed area. All are pixel values. W or H zero means redraw
23057 the entire frame. */
23060 expose_frame (f
, x
, y
, w
, h
)
23065 int mouse_face_overwritten_p
= 0;
23067 TRACE ((stderr
, "expose_frame "));
23069 /* No need to redraw if frame will be redrawn soon. */
23070 if (FRAME_GARBAGED_P (f
))
23072 TRACE ((stderr
, " garbaged\n"));
23076 /* If basic faces haven't been realized yet, there is no point in
23077 trying to redraw anything. This can happen when we get an expose
23078 event while Emacs is starting, e.g. by moving another window. */
23079 if (FRAME_FACE_CACHE (f
) == NULL
23080 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
23082 TRACE ((stderr
, " no faces\n"));
23086 if (w
== 0 || h
== 0)
23089 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
23090 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
23100 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
23101 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
23103 if (WINDOWP (f
->tool_bar_window
))
23104 mouse_face_overwritten_p
23105 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
23107 #ifdef HAVE_X_WINDOWS
23109 #ifndef USE_X_TOOLKIT
23110 if (WINDOWP (f
->menu_bar_window
))
23111 mouse_face_overwritten_p
23112 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
23113 #endif /* not USE_X_TOOLKIT */
23117 /* Some window managers support a focus-follows-mouse style with
23118 delayed raising of frames. Imagine a partially obscured frame,
23119 and moving the mouse into partially obscured mouse-face on that
23120 frame. The visible part of the mouse-face will be highlighted,
23121 then the WM raises the obscured frame. With at least one WM, KDE
23122 2.1, Emacs is not getting any event for the raising of the frame
23123 (even tried with SubstructureRedirectMask), only Expose events.
23124 These expose events will draw text normally, i.e. not
23125 highlighted. Which means we must redo the highlight here.
23126 Subsume it under ``we love X''. --gerd 2001-08-15 */
23127 /* Included in Windows version because Windows most likely does not
23128 do the right thing if any third party tool offers
23129 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
23130 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
23132 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23133 if (f
== dpyinfo
->mouse_face_mouse_frame
)
23135 int x
= dpyinfo
->mouse_face_mouse_x
;
23136 int y
= dpyinfo
->mouse_face_mouse_y
;
23137 clear_mouse_face (dpyinfo
);
23138 note_mouse_highlight (f
, x
, y
);
23145 Determine the intersection of two rectangles R1 and R2. Return
23146 the intersection in *RESULT. Value is non-zero if RESULT is not
23150 x_intersect_rectangles (r1
, r2
, result
)
23151 XRectangle
*r1
, *r2
, *result
;
23153 XRectangle
*left
, *right
;
23154 XRectangle
*upper
, *lower
;
23155 int intersection_p
= 0;
23157 /* Rearrange so that R1 is the left-most rectangle. */
23159 left
= r1
, right
= r2
;
23161 left
= r2
, right
= r1
;
23163 /* X0 of the intersection is right.x0, if this is inside R1,
23164 otherwise there is no intersection. */
23165 if (right
->x
<= left
->x
+ left
->width
)
23167 result
->x
= right
->x
;
23169 /* The right end of the intersection is the minimum of the
23170 the right ends of left and right. */
23171 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
23174 /* Same game for Y. */
23176 upper
= r1
, lower
= r2
;
23178 upper
= r2
, lower
= r1
;
23180 /* The upper end of the intersection is lower.y0, if this is inside
23181 of upper. Otherwise, there is no intersection. */
23182 if (lower
->y
<= upper
->y
+ upper
->height
)
23184 result
->y
= lower
->y
;
23186 /* The lower end of the intersection is the minimum of the lower
23187 ends of upper and lower. */
23188 result
->height
= (min (lower
->y
+ lower
->height
,
23189 upper
->y
+ upper
->height
)
23191 intersection_p
= 1;
23195 return intersection_p
;
23198 #endif /* HAVE_WINDOW_SYSTEM */
23201 /***********************************************************************
23203 ***********************************************************************/
23208 Vwith_echo_area_save_vector
= Qnil
;
23209 staticpro (&Vwith_echo_area_save_vector
);
23211 Vmessage_stack
= Qnil
;
23212 staticpro (&Vmessage_stack
);
23214 Qinhibit_redisplay
= intern ("inhibit-redisplay");
23215 staticpro (&Qinhibit_redisplay
);
23217 message_dolog_marker1
= Fmake_marker ();
23218 staticpro (&message_dolog_marker1
);
23219 message_dolog_marker2
= Fmake_marker ();
23220 staticpro (&message_dolog_marker2
);
23221 message_dolog_marker3
= Fmake_marker ();
23222 staticpro (&message_dolog_marker3
);
23225 defsubr (&Sdump_frame_glyph_matrix
);
23226 defsubr (&Sdump_glyph_matrix
);
23227 defsubr (&Sdump_glyph_row
);
23228 defsubr (&Sdump_tool_bar_row
);
23229 defsubr (&Strace_redisplay
);
23230 defsubr (&Strace_to_stderr
);
23232 #ifdef HAVE_WINDOW_SYSTEM
23233 defsubr (&Stool_bar_lines_needed
);
23234 defsubr (&Slookup_image_map
);
23236 defsubr (&Sformat_mode_line
);
23238 staticpro (&Qmenu_bar_update_hook
);
23239 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
23241 staticpro (&Qoverriding_terminal_local_map
);
23242 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
23244 staticpro (&Qoverriding_local_map
);
23245 Qoverriding_local_map
= intern ("overriding-local-map");
23247 staticpro (&Qwindow_scroll_functions
);
23248 Qwindow_scroll_functions
= intern ("window-scroll-functions");
23250 staticpro (&Qredisplay_end_trigger_functions
);
23251 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
23253 staticpro (&Qinhibit_point_motion_hooks
);
23254 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
23256 QCdata
= intern (":data");
23257 staticpro (&QCdata
);
23258 Qdisplay
= intern ("display");
23259 staticpro (&Qdisplay
);
23260 Qspace_width
= intern ("space-width");
23261 staticpro (&Qspace_width
);
23262 Qraise
= intern ("raise");
23263 staticpro (&Qraise
);
23264 Qslice
= intern ("slice");
23265 staticpro (&Qslice
);
23266 Qspace
= intern ("space");
23267 staticpro (&Qspace
);
23268 Qmargin
= intern ("margin");
23269 staticpro (&Qmargin
);
23270 Qpointer
= intern ("pointer");
23271 staticpro (&Qpointer
);
23272 Qleft_margin
= intern ("left-margin");
23273 staticpro (&Qleft_margin
);
23274 Qright_margin
= intern ("right-margin");
23275 staticpro (&Qright_margin
);
23276 Qcenter
= intern ("center");
23277 staticpro (&Qcenter
);
23278 Qline_height
= intern ("line-height");
23279 staticpro (&Qline_height
);
23280 QCalign_to
= intern (":align-to");
23281 staticpro (&QCalign_to
);
23282 QCrelative_width
= intern (":relative-width");
23283 staticpro (&QCrelative_width
);
23284 QCrelative_height
= intern (":relative-height");
23285 staticpro (&QCrelative_height
);
23286 QCeval
= intern (":eval");
23287 staticpro (&QCeval
);
23288 QCpropertize
= intern (":propertize");
23289 staticpro (&QCpropertize
);
23290 QCfile
= intern (":file");
23291 staticpro (&QCfile
);
23292 Qfontified
= intern ("fontified");
23293 staticpro (&Qfontified
);
23294 Qfontification_functions
= intern ("fontification-functions");
23295 staticpro (&Qfontification_functions
);
23296 Qtrailing_whitespace
= intern ("trailing-whitespace");
23297 staticpro (&Qtrailing_whitespace
);
23298 Qescape_glyph
= intern ("escape-glyph");
23299 staticpro (&Qescape_glyph
);
23300 Qnobreak_space
= intern ("nobreak-space");
23301 staticpro (&Qnobreak_space
);
23302 Qimage
= intern ("image");
23303 staticpro (&Qimage
);
23304 QCmap
= intern (":map");
23305 staticpro (&QCmap
);
23306 QCpointer
= intern (":pointer");
23307 staticpro (&QCpointer
);
23308 Qrect
= intern ("rect");
23309 staticpro (&Qrect
);
23310 Qcircle
= intern ("circle");
23311 staticpro (&Qcircle
);
23312 Qpoly
= intern ("poly");
23313 staticpro (&Qpoly
);
23314 Qmessage_truncate_lines
= intern ("message-truncate-lines");
23315 staticpro (&Qmessage_truncate_lines
);
23316 Qgrow_only
= intern ("grow-only");
23317 staticpro (&Qgrow_only
);
23318 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
23319 staticpro (&Qinhibit_menubar_update
);
23320 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
23321 staticpro (&Qinhibit_eval_during_redisplay
);
23322 Qposition
= intern ("position");
23323 staticpro (&Qposition
);
23324 Qbuffer_position
= intern ("buffer-position");
23325 staticpro (&Qbuffer_position
);
23326 Qobject
= intern ("object");
23327 staticpro (&Qobject
);
23328 Qbar
= intern ("bar");
23330 Qhbar
= intern ("hbar");
23331 staticpro (&Qhbar
);
23332 Qbox
= intern ("box");
23334 Qhollow
= intern ("hollow");
23335 staticpro (&Qhollow
);
23336 Qhand
= intern ("hand");
23337 staticpro (&Qhand
);
23338 Qarrow
= intern ("arrow");
23339 staticpro (&Qarrow
);
23340 Qtext
= intern ("text");
23341 staticpro (&Qtext
);
23342 Qrisky_local_variable
= intern ("risky-local-variable");
23343 staticpro (&Qrisky_local_variable
);
23344 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
23345 staticpro (&Qinhibit_free_realized_faces
);
23347 list_of_error
= Fcons (Fcons (intern ("error"),
23348 Fcons (intern ("void-variable"), Qnil
)),
23350 staticpro (&list_of_error
);
23352 Qlast_arrow_position
= intern ("last-arrow-position");
23353 staticpro (&Qlast_arrow_position
);
23354 Qlast_arrow_string
= intern ("last-arrow-string");
23355 staticpro (&Qlast_arrow_string
);
23357 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
23358 staticpro (&Qoverlay_arrow_string
);
23359 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
23360 staticpro (&Qoverlay_arrow_bitmap
);
23362 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
23363 staticpro (&echo_buffer
[0]);
23364 staticpro (&echo_buffer
[1]);
23366 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
23367 staticpro (&echo_area_buffer
[0]);
23368 staticpro (&echo_area_buffer
[1]);
23370 Vmessages_buffer_name
= build_string ("*Messages*");
23371 staticpro (&Vmessages_buffer_name
);
23373 mode_line_proptrans_alist
= Qnil
;
23374 staticpro (&mode_line_proptrans_alist
);
23375 mode_line_string_list
= Qnil
;
23376 staticpro (&mode_line_string_list
);
23377 mode_line_string_face
= Qnil
;
23378 staticpro (&mode_line_string_face
);
23379 mode_line_string_face_prop
= Qnil
;
23380 staticpro (&mode_line_string_face_prop
);
23381 Vmode_line_unwind_vector
= Qnil
;
23382 staticpro (&Vmode_line_unwind_vector
);
23384 help_echo_string
= Qnil
;
23385 staticpro (&help_echo_string
);
23386 help_echo_object
= Qnil
;
23387 staticpro (&help_echo_object
);
23388 help_echo_window
= Qnil
;
23389 staticpro (&help_echo_window
);
23390 previous_help_echo_string
= Qnil
;
23391 staticpro (&previous_help_echo_string
);
23392 help_echo_pos
= -1;
23394 #ifdef HAVE_WINDOW_SYSTEM
23395 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
23396 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
23397 For example, if a block cursor is over a tab, it will be drawn as
23398 wide as that tab on the display. */);
23399 x_stretch_cursor_p
= 0;
23402 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
23403 doc
: /* *Non-nil means highlight trailing whitespace.
23404 The face used for trailing whitespace is `trailing-whitespace'. */);
23405 Vshow_trailing_whitespace
= Qnil
;
23407 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
23408 doc
: /* *Control highlighting of nobreak space and soft hyphen.
23409 A value of t means highlight the character itself (for nobreak space,
23410 use face `nobreak-space').
23411 A value of nil means no highlighting.
23412 Other values mean display the escape glyph followed by an ordinary
23413 space or ordinary hyphen. */);
23414 Vnobreak_char_display
= Qt
;
23416 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
23417 doc
: /* *The pointer shape to show in void text areas.
23418 A value of nil means to show the text pointer. Other options are `arrow',
23419 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
23420 Vvoid_text_area_pointer
= Qarrow
;
23422 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
23423 doc
: /* Non-nil means don't actually do any redisplay.
23424 This is used for internal purposes. */);
23425 Vinhibit_redisplay
= Qnil
;
23427 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
23428 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
23429 Vglobal_mode_string
= Qnil
;
23431 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
23432 doc
: /* Marker for where to display an arrow on top of the buffer text.
23433 This must be the beginning of a line in order to work.
23434 See also `overlay-arrow-string'. */);
23435 Voverlay_arrow_position
= Qnil
;
23437 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
23438 doc
: /* String to display as an arrow in non-window frames.
23439 See also `overlay-arrow-position'. */);
23440 Voverlay_arrow_string
= build_string ("=>");
23442 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
23443 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
23444 The symbols on this list are examined during redisplay to determine
23445 where to display overlay arrows. */);
23446 Voverlay_arrow_variable_list
23447 = Fcons (intern ("overlay-arrow-position"), Qnil
);
23449 DEFVAR_INT ("scroll-step", &scroll_step
,
23450 doc
: /* *The number of lines to try scrolling a window by when point moves out.
23451 If that fails to bring point back on frame, point is centered instead.
23452 If this is zero, point is always centered after it moves off frame.
23453 If you want scrolling to always be a line at a time, you should set
23454 `scroll-conservatively' to a large value rather than set this to 1. */);
23456 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
23457 doc
: /* *Scroll up to this many lines, to bring point back on screen.
23458 A value of zero means to scroll the text to center point vertically
23459 in the window. */);
23460 scroll_conservatively
= 0;
23462 DEFVAR_INT ("scroll-margin", &scroll_margin
,
23463 doc
: /* *Number of lines of margin at the top and bottom of a window.
23464 Recenter the window whenever point gets within this many lines
23465 of the top or bottom of the window. */);
23468 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
23469 doc
: /* Pixels per inch value for non-window system displays.
23470 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
23471 Vdisplay_pixels_per_inch
= make_float (72.0);
23474 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
23477 DEFVAR_BOOL ("truncate-partial-width-windows",
23478 &truncate_partial_width_windows
,
23479 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
23480 truncate_partial_width_windows
= 1;
23482 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
23483 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
23484 Any other value means to use the appropriate face, `mode-line',
23485 `header-line', or `menu' respectively. */);
23486 mode_line_inverse_video
= 1;
23488 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
23489 doc
: /* *Maximum buffer size for which line number should be displayed.
23490 If the buffer is bigger than this, the line number does not appear
23491 in the mode line. A value of nil means no limit. */);
23492 Vline_number_display_limit
= Qnil
;
23494 DEFVAR_INT ("line-number-display-limit-width",
23495 &line_number_display_limit_width
,
23496 doc
: /* *Maximum line width (in characters) for line number display.
23497 If the average length of the lines near point is bigger than this, then the
23498 line number may be omitted from the mode line. */);
23499 line_number_display_limit_width
= 200;
23501 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
23502 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
23503 highlight_nonselected_windows
= 0;
23505 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
23506 doc
: /* Non-nil if more than one frame is visible on this display.
23507 Minibuffer-only frames don't count, but iconified frames do.
23508 This variable is not guaranteed to be accurate except while processing
23509 `frame-title-format' and `icon-title-format'. */);
23511 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
23512 doc
: /* Template for displaying the title bar of visible frames.
23513 \(Assuming the window manager supports this feature.)
23514 This variable has the same structure as `mode-line-format' (which see),
23515 and is used only on frames for which no explicit name has been set
23516 \(see `modify-frame-parameters'). */);
23518 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
23519 doc
: /* Template for displaying the title bar of an iconified frame.
23520 \(Assuming the window manager supports this feature.)
23521 This variable has the same structure as `mode-line-format' (which see),
23522 and is used only on frames for which no explicit name has been set
23523 \(see `modify-frame-parameters'). */);
23525 = Vframe_title_format
23526 = Fcons (intern ("multiple-frames"),
23527 Fcons (build_string ("%b"),
23528 Fcons (Fcons (empty_string
,
23529 Fcons (intern ("invocation-name"),
23530 Fcons (build_string ("@"),
23531 Fcons (intern ("system-name"),
23535 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
23536 doc
: /* Maximum number of lines to keep in the message log buffer.
23537 If nil, disable message logging. If t, log messages but don't truncate
23538 the buffer when it becomes large. */);
23539 Vmessage_log_max
= make_number (50);
23541 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
23542 doc
: /* Functions called before redisplay, if window sizes have changed.
23543 The value should be a list of functions that take one argument.
23544 Just before redisplay, for each frame, if any of its windows have changed
23545 size since the last redisplay, or have been split or deleted,
23546 all the functions in the list are called, with the frame as argument. */);
23547 Vwindow_size_change_functions
= Qnil
;
23549 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
23550 doc
: /* List of functions to call before redisplaying a window with scrolling.
23551 Each function is called with two arguments, the window
23552 and its new display-start position. Note that the value of `window-end'
23553 is not valid when these functions are called. */);
23554 Vwindow_scroll_functions
= Qnil
;
23556 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
23557 doc
: /* Functions called when redisplay of a window reaches the end trigger.
23558 Each function is called with two arguments, the window and the end trigger value.
23559 See `set-window-redisplay-end-trigger'. */);
23560 Vredisplay_end_trigger_functions
= Qnil
;
23562 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
23563 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
23564 mouse_autoselect_window
= 0;
23566 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
23567 doc
: /* *Non-nil means automatically resize tool-bars.
23568 This increases a tool-bar's height if not all tool-bar items are visible.
23569 It decreases a tool-bar's height when it would display blank lines
23571 auto_resize_tool_bars_p
= 1;
23573 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
23574 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
23575 auto_raise_tool_bar_buttons_p
= 1;
23577 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
23578 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
23579 make_cursor_line_fully_visible_p
= 1;
23581 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
23582 doc
: /* *Margin around tool-bar buttons in pixels.
23583 If an integer, use that for both horizontal and vertical margins.
23584 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
23585 HORZ specifying the horizontal margin, and VERT specifying the
23586 vertical margin. */);
23587 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
23589 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
23590 doc
: /* *Relief thickness of tool-bar buttons. */);
23591 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
23593 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
23594 doc
: /* List of functions to call to fontify regions of text.
23595 Each function is called with one argument POS. Functions must
23596 fontify a region starting at POS in the current buffer, and give
23597 fontified regions the property `fontified'. */);
23598 Vfontification_functions
= Qnil
;
23599 Fmake_variable_buffer_local (Qfontification_functions
);
23601 DEFVAR_BOOL ("unibyte-display-via-language-environment",
23602 &unibyte_display_via_language_environment
,
23603 doc
: /* *Non-nil means display unibyte text according to language environment.
23604 Specifically this means that unibyte non-ASCII characters
23605 are displayed by converting them to the equivalent multibyte characters
23606 according to the current language environment. As a result, they are
23607 displayed according to the current fontset. */);
23608 unibyte_display_via_language_environment
= 0;
23610 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
23611 doc
: /* *Maximum height for resizing mini-windows.
23612 If a float, it specifies a fraction of the mini-window frame's height.
23613 If an integer, it specifies a number of lines. */);
23614 Vmax_mini_window_height
= make_float (0.25);
23616 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
23617 doc
: /* *How to resize mini-windows.
23618 A value of nil means don't automatically resize mini-windows.
23619 A value of t means resize them to fit the text displayed in them.
23620 A value of `grow-only', the default, means let mini-windows grow
23621 only, until their display becomes empty, at which point the windows
23622 go back to their normal size. */);
23623 Vresize_mini_windows
= Qgrow_only
;
23625 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
23626 doc
: /* Alist specifying how to blink the cursor off.
23627 Each element has the form (ON-STATE . OFF-STATE). Whenever the
23628 `cursor-type' frame-parameter or variable equals ON-STATE,
23629 comparing using `equal', Emacs uses OFF-STATE to specify
23630 how to blink it off. */);
23631 Vblink_cursor_alist
= Qnil
;
23633 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
23634 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
23635 automatic_hscrolling_p
= 1;
23637 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
23638 doc
: /* *How many columns away from the window edge point is allowed to get
23639 before automatic hscrolling will horizontally scroll the window. */);
23640 hscroll_margin
= 5;
23642 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
23643 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
23644 When point is less than `automatic-hscroll-margin' columns from the window
23645 edge, automatic hscrolling will scroll the window by the amount of columns
23646 determined by this variable. If its value is a positive integer, scroll that
23647 many columns. If it's a positive floating-point number, it specifies the
23648 fraction of the window's width to scroll. If it's nil or zero, point will be
23649 centered horizontally after the scroll. Any other value, including negative
23650 numbers, are treated as if the value were zero.
23652 Automatic hscrolling always moves point outside the scroll margin, so if
23653 point was more than scroll step columns inside the margin, the window will
23654 scroll more than the value given by the scroll step.
23656 Note that the lower bound for automatic hscrolling specified by `scroll-left'
23657 and `scroll-right' overrides this variable's effect. */);
23658 Vhscroll_step
= make_number (0);
23660 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
23661 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
23662 Bind this around calls to `message' to let it take effect. */);
23663 message_truncate_lines
= 0;
23665 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
23666 doc
: /* Normal hook run to update the menu bar definitions.
23667 Redisplay runs this hook before it redisplays the menu bar.
23668 This is used to update submenus such as Buffers,
23669 whose contents depend on various data. */);
23670 Vmenu_bar_update_hook
= Qnil
;
23672 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
23673 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
23674 inhibit_menubar_update
= 0;
23676 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
23677 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
23678 inhibit_eval_during_redisplay
= 0;
23680 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
23681 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
23682 inhibit_free_realized_faces
= 0;
23685 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
23686 doc
: /* Inhibit try_window_id display optimization. */);
23687 inhibit_try_window_id
= 0;
23689 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
23690 doc
: /* Inhibit try_window_reusing display optimization. */);
23691 inhibit_try_window_reusing
= 0;
23693 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
23694 doc
: /* Inhibit try_cursor_movement display optimization. */);
23695 inhibit_try_cursor_movement
= 0;
23696 #endif /* GLYPH_DEBUG */
23700 /* Initialize this module when Emacs starts. */
23705 Lisp_Object root_window
;
23706 struct window
*mini_w
;
23708 current_header_line_height
= current_mode_line_height
= -1;
23710 CHARPOS (this_line_start_pos
) = 0;
23712 mini_w
= XWINDOW (minibuf_window
);
23713 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
23715 if (!noninteractive
)
23717 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
23720 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
23721 set_window_height (root_window
,
23722 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
23724 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
23725 set_window_height (minibuf_window
, 1, 0);
23727 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
23728 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
23730 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
23731 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
23732 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
23734 /* The default ellipsis glyphs `...'. */
23735 for (i
= 0; i
< 3; ++i
)
23736 default_invis_vector
[i
] = make_number ('.');
23740 /* Allocate the buffer for frame titles.
23741 Also used for `format-mode-line'. */
23743 mode_line_noprop_buf
= (char *) xmalloc (size
);
23744 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
23745 mode_line_noprop_ptr
= mode_line_noprop_buf
;
23746 mode_line_target
= MODE_LINE_DISPLAY
;
23749 help_echo_showing_p
= 0;
23753 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
23754 (do not change this comment) */